Back to index

salome-geom  6.5.0
GEOMImpl_ArchimedeDriver.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "GEOMImpl_ArchimedeDriver.hxx"
00024 #include "GEOMImpl_IArchimede.hxx"
00025 #include "GEOMImpl_Types.hxx"
00026 
00027 #include "Archimede_VolumeSection.hxx"
00028 
00029 #include <Basics_OCCTVersion.hxx>
00030 
00031 #include <stdio.h>
00032 
00033 #include <BRepBuilderAPI_MakeFace.hxx>
00034 
00035 #include <TopoDS_Shape.hxx>
00036 #include <TopoDS_Face.hxx>
00037 
00038 #include <Geom_Plane.hxx>
00039 #include <Geom_Geometry.hxx>
00040 #include <Geom_RectangularTrimmedSurface.hxx>
00041 
00042 #include <gp_Pnt.hxx>
00043 #include <gp_Dir.hxx>
00044 
00045 #include <StdFail_NotDone.hxx>
00046 
00047 
00048 //=======================================================================
00049 //function : GetID
00050 //purpose  :
00051 //=======================================================================
00052 const Standard_GUID& GEOMImpl_ArchimedeDriver::GetID()
00053 {
00054   static Standard_GUID aArchimedeDriver("FF1BBB59-5D14-4df2-980B-3A668264EA16");
00055   return aArchimedeDriver;
00056 }
00057 
00058 
00059 //=======================================================================
00060 //function : GEOMImpl_ArchimedeDriver
00061 //purpose  :
00062 //=======================================================================
00063 
00064 GEOMImpl_ArchimedeDriver::GEOMImpl_ArchimedeDriver()
00065 {
00066 }
00067 
00068 //=======================================================================
00069 //function : Execute
00070 //purpose  :
00071 //=======================================================================
00072 Standard_Integer GEOMImpl_ArchimedeDriver::Execute(TFunction_Logbook& log) const
00073 {
00074   if (Label().IsNull()) return 0;
00075   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00076 
00077   Standard_Integer aType = aFunction->GetType();
00078   if (aType != ARCHIMEDE_TYPE) return 0;
00079 
00080   GEOMImpl_IArchimede IA (aFunction);
00081 
00082   Handle(GEOM_Function) aShapeFunction = IA.GetBasicShape();
00083   if (aShapeFunction.IsNull()) return 0;
00084   TopoDS_Shape shape = aShapeFunction->GetValue();
00085   if(shape.IsNull()) return 0;
00086 
00087   Standard_Real aWaterDensity = IA.GetDensity();
00088   Standard_Real aWeight = IA.GetWeight();
00089   Standard_Real aMeshingDeflection = IA.GetDeflection();
00090 
00091   double cste = -1;
00092   if (aWaterDensity != 0.)
00093     cste = aWeight/aWaterDensity;
00094   else
00095     return 0;
00096 
00097   gp_Dir direct (0.0, 0.0, 1.0);
00098   gp_Pnt PosPlan (0.0, 0.0, 0.0);
00099   Geom_Plane PP (PosPlan, direct);
00100   Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(PP.Copy());
00101 
00102   gp_Dir Zdirection (0.0, 0.0, 1.0);
00103   VolumeSection VOL (shape, aMeshingDeflection);
00104   VOL.SetPlane(P);
00105   Handle(Geom_RectangularTrimmedSurface) SurfaceTrimmee;
00106 
00107   if (Zdirection.IsEqual(direct, Precision::Angular()) == Standard_False) {
00108     VOL.MakeRotation(direct);
00109   }
00110 
00111   VOL.CenterOfGravity();
00112   SurfaceTrimmee = VOL.TrimSurf();
00113   Standard_Real Cote = VOL.Archimede(cste, aMeshingDeflection);
00114 
00115   if (Cote == -1) {
00116     double Zmin,Zmax;
00117     VOL.getZ(Zmin,Zmax);
00118     double volume = VOL.CalculateVolume(Zmax) * aWaterDensity;
00119 
00120     char msg[100] = "";
00121     sprintf(msg, "shape sinks to the bottom : Weigth max = %.1f", volume);
00122 
00123     StdFail_NotDone::Raise(msg);
00124   }
00125 
00126   SurfaceTrimmee = VOL.AjustePlan(SurfaceTrimmee,Cote,PosPlan);
00127   if (Zdirection.IsEqual(direct,Precision::Angular()) == Standard_False) {
00128     SurfaceTrimmee = VOL.InvMakeRotation(direct,SurfaceTrimmee);
00129   }
00130 
00131   Standard_Real u1,u2,v1,v2;
00132   SurfaceTrimmee->Bounds(u1,u2,v1,v2);
00133 #if OCC_VERSION_LARGE > 0x06050100 // for OCC-6.5.2 and higher version
00134   TopoDS_Face tirant = BRepBuilderAPI_MakeFace(SurfaceTrimmee, u1, u2, v1, v2, Precision::Confusion());
00135 #else
00136   TopoDS_Face tirant = BRepBuilderAPI_MakeFace(SurfaceTrimmee, u1, u2, v1, v2);
00137 #endif
00138 
00139   if (tirant.IsNull()) {
00140     StdFail_NotDone::Raise("Failed to build secant face");
00141   }
00142 
00143   aFunction->SetValue(tirant);
00144 
00145   log.SetTouched(Label());
00146 
00147   return 1;
00148 }
00149 
00150 
00151 //=======================================================================
00152 //function :  GEOMImpl_ArchimedeDriver_Type_
00153 //purpose  :
00154 //=======================================================================
00155 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ArchimedeDriver_Type_()
00156 {
00157 
00158   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
00159   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
00160   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
00161   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
00162   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
00163   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
00164 
00165 
00166   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
00167   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ArchimedeDriver",
00168                                                          sizeof(GEOMImpl_ArchimedeDriver),
00169                                                          1,
00170                                                          (Standard_Address)_Ancestors,
00171                                                          (Standard_Address)NULL);
00172 
00173   return _aType;
00174 }
00175 
00176 //=======================================================================
00177 //function : DownCast
00178 //purpose  :
00179 //=======================================================================
00180 
00181 const Handle(GEOMImpl_ArchimedeDriver) Handle(GEOMImpl_ArchimedeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
00182 {
00183   Handle(GEOMImpl_ArchimedeDriver) _anOtherObject;
00184 
00185   if (!AnObject.IsNull()) {
00186      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ArchimedeDriver))) {
00187        _anOtherObject = Handle(GEOMImpl_ArchimedeDriver)((Handle(GEOMImpl_ArchimedeDriver)&)AnObject);
00188      }
00189   }
00190 
00191   return _anOtherObject;
00192 }