Skip to content

Commit

Permalink
Measure: Add MeasureAngle ViewProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
hlorus committed Sep 5, 2023
1 parent 17c5396 commit b67dc81
Show file tree
Hide file tree
Showing 10 changed files with 488 additions and 76 deletions.
48 changes: 0 additions & 48 deletions .vscode/launch.json

This file was deleted.

14 changes: 14 additions & 0 deletions src/Gui/ArcEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ ArcEngine::ArcEngine()

SO_ENGINE_ADD_OUTPUT(points, SoMFVec3f);
SO_ENGINE_ADD_OUTPUT(pointCount, SoSFInt32);
SO_ENGINE_ADD_OUTPUT(midpoint, SoSFVec3f);
}

void ArcEngine::initClass()
Expand Down Expand Up @@ -106,6 +107,16 @@ void ArcEngine::evaluate()
SO_ENGINE_OUTPUT(points, SoMFVec3f, set1Value(currentIndex, temp));
}

// Get Midpoint
float a = angle.getValue() / 2;
SbRotation rot(SbVec3f(0.0, 0.0, 1.0), a);
SbVec3f midPnt(1.0, 0.0, 0.0);
rot.multVec(midPnt, midPnt);
midPnt = midPnt * radius.getValue();

SO_ENGINE_OUTPUT(midpoint, SoSFVec3f, setValue(midPnt));


}

void ArcEngine::defaultValues()
Expand All @@ -117,4 +128,7 @@ void ArcEngine::defaultValues()
SbVec3f point2(7.07f, 7.07f, 0.0);
SO_ENGINE_OUTPUT(points, SoMFVec3f, set1Value(1, point2));
SO_ENGINE_OUTPUT(pointCount, SoSFInt32, setValue(2));

Check warning on line 131 in src/Gui/ArcEngine.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

<-- trailing whitespace
SbVec3f point3(7.07f, 7.07f, 0.0);
SO_ENGINE_OUTPUT(midpoint, SoSFVec3f, setValue(point3));
}

Check warning on line 134 in src/Gui/ArcEngine.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Could not find a newline character at the end of the file. [whitespace/ending_newline] [5]
2 changes: 2 additions & 0 deletions src/Gui/ArcEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class GuiExport ArcEngine : public SoEngine

SoEngineOutput points;
SoEngineOutput pointCount;
SoEngineOutput midpoint;

protected:
void evaluate() override;
private:
Expand Down
27 changes: 14 additions & 13 deletions src/Mod/Measure/App/MeasureAngle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,53 +146,54 @@ const char* className = ob.getSubObject(subName.c_str())->getTypeId().getName();
return info.position;
}

Base::Vector3d MeasureAngle::vector1() {
gp_Vec MeasureAngle::vector1() {

App::DocumentObject* ob = Element1.getValue();
std::vector<std::string> subs = Element1.getSubValues();

if (!ob || !ob->isValid() || subs.size() < 1 ) {
return Base::Vector3d();
return gp_Vec();
}

Base::Vector3d vec;
getVec(*ob, subs.at(0), vec);
return vec;
return gp_Vec(vec.x, vec.y, vec.z);
}

Base::Vector3d MeasureAngle::vector2() {
gp_Vec MeasureAngle::vector2() {
App::DocumentObject* ob = Element2.getValue();
std::vector<std::string> subs = Element2.getSubValues();

if (!ob || !ob->isValid() || subs.size() < 1 ) {
return Base::Vector3d();
return gp_Vec();
}

Base::Vector3d vec;
getVec(*ob, subs.at(0), vec);
return vec;
return gp_Vec(vec.x, vec.y, vec.z);
}

Base::Vector3d MeasureAngle::location1() {
gp_Vec MeasureAngle::location1() {

App::DocumentObject* ob = Element1.getValue();
std::vector<std::string> subs = Element1.getSubValues();

if (!ob || !ob->isValid() || subs.size() < 1 ) {
return Base::Vector3d();
return {};
}

return getLoc(*ob, subs.at(0));
auto temp = getLoc(*ob, subs.at(0));
return {temp.x, temp.y, temp.z};
}
Base::Vector3d MeasureAngle::location2() {
gp_Vec MeasureAngle::location2() {
App::DocumentObject* ob = Element2.getValue();
std::vector<std::string> subs = Element2.getSubValues();

if (!ob || !ob->isValid() || subs.size() < 1 ) {
return Base::Vector3d();
return {};
}

return getLoc(*ob, subs.at(0));
auto temp = getLoc(*ob, subs.at(0));
return {temp.x, temp.y, temp.z};
}


Expand Down
11 changes: 6 additions & 5 deletions src/Mod/Measure/App/MeasureAngle.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <map>

#include <Base/Vector3D.h>
#include <gp_Vec.hxx>

#include <Mod/Measure/MeasureGlobal.h>

Expand Down Expand Up @@ -65,7 +66,7 @@ class MeasureExport MeasureAngle : public App::MeasurementBaseExtendable<Measure
App::DocumentObjectExecReturn *execute() override;

const char* getViewProviderName() const override {
return "Gui::ViewProviderMeasureAngle";
return "MeasureGui::ViewProviderMeasureAngle";
}

static bool isValidSelection(const App::MeasureSelection& selection);
Expand All @@ -77,12 +78,12 @@ class MeasureExport MeasureAngle : public App::MeasurementBaseExtendable<Measure
Base::Vector3d getLoc(App::DocumentObject& ob, std::string& subName);

// Orientation Vectors
Base::Vector3d vector1();
Base::Vector3d vector2();
gp_Vec vector1();
gp_Vec vector2();

// Location Vectors
Base::Vector3d location1();
Base::Vector3d location2();
gp_Vec location1();
gp_Vec location2();

private:

Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Measure/Gui/AppMeasureGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <Gui/Application.h>

#include "ViewProviderMeasureDistancePoints.h"
#include "ViewProviderMeasureAngle.h"



Expand Down Expand Up @@ -78,6 +79,7 @@ PyMOD_INIT_FUNC(MeasureGui)
}

MeasureGui::ViewProviderMeasureDistancePoints ::init();
MeasureGui::ViewProviderMeasureAngle ::init();

// instantiating the commands
CreateMeasureCommands();
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Measure/Gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ SET(MeasureGui_SRCS
PreCompiled.h
ViewProviderMeasureDistancePoints.cpp
ViewProviderMeasureDistancePoints.h
ViewProviderMeasureAngle.cpp
ViewProviderMeasureAngle.h
# Workbench.cpp
# Workbench.h
)
Expand Down
Loading

0 comments on commit b67dc81

Please sign in to comment.