00001 // Copyright (c) 1998-2014 by Tech Soft 3D, Inc. 00002 // 00003 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., 00004 // and considered a trade secret as defined under civil and criminal statutes. 00005 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of 00006 // unauthorized use or misappropriation of its trade secrets. Use of this information 00007 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under 00008 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use. 00009 00010 #ifndef HBINFILETK_TOOLKIT 00011 #define HBINFILETK_TOOLKIT 00012 00013 00014 #ifndef HSTREAM_READONLY 00015 00016 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00017 00018 class Internal_Key_Array { 00019 friend class HStreamFileToolkit; 00020 friend class Internal_Pending_Tag; 00021 friend class Internal_Segment_Processor; 00022 private: 00023 Internal_Key_Array() { m_data = 0; } 00024 ~Internal_Key_Array() { delete [] m_data; } 00025 00026 int m_count; 00027 HC_KEY *m_data; 00028 }; 00029 00030 class Internal_Pending_Tag { 00031 friend class HStreamFileToolkit; 00032 friend class Internal_Segment_Processor; 00033 friend class HTK_Referenced_Segment; 00034 friend class HTK_Reference; 00035 friend class HTK_Texture; 00036 friend class HTK_Named_Style_Def; 00037 private: 00038 Internal_Pending_Tag() { m_next = 0; m_array = 0; } 00039 ~Internal_Pending_Tag() { delete m_array; } 00040 00041 Internal_Pending_Tag * m_next; 00042 HC_KEY m_key; //m_key set to tk.m_last_keys[0], just for the purposes of matching tag requests 00043 int m_variant; 00044 Internal_Key_Array * m_array; //set to null unless we are associating multiple keys with a single tag call. 00045 }; 00046 00047 00048 class Internal_Texture_List { 00049 friend class HStreamFileToolkit; 00050 friend class HTK_Image; 00051 private: 00052 Internal_Texture_List * m_next; 00053 char * m_name; 00054 char * m_image; 00055 HC_KEY m_image_key; 00056 bool m_do_write_image; 00057 00058 public: 00059 Internal_Texture_List (char const * name, char const * image, HC_KEY key = -1); 00060 ~Internal_Texture_List(); 00061 }; 00062 00063 00065 class HBINFILETK_API HStreamFileToolkit; //forward declaration 00066 00067 // special output-only pseudo-object 00068 class HBINFILETK_API2 Internal_Segment_Processor : public BBaseOpcodeHandler { 00069 protected: 00070 char * m_name; 00071 HC_KEY m_key; 00072 bool m_top_level; 00073 HC_KEY m_root; 00074 BBaseOpcodeHandler * m_current_object; 00075 BBaseOpcodeHandler * m_must_delete; 00076 HC_KEY m_item_key; 00077 int m_saved_count; 00078 HC_KEY * m_saved_keys; 00079 HC_KEY m_renumbered; 00080 unsigned char m_renumbered_scope; 00081 int m_priority; 00082 bool m_has_priority; 00083 int m_start_offset; 00084 bool m_searching; 00085 unsigned char m_use_polypolylines; 00086 unsigned char m_polylines_already_handled; 00087 bool m_geometry_attributes; 00088 bool m_geometry_open; 00089 BBaseOpcodeHandler * m_deferred; 00090 int m_search_pass; 00091 bool m_look_for_bounds; 00093 void save_keys (HStreamFileToolkit & tk); 00094 void restore_keys (HStreamFileToolkit & tk); 00095 00096 public: 00097 Internal_Segment_Processor (ID_Key key = -1, char const * name = 0); 00098 ~Internal_Segment_Processor (); 00099 00100 TK_Status Read (BStreamFileToolkit & tk); 00101 TK_Status Write (BStreamFileToolkit & tk); 00102 TK_Status Interpret (BStreamFileToolkit & tk, ID_Key key, int variant = 0); 00103 TK_Status Interpret (BStreamFileToolkit & tk, ID_Key key, char const * special); 00104 void Reset (); 00105 TK_Status Clone (BStreamFileToolkit & tk, BBaseOpcodeHandler **) const; 00106 00107 void SetRoot (HC_KEY root) { m_root = root; } 00108 HC_KEY GetRoot () const { return m_root; } 00109 }; 00110 00111 #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 00112 00113 #endif //HSTREAM_READONLY 00114 00115 00116 00117 00118 00120 00138 class HBINFILETK_API2 HStreamFileToolkit : public BStreamFileToolkit { 00139 friend class Internal_Segment_Processor; 00140 friend class HTK_Open_Segment; 00141 friend class HTK_Referenced_Segment; 00142 friend class HTK_Reference; 00143 friend class HTK_Texture; 00144 friend class HTK_Image; 00145 friend class HTK_Named_Style_Def; 00146 friend class HTK_Delete_Object; 00147 private: 00148 int m_hoops_version; /* Version of Hoops we are using */ 00149 Internal_Segment_List * m_unnamed_segments; /* Segments which need to be renamed to unnamed when able */ 00150 00151 HC_KEY * m_excluded_segments; /* keys of segments (if any) to skip during write */ 00152 int m_excluded_count; /* size of exclusion array */ 00153 00154 #ifndef HSTREAM_READONLY 00155 Internal_Segment_Processor * m_segment_processor; /* Handler for top segment & revisited segments */ 00156 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 */ 00157 Internal_Texture_List * m_texture_list; /* Textures being processed */ 00158 bool m_non_segment_revisits; /* Does the revisit list contain something other than segments? */ 00159 int m_revisit_offset; /* File offset of start of current revisit object (including compression if appropriate) */ 00160 BBaseOpcodeHandler * m_thumbnail; /* handler for a thumbnail (if any) to write */ 00161 int m_local_attributes; /* flag presence of geometry-level attributes (used in GenerateOne) */ 00162 BBaseOpcodeHandler * m_must_delete; /* pointer to any temporary handler to discard when done */ 00163 char * m_prepend_root; /* a string to prepend on rooted segments */ 00164 int m_revisit_state; /* state of progress in revisit loop */ 00165 00166 void * m_deferred_styles_ptr; 00167 void cleanup_deferred_styles(); 00168 void apply_deferred_styles(); 00169 00170 bool issorted_revisit(Internal_Revisit_Item *array[], int count); 00171 void qsort_revisit(Internal_Revisit_Item ** first, Internal_Revisit_Item ** last) { qsort_revisit (first, last, 0); } 00172 void qsort_revisit(Internal_Revisit_Item **, Internal_Revisit_Item **, int); 00173 TK_Status sort_revisit(); 00174 00175 TK_Status find_textures(); 00176 00177 00178 enum Revisit { 00179 Nothing, 00180 Working, 00181 Force 00182 }; 00183 #endif 00184 00185 public: 00189 HStreamFileToolkit (); 00190 00191 ~HStreamFileToolkit (); 00192 // clean out current state 00193 00199 void Restart (); 00200 00201 // normal processing functions 00202 00221 TK_Status GenerateBuffer (char * b, int s, int & f, char const * start_segment = 0); 00222 00223 00237 TK_Status GenerateOneItemBuffer (char * b, int s, int & f, HC_KEY item); 00238 00239 00249 unsigned POINTER_SIZED_INT CountObjects (char const * start_segment = 0); 00250 00251 00252 void ActivateContext (ID_Key key); 00253 void DeactivateContext (ID_Key key); 00254 void NewFileContext (ID_Key key); 00255 00256 00263 int GetHoopsVersion() { if (m_hoops_version == 0) validate_hoops_version(); return m_hoops_version; } 00264 00271 TK_Status StringToHandler (char const *type, BBaseOpcodeHandler **handler); 00272 00279 TK_Status StringToOpcode (char const *type, unsigned char *opcode_out); 00280 00281 00289 void SetThumbnail (BBaseOpcodeHandler * handler); 00290 00301 void SetThumbnail (int format, int width, int height, unsigned char const * data); 00302 00307 TK_Status Write_Stream_File (); 00308 00314 void AddExcludedSegments (int count, HC_KEY const keys[]); 00319 void AddExcludedSegment (HC_KEY key) { AddExcludedSegments (1, &key); } 00325 bool SegmentIsExcluded (HC_KEY key) const; 00329 void ClearExcludedSegments (); 00334 int GetExcludedSegmentCount () const { return m_excluded_count; } 00339 HC_KEY const * GetExcludedSegments () const { return m_excluded_segments; } 00340 00345 void SetPrependRootSegment(const char * segment); 00350 const char * GetPrependRootSegment() { return m_prepend_root; } 00351 00352 00356 bool MatchPreviousExRef () const; 00357 00358 char const **m_search_strings; 00359 00360 protected: 00362 void validate_hoops_version(); 00364 void add_unnamed_segment (HC_KEY key); 00366 void read_completed (); 00368 void empty_lists (); 00370 TK_Status tag (int variant); 00372 unsigned HLONG count_segment_objects (HC_KEY key, char const * start_segment = 0); 00373 00374 virtual void FileDone() { 00375 apply_deferred_styles(); 00376 } 00377 00378 }; 00379 00380 00381 #endif //HBINFILETK_TOOLKIT