MeasureGui: Add back DimensionLinear node kit
This commit is contained in:
@@ -89,6 +89,8 @@ PyMOD_INIT_FUNC(MeasureGui)
|
||||
// instantiating the commands
|
||||
CreateMeasureCommands();
|
||||
|
||||
MeasureGui::DimensionLinear::initClass();
|
||||
|
||||
MeasureGui::ViewProviderMeasureGroup ::init();
|
||||
MeasureGui::ViewProviderMeasureBase ::init();
|
||||
MeasureGui::ViewProviderMeasure ::init();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 David Friedli <david[at]friedli-be.ch> *
|
||||
* Copyright (c) 2013 Thomas Anderson <blobfish[at]gmx.com> *
|
||||
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of FreeCAD. *
|
||||
@@ -23,20 +24,29 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
# include <QApplication>
|
||||
# include <Inventor/engines/SoCalculator.h>
|
||||
# include <Inventor/engines/SoConcatenate.h>
|
||||
# include <Inventor/nodes/SoAnnotation.h>
|
||||
# include <Inventor/nodes/SoBaseColor.h>
|
||||
# include <Inventor/nodes/SoCoordinate3.h>
|
||||
# include <Inventor/nodes/SoDrawStyle.h>
|
||||
# include <Inventor/nodes/SoFontStyle.h>
|
||||
# include <Inventor/nodes/SoIndexedLineSet.h>
|
||||
# include <Inventor/nodes/SoMarkerSet.h>
|
||||
# include <Inventor/nodes/SoPickStyle.h>
|
||||
# include <Inventor/nodes/SoText2.h>
|
||||
# include <Inventor/nodes/SoTranslation.h>
|
||||
#include <sstream>
|
||||
#include <QApplication>
|
||||
#include <Inventor/engines/SoCalculator.h>
|
||||
#include <Inventor/engines/SoConcatenate.h>
|
||||
#include <Inventor/engines/SoComposeRotation.h>
|
||||
#include <Inventor/engines/SoComposeRotationFromTo.h>
|
||||
#include <Inventor/engines/SoComposeVec3f.h>
|
||||
#include <Inventor/engines/SoDecomposeVec3f.h>
|
||||
#include <Inventor/nodes/SoAnnotation.h>
|
||||
#include <Inventor/nodes/SoBaseColor.h>
|
||||
#include <Inventor/nodes/SoCoordinate3.h>
|
||||
#include <Inventor/nodes/SoDrawStyle.h>
|
||||
#include <Inventor/nodes/SoFontStyle.h>
|
||||
#include <Inventor/nodes/SoIndexedLineSet.h>
|
||||
#include <Inventor/nodes/SoMarkerSet.h>
|
||||
#include <Inventor/nodes/SoPickStyle.h>
|
||||
#include <Inventor/nodes/SoText2.h>
|
||||
#include <Inventor/nodes/SoTranslation.h>
|
||||
#include <Inventor/nodes/SoMaterial.h>
|
||||
#include <Inventor/nodes/SoSwitch.h>
|
||||
#include <Inventor/nodes/SoCone.h>
|
||||
#include <Inventor/nodes/SoResetTransform.h>
|
||||
#include <Inventor/nodes/SoNodes.h>
|
||||
#endif
|
||||
|
||||
#include <Gui/Inventor/MarkerBitmaps.h>
|
||||
@@ -60,6 +70,163 @@ using namespace Measure;
|
||||
|
||||
PROPERTY_SOURCE(MeasureGui::ViewProviderMeasureDistance, MeasureGui::ViewProviderMeasureBase)
|
||||
|
||||
SO_KIT_SOURCE(MeasureGui::DimensionLinear)
|
||||
|
||||
void MeasureGui::DimensionLinear::initClass()
|
||||
{
|
||||
SO_KIT_INIT_CLASS(DimensionLinear, SoSeparatorKit, "SeparatorKit");
|
||||
}
|
||||
|
||||
MeasureGui::DimensionLinear::DimensionLinear()
|
||||
{
|
||||
SO_KIT_CONSTRUCTOR(MeasureGui::DimensionLinear);
|
||||
|
||||
SO_KIT_ADD_CATALOG_ENTRY(transformation, SoTransform, true, topSeparator, "", true);
|
||||
SO_KIT_ADD_CATALOG_ENTRY(annotate, SoAnnotation, true, topSeparator, "", true);
|
||||
SO_KIT_ADD_CATALOG_ENTRY(leftArrow, SoShapeKit, true, topSeparator, "", true);
|
||||
SO_KIT_ADD_CATALOG_ENTRY(rightArrow, SoShapeKit, true, topSeparator, "", true);
|
||||
SO_KIT_ADD_CATALOG_ENTRY(line, SoShapeKit, true, annotate, "", true);
|
||||
SO_KIT_ADD_CATALOG_ENTRY(textSep, SoSeparator, true, annotate, "", true);
|
||||
|
||||
SO_KIT_INIT_INSTANCE();
|
||||
|
||||
SO_NODE_ADD_FIELD(rotate, (1.0, 0.0, 0.0, 0.0)); // position orientation of the dimension.
|
||||
SO_NODE_ADD_FIELD(length, (1.0)); // turns into dimension length
|
||||
SO_NODE_ADD_FIELD(origin, (0.0, 0.0, 0.0)); // static
|
||||
SO_NODE_ADD_FIELD(text, ("test")); // dimension text
|
||||
SO_NODE_ADD_FIELD(dColor, (1.0, 0.0, 0.0)); // dimension color.
|
||||
SO_NODE_ADD_FIELD(showArrows, (false)); // display dimension arrows
|
||||
SO_NODE_ADD_FIELD(fontSize, (12.0)); // size of the dimension font
|
||||
}
|
||||
|
||||
MeasureGui::DimensionLinear::~DimensionLinear()
|
||||
{}
|
||||
|
||||
SbBool MeasureGui::DimensionLinear::affectsState() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void MeasureGui::DimensionLinear::setupDimension()
|
||||
{
|
||||
// make unpickable
|
||||
SoPickStyle* ps = static_cast<SoPickStyle*>(getPart("pickStyle", true));
|
||||
if (ps) {
|
||||
ps->style = SoPickStyle::UNPICKABLE;
|
||||
}
|
||||
|
||||
// transformation
|
||||
SoTransform* trans = static_cast<SoTransform*>(getPart("transformation", true));
|
||||
trans->translation.connectFrom(&point1);
|
||||
// build engine for vector subtraction and length.
|
||||
SoCalculator* hyp = new SoCalculator();
|
||||
hyp->A.connectFrom(&point1);
|
||||
hyp->B.connectFrom(&point2);
|
||||
hyp->expression.set1Value(0, "oA = B-A");
|
||||
hyp->expression.set1Value(1, "oB = normalize(oA)");
|
||||
hyp->expression.set1Value(2, "oa = length(oA)");
|
||||
length.connectFrom(&hyp->oa);
|
||||
|
||||
// build engine for rotation.
|
||||
SoComposeRotationFromTo* rotationEngine = new SoComposeRotationFromTo();
|
||||
rotationEngine->from.setValue(SbVec3f(1.0, 0.0, 0.0));
|
||||
rotationEngine->to.connectFrom(&hyp->oB);
|
||||
trans->rotation.connectFrom(&rotationEngine->rotation);
|
||||
|
||||
// color
|
||||
SoMaterial* material = new SoMaterial;
|
||||
material->diffuseColor.connectFrom(&dColor);
|
||||
|
||||
// dimension arrows
|
||||
float dimLength = (point2.getValue() - point1.getValue()).length();
|
||||
float coneHeight = dimLength * 0.06;
|
||||
float coneRadius = coneHeight * 0.5;
|
||||
|
||||
SoComposeVec3f* vec = new SoComposeVec3f;
|
||||
vec->x.connectFrom(&length);
|
||||
vec->y.setValue(0.0);
|
||||
vec->z.setValue(0.0);
|
||||
|
||||
// NOTE: showArrows is only respected at setup stage and cannot be changed later
|
||||
if (showArrows.getValue()) {
|
||||
SoCone* cone = new SoCone();
|
||||
cone->bottomRadius.setValue(coneRadius);
|
||||
cone->height.setValue(coneHeight);
|
||||
|
||||
char lStr[100];
|
||||
char rStr[100];
|
||||
snprintf(lStr, sizeof(lStr), "translation %.6f 0.0 0.0", coneHeight * 0.5);
|
||||
snprintf(rStr, sizeof(rStr), "translation 0.0 -%.6f 0.0", coneHeight * 0.5);
|
||||
|
||||
setPart("leftArrow.shape", cone);
|
||||
set("leftArrow.transform", "rotation 0.0 0.0 1.0 1.5707963");
|
||||
set("leftArrow.transform", lStr);
|
||||
setPart("rightArrow.shape", cone);
|
||||
set("rightArrow.transform", "rotation 0.0 0.0 -1.0 1.5707963"); // no constant for PI.
|
||||
// have use local here to do the offset because the main is wired up to length of dimension.
|
||||
set("rightArrow.localTransform", rStr);
|
||||
|
||||
SoTransform* transform = static_cast<SoTransform*>(getPart("rightArrow.transform", false));
|
||||
if (!transform) {
|
||||
return; // what to do here?
|
||||
}
|
||||
transform->translation.connectFrom(&vec->vector);
|
||||
|
||||
setPart("leftArrow.material", material);
|
||||
setPart("rightArrow.material", material);
|
||||
}
|
||||
|
||||
// line
|
||||
SoConcatenate* catEngine = new SoConcatenate(SoMFVec3f::getClassTypeId());
|
||||
// don't know how to get around having this dummy origin. cat engine wants to connectfrom?
|
||||
catEngine->input[0]->connectFrom(&origin);
|
||||
catEngine->input[1]->connectFrom(&vec->vector);
|
||||
|
||||
SoVertexProperty* lineVerts = new SoVertexProperty;
|
||||
lineVerts->vertex.connectFrom(catEngine->output);
|
||||
|
||||
int lineVertexMap[] = {0, 1};
|
||||
int lineVertexMapSize(sizeof(lineVertexMap) / sizeof(int));
|
||||
SoIndexedLineSet* line = new SoIndexedLineSet;
|
||||
line->vertexProperty = lineVerts;
|
||||
line->coordIndex.setValues(0, lineVertexMapSize, lineVertexMap);
|
||||
|
||||
setPart("line.shape", line);
|
||||
setPart("line.material", material);
|
||||
|
||||
// text
|
||||
SoSeparator* textSep = static_cast<SoSeparator*>(getPart("textSep", true));
|
||||
if (!textSep) {
|
||||
return;
|
||||
}
|
||||
|
||||
textSep->addChild(material);
|
||||
|
||||
SoCalculator* textVecCalc = new SoCalculator();
|
||||
textVecCalc->A.connectFrom(&vec->vector);
|
||||
textVecCalc->B.set1Value(0, 0.0, 0.250, 0.0);
|
||||
textVecCalc->expression.set1Value(0, "oA = (A / 2) + B");
|
||||
|
||||
SoTransform* textTransform = new SoTransform();
|
||||
textTransform->translation.connectFrom(&textVecCalc->oA);
|
||||
textSep->addChild(textTransform);
|
||||
|
||||
SoFont* fontNode = new SoFont();
|
||||
fontNode->name.setValue("Helvetica : Bold");
|
||||
fontNode->size.connectFrom(&fontSize);
|
||||
textSep->addChild(fontNode);
|
||||
|
||||
SoText2* textNode = new SoText2();
|
||||
textNode->justification = SoText2::CENTER;
|
||||
textNode->string.connectFrom(&text);
|
||||
textSep->addChild(textNode);
|
||||
|
||||
// this prevents the 2d text from screwing up the bounding box for a viewall
|
||||
SoResetTransform* rTrans = new SoResetTransform;
|
||||
rTrans->whatToReset = SoResetTransform::BBOX;
|
||||
textSep->addChild(rTrans);
|
||||
}
|
||||
|
||||
|
||||
SbMatrix ViewProviderMeasureDistance::getMatrix() {
|
||||
if (!pcObject) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 David Friedli <david[at]friedli-be.ch> *
|
||||
* Copyright (c) 2013 Thomas Anderson <blobfish[at]gmx.com> *
|
||||
* *
|
||||
* This file is part of FreeCAD. *
|
||||
* *
|
||||
@@ -28,6 +29,17 @@
|
||||
#include <Mod/Measure/MeasureGlobal.h>
|
||||
#include "ViewProviderMeasureBase.h"
|
||||
|
||||
#include <Inventor/engines/SoSubEngine.h>
|
||||
#include <Inventor/engines/SoEngine.h>
|
||||
#include <Inventor/fields/SoSFBool.h>
|
||||
#include <Inventor/fields/SoSFColor.h>
|
||||
#include <Inventor/fields/SoSFFloat.h>
|
||||
#include <Inventor/fields/SoSFMatrix.h>
|
||||
#include <Inventor/fields/SoSFRotation.h>
|
||||
#include <Inventor/fields/SoSFString.h>
|
||||
#include <Inventor/fields/SoSFVec3f.h>
|
||||
#include <Inventor/nodekits/SoSeparatorKit.h>
|
||||
|
||||
|
||||
class SoCoordinate3;
|
||||
class SoIndexedLineSet;
|
||||
@@ -35,6 +47,40 @@ class SoIndexedLineSet;
|
||||
namespace MeasureGui
|
||||
{
|
||||
|
||||
class DimensionLinear: public SoSeparatorKit
|
||||
{
|
||||
SO_KIT_HEADER(DimensionLinear);
|
||||
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(transformation);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(annotate);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(leftArrow);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(rightArrow);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(line);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(textSep);
|
||||
|
||||
public:
|
||||
DimensionLinear();
|
||||
static void initClass();
|
||||
SbBool affectsState() const override;
|
||||
void setupDimension();
|
||||
|
||||
SoSFVec3f point1;
|
||||
SoSFVec3f point2;
|
||||
SoSFString text;
|
||||
SoSFColor dColor;
|
||||
SoSFBool showArrows;
|
||||
SoSFFloat fontSize;
|
||||
|
||||
protected:
|
||||
SoSFRotation rotate;
|
||||
SoSFFloat length;
|
||||
SoSFVec3f origin;
|
||||
|
||||
private:
|
||||
~DimensionLinear() override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class MeasureGuiExport ViewProviderMeasureDistance : public MeasureGui::ViewProviderMeasureBase
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user