2 #include "GEOMImpl_ArchimedeDriver.hxx"
3 #include "GEOMImpl_IArchimede.hxx"
4 #include "GEOMImpl_Types.hxx"
6 #include "Archimede_VolumeSection.hxx"
10 #include <BRepBuilderAPI_MakeFace.hxx>
12 #include <TopoDS_Shape.hxx>
13 #include <TopoDS_Face.hxx>
15 #include <Geom_Plane.hxx>
16 #include <Geom_Geometry.hxx>
17 #include <Geom_RectangularTrimmedSurface.hxx>
22 #include <StdFail_NotDone.hxx>
26 //=======================================================================
29 //=======================================================================
30 const Standard_GUID& GEOMImpl_ArchimedeDriver::GetID()
32 static Standard_GUID aArchimedeDriver("FF1BBB59-5D14-4df2-980B-3A668264EA16");
33 return aArchimedeDriver;
37 //=======================================================================
38 //function : GEOMImpl_ArchimedeDriver
40 //=======================================================================
42 GEOMImpl_ArchimedeDriver::GEOMImpl_ArchimedeDriver()
46 //=======================================================================
49 //=======================================================================
50 Standard_Integer GEOMImpl_ArchimedeDriver::Execute(TFunction_Logbook& log) const
52 if (Label().IsNull()) return 0;
53 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
55 Standard_Integer aType = aFunction->GetType();
56 if (aType != ARCHIMEDE_TYPE) return 0;
58 GEOMImpl_IArchimede IA (aFunction);
60 Handle(GEOM_Function) aShapeFunction = IA.GetBasicShape();
61 if (aShapeFunction.IsNull()) return 0;
62 TopoDS_Shape shape = aShapeFunction->GetValue();
63 if(shape.IsNull()) return 0;
65 Standard_Real aWaterDensity = IA.GetDensity();
66 Standard_Real aWeight = IA.GetWeight();
67 Standard_Real aMeshingDeflection = IA.GetDeflection();
70 if (aWaterDensity != 0.)
71 cste = aWeight/aWaterDensity;
75 gp_Dir direct (0.0, 0.0, 1.0);
76 gp_Pnt PosPlan (0.0, 0.0, 0.0);
77 Geom_Plane PP (PosPlan, direct);
78 Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(PP.Copy());
80 gp_Dir Zdirection (0.0, 0.0, 1.0);
81 VolumeSection VOL (shape, aMeshingDeflection);
83 Handle(Geom_RectangularTrimmedSurface) SurfaceTrimmee;
85 if (Zdirection.IsEqual(direct, Precision::Angular()) == Standard_False) {
86 VOL.MakeRotation(direct);
89 VOL.CenterOfGravity();
90 SurfaceTrimmee = VOL.TrimSurf();
91 Standard_Real Cote = VOL.Archimede(cste, aMeshingDeflection);
96 double volume = VOL.CalculateVolume(Zmax) * aWaterDensity;
99 sprintf(msg, "shape sinks to the bottom : Weigth max = %.1f", volume);
101 StdFail_NotDone::Raise(msg);
104 SurfaceTrimmee = VOL.AjustePlan(SurfaceTrimmee,Cote,PosPlan);
105 if (Zdirection.IsEqual(direct,Precision::Angular()) == Standard_False) {
106 SurfaceTrimmee = VOL.InvMakeRotation(direct,SurfaceTrimmee);
109 Standard_Real u1,u2,v1,v2;
110 SurfaceTrimmee->Bounds(u1,u2,v1,v2);
111 TopoDS_Face tirant = BRepBuilderAPI_MakeFace(SurfaceTrimmee, u1, u2, v1, v2);
113 if (tirant.IsNull()) {
114 StdFail_NotDone::Raise("Failed to build secant face");
117 aFunction->SetValue(tirant);
119 log.SetTouched(Label());
125 //=======================================================================
126 //function : GEOMImpl_ArchimedeDriver_Type_
128 //=======================================================================
129 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ArchimedeDriver_Type_()
132 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
133 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
134 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
135 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
136 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
137 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
140 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
141 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ArchimedeDriver",
142 sizeof(GEOMImpl_ArchimedeDriver),
144 (Standard_Address)_Ancestors,
145 (Standard_Address)NULL);
150 //=======================================================================
151 //function : DownCast
153 //=======================================================================
155 const Handle(GEOMImpl_ArchimedeDriver) Handle(GEOMImpl_ArchimedeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
157 Handle(GEOMImpl_ArchimedeDriver) _anOtherObject;
159 if (!AnObject.IsNull()) {
160 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ArchimedeDriver))) {
161 _anOtherObject = Handle(GEOMImpl_ArchimedeDriver)((Handle(GEOMImpl_ArchimedeDriver)&)AnObject);
165 return _anOtherObject ;