diff --git a/src/Mod/Mesh/App/Edge.h b/src/Mod/Mesh/App/Edge.h index 0dda23e542..46e317ca94 100644 --- a/src/Mod/Mesh/App/Edge.h +++ b/src/Mod/Mesh/App/Edge.h @@ -54,7 +54,7 @@ public: int Index; MeshCore::PointIndex PIndex[2]; MeshCore::FacetIndex NIndex[2]; - Base::Reference Mesh; + Base::Reference Mesh; }; } // namespace Mesh diff --git a/src/Mod/Mesh/App/Facet.cpp b/src/Mod/Mesh/App/Facet.cpp index 01119c1a63..d66f4ab45d 100644 --- a/src/Mod/Mesh/App/Facet.cpp +++ b/src/Mod/Mesh/App/Facet.cpp @@ -31,7 +31,7 @@ using namespace Mesh; -Facet::Facet(const MeshCore::MeshFacet& face, MeshObject* obj, MeshCore::FacetIndex index) +Facet::Facet(const MeshCore::MeshFacet& face, const MeshObject* obj, MeshCore::FacetIndex index) : Index(index), Mesh(obj) { for (int i=0; i<3; i++) { diff --git a/src/Mod/Mesh/App/Facet.h b/src/Mod/Mesh/App/Facet.h index 893670fe76..e21dcb1d01 100644 --- a/src/Mod/Mesh/App/Facet.h +++ b/src/Mod/Mesh/App/Facet.h @@ -43,7 +43,7 @@ class MeshObject; class MeshExport Facet : public MeshCore::MeshGeomFacet { public: - Facet(const MeshCore::MeshFacet& face = MeshCore::MeshFacet(), MeshObject* obj = nullptr, MeshCore::FacetIndex index = MeshCore::FACET_INDEX_MAX); + Facet(const MeshCore::MeshFacet& face = MeshCore::MeshFacet(), const MeshObject* obj = nullptr, MeshCore::FacetIndex index = MeshCore::FACET_INDEX_MAX); Facet(const Facet& f); ~Facet(); @@ -54,7 +54,7 @@ public: MeshCore::FacetIndex Index; MeshCore::PointIndex PIndex[3]; MeshCore::FacetIndex NIndex[3]; - Base::Reference Mesh; + Base::Reference Mesh; }; } // namespace Mesh diff --git a/src/Mod/Mesh/App/Mesh.cpp b/src/Mod/Mesh/App/Mesh.cpp index 24d6d70ca1..4436902f74 100644 --- a/src/Mod/Mesh/App/Mesh.cpp +++ b/src/Mod/Mesh/App/Mesh.cpp @@ -168,7 +168,7 @@ Base::Matrix4D MeshObject::getTransform() const Base::BoundBox3d MeshObject::getBoundBox()const { - const_cast(_kernel).RecalcBoundBox(); + _kernel.RecalcBoundBox(); Base::BoundBox3f Bnd = _kernel.GetBoundBox(); Base::BoundBox3d Bnd2; @@ -293,12 +293,17 @@ double MeshObject::getVolume() const return _kernel.GetVolume(); } -MeshPoint MeshObject::getPoint(PointIndex index) const +Base::Vector3d MeshObject::getPoint(PointIndex index) const { Base::Vector3f vertf = _kernel.GetPoint(index); Base::Vector3d vertd(vertf.x, vertf.y, vertf.z); vertd = _Mtrx * vertd; - MeshPoint point(vertd, const_cast(this), index); + return vertd; +} + +MeshPoint MeshObject::getMeshPoint(PointIndex index) const +{ + MeshPoint point(getPoint(index), this, index); return point; } @@ -311,10 +316,7 @@ void MeshObject::getPoints(std::vector &Points, unsigned long ctpoints = _kernel.CountPoints(); Points.reserve(ctpoints); for (unsigned long i=0; i &Points, } } -Mesh::Facet MeshObject::getFacet(FacetIndex index) const +Mesh::Facet MeshObject::getMeshFacet(FacetIndex index) const { - Mesh::Facet face(_kernel.GetFacets()[index], const_cast(this), index); + Mesh::Facet face(_kernel.GetFacets()[index], this, index); return face; } @@ -343,7 +345,7 @@ void MeshObject::getFaces(std::vector &Points,std::vector unsigned long ctpoints = _kernel.CountPoints(); Points.reserve(ctpoints); for (unsigned long i=0; igetPoint(i)); + Points.push_back(getPoint(i)); } unsigned long ctfacets = _kernel.CountFacets(); @@ -405,7 +407,7 @@ void MeshObject::save(const char* file, MeshCore::MeshIO::Format f, aWriter.SetGroups(groups); if (mat && mat->library.empty()) { Base::FileInfo fi(file); - const_cast(mat)->library = fi.fileNamePure() + ".mtl"; + mat->library = fi.fileNamePure() + ".mtl"; } aWriter.Transform(this->_Mtrx); @@ -800,7 +802,7 @@ std::vector MeshObject::getPointsFromFacets(const std::vector& facets) +void MeshObject::updateMesh(const std::vector& facets) const { std::vector points; points = _kernel.GetFacetPoints(facets); @@ -810,12 +812,12 @@ void MeshObject::updateMesh(const std::vector& facets) alg.SetPointsFlag(points, MeshCore::MeshPoint::SEGMENT); } -void MeshObject::updateMesh() +void MeshObject::updateMesh() const { MeshCore::MeshAlgorithm alg(_kernel); alg.ResetFacetFlag(MeshCore::MeshFacet::SEGMENT); alg.ResetPointFlag(MeshCore::MeshPoint::SEGMENT); - for (std::vector::iterator it = this->_segments.begin(); + for (std::vector::const_iterator it = this->_segments.begin(); it != this->_segments.end(); ++it) { std::vector points; points = _kernel.GetFacetPoints(it->getIndices()); @@ -1948,7 +1950,7 @@ std::vector MeshObject::getSegmentsOfType(MeshObject::GeometryType type const std::vector& data = surf->GetSegments(); for (std::vector::const_iterator it = data.begin(); it != data.end(); ++it) { - segm.emplace_back(const_cast(this), *it, false); + segm.emplace_back(this, *it, false); } } @@ -1962,7 +1964,7 @@ MeshObject::const_point_iterator::const_point_iterator(const MeshObject* mesh, P { this->_p_it.Set(index); this->_p_it.Transform(_mesh->_Mtrx); - this->_point.Mesh = const_cast(_mesh); + this->_point.Mesh = _mesh; } MeshObject::const_point_iterator::const_point_iterator(const MeshObject::const_point_iterator& fi) @@ -2031,7 +2033,7 @@ MeshObject::const_facet_iterator::const_facet_iterator(const MeshObject* mesh, F { this->_f_it.Set(index); this->_f_it.Transform(_mesh->_Mtrx); - this->_facet.Mesh = const_cast(_mesh); + this->_facet.Mesh = _mesh; } MeshObject::const_facet_iterator::const_facet_iterator(const MeshObject::const_facet_iterator& fi) diff --git a/src/Mod/Mesh/App/Mesh.h b/src/Mod/Mesh/App/Mesh.h index ea3f54ca1a..922fffbe98 100644 --- a/src/Mod/Mesh/App/Mesh.h +++ b/src/Mod/Mesh/App/Mesh.h @@ -42,7 +42,6 @@ #include "Core/Iterator.h" #include "MeshPoint.h" #include "Facet.h" -#include "MeshPoint.h" #include "Segment.h" namespace Py { @@ -138,8 +137,9 @@ public: unsigned long countEdges () const; unsigned long countSegments() const; bool isSolid() const; - MeshPoint getPoint(PointIndex) const; - Mesh::Facet getFacet(FacetIndex) const; + Base::Vector3d getPoint(PointIndex) const; + MeshPoint getMeshPoint(PointIndex) const; + Mesh::Facet getMeshFacet(FacetIndex) const; double getSurface() const; double getVolume() const; /** Get points from object with given accuracy */ @@ -408,8 +408,8 @@ public: private: void deletedFacets(const std::vector& remFacets); - void updateMesh(const std::vector&); - void updateMesh(); + void updateMesh(const std::vector&) const; + void updateMesh() const; void swapKernel(MeshCore::MeshKernel& m, const std::vector& g); void copySegments(const MeshObject&); void swapSegments(MeshObject&); diff --git a/src/Mod/Mesh/App/MeshFeature.cpp b/src/Mod/Mesh/App/MeshFeature.cpp index 2e9ded7909..b8a6470075 100644 --- a/src/Mod/Mesh/App/MeshFeature.cpp +++ b/src/Mod/Mesh/App/MeshFeature.cpp @@ -75,13 +75,12 @@ void Feature::onChanged(const App::Property* prop) { // if the placement has changed apply the change to the mesh data as well if (prop == &this->Placement) { - MeshObject& mesh = const_cast(this->Mesh.getValue()); - mesh.setTransform(this->Placement.getValue().toMatrix()); + this->Mesh.setTransform(this->Placement.getValue().toMatrix()); } // if the mesh data has changed check and adjust the transformation as well else if (prop == &this->Mesh) { Base::Placement p; - p.fromMatrix(this->Mesh.getValue().getTransform()); + p.fromMatrix(this->Mesh.getTransform()); if (p != this->Placement.getValue()) this->Placement.setValue(p); } diff --git a/src/Mod/Mesh/App/MeshPoint.h b/src/Mod/Mesh/App/MeshPoint.h index f45cb3a017..e576f5cbc6 100644 --- a/src/Mod/Mesh/App/MeshPoint.h +++ b/src/Mod/Mesh/App/MeshPoint.h @@ -49,14 +49,14 @@ class MeshExport MeshPoint : public Vector3d public: /// simple constructor - MeshPoint(const Vector3d& vec = Vector3d(),MeshObject* obj = nullptr, unsigned int index = UINT_MAX) + MeshPoint(const Vector3d& vec = Vector3d(), const MeshObject* obj = nullptr, unsigned int index = UINT_MAX) :Vector3d(vec),Index(index),Mesh(obj) {} bool isBound() const {return Index != UINT_MAX;} unsigned int Index; - Base::Reference Mesh; + Base::Reference Mesh; }; } // namespace Mesh diff --git a/src/Mod/Mesh/App/MeshPointPy.xml b/src/Mod/Mesh/App/MeshPointPy.xml index 5cfda8daf0..cf08041243 100644 --- a/src/Mod/Mesh/App/MeshPointPy.xml +++ b/src/Mod/Mesh/App/MeshPointPy.xml @@ -32,16 +32,6 @@ work! - - - method move(Vector) -This method moves the point in the mesh along the -given vector. This affects the geometry of the mesh. -Be aware that after moving point(s) the mesh can -have self intersections! - - - The index of this point in the MeshObject @@ -66,26 +56,23 @@ have self intersections! - + - The X component of the point. -Setting this value also affects the mesh if this point is connected to it. + The X component of the point. - + - The Y component of the point. -Setting this value also affects the mesh if this point is connected to it. + The Y component of the point. - + - The Z component of the point. -Setting this value also affects the mesh if this point is connected to it. + The Z component of the point. - + diff --git a/src/Mod/Mesh/App/MeshPointPyImp.cpp b/src/Mod/Mesh/App/MeshPointPyImp.cpp index 4fad3ce1cc..8df6de5ad0 100644 --- a/src/Mod/Mesh/App/MeshPointPyImp.cpp +++ b/src/Mod/Mesh/App/MeshPointPyImp.cpp @@ -86,42 +86,6 @@ PyObject* MeshPointPy::unbound(PyObject *args) Py_Return; } -PyObject* MeshPointPy::move(PyObject *args) -{ - if (!getMeshPointPtr()->isBound()) { - PyErr_SetString(PyExc_RuntimeError, "This object is not bounded to a mesh, so no topological operation is possible!"); - return nullptr; - } - if (getMeshPointPtr()->Mesh->countPoints() <= getMeshPointPtr()->Index) { - PyErr_SetString(PyExc_IndexError, "Index out of range"); - return nullptr; - } - - double x=0.0,y=0.0,z=0.0; - PyObject *object; - Base::Vector3d vec; - - do { - if (PyArg_ParseTuple(args, "ddd", &x,&y,&z)) { - vec.Set(x,y,z); - break; - } - - PyErr_Clear(); // set by PyArg_ParseTuple() - if (PyArg_ParseTuple(args,"O!",&(Base::VectorPy::Type), &object)) { - vec = *(static_cast(object)->getVectorPtr()); - break; - } - - PyErr_SetString(PyExc_TypeError, "Tuple of three floats or Vector expected"); - return nullptr; - } - while (false); - - getMeshPointPtr()->Mesh->movePoint(getMeshPointPtr()->Index,vec); - Py_Return; -} - Py::Long MeshPointPy::getIndex() const { return Py::Long((long) getMeshPointPtr()->Index); @@ -167,17 +131,6 @@ Py::Float MeshPointPy::getx() const return Py::Float(x); } -void MeshPointPy::setx(Py::Float arg) -{ - MeshPointPy::PointerType ptr = static_cast(_pcTwinPointer); - ptr->x = (double)arg; - - if (getMeshPointPtr()->isBound()) { - if (getMeshPointPtr()->Mesh->countPoints() > getMeshPointPtr()->Index) - getMeshPointPtr()->Mesh->setPoint(getMeshPointPtr()->Index,*ptr); - } -} - Py::Float MeshPointPy::gety() const { MeshPointPy::PointerType ptr = static_cast(_pcTwinPointer); @@ -191,17 +144,6 @@ Py::Float MeshPointPy::gety() const return Py::Float(y); } -void MeshPointPy::sety(Py::Float arg) -{ - MeshPointPy::PointerType ptr = static_cast(_pcTwinPointer); - ptr->y = (double)arg; - - if (getMeshPointPtr()->isBound()) { - if (getMeshPointPtr()->Mesh->countPoints() > getMeshPointPtr()->Index) - getMeshPointPtr()->Mesh->setPoint(getMeshPointPtr()->Index,*ptr); - } -} - Py::Float MeshPointPy::getz() const { MeshPointPy::PointerType ptr = static_cast(_pcTwinPointer); @@ -215,17 +157,6 @@ Py::Float MeshPointPy::getz() const return Py::Float(z); } -void MeshPointPy::setz(Py::Float arg) -{ - MeshPointPy::PointerType ptr = static_cast(_pcTwinPointer); - ptr->z = (double)arg; - - if (getMeshPointPtr()->isBound()) { - if (getMeshPointPtr()->Mesh->countPoints() > getMeshPointPtr()->Index) - getMeshPointPtr()->Mesh->setPoint(getMeshPointPtr()->Index,*ptr); - } -} - PyObject *MeshPointPy::getCustomAttributes(const char* /*attr*/) const { return nullptr; diff --git a/src/Mod/Mesh/App/MeshProperties.cpp b/src/Mod/Mesh/App/MeshProperties.cpp index 13dbb94511..8d307f0384 100644 --- a/src/Mod/Mesh/App/MeshProperties.cpp +++ b/src/Mod/Mesh/App/MeshProperties.cpp @@ -538,6 +538,16 @@ void PropertyMeshKernel::setPointIndices(const std::vectorsetTransform(rclTrf); +} + +Base::Matrix4D PropertyMeshKernel::getTransform() const +{ + return _meshObject->getTransform(); +} + PyObject *PropertyMeshKernel::getPyObject() { if (!meshPyObject) { diff --git a/src/Mod/Mesh/App/MeshProperties.h b/src/Mod/Mesh/App/MeshProperties.h index babd593ec4..ea007cf8ca 100644 --- a/src/Mod/Mesh/App/MeshProperties.h +++ b/src/Mod/Mesh/App/MeshProperties.h @@ -216,6 +216,8 @@ public: /// Transform the real mesh data void transformGeometry(const Base::Matrix4D &rclMat); void setPointIndices( const std::vector >& ); + void setTransform(const Base::Matrix4D& rclTrf); + Base::Matrix4D getTransform() const; //@} /** @name Python interface */ diff --git a/src/Mod/Mesh/App/MeshPy.xml b/src/Mod/Mesh/App/MeshPy.xml index 0ea21cddbf..10c9e9c027 100644 --- a/src/Mod/Mesh/App/MeshPy.xml +++ b/src/Mod/Mesh/App/MeshPy.xml @@ -176,7 +176,17 @@ lines = mesh.section(mesh2, [ConnectLines=True, MinDist=0.0001]) - + + + movePoint(int, Vector) + This method moves the point in the mesh along the + given vector. This affects the geometry of the mesh. + Be aware that after moving point(s) the mesh can + have self intersections! + + + + getPointNormals() @@ -507,7 +517,7 @@ smooth([iteration=1,maxError=FLT_MAX]) - + nearestFacetOnRay(tuple, tuple) -> dict Get the index and intersection point of the nearest facet to a ray. diff --git a/src/Mod/Mesh/App/MeshPyImp.cpp b/src/Mod/Mesh/App/MeshPyImp.cpp index d51221aae9..b01366371c 100644 --- a/src/Mod/Mesh/App/MeshPyImp.cpp +++ b/src/Mod/Mesh/App/MeshPyImp.cpp @@ -828,6 +828,34 @@ PyObject* MeshPy::setPoint(PyObject *args) Py_Return; } +PyObject* MeshPy::movePoint(PyObject *args) +{ + unsigned long index; + Base::Vector3d vec; + + do { + double x=0.0,y=0.0,z=0.0; + if (PyArg_ParseTuple(args, "kddd", &index,&x,&y,&z)) { + vec.Set(x,y,z); + break; + } + + PyErr_Clear(); // set by PyArg_ParseTuple() + PyObject *object; + if (PyArg_ParseTuple(args,"kO!", &index, &(Base::VectorPy::Type), &object)) { + vec = *(static_cast(object)->getVectorPtr()); + break; + } + + PyErr_SetString(PyExc_TypeError, "Tuple of three floats or Vector expected"); + return nullptr; + } + while (false); + + getMeshObjectPtr()->movePoint(index, vec); + Py_Return; +} + PyObject* MeshPy::getPointNormals(PyObject *args) { if (!PyArg_ParseTuple(args, "")) diff --git a/src/Mod/Mesh/App/Segment.cpp b/src/Mod/Mesh/App/Segment.cpp index cf7eb5c414..04e1a80246 100644 --- a/src/Mod/Mesh/App/Segment.cpp +++ b/src/Mod/Mesh/App/Segment.cpp @@ -36,14 +36,14 @@ using namespace Mesh; -Segment::Segment(MeshObject* mesh, bool mod) +Segment::Segment(const MeshObject* mesh, bool mod) : _mesh(mesh) , _save(false) , _modifykernel(mod) { } -Segment::Segment(MeshObject* mesh, const std::vector& inds, bool mod) +Segment::Segment(const MeshObject* mesh, const std::vector& inds, bool mod) : _mesh(mesh) , _indices(inds) , _save(false) @@ -135,7 +135,7 @@ Segment::const_facet_iterator& Segment::const_facet_iterator::operator=(const Se return *this; } -void Segment::const_facet_iterator::dereference() +void Segment::const_facet_iterator::dereference() const { this->_f_it.Set(*_it); this->_facet.MeshCore::MeshGeomFacet::operator = (*_f_it); @@ -149,13 +149,13 @@ void Segment::const_facet_iterator::dereference() const Facet& Segment::const_facet_iterator::operator*() const { - const_cast(this)->dereference(); + this->dereference(); return this->_facet; } const Facet* Segment::const_facet_iterator::operator->() const { - const_cast(this)->dereference(); + this->dereference(); return &(this->_facet); } diff --git a/src/Mod/Mesh/App/Segment.h b/src/Mod/Mesh/App/Segment.h index aea805c1b9..992b3beb90 100644 --- a/src/Mod/Mesh/App/Segment.h +++ b/src/Mod/Mesh/App/Segment.h @@ -38,8 +38,8 @@ class MeshObject; class MeshExport Segment { public: - Segment(MeshObject*, bool mod); - Segment(MeshObject*, const std::vector& inds, bool mod); + Segment(const MeshObject*, bool mod); + Segment(const MeshObject*, const std::vector& inds, bool mod); void addIndices(const std::vector& inds); void removeIndices(const std::vector& inds); const std::vector& getIndices() const; @@ -62,7 +62,7 @@ public: friend class MeshObject; private: - MeshObject* _mesh; + const MeshObject* _mesh; std::vector _indices; std::string _name; std::string _color; @@ -85,10 +85,10 @@ public: const_facet_iterator& operator++(); const_facet_iterator& operator--(); private: - void dereference(); + void dereference() const; const Segment* _segment; - Facet _facet; - MeshCore::MeshFacetIterator _f_it; + mutable Facet _facet; + mutable MeshCore::MeshFacetIterator _f_it; std::vector::const_iterator _it; }; diff --git a/src/Mod/Mesh/Gui/ViewProvider.cpp b/src/Mod/Mesh/Gui/ViewProvider.cpp index dde3cc8680..810566d710 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.cpp +++ b/src/Mod/Mesh/Gui/ViewProvider.cpp @@ -1252,8 +1252,8 @@ std::vector ViewProviderMesh::getFacetsOfRegion(const SbViewpo SoSeparator* root = new SoSeparator(); root->ref(); root->addChild(camera); - root->addChild(const_cast(this)->getCoordNode()); - root->addChild(const_cast(this)->getShapeNode()); + root->addChild(this->getCoordNode()); + root->addChild(this->getShapeNode()); Gui::SoGLSelectAction gl(region, select); gl.apply(root); root->unref();