00001 #ifndef COMMAND_H_IS_INCLUDED
00002 #define COMMAND_H_IS_INCLUDED
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "geom/geom.H"
00015 #include "disp/view.H"
00016 #include "std/ref.H"
00017
00018 class COMMAND;
00019 typedef const COMMAND CCOMMAND;
00020 MAKE_PTR_BASEC(COMMAND);
00021 typedef const COMMANDptr CCOMMANDptr;
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 class COMMAND : public REFcounter {
00070
00071 public:
00072
00073
00074
00075
00076 DEFINE_RTTI_METHODS_BASE("COMMAND", CCOMMAND*);
00077
00078
00079
00080
00081
00082
00083 COMMAND(bool done=false): _is_done(done), _is_undone(false) {}
00084
00085
00086
00087
00088
00089
00090
00091 bool is_clear() const { return !(_is_done || _is_undone); }
00092
00093
00094 bool is_done() const { return _is_done; }
00095
00096
00097 bool is_undone() const { return _is_undone; }
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 virtual bool doit();
00108
00109
00110
00111
00112 virtual bool undoit();
00113
00114
00115
00116 virtual bool clear();
00117
00118
00119
00120
00121
00122
00123 virtual void print() const { cerr << class_name() << " "; }
00124
00125
00126
00127 protected:
00128
00129 bool _is_done;
00130 bool _is_undone;
00131
00132 };
00133
00134 MAKE_PTR_SUBC(UNDO_CMD,COMMAND);
00135
00136
00137
00138
00139
00140 class UNDO_CMD : public COMMAND {
00141
00142 public:
00143
00144
00145
00146
00147 UNDO_CMD(const COMMANDptr& c) : _cmd(c) {}
00148
00149
00150
00151
00152
00153
00154 DEFINE_RTTI_METHODS3("UNDO_CMD", UNDO_CMD*, COMMAND, CCOMMAND*);
00155
00156
00157
00158
00159
00160
00161 virtual bool doit();
00162 virtual bool undoit();
00163 virtual bool clear();
00164
00165
00166
00167
00168
00169
00170 virtual void print() const {
00171 cerr << class_name() << ": { ";
00172 if (_cmd) _cmd->print();
00173 cerr << " } ";
00174 }
00175
00176
00177
00178 protected:
00179
00180 COMMANDptr _cmd;
00181
00182 };
00183
00184 MAKE_PTR_SUBC(DISPLAY_CMD,COMMAND);
00185
00186
00187
00188
00189
00190
00191
00192
00193 class DISPLAY_CMD : public COMMAND {
00194
00195 public:
00196
00197
00198
00199
00200 DISPLAY_CMD(CGELptr& gel ) : _gels(gel) {}
00201 DISPLAY_CMD(CGELlist& gels) : _gels(gels) {}
00202
00203
00204
00205
00206
00207
00208 DEFINE_RTTI_METHODS3("DISPLAY_CMD", DISPLAY_CMD*, COMMAND, CCOMMAND*);
00209
00210
00211
00212
00213
00214
00215 virtual bool doit();
00216 virtual bool undoit();
00217
00218
00219
00220
00221
00222
00223 virtual void print() const {
00224 cerr << class_name() << " { ";
00225 for (int i=0; i<_gels.num(); i++)
00226 cerr << _gels[i]->class_name() << " ";
00227 cerr << " } ";
00228 }
00229
00230
00231
00232 protected:
00233
00234 GELlist _gels;
00235
00236 };
00237
00238 MAKE_PTR_SUBC(UNDISPLAY_CMD, UNDO_CMD);
00239
00240
00241
00242
00243
00244
00245
00246
00247 class UNDISPLAY_CMD : public UNDO_CMD {
00248 public:
00249
00250
00251
00252
00253 UNDISPLAY_CMD(CGELptr& gel ) : UNDO_CMD(new DISPLAY_CMD(gel)) {}
00254 UNDISPLAY_CMD(CGELlist& gels) : UNDO_CMD(new DISPLAY_CMD(gels)) {}
00255
00256
00257
00258
00259
00260
00261 DEFINE_RTTI_METHODS3("UNDISPLAY_CMD", UNDISPLAY_CMD*, UNDO_CMD, CCOMMAND*);
00262
00263
00264
00265 };
00266
00267 MAKE_PTR_SUBC(MULTI_CMD,COMMAND);
00268
00269
00270
00271
00272
00273 class MULTI_CMD : public COMMAND {
00274
00275 public:
00276
00277
00278
00279
00280 DEFINE_RTTI_METHODS3("MULTI_CMD", MULTI_CMD*, COMMAND, CCOMMAND*);
00281
00282
00283
00284
00285
00286
00287 CLIST<COMMANDptr>& commands() const { return _commands; }
00288 bool is_empty() const { return _commands.empty(); }
00289
00290 void add(CCOMMANDptr& cmd) { _commands += cmd; }
00291 void rem(CCOMMANDptr& cmd) { _commands -= cmd; }
00292 COMMANDptr pop() { return _commands.pop(); }
00293
00294 CCOMMANDptr& last() const { return _commands.last(); }
00295
00296
00297
00298
00299
00300
00301 virtual bool doit();
00302 virtual bool undoit();
00303 virtual bool clear();
00304
00305
00306
00307
00308
00309
00310 virtual void print() const {
00311 cerr << class_name() << " { ";
00312 for (int i=0; i<_commands.num(); i++)
00313 _commands[i]->print();
00314 cerr << " } ";
00315 }
00316
00317
00318
00319 protected:
00320
00321 LIST<COMMANDptr> _commands;
00322
00323 };
00324
00325 #endif // COMMAND_H_IS_INCLUDED
00326
00327