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..32275eef26 100644 --- a/Bindings/Python/swig/python_preliminaries.i +++ b/Bindings/Python/swig/python_preliminaries.i @@ -11,8 +11,7 @@ own project. // Make sure clone does not leak memory %newobject *::clone; -/* This file is for creation/handling of arrays */ -%include "std_carray.i"; +%include "std_container.i" /* This interface file is for better handling of pointers and references */ %include "typemaps.i" @@ -21,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..c596494084 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,6 +175,7 @@ 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); 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 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+" -]+"; 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: 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. */