From 13f33ddd75a0187d0bd312b1e938a4a086665109 Mon Sep 17 00:00:00 2001 From: aymanhab Date: Fri, 3 May 2024 09:52:32 -0700 Subject: [PATCH 1/5] Allow swig versions 4.1.1+, remove reference to removed std_carray.i, rewrite regular expressions to be digested by later swig version --- Bindings/CMakeLists.txt | 2 +- Bindings/Python/swig/python_preliminaries.i | 3 --- OpenSim/Common/DelimFileAdapter.h | 4 ++-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Bindings/CMakeLists.txt b/Bindings/CMakeLists.txt index 4854f4dffd..afe43ffc3a 100644 --- a/Bindings/CMakeLists.txt +++ b/Bindings/CMakeLists.txt @@ -1,5 +1,5 @@ if(BUILD_PYTHON_WRAPPING OR BUILD_JAVA_WRAPPING) - find_package(SWIG 4.1.1 EXACT REQUIRED) + find_package(SWIG 4.1.1 REQUIRED) endif() # Flags are both Python and Java bindings will use. diff --git a/Bindings/Python/swig/python_preliminaries.i b/Bindings/Python/swig/python_preliminaries.i index 74c349d0c1..1c1c03aa71 100644 --- a/Bindings/Python/swig/python_preliminaries.i +++ b/Bindings/Python/swig/python_preliminaries.i @@ -11,9 +11,6 @@ own project. // Make sure clone does not leak memory %newobject *::clone; -/* This file is for creation/handling of arrays */ -%include "std_carray.i"; - /* This interface file is for better handling of pointers and references */ %include "typemaps.i" %include "std_string.i" diff --git a/OpenSim/Common/DelimFileAdapter.h b/OpenSim/Common/DelimFileAdapter.h index 1224ef2034..6fbc3938b9 100644 --- a/OpenSim/Common/DelimFileAdapter.h +++ b/OpenSim/Common/DelimFileAdapter.h @@ -321,8 +321,8 @@ DelimFileAdapter::extendRead(const std::string& fileName) const { size_t line_num{}; // All the lines until "endheader" is header. - std::regex endheader{R"([ \t]*)" + _endHeaderString + R"([ \t]*)"}; - std::regex keyvalue{R"((.*)=(.*))"}; + std::regex endheader {"[ \t]*" + _endHeaderString + "[ \t]*"}; + std::regex keyvalue{"(.*)=(.*)"}; std::string header{}; std::string line{}; std::string numberOrDelim = "[0-9][0-9."+_delimitersRead+" -]+"; From b780629b4c0b9e0980712ed4e2e751d9dfc9b9a0 Mon Sep 17 00:00:00 2001 From: aymanhab Date: Fri, 3 May 2024 11:06:54 -0700 Subject: [PATCH 2/5] rewrite another regex to not use R syntax --- OpenSim/Moco/MocoUtilities.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSim/Moco/MocoUtilities.h b/OpenSim/Moco/MocoUtilities.h index 8955c53384..0c42496465 100644 --- a/OpenSim/Moco/MocoUtilities.h +++ b/OpenSim/Moco/MocoUtilities.h @@ -155,7 +155,7 @@ OSIMMOCO_API MocoTrajectory createPeriodicTrajectory( ".*pelvis_tz/value", ".*lumbar_bending/value"}, std::vector> symmetryPatterns = - {{R"(_r(\/|_|$))", "_l$1"}, {R"(_l(\/|_|$))", "_r$1"}}); + {{"_r(/|_|$)", "_l$1"}, {"_l(/|_|$)", "_r$1"}}); /// This obtains the value of the OPENSIM_MOCO_PARALLEL environment variable. /// The value has the following meanings: From cfca373b212d2e366a690a61cb5f08e4e09608ef Mon Sep 17 00:00:00 2001 From: aymanhab Date: Fri, 3 May 2024 12:00:50 -0700 Subject: [PATCH 3/5] include std_container.i to fix compilation errors with swig 4.1.1 --- Bindings/Python/swig/python_preliminaries.i | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Bindings/Python/swig/python_preliminaries.i b/Bindings/Python/swig/python_preliminaries.i index 1c1c03aa71..e0a760a667 100644 --- a/Bindings/Python/swig/python_preliminaries.i +++ b/Bindings/Python/swig/python_preliminaries.i @@ -11,6 +11,8 @@ own project. // Make sure clone does not leak memory %newobject *::clone; +%include "std_container.i" + /* This interface file is for better handling of pointers and references */ %include "typemaps.i" %include "std_string.i" From 13484c39ece8f8aa5c8f95d98bfcd22af2608d32 Mon Sep 17 00:00:00 2001 From: aymanhab Date: Tue, 14 May 2024 12:58:17 -0700 Subject: [PATCH 4/5] Remove StatesTrajectory from python binding and ignore more operators so the resulting code compiles --- Bindings/Python/swig/python_preliminaries.i | 5 +++++ Bindings/Python/swig/python_simulation.i | 6 ++++-- Bindings/simulation.i | 4 +++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Bindings/Python/swig/python_preliminaries.i b/Bindings/Python/swig/python_preliminaries.i index e0a760a667..32275eef26 100644 --- a/Bindings/Python/swig/python_preliminaries.i +++ b/Bindings/Python/swig/python_preliminaries.i @@ -20,6 +20,11 @@ own project. /* If needed %extend will be used, these operators are not supported.*/ %ignore *::operator[]; %ignore *::operator=; +%ignore *::operator==; +%ignore *::operator!=; +%ignore *::operator>; +%ignore *::operator>=; +%ignore *::operator<=; // For reference (doesn't work and should not be necessary): // %rename(__add__) operator+; diff --git a/Bindings/Python/swig/python_simulation.i b/Bindings/Python/swig/python_simulation.i index e98abe2f0f..3088547e4a 100644 --- a/Bindings/Python/swig/python_simulation.i +++ b/Bindings/Python/swig/python_simulation.i @@ -107,7 +107,7 @@ MODEL_ADOPT_HELPER(Controller); // TODO remove. %rename(_getBetween) OpenSim::StatesTrajectory::getBetween; - +/* %extend OpenSim::StatesTrajectory { %pythoncode %{ @@ -129,7 +129,7 @@ MODEL_ADOPT_HELPER(Controller); yield it.next() %} }; - +*/ // TODO we already made a StdVectorState in simbody.i, but this is required // to create type traits for the simulation module. Ideally, we would not need // the following line: @@ -175,8 +175,10 @@ SET_ADOPT_HELPER(Analysis); // Pythonic operators // ================== // Allow indexing operator in python (e.g., states[i]). +/* %extend OpenSim::StatesTrajectory { const SimTK::State& __getitem__(int i) const { return $self->get(i); } }; +*/ \ No newline at end of file diff --git a/Bindings/simulation.i b/Bindings/simulation.i index 906b5d8c64..52c60eae0c 100644 --- a/Bindings/simulation.i +++ b/Bindings/simulation.i @@ -247,11 +247,13 @@ OpenSim::ModelComponentSet; %include %template(StdVectorIMUs) std::vector< OpenSim::IMU* >; - +/* %include // This enables iterating using the getBetween() method. + %template(IteratorRangeStatesTrajectoryIterator) SimTK::IteratorRange; +*/ %include %include %include From 6977507f3772c0c726a3f3d4ba30eb58d6849535 Mon Sep 17 00:00:00 2001 From: aymanhab Date: Tue, 21 May 2024 13:54:08 -0700 Subject: [PATCH 5/5] undo block commented for debugging in .i file and swig out IteratorRange for now --- Bindings/Python/swig/python_simulation.i | 3 +-- OpenSim/Simulation/StatesTrajectory.h | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Bindings/Python/swig/python_simulation.i b/Bindings/Python/swig/python_simulation.i index 3088547e4a..c596494084 100644 --- a/Bindings/Python/swig/python_simulation.i +++ b/Bindings/Python/swig/python_simulation.i @@ -175,10 +175,9 @@ SET_ADOPT_HELPER(Analysis); // Pythonic operators // ================== // Allow indexing operator in python (e.g., states[i]). -/* + %extend OpenSim::StatesTrajectory { const SimTK::State& __getitem__(int i) const { return $self->get(i); } }; -*/ \ No newline at end of file diff --git a/OpenSim/Simulation/StatesTrajectory.h b/OpenSim/Simulation/StatesTrajectory.h index 8a4b265dcf..92cfb08fa3 100644 --- a/OpenSim/Simulation/StatesTrajectory.h +++ b/OpenSim/Simulation/StatesTrajectory.h @@ -185,11 +185,11 @@ class OSIMSIMULATION_API StatesTrajectory { return m_states.back(); } /// @} - + /** Iterator type that does not allow modifying the trajectory. * Most users do not need to understand what this is. */ typedef std::vector::const_iterator const_iterator; - +#ifndef SWIG /** A helper type to allow using range for loops over a subset of the * trajectory. */ typedef SimTK::IteratorRange IteratorRange; @@ -204,7 +204,7 @@ class OSIMSIMULATION_API StatesTrajectory { * class in a range for loop. */ const_iterator end() const { return m_states.cend(); } /// @} - +#endif /// @name Modify the contents of the trajectory /// @{ /** Clear all the states in the trajectory. */