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 e8e4f31b14
commit 9753f27064
9 changed files with 362 additions and 577 deletions

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;
}