]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_DividedDiskDriver.cxx
Salome HOME
Missing files
[modules/geom.git] / src / GEOMImpl / GEOMImpl_DividedDiskDriver.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 #include <Standard_Stream.hxx>
23
24 #include <GEOMImpl_DividedDiskDriver.hxx>
25 #include <GEOMImpl_IDividedDisk.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOM_Function.hxx>
28
29 // OCCT includes
30 #include <gp_Pnt.hxx>
31 #include <gp_Dir.hxx>
32 #include <gp_Lin.hxx>
33 #include <gp_Circ.hxx>
34 #include <gp_Ax1.hxx>
35 #include <gp_Ax2.hxx>
36
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>
43
44 #include <Geom_Plane.hxx>
45
46 #include <TopoDS.hxx>
47 #include <TopoDS_Shape.hxx>
48 #include <TopoDS_Edge.hxx>
49
50 #include <TFunction_Logbook.hxx>
51 #include <StdFail_NotDone.hxx>
52
53 #include <utilities.h>
54
55 //@@ include required header files here @@//
56
57 //=======================================================================
58 //function : GetID
59 //purpose  :
60 //=======================================================================
61 const Standard_GUID& GEOMImpl_DividedDiskDriver::GetID()
62 {
63   static Standard_GUID aGUID("0b01da9a-c5da-11e1-8d80-78e7d1879630");
64   return aGUID;
65 }
66
67 //=======================================================================
68 //function : GEOMImpl_DividedDiskDriver
69 //purpose  :
70 //=======================================================================
71 GEOMImpl_DividedDiskDriver::GEOMImpl_DividedDiskDriver()
72 {
73 }
74
75 //=======================================================================
76 //function : Execute
77 //purpose  :
78 //=======================================================================
79 Standard_Integer GEOMImpl_DividedDiskDriver::Execute(TFunction_Logbook& log) const
80 {
81   if (Label().IsNull()) return 0;
82   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
83
84   GEOMImpl_IDividedDisk aData (aFunction);
85   Standard_Integer aType = aFunction->GetType();
86
87   TopoDS_Shape aShape;
88
89   if (aType == DIVIDEDDISK_R_RATIO) {
90     
91     // Getting data
92     double R = aData.GetR();
93     double Ratio = aData.GetRatio();
94     
95     // Geometry
96     gp_Dir ZDir(0,0,1);
97     gp_Dir XDir(1,0,0);
98     gp_Pnt Orig(0,0,0);
99     
100     // Circle
101     gp_Ax1 Ax1(Orig,ZDir);
102     gp_Ax2 Ax(Orig,ZDir,XDir);
103     gp_Circ aCircle(Ax, R);
104     
105     // Points
106     gp_Pnt P1(0.01*Ratio*R,0,0);
107     gp_Pnt P2(R,0,0);
108     gp_Pnt P3    = P2.Rotated(Ax1,M_PI/6.0);
109     gp_Pnt P4(P1.X(), 
110               P1.X()/sqrt(3.0),0);
111     
112     //surfaces
113     gp_Ax2 anAx (gp::XOY());
114     Handle(Geom_Plane) aPlane = new Geom_Plane (anAx);
115     
116     // Topology
117     
118     // Vertices
119     TopoDS_Vertex O  = BRepBuilderAPI_MakeVertex(Orig);
120     TopoDS_Vertex V1_init = BRepBuilderAPI_MakeVertex(P1);
121     TopoDS_Vertex V2_init = BRepBuilderAPI_MakeVertex(P2);
122     TopoDS_Vertex V3 = BRepBuilderAPI_MakeVertex(P3);
123     TopoDS_Vertex V4 = BRepBuilderAPI_MakeVertex(P4);
124     
125     TopoDS_Vertex V1 = V1_init;
126     TopoDS_Vertex V2 = V2_init;
127     
128     //Rotation
129     gp_Trsf myTrsf;
130     myTrsf.SetRotation(Ax1, M_PI/3.0);
131     
132     BRepBuilderAPI_Transform xform(myTrsf);
133     xform.Perform(V1,Standard_True);
134     TopoDS_Vertex V1_60 = TopoDS::Vertex(xform.Shape()); 
135     xform.Perform(V2,Standard_True);
136     TopoDS_Vertex V2_60 = TopoDS::Vertex(xform.Shape());
137     
138     // Declaration of shapes (used in the loop) 
139     TopoDS_Edge E1, E2, E3, E4, E5, E6, E7, E8, E9;
140     TopoDS_Wire W1, W2, W3;
141     TopoDS_Face F1, F2, F3;   
142     TopoDS_Shell S;
143     
144     BRep_Builder aBuilder;
145     aBuilder.MakeShell(S);
146     
147     // Initialisation of edges
148     TopoDS_Edge E1_init = BRepBuilderAPI_MakeEdge(V1,TopoDS::Vertex(V2.Reversed()));
149     E1 = E1_init;
150     TopoDS_Edge E8_init = BRepBuilderAPI_MakeEdge(O,TopoDS::Vertex(V1.Reversed()));
151     E8 = E8_init;
152     
153     for (int i=1;i<=6;i++)
154     { 
155       // Edges
156       // for Face1
157       E2 = BRepBuilderAPI_MakeEdge(aCircle, V2, TopoDS::Vertex(V3.Reversed())); 
158       E3 = BRepBuilderAPI_MakeEdge(V3,TopoDS::Vertex(V4.Reversed()));
159       E4 = BRepBuilderAPI_MakeEdge(V4,TopoDS::Vertex(V1.Reversed()));
160        
161       // for Face2
162       if (i==6)
163       {
164         E5 = BRepBuilderAPI_MakeEdge(aCircle, V3, TopoDS::Vertex(V2_init.Reversed()));
165         E7 = BRepBuilderAPI_MakeEdge(V1_init,TopoDS::Vertex(V4.Reversed()));
166       }
167       else
168       {
169         E5 = BRepBuilderAPI_MakeEdge(aCircle, V3, TopoDS::Vertex(V2_60.Reversed()));
170         E7 = BRepBuilderAPI_MakeEdge(V1_60,TopoDS::Vertex(V4.Reversed()));
171       }    
172       E6 = BRepBuilderAPI_MakeEdge(V2_60,TopoDS::Vertex(V1_60.Reversed()));
173       
174       // for Face3
175       E9 = BRepBuilderAPI_MakeEdge(V1_60,TopoDS::Vertex(O.Reversed()));
176       
177       
178       // Wires
179       //Wire1
180       aBuilder.MakeWire(W1);
181       if (i==1)
182         aBuilder.Add(W1,E1);
183       else
184         aBuilder.Add(W1,TopoDS::Edge(E1.Reversed()));
185       aBuilder.Add(W1,E2);
186       aBuilder.Add(W1,E3);
187       aBuilder.Add(W1,E4);
188       
189       // Wire 2
190       aBuilder.MakeWire(W2);
191       aBuilder.Add(W2,TopoDS::Edge(E3.Reversed()));
192       aBuilder.Add(W2,E5);
193       if (i==6)
194         aBuilder.Add(W2,TopoDS::Edge(E1_init.Reversed()));
195       else
196         aBuilder.Add(W2,E6);
197       aBuilder.Add(W2,E7);
198       
199       // Wire3
200       aBuilder.MakeWire(W3);
201       if (i==1)
202         aBuilder.Add(W3,E8);
203       else 
204         aBuilder.Add(W3,TopoDS::Edge(E8.Reversed()));    
205       aBuilder.Add(W3,TopoDS::Edge(E4.Reversed()));
206       aBuilder.Add(W3,TopoDS::Edge(E7.Reversed()));
207       if (i==6)
208         aBuilder.Add(W3,TopoDS::Edge(E8_init.Reversed()));
209       else
210         aBuilder.Add(W3,E9);
211         
212       // Faces creation
213       F1 = BRepBuilderAPI_MakeFace(aPlane,W1);
214       F2 = BRepBuilderAPI_MakeFace(aPlane,W2);
215       F3 = BRepBuilderAPI_MakeFace(aPlane,W3);
216       
217       //Shell
218       aBuilder.Add(S, F1);
219       aBuilder.Add(S, F2);
220       aBuilder.Add(S, F3);
221       
222       
223       // rotation
224       V1=V1_60;
225       V2=V2_60;
226       
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());
235       
236       // "Increment" of edges
237       E1=E6;
238       E8=E9;         
239     }
240     
241     aShape = S;
242   }
243   else {
244     // other construction modes here
245   }
246
247   if (aShape.IsNull()) return 0;
248
249   aFunction->SetValue(aShape);
250
251   log.SetTouched(Label());
252
253   return 1;
254 }
255
256 //=======================================================================
257 //function :  GEOMImpl_DividedDiskDriver_Type_
258 //purpose  :
259 //=======================================================================
260 Standard_EXPORT Handle_Standard_Type& GEOMImpl_DividedDiskDriver_Type_()
261 {
262   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
263   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
264   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
265   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
266   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
267   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
268
269   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
270   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_DividedDiskDriver",
271                                                          sizeof(GEOMImpl_DividedDiskDriver),
272                                                          1,
273                                                          (Standard_Address)_Ancestors,
274                                                          (Standard_Address)NULL);
275   return _aType;
276 }
277
278 //=======================================================================
279 //function : DownCast
280 //purpose  :
281 //=======================================================================
282 const Handle(GEOMImpl_DividedDiskDriver) Handle(GEOMImpl_DividedDiskDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
283 {
284   Handle(GEOMImpl_DividedDiskDriver) _anOtherObject;
285
286   if (!AnObject.IsNull()) {
287      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_DividedDiskDriver))) {
288        _anOtherObject = Handle(GEOMImpl_DividedDiskDriver)((Handle(GEOMImpl_DividedDiskDriver)&)AnObject);
289      }
290   }
291
292   return _anOtherObject;
293 }