1 #ifndef OPENSIM_MODEL_COMPONENT_SET_H 2 #define OPENSIM_MODEL_COMPONENT_SET_H 3 /* -------------------------------------------------------------------------- * 4 * OpenSim: ModelComponentSet.h * 5 * -------------------------------------------------------------------------- * 6 * The OpenSim API is a toolkit for musculoskeletal modeling and simulation. * 7 * See http://opensim.stanford.edu and the NOTICE file for more information. * 8 * OpenSim is developed at Stanford University and supported by the US * 9 * National Institutes of Health (U54 GM072970, R24 HD065690) and by DARPA * 10 * through the Warrior Web program. * 11 * * 12 * Copyright (c) 2005-2017 Stanford University and the Authors * 13 * Author(s): Ajay Seth * 14 * * 15 * Licensed under the Apache License, Version 2.0 (the "License"); you may * 16 * not use this file except in compliance with the License. You may obtain a * 17 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * 18 * * 19 * Unless required by applicable law or agreed to in writing, software * 20 * distributed under the License is distributed on an "AS IS" BASIS, * 21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 22 * See the License for the specific language governing permissions and * 23 * limitations under the License. * 24 * -------------------------------------------------------------------------- */ 25 26 // INCLUDES 27 #include <OpenSim/Simulation/osimSimulationDLL.h> 28 #include <OpenSim/Common/IO.h> 29 #include <OpenSim/Common/Set.h> 30 #include "ModelComponent.h" 31 32 #ifdef SWIG 33 #ifdef OSIMSIMULATION_API 34 #undef OSIMSIMULATION_API 35 #define OSIMSIMULATION_API 36 #endif 37 #endif 38 39 namespace OpenSim { 40 41 class Model; 42 43 //============================================================================= 44 //============================================================================= 45 /** 46 * This is the base class for sets of ModelComponent subclasses. It provides 47 * methods for invoking all of the ModelComponent methods on each member of the 48 * set. 49 * 50 * @tparam T This must be a concrete class derived from ModelComponent. 51 */ 52 53 template<typename T> 54 using SetTModelComponent = Set<T, ModelComponent>; 55 56 template <class T=ModelComponent> 57 class ModelComponentSet : public Set<T, ModelComponent> { 58 OpenSim_DECLARE_CONCRETE_OBJECT_T(ModelComponentSet, T, SetTModelComponent<T>); 59 60 //============================================================================ 61 // METHODS 62 //============================================================================= 63 public: 64 using Super::Super; extendFinalizeFromProperties()65 void extendFinalizeFromProperties() override final { 66 Super::extendFinalizeFromProperties(); 67 // ModelComponentSets are unnamed properties of models, but as 68 // components they must have a unique name. There is also nothing 69 // stopping users from editing the XML to add a name. 70 // We maintain consistency by overwriting any user set names with 71 // the class name, which is also the default for the unnamed property. 72 const std::string& name = this->getName(); 73 if (name != IO::Lowercase(getConcreteClassName())) { 74 std::string msg = getConcreteClassName() + " '" + name + "' "; 75 this->setName(IO::Lowercase(getConcreteClassName())); 76 77 msg += "was renamed and is being reset to '" + name 78 + "'."; 79 std::cout << msg << std::endl; 80 } 81 } 82 83 //============================================================================= 84 }; // END of class ModelComponentSet 85 //============================================================================= 86 //============================================================================= 87 88 } // end of namespace OpenSim 89 90 #endif // OPENSIM_MODEL_COMPONENT_SET_H 91 92