Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support swig 42 #3777

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 6 additions & 2 deletions Bindings/Python/swig/python_preliminaries.i
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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+;
Expand Down
5 changes: 3 additions & 2 deletions Bindings/Python/swig/python_simulation.i
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ MODEL_ADOPT_HELPER(Controller);

// TODO remove.
%rename(_getBetween) OpenSim::StatesTrajectory::getBetween;

/*
%extend OpenSim::StatesTrajectory {
%pythoncode %{

Expand All @@ -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:
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion Bindings/simulation.i
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,13 @@ OpenSim::ModelComponentSet<OpenSim::Controller>;
%include <OpenSim/Simulation/OpenSense/OpenSenseUtilities.h>

%template(StdVectorIMUs) std::vector< OpenSim::IMU* >;

/*
%include <OpenSim/Simulation/StatesTrajectory.h>
// This enables iterating using the getBetween() method.

%template(IteratorRangeStatesTrajectoryIterator)
SimTK::IteratorRange<OpenSim::StatesTrajectory::const_iterator>;
*/
%include <OpenSim/Simulation/StatesTrajectoryReporter.h>
%include <OpenSim/Simulation/PositionMotion.h>
%include <OpenSim/Simulation/SimulationUtilities.h>
Expand Down
4 changes: 2 additions & 2 deletions OpenSim/Common/DelimFileAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ DelimFileAdapter<T>::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+" -]+";
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Moco/MocoUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ OSIMMOCO_API MocoTrajectory createPeriodicTrajectory(
".*pelvis_tz/value",
".*lumbar_bending/value"},
std::vector<std::pair<std::string, std::string>> 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:
Expand Down
6 changes: 3 additions & 3 deletions OpenSim/Simulation/StatesTrajectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<SimTK::State>::const_iterator const_iterator;

#ifndef SWIG
/** A helper type to allow using range for loops over a subset of the
* trajectory. */
typedef SimTK::IteratorRange<const_iterator> IteratorRange;
Expand All @@ -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. */
Expand Down
Loading