00001 /* $NoKeywords: $ */ 00002 /* 00003 // 00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved. 00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert 00006 // McNeel & Associates. 00007 // 00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF 00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED. 00011 // 00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>. 00013 // 00015 */ 00016 00017 #if !defined(OPENNURBS_INSTANCE_INC_) 00018 #define OPENNURBS_INSTANCE_INC_ 00019 00020 /* 00021 Description: 00022 An ON_InstanceDefinition defines the geometry used by 00023 instance references. 00024 See Also: 00025 ON_InstanceRef 00026 */ 00027 class ON_CLASS ON_InstanceDefinition : public ON_Geometry 00028 { 00029 ON_OBJECT_DECLARE(ON_InstanceDefinition); 00030 00031 public: 00032 00033 // IDEF_UPDATE_TYPE lists the possible relationships between 00034 // the instance definition geometry and the archive 00035 // (m_source_archive) containing the original defition. 00036 enum IDEF_UPDATE_TYPE 00037 { 00038 static_def = 0, 00039 embedded_def = 1, 00040 // As of 7 February, "static_def" and "embedded_def" 00041 // and shall be treated the same. Using "static_def" 00042 // is prefered and "embedded_def" is obsolete. 00043 // The geometry for the instance definition 00044 // is saved in archives, is fixed and has no 00045 // connection to a source archive. 00046 // All source archive information should be 00047 // empty strings and m_source_archive_checksum 00048 // shoule be "zero". 00049 linked_and_embedded_def = 2, 00050 // The geometry for the instance definition 00051 // is saved in archives. Complete source 00052 // archive and checksum information will be 00053 // present. The document setting 00054 // ON_3dmIOSettings.m_idef_link_update 00055 // determines if, when and how the instance 00056 // definition geometry is updated by reading the 00057 // source archive. 00058 linked_def = 3, 00059 // The geometry for this instance definition 00060 // is not saved in the archive that contains 00061 // this instance definition. This instance 00062 // definition geometry is imported from a 00063 // "source archive" The "source archive" file 00064 // name and checksum information are saved 00065 // in m_source_archive and m_source_archive_checksum. 00066 // If file named in m_source_archive is not available, 00067 // then this instance definition is not valid and any 00068 // references to it are not valid. 00069 force_32bit_idef_update_type = 0xFFFFFFFF 00070 }; 00071 00072 // Converts and integer into an IDEF_UPDATE_TYPE enum. 00073 static IDEF_UPDATE_TYPE IdefUpdateType(int i); 00074 00075 // Bits that identify subsets of the instance defintion 00076 // fields. These bits are used to determine which fields to 00077 // set when an ON_InstanceDefinition class is used to 00078 // modify an existing instance definition. 00079 enum 00080 { 00081 no_idef_settings = 0, 00082 idef_name_setting = 1, // m_name 00083 idef_description_setting = 2, // m_description 00084 idef_url_setting = 4, // all m_url_* fields 00085 idef_units_setting = 8, // m_us and m_unit_scale 00086 idef_source_archive_setting = 0x10, // all m_source_*, layer style, update depth fields 00087 idef_userdata_setting = 0x20, 00088 all_idef_settings = 0xFFFFFFFF 00089 }; 00090 00091 public: 00092 ON_InstanceDefinition(); 00093 ~ON_InstanceDefinition(); 00094 00095 // virtual ON_Object overrides 00096 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 00097 00098 // virtual ON_Object::Dump override 00099 void Dump( ON_TextLog& ) const; 00100 00101 ON_BOOL32 Write( 00102 ON_BinaryArchive& binary_archive 00103 ) const; 00104 ON_BOOL32 Read( 00105 ON_BinaryArchive& binary_archive 00106 ); 00107 ON::object_type ObjectType() const; 00108 unsigned int SizeOf() const; 00109 00110 // virtual ON_Geometry overrides 00111 int Dimension() const; 00112 ON_BOOL32 GetBBox( 00113 double* boxmin, 00114 double* boxmax, 00115 int bGrowBox = false 00116 ) const; 00117 ON_BOOL32 Transform( 00118 const ON_Xform& xform 00119 ); 00120 00121 // virtual 00122 ON_UUID ModelObjectId() const; 00123 00124 // Interface 00125 const wchar_t* Name() const; 00126 void SetName( const wchar_t* name ); 00127 00128 const wchar_t* Description() const; 00129 void SetDescription( const wchar_t* description ); 00130 00131 const wchar_t* URL() const; 00132 void SetURL( const wchar_t* url ); 00133 00134 const wchar_t* URL_Tag() const; 00135 void SetURL_Tag( const wchar_t* url_tag ); 00136 00137 ON_UUID Uuid() const; 00138 void SetUuid( ON_UUID uuid ); 00139 00140 void SetBoundingBox( ON_BoundingBox bbox ); 00141 00142 // list of object ids in the instance geometry table. 00143 ON_SimpleArray<ON_UUID> m_object_uuid; 00144 00145 /* 00146 Description: 00147 If the instance definition is linked or embedded, use 00148 SetSource to specify the source archive. 00149 Parameters: 00150 source_archive - [in] name of source archive 00151 checksum - [in] check sum used to detect changed. 00152 Generally, you will pass ON_CheckSum::UnsetCheckSum 00153 for this argument and Rhino will handle setting 00154 the checksum to the appropriate value at the appropriate 00155 time. 00156 source_type - [in] 00157 If source_archive and checksum are empty, then 00158 source_type is ignored and static_def will be used. 00159 If source_archive is a nonempty string and checksum 00160 is set, then source_type must be either 00161 linked_and_embedded_def or linked_def. If you 00162 are changing the source archive of a valid idef, 00163 then simply pass this->IdefUpdateType(). 00164 Remarks: 00165 See the IDEF_UPDATE_TYPE comments for more details. 00166 */ 00167 void SetSourceArchive( 00168 const wchar_t* source_archive, 00169 ON_CheckSum checksum, 00170 IDEF_UPDATE_TYPE update_type 00171 ); 00172 00173 /* 00174 Description: 00175 Destroys all source archive information. 00176 Specifically: 00177 * m_source_archive is set to the empty string. 00178 * m_source_bRelativePath is set to false 00179 * The alternative source archive path is set 00180 to the empty string. 00181 * m_source_archive_checksum.Zero() is used to 00182 destroy all checksum information. 00183 * m_idef_update_type is set to static_def. 00184 */ 00185 void DestroySourceArchive(); 00186 00187 /* 00188 Returns: 00189 Name of source archive. 00190 */ 00191 const wchar_t* SourceArchive() const; 00192 00193 /* 00194 Returns: 00195 Check sum of source archive. 00196 */ 00197 ON_CheckSum SourceArchiveCheckSum() const; 00198 00199 const ON_UnitSystem& UnitSystem() const; 00200 00201 /* 00202 Description: 00203 Use this function to specify an alternate location to 00204 look for a linked instance defininition archive if it 00205 cannot be found in the location specified by m_source_archive. 00206 Parameters: 00207 alternate_source_archive_path - [in] 00208 alterate location. pass null to delete the alternate path. 00209 bRelativePath - [in] 00210 true if alternate_source_archive_path is a relative path. 00211 */ 00212 void SetAlternateSourceArchivePath( 00213 const wchar_t* alternate_source_archive_path, 00214 bool bRelativePath 00215 ); 00216 00217 /* 00218 Description: 00219 If there is an alternate location to look for a linked instance 00220 defininition archive when it cannot be found in the location 00221 specified by m_source_archive, then function will return the 00222 alterate location. 00223 Parameters: 00224 alternate_source_archive_path - [out] 00225 bRelativePath - [out] 00226 true if alternate_source_archive_path is a relative path. 00227 */ 00228 bool GetAlternateSourceArchivePath( 00229 ON_wString& alternate_source_archive_path, 00230 bool& bRelativePath 00231 ) const; 00232 /* 00233 Description: 00234 Sets m_us and m_unit_scale. 00235 */ 00236 void SetUnitSystem( ON::unit_system us ); 00237 void SetUnitSystem( const ON_UnitSystem& us ); 00238 00239 /* 00240 Returns: 00241 True if this is a linked instance definition with 00242 layer settings information. 00243 */ 00244 bool HasLinkedIdefLayerSettings() const; 00245 00246 /* 00247 Description: 00248 Set linked instance definition reference file layer settings. 00249 Parameters: 00250 layer_settings - [in/out] 00251 input: layer settings read from the linked file. 00252 output: layer settings to use in the context of the idef. 00253 */ 00254 void UpdateLinkedIdefReferenceFileLayerSettings( unsigned int layer_count, ON_Layer** layer_settings ); 00255 00256 /* 00257 Description: 00258 Set linked instance definition parent layer information. 00259 Typically this is done just before the linked idef is 00260 saved to a file. 00261 Parameters: 00262 linked_idef_parent_layer - [in] 00263 */ 00264 void UpdateLinkedIdefParentLayerSettings( const ON_Layer* linked_idef_parent_layer ); 00265 00266 const ON_Layer* LinkedIdefParentLayerSettings() const; 00267 00268 /* 00269 Description: 00270 When a linked instance definition is read and its layers are added to the 00271 context when the idef exists, runtime layer ids may need to be changed 00272 when an id collision occures. In this case, use this function to 00273 inform the linked instance definition of the map from runtime layer 00274 id to the layer id found in the linked file. 00275 Parameters: 00276 id_map - [in] 00277 The first id in the pair is the layer id in the current context 00278 where the idef is being used. 00279 The second id in the pair is the layer id found in the linked file. 00280 */ 00281 void UpdateLinkedIdefReferenceFileLayerRuntimeId( const ON_UuidPairList& id_map ); 00282 00283 /* 00284 Description: 00285 Set linked instance definition layer settings. 00286 Typically this is done just before the linked idef is 00287 saved to a file. 00288 Parameters: 00289 layer_settings - [in] 00290 Layer settings in the context where the linked idef is being used. 00291 Remarks: 00292 Linked idefs save the original layer informtion from the linked file. 00293 In the context where the idef is used, some of those settings (color, 00294 visibility, ...) can be modified. This function saves those modifications 00295 so the can be applied the next time the linked idef is read. 00296 */ 00297 void UpdateLinkedIdefLayerSettings( unsigned int layer_count, const ON_Layer*const* layer_settings ); 00298 00299 public: 00300 00301 ON_UUID m_uuid; // unique id for this instance definition 00302 ON_wString m_name; // The "name" is for human comfort. 00303 // It can be empty and duplicates 00304 // may exist. Instance reference use 00305 // m_uuid to find instance definitions. 00306 ON_wString m_description; 00307 00308 ON_wString m_url; 00309 ON_wString m_url_tag; // UI link text for m_url 00310 00311 #if defined(ON_32BIT_POINTER) 00312 private: 00313 // 24 January 2011: 00314 // Because the Rhino 4 and 5 SDKs are fixed, the offset of 00315 // existing fields cannot be changed and the m_reserved1 00316 // value has to be located in different places for 00317 // 32 and 64 bit builds. 00318 unsigned int m_reserved1; 00319 #endif 00320 00321 public: 00322 ON_BoundingBox m_bbox; 00323 00324 ON_UnitSystem m_us; 00325 00326 // Note: the embedded_def type is obsolete. 00327 // To avoid having to deal with this obsolete type in 00328 // your code, using ON_InstanceDefintion::IdefUpdateType() 00329 // to get this value. The IdefUpdateType() function 00330 // with convert the obsolte value to the correct 00331 // value. 00332 IDEF_UPDATE_TYPE m_idef_update_type; 00333 00334 IDEF_UPDATE_TYPE IdefUpdateType() const; 00335 00336 int m_idef_update_depth; // Controls how much geometry is read when 00337 // a linked idef is updated. 00338 // 0: read everything, included nested linked idefs 00339 // 1: skip nested linked idefs. 00340 00341 ON_wString m_source_archive; // filename used to update idef 00342 // (it can be empty or relative) 00343 bool m_source_bRelativePath; // True if the filename in m_source_archive is 00344 // a relative the location of the 3dm file 00345 // containing this instance definition. 00346 00347 // A static or linked_and_embedded idef must have m_layer_style = 0 00348 // A linked idef must have m_layer_style = 1 or 2 00349 // 0 = unset 00350 // 1 = active (linked idef layers will be active) 00351 // 2 = reference (linked idef layers will be reference) 00352 unsigned char m_idef_layer_style; 00353 00354 private: 00355 unsigned char m_reserved2[2]; 00356 00357 #if defined(ON_64BIT_POINTER) 00358 private: 00359 // 24 January 2011: 00360 // Because the Rhino 4 and 5 SDKs are fixed, the offset of 00361 // existing fields cannot be changed and the m_runtime_sn 00362 // value has to be located in different places for 00363 // 32 and 64 bit builds. 00364 unsigned int m_reserved1; 00365 #endif 00366 00367 public: 00368 ON_CheckSum m_source_archive_checksum; // used to detect when idef is out of 00369 // synch with source archive. 00370 }; 00371 00372 00373 /* 00374 Description: 00375 An ON_InstanceRef is a reference to an instance definition 00376 along with transformation to apply to the definition. 00377 See Also: 00378 ON_InstanceRef 00379 */ 00380 class ON_CLASS ON_InstanceRef : public ON_Geometry 00381 { 00382 ON_OBJECT_DECLARE(ON_InstanceRef); 00383 00384 public: 00385 ON_InstanceRef(); 00386 00388 // 00389 // virtual ON_Object overrides 00390 // 00391 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 00392 ON_BOOL32 Write( 00393 ON_BinaryArchive& binary_archive 00394 ) const; 00395 ON_BOOL32 Read( 00396 ON_BinaryArchive& binary_archive 00397 ); 00398 ON::object_type ObjectType() const; 00399 00401 // 00402 // virtual ON_Geometry overrides 00403 // 00404 int Dimension() const; 00405 ON_BOOL32 GetBBox( 00406 double* boxmin, 00407 double* boxmax, 00408 int bGrowBox = false 00409 ) const; 00410 ON_BOOL32 Transform( 00411 const ON_Xform& xform 00412 ); 00413 00414 // virtual ON_Geometry::IsDeformable() override 00415 bool IsDeformable() const; 00416 00417 // virtual ON_Geometry::MakeDeformable() override 00418 bool MakeDeformable(); 00419 00421 // 00422 00423 // Unique id of the instance definition (ON_InstanceDefinition) 00424 // in the instance definition table that defines the geometry 00425 // used by this reference. 00426 ON_UUID m_instance_definition_uuid; 00427 00428 // Transformation for this reference. 00429 ON_Xform m_xform; 00430 00431 // Bounding box for this reference. 00432 ON_BoundingBox m_bbox; 00433 00434 // Tolerance to use for flagging instance xforms 00435 // as singular. 00436 static const double m_singular_xform_tol; 00437 }; 00438 00439 #endif