diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index 5635bef1fc..2334876e01 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -35,10 +35,13 @@ set(FemGui_LIBS PartGui ) +generate_from_xml(ViewProviderFemConstraintPy) generate_from_xml(ViewProviderFemMeshPy) generate_from_xml(ViewProviderFemPostPipelinePy) SET(Python_SRCS + ViewProviderFemConstraintPy.xml + ViewProviderFemConstraintPyImp.cpp ViewProviderFemMeshPy.xml ViewProviderFemMeshPyImp.cpp ViewProviderFemPostPipelinePy.xml diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraint.cpp b/src/Mod/Fem/Gui/ViewProviderFemConstraint.cpp index 82fee78652..360bebe908 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemConstraint.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraint.cpp @@ -47,6 +47,7 @@ #include "TaskFemConstraint.h" #include "ViewProviderFemConstraint.h" +#include "ViewProviderFemConstraintPy.h" using namespace FemGui; @@ -215,6 +216,15 @@ void ViewProviderFemConstraint::unsetEdit(int ModNum) } } } + +PyObject* ViewProviderFemConstraint::getPyObject() +{ + if (!pyViewObject) { + pyViewObject = new ViewProviderFemConstraintPy(this); + } + pyViewObject->IncRef(); + return pyViewObject; +} /* // Create a local coordinate system with the z-axis given in dir void getLocalCoordinateSystem(const SbVec3f& z, SbVec3f& y, SbVec3f& x) diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraint.h b/src/Mod/Fem/Gui/ViewProviderFemConstraint.h index e3843fb0fe..f652fa1da6 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemConstraint.h +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraint.h @@ -72,10 +72,17 @@ public: std::vector claimChildren() const override; void setupContextMenu(QMenu*, QObject*, const char*) override; + PyObject* getPyObject() override; + /// Highlight the references that have been selected virtual void highlightReferences(const bool /* on */) {} + SoSeparator* getSymbolSeparator() const + { + return pShapeSep; + } + static std::string gethideMeshShowPartStr(); static std::string gethideMeshShowPartStr(const std::string showConstr); diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintPy.xml b/src/Mod/Fem/Gui/ViewProviderFemConstraintPy.xml new file mode 100644 index 0000000000..0c3a40bbf3 --- /dev/null +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintPy.xml @@ -0,0 +1,23 @@ + + + + + + This is the ViewProviderFemConstraint class + + + + A pivy SoSeparator with the nodes of the constraint symbols + + + + + diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintPyImp.cpp b/src/Mod/Fem/Gui/ViewProviderFemConstraintPyImp.cpp new file mode 100644 index 0000000000..8117daf4c8 --- /dev/null +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintPyImp.cpp @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +/*************************************************************************** + * Copyright (c) 2024 Mario Passaglia * + * * + * 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 +#endif + +#include + +#include "ViewProviderFemConstraintPy.h" +#include "ViewProviderFemConstraintPy.cpp" + + +using namespace FemGui; + +// returns a string which represent the object e.g. when printed in python +std::string ViewProviderFemConstraintPy::representation() const +{ + std::stringstream str; + str << ""; + + return str.str(); +} + + +Py::Object ViewProviderFemConstraintPy::getSymbolNode() const +{ + try { + SoSeparator* sep = getViewProviderFemConstraintPtr()->getSymbolSeparator(); + PyObject* Ptr = + Base::Interpreter().createSWIGPointerObj("pivy.coin", "_p_SoSeparator", sep, 1); + + sep->ref(); + + return Py::Object(Ptr, true); + } + catch (const Base::Exception& e) { + throw Py::RuntimeError(e.what()); + } +} + +PyObject* ViewProviderFemConstraintPy::getCustomAttributes(const char* /*attr*/) const +{ + return nullptr; +} + +int ViewProviderFemConstraintPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +}