00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00015
00016
00017 #include "pcl/surface/3rdparty/opennurbs/opennurbs.h"
00018
00019 ON_COMPONENT_INDEX::ON_COMPONENT_INDEX()
00020 : m_type(ON_COMPONENT_INDEX::invalid_type),
00021 m_index(-1)
00022 {
00023 }
00024
00025 ON_COMPONENT_INDEX::ON_COMPONENT_INDEX(
00026 ON_COMPONENT_INDEX::TYPE type,
00027 int index
00028 )
00029 : m_type(type),
00030 m_index(index)
00031 {
00032 }
00033
00034 ON_COMPONENT_INDEX::TYPE ON_COMPONENT_INDEX::Type(int i)
00035 {
00036 TYPE t = invalid_type;
00037 switch((unsigned int)i)
00038 {
00039 case no_type: t = no_type; break;
00040 case brep_vertex: t = brep_vertex; break;
00041 case brep_edge: t = brep_edge; break;
00042 case brep_face: t = brep_face; break;
00043 case brep_trim: t = brep_trim; break;
00044 case brep_loop: t = brep_loop; break;
00045 case mesh_vertex: t = mesh_vertex; break;
00046 case meshtop_vertex: t = meshtop_vertex; break;
00047 case meshtop_edge: t = meshtop_edge; break;
00048 case mesh_face: t = mesh_face; break;
00049 case idef_part: t = idef_part; break;
00050 case polycurve_segment: t = polycurve_segment; break;
00051 case pointcloud_point: t = pointcloud_point; break;
00052 case group_member: t = group_member; break;
00053
00054 case extrusion_bottom_profile: t = extrusion_bottom_profile; break;
00055 case extrusion_top_profile: t = extrusion_top_profile; break;
00056 case extrusion_wall_edge: t = extrusion_wall_edge; break;
00057 case extrusion_wall_surface: t = extrusion_wall_surface; break;
00058 case extrusion_cap_surface: t = extrusion_cap_surface; break;
00059 case extrusion_path: t = extrusion_path; break;
00060
00061 case dim_linear_point: t = dim_linear_point; break;
00062 case dim_radial_point: t = dim_radial_point; break;
00063 case dim_angular_point: t = dim_angular_point; break;
00064 case dim_ordinate_point: t = dim_ordinate_point; break;
00065 case dim_text_point: t = dim_text_point; break;
00066 }
00067 return t;
00068 }
00069
00070
00071 void ON_COMPONENT_INDEX::Set(
00072 ON_COMPONENT_INDEX::TYPE type,
00073 int index
00074 )
00075 {
00076 m_type = type;
00077 m_index = index;
00078 }
00079
00080 void ON_COMPONENT_INDEX::UnSet()
00081 {
00082 m_type = ON_COMPONENT_INDEX::invalid_type;
00083 m_index = -1;
00084 }
00085
00086 bool ON_COMPONENT_INDEX::IsMeshComponentIndex() const
00087 {
00088 bool rc = false;
00089 switch(m_type)
00090 {
00091 case ON_COMPONENT_INDEX::mesh_vertex:
00092 case ON_COMPONENT_INDEX::meshtop_vertex:
00093 case ON_COMPONENT_INDEX::meshtop_edge:
00094 case ON_COMPONENT_INDEX::mesh_face:
00095 if ( m_index >= 0 )
00096 {
00097 rc = true;
00098 }
00099 break;
00100 default:
00101
00102 break;
00103 }
00104 return rc;
00105 }
00106
00107 bool ON_COMPONENT_INDEX::IsAnnotationComponentIndex() const
00108 {
00109 bool rc = false;
00110 switch(m_type)
00111 {
00112 case ON_COMPONENT_INDEX::dim_linear_point:
00113 case ON_COMPONENT_INDEX::dim_radial_point:
00114 case ON_COMPONENT_INDEX::dim_angular_point:
00115 case ON_COMPONENT_INDEX::dim_ordinate_point:
00116 case ON_COMPONENT_INDEX::dim_text_point:
00117 if ( m_index >= 0 )
00118 {
00119 rc = true;
00120 }
00121 break;
00122 default:
00123
00124 break;
00125 }
00126 return rc;
00127 }
00128
00129 bool ON_COMPONENT_INDEX::IsBrepComponentIndex() const
00130 {
00131 bool rc = false;
00132 switch(m_type)
00133 {
00134 case ON_COMPONENT_INDEX::brep_vertex:
00135 case ON_COMPONENT_INDEX::brep_trim:
00136 case ON_COMPONENT_INDEX::brep_loop:
00137 case ON_COMPONENT_INDEX::brep_edge:
00138 case ON_COMPONENT_INDEX::brep_face:
00139 if ( m_index >= 0 )
00140 {
00141 rc = true;
00142 }
00143 break;
00144 default:
00145
00146 break;
00147 }
00148 return rc;
00149 }
00150
00151 bool ON_COMPONENT_INDEX::IsIDefComponentIndex() const
00152 {
00153 return ( ON_COMPONENT_INDEX::idef_part == m_type && m_index >= 0 );
00154 }
00155
00156 bool ON_COMPONENT_INDEX::IsPolyCurveComponentIndex() const
00157 {
00158 return ( ON_COMPONENT_INDEX::polycurve_segment == m_type && m_index >= 0 );
00159 }
00160
00161 bool ON_COMPONENT_INDEX::IsGroupMemberComponentIndex() const
00162 {
00163 return ( ON_COMPONENT_INDEX::group_member == m_type && m_index >= 0 );
00164 }
00165
00166 bool ON_COMPONENT_INDEX::IsExtrusionProfileComponentIndex() const
00167 {
00168 return ( ( ON_COMPONENT_INDEX::extrusion_bottom_profile == m_type
00169 || ON_COMPONENT_INDEX::extrusion_top_profile == m_type
00170 )
00171 && m_index >= 0
00172 );
00173 }
00174
00175 bool ON_COMPONENT_INDEX::IsExtrusionPathComponentIndex() const
00176 {
00177 return ( ON_COMPONENT_INDEX::extrusion_path == m_type
00178 && m_index >= -1
00179 && m_index <= 1
00180 );
00181 }
00182
00183 bool ON_COMPONENT_INDEX::IsExtrusionWallEdgeComponentIndex() const
00184 {
00185 return ( ON_COMPONENT_INDEX::extrusion_wall_edge == m_type
00186 && m_index >= 0
00187 );
00188 }
00189
00190 bool ON_COMPONENT_INDEX::IsExtrusionWallSurfaceComponentIndex() const
00191 {
00192 return ( ON_COMPONENT_INDEX::extrusion_wall_surface == m_type
00193 && m_index >= 0
00194 );
00195 }
00196
00197 bool ON_COMPONENT_INDEX::IsExtrusionWallComponentIndex() const
00198 {
00199 return ( ( ON_COMPONENT_INDEX::extrusion_wall_edge == m_type
00200 || ON_COMPONENT_INDEX::extrusion_wall_surface == m_type
00201 )
00202 && m_index >= 0
00203 );
00204 }
00205
00206 bool ON_COMPONENT_INDEX::IsExtrusionComponentIndex() const
00207 {
00208 return ( ( ON_COMPONENT_INDEX::extrusion_bottom_profile == m_type
00209 || ON_COMPONENT_INDEX::extrusion_top_profile == m_type
00210 || ON_COMPONENT_INDEX::extrusion_wall_edge == m_type
00211 || ON_COMPONENT_INDEX::extrusion_wall_surface == m_type
00212 || ON_COMPONENT_INDEX::extrusion_cap_surface == m_type
00213 || ON_COMPONENT_INDEX::extrusion_path == m_type
00214 )
00215 &&
00216 ( m_index >= 0
00217 || (-1 == m_index && ON_COMPONENT_INDEX::extrusion_path == m_type)
00218 )
00219 );
00220 }
00221
00222 bool ON_COMPONENT_INDEX::IsPointCloudComponentIndex() const
00223 {
00224 return ( ON_COMPONENT_INDEX::pointcloud_point == m_type && m_index >= 0 );
00225 }
00226
00227 bool ON_COMPONENT_INDEX::IsSet() const
00228 {
00229 bool rc = false;
00230 switch(m_type)
00231 {
00232 case invalid_type:
00233 rc = false;
00234 break;
00235
00236 case no_type:
00237 rc = false;
00238 break;
00239
00240 case brep_vertex:
00241 case brep_edge:
00242 case brep_face:
00243 case brep_trim:
00244 case brep_loop:
00245 case mesh_vertex:
00246 case meshtop_vertex:
00247 case meshtop_edge:
00248 case mesh_face:
00249 case idef_part:
00250 case polycurve_segment:
00251 case pointcloud_point:
00252 case group_member:
00253 rc = (m_index != -1);
00254 break;
00255
00256 default:
00257 rc = false;
00258 break;
00259 }
00260 return rc;
00261 }
00262
00263
00264 int ON_COMPONENT_INDEX::Compare( const ON_COMPONENT_INDEX* a, const ON_COMPONENT_INDEX* b )
00265 {
00266 int i = ((int)a->m_type) - ((int)b->m_type);
00267 if ( 0 == i )
00268 {
00269 i = a->m_index - b->m_index;
00270 }
00271 return i;
00272 }
00273
00274 bool ON_COMPONENT_INDEX::operator==(const ON_COMPONENT_INDEX& other) const
00275 {
00276 return (m_type == other.m_type && m_index == other.m_index);
00277 }
00278
00279 bool ON_COMPONENT_INDEX::operator!=(const ON_COMPONENT_INDEX& other) const
00280 {
00281 return (m_type != other.m_type || m_index != other.m_index);
00282 }
00283
00284 bool ON_COMPONENT_INDEX::operator<(const ON_COMPONENT_INDEX& other) const
00285 {
00286 return (ON_COMPONENT_INDEX::Compare(this,&other) < 0);
00287 }
00288
00289 bool ON_COMPONENT_INDEX::operator<=(const ON_COMPONENT_INDEX& other) const
00290 {
00291 return (ON_COMPONENT_INDEX::Compare(this,&other) <= 0);
00292 }
00293
00294 bool ON_COMPONENT_INDEX::operator>(const ON_COMPONENT_INDEX& other) const
00295 {
00296 return (ON_COMPONENT_INDEX::Compare(this,&other) > 0);
00297 }
00298
00299 bool ON_COMPONENT_INDEX::operator>=(const ON_COMPONENT_INDEX& other) const
00300 {
00301 return (ON_COMPONENT_INDEX::Compare(this,&other) >= 0);
00302 }
00303
00304 ON_ObjRefEvaluationParameter::ON_ObjRefEvaluationParameter()
00305 : m_t_type(0)
00306 , m_reserved(0)
00307 {
00308 m_t[0] = ON_UNSET_VALUE;
00309 m_t[1] = ON_UNSET_VALUE;
00310 m_t[2] = ON_UNSET_VALUE;
00311 m_t[3] = ON_UNSET_VALUE;
00312 }
00313
00314 void ON_ObjRefEvaluationParameter::Default()
00315 {
00316 ON_ObjRefEvaluationParameter d;
00317 *this = d;
00318 }
00319
00320 ON_ObjRefEvaluationParameter::~ON_ObjRefEvaluationParameter()
00321 {
00322 }
00323
00324 bool ON_ObjRefEvaluationParameter::Write( ON_BinaryArchive& archive ) const
00325 {
00326 bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
00327 if (!rc)
00328 return rc;
00329
00330 for(;;)
00331 {
00332 rc = archive.WriteInt(m_t_type);
00333 if (!rc) break;
00334
00335 rc = archive.WriteComponentIndex(m_t_ci);
00336 if (!rc) break;
00337
00338 rc = archive.WriteDouble(4,m_t);
00339 if (!rc) break;
00340
00341 rc = archive.WriteInterval(m_s[0]);
00342 if (!rc) break;
00343
00344 rc = archive.WriteInterval(m_s[1]);
00345 if (!rc) break;
00346
00347 rc = archive.WriteInterval(m_s[2]);
00348 if (!rc) break;
00349
00350 break;
00351 }
00352
00353 if ( !archive.EndWrite3dmChunk() )
00354 rc = false;
00355
00356 return rc;
00357 }
00358
00359 bool ON_ObjRefEvaluationParameter::Read( ON_BinaryArchive& archive )
00360 {
00361 Default();
00362
00363 int major_version = 0;
00364 int minor_version = 0;
00365 bool rc = archive.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&major_version,&minor_version);
00366 if (!rc)
00367 return rc;
00368
00369 for(;;)
00370 {
00371 rc = (1 == major_version);
00372 if (!rc) break;
00373
00374 rc = archive.ReadInt(&m_t_type);
00375 if (!rc) break;
00376
00377 rc = archive.ReadComponentIndex(m_t_ci);
00378 if (!rc) break;
00379
00380 rc = archive.ReadDouble(4,m_t);
00381 if (!rc) break;
00382
00383 rc = archive.ReadInterval(m_s[0]);
00384 if (!rc) break;
00385
00386 rc = archive.ReadInterval(m_s[1]);
00387 if (!rc) break;
00388
00389 rc = archive.ReadInterval(m_s[2]);
00390 if (!rc) break;
00391
00392 break;
00393 }
00394
00395 if ( !archive.EndRead3dmChunk() )
00396 rc = false;
00397
00398 return rc;
00399 }
00400
00401 ON_ObjRef::ON_ObjRef()
00402 : m_uuid(ON_nil_uuid),
00403 m_geometry(0),
00404 m_parent_geometry(0),
00405 m_geometry_type(ON::unknown_object_type),
00406 m_runtime_sn(0),
00407 m_point(ON_UNSET_POINT),
00408 m_osnap_mode(ON::os_none),
00409 m__proxy1(0),
00410 m__proxy2(0),
00411 m__proxy_ref_count(0)
00412 {
00413 }
00414
00415 void ON_ObjRef::Destroy()
00416 {
00417 DecrementProxyReferenceCount();
00418 m_uuid = ON_nil_uuid;
00419 m_geometry = 0;
00420 m_parent_geometry = 0;
00421 m_geometry_type = ON::unknown_object_type;
00422 m_runtime_sn = 0;
00423 m_point = ON_UNSET_POINT;
00424 m_osnap_mode = ON::os_none;
00425 m__proxy1 = 0;
00426 m__proxy2 = 0;
00427 m__proxy_ref_count = 0;
00428 }
00429
00430
00431 ON_ObjRef::ON_ObjRef( const ON_ObjRef& src )
00432 : m_uuid(src.m_uuid),
00433 m_geometry(src.m_geometry),
00434 m_parent_geometry(src.m_parent_geometry),
00435 m_component_index(src.m_component_index),
00436 m_geometry_type(src.m_geometry_type),
00437 m_runtime_sn(src.m_runtime_sn),
00438 m_point(src.m_point),
00439 m_osnap_mode(src.m_osnap_mode),
00440 m_evp(src.m_evp),
00441 m__iref(src.m__iref),
00442 m__proxy1(src.m__proxy1),
00443 m__proxy2(src.m__proxy2),
00444 m__proxy_ref_count(src.m__proxy_ref_count)
00445 {
00446 if ( m__proxy_ref_count && *m__proxy_ref_count > 0 )
00447 {
00448 *m__proxy_ref_count = *m__proxy_ref_count + 1;
00449 }
00450 }
00451
00452 ON_ObjRef& ON_ObjRef::operator=( const ON_ObjRef& src )
00453 {
00454 if ( this != &src )
00455 {
00456
00457
00458 DecrementProxyReferenceCount();
00459
00460
00461 m_uuid = src.m_uuid;
00462 m_geometry = src.m_geometry;
00463 m_parent_geometry = src.m_parent_geometry;
00464 m_component_index = src.m_component_index;
00465 m_geometry_type = src.m_geometry_type;
00466 m_runtime_sn = src.m_runtime_sn;
00467 m_point = src.m_point;
00468 m_osnap_mode = src.m_osnap_mode;
00469 m_evp = src.m_evp;
00470 m__iref = src.m__iref;
00471 m__proxy1 = src.m__proxy1;
00472 m__proxy2 = src.m__proxy2;
00473 m__proxy_ref_count = src.m__proxy_ref_count;
00474
00475 if ( m__proxy_ref_count && *m__proxy_ref_count > 0 )
00476 {
00477 *m__proxy_ref_count = *m__proxy_ref_count + 1;
00478 }
00479 }
00480
00481 return *this;
00482 }
00483
00484 bool ON_ObjRef_IRefID::Write( ON_BinaryArchive& archive ) const
00485 {
00486 bool rc = archive.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 1, 1 );
00487 if ( !rc )
00488 return false;
00489
00490 for(;;)
00491 {
00492 rc = archive.WriteUuid(m_iref_uuid);
00493 if (!rc) break;
00494
00495 rc = archive.WriteXform(m_iref_xform);
00496 if (!rc) break;
00497
00498 rc = archive.WriteUuid(m_idef_uuid);
00499 if (!rc) break;
00500
00501 rc = archive.WriteInt(m_idef_geometry_index);
00502 if (!rc) break;
00503
00504
00505 rc = archive.WriteComponentIndex(m_component_index);
00506 if (!rc) break;
00507
00508 rc = m_evp.Write(archive);
00509 if (!rc) break;
00510
00511 break;
00512 }
00513
00514 if ( !archive.EndWrite3dmChunk() )
00515 rc = false;
00516 return rc;
00517 }
00518
00519 bool ON_ObjRef_IRefID::Read( ON_BinaryArchive& archive )
00520 {
00521 Default();
00522
00523 int major_version = 0;
00524 int minor_version = 0;
00525 bool rc = archive.BeginRead3dmChunk(
00526 TCODE_ANONYMOUS_CHUNK,
00527 &major_version,
00528 &minor_version );
00529 if ( !rc )
00530 return false;
00531
00532 for(;;)
00533 {
00534 rc = (1 == major_version);
00535 if (!rc) break;
00536
00537 rc = archive.ReadUuid(m_iref_uuid);
00538 if (!rc) break;
00539
00540 rc = archive.ReadXform(m_iref_xform);
00541 if (!rc) break;
00542
00543 rc = archive.ReadUuid(m_idef_uuid);
00544 if (!rc) break;
00545
00546 rc = archive.ReadInt(&m_idef_geometry_index);
00547 if (!rc) break;
00548
00549 if ( minor_version >= 1 )
00550 {
00551
00552 rc = archive.ReadComponentIndex(m_component_index);
00553 if (!rc) break;
00554
00555 rc = m_evp.Read(archive);
00556 if (!rc) break;
00557 }
00558
00559 break;
00560 }
00561
00562 if ( !archive.EndRead3dmChunk() )
00563 rc = false;
00564 return rc;
00565 }
00566
00567
00568 bool ON_ObjRef::Write( ON_BinaryArchive& archive ) const
00569 {
00570 bool rc = archive.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 1, 2 );
00571 if ( !rc )
00572 return false;
00573
00574 for(;;)
00575 {
00576 rc = archive.WriteUuid(m_uuid);
00577 if (!rc) break;
00578
00579 rc = archive.WriteComponentIndex(m_component_index);
00580 if (!rc) break;
00581
00582 rc = archive.WriteInt(m_geometry_type);
00583 if (!rc) break;
00584
00585
00586
00587
00588
00589 rc = archive.WritePoint(m_point);
00590 if (!rc) break;
00591
00592
00593
00594
00595
00596 rc = archive.WriteInt(m_evp.m_t_type);
00597 if (!rc) break;
00598
00599 rc = archive.WriteComponentIndex(m_evp.m_t_ci);
00600 if (!rc) break;
00601
00602 rc = archive.WriteDouble(4,m_evp.m_t);
00603 if (!rc) break;
00604
00605 rc = archive.WriteArray(m__iref);
00606 if (!rc) break;
00607
00608
00609 rc = archive.WriteInterval(m_evp.m_s[0]);
00610 if (!rc) break;
00611
00612 rc = archive.WriteInterval(m_evp.m_s[1]);
00613 if (!rc) break;
00614
00615
00616 rc = archive.WriteInterval(m_evp.m_s[2]);
00617 if (!rc) break;
00618
00619 break;
00620 }
00621
00622 if ( !archive.EndWrite3dmChunk() )
00623 rc = false;
00624 return rc;
00625 }
00626
00627 bool ON_ObjRef::Read( ON_BinaryArchive& archive )
00628 {
00629 int major_version = 0;
00630 int minor_version = 0;
00631 bool rc = archive.BeginRead3dmChunk( TCODE_ANONYMOUS_CHUNK, &major_version, &minor_version );
00632 if ( !rc )
00633 return false;
00634
00635 for(;;)
00636 {
00637 rc = (1 == major_version);
00638 if (!rc) break;
00639
00640 rc = archive.ReadUuid(m_uuid);
00641 if (!rc) break;
00642
00643 rc = archive.ReadComponentIndex(m_component_index);
00644 if (!rc) break;
00645
00646 rc = archive.ReadInt(&m_geometry_type);
00647 if (!rc) break;
00648
00649 rc = archive.ReadPoint(m_point);
00650 if (!rc) break;
00651
00652
00653
00654
00655
00656 rc = archive.ReadInt(&m_evp.m_t_type);
00657 if (!rc) break;
00658
00659 rc = archive.ReadComponentIndex(m_evp.m_t_ci);
00660 if (!rc) break;
00661
00662 rc = archive.ReadDouble(4,m_evp.m_t);
00663 if (!rc) break;
00664
00665 rc = archive.ReadArray(m__iref);
00666 if (!rc) break;
00667
00668 if ( minor_version >= 1 )
00669 {
00670
00671 rc = archive.ReadInterval(m_evp.m_s[0]);
00672 if (!rc) break;
00673 rc = archive.ReadInterval(m_evp.m_s[1]);
00674 if (!rc) break;
00675 if ( minor_version >= 2 )
00676 {
00677 rc = archive.ReadInterval(m_evp.m_s[2]);
00678 if (!rc) break;
00679 }
00680 }
00681
00682 break;
00683 }
00684
00685 if ( !archive.EndRead3dmChunk() )
00686 rc = false;
00687 return rc;
00688 }
00689
00690
00691 ON_ObjRef::~ON_ObjRef()
00692 {
00693 DecrementProxyReferenceCount();
00694 }
00695
00696
00697 void ON_ObjRef::RemapObjectId( const ON_SimpleArray<ON_UuidPair>& id_remap )
00698 {
00699
00700
00701 int i = id_remap.BinarySearch((const ON_UuidPair*)&m_uuid,ON_UuidPair::CompareFirstUuid);
00702 if ( i >= 0 )
00703 m_uuid = id_remap[i].m_uuid[1];
00704 }
00705
00706 int ON_ObjRef::ProxyReferenceCount() const
00707 {
00708 return m__proxy_ref_count ? *m__proxy_ref_count : 0;
00709 }
00710
00711 const ON_Brep* ON_BrepParent( const ON_Geometry* geo )
00712 {
00713 const ON_Brep* brep = 0;
00714
00715 if ( geo == NULL )
00716 return NULL;
00717
00718 if ( ON::brep_object == geo->ObjectType() )
00719 {
00720 brep = ON_Brep::Cast(geo);
00721 }
00722 else
00723 {
00724
00725 switch( geo->ComponentIndex().m_type )
00726 {
00727 case ON_COMPONENT_INDEX::brep_edge:
00728 {
00729 const ON_BrepEdge* edge = ON_BrepEdge::Cast(geo);
00730 if ( edge )
00731 brep = edge->Brep();
00732 }
00733 break;
00734
00735 case ON_COMPONENT_INDEX::brep_face:
00736 {
00737 const ON_BrepFace* face = ON_BrepFace::Cast(geo);
00738 if ( face )
00739 brep = face->Brep();
00740 }
00741 break;
00742
00743 case ON_COMPONENT_INDEX::brep_trim:
00744 {
00745 const ON_BrepTrim* trim = ON_BrepTrim::Cast(geo);
00746 if ( trim )
00747 brep = trim->Brep();
00748 }
00749 break;
00750
00751 case ON_COMPONENT_INDEX::brep_loop:
00752 {
00753 const ON_BrepLoop* loop = ON_BrepLoop::Cast(geo);
00754 if ( loop )
00755 brep = loop->Brep();
00756 }
00757 break;
00758
00759 default:
00760
00761 break;
00762 }
00763 }
00764
00765 return brep;
00766 }
00767
00768
00769 const ON_Mesh* ON_MeshParent( const ON_Geometry* geo )
00770 {
00771 const ON_Mesh* mesh = 0;
00772
00773 if ( geo == NULL )
00774 return NULL;
00775
00776 if ( ON::mesh_object == geo->ObjectType() )
00777 {
00778 mesh = ON_Mesh::Cast(geo);
00779 }
00780 else
00781 {
00782
00783 switch( geo->ComponentIndex().m_type )
00784 {
00785 case ON_COMPONENT_INDEX::mesh_vertex:
00786 case ON_COMPONENT_INDEX::meshtop_vertex:
00787 {
00788 const ON_MeshVertexRef* vref = ON_MeshVertexRef::Cast(geo);
00789 if ( vref )
00790 mesh = vref->m_mesh;
00791 }
00792 break;
00793
00794 case ON_COMPONENT_INDEX::meshtop_edge:
00795 {
00796 const ON_MeshEdgeRef* eref = ON_MeshEdgeRef::Cast(geo);
00797 if ( eref )
00798 mesh = eref->m_mesh;
00799 }
00800 break;
00801
00802 case ON_COMPONENT_INDEX::mesh_face:
00803 {
00804 const ON_MeshFaceRef* fref = ON_MeshFaceRef::Cast(geo);
00805 if ( fref )
00806 mesh = fref->m_mesh;
00807 }
00808 break;
00809
00810 default:
00811
00812 break;
00813 }
00814 }
00815
00816 return mesh;
00817 }
00818
00819 bool ON_ObjRef::SetParentIRef( const ON_InstanceRef& iref,
00820 ON_UUID iref_id,
00821 int idef_geometry_index
00822 )
00823 {
00824 bool rc = false;
00825
00826 if ( m__iref.Count() > 0 )
00827 {
00828
00829 if ( 0 == m__proxy2
00830 || 0 == m__proxy_ref_count
00831 || *m__proxy_ref_count <= 0 )
00832 {
00833 return false;
00834 }
00835 ON_Geometry* proxy_geo = ON_Geometry::Cast(m__proxy2);
00836 if ( !proxy_geo )
00837 return false;
00838 if ( !proxy_geo->Transform(iref.m_xform) )
00839 return false;
00840 rc = true;
00841 }
00842 else if ( ON_COMPONENT_INDEX::invalid_type == m_component_index.m_type )
00843 {
00844
00845 while ( m__proxy1 || m__proxy2 || m__proxy_ref_count )
00846 {
00847
00848 if ( 0 != m__proxy1
00849 && 0 == m__proxy2
00850 && 0 != m__proxy_ref_count
00851 && 1 == *m__proxy_ref_count
00852 && m__proxy1 != m_geometry
00853 && 0 != ON_Brep::Cast(m_geometry)
00854 )
00855 {
00856
00857
00858
00859
00860 break;
00861 }
00862 return false;
00863 }
00864
00865 if ( !m_geometry )
00866 {
00867 return false;
00868 }
00869 if ( m_geometry->ComponentIndex().m_type != ON_COMPONENT_INDEX::invalid_type )
00870 {
00871 return false;
00872 }
00873 if ( m_parent_geometry && m_geometry != m_parent_geometry )
00874 {
00875 return false;
00876 }
00877 ON_Geometry* proxy_geo = m_geometry->Duplicate();
00878 if ( !proxy_geo->Transform(iref.m_xform) )
00879 {
00880 delete proxy_geo;
00881 return false;
00882 }
00883
00884
00885
00886
00887
00888 SetProxy(0,proxy_geo,true);
00889 m_geometry = proxy_geo;
00890 m_parent_geometry = proxy_geo;
00891 rc = true;
00892 }
00893 else
00894 {
00895
00896
00897 if ( m__proxy2 )
00898 return false;
00899
00900 const ON_Brep* parent_brep = ON_BrepParent(m_parent_geometry);
00901 if ( !parent_brep)
00902 parent_brep = ON_BrepParent(m_geometry);
00903 if ( parent_brep )
00904 {
00905
00906 if ( m__proxy1 || m__proxy_ref_count )
00907 {
00908 return false;
00909 }
00910 if ( m_parent_geometry != parent_brep && 0 != m_parent_geometry )
00911 {
00912 return false;
00913 }
00914 if ( m_geometry != parent_brep->BrepComponent(m_component_index) )
00915 {
00916 return false;
00917 }
00918 ON_Brep* proxy_brep = parent_brep->Duplicate();
00919 if ( !proxy_brep->Transform(iref.m_xform) )
00920 {
00921 delete proxy_brep;
00922 return false;
00923 }
00924 const ON_Geometry* brep_component = proxy_brep->BrepComponent(m_component_index);
00925 if ( !brep_component )
00926 {
00927 delete brep_component;
00928 return false;
00929 }
00930 SetProxy(0,proxy_brep,true);
00931 m_geometry = brep_component;
00932 m_parent_geometry = proxy_brep;
00933 rc = true;
00934 }
00935 else
00936 {
00937 const ON_Mesh* parent_mesh = ON_MeshParent(m_parent_geometry);
00938 if ( !parent_mesh)
00939 parent_mesh = ON_MeshParent(m_geometry);
00940 if ( parent_mesh )
00941 {
00942
00943 switch(m_component_index.m_type)
00944 {
00945 case ON_COMPONENT_INDEX::mesh_vertex:
00946 case ON_COMPONENT_INDEX::meshtop_vertex:
00947 case ON_COMPONENT_INDEX::meshtop_edge:
00948 case ON_COMPONENT_INDEX::mesh_face:
00949 {
00950 if ( m_geometry->ComponentIndex() != m_component_index )
00951 return false;
00952 ON_Mesh* proxy_mesh = parent_mesh->Duplicate();
00953 if ( !proxy_mesh->Transform(iref.m_xform) )
00954 {
00955 delete proxy_mesh;
00956 return false;
00957 }
00958 ON_Geometry* proxy_component = proxy_mesh->MeshComponent(m_component_index);
00959 if( !proxy_component )
00960 {
00961 delete proxy_mesh;
00962 return false;
00963 }
00964 m_geometry = proxy_component;
00965 m_parent_geometry = proxy_mesh;
00966 SetProxy(proxy_component,proxy_mesh,true);
00967 rc = true;
00968 }
00969 break;
00970 default:
00971 return false;
00972 break;
00973 }
00974 }
00975 }
00976 }
00977
00978 if ( rc )
00979 {
00980
00981
00982
00983 ON_Xform geometry_xform(1.0);
00984 if ( m__iref.Count() > 0 )
00985 geometry_xform = m__iref.Last()->m_geometry_xform;
00986
00987 ON_ObjRef_IRefID& this_ref = m__iref.AppendNew();
00988 this_ref.m_iref_uuid = iref_id;
00989 this_ref.m_iref_xform = iref.m_xform;
00990 this_ref.m_idef_uuid = iref.m_instance_definition_uuid;
00991 this_ref.m_idef_geometry_index = idef_geometry_index;
00992 this_ref.m_geometry_xform = iref.m_xform*geometry_xform;
00993
00994 m_uuid = this_ref.m_iref_uuid;
00995 }
00996
00997 return rc;
00998 }
00999
01000 const ON_Object* ON_ObjRef::ProxyObject(int proxy_object_index) const
01001 {
01002 return ( (1 == proxy_object_index)
01003 ? m__proxy1
01004 : ((2==proxy_object_index) ? m__proxy2 : 0)
01005 );
01006 }
01007
01008 void ON_ObjRef::SetProxy(
01009 ON_Object* proxy1,
01010 ON_Object* proxy2,
01011 bool bCountReferences
01012 )
01013 {
01014 if ( m__proxy1 || m__proxy2 || m__proxy_ref_count )
01015 {
01016
01017
01018 DecrementProxyReferenceCount();
01019 }
01020
01021 m__proxy1 = proxy1;
01022 m__proxy2 = proxy2;
01023 if ( bCountReferences && (m__proxy1 || m__proxy2) )
01024 {
01025 m__proxy_ref_count = (int*)onmalloc_from_pool(
01026 ON_MainMemoryPool(),
01027 sizeof(*m__proxy_ref_count)
01028 );
01029 *m__proxy_ref_count = 1;
01030 }
01031 }
01032
01033 void ON_ObjRef::DecrementProxyReferenceCount()
01034 {
01035 if ( 0 != m__proxy_ref_count )
01036 {
01037 if (*m__proxy_ref_count > 1)
01038 {
01039
01040
01041
01042
01043 *m__proxy_ref_count = *m__proxy_ref_count - 1;
01044 }
01045 else if ( 1 == *m__proxy_ref_count )
01046 {
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057 *m__proxy_ref_count = 0;
01058 if ( m__proxy1 )
01059 {
01060
01061 delete m__proxy1;
01062 }
01063 if ( m__proxy2 )
01064 {
01065
01066 delete m__proxy2;
01067 }
01068 onfree(m__proxy_ref_count);
01069 }
01070 else
01071 {
01072
01073
01074
01075 ON_ERROR("ON_ObjRef::DecrementReferenceCount() *m__proxy_ref_count <= 0");
01076 }
01077 }
01078
01079
01080
01081 m__proxy_ref_count = 0;
01082 m__proxy1 = 0;
01083 m__proxy2 = 0;
01084 m_geometry = 0;
01085 }
01086
01087 ON_ObjRef_IRefID::ON_ObjRef_IRefID()
01088 : m_iref_uuid(ON_nil_uuid),
01089 m_iref_xform(0.0),
01090 m_idef_uuid(ON_nil_uuid),
01091 m_idef_geometry_index(0),
01092 m_geometry_xform(0.0)
01093 {
01094 }
01095
01096 void ON_ObjRef_IRefID::Default()
01097 {
01098 ON_ObjRef_IRefID d;
01099 *this = d;
01100 }
01101
01102 ON_ObjRef_IRefID::~ON_ObjRef_IRefID()
01103 {
01104 }
01105
01106