1 // Copyright (C) 2007-2008 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
22 #include <Standard_Stream.hxx>
24 #include <GEOMImpl_DividedDiskDriver.hxx>
25 #include <GEOMImpl_IDividedDisk.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOM_Function.hxx>
33 #include <gp_Circ.hxx>
37 #include <BRep_Builder.hxx>
38 #include <BRepBuilderAPI_MakeFace.hxx>
39 #include <BRepBuilderAPI_MakeEdge.hxx>
40 #include <BRepBuilderAPI_MakeVertex.hxx>
41 #include <BRepBuilderAPI_MakeWire.hxx>
42 #include <BRepBuilderAPI_Transform.hxx>
44 #include <Geom_Plane.hxx>
47 #include <TopoDS_Shape.hxx>
48 #include <TopoDS_Edge.hxx>
50 #include <TFunction_Logbook.hxx>
51 #include <StdFail_NotDone.hxx>
53 #include <utilities.h>
55 //@@ include required header files here @@//
57 //=======================================================================
60 //=======================================================================
61 const Standard_GUID& GEOMImpl_DividedDiskDriver::GetID()
63 static Standard_GUID aGUID("0b01da9a-c5da-11e1-8d80-78e7d1879630");
67 //=======================================================================
68 //function : GEOMImpl_DividedDiskDriver
70 //=======================================================================
71 GEOMImpl_DividedDiskDriver::GEOMImpl_DividedDiskDriver()
75 //=======================================================================
78 //=======================================================================
79 Standard_Integer GEOMImpl_DividedDiskDriver::Execute(TFunction_Logbook& log) const
81 if (Label().IsNull()) return 0;
82 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
84 GEOMImpl_IDividedDisk aData (aFunction);
85 Standard_Integer aType = aFunction->GetType();
89 if (aType == DIVIDEDDISK_R_RATIO) {
92 double R = aData.GetR();
93 double Ratio = aData.GetRatio();
94 int theOrientation = aData.GetOrientation();
102 gp_Ax1 Ax1(Orig,ZDir);
103 gp_Ax2 Ax(Orig,ZDir,XDir);
104 gp_Circ aCircle(Ax, R);
107 gp_Pnt P1(0.01*Ratio*R,0,0);
109 gp_Pnt P3 = P2.Rotated(Ax1,M_PI/6.0);
114 gp_Ax2 anAx (gp::XOY());
115 Handle(Geom_Plane) aPlane = new Geom_Plane (anAx);
120 TopoDS_Vertex O = BRepBuilderAPI_MakeVertex(Orig);
121 TopoDS_Vertex V1_init = BRepBuilderAPI_MakeVertex(P1);
122 TopoDS_Vertex V2_init = BRepBuilderAPI_MakeVertex(P2);
123 TopoDS_Vertex V3 = BRepBuilderAPI_MakeVertex(P3);
124 TopoDS_Vertex V4 = BRepBuilderAPI_MakeVertex(P4);
126 TopoDS_Vertex V1 = V1_init;
127 TopoDS_Vertex V2 = V2_init;
131 myTrsf.SetRotation(Ax1, M_PI/3.0);
133 BRepBuilderAPI_Transform xform(myTrsf);
134 xform.Perform(V1,Standard_True);
135 TopoDS_Vertex V1_60 = TopoDS::Vertex(xform.Shape());
136 xform.Perform(V2,Standard_True);
137 TopoDS_Vertex V2_60 = TopoDS::Vertex(xform.Shape());
139 // Declaration of shapes (used in the loop)
140 TopoDS_Edge E1, E2, E3, E4, E5, E6, E7, E8, E9;
141 TopoDS_Wire W1, W2, W3;
142 TopoDS_Face F1, F2, F3;
145 BRep_Builder aBuilder;
146 aBuilder.MakeShell(S);
148 // Initialisation of edges
149 TopoDS_Edge E1_init = BRepBuilderAPI_MakeEdge(V1,TopoDS::Vertex(V2.Reversed()));
151 TopoDS_Edge E8_init = BRepBuilderAPI_MakeEdge(O,TopoDS::Vertex(V1.Reversed()));
154 for (int i=1;i<=6;i++)
158 E2 = BRepBuilderAPI_MakeEdge(aCircle, V2, TopoDS::Vertex(V3.Reversed()));
159 E3 = BRepBuilderAPI_MakeEdge(V3,TopoDS::Vertex(V4.Reversed()));
160 E4 = BRepBuilderAPI_MakeEdge(V4,TopoDS::Vertex(V1.Reversed()));
165 E5 = BRepBuilderAPI_MakeEdge(aCircle, V3, TopoDS::Vertex(V2_init.Reversed()));
166 E7 = BRepBuilderAPI_MakeEdge(V1_init,TopoDS::Vertex(V4.Reversed()));
170 E5 = BRepBuilderAPI_MakeEdge(aCircle, V3, TopoDS::Vertex(V2_60.Reversed()));
171 E7 = BRepBuilderAPI_MakeEdge(V1_60,TopoDS::Vertex(V4.Reversed()));
173 E6 = BRepBuilderAPI_MakeEdge(V2_60,TopoDS::Vertex(V1_60.Reversed()));
176 E9 = BRepBuilderAPI_MakeEdge(V1_60,TopoDS::Vertex(O.Reversed()));
181 aBuilder.MakeWire(W1);
185 aBuilder.Add(W1,TopoDS::Edge(E1.Reversed()));
191 aBuilder.MakeWire(W2);
192 aBuilder.Add(W2,TopoDS::Edge(E3.Reversed()));
195 aBuilder.Add(W2,TopoDS::Edge(E1_init.Reversed()));
201 aBuilder.MakeWire(W3);
205 aBuilder.Add(W3,TopoDS::Edge(E8.Reversed()));
206 aBuilder.Add(W3,TopoDS::Edge(E4.Reversed()));
207 aBuilder.Add(W3,TopoDS::Edge(E7.Reversed()));
209 aBuilder.Add(W3,TopoDS::Edge(E8_init.Reversed()));
214 F1 = BRepBuilderAPI_MakeFace(aPlane,W1);
215 F2 = BRepBuilderAPI_MakeFace(aPlane,W2);
216 F3 = BRepBuilderAPI_MakeFace(aPlane,W3);
227 xform.Perform(V1_60,Standard_True);
228 V1_60 = TopoDS::Vertex(xform.Shape());
229 xform.Perform(V2_60,Standard_True);
230 V2_60 = TopoDS::Vertex(xform.Shape());
231 xform.Perform(V3,Standard_True);
232 V3 = TopoDS::Vertex(xform.Shape());
233 xform.Perform(V4,Standard_True);
234 V4 = TopoDS::Vertex(xform.Shape());
236 // "Increment" of edges
241 aShape = TransformShape(S, theOrientation);
244 // other construction modes here
247 if (aShape.IsNull()) return 0;
249 aFunction->SetValue(aShape);
251 log.SetTouched(Label());
256 //=======================================================================
257 //function : TrasformShape(int theOrientation)
258 //purpose : Perform shape transformation accordingly with specified
260 //=======================================================================
261 TopoDS_Shape GEOMImpl_DividedDiskDriver::TransformShape(TopoDS_Shape aShape, int theOrientation) const
264 gp_Pnt theOrigin = gp::Origin();
266 switch(theOrientation)
288 gp_Ax3 aWPlane = gp_Ax3(theOrigin, N, Vx);
291 aTrans.SetTransformation(aWPlane);
293 BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
294 return aTransformation.Shape();
297 //=======================================================================
298 //function : GEOMImpl_DividedDiskDriver_Type_
300 //=======================================================================
301 Standard_EXPORT Handle_Standard_Type& GEOMImpl_DividedDiskDriver_Type_()
303 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
304 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
305 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
306 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
307 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
308 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
310 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
311 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_DividedDiskDriver",
312 sizeof(GEOMImpl_DividedDiskDriver),
314 (Standard_Address)_Ancestors,
315 (Standard_Address)NULL);
319 //=======================================================================
320 //function : DownCast
322 //=======================================================================
323 const Handle(GEOMImpl_DividedDiskDriver) Handle(GEOMImpl_DividedDiskDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
325 Handle(GEOMImpl_DividedDiskDriver) _anOtherObject;
327 if (!AnObject.IsNull()) {
328 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_DividedDiskDriver))) {
329 _anOtherObject = Handle(GEOMImpl_DividedDiskDriver)((Handle(GEOMImpl_DividedDiskDriver)&)AnObject);
333 return _anOtherObject;