0024023: Revamp the OCCT Handle -- ambiguity
[occt.git] / src / TNaming / TNaming_TranslateTool.cxx
CommitLineData
b311480e 1// Created on: 1999-06-24
2// Created by: Sergey ZARITCHNY
3// Copyright (c) 1999-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <TNaming_TranslateTool.ixx>
18#include <BRep_Builder.hxx>
19#include <TopoDS.hxx>
20#include <BRep_TVertex.hxx>
21#include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
22#include <BRep_ListOfPointRepresentation.hxx>
23#include <BRep_PointRepresentation.hxx>
24#include <BRep_PointOnCurve.hxx>
25#include <BRep_PointOnCurveOnSurface.hxx>
26#include <TNaming_CopyShape.hxx>
27#include <BRep_TFace.hxx>
28#include <BRep_TEdge.hxx>
29#include <BRep_PointOnSurface.hxx>
30#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
31#include <BRep_ListOfCurveRepresentation.hxx>
32#include <BRep_CurveRepresentation.hxx>
33#include <BRep_GCurve.hxx>
34#include <BRep_Curve3D.hxx>
35#include <BRep_CurveOnSurface.hxx>
36#include <BRep_CurveOnClosedSurface.hxx>
37#include <BRep_CurveOn2Surfaces.hxx>
38#include <BRep_Polygon3D.hxx>
39#include <BRep_PolygonOnClosedSurface.hxx>
40#include <BRep_PolygonOnSurface.hxx>
41#include <BRep_PolygonOnClosedTriangulation.hxx>
42#include <BRep_PolygonOnTriangulation.hxx>
43#include <Standard_NullObject.hxx>
44
45
46//=======================================================================
47//function : TNaming_TranslateTool
48
49//purpose :
50//=======================================================================
51
52//TNaming_TranslateTool::TNaming_TranslateTool
53//(const MgtBRep_TriangleMode aTriMode) :
54//myTriangleMode(aTriMode)
55//{
56//}
57
58//=======================================================================
59//function : Add
60//purpose : Adds S2 in S1
61//=======================================================================
62
63void TNaming_TranslateTool::Add(TopoDS_Shape& S1,
64 const TopoDS_Shape& S2) const
65{
66 BRep_Builder B;
67 B.Add(S1,S2);
68}
69
70//=======================================================================
71//function : MakeVertex
72//purpose :
73//=======================================================================
74
75void TNaming_TranslateTool::MakeVertex(TopoDS_Shape& S) const
76{
77 BRep_Builder B;
78 B.MakeVertex(TopoDS::Vertex(S));
79}
80
81//=======================================================================
82//function : MakeEdge
83//purpose :
84//=======================================================================
85
86void TNaming_TranslateTool::MakeEdge(TopoDS_Shape& S) const
87{
88 BRep_Builder B;
89 B.MakeEdge(TopoDS::Edge(S));
90}
91
92//=======================================================================
93//function : MakeWire
94//purpose :
95//=======================================================================
96
97void TNaming_TranslateTool::MakeWire(TopoDS_Shape& S) const
98{
99 BRep_Builder B;
100 B.MakeWire(TopoDS::Wire(S));
101}
102
103//=======================================================================
104//function : MakeFace
105//purpose :
106//=======================================================================
107
108void TNaming_TranslateTool::MakeFace(TopoDS_Shape& S) const
109{
110 BRep_Builder B;
111 B.MakeFace(TopoDS::Face(S));
112}
113
114//=======================================================================
115//function : MakeShell
116//purpose :
117//=======================================================================
118
119void TNaming_TranslateTool::MakeShell(TopoDS_Shape& S) const
120{
121 BRep_Builder B;
122 B.MakeShell(TopoDS::Shell(S));
123}
124
125//=======================================================================
126//function : MakeSolid
127//purpose :
128//=======================================================================
129
130void TNaming_TranslateTool::MakeSolid(TopoDS_Shape& S) const
131{
132 BRep_Builder B;
133 B.MakeSolid(TopoDS::Solid(S));
134}
135
136//=======================================================================
137//function : MakeCompSolid
138//purpose :
139//=======================================================================
140
141void TNaming_TranslateTool::MakeCompSolid(TopoDS_Shape& S) const
142{
143 BRep_Builder B;
144 B.MakeCompSolid(TopoDS::CompSolid(S));
145}
146
147//=======================================================================
148//function : MakeCompound
149//purpose :
150//=======================================================================
151
152void TNaming_TranslateTool::MakeCompound(TopoDS_Shape& S) const
153{
154 BRep_Builder B;
155 B.MakeCompound(TopoDS::Compound(S));
156}
157
158//=======================================================================
159// Update methods
160//=======================================================================
161//function : UpdateVertex
162//purpose :
163//=======================================================================
164
165void TNaming_TranslateTool::UpdateVertex
166(const TopoDS_Shape& S1,
167 TopoDS_Shape& S2,
168 TColStd_IndexedDataMapOfTransientTransient& aMap) const
169{
170 const Handle(BRep_TVertex)& TTV1 = *((Handle(BRep_TVertex)*) &(S1.TShape()));
171 const Handle(BRep_TVertex)& TTV2 = *((Handle(BRep_TVertex)*) &(S2.TShape()));
172
173 // Point
174 TTV2->Pnt(TTV1->Pnt());
175
176 // Tolerance
177 TTV2->Tolerance(TTV1->Tolerance());
178
179 // Representations
180 BRep_ListIteratorOfListOfPointRepresentation itpr(TTV1->Points());
181// cout << "Vertex List Extent = "<< TTV1->Points().Extent()<< endl;// == 0 ???
182 BRep_ListOfPointRepresentation& lpr = TTV2->ChangePoints();
183 lpr.Clear();
184
185 while (itpr.More()) {
186
187 const Handle(BRep_PointRepresentation)& PR1 = itpr.Value();
188 Handle(BRep_PointRepresentation) PR2;
189
190 if (PR1->IsPointOnCurve()) { // pointOnCurve (1)
191 Handle(BRep_PointOnCurve) OC =
192 new BRep_PointOnCurve(PR1->Parameter(), // the same geometry
193 PR1->Curve(), // the same geometry
194 TNaming_CopyShape::Translate(PR1->Location(), aMap));
195 PR2 = OC;
196 }
197
198 else if (PR1->IsPointOnCurveOnSurface()) { // PointOnCurveOnSurface (2)
199
200 Handle(BRep_PointOnCurveOnSurface) OCS =
201 new BRep_PointOnCurveOnSurface(PR1->Parameter(),
202 PR1->PCurve(),
203 PR1->Surface(),
204 TNaming_CopyShape::Translate(PR1->Location(), aMap));
205 PR2 = OCS;
206 }
207
208 else if (PR1->IsPointOnSurface()) { // PointOnSurface (3)
209
210 Handle(BRep_PointOnSurface) OS =
211 new BRep_PointOnSurface(PR1->Parameter(),
212 PR1->Parameter2(),
213 PR1->Surface(),
214 TNaming_CopyShape::Translate(PR1->Location(), aMap));
215 PR2 = OS;
216 }
217
218// lpr.Prepend(PR2);
219 lpr.Append(PR2);
220 itpr.Next();
221 }
222
223 UpdateShape(S1,S2);
224
225}
226
227//=======================================================================
228//function : UpdateEdge
229//purpose : Transient->Transient
230//=======================================================================
231
232void TNaming_TranslateTool::UpdateEdge
233(const TopoDS_Shape& S1,
234 TopoDS_Shape& S2,
235 TColStd_IndexedDataMapOfTransientTransient& aMap) const
236{
237 const Handle(BRep_TEdge)& TTE1 = *((Handle(BRep_TEdge)*) &(S1.TShape()));
238 const Handle(BRep_TEdge)& TTE2 = *((Handle(BRep_TEdge)*) &(S2.TShape()));
239 // tolerance TopLoc_Location
240 TTE2->Tolerance(TTE1->Tolerance());
241
242 // same parameter
243 TTE2->SameParameter(TTE1->SameParameter());
244
245 // same range
246 TTE2->SameRange(TTE1->SameRange());
247
248 // Degenerated
249 TTE2->Degenerated(TTE1->Degenerated());
250
251 // Representations
252 BRep_ListIteratorOfListOfCurveRepresentation itcr(TTE1->Curves());
253 BRep_ListOfCurveRepresentation& lcr = TTE2->ChangeCurves();
254 lcr.Clear();
255 Handle(BRep_CurveRepresentation) CR;
256
257 Handle(BRep_GCurve) GC;
258 Standard_Real f, l;
259 while (itcr.More()) {
260
261 const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
262 Handle(BRep_CurveRepresentation) CR2;
263
264 GC = Handle(BRep_GCurve)::DownCast(CR);
265 if (!GC.IsNull()) { // (1)
266 GC->Range(f, l);
267 // CurveRepresentation is Curve3D - (1a)
268 if (CR->IsCurve3D()) {
269
270 CR2 = (Handle(BRep_Curve3D)::DownCast(GC))->Copy();
271
272 }
273
274 // CurveRepresentation is CurveOnSurface - (1b)
275 else if (CR->IsCurveOnSurface()) {
276
277 if (!CR->IsCurveOnClosedSurface()) { // -(1b1) -if not closed surface
278
279 // CurveRepresentation is a PBRep_CurveOnSurface
280 CR2 = (Handle(BRep_CurveOnSurface)::DownCast(GC))->Copy();
281 }
282
283 else {
284 // CurveRepresentation is CurveOnClosedSurface -(1b2)
285 CR2 = (Handle(BRep_CurveOnClosedSurface)::DownCast(GC))->Copy();
286 }
287 }
288
289 (Handle(BRep_GCurve)::DownCast(CR2))->SetRange(f, l);
290 }
291
292 // CurveRepresentation is CurveOn2Surfaces (2:)
293 else if (CR->IsRegularity()) {
294
295 CR2 = (Handle(BRep_CurveOn2Surfaces)::DownCast(CR))->Copy();
296 TopLoc_Location L2 = TNaming_CopyShape::Translate(CR->Location2(), aMap);
297 CR2->Location(L2);
298 }
299
300 // CurveRepresentation is Polygon or Triangulation (3:)
301// else if (myTriangleMode == MgtBRep_WithTriangle) {
302
303 // CurveRepresentation is Polygon3D (3a)
304 else if (CR->IsPolygon3D()) {
305
306 CR2 = (Handle(BRep_Polygon3D)::DownCast(CR))->Copy();
307 }
308
309 // CurveRepresentation is PolygonOnSurface - (3b)
310 else if (CR->IsPolygonOnSurface()) {
311
312 // CurveRepresentation is PolygonOnClosedSurface - (3b1)
313 if (CR->IsPolygonOnClosedSurface()) {
314
315 CR2 = (Handle(BRep_PolygonOnClosedSurface)::DownCast(CR))->Copy();
316 }
317
318 // CurveRepresentation is PolygonOnSurface - (3b2)
319 else {
320
321 CR2 = (Handle(BRep_PolygonOnSurface)::DownCast(CR))->Copy();
322
323 }
324 }
325
326 // CurveRepresentation is PolygonOnTriangulation - (3c)
327 else if (CR->IsPolygonOnTriangulation()) {
328
329 // CurveRepresentation is PolygonOnClosedTriangulation
330 if (CR->IsPolygonOnClosedTriangulation()) { // (3c1)
331
332 CR2 = (Handle(BRep_PolygonOnClosedTriangulation)::DownCast(CR))->Copy();
333 }
334
335 // CurveRepresentation is PolygonOnTriangulation - (3c2)
336 else {
337
338 CR2 = (Handle(BRep_PolygonOnTriangulation)::DownCast(CR))->Copy();
339 }
340 }
341// }
342 else {
343 // jumps the curve representation
344 itcr.Next();
345 continue;
346 }
347
348 TopLoc_Location L = TNaming_CopyShape::Translate(CR->Location(), aMap);
349 CR2->Location(L);
350
351 Standard_NullObject_Raise_if (CR2.IsNull(), "Null CurveRepresentation");
352
353// lcr.Prepend(CR2); // add
354 lcr.Append(CR2);
355 itcr.Next();
356 }
357
358 UpdateShape(S1,S2);
359}
360
361
362//=======================================================================
363//function : UpdateFace
364//purpose : Transient->Transient
365//=======================================================================
366
367void TNaming_TranslateTool::UpdateFace
368(const TopoDS_Shape& S1,
369 TopoDS_Shape& S2,
370 TColStd_IndexedDataMapOfTransientTransient& aMap) const
371{
372 const Handle(BRep_TFace)& TTF1 = *((Handle(BRep_TFace)*) &(S1.TShape()));
373 const Handle(BRep_TFace)& TTF2 = *((Handle(BRep_TFace)*) &(S2.TShape()));
374
375 // natural restriction
376 TTF2->NaturalRestriction(TTF1->NaturalRestriction());
377
378 // tolerance
379 TTF2->Tolerance(TTF1->Tolerance());
380
381 // location
382 TTF2->Location(TNaming_CopyShape::Translate(TTF1->Location(), aMap));
383
384 // surface
385 TTF2->Surface(TTF1->Surface());
386
387 // Triangulation
388 // if (myTriangleMode == MgtBRep_WithTriangle) {
389 TTF2->Triangulation(TTF1->Triangulation());
390 // }
391
392 UpdateShape(S1,S2);
393
394}
395
396//=======================================================================
397//function : UpdateShape
398//purpose :
399//=======================================================================
400
401void TNaming_TranslateTool::UpdateShape
402 (const TopoDS_Shape& S1, TopoDS_Shape& S2) const
403{
404 // Transfer the flags
405 S2.TShape()->Free(S1.TShape()->Free());
406 S2.TShape()->Modified(S1.TShape()->Modified());
407 S2.TShape()->Checked(S1.TShape()->Checked());
408 S2.TShape()->Orientable(S1.TShape()->Orientable());
409 S2.TShape()->Closed(S1.TShape()->Closed());
410 S2.TShape()->Infinite(S1.TShape()->Infinite());
411 S2.TShape()->Convex(S1.TShape()->Convex());
412}