diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 36aa9f9c92..7e60e9e982 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -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(); diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 386b664d44..34bc3b75bc 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -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 diff --git a/src/Gui/ViewProviderLine.cpp b/src/Gui/ViewProviderLine.cpp index 7e9276a3a5..cebaed04cc 100644 --- a/src/Gui/ViewProviderLine.cpp +++ b/src/Gui/ViewProviderLine.cpp @@ -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) 2015 * * * * This file is part of the FreeCAD CAx development system. * * * @@ -24,269 +25,56 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +# include # include +# include # include -# include -# include +# include +# include #endif -#include -#include -#include -#include -#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 +#include "ViewProviderOrigin.h" -#include -#include -#include -#include +#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 ViewProviderLine::getDisplayModes(void) const -{ - // add modes - std::vector 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(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; -} - -// ---------------------------------------------------------------------------- - - diff --git a/src/Gui/ViewProviderLine.h b/src/Gui/ViewProviderLine.h index db86670c6b..b7fc8a86ac 100644 --- a/src/Gui/ViewProviderLine.h +++ b/src/Gui/ViewProviderLine.h @@ -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) 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 - -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 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 diff --git a/src/Gui/ViewProviderOriginFeature.cpp b/src/Gui/ViewProviderOriginFeature.cpp new file mode 100644 index 0000000000..364d2807aa --- /dev/null +++ b/src/Gui/ViewProviderOriginFeature.cpp @@ -0,0 +1,205 @@ +/*************************************************************************** + * Copyright (c) 2015 Alexander Golubev (Fat-Zer) * + * * + * 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 +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include + +#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 ViewProviderOriginFeature::getDisplayModes () const +{ + // add modes + std::vector 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(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; +} diff --git a/src/Gui/ViewProviderOriginFeature.h b/src/Gui/ViewProviderOriginFeature.h new file mode 100644 index 0000000000..e0b9582168 --- /dev/null +++ b/src/Gui/ViewProviderOriginFeature.h @@ -0,0 +1,84 @@ +/*************************************************************************** + * Copyright (c) 2015 Alexander Golubev (Fat-Zer) * + * * + * 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 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 */ diff --git a/src/Gui/ViewProviderOriginGroup.cpp b/src/Gui/ViewProviderOriginGroup.cpp index b70c889c2c..c69463c56b 100644 --- a/src/Gui/ViewProviderOriginGroup.cpp +++ b/src/Gui/ViewProviderOriginGroup.cpp @@ -37,6 +37,7 @@ #include "View3DInventor.h" #include "View3DInventorViewer.h" #include "ViewProviderOrigin.h" +#include "ViewProviderOriginFeature.h" #include "ViewProviderOriginGroup.h" diff --git a/src/Gui/ViewProviderPlane.cpp b/src/Gui/ViewProviderPlane.cpp index e78583e7db..3805e4f8b1 100644 --- a/src/Gui/ViewProviderPlane.cpp +++ b/src/Gui/ViewProviderPlane.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (c) Juergen Riegel (juergen.riegel@web.de) 2012 * + * Copyright (c) Alexander Golubev (Fat-Zer) 2015 * * * * This file is part of the FreeCAD CAx development system. * * * @@ -24,268 +25,58 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +# include # include +# include # include -# include -# include +# include +# include #endif -#include -#include -#include -#include -#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 +#include "ViewProviderOrigin.h" -#include -#include -#include -#include +#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 ViewProviderPlane::getDisplayModes(void) const -{ - // add modes - std::vector 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(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; -} - -// ---------------------------------------------------------------------------- - - diff --git a/src/Gui/ViewProviderPlane.h b/src/Gui/ViewProviderPlane.h index 6f43c21439..378a06dc5c 100644 --- a/src/Gui/ViewProviderPlane.h +++ b/src/Gui/ViewProviderPlane.h @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2012 * + * Copyright (c) Alexander Golubev (Fat-Zer) 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 +#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 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