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"
9 #include <BRep_Tool.hxx>
10 #include <BRepGProp.hxx>
11 #include <BRepBuilderAPI_MakeVertex.hxx>
15 #include <TopoDS_Shape.hxx>
17 #include <GProp_GProps.hxx>
20 #include <Precision.hxx>
21 #include <Standard_NullObject.hxx>
23 //=======================================================================
26 //=======================================================================
27 const Standard_GUID& GEOMImpl_MeasureDriver::GetID()
29 static Standard_GUID aMeasureDriver("FF1BBB65-5D14-4df2-980B-3A668264EA16");
30 return aMeasureDriver;
34 //=======================================================================
35 //function : GEOMImpl_MeasureDriver
37 //=======================================================================
38 GEOMImpl_MeasureDriver::GEOMImpl_MeasureDriver()
42 //=======================================================================
45 //=======================================================================
46 Standard_Integer GEOMImpl_MeasureDriver::Execute(TFunction_Logbook& log) const
48 if (Label().IsNull()) return 0;
49 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
51 GEOMImpl_IMeasure aCI (aFunction);
52 Standard_Integer aType = aFunction->GetType();
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");
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();
75 BRepGProp::VolumeProperties(aShapeBase, aSystem);
76 aCenterMass = aSystem.CentreOfMass();
79 aShape = BRepBuilderAPI_MakeVertex(aCenterMass).Shape();
84 if (aShape.IsNull()) return 0;
86 aFunction->SetValue(aShape);
88 log.SetTouched(Label());
94 //=======================================================================
95 //function : GEOMImpl_MeasureDriver_Type_
97 //=======================================================================
98 Standard_EXPORT Handle_Standard_Type& GEOMImpl_MeasureDriver_Type_()
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);
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),
113 (Standard_Address)_Ancestors,
114 (Standard_Address)NULL);
119 //=======================================================================
120 //function : DownCast
122 //=======================================================================
123 const Handle(GEOMImpl_MeasureDriver) Handle(GEOMImpl_MeasureDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
125 Handle(GEOMImpl_MeasureDriver) _anOtherObject;
127 if (!AnObject.IsNull()) {
128 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_MeasureDriver))) {
129 _anOtherObject = Handle(GEOMImpl_MeasureDriver)((Handle(GEOMImpl_MeasureDriver)&)AnObject);
133 return _anOtherObject ;