1 // Copyright (C) 2007-2011 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 "GEOMImpl_ArchimedeDriver.hxx"
23 #include "GEOMImpl_IArchimede.hxx"
24 #include "GEOMImpl_Types.hxx"
26 #include "Archimede_VolumeSection.hxx"
28 #include <Basics_OCCTVersion.hxx>
32 #include <BRepBuilderAPI_MakeFace.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Face.hxx>
37 #include <Geom_Plane.hxx>
38 #include <Geom_Geometry.hxx>
39 #include <Geom_RectangularTrimmedSurface.hxx>
44 #include <StdFail_NotDone.hxx>
47 //=======================================================================
50 //=======================================================================
51 const Standard_GUID& GEOMImpl_ArchimedeDriver::GetID()
53 static Standard_GUID aArchimedeDriver("FF1BBB59-5D14-4df2-980B-3A668264EA16");
54 return aArchimedeDriver;
58 //=======================================================================
59 //function : GEOMImpl_ArchimedeDriver
61 //=======================================================================
63 GEOMImpl_ArchimedeDriver::GEOMImpl_ArchimedeDriver()
67 //=======================================================================
70 //=======================================================================
71 Standard_Integer GEOMImpl_ArchimedeDriver::Execute(TFunction_Logbook& log) const
73 if (Label().IsNull()) return 0;
74 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
76 Standard_Integer aType = aFunction->GetType();
77 if (aType != ARCHIMEDE_TYPE) return 0;
79 GEOMImpl_IArchimede IA (aFunction);
81 Handle(GEOM_Function) aShapeFunction = IA.GetBasicShape();
82 if (aShapeFunction.IsNull()) return 0;
83 TopoDS_Shape shape = aShapeFunction->GetValue();
84 if(shape.IsNull()) return 0;
86 Standard_Real aWaterDensity = IA.GetDensity();
87 Standard_Real aWeight = IA.GetWeight();
88 Standard_Real aMeshingDeflection = IA.GetDeflection();
91 if (aWaterDensity != 0.)
92 cste = aWeight/aWaterDensity;
96 gp_Dir direct (0.0, 0.0, 1.0);
97 gp_Pnt PosPlan (0.0, 0.0, 0.0);
98 Geom_Plane PP (PosPlan, direct);
99 Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(PP.Copy());
101 gp_Dir Zdirection (0.0, 0.0, 1.0);
102 VolumeSection VOL (shape, aMeshingDeflection);
104 Handle(Geom_RectangularTrimmedSurface) SurfaceTrimmee;
106 if (Zdirection.IsEqual(direct, Precision::Angular()) == Standard_False) {
107 VOL.MakeRotation(direct);
110 VOL.CenterOfGravity();
111 SurfaceTrimmee = VOL.TrimSurf();
112 Standard_Real Cote = VOL.Archimede(cste, aMeshingDeflection);
117 double volume = VOL.CalculateVolume(Zmax) * aWaterDensity;
120 sprintf(msg, "shape sinks to the bottom : Weigth max = %.1f", volume);
122 StdFail_NotDone::Raise(msg);
125 SurfaceTrimmee = VOL.AjustePlan(SurfaceTrimmee,Cote,PosPlan);
126 if (Zdirection.IsEqual(direct,Precision::Angular()) == Standard_False) {
127 SurfaceTrimmee = VOL.InvMakeRotation(direct,SurfaceTrimmee);
130 Standard_Real u1,u2,v1,v2;
131 SurfaceTrimmee->Bounds(u1,u2,v1,v2);
132 #if OCC_VERSION_LARGE > 0x06050100 // for OCC-6.5.2 and higher version
133 TopoDS_Face tirant = BRepBuilderAPI_MakeFace(SurfaceTrimmee, u1, u2, v1, v2, Precision::Confusion());
135 TopoDS_Face tirant = BRepBuilderAPI_MakeFace(SurfaceTrimmee, u1, u2, v1, v2);
138 if (tirant.IsNull()) {
139 StdFail_NotDone::Raise("Failed to build secant face");
142 aFunction->SetValue(tirant);
144 log.SetTouched(Label());
150 //=======================================================================
151 //function : GEOMImpl_ArchimedeDriver_Type_
153 //=======================================================================
154 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ArchimedeDriver_Type_()
157 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
158 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
159 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
160 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
161 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
162 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
165 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
166 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ArchimedeDriver",
167 sizeof(GEOMImpl_ArchimedeDriver),
169 (Standard_Address)_Ancestors,
170 (Standard_Address)NULL);
175 //=======================================================================
176 //function : DownCast
178 //=======================================================================
180 const Handle(GEOMImpl_ArchimedeDriver) Handle(GEOMImpl_ArchimedeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
182 Handle(GEOMImpl_ArchimedeDriver) _anOtherObject;
184 if (!AnObject.IsNull()) {
185 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ArchimedeDriver))) {
186 _anOtherObject = Handle(GEOMImpl_ArchimedeDriver)((Handle(GEOMImpl_ArchimedeDriver)&)AnObject);
190 return _anOtherObject;