Gui: Placement/DatumCS view provider changes
* Add always zoom invariant and always on top rendering to ViewProviderDatumCS * Add a new utility class AxisOrigin for more efficient axis rendering. Also exposed to python. * Change ViewProviderPlacement to use AxisOrigin for rendering. A single instance of AxisOrigin is shared by all ViewProviderPlacement. Selection context is used to distinguish among different instances.
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <Inventor/nodes/SoAsciiText.h>
|
||||
# include <Inventor/nodes/SoText2.h>
|
||||
# include <Inventor/nodes/SoCoordinate3.h>
|
||||
# include <Inventor/nodes/SoDrawStyle.h>
|
||||
# include <Inventor/nodes/SoFont.h>
|
||||
@@ -32,8 +32,12 @@
|
||||
# include <Inventor/nodes/SoRotation.h>
|
||||
# include <Inventor/nodes/SoSeparator.h>
|
||||
# include <Inventor/nodes/SoTranslation.h>
|
||||
# include <Inventor/nodes/SoSwitch.h>
|
||||
# include <Inventor/details/SoLineDetail.h>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <Gui/Inventor/SoAutoZoomTranslation.h>
|
||||
#include "TaskDatumParameters.h"
|
||||
#include <Mod/Part/Gui/SoBrepEdgeSet.h>
|
||||
|
||||
@@ -43,13 +47,33 @@ using namespace PartDesignGui;
|
||||
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderDatumCoordinateSystem,PartDesignGui::ViewProviderDatum)
|
||||
|
||||
const App::PropertyFloatConstraint::Constraints ZoomConstraint = {0.0,DBL_MAX,0.2};
|
||||
const App::PropertyIntegerConstraint::Constraints FontConstraint = {1,INT_MAX,1};
|
||||
|
||||
ViewProviderDatumCoordinateSystem::ViewProviderDatumCoordinateSystem()
|
||||
{
|
||||
Zoom.setConstraints(&ZoomConstraint);
|
||||
FontSize.setConstraints(&FontConstraint);
|
||||
|
||||
auto hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Mod/PartDesign");
|
||||
auto fontSize = hGrp->GetInt("CoordinateSystemFontSize",10);
|
||||
auto zoom = hGrp->GetFloat("CoordinateSystemZoom",1.0);
|
||||
auto showLabel = hGrp->GetBool("CoordinateSystemShowLabel",false);
|
||||
|
||||
ADD_PROPERTY_TYPE(FontSize, (fontSize), "Datum", App::Prop_None, "");
|
||||
ADD_PROPERTY_TYPE(Zoom, (zoom), "Datum", App::Prop_None, "");
|
||||
ADD_PROPERTY_TYPE(ShowLabel, (showLabel), "Datum", App::Prop_None, "");
|
||||
|
||||
if(hGrp->GetBool("CoordinateSystemSelectOnTop",true))
|
||||
OnTopWhenSelected.setValue(1);
|
||||
|
||||
sPixmap = "PartDesign_CoordinateSystem.svg";
|
||||
|
||||
coord = new SoCoordinate3();
|
||||
coord->ref();
|
||||
font = new SoFont();
|
||||
font->size = FontSize.getValue();
|
||||
font->ref();
|
||||
axisLabelXTrans = new SoTranslation();
|
||||
axisLabelXTrans->ref();
|
||||
@@ -57,6 +81,11 @@ ViewProviderDatumCoordinateSystem::ViewProviderDatumCoordinateSystem()
|
||||
axisLabelXToYTrans->ref();
|
||||
axisLabelYToZTrans = new SoTranslation();
|
||||
axisLabelYToZTrans->ref();
|
||||
|
||||
autoZoom = new Gui::SoAutoZoomTranslation;
|
||||
autoZoom->ref();
|
||||
|
||||
labelSwitch = 0;
|
||||
}
|
||||
|
||||
ViewProviderDatumCoordinateSystem::~ViewProviderDatumCoordinateSystem()
|
||||
@@ -66,6 +95,9 @@ ViewProviderDatumCoordinateSystem::~ViewProviderDatumCoordinateSystem()
|
||||
axisLabelXTrans->unref();
|
||||
axisLabelXToYTrans->unref();
|
||||
axisLabelYToZTrans->unref();
|
||||
if(labelSwitch)
|
||||
labelSwitch->unref();
|
||||
autoZoom->unref();
|
||||
}
|
||||
|
||||
void ViewProviderDatumCoordinateSystem::attach ( App::DocumentObject *obj ) {
|
||||
@@ -75,11 +107,13 @@ void ViewProviderDatumCoordinateSystem::attach ( App::DocumentObject *obj ) {
|
||||
material->diffuseColor.setNum(4);
|
||||
material->diffuseColor.set1Value(0, SbColor(0.f, 0.f, 0.f));
|
||||
material->diffuseColor.set1Value(1, SbColor(1.f, 0.f, 0.f));
|
||||
material->diffuseColor.set1Value(2, SbColor(0.f, 1.f, 0.f));
|
||||
material->diffuseColor.set1Value(2, SbColor(0.f, 0.6f, 0.f));
|
||||
material->diffuseColor.set1Value(3, SbColor(0.f, 0.f, 1.f));
|
||||
SoMaterialBinding* binding = new SoMaterialBinding();
|
||||
binding->value = SoMaterialBinding::PER_FACE_INDEXED;
|
||||
|
||||
autoZoom->scaleFactor.setValue(Zoom.getValue());
|
||||
getShapeRoot ()->addChild(autoZoom);
|
||||
getShapeRoot ()->addChild(binding);
|
||||
getShapeRoot ()->addChild(material);
|
||||
|
||||
@@ -114,55 +148,126 @@ void ViewProviderDatumCoordinateSystem::attach ( App::DocumentObject *obj ) {
|
||||
lineSet->materialIndex.set1Value(2,3);
|
||||
getShapeRoot ()->addChild(lineSet);
|
||||
|
||||
getShapeRoot ()->addChild(font);
|
||||
setupLabels();
|
||||
}
|
||||
|
||||
void ViewProviderDatumCoordinateSystem::setupLabels() {
|
||||
|
||||
if(!ShowLabel.getValue()) {
|
||||
if(labelSwitch)
|
||||
labelSwitch->whichChild = -1;
|
||||
return;
|
||||
}else if(labelSwitch) {
|
||||
labelSwitch->whichChild = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
labelSwitch = new SoSwitch;
|
||||
labelSwitch->ref();
|
||||
|
||||
getShapeRoot ()->addChild(labelSwitch);
|
||||
|
||||
SoGroup *labelGroup = new SoGroup;
|
||||
labelSwitch->addChild(labelGroup);
|
||||
labelSwitch->whichChild = 0;
|
||||
|
||||
labelGroup->addChild(font);
|
||||
|
||||
// Transformation for axis labels are relative so no need in separators
|
||||
getShapeRoot ()->addChild(axisLabelXTrans);
|
||||
SoAsciiText* t = new SoAsciiText();
|
||||
labelGroup->addChild(axisLabelXTrans);
|
||||
auto* t = new SoText2();
|
||||
t->string = "X";
|
||||
getShapeRoot ()->addChild(t);
|
||||
labelGroup->addChild(t);
|
||||
|
||||
getShapeRoot ()->addChild(axisLabelXToYTrans);
|
||||
t = new SoAsciiText();
|
||||
labelGroup->addChild(axisLabelXToYTrans);
|
||||
t = new SoText2();
|
||||
t->string = "Y";
|
||||
getShapeRoot ()->addChild(t);
|
||||
labelGroup->addChild(t);
|
||||
|
||||
getShapeRoot ()->addChild(axisLabelYToZTrans);
|
||||
SoRotation *rot = new SoRotation();
|
||||
rot->rotation = SbRotation(SbVec3f(1,1,1), static_cast<float>(2*M_PI/3));
|
||||
getShapeRoot ()->addChild(rot);
|
||||
t = new SoAsciiText();
|
||||
labelGroup->addChild(axisLabelYToZTrans);
|
||||
t = new SoText2();
|
||||
t->string = "Z";
|
||||
getShapeRoot ()->addChild(t);
|
||||
labelGroup->addChild(t);
|
||||
}
|
||||
|
||||
void ViewProviderDatumCoordinateSystem::updateData(const App::Property* prop)
|
||||
{
|
||||
if (strcmp(prop->getName(),"Placement") == 0) {
|
||||
if (strcmp(prop->getName(),"Placement") == 0)
|
||||
updateExtents ();
|
||||
}
|
||||
|
||||
ViewProviderDatum::updateData(prop);
|
||||
}
|
||||
|
||||
void ViewProviderDatumCoordinateSystem::onChanged(const App::Property *prop) {
|
||||
if(getObject()) {
|
||||
if(prop == &ShowLabel)
|
||||
setupLabels();
|
||||
else if(prop == &Zoom) {
|
||||
autoZoom->scaleFactor.setValue(Zoom.getValue());
|
||||
updateExtents ();
|
||||
} else if(prop == &FontSize)
|
||||
font->size = FontSize.getValue();
|
||||
}
|
||||
ViewProviderDatum::onChanged(prop);
|
||||
}
|
||||
|
||||
void ViewProviderDatumCoordinateSystem::setExtents (Base::BoundBox3d bbox) {
|
||||
// Axis length of the CS is 1/3 of maximum bbox dimension, any smarter sizing will make it only worse
|
||||
double axisLength = std::max ( { bbox.LengthX (), bbox.LengthY(), bbox.LengthZ() } );
|
||||
axisLength *= (1 + marginFactor ()) / 3;
|
||||
double axisLength;
|
||||
|
||||
if(Zoom.getValue()) {
|
||||
axisLength = 6 * Zoom.getValue();
|
||||
}else{
|
||||
axisLength = std::max ( { bbox.LengthX (), bbox.LengthY(), bbox.LengthZ() } );
|
||||
axisLength *= (1 + marginFactor ()) / 3;
|
||||
}
|
||||
|
||||
coord->point.set1Value ( 0, 0, 0, 0 );
|
||||
coord->point.set1Value ( 1, axisLength, 0, 0 );
|
||||
coord->point.set1Value ( 2, 0, axisLength, 0 );
|
||||
coord->point.set1Value ( 3, 0, 0, axisLength );
|
||||
|
||||
double fontSz = axisLength / 10.;
|
||||
font->size = fontSz;
|
||||
|
||||
double labelPos = 9./10.*axisLength;
|
||||
double labelOffset = fontSz/8.;
|
||||
double labelPos = axisLength;
|
||||
double labelOffset = 0;
|
||||
|
||||
// offset 1 pixel
|
||||
axisLabelXTrans->translation.setValue ( SbVec3f( labelPos, labelOffset, 0) );
|
||||
axisLabelXToYTrans->translation.setValue ( SbVec3f( -labelPos + labelOffset, labelPos - labelOffset, 0) );
|
||||
axisLabelYToZTrans->translation.setValue ( SbVec3f( -labelOffset, -labelPos + labelOffset, labelPos) );
|
||||
}
|
||||
|
||||
std::string ViewProviderDatumCoordinateSystem::getElement(const SoDetail* detail) const
|
||||
{
|
||||
if (detail && detail->getTypeId() == SoLineDetail::getClassTypeId()) {
|
||||
const SoLineDetail* line_detail = static_cast<const SoLineDetail*>(detail);
|
||||
switch(line_detail->getLineIndex()) {
|
||||
case 0:
|
||||
return "X";
|
||||
case 1:
|
||||
return "Y";
|
||||
case 2:
|
||||
return "Z";
|
||||
}
|
||||
}
|
||||
|
||||
return std::string();
|
||||
}
|
||||
|
||||
SoDetail* ViewProviderDatumCoordinateSystem::getDetail(const char* subelement) const
|
||||
{
|
||||
if (strcmp(subelement,"X")==0) {
|
||||
SoLineDetail* detail = new SoLineDetail();
|
||||
detail->setLineIndex(0);
|
||||
return detail;
|
||||
} else if (strcmp(subelement,"Y")==0) {
|
||||
SoLineDetail* detail = new SoLineDetail();
|
||||
detail->setLineIndex(1);
|
||||
return detail;
|
||||
} else if (strcmp(subelement,"Z")==0) {
|
||||
SoLineDetail* detail = new SoLineDetail();
|
||||
detail->setLineIndex(2);
|
||||
return detail;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,10 @@
|
||||
class SoFont;
|
||||
class SoTranslation;
|
||||
|
||||
namespace Gui {
|
||||
class SoAutoZoomTranslation;
|
||||
}
|
||||
|
||||
namespace PartDesignGui {
|
||||
|
||||
class PartDesignGuiExport ViewProviderDatumCoordinateSystem : public PartDesignGui::ViewProviderDatum
|
||||
@@ -37,20 +41,34 @@ class PartDesignGuiExport ViewProviderDatumCoordinateSystem : public PartDesignG
|
||||
PROPERTY_HEADER(PartDesignGui::ViewProviderDatumCoordinateSystem);
|
||||
|
||||
public:
|
||||
App::PropertyFloatConstraint Zoom;
|
||||
App::PropertyIntegerConstraint FontSize;
|
||||
App::PropertyBool ShowLabel;
|
||||
|
||||
/// Constructor
|
||||
ViewProviderDatumCoordinateSystem();
|
||||
virtual ~ViewProviderDatumCoordinateSystem();
|
||||
|
||||
virtual void attach ( App::DocumentObject *obj );
|
||||
virtual void updateData(const App::Property*);
|
||||
virtual void onChanged(const App::Property*);
|
||||
|
||||
virtual void setExtents (Base::BoundBox3d bbox);
|
||||
|
||||
virtual SoDetail* getDetail(const char* subelement) const;
|
||||
virtual std::string getElement(const SoDetail* detail) const;
|
||||
|
||||
private:
|
||||
void setupLabels();
|
||||
|
||||
private:
|
||||
SoCoordinate3 *coord;
|
||||
SoTranslation *axisLabelXTrans;
|
||||
SoTranslation *axisLabelXToYTrans;
|
||||
SoTranslation *axisLabelYToZTrans;
|
||||
SoFont* font;
|
||||
SoSwitch *labelSwitch;
|
||||
Gui::SoAutoZoomTranslation *autoZoom;
|
||||
};
|
||||
|
||||
} // namespace PartDesignGui
|
||||
|
||||
Reference in New Issue
Block a user