1 /* === S I N F G =========================================================== */
3 ** \brief Template File
5 ** $Id: action.h,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === S T A R T =========================================================== */
24 #ifndef __SINFG_APP_ACTION_H
25 #define __SINFG_APP_ACTION_H
27 /* === H E A D E R S ======================================================= */
29 #include <sinfg/string.h>
30 #include <sinfg/canvas.h>
32 #include <ETL/stringf>
33 #include <ETL/trivial>
38 #include <sinfg/layer.h>
39 #include <sinfg/canvas.h>
40 #include <sinfg/valuenode.h>
41 #include <sinfgapp/value_desc.h>
42 #include <sinfg/value.h>
43 #include <sinfg/activepoint.h>
44 #include <sinfg/valuenode_animated.h>
45 #include <sinfg/string.h>
46 #include <sinfg/keyframe.h>
48 #include "action_param.h"
51 /* === M A C R O S ========================================================= */
53 #define ACTION_MODULE_EXT public: \
54 static const char name__[], local_name__[], version__[], cvs_id__[], task__[]; \
55 static const Category category__; \
56 static const int priority__; \
57 static Action::Base *create(); \
58 virtual sinfg::String get_name()const; \
59 virtual sinfg::String get_local_name()const;
62 #define ACTION_SET_NAME(class,x) const char class::name__[]=x
64 #define ACTION_SET_CATEGORY(class,x) const Category class::category__(x)
66 #define ACTION_SET_TASK(class,x) const char class::task__[]=x
68 #define ACTION_SET_PRIORITY(class,x) const int class::priority__=x
70 #define ACTION_SET_LOCAL_NAME(class,x) const char class::local_name__[]=x
72 #define ACTION_SET_VERSION(class,x) const char class::version__[]=x
74 #define ACTION_SET_CVS_ID(class,x) const char class::cvs_id__[]=x
76 #define ACTION_INIT(class) \
77 Action::Base* class::create() { return new class(); } \
78 sinfg::String class::get_name()const { return name__; } \
79 sinfg::String class::get_local_name()const { return local_name__; } \
81 /* === T Y P E D E F S ===================================================== */
83 /* === C L A S S E S & S T R U C T S ======================================= */
86 class ProgressCallback;
88 }; // END of namespace sinfg
100 //! Exception class, thrown when redoing or undoing an action
122 Error(Type type, const char *format, ...):
126 va_start(args,format);
127 desc_=etl::vstrprintf(format,args);
130 Error(const char *format, ...):
134 va_start(args,format);
135 desc_=etl::vstrprintf(format,args);
138 Error(Type type=TYPE_UNABLE):
143 Type get_type()const { return type_; }
144 sinfg::String get_desc()const { return desc_; }
146 }; // END of class Action::Error
157 CATEGORY_LAYER =(1<<0),
158 CATEGORY_CANVAS =(1<<1),
159 CATEGORY_WAYPOINT =(1<<2),
160 CATEGORY_ACTIVEPOINT =(1<<3),
161 CATEGORY_VALUEDESC =(1<<4),
162 CATEGORY_VALUENODE =(1<<5),
163 CATEGORY_KEYFRAME =(1<<6),
164 CATEGORY_GROUP =(1<<7),
166 CATEGORY_OTHER =(1<<12),
168 CATEGORY_DRAG =(1<<24),
170 CATEGORY_HIDDEN =(1<<31),
171 CATEGORY_ALL =(~0)-(1<<31) //!< All categories (EXCEPT HIDDEN)
172 }; // END of enum Category
174 inline Category operator|(Category lhs, Category rhs)
175 { return static_cast<Category>(int(lhs)|int(rhs)); }
179 //! Action Base Class
180 /*! An action should implement the following functions:
181 ** static bool is_canidate(const ParamList &x);
182 ** - Checks the ParamList to see if this action could be performed.
183 ** static ParamVocab get_param_vocab();
184 ** - Yields the ParamVocab object which describes what
185 ** this action needs before it can perform the act.
186 ** static Action::Base* create();
187 ** - Factory for creating this action from a ParamList
190 class Base : public etl::shared_object
198 //! This function will throw an Action::Error() on failure
199 virtual void perform()=0;
201 virtual bool set_param(const sinfg::String& name, const Param &) { return false; }
202 virtual bool is_ready()const=0;
204 virtual sinfg::String get_name()const =0;
205 virtual sinfg::String get_local_name()const { return get_name(); }
207 void set_param_list(const ParamList &);
209 }; // END of class Action::Base
211 typedef Action::Base* (*Factory)();
212 typedef bool (*CanidateChecker)(const ParamList &x);
213 typedef ParamVocab (*GetParamVocab)();
215 typedef etl::handle<Base> Handle;
217 //! Undoable Action Base Class
218 class Undoable : public Base
224 Undoable():active_(true) { }
227 void set_active(bool x) { active_=x; }
231 //! This function will throw an Action::Error() on failure
232 virtual void undo()=0;
234 bool is_active()const { return active_; }
236 }; // END of class Action::Undoable
238 //! Action base class for canvas-specific actions
245 etl::loose_handle<sinfgapp::CanvasInterface> canvas_interface_;
246 sinfg::Canvas::Handle canvas_;
249 CanvasSpecific(const sinfg::Canvas::Handle &canvas):is_dirty_(true),mode_(MODE_UNDEFINED),canvas_(canvas) { }
250 CanvasSpecific():mode_(MODE_UNDEFINED) { }
252 virtual ~CanvasSpecific() { };
257 void set_canvas(sinfg::Canvas::Handle x) { canvas_=x; }
258 void set_canvas_interface(etl::loose_handle<sinfgapp::CanvasInterface> x) { canvas_interface_=x; }
260 sinfg::Canvas::Handle get_canvas()const { return canvas_; }
261 etl::loose_handle<sinfgapp::CanvasInterface> get_canvas_interface()const { return canvas_interface_; }
263 static ParamVocab get_param_vocab();
264 virtual bool set_param(const sinfg::String& name, const Param &);
265 virtual bool is_ready()const;
267 EditMode get_edit_mode()const;
269 void set_edit_mode(EditMode x) { mode_=x; }
271 bool is_dirty()const { return is_dirty_; }
272 void set_dirty(bool x=true) { is_dirty_=x; }
274 }; // END of class Action::Undoable
276 typedef std::list< etl::handle<Action::Undoable> > ActionList;
278 /*! \class sinfgapp::Action::Super
279 ** \brief Super-Action base class for actions composed of several other actions.
281 ** Actions deriving from this class should only implement prepare(), and
282 ** NOT implement perform() or undo().
284 class Super : public Undoable, public CanvasSpecific
286 ActionList action_list_;
290 ActionList &action_list() { return action_list_; }
291 const ActionList &action_list()const { return action_list_; }
293 virtual void prepare()=0;
295 void clear() { action_list().clear(); }
297 bool first_time()const { return action_list_.empty(); }
299 void add_action(etl::handle<Undoable> action);
301 void add_action_front(etl::handle<Undoable> action);
303 virtual void perform();
306 }; // END of class Action::Super
309 class Group : public Super
313 ActionList action_list_;
317 Group(const sinfg::String &str="Group");
320 virtual sinfg::String get_name()const { return name_; }
322 virtual void prepare() { };
324 virtual bool set_param(const sinfg::String& name, const Param &)const { return false; }
325 virtual bool is_ready()const { return ready_; }
327 void set_name(std::string&x) { name_=x; }
328 }; // END of class Action::Group
337 sinfg::String local_name;
338 sinfg::String version;
343 CanidateChecker is_canidate;
344 GetParamVocab get_param_vocab;
346 bool operator<(const BookEntry &rhs)const { return priority<rhs.priority; }
347 }; // END of struct BookEntry
349 typedef std::map<sinfg::String,BookEntry> Book;
351 class CanidateList : public std::list<BookEntry>
354 iterator find(const sinfg::String& x);
355 const_iterator find(const sinfg::String& x)const { return const_cast<CanidateList*>(this)->find(x); }
360 Handle create(const sinfg::String &name);
362 //! Compiles a list of potential canidate actions with the given \a param_list and \a category
363 CanidateList compile_canidate_list(const ParamList& param_list, Category category=CATEGORY_ALL);
365 /*! \class sinfgapp::Action::Main
372 friend class sinfgapp::Main;
379 }; // END of class Action::Main
381 }; // END of namespace Action
383 }; // END of namespace sinfgapp
385 /* === E N D =============================================================== */