00001 // 00002 // Copyright (c) 2000 by Tech Soft 3D, LLC. 00003 // The information contained herein is confidential and proprietary to 00004 // Tech Soft 3D, LLC., and considered a trade secret as defined under 00005 // civil and criminal statutes. Tech Soft 3D shall pursue its civil 00006 // and criminal remedies in the event of unauthorized use or misappropriation 00007 // of its trade secrets. Use of this information by anyone other than 00008 // authorized employees of Tech Soft 3D, LLC. is granted only under a 00009 // written non-disclosure agreement, expressly prescribing the scope and 00010 // manner of such use. 00011 // 00012 // $Id: 1dc0122b76f841c6875d11f23ece5569d59a6701 $ 00013 // 00014 00015 #ifndef HBINFILETK_TOOLKIT 00016 #define HBINFILETK_TOOLKIT 00017 00018 00019 #ifndef HSTREAM_READONLY 00020 00021 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00022 00023 class Internal_Key_Array { 00024 friend class HStreamFileToolkit; 00025 friend class Internal_Pending_Tag; 00026 friend class Internal_Segment_Processor; 00027 private: 00028 Internal_Key_Array() { m_data = 0; } 00029 ~Internal_Key_Array() { delete [] m_data; } 00030 00031 int m_count; 00032 HC_KEY *m_data; 00033 }; 00034 00035 class Internal_Pending_Tag { 00036 friend class HStreamFileToolkit; 00037 friend class Internal_Segment_Processor; 00038 friend class HTK_Referenced_Segment; 00039 friend class HTK_Reference; 00040 friend class HTK_Texture; 00041 friend class HTK_Named_Style_Def; 00042 private: 00043 Internal_Pending_Tag() { m_next = 0; m_array = 0; } 00044 ~Internal_Pending_Tag() { delete m_array; } 00045 00046 Internal_Pending_Tag * m_next; 00047 HC_KEY m_key; //m_key set to tk.m_last_keys[0], just for the purposes of matching tag requests 00048 int m_variant; 00049 Internal_Key_Array * m_array; //set to null unless we are associating multiple keys with a single tag call. 00050 }; 00051 00052 00053 class Internal_Texture_List { 00054 friend class HStreamFileToolkit; 00055 friend class HTK_Image; 00056 private: 00057 Internal_Texture_List * m_next; 00058 char * m_name; 00059 char * m_image; 00060 HC_KEY m_image_key; 00061 bool m_do_write_image; 00062 00063 public: 00064 Internal_Texture_List (char const * name, char const * image, HC_KEY key = -1); 00065 ~Internal_Texture_List(); 00066 }; 00067 00068 00070 class HBINFILETK_API HStreamFileToolkit; //forward declaration 00071 00072 // special output-only pseudo-object 00073 class HBINFILETK_API2 Internal_Segment_Processor : public BBaseOpcodeHandler { 00074 protected: 00075 char * m_name; 00076 HC_KEY m_key; 00077 bool m_top_level; 00078 HC_KEY m_root; 00079 BBaseOpcodeHandler * m_current_object; 00080 BBaseOpcodeHandler * m_must_delete; 00081 HC_KEY m_item_key; 00082 int m_saved_count; 00083 HC_KEY * m_saved_keys; 00084 HC_KEY m_renumbered; 00085 unsigned char m_renumbered_scope; 00086 int m_priority; 00087 bool m_has_priority; 00088 int m_start_offset; 00089 bool m_searching; 00090 unsigned char m_use_polypolylines; 00091 unsigned char m_polylines_already_handled; 00092 bool m_geometry_attributes; 00093 bool m_geometry_open; 00094 BBaseOpcodeHandler * m_deferred; 00095 int m_search_pass; 00096 bool m_look_for_bounds; 00098 void save_keys (HStreamFileToolkit & tk); 00099 void restore_keys (HStreamFileToolkit & tk); 00100 00101 public: 00102 Internal_Segment_Processor (ID_Key key = -1, char const * name = 0); 00103 ~Internal_Segment_Processor (); 00104 00105 TK_Status Read (BStreamFileToolkit & tk); 00106 TK_Status Write (BStreamFileToolkit & tk); 00107 TK_Status Interpret (BStreamFileToolkit & tk, ID_Key key, int variant = 0); 00108 TK_Status Interpret (BStreamFileToolkit & tk, ID_Key key, char const * special); 00109 void Reset (); 00110 TK_Status Clone (BStreamFileToolkit & tk, BBaseOpcodeHandler **) const; 00111 00112 void SetRoot (HC_KEY root) { m_root = root; } 00113 HC_KEY GetRoot () const { return m_root; } 00114 }; 00115 00116 #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 00117 00118 #endif //HSTREAM_READONLY 00119 00120 00121 00122 00123 00125 00143 class HBINFILETK_API2 HStreamFileToolkit : public BStreamFileToolkit { 00144 friend class Internal_Segment_Processor; 00145 friend class HTK_Open_Segment; 00146 friend class HTK_Referenced_Segment; 00147 friend class HTK_Reference; 00148 friend class HTK_Texture; 00149 friend class HTK_Image; 00150 friend class HTK_Named_Style_Def; 00151 private: 00152 int m_hoops_version; /* Version of Hoops we are using */ 00153 Internal_Segment_List * m_unnamed_segments; /* Segments which need to be renamed to unnamed when able */ 00154 00155 HC_KEY * m_excluded_segments; /* keys of segments (if any) to skip during write */ 00156 int m_excluded_count; /* size of exclusion array */ 00157 00158 #ifndef HSTREAM_READONLY 00159 Internal_Segment_Processor * m_segment_processor; /* Handler for top segment & revisited segments */ 00160 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 */ 00161 Internal_Texture_List * m_texture_list; /* Textures being processed */ 00162 bool m_non_segment_revisits; /* Does the revisit list contain something other than segments? */ 00163 int m_revisit_offset; /* File offset of start of current revisit object (including compression if appropriate) */ 00164 BBaseOpcodeHandler * m_thumbnail; /* handler for a thumbnail (if any) to write */ 00165 int m_local_attributes; /* flag presence of geometry-level attributes (used in GenerateOne) */ 00166 BBaseOpcodeHandler * m_must_delete; /* pointer to any temporary handler to discard when done */ 00167 char * m_prepend_root; /* a string to prepend on rooted segments */ 00168 int m_revisit_state; /* state of progress in revisit loop */ 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 }; 00375 00376 00377 #endif //HBINFILETK_TOOLKIT