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  private:
38  Internal_Pending_Tag() { m_next = 0; m_array = 0; }
39  ~Internal_Pending_Tag() { delete m_array; }
40 
41  Internal_Pending_Tag * m_next;
42  HC_KEY m_key; //m_key set to tk.m_last_keys[0], just for the purposes of matching tag requests
43  int m_variant;
44  Internal_Key_Array * m_array; //set to null unless we are associating multiple keys with a single tag call.
45 };
46 
47 
48 class Internal_Texture_List {
49  friend class HStreamFileToolkit;
50  friend class HTK_Image;
51  private:
52  Internal_Texture_List * m_next;
53  char * m_name;
54  char * m_image;
55  HC_KEY m_image_key;
56  bool m_do_write_image;
57 
58  public:
59  Internal_Texture_List (char const * name, char const * image, HC_KEY key = -1);
60  ~Internal_Texture_List();
61 };
62 
63 
65 class HBINFILETK_API HStreamFileToolkit; //forward declaration
66 
67 // special output-only pseudo-object
68 class HBINFILETK_API2 Internal_Segment_Processor : public BBaseOpcodeHandler {
69  protected:
70  char * m_name;
71  HC_KEY m_key;
72  bool m_top_level;
73  HC_KEY m_root;
74  BBaseOpcodeHandler * m_current_object;
75  BBaseOpcodeHandler * m_must_delete;
76  HC_KEY m_item_key;
77  int m_saved_count;
78  HC_KEY * m_saved_keys;
79  HC_KEY m_renumbered;
80  unsigned char m_renumbered_scope;
81  int m_priority;
82  bool m_has_priority;
83  int m_start_offset;
84  bool m_searching;
85  unsigned char m_use_polypolylines;
86  unsigned char m_polylines_already_handled;
87  bool m_geometry_attributes;
88  bool m_geometry_open;
89  BBaseOpcodeHandler * m_deferred;
90  int m_search_pass;
91  bool m_look_for_bounds;
93  void save_keys (HStreamFileToolkit & tk);
94  void restore_keys (HStreamFileToolkit & tk);
95 
96  public:
97  Internal_Segment_Processor (ID_Key key = -1, char const * name = 0);
98  ~Internal_Segment_Processor ();
99 
102  TK_Status Interpret (BStreamFileToolkit & tk, ID_Key key, int variant = 0);
103  TK_Status Interpret (BStreamFileToolkit & tk, ID_Key key, char const * special);
104  void Reset ();
106 
107  void SetRoot (HC_KEY root) { m_root = root; }
108  HC_KEY GetRoot () const { return m_root; }
109 };
110 
111 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
112 
113 #endif //HSTREAM_READONLY
114 
115 
116 
117 
118 
120 
138 class HBINFILETK_API2 HStreamFileToolkit : public BStreamFileToolkit {
139  friend class Internal_Segment_Processor;
140  friend class HTK_Open_Segment;
141  friend class HTK_Referenced_Segment;
142  friend class HTK_Reference;
143  friend class HTK_Texture;
144  friend class HTK_Image;
145  friend class HTK_Named_Style_Def;
146  friend class HTK_Delete_Object;
147  private:
148  int m_hoops_version; /* Version of Hoops we are using */
149  Internal_Segment_List * m_unnamed_segments; /* Segments which need to be renamed to unnamed when able */
150 
151  HC_KEY * m_excluded_segments; /* keys of segments (if any) to skip during write */
152  int m_excluded_count; /* size of exclusion array */
153 
154 #ifndef HSTREAM_READONLY
155  Internal_Segment_Processor * m_segment_processor; /* Handler for top segment & revisited segments */
156  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 */
157  Internal_Texture_List * m_texture_list; /* Textures being processed */
158  bool m_non_segment_revisits; /* Does the revisit list contain something other than segments? */
159  int m_revisit_offset; /* File offset of start of current revisit object (including compression if appropriate) */
160  BBaseOpcodeHandler * m_thumbnail; /* handler for a thumbnail (if any) to write */
161  int m_local_attributes; /* flag presence of geometry-level attributes (used in GenerateOne) */
162  BBaseOpcodeHandler * m_must_delete; /* pointer to any temporary handler to discard when done */
163  char * m_prepend_root; /* a string to prepend on rooted segments */
164  int m_revisit_state; /* state of progress in revisit loop */
165 
166  void * m_deferred_styles_ptr;
167  void cleanup_deferred_styles();
168  void apply_deferred_styles();
169 
170  bool issorted_revisit(Internal_Revisit_Item *array[], int count);
171  void qsort_revisit(Internal_Revisit_Item ** first, Internal_Revisit_Item ** last) { qsort_revisit (first, last, 0); }
172  void qsort_revisit(Internal_Revisit_Item **, Internal_Revisit_Item **, int);
173  TK_Status sort_revisit();
174 
175  TK_Status find_textures();
176 
177 
178  enum Revisit {
179  Nothing,
180  Working,
181  Force
182  };
183 #endif
184 
185  public:
190 
191  ~HStreamFileToolkit ();
192  // clean out current state
193 
199  void Restart ();
200 
201  // normal processing functions
202 
221  TK_Status GenerateBuffer (char * b, int s, int & f, char const * start_segment = 0);
222 
223 
237  TK_Status GenerateOneItemBuffer (char * b, int s, int & f, HC_KEY item);
238 
239 
249  unsigned POINTER_SIZED_INT CountObjects (char const * start_segment = 0);
250 
251 
252  void ActivateContext (ID_Key key);
253  void DeactivateContext (ID_Key key);
254  void NewFileContext (ID_Key key);
255 
256 
263  int GetHoopsVersion() { if (m_hoops_version == 0) validate_hoops_version(); return m_hoops_version; }
264 
271  TK_Status StringToHandler (char const *type, BBaseOpcodeHandler **handler);
272 
279  TK_Status StringToOpcode (char const *type, unsigned char *opcode_out);
280 
281 
289  void SetThumbnail (BBaseOpcodeHandler * handler);
290 
301  void SetThumbnail (int format, int width, int height, unsigned char const * data);
302 
307  TK_Status Write_Stream_File ();
308 
314  void AddExcludedSegments (int count, HC_KEY const keys[]);
319  void AddExcludedSegment (HC_KEY key) { AddExcludedSegments (1, &key); }
325  bool SegmentIsExcluded (HC_KEY key) const;
329  void ClearExcludedSegments ();
334  int GetExcludedSegmentCount () const { return m_excluded_count; }
339  HC_KEY const * GetExcludedSegments () const { return m_excluded_segments; }
340 
345  void SetPrependRootSegment(const char * segment);
350  const char * GetPrependRootSegment() { return m_prepend_root; }
351 
352 
356  bool MatchPreviousExRef () const;
357 
358  char const **m_search_strings;
359 
360  protected:
362  void validate_hoops_version();
364  void add_unnamed_segment (HC_KEY key);
366  void read_completed ();
368  void empty_lists ();
370  TK_Status tag (int variant);
372  unsigned HLONG count_segment_objects (HC_KEY key, char const * start_segment = 0);
373 
374  virtual void FileDone() {
375  apply_deferred_styles();
376  }
377 
378 };
379 
380 
381 #endif //HBINFILETK_TOOLKIT
virtual void NewFileContext(ID_Key key)
Definition: BStreamFileToolkit.h:598
The HStreamFileToolkit class provides support for exporting/importing HOOPS Stream File information f...
Definition: HStreamFileToolkit.h:138
Provides HOOPS/3dGS-specific handling of the TKE_Delete_Object opcode.
Definition: HOpcodeHandler.h:165
virtual void Reset()
The BStreamFileToolkit class provides support for importing/exporting HOOPS Stream File information...
Definition: BStreamFileToolkit.h:367
int GetExcludedSegmentCount() const
Definition: HStreamFileToolkit.h:334
virtual void Restart()
Provides HOOPS/3dGS-specific handling of the TKE_Image opcode.
Definition: HOpcodeHandler.h:1313
const char * GetPrependRootSegment()
Definition: HStreamFileToolkit.h:350
virtual TK_Status Read(BStreamFileToolkit &tk)=0
#define HC_KEY
Provides HOOPS/3dGS-specific handling of the TKE_Named_Style_Defs.
Definition: HOpcodeHandler.h:1431
virtual TK_Status Interpret(BStreamFileToolkit &tk, ID_Key key, int variant=0)
Provides HOOPS/3dGS-specific handling of the TKE_Reopen_Segment opcodes.
Definition: HOpcodeHandler.h:82
HC_KEY m_key
segment key
Definition: HOpcodeHandler.h:1433
int GetHoopsVersion()
Definition: HStreamFileToolkit.h:263
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:254
#define ID_Key
Definition: BStream.h:230
char * m_name
Definition: BOpcodeHandler.h:6642
Provides HOOPS/3dGS-specific handling of the TKE_Open_Segment opcode.
Definition: HOpcodeHandler.h:31
virtual TK_Status Clone(BStreamFileToolkit &tk, BBaseOpcodeHandler **handler) const
Definition: BOpcodeHandler.h:207
virtual void DeactivateContext(ID_Key key)
Definition: BStreamFileToolkit.h:589
HC_KEY const * GetExcludedSegments() const
Definition: HStreamFileToolkit.h:339
Provides HOOPS/3dGS-specific handling of the TKE_Texture.
Definition: HOpcodeHandler.h:1339
void AddExcludedSegment(HC_KEY key)
Definition: HStreamFileToolkit.h:319
virtual TK_Status Write(BStreamFileToolkit &tk)=0
Provides HOOPS/3dGS-specific handling of the TKE_Reference opcode.
Definition: HOpcodeHandler.h:118
virtual bool MatchPreviousExRef() const
Definition: BStreamFileToolkit.h:1205
virtual void ActivateContext(ID_Key key)
Definition: BStreamFileToolkit.h:582