Skip to content

Commit ea840bc

Browse files
marioalexis84chennes
authored andcommitted
Fem: Expose Constraint view provider symbol node to Python
1 parent c49c527 commit ea840bc

5 files changed

+114
-0
lines changed

src/Mod/Fem/Gui/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ set(FemGui_LIBS
3535
PartGui
3636
)
3737

38+
generate_from_xml(ViewProviderFemConstraintPy)
3839
generate_from_xml(ViewProviderFemMeshPy)
3940
generate_from_xml(ViewProviderFemPostPipelinePy)
4041

4142
SET(Python_SRCS
43+
ViewProviderFemConstraintPy.xml
44+
ViewProviderFemConstraintPyImp.cpp
4245
ViewProviderFemMeshPy.xml
4346
ViewProviderFemMeshPyImp.cpp
4447
ViewProviderFemPostPipelinePy.xml

src/Mod/Fem/Gui/ViewProviderFemConstraint.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
#include "TaskFemConstraint.h"
4949
#include "ViewProviderFemConstraint.h"
50+
#include "ViewProviderFemConstraintPy.h"
5051

5152

5253
using namespace FemGui;
@@ -215,6 +216,15 @@ void ViewProviderFemConstraint::unsetEdit(int ModNum)
215216
}
216217
}
217218
}
219+
220+
PyObject* ViewProviderFemConstraint::getPyObject()
221+
{
222+
if (!pyViewObject) {
223+
pyViewObject = new ViewProviderFemConstraintPy(this);
224+
}
225+
pyViewObject->IncRef();
226+
return pyViewObject;
227+
}
218228
/*
219229
// Create a local coordinate system with the z-axis given in dir
220230
void getLocalCoordinateSystem(const SbVec3f& z, SbVec3f& y, SbVec3f& x)

src/Mod/Fem/Gui/ViewProviderFemConstraint.h

+7
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,17 @@ class FemGuiExport ViewProviderFemConstraint: public Gui::ViewProviderGeometryOb
7272
std::vector<App::DocumentObject*> claimChildren() const override;
7373
void setupContextMenu(QMenu*, QObject*, const char*) override;
7474

75+
PyObject* getPyObject() override;
76+
7577
/// Highlight the references that have been selected
7678
virtual void highlightReferences(const bool /* on */)
7779
{}
7880

81+
SoSeparator* getSymbolSeparator() const
82+
{
83+
return pShapeSep;
84+
}
85+
7986
static std::string gethideMeshShowPartStr();
8087
static std::string gethideMeshShowPartStr(const std::string showConstr);
8188

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
3+
<PythonExport
4+
Father="ViewProviderDocumentObjectPy"
5+
Name="ViewProviderFemConstraintPy"
6+
Twin="ViewProviderFemConstraint"
7+
TwinPointer="ViewProviderFemConstraint"
8+
Include="Mod/Fem/Gui/ViewProviderFemConstraint.h"
9+
Namespace="FemGui"
10+
FatherInclude="Gui/ViewProviderDocumentObjectPy.h"
11+
FatherNamespace="Gui">
12+
<Documentation>
13+
<Author Licence="LGPL" Name="Mario Passaglia" EMail="[email protected]" />
14+
<UserDocu>This is the ViewProviderFemConstraint class</UserDocu>
15+
</Documentation>
16+
<Attribute Name="SymbolNode" ReadOnly="true">
17+
<Documentation>
18+
<UserDocu>A pivy SoSeparator with the nodes of the constraint symbols</UserDocu>
19+
</Documentation>
20+
<Parameter Name="SymbolNode" Type="Object" />
21+
</Attribute>
22+
</PythonExport>
23+
</GenerateModel>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// SPDX-License-Identifier: LGPL-2.1-or-later
2+
3+
/***************************************************************************
4+
* Copyright (c) 2024 Mario Passaglia <mpassaglia[at]cbc.uba.ar> *
5+
* *
6+
* This file is part of FreeCAD. *
7+
* *
8+
* FreeCAD is free software: you can redistribute it and/or modify it *
9+
* under the terms of the GNU Lesser General Public License as *
10+
* published by the Free Software Foundation, either version 2.1 of the *
11+
* License, or (at your option) any later version. *
12+
* *
13+
* FreeCAD is distributed in the hope that it will be useful, but *
14+
* WITHOUT ANY WARRANTY; without even the implied warranty of *
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16+
* Lesser General Public License for more details. *
17+
* *
18+
* You should have received a copy of the GNU Lesser General Public *
19+
* License along with FreeCAD. If not, see *
20+
* <https://www.gnu.org/licenses/>. *
21+
* *
22+
**************************************************************************/
23+
24+
#include "PreCompiled.h"
25+
#ifndef _PreComp_
26+
#include <Inventor/nodes/SoSeparator.h>
27+
#endif
28+
29+
#include <Base/Interpreter.h>
30+
31+
#include "ViewProviderFemConstraintPy.h"
32+
#include "ViewProviderFemConstraintPy.cpp"
33+
34+
35+
using namespace FemGui;
36+
37+
// returns a string which represent the object e.g. when printed in python
38+
std::string ViewProviderFemConstraintPy::representation() const
39+
{
40+
std::stringstream str;
41+
str << "<View provider FemConstraint object at " << getViewProviderFemConstraintPtr() << ">";
42+
43+
return str.str();
44+
}
45+
46+
47+
Py::Object ViewProviderFemConstraintPy::getSymbolNode() const
48+
{
49+
try {
50+
SoSeparator* sep = getViewProviderFemConstraintPtr()->getSymbolSeparator();
51+
PyObject* Ptr =
52+
Base::Interpreter().createSWIGPointerObj("pivy.coin", "_p_SoSeparator", sep, 1);
53+
54+
sep->ref();
55+
56+
return Py::Object(Ptr, true);
57+
}
58+
catch (const Base::Exception& e) {
59+
throw Py::RuntimeError(e.what());
60+
}
61+
}
62+
63+
PyObject* ViewProviderFemConstraintPy::getCustomAttributes(const char* /*attr*/) const
64+
{
65+
return nullptr;
66+
}
67+
68+
int ViewProviderFemConstraintPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
69+
{
70+
return 0;
71+
}

0 commit comments

Comments
 (0)