Author Topic: [Serializable] not!  (Read 3805 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8659
  • AKA Daniel
[Serializable] not!
« on: October 26, 2007, 01:55:17 AM »

Does anyone know why Autodesk chose not to mark some of the basic types
such as Point3d, Point2d, ObjectId, etc [Serializable]   ?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: [Serializable] not!
« Reply #1 on: October 26, 2007, 04:31:39 AM »
Insomniac response so it's probably way out to lunch but - perhaps because they are all primitive data types the overhead / bloat isn't justifiable, in particular because of the cascaded effect upon the object model greater.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: [Serializable] not!
« Reply #2 on: October 26, 2007, 05:33:34 AM »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: [Serializable] not!
« Reply #3 on: October 26, 2007, 06:18:37 AM »
Hi Daniel .. I'm playing guessing games as well, but Michael's conjecture seems to make sense.

... I'd also guess that the serialization would need to be purpose specific'

..  .. from memory very few of the library classes are Serializable.

There is a .net sample in the ObjectARX SDK called TestFiler.cs demonstrating Object dumping ... but there probably won't be much new stuff there for you :-)

sorry I can't be of help.
   
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.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8659
  • AKA Daniel
Re: [Serializable] not!
« Reply #4 on: October 26, 2007, 06:30:59 AM »
Thanks for the replies. I’ll just wrap the objects I need serialized in new serializable objects and/or breakout the primitives I need stored.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: [Serializable] not!
« Reply #5 on: October 26, 2007, 07:58:08 PM »

Does anyone know why Autodesk chose not to mark some of the basic types
such as Point3d, Point2d, ObjectId, etc [Serializable]   ?

My guess would be is seeing that acad looks after serialisation itself and the .net lib's are just a wrapper/interface to the 'real' objects it wasn't required...from their point of view of course.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8659
  • AKA Daniel
Re: [Serializable] not!
« Reply #6 on: October 27, 2007, 01:36:17 AM »
Having a little fun here

Code: [Select]
//(Serialize "c:\\test.dat" "hola")
//(Serialize "c:\\test.dat" '(1 1 1))
//(Serialize "c:\\test.dat" '(1 2 3 1.2 "Wow This is almost cool"))
//(UnSerialize "c:\\test.dat")

//(SaveVars "c:\\test.dat")
//(RestoreVars "c:\\test.dat")

//(defun savevars (path / outlist varlist)
// (setq outlist '())
// (setq varlist '("osmode" "cmdecho" "attdia" "pickstyle"))
// (foreach e varlist
//  (setq outlist (cons (cons e (getvar e)) outlist))
// )
// (Serialize path outlist)
//)

//(defun RestoreVars (path / e inlist)
// (setq inlist (UnSerialize path))
// (if (/=(car inlist) nill)
//  (foreach e inlist
//   (setvar (car e)(cdr e) )
//  )
// )
// (princ)
//)


using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass(typeof(LispSerialization.Commands))]

namespace LispSerialization
{
  public class Commands
  {
    public Commands()
    {
    }
    [LispFunction("Serialize")]
    static public ResultBuffer dome(ResultBuffer Rb)
    {
      ResultBuffer RetRb = new ResultBuffer();
      try
      {
        TypedValue[] tvArray = Rb.AsArray();
        Stream stream = new FileStream((string)tvArray[0].Value, FileMode.Create);
        try
        {
          List<KeyValuePair<int, Object>>
            kvList = new List<KeyValuePair<int, object>>();
          for (int i = 1; i < tvArray.Length; i++)
          {
            switch ((int)tvArray[i].TypeCode)
            {
              case (int)LispDataType.Point2d:
                {
                  Point2d pt = (Point2d)tvArray[i].Value;
                  kvList.Add(new KeyValuePair<int, object>
                     ((int)LispDataType.ListBegin, null));

                  kvList.Add(new KeyValuePair<int, object>
                     ((int)LispDataType.Double, pt.X));

                  kvList.Add(new KeyValuePair<int, object>
                     ((int)LispDataType.Double, pt.Y));

                  kvList.Add(new KeyValuePair<int, object>
                    ((int)LispDataType.ListEnd, null));
                }
                break;
              case (int)LispDataType.Point3d:
                {
                  Point3d pt = (Point3d)tvArray[i].Value;

                  kvList.Add(new KeyValuePair<int, object>
                     ((int)LispDataType.ListBegin, null));

                  kvList.Add(new KeyValuePair<int, object>
                     ((int)LispDataType.Double, pt.X));

                  kvList.Add(new KeyValuePair<int, object>
                     ((int)LispDataType.Double, pt.Y));

                  kvList.Add(new KeyValuePair<int, object>
                     ((int)LispDataType.Double, pt.Z));

                  kvList.Add(new KeyValuePair<int, object>
                    ((int)LispDataType.ListEnd, null));
                }
                break;
              case (int)LispDataType.Angle:
              case (int)LispDataType.DottedPair:
              case (int)LispDataType.Double:
              case (int)LispDataType.Int16:
              case (int)LispDataType.Int32:
              case (int)LispDataType.ListBegin:
              case (int)LispDataType.ListEnd:
              case (int)LispDataType.Nil:
              case (int)LispDataType.None:
              //case (int)LispDataType.Orientation:
              case (int)LispDataType.T_atom:
              case (int)LispDataType.Text:
              case (int)LispDataType.Void:
                kvList.Add(new KeyValuePair<int, object>
                       ((int)tvArray[i].TypeCode, (object)tvArray[i].Value));
                break;
            }
          }
          IFormatter formatter = new BinaryFormatter();
          formatter.Serialize(stream, kvList);
          RetRb.Add(new TypedValue((int)LispDataType.T_atom));
        }
        finally
        {
          stream.Close();
        }
      }
      catch
      {
        RetRb.Add(new TypedValue((int)LispDataType.Nil));
      }
      return RetRb;
    }

    [LispFunction("UnSerialize")]
    static public ResultBuffer undome(ResultBuffer Rb)
    {
      TypedValue[] tvArray = Rb.AsArray();
      ResultBuffer RetRb = new ResultBuffer();
      Stream stream = null;
      try
      {
        stream = new FileStream((string)tvArray[0].Value, FileMode.Open);
        IFormatter formatter = new BinaryFormatter();

        List<KeyValuePair<int, Object>> kvList =
          (List<KeyValuePair<int, Object>>)formatter.Deserialize(stream);

        for (int i = 0; i < kvList.Count; i++)
        {
          RetRb.Add(new TypedValue(kvList[i].Key, kvList[i].Value));
        }
      }
      catch
      {
        RetRb.Add(new TypedValue((int)LispDataType.Nil));
      }
      finally
      {
        stream.Close();
      }
      return RetRb;
    }
  }
}