1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <Standard_Stream.hxx>
25 #include <GEOMImpl_DividedDiskDriver.hxx>
26 #include <GEOMImpl_IDividedDisk.hxx>
27 #include <GEOMImpl_Types.hxx>
28 #include <GEOM_Function.hxx>
34 #include <gp_Circ.hxx>
38 #include <BRep_Builder.hxx>
39 #include <BRepBuilderAPI_MakeFace.hxx>
40 #include <BRepBuilderAPI_MakeEdge.hxx>
41 #include <BRepBuilderAPI_MakeVertex.hxx>
42 #include <BRepBuilderAPI_MakeWire.hxx>
43 #include <BRepBuilderAPI_Transform.hxx>
45 #include <Geom_Plane.hxx>
48 #include <TopoDS_Shape.hxx>
49 #include <TopoDS_Edge.hxx>
51 #include <TFunction_Logbook.hxx>
52 #include <StdFail_NotDone.hxx>
56 #include <utilities.h>
57 //@@ include required header files here @@//
64 //=======================================================================
67 //=======================================================================
68 const Standard_GUID& GEOMImpl_DividedDiskDriver::GetID()
70 static Standard_GUID aGUID("0b01da9a-c5da-11e1-8d80-78e7d1879630");
74 //=======================================================================
75 //function : GEOMImpl_DividedDiskDriver
77 //=======================================================================
78 GEOMImpl_DividedDiskDriver::GEOMImpl_DividedDiskDriver()
82 //=======================================================================
85 //=======================================================================
86 Standard_Integer GEOMImpl_DividedDiskDriver::Execute(TFunction_Logbook& log) const
88 if (Label().IsNull()) return 0;
89 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
91 GEOMImpl_IDividedDisk aData (aFunction);
92 Standard_Integer aType = aFunction->GetType();
97 double R = aData.GetR();
98 double Ratio = aData.GetRatio();
99 int Pattern = aData.GetType();
101 // Build reference disk (in the global coordinate system)
104 if (Pattern == SQUARE)
105 aDisk = MakeDiskSquare( R, Ratio );
106 else if (Pattern == HEXAGON)
107 aDisk = MakeDiskHexagon( R, Ratio );
109 if (aType == DIVIDEDDISK_R_RATIO)
111 int theOrientation = aData.GetOrientation();
112 aShape = TransformShape(aDisk, theOrientation);
114 else if (aType == DIVIDEDDISK_R_VECTOR_PNT)
116 Handle(GEOM_Function) aRefPoint = aData.GetCenter();
117 Handle(GEOM_Function) aRefVector = aData.GetVector();
118 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
119 TopoDS_Shape aShapeVec = aRefVector->GetValue();
121 if (aShapePnt.ShapeType() == TopAbs_VERTEX &&
122 aShapeVec.ShapeType() == TopAbs_EDGE)
124 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
125 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
126 TopoDS_Vertex V1, V2;
127 TopExp::Vertices(anE, V1, V2, Standard_True);
128 if (!V1.IsNull() && !V2.IsNull())
130 gp_Vec aVec (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
132 aShape = TransformShape(aDisk, aPnt, aDir);
137 if (aShape.IsNull()) return 0;
139 aFunction->SetValue(aShape);
141 log.SetTouched(Label());
147 //=======================================================================
148 //function : MakeDiskHexagon
150 //=======================================================================
151 TopoDS_Shell GEOMImpl_DividedDiskDriver::MakeDiskHexagon(double R, double Ratio) const
159 gp_Ax1 Ax1(Orig,ZDir);
160 gp_Ax2 Ax(Orig,ZDir,XDir);
161 gp_Circ aCircle(Ax, R);
164 // gp_Pnt P4(0.01*Ratio*R,0,0);
166 // gp_Pnt P2 = P3.Rotated(Ax1,-M_PI/6.0);
168 // P4.X()/sqrt(3.0),0);
169 gp_Pnt P1(0.01*Ratio*R*sqrt(3.0)/2,0,0);
171 gp_Pnt P3 = P2.Rotated(Ax1,M_PI/6.0);
177 gp_Ax2 anAx (gp::XOY());
178 Handle(Geom_Plane) aPlane = new Geom_Plane (anAx);
183 TopoDS_Vertex O = BRepBuilderAPI_MakeVertex(Orig);
184 TopoDS_Vertex V1_init = BRepBuilderAPI_MakeVertex(P1);
185 TopoDS_Vertex V2_init = BRepBuilderAPI_MakeVertex(P2);
186 TopoDS_Vertex V3 = BRepBuilderAPI_MakeVertex(P3);
187 TopoDS_Vertex V4 = BRepBuilderAPI_MakeVertex(P4);
189 TopoDS_Vertex V1 = V1_init;
190 TopoDS_Vertex V2 = V2_init;
194 myTrsf.SetRotation(Ax1, M_PI/3.0);
196 BRepBuilderAPI_Transform xform(myTrsf);
197 xform.Perform(V1,Standard_True);
198 TopoDS_Vertex V1_60 = TopoDS::Vertex(xform.Shape());
199 xform.Perform(V2,Standard_True);
200 TopoDS_Vertex V2_60 = TopoDS::Vertex(xform.Shape());
202 // Declaration of shapes (used in the loop)
203 TopoDS_Edge E1, E2, E3, E4, E5, E6, E7, E8, E9;
204 TopoDS_Wire W1, W2, W3;
205 TopoDS_Face F1, F2, F3;
208 BRep_Builder aBuilder;
209 aBuilder.MakeShell(S);
211 // Initialisation of edges
212 TopoDS_Edge E1_init = BRepBuilderAPI_MakeEdge(V1,TopoDS::Vertex(V2.Reversed()));
214 TopoDS_Edge E8_init = BRepBuilderAPI_MakeEdge(O,TopoDS::Vertex(V1.Reversed()));
217 for (int i=1;i<=6;i++)
222 E2 = BRepBuilderAPI_MakeEdge(aCircle, V2, TopoDS::Vertex(V3.Reversed()));
223 E3 = BRepBuilderAPI_MakeEdge(V3,TopoDS::Vertex(V4.Reversed()));
224 E4 = BRepBuilderAPI_MakeEdge(V4,TopoDS::Vertex(V1.Reversed()));
229 E5 = BRepBuilderAPI_MakeEdge(aCircle, V3, TopoDS::Vertex(V2_init.Reversed()));
230 E7 = BRepBuilderAPI_MakeEdge(V1_init,TopoDS::Vertex(V4.Reversed()));
234 E5 = BRepBuilderAPI_MakeEdge(aCircle, V3, TopoDS::Vertex(V2_60.Reversed()));
235 E7 = BRepBuilderAPI_MakeEdge(V1_60,TopoDS::Vertex(V4.Reversed()));
237 E6 = BRepBuilderAPI_MakeEdge(V2_60,TopoDS::Vertex(V1_60.Reversed()));
240 E9 = BRepBuilderAPI_MakeEdge(V1_60,TopoDS::Vertex(O.Reversed()));
246 aBuilder.MakeWire(W1);
250 aBuilder.Add(W1,TopoDS::Edge(E1.Reversed()));
256 aBuilder.MakeWire(W2);
257 aBuilder.Add(W2,TopoDS::Edge(E3.Reversed()));
260 aBuilder.Add(W2,TopoDS::Edge(E1_init.Reversed()));
266 aBuilder.MakeWire(W3);
270 aBuilder.Add(W3,TopoDS::Edge(E8.Reversed()));
271 aBuilder.Add(W3,TopoDS::Edge(E4.Reversed()));
272 aBuilder.Add(W3,TopoDS::Edge(E7.Reversed()));
274 aBuilder.Add(W3,TopoDS::Edge(E8_init.Reversed()));
279 F1 = BRepBuilderAPI_MakeFace(aPlane,W1);
280 F2 = BRepBuilderAPI_MakeFace(aPlane,W2);
281 F3 = BRepBuilderAPI_MakeFace(aPlane,W3);
292 xform.Perform(V1_60,Standard_True);
293 V1_60 = TopoDS::Vertex(xform.Shape());
294 xform.Perform(V2_60,Standard_True);
295 V2_60 = TopoDS::Vertex(xform.Shape());
296 xform.Perform(V3,Standard_True);
297 V3 = TopoDS::Vertex(xform.Shape());
298 xform.Perform(V4,Standard_True);
299 V4 = TopoDS::Vertex(xform.Shape());
301 // "Increment" of edges
309 //=======================================================================
310 //function : MakeDiskSquare
312 //=======================================================================
313 TopoDS_Shape GEOMImpl_DividedDiskDriver::MakeDiskSquare(double R, double Ratio) const
321 gp_Ax1 Ax1(Orig,ZDir);
322 gp_Ax2 Ax(Orig,ZDir,XDir);
323 gp_Circ aCircle(Ax, R);
326 gp_Pnt P1(0.01*Ratio*R,0,0);
330 gp_Ax2 anAx (gp::XOY());
331 Handle(Geom_Plane) aPlane = new Geom_Plane (anAx);
336 TopoDS_Vertex V1_init = BRepBuilderAPI_MakeVertex(P1);
337 TopoDS_Vertex V2_init = BRepBuilderAPI_MakeVertex(P2);
339 TopoDS_Vertex V1 = V1_init;
340 TopoDS_Vertex V2 = V2_init;
344 myTrsf.SetRotation(Ax1, M_PI/2);
346 BRepBuilderAPI_Transform xform(myTrsf);
347 xform.Perform(V1,Standard_True);
348 TopoDS_Vertex V1_rotated = TopoDS::Vertex(xform.Shape());
349 xform.Perform(V2,Standard_True);
350 TopoDS_Vertex V2_rotated = TopoDS::Vertex(xform.Shape());
352 // Declaration of shapes (used in the loop)
353 TopoDS_Edge E1, E2, E3, E4;
358 BRep_Builder aBuilder;
359 aBuilder.MakeWire(W2); // Central Wire
360 aBuilder.MakeShell(S); // Shell
362 // Initialisation of edges
363 TopoDS_Edge E1_init = BRepBuilderAPI_MakeEdge(V1,TopoDS::Vertex(V2.Reversed()));
366 for (int i=1;i<=4;i++)
371 E3 = BRepBuilderAPI_MakeEdge(V2_rotated,TopoDS::Vertex(V1_rotated.Reversed()));
374 E2 = BRepBuilderAPI_MakeEdge(aCircle, V2, TopoDS::Vertex(V2_init.Reversed()));
375 E4 = BRepBuilderAPI_MakeEdge(V1_init,TopoDS::Vertex(V1.Reversed()));
379 E2 = BRepBuilderAPI_MakeEdge(aCircle, V2, TopoDS::Vertex(V2_rotated.Reversed()));
380 E4 = BRepBuilderAPI_MakeEdge(V1_rotated,TopoDS::Vertex(V1.Reversed()));
385 aBuilder.MakeWire(W1);
389 aBuilder.Add(W1,TopoDS::Edge(E1.Reversed()));
392 aBuilder.Add(W1,TopoDS::Edge(E1_init.Reversed()));
398 aBuilder.Add(W2,TopoDS::Edge(E4.Reversed()));
401 F1 = BRepBuilderAPI_MakeFace(aPlane,W1);
410 xform.Perform(V1_rotated,Standard_True);
411 V1_rotated = TopoDS::Vertex(xform.Shape());
412 xform.Perform(V2_rotated,Standard_True);
413 V2_rotated = TopoDS::Vertex(xform.Shape());
415 // "Increment" of edges
418 // Central square Face
419 F2 = BRepBuilderAPI_MakeFace(aPlane,W2);
426 //=======================================================================
427 //function : TrasformShape(TopoDS_Shape aShape,int theOrientation)
428 //purpose : Perform shape transformation accordingly with specified
430 //=======================================================================
431 TopoDS_Shape GEOMImpl_DividedDiskDriver::TransformShape(TopoDS_Shape theShape, int theOrientation) const
434 gp_Pnt theOrigin = gp::Origin();
436 switch(theOrientation)
458 gp_Ax3 aWPlane = gp_Ax3(theOrigin, N, Vx);
460 return WPlaneTransform(theShape, aWPlane);
463 //=======================================================================
464 //function : TrasformShape(TopoDS_Shape aShape, gp_Dir V, gp_Pnt P)
465 //purpose : Perform shape transformation accordingly with specified
467 //=======================================================================
468 TopoDS_Shape GEOMImpl_DividedDiskDriver::TransformShape(TopoDS_Shape theShape, gp_Pnt P, gp_Dir V) const
470 gp_Ax3 aWPlane( P, V );
471 return WPlaneTransform(theShape, aWPlane);
474 //=======================================================================
475 //function : WPlaneTransform
476 //purpose : Perform shape transformation accordingly with the given
478 //=======================================================================
479 TopoDS_Shape GEOMImpl_DividedDiskDriver::WPlaneTransform(TopoDS_Shape theShape, gp_Ax3 theWPlane) const
482 aTrans.SetTransformation(theWPlane);
484 BRepBuilderAPI_Transform aTransformation (theShape, aTrans, Standard_False);
485 return aTransformation.Shape();
488 //=======================================================================
489 //function : GEOMImpl_DividedDiskDriver_Type_
491 //=======================================================================
492 Standard_EXPORT Handle_Standard_Type& GEOMImpl_DividedDiskDriver_Type_()
494 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
495 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
496 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
497 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
498 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
499 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
501 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
502 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_DividedDiskDriver",
503 sizeof(GEOMImpl_DividedDiskDriver),
505 (Standard_Address)_Ancestors,
506 (Standard_Address)NULL);
510 //=======================================================================
511 //function : DownCast
513 //=======================================================================
514 const Handle(GEOMImpl_DividedDiskDriver) Handle(GEOMImpl_DividedDiskDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
516 Handle(GEOMImpl_DividedDiskDriver) _anOtherObject;
518 if (!AnObject.IsNull()) {
519 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_DividedDiskDriver))) {
520 _anOtherObject = Handle(GEOMImpl_DividedDiskDriver)((Handle(GEOMImpl_DividedDiskDriver)&)AnObject);
524 return _anOtherObject;