Skip to content

Commit 5ce5c5c

Browse files
Merge branch 'master' into wip-add-binding_mapping
2 parents 6a8cc8f + 1219430 commit 5ce5c5c

14 files changed

+389
-3
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,15 @@ jobs:
224224
binary_status=$([ '${{ steps.gen-artifact.outcome }}' == 'success' ] && \
225225
[ '${{ steps.install-artifact.outcome }}' == 'success' ] && \
226226
echo 'true' || echo 'false')
227+
228+
os=$(echo "${{ matrix.os }}" | awk -F- '{ print $1 }')
227229
228230
229231
curl -X POST -H "X-API-KEY: $DASH_AUTH" -H "Content-Type: application/json" -d \
230232
"{\"id\":\"$(echo "${{ github.repository }}" | awk -F/ '{ print $2 }')\",\
231233
\"github_ref\":\"${{ github.sha }}\",\
232234
\"url\":\"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\",\
235+
\"os\":\"$os\",\
233236
\"build\":$build_status,\
234237
\"tests\":$test_status,\
235238
\"binary\":$binary_status}"\

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_BaseData.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@ std::unique_ptr<DataContainerContext> writeableArray(BaseData* self)
112112
return nullptr;
113113
}
114114

115-
void __setattr__(py::object self, const std::string& s, py::object value)
115+
py::object getValue(py::object self)
116+
{
117+
return PythonFactory::valueToPython_ro(py::cast<BaseData*>(self));
118+
}
119+
120+
void setValue(py::object self, py::object value)
116121
{
117-
SOFA_UNUSED(s);
118122
BaseData* selfdata = py::cast<BaseData*>(self);
119123

120124
if(py::isinstance<DataContainer>(value))
@@ -132,14 +136,20 @@ void __setattr__(py::object self, const std::string& s, py::object value)
132136
BindingBase::SetAttr(py::cast(selfdata->getOwner()),selfdata->getName(),value);
133137
}
134138

139+
void __setattr__(py::object self, const std::string& s, py::object value)
140+
{
141+
SOFA_UNUSED(s);
142+
setValue(self, value);
143+
}
144+
135145
py::object __getattr__(py::object self, const std::string& s)
136146
{
137147
/// If this is data.value we returns the content value of the data field converted into
138148
/// a python object that is easy to manipulate. The conversion is done with the toPython
139149
/// function.
140150
if(s == "value")
141151
{
142-
return PythonFactory::valueToPython_ro(py::cast<BaseData*>(self));
152+
return getValue(self);
143153
}
144154

145155
if(s == "linkpath")
@@ -150,6 +160,8 @@ py::object __getattr__(py::object self, const std::string& s)
150160
throw py::attribute_error("There is no attribute '"+s+"'");
151161
}
152162

163+
164+
153165
void setParent(BaseData* self, BaseData* parent)
154166
{
155167
self->setParent(parent);
@@ -211,6 +223,8 @@ void moduleAddBaseData(py::module& m)
211223
data.def("getName", [](BaseData& b){ return b.getName(); }, sofapython3::doc::baseData::getName);
212224
data.def("setName", [](BaseData& b, const std::string& s){ b.setName(s); }, sofapython3::doc::baseData::setName);
213225
data.def("getCounter", [](BaseData& self) { return self.getCounter(); }, sofapython3::doc::baseData::getCounter);
226+
data.def("setValue", setValue);
227+
data.def("getValue", getValue);
214228
data.def("getHelp", &BaseData::getHelp, sofapython3::doc::baseData::getHelp);
215229
data.def("unset", [](BaseData& b){ b.unset(); }, sofapython3::doc::baseData::unset);
216230
data.def("getOwner", &getOwner, sofapython3::doc::baseData::getOwner);

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <pybind11/numpy.h>
2323

2424
#include <sofa/simulation/Simulation.h>
25+
#include <sofa/simulation/mechanicalvisitor/MechanicalComputeEnergyVisitor.h>
2526
#include <sofa/core/ComponentNameHelper.h>
2627

2728
#include <sofa/core/objectmodel/BaseData.h>
@@ -606,6 +607,15 @@ void sendEvent(Node* self, py::object pyUserData, char* eventName)
606607
self->propagateEvent(sofa::core::execparams::defaultInstance(), &event);
607608
}
608609

610+
py::object computeEnergy(Node* self)
611+
{
612+
sofa::simulation::mechanicalvisitor::MechanicalComputeEnergyVisitor energyVisitor(sofa::core::mechanicalparams::defaultInstance());
613+
energyVisitor.execute(self->getContext());
614+
const SReal kineticEnergy = energyVisitor.getKineticEnergy();
615+
const SReal potentialEnergy = energyVisitor.getPotentialEnergy();
616+
return py::cast(std::make_tuple(kineticEnergy, potentialEnergy));
617+
}
618+
609619
}
610620

611621
void moduleAddNode(py::module &m) {
@@ -660,6 +670,7 @@ void moduleAddNode(py::module &m) {
660670
p.def("getMechanicalState", &getMechanicalState, sofapython3::doc::sofa::core::Node::getMechanicalState);
661671
p.def("getMechanicalMapping", &getMechanicalMapping, sofapython3::doc::sofa::core::Node::getMechanicalMapping);
662672
p.def("sendEvent", &sendEvent, sofapython3::doc::sofa::core::Node::sendEvent);
673+
p.def("computeEnergy", &computeEnergy, sofapython3::doc::sofa::core::Node::computeEnergy);
663674

664675
}
665676
} /// namespace sofapython3

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node_doc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@ static auto sendEvent =
397397
:type pyUserData: py::object
398398
:type eventName: string
399399
)";
400+
static auto computeEnergy =
401+
R"(
402+
Returns the tuple (kineticEnergy, potentialEnergy)
403+
)";
400404

401405
}
402406

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/******************************************************************************
2+
* SofaPython3 plugin *
3+
* (c) 2021 CNRS, University of Lille, INRIA *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Contact information: contact@sofa-framework.org *
19+
******************************************************************************/
20+
#include <SofaPython3/Sofa/Simulation/Binding_SceneCheck.h>
21+
#include <SofaPython3/Sofa/Simulation/Binding_SceneCheck_doc.h>
22+
#include <sofa/simulation/SceneCheck.h>
23+
24+
namespace sofapython3
25+
{
26+
27+
namespace py { using namespace pybind11; }
28+
29+
void moduleAddSceneCheck(pybind11::module &m)
30+
{
31+
// create a python binding for the C++ class LinearSpring from SofaDeformable
32+
py::class_<sofa::simulation::SceneCheck, std::shared_ptr<sofa::simulation::SceneCheck>> s
33+
(m, "SceneCheck", sofapython3::doc::simulation::SceneCheckClass);
34+
35+
s.def("getName", &sofa::simulation::SceneCheck::getName, sofapython3::doc::simulation::SceneCheck_getName);
36+
s.def("getDesc", &sofa::simulation::SceneCheck::getDesc, sofapython3::doc::simulation::SceneCheck_getDesc);
37+
}
38+
39+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/******************************************************************************
2+
* SofaPython3 plugin *
3+
* (c) 2021 CNRS, University of Lille, INRIA *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Contact information: contact@sofa-framework.org *
19+
******************************************************************************/
20+
#pragma once
21+
22+
#include <pybind11/pybind11.h>
23+
24+
namespace sofapython3 {
25+
26+
void moduleAddSceneCheck(pybind11::module& m);
27+
28+
} // namespace sofapython3
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/******************************************************************************
2+
* SofaPython3 plugin *
3+
* (c) 2021 CNRS, University of Lille, INRIA *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Contact information: contact@sofa-framework.org *
19+
******************************************************************************/
20+
#include <SofaPython3/Sofa/Simulation/Binding_SceneCheckMainRegistry.h>
21+
#include <SofaPython3/Sofa/Simulation/Binding_SceneCheckMainRegistry_doc.h>
22+
#include <sofa/simulation/SceneCheckMainRegistry.h>
23+
#include <pybind11/stl.h>
24+
25+
namespace sofapython3
26+
{
27+
28+
namespace py { using namespace pybind11; }
29+
30+
void moduleAddSceneCheckMainRegistry(pybind11::module &m)
31+
{
32+
py::class_<sofa::simulation::SceneCheckMainRegistry> registry (m, "SceneCheckMainRegistry",
33+
sofapython3::doc::simulation::SceneCheckMainRegistryClass);
34+
35+
registry.def_static("getRegisteredSceneChecks",
36+
[]() {
37+
return std::vector(sofa::simulation::SceneCheckMainRegistry::getRegisteredSceneChecks());
38+
},
39+
sofapython3::doc::simulation::SceneCheckMainRegistry_getRegisteredSceneChecks);
40+
}
41+
42+
} // namespace sofapython3
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/******************************************************************************
2+
* SofaPython3 plugin *
3+
* (c) 2021 CNRS, University of Lille, INRIA *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Contact information: contact@sofa-framework.org *
19+
******************************************************************************/
20+
#pragma once
21+
22+
#include <pybind11/pybind11.h>
23+
24+
namespace sofapython3 {
25+
26+
void moduleAddSceneCheckMainRegistry(pybind11::module& m);
27+
28+
} // namespace sofapython3
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/******************************************************************************
2+
* SofaPython3 plugin *
3+
* (c) 2021 CNRS, University of Lille, INRIA *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Contact information: contact@sofa-framework.org *
19+
******************************************************************************/
20+
#pragma once
21+
22+
namespace sofapython3::doc::simulation
23+
{
24+
25+
static auto SceneCheckMainRegistryClass = "The main registry containing verification checks on a scene.";
26+
static auto SceneCheckMainRegistry_getRegisteredSceneChecks = "Returns all the verification checks registered into the main registry.";
27+
28+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/******************************************************************************
2+
* SofaPython3 plugin *
3+
* (c) 2021 CNRS, University of Lille, INRIA *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Contact information: contact@sofa-framework.org *
19+
******************************************************************************/
20+
#pragma once
21+
22+
namespace sofapython3::doc::simulation
23+
{
24+
25+
static auto SceneCheckClass = "A verification check on a scene.";
26+
27+
static auto SceneCheck_getName = "Returns the name of the verification check.";
28+
static auto SceneCheck_getDesc = "Returns the description of the verification check.";
29+
30+
}

0 commit comments

Comments
 (0)