1 // Created on: 1993-03-09
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <MgtTopoDS.ixx>
24 #include <MgtTopLoc.hxx>
26 #include <PTopoDS_HShape.hxx>
27 #include <PTopoDS_TShape.hxx>
28 #include <PTopoDS_Shape1.hxx>
29 #include <PTopoDS_TShape1.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_TShape.hxx>
33 #include <TopoDS_Iterator.hxx>
35 #include <PTopoDS_HArray1OfHShape.hxx>
36 #include <PTopoDS_HArray1OfShape1.hxx>
38 #include <BRepTools.hxx>
40 #include <PTColStd_TransientPersistentMap.hxx>
41 #include <PTColStd_PersistentTransientMap.hxx>
44 #include <OSD_Timer.hxx>
45 extern OSD_Timer VertexTimer;
46 extern OSD_Timer EdgeTimer;
47 extern OSD_Timer WireTimer;
48 extern OSD_Timer FaceTimer;
49 extern OSD_Timer ShellTimer;
50 extern OSD_Timer SolidTimer;
51 extern OSD_Timer StoreEdgeTimer;
52 #define TIMER_START(THETIMER) THETIMER.Start()
53 #define TIMER_STOP(THETIMER) THETIMER.Stop()
55 #define TIMER_START(THETIMER)
56 #define TIMER_STOP(THETIMER)
59 //=======================================================================
60 //function : Translate
61 //purpose : Translation Transient Shape -> Persistent Shape
62 // Used for upwards compatibility.
63 //=======================================================================
65 Handle(PTopoDS_HShape) MgtTopoDS::Translate
66 (const TopoDS_Shape& aShape,
67 const Handle(MgtTopoDS_TranslateTool)& TrTool,
68 PTColStd_TransientPersistentMap &aMap)
71 return new PTopoDS_HShape();
73 // Translate the top-level shape
74 Handle(PTopoDS_HShape) pHShape = new PTopoDS_HShape();
76 Standard_Boolean translated = aMap.IsBound(aShape.TShape());
78 // get the translated TShape
80 Handle(Standard_Persistent) aPers = aMap.Find(aShape.TShape());
81 Handle(PTopoDS_TShape)& pTS = (Handle(PTopoDS_TShape)&) aPers;
87 // create if not translated and update
89 switch (aShape.ShapeType()) {
92 TrTool->MakeVertex(pHShape);
93 TrTool->UpdateVertex(aShape,pHShape, aMap);
98 StoreEdgeTimer.Start();
100 TrTool->MakeEdge(pHShape);
101 TrTool->UpdateEdge(aShape,pHShape, aMap);
103 StoreEdgeTimer.Stop();
108 TrTool->MakeWire(pHShape);
109 //TrTool.UpdateWire(aShape,pHShape);
110 TrTool->UpdateShape(aShape,pHShape);
114 TrTool->MakeFace(pHShape);
115 TrTool->UpdateFace(aShape,pHShape, aMap);
119 TrTool->MakeShell(pHShape);
120 //TrTool.UpdateShell(aShape,pHShape);
121 TrTool->UpdateShape(aShape,pHShape);
125 TrTool->MakeSolid(pHShape);
126 //TrTool.UpdateSolid(aShape,pHShape);
127 TrTool->UpdateShape(aShape,pHShape);
130 case TopAbs_COMPSOLID :
131 TrTool->MakeCompSolid(pHShape);
132 //TrTool.UpdateCompSolid(aShape,pHShape);
133 TrTool->UpdateShape(aShape,pHShape);
136 case TopAbs_COMPOUND :
137 TrTool->MakeCompound(pHShape);
138 //TrTool.UpdateCompound(aShape,pHShape);
139 TrTool->UpdateShape(aShape,pHShape);
147 // bind and copy the sub-elements
149 aMap.Bind(aShape.TShape(),pHShape->TShape());
150 // copy current Shape
151 TopoDS_Shape S = aShape;
152 S.Orientation(TopAbs_FORWARD);
153 S.Location(TopLoc_Location());
154 // count the number of <sub-shape> of the Shape's TShape
155 Standard_Integer nbElem = 0;
156 TopoDS_Iterator ItCount(S);
157 while (ItCount.More()){
163 Handle(PTopoDS_HArray1OfHShape) myArray =
164 new PTopoDS_HArray1OfHShape(1,nbElem);
165 // translate <sub-shapes>
166 TopoDS_Iterator ItTrans(S);
167 Standard_Integer i = 1;
168 while(ItTrans.More()) {
169 myArray->SetValue(i, MgtTopoDS::Translate(ItTrans.Value(),
174 pHShape->TShape()->Shapes(myArray);
179 pHShape->Orientation(aShape.Orientation());
180 pHShape->Location(MgtTopLoc::Translate(aShape.Location(), aMap));
185 //=======================================================================
186 //function : Translate
187 //purpose : Translation Persistent HShape -> Transient Shape
188 // Used for upwards compatibility.
189 //=======================================================================
191 void MgtTopoDS::Translate
192 (const Handle(PTopoDS_HShape)& aHShape,
193 const Handle(MgtTopoDS_TranslateTool)& TrTool,
194 PTColStd_PersistentTransientMap& aMap,
195 TopoDS_Shape& theShape)
197 if (aHShape->TShape().IsNull()) return;
199 // Translate the top-level shape
200 #ifndef DEB // Linux porting - to avoid warnings
201 if ( aMap.IsBound(aHShape->TShape()) ) {
203 Standard_Boolean translated = aMap.IsBound(aHShape->TShape());
206 // get the translated TShape
207 Handle(TopoDS_TShape) TS =
208 *((Handle(TopoDS_TShape)*) &aMap.Find(aHShape->TShape()));
213 // create if not translated and update
214 switch (aHShape->TShape()->ShapeType()) {
217 TIMER_START(VertexTimer);
218 TrTool->MakeVertex(theShape);
219 TrTool->UpdateVertex(aHShape,theShape, aMap);
220 TIMER_STOP(VertexTimer);
224 TIMER_START(EdgeTimer);
225 TrTool->MakeEdge(theShape);
226 TrTool->UpdateEdge(aHShape,theShape, aMap);
227 TIMER_STOP(EdgeTimer);
231 TIMER_START(WireTimer);
232 TrTool->MakeWire(theShape);
233 //TrTool.UpdateWire(aHShape,theShape);
234 TrTool->UpdateShape(aHShape,theShape);
235 TIMER_STOP(WireTimer);
239 TIMER_START(FaceTimer);
240 TrTool->MakeFace(theShape);
241 TrTool->UpdateFace(aHShape,theShape, aMap);
242 TIMER_STOP(FaceTimer);
246 TIMER_START(ShellTimer);
247 TrTool->MakeShell(theShape);
248 //TrTool.UpdateShell(aHShape,theShape);
249 TrTool->UpdateShape(aHShape,theShape);
250 TIMER_STOP(ShellTimer);
254 TIMER_START(SolidTimer);
255 TrTool->MakeSolid(theShape);
256 //TrTool.UpdateSolid(aHShape,theShape);
257 TrTool->UpdateShape(aHShape,theShape);
258 TIMER_STOP(SolidTimer);
261 case TopAbs_COMPSOLID :
262 TrTool->MakeCompSolid(theShape);
263 //TrTool.UpdateCompSolid(aHShape,theShape);
264 TrTool->UpdateShape(aHShape,theShape);
267 case TopAbs_COMPOUND :
268 TrTool->MakeCompound(theShape);
269 //TrTool.UpdateCompound(aHShape,theShape);
270 TrTool->UpdateShape(aHShape,theShape);
278 // bind and copy the sub-elements
280 Standard_Boolean wasFree = theShape.Free();
281 theShape.Free(Standard_True);
282 aMap.Bind(aHShape->TShape(), theShape.TShape());
283 // count the number of <sub-shape> of the Shape's TShape
284 // Is there any sub-shape
285 if (!aHShape->TShape()->Shapes().IsNull()) {
286 #ifndef DEB // Linux porting - to avoid warnings
287 for (Standard_Integer i = 1 ; i<= aHShape->TShape()->Shapes()->Length(); i++) {
289 Standard_Integer nbElem = aHShape->TShape()->Shapes()->Length();
290 for (Standard_Integer i = 1 ; i<=nbElem ; i++) {
292 TopoDS_Shape subShape;
293 MgtTopoDS::Translate(aHShape->TShape()->Shapes(i),
294 TrTool, aMap, subShape);
295 TrTool->Add(theShape,subShape);
298 theShape.Free(wasFree);
301 theShape.Orientation(aHShape->Orientation());
302 theShape.Location(MgtTopLoc::Translate(aHShape->Location(), aMap));
306 //=======================================================================
307 //function : Translate1
308 //purpose : Translation Transient Shape1 -> Persistent Shape
309 //=======================================================================
311 void MgtTopoDS::Translate1
312 (const TopoDS_Shape& aShape,
313 const Handle(MgtTopoDS_TranslateTool1)& TrTool,
314 PTColStd_TransientPersistentMap &aMap,
315 PTopoDS_Shape1& aPShape)
317 if (aShape.IsNull()) return;
319 if (aMap.IsBound(aShape.TShape())) {
320 // get the translated TShape
321 Handle(PTopoDS_TShape1) pTS =
322 *((Handle(PTopoDS_TShape1)*) &aMap.Find(aShape.TShape()));
327 // create if not translated and update
329 switch (aShape.ShapeType()) {
332 TrTool->MakeVertex(aPShape);
333 TrTool->UpdateVertex(aShape,aPShape,aMap);
337 TIMER_START(StoreEdgeTimer);
338 TrTool->MakeEdge(aPShape);
339 TrTool->UpdateEdge(aShape,aPShape,aMap);
340 TIMER_STOP(StoreEdgeTimer);
344 TrTool->MakeWire(aPShape);
345 TrTool->UpdateShape(aShape,aPShape);
349 TrTool->MakeFace(aPShape);
350 TrTool->UpdateFace(aShape,aPShape,aMap);
354 TrTool->MakeShell(aPShape);
355 TrTool->UpdateShape(aShape,aPShape);
359 TrTool->MakeSolid(aPShape);
360 TrTool->UpdateShape(aShape,aPShape);
363 case TopAbs_COMPSOLID :
364 TrTool->MakeCompSolid(aPShape);
365 TrTool->UpdateShape(aShape,aPShape);
368 case TopAbs_COMPOUND :
369 TrTool->MakeCompound(aPShape);
370 TrTool->UpdateShape(aShape,aPShape);
378 // bind and copy the sub-elements
379 aMap.Bind(aShape.TShape(),aPShape.TShape());
380 // copy current Shape
381 TopoDS_Shape S = aShape;
382 S.Orientation(TopAbs_FORWARD);
383 S.Location(TopLoc_Location());
384 // count the number of <sub-shape> of the Shape's TShape
385 Standard_Integer nbElem = 0;
386 TopoDS_Iterator itr(S);
387 for (;itr.More();++nbElem,itr.Next());
390 Handle(PTopoDS_HArray1OfShape1) myArray =
391 new PTopoDS_HArray1OfShape1(1,nbElem);
392 // translate <sub-shapes>
396 for (itr.Initialize(S);itr.More();++nbElem,itr.Next()) {
397 MgtTopoDS::Translate1(itr.Value(),TrTool,aMap,pSh);
398 myArray->SetValue(nbElem,pSh);
401 aPShape.TShape()->Shapes(myArray);
406 aPShape.Orientation(aShape.Orientation());
407 aPShape.Location(MgtTopLoc::Translate(aShape.Location(), aMap));
411 //=======================================================================
412 //function : Translate1
413 //purpose : Translation Persistent Shape -> Transient Shape
414 //=======================================================================
416 void MgtTopoDS::Translate1
417 (const PTopoDS_Shape1& aPShape,
418 const Handle(MgtTopoDS_TranslateTool1)& TrTool,
419 PTColStd_PersistentTransientMap& aMap,
420 TopoDS_Shape& aShape)
422 if (aPShape.TShape().IsNull()) return;
424 // Translate the top-level shape
425 if (aMap.IsBound(aPShape.TShape())) {
426 // get the translated TShape
427 Handle(TopoDS_TShape) TS =
428 *((Handle(TopoDS_TShape)*) &aMap.Find(aPShape.TShape()));
433 // create if not translated and update
435 switch (aPShape.TShape()->ShapeType()) {
438 TIMER_START(VertexTimer);
439 TrTool->MakeVertex(aShape);
440 TrTool->UpdateVertex(aPShape,aShape, aMap);
441 TIMER_STOP(VertexTimer);
445 TIMER_START(EdgeTimer);
446 TrTool->MakeEdge(aShape);
447 TrTool->UpdateEdge(aPShape,aShape, aMap);
448 TIMER_STOP(EdgeTimer);
452 TIMER_START(WireTimer);
453 TrTool->MakeWire(aShape);
454 //TrTool.UpdateWire(aPShape,aShape);
455 TrTool->UpdateShape(aPShape,aShape);
456 TIMER_STOP(WireTimer);
460 TIMER_START(FaceTimer);
461 TrTool->MakeFace(aShape);
462 TrTool->UpdateFace(aPShape,aShape, aMap);
463 TIMER_STOP(FaceTimer);
467 TIMER_START(ShellTimer);
468 TrTool->MakeShell(aShape);
469 //TrTool.UpdateShell(aPShape,aShape);
470 TrTool->UpdateShape(aPShape,aShape);
471 TIMER_STOP(ShellTimer);
475 TIMER_START(SolidTimer);
476 TrTool->MakeSolid(aShape);
477 //TrTool.UpdateSolid(aPShape,aShape);
478 TrTool->UpdateShape(aPShape,aShape);
479 TIMER_STOP(SolidTimer);
482 case TopAbs_COMPSOLID :
483 TrTool->MakeCompSolid(aShape);
484 //TrTool.UpdateCompSolid(aPShape,aShape);
485 TrTool->UpdateShape(aPShape,aShape);
488 case TopAbs_COMPOUND :
489 TrTool->MakeCompound(aShape);
490 //TrTool.UpdateCompound(aPShape,aShape);
491 TrTool->UpdateShape(aPShape,aShape);
499 // bind and copy the sub-elements
501 Standard_Boolean wasFree = aShape.Free();
502 aShape.Free(Standard_True);
503 aMap.Bind(aPShape.TShape(), aShape.TShape());
504 // count the number of <sub-shape> of the Shape's TShape
505 // Is there any sub-shape
506 if (!aPShape.TShape()->Shapes().IsNull()) {
507 Standard_Integer nbElem = aPShape.TShape()->Shapes()->Length();
508 for (Standard_Integer i = 1 ; i<=nbElem ; i++) {
509 TopoDS_Shape subShape;
510 MgtTopoDS::Translate1(aPShape.TShape()->Shapes(i),
513 TrTool->Add(aShape,subShape);
516 aShape.Free(wasFree);
519 aShape.Orientation(aPShape.Orientation());
520 aShape.Location(MgtTopLoc::Translate(aPShape.Location(), aMap));