0030480: Visualization - Clear of Select3D_SensitiveGroup does not update internal...
[occt.git] / src / ShapePersistent / ShapePersistent_Geom_Surface.cxx
CommitLineData
ff205346 1// Copyright (c) 2015 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#include <ShapePersistent_Geom_Surface.hxx>
ec964372 15#include <StdLPersistent_HArray1.hxx>
16#include <ShapePersistent_HArray2.hxx>
ff205346 17
18#include <Geom_SurfaceOfLinearExtrusion.hxx>
19#include <Geom_SurfaceOfRevolution.hxx>
20#include <Geom_BezierSurface.hxx>
21#include <Geom_BSplineSurface.hxx>
22#include <Geom_RectangularTrimmedSurface.hxx>
23#include <Geom_OffsetSurface.hxx>
24
25#include <gp_Ax1.hxx>
26
27
28Handle(Geom_Surface) ShapePersistent_Geom_Surface::pLinearExtrusion::Import()
29 const
30{
31 if (myBasisCurve.IsNull())
32 return NULL;
33
34 return new Geom_SurfaceOfLinearExtrusion
35 (myBasisCurve->Import(), myDirection);
36}
37
38Handle(Geom_Surface) ShapePersistent_Geom_Surface::pRevolution::Import() const
39{
40 if (myBasisCurve.IsNull())
41 return NULL;
42
43 return new Geom_SurfaceOfRevolution
44 (myBasisCurve->Import(), gp_Ax1 (myLocation, myDirection));
45}
46
47Handle(Geom_Surface) ShapePersistent_Geom_Surface::pBezier::Import() const
48{
49 if (myPoles.IsNull())
50 return NULL;
51
52 if (myURational || myVRational)
53 {
54 if (myWeights.IsNull())
55 return NULL;
56 return new Geom_BezierSurface (*myPoles->Array(), *myWeights->Array());
57 }
58 else
59 return new Geom_BezierSurface (*myPoles->Array());
60}
61
62Handle(Geom_Surface) ShapePersistent_Geom_Surface::pBSpline::Import() const
63{
64 if (myPoles.IsNull() || myUKnots.IsNull() || myVKnots.IsNull()
65 || myUMultiplicities.IsNull() || myVMultiplicities.IsNull())
66 return NULL;
67
68 if (myURational || myVRational)
69 {
70 if (myWeights.IsNull())
71 return NULL;
72
73 return new Geom_BSplineSurface (*myPoles->Array(),
74 *myWeights->Array(),
75 *myUKnots->Array(),
76 *myVKnots->Array(),
77 *myUMultiplicities->Array(),
78 *myVMultiplicities->Array(),
79 myUSpineDegree,
80 myVSpineDegree,
81 myUPeriodic,
82 myVPeriodic);
83 }
84 else
85 return new Geom_BSplineSurface (*myPoles->Array(),
86 *myUKnots->Array(),
87 *myVKnots->Array(),
88 *myUMultiplicities->Array(),
89 *myVMultiplicities->Array(),
90 myUSpineDegree,
91 myVSpineDegree,
92 myUPeriodic,
93 myVPeriodic);
94}
95
96Handle(Geom_Surface) ShapePersistent_Geom_Surface::pRectangularTrimmed::Import()
97 const
98{
99 if (myBasisSurface.IsNull())
100 return NULL;
101
102 return new Geom_RectangularTrimmedSurface
103 (myBasisSurface->Import(), myFirstU, myLastU, myFirstV, myLastV);
104}
105
106Handle(Geom_Surface) ShapePersistent_Geom_Surface::pOffset::Import() const
107{
108 if (myBasisSurface.IsNull())
109 return NULL;
110
111 return new Geom_OffsetSurface (myBasisSurface->Import(), myOffsetValue);
112}
ec964372 113
114//=======================================================================
115// Elementary
116//=======================================================================
117template<>
118Standard_CString ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface,
119 gp_Ax3>
120 ::PName() const { return "PGeom_ElementarySurface"; }
121
122//=======================================================================
123// Plane
124//=======================================================================
125template<>
126Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
127 Geom_Plane,
128 gp_Ax3>
129 ::PName() const { return "PGeom_Plane"; }
130
131template<>
132void ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
133 Geom_Plane,
134 gp_Ax3>
135 ::Write(StdObjMgt_WriteData& theWriteData) const
136{
137 Handle(Geom_Plane) aMyGeom =
138 Handle(Geom_Plane)::DownCast(myTransient);
139 theWriteData << aMyGeom->Position();
140}
141
142Handle(ShapePersistent_Geom::Surface)
143ShapePersistent_Geom_Surface::Translate(const Handle(Geom_Plane)& theSurf,
144 StdObjMgt_TransientPersistentMap& theMap)
145{
146 Handle(ShapePersistent_Geom::Surface) aPS;
147 if (!theSurf.IsNull())
148 {
149 if (theMap.IsBound(theSurf))
150 aPS = Handle(ShapePersistent_Geom::Surface)::DownCast(theMap.Find(theSurf));
151 else
152 {
153 Handle(Plane) aPP = new Plane;
154 aPP->myTransient = theSurf;
155 aPS = aPP;
156 }
157 }
158 return aPS;
159}
160
161//=======================================================================
162// Conical
163//=======================================================================
164template<>
165Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
166 Geom_ConicalSurface,
167 gp_Cone>
168 ::PName() const { return "PGeom_ConicalSurface"; }
169
170template<>
171void ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
172 Geom_ConicalSurface,
173 gp_Cone>
174 ::Write(StdObjMgt_WriteData& theWriteData) const
175{
176 Handle(Geom_ConicalSurface) aMyGeom =
177 Handle(Geom_ConicalSurface)::DownCast(myTransient);
178 theWriteData << aMyGeom->Cone();
179}
180
181Handle(ShapePersistent_Geom::Surface)
182ShapePersistent_Geom_Surface::Translate(const Handle(Geom_ConicalSurface)& theSurf,
183 StdObjMgt_TransientPersistentMap& theMap)
184{
185 Handle(ShapePersistent_Geom::Surface) aPS;
186 if (!theSurf.IsNull())
187 {
188 if (theMap.IsBound(theSurf))
189 aPS = Handle(ShapePersistent_Geom::Surface)::DownCast(theMap.Find(theSurf));
190 else
191 {
192 Handle(Conical) aPCon = new Conical;
193 aPCon->myTransient = theSurf;
194 aPS = aPCon;
195 }
196 }
197 return aPS;
198}
199
200//=======================================================================
201// Cylindrical
202//=======================================================================
203template<>
204Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
205 Geom_CylindricalSurface,
206 gp_Cylinder>
207 ::PName() const { return "PGeom_CylindricalSurface"; }
208
209template<>
210void ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
211 Geom_CylindricalSurface,
212 gp_Cylinder>
213 ::Write(StdObjMgt_WriteData& theWriteData) const
214{
215 Handle(Geom_CylindricalSurface) aMyGeom =
216 Handle(Geom_CylindricalSurface)::DownCast(myTransient);
217 theWriteData << aMyGeom->Cylinder();
218}
219
220Handle(ShapePersistent_Geom::Surface)
221ShapePersistent_Geom_Surface::Translate(const Handle(Geom_CylindricalSurface)& theSurf,
222 StdObjMgt_TransientPersistentMap& theMap)
223{
224 Handle(ShapePersistent_Geom::Surface) aPS;
225 if (!theSurf.IsNull())
226 {
227 if (theMap.IsBound(theSurf))
228 aPS = Handle(ShapePersistent_Geom::Surface)::DownCast(theMap.Find(theSurf));
229 else
230 {
231 Handle(Cylindrical) aPCyl = new Cylindrical;
232 aPCyl->myTransient = theSurf;
233 aPS = aPCyl;
234 }
235 }
236 return aPS;
237}
238
239//=======================================================================
240// Spherical
241//=======================================================================
242template<>
243Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
244 Geom_SphericalSurface,
245 gp_Sphere>
246 ::PName() const { return "PGeom_SphericalSurface"; }
247
248template<>
249void ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
250 Geom_SphericalSurface,
251 gp_Sphere>
252 ::Write(StdObjMgt_WriteData& theWriteData) const
253{
254 Handle(Geom_SphericalSurface) aMyGeom =
255 Handle(Geom_SphericalSurface)::DownCast(myTransient);
256 theWriteData << aMyGeom->Sphere();
257}
258
259Handle(ShapePersistent_Geom::Surface)
260ShapePersistent_Geom_Surface::Translate(const Handle(Geom_SphericalSurface)& theSurf,
261 StdObjMgt_TransientPersistentMap& theMap)
262{
263 Handle(ShapePersistent_Geom::Surface) aPS;
264 if (!theSurf.IsNull())
265 {
266 if (theMap.IsBound(theSurf))
267 aPS = Handle(ShapePersistent_Geom::Surface)::DownCast(theMap.Find(theSurf));
268 else
269 {
270 Handle(Spherical) aPSph = new Spherical;
271 aPSph->myTransient = theSurf;
272 aPS = aPSph;
273 }
274 }
275 return aPS;
276}
277
278//=======================================================================
279// Toroidal
280//=======================================================================
281template<>
282Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
283 Geom_ToroidalSurface,
284 gp_Torus>
285 ::PName() const { return "PGeom_ToroidalSurface"; }
286
287template<>
288void ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
289 Geom_ToroidalSurface,
290 gp_Torus>
291 ::Write(StdObjMgt_WriteData& theWriteData) const
292{
293 Handle(Geom_ToroidalSurface) aMyGeom =
294 Handle(Geom_ToroidalSurface)::DownCast(myTransient);
295 theWriteData << aMyGeom->Torus();
296}
297
298Handle(ShapePersistent_Geom::Surface)
299ShapePersistent_Geom_Surface::Translate(const Handle(Geom_ToroidalSurface)& theSurf,
300 StdObjMgt_TransientPersistentMap& theMap)
301{
302 Handle(ShapePersistent_Geom::Surface) aPS;
303 if (!theSurf.IsNull())
304 {
305 if (theMap.IsBound(theSurf))
306 aPS = Handle(ShapePersistent_Geom::Surface)::DownCast(theMap.Find(theSurf));
307 else
308 {
309 Handle(Toroidal) aPTor = new Toroidal;
310 aPTor->myTransient = theSurf;
311 aPS = aPTor;
312 }
313 }
314 return aPS;
315}
316
317//=======================================================================
318// LinearExtrusion
319//=======================================================================
320Handle(ShapePersistent_Geom::Surface)
321ShapePersistent_Geom_Surface::Translate(const Handle(Geom_SurfaceOfLinearExtrusion)& theSurf,
322 StdObjMgt_TransientPersistentMap& theMap)
323{
324 Handle(ShapePersistent_Geom::Surface) aPS;
325 if (!theSurf.IsNull())
326 {
327 if (theMap.IsBound(theSurf))
328 aPS = Handle(ShapePersistent_Geom::Surface)::DownCast(theMap.Find(theSurf));
329 else
330 {
331 Handle(LinearExtrusion) aPLE = new LinearExtrusion;
332 Handle(pLinearExtrusion) aPpLE = new pLinearExtrusion;
333 aPpLE->myDirection = theSurf->Direction();
334 aPpLE->myBasisCurve = ShapePersistent_Geom::Translate(theSurf->BasisCurve(), theMap);
335 aPLE->myPersistent = aPpLE;
336 aPS = aPLE;
337 }
338 }
339 return aPS;
340}
341
342//=======================================================================
343// Revolution
344//=======================================================================
345Handle(ShapePersistent_Geom::Surface)
346ShapePersistent_Geom_Surface::Translate(const Handle(Geom_SurfaceOfRevolution)& theSurf,
347 StdObjMgt_TransientPersistentMap& theMap)
348{
349 Handle(ShapePersistent_Geom::Surface) aPS;
350 if (!theSurf.IsNull())
351 {
352 if (theMap.IsBound(theSurf))
353 aPS = Handle(ShapePersistent_Geom::Surface)::DownCast(theMap.Find(theSurf));
354 else
355 {
356 Handle(Revolution) aPR = new Revolution;
357 Handle(pRevolution) aPpR = new pRevolution;
358 aPpR->myLocation = theSurf->Location();
359 aPpR->myDirection = theSurf->Direction();
360 aPpR->myBasisCurve = ShapePersistent_Geom::Translate(theSurf->BasisCurve(), theMap);
361 aPR->myPersistent = aPpR;
362 aPS = aPR;
363 }
364 }
365 return aPS;
366}
367
368//=======================================================================
369//
370//=======================================================================
371Handle(ShapePersistent_Geom::Surface)
372ShapePersistent_Geom_Surface::Translate(const Handle(Geom_BezierSurface)& theSurf,
373 StdObjMgt_TransientPersistentMap& theMap)
374{
375 Handle(ShapePersistent_Geom::Surface) aPS;
376 if (!theSurf.IsNull())
377 {
378 if (theMap.IsBound(theSurf))
379 aPS = Handle(ShapePersistent_Geom::Surface)::DownCast(theMap.Find(theSurf));
380 else
381 {
382 Handle(Bezier) aPB = new Bezier;
383 Handle(pBezier) aPpB = new pBezier;
384 aPpB->myURational = theSurf->IsURational();
385 aPpB->myVRational = theSurf->IsVRational();
386 aPpB->myPoles = StdLPersistent_HArray2::Translate<TColgp_HArray2OfPnt>("PColgp_HArray2OfPnt", theSurf->Poles());
387 if (theSurf->IsURational() || theSurf->IsVRational()) {
388 aPpB->myWeights = StdLPersistent_HArray2::Translate<TColStd_HArray2OfReal>(*theSurf->Weights());
389 }
390 aPB->myPersistent = aPpB;
391 aPS = aPB;
392 }
393 }
394 return aPS;
395}
396
397//=======================================================================
398// BSpline
399//=======================================================================
400Handle(ShapePersistent_Geom::Surface)
401ShapePersistent_Geom_Surface::Translate(const Handle(Geom_BSplineSurface)& theSurf,
402 StdObjMgt_TransientPersistentMap& theMap)
403{
404 Handle(ShapePersistent_Geom::Surface) aPS;
405 if (!theSurf.IsNull())
406 {
407 if (theMap.IsBound(theSurf))
408 aPS = Handle(ShapePersistent_Geom::Surface)::DownCast(theMap.Find(theSurf));
409 else
410 {
411 Handle(BSpline) aPBS = new BSpline;
412 Handle(pBSpline) aPpBS = new pBSpline;
413 aPpBS->myURational = theSurf->IsURational();
414 aPpBS->myVRational = theSurf->IsVRational();
415 aPpBS->myUPeriodic = theSurf->IsUPeriodic();
416 aPpBS->myVPeriodic = theSurf->IsVPeriodic();
417 aPpBS->myUSpineDegree = theSurf->UDegree();
418 aPpBS->myVSpineDegree = theSurf->VDegree();
419 aPpBS->myPoles = StdLPersistent_HArray2::Translate<TColgp_HArray2OfPnt>("PColgp_HArray2OfPnt", theSurf->Poles());
420 if (theSurf->IsURational() || theSurf->IsVRational()) {
421 aPpBS->myWeights = StdLPersistent_HArray2::Translate<TColStd_HArray2OfReal>(*theSurf->Weights());
422 }
423 aPpBS->myUKnots = StdLPersistent_HArray1::Translate<TColStd_HArray1OfReal>(theSurf->UKnots());
424 aPpBS->myVKnots = StdLPersistent_HArray1::Translate<TColStd_HArray1OfReal>(theSurf->VKnots());
425 aPpBS->myUMultiplicities = StdLPersistent_HArray1::Translate<TColStd_HArray1OfInteger>(theSurf->UMultiplicities());
426 aPpBS->myVMultiplicities = StdLPersistent_HArray1::Translate<TColStd_HArray1OfInteger>(theSurf->VMultiplicities());
427
428 aPBS->myPersistent = aPpBS;
429 aPS = aPBS;
430 }
431 }
432 return aPS;
433}
434
435//=======================================================================
436// RectangularTrimmed
437//=======================================================================
438Handle(ShapePersistent_Geom::Surface)
439ShapePersistent_Geom_Surface::Translate(const Handle(Geom_RectangularTrimmedSurface)& theSurf,
440 StdObjMgt_TransientPersistentMap& theMap)
441{
442 Handle(ShapePersistent_Geom::Surface) aPS;
443 if (!theSurf.IsNull())
444 {
445 if (theMap.IsBound(theSurf))
446 aPS = Handle(ShapePersistent_Geom::Surface)::DownCast(theMap.Find(theSurf));
447 else
448 {
449 Handle(RectangularTrimmed) aPRT = new RectangularTrimmed;
450 Handle(pRectangularTrimmed) aPpRT = new pRectangularTrimmed;
451 theSurf->Bounds(aPpRT->myFirstU, aPpRT->myLastU, aPpRT->myFirstV, aPpRT->myLastV);
452 aPpRT->myBasisSurface = ShapePersistent_Geom::Translate(theSurf->BasisSurface(), theMap);
453 aPRT->myPersistent = aPpRT;
454 aPS = aPRT;
455 }
456 }
457 return aPS;
458}
459
460//=======================================================================
461// Offset
462//=======================================================================
463Handle(ShapePersistent_Geom::Surface)
464ShapePersistent_Geom_Surface::Translate(const Handle(Geom_OffsetSurface)& theSurf,
465 StdObjMgt_TransientPersistentMap& theMap)
466{
467 Handle(ShapePersistent_Geom::Surface) aPS;
468 if (!theSurf.IsNull())
469 {
470 if (theMap.IsBound(theSurf))
471 aPS = Handle(ShapePersistent_Geom::Surface)::DownCast(theMap.Find(theSurf));
472 else
473 {
474 Handle(Offset) aPO = new Offset;
475 Handle(pOffset) aPpO = new pOffset;
476 aPpO->myOffsetValue = theSurf->Offset();
477 aPpO->myBasisSurface = ShapePersistent_Geom::Translate(theSurf->BasisSurface(), theMap);
478 aPO->myPersistent = aPpO;
479 aPS = aPO;
480 }
481 }
482 return aPS;
483}