Skip to content

Commit 677458f

Browse files
committed
Merge remote-tracking branch 'upstream/master' into stiffnessmassmatrix
2 parents 96ed9f5 + b6042b7 commit 677458f

7 files changed

Lines changed: 97 additions & 27 deletions

File tree

bindings/Modules/src/SofaPython3/SofaDeformable/Binding_SpringForceField.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,13 @@ void bindSpringForcefield(py::module& m) {
101101
});
102102
}
103103

104-
void moduleAddSpringForceField(py::module& m) {
105-
bindSpringForcefield<sofa::defaulttype::Vec3dTypes>(m);
106-
bindSpringForcefield<sofa::defaulttype::Vec6dTypes>(m);
104+
void moduleAddSpringForceField(py::module& m)
105+
{
106+
bindSpringForcefield<sofa::defaulttype::Vec3Types>(m);
107+
bindSpringForcefield<sofa::defaulttype::Vec2Types>(m);
108+
bindSpringForcefield<sofa::defaulttype::Vec1Types>(m);
109+
bindSpringForcefield<sofa::defaulttype::Vec6Types>(m);
110+
bindSpringForcefield<sofa::defaulttype::Rigid3Types>(m);
107111
}
112+
108113
} // namespace sofapython3

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ void Controller_Trampoline::reinit()
6464
void Controller_Trampoline::callScriptMethod(
6565
const py::object& self, Event* event, const std::string & methodName)
6666
{
67+
if(f_printLog.getValue())
68+
{
69+
std::string name = std::string("on")+event->getClassName();
70+
std::string eventStr = py::str(PythonFactory::toPython(event));
71+
msg_info() << name << " " << eventStr;
72+
}
73+
6774
if( py::hasattr(self, methodName.c_str()) )
6875
{
6976
py::object fct = self.attr(methodName.c_str());

bindings/SofaGui/Bindings.SofaGuiConfig.cmake.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ find_package(SofaPython3 QUIET REQUIRED COMPONENTS Plugin Bindings.Sofa)
77

88
find_package(Sofa.GL QUIET REQUIRED)
99
find_package(Sofa.Core QUIET REQUIRED)
10-
find_package(SofaGuiCommon QUIET REQUIRED)
1110
find_package(SofaGui QUIET REQUIRED)
1211

1312
# If we are importing this config file and the target is not yet there this is indicating that

bindings/SofaGui/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ SP3_add_python_module(
2121
DESTINATION Sofa
2222
SOURCES ${SOURCE_FILES}
2323
HEADERS ${HEADER_FILES}
24-
DEPENDS Sofa.Core SofaGuiCommon SofaGui SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core
24+
DEPENDS Sofa.Core SofaGui SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core
2525
)
2626

2727
sofa_create_component_in_package_with_targets(

bindings/SofaGui/src/SofaPython3/SofaGui/Binding_BaseGui.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@
2020

2121
#include "Binding_BaseGui.h"
2222

23-
#include <sofa/gui/BaseGUI.h>
23+
#include <sofa/gui/common/BaseGUI.h>
2424

2525
namespace py = pybind11;
2626

2727
namespace sofapython3 {
28-
using sofa::gui::BaseGUI;
28+
using sofa::gui::common::BaseGUI;
2929
using sofa::simulation::Node;
3030

3131
void moduleAddBaseGui(py::module& m)
3232
{
33-
py::class_<sofa::gui::BaseGUI, std::unique_ptr<sofa::gui::BaseGUI, py::nodelete>> baseGUI(m, "BaseGUI");
33+
py::class_<sofa::gui::common::BaseGUI, std::unique_ptr<sofa::gui::common::BaseGUI, py::nodelete>> baseGUI(m, "BaseGUI");
3434

3535
/*
3636
* Sofa.Gui.BaseGUI.SetBackgroundImage
@@ -41,8 +41,8 @@ void moduleAddBaseGui(py::module& m)
4141
:param filename: Path to the image which will become the background of the viewer.
4242
:type filename: str
4343
)doc";
44-
baseGUI.def("setBackgroundImage", &sofa::gui::BaseGUI::setBackgroundImage, SetBackgroundImageDoc);
44+
baseGUI.def("setBackgroundImage", &sofa::gui::common::BaseGUI::setBackgroundImage, SetBackgroundImageDoc);
4545

4646
}
4747

48-
} // namespace sofapython3
48+
} // namespace sofapython3

bindings/SofaGui/src/SofaPython3/SofaGui/Binding_GUIManager.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include <pybind11/stl.h>
2222

2323
#include <SofaPython3/SofaGui/Binding_GUIManager.h>
24-
#include <sofa/gui/GUIManager.h>
25-
#include <sofa/gui/BaseGUI.h>
24+
#include <sofa/gui/common/GUIManager.h>
25+
#include <sofa/gui/common/BaseGUI.h>
2626
#include <sofa/simulation/Node.h>
2727

2828
/// Makes an alias for the pybind11 namespace to increase readability.
@@ -32,7 +32,7 @@ namespace sofapython3 {
3232

3333
void moduleAddGuiManager(py::module& m)
3434
{
35-
py::class_<sofa::gui::GUIManager> guiManager(m, "GUIManager");
35+
py::class_<sofa::gui::common::GUIManager> guiManager(m, "GUIManager");
3636

3737
/*
3838
* Sofa.Gui.GUIManager.ListSupportedGUI
@@ -45,8 +45,8 @@ void moduleAddGuiManager(py::module& m)
4545
:return: A string containing each available GUIs. If the parameter 'separator' is omitted, a list containing the
4646
available GUIs is returned instead of a string.
4747
)doc";
48-
guiManager.def_static("ListSupportedGUI", py::overload_cast<>(&sofa::gui::GUIManager::ListSupportedGUI), listSupportedGUIDoc);
49-
guiManager.def_static("ListSupportedGUI", py::overload_cast<char>(&sofa::gui::GUIManager::ListSupportedGUI), listSupportedGUIDoc );
48+
guiManager.def_static("ListSupportedGUI", py::overload_cast<>(&sofa::gui::common::GUIManager::ListSupportedGUI), listSupportedGUIDoc);
49+
guiManager.def_static("ListSupportedGUI", py::overload_cast<char>(&sofa::gui::common::GUIManager::ListSupportedGUI), listSupportedGUIDoc );
5050

5151

5252
/*
@@ -60,7 +60,7 @@ void moduleAddGuiManager(py::module& m)
6060
:param gui_name: The name of the GUI used. See Sofa.Gui.GUIManager.ListSupportedGUI(). (optional)
6161
:type gui_name: str
6262
)doc";
63-
guiManager.def_static("Init", &sofa::gui::GUIManager::Init, py::arg("program_name"), py::arg("gui_name") = "", initDoc);
63+
guiManager.def_static("Init", &sofa::gui::common::GUIManager::Init, py::arg("program_name"), py::arg("gui_name") = "", initDoc);
6464

6565

6666
/*
@@ -76,10 +76,10 @@ void moduleAddGuiManager(py::module& m)
7676
:return: 0 if the GUI creation succeed, 1 otherwise
7777
)doc";
7878
guiManager.def_static("createGUI", [](sofa::simulation::Node & node, const std::string & filename) -> int {
79-
return sofa::gui::GUIManager::createGUI(&node, filename.c_str());
79+
return sofa::gui::common::GUIManager::createGUI(&node, filename.c_str());
8080
}, createGUIDoc);
8181
guiManager.def_static("createGUI", [](sofa::simulation::Node & node) -> int {
82-
return sofa::gui::GUIManager::createGUI(&node);
82+
return sofa::gui::common::GUIManager::createGUI(&node);
8383
}, createGUIDoc);
8484

8585

@@ -89,7 +89,7 @@ void moduleAddGuiManager(py::module& m)
8989
const auto closeGUIDoc = R"doc(
9090
Close the current GUI.
9191
)doc";
92-
guiManager.def_static("closeGUI", &sofa::gui::GUIManager::closeGUI, closeGUIDoc);
92+
guiManager.def_static("closeGUI", &sofa::gui::common::GUIManager::closeGUI, closeGUIDoc);
9393

9494

9595
/*
@@ -106,7 +106,7 @@ void moduleAddGuiManager(py::module& m)
106106
:type temporaryFile: bool
107107
)doc";
108108
guiManager.def_static("SetScene", [](sofa::simulation::Node & node, const char * filename = nullptr, bool temporaryFile = false) {
109-
sofa::gui::GUIManager::SetScene(&node, filename, temporaryFile);
109+
sofa::gui::common::GUIManager::SetScene(&node, filename, temporaryFile);
110110
}, py::arg("root"), py::arg("filename") = nullptr, py::arg("temporaryFile") = false, setSceneDoc);
111111

112112

@@ -125,10 +125,10 @@ void moduleAddGuiManager(py::module& m)
125125
:return: 0 if the main loop succeed, 1 otherwise
126126
)doc";
127127
guiManager.def_static("MainLoop", [](sofa::simulation::Node & node, const std::string & filename) -> int {
128-
return sofa::gui::GUIManager::MainLoop(&node, filename.c_str());
128+
return sofa::gui::common::GUIManager::MainLoop(&node, filename.c_str());
129129
}, mainLoopDoc);
130130
guiManager.def_static("MainLoop", [](sofa::simulation::Node & node) -> int {
131-
return sofa::gui::GUIManager::MainLoop(&node);
131+
return sofa::gui::common::GUIManager::MainLoop(&node);
132132
}, mainLoopDoc);
133133

134134

@@ -145,7 +145,7 @@ void moduleAddGuiManager(py::module& m)
145145
:param height:
146146
:type height: int
147147
)doc";
148-
guiManager.def_static("SetDimension", &sofa::gui::GUIManager::SetDimension, setDimensionDoc);
148+
guiManager.def_static("SetDimension", &sofa::gui::common::GUIManager::SetDimension, setDimensionDoc);
149149

150150

151151
/*
@@ -154,7 +154,7 @@ void moduleAddGuiManager(py::module& m)
154154
const auto SetFullScreenDoc = R"doc(
155155
Set the GUI in full screen mode.
156156
)doc";
157-
guiManager.def_static("SetFullScreen", &sofa::gui::GUIManager::SetFullScreen, SetFullScreenDoc);
157+
guiManager.def_static("SetFullScreen", &sofa::gui::common::GUIManager::SetFullScreen, SetFullScreenDoc);
158158

159159
/*
160160
* Sofa.Gui.GUIManager.SaveScreenshot
@@ -165,15 +165,15 @@ void moduleAddGuiManager(py::module& m)
165165
:param filename: Where to save the screenshot.
166166
:type filename: str
167167
)doc";
168-
guiManager.def_static("SaveScreenshot", &sofa::gui::GUIManager::SaveScreenshot, SaveScreenshotDoc);
168+
guiManager.def_static("SaveScreenshot", &sofa::gui::common::GUIManager::SaveScreenshot, SaveScreenshotDoc);
169169

170170
/*
171171
* Sofa.Gui.GUIManager.GetGUI
172172
*/
173173
const auto GetGUIDoc = R"doc(
174174
Get the current GUI.
175175
)doc";
176-
guiManager.def_static("GetGUI", &sofa::gui::GUIManager::getGUI, GetGUIDoc);
176+
guiManager.def_static("GetGUI", &sofa::gui::common::GUIManager::getGUI, GetGUIDoc);
177177
}
178178

179-
} /// namespace sofapython3
179+
} /// namespace sofapython3

examples/springForceField.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import Sofa
2+
import SofaRuntime
3+
from Sofa import SofaDeformable
4+
5+
6+
def createScene(root):
7+
root.gravity = [0, -9.81, 0]
8+
9+
root.addObject('DefaultAnimationLoop')
10+
root.addObject('DefaultVisualManagerLoop')
11+
12+
surface_node = root.addChild('Surface')
13+
surface_loader = surface_node.addObject('MeshOBJLoader', name='surface_loader', filename='mesh/ball.obj')
14+
15+
root.addObject('EulerImplicitSolver', name='ODE', rayleighStiffness=0.1, rayleighMass=0.1)
16+
root.addObject('CGLinearSolver', name='linear solver', iterations=25, tolerance=1e-08, threshold=1e-08)
17+
18+
ball_0 = add_ball(root, 'ball_0', (-2, 0, 0), surface_loader)
19+
ball_1 = add_ball(root, 'ball_1', (2, 0, 0), surface_loader)
20+
21+
ball_0.addObject('RestShapeSpringsForceField', name='rest_spring', stiffness=1e1, angularStiffness=1e03)
22+
springs = root.addObject('StiffSpringForceField',
23+
object1=ball_0.dofs.getLinkPath(), object2=ball_1.dofs.getLinkPath(),
24+
indices1=[0], indices2=[0],
25+
length=[4], stiffness=2)
26+
27+
root.addObject(KeyPressedController(name='controller', springs=springs))
28+
29+
floor = root.addChild('Floor')
30+
floor_loader = floor.addObject('MeshOBJLoader', name='surface_loader', filename='mesh/floor.obj',
31+
scale3d=[0.2, 0.1, 0.2], translation=[0, -15, 0])
32+
floor.addObject('OglModel', src=floor_loader.getLinkPath())
33+
34+
35+
def add_ball(root, name, position, obj_loader):
36+
ball_node = root.addChild(name)
37+
38+
initial_position = position + (0, 0, 0, 1)
39+
ball_node.addObject('MechanicalObject', name='dofs', template='Rigid3d', position=initial_position)
40+
ball_node.addObject('UniformMass', name='mass', totalMass=1)
41+
ball_node.addObject('PlaneForceField', normal='0 1 0', d='-15', stiffness='10000')
42+
43+
visual_model = ball_node.addChild('visual')
44+
visual_model.addObject('OglModel', src=obj_loader.getLinkPath())
45+
visual_model.addObject('RigidMapping')
46+
47+
return ball_node
48+
49+
50+
class KeyPressedController(Sofa.Core.Controller):
51+
52+
def __init__(self, *args, **kwargs):
53+
Sofa.Core.Controller.__init__(self, *args, **kwargs)
54+
self.springs = kwargs.get('springs')
55+
56+
def onKeypressedEvent(self, event):
57+
if event['key'] == 'L':
58+
print('Remove spring')
59+
self.springs.removeSpring(0)

0 commit comments

Comments
 (0)