diff --git a/src/Gui/ArcEngine.cpp b/src/Gui/ArcEngine.cpp new file mode 100644 index 0000000000..a0edab0d00 --- /dev/null +++ b/src/Gui/ArcEngine.cpp @@ -0,0 +1,135 @@ +/*************************************************************************** + * Copyright (c) 2013 Thomas Anderson * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" + +#include "ArcEngine.h" +#include + +# include +# include +# include +# include +# include + +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include + +using namespace Gui; + + + +SO_ENGINE_SOURCE(ArcEngine) + +ArcEngine::ArcEngine() +{ + SO_ENGINE_CONSTRUCTOR(ArcEngine); + + SO_ENGINE_ADD_INPUT(radius, (10.0)); + SO_ENGINE_ADD_INPUT(angle, (1.0)); + SO_ENGINE_ADD_INPUT(deviation, (0.25)); + + SO_ENGINE_ADD_OUTPUT(points, SoMFVec3f); + SO_ENGINE_ADD_OUTPUT(pointCount, SoSFInt32); + SO_ENGINE_ADD_OUTPUT(midpoint, SoSFVec3f); +} + +void ArcEngine::initClass() +{ + SO_ENGINE_INIT_CLASS(ArcEngine, SoEngine, "Engine"); +} + +void ArcEngine::evaluate() +{ + float angle = abs(this->angle.getValue()); + + if (radius.getValue() < std::numeric_limits::epsilon() || + deviation.getValue() < std::numeric_limits::epsilon()) + { + defaultValues(); + return; + } + + float deviationAngle(acos((radius.getValue() - deviation.getValue()) / radius.getValue())); + std::vector tempPoints; + int segmentCount; + if (deviationAngle >= angle) { + segmentCount = 1; + } + else { + segmentCount = static_cast(angle / deviationAngle) + 1; + if (segmentCount < 2) { + defaultValues(); + return; + } + } + float angleIncrement = (this->angle.getValue() > 0 ? angle : -angle) / static_cast(segmentCount); + for (int index = 0; index < segmentCount + 1; ++index) + { + SbVec3f currentNormal(1.0, 0.0, 0.0); + float currentAngle = index * angleIncrement; + SbRotation rotation(SbVec3f(0.0, 0.0, 1.0), currentAngle); + rotation.multVec(currentNormal, currentNormal); + tempPoints.push_back(currentNormal * radius.getValue()); + } + int tempCount = tempPoints.size(); //for macro. + SO_ENGINE_OUTPUT(points, SoMFVec3f, setNum(tempCount)); + SO_ENGINE_OUTPUT(pointCount, SoSFInt32, setValue(tempCount)); + std::vector::const_iterator it; + for (it = tempPoints.begin(); it != tempPoints.end(); ++it) + { + int currentIndex = it-tempPoints.begin(); //for macro. + SbVec3f temp(*it); //for macro + SO_ENGINE_OUTPUT(points, SoMFVec3f, set1Value(currentIndex, temp)); + } + + // Get Midpoint + float a = angle / 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() +{ + //just some non-failing info. + SO_ENGINE_OUTPUT(points, SoMFVec3f, setNum(2)); + SbVec3f point1(10.0, 0.0, 0.0); + SO_ENGINE_OUTPUT(points, SoMFVec3f, set1Value(0, point1)); + SbVec3f point2(7.07f, 7.07f, 0.0); + SO_ENGINE_OUTPUT(points, SoMFVec3f, set1Value(1, point2)); + SO_ENGINE_OUTPUT(pointCount, SoSFInt32, setValue(2)); + SbVec3f point3(7.07f, 7.07f, 0.0); + SO_ENGINE_OUTPUT(midpoint, SoSFVec3f, setValue(point3)); +} \ No newline at end of file diff --git a/src/Gui/ArcEngine.h b/src/Gui/ArcEngine.h new file mode 100644 index 0000000000..fdba1b6299 --- /dev/null +++ b/src/Gui/ArcEngine.h @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (c) 2013 Thomas Anderson * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef GUI_ARCENGINE_H +#define GUI_ARCENGINE_H + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class SoText2; +class SoTranslation; +class SoCoordinate3; +class SoIndexedLineSet; + +namespace Gui { + + +// /*used for generating points for arc display*/ +class GuiExport ArcEngine : public SoEngine +{ + SO_ENGINE_HEADER(ArcEngine); +public: + ArcEngine(); + static void initClass(); + + SoSFFloat radius; + SoSFFloat angle; + SoSFFloat deviation; + + SoEngineOutput points; + SoEngineOutput pointCount; + SoEngineOutput midpoint; + +protected: + void evaluate() override; +private: + ~ArcEngine() override{} + void defaultValues(); //some non error values if something goes wrong. +}; + +} // namespace Gui + +#endif // GUI_ARCENGINE_H \ No newline at end of file diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index c0a0202ed1..7a06a512eb 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -1009,6 +1009,7 @@ SET(Inventor_CPP_SRCS SoTouchEvents.cpp SoMouseWheelEvent.cpp SoFCCSysDragger.cpp + ArcEngine.cpp ) SET(Inventor_SRCS ${Inventor_CPP_SRCS} @@ -1037,6 +1038,7 @@ SET(Inventor_SRCS SoTouchEvents.h SoMouseWheelEvent.h SoFCCSysDragger.h + ArcEngine.h ) SOURCE_GROUP("View3D\\Inventor" FILES ${Inventor_SRCS}) diff --git a/src/Gui/SoFCDB.cpp b/src/Gui/SoFCDB.cpp index 582d35cb5a..cdd8c6f5ac 100644 --- a/src/Gui/SoFCDB.cpp +++ b/src/Gui/SoFCDB.cpp @@ -74,6 +74,7 @@ #include "Inventor/SoAutoZoomTranslation.h" #include "Inventor/SoDrawingGrid.h" #include "propertyeditor/PropertyItem.h" +#include "ArcEngine.h" using namespace Gui; @@ -193,6 +194,8 @@ void Gui::SoFCDB::init() SelectionObject ::init(); + ArcEngine ::initClass(); + qRegisterMetaType("Base::Vector3f"); qRegisterMetaType("Base::Vector3d"); qRegisterMetaType("Base::Quantity"); diff --git a/src/Mod/Part/Gui/AppPartGui.cpp b/src/Mod/Part/Gui/AppPartGui.cpp index a224a3806d..4aef8a4efe 100644 --- a/src/Mod/Part/Gui/AppPartGui.cpp +++ b/src/Mod/Part/Gui/AppPartGui.cpp @@ -214,7 +214,6 @@ PyMOD_INIT_FUNC(PartGui) PartGui::ViewProviderProjectOnSurface ::init(); PartGui::DimensionLinear ::initClass(); PartGui::DimensionAngular ::initClass(); - PartGui::ArcEngine ::initClass(); PartGui::Workbench ::init(); auto manip = std::make_shared();