1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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 "AdvancedEngine_DividedDiskDriver.hxx"
26 #include "AdvancedEngine_IDividedDisk.hxx"
27 #include "AdvancedEngine_Types.hxx"
29 #include "GEOM_Function.hxx"
35 #include <gp_Circ.hxx>
39 #include <BRep_Builder.hxx>
40 #include <BRepBuilderAPI_MakeFace.hxx>
41 #include <BRepBuilderAPI_MakeEdge.hxx>
42 #include <BRepBuilderAPI_MakeVertex.hxx>
43 #include <BRepBuilderAPI_MakeWire.hxx>
44 #include <BRepBuilderAPI_Transform.hxx>
46 #include <Geom_Plane.hxx>
49 #include <TopoDS_Shape.hxx>
50 #include <TopoDS_Edge.hxx>
52 #include <TFunction_Logbook.hxx>
53 #include <StdFail_NotDone.hxx>
57 #include <utilities.h>
65 //=======================================================================
68 //=======================================================================
69 const Standard_GUID& AdvancedEngine_DividedDiskDriver::GetID()
71 static Standard_GUID aGUID("0b01da9a-c5da-11e1-8d80-78e7d1879630");
75 //=======================================================================
76 //function : AdvancedEngine_DividedDiskDriver
78 //=======================================================================
79 AdvancedEngine_DividedDiskDriver::AdvancedEngine_DividedDiskDriver()
83 //=======================================================================
86 //=======================================================================
87 Standard_Integer AdvancedEngine_DividedDiskDriver::Execute(TFunction_Logbook& log) const
89 if (Label().IsNull()) return 0;
90 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
92 AdvancedEngine_IDividedDisk aData (aFunction);
93 Standard_Integer aType = aFunction->GetType();
98 double R = aData.GetR();
99 double Ratio = aData.GetRatio();
100 int Pattern = aData.GetType();
102 // Build reference disk (in the global coordinate system)
105 if (Pattern == SQUARE)
106 aDisk = MakeDiskSquare( R, Ratio );
107 else if (Pattern == HEXAGON)
108 aDisk = MakeDiskHexagon( R, Ratio );
110 if (aType == DIVIDEDDISK_R_RATIO)
112 int theOrientation = aData.GetOrientation();
113 aShape = TransformShape(aDisk, theOrientation);
115 else if (aType == DIVIDEDDISK_R_VECTOR_PNT)
117 Handle(GEOM_Function) aRefPoint = aData.GetCenter();
118 Handle(GEOM_Function) aRefVector = aData.GetVector();
119 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
120 TopoDS_Shape aShapeVec = aRefVector->GetValue();
122 if (aShapePnt.ShapeType() == TopAbs_VERTEX &&
123 aShapeVec.ShapeType() == TopAbs_EDGE)
125 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
126 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
127 TopoDS_Vertex V1, V2;
128 TopExp::Vertices(anE, V1, V2, Standard_True);
129 if (!V1.IsNull() && !V2.IsNull())
131 gp_Vec aVec (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
133 aShape = TransformShape(aDisk, aPnt, aDir);
138 if (aShape.IsNull()) return 0;
140 aFunction->SetValue(aShape);
142 log.SetTouched(Label());
148 //=======================================================================
149 //function : MakeDiskHexagon
151 //=======================================================================
152 TopoDS_Shell AdvancedEngine_DividedDiskDriver::MakeDiskHexagon(double R, double Ratio) const
160 gp_Ax1 Ax1(Orig,ZDir);
161 gp_Ax2 Ax(Orig,ZDir,XDir);
162 gp_Circ aCircle(Ax, R);
165 // gp_Pnt P4(0.01*Ratio*R,0,0);
167 // gp_Pnt P2 = P3.Rotated(Ax1,-M_PI/6.0);
169 // P4.X()/sqrt(3.0),0);
170 gp_Pnt P1(0.01*Ratio*R*sqrt(3.0)/2,0,0);
172 gp_Pnt P3 = P2.Rotated(Ax1,M_PI/6.0);
178 gp_Ax2 anAx (gp::XOY());
179 Handle(Geom_Plane) aPlane = new Geom_Plane (anAx);
184 TopoDS_Vertex O = BRepBuilderAPI_MakeVertex(Orig);
185 TopoDS_Vertex V1_init = BRepBuilderAPI_MakeVertex(P1);
186 TopoDS_Vertex V2_init = BRepBuilderAPI_MakeVertex(P2);
187 TopoDS_Vertex V3 = BRepBuilderAPI_MakeVertex(P3);
188 TopoDS_Vertex V4 = BRepBuilderAPI_MakeVertex(P4);
190 TopoDS_Vertex V1 = V1_init;
191 TopoDS_Vertex V2 = V2_init;
195 myTrsf.SetRotation(Ax1, M_PI/3.0);
197 BRepBuilderAPI_Transform xform(myTrsf);
198 xform.Perform(V1,Standard_True);
199 TopoDS_Vertex V1_60 = TopoDS::Vertex(xform.Shape());
200 xform.Perform(V2,Standard_True);
201 TopoDS_Vertex V2_60 = TopoDS::Vertex(xform.Shape());
203 // Declaration of shapes (used in the loop)
204 TopoDS_Edge E1, E2, E3, E4, E5, E6, E7, E8, E9;
205 TopoDS_Wire W1, W2, W3;
206 TopoDS_Face F1, F2, F3;
209 BRep_Builder aBuilder;
210 aBuilder.MakeShell(S);
212 // Initialisation of edges
213 TopoDS_Edge E1_init = BRepBuilderAPI_MakeEdge(V1,TopoDS::Vertex(V2.Reversed()));
215 TopoDS_Edge E8_init = BRepBuilderAPI_MakeEdge(O,TopoDS::Vertex(V1.Reversed()));
218 for (int i=1;i<=6;i++)
223 E2 = BRepBuilderAPI_MakeEdge(aCircle, V2, TopoDS::Vertex(V3.Reversed()));
224 E3 = BRepBuilderAPI_MakeEdge(V3,TopoDS::Vertex(V4.Reversed()));
225 E4 = BRepBuilderAPI_MakeEdge(V4,TopoDS::Vertex(V1.Reversed()));
230 E5 = BRepBuilderAPI_MakeEdge(aCircle, V3, TopoDS::Vertex(V2_init.Reversed()));
231 E7 = BRepBuilderAPI_MakeEdge(V1_init,TopoDS::Vertex(V4.Reversed()));
235 E5 = BRepBuilderAPI_MakeEdge(aCircle, V3, TopoDS::Vertex(V2_60.Reversed()));
236 E7 = BRepBuilderAPI_MakeEdge(V1_60,TopoDS::Vertex(V4.Reversed()));
238 E6 = BRepBuilderAPI_MakeEdge(V2_60,TopoDS::Vertex(V1_60.Reversed()));
241 E9 = BRepBuilderAPI_MakeEdge(V1_60,TopoDS::Vertex(O.Reversed()));
247 aBuilder.MakeWire(W1);
251 aBuilder.Add(W1,TopoDS::Edge(E1.Reversed()));
257 aBuilder.MakeWire(W2);
258 aBuilder.Add(W2,TopoDS::Edge(E3.Reversed()));
261 aBuilder.Add(W2,TopoDS::Edge(E1_init.Reversed()));
267 aBuilder.MakeWire(W3);
271 aBuilder.Add(W3,TopoDS::Edge(E8.Reversed()));
272 aBuilder.Add(W3,TopoDS::Edge(E4.Reversed()));
273 aBuilder.Add(W3,TopoDS::Edge(E7.Reversed()));
275 aBuilder.Add(W3,TopoDS::Edge(E8_init.Reversed()));
280 F1 = BRepBuilderAPI_MakeFace(aPlane,W1);
281 F2 = BRepBuilderAPI_MakeFace(aPlane,W2);
282 F3 = BRepBuilderAPI_MakeFace(aPlane,W3);
293 xform.Perform(V1_60,Standard_True);
294 V1_60 = TopoDS::Vertex(xform.Shape());
295 xform.Perform(V2_60,Standard_True);
296 V2_60 = TopoDS::Vertex(xform.Shape());
297 xform.Perform(V3,Standard_True);
298 V3 = TopoDS::Vertex(xform.Shape());
299 xform.Perform(V4,Standard_True);
300 V4 = TopoDS::Vertex(xform.Shape());
302 // "Increment" of edges
310 //=======================================================================
311 //function : MakeDiskSquare
313 //=======================================================================
314 TopoDS_Shape AdvancedEngine_DividedDiskDriver::MakeDiskSquare(double R, double Ratio) const
322 gp_Ax1 Ax1(Orig,ZDir);
323 gp_Ax2 Ax(Orig,ZDir,XDir);
324 gp_Circ aCircle(Ax, R);
327 gp_Pnt P1(0.01*Ratio*R,0,0);
331 gp_Ax2 anAx (gp::XOY());
332 Handle(Geom_Plane) aPlane = new Geom_Plane (anAx);
337 TopoDS_Vertex V1_init = BRepBuilderAPI_MakeVertex(P1);
338 TopoDS_Vertex V2_init = BRepBuilderAPI_MakeVertex(P2);
340 TopoDS_Vertex V1 = V1_init;
341 TopoDS_Vertex V2 = V2_init;
345 myTrsf.SetRotation(Ax1, M_PI/2);
347 BRepBuilderAPI_Transform xform(myTrsf);
348 xform.Perform(V1,Standard_True);
349 TopoDS_Vertex V1_rotated = TopoDS::Vertex(xform.Shape());
350 xform.Perform(V2,Standard_True);
351 TopoDS_Vertex V2_rotated = TopoDS::Vertex(xform.Shape());
353 // Declaration of shapes (used in the loop)
354 TopoDS_Edge E1, E2, E3, E4;
359 BRep_Builder aBuilder;
360 aBuilder.MakeWire(W2); // Central Wire
361 aBuilder.MakeShell(S); // Shell
363 // Initialisation of edges
364 TopoDS_Edge E1_init = BRepBuilderAPI_MakeEdge(V1,TopoDS::Vertex(V2.Reversed()));
367 for (int i=1;i<=4;i++)
372 E3 = BRepBuilderAPI_MakeEdge(V2_rotated,TopoDS::Vertex(V1_rotated.Reversed()));
375 E2 = BRepBuilderAPI_MakeEdge(aCircle, V2, TopoDS::Vertex(V2_init.Reversed()));
376 E4 = BRepBuilderAPI_MakeEdge(V1_init,TopoDS::Vertex(V1.Reversed()));
380 E2 = BRepBuilderAPI_MakeEdge(aCircle, V2, TopoDS::Vertex(V2_rotated.Reversed()));
381 E4 = BRepBuilderAPI_MakeEdge(V1_rotated,TopoDS::Vertex(V1.Reversed()));
386 aBuilder.MakeWire(W1);
390 aBuilder.Add(W1,TopoDS::Edge(E1.Reversed()));
393 aBuilder.Add(W1,TopoDS::Edge(E1_init.Reversed()));
399 aBuilder.Add(W2,TopoDS::Edge(E4.Reversed()));
402 F1 = BRepBuilderAPI_MakeFace(aPlane,W1);
411 xform.Perform(V1_rotated,Standard_True);
412 V1_rotated = TopoDS::Vertex(xform.Shape());
413 xform.Perform(V2_rotated,Standard_True);
414 V2_rotated = TopoDS::Vertex(xform.Shape());
416 // "Increment" of edges
419 // Central square Face
420 F2 = BRepBuilderAPI_MakeFace(aPlane,W2);
427 //=======================================================================
428 //function : TrasformShape(TopoDS_Shape aShape,int theOrientation)
429 //purpose : Perform shape transformation accordingly with specified
431 //=======================================================================
432 TopoDS_Shape AdvancedEngine_DividedDiskDriver::TransformShape(TopoDS_Shape theShape, int theOrientation) const
435 gp_Pnt theOrigin = gp::Origin();
437 switch(theOrientation)
459 gp_Ax3 aWPlane = gp_Ax3(theOrigin, N, Vx);
461 return WPlaneTransform(theShape, aWPlane);
464 //=======================================================================
465 //function : TrasformShape(TopoDS_Shape aShape, gp_Dir V, gp_Pnt P)
466 //purpose : Perform shape transformation accordingly with specified
468 //=======================================================================
469 TopoDS_Shape AdvancedEngine_DividedDiskDriver::TransformShape(TopoDS_Shape theShape, gp_Pnt P, gp_Dir V) const
471 gp_Ax3 aWPlane( P, V );
472 return WPlaneTransform(theShape, aWPlane);
475 //=======================================================================
476 //function : WPlaneTransform
477 //purpose : Perform shape transformation accordingly with the given
479 //=======================================================================
480 TopoDS_Shape AdvancedEngine_DividedDiskDriver::WPlaneTransform(TopoDS_Shape theShape, gp_Ax3 theWPlane) const
483 aTrans.SetTransformation(theWPlane);
485 BRepBuilderAPI_Transform aTransformation (theShape, aTrans, Standard_False);
486 return aTransformation.Shape();
489 //================================================================================
491 * \brief Returns a name of creation operation and names and values of creation parameters
493 //================================================================================
495 bool AdvancedEngine_DividedDiskDriver::
496 GetCreationInformation(std::string& theOperationName,
497 std::vector<GEOM_Param>& theParams)
499 if (Label().IsNull()) return 0;
500 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
502 AdvancedEngine_IDividedDisk aCI( function );
503 Standard_Integer aType = function->GetType();
505 theOperationName = "DIVIDEDDISK";
508 case DIVIDEDDISK_R_RATIO:
509 AddParam( theParams, "Radius", aCI.GetR() );
510 AddParam( theParams, "Ratio", aCI.GetRatio() );
511 AddParam( theParams, "Orientation", aCI.GetOrientation() );
512 AddParam( theParams, "Division pattern", aCI.GetType() );
514 case DIVIDEDDISK_R_VECTOR_PNT:
515 AddParam( theParams, "Center Point", aCI.GetCenter() );
516 AddParam( theParams, "Vector", aCI.GetVector() );
517 AddParam( theParams, "Radius", aCI.GetR() );
518 AddParam( theParams, "Division pattern", aCI.GetType() );
527 IMPLEMENT_STANDARD_HANDLE (AdvancedEngine_DividedDiskDriver,GEOM_BaseDriver);
528 IMPLEMENT_STANDARD_RTTIEXT (AdvancedEngine_DividedDiskDriver,GEOM_BaseDriver);