TheSwamp

Code Red => .NET => Topic started by: Kerry on October 28, 2011, 03:37:07 AM

Title: Obsolete warnings ... various
Post by: Kerry on October 28, 2011, 03:37:07 AM

I have been re-building some old code  in VS2010 using the 2012 ObjectARX SDK and came across some
     'blablabla is obsolete: use thingy instead' warnings.

The code still compiles and runs fine but I want to start thinking about the future.

a few examples will follow, please add any others you come across.

Regards,
Title: Re: Obsolete warnings ... various
Post by: Kerry on October 28, 2011, 03:40:02 AM
WARNING :
'Autodesk.AutoCAD.DatabaseServices.Entity.IntersectWith(
                                                     Autodesk.AutoCAD.DatabaseServices.Entity,
                                                     Autodesk.AutoCAD.DatabaseServices.Intersect,
                                                     Autodesk.AutoCAD.Geometry.Point3dCollection,
                                                     long,
                                                     long)' is obsolete:
'Use the overload taking IntPtr instead.'   


The reflected signatures are
Code: [Select]
[Obsolete("Use the overload taking IntPtr instead.")]
public void IntersectWith(Entity entityPointer, Intersect intersectType, Point3dCollection points, long thisGraphicSystemMarker, long otherGraphicSystemMarker)
{
}

public void IntersectWith(Entity entityPointer, Intersect intersectType, Point3dCollection points, IntPtr thisGraphicSystemMarker, IntPtr otherGraphicSystemMarker)
{
}


This was pretty easy
This was the offending statement :
Code: [Select]
       ent1.IntersectWith(ent2, intersectType, pts, 0, 0);
could have used
Code: [Select]
       ent1.IntersectWith(ent2, intersectType, pts, new IntPtr(0), new IntPtr(0));
decided to use
Code: [Select]
       ent1.IntersectWith(ent2, intersectType, pts, IntPtr.Zero, IntPtr.Zero;
Title: Re: Obsolete warnings ... various
Post by: Kerry on October 28, 2011, 04:06:19 AM

The next was to do with the Table Class
ie  Autodesk.AutoCAD.DatabaseServices.Table

In fact, there are a myriad of obsolete warnings in the Table class  ... some of them appear to have no documented resolution, some appear to not work using the suggested resolutiom.

The reflected signatures that have the Obsolete Attribute set.
Code: [Select]
[Obsolete("Use Table.Columns.Count instead.")]
public virtual int NumColumns
{
    [Category("Table")]
    get    {    }
    set    {    }
}

[Obsolete("Use Table.Rows.Count instead.")]
public virtual int NumRows
{
    [Category("Table")]
    get    {    }
    set    {    }
}
 


Offending code :
Code: [Select]
            Table table;
            int rows = table.NumRows;
            int cols = table.NumColumns;
 



Amended property usage :
Code: [Select]
            Table table;
            int rows = table.Rows.Count;
            int cols = table.Columns.Count;
 


Title: Re: Obsolete warnings ... various
Post by: Kerry on October 28, 2011, 04:16:58 AM

Still with the Table ...
Here's a couple I can't find a resolution for :

Reflected signatures :-
Code: [Select]

[UnitType(UnitType.Distance), Obsolete("Use Table.Cells[row, column].HorizontalLine.Margin instead."), Category("Table")]
public virtual double HorizontalCellMargin
{
    get    {    }
    set    {    }
}

Code: [Select]

[UnitType(UnitType.Distance), Obsolete("Use Table.Cells[row, column].VerticalLine.Margin instead."), Category("Table")]
public virtual double VerticalCellMargin
{
    get    {    }
    set    {    }
}
 

Code: [Select]
[Obsolete("Use Cell functionality instead.")]
public virtual bool IsHeaderSuppressed
{
    [return: MarshalAs(UnmanagedType.U1)]
    [Category("Table")]
    get    {    }
    [param: MarshalAs(UnmanagedType.U1)]
    set    {    }
}

 
Code: [Select]
[Obsolete("Use Cell functionality instead.")]
public virtual bool IsTitleSuppressed
{
    [return: MarshalAs(UnmanagedType.U1)]
    [Category("Table")]
    get    {    }
    [param: MarshalAs(UnmanagedType.U1)]
    set    {    }
}
 

Has anyone come across a resolution to these ??
Title: Re: Obsolete warnings ... various
Post by: mohnston on October 28, 2011, 02:01:29 PM
Not those specific ones but others.
They changed from a bunch of functions to a better "object properties" approach. It made a mess of some of my code too.

[Warning: this is not actual code.]
Where they had SetColumnWidth(ColumnNumber, Value) it became Table.Column[ColumnNumber].Width = Value.
A lot of the SetColumnThis and SetCellThat functions went away.
You now set the properties of the column, row and cell objects.

Or did I completely miss the point of your question?
Title: Re: Obsolete warnings ... various
Post by: Kerry on October 30, 2011, 04:59:29 AM
Hello Mark


I was mainly looking for a resolution to the properties posted in Reply #3
ie
Code: [Select]
[Obsolete("Use Cell functionality instead.")]
public virtual bool IsHeaderSuppressed
{ // ..........
}
etc
 .... and for the general education of all, any others that  members have modified to suit the most recent build.

Title: Re: Obsolete warnings ... various
Post by: Jeff H on October 30, 2011, 08:17:13 AM
Kerry,
Do they work by using it's
TableStyle.HorizontalCellMargin
TableStyle.IsHeaderSuppressed
etc.........?
 
Code: [Select]
                    Table tbl = new Table();
                    tbl.TableStyle = db.Tablestyle;

                    TableStyle ts = (TableStyle)trx.GetObject(tbl.TableStyle, OpenMode.ForRead);
                    ts.HorizontalCellMargin = 12;
                    ts.IsHeaderSuppressed = true;
                    ////etc.......

 
Quote

TableStyle class objects are used to store the table formatting properties (for example, grid visibility, lineweight, line color, and cell font, height, color, and background fill) used by Table entities.
 
Because tables appear in a variety of forms, table objects will be based on a table style similar to the way text objects and dimension objects are based on styles in AutoCAD. The table style controls the initial formatting of a newly created table object and whether the table includes a title and header row.
 
Title: Re: Obsolete warnings ... various
Post by: Kerry on October 30, 2011, 09:02:52 AM


Chances are you're correct Jeff
..... the confusing issue is that the message says use the Cell functionality.

I'm guessing that the Acad_Table API is not complete.
.... time to 'phone a friend' I think.

Regards
Title: Re: Obsolete warnings ... various
Post by: Jeff H on October 30, 2011, 09:09:34 AM
And to add to the confusion they tell you use a method that does not exist or I can not find
Quote

HorizontalLine.Margin
Title: Re: Obsolete warnings ... various
Post by: Kerry on October 30, 2011, 09:16:27 AM
And to add to the confusion they tell you use a method that does not exist or I can not find
Quote

HorizontalLine.Margin

Yep, That's one of these  :)


The next was to do with the Table Class
ie  Autodesk.AutoCAD.DatabaseServices.Table

In fact, there are a myriad of obsolete warnings in the Table class  ... some of them appear to have no documented resolution, some appear to not work
Title: Re: Obsolete warnings ... various
Post by: Kerry on October 31, 2011, 06:07:28 AM

Sort of off topic :

I wonder why the Class is called Table.
... Have [you] tried to do a search for table   :ugly:
Title: Re: Obsolete warnings ... various
Post by: mohnston on October 31, 2011, 11:40:38 AM
Off your "off topic"
It's especially miserable when your program has database elements.
Now VS doesn't know which Table you mean.
Would have been better to call it AcadTable or something.

I looked back through my table code and didn't come across any instances where I used those particular properties so this comment is as useless as my last one.
Title: Re: Obsolete warnings ... various
Post by: Kean on November 04, 2011, 01:12:25 PM
Hello everyone,

At Kerry's suggestion, I've written a blog post to (hopefully) address this topic:

http://through-the-interface.typepad.com/through_the_interface/2011/11/handling-protocol-changes-to-autocads-table-in-net.html

By the way: we've avoided using "Acad" as a prefix (as we did for COM) in our .NET API (if I recall correctly it's recommended to use namespaces rather than prefixes in the .NET Framework Design Guidelines, although I may have that wrong). Anyway - if it's hard to find information about classes of a particular name, that's really a tooling issue rather than an API design issue, in my opinion.

Cheers,

Kean
Title: Re: Obsolete warnings ... various
Post by: Jeff_M on November 04, 2011, 05:17:57 PM
Thanks for the post, Kean. And thanks to Kerry for asking about it.

I ran into this last year when I first was tackling Tables, I never found a resolution and since it worked I just left it alone. It's funny how easy it is now, seeing what Kean did, but I must've spent 5-6 hours trying various things. I wish I had been as smart as Kerry and just asked the right people :-)  Off to fix my code now.....
Title: Re: Obsolete warnings ... various
Post by: Kerry on November 04, 2011, 06:05:08 PM

Thank you Kean for your continued support.

That should solve the issue for a lot of people.

... not to forget kudos to Stephen, Philippe and Balaji

Regards
 
Title: Re: Obsolete warnings ... various
Post by: Gasty on November 04, 2011, 06:28:14 PM
Hi,

As for the VS confusing db tables and acad tables, that can be avoided using an alias, like:

using fTable = Autodesk.AutoCAD.DatabaseServices.Table

-gnb
Title: Re: Obsolete warnings ... various
Post by: Kerry on November 04, 2011, 06:37:02 PM

Welcome to theSwamp Gasty.

Yes, using an alias works fine locally ... though I've had no issue with the compiler understanding the Class.

My issue is with 'google' and desktop searches for the word 'Table'.

... probably just a personal problem :)
Title: Re: Obsolete warnings ... various
Post by: It's Alive! on November 04, 2011, 10:29:17 PM
IMHO, some warnings are just to keep the newbie's out of trouble.
For Tables,  I see no issue with setting the number of rows and columns when creating a table, it's the subsequent calls  that can cause problems.  A safer and more generic way to "add" rows & columns would be.

Code: [Select]
tb.InsertRows( tb.Rows.Count, rowHeight, numRows - tb.Rows.Count);
tb.InsertColumns(tb.Columns.Count, colWidth, numCols - tb.Columns.Count);

in fact, this might make a good extension method. (Add)

I do like the newer style, its more dataset like
Title: Re: Obsolete warnings ... various
Post by: Kerry on November 04, 2011, 10:31:29 PM
< ... >
in fact, this might make a good extension method. (Add)

I do like the newer style, its more dataset like

yes,   and I like it too.
Title: Re: Obsolete warnings ... various
Post by: mohnston on November 07, 2011, 12:53:32 PM
Hi,

As for the VS confusing db tables and acad tables, that can be avoided using an alias, like:

using fTable = Autodesk.AutoCAD.DatabaseServices.Table

-gnb
Welcome indeed!
I hadn't thought of that. Thank you.

BTW - This is only an issue if you are "using" both Autodesk.AutoCAD.DatabaseServices and System.Data in the same class.