diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index ad10921ae2..2bf2d84286 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -1025,6 +1025,7 @@ SET(Inventor_CPP_SRCS Inventor/SoFCBackgroundGradient.cpp Inventor/SoFCBoundingBox.cpp Inventor/SoMouseWheelEvent.cpp + Inventor/SoFCTransform.cpp SoFCColorBar.cpp SoFCColorBarNotifier.cpp SoFCColorGradient.cpp @@ -1055,6 +1056,7 @@ SET(Inventor_SRCS Inventor/SoFCBackgroundGradient.h Inventor/SoFCBoundingBox.h Inventor/SoMouseWheelEvent.h + Inventor/SoFCTransform.h SoFCColorBar.h SoFCColorBarNotifier.h SoFCColorGradient.h diff --git a/src/Gui/Inventor/SoFCTransform.cpp b/src/Gui/Inventor/SoFCTransform.cpp new file mode 100644 index 0000000000..c0bb145a70 --- /dev/null +++ b/src/Gui/Inventor/SoFCTransform.cpp @@ -0,0 +1,91 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +/*************************************************************************** + * Copyright (c) 2024 Werner Mayer * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + **************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +#include +#include +#include +#include +#include +#include +#endif + +#include "SoFCTransform.h" + + +using namespace Gui; + +SO_NODE_SOURCE(SoFCTransform) + +void SoFCTransform::initClass() +{ + SO_NODE_INIT_CLASS(SoFCTransform, SoTransform, "Transform"); +} + +SoFCTransform::SoFCTransform() +{ + SO_NODE_CONSTRUCTOR(SoFCTransform); +} + +void SoFCTransform::GLRender(SoGLRenderAction * action) +{ + SoFCTransform::doAction(action); +} + +void SoFCTransform::callback(SoCallbackAction * action) +{ + SoFCTransform::doAction(action); +} + +void SoFCTransform::pick(SoPickAction * action) +{ + SoFCTransform::doAction(action); +} + +void SoFCTransform::getPrimitiveCount(SoGetPrimitiveCountAction * action) +{ + SoFCTransform::doAction(action); +} + +void SoFCTransform::getBoundingBox(SoGetBoundingBoxAction * action) +{ + SoFCTransform::doAction(action); +} + +void SoFCTransform::doAction(SoAction * action) +{ + SbMatrix matrix; + matrix.setTransform(this->translation.getValue(), + this->rotation.getValue(), + this->scaleFactor.getValue(), + this->scaleOrientation.getValue(), + this->center.getValue()); + + // This is different to SoTransform::doAction() where model matrix + // is always set + if (matrix != SbMatrix::identity()) { + SoModelMatrixElement::mult(action->getState(), this, matrix); + } +} diff --git a/src/Gui/Inventor/SoFCTransform.h b/src/Gui/Inventor/SoFCTransform.h new file mode 100644 index 0000000000..9e79f64c3c --- /dev/null +++ b/src/Gui/Inventor/SoFCTransform.h @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +/*************************************************************************** + * Copyright (c) 2024 Werner Mayer * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + **************************************************************************/ + +#ifndef GUI_INVENTOR_SOFCTRANSFORM_H +#define GUI_INVENTOR_SOFCTRANSFORM_H + +#include +#include + +namespace Gui +{ + +class GuiExport SoFCTransform : public SoTransform +{ + using inherited = SoTransform; + + SO_NODE_HEADER(SoFCTransform); + +public: + static void initClass(); + SoFCTransform(); + +protected: + void GLRender(SoGLRenderAction * action) override; + void callback(SoCallbackAction * action) override; + void pick(SoPickAction * action) override; + void getPrimitiveCount(SoGetPrimitiveCountAction * action) override; + void getBoundingBox(SoGetBoundingBoxAction * action) override; + void doAction(SoAction * action) override; +}; + +} // namespace Gui + +#endif // GUI_INVENTOR_SOFCTRANSFORM_H diff --git a/src/Gui/SoFCDB.cpp b/src/Gui/SoFCDB.cpp index 26b17df172..fc746a2fbe 100644 --- a/src/Gui/SoFCDB.cpp +++ b/src/Gui/SoFCDB.cpp @@ -74,6 +74,7 @@ #include "Inventor/SoFCBackgroundGradient.h" #include "Inventor/SoFCBoundingBox.h" #include "Inventor/SoMouseWheelEvent.h" +#include "Inventor/SoFCTransform.h" #include "propertyeditor/PropertyItem.h" #include "ArcEngine.h" @@ -134,6 +135,7 @@ void Gui::SoFCDB::init() SoAxisCrossKit ::initClass(); SoRegPoint ::initClass(); SoDrawingGrid ::initClass(); + SoFCTransform ::initClass(); SoAutoZoomTranslation ::initClass(); MarkerBitmaps ::initClass(); SoFCCSysDragger ::initClass(); diff --git a/src/Gui/ViewProvider.cpp b/src/Gui/ViewProvider.cpp index fdd63583be..95085b677d 100644 --- a/src/Gui/ViewProvider.cpp +++ b/src/Gui/ViewProvider.cpp @@ -42,6 +42,7 @@ #include #include "Inventor/SoMouseWheelEvent.h" +#include "Inventor/SoFCTransform.h" #include "ViewProvider.h" #include "ActionFunction.h" #include "Application.h" @@ -104,7 +105,7 @@ ViewProvider::ViewProvider() pcRoot->ref(); pcModeSwitch = new SoSwitch(); pcModeSwitch->ref(); - pcTransform = new SoTransform(); + pcTransform = new SoFCTransform(); pcTransform->ref(); pcRoot->addChild(pcTransform); pcRoot->addChild(pcModeSwitch);