diff --git a/src/Gui/ViewProviderLine.cpp b/src/Gui/ViewProviderLine.cpp index 91d84baf5..6026bb16c 100644 --- a/src/Gui/ViewProviderLine.cpp +++ b/src/Gui/ViewProviderLine.cpp @@ -101,9 +101,11 @@ ViewProviderLine::ViewProviderLine() pFont->size.setValue(Size.getValue()/10.); pTranslation = new SoTranslation(); + pTranslation->ref(); pTranslation->translation.setValue(SbVec3f(-1,0,0)); pText = new SoAsciiText(); + pText->ref(); pText->width.setValue(-1); sPixmap = "view-measurement"; @@ -114,6 +116,8 @@ ViewProviderLine::~ViewProviderLine() pCoords->unref(); pLines->unref(); pMat->unref(); + pTranslation->unref(); + pText->unref(); } void ViewProviderLine::onChanged(const App::Property* prop) diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumCS.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumCS.cpp index 05719943e..cf5d2d851 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumCS.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumCS.cpp @@ -28,6 +28,10 @@ # include # include # include +#include +#include +#include +#include # include # include # include @@ -50,6 +54,7 @@ #include #include #include +#include using namespace PartDesignGui; @@ -60,14 +65,32 @@ ViewProviderDatumCoordinateSystem::ViewProviderDatumCoordinateSystem() sPixmap = "PartDesign_CoordinateSystem.svg"; SoMaterial* material = new SoMaterial(); - material->diffuseColor.setValue(0.9f, 0.9f, 0.13f); - material->transparency.setValue(0.5f); + 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(3, SbColor(0.f, 0.f, 1.f)); + SoMaterialBinding* binding = new SoMaterialBinding(); + binding->value = SoMaterialBinding::PER_FACE_INDEXED; + pShapeSep->addChild(binding); pShapeSep->addChild(material); + + font = new SoFont(); + font->ref(); + transX = new SoTranslation(); + transX->ref(); + transY = new SoTranslation(); + transY->ref(); + transZ = new SoTranslation(); + transZ->ref(); } ViewProviderDatumCoordinateSystem::~ViewProviderDatumCoordinateSystem() { - + font->unref(); + transX->unref(); + transY->unref(); + transZ->unref(); } void ViewProviderDatumCoordinateSystem::updateData(const App::Property* prop) @@ -94,7 +117,7 @@ void ViewProviderDatumCoordinateSystem::updateData(const App::Property* prop) PartGui::SoBrepEdgeSet* lineSet; SoCoordinate3* coord; - if (pShapeSep->getNumChildren() == 1) { + if (pShapeSep->getNumChildren() == 2) { coord = new SoCoordinate3(); coord->point.setNum(4); coord->point.set1Value(0, base.x, base.y, base.z); @@ -104,19 +127,56 @@ void ViewProviderDatumCoordinateSystem::updateData(const App::Property* prop) pShapeSep->addChild(coord); lineSet = new PartGui::SoBrepEdgeSet(); - lineSet->coordIndex.setNum(5); - lineSet->coordIndex.set1Value(0, 1); - lineSet->coordIndex.set1Value(1, 0); - lineSet->coordIndex.set1Value(2, 2); + lineSet->coordIndex.setNum(9); + lineSet->coordIndex.set1Value(0, 0); + lineSet->coordIndex.set1Value(1, 1); + lineSet->coordIndex.set1Value(2, -1); lineSet->coordIndex.set1Value(3, 0); - lineSet->coordIndex.set1Value(4, 3); + lineSet->coordIndex.set1Value(4, 2); + lineSet->coordIndex.set1Value(5, -1); + lineSet->coordIndex.set1Value(6, 0); + lineSet->coordIndex.set1Value(7, 3); + lineSet->coordIndex.set1Value(8, -1); + lineSet->materialIndex.setNum(3); + lineSet->materialIndex.set1Value(0,1); + lineSet->materialIndex.set1Value(1,2); + lineSet->materialIndex.set1Value(2,3); pShapeSep->addChild(lineSet); + + pShapeSep->addChild(font); + font->size = axis.Length()/10.; + pShapeSep->addChild(transX); + transX->translation.setValue(SbVec3f(x.x,x.y,x.z)); + SoAsciiText* t = new SoAsciiText(); + t->string = "X"; + pShapeSep->addChild(t); + pShapeSep->addChild(transY); + transY->translation.setValue(SbVec3f(-x.x + y.x, x.y + y.y, -x.z + y.z)); + t = new SoAsciiText(); + t->string = "Y"; + pShapeSep->addChild(t); + pShapeSep->addChild(transZ); + auto* rot = new SoRotation(); + rot->rotation = SbRotation(SbVec3f(0,1,0), M_PI/2); + pShapeSep->addChild(rot); + transZ->translation.setValue(SbVec3f(-y.x + z.x, -y.y + z.y, -y.z + z.z)); + t = new SoAsciiText(); + t->string = "Z"; + pShapeSep->addChild(t); + } else { - coord = static_cast(pShapeSep->getChild(1)); + coord = static_cast(pShapeSep->getChild(2)); coord->point.set1Value(0, base.x, base.y, base.z); coord->point.set1Value(1, x.x, x.y, x.z); coord->point.set1Value(2, y.x, y.y, y.z); coord->point.set1Value(3, z.x, z.y, z.z); + + x = 9./10.*x; + y = 9./10.*y; + font->size = axis.Length()/10.; + transX->translation.setValue(SbVec3f(x.x,x.y,x.z)); + transY->translation.setValue(SbVec3f(-x.x + y.x, x.y + y.y, -x.z + y.z)); + transZ->translation.setValue(SbVec3f(-y.x + z.x, -y.y + z.y, -y.z + z.z)); } } diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumCS.h b/src/Mod/PartDesign/Gui/ViewProviderDatumCS.h index 3b0bc1a2f..487386fb5 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumCS.h +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumCS.h @@ -27,6 +27,9 @@ #include "Gui/ViewProviderGeometryObject.h" #include "ViewProviderDatum.h" +class SoFont; +class SoTranslation; + namespace PartDesignGui { class PartDesignGuiExport ViewProviderDatumCoordinateSystem : public PartDesignGui::ViewProviderDatum @@ -42,6 +45,9 @@ public: private: void getPointForDirection(Base::Vector3d Dir, Base::Vector3d& p); + + SoTranslation *transX, *transY, *transZ; + SoFont* font; }; } // namespace PartDesignGui