0023024: Update headers of OCCT files
[occt.git] / src / TNaming / TNaming_TranslateTool.cxx
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
5 //
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.
10 //
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.
13 //
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.
20
21
22
23 #include <TNaming_TranslateTool.ixx>
24 #include <BRep_Builder.hxx>
25 #include <TopoDS.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>
50
51
52 //=======================================================================
53 //function : TNaming_TranslateTool
54
55 //purpose  : 
56 //=======================================================================
57
58 //TNaming_TranslateTool::TNaming_TranslateTool
59 //(const MgtBRep_TriangleMode aTriMode) : 
60 //myTriangleMode(aTriMode)
61 //{
62 //}
63
64 //=======================================================================
65 //function : Add
66 //purpose  : Adds S2 in S1
67 //=======================================================================
68
69 void TNaming_TranslateTool::Add(TopoDS_Shape& S1,
70                                 const TopoDS_Shape& S2) const 
71 {
72   BRep_Builder B;
73   B.Add(S1,S2);
74 }
75
76 //=======================================================================
77 //function : MakeVertex
78 //purpose  : 
79 //=======================================================================
80
81 void  TNaming_TranslateTool::MakeVertex(TopoDS_Shape& S) const 
82 {
83   BRep_Builder B;
84   B.MakeVertex(TopoDS::Vertex(S));
85 }
86
87 //=======================================================================
88 //function : MakeEdge
89 //purpose  : 
90 //=======================================================================
91
92 void  TNaming_TranslateTool::MakeEdge(TopoDS_Shape& S) const 
93 {
94   BRep_Builder B;
95   B.MakeEdge(TopoDS::Edge(S));
96 }
97
98 //=======================================================================
99 //function : MakeWire
100 //purpose  : 
101 //=======================================================================
102
103 void  TNaming_TranslateTool::MakeWire(TopoDS_Shape& S) const 
104 {
105   BRep_Builder B;
106   B.MakeWire(TopoDS::Wire(S));
107 }
108
109 //=======================================================================
110 //function : MakeFace
111 //purpose  : 
112 //=======================================================================
113
114 void  TNaming_TranslateTool::MakeFace(TopoDS_Shape& S) const 
115 {
116   BRep_Builder B;
117   B.MakeFace(TopoDS::Face(S));
118 }
119
120 //=======================================================================
121 //function : MakeShell
122 //purpose  : 
123 //=======================================================================
124
125 void  TNaming_TranslateTool::MakeShell(TopoDS_Shape& S) const 
126 {
127   BRep_Builder B;
128   B.MakeShell(TopoDS::Shell(S));
129 }
130
131 //=======================================================================
132 //function : MakeSolid
133 //purpose  : 
134 //=======================================================================
135
136 void  TNaming_TranslateTool::MakeSolid(TopoDS_Shape& S) const 
137 {
138   BRep_Builder B;
139   B.MakeSolid(TopoDS::Solid(S));
140 }
141
142 //=======================================================================
143 //function : MakeCompSolid
144 //purpose  : 
145 //=======================================================================
146
147 void  TNaming_TranslateTool::MakeCompSolid(TopoDS_Shape& S) const 
148 {
149   BRep_Builder B;
150   B.MakeCompSolid(TopoDS::CompSolid(S));
151 }
152
153 //=======================================================================
154 //function : MakeCompound
155 //purpose  : 
156 //=======================================================================
157
158 void  TNaming_TranslateTool::MakeCompound(TopoDS_Shape& S) const 
159 {
160   BRep_Builder B;
161   B.MakeCompound(TopoDS::Compound(S));
162 }
163
164 //=======================================================================
165 // Update methods
166 //=======================================================================
167 //function : UpdateVertex
168 //purpose  : 
169 //=======================================================================
170
171 void TNaming_TranslateTool::UpdateVertex
172 (const TopoDS_Shape& S1,
173        TopoDS_Shape& S2,
174  TColStd_IndexedDataMapOfTransientTransient& aMap) const 
175 {
176   const Handle(BRep_TVertex)& TTV1 = *((Handle(BRep_TVertex)*) &(S1.TShape()));
177   const Handle(BRep_TVertex)& TTV2 = *((Handle(BRep_TVertex)*) &(S2.TShape()));
178
179   // Point
180   TTV2->Pnt(TTV1->Pnt());
181
182   // Tolerance
183   TTV2->Tolerance(TTV1->Tolerance());
184
185   // Representations
186   BRep_ListIteratorOfListOfPointRepresentation itpr(TTV1->Points());
187 //  cout << "Vertex List Extent = "<<  TTV1->Points().Extent()<< endl;//  == 0 ???
188   BRep_ListOfPointRepresentation& lpr = TTV2->ChangePoints();
189   lpr.Clear();
190
191   while (itpr.More()) {
192
193     const Handle(BRep_PointRepresentation)& PR1 = itpr.Value();
194     Handle(BRep_PointRepresentation) PR2;
195     
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));
201       PR2 = OC;
202     }
203
204     else if (PR1->IsPointOnCurveOnSurface()) { // PointOnCurveOnSurface (2)
205
206       Handle(BRep_PointOnCurveOnSurface) OCS =
207         new BRep_PointOnCurveOnSurface(PR1->Parameter(),
208                                        PR1->PCurve(),
209                                        PR1->Surface(),
210                                        TNaming_CopyShape::Translate(PR1->Location(), aMap));
211       PR2 = OCS;
212     }
213
214     else if (PR1->IsPointOnSurface()) { // PointOnSurface (3)
215       
216       Handle(BRep_PointOnSurface) OS =
217         new BRep_PointOnSurface(PR1->Parameter(),
218                                 PR1->Parameter2(),
219                                 PR1->Surface(),
220                                 TNaming_CopyShape::Translate(PR1->Location(), aMap));
221       PR2 = OS;
222     }
223     
224 //    lpr.Prepend(PR2);
225     lpr.Append(PR2);
226     itpr.Next();
227   }
228   
229   UpdateShape(S1,S2);
230
231 }
232
233 //=======================================================================
234 //function : UpdateEdge
235 //purpose  : Transient->Transient
236 //=======================================================================
237
238 void TNaming_TranslateTool::UpdateEdge
239 (const TopoDS_Shape& S1,
240        TopoDS_Shape& S2,
241  TColStd_IndexedDataMapOfTransientTransient& aMap) const 
242 {
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());
247   
248   // same parameter
249   TTE2->SameParameter(TTE1->SameParameter());
250
251   // same range
252   TTE2->SameRange(TTE1->SameRange());
253
254   // Degenerated
255   TTE2->Degenerated(TTE1->Degenerated());
256   
257   // Representations
258   BRep_ListIteratorOfListOfCurveRepresentation itcr(TTE1->Curves());
259   BRep_ListOfCurveRepresentation& lcr = TTE2->ChangeCurves();
260   lcr.Clear();
261   Handle(BRep_CurveRepresentation) CR;
262
263   Handle(BRep_GCurve) GC;
264   Standard_Real f, l;
265   while (itcr.More()) {
266
267     const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
268     Handle(BRep_CurveRepresentation) CR2;
269
270     GC = Handle(BRep_GCurve)::DownCast(CR);
271     if (!GC.IsNull()) { // (1)
272       GC->Range(f, l);      
273       // CurveRepresentation is Curve3D - (1a)
274       if (CR->IsCurve3D()) { 
275         
276         CR2 = (Handle(BRep_Curve3D)::DownCast(GC))->Copy();
277         
278       } 
279       
280       // CurveRepresentation is CurveOnSurface - (1b)
281       else if (CR->IsCurveOnSurface()) { 
282
283         if (!CR->IsCurveOnClosedSurface()) { // -(1b1) -if not closed surface
284
285           // CurveRepresentation is a PBRep_CurveOnSurface
286           CR2 = (Handle(BRep_CurveOnSurface)::DownCast(GC))->Copy();
287         } 
288         
289         else { 
290           // CurveRepresentation is CurveOnClosedSurface -(1b2)
291           CR2 = (Handle(BRep_CurveOnClosedSurface)::DownCast(GC))->Copy();
292         }       
293       } 
294
295       (Handle(BRep_GCurve)::DownCast(CR2))->SetRange(f, l);
296     }
297     
298     // CurveRepresentation is CurveOn2Surfaces (2:)
299     else if (CR->IsRegularity()) {
300       
301       CR2 = (Handle(BRep_CurveOn2Surfaces)::DownCast(CR))->Copy();
302       TopLoc_Location L2 = TNaming_CopyShape::Translate(CR->Location2(), aMap);
303       CR2->Location(L2);
304     }
305     
306     // CurveRepresentation is Polygon or Triangulation  (3:)
307 //    else if (myTriangleMode == MgtBRep_WithTriangle) {
308       
309       // CurveRepresentation is Polygon3D (3a)
310     else if (CR->IsPolygon3D()) { 
311       
312       CR2 = (Handle(BRep_Polygon3D)::DownCast(CR))->Copy();
313     }
314
315       // CurveRepresentation is PolygonOnSurface - (3b)
316     else if (CR->IsPolygonOnSurface()) {
317       
318       // CurveRepresentation is PolygonOnClosedSurface - (3b1)
319       if (CR->IsPolygonOnClosedSurface()) {
320         
321         CR2 = (Handle(BRep_PolygonOnClosedSurface)::DownCast(CR))->Copy();
322       }
323       
324       // CurveRepresentation is PolygonOnSurface -  (3b2)
325       else {
326         
327           CR2 = (Handle(BRep_PolygonOnSurface)::DownCast(CR))->Copy();
328           
329         }
330     } 
331
332       // CurveRepresentation is PolygonOnTriangulation - (3c)
333     else if (CR->IsPolygonOnTriangulation()) {
334
335       // CurveRepresentation is PolygonOnClosedTriangulation
336       if (CR->IsPolygonOnClosedTriangulation()) { // (3c1)
337         
338         CR2 = (Handle(BRep_PolygonOnClosedTriangulation)::DownCast(CR))->Copy();
339       }
340       
341       // CurveRepresentation is PolygonOnTriangulation - (3c2)
342       else {
343         
344         CR2 = (Handle(BRep_PolygonOnTriangulation)::DownCast(CR))->Copy();
345       } 
346     }
347 //    }
348     else {
349       // jumps the curve representation
350       itcr.Next();
351       continue;
352     }
353     
354     TopLoc_Location L = TNaming_CopyShape::Translate(CR->Location(), aMap);
355     CR2->Location(L);
356     
357     Standard_NullObject_Raise_if (CR2.IsNull(), "Null CurveRepresentation");
358     
359 //    lcr.Prepend(CR2); // add
360     lcr.Append(CR2);
361     itcr.Next(); 
362   }
363   
364   UpdateShape(S1,S2);
365 }
366
367
368 //=======================================================================
369 //function : UpdateFace
370 //purpose  : Transient->Transient
371 //=======================================================================
372
373 void TNaming_TranslateTool::UpdateFace
374 (const TopoDS_Shape& S1, 
375        TopoDS_Shape& S2,
376  TColStd_IndexedDataMapOfTransientTransient& aMap) const 
377 {
378   const Handle(BRep_TFace)&  TTF1 = *((Handle(BRep_TFace)*) &(S1.TShape()));
379   const Handle(BRep_TFace)&  TTF2 = *((Handle(BRep_TFace)*) &(S2.TShape()));
380
381   // natural restriction
382   TTF2->NaturalRestriction(TTF1->NaturalRestriction());
383
384   // tolerance
385   TTF2->Tolerance(TTF1->Tolerance());
386
387   // location
388   TTF2->Location(TNaming_CopyShape::Translate(TTF1->Location(), aMap));
389
390   // surface
391   TTF2->Surface(TTF1->Surface());
392
393   // Triangulation
394  // if (myTriangleMode == MgtBRep_WithTriangle) { 
395   TTF2->Triangulation(TTF1->Triangulation());
396   //  }
397   
398   UpdateShape(S1,S2);
399
400 }
401
402 //=======================================================================
403 //function : UpdateShape
404 //purpose  : 
405 //=======================================================================
406
407 void TNaming_TranslateTool::UpdateShape
408   (const TopoDS_Shape& S1, TopoDS_Shape& S2) const
409 {
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()); 
418 }