Gui: added bbox selection style to GeometryObject
This commit is contained in:
@@ -79,6 +79,7 @@
|
||||
#include "SoFCInteractiveElement.h"
|
||||
#include "SoFCSelectionAction.h"
|
||||
#include "ViewProviderDocumentObject.h"
|
||||
#include "ViewProviderGeometryObject.h"
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
|
||||
@@ -91,6 +91,8 @@ public:
|
||||
//virtual void GLRenderInPath(SoGLRenderAction * action);
|
||||
//static void turnOffCurrentHighlight(SoGLRenderAction * action);
|
||||
|
||||
bool checkSelectionStyle(int type, ViewProvider *vp);
|
||||
|
||||
friend class View3DInventorViewer;
|
||||
protected:
|
||||
virtual ~SoFCUnifiedSelection();
|
||||
|
||||
@@ -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)
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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) {
|
||||
@@ -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);
|
||||
|
||||
@@ -33,6 +33,7 @@ class SoSensor;
|
||||
class SoDragger;
|
||||
class SbVec2s;
|
||||
class SoTransform;
|
||||
class SoBaseColor;
|
||||
|
||||
namespace Base { class Placement;}
|
||||
|
||||
@@ -64,6 +65,7 @@ public:
|
||||
App::PropertyMaterial ShapeMaterial;
|
||||
App::PropertyBool BoundingBox;
|
||||
App::PropertyBool Selectable;
|
||||
App::PropertyEnumeration SelectionStyle;
|
||||
|
||||
/**
|
||||
* Attaches the document object to this view provider.
|
||||
@@ -93,6 +95,9 @@ public:
|
||||
|
||||
/*! 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);
|
||||
@@ -102,10 +107,10 @@ protected:
|
||||
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);
|
||||
@@ -117,6 +122,7 @@ protected:
|
||||
SoMaterial * pcShapeMaterial;
|
||||
SoFCBoundingBox * pcBoundingBox;
|
||||
SoSwitch * pcBoundSwitch;
|
||||
SoBaseColor * pcBoundColor;
|
||||
};
|
||||
|
||||
} // namespace Gui
|
||||
|
||||
Reference in New Issue
Block a user