home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 v2.4 Fix / W95-v2.4fix.iso / ACADWIN / ADS / CPP / GENERAL / ADSENT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-08  |  8.9 KB  |  286 lines

  1. /* 
  2.     ADSENT.CPP -
  3.     
  4.     This file:
  5.  
  6.         Defines basic ADS entity objects.  Only a few objects,
  7.         ADS_POINT, ADS_LINE and ADS_CIRCLE are declared.  This 
  8.         should be expanded to cover wider range of ACAD objects 
  9.         by the users.
  10.         
  11.  
  12.     (C) Copyright 1988-1994 by Autodesk, Inc.
  13.  
  14.     This program is copyrighted by Autodesk, Inc. and is  licensed
  15.     to you under the following conditions.  You may not distribute
  16.     or  publish the source code of this program in any form.   You
  17.     may  incorporate this code in object form in derivative  works
  18.     provided  such  derivative  works  are  (i.) are  designed and
  19.     intended  to  work  solely  with  Autodesk, Inc. products, and
  20.     (ii.)  contain  Autodesk's  copyright  notice  "(C)  Copyright
  21.     1988-1994 by Autodesk, Inc."
  22.  
  23.     AUTODESK  PROVIDES THIS PROGRAM "AS IS" AND WITH  ALL  FAULTS.
  24.     AUTODESK  SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF  MER-
  25.     CHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK,  INC.
  26.     DOES  NOT  WARRANT THAT THE OPERATION OF THE PROGRAM  WILL  BE
  27.     UNINTERRUPTED OR ERROR FREE.
  28.  
  29. */
  30. #include "adsinc.h"
  31.  
  32. //-----------------------------------------------------------------------------
  33. //static ADS_STRING       entity_end_string( "\n\tEnd of Entity" );
  34. //static ADS_STRING       entity_begin_string( "\tBegin of Entity\n" );
  35. static ADS_STRING       entity_record_seperator("\n");
  36.  
  37. static ADS_STRING       entity_end_string( "\n" );
  38. static ADS_STRING       entity_begin_string( " " );
  39. //static ADS_STRING     entity_record_seperator( " " );
  40.  
  41. static ADS_STRING       entity_name_mark( "Entity Name:\t" );
  42.  
  43.  
  44. //-----------------------------------------------------------------------------
  45. ADS_ENT_OBJ* MakeAdsLine( struct resbuf *rb );
  46. ADS_ENT_OBJ* MakeAdsCircle( struct resbuf *rb );
  47. ADS_ENT_OBJ* MakeAdsPoint( struct resbuf *rb );
  48. ADS_ENT_OBJ* MakeAdsShape( struct resbuf *rb );
  49. ADS_ENT_OBJ* MakeAdsGenericEntity( struct resbuf *rb );
  50.  
  51. //-----------------------------------------------------------------------------
  52. struct _ADS_ENT_TYPES
  53. {
  54.     ADS_ENT_OBJ* ( *MakeEntFun )( struct resbuf *rb );
  55.     char            *typename;
  56. }ADS_ENT_TYPES[] =
  57. {
  58.     { MakeAdsLine,          "LINE" }
  59.     , { MakeAdsPoint,       "POINT" }
  60.     , { MakeAdsCircle,      "CIRCLE" }
  61.     , { MakeAdsShape,       "SHAPE" }
  62. };
  63.  
  64. //-----------------------------------------------------------------------------
  65. void DeleteAdsEntity( ADS_ENT_OBJ* ent_obj )
  66. {
  67.     delete ent_obj;
  68. }
  69.  
  70. //-----------------------------------------------------------------------------
  71. ADS_ENT_OBJ* MakeAdsEntity( struct resbuf *rb )
  72. {
  73.     int     i;
  74.     for ( i = 0; i < ARRAY_SIZE( ADS_ENT_TYPES  ) ; i++ )
  75.     {
  76.         if ( _stricmp( rb->rbnext->resval.rstring
  77.                     , ADS_ENT_TYPES[ i ].typename ) == 0 )
  78.         {
  79.             return ( * ( ADS_ENT_TYPES[ i ].MakeEntFun ) )( rb );
  80.         }
  81.     }
  82.     if ( i == ARRAY_SIZE ( ADS_ENT_TYPES ) )
  83.     {
  84.         return MakeAdsGenericEntity( rb );
  85.     }
  86.     return NULL;
  87. }
  88.  
  89.  
  90. //-----------------------------------------------------------------------------
  91. ADS_ENT_OBJ* MakeAdsLine( struct resbuf *rb )
  92. {
  93.     return new ADS_LINE( rb );
  94. }
  95.  
  96. //-----------------------------------------------------------------------------
  97. ADS_ENT_OBJ* MakeAdsCircle( struct resbuf *rb )
  98. {
  99.     return new ADS_CIRCLE( rb );
  100. }
  101.  
  102. //-----------------------------------------------------------------------------
  103. ADS_ENT_OBJ* MakeAdsPoint( struct resbuf *rb )
  104. {
  105.     return new ADS_POINT( rb );
  106. }
  107.  
  108. //-----------------------------------------------------------------------------
  109. ADS_ENT_OBJ* MakeAdsShape( struct resbuf *rb )
  110. {
  111.     return new ADS_SHAPE( rb );
  112. }
  113.  
  114. //-----------------------------------------------------------------------------
  115. ADS_ENT_OBJ* MakeAdsGenericEntity( struct resbuf *rb )
  116. {
  117.     return new ADS_GENERIC_ENTITY( rb );
  118. }
  119.  
  120. /******************************************************************************
  121. *                                                                             *
  122. *                       ADS_ENT_OBJ member functions                          *
  123. *                                                                             *
  124. ******************************************************************************/
  125. //-----------------------------------------------------------------------------
  126. char* ADS_ENT_OBJ::GetEntityName( char *buf, int buf_size )
  127. {
  128.     AdsName2Str( buf, rb );
  129.  
  130.     if ( rb->rbnext 
  131.         && rb->rbnext->restype == 0 
  132.         && rb->rbnext->resval.rstring != NULL )
  133.     {
  134.         strcat( buf, ", " );
  135.         strcat( buf, rb->rbnext->resval.rstring );
  136.     }
  137.     return buf;
  138. }
  139.  
  140. //-----------------------------------------------------------------------------
  141. ADS_STRING& ADS_ENT_OBJ::FormatEntityString()
  142. {
  143.     if ( rb == NULL || rb->restype != -1 )
  144.     {
  145.         formatstring = "";
  146.         return formatstring;
  147.     }
  148.  
  149.     char    *record_buffer = new char[ GENERAL_BUFFER_SIZE ];
  150.     //
  151.     // Terrible way to do this, what if rb has more info GENERAL_BUFFER_SIZE
  152.     // can handle?  I need a string library!
  153.     //
  154.     // Set the entity name first, which should be the rb->resval.rlname
  155.     formatstring = entity_name_mark;
  156.  
  157.     if ( AdsName2Str( record_buffer, rb ) )
  158.     {
  159.         formatstring += record_buffer;
  160.     }
  161.     
  162.     //
  163.     // treeing down the resbuf for the list
  164.     //
  165.     struct resbuf* current_resbuf = rb->rbnext;
  166.     while ( current_resbuf )
  167.     {
  168.         if ( DXFGroupCode2Str( current_resbuf, record_buffer ) != NULL )
  169.         {
  170.             formatstring += entity_record_seperator 
  171.                             + record_buffer;
  172.         }
  173.         current_resbuf = current_resbuf->rbnext;
  174.     }
  175.     formatstring += entity_end_string;
  176.  
  177.     delete record_buffer;
  178.     return formatstring;
  179. }
  180.  
  181. //-----------------------------------------------------------------------------
  182. // No checking for this function, used to retrieve the information pointed
  183. // by rb. 
  184. static inline void _JustDoIt_GetAdsPoint( ads_point& dst, struct resbuf* rb )
  185. {
  186.     // how about memcopy? nah...
  187.     if ( rb == NULL )
  188.     {
  189.         dst[ 0 ] = 0;
  190.         dst[ 1 ] = 0;
  191.         dst[ 2 ] = 0;
  192.     }
  193.     else
  194.     {
  195.         dst[ 0 ] = rb->resval.rpoint[ 0 ];
  196.         dst[ 1 ] = rb->resval.rpoint[ 1 ];
  197.         dst[ 2 ] = rb->resval.rpoint[ 2 ];
  198.     }
  199. }
  200. /******************************************************************************
  201. *                                                                             *
  202. *                         ADS_LINE member functions                           *
  203. *                                                                             *
  204. ******************************************************************************/
  205. //-----------------------------------------------------------------------------
  206. ads_point&
  207. ADS_LINE::GetPrimary( ads_point& dst ) const
  208. {
  209.     // go to the DXF_PRIM_X
  210.     struct resbuf *temp_rb = rb;
  211.  
  212.     while( temp_rb != NULL 
  213.         && DXFGroupCode( temp_rb->restype ) != DXF_PRIM_X )
  214.     {
  215.         temp_rb = temp_rb->rbnext;
  216.     }
  217.     ASSERT ( temp_rb != NULL );
  218.  
  219.     _JustDoIt_GetAdsPoint( dst, temp_rb );
  220.  
  221.     return dst;
  222. }
  223.  
  224. //-----------------------------------------------------------------------------
  225. ads_point&
  226. ADS_LINE::GetSecondary( ads_point& dst ) const
  227. {
  228.     // go to the DXF_OTHER_X
  229.     struct resbuf *temp_rb = rb;
  230.  
  231.     while( temp_rb != NULL 
  232.         && DXFGroupCode( temp_rb->restype ) != DXF_OTHER_X )
  233.     {
  234.         temp_rb = temp_rb->rbnext;
  235.     }
  236.     ASSERT ( temp_rb != NULL );
  237.  
  238.     _JustDoIt_GetAdsPoint( dst, temp_rb );
  239.  
  240.     return dst;
  241. }
  242.  
  243. /******************************************************************************
  244. *                                                                             *
  245. *                         ADS_CIRCLE member functions                           *
  246. *                                                                             *
  247. ******************************************************************************/
  248. //-----------------------------------------------------------------------------
  249. ads_point&
  250. ADS_CIRCLE::GetRadius( ads_point& dst )
  251. {
  252.     // go to the DXF_FLOAT_FACT which is the radius
  253.     struct resbuf *temp_rb = rb;
  254.  
  255.     while( temp_rb != NULL 
  256.         && DXFGroupCode( temp_rb->restype ) != DXF_FLOAT_FACT )
  257.     {
  258.         temp_rb = temp_rb->rbnext;
  259.     }
  260.     ASSERT ( temp_rb != NULL );
  261.  
  262.     _JustDoIt_GetAdsPoint( dst, temp_rb );
  263.  
  264.     return dst;
  265. }
  266.  
  267. //-----------------------------------------------------------------------------
  268. ads_point&
  269. ADS_CIRCLE::GetCenter( ads_point& dst )
  270. {
  271.     // go to the DXF_PRIM_X which is the center
  272.     struct resbuf *temp_rb = rb;
  273.  
  274.     while( temp_rb != NULL 
  275.         && DXFGroupCode( temp_rb->restype ) != DXF_PRIM_X )
  276.     {
  277.         temp_rb = temp_rb->rbnext;
  278.     }
  279.     ASSERT ( temp_rb != NULL );
  280.  
  281.     _JustDoIt_GetAdsPoint( dst, temp_rb );
  282.  
  283.     return dst;
  284. }
  285.  
  286.