1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "GEOMImpl_ArchimedeDriver.hxx"
22 #include "GEOMImpl_IArchimede.hxx"
23 #include "GEOMImpl_Types.hxx"
25 #include "Archimede_VolumeSection.hxx"
29 #include <BRepBuilderAPI_MakeFace.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Face.hxx>
34 #include <Geom_Plane.hxx>
35 #include <Geom_Geometry.hxx>
36 #include <Geom_RectangularTrimmedSurface.hxx>
41 #include <StdFail_NotDone.hxx>
45 //=======================================================================
48 //=======================================================================
49 const Standard_GUID& GEOMImpl_ArchimedeDriver::GetID()
51 static Standard_GUID aArchimedeDriver("FF1BBB59-5D14-4df2-980B-3A668264EA16");
52 return aArchimedeDriver;
56 //=======================================================================
57 //function : GEOMImpl_ArchimedeDriver
59 //=======================================================================
61 GEOMImpl_ArchimedeDriver::GEOMImpl_ArchimedeDriver()
65 //=======================================================================
68 //=======================================================================
69 Standard_Integer GEOMImpl_ArchimedeDriver::Execute(TFunction_Logbook& log) const
71 if (Label().IsNull()) return 0;
72 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
74 Standard_Integer aType = aFunction->GetType();
75 if (aType != ARCHIMEDE_TYPE) return 0;
77 GEOMImpl_IArchimede IA (aFunction);
79 Handle(GEOM_Function) aShapeFunction = IA.GetBasicShape();
80 if (aShapeFunction.IsNull()) return 0;
81 TopoDS_Shape shape = aShapeFunction->GetValue();
82 if(shape.IsNull()) return 0;
84 Standard_Real aWaterDensity = IA.GetDensity();
85 Standard_Real aWeight = IA.GetWeight();
86 Standard_Real aMeshingDeflection = IA.GetDeflection();
89 if (aWaterDensity != 0.)
90 cste = aWeight/aWaterDensity;
94 gp_Dir direct (0.0, 0.0, 1.0);
95 gp_Pnt PosPlan (0.0, 0.0, 0.0);
96 Geom_Plane PP (PosPlan, direct);
97 Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(PP.Copy());
99 gp_Dir Zdirection (0.0, 0.0, 1.0);
100 VolumeSection VOL (shape, aMeshingDeflection);
102 Handle(Geom_RectangularTrimmedSurface) SurfaceTrimmee;
104 if (Zdirection.IsEqual(direct, Precision::Angular()) == Standard_False) {
105 VOL.MakeRotation(direct);
108 VOL.CenterOfGravity();
109 SurfaceTrimmee = VOL.TrimSurf();
110 Standard_Real Cote = VOL.Archimede(cste, aMeshingDeflection);
115 double volume = VOL.CalculateVolume(Zmax) * aWaterDensity;
118 sprintf(msg, "shape sinks to the bottom : Weigth max = %.1f", volume);
120 StdFail_NotDone::Raise(msg);
123 SurfaceTrimmee = VOL.AjustePlan(SurfaceTrimmee,Cote,PosPlan);
124 if (Zdirection.IsEqual(direct,Precision::Angular()) == Standard_False) {
125 SurfaceTrimmee = VOL.InvMakeRotation(direct,SurfaceTrimmee);
128 Standard_Real u1,u2,v1,v2;
129 SurfaceTrimmee->Bounds(u1,u2,v1,v2);
130 TopoDS_Face tirant = BRepBuilderAPI_MakeFace(SurfaceTrimmee, u1, u2, v1, v2);
132 if (tirant.IsNull()) {
133 StdFail_NotDone::Raise("Failed to build secant face");
136 aFunction->SetValue(tirant);
138 log.SetTouched(Label());
144 //=======================================================================
145 //function : GEOMImpl_ArchimedeDriver_Type_
147 //=======================================================================
148 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ArchimedeDriver_Type_()
151 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
152 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
153 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
154 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
155 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
156 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
159 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
160 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ArchimedeDriver",
161 sizeof(GEOMImpl_ArchimedeDriver),
163 (Standard_Address)_Ancestors,
164 (Standard_Address)NULL);
169 //=======================================================================
170 //function : DownCast
172 //=======================================================================
174 const Handle(GEOMImpl_ArchimedeDriver) Handle(GEOMImpl_ArchimedeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
176 Handle(GEOMImpl_ArchimedeDriver) _anOtherObject;
178 if (!AnObject.IsNull()) {
179 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ArchimedeDriver))) {
180 _anOtherObject = Handle(GEOMImpl_ArchimedeDriver)((Handle(GEOMImpl_ArchimedeDriver)&)AnObject);
184 return _anOtherObject ;