1 // Copyright (C) 2007-2016 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 <StdFail_NotDone.hxx>
56 #include <utilities.h>
64 //=======================================================================
67 //=======================================================================
68 const Standard_GUID& AdvancedEngine_DividedDiskDriver::GetID()
70 static Standard_GUID aGUID("0b01da9a-c5da-11e1-8d80-78e7d1879630");
74 //=======================================================================
75 //function : AdvancedEngine_DividedDiskDriver
77 //=======================================================================
78 AdvancedEngine_DividedDiskDriver::AdvancedEngine_DividedDiskDriver()
82 //=======================================================================
85 //=======================================================================
86 Standard_Integer AdvancedEngine_DividedDiskDriver::Execute(LOGBOOK& log) const
88 if (Label().IsNull()) return 0;
89 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
91 AdvancedEngine_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 #if OCC_VERSION_MAJOR < 7
142 log.SetTouched(Label());
144 log->SetTouched(Label());
151 //=======================================================================
152 //function : MakeDiskHexagon
154 //=======================================================================
155 TopoDS_Shell AdvancedEngine_DividedDiskDriver::MakeDiskHexagon(double R, double Ratio) const
163 gp_Ax1 Ax1(Orig,ZDir);
164 gp_Ax2 Ax(Orig,ZDir,XDir);
165 gp_Circ aCircle(Ax, R);
168 // gp_Pnt P4(0.01*Ratio*R,0,0);
170 // gp_Pnt P2 = P3.Rotated(Ax1,-M_PI/6.0);
172 // P4.X()/sqrt(3.0),0);
173 gp_Pnt P1(0.01*Ratio*R*sqrt(3.0)/2,0,0);
175 gp_Pnt P3 = P2.Rotated(Ax1,M_PI/6.0);
181 gp_Ax2 anAx (gp::XOY());
182 Handle(Geom_Plane) aPlane = new Geom_Plane (anAx);
187 TopoDS_Vertex O = BRepBuilderAPI_MakeVertex(Orig);
188 TopoDS_Vertex V1_init = BRepBuilderAPI_MakeVertex(P1);
189 TopoDS_Vertex V2_init = BRepBuilderAPI_MakeVertex(P2);
190 TopoDS_Vertex V3 = BRepBuilderAPI_MakeVertex(P3);
191 TopoDS_Vertex V4 = BRepBuilderAPI_MakeVertex(P4);
193 TopoDS_Vertex V1 = V1_init;
194 TopoDS_Vertex V2 = V2_init;
198 myTrsf.SetRotation(Ax1, M_PI/3.0);
200 BRepBuilderAPI_Transform xform(myTrsf);
201 xform.Perform(V1,Standard_True);
202 TopoDS_Vertex V1_60 = TopoDS::Vertex(xform.Shape());
203 xform.Perform(V2,Standard_True);
204 TopoDS_Vertex V2_60 = TopoDS::Vertex(xform.Shape());
206 // Declaration of shapes (used in the loop)
207 TopoDS_Edge E1, E2, E3, E4, E5, E6, E7, E8, E9;
208 TopoDS_Wire W1, W2, W3;
209 TopoDS_Face F1, F2, F3;
212 BRep_Builder aBuilder;
213 aBuilder.MakeShell(S);
215 // Initialisation of edges
216 TopoDS_Edge E1_init = BRepBuilderAPI_MakeEdge(V1,TopoDS::Vertex(V2.Reversed()));
218 TopoDS_Edge E8_init = BRepBuilderAPI_MakeEdge(O,TopoDS::Vertex(V1.Reversed()));
221 for (int i=1;i<=6;i++)
226 E2 = BRepBuilderAPI_MakeEdge(aCircle, V2, TopoDS::Vertex(V3.Reversed()));
227 E3 = BRepBuilderAPI_MakeEdge(V3,TopoDS::Vertex(V4.Reversed()));
228 E4 = BRepBuilderAPI_MakeEdge(V4,TopoDS::Vertex(V1.Reversed()));
233 E5 = BRepBuilderAPI_MakeEdge(aCircle, V3, TopoDS::Vertex(V2_init.Reversed()));
234 E7 = BRepBuilderAPI_MakeEdge(V1_init,TopoDS::Vertex(V4.Reversed()));
238 E5 = BRepBuilderAPI_MakeEdge(aCircle, V3, TopoDS::Vertex(V2_60.Reversed()));
239 E7 = BRepBuilderAPI_MakeEdge(V1_60,TopoDS::Vertex(V4.Reversed()));
241 E6 = BRepBuilderAPI_MakeEdge(V2_60,TopoDS::Vertex(V1_60.Reversed()));
244 E9 = BRepBuilderAPI_MakeEdge(V1_60,TopoDS::Vertex(O.Reversed()));
250 aBuilder.MakeWire(W1);
254 aBuilder.Add(W1,TopoDS::Edge(E1.Reversed()));
260 aBuilder.MakeWire(W2);
261 aBuilder.Add(W2,TopoDS::Edge(E3.Reversed()));
264 aBuilder.Add(W2,TopoDS::Edge(E1_init.Reversed()));
270 aBuilder.MakeWire(W3);
274 aBuilder.Add(W3,TopoDS::Edge(E8.Reversed()));
275 aBuilder.Add(W3,TopoDS::Edge(E4.Reversed()));
276 aBuilder.Add(W3,TopoDS::Edge(E7.Reversed()));
278 aBuilder.Add(W3,TopoDS::Edge(E8_init.Reversed()));
283 F1 = BRepBuilderAPI_MakeFace(aPlane,W1);
284 F2 = BRepBuilderAPI_MakeFace(aPlane,W2);
285 F3 = BRepBuilderAPI_MakeFace(aPlane,W3);
296 xform.Perform(V1_60,Standard_True);
297 V1_60 = TopoDS::Vertex(xform.Shape());
298 xform.Perform(V2_60,Standard_True);
299 V2_60 = TopoDS::Vertex(xform.Shape());
300 xform.Perform(V3,Standard_True);
301 V3 = TopoDS::Vertex(xform.Shape());
302 xform.Perform(V4,Standard_True);
303 V4 = TopoDS::Vertex(xform.Shape());
305 // "Increment" of edges
313 //=======================================================================
314 //function : MakeDiskSquare
316 //=======================================================================
317 TopoDS_Shape AdvancedEngine_DividedDiskDriver::MakeDiskSquare(double R, double Ratio) const
325 gp_Ax1 Ax1(Orig,ZDir);
326 gp_Ax2 Ax(Orig,ZDir,XDir);
327 gp_Circ aCircle(Ax, R);
330 gp_Pnt P1(0.01*Ratio*R,0,0);
334 gp_Ax2 anAx (gp::XOY());
335 Handle(Geom_Plane) aPlane = new Geom_Plane (anAx);
340 TopoDS_Vertex V1_init = BRepBuilderAPI_MakeVertex(P1);
341 TopoDS_Vertex V2_init = BRepBuilderAPI_MakeVertex(P2);
343 TopoDS_Vertex V1 = V1_init;
344 TopoDS_Vertex V2 = V2_init;
348 myTrsf.SetRotation(Ax1, M_PI/2);
350 BRepBuilderAPI_Transform xform(myTrsf);
351 xform.Perform(V1,Standard_True);
352 TopoDS_Vertex V1_rotated = TopoDS::Vertex(xform.Shape());
353 xform.Perform(V2,Standard_True);
354 TopoDS_Vertex V2_rotated = TopoDS::Vertex(xform.Shape());
356 // Declaration of shapes (used in the loop)
357 TopoDS_Edge E1, E2, E3, E4;
362 BRep_Builder aBuilder;
363 aBuilder.MakeWire(W2); // Central Wire
364 aBuilder.MakeShell(S); // Shell
366 // Initialisation of edges
367 TopoDS_Edge E1_init = BRepBuilderAPI_MakeEdge(V1,TopoDS::Vertex(V2.Reversed()));
370 for (int i=1;i<=4;i++)
375 E3 = BRepBuilderAPI_MakeEdge(V2_rotated,TopoDS::Vertex(V1_rotated.Reversed()));
378 E2 = BRepBuilderAPI_MakeEdge(aCircle, V2, TopoDS::Vertex(V2_init.Reversed()));
379 E4 = BRepBuilderAPI_MakeEdge(V1_init,TopoDS::Vertex(V1.Reversed()));
383 E2 = BRepBuilderAPI_MakeEdge(aCircle, V2, TopoDS::Vertex(V2_rotated.Reversed()));
384 E4 = BRepBuilderAPI_MakeEdge(V1_rotated,TopoDS::Vertex(V1.Reversed()));
389 aBuilder.MakeWire(W1);
393 aBuilder.Add(W1,TopoDS::Edge(E1.Reversed()));
396 aBuilder.Add(W1,TopoDS::Edge(E1_init.Reversed()));
402 aBuilder.Add(W2,TopoDS::Edge(E4.Reversed()));
405 F1 = BRepBuilderAPI_MakeFace(aPlane,W1);
414 xform.Perform(V1_rotated,Standard_True);
415 V1_rotated = TopoDS::Vertex(xform.Shape());
416 xform.Perform(V2_rotated,Standard_True);
417 V2_rotated = TopoDS::Vertex(xform.Shape());
419 // "Increment" of edges
422 // Central square Face
423 F2 = BRepBuilderAPI_MakeFace(aPlane,W2);
430 //=======================================================================
431 //function : TrasformShape(TopoDS_Shape aShape,int theOrientation)
432 //purpose : Perform shape transformation accordingly with specified
434 //=======================================================================
435 TopoDS_Shape AdvancedEngine_DividedDiskDriver::TransformShape(TopoDS_Shape theShape, int theOrientation) const
438 gp_Pnt theOrigin = gp::Origin();
440 switch(theOrientation)
462 gp_Ax3 aWPlane = gp_Ax3(theOrigin, N, Vx);
464 return WPlaneTransform(theShape, aWPlane);
467 //=======================================================================
468 //function : TrasformShape(TopoDS_Shape aShape, gp_Dir V, gp_Pnt P)
469 //purpose : Perform shape transformation accordingly with specified
471 //=======================================================================
472 TopoDS_Shape AdvancedEngine_DividedDiskDriver::TransformShape(TopoDS_Shape theShape, gp_Pnt P, gp_Dir V) const
474 gp_Ax3 aWPlane( P, V );
475 return WPlaneTransform(theShape, aWPlane);
478 //=======================================================================
479 //function : WPlaneTransform
480 //purpose : Perform shape transformation accordingly with the given
482 //=======================================================================
483 TopoDS_Shape AdvancedEngine_DividedDiskDriver::WPlaneTransform(TopoDS_Shape theShape, gp_Ax3 theWPlane) const
486 aTrans.SetTransformation(theWPlane);
488 BRepBuilderAPI_Transform aTransformation (theShape, aTrans, Standard_False);
489 return aTransformation.Shape();
492 //================================================================================
494 * \brief Returns a name of creation operation and names and values of creation parameters
496 //================================================================================
498 bool AdvancedEngine_DividedDiskDriver::
499 GetCreationInformation(std::string& theOperationName,
500 std::vector<GEOM_Param>& theParams)
502 if (Label().IsNull()) return 0;
503 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
505 AdvancedEngine_IDividedDisk aCI( function );
506 Standard_Integer aType = function->GetType();
508 theOperationName = "DIVIDEDDISK";
511 case DIVIDEDDISK_R_RATIO:
512 AddParam( theParams, "Radius", aCI.GetR() );
513 AddParam( theParams, "Ratio", aCI.GetRatio() );
514 AddParam( theParams, "Orientation", aCI.GetOrientation() );
515 AddParam( theParams, "Division pattern", aCI.GetType() );
517 case DIVIDEDDISK_R_VECTOR_PNT:
518 AddParam( theParams, "Center Point", aCI.GetCenter() );
519 AddParam( theParams, "Vector", aCI.GetVector() );
520 AddParam( theParams, "Radius", aCI.GetR() );
521 AddParam( theParams, "Division pattern", aCI.GetType() );
530 OCCT_IMPLEMENT_STANDARD_RTTIEXT (AdvancedEngine_DividedDiskDriver,GEOM_BaseDriver);