1 // Created on: 1999-06-24
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 1999-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 <TNaming_TranslateTool.ixx>
24 #include <BRep_Builder.hxx>
26 #include <BRep_TVertex.hxx>
27 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
28 #include <BRep_ListOfPointRepresentation.hxx>
29 #include <BRep_PointRepresentation.hxx>
30 #include <BRep_PointOnCurve.hxx>
31 #include <BRep_PointOnCurveOnSurface.hxx>
32 #include <TNaming_CopyShape.hxx>
33 #include <BRep_TFace.hxx>
34 #include <BRep_TEdge.hxx>
35 #include <BRep_PointOnSurface.hxx>
36 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
37 #include <BRep_ListOfCurveRepresentation.hxx>
38 #include <BRep_CurveRepresentation.hxx>
39 #include <BRep_GCurve.hxx>
40 #include <BRep_Curve3D.hxx>
41 #include <BRep_CurveOnSurface.hxx>
42 #include <BRep_CurveOnClosedSurface.hxx>
43 #include <BRep_CurveOn2Surfaces.hxx>
44 #include <BRep_Polygon3D.hxx>
45 #include <BRep_PolygonOnClosedSurface.hxx>
46 #include <BRep_PolygonOnSurface.hxx>
47 #include <BRep_PolygonOnClosedTriangulation.hxx>
48 #include <BRep_PolygonOnTriangulation.hxx>
49 #include <Standard_NullObject.hxx>
52 //=======================================================================
53 //function : TNaming_TranslateTool
56 //=======================================================================
58 //TNaming_TranslateTool::TNaming_TranslateTool
59 //(const MgtBRep_TriangleMode aTriMode) :
60 //myTriangleMode(aTriMode)
64 //=======================================================================
66 //purpose : Adds S2 in S1
67 //=======================================================================
69 void TNaming_TranslateTool::Add(TopoDS_Shape& S1,
70 const TopoDS_Shape& S2) const
76 //=======================================================================
77 //function : MakeVertex
79 //=======================================================================
81 void TNaming_TranslateTool::MakeVertex(TopoDS_Shape& S) const
84 B.MakeVertex(TopoDS::Vertex(S));
87 //=======================================================================
90 //=======================================================================
92 void TNaming_TranslateTool::MakeEdge(TopoDS_Shape& S) const
95 B.MakeEdge(TopoDS::Edge(S));
98 //=======================================================================
101 //=======================================================================
103 void TNaming_TranslateTool::MakeWire(TopoDS_Shape& S) const
106 B.MakeWire(TopoDS::Wire(S));
109 //=======================================================================
110 //function : MakeFace
112 //=======================================================================
114 void TNaming_TranslateTool::MakeFace(TopoDS_Shape& S) const
117 B.MakeFace(TopoDS::Face(S));
120 //=======================================================================
121 //function : MakeShell
123 //=======================================================================
125 void TNaming_TranslateTool::MakeShell(TopoDS_Shape& S) const
128 B.MakeShell(TopoDS::Shell(S));
131 //=======================================================================
132 //function : MakeSolid
134 //=======================================================================
136 void TNaming_TranslateTool::MakeSolid(TopoDS_Shape& S) const
139 B.MakeSolid(TopoDS::Solid(S));
142 //=======================================================================
143 //function : MakeCompSolid
145 //=======================================================================
147 void TNaming_TranslateTool::MakeCompSolid(TopoDS_Shape& S) const
150 B.MakeCompSolid(TopoDS::CompSolid(S));
153 //=======================================================================
154 //function : MakeCompound
156 //=======================================================================
158 void TNaming_TranslateTool::MakeCompound(TopoDS_Shape& S) const
161 B.MakeCompound(TopoDS::Compound(S));
164 //=======================================================================
166 //=======================================================================
167 //function : UpdateVertex
169 //=======================================================================
171 void TNaming_TranslateTool::UpdateVertex
172 (const TopoDS_Shape& S1,
174 TColStd_IndexedDataMapOfTransientTransient& aMap) const
176 const Handle(BRep_TVertex)& TTV1 = *((Handle(BRep_TVertex)*) &(S1.TShape()));
177 const Handle(BRep_TVertex)& TTV2 = *((Handle(BRep_TVertex)*) &(S2.TShape()));
180 TTV2->Pnt(TTV1->Pnt());
183 TTV2->Tolerance(TTV1->Tolerance());
186 BRep_ListIteratorOfListOfPointRepresentation itpr(TTV1->Points());
187 // cout << "Vertex List Extent = "<< TTV1->Points().Extent()<< endl;// == 0 ???
188 BRep_ListOfPointRepresentation& lpr = TTV2->ChangePoints();
191 while (itpr.More()) {
193 const Handle(BRep_PointRepresentation)& PR1 = itpr.Value();
194 Handle(BRep_PointRepresentation) PR2;
196 if (PR1->IsPointOnCurve()) { // pointOnCurve (1)
197 Handle(BRep_PointOnCurve) OC =
198 new BRep_PointOnCurve(PR1->Parameter(), // the same geometry
199 PR1->Curve(), // the same geometry
200 TNaming_CopyShape::Translate(PR1->Location(), aMap));
204 else if (PR1->IsPointOnCurveOnSurface()) { // PointOnCurveOnSurface (2)
206 Handle(BRep_PointOnCurveOnSurface) OCS =
207 new BRep_PointOnCurveOnSurface(PR1->Parameter(),
210 TNaming_CopyShape::Translate(PR1->Location(), aMap));
214 else if (PR1->IsPointOnSurface()) { // PointOnSurface (3)
216 Handle(BRep_PointOnSurface) OS =
217 new BRep_PointOnSurface(PR1->Parameter(),
220 TNaming_CopyShape::Translate(PR1->Location(), aMap));
233 //=======================================================================
234 //function : UpdateEdge
235 //purpose : Transient->Transient
236 //=======================================================================
238 void TNaming_TranslateTool::UpdateEdge
239 (const TopoDS_Shape& S1,
241 TColStd_IndexedDataMapOfTransientTransient& aMap) const
243 const Handle(BRep_TEdge)& TTE1 = *((Handle(BRep_TEdge)*) &(S1.TShape()));
244 const Handle(BRep_TEdge)& TTE2 = *((Handle(BRep_TEdge)*) &(S2.TShape()));
245 // tolerance TopLoc_Location
246 TTE2->Tolerance(TTE1->Tolerance());
249 TTE2->SameParameter(TTE1->SameParameter());
252 TTE2->SameRange(TTE1->SameRange());
255 TTE2->Degenerated(TTE1->Degenerated());
258 BRep_ListIteratorOfListOfCurveRepresentation itcr(TTE1->Curves());
259 BRep_ListOfCurveRepresentation& lcr = TTE2->ChangeCurves();
261 Handle(BRep_CurveRepresentation) CR;
263 Handle(BRep_GCurve) GC;
265 while (itcr.More()) {
267 const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
268 Handle(BRep_CurveRepresentation) CR2;
270 GC = Handle(BRep_GCurve)::DownCast(CR);
271 if (!GC.IsNull()) { // (1)
273 // CurveRepresentation is Curve3D - (1a)
274 if (CR->IsCurve3D()) {
276 CR2 = (Handle(BRep_Curve3D)::DownCast(GC))->Copy();
280 // CurveRepresentation is CurveOnSurface - (1b)
281 else if (CR->IsCurveOnSurface()) {
283 if (!CR->IsCurveOnClosedSurface()) { // -(1b1) -if not closed surface
285 // CurveRepresentation is a PBRep_CurveOnSurface
286 CR2 = (Handle(BRep_CurveOnSurface)::DownCast(GC))->Copy();
290 // CurveRepresentation is CurveOnClosedSurface -(1b2)
291 CR2 = (Handle(BRep_CurveOnClosedSurface)::DownCast(GC))->Copy();
295 (Handle(BRep_GCurve)::DownCast(CR2))->SetRange(f, l);
298 // CurveRepresentation is CurveOn2Surfaces (2:)
299 else if (CR->IsRegularity()) {
301 CR2 = (Handle(BRep_CurveOn2Surfaces)::DownCast(CR))->Copy();
302 TopLoc_Location L2 = TNaming_CopyShape::Translate(CR->Location2(), aMap);
306 // CurveRepresentation is Polygon or Triangulation (3:)
307 // else if (myTriangleMode == MgtBRep_WithTriangle) {
309 // CurveRepresentation is Polygon3D (3a)
310 else if (CR->IsPolygon3D()) {
312 CR2 = (Handle(BRep_Polygon3D)::DownCast(CR))->Copy();
315 // CurveRepresentation is PolygonOnSurface - (3b)
316 else if (CR->IsPolygonOnSurface()) {
318 // CurveRepresentation is PolygonOnClosedSurface - (3b1)
319 if (CR->IsPolygonOnClosedSurface()) {
321 CR2 = (Handle(BRep_PolygonOnClosedSurface)::DownCast(CR))->Copy();
324 // CurveRepresentation is PolygonOnSurface - (3b2)
327 CR2 = (Handle(BRep_PolygonOnSurface)::DownCast(CR))->Copy();
332 // CurveRepresentation is PolygonOnTriangulation - (3c)
333 else if (CR->IsPolygonOnTriangulation()) {
335 // CurveRepresentation is PolygonOnClosedTriangulation
336 if (CR->IsPolygonOnClosedTriangulation()) { // (3c1)
338 CR2 = (Handle(BRep_PolygonOnClosedTriangulation)::DownCast(CR))->Copy();
341 // CurveRepresentation is PolygonOnTriangulation - (3c2)
344 CR2 = (Handle(BRep_PolygonOnTriangulation)::DownCast(CR))->Copy();
349 // jumps the curve representation
354 TopLoc_Location L = TNaming_CopyShape::Translate(CR->Location(), aMap);
357 Standard_NullObject_Raise_if (CR2.IsNull(), "Null CurveRepresentation");
359 // lcr.Prepend(CR2); // add
368 //=======================================================================
369 //function : UpdateFace
370 //purpose : Transient->Transient
371 //=======================================================================
373 void TNaming_TranslateTool::UpdateFace
374 (const TopoDS_Shape& S1,
376 TColStd_IndexedDataMapOfTransientTransient& aMap) const
378 const Handle(BRep_TFace)& TTF1 = *((Handle(BRep_TFace)*) &(S1.TShape()));
379 const Handle(BRep_TFace)& TTF2 = *((Handle(BRep_TFace)*) &(S2.TShape()));
381 // natural restriction
382 TTF2->NaturalRestriction(TTF1->NaturalRestriction());
385 TTF2->Tolerance(TTF1->Tolerance());
388 TTF2->Location(TNaming_CopyShape::Translate(TTF1->Location(), aMap));
391 TTF2->Surface(TTF1->Surface());
394 // if (myTriangleMode == MgtBRep_WithTriangle) {
395 TTF2->Triangulation(TTF1->Triangulation());
402 //=======================================================================
403 //function : UpdateShape
405 //=======================================================================
407 void TNaming_TranslateTool::UpdateShape
408 (const TopoDS_Shape& S1, TopoDS_Shape& S2) const
410 // Transfer the flags
411 S2.TShape()->Free(S1.TShape()->Free());
412 S2.TShape()->Modified(S1.TShape()->Modified());
413 S2.TShape()->Checked(S1.TShape()->Checked());
414 S2.TShape()->Orientable(S1.TShape()->Orientable());
415 S2.TShape()->Closed(S1.TShape()->Closed());
416 S2.TShape()->Infinite(S1.TShape()->Infinite());
417 S2.TShape()->Convex(S1.TShape()->Convex());