Gui: refactor Plane's and Line's ViewProviders and add yet another one for OriginFeature

- Share the code of Gui::ViewProviderPlanes and Gui::ViewProviderLine
   in Gui::ViewProviderOriginFeature
 - Add support for coloring and transparencing the OriginFeatures by
   ViewProviderGeometryObject means.
This commit is contained in:
Alexander Golubev
2015-09-03 08:37:06 +03:00
committed by Stefan Tröger
parent 6414c3166b
commit 1b76b1117d
9 changed files with 362 additions and 577 deletions

View File

@@ -103,6 +103,7 @@
#include "ViewProviderAnnotation.h"
#include "ViewProviderMeasureDistance.h"
#include "ViewProviderPlacement.h"
#include "ViewProviderOriginFeature.h"
#include "ViewProviderPlane.h"
#include "ViewProviderLine.h"
#include "ViewProviderGeoFeatureGroup.h"
@@ -1543,6 +1544,7 @@ void Application::initTypes(void)
Gui::ViewProviderPythonFeature ::init();
Gui::ViewProviderPythonGeometry ::init();
Gui::ViewProviderPlacement ::init();
Gui::ViewProviderOriginFeature ::init();
Gui::ViewProviderPlane ::init();
Gui::ViewProviderLine ::init();
Gui::ViewProviderGeoFeatureGroup ::init();

View File

@@ -834,6 +834,7 @@ SET(Viewprovider_CPP_SRCS
ViewProviderVRMLObject.cpp
ViewProviderBuilder.cpp
ViewProviderPlacement.cpp
ViewProviderOriginFeature.cpp
ViewProviderPlane.cpp
ViewProviderLine.cpp
ViewProviderGeoFeatureGroup.cpp
@@ -857,6 +858,7 @@ SET(Viewprovider_SRCS
ViewProviderVRMLObject.h
ViewProviderBuilder.h
ViewProviderPlacement.h
ViewProviderOriginFeature.h
ViewProviderPlane.h
ViewProviderLine.h
ViewProviderGeoFeatureGroup.h

View File

@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright (c) J<EFBFBD>rgen Riegel (juergen.riegel@web.de) 2012 *
* Copyright (c) Juergen Riegel (juergen.riegel@web.de) 2012 *
* Copyright (c) Alexander Golubev (Fat-Zer) <fatzer2@gmail.com> 2015 *
* *
* This file is part of the FreeCAD CAx development system. *
* *
@@ -24,269 +25,56 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <sstream>
# include <QApplication>
# include <Inventor/SoPickedPoint.h>
# include <Inventor/events/SoMouseButtonEvent.h>
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/nodes/SoBaseColor.h>
# include <Inventor/nodes/SoFontStyle.h>
# include <Inventor/nodes/SoPickStyle.h>
# include <Inventor/nodes/SoText2.h>
# include <Inventor/nodes/SoTranslation.h>
# include <Inventor/nodes/SoAsciiText.h>
# include <Inventor/nodes/SoCoordinate3.h>
# include <Inventor/nodes/SoFont.h>
# include <Inventor/nodes/SoIndexedLineSet.h>
# include <Inventor/nodes/SoMarkerSet.h>
# include <Inventor/nodes/SoDrawStyle.h>
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/nodes/SoTranslation.h>
#endif
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoAnnotation.h>
#include <Inventor/details/SoLineDetail.h>
#include <Inventor/nodes/SoAsciiText.h>
#include "ViewProviderLine.h"
#include "SoFCSelection.h"
#include "Application.h"
#include "Document.h"
#include "View3DInventorViewer.h"
#include "Inventor/SoAutoZoomTranslation.h"
#include "SoAxisCrossKit.h"
#include "Window.h"
//#include <SoDepthBuffer.h>
#include "ViewProviderOrigin.h"
#include <App/PropertyGeo.h>
#include <App/PropertyStandard.h>
#include <App/MeasureDistance.h>
#include <Base/Console.h>
#include "ViewProviderLine.h"
using namespace Gui;
PROPERTY_SOURCE(Gui::ViewProviderLine, Gui::ViewProviderGeometryObject)
PROPERTY_SOURCE(Gui::ViewProviderLine, Gui::ViewProviderOriginFeature)
ViewProviderLine::ViewProviderLine()
{
{ }
ADD_PROPERTY(Size,(1.0));
ViewProviderLine::~ViewProviderLine()
{ }
pMat = new SoMaterial();
pMat->ref();
void ViewProviderLine::attach ( App::DocumentObject *obj ) {
ViewProviderOriginFeature::attach ( obj );
float size = Size.getValue(); // Note: If you change this, you need to also adapt App/Line.cpp getBoundBox()
static const float size = ViewProviderOrigin::defaultSize ();
SbVec3f verts[4] =
{
SbVec3f(-size,0,0), SbVec3f(size,0,0),
};
static const SbVec3f verts[2] = { SbVec3f(size, 0, 0), SbVec3f ( -size, 0, 0 ) };
// indexes used to create the edges
static const int32_t lines[6] =
{
0,1,-1
};
static const int32_t lines[4] = { 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.));
SoSeparator *sep = getOriginFeatureRoot ();
pCoords = new SoCoordinate3();
pCoords->ref();
pCoords->point.setNum(2);
pCoords->point.setValues(0, 2, verts);
SoCoordinate3 *pCoords = new SoCoordinate3 ();
pCoords->point.setNum (2);
pCoords->point.setValues ( 0, 2, verts );
sep->addChild ( pCoords );
pLines = new SoIndexedLineSet();
SoIndexedLineSet *pLines = new SoIndexedLineSet ();
pLines->ref();
pLines->coordIndex.setNum(3);
pLines->coordIndex.setValues(0, 3, lines);
sep->addChild ( pLines );
pFont = new SoFont();
pFont->size.setValue(Size.getValue()/10.);
SoTranslation *textTranslation = new SoTranslation ();
textTranslation->ref ();
textTranslation->translation.setValue ( SbVec3f ( -size * 49. / 50., size / 30., 0 ) );
sep->addChild ( textTranslation );
pTranslation = new SoTranslation();
pTranslation->ref();
pTranslation->translation.setValue(SbVec3f(-1,0,0));
pText = new SoAsciiText();
pText->ref();
pText->width.setValue(-1);
sPixmap = "view-measurement";
sep->addChild ( getLabel () );
}
ViewProviderLine::~ViewProviderLine()
{
pcHighlight->unref();
pCoords->unref();
pLines->unref();
pMat->unref();
pTranslation->unref();
pText->unref();
}
void ViewProviderLine::onChanged(const App::Property* prop)
{
if (prop == &Size){
float size = Size.getValue(); // Note: If you change this, you need to also adapt App/Line.cpp getBoundBox()
SbVec3f verts[2] =
{
SbVec3f(-size,0,0), SbVec3f(size,0,0),
};
pCoords->point.setValues(0, 2, verts);
pFont->size.setValue(Size.getValue()/10.);
pTranslation->translation.setValue(SbVec3f(-size,0,0));
}
else
ViewProviderGeometryObject::onChanged(prop);
}
std::vector<std::string> ViewProviderLine::getDisplayModes(void) const
{
// add modes
std::vector<std::string> StrList;
StrList.push_back("Base");
return StrList;
}
void ViewProviderLine::setDisplayMode(const char* ModeName)
{
if (strcmp(ModeName, "Base") == 0)
setDisplayMaskMode("Base");
ViewProviderGeometryObject::setDisplayMode(ModeName);
}
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();
SoDrawStyle* style = new SoDrawStyle();
style->lineWidth = 2.0f;
SoMaterialBinding* matBinding = new SoMaterialBinding;
matBinding->value = SoMaterialBinding::OVERALL;
sep->addChild(matBinding);
sep->addChild(pMat);
sep->addChild(pcHighlight);
pcHighlight->addChild(style);
pcHighlight->addChild(pCoords);
pcHighlight->addChild(pLines);
style = new SoDrawStyle();
style->lineWidth = 2.0f;
style->linePattern.setValue(0xF000);
lineSep->addChild(style);
lineSep->addChild(pLines);
lineSep->addChild(pFont);
pText->string.setValue(SbString(pcObject->Label.getValue()));
lineSep->addChild(pTranslation);
lineSep->addChild(pText);
pcHighlight->addChild(lineSep);
pcHighlight->style = SoFCSelection::EMISSIVE_DIFFUSE;
addDisplayMaskMode(sep, "Base");
}
void ViewProviderLine::updateData(const App::Property* prop)
{
pText->string.setValue(SbString(pcObject->Label.getValue()));
ViewProviderGeometryObject::updateData(prop);
}
std::string ViewProviderLine::getElement(const SoDetail* detail) const
{
if (detail) {
if (detail->getTypeId() == SoLineDetail::getClassTypeId()) {
const SoLineDetail* line_detail = static_cast<const SoLineDetail*>(detail);
int edge = line_detail->getLineIndex();
if (edge == 0)
{
return std::string("Main");
}
}
}
return std::string("");
}
SoDetail* ViewProviderLine::getDetail(const char* subelement) const
{
SoLineDetail* detail = 0;
std::string subelem(subelement);
int edge = -1;
if(subelem == "Main") edge = 0;
if(edge >= 0) {
detail = new SoLineDetail();
detail->setPartIndex(edge);
}
return detail;
}
bool ViewProviderLine::isSelectable(void) const
{
return true;
}
bool ViewProviderLine::setEdit(int ModNum)
{
return true;
}
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;
}
// ----------------------------------------------------------------------------

View File

@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2012 *
* Copyright (c) Juergen Riegel (juergen.riegel@web.de) 2012 *
* Copyright (c) Alexander Golubev (Fat-Zer) <fatzer2@gmail.com> 2015 *
* *
* This file is part of the FreeCAD CAx development system. *
* *
@@ -24,64 +25,19 @@
#ifndef GUI_ViewProviderLine_H
#define GUI_ViewProviderLine_H
#include "ViewProviderGeometryObject.h"
#include <QObject>
class SoFontStyle;
class SoText2;
class SoBaseColor;
class SoTranslation;
class SoCoordinate3;
class SoIndexedLineSet;
class SoEventCallback;
class SoMaterial;
class SoAsciiText;
class SoFont;
#include "ViewProviderOriginFeature.h"
namespace Gui
{
class SoFCSelection;
class GuiExport ViewProviderLine : public ViewProviderGeometryObject
{
class GuiExport ViewProviderLine : public ViewProviderOriginFeature {
PROPERTY_HEADER(Gui::ViewProviderLine);
public:
/// Constructor
ViewProviderLine(void);
virtual ~ViewProviderLine();
App::PropertyFloat Size;
void attach(App::DocumentObject *);
void updateData(const App::Property*);
std::vector<std::string> getDisplayModes(void) const;
void setDisplayMode(const char* ModeName);
/// indicates if the ViewProvider use the new Selection model
virtual bool useNewSelectionModel(void) const {return true;}
/// indicates if the ViewProvider can be selected
virtual bool isSelectable(void) const ;
/// return a hit element to the selection path or 0
virtual std::string getElement(const SoDetail *) const;
virtual SoDetail* getDetail(const char*) const;
virtual bool setEdit(int ModNum);
virtual void unsetEdit(int ModNum);
protected:
SoFCSelection* createFromSettings() const;
void onChanged(const App::Property* prop);
private:
SoFCSelection * pcHighlight;
SoCoordinate3 * pCoords;
SoMaterial * pMat;
SoIndexedLineSet * pLines;
SoAsciiText * pText;
SoFont * pFont;
SoTranslation * pTranslation;
virtual void attach ( App::DocumentObject * );
};
} //namespace Gui

View File

@@ -0,0 +1,205 @@
/***************************************************************************
* Copyright (c) 2015 Alexander Golubev (Fat-Zer) <fatzer2@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <Inventor/nodes/SoAsciiText.h>
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/nodes/SoMaterial.h>
# include <Inventor/nodes/SoMaterialBinding.h>
# include <Inventor/nodes/SoAnnotation.h>
# include <Inventor/nodes/SoDrawStyle.h>
# include <Inventor/nodes/SoCoordinate3.h>
# include <Inventor/nodes/SoIndexedLineSet.h>
# include <Inventor/nodes/SoTranslation.h>
# include <Inventor/nodes/SoFontStyle.h>
# include <Inventor/nodes/SoScale.h>
# include <Inventor/details/SoLineDetail.h>
#endif
#include <App/Document.h>
#include "SoFCSelection.h"
#include "Window.h"
#include "ViewProviderOrigin.h"
#include "ViewProviderOriginFeature.h"
using namespace Gui;
PROPERTY_SOURCE(Gui::ViewProviderOriginFeature, Gui::ViewProviderGeometryObject)
ViewProviderOriginFeature::ViewProviderOriginFeature () {
ADD_PROPERTY_TYPE ( Size, (ViewProviderOrigin::defaultSize()), 0, App::Prop_ReadOnly,
"Visual size of the feature" );
ShapeColor.setValue ( 50./255, 150./255, 250./255 ); // Set default color for origin (light-blue)
BoundingBox.StatusBits.set (3, true) ; // Hide Boundingbox from the user due to it doesn't make sence
// Create node for scaling the origin
pScale = new SoScale ();
pScale->ref ();
// Create the separator filled by inherited classes
pOriginFeatureRoot = new SoSeparator();
pOriginFeatureRoot->ref ();
// Create the Label node
pLabel = new SoAsciiText();
pLabel->ref();
pLabel->width.setValue(-1);
sPixmap = "view-measurement";
}
ViewProviderOriginFeature::~ViewProviderOriginFeature () {
pScale->unref ();
pOriginFeatureRoot->unref ();
pLabel->unref ();
}
void ViewProviderOriginFeature::attach(App::DocumentObject* pcObject)
{
ViewProviderGeometryObject::attach(pcObject);
float defaultSz = ViewProviderOrigin::defaultSize();
float sz = Size.getValue () / defaultSz;
// Create an external separator
SoSeparator *sep = new SoSeparator();
// Add material from the base class
sep->addChild(pcShapeMaterial);
// Bind same material to all part
SoMaterialBinding* matBinding = new SoMaterialBinding;
matBinding->value = SoMaterialBinding::OVERALL;
sep->addChild(matBinding);
// Scale feature to the given size
pScale->scaleFactor = SbVec3f (sz, sz, sz);
sep->addChild (pScale);
// Setup font size
SoFont *font = new SoFont ();
font->size.setValue ( defaultSz/10.);
sep->addChild ( font );
// Create the selection node
SoFCSelection *highlight = new SoFCSelection ();
highlight->applySettings ();
if ( !Selectable.getValue() ) {
highlight->selectionMode = Gui::SoFCSelection::SEL_OFF;
}
highlight->objectName = getObject()->getNameInDocument();
highlight->documentName = getObject()->getDocument()->getName();
// highlight->subElementName = "Main";
highlight->style = SoFCSelection::EMISSIVE_DIFFUSE;
// Style for normal (visiable) lines
SoDrawStyle* style = new SoDrawStyle ();
style->lineWidth = 2.0f;
highlight->addChild ( style );
// Visible lines
highlight->addChild ( pOriginFeatureRoot );
// Hidden features
SoAnnotation *hidden = new SoAnnotation ();
// Style for hidden lines
style = new SoDrawStyle ();
style->lineWidth = 2.0f;
style->linePattern.setValue ( 0xF000 ); // (dash-skip-skip-skip)
hidden->addChild ( style );
// Hidden lines
hidden->addChild ( pOriginFeatureRoot );
highlight->addChild ( hidden );
sep->addChild ( highlight );
// Setup the object label as it's text
pLabel->string.setValue ( SbString ( pcObject->Label.getValue () ) );
addDisplayMaskMode ( sep, "Base" );
}
void ViewProviderOriginFeature::updateData ( const App::Property* prop ) {
if (prop == &getObject()->Label) {
pLabel->string.setValue ( SbString ( getObject()->Label.getValue () ) );
}
ViewProviderGeometryObject::updateData(prop);
}
void ViewProviderOriginFeature::onChanged ( const App::Property* prop ) {
if (prop == &Size) {
float sz = Size.getValue () / ViewProviderOrigin::defaultSize();
pScale->scaleFactor = SbVec3f (sz, sz, sz);
}
ViewProviderGeometryObject::onChanged(prop);
}
std::vector<std::string> ViewProviderOriginFeature::getDisplayModes () const
{
// add modes
std::vector<std::string> StrList;
StrList.push_back("Base");
return StrList;
}
void ViewProviderOriginFeature::setDisplayMode (const char* ModeName)
{
if (strcmp(ModeName, "Base") == 0)
setDisplayMaskMode("Base");
ViewProviderGeometryObject::setDisplayMode(ModeName);
}
std::string ViewProviderOriginFeature::getElement ( const SoDetail *detail ) const {
// TODO Explain what the heck here is or delete (2015-09-02, Fat-Zer)
// if (detail) {
// if (detail->getTypeId() == SoLineDetail::getClassTypeId()) {
// const SoLineDetail* line_detail = static_cast<const SoLineDetail*>(detail);
// if (line_detail->getLineIndex() == 0)
// {
// return std::string("Main");
// }
// }
// }
return std::string("");
}
SoDetail* ViewProviderOriginFeature::getDetail ( const char* subelement ) const {
// TODO Explain what the heck here is or delete (2015-09-02, Fat-Zer)
// if ( strcmp(subelement, "Main") == 0 ) {
// SoLineDetail* detail = new SoLineDetail();
// detail->setPartIndex( 0 );
// return detail;
// }
return 0;
}

View File

@@ -0,0 +1,84 @@
/***************************************************************************
* Copyright (c) 2015 Alexander Golubev (Fat-Zer) <fatzer2@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef VIEWPROVIDEORIGINFEATURE_H_BYJRZNDL
#define VIEWPROVIDEORIGINFEATURE_H_BYJRZNDL
#include "ViewProviderGeometryObject.h"
class SoAsciiText;
class SoScale;
namespace Gui
{
/**
* View provider associated with an App::OriginFeature.
*/
class ViewProviderOriginFeature: public ViewProviderGeometryObject {
PROPERTY_HEADER(Gui::ViewProviderOriginFeature);
public:
/// The display size of the feature
App::PropertyFloat Size;
ViewProviderOriginFeature ();
virtual ~ViewProviderOriginFeature ();
/// Get point derived classes will add their specific stuff
SoSeparator * getOriginFeatureRoot () { return pOriginFeatureRoot; }
/// Get pointer to the text label associated with the feature
SoAsciiText * getLabel () { return pLabel; }
/// indicates if the ViewProvider use the new Selection model
virtual bool useNewSelectionModel () const
{ return true; }
virtual void attach(App::DocumentObject *);
virtual void updateData(const App::Property *);
virtual std::vector<std::string> getDisplayModes() const;
virtual void setDisplayMode(const char *ModeName);
/// return a hit element to the selection path or 0
virtual std::string getElement ( const SoDetail *detail ) const;
virtual SoDetail* getDetail ( const char *subelement ) const;
/// @name Suppress ViewProviderGeometryObject's behaviour
///@{
virtual bool setEdit ( int )
{ return false; }
virtual void unsetEdit ( int )
{ }
///@}
protected:
virtual void onChanged ( const App::Property* prop );
protected:
SoSeparator * pOriginFeatureRoot;
SoScale * pScale;
SoAsciiText * pLabel;
};
} /* Gui */
#endif /* end of include guard: VIEWPROVIDEORIGINFEATURE_H_BYJRZNDL */

View File

@@ -37,6 +37,7 @@
#include "View3DInventor.h"
#include "View3DInventorViewer.h"
#include "ViewProviderOrigin.h"
#include "ViewProviderOriginFeature.h"
#include "ViewProviderOriginGroup.h"

View File

@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright (c) Juergen Riegel (juergen.riegel@web.de) 2012 *
* Copyright (c) Alexander Golubev (Fat-Zer) <fatzer2@gmail.com> 2015 *
* *
* This file is part of the FreeCAD CAx development system. *
* *
@@ -24,268 +25,58 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <sstream>
# include <QApplication>
# include <Inventor/SoPickedPoint.h>
# include <Inventor/events/SoMouseButtonEvent.h>
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/nodes/SoBaseColor.h>
# include <Inventor/nodes/SoFontStyle.h>
# include <Inventor/nodes/SoPickStyle.h>
# include <Inventor/nodes/SoText2.h>
# include <Inventor/nodes/SoTranslation.h>
# include <Inventor/nodes/SoAsciiText.h>
# include <Inventor/nodes/SoCoordinate3.h>
# include <Inventor/nodes/SoFont.h>
# include <Inventor/nodes/SoIndexedLineSet.h>
# include <Inventor/nodes/SoMarkerSet.h>
# include <Inventor/nodes/SoDrawStyle.h>
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/nodes/SoTranslation.h>
#endif
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoAnnotation.h>
#include <Inventor/details/SoLineDetail.h>
#include <Inventor/nodes/SoAsciiText.h>
#include "ViewProviderPlane.h"
#include "SoFCSelection.h"
#include "Application.h"
#include "Document.h"
#include "View3DInventorViewer.h"
#include "Inventor/SoAutoZoomTranslation.h"
#include "SoAxisCrossKit.h"
#include "Window.h"
//#include <SoDepthBuffer.h>
#include "ViewProviderOrigin.h"
#include <App/PropertyGeo.h>
#include <App/PropertyStandard.h>
#include <App/MeasureDistance.h>
#include <Base/Console.h>
#include "ViewProviderPlane.h"
using namespace Gui;
PROPERTY_SOURCE(Gui::ViewProviderPlane, Gui::ViewProviderGeometryObject)
PROPERTY_SOURCE(Gui::ViewProviderPlane, Gui::ViewProviderOriginFeature)
ViewProviderPlane::ViewProviderPlane()
{
{ }
ADD_PROPERTY(Size,(1.0));
ViewProviderPlane::~ViewProviderPlane()
{ }
pMat = new SoMaterial();
pMat->ref();
void ViewProviderPlane::attach ( App::DocumentObject *obj ) {
ViewProviderOriginFeature::attach ( obj );
static const float size = ViewProviderOrigin::defaultSize ();
float size = Size.getValue(); // Note: If you change this, you need to also adapt App/Plane.cpp getBoundBox()
SbVec3f verts[4] =
{
SbVec3f(size,size,0), SbVec3f(size,-size,0),
static const SbVec3f verts[4] = {
SbVec3f(size,size,0), SbVec3f(size,-size,0),
SbVec3f(-size,-size,0), SbVec3f(-size,size,0),
};
// indexes used to create the edges
static const int32_t lines[6] =
{
0,1,2,3,0,-1
};
static const int32_t lines[6] = { 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);
SoSeparator *sep = getOriginFeatureRoot ();
SoCoordinate3 *pCoords = new SoCoordinate3 ();
pCoords->point.setNum (4);
pCoords->point.setValues ( 0, 4, verts );
sep->addChild ( pCoords );
pMat->diffuseColor.setNum(1);
pMat->diffuseColor.set1Value(0, SbColor(50./255., 150./255., 250./255.));
pCoords = new SoCoordinate3();
pCoords->ref();
pCoords->point.setNum(4);
pCoords->point.setValues(0, 4, verts);
pLines = new SoIndexedLineSet();
SoIndexedLineSet *pLines = new SoIndexedLineSet ();
pLines->ref();
pLines->coordIndex.setNum(6);
pLines->coordIndex.setValues(0, 6, lines);
sep->addChild ( pLines );
pFont = new SoFont();
pFont->size.setValue(Size.getValue()/10.);
SoTranslation *textTranslation = new SoTranslation ();
textTranslation->ref ();
textTranslation->translation.setValue ( SbVec3f ( -size * 49. / 50., size * 9./10., 0 ) );
sep->addChild ( textTranslation );
pTranslation = new SoTranslation();
pTranslation->translation.setValue(SbVec3f(-1,9./10.,0));
pText = new SoAsciiText();
pText->width.setValue(-1);
sPixmap = "view-measurement";
sep->addChild ( getLabel () );
}
ViewProviderPlane::~ViewProviderPlane()
{
pcHighlight->unref();
pCoords->unref();
pLines->unref();
pMat->unref();
}
void ViewProviderPlane::onChanged(const App::Property* prop)
{
if (prop == &Size){
float size = Size.getValue(); // Note: If you change this, you need to also adapt App/Plane.cpp getBoundBox()
SbVec3f verts[4] =
{
SbVec3f(size,size,0), SbVec3f(size,-size,0),
SbVec3f(-size,-size,0), SbVec3f(-size,size,0),
};
pCoords->point.setValues(0, 4, verts);
pFont->size.setValue(Size.getValue()/10.);
pTranslation->translation.setValue(SbVec3f(-size,size*9./10.,0));
}
else
ViewProviderGeometryObject::onChanged(prop);
}
std::vector<std::string> ViewProviderPlane::getDisplayModes(void) const
{
// add modes
std::vector<std::string> StrList;
StrList.push_back("Base");
return StrList;
}
void ViewProviderPlane::setDisplayMode(const char* ModeName)
{
if (strcmp(ModeName, "Base") == 0)
setDisplayMaskMode("Base");
ViewProviderGeometryObject::setDisplayMode(ModeName);
}
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();
SoDrawStyle* style = new SoDrawStyle();
style->lineWidth = 2.0f;
SoMaterialBinding* matBinding = new SoMaterialBinding;
matBinding->value = SoMaterialBinding::OVERALL;
sep->addChild(matBinding);
sep->addChild(pMat);
sep->addChild(pcHighlight);
pcHighlight->addChild(style);
pcHighlight->addChild(pCoords);
pcHighlight->addChild(pLines);
style = new SoDrawStyle();
style->lineWidth = 2.0f;
style->linePattern.setValue(0xF000);
lineSep->addChild(style);
lineSep->addChild(pLines);
lineSep->addChild(pFont);
pText->string.setValue(SbString(pcObject->Label.getValue()));
lineSep->addChild(pTranslation);
lineSep->addChild(pText);
pcHighlight->addChild(lineSep);
pcHighlight->style = SoFCSelection::EMISSIVE_DIFFUSE;
addDisplayMaskMode(sep, "Base");
}
void ViewProviderPlane::updateData(const App::Property* prop)
{
pText->string.setValue(SbString(pcObject->Label.getValue()));
ViewProviderGeometryObject::updateData(prop);
}
std::string ViewProviderPlane::getElement(const SoDetail* detail) const
{
if (detail) {
if (detail->getTypeId() == SoLineDetail::getClassTypeId()) {
const SoLineDetail* line_detail = static_cast<const SoLineDetail*>(detail);
int edge = line_detail->getLineIndex();
if (edge == 0)
{
return std::string("Main");
}
}
}
return std::string("");
}
SoDetail* ViewProviderPlane::getDetail(const char* subelement) const
{
SoLineDetail* detail = 0;
std::string subelem(subelement);
int edge = -1;
if(subelem == "Main") edge = 0;
if(edge >= 0) {
detail = new SoLineDetail();
detail->setPartIndex(edge);
}
return detail;
}
bool ViewProviderPlane::isSelectable(void) const
{
return true;
}
bool ViewProviderPlane::setEdit(int ModNum)
{
return true;
}
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;
}
// ----------------------------------------------------------------------------

View File

@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2012 *
* Copyright (c) Alexander Golubev (Fat-Zer) <fatzer2@gmail.com> 2015 *
* *
* This file is part of the FreeCAD CAx development system. *
* *
@@ -24,65 +25,20 @@
#ifndef GUI_ViewProviderPlane_H
#define GUI_ViewProviderPlane_H
#include "ViewProviderGeometryObject.h"
#include <QObject>
#include "ViewProviderOriginFeature.h"
class SoFontStyle;
class SoText2;
class SoBaseColor;
class SoTranslation;
class SoCoordinate3;
class SoIndexedLineSet;
class SoEventCallback;
class SoMaterial;
class SoAsciiText;
class SoFont;
namespace Gui
namespace Gui
{
class SoFCSelection;
class GuiExport ViewProviderPlane : public ViewProviderGeometryObject
class GuiExport ViewProviderPlane : public ViewProviderOriginFeature
{
PROPERTY_HEADER(Gui::ViewProviderPlane);
public:
/// Constructor
ViewProviderPlane(void);
virtual ~ViewProviderPlane();
App::PropertyFloat Size;
void attach(App::DocumentObject *);
void updateData(const App::Property*);
std::vector<std::string> getDisplayModes(void) const;
void setDisplayMode(const char* ModeName);
/// indicates if the ViewProvider use the new Selection model
virtual bool useNewSelectionModel(void) const {return true;}
/// indicates if the ViewProvider can be selected
virtual bool isSelectable(void) const ;
/// return a hit element to the selection path or 0
virtual std::string getElement(const SoDetail *) const;
virtual SoDetail* getDetail(const char*) const;
virtual bool setEdit(int ModNum);
virtual void unsetEdit(int ModNum);
protected:
SoFCSelection* createFromSettings() const;
void onChanged(const App::Property* prop);
private:
SoFCSelection * pcHighlight;
SoCoordinate3 * pCoords;
SoMaterial * pMat;
SoIndexedLineSet * pLines;
SoAsciiText * pText;
SoFont * pFont;
SoTranslation * pTranslation;
virtual void attach ( App::DocumentObject * );
};
} //namespace Gui