1 // Copyright (C) 2007-2010 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
23 #include "GEOMImpl_ArchimedeDriver.hxx"
24 #include "GEOMImpl_IArchimede.hxx"
25 #include "GEOMImpl_Types.hxx"
27 #include "Archimede_VolumeSection.hxx"
31 #include <BRepBuilderAPI_MakeFace.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Face.hxx>
36 #include <Geom_Plane.hxx>
37 #include <Geom_Geometry.hxx>
38 #include <Geom_RectangularTrimmedSurface.hxx>
43 #include <StdFail_NotDone.hxx>
46 //=======================================================================
49 //=======================================================================
50 const Standard_GUID& GEOMImpl_ArchimedeDriver::GetID()
52 static Standard_GUID aArchimedeDriver("FF1BBB59-5D14-4df2-980B-3A668264EA16");
53 return aArchimedeDriver;
57 //=======================================================================
58 //function : GEOMImpl_ArchimedeDriver
60 //=======================================================================
62 GEOMImpl_ArchimedeDriver::GEOMImpl_ArchimedeDriver()
66 //=======================================================================
69 //=======================================================================
70 Standard_Integer GEOMImpl_ArchimedeDriver::Execute(TFunction_Logbook& log) const
72 if (Label().IsNull()) return 0;
73 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
75 Standard_Integer aType = aFunction->GetType();
76 if (aType != ARCHIMEDE_TYPE) return 0;
78 GEOMImpl_IArchimede IA (aFunction);
80 Handle(GEOM_Function) aShapeFunction = IA.GetBasicShape();
81 if (aShapeFunction.IsNull()) return 0;
82 TopoDS_Shape shape = aShapeFunction->GetValue();
83 if(shape.IsNull()) return 0;
85 Standard_Real aWaterDensity = IA.GetDensity();
86 Standard_Real aWeight = IA.GetWeight();
87 Standard_Real aMeshingDeflection = IA.GetDeflection();
90 if (aWaterDensity != 0.)
91 cste = aWeight/aWaterDensity;
95 gp_Dir direct (0.0, 0.0, 1.0);
96 gp_Pnt PosPlan (0.0, 0.0, 0.0);
97 Geom_Plane PP (PosPlan, direct);
98 Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(PP.Copy());
100 gp_Dir Zdirection (0.0, 0.0, 1.0);
101 VolumeSection VOL (shape, aMeshingDeflection);
103 Handle(Geom_RectangularTrimmedSurface) SurfaceTrimmee;
105 if (Zdirection.IsEqual(direct, Precision::Angular()) == Standard_False) {
106 VOL.MakeRotation(direct);
109 VOL.CenterOfGravity();
110 SurfaceTrimmee = VOL.TrimSurf();
111 Standard_Real Cote = VOL.Archimede(cste, aMeshingDeflection);
116 double volume = VOL.CalculateVolume(Zmax) * aWaterDensity;
119 sprintf(msg, "shape sinks to the bottom : Weigth max = %.1f", volume);
121 StdFail_NotDone::Raise(msg);
124 SurfaceTrimmee = VOL.AjustePlan(SurfaceTrimmee,Cote,PosPlan);
125 if (Zdirection.IsEqual(direct,Precision::Angular()) == Standard_False) {
126 SurfaceTrimmee = VOL.InvMakeRotation(direct,SurfaceTrimmee);
129 Standard_Real u1,u2,v1,v2;
130 SurfaceTrimmee->Bounds(u1,u2,v1,v2);
131 TopoDS_Face tirant = BRepBuilderAPI_MakeFace(SurfaceTrimmee, u1, u2, v1, v2);
133 if (tirant.IsNull()) {
134 StdFail_NotDone::Raise("Failed to build secant face");
137 aFunction->SetValue(tirant);
139 log.SetTouched(Label());
145 //=======================================================================
146 //function : GEOMImpl_ArchimedeDriver_Type_
148 //=======================================================================
149 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ArchimedeDriver_Type_()
152 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
153 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
154 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
155 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
156 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
157 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
160 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
161 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ArchimedeDriver",
162 sizeof(GEOMImpl_ArchimedeDriver),
164 (Standard_Address)_Ancestors,
165 (Standard_Address)NULL);
170 //=======================================================================
171 //function : DownCast
173 //=======================================================================
175 const Handle(GEOMImpl_ArchimedeDriver) Handle(GEOMImpl_ArchimedeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
177 Handle(GEOMImpl_ArchimedeDriver) _anOtherObject;
179 if (!AnObject.IsNull()) {
180 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ArchimedeDriver))) {
181 _anOtherObject = Handle(GEOMImpl_ArchimedeDriver)((Handle(GEOMImpl_ArchimedeDriver)&)AnObject);
185 return _anOtherObject ;