Skip to content

Commit

Permalink
extend interface to get actual property with geometric data, get cent…
Browse files Browse the repository at this point in the history
…er of gravity of a geometry
  • Loading branch information
wwmayer committed Mar 5, 2017
1 parent 45bf8ed commit 35e8ede
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/App/ComplexGeoData.cpp
Expand Up @@ -148,3 +148,8 @@ void ComplexGeoData::getFaces(std::vector<Base::Vector3d> &Points,
(void)Accuracy;
(void)flags;
}

bool ComplexGeoData::getCenterOfGravity(Base::Vector3d&) const
{
return false;
}
5 changes: 5 additions & 0 deletions src/App/ComplexGeoData.h
Expand Up @@ -145,6 +145,11 @@ class AppExport ComplexGeoData: public Base::Persistence, public Base::Handled
/** Get faces from object with given accuracy */
virtual void getFaces(std::vector<Base::Vector3d> &Points,std::vector<Facet> &faces,
float Accuracy, uint16_t flags=0) const;
/** Get the center of gravity
* If this method is implemented then true is returned and the center of gravity.
* The default implementation only returns false.
*/
virtual bool getCenterOfGravity(Base::Vector3d& center) const;
//@}

protected:
Expand Down
5 changes: 5 additions & 0 deletions src/App/GeoFeature.cpp
Expand Up @@ -53,3 +53,8 @@ void GeoFeature::transformPlacement(const Base::Placement &transform)
plm = transform * plm;
this->Placement.setValue(plm);
}

const PropertyComplexGeoData* GeoFeature::getPropertyOfGeometry() const
{
return nullptr;
}
7 changes: 7 additions & 0 deletions src/App/GeoFeature.h
Expand Up @@ -54,6 +54,13 @@ class AppExport GeoFeature : public App::DocumentObject
* @param transform (input).
*/
virtual void transformPlacement(const Base::Placement &transform);
/**
* This method returns the main property of a geometric object that holds
* the actual geometry. For a part object this is the Shape property, for
* a mesh object the Mesh property and so on.
* The default implementation returns null.
*/
virtual const PropertyComplexGeoData* getPropertyOfGeometry() const;
};

} //namespace App
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Mesh/App/MeshFeature.h
Expand Up @@ -77,6 +77,9 @@ class MeshExport Feature : public App::GeoFeature
virtual const char* getViewProviderName(void) const {
return "MeshGui::ViewProviderMeshFaceSet";
}
virtual const App::PropertyComplexGeoData* getPropertyOfGeometry() const {
return &Mesh;
}

/// handles the MeshPy object
virtual PyObject* getPyObject(void);
Expand Down
5 changes: 5 additions & 0 deletions src/Mod/Part/App/PartFeature.cpp
Expand Up @@ -238,6 +238,11 @@ const char* Feature::getViewProviderName(void) const {
return "PartGui::ViewProviderPart";
}

const App::PropertyComplexGeoData* Feature::getPropertyOfGeometry() const
{
return &Shape;
}

// ---------------------------------------------------------

PROPERTY_SOURCE(Part::FilletBase, Part::Feature)
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Part/App/PartFeature.h
Expand Up @@ -60,6 +60,7 @@ class PartExport Feature : public App::GeoFeature

/// returns the type name of the ViewProvider
virtual const char* getViewProviderName(void) const;
virtual const App::PropertyComplexGeoData* getPropertyOfGeometry() const;

virtual PyObject* getPyObject(void);
virtual std::vector<PyObject *> getPySubObjects(const std::vector<std::string>&) const;
Expand Down
32 changes: 32 additions & 0 deletions src/Mod/Part/App/TopoShape.cpp
Expand Up @@ -63,6 +63,7 @@
# include <BRepCheck_Result.hxx>
# include <BRepClass_FaceClassifier.hxx>
# include <BRepFilletAPI_MakeFillet.hxx>
# include <BRepGProp.hxx>
# include <BRepMesh_IncrementalMesh.hxx>
# include <BRepMesh_Triangle.hxx>
# include <BRepMesh_Edge.hxx>
Expand Down Expand Up @@ -94,6 +95,7 @@
# include <GeomFill_SectionLaw.hxx>
# include <GeomFill_Sweep.hxx>
# include <GeomLib.hxx>
# include <GProp_GProps.hxx>
# include <Law_BSpFunc.hxx>
# include <Law_BSpline.hxx>
# include <Law_BSpFunc.hxx>
Expand Down Expand Up @@ -928,6 +930,36 @@ Base::BoundBox3d TopoShape::getBoundBox(void) const
return box;
}

bool TopoShape::getCenterOfGravity(Base::Vector3d& center) const
{
if (_Shape.IsNull())
return false;

// Computing of CentreOfMass
gp_Pnt pnt;

if (_Shape.ShapeType() == TopAbs_VERTEX) {
pnt = BRep_Tool::Pnt(TopoDS::Vertex(_Shape));
}
else {
GProp_GProps prop;
if (_Shape.ShapeType() == TopAbs_EDGE || _Shape.ShapeType() == TopAbs_WIRE) {
BRepGProp::LinearProperties(_Shape, prop);
}
else if (_Shape.ShapeType() == TopAbs_FACE || _Shape.ShapeType() == TopAbs_SHELL) {
BRepGProp::SurfaceProperties(_Shape, prop);
}
else {
BRepGProp::VolumeProperties(_Shape, prop);
}

pnt = prop.CentreOfMass();
}

center.Set(pnt.X(), pnt.Y(), pnt.Z());
return true;
}

void TopoShape::Save (Base::Writer & ) const
{
}
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Part/App/TopoShape.h
Expand Up @@ -81,6 +81,7 @@ class PartExport TopoShape : public Data::ComplexGeoData
Base::Matrix4D getTransform(void) const;
/// Bound box from the CasCade shape
Base::BoundBox3d getBoundBox(void)const;
virtual bool getCenterOfGravity(Base::Vector3d& center) const;
static void convertTogpTrsf(const Base::Matrix4D& mtrx, gp_Trsf& trsf);
static void convertToMatrix(const gp_Trsf& trsf, Base::Matrix4D& mtrx);
//@}
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/Points/App/PointsFeature.h
Expand Up @@ -69,6 +69,10 @@ class PointsExport Feature : public App::GeoFeature
virtual const char* getViewProviderName(void) const {
return "PointsGui::ViewProviderScattered";
}

virtual const App::PropertyComplexGeoData* getPropertyOfGeometry() const {
return &Points;
}
protected:
void onChanged(const App::Property* prop);
//@}
Expand Down

0 comments on commit 35e8ede

Please sign in to comment.