2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_MeasureDriver.hxx>
5 #include <GEOMImpl_IMeasure.hxx>
6 #include <GEOMImpl_IMeasureOperations.hxx>
7 #include <GEOMImpl_Types.hxx>
8 #include <GEOM_Function.hxx>
10 #include <BRep_Tool.hxx>
11 #include <BRepGProp.hxx>
12 #include <BRepBuilderAPI_MakeVertex.hxx>
16 #include <TopoDS_Shape.hxx>
18 #include <GProp_GProps.hxx>
21 #include <Precision.hxx>
22 #include <Standard_NullObject.hxx>
24 //=======================================================================
27 //=======================================================================
28 const Standard_GUID& GEOMImpl_MeasureDriver::GetID()
30 static Standard_GUID aMeasureDriver("FF1BBB65-5D14-4df2-980B-3A668264EA16");
31 return aMeasureDriver;
35 //=======================================================================
36 //function : GEOMImpl_MeasureDriver
38 //=======================================================================
39 GEOMImpl_MeasureDriver::GEOMImpl_MeasureDriver()
43 //=======================================================================
46 //=======================================================================
47 Standard_Integer GEOMImpl_MeasureDriver::Execute(TFunction_Logbook& log) const
49 if (Label().IsNull()) return 0;
50 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
52 GEOMImpl_IMeasure aCI (aFunction);
53 Standard_Integer aType = aFunction->GetType();
57 if (aType == CDG_MEASURE) {
58 Handle(GEOM_Function) aRefBase = aCI.GetBase();
59 TopoDS_Shape aShapeBase = aRefBase->GetValue();
60 if (aShapeBase.IsNull()) {
61 Standard_NullObject::Raise("Shape for centre of mass calculation is null");
67 if (aShapeBase.ShapeType() == TopAbs_VERTEX) {
68 aCenterMass = BRep_Tool::Pnt(TopoDS::Vertex(aShapeBase));
69 } else if (aShapeBase.ShapeType() == TopAbs_EDGE || aShapeBase.ShapeType() == TopAbs_WIRE) {
70 BRepGProp::LinearProperties(aShapeBase, aSystem);
71 aCenterMass = aSystem.CentreOfMass();
72 } else if (aShapeBase.ShapeType() == TopAbs_FACE || aShapeBase.ShapeType() == TopAbs_SHELL) {
73 BRepGProp::SurfaceProperties(aShapeBase, aSystem);
74 aCenterMass = aSystem.CentreOfMass();
76 BRepGProp::VolumeProperties(aShapeBase, aSystem);
77 aCenterMass = aSystem.CentreOfMass();
80 aShape = BRepBuilderAPI_MakeVertex(aCenterMass).Shape();
85 if (aShape.IsNull()) return 0;
87 aFunction->SetValue(aShape);
89 log.SetTouched(Label());
95 //=======================================================================
96 //function : GEOMImpl_MeasureDriver_Type_
98 //=======================================================================
99 Standard_EXPORT Handle_Standard_Type& GEOMImpl_MeasureDriver_Type_()
102 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
103 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
104 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
105 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
106 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
107 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
110 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
111 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_MeasureDriver",
112 sizeof(GEOMImpl_MeasureDriver),
114 (Standard_Address)_Ancestors,
115 (Standard_Address)NULL);
120 //=======================================================================
121 //function : DownCast
123 //=======================================================================
124 const Handle(GEOMImpl_MeasureDriver) Handle(GEOMImpl_MeasureDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
126 Handle(GEOMImpl_MeasureDriver) _anOtherObject;
128 if (!AnObject.IsNull()) {
129 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_MeasureDriver))) {
130 _anOtherObject = Handle(GEOMImpl_MeasureDriver)((Handle(GEOMImpl_MeasureDriver)&)AnObject);
134 return _anOtherObject ;