Salome HOME
Update mail address
[modules/geom.git] / src / GEOMImpl / GEOMImpl_MeasureDriver.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 #include <Standard_Stream.hxx>
22
23 #include <GEOMImpl_MeasureDriver.hxx>
24 #include <GEOMImpl_IMeasure.hxx>
25 #include <GEOMImpl_IMeasureOperations.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOM_Function.hxx>
28
29 #include <BRep_Tool.hxx>
30 #include <BRepGProp.hxx>
31 #include <BRepBuilderAPI_MakeVertex.hxx>
32
33 #include <TopAbs.hxx>
34 #include <TopoDS.hxx>
35 #include <TopoDS_Shape.hxx>
36
37 #include <GProp_GProps.hxx>
38
39 #include <gp_Pnt.hxx>
40 #include <Precision.hxx>
41 #include <Standard_NullObject.hxx>
42
43 //=======================================================================
44 //function : GetID
45 //purpose  :
46 //======================================================================= 
47 const Standard_GUID& GEOMImpl_MeasureDriver::GetID()
48 {
49   static Standard_GUID aMeasureDriver("FF1BBB65-5D14-4df2-980B-3A668264EA16");
50   return aMeasureDriver; 
51 }
52
53
54 //=======================================================================
55 //function : GEOMImpl_MeasureDriver
56 //purpose  : 
57 //=======================================================================
58 GEOMImpl_MeasureDriver::GEOMImpl_MeasureDriver() 
59 {
60 }
61
62 //=======================================================================
63 //function : Execute
64 //purpose  :
65 //======================================================================= 
66 Standard_Integer GEOMImpl_MeasureDriver::Execute(TFunction_Logbook& log) const
67 {
68   if (Label().IsNull()) return 0;    
69   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
70
71   GEOMImpl_IMeasure aCI (aFunction);
72   Standard_Integer aType = aFunction->GetType();
73
74   TopoDS_Shape aShape;
75
76   if (aType == CDG_MEASURE) {
77     Handle(GEOM_Function) aRefBase = aCI.GetBase();
78     TopoDS_Shape aShapeBase = aRefBase->GetValue();
79     if (aShapeBase.IsNull()) {
80       Standard_NullObject::Raise("Shape for centre of mass calculation is null");
81     }
82
83     GProp_GProps aSystem;
84     gp_Pnt aCenterMass;
85
86     if (aShapeBase.ShapeType() == TopAbs_VERTEX) {
87       aCenterMass = BRep_Tool::Pnt(TopoDS::Vertex(aShapeBase));
88     } else if (aShapeBase.ShapeType() == TopAbs_EDGE || aShapeBase.ShapeType() == TopAbs_WIRE) {
89       BRepGProp::LinearProperties(aShapeBase, aSystem);
90       aCenterMass = aSystem.CentreOfMass();
91     } else if (aShapeBase.ShapeType() == TopAbs_FACE || aShapeBase.ShapeType() == TopAbs_SHELL) {
92       BRepGProp::SurfaceProperties(aShapeBase, aSystem);
93       aCenterMass = aSystem.CentreOfMass();
94     } else {
95       BRepGProp::VolumeProperties(aShapeBase, aSystem);
96       aCenterMass = aSystem.CentreOfMass();
97     }
98
99     aShape = BRepBuilderAPI_MakeVertex(aCenterMass).Shape();
100
101   } else {
102   }
103
104   if (aShape.IsNull()) return 0;
105
106   aFunction->SetValue(aShape);
107
108   log.SetTouched(Label()); 
109
110   return 1;    
111 }
112
113
114 //=======================================================================
115 //function :  GEOMImpl_MeasureDriver_Type_
116 //purpose  :
117 //======================================================================= 
118 Standard_EXPORT Handle_Standard_Type& GEOMImpl_MeasureDriver_Type_()
119 {
120
121   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
122   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
123   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
124   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
125   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
126   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
127  
128
129   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
130   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_MeasureDriver",
131                                                          sizeof(GEOMImpl_MeasureDriver),
132                                                          1,
133                                                          (Standard_Address)_Ancestors,
134                                                          (Standard_Address)NULL);
135
136   return _aType;
137 }
138
139 //=======================================================================
140 //function : DownCast
141 //purpose  :
142 //======================================================================= 
143 const Handle(GEOMImpl_MeasureDriver) Handle(GEOMImpl_MeasureDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
144 {
145   Handle(GEOMImpl_MeasureDriver) _anOtherObject;
146
147   if (!AnObject.IsNull()) {
148      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_MeasureDriver))) {
149        _anOtherObject = Handle(GEOMImpl_MeasureDriver)((Handle(GEOMImpl_MeasureDriver)&)AnObject);
150      }
151   }
152
153   return _anOtherObject ;
154 }