From 8f9a9b71a20aeac0a4f395b194acc47a52e33a6e Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 4 Sep 2013 12:18:20 +0200 Subject: [PATCH] Enhance API of mesh selection --- src/Mod/Mesh/App/Core/Algorithm.cpp | 20 ++++++++++++++++++++ src/Mod/Mesh/App/Core/Algorithm.h | 4 ++++ src/Mod/Mesh/Gui/MeshSelection.cpp | 25 +++++++++++++++++++++---- src/Mod/Mesh/Gui/MeshSelection.h | 9 +++++++-- src/Mod/Mesh/Gui/ViewProvider.cpp | 6 +----- 5 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/Mod/Mesh/App/Core/Algorithm.cpp b/src/Mod/Mesh/App/Core/Algorithm.cpp index 31ac95a14..6424d448e 100644 --- a/src/Mod/Mesh/App/Core/Algorithm.cpp +++ b/src/Mod/Mesh/App/Core/Algorithm.cpp @@ -1794,6 +1794,16 @@ MeshRefPointToFacets::operator[] (unsigned long pos) const return _map[pos]; } +void MeshRefPointToFacets::AddNeighbour(unsigned long pos, unsigned long facet) +{ + _map[pos].insert(facet); +} + +void MeshRefPointToFacets::RemoveNeighbour(unsigned long pos, unsigned long facet) +{ + _map[pos].erase(facet); +} + //---------------------------------------------------------------------------- void MeshRefFacetToFacets::Rebuild (void) @@ -1881,6 +1891,16 @@ MeshRefPointToPoints::operator[] (unsigned long pos) const return _map[pos]; } +void MeshRefPointToPoints::AddNeighbour(unsigned long pos, unsigned long facet) +{ + _map[pos].insert(facet); +} + +void MeshRefPointToPoints::RemoveNeighbour(unsigned long pos, unsigned long facet) +{ + _map[pos].erase(facet); +} + //---------------------------------------------------------------------------- void MeshRefEdgeToFacets::Rebuild (void) diff --git a/src/Mod/Mesh/App/Core/Algorithm.h b/src/Mod/Mesh/App/Core/Algorithm.h index 7d55d6e94..b4c3057dc 100644 --- a/src/Mod/Mesh/App/Core/Algorithm.h +++ b/src/Mod/Mesh/App/Core/Algorithm.h @@ -374,6 +374,8 @@ public: std::set NeighbourPoints(const std::vector& , int level) const; void Neighbours (unsigned long ulFacetInd, float fMaxDist, MeshCollector& collect) const; Base::Vector3f GetNormal(unsigned long) const; + void AddNeighbour(unsigned long, unsigned long); + void RemoveNeighbour(unsigned long, unsigned long); protected: void SearchNeighbours(const MeshFacetArray& rFacets, unsigned long index, const Base::Vector3f &rclCenter, @@ -432,6 +434,8 @@ public: const std::set& operator[] (unsigned long) const; Base::Vector3f GetNormal(unsigned long) const; float GetAverageEdgeLength(unsigned long) const; + void AddNeighbour(unsigned long, unsigned long); + void RemoveNeighbour(unsigned long, unsigned long); protected: const MeshKernel &_rclMesh; /**< The mesh kernel. */ diff --git a/src/Mod/Mesh/Gui/MeshSelection.cpp b/src/Mod/Mesh/Gui/MeshSelection.cpp index f04272801..0df1e8490 100644 --- a/src/Mod/Mesh/Gui/MeshSelection.cpp +++ b/src/Mod/Mesh/Gui/MeshSelection.cpp @@ -162,13 +162,13 @@ void MeshSelection::stopInteractiveCallback(Gui::View3DInventorViewer* viewer) } } -void MeshSelection::prepareBrushSelection(bool add) +void MeshSelection::prepareBrushSelection(bool add,SoEventCallbackCB *cb) { // a rubberband to select a rectangle area of the meshes Gui::View3DInventorViewer* viewer = this->getViewer(); if (viewer) { stopInteractiveCallback(viewer); - startInteractiveCallback(viewer, selectGLCallback); + startInteractiveCallback(viewer, cb); // set cross cursor Gui::BrushSelection* brush = new Gui::BrushSelection(); brush->setColor(1.0f,0.0f,0.0f); @@ -186,12 +186,19 @@ void MeshSelection::prepareBrushSelection(bool add) void MeshSelection::startSelection() { - prepareBrushSelection(true); + prepareBrushSelection(true, selectGLCallback); } void MeshSelection::startDeselection() { - prepareBrushSelection(false); + prepareBrushSelection(false, selectGLCallback); +} + +void MeshSelection::stopSelection() +{ + Gui::View3DInventorViewer* viewer = getViewer(); + if (viewer) + stopInteractiveCallback(viewer); } void MeshSelection::fullSelection() @@ -332,11 +339,21 @@ void MeshSelection::setCheckOnlyPointToUserTriangles(bool on) onlyPointToUserTriangles = on; } +bool MeshSelection::isCheckedOnlyPointToUserTriangles() const +{ + return onlyPointToUserTriangles; +} + void MeshSelection::setCheckOnlyVisibleTriangles(bool on) { onlyVisibleTriangles = on; } +bool MeshSelection::isCheckedOnlyVisibleTriangles() const +{ + return onlyVisibleTriangles; +} + void MeshSelection::setAddComponentOnClick(bool on) { addComponent = on; diff --git a/src/Mod/Mesh/Gui/MeshSelection.h b/src/Mod/Mesh/Gui/MeshSelection.h index e2857ba02..ea31a3991 100644 --- a/src/Mod/Mesh/Gui/MeshSelection.h +++ b/src/Mod/Mesh/Gui/MeshSelection.h @@ -47,6 +47,7 @@ public: void startSelection(); void startDeselection(); + void stopSelection(); bool deleteSelection(); void fullSelection(); void clearSelection(); @@ -58,18 +59,22 @@ public: void deselectTriangle(); void setCheckOnlyPointToUserTriangles(bool); + bool isCheckedOnlyPointToUserTriangles() const; void setCheckOnlyVisibleTriangles(bool); + bool isCheckedOnlyVisibleTriangles() const; void setAddComponentOnClick(bool); void setRemoveComponentOnClick(bool); void setObjects(const std::vector&); std::vector getObjects() const; -private: +protected: std::list getViewProviders() const; Gui::View3DInventorViewer* getViewer() const; + void prepareBrushSelection(bool,SoEventCallbackCB *cb); void startInteractiveCallback(Gui::View3DInventorViewer* viewer,SoEventCallbackCB *cb); void stopInteractiveCallback(Gui::View3DInventorViewer* viewer); - void prepareBrushSelection(bool); + +private: static void selectGLCallback(void * ud, SoEventCallback * n); static void pickFaceCallback(void * ud, SoEventCallback * n); diff --git a/src/Mod/Mesh/Gui/ViewProvider.cpp b/src/Mod/Mesh/Gui/ViewProvider.cpp index 21c5da129..26aef2782 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.cpp +++ b/src/Mod/Mesh/Gui/ViewProvider.cpp @@ -1596,11 +1596,7 @@ void ViewProviderMesh::deleteSelection() if (!indices.empty()) { rMesh.clearFacetSelection(); unhighlightSelection(); - - Mesh::MeshObject* pMesh = meshProp.startEditing(); - pMesh->deleteFacets(indices); - meshProp.finishEditing(); - pcObject->purgeTouched(); + removeFacets(indices); } }