+ move creation of SoFCSelection node to ViewProviderBuilder to avoid code duplication
This commit is contained in:
parent
2521718820
commit
d4ec3a985a
|
@ -28,6 +28,8 @@
|
|||
#endif
|
||||
|
||||
#include "ViewProviderBuilder.h"
|
||||
#include "SoFCSelection.h"
|
||||
#include "Window.h"
|
||||
#include <App/PropertyStandard.h>
|
||||
|
||||
using namespace Gui;
|
||||
|
@ -55,6 +57,40 @@ ViewProvider* ViewProviderBuilder::create(const Base::Type& type)
|
|||
return 0;
|
||||
}
|
||||
|
||||
Gui::SoFCSelection* ViewProviderBuilder::createSelection()
|
||||
{
|
||||
Gui::SoFCSelection* sel = new Gui::SoFCSelection();
|
||||
|
||||
float transparency;
|
||||
ParameterGrp::handle hGrp = Gui::WindowParameter::getDefaultParameter()->GetGroup("View");
|
||||
bool enablePre = hGrp->GetBool("EnablePreselection", true);
|
||||
bool enableSel = hGrp->GetBool("EnableSelection", true);
|
||||
if (!enablePre) {
|
||||
sel->highlightMode = Gui::SoFCSelection::OFF;
|
||||
}
|
||||
else {
|
||||
// Search for a user defined value with the current color as default
|
||||
SbColor highlightColor = sel->colorHighlight.getValue();
|
||||
unsigned long highlight = (unsigned long)(highlightColor.getPackedValue());
|
||||
highlight = hGrp->GetUnsigned("HighlightColor", highlight);
|
||||
highlightColor.setPackedValue((uint32_t)highlight, transparency);
|
||||
sel->colorHighlight.setValue(highlightColor);
|
||||
}
|
||||
if (!enableSel) {
|
||||
sel->selectionMode = Gui::SoFCSelection::SEL_OFF;
|
||||
}
|
||||
else {
|
||||
// Do the same with the selection color
|
||||
SbColor selectionColor = sel->colorSelection.getValue();
|
||||
unsigned long selection = (unsigned long)(selectionColor.getPackedValue());
|
||||
selection = hGrp->GetUnsigned("SelectionColor", selection);
|
||||
selectionColor.setPackedValue((uint32_t)selection, transparency);
|
||||
sel->colorSelection.setValue(selectionColor);
|
||||
}
|
||||
|
||||
return sel;
|
||||
}
|
||||
|
||||
// --------------------------------------
|
||||
|
||||
ViewProviderColorBuilder::ViewProviderColorBuilder()
|
||||
|
|
|
@ -40,6 +40,7 @@ namespace Gui
|
|||
{
|
||||
|
||||
class ViewProvider;
|
||||
class SoFCSelection;
|
||||
class GuiExport ViewProviderBuilder
|
||||
{
|
||||
public:
|
||||
|
@ -50,6 +51,7 @@ public:
|
|||
|
||||
static void add(const Base::Type&, const Base::Type&);
|
||||
static ViewProvider* create(const Base::Type&);
|
||||
static SoFCSelection* createSelection();
|
||||
|
||||
private:
|
||||
static std::map<Base::Type, Base::Type> _prop_to_view;
|
||||
|
|
|
@ -244,7 +244,7 @@ ViewProviderMesh::ViewProviderMesh() : pcOpenEdge(0)
|
|||
ADD_PROPERTY(LineColor,(0,0,0));
|
||||
|
||||
// Create the selection node
|
||||
pcHighlight = createFromSettings();
|
||||
pcHighlight = Gui::ViewProviderBuilder::createSelection();
|
||||
pcHighlight->ref();
|
||||
if (pcHighlight->selectionMode.getValue() == Gui::SoFCSelection::SEL_OFF)
|
||||
Selectable.setValue(false);
|
||||
|
@ -325,40 +325,6 @@ ViewProviderMesh::~ViewProviderMesh()
|
|||
pLineColor->unref();
|
||||
}
|
||||
|
||||
Gui::SoFCSelection* ViewProviderMesh::createFromSettings() const
|
||||
{
|
||||
Gui::SoFCSelection* sel = new Gui::SoFCSelection();
|
||||
|
||||
float transparency;
|
||||
ParameterGrp::handle hGrp = Gui::WindowParameter::getDefaultParameter()->GetGroup("View");
|
||||
bool enablePre = hGrp->GetBool("EnablePreselection", true);
|
||||
bool enableSel = hGrp->GetBool("EnableSelection", true);
|
||||
if (!enablePre) {
|
||||
sel->highlightMode = Gui::SoFCSelection::OFF;
|
||||
}
|
||||
else {
|
||||
// Search for a user defined value with the current color as default
|
||||
SbColor highlightColor = sel->colorHighlight.getValue();
|
||||
unsigned long highlight = (unsigned long)(highlightColor.getPackedValue());
|
||||
highlight = hGrp->GetUnsigned("HighlightColor", highlight);
|
||||
highlightColor.setPackedValue((uint32_t)highlight, transparency);
|
||||
sel->colorHighlight.setValue(highlightColor);
|
||||
}
|
||||
if (!enableSel || !Selectable.getValue()) {
|
||||
sel->selectionMode = Gui::SoFCSelection::SEL_OFF;
|
||||
}
|
||||
else {
|
||||
// Do the same with the selection color
|
||||
SbColor selectionColor = sel->colorSelection.getValue();
|
||||
unsigned long selection = (unsigned long)(selectionColor.getPackedValue());
|
||||
selection = hGrp->GetUnsigned("SelectionColor", selection);
|
||||
selectionColor.setPackedValue((uint32_t)selection, transparency);
|
||||
sel->colorSelection.setValue(selectionColor);
|
||||
}
|
||||
|
||||
return sel;
|
||||
}
|
||||
|
||||
void ViewProviderMesh::onChanged(const App::Property* prop)
|
||||
{
|
||||
// we gonna change the number of colors to one
|
||||
|
@ -474,7 +440,7 @@ void ViewProviderMesh::attach(App::DocumentObject *pcFeat)
|
|||
addDisplayMaskMode(pcWireRoot, "Wireframe");
|
||||
|
||||
// faces+wires
|
||||
Gui::SoFCSelection* selGroup = createFromSettings();
|
||||
Gui::SoFCSelection* selGroup = Gui::ViewProviderBuilder::createSelection();
|
||||
selGroup->objectName = getObject()->getNameInDocument();
|
||||
selGroup->documentName = getObject()->getDocument()->getName();
|
||||
selGroup->subElementName = "Main";
|
||||
|
|
|
@ -184,7 +184,6 @@ protected:
|
|||
|
||||
virtual SoShape* getShapeNode() const;
|
||||
virtual SoNode* getCoordNode() const;
|
||||
Gui::SoFCSelection* createFromSettings() const;
|
||||
|
||||
public:
|
||||
static void faceInfoCallback(void * ud, SoEventCallback * n);
|
||||
|
|
|
@ -75,7 +75,7 @@ ViewProviderPoints::ViewProviderPoints()
|
|||
PointSize.setConstraints(&floatRange);
|
||||
|
||||
// Create the selection node
|
||||
pcHighlight = createFromSettings();
|
||||
pcHighlight = Gui::ViewProviderBuilder::createSelection();
|
||||
pcHighlight->ref();
|
||||
if (pcHighlight->selectionMode.getValue() == Gui::SoFCSelection::SEL_OFF)
|
||||
Selectable.setValue(false);
|
||||
|
@ -102,40 +102,6 @@ ViewProviderPoints::~ViewProviderPoints()
|
|||
pcPointStyle->unref();
|
||||
}
|
||||
|
||||
Gui::SoFCSelection* ViewProviderPoints::createFromSettings() const
|
||||
{
|
||||
Gui::SoFCSelection* sel = new Gui::SoFCSelection();
|
||||
|
||||
float transparency;
|
||||
ParameterGrp::handle hGrp = Gui::WindowParameter::getDefaultParameter()->GetGroup("View");
|
||||
bool enablePre = hGrp->GetBool("EnablePreselection", true);
|
||||
bool enableSel = hGrp->GetBool("EnableSelection", true);
|
||||
if (!enablePre) {
|
||||
sel->highlightMode = Gui::SoFCSelection::OFF;
|
||||
}
|
||||
else {
|
||||
// Search for a user defined value with the current color as default
|
||||
SbColor highlightColor = sel->colorHighlight.getValue();
|
||||
unsigned long highlight = (unsigned long)(highlightColor.getPackedValue());
|
||||
highlight = hGrp->GetUnsigned("HighlightColor", highlight);
|
||||
highlightColor.setPackedValue((uint32_t)highlight, transparency);
|
||||
sel->colorHighlight.setValue(highlightColor);
|
||||
}
|
||||
if (!enableSel || !Selectable.getValue()) {
|
||||
sel->selectionMode = Gui::SoFCSelection::SEL_OFF;
|
||||
}
|
||||
else {
|
||||
// Do the same with the selection color
|
||||
SbColor selectionColor = sel->colorSelection.getValue();
|
||||
unsigned long selection = (unsigned long)(selectionColor.getPackedValue());
|
||||
selection = hGrp->GetUnsigned("SelectionColor", selection);
|
||||
selectionColor.setPackedValue((uint32_t)selection, transparency);
|
||||
sel->colorSelection.setValue(selectionColor);
|
||||
}
|
||||
|
||||
return sel;
|
||||
}
|
||||
|
||||
void ViewProviderPoints::onChanged(const App::Property* prop)
|
||||
{
|
||||
if (prop == &PointSize) {
|
||||
|
|
|
@ -95,7 +95,6 @@ public:
|
|||
static void clipPointsCallback(void * ud, SoEventCallback * n);
|
||||
|
||||
protected:
|
||||
Gui::SoFCSelection* createFromSettings() const;
|
||||
void onChanged(const App::Property* prop);
|
||||
void setVertexColorMode(App::PropertyColorList*);
|
||||
void setVertexGreyvalueMode(Points::PropertyGreyValueList*);
|
||||
|
|
Loading…
Reference in New Issue
Block a user