Author Topic: An Interesting Puzzle....  (Read 1891 times)

0 Members and 1 Guest are viewing this topic.

TheMaster

  • Guest
An Interesting Puzzle....
« on: February 13, 2013, 11:56:25 PM »
Regarding Kean's latest work of art:

http://through-the-interface.typepad.com/through_the_interface/2013/02/maintaining-per-object-xdata-in-autocad-using-net.html

See my comment there, and look at his solution...

Can someone tell me what it is that was overlooked, and how that makes his solution fatally-flawed? 

Jeff H

  • Needs a day job
  • Posts: 6150
Re: An Interesting Puzzle....
« Reply #1 on: February 14, 2013, 12:25:49 AM »
Not sure if one of the points you were referring to but if the drawing is WBlocked then the object can have the same handle.

Maybe for that to work would have to prefix with drawing file path?

Jeff H

  • Needs a day job
  • Posts: 6150
Re: An Interesting Puzzle....
« Reply #2 on: February 14, 2013, 01:04:43 AM »
Not sure if this matters depending on requirements but just to throw it out there wouldn't you get bite from commands like BREAK that use handOverTo?
« Last Edit: February 14, 2013, 01:08:15 AM by Jeff H »

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
Re: An Interesting Puzzle....
« Reply #3 on: February 14, 2013, 03:32:03 AM »
It might be interesting to see TT his missing piece of the puzzle. Still I think Keans post is very useful, and the solution to TRY to keep the Xdata attached to the right object, seems to be effective. At least for the use of Xdata. Even Kean admits the post is not about which is better: Xdata or Xrecords or other.

There are other and better ways to store extended data to an object, but with the limitations of Xdata it is a handy trick. Btw, the biggest limitation of Xdata is the ignorant user who can destroy every system.

In the past we had an application that used Xdata to keep track of surveyed data and the mutation status (new, existing, erased). With use of reactors the application tried to catch deleted objects to change the status into erased. But if the app was not loaded, the erased elements were gone. Also joined or exploded objects, or copied surveyed objects destroyed the full plan. It depends on the knowledge and the willingness of the user if such a system is reliable.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: An Interesting Puzzle....
« Reply #4 on: February 14, 2013, 04:24:28 AM »
I have deleted several posts from this thread that I believe are contrary to the goals of theSwamp.
If you feel that you have been hard done by ;  PM be and make your case.

Regards
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

TheMaster

  • Guest
Re: An Interesting Puzzle....
« Reply #5 on: February 14, 2013, 06:46:38 AM »
Not sure if one of the points you were referring to but if the drawing is WBlocked then the object can have the same handle.

Maybe for that to work would have to prefix with drawing file path?

Right. An object cloned from one database to another could have the same handle as the original source object.  Sticking a database identifier in with the handle string would also not work, because the file could be renamed, or copied (e.g. 'forked'),  and the objects in both the original and the copy will have the same database identifiers.

Of course that would certainly decrease the chances of a source object and clone having the same handle to something that would be nearly-impossible, but the cost is having carry around all of that data.

I use Overrules to solve similar problems because they are the types of problem that Overrules were intended to solve:

Code - C#: [Select]
  1.  
  2. public abstract class XDataCloneOverrule<T> : XDataOverrule<T>
  3.    where T : DBObject
  4. {
  5.    protected XDataCloneOverrule( string appname, Database database = null )
  6.       : base( appname, database )
  7.    {
  8.    }
  9.  
  10.    public override DBObject DeepClone( DBObject dbObject, DBObject ownerObject, IdMapping idMap, bool isPrimary )
  11.    {
  12.       DBObject result = base.DeepClone( dbObject, ownerObject, idMap, isPrimary );
  13.       if( IsDatabaseApplicable( ownerObject.Database ) )
  14.       {
  15.          try
  16.          {
  17.             using( ResultBuffer xdata = GetXData( dbObject ) )
  18.             {
  19.                if( xdata != null )
  20.                {
  21.                   T source = dbObject as T;
  22.                   if( source != null )
  23.                   {
  24.                      T clone = result as T;
  25.                      if( clone != null )
  26.                         OnCloned( source, xdata, clone, ownerObject, idMap, isPrimary );
  27.                   }
  28.                }
  29.             }
  30.          }
  31.          catch( System.Exception ex )
  32.          {
  33.             throw ex;
  34.          }
  35.       }
  36.       return result;
  37.    }
  38.  
  39.    public override DBObject WblockClone( DBObject dbObject, RXObject ownerObject, IdMapping idMap, bool isPrimary )
  40.    {
  41.       DBObject result = base.WblockClone( dbObject, ownerObject, idMap, isPrimary );
  42.       if( IsDatabaseApplicable( ownerObject ) )
  43.       {
  44.          try
  45.          {
  46.             using( ResultBuffer xdata = GetXData( dbObject ) )
  47.             {
  48.                if( xdata != null )
  49.                {
  50.                   T source = dbObject as T;
  51.                   if( source != null )
  52.                   {
  53.                      T clone = result as T;
  54.                      if( clone != null )
  55.                         OnCloned( source, xdata, clone, ownerObject, idMap, isPrimary );
  56.                   }
  57.                }
  58.             }
  59.          }
  60.          catch( System.Exception ex )
  61.          {
  62.             throw ex;
  63.          }
  64.       }
  65.       return result;
  66.    }
  67.  
  68.    /// <summary>
  69.    ///
  70.    /// You can override this to get control after the clone has
  71.    /// been created by either DeepClone() or WblockClone() (the
  72.    /// context indicating which can be deduced from the idMap),
  73.    /// and act on the clone and the xdata from the source object.
  74.    /// This will only be called if the source object has XData
  75.    /// for the given application name.
  76.    ///
  77.    /// This is where you can resolve xdata on cloned objects in
  78.    /// those cases where the data has some special requirement,
  79.    /// such as having values that must be unique, or values in
  80.    /// xdata of copied objects that have some dependence on the
  81.    /// corresponding value in a source object.
  82.    ///
  83.    /// </summary>
  84.    /// <param name="source">The source object that was cloned</param>
  85.    /// <param name="xdata">The source object's XData for the given application name</param>
  86.    /// <param name="clone">The clone of the source object</param>
  87.    /// <param name="owner">The owner object which the clone was appended to, or the owning Database</param>
  88.    /// <param name="idMap">The id map</param>
  89.    /// <param name="isPrimary">IsPrimary</param>
  90.  
  91.    protected virtual void OnCloned( T source, ResultBuffer xdata, T clone, RXObject owner, IdMapping idMap, bool isPrimary )
  92.    {
  93.    }
  94. }
  95.  
  96.  
  97.