hasfiletoolkit.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. //
  2. // Copyright (c) 2000 by Tech Soft 3D, LLC.
  3. // The information contained herein is confidential and proprietary to
  4. // Tech Soft 3D, LLC., and considered a trade secret as defined under
  5. // civil and criminal statutes. Tech Soft 3D shall pursue its civil
  6. // and criminal remedies in the event of unauthorized use or misappropriation
  7. // of its trade secrets. Use of this information by anyone other than
  8. // authorized employees of Tech Soft 3D, LLC. is granted only under a
  9. // written non-disclosure agreement, expressly prescribing the scope and
  10. // manner of such use.
  11. //
  12. // $Header: /files/homes/master/cvs/hoops_master/hoops_appwizard/VCWizards/HOOPSAppWiz_NET2008/Templates/1033/3daf/HMSFileToolkit.h,v 1.1 2008-04-16 23:14:27 stage Exp $
  13. //
  14. #ifndef _HMSFILETOOLKIT_H_
  15. #define _HMSFILETOOLKIT_H_
  16. #include "afxtempl.h"
  17. #include "HStream.h"
  18. #include "HOpcodeShell.h"
  19. #include "HPolyPoly.h"
  20. class HBaseModel;
  21. //! The CModellerObject class is used to store and manage information about an solid modeler object
  22. /*!
  23. Assuming a BRep model, this class stores the information about it's (body, face, edge etc.) and also about
  24. its parents and childern. This class is expected to be used as a base class for different type of modeller
  25. objects your geometry kernel may have.
  26. */
  27. class CModellerObject
  28. {
  29. public:
  30. HC_KEY *m_keys; /*!< Array of HOOPS keys associated with this modeller object */
  31. int m_numchildren; /*!< Number of children this object has */
  32. long *m_children; /*!< Array of ids of children of this object */
  33. long *m_parents; /*!< Array of ids of parents of this object */
  34. int m_identifier; /*!< Solid modeler identifier (tag/pointer) of this object */
  35. /*! Constructs CModellerObject object */
  36. CModellerObject() { m_keys = 0; m_numchildren=0; m_children = 0; m_parents = 0; m_identifier = 0; }
  37. /*! Destroys the CModeller object and frees up memory associated with it */
  38. ~CModellerObject()
  39. {
  40. delete [] m_keys;
  41. delete [] m_children;
  42. delete [] m_parents;
  43. }
  44. /*! Returns the class of the object (body/face/edge). Should be overridden by the derived class */
  45. virtual int AskClass() { return 0; }
  46. /*! Returns the number of keys associated with this model. Should be overridden */
  47. virtual long GetKeyNum() {
  48. if (!m_keys)
  49. return 0;
  50. else
  51. return 1;
  52. }
  53. /*! Associates the given key with the modeller object. It erases any previously associated keys */
  54. virtual void SetKey(HC_KEY key)
  55. {
  56. if (m_keys!=0)
  57. delete m_keys;
  58. if (key!=0)
  59. {
  60. m_keys = new HC_KEY;
  61. m_keys[0] = key;
  62. }
  63. }
  64. /*! Associates the given id as a parent of this modeller object. It erases any previously associated parent */
  65. virtual void SetParent(long parent)
  66. {
  67. if (m_parents!=0)
  68. delete m_parents;
  69. m_parents = new long;
  70. m_parents[0] = parent;
  71. }
  72. /*! Sets the children count and allocated memory to store the ids. It erases any previously associated children */
  73. void SetChildNum(int numchildren)
  74. {
  75. m_numchildren = numchildren;
  76. if (m_children)
  77. delete [] m_children;
  78. m_children = new long[numchildren];
  79. }
  80. };
  81. //! The CBaseModellerObject class is used to store and manage information about an solid modeler object
  82. /*!
  83. This class can be use to extend the base class and create a more specific modeller object (e.g. BRep object).
  84. Currently, there it is not utilised in that way.
  85. */
  86. class CBaseModellerObject : public CModellerObject
  87. {
  88. public:
  89. /*! Constructor */
  90. CBaseModellerObject() : CModellerObject() {}
  91. /*! Returns the class of the object (body/face/edge). Should be overridden by the derived class */
  92. virtual int AskClass() { return 0; }
  93. };
  94. //! The CBodyModellerObject class represents a BODY type of solid modeller object
  95. /*!
  96. The CBodyModellerObject class represents a BODY type of solid modeller object
  97. */
  98. class CBodyModellerObject : public CModellerObject
  99. {
  100. public:
  101. /*! Constructor */
  102. CBodyModellerObject() : CModellerObject() {}
  103. /*! Returns the class of the object - which in this case is BODY */
  104. virtual int AskClass() { return BODY_TYPE; }
  105. };
  106. //! The CFaceModellerObject class represents a FACE type of solid modeller object
  107. /*!
  108. The CFaceModellerObject class represents a FACE type of solid modeller object
  109. */
  110. class CFaceModellerObject : public CModellerObject
  111. {
  112. public:
  113. /*! Constructor */
  114. CFaceModellerObject() : CModellerObject() {}
  115. /*! Returns the class of the object - which in this case is FACE */
  116. virtual int AskClass() { return FACE_TYPE; }
  117. };
  118. //! The CEdgeModellerObject class represents a EDGE type of solid modeller object
  119. /*!
  120. The CEdgeModellerObject class represents a EDGE type of solid modeller object
  121. */
  122. class CEdgeModellerObject : public CModellerObject
  123. {
  124. public:
  125. int m_numkeys; /*!< Number of keys associated with this object */
  126. int m_numparents; /*!< Number of parents associated with this object */
  127. /*! Constructor */
  128. CEdgeModellerObject() : CModellerObject() {m_numparents=0;}
  129. /*! Returns the class of the object - which in this case is EDGE */
  130. virtual int AskClass() { return EDGE_TYPE; }
  131. /*! Associates a key to the object. The key is inserted in the list at the given position */
  132. void SetKey(int pos, int key)
  133. {
  134. m_keys[pos] = key;
  135. }
  136. /*! Sets the associated keys count and allocated memory to store the ids. It erases any previously associated keys */
  137. void SetKeyNum(int numkeys)
  138. {
  139. if (m_keys!=0)
  140. delete m_keys;
  141. m_keys = new HC_KEY[numkeys];
  142. m_numkeys = numkeys;
  143. }
  144. /*! Adds the given id to the parents array of the object. The parent is ignored if the object has already more
  145. than one parent associated
  146. */
  147. void AddParent(int parent)
  148. {
  149. if (m_numparents == 0)
  150. {
  151. delete m_parents;
  152. m_parents = new long[2];
  153. }
  154. if (m_numparents<2)
  155. m_parents[m_numparents++] = parent;
  156. }
  157. /*! Returns the number of keys associated */
  158. long GetKeyNum() { return m_numkeys; }
  159. };
  160. //! The CModellerInfo class manages the associativity information
  161. /*!
  162. The CModellerInfo uses a hash map to store the associativity information between the solid modeller and HOOPS
  163. */
  164. class CModellerInfo
  165. {
  166. public:
  167. int m_objectnum; /*!< Number of objects */
  168. bool m_bIsValid; /*!< Is the object valid for use */
  169. CModellerObject **m_objects; /*!< Solid modeler object information */
  170. CMap <long,long&,long,long&> m_map; /*!< Hash map storing the associativity information */
  171. bool m_bTesselatedFaces; /*!< true if the body is tessleated at face level */
  172. bool m_bPSF; /*!< true if the modeler file is embedded into the hsf file */
  173. /*! Constructor */
  174. CModellerInfo()
  175. {
  176. m_objects=0;
  177. m_objectnum = 0;
  178. m_map.InitHashTable(1201);
  179. m_bIsValid = false;
  180. m_bTesselatedFaces = false;
  181. m_bPSF = false;
  182. }
  183. /*! Destroys the CModellerInfo object and frees up memory associated with it */
  184. ~CModellerInfo()
  185. {
  186. if( m_objects )
  187. {
  188. for (int i=0;i<m_objectnum;i++)
  189. delete m_objects[i];
  190. delete [] m_objects;
  191. }
  192. }
  193. /*! Initializes the CModellerInfo. Allocates memory to store information about given number of objects */
  194. bool Init(int number_of_objects)
  195. {
  196. if (m_objects!=0)
  197. delete [] m_objects;
  198. m_objects = new CModellerObject *[number_of_objects];
  199. for (int i=0;i<number_of_objects;i++)
  200. m_objects[i]=0;
  201. m_objectnum = number_of_objects;
  202. return 1;
  203. }
  204. /*! Returns the number of bodies and their ids this modeller info has stored */
  205. bool ask_bodies(int * const nbodies, long** const body_indices);
  206. /*! Returns the number of faces and their ids for the given body */
  207. bool BODY_ask_faces(long body_index, int * const nfaces, long** const face_indices);
  208. /*! Returns the number of edges and their ids for the given face */
  209. bool FACE_ask_edges(long face_index, int * const nedges, long** const edge_indices);
  210. /*! Returns the number of owner faces and their ids for the given edge */
  211. bool EDGE_ask_faces(long edge_index, int * const nfaces, long** const face_indices);
  212. /*! Returns the id of the owner body for the given face */
  213. bool FACE_ask_body(long face_index, long* const body_index);
  214. /*! Returns the type (body, face, edge) for the given entity */
  215. bool ENTITY_ask_class(long entity_index, int & eclass);
  216. /*! Returns the id of the given entity */
  217. bool ENTITY_ask_identifier(long entity_index, int *ident);
  218. /*! Adds the modeler object information at the given position */
  219. void SetModellerObject (int pos, CModellerObject * object);
  220. /*! Returns the modeller object at the given position */
  221. CModellerObject * GetModellerObject (int pos);
  222. /*! Returns the id of the given HOOPS key */
  223. long Compute_Entity_Index(HC_KEY key, int eclass);
  224. /*! Returns the HOOPS keys for the given modeler object */
  225. long Compute_Geometry_Keys(long index, long max_count, HC_KEY* keys);
  226. };
  227. //! The TK_PSLine is a custom object handler
  228. /*!
  229. This class helps to tag the line objects which are not tagged by the HOOPS StreamToolkit by default.
  230. */
  231. class TK_PSLine : public HTK_Line {
  232. private:
  233. int m_mystage;
  234. public:
  235. TK_PSLine() : HTK_Line() { m_mystage = 0; }
  236. TK_Status Write (BStreamFileToolkit & tk) alter;
  237. };
  238. //! The TK_PSPolypoint is a custom object handler
  239. /*!
  240. This class helps to tag the TK_PSPolypoint objects which are not tagged by the HOOPS StreamToolkit by default.
  241. */
  242. class TK_PSPolypoint : public HTK_Polypoint {
  243. private:
  244. int m_mystage;
  245. public:
  246. TK_PSPolypoint(unsigned char opcode) : HTK_Polypoint(opcode) { m_mystage = 0; }
  247. TK_Status Write (BStreamFileToolkit & tk) alter;
  248. };
  249. //! The TK_PSPolyPolypoint is a custom object handler
  250. /*!
  251. This class helps to tag the TK_PSPolyPolypoint objects which are not tagged by the HOOPS StreamToolkit by default.
  252. */
  253. class TK_PSPolyPolypoint : public HTK_PolyPolypoint {
  254. private:
  255. int m_mystage;
  256. public:
  257. TK_PSPolyPolypoint(unsigned char opcode) : HTK_PolyPolypoint(opcode) { m_mystage = 0; }
  258. TK_Status Write (BStreamFileToolkit & tk) alter;
  259. };
  260. //! The TK_PSEllipse is a custom object handler
  261. /*!
  262. This class helps to tag the TK_PSEllipse objects which are not tagged by the HOOPS StreamToolkit by default.
  263. */
  264. class TK_PSEllipse : public HTK_Ellipse {
  265. private:
  266. int m_mystage;
  267. public:
  268. TK_PSEllipse(unsigned char opcode) : HTK_Ellipse(opcode) { m_mystage = 0; }
  269. TK_Status Write (BStreamFileToolkit & tk) alter;
  270. };
  271. //! The TK_PSCircle is a custom object handler
  272. /*!
  273. This class helps to tag the TK_PSCircle objects which are not tagged by the HOOPS StreamToolkit by default.
  274. */
  275. class TK_PSCircle : public HTK_Circle {
  276. private:
  277. int m_mystage;
  278. public:
  279. TK_PSCircle(unsigned char opcode) : HTK_Circle(opcode) { m_mystage = 0; }
  280. TK_Status Write (BStreamFileToolkit & tk) alter;
  281. };
  282. //! The TK_PSClose_Segment is a custom object handler
  283. /*!
  284. This class helps to tag the TK_PSClose_Segment objects which are not tagged by the HOOPS StreamToolkit by default.
  285. */
  286. class TK_PSClose_Segment : public HTK_Close_Segment {
  287. private:
  288. int m_mystage;
  289. public:
  290. TK_PSClose_Segment() : HTK_Close_Segment() { m_mystage = 0; }
  291. TK_Status Write(BStreamFileToolkit &tk);
  292. };
  293. //! The TK_PSUser_Data is a custom object handler
  294. /*!
  295. This is the main class which handler storing and restoring of solid modeler information in an hsf file as a user data.
  296. */
  297. class TK_PSUser_Data : public TK_User_Data {
  298. private:
  299. int m_pos; /*!< Variable which keeps track of current position in the data */
  300. CModellerInfo *m_mi; /*!< Solid modeler objects information */
  301. int m_mystage; /*!< Internal variable to track the current stage in reading/writing */
  302. CString m_psf_tempfilename; /*!< Filename of temporary solid modeler file */
  303. long m_psf_filesize; /*!< Size of solid modeler file */
  304. FILE *m_psf_filehandle; /*!< File handle of solid modeler file */
  305. char *m_psf_file_buff; /*!< Buffer to read solid modeler file into */
  306. int m_psf_buff_count; /*!< Size of the buffer */
  307. ENTITY_LIST& m_entityList; /*!< List of ACIS entities to be embedded as .sat file */
  308. public:
  309. /*!
  310. Constructor
  311. \param mi Solid modeler information
  312. \param ENTITY_LIST ACIS entitylist to export/receive ACIS entities
  313. \param psf Is the solid modeler file embedded
  314. */
  315. TK_PSUser_Data (CModellerInfo **mi, ENTITY_LIST& ent_list, bool psf = false);
  316. /*! Physically reads the topology information and the modeler file (if m_bPSF is true).
  317. The topology information is read into the member (m_data).
  318. The modeler file may be too large to hold into the memory, hence
  319. it is read and stored as a temporary disk file.
  320. */
  321. TK_Status Read (BStreamFileToolkit & tk) alter;
  322. /*! Converts the raw topology information into CModellerInfo.
  323. Calls geometry kernel api to read the solid modeler file (by calling ExecutePS function)
  324. Restores the associativity information by converting the streamtoolkit indices to actual HOOPS keys.
  325. */
  326. TK_Status Execute (BStreamFileToolkit & tk) alter;
  327. /*! Generates and topology information from the solid modeler entities the kernel apis.
  328. */
  329. TK_Status Interpret (BStreamFileToolkit & tk, long key, int lod=0) alter;
  330. /*! Physically writes the topology information and the modeler file (if m_bPSF is true).
  331. The modeler file may be too large to hold into the memory, hence
  332. it is written to a temporary disk file (by calling InterpretPS).
  333. Note: Special code is required to handle large modeler files since they can't be read all
  334. at once into a memory buffer and provided to the streamtoolkit.
  335. */
  336. TK_Status Write (BStreamFileToolkit & tk) alter;
  337. /*! Creates a temporary physical solid modeler file from the entity list which is later
  338. embedded into the stream file.
  339. */
  340. TK_Status InterpretPS(BStreamFileToolkit & tk, long key = -1, int lod=0) alter;
  341. /*! Uses geometry kernel api to read the solid modeler file which was embedded in the modeler
  342. stream file.
  343. */
  344. TK_Status ExecutePS(BStreamFileToolkit & tk);
  345. /*! Accumulates the data in the member variable */
  346. void putdata(void *data, int size);
  347. /*! returns the data (long) at the current position */
  348. void getdata(long &data);
  349. /*! returns the data (char) at the current position */
  350. void getdata(char &data);
  351. /*! Returns the given amount (len) of data into the variable (data) */
  352. void getdata(void *data,int len);
  353. void Reset();
  354. };
  355. // Add an identifier to hsf files written out by modeler based partviewer as a comment.
  356. // This will help us distinguish files which have our TK_User_Data from other applications.
  357. #define FILE_COMMENT_ID "Exported by TSA Partviewer"
  358. class TK_PSComment : public TK_Comment
  359. {
  360. private:
  361. int m_mystage;
  362. HBaseModel * m_pHModel;
  363. public:
  364. /*! Constructor */
  365. TK_PSComment(HBaseModel * pHModel) : TK_Comment()
  366. {
  367. m_mystage = 0;
  368. m_pHModel = pHModel;
  369. }
  370. /*! Inserts a comment into the file so that it can be identified as a modeler stream file while reading
  371. */
  372. TK_Status Write(BStreamFileToolkit &tk)
  373. {
  374. // stamp our id
  375. SetComment(FILE_COMMENT_ID);
  376. return TK_Comment::Write(tk);
  377. };
  378. /*! Checks if the comment in the file contains FILE_COMMENT_ID string.
  379. If it does, it means this is modeler stream file and sets the custom user data (TK_PSUser_Data)
  380. opcode handler to handle it.
  381. This is required during the reading of modeler stream file.
  382. */
  383. TK_Status Execute (BStreamFileToolkit & tk);
  384. // need to have this overridden for prewalk handlers.
  385. TK_Status Interpret (BStreamFileToolkit & tk, ID_Key key, int variant = 0) alter{ return TK_Normal; };
  386. };
  387. #endif //_HMSFILETOOLKIT_H_