Simbody
3.4 (development)
|
00001 #ifndef SimTK_SimTKCOMMON_EVENT_HANDLER_H_ 00002 #define SimTK_SimTKCOMMON_EVENT_HANDLER_H_ 00003 00004 /* -------------------------------------------------------------------------- * 00005 * Simbody(tm): SimTKcommon * 00006 * -------------------------------------------------------------------------- * 00007 * This is part of the SimTK biosimulation toolkit originating from * 00008 * Simbios, the NIH National Center for Physics-Based Simulation of * 00009 * Biological Structures at Stanford, funded under the NIH Roadmap for * 00010 * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. * 00011 * * 00012 * Portions copyright (c) 2007-12 Stanford University and the Authors. * 00013 * Authors: Peter Eastman * 00014 * Contributors: Michael Sherman * 00015 * * 00016 * Licensed under the Apache License, Version 2.0 (the "License"); you may * 00017 * not use this file except in compliance with the License. You may obtain a * 00018 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * 00019 * * 00020 * Unless required by applicable law or agreed to in writing, software * 00021 * distributed under the License is distributed on an "AS IS" BASIS, * 00022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 00023 * See the License for the specific language governing permissions and * 00024 * limitations under the License. * 00025 * -------------------------------------------------------------------------- */ 00026 00027 #include "SimTKcommon/basics.h" 00028 #include "SimTKcommon/Simmatrix.h" 00029 #include "SimTKcommon/internal/State.h" 00030 #include "SimTKcommon/internal/System.h" 00031 00032 namespace SimTK { 00033 00051 class SimTK_SimTKCOMMON_EXPORT EventHandler { 00052 public: 00053 virtual ~EventHandler(); 00054 00073 virtual void handleEvent(State& state, Real accuracy, 00074 bool& shouldTerminate) const = 0; 00075 }; 00076 00084 class SimTK_SimTKCOMMON_EXPORT ScheduledEventHandler : public EventHandler { 00085 public: 00086 virtual ~ScheduledEventHandler(); 00087 00096 virtual Real getNextEventTime(const State& state, 00097 bool includeCurrentTime) const = 0; 00098 }; 00099 00109 class SimTK_SimTKCOMMON_EXPORT TriggeredEventHandler : public EventHandler { 00110 public: 00111 class TriggeredEventHandlerImpl; 00112 TriggeredEventHandler(const TriggeredEventHandler& clone); 00113 TriggeredEventHandler& operator=(const TriggeredEventHandler& clone); 00114 virtual ~TriggeredEventHandler(); 00115 00122 TriggeredEventHandler(Stage requiredStage); 00123 00127 virtual Real getValue(const State&) const = 0; 00128 00133 EventTriggerInfo& getTriggerInfo(); 00134 00138 Stage getRequiredStage() const; 00139 private: 00140 TriggeredEventHandlerImpl* impl; 00141 }; 00142 00146 class SimTK_SimTKCOMMON_EXPORT PeriodicEventHandler 00147 : public ScheduledEventHandler { 00148 public: 00149 class PeriodicEventHandlerImpl; 00150 ~PeriodicEventHandler(); 00151 Real getNextEventTime(const State& state, bool includeCurrentTime) const; 00152 00159 PeriodicEventHandler(Real eventInterval); 00160 00164 Real getEventInterval() const; 00165 00169 void setEventInterval(Real eventInterval); 00170 private: 00171 PeriodicEventHandlerImpl* impl; 00172 }; 00173 00174 } // namespace SimTK 00175 00176 #endif // SimTK_SimTKCOMMON_EVENT_HANDLER_H_