Salome HOME
Merge with OCC_development_01
[modules/geom.git] / src / GEOMImpl / GEOMImpl_MeasureDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_MeasureDriver.hxx"
4 #include "GEOMImpl_IMeasure.hxx"
5 #include "GEOMImpl_IMeasureOperations.hxx"
6 #include "GEOMImpl_Types.hxx"
7 #include "GEOM_Function.hxx"
8
9 #include <BRep_Tool.hxx>
10 #include <BRepGProp.hxx>
11 #include <BRepBuilderAPI_MakeVertex.hxx>
12
13 #include <TopAbs.hxx>
14 #include <TopoDS.hxx>
15 #include <TopoDS_Shape.hxx>
16
17 #include <GProp_GProps.hxx>
18
19 #include <gp_Pnt.hxx>
20 #include <Precision.hxx>
21 #include <Standard_NullObject.hxx>
22
23 //=======================================================================
24 //function : GetID
25 //purpose  :
26 //======================================================================= 
27 const Standard_GUID& GEOMImpl_MeasureDriver::GetID()
28 {
29   static Standard_GUID aMeasureDriver("FF1BBB65-5D14-4df2-980B-3A668264EA16");
30   return aMeasureDriver; 
31 }
32
33
34 //=======================================================================
35 //function : GEOMImpl_MeasureDriver
36 //purpose  : 
37 //=======================================================================
38 GEOMImpl_MeasureDriver::GEOMImpl_MeasureDriver() 
39 {
40 }
41
42 //=======================================================================
43 //function : Execute
44 //purpose  :
45 //======================================================================= 
46 Standard_Integer GEOMImpl_MeasureDriver::Execute(TFunction_Logbook& log) const
47 {
48   if (Label().IsNull()) return 0;    
49   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
50
51   GEOMImpl_IMeasure aCI (aFunction);
52   Standard_Integer aType = aFunction->GetType();
53
54   TopoDS_Shape aShape;
55
56   if (aType == CDG_MEASURE) {
57     Handle(GEOM_Function) aRefBase = aCI.GetBase();
58     TopoDS_Shape aShapeBase = aRefBase->GetValue();
59     if (aShapeBase.IsNull()) {
60       Standard_NullObject::Raise("Shape for centre of mass calculation is null");
61     }
62
63     GProp_GProps aSystem;
64     gp_Pnt aCenterMass;
65
66     if (aShapeBase.ShapeType() == TopAbs_VERTEX) {
67       aCenterMass = BRep_Tool::Pnt(TopoDS::Vertex(aShapeBase));
68     } else if (aShapeBase.ShapeType() == TopAbs_EDGE || aShapeBase.ShapeType() == TopAbs_WIRE) {
69       BRepGProp::LinearProperties(aShapeBase, aSystem);
70       aCenterMass = aSystem.CentreOfMass();
71     } else if (aShapeBase.ShapeType() == TopAbs_FACE || aShapeBase.ShapeType() == TopAbs_SHELL) {
72       BRepGProp::SurfaceProperties(aShapeBase, aSystem);
73       aCenterMass = aSystem.CentreOfMass();
74     } else {
75       BRepGProp::VolumeProperties(aShapeBase, aSystem);
76       aCenterMass = aSystem.CentreOfMass();
77     }
78
79     aShape = BRepBuilderAPI_MakeVertex(aCenterMass).Shape();
80
81   } else {
82   }
83
84   if (aShape.IsNull()) return 0;
85
86   aFunction->SetValue(aShape);
87
88   log.SetTouched(Label()); 
89
90   return 1;    
91 }
92
93
94 //=======================================================================
95 //function :  GEOMImpl_MeasureDriver_Type_
96 //purpose  :
97 //======================================================================= 
98 Standard_EXPORT Handle_Standard_Type& GEOMImpl_MeasureDriver_Type_()
99 {
100
101   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
102   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
103   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
104   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
105   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
106   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
107  
108
109   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
110   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_MeasureDriver",
111                                                          sizeof(GEOMImpl_MeasureDriver),
112                                                          1,
113                                                          (Standard_Address)_Ancestors,
114                                                          (Standard_Address)NULL);
115
116   return _aType;
117 }
118
119 //=======================================================================
120 //function : DownCast
121 //purpose  :
122 //======================================================================= 
123 const Handle(GEOMImpl_MeasureDriver) Handle(GEOMImpl_MeasureDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
124 {
125   Handle(GEOMImpl_MeasureDriver) _anOtherObject;
126
127   if (!AnObject.IsNull()) {
128      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_MeasureDriver))) {
129        _anOtherObject = Handle(GEOMImpl_MeasureDriver)((Handle(GEOMImpl_MeasureDriver)&)AnObject);
130      }
131   }
132
133   return _anOtherObject ;
134 }