Loading ...
Sorry, an error occurred while loading the content.

Re: Can I create a PATH2 element without adding it to a drawing list?

Expand Messages
  • saul012000
    Its just amazing. I ve been trying to figure out how to do this since I started coding XPs ... off and on for over 10 years. It was never a high priority
    Message 1 of 3 , Nov 9, 2010
    • 0 Attachment
      Its just amazing. I've been trying to figure out how to do this since I started coding XPs ... off and on for over 10 years. It was never a high priority since I had a way that worked, but it was just something that I wanted to do.

      Now, after finally breaking down and asking for help, I finally figure it out. Since I thought I had tried this before, but maybe my earlier attempts failed because I did not set EVERY member of the struct.

      Well, for those that care, here is the code:

      PATH2 *pathPtr = (PATH2*)malloc(sizeof(PATH2));

      pathPtr->CStuff.ERLen = sizeof(PATH2); // entity record length
      pathPtr->CStuff.EType = ET_PATH2; // entity type code
      pathPtr->CStuff.EFlags = 0; // erase/select bits
      pathPtr->CStuff.EFlags2 = 0; // extra flags
      pathPtr->CStuff.EColor = 1; // entity color
      pathPtr->CStuff.EColor2 = 1; // fill (2nd) color
      pathPtr->CStuff.EThick = 0; // pen thickness 0..25.4 mm
      pathPtr->CStuff.WPlane = 0; // workplane (0 = XY plane)
      pathPtr->CStuff.ELayer = 1; // layer
      pathPtr->CStuff.ELStyle = 0; // line style (0=solid)
      pathPtr->CStuff.GroupID = 0; // group id (0 = not grouped)
      pathPtr->CStuff.EFStyle = 0; // fill style (0=hollow)
      pathPtr->CStuff.LWidth = 0.0; // line width
      pathPtr->CStuff.Tag = 0; // entity tag id
      pathPtr->Path.SmType = 0; //SmType
      pathPtr->Path.SRes = 8; //SRes
      pathPtr->Path.SParm = 0.0; //SParm
      pathPtr->Path.EParm = 0.0; //EParm
      pathPtr->Path.Count = 0; //Count
      pathPtr->Path.Flags = 0; //Flags
      pathPtr->Path.unused = 0; //unused

      GetCStuff((pENTREC)pathPtr);

      pathPtr = (PATH2*)realloc(pathPtr, sizeof(PATH2) + sizeof(GPOINT2) * 4);

      pathPtr->CStuff.ERLen = sizeof(PATH2) + sizeof(GPOINT2) * 4;

      pathPtr->Path.Nodes[0].x = 0.0; //Nodes[0]
      pathPtr->Path.Nodes[0].y = 0.0; //Nodes[0]
      pathPtr->Path.Nodes[1].x = 0.0; //Nodes[1]
      pathPtr->Path.Nodes[1].y = 1000.0; //Nodes[1]
      pathPtr->Path.Nodes[2].x = 1000.0; //Nodes[2]
      pathPtr->Path.Nodes[2].y = 1000.0; //Nodes[2]
      pathPtr->Path.Nodes[3].x = 1000.0; //Nodes[3]
      pathPtr->Path.Nodes[3].y = 0.0; //Nodes[3]

      pathPtr->Path.Count = 4;
      pathPtr->Path.EParm = 4.0;
      pathPtr->Path.Flags = NL_CLS;

      pENTREC pEntRec = DLApnd(NULL, (pENTREC)pathPtr);

      EDraw(pEntRec);

      free(pathPtr);

      > OK, I've been playing around with this for a few days ... here is what I've got that works and what I am trying to do and failing at:
      >
      > PATH2 path = { sizeof(PATH2) + sizeof(GPOINT2) * 3, // entity record length
      > ET_PATH2, // entity type code
      > 0, // erase/select bits
      > 0, // extra flags
      > 1, // entity color
      > 1, // fill (2nd) color
      > 0, // pen thickness 0..25.4 mm
      > 0, // workplane (0 = XY plane)
      > 1, // layer
      > 0, // line style (0=solid)
      > 0, // group id (0 = not grouped)
      > 0, // fill style (0=hollow)
      > 0.0, // line width
      > 0, // entity tag id
      > 0, //SmType
      > 8, //SRes
      > 0.0, //SParm
      > 2.0, //EParm
      > 3, //Count
      > 0, //Flags
      > 0, //unused
      > 0.0, //Nodes[0]
      > 0.0, //Nodes[0]
      > 0.0, //Nodes[1]
      > 1000.0, //Nodes[1]
      > 1000.0, //Nodes[2]
      > 1000.0 }; //Nodes[2]
      >
      > PATH2 *pathPtr = &path;
      >
      > pENTREC pEntRec = DLApnd(NULL, (pENTREC)pathPtr);
      >
      >
      >
      > This works, but it is limiting to a hardcoded number of points. So I need a way to resize path/pathPtr, but when I try to re-allocate (the equivalent to DLResize) using realloc, it blows up. What am I doing wrong?
      >
      >
      >
      > PATH2 path = { sizeof(PATH2) + sizeof(GPOINT2) * 3, // entity record length
      > ET_PATH2, // entity type code
      > 0, // erase/select bits
      > 0, // extra flags
      > 1, // entity color
      > 1, // fill (2nd) color
      > 0, // pen thickness 0..25.4 mm
      > 0, // workplane (0 = XY plane)
      > 1, // layer
      > 0, // line style (0=solid)
      > 0, // group id (0 = not grouped)
      > 0, // fill style (0=hollow)
      > 0.0, // line width
      > 0, // entity tag id
      > 0, //SmType
      > 8, //SRes
      > 0.0, //SParm
      > 2.0, //EParm
      > 3, //Count
      > 0, //Flags
      > 0, //unused
      > 0.0, //Nodes[0]
      > 0.0, //Nodes[0]
      > 0.0, //Nodes[1]
      > 1000.0, //Nodes[1]
      > 1000.0, //Nodes[2]
      > 1000.0 }; //Nodes[2]
      >
      > PATH2 *pathPtr = &path;
      >
      > pathPtr = (PATH2*)realloc(pathPtr, sizeof(PATH2) + sizeof(GPOINT2) * 4);
      >
      > pathPtr->CStuff.ERLen = sizeof(PATH2) + sizeof(GPOINT2) * 4;
      >
      > pathPtr->Path.Nodes[3].x = 1000.0;
      > pathPtr->Path.Nodes[3].y = 0.0;
      >
      > pathPtr->Path.Count = 4;
      > pathPtr->Path.EParm = 3.0;
      >
      > pENTREC pEntRec = DLApnd(NULL, (pENTREC)pathPtr);
      >
      > --- In cc2-dev-l@yahoogroups.com, "Larry" <saunderl@> wrote:
      > >
      > > Mike - Peter?
      > >
      > > Is it possible to declare a PATH2 variable with, say, 6 nodes in it then add it to a drawing list later, or do I have to create a pENTREC by DLApndE of type ET_PATH2.
      > >
      > > The included examples show how to create a LINE2 variable and a CIR2 variable, but these are fixed size records and PATH2 is variable in size.
      > >
      > > I've tried various things including:
      > > PATH2 p = *((PATH2*)malloc(sizeof(PATH2) + (sizeof(GPOINT2) * 6));
      > >
      > > This worked to a point. The first point (or node), but all the rest of the node elements, when set, did not transfer over to the drawing list when p was added to the drawing list with DLApnd(NULL, (pENTREC)&p).
      > >
      > > Thanks for the help.
      > > Lee
      > >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.