]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_ArchimedeDriver.cxx
Salome HOME
Modified a method createAndDisplayGO
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ArchimedeDriver.cxx
1
2 #include "GEOMImpl_ArchimedeDriver.hxx"
3 #include "GEOMImpl_IArchimede.hxx"
4 #include "GEOMImpl_Types.hxx"
5
6 #include "Archimede_VolumeSection.hxx"
7
8 #include <stdio.h>
9
10 #include <BRepBuilderAPI_MakeFace.hxx>
11
12 #include <TopoDS_Shape.hxx>
13 #include <TopoDS_Face.hxx>
14
15 #include <Geom_Plane.hxx>
16 #include <Geom_Geometry.hxx>
17 #include <Geom_RectangularTrimmedSurface.hxx>
18
19 #include <gp_Pnt.hxx>
20 #include <gp_Dir.hxx>
21
22 #include <StdFail_NotDone.hxx>
23
24 using namespace std;
25
26 //=======================================================================
27 //function : GetID
28 //purpose  :
29 //=======================================================================
30 const Standard_GUID& GEOMImpl_ArchimedeDriver::GetID()
31 {
32   static Standard_GUID aArchimedeDriver("FF1BBB59-5D14-4df2-980B-3A668264EA16");
33   return aArchimedeDriver;
34 }
35
36
37 //=======================================================================
38 //function : GEOMImpl_ArchimedeDriver
39 //purpose  :
40 //=======================================================================
41
42 GEOMImpl_ArchimedeDriver::GEOMImpl_ArchimedeDriver()
43 {
44 }
45
46 //=======================================================================
47 //function : Execute
48 //purpose  :
49 //=======================================================================
50 Standard_Integer GEOMImpl_ArchimedeDriver::Execute(TFunction_Logbook& log) const
51 {
52   if (Label().IsNull()) return 0;
53   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
54
55   Standard_Integer aType = aFunction->GetType();
56   if (aType != ARCHIMEDE_TYPE) return 0;
57
58   GEOMImpl_IArchimede IA (aFunction);
59
60   Handle(GEOM_Function) aShapeFunction = IA.GetBasicShape();
61   if (aShapeFunction.IsNull()) return 0;
62   TopoDS_Shape shape = aShapeFunction->GetValue();
63   if(shape.IsNull()) return 0;
64
65   Standard_Real aWaterDensity = IA.GetDensity();
66   Standard_Real aWeight = IA.GetWeight();
67   Standard_Real aMeshingDeflection = IA.GetDeflection();
68
69   double cste = -1;
70   if (aWaterDensity != 0.)
71     cste = aWeight/aWaterDensity;
72   else
73     return 0;
74
75   gp_Dir direct (0.0, 0.0, 1.0);
76   gp_Pnt PosPlan (0.0, 0.0, 0.0);
77   Geom_Plane PP (PosPlan, direct);
78   Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(PP.Copy());
79
80   gp_Dir Zdirection (0.0, 0.0, 1.0);
81   VolumeSection VOL (shape, aMeshingDeflection);
82   VOL.SetPlane(P);
83   Handle(Geom_RectangularTrimmedSurface) SurfaceTrimmee;
84
85   if (Zdirection.IsEqual(direct, Precision::Angular()) == Standard_False) {
86     VOL.MakeRotation(direct);
87   }
88
89   VOL.CenterOfGravity();
90   SurfaceTrimmee = VOL.TrimSurf();
91   Standard_Real Cote = VOL.Archimede(cste, aMeshingDeflection);
92
93   if (Cote == -1) {
94     double Zmin,Zmax;
95     VOL.getZ(Zmin,Zmax);
96     double volume = VOL.CalculateVolume(Zmax) * aWaterDensity;
97
98     char msg[100] = "";
99     sprintf(msg, "shape sinks to the bottom : Weigth max = %.1f", volume);
100
101     StdFail_NotDone::Raise(msg);
102   }
103
104   SurfaceTrimmee = VOL.AjustePlan(SurfaceTrimmee,Cote,PosPlan);
105   if (Zdirection.IsEqual(direct,Precision::Angular()) == Standard_False) {
106     SurfaceTrimmee = VOL.InvMakeRotation(direct,SurfaceTrimmee);
107   }
108
109   Standard_Real u1,u2,v1,v2;
110   SurfaceTrimmee->Bounds(u1,u2,v1,v2);
111   TopoDS_Face tirant = BRepBuilderAPI_MakeFace(SurfaceTrimmee, u1, u2, v1, v2);
112
113   if (tirant.IsNull()) {
114     StdFail_NotDone::Raise("Failed to build secant face");
115   }
116
117   aFunction->SetValue(tirant);
118
119   log.SetTouched(Label());
120
121   return 1;
122 }
123
124
125 //=======================================================================
126 //function :  GEOMImpl_ArchimedeDriver_Type_
127 //purpose  :
128 //=======================================================================
129 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ArchimedeDriver_Type_()
130 {
131
132   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
133   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
134   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
135   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
136   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
137   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
138
139
140   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
141   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ArchimedeDriver",
142                                                          sizeof(GEOMImpl_ArchimedeDriver),
143                                                          1,
144                                                          (Standard_Address)_Ancestors,
145                                                          (Standard_Address)NULL);
146
147   return _aType;
148 }
149
150 //=======================================================================
151 //function : DownCast
152 //purpose  :
153 //=======================================================================
154
155 const Handle(GEOMImpl_ArchimedeDriver) Handle(GEOMImpl_ArchimedeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
156 {
157   Handle(GEOMImpl_ArchimedeDriver) _anOtherObject;
158
159   if (!AnObject.IsNull()) {
160      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ArchimedeDriver))) {
161        _anOtherObject = Handle(GEOMImpl_ArchimedeDriver)((Handle(GEOMImpl_ArchimedeDriver)&)AnObject);
162      }
163   }
164
165   return _anOtherObject ;
166 }
167
168