Skip to content

Commit

Permalink
Gui: added bbox selection style to GeometryObject
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder authored and wwmayer committed Mar 21, 2017
1 parent 69af452 commit a210cc5
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 24 deletions.
40 changes: 28 additions & 12 deletions src/Gui/SoFCUnifiedSelection.cpp
Expand Up @@ -79,6 +79,7 @@
#include "SoFCInteractiveElement.h"
#include "SoFCSelectionAction.h"
#include "ViewProviderDocumentObject.h"
#include "ViewProviderGeometryObject.h"

using namespace Gui;

Expand Down Expand Up @@ -281,10 +282,12 @@ void SoFCUnifiedSelection::doAction(SoAction *action)
type = SoSelectionElementAction::None;
}

SoSelectionElementAction action(type);
action.setColor(this->colorSelection.getValue());
action.setElement(detail);
action.apply(vp->getRoot());
if(checkSelectionStyle(type,vp)) {
SoSelectionElementAction action(type);
action.setColor(this->colorSelection.getValue());
action.setElement(detail);
action.apply(vp->getRoot());
}
delete detail;
}
}
Expand All @@ -296,13 +299,13 @@ void SoFCUnifiedSelection::doAction(SoAction *action)
for (std::vector<ViewProvider*>::iterator it = vps.begin(); it != vps.end(); ++it) {
ViewProviderDocumentObject* vpd = static_cast<ViewProviderDocumentObject*>(*it);
if (vpd->useNewSelectionModel()) {
if (Selection().isSelected(vpd->getObject()) && vpd->isSelectable()) {
SoSelectionElementAction action(SoSelectionElementAction::All);
action.setColor(this->colorSelection.getValue());
action.apply(vpd->getRoot());
}
else {
SoSelectionElementAction action(SoSelectionElementAction::None);
SoSelectionElementAction::Type type;
if(Selection().isSelected(vpd->getObject()) && vpd->isSelectable())
type = SoSelectionElementAction::All;
else
type = SoSelectionElementAction::None;
if(checkSelectionStyle(type,vpd)) {
SoSelectionElementAction action(type);
action.setColor(this->colorSelection.getValue());
action.apply(vpd->getRoot());
}
Expand Down Expand Up @@ -518,7 +521,7 @@ SoFCUnifiedSelection::handleEvent(SoHandleEventAction * action)
}

action->setHandled();
if (currenthighlight) {
if (currenthighlight && checkSelectionStyle(type,vpd)) {
SoSelectionElementAction action(type);
action.setColor(this->colorSelection.getValue());
action.setElement(pp ? pp->getDetail() : 0);
Expand All @@ -532,6 +535,19 @@ SoFCUnifiedSelection::handleEvent(SoHandleEventAction * action)
inherited::handleEvent(action);
}

bool SoFCUnifiedSelection::checkSelectionStyle(int type, ViewProvider *vp) {
if((type == SoSelectionElementAction::All ||
type == SoSelectionElementAction::None) &&
vp->isDerivedFrom(ViewProviderGeometryObject::getClassTypeId()) &&
static_cast<ViewProviderGeometryObject*>(vp)->SelectionStyle.getValue()==1)
{
bool selected = type==SoSelectionElementAction::All;
static_cast<ViewProviderGeometryObject*>(vp)->showBoundingBox(selected);
if(selected) return false;
}
return true;
}

void SoFCUnifiedSelection::GLRenderBelowPath(SoGLRenderAction * action)
{
inherited::GLRenderBelowPath(action);
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/SoFCUnifiedSelection.h
Expand Up @@ -91,6 +91,8 @@ class GuiExport SoFCUnifiedSelection : public SoSeparator {
//virtual void GLRenderInPath(SoGLRenderAction * action);
//static void turnOffCurrentHighlight(SoGLRenderAction * action);

bool checkSelectionStyle(int type, ViewProvider *vp);

friend class View3DInventorViewer;
protected:
virtual ~SoFCUnifiedSelection();
Expand Down
45 changes: 34 additions & 11 deletions src/Gui/ViewProviderGeometryObject.cpp
Expand Up @@ -74,7 +74,7 @@ PROPERTY_SOURCE(Gui::ViewProviderGeometryObject, Gui::ViewProviderDocumentObject

const App::PropertyIntegerConstraint::Constraints intPercent = {0,100,1};

ViewProviderGeometryObject::ViewProviderGeometryObject() : pcBoundSwitch(0)
ViewProviderGeometryObject::ViewProviderGeometryObject() : pcBoundSwitch(0),pcBoundColor(0)
{
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
unsigned long shcol = hGrp->GetUnsigned("DefaultShapeColor",3435973887UL); // light gray (204,204,204)
Expand All @@ -88,6 +88,10 @@ ViewProviderGeometryObject::ViewProviderGeometryObject() : pcBoundSwitch(0)
ADD_PROPERTY(BoundingBox,(false));
ADD_PROPERTY(Selectable,(true));

ADD_PROPERTY(SelectionStyle,((long)0));
static const char *SelectionStyleEnum[] = {"Shape","BoundBox",0};
SelectionStyle.setEnums(SelectionStyleEnum);

bool enableSel = hGrp->GetBool("EnableSelection", true);
Selectable.setValue(enableSel);

Expand Down Expand Up @@ -146,8 +150,10 @@ void ViewProviderGeometryObject::onChanged(const App::Property* prop)
pcShapeMaterial->shininess.setValue(Mat.shininess);
pcShapeMaterial->transparency.setValue(Mat.transparency);
}
else if (prop == &BoundingBox) {
showBoundingBox( BoundingBox.getValue() );
else if (prop == &BoundingBox || prop == &SelectionStyle) {
applyBoundColor();
if(SelectionStyle.getValue()==0 || !Selectable.getValue())
showBoundingBox( BoundingBox.getValue() );
}

ViewProviderDocumentObject::onChanged(prop);
Expand Down Expand Up @@ -409,21 +415,32 @@ SoPickedPoint* ViewProviderGeometryObject::getPickedPoint(const SbVec2s& pos, co
return (pick ? new SoPickedPoint(*pick) : 0);
}

void ViewProviderGeometryObject::applyBoundColor() {
if(!pcBoundColor) return;
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
unsigned long bbcol;
if(SelectionStyle.getValue() == 0 || !Selectable.getValue() || !hGrp->GetBool("EnableSelection", true))
bbcol = hGrp->GetUnsigned("BoundingBoxColor",4294967295UL); // white (255,255,255)
else
bbcol = hGrp->GetUnsigned("SelectionColor",0x00CD00UL); // rgb(0,205,0)

float r,g,b;
r = ((bbcol >> 24) & 0xff) / 255.0; g = ((bbcol >> 16) & 0xff) / 255.0; b = ((bbcol >> 8) & 0xff) / 255.0;
pcBoundColor->rgb.setValue(r, g, b);
}

void ViewProviderGeometryObject::showBoundingBox(bool show)
{
if (!pcBoundSwitch && show) {
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
unsigned long bbcol = hGrp->GetUnsigned("BoundingBoxColor",4294967295UL); // white (255,255,255)
float r,g,b;
r = ((bbcol >> 24) & 0xff) / 255.0; g = ((bbcol >> 16) & 0xff) / 255.0; b = ((bbcol >> 8) & 0xff) / 255.0;
pcBoundSwitch = new SoSwitch();
SoSeparator* pBoundingSep = new SoSeparator();
SoDrawStyle* lineStyle = new SoDrawStyle;
lineStyle->lineWidth = 2.0f;
pBoundingSep->addChild(lineStyle);
SoBaseColor* color = new SoBaseColor();
color->rgb.setValue(r, g, b);
pBoundingSep->addChild(color);

pcBoundColor = new SoBaseColor();
pBoundingSep->addChild(pcBoundColor);
applyBoundColor();

pBoundingSep->addChild(new SoResetTransform());
pBoundingSep->addChild(pcBoundingBox);
Expand All @@ -432,7 +449,7 @@ void ViewProviderGeometryObject::showBoundingBox(bool show)

// add to the highlight node
pcBoundSwitch->addChild(pBoundingSep);
pcRoot->addChild(pcBoundSwitch);
pcRoot->insertChild(pcBoundSwitch,pcRoot->findChild(pcModeSwitch));
}

if (pcBoundSwitch) {
Expand All @@ -442,6 +459,12 @@ void ViewProviderGeometryObject::showBoundingBox(bool show)

void ViewProviderGeometryObject::setSelectable(bool selectable)
{
if(SelectionStyle.getValue()) {
applyBoundColor();
if(!selectable)
showBoundingBox(false);
}

SoSearchAction sa;
sa.setInterest(SoSearchAction::ALL);
sa.setSearchingAll(TRUE);
Expand Down
8 changes: 7 additions & 1 deletion src/Gui/ViewProviderGeometryObject.h
Expand Up @@ -33,6 +33,7 @@ class SoSensor;
class SoDragger;
class SbVec2s;
class SoTransform;
class SoBaseColor;

namespace Base { class Placement;}

Expand Down Expand Up @@ -64,6 +65,7 @@ class GuiExport ViewProviderGeometryObject : public ViewProviderDocumentObject
App::PropertyMaterial ShapeMaterial;
App::PropertyBool BoundingBox;
App::PropertyBool Selectable;
App::PropertyEnumeration SelectionStyle;

/**
* Attaches the document object to this view provider.
Expand Down Expand Up @@ -93,6 +95,9 @@ class GuiExport ViewProviderGeometryObject : public ViewProviderDocumentObject

/*! synchronize From FC placement to Coin placement*/
static void updateTransform(const Base::Placement &from, SoTransform *to);

void showBoundingBox(bool);

protected:
bool setEdit(int ModNum);
void unsetEdit(int ModNum);
Expand All @@ -102,10 +107,10 @@ class GuiExport ViewProviderGeometryObject : public ViewProviderDocumentObject
SoFCCSysDragger *csysDragger = nullptr;

protected:
void showBoundingBox(bool);
/// get called by the container whenever a property has been changed
void onChanged(const App::Property* prop);
void setSelectable(bool Selectable=true);
void applyBoundColor();

private:
static void dragStartCallback(void * data, SoDragger * d);
Expand All @@ -117,6 +122,7 @@ class GuiExport ViewProviderGeometryObject : public ViewProviderDocumentObject
SoMaterial * pcShapeMaterial;
SoFCBoundingBox * pcBoundingBox;
SoSwitch * pcBoundSwitch;
SoBaseColor * pcBoundColor;
};

} // namespace Gui
Expand Down

0 comments on commit a210cc5

Please sign in to comment.