From 2a5d8009409231403c596b79eb38a79304de546e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Sat, 8 Aug 2015 11:07:37 +0200 Subject: [PATCH] fix origin plane and line viewprovider master changed the highlight code for viewproviders, needed an adjustement after rebase --- src/Gui/ViewProviderLine.cpp | 62 ++++++++++++++++++++++++++++++----- src/Gui/ViewProviderLine.h | 3 ++ src/Gui/ViewProviderPlane.cpp | 60 +++++++++++++++++++++++++++++---- src/Gui/ViewProviderPlane.h | 6 +++- 4 files changed, 115 insertions(+), 16 deletions(-) diff --git a/src/Gui/ViewProviderLine.cpp b/src/Gui/ViewProviderLine.cpp index 6026bb16c..7e9276a3a 100644 --- a/src/Gui/ViewProviderLine.cpp +++ b/src/Gui/ViewProviderLine.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2012 * + * Copyright (c) J�rgen Riegel (juergen.riegel@web.de) 2012 * * * * This file is part of the FreeCAD CAx development system. * * * @@ -51,6 +51,7 @@ #include "View3DInventorViewer.h" #include "Inventor/SoAutoZoomTranslation.h" #include "SoAxisCrossKit.h" +#include "Window.h" //#include #include @@ -84,6 +85,12 @@ ViewProviderLine::ViewProviderLine() 0,1,-1 }; + // Create the selection node + pcHighlight = createFromSettings(); + pcHighlight->ref(); + if (pcHighlight->selectionMode.getValue() == Gui::SoFCSelection::SEL_OFF) + Selectable.setValue(false); + pMat->diffuseColor.setNum(1); pMat->diffuseColor.set1Value(0, SbColor(50./255., 150./255., 250./255.)); @@ -113,6 +120,7 @@ ViewProviderLine::ViewProviderLine() ViewProviderLine::~ViewProviderLine() { + pcHighlight->unref(); pCoords->unref(); pLines->unref(); pMat->unref(); @@ -157,6 +165,10 @@ void ViewProviderLine::attach(App::DocumentObject* pcObject) { ViewProviderGeometryObject::attach(pcObject); + pcHighlight->objectName = pcObject->getNameInDocument(); + pcHighlight->documentName = pcObject->getDocument()->getName(); + pcHighlight->subElementName = "Main"; + SoSeparator *sep = new SoSeparator(); SoAnnotation *lineSep = new SoAnnotation(); @@ -168,10 +180,10 @@ void ViewProviderLine::attach(App::DocumentObject* pcObject) sep->addChild(matBinding); sep->addChild(pMat); -// sep->addChild(getHighlightNode()); -// pcHighlight->addChild(style); -// pcHighlight->addChild(pCoords); -// pcHighlight->addChild(pLines); + sep->addChild(pcHighlight); + pcHighlight->addChild(style); + pcHighlight->addChild(pCoords); + pcHighlight->addChild(pLines); style = new SoDrawStyle(); style->lineWidth = 2.0f; @@ -182,9 +194,9 @@ void ViewProviderLine::attach(App::DocumentObject* pcObject) pText->string.setValue(SbString(pcObject->Label.getValue())); lineSep->addChild(pTranslation); lineSep->addChild(pText); -// pcHighlight->addChild(lineSep); -// -// pcHighlight->style = SoFCSelection::EMISSIVE_DIFFUSE; + pcHighlight->addChild(lineSep); + + pcHighlight->style = SoFCSelection::EMISSIVE_DIFFUSE; addDisplayMaskMode(sep, "Base"); } @@ -241,6 +253,40 @@ void ViewProviderLine::unsetEdit(int ModNum) } +Gui::SoFCSelection* ViewProviderLine::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; +} + // ---------------------------------------------------------------------------- diff --git a/src/Gui/ViewProviderLine.h b/src/Gui/ViewProviderLine.h index a108c0d5e..db86670c6 100644 --- a/src/Gui/ViewProviderLine.h +++ b/src/Gui/ViewProviderLine.h @@ -41,6 +41,7 @@ class SoFont; namespace Gui { +class SoFCSelection; class GuiExport ViewProviderLine : public ViewProviderGeometryObject { @@ -70,9 +71,11 @@ public: virtual void unsetEdit(int ModNum); protected: + SoFCSelection* createFromSettings() const; void onChanged(const App::Property* prop); private: + SoFCSelection * pcHighlight; SoCoordinate3 * pCoords; SoMaterial * pMat; SoIndexedLineSet * pLines; diff --git a/src/Gui/ViewProviderPlane.cpp b/src/Gui/ViewProviderPlane.cpp index 9277fba2b..e78583e7d 100644 --- a/src/Gui/ViewProviderPlane.cpp +++ b/src/Gui/ViewProviderPlane.cpp @@ -51,6 +51,7 @@ #include "View3DInventorViewer.h" #include "Inventor/SoAutoZoomTranslation.h" #include "SoAxisCrossKit.h" +#include "Window.h" //#include #include @@ -85,6 +86,13 @@ ViewProviderPlane::ViewProviderPlane() 0,1,2,3,0,-1 }; + // Create the selection node + pcHighlight = createFromSettings(); + pcHighlight->ref(); + if (pcHighlight->selectionMode.getValue() == Gui::SoFCSelection::SEL_OFF) + Selectable.setValue(false); + + pMat->diffuseColor.setNum(1); pMat->diffuseColor.set1Value(0, SbColor(50./255., 150./255., 250./255.)); @@ -112,6 +120,7 @@ ViewProviderPlane::ViewProviderPlane() ViewProviderPlane::~ViewProviderPlane() { + pcHighlight->unref(); pCoords->unref(); pLines->unref(); pMat->unref(); @@ -155,9 +164,12 @@ void ViewProviderPlane::attach(App::DocumentObject* pcObject) { ViewProviderGeometryObject::attach(pcObject); + pcHighlight->objectName = pcObject->getNameInDocument(); + pcHighlight->documentName = pcObject->getDocument()->getName(); + pcHighlight->subElementName = "Main"; + SoSeparator *sep = new SoSeparator(); SoAnnotation *lineSep = new SoAnnotation(); - SoFCSelection *highlight = new SoFCSelection(); SoDrawStyle* style = new SoDrawStyle(); style->lineWidth = 2.0f; @@ -167,10 +179,10 @@ void ViewProviderPlane::attach(App::DocumentObject* pcObject) sep->addChild(matBinding); sep->addChild(pMat); - sep->addChild(highlight); - highlight->addChild(style); - highlight->addChild(pCoords); - highlight->addChild(pLines); + sep->addChild(pcHighlight); + pcHighlight->addChild(style); + pcHighlight->addChild(pCoords); + pcHighlight->addChild(pLines); style = new SoDrawStyle(); style->lineWidth = 2.0f; @@ -181,9 +193,9 @@ void ViewProviderPlane::attach(App::DocumentObject* pcObject) pText->string.setValue(SbString(pcObject->Label.getValue())); lineSep->addChild(pTranslation); lineSep->addChild(pText); - highlight->addChild(lineSep); + pcHighlight->addChild(lineSep); - highlight->style = SoFCSelection::EMISSIVE_DIFFUSE; + pcHighlight->style = SoFCSelection::EMISSIVE_DIFFUSE; addDisplayMaskMode(sep, "Base"); } @@ -240,6 +252,40 @@ void ViewProviderPlane::unsetEdit(int ModNum) } +Gui::SoFCSelection* ViewProviderPlane::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; +} + // ---------------------------------------------------------------------------- diff --git a/src/Gui/ViewProviderPlane.h b/src/Gui/ViewProviderPlane.h index 024ffa10b..6f43c2143 100644 --- a/src/Gui/ViewProviderPlane.h +++ b/src/Gui/ViewProviderPlane.h @@ -38,8 +38,10 @@ class SoMaterial; class SoAsciiText; class SoFont; -namespace Gui +namespace Gui { + +class SoFCSelection; class GuiExport ViewProviderPlane : public ViewProviderGeometryObject @@ -70,9 +72,11 @@ public: virtual void unsetEdit(int ModNum); protected: + SoFCSelection* createFromSettings() const; void onChanged(const App::Property* prop); private: + SoFCSelection * pcHighlight; SoCoordinate3 * pCoords; SoMaterial * pMat; SoIndexedLineSet * pLines;