1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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"
29 #include <Basics_OCCTVersion.hxx>
33 #include <BRepBuilderAPI_MakeFace.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Face.hxx>
38 #include <Geom_Plane.hxx>
39 #include <Geom_Geometry.hxx>
40 #include <Geom_RectangularTrimmedSurface.hxx>
45 #include <StdFail_NotDone.hxx>
48 //=======================================================================
51 //=======================================================================
52 const Standard_GUID& GEOMImpl_ArchimedeDriver::GetID()
54 static Standard_GUID aArchimedeDriver("FF1BBB59-5D14-4df2-980B-3A668264EA16");
55 return aArchimedeDriver;
59 //=======================================================================
60 //function : GEOMImpl_ArchimedeDriver
62 //=======================================================================
64 GEOMImpl_ArchimedeDriver::GEOMImpl_ArchimedeDriver()
68 //=======================================================================
71 //=======================================================================
72 Standard_Integer GEOMImpl_ArchimedeDriver::Execute(LOGBOOK& log) const
74 if (Label().IsNull()) return 0;
75 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
77 Standard_Integer aType = aFunction->GetType();
78 if (aType != ARCHIMEDE_TYPE) return 0;
80 GEOMImpl_IArchimede IA (aFunction);
82 Handle(GEOM_Function) aShapeFunction = IA.GetBasicShape();
83 if (aShapeFunction.IsNull()) return 0;
84 TopoDS_Shape shape = aShapeFunction->GetValue();
85 if(shape.IsNull()) return 0;
87 Standard_Real aWaterDensity = IA.GetDensity();
88 Standard_Real aWeight = IA.GetWeight();
89 Standard_Real aMeshingDeflection = IA.GetDeflection();
92 if (aWaterDensity != 0.)
93 cste = aWeight/aWaterDensity;
97 gp_Dir direct (0.0, 0.0, 1.0);
98 gp_Pnt PosPlan (0.0, 0.0, 0.0);
99 Geom_Plane PP (PosPlan, direct);
100 Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(PP.Copy());
102 gp_Dir Zdirection (0.0, 0.0, 1.0);
103 VolumeSection VOL (shape, aMeshingDeflection);
105 Handle(Geom_RectangularTrimmedSurface) SurfaceTrimmee;
107 if (Zdirection.IsEqual(direct, Precision::Angular()) == Standard_False) {
108 VOL.MakeRotation(direct);
111 VOL.CenterOfGravity();
112 SurfaceTrimmee = VOL.TrimSurf();
113 Standard_Real Cote = VOL.Archimede(cste, aMeshingDeflection);
118 double volume = VOL.CalculateVolume(Zmax) * aWaterDensity;
121 sprintf(msg, "shape sinks to the bottom : Weigth max = %.1f", volume);
123 StdFail_NotDone::Raise(msg);
126 SurfaceTrimmee = VOL.AjustePlan(SurfaceTrimmee,Cote,PosPlan);
127 if (Zdirection.IsEqual(direct,Precision::Angular()) == Standard_False) {
128 SurfaceTrimmee = VOL.InvMakeRotation(direct,SurfaceTrimmee);
131 Standard_Real u1,u2,v1,v2;
132 SurfaceTrimmee->Bounds(u1,u2,v1,v2);
133 TopoDS_Face tirant = BRepBuilderAPI_MakeFace(SurfaceTrimmee, u1, u2, v1, v2, Precision::Confusion());
135 if (tirant.IsNull()) {
136 StdFail_NotDone::Raise("Failed to build secant face");
139 aFunction->SetValue(tirant);
141 #if OCC_VERSION_MAJOR < 7
142 log.SetTouched(Label());
144 log->SetTouched(Label());
150 //================================================================================
152 * \brief Returns a name of creation operation and names and values of creation parameters
154 //================================================================================
156 bool GEOMImpl_ArchimedeDriver::
157 GetCreationInformation(std::string& theOperationName,
158 std::vector<GEOM_Param>& theParams)
160 if (Label().IsNull()) return 0;
161 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
163 GEOMImpl_IArchimede IA (function);
164 Standard_Integer aType = function->GetType();
165 if (aType != ARCHIMEDE_TYPE) return 0;
167 theOperationName = "ARCHIMEDE";
169 AddParam( theParams, "Objects", IA.GetBasicShape() );
170 AddParam( theParams, "Weight", IA.GetWeight() );
171 AddParam( theParams, "Water Density", IA.GetDensity() );
172 AddParam( theParams, "Meshing Deflect.", IA.GetDeflection() );
177 OCCT_IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_ArchimedeDriver,GEOM_BaseDriver);