Core: Add App::LocalCoordinateSystem.
Most of App::Origin is moved into this sub class of App::Origin. Add App::Point. Change graphics of the planes/axis. Remove scale-by-content behavior and make it fixed size on screen.
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <Inventor/nodes/SoText2.h>
|
||||
# include <Inventor/nodes/SoAsciiText.h>
|
||||
# include <Inventor/nodes/SoCoordinate3.h>
|
||||
# include <Inventor/nodes/SoFaceSet.h>
|
||||
@@ -36,6 +37,9 @@
|
||||
# include <Inventor/SbColor.h>
|
||||
#endif
|
||||
|
||||
#include <App/Datums.h>
|
||||
#include <Gui/ViewParams.h>
|
||||
|
||||
#include "ViewProviderPlane.h"
|
||||
#include "ViewProviderOrigin.h"
|
||||
|
||||
@@ -48,43 +52,85 @@ PROPERTY_SOURCE(Gui::ViewProviderPlane, Gui::ViewProviderDatum)
|
||||
ViewProviderPlane::ViewProviderPlane()
|
||||
{
|
||||
sPixmap = "Std_Plane";
|
||||
lineThickness = 1.0;
|
||||
}
|
||||
|
||||
ViewProviderPlane::~ViewProviderPlane() = default;
|
||||
|
||||
void ViewProviderPlane::attach(App::DocumentObject * obj) {
|
||||
ViewProviderDatum::attach(obj);
|
||||
static const float size = ViewProviderOrigin::defaultSize ();
|
||||
|
||||
static const SbVec3f verts[4] = {
|
||||
SbVec3f(size,size,0), SbVec3f(size,-size,0),
|
||||
SbVec3f(-size,-size,0), SbVec3f(-size,size,0),
|
||||
};
|
||||
const char* name = pcObject->getNameInDocument();
|
||||
|
||||
// Setup colors
|
||||
auto material = new SoMaterial();
|
||||
SbColor color;
|
||||
material->transparency.setValue(0.95f);
|
||||
float alpha = 0.0f;
|
||||
float lineTransparency = 0.5;
|
||||
bool noRole = false;
|
||||
auto planesRoles = App::LocalCoordinateSystem::PlaneRoles;
|
||||
if (strncmp(name, planesRoles[0], strlen(planesRoles[0])) == 0) {
|
||||
// XY-axis: blue
|
||||
ShapeAppearance.setDiffuseColor(ViewParams::instance()->getAxisZColor());
|
||||
ShapeAppearance.setTransparency(lineTransparency);
|
||||
color.setPackedValue(ViewParams::instance()->getAxisZColor(), alpha);
|
||||
}
|
||||
else if (strncmp(name, planesRoles[1], strlen(planesRoles[1])) == 0) {
|
||||
// XZ-axis: green
|
||||
ShapeAppearance.setDiffuseColor(ViewParams::instance()->getAxisYColor());
|
||||
ShapeAppearance.setTransparency(lineTransparency);
|
||||
color.setPackedValue(ViewParams::instance()->getAxisYColor(), alpha);
|
||||
}
|
||||
else if (strncmp(name, planesRoles[2], strlen(planesRoles[2])) == 0) {
|
||||
// YZ-axis: red
|
||||
ShapeAppearance.setDiffuseColor(ViewParams::instance()->getAxisXColor());
|
||||
ShapeAppearance.setTransparency(lineTransparency);
|
||||
color.setPackedValue(ViewParams::instance()->getAxisXColor(), alpha);
|
||||
}
|
||||
else {
|
||||
noRole = true;
|
||||
}
|
||||
|
||||
static const float size = ViewProviderOrigin::defaultSize() * 0.6; //NOLINT
|
||||
static const float startSize = 0.25 * size; //NOLINT
|
||||
|
||||
|
||||
SbVec3f verts[4];
|
||||
if (noRole) {
|
||||
verts[0] = SbVec3f(size, size, 0);
|
||||
verts[1] = SbVec3f(size, -size, 0);
|
||||
verts[2] = SbVec3f(-size, -size, 0);
|
||||
verts[3] = SbVec3f(-size, size, 0);
|
||||
}
|
||||
else {
|
||||
verts[0] = SbVec3f(size, size, 0);
|
||||
verts[1] = SbVec3f(size, startSize, 0);
|
||||
verts[2] = SbVec3f(startSize, startSize, 0);
|
||||
verts[3] = SbVec3f(startSize, size, 0);
|
||||
}
|
||||
|
||||
|
||||
// indexes used to create the edges
|
||||
static const int32_t lines[6] = { 0, 1, 2, 3, 0, -1 };
|
||||
|
||||
SoSeparator *sep = getOriginFeatureRoot ();
|
||||
SoSeparator* sep = getRoot();
|
||||
|
||||
auto pCoords = new SoCoordinate3 ();
|
||||
pCoords->point.setNum (4);
|
||||
pCoords->point.setValues ( 0, 4, verts );
|
||||
sep->addChild ( pCoords );
|
||||
auto pCoords = new SoCoordinate3();
|
||||
pCoords->point.setNum(4);
|
||||
pCoords->point.setValues(0, 4, verts);
|
||||
sep->addChild(pCoords);
|
||||
|
||||
auto pLines = new SoIndexedLineSet ();
|
||||
auto pLines = new SoIndexedLineSet();
|
||||
pLines->coordIndex.setNum(6);
|
||||
pLines->coordIndex.setValues(0, 6, lines);
|
||||
sep->addChild ( pLines );
|
||||
sep->addChild(pLines);
|
||||
|
||||
// add semi transparent face
|
||||
auto faceSeparator = new SoSeparator();
|
||||
sep->addChild(faceSeparator);
|
||||
|
||||
auto material = new SoMaterial();
|
||||
material->transparency.setValue(0.95f);
|
||||
SbColor color;
|
||||
float alpha = 0.0f;
|
||||
color.setPackedValue(ViewProviderOrigin::defaultColor, alpha);
|
||||
|
||||
material->ambientColor.setValue(color);
|
||||
material->diffuseColor.setValue(color);
|
||||
faceSeparator->addChild(material);
|
||||
@@ -95,9 +141,8 @@ void ViewProviderPlane::attach(App::DocumentObject * obj) {
|
||||
shapeHints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
|
||||
faceSeparator->addChild(shapeHints);
|
||||
|
||||
// disable picking
|
||||
auto pickStyle = new SoPickStyle();
|
||||
pickStyle->style = SoPickStyle::UNPICKABLE;
|
||||
pickStyle->style = SoPickStyle::SHAPE_ON_TOP;
|
||||
faceSeparator->addChild(pickStyle);
|
||||
|
||||
auto faceSet = new SoFaceSet();
|
||||
@@ -106,13 +151,9 @@ void ViewProviderPlane::attach(App::DocumentObject * obj) {
|
||||
faceSet->vertexProperty.setValue(vertexProperty);
|
||||
faceSeparator->addChild(faceSet);
|
||||
|
||||
auto textTranslation = new SoTranslation ();
|
||||
textTranslation->translation.setValue ( SbVec3f ( -size * 49. / 50., size * 9./10., 0 ) );
|
||||
sep->addChild ( textTranslation );
|
||||
|
||||
auto ps = new SoPickStyle();
|
||||
ps->style.setValue(SoPickStyle::BOUNDING_BOX);
|
||||
sep->addChild(ps);
|
||||
|
||||
sep->addChild ( getLabel () );
|
||||
sep->addChild(getLabel());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user