HStreamFileToolkit.h
1 // Copyright (c) Tech Soft 3D, Inc.
2 //
3 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc.,
4 // and considered a trade secret as defined under civil and criminal statutes.
5 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of
6 // unauthorized use or misappropriation of its trade secrets. Use of this information
7 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under
8 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use.
9 
10 #ifndef HBINFILETK_TOOLKIT
11 #define HBINFILETK_TOOLKIT
12 
13 
14 #ifndef HSTREAM_READONLY
15 
16 #ifndef DOXYGEN_SHOULD_SKIP_THIS
17 
18 class Internal_Key_Array {
19  friend class HStreamFileToolkit;
20  friend class Internal_Pending_Tag;
21  friend class Internal_Segment_Processor;
22  private:
23  Internal_Key_Array() { m_data = 0; }
24  ~Internal_Key_Array() { delete [] m_data; }
25 
26  int m_count;
27  HC_KEY *m_data;
28 };
29 
30 class Internal_Pending_Tag {
31  friend class HStreamFileToolkit;
32  friend class Internal_Segment_Processor;
33  friend class HTK_Referenced_Segment;
34  friend class HTK_Reference;
35  friend class HTK_Texture;
36  friend class HTK_Named_Style_Def;
37  friend class HTK_Custom_Shader_Definition;
38  friend class HTK_Custom_Shader_Texture;
39  friend class HTK_Custom_Shader_Sampler;
40  private:
41  Internal_Pending_Tag() { m_next = 0; m_array = 0; }
42  ~Internal_Pending_Tag() { delete m_array; }
43 
44  Internal_Pending_Tag * m_next;
45  HC_KEY m_key; //m_key set to tk.m_last_keys[0], just for the purposes of matching tag requests
46  int m_variant;
47  Internal_Key_Array * m_array; //set to null unless we are associating multiple keys with a single tag call.
48 };
49 
50 
51 class Internal_Texture_List {
52  friend class HStreamFileToolkit;
53  friend class HTK_Image;
54  private:
55  Internal_Texture_List * m_next;
56  char * m_name;
57  char * m_image;
58  HC_KEY m_image_key;
59  bool m_do_write_image;
60 
61  public:
62  Internal_Texture_List (char const * name, char const * image, HC_KEY key = -1);
63  ~Internal_Texture_List();
64 };
65 
66 
68 class HBINFILETK_API HStreamFileToolkit; //forward declaration
69 
70 // special output-only pseudo-object
71 class HBINFILETK_API2 Internal_Segment_Processor : public BBaseOpcodeHandler {
72  protected:
73  char * m_name;
74  HC_KEY m_key;
75  bool m_top_level;
76  HC_KEY m_root;
77  BBaseOpcodeHandler * m_current_object;
78  BBaseOpcodeHandler * m_must_delete;
79  HC_KEY m_item_key;
80  int m_saved_count;
81  HC_KEY * m_saved_keys;
82  HC_KEY m_renumbered;
83  unsigned char m_renumbered_scope;
84  int m_priority;
85  bool m_has_priority;
86  int m_start_offset;
87  bool m_searching;
88  unsigned char m_use_polypolylines;
89  unsigned char m_polylines_already_handled;
90  bool m_geometry_attributes;
91  bool m_geometry_open;
92  BBaseOpcodeHandler * m_deferred;
93  int m_search_pass;
94  bool m_look_for_bounds;
96  void save_keys (HStreamFileToolkit & tk);
97  void restore_keys (HStreamFileToolkit & tk);
98 
99  public:
100  Internal_Segment_Processor (ID_Key key = -1, char const * name = 0);
101  ~Internal_Segment_Processor ();
102 
105  TK_Status Interpret (BStreamFileToolkit & tk, ID_Key key, int variant = 0);
106  TK_Status Interpret (BStreamFileToolkit & tk, ID_Key key, char const * special);
107  void Reset ();
109 
110  void SetRoot (HC_KEY root) { m_root = root; }
111  HC_KEY GetRoot () const { return m_root; }
112 };
113 
114 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
115 
116 #endif //HSTREAM_READONLY
117 
118 
119 
120 
121 
123 
141 class HBINFILETK_API2 HStreamFileToolkit : public BStreamFileToolkit {
142  friend class Internal_Segment_Processor;
143  friend class HTK_Open_Segment;
144  friend class HTK_Referenced_Segment;
145  friend class HTK_Reference;
146  friend class HTK_Texture;
147  friend class HTK_Image;
148  friend class HTK_Named_Style_Def;
149  friend class HTK_Delete_Object;
150  friend class HTK_Custom_Shader_Definition;
151  friend class HTK_Custom_Shader_Texture;
152  friend class HTK_Custom_Shader_Sampler;
153  private:
154  int m_hoops_version; /* Version of Hoops we are using */
155  Internal_Segment_List * m_unnamed_segments; /* Segments which need to be renamed to unnamed when able */
156 
157  HC_KEY * m_excluded_segments; /* keys of segments (if any) to skip during write */
158  int m_excluded_count; /* size of exclusion array */
159 
160 #ifndef HSTREAM_READONLY
161  Internal_Segment_Processor * m_segment_processor; /* Handler for top segment & revisited segments */
162  Internal_Pending_Tag * m_pending_tags; /* List of items to have tags attached. Tags should come absolutely last (even after user data), so tagging postponed to the end. It is a list to allow for recursion if we ever need it */
163  Internal_Texture_List * m_texture_list; /* Textures being processed */
164  bool m_non_segment_revisits; /* Does the revisit list contain something other than segments? */
165  int m_revisit_offset; /* File offset of start of current revisit object (including compression if appropriate) */
166  BBaseOpcodeHandler * m_thumbnail; /* handler for a thumbnail (if any) to write */
167  int m_local_attributes; /* flag presence of geometry-level attributes (used in GenerateOne) */
168  BBaseOpcodeHandler * m_must_delete; /* pointer to any temporary handler to discard when done */
169  char * m_prepend_root; /* a string to prepend on rooted segments */
170  int m_revisit_state; /* state of progress in revisit loop */
171 
172  int m_attribute_precision_mode;
173  int m_geometry_precision_mode;
174  int m_double_added;
175 
176  void * m_deferred_styles_ptr;
177  void cleanup_deferred_styles();
178  void apply_deferred_styles();
179 
180  bool issorted_revisit(Internal_Revisit_Item *array[], int count);
181  void qsort_revisit(Internal_Revisit_Item ** first, Internal_Revisit_Item ** last) { qsort_revisit (first, last, 0); }
182  void qsort_revisit(Internal_Revisit_Item **, Internal_Revisit_Item **, int);
183  TK_Status sort_revisit();
184 
185  TK_Status find_textures();
186 
187  TK_Status write_custom_shader_definition(BStreamFileToolkit& tk);
188 
189  enum Revisit {
190  Nothing,
191  Working,
192  Force
193  };
194 #endif
195 
196  public:
201 
202  ~HStreamFileToolkit ();
203  // clean out current state
204 
210  void Restart ();
211 
212  // normal processing functions
213 
232  TK_Status GenerateBuffer (char * b, int s, int & f, char const * start_segment = 0);
233 
234 
248  TK_Status GenerateOneItemBuffer (char * b, int s, int & f, HC_KEY item);
249 
250 
260  unsigned POINTER_SIZED_INT CountObjects (char const * start_segment = 0);
261 
262 
263  void ActivateContext (ID_Key key);
264  void DeactivateContext (ID_Key key);
265  void NewFileContext (ID_Key key);
266 
267 
274  int GetHoopsVersion() { if (m_hoops_version == 0) validate_hoops_version(); return m_hoops_version; }
275 
282  TK_Status StringToHandler (char const *type, BBaseOpcodeHandler **handler);
283 
290  TK_Status StringToOpcode (char const *type, unsigned char *opcode_out);
291 
292 
300  void SetThumbnail (BBaseOpcodeHandler * handler);
301 
312  void SetThumbnail (int format, int width, int height, unsigned char const * data);
313 
318  TK_Status Write_Stream_File ();
319 
325  void AddExcludedSegments (int count, HC_KEY const keys[]);
330  void AddExcludedSegment (HC_KEY key) { AddExcludedSegments (1, &key); }
336  bool SegmentIsExcluded (HC_KEY key) const;
340  void ClearExcludedSegments ();
345  int GetExcludedSegmentCount () const { return m_excluded_count; }
350  HC_KEY const * GetExcludedSegments () const { return m_excluded_segments; }
351 
356  void SetPrependRootSegment(const char * segment);
361  const char * GetPrependRootSegment() { return m_prepend_root; }
362 
363 
367  bool MatchPreviousExRef () const;
368 
369  char const **m_search_strings;
370 
371 
372  enum DoubleMode {
377  FORCE_DOUBLE
378  };
379 
380  enum DoubleAdded {
381  ATTRIBUTES = 0x01,
382  GEOMETRY = 0x02
383  };
384 
385 
390  void SetAttributePrecisionMode(int mode) { m_attribute_precision_mode = mode; }
395  int GetAttributePrecisionMode() { return m_attribute_precision_mode; }
396  // /*!
397  // Sets the manner in which double-precision geometries are handled
398  // \param mode handling mode
399  // */
400  // void SetGeometryPrecisionMode(int mode) { m_geometry_precision_mode = mode; }
401  // /*!
402  // Returns the chosen the manner in which double-precision geometries are handled
403  // \return double-precision handling mode
404  // */
405  // int GetGeometryPrecisionMode() { return m_geometry_precision_mode; }
406 
410  int GetAddedDoubleTypes() const { return m_double_added; }
411 
412 
413 
415  void AddDoubleType(int type) { m_double_added |= type; }
416 
417 
418  protected:
420  void validate_hoops_version();
422  void add_unnamed_segment (HC_KEY key);
424  void read_completed ();
426  void empty_lists ();
428  TK_Status tag (int variant);
430  unsigned HLONG count_segment_objects (HC_KEY key, char const * start_segment = 0);
432  unsigned HLONG count_custom_shader_objects ();
433 
434  virtual void FileDone() {
435  apply_deferred_styles();
436  }
437 
438 };
439 
440 
441 #endif //HBINFILETK_TOOLKIT
virtual void NewFileContext(ID_Key key)
Definition: BStreamFileToolkit.h:599
The HStreamFileToolkit class provides support for exporting/importing HOOPS Stream File information f...
Definition: HStreamFileToolkit.h:141
Provides HOOPS/3dGS-specific handling of the TKE_Delete_Object opcode.
Definition: HOpcodeHandler.h:187
virtual void Reset()
The BStreamFileToolkit class provides support for importing/exporting HOOPS Stream File information...
Definition: BStreamFileToolkit.h:367
data is kept in the format from the file
Definition: HStreamFileToolkit.h:374
Provides HOOPS/3dGS-specific handling of the TKE_Custom_Shader_Definition.
Definition: HOpcodeHandler.h:1484
virtual void Restart()
int GetExcludedSegmentCount() const
Definition: HStreamFileToolkit.h:345
Provides HOOPS/3dGS-specific handling of the TKE_Image opcode.
Definition: HOpcodeHandler.h:1375
const char * GetPrependRootSegment()
Definition: HStreamFileToolkit.h:361
virtual TK_Status Read(BStreamFileToolkit &tk)=0
Provides HOOPS/3dGS-specific handling of the TKE_Named_Style_Defs.
Definition: HOpcodeHandler.h:1680
virtual TK_Status Interpret(BStreamFileToolkit &tk, ID_Key key, int variant=0)
int GetAddedDoubleTypes() const
Definition: HStreamFileToolkit.h:410
Provides HOOPS/3dGS-specific handling of the TKE_Reopen_Segment opcodes.
Definition: HOpcodeHandler.h:104
virtual bool MatchPreviousExRef() const
Definition: BStreamFileToolkit.h:1206
int GetHoopsVersion()
Definition: HStreamFileToolkit.h:274
HC_KEY const * GetExcludedSegments() const
Definition: HStreamFileToolkit.h:350
data is forced to single-precision
Definition: HStreamFileToolkit.h:376
Provides HOOPS/3dGS-specific handling of the TKE_Custom_Shader_Sampler.
Definition: HOpcodeHandler.h:1546
handling choice is left to the importer
Definition: HStreamFileToolkit.h:373
void SetAttributePrecisionMode(int mode)
Definition: HStreamFileToolkit.h:390
virtual TK_Status Clone(BStreamFileToolkit &tk, BBaseOpcodeHandler **handler) const
Definition: BOpcodeHandler.h:216
The BBaseOpcodeHandler abstract class is used as a base for derived classes which manage logical piec...
Definition: BOpcodeHandler.h:55
TK_Status
Codes which can be either passed to various toolkit functions, or indicate the result of a toolkit fu...
Definition: BStream.h:278
#define ID_Key
Definition: BStream.h:254
data is converted to float if it appears safe, otherwise it is retained as double ...
Definition: HStreamFileToolkit.h:375
int GetAttributePrecisionMode()
Definition: HStreamFileToolkit.h:395
char * m_name
Definition: BOpcodeHandler.h:7099
Provides HOOPS/3dGS-specific handling of the TKE_Open_Segment opcode.
Definition: HOpcodeHandler.h:53
Provides HOOPS/3dGS-specific handling of the TKE_Custom_Shader_Texture.
Definition: HOpcodeHandler.h:1518
virtual void DeactivateContext(ID_Key key)
Definition: BStreamFileToolkit.h:590
Provides HOOPS/3dGS-specific handling of the TKE_Texture.
Definition: HOpcodeHandler.h:1401
void AddExcludedSegment(HC_KEY key)
Definition: HStreamFileToolkit.h:330
virtual TK_Status Write(BStreamFileToolkit &tk)=0
DoubleMode
Definition: HStreamFileToolkit.h:372
void AddDoubleType(int type)
internal use
Definition: HStreamFileToolkit.h:415
Provides HOOPS/3dGS-specific handling of the TKE_Reference opcode.
Definition: HOpcodeHandler.h:140
virtual void ActivateContext(ID_Key key)
Definition: BStreamFileToolkit.h:583