Core datums: Rework to improve new sketch
This commit is contained in:
committed by
Max Wilfinger
parent
7083362acb
commit
e977eb49e3
@@ -24,7 +24,6 @@
|
||||
#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>
|
||||
@@ -34,6 +33,7 @@
|
||||
# include <Inventor/nodes/SoSeparator.h>
|
||||
# include <Inventor/nodes/SoShapeHints.h>
|
||||
# include <Inventor/nodes/SoTranslation.h>
|
||||
# include <Inventor/nodes/SoSwitch.h>
|
||||
# include <Inventor/SbColor.h>
|
||||
#endif
|
||||
|
||||
@@ -53,6 +53,8 @@ ViewProviderPlane::ViewProviderPlane()
|
||||
{
|
||||
sPixmap = "Std_Plane";
|
||||
lineThickness = 1.0;
|
||||
|
||||
pLabel = new SoAsciiText();
|
||||
}
|
||||
|
||||
ViewProviderPlane::~ViewProviderPlane() = default;
|
||||
@@ -60,44 +62,31 @@ ViewProviderPlane::~ViewProviderPlane() = default;
|
||||
void ViewProviderPlane::attach(App::DocumentObject * obj) {
|
||||
ViewProviderDatum::attach(obj);
|
||||
|
||||
const char* name = pcObject->getNameInDocument();
|
||||
std::string role = getRole();
|
||||
|
||||
SoSeparator* sep = getDatumRoot();
|
||||
|
||||
// Setup colors
|
||||
// Can't use transparency because of https://github.com/FreeCAD/FreeCAD/issues/18395
|
||||
// When this issue is fixed then we can use the below and remove the material here
|
||||
// and faceSeparator...
|
||||
//ShapeAppearance.setTransparency(0.8);
|
||||
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;
|
||||
if (!role.empty()) {
|
||||
ShapeAppearance.setDiffuseColor(getColor(role));
|
||||
SbColor color;
|
||||
float alpha = 0.0f;
|
||||
color.setPackedValue(getColor(role), alpha);
|
||||
material->ambientColor.setValue(color);
|
||||
material->diffuseColor.setValue(color);
|
||||
}
|
||||
|
||||
static const float size = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")->GetFloat("DatumPlaneSize", 40.0);
|
||||
static const float startSize = 0.25 * size; //NOLINT
|
||||
|
||||
|
||||
SbVec3f verts[4];
|
||||
if (noRole) {
|
||||
if (role.empty()) {
|
||||
verts[0] = SbVec3f(size, size, 0);
|
||||
verts[1] = SbVec3f(size, -size, 0);
|
||||
verts[2] = SbVec3f(-size, -size, 0);
|
||||
@@ -110,29 +99,27 @@ void ViewProviderPlane::attach(App::DocumentObject * obj) {
|
||||
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 = getDatumRoot();
|
||||
|
||||
auto pCoords = new SoCoordinate3();
|
||||
pCoords->point.setNum(4);
|
||||
pCoords->point.setValues(0, 4, verts);
|
||||
sep->addChild(pCoords);
|
||||
|
||||
auto lineSeparator = new SoSeparator();
|
||||
auto pLines = new SoIndexedLineSet();
|
||||
static const int32_t lines[6] = { 0, 1, 2, 3, 0, -1 };
|
||||
pLines->coordIndex.setNum(6);
|
||||
pLines->coordIndex.setValues(0, 6, lines);
|
||||
sep->addChild(pLines);
|
||||
|
||||
auto ps = new SoPickStyle();
|
||||
ps->style.setValue(SoPickStyle::SHAPE_ON_TOP);
|
||||
lineSeparator->addChild(ps);
|
||||
lineSeparator->addChild(pLines);
|
||||
sep->addChild(lineSeparator);
|
||||
|
||||
// add semi transparent face
|
||||
auto faceSeparator = new SoSeparator();
|
||||
sep->addChild(faceSeparator);
|
||||
|
||||
|
||||
material->ambientColor.setValue(color);
|
||||
material->diffuseColor.setValue(color);
|
||||
faceSeparator->addChild(material);
|
||||
|
||||
// disable backface culling and render with two-sided lighting
|
||||
@@ -141,19 +128,75 @@ void ViewProviderPlane::attach(App::DocumentObject * obj) {
|
||||
shapeHints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
|
||||
faceSeparator->addChild(shapeHints);
|
||||
|
||||
auto pickStyle = new SoPickStyle();
|
||||
pickStyle->style = SoPickStyle::SHAPE_ON_TOP;
|
||||
faceSeparator->addChild(pickStyle);
|
||||
|
||||
auto faceSet = new SoFaceSet();
|
||||
auto vertexProperty = new SoVertexProperty();
|
||||
vertexProperty->vertex.setValues(0, 4, verts);
|
||||
faceSet->vertexProperty.setValue(vertexProperty);
|
||||
faceSeparator->addChild(faceSet);
|
||||
|
||||
auto ps = new SoPickStyle();
|
||||
ps->style.setValue(SoPickStyle::BOUNDING_BOX);
|
||||
sep->addChild(ps);
|
||||
auto textTranslation = new SoTranslation();
|
||||
SbVec3f centeringVec = size * SbVec3f(0.36, 0.49, 0); // NOLINT
|
||||
textTranslation->translation.setValue(centeringVec);
|
||||
sep->addChild(textTranslation);
|
||||
|
||||
sep->addChild(getLabel());
|
||||
pLabel->string.setValue(getLabelText(role).c_str());
|
||||
|
||||
labelSwitch = new SoSwitch();
|
||||
setLabelVisibility(false);
|
||||
labelSwitch->addChild(pLabel);
|
||||
sep->addChild(labelSwitch);
|
||||
}
|
||||
|
||||
void ViewProviderPlane::setLabelVisibility(bool val)
|
||||
{
|
||||
labelSwitch->whichChild = val ? SO_SWITCH_ALL : SO_SWITCH_NONE;
|
||||
}
|
||||
|
||||
unsigned long ViewProviderPlane::getColor(std::string& role)
|
||||
{
|
||||
auto planesRoles = App::LocalCoordinateSystem::PlaneRoles;
|
||||
if (role == planesRoles[0]) {
|
||||
return ViewParams::instance()->getAxisZColor(); // XY-plane
|
||||
}
|
||||
else if (role == planesRoles[1]) {
|
||||
return ViewParams::instance()->getAxisYColor(); // XZ-plane
|
||||
}
|
||||
else if (role == planesRoles[2]) {
|
||||
return ViewParams::instance()->getAxisXColor(); // YZ-plane
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string ViewProviderPlane::getLabelText(std::string& role)
|
||||
{
|
||||
std::string text;
|
||||
auto planesRoles = App::LocalCoordinateSystem::PlaneRoles;
|
||||
if (role == planesRoles[0]) {
|
||||
text = "XY";
|
||||
}
|
||||
else if (role == planesRoles[1]) {
|
||||
text = "XZ";
|
||||
}
|
||||
else if (role == planesRoles[2]) {
|
||||
text = "YZ";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
std::string ViewProviderPlane::getRole()
|
||||
{
|
||||
// Note: Role property of App::Plane is not set yet when attaching.
|
||||
const char* name = pcObject->getNameInDocument();
|
||||
auto planesRoles = App::LocalCoordinateSystem::PlaneRoles;
|
||||
if (strncmp(name, planesRoles[0], strlen(planesRoles[0])) == 0) {
|
||||
return planesRoles[0];
|
||||
}
|
||||
else if (strncmp(name, planesRoles[1], strlen(planesRoles[1])) == 0) {
|
||||
return planesRoles[1];
|
||||
}
|
||||
else if (strncmp(name, planesRoles[2], strlen(planesRoles[2])) == 0) {
|
||||
return planesRoles[2];
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
Reference in New Issue
Block a user