Skip to content

Commit

Permalink
+ improve MeshSelection class
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Mar 31, 2016
1 parent 7dbcbc0 commit 0317111
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
33 changes: 21 additions & 12 deletions src/Mod/Mesh/Gui/MeshSelection.cpp
Expand Up @@ -76,19 +76,28 @@ unsigned char MeshSelection::cross_mask_bitmap[] = {
};

MeshSelection::MeshSelection()
: onlyPointToUserTriangles(false), onlyVisibleTriangles(false), _activeCB(0)
: onlyPointToUserTriangles(false)
, onlyVisibleTriangles(false)
, activeCB(0)
, selectionCB(0)
{
setCallback(selectGLCallback);
}

MeshSelection::~MeshSelection()
{
if (_activeCB) {
if (this->activeCB) {
Gui::View3DInventorViewer* viewer = this->getViewer();
if (viewer)
stopInteractiveCallback(viewer);
}
}

void MeshSelection::setCallback(SoEventCallbackCB *cb)
{
selectionCB = cb;
}

void MeshSelection::setObjects(const std::vector<Gui::SelectionObject>& obj)
{
meshObjects = obj;
Expand Down Expand Up @@ -145,29 +154,29 @@ Gui::View3DInventorViewer* MeshSelection::getViewer() const

void MeshSelection::startInteractiveCallback(Gui::View3DInventorViewer* viewer,SoEventCallbackCB *cb)
{
if (this->_activeCB)
if (this->activeCB)
return;
viewer->setEditing(true);
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), cb, this);
this->_activeCB = cb;
this->activeCB = cb;
}

void MeshSelection::stopInteractiveCallback(Gui::View3DInventorViewer* viewer)
{
if (!this->_activeCB)
if (!this->activeCB)
return;
if (viewer->isEditing()) {
viewer->setEditing(false);
viewer->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), this->_activeCB, this);
this->_activeCB = 0;
}
viewer->setEditing(false);
viewer->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), this->activeCB, this);
this->activeCB = 0;
}

void MeshSelection::prepareBrushSelection(bool add,SoEventCallbackCB *cb)
{
// a rubberband to select a rectangle area of the meshes
Gui::View3DInventorViewer* viewer = this->getViewer();
if (viewer) {
// Note: It is possible that the mouse selection mode can be stopped
// but then the callback function is still active.
stopInteractiveCallback(viewer);
startInteractiveCallback(viewer, cb);
viewer->navigationStyle()->stopSelection();
Expand All @@ -189,12 +198,12 @@ void MeshSelection::prepareBrushSelection(bool add,SoEventCallbackCB *cb)

void MeshSelection::startSelection()
{
prepareBrushSelection(true, selectGLCallback);
prepareBrushSelection(true, selectionCB);
}

void MeshSelection::startDeselection()
{
prepareBrushSelection(false, selectGLCallback);
prepareBrushSelection(false, selectionCB);
}

void MeshSelection::stopSelection()
Expand Down
4 changes: 3 additions & 1 deletion src/Mod/Mesh/Gui/MeshSelection.h
Expand Up @@ -69,6 +69,7 @@ class MeshGuiExport MeshSelection
std::vector<App::DocumentObject*> getObjects() const;

protected:
void setCallback(SoEventCallbackCB *cb);
std::list<ViewProviderMesh*> getViewProviders() const;
Gui::View3DInventorViewer* getViewer() const;
void prepareBrushSelection(bool,SoEventCallbackCB *cb);
Expand All @@ -83,7 +84,8 @@ class MeshGuiExport MeshSelection
private:
bool onlyPointToUserTriangles, onlyVisibleTriangles;
bool addToSelection, addComponent, removeComponent;
SoEventCallbackCB *_activeCB;
SoEventCallbackCB *activeCB;
SoEventCallbackCB *selectionCB;
mutable std::vector<Gui::SelectionObject> meshObjects;

static unsigned char cross_bitmap[];
Expand Down

0 comments on commit 0317111

Please sign in to comment.