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

RE: [cc2-dev-l] Help with a text entity

Expand Messages
  • L. Lee Saunders
    JdR Here is the code I use to create the individual characters in the ATTC command. pText=DLApndE(HList, ET_TEXT2, 100); GetCStuff(pText);
    Message 1 of 3 , Mar 9, 2012
      JdR
       
      Here is the code I use to create the individual characters in the ATTC command.
       
      				pText=DLApndE(HList, ET_TEXT2, 100);
       
      				GetCStuff(pText);
      			
      				pText->Txt.Text.Font=Header->TSpec.Font;
      				pText->Txt.Text.Hght=Header->TSpec.Hgt;
      				pText->Txt.Text.XScl=Header->TSpec.XScl;
      				pText->Txt.Text.TFlags=Header->TSpec.Flags;
      				pText->Txt.Text.TData[0]=InText[i];
      				pText->Txt.Text.TData[1]='\0';
      				pText->Txt.Text.Origin.x=Pt.x;
      				pText->Txt.Text.Origin.y=Pt.y;
      				pText->Txt.Text.Just=Placement; //1 Above : 7 Below : 4 Centered
      				pText->Txt.Text.BAng=TanAngle;
       
      				EDraw(pText);
       
      Some points of interest.  TData is a null terminated string.  So, it is one character longer than the number of characters you want to display and the last character is the null character '\0'. So, your random characters are what the code is finding in memory after your one char and going until it finds a null char.
       
      TData is part of GTEXT2
      typedef struct 
      {
      	short	Font;
      	GPOINT2 Origin;
      	float	Hght;
      	float	XScl;
      	float	BAng;
      	float	Spacing;
      	short	TFlags;
      	short	DFlags;
      	short	Just;
      	char	TData[1];
      } GTEXT2;
      And because it is the last member of the struct, when more memory is given to the pEntRec that is your Text object, it will be for the increase in size of your text object.  This is just like the Path object in that you need to increase its size for every additional point you add, so you need to also add one byte in size of the Text object for each byte increase in size you make your text string.  Otherwise, your string (char array) will overright some other enitity in the Drawing List.
       
      So, treat it like a path and you should have no problems.

      L. Lee Saunders
       
      "It was only a partial solution, of course, as solutions usually are, and addressed only one specific problem, as solutions usually do. But, as was often also true, it opened the door—if only a crack—for the multitude of solutions to follow." 
      1632 - Eric Flint
       
      my blog: http://oldschooldotnet.blogspot.com
      Taking Dot Net "Old School" - Playing with old ideas/concepts using the newest tools!
       
       


       

      To: cc2-dev-l@yahoogroups.com
      From: jdr68@...
      Date: Fri, 9 Mar 2012 13:00:55 +0100
      Subject: [cc2-dev-l] Help with a text entity

       
      Hi,
       
      I need to create text entities that display numeric values.
       
      1) In which format do I need to convert the number (integer or perhaps float) ?
      I've tried the String^ with the basic ToString("0")
      I've tried the FORMSTPKT route
      I've even written code to convert a float in a std::string
      And I've tried to create a char* pointer to one of those to no avail...because :
      2) How do I give the string to the TXT2 TData parameter ?
      The doc says "char TData[1]" which means, I believe, a 2 char long string.
      When I try things like
      TData[0]='S';
      I get a text entity which displays an arrow head pointing left (not related to the Just byte) over a S sometimes followed by random caracters such as "Sgled Gr"
      When I try
      TData[1] = 'S'; I get an empty text entity
       
      From a older post I also tried a lstrcopy() that doesn't work either...
       
      Help please! Thanks...
       
      JdR
       


    • Joachim de Ravenbel
      OMG you re a genius !!! It works fine, though I still don t know what I did wrong... I was aware of the /0 thing but handled it badly... Perhaps it was
      Message 2 of 3 , Mar 10, 2012
        OMG you're a genius !!!
         
        It works fine, though I still don't know what I did wrong... I was aware of the /0 thing but handled it badly...
        Perhaps it was creating first a TXT2 entity and using DLApnd after instead of beginning with a DLApndE ?
        Here's my code in case of...
         
        GPOINT2 A,B;
        int alt,leng,j;
        std::string mytext;
        pENTREC pText;
        HDR *Header=GetHeaderAdr();
        MarkUndoAdd();
        for (int i=0; i<16; i++)
        {
            A.x = M.x + BoxHeight*LegendScale;
            A.y = M.y - 1.5*i*BoxHeight*LegendScale - BoxHeight*LegendScale;
            B.x = M.x + BoxHeight*LegendScale + BoxWidth*LegendScale;
            B.y = M.y - (1.5*i + 1)*BoxHeight*LegendScale - BoxHeight*LegendScale;
            DrawABox(A,B,Cschm[i]);
            alt = 100*i;
            mytext = CSTR2((
        float)alt,0);
            leng = mytext.length();
            pText=DLApndE(NULL, ET_TEXT2,
        sizeof(TXT2) + leng + 1);
            GetCStuff(pText)
            pText->Txt.Text.Font=Header->TSpec.Font;
            pText->Txt.Text.Hght=BoxHeight;
            pText->Txt.Text.XScl=Header->TSpec.XScl;
            pText->Txt.Text.TFlags=Header->TSpec.Flags;
            for (int j=0 ; j<leng ; j++)
            {
                pText->Txt.Text.TData[j]=(
        char)mytext[j];
            }
            pText->Txt.Text.TData[leng]=
        '\0';
            pText->Txt.Text.Origin.x= M.x + BoxHeight*LegendScale + BoxWidth*LegendScale;
            pText->Txt.Text.Origin.y= M.y - (1.5*i + 0.5)*BoxHeight*LegendScale - BoxHeight*LegendScale;
            pText->Txt.Text.Just= 9;
            pText->Txt.Text.BAng= 0;
            EDraw(pText)
        }
         
        DrawABox(GPOINT2 A, GPOINT2 B, char Color) is self explaining I think.
        std::string CSTR2(float Number, int decimal_digits) is a routine I wrote before I found out about ToString() and marshalling... It converts a float in a standard string.
         
        There might be a nicer way to insert the string...
         
        I'm in you debt... Again...
        Thanks a lot!
         
        JdR
         
        ----- Original Message -----
        To: dev
        Sent: Saturday, March 10, 2012 3:04 AM
        Subject: RE: [cc2-dev-l] Help with a text entity

         

        JdR
         
        Here is the code I use to create the individual characters in the ATTC command.
         
        				pText=DLApndE(HList, ET_TEXT2, 100);
         
        				GetCStuff(pText);
        			
        				pText->Txt.Text.Font=Header->TSpec.Font;
        				pText->Txt.Text.Hght=Header->TSpec.Hgt;
        				pText->Txt.Text.XScl=Header->TSpec.XScl;
        				pText->Txt.Text.TFlags=Header->TSpec.Flags;
        				pText->Txt.Text.TData[0]=InText[i];
        				pText->Txt.Text.TData[1]='\0';
        				pText->Txt.Text.Origin.x=Pt.x;
        				pText->Txt.Text.Origin.y=Pt.y;
        				pText->Txt.Text.Just=Placement; //1 Above : 7 Below : 4 Centered
        				pText->Txt.Text.BAng=TanAngle;
         
        				EDraw(pText);
         
        Some points of interest.  TData is a null terminated string.  So, it is one character longer than the number of characters you want to display and the last character is the null character '\0'. So, your random characters are what the code is finding in memory after your one char and going until it finds a null char.
         
        TData is part of GTEXT2
        typedef struct 
        {
        	short	Font;
        	GPOINT2 Origin;
        	float	Hght;
        	float	XScl;
        	float	BAng;
        	float	Spacing;
        	short	TFlags;
        	short	DFlags;
        	short	Just;
        	char	TData[1];
        } GTEXT2;
        And because it is the last member of the struct, when more memory is given to the pEntRec that is your Text object, it will be for the increase in size of your text object.  This is just like the Path object in that you need to increase its size for every additional point you add, so you need to also add one byte in size of the Text object for each byte increase in size you make your text string.  Otherwise, your string (char array) will overright some other enitity in the Drawing List.
         
        So, treat it like a path and you should have no problems.

        L. Lee Saunders
         
        "It was only a partial solution, of course, as solutions usually are, and addressed only one specific problem, as solutions usually do. But, as was often also true, it opened the door—if only a crack—for the multitude of solutions to follow." 
        1632 - Eric Flint
         
        my blog: http://oldschooldotnet.blogspot.com
        Taking Dot Net "Old School" - Playing with old ideas/concepts using the newest tools!
         
         


         

        To: cc2-dev-l@yahoogroups.com
        From: jdr68@...
        Date: Fri, 9 Mar 2012 13:00:55 +0100
        Subject: [cc2-dev-l] Help with a text entity

         
        Hi,
         
        I need to create text entities that display numeric values.
         
        1) In which format do I need to convert the number (integer or perhaps float) ?
        I've tried the String^ with the basic ToString("0")
        I've tried the FORMSTPKT route
        I've even written code to convert a float in a std::string
        And I've tried to create a char* pointer to one of those to no avail...because :
        2) How do I give the string to the TXT2 TData parameter ?
        The doc says "char TData[1]" which means, I believe, a 2 char long string.
        When I try things like
        TData[0]='S';
        I get a text entity which displays an arrow head pointing left (not related to the Just byte) over a S sometimes followed by random caracters such as "Sgled Gr"
        When I try
        TData[1] = 'S'; I get an empty text entity
         
        From a older post I also tried a lstrcopy() that doesn't work either...
         
        Help please! Thanks...
         
        JdR
         


      Your message has been successfully submitted and would be delivered to recipients shortly.