App: add pure virtual methods to PropertyGeometry to delegate it to the geometry of sub-classes

Following the law of Demeter add some wrapper methods to PropertyGeometry and implement them in sub-classes. As a side-effect this makes some const_cast obsolete
This commit is contained in:
wmayer
2022-06-24 16:15:02 +02:00
parent f87d9bd626
commit 5234d9bc67
10 changed files with 49 additions and 8 deletions

View File

@@ -508,6 +508,10 @@ public:
/** @name Modification */
//@{
/// Set the placement of the geometry
virtual void setTransform(const Base::Matrix4D& rclTrf) = 0;
/// Get the placement of the geometry
virtual Base::Matrix4D getTransform() const = 0;
/// Applies a transformation on the real geometric data type
virtual void transformGeometry(const Base::Matrix4D &rclMat) = 0;
/// Retrieve bounding box information

View File

@@ -68,7 +68,7 @@ void FemMeshObject::onChanged(const Property* prop)
// if the placement has changed apply the change to the mesh data as well
if (prop == &this->Placement) {
const_cast<Fem::FemMesh&>(this->FemMesh.getValue()).setTransform(this->Placement.getValue().toMatrix());
this->FemMesh.setTransform(this->Placement.getValue().toMatrix());
}
}

View File

@@ -82,6 +82,16 @@ Base::BoundBox3d PropertyFemMesh::getBoundingBox() const
return _FemMesh->getBoundBox();
}
void PropertyFemMesh::setTransform(const Base::Matrix4D &rclTrf)
{
_FemMesh->setTransform(rclTrf);
}
Base::Matrix4D PropertyFemMesh::getTransform() const
{
return _FemMesh->getTransform();
}
void PropertyFemMesh::transformGeometry(const Base::Matrix4D &rclMat)
{
aboutToSetValue();

View File

@@ -60,6 +60,10 @@ public:
//@{
/** Returns the bounding box around the underlying mesh kernel */
Base::BoundBox3d getBoundingBox() const;
/// Set the placement of the geometry
void setTransform(const Base::Matrix4D& rclTrf);
/// Get the placement of the geometry
Base::Matrix4D getTransform() const;
void transformGeometry(const Base::Matrix4D &rclMat);
//@}

View File

@@ -541,14 +541,12 @@ void Feature::onChanged(const App::Property* prop)
{
// if the placement has changed apply the change to the point data as well
if (prop == &this->Placement) {
TopoShape& shape = const_cast<TopoShape&>(this->Shape.getShape());
shape.setTransform(this->Placement.getValue().toMatrix());
this->Shape.setTransform(this->Placement.getValue().toMatrix());
}
// if the point data has changed check and adjust the transformation as well
else if (prop == &this->Shape) {
if (this->isRecomputing()) {
TopoShape& shape = const_cast<TopoShape&>(this->Shape.getShape());
shape.setTransform(this->Placement.getValue().toMatrix());
this->Shape.setTransform(this->Placement.getValue().toMatrix());
}
else {
Base::Placement p;

View File

@@ -137,6 +137,16 @@ Base::BoundBox3d PropertyPartShape::getBoundingBox() const
return box;
}
void PropertyPartShape::setTransform(const Base::Matrix4D &rclTrf)
{
_Shape.setTransform(rclTrf);
}
Base::Matrix4D PropertyPartShape::getTransform() const
{
return _Shape.getTransform();
}
void PropertyPartShape::transformGeometry(const Base::Matrix4D &rclTrf)
{
aboutToSetValue();

View File

@@ -59,6 +59,10 @@ public:
/** @name Modification */
//@{
/// Set the placement of the geometry
void setTransform(const Base::Matrix4D& rclTrf);
/// Get the placement of the geometry
Base::Matrix4D getTransform() const;
/// Transform the real shape data
void transformGeometry(const Base::Matrix4D &rclMat);
//@}

View File

@@ -80,13 +80,12 @@ void Feature::onChanged(const App::Property* prop)
{
// if the placement has changed apply the change to the point data as well
if (prop == &this->Placement) {
PointKernel& pts = const_cast<PointKernel&>(this->Points.getValue());
pts.setTransform(this->Placement.getValue().toMatrix());
this->Points.setTransform(this->Placement.getValue().toMatrix());
}
// if the point data has changed check and adjust the transformation as well
else if (prop == &this->Points) {
Base::Placement p;
p.fromMatrix(this->Points.getValue().getTransform());
p.fromMatrix(this->Points.getTransform());
if (p != this->Placement.getValue())
this->Placement.setValue(p);
}

View File

@@ -68,6 +68,16 @@ const Data::ComplexGeoData* PropertyPointKernel::getComplexData() const
return _cPoints;
}
void PropertyPointKernel::setTransform(const Base::Matrix4D& rclTrf)
{
_cPoints->setTransform(rclTrf);
}
Base::Matrix4D PropertyPointKernel::getTransform() const
{
return _cPoints->getTransform();
}
Base::BoundBox3d PropertyPointKernel::getBoundingBox() const
{
return _cPoints->getBoundBox();

View File

@@ -46,6 +46,8 @@ public:
/// get the points (only const possible!)
const PointKernel &getValue() const;
const Data::ComplexGeoData* getComplexData() const;
void setTransform(const Base::Matrix4D& rclTrf);
Base::Matrix4D getTransform() const;
//@}
/** @name Getting basic geometric entities */