Skip to content

Commit

Permalink
fix origin plane and line viewprovider
Browse files Browse the repository at this point in the history
master changed the highlight code for viewproviders, needed an adjustement after rebase
  • Loading branch information
ickby committed Aug 8, 2015
1 parent c4f3c5d commit 397f592
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 15 deletions.
60 changes: 53 additions & 7 deletions src/Gui/ViewProviderLine.cpp
Expand Up @@ -51,6 +51,7 @@
#include "View3DInventorViewer.h"
#include "Inventor/SoAutoZoomTranslation.h"
#include "SoAxisCrossKit.h"
#include "Window.h"
//#include <SoDepthBuffer.h>

#include <App/PropertyGeo.h>
Expand Down Expand Up @@ -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.));

Expand Down Expand Up @@ -113,6 +120,7 @@ ViewProviderLine::ViewProviderLine()

ViewProviderLine::~ViewProviderLine()
{
pcHighlight->unref();
pCoords->unref();
pLines->unref();
pMat->unref();
Expand Down Expand Up @@ -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();

Expand All @@ -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;
Expand All @@ -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");
}

Expand Down Expand Up @@ -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;
}

// ----------------------------------------------------------------------------


3 changes: 3 additions & 0 deletions src/Gui/ViewProviderLine.h
Expand Up @@ -41,6 +41,7 @@ class SoFont;
namespace Gui
{

class SoFCSelection;

class GuiExport ViewProviderLine : public ViewProviderGeometryObject
{
Expand Down Expand Up @@ -70,9 +71,11 @@ class GuiExport ViewProviderLine : public ViewProviderGeometryObject
virtual void unsetEdit(int ModNum);

protected:
SoFCSelection* createFromSettings() const;
void onChanged(const App::Property* prop);

private:
SoFCSelection * pcHighlight;
SoCoordinate3 * pCoords;
SoMaterial * pMat;
SoIndexedLineSet * pLines;
Expand Down
61 changes: 54 additions & 7 deletions src/Gui/ViewProviderPlane.cpp
Expand Up @@ -51,6 +51,7 @@
#include "View3DInventorViewer.h"
#include "Inventor/SoAutoZoomTranslation.h"
#include "SoAxisCrossKit.h"
#include "Window.h"
//#include <SoDepthBuffer.h>

#include <App/PropertyGeo.h>
Expand Down Expand Up @@ -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.));

Expand Down Expand Up @@ -112,6 +120,7 @@ ViewProviderPlane::ViewProviderPlane()

ViewProviderPlane::~ViewProviderPlane()
{
pcHighlight->unref();
pCoords->unref();
pLines->unref();
pMat->unref();
Expand Down Expand Up @@ -155,6 +164,10 @@ 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();

Expand All @@ -166,10 +179,10 @@ void ViewProviderPlane::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;
Expand All @@ -180,9 +193,9 @@ void ViewProviderPlane::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");
}

Expand Down Expand Up @@ -239,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;
}

// ----------------------------------------------------------------------------


6 changes: 5 additions & 1 deletion src/Gui/ViewProviderPlane.h
Expand Up @@ -38,8 +38,10 @@ class SoMaterial;
class SoAsciiText;
class SoFont;

namespace Gui
namespace Gui
{

class SoFCSelection;


class GuiExport ViewProviderPlane : public ViewProviderGeometryObject
Expand Down Expand Up @@ -70,9 +72,11 @@ class GuiExport ViewProviderPlane : public ViewProviderGeometryObject
virtual void unsetEdit(int ModNum);

protected:
SoFCSelection* createFromSettings() const;
void onChanged(const App::Property* prop);

private:
SoFCSelection * pcHighlight;
SoCoordinate3 * pCoords;
SoMaterial * pMat;
SoIndexedLineSet * pLines;
Expand Down

1 comment on commit 397f592

@Fat-Zer
Copy link

@Fat-Zer Fat-Zer commented on 397f592 Nov 1, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commited earlier and particularly rewritten...

Please sign in to comment.