From c383f64758d2157930d660e2e1931552405777f4 Mon Sep 17 00:00:00 2001 From: Nicholas Bianco Date: Wed, 30 Aug 2023 10:04:46 -0700 Subject: [PATCH] Rule of five; more code clean up --- OpenSim/Actuators/ModelFactory.cpp | 3 +-- OpenSim/Simulation/Model/AbstractPath.cpp | 6 +++++- OpenSim/Simulation/Model/AbstractPath.h | 7 +++++-- OpenSim/Simulation/Model/Blankevoort1991Ligament.h | 2 +- OpenSim/Simulation/Model/Ligament.h | 2 +- OpenSim/Simulation/Model/Muscle.h | 4 ++-- OpenSim/Simulation/Model/PathActuator.h | 2 +- OpenSim/Simulation/Model/PathSpring.h | 2 +- OpenSim/Tests/Wrapping/testWrapCylinder.cpp | 2 +- 9 files changed, 18 insertions(+), 12 deletions(-) diff --git a/OpenSim/Actuators/ModelFactory.cpp b/OpenSim/Actuators/ModelFactory.cpp index a3a94c9d03..340e7d8609 100644 --- a/OpenSim/Actuators/ModelFactory.cpp +++ b/OpenSim/Actuators/ModelFactory.cpp @@ -173,8 +173,7 @@ void ModelFactory::replaceMusclesWithPathActuators(OpenSim::Model &model) { model.addForce(actu); // Copy the muscle's path. - AbstractPath& path = musc.updPath(); - if (auto* pGeometryPath = dynamic_cast(&path)) { + if (auto* pGeometryPath = musc.tryUpdPath()) { GeometryPath& thisGeometryPath = actu->initGeometryPath(); // For the connectee names in the PathPoints to be correct, we must diff --git a/OpenSim/Simulation/Model/AbstractPath.cpp b/OpenSim/Simulation/Model/AbstractPath.cpp index 839a5e7744..591d4eef49 100644 --- a/OpenSim/Simulation/Model/AbstractPath.cpp +++ b/OpenSim/Simulation/Model/AbstractPath.cpp @@ -40,6 +40,10 @@ AbstractPath::~AbstractPath() noexcept = default; AbstractPath& AbstractPath::operator=(const AbstractPath&) = default; +AbstractPath::AbstractPath(AbstractPath&& other) noexcept = default; + +AbstractPath& AbstractPath::operator=(AbstractPath&& other) noexcept = default; + // DEFAULTED METHODS const SimTK::Vec3& AbstractPath::getDefaultColor() const { @@ -61,4 +65,4 @@ void AbstractPath::setPreScaleLength(const SimTK::State&, double preScaleLength) { _preScaleLength = preScaleLength; -} \ No newline at end of file +} diff --git a/OpenSim/Simulation/Model/AbstractPath.h b/OpenSim/Simulation/Model/AbstractPath.h index ac687464c1..4ecca0c14f 100644 --- a/OpenSim/Simulation/Model/AbstractPath.h +++ b/OpenSim/Simulation/Model/AbstractPath.h @@ -77,10 +77,13 @@ OpenSim_DECLARE_ABSTRACT_OBJECT(AbstractPath, ModelComponent); // METHODS //============================================================================= AbstractPath(); - AbstractPath(const AbstractPath&); ~AbstractPath() noexcept; - + + AbstractPath(const AbstractPath&); AbstractPath& operator=(const AbstractPath&); + + AbstractPath(AbstractPath&& other) noexcept; + AbstractPath& operator=(AbstractPath&& other) noexcept; // INTERFACE METHODS // diff --git a/OpenSim/Simulation/Model/Blankevoort1991Ligament.h b/OpenSim/Simulation/Model/Blankevoort1991Ligament.h index 62797fcb93..13ac46a6b2 100644 --- a/OpenSim/Simulation/Model/Blankevoort1991Ligament.h +++ b/OpenSim/Simulation/Model/Blankevoort1991Ligament.h @@ -236,7 +236,7 @@ OpenSim_DECLARE_CONCRETE_OBJECT(Blankevoort1991Ligament, Force) double linear_stiffness, double slack_length); // Path - bool hasPath() const override { return true;}; + bool hasPath() const override { return true; }; AbstractPath& updPath() { return upd_path(); } const AbstractPath& getPath() const { return get_path(); } diff --git a/OpenSim/Simulation/Model/Ligament.h b/OpenSim/Simulation/Model/Ligament.h index 23e91dda48..f6da52bc22 100644 --- a/OpenSim/Simulation/Model/Ligament.h +++ b/OpenSim/Simulation/Model/Ligament.h @@ -74,7 +74,7 @@ OpenSim_DECLARE_CONCRETE_OBJECT(Ligament, Force); //-------------------------------------------------------------------------- // PATH //-------------------------------------------------------------------------- - bool hasPath() const override { return true;}; + bool hasPath() const override { return true; }; AbstractPath& updPath() { return upd_path(); } const AbstractPath& getPath() const { return get_path(); } diff --git a/OpenSim/Simulation/Model/Muscle.h b/OpenSim/Simulation/Model/Muscle.h index 6f35d27fef..bbcec228dc 100644 --- a/OpenSim/Simulation/Model/Muscle.h +++ b/OpenSim/Simulation/Model/Muscle.h @@ -430,7 +430,7 @@ OpenSim_DECLARE_ABSTRACT_OBJECT(Muscle, PathActuator); /** Potential energy stored by the muscle */ double computePotentialEnergy(const SimTK::State& state) const override; - + /** Override PathActuator virtual to calculate a preferred color for the muscle path based on activation. **/ SimTK::Vec3 computePathColor(const SimTK::State& state) const override; @@ -440,7 +440,7 @@ OpenSim_DECLARE_ABSTRACT_OBJECT(Muscle, PathActuator); void extendAddToSystem(SimTK::MultibodySystem& system) const override; void extendSetPropertiesFromState(const SimTK::State &s) override; void extendInitStateFromProperties(SimTK::State& state) const override; - + // Update the display geometry attached to the muscle virtual void updateGeometry(const SimTK::State& s); // End of Interfaces imposed by parent classes. diff --git a/OpenSim/Simulation/Model/PathActuator.h b/OpenSim/Simulation/Model/PathActuator.h index f634a9e669..a85a9370c0 100644 --- a/OpenSim/Simulation/Model/PathActuator.h +++ b/OpenSim/Simulation/Model/PathActuator.h @@ -66,7 +66,7 @@ class OSIMSIMULATION_API PathActuator : public ScalarActuator { // GET AND SET //-------------------------------------------------------------------------- // Path - bool hasPath() const override { return true;}; + bool hasPath() const override { return true; }; AbstractPath& updPath() { return upd_path(); } const AbstractPath& getPath() const { return get_path(); } diff --git a/OpenSim/Simulation/Model/PathSpring.h b/OpenSim/Simulation/Model/PathSpring.h index cdbd1eecc1..bb5f466406 100644 --- a/OpenSim/Simulation/Model/PathSpring.h +++ b/OpenSim/Simulation/Model/PathSpring.h @@ -117,7 +117,7 @@ OpenSim_DECLARE_CONCRETE_OBJECT(PathSpring, Force); void setDissipation(double dissipation); /** get/set the path object */ - bool hasPath() const override { return true;}; + bool hasPath() const override { return true; }; AbstractPath& updPath() { return upd_path(); } const AbstractPath& getPath() const { return get_path(); } diff --git a/OpenSim/Tests/Wrapping/testWrapCylinder.cpp b/OpenSim/Tests/Wrapping/testWrapCylinder.cpp index 30030e712d..5d01272b8c 100644 --- a/OpenSim/Tests/Wrapping/testWrapCylinder.cpp +++ b/OpenSim/Tests/Wrapping/testWrapCylinder.cpp @@ -452,7 +452,7 @@ namespace { // Trigger computing the wrapping path (realizing the state will not). model.getComponent("spring").getLength(state); const WrapResult wrapResult = model.getComponent("spring") - .getPath() + .getGeometryPath() .getWrapSet() .get("pathwrap") .getPreviousWrap();