From ef610c8c961700b742e5e81cb00a829625606665 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 20 May 2015 21:44:27 +0200 Subject: [PATCH] + remove SoFCSelection from ViewProviderGeometryObject --- src/Gui/ViewProviderGeometryObject.cpp | 49 ++-------------------- src/Gui/ViewProviderGeometryObject.h | 5 +-- src/Mod/Fem/Gui/ViewProviderFemMesh.cpp | 2 - src/Mod/Mesh/Gui/ViewProvider.cpp | 45 ++++++++++++++++++++ src/Mod/Mesh/Gui/ViewProvider.h | 3 ++ src/Mod/Mesh/Gui/ViewProviderCurvature.cpp | 2 +- src/Mod/Mesh/Gui/ViewProviderDefects.cpp | 1 - src/Mod/Points/Gui/ViewProvider.cpp | 46 ++++++++++++++++++++ src/Mod/Points/Gui/ViewProvider.h | 16 ++++--- 9 files changed, 111 insertions(+), 58 deletions(-) diff --git a/src/Gui/ViewProviderGeometryObject.cpp b/src/Gui/ViewProviderGeometryObject.cpp index fad2a958833d..55ab5c92aeb8 100644 --- a/src/Gui/ViewProviderGeometryObject.cpp +++ b/src/Gui/ViewProviderGeometryObject.cpp @@ -85,11 +85,8 @@ ViewProviderGeometryObject::ViewProviderGeometryObject() : pcBoundSwitch(0) ADD_PROPERTY(BoundingBox,(false)); ADD_PROPERTY(Selectable,(true)); - // Create the selection node - pcHighlight = createFromSettings(); - pcHighlight->ref(); - if (pcHighlight->selectionMode.getValue() == Gui::SoFCSelection::SEL_OFF) - Selectable.setValue(false); + bool enableSel = hGrp->GetBool("EnableSelection", true); + Selectable.setValue(enableSel); pcShapeMaterial = new SoMaterial; pcShapeMaterial->ref(); @@ -104,7 +101,6 @@ ViewProviderGeometryObject::ViewProviderGeometryObject() : pcBoundSwitch(0) ViewProviderGeometryObject::~ViewProviderGeometryObject() { pcShapeMaterial->unref(); - pcHighlight->unref(); pcBoundingBox->unref(); } @@ -157,9 +153,6 @@ void ViewProviderGeometryObject::onChanged(const App::Property* prop) void ViewProviderGeometryObject::attach(App::DocumentObject *pcObj) { ViewProviderDocumentObject::attach(pcObj); - pcHighlight->objectName = pcObj->getNameInDocument(); - pcHighlight->documentName = pcObj->getDocument()->getName(); - pcHighlight->subElementName = "Main"; } void ViewProviderGeometryObject::updateData(const App::Property* prop) @@ -516,7 +509,7 @@ SoPickedPointList ViewProviderGeometryObject::getPickedPoints(const SbVec2s& pos root->ref(); root->addChild(viewer.getHeadlight()); root->addChild(viewer.getSoRenderManager()->getCamera()); - root->addChild(this->pcHighlight); + root->addChild(const_cast(this)->getRoot()); SoRayPickAction rp(viewer.getSoRenderManager()->getViewportRegion()); rp.setPickAll(pickAll); @@ -534,7 +527,7 @@ SoPickedPoint* ViewProviderGeometryObject::getPickedPoint(const SbVec2s& pos, co root->ref(); root->addChild(viewer.getHeadlight()); root->addChild(viewer.getSoRenderManager()->getCamera()); - root->addChild(this->pcHighlight); + root->addChild(const_cast(this)->getRoot()); SoRayPickAction rp(viewer.getSoRenderManager()->getViewportRegion()); rp.setPoint(pos); @@ -578,40 +571,6 @@ void ViewProviderGeometryObject::showBoundingBox(bool show) } } -SoFCSelection* ViewProviderGeometryObject::createFromSettings() const -{ - SoFCSelection* sel = new 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 ViewProviderGeometryObject::setSelectable(bool selectable) { SoSearchAction sa; diff --git a/src/Gui/ViewProviderGeometryObject.h b/src/Gui/ViewProviderGeometryObject.h index 08e7dd56058d..a538c6b7c69c 100644 --- a/src/Gui/ViewProviderGeometryObject.h +++ b/src/Gui/ViewProviderGeometryObject.h @@ -67,11 +67,10 @@ class GuiExport ViewProviderGeometryObject : public ViewProviderDocumentObject void attach(App::DocumentObject *pcObject); void updateData(const App::Property*); - SoFCSelection* getHighlightNode() const { return pcHighlight; } bool isSelectable(void) const {return Selectable.getValue();} /** - * Returns a list of picked points from the geometry under \a pcHighlight. + * Returns a list of picked points from the geometry under \a getRoot(). * If \a pickAll is false (the default) only the intersection point closest to the camera will be picked, otherwise * all intersection points will be picked. */ @@ -98,7 +97,6 @@ class GuiExport ViewProviderGeometryObject : public ViewProviderDocumentObject void showBoundingBox(bool); /// get called by the container whenever a property has been changed void onChanged(const App::Property* prop); - SoFCSelection* createFromSettings() const; void setSelectable(bool Selectable=true); private: @@ -108,7 +106,6 @@ class GuiExport ViewProviderGeometryObject : public ViewProviderDocumentObject static void dragMotionCallback(void * data, SoDragger * d); protected: - SoFCSelection * pcHighlight; SoMaterial * pcShapeMaterial; SoFCBoundingBox * pcBoundingBox; SoSwitch * pcBoundSwitch; diff --git a/src/Mod/Fem/Gui/ViewProviderFemMesh.cpp b/src/Mod/Fem/Gui/ViewProviderFemMesh.cpp index 382e0f4ff0b1..0d21508e8db4 100755 --- a/src/Mod/Fem/Gui/ViewProviderFemMesh.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemMesh.cpp @@ -254,8 +254,6 @@ void ViewProviderFemMesh::attach(App::DocumentObject *pcObj) SoPointSet * pointset = new SoPointSet; pcAnotRoot->addChild(pointset); - //pcHighlight->addChild(pcFaces); - // flat SoGroup* pcFlatRoot = new SoGroup(); // face nodes diff --git a/src/Mod/Mesh/Gui/ViewProvider.cpp b/src/Mod/Mesh/Gui/ViewProvider.cpp index 740e42842356..481a1c9bd8a3 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.cpp +++ b/src/Mod/Mesh/Gui/ViewProvider.cpp @@ -242,6 +242,12 @@ ViewProviderMesh::ViewProviderMesh() : pcOpenEdge(0) Lighting.setEnums(LightingEnums); ADD_PROPERTY(LineColor,(0,0,0)); + // Create the selection node + pcHighlight = createFromSettings(); + pcHighlight->ref(); + if (pcHighlight->selectionMode.getValue() == Gui::SoFCSelection::SEL_OFF) + Selectable.setValue(false); + pOpenColor = new SoBaseColor(); setOpenEdgeColorFrom(ShapeColor.getValue()); pOpenColor->ref(); @@ -307,6 +313,7 @@ ViewProviderMesh::ViewProviderMesh() : pcOpenEdge(0) ViewProviderMesh::~ViewProviderMesh() { + pcHighlight->unref(); pOpenColor->unref(); pcLineStyle->unref(); pcPointStyle->unref(); @@ -315,6 +322,40 @@ 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 @@ -389,6 +430,10 @@ void ViewProviderMesh::attach(App::DocumentObject *pcFeat) { ViewProviderGeometryObject::attach(pcFeat); + pcHighlight->objectName = pcFeat->getNameInDocument(); + pcHighlight->documentName = pcFeat->getDocument()->getName(); + pcHighlight->subElementName = "Main"; + // Note: Since for mesh data the SoFCSelection node has no SoSeparator but // an SoGroup as parent the EMISSIVE style if set has fundamentally no effect. // This behaviour is given due to the fact that SoFCSelection inherits from diff --git a/src/Mod/Mesh/Gui/ViewProvider.h b/src/Mod/Mesh/Gui/ViewProvider.h index 6936fdec7af0..de7655f56464 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.h +++ b/src/Mod/Mesh/Gui/ViewProvider.h @@ -123,6 +123,7 @@ class MeshGuiExport ViewProviderMesh : public Gui::ViewProviderGeometryObject virtual void attach(App::DocumentObject *); virtual bool useNewSelectionModel(void) const {return false;} + Gui::SoFCSelection* getHighlightNode() const { return pcHighlight; } virtual QIcon getIcon() const; /// Sets the correct display mode virtual void setDisplayMode(const char* ModeName); @@ -175,6 +176,7 @@ class MeshGuiExport ViewProviderMesh : public Gui::ViewProviderGeometryObject virtual SoShape* getShapeNode() const; virtual SoNode* getCoordNode() const; + Gui::SoFCSelection* createFromSettings() const; public: static void faceInfoCallback(void * ud, SoEventCallback * n); @@ -195,6 +197,7 @@ class MeshGuiExport ViewProviderMesh : public Gui::ViewProviderGeometryObject static void panCamera(SoCamera*, float, const SbPlane&, const SbVec2f&, const SbVec2f&); protected: + Gui::SoFCSelection * pcHighlight; SoDrawStyle * pcLineStyle; SoDrawStyle * pcPointStyle; SoSeparator * pcOpenEdge; diff --git a/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp b/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp index 0fe1d5454599..475da1f1dac6 100644 --- a/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp +++ b/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp @@ -315,7 +315,7 @@ void ViewProviderMeshCurvature::updateData(const App::Property* prop) // get the view provider of the associated mesh feature App::Document* rDoc = pcObject->getDocument(); Gui::Document* pDoc = Gui::Application::Instance->getDocument(rDoc); - Gui::ViewProviderGeometryObject* view = static_cast(pDoc->getViewProvider(object)); + ViewProviderMesh* view = static_cast(pDoc->getViewProvider(object)); this->pcLinkRoot->addChild(view->getHighlightNode()); } } diff --git a/src/Mod/Mesh/Gui/ViewProviderDefects.cpp b/src/Mod/Mesh/Gui/ViewProviderDefects.cpp index af9e036717ff..698adc608655 100644 --- a/src/Mod/Mesh/Gui/ViewProviderDefects.cpp +++ b/src/Mod/Mesh/Gui/ViewProviderDefects.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include #include diff --git a/src/Mod/Points/Gui/ViewProvider.cpp b/src/Mod/Points/Gui/ViewProvider.cpp index 4941b4c4b89c..ee878513ec71 100644 --- a/src/Mod/Points/Gui/ViewProvider.cpp +++ b/src/Mod/Points/Gui/ViewProvider.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #include @@ -72,6 +73,12 @@ ViewProviderPoints::ViewProviderPoints() ADD_PROPERTY(PointSize,(2.0f)); PointSize.setConstraints(&floatRange); + // Create the selection node + pcHighlight = createFromSettings(); + pcHighlight->ref(); + if (pcHighlight->selectionMode.getValue() == Gui::SoFCSelection::SEL_OFF) + Selectable.setValue(false); + pcPointsCoord = new SoCoordinate3(); pcPointsCoord->ref(); pcPoints = new SoPointSet(); @@ -89,6 +96,7 @@ ViewProviderPoints::ViewProviderPoints() ViewProviderPoints::~ViewProviderPoints() { + pcHighlight->unref(); pcPointsCoord->unref(); pcPoints->unref(); pcPointsNormal->unref(); @@ -96,6 +104,40 @@ 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 ) { @@ -162,6 +204,10 @@ void ViewProviderPoints::attach(App::DocumentObject* pcObj) // call parent's attach to define display modes ViewProviderGeometryObject::attach(pcObj); + pcHighlight->objectName = pcObj->getNameInDocument(); + pcHighlight->documentName = pcObj->getDocument()->getName(); + pcHighlight->subElementName = "Main"; + SoGroup* pcPointRoot = new SoGroup(); SoGroup* pcPointShadedRoot = new SoGroup(); SoGroup* pcColorShadedRoot = new SoGroup(); diff --git a/src/Mod/Points/Gui/ViewProvider.h b/src/Mod/Points/Gui/ViewProvider.h index 40e978b1af6c..60c9266d89f6 100644 --- a/src/Mod/Points/Gui/ViewProvider.h +++ b/src/Mod/Points/Gui/ViewProvider.h @@ -41,6 +41,10 @@ namespace App { class PropertyColorList; } +namespace Gui { + class SoFCSelection; +} + namespace Points { class PropertyGreyValueList; class PropertyNormalList; @@ -96,6 +100,7 @@ class PointsGuiExport ViewProviderPoints : public Gui::ViewProviderGeometryObjec 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*); @@ -103,11 +108,12 @@ class PointsGuiExport ViewProviderPoints : public Gui::ViewProviderGeometryObjec virtual void cut( const std::vector& picked, Gui::View3DInventorViewer &Viewer); protected: - SoCoordinate3 *pcPointsCoord; - SoPointSet *pcPoints; - SoMaterial *pcColorMat; - SoNormal *pcPointsNormal; - SoDrawStyle *pcPointStyle; + Gui::SoFCSelection * pcHighlight; + SoCoordinate3 * pcPointsCoord; + SoPointSet * pcPoints; + SoMaterial * pcColorMat; + SoNormal * pcPointsNormal; + SoDrawStyle * pcPointStyle; private: static App::PropertyFloatConstraint::Constraints floatRange;