Commands.h

Go to the documentation of this file.
00001 #ifndef _MOVECMDS_HEADER
00002 #define _MOVECMDS_HEADER
00003 
00004 
00005 #include "Command.h"
00006 #include "SpeechControlSource.h"
00007 #include <assert.h>
00008 
00009 
00010 namespace ot
00011 {
00012 
00013 
00014 // class *CmdUpMovement*
00015 // *******************************************************************************************
00016 
00017 class CmdUpMovement : public Command
00018 {
00019 public:
00020         CmdUpMovement(TtsString name_, int step_, SpeechControlSource &parentSrc_)
00021         : Command(name_, TtsString("up movement", 3), parentSrc_, true, true), step(step_), range(step_)        {}
00022 
00023         bool extend()   { getEvent().getPosition()[1] += step * scale; range += step; return true; };
00024         bool redo()             { getEvent().getPosition()[1] += range * scale; return true; }
00025         bool undo()             { getEvent().getPosition()[1] -= range * scale; return true; }
00026         bool combine(Command &cmd)
00027         {
00028                 if (isCombinable(cmd))
00029                         range += ((CmdUpMovement*)&cmd)->range;
00030                 return isCombinable(cmd);
00031         }
00032 
00033 protected:
00034         int step;
00035         int range;
00036 };
00037 
00038 
00039 // class *CmdUp*
00040 
00041 class CmdUp : public CmdUpMovement
00042 {
00043 public:
00044         CmdUp(SpeechControlSource &parentSrc_)
00045         : CmdUpMovement(TtsString("up", 1), 1, parentSrc_)      {}
00046 };
00047 
00048 
00049 // class *CmdMoveUp*
00050 
00051 class CmdMoveUp : public CmdUpMovement
00052 {
00053 public:
00054         CmdMoveUp(SpeechControlSource &parentSrc_)
00055         : CmdUpMovement(TtsString("move up", 2), 5, parentSrc_) {}
00056 };
00057 
00058 
00059 // class *CmdDownMovement*
00060 // *******************************************************************************************
00061 
00062 class CmdDownMovement : public Command
00063 {
00064 public:
00065         CmdDownMovement(TtsString name_, int step_, SpeechControlSource &parentSrc_)
00066         : Command(name_, TtsString("down movement", 3), parentSrc_, true, true), step(step_), range(step_)      {}
00067 
00068         bool extend()   { getEvent().getPosition()[1] -= step * scale; range += step; return true; };
00069         bool redo()             { getEvent().getPosition()[1] -= range * scale; return true; }
00070         bool undo()             { getEvent().getPosition()[1] += range * scale; return true; }
00071         bool combine(Command &cmd)
00072         {
00073                 if (isCombinable(cmd))
00074                         range += ((CmdDownMovement*)&cmd)->range;
00075                 return isCombinable(cmd);
00076         }
00077 
00078 protected:
00079         int step;
00080         int range;
00081 };
00082 
00083 
00084 // class *CmdDown*
00085 
00086 class CmdDown : public CmdDownMovement
00087 {
00088 public:
00089         CmdDown(SpeechControlSource &parentSrc_)
00090         : CmdDownMovement(TtsString("down", 1), 1, parentSrc_)  {}
00091 };
00092 
00093 
00094 // class *CmdMoveDown*
00095 
00096 class CmdMoveDown : public CmdDownMovement
00097 {
00098 public:
00099         CmdMoveDown(SpeechControlSource &parentSrc_)
00100         : CmdDownMovement(TtsString("move down", 2), 5, parentSrc_)     {}
00101 };
00102 
00103 
00104 // class *CmdRightMovement*
00105 // *******************************************************************************************
00106 
00107 class CmdRightMovement : public Command
00108 {
00109 public:
00110         CmdRightMovement(TtsString name_, int step_, SpeechControlSource &parentSrc_)
00111         : Command(name_, TtsString("right movement", 3), parentSrc_, true, true), step(step_), range(step_)     {}
00112 
00113         bool extend()   { getEvent().getPosition()[0] += step * scale; range += step; return true; };
00114         bool redo()             { getEvent().getPosition()[0] += range * scale; return true; }
00115         bool undo()             { getEvent().getPosition()[0] -= range * scale; return true; }
00116         bool combine(Command &cmd)
00117         {
00118                 if (isCombinable(cmd))
00119                         range += ((CmdRightMovement*)&cmd)->range;
00120                 return isCombinable(cmd);
00121         }
00122 
00123 protected:
00124         int step;
00125         int range;
00126 };
00127 
00128 
00129 // class *CmdRight*
00130 
00131 class CmdRight : public CmdRightMovement
00132 {
00133 public:
00134         CmdRight(SpeechControlSource &parentSrc_)
00135         : CmdRightMovement(TtsString("right", 1), 1, parentSrc_)        {}
00136 };
00137 
00138 
00139 // class *CmdMoveRight*
00140 
00141 class CmdMoveRight : public CmdRightMovement
00142 {
00143 public:
00144         CmdMoveRight(SpeechControlSource &parentSrc_)
00145         : CmdRightMovement(TtsString("move right", 2), 5, parentSrc_)   {}
00146 };
00147 
00148 
00149 // class *CmdLeftMovement*
00150 // *******************************************************************************************
00151 
00152 class CmdLeftMovement : public Command
00153 {
00154 public:
00155         CmdLeftMovement(TtsString name_, int step_, SpeechControlSource &parentSrc_)
00156         : Command(name_, TtsString("left movement", 3), parentSrc_, true, true), step(step_), range(step_)      {}
00157 
00158         bool extend()   { getEvent().getPosition()[0] -= step * scale; range += step; return true; };
00159         bool redo()             { getEvent().getPosition()[0] -= range * scale; return true; }
00160         bool undo()             { getEvent().getPosition()[0] += range * scale; return true; }
00161         bool combine(Command &cmd)
00162         {
00163                 if (isCombinable(cmd))
00164                         range += ((CmdLeftMovement*)&cmd)->range;
00165                 return isCombinable(cmd);
00166         }
00167 
00168 protected:
00169         int step;
00170         int range;
00171 };
00172 
00173 
00174 // class *CmdLeft*
00175 
00176 class CmdLeft : public CmdLeftMovement
00177 {
00178 public:
00179         CmdLeft(SpeechControlSource &parentSrc_)
00180         : CmdLeftMovement(TtsString("left", 1), 1, parentSrc_)  {}
00181 };
00182 
00183 
00184 // class *CmdMoveLeft*
00185 
00186 class CmdMoveLeft : public CmdLeftMovement
00187 {
00188 public:
00189         CmdMoveLeft(SpeechControlSource &parentSrc_)
00190         : CmdLeftMovement(TtsString("move left", 2), 5, parentSrc_)     {}
00191 };
00192 
00193 
00194 // class *CmdForwardMovement*
00195 // *******************************************************************************************
00196 
00197 class CmdForwardMovement : public Command
00198 {
00199 public:
00200         CmdForwardMovement(TtsString name_, int step_, SpeechControlSource &parentSrc_)
00201         : Command(name_, TtsString("forward movement", 4), parentSrc_, true, true), step(step_), range(step_)   {}
00202 
00203         bool extend()   { getEvent().getPosition()[2] += step * scale; range += step; return true; };
00204         bool redo()             { getEvent().getPosition()[2] += range * scale; return true; }
00205         bool undo()             { getEvent().getPosition()[2] -= range * scale; return true; }
00206         bool combine(Command &cmd)
00207         {
00208                 if (isCombinable(cmd))
00209                         range += ((CmdForwardMovement*)&cmd)->range;
00210                 return isCombinable(cmd);
00211         }
00212 
00213 protected:
00214         int step;
00215         int range;
00216 };
00217 
00218 
00219 // class *CmdForward*
00220 
00221 class CmdForward : public CmdForwardMovement
00222 {
00223 public:
00224         CmdForward(SpeechControlSource &parentSrc_)
00225         : CmdForwardMovement(TtsString("forward", 2), 1, parentSrc_)    {}
00226 };
00227 
00228 
00229 // class *CmdMoveForward*
00230 
00231 class CmdMoveForward : public CmdForwardMovement
00232 {
00233 public:
00234         CmdMoveForward(SpeechControlSource &parentSrc_)
00235         : CmdForwardMovement(TtsString("move forward", 3), 5, parentSrc_)       {}
00236 };
00237 
00238 
00239 // class *CmdBackwardMovement*
00240 // *******************************************************************************************
00241 
00242 class CmdBackwardMovement : public Command
00243 {
00244 public:
00245         CmdBackwardMovement(TtsString name_, int step_, SpeechControlSource &parentSrc_)
00246         : Command(name_, TtsString("backward movement", 4), parentSrc_, true, true), step(step_), range(step_)  {}
00247 
00248         bool extend()   { getEvent().getPosition()[2] -= step * scale; range += step; return true; };
00249         bool redo()             { getEvent().getPosition()[2] -= range * scale; return true; }
00250         bool undo()             { getEvent().getPosition()[2] += range * scale; return true; }
00251         bool combine(Command &cmd)
00252         {
00253                 if (isCombinable(cmd))
00254                         range += ((CmdBackwardMovement*)&cmd)->range;
00255                 return isCombinable(cmd);
00256         }
00257 
00258 protected:
00259         int step;
00260         int range;
00261 };
00262 
00263 
00264 // class *CmdBackward*
00265 
00266 class CmdBackward : public CmdBackwardMovement
00267 {
00268 public:
00269         CmdBackward(SpeechControlSource &parentSrc_)
00270         : CmdBackwardMovement(TtsString("backward", 2), 1, parentSrc_)  {}
00271 };
00272 
00273 
00274 // class *CmdMoveBackward*
00275 
00276 class CmdMoveBackward : public CmdBackwardMovement
00277 {
00278 public:
00279         CmdMoveBackward(SpeechControlSource &parentSrc_)
00280         : CmdBackwardMovement(TtsString("move backward", 3), 5, parentSrc_)     {}
00281 };
00282 
00283 
00284 // class *CmdAxial*
00285 // *******************************************************************************************
00286 
00287 class CmdAxial : public Command
00288 {
00289 public:
00290         CmdAxial(SpeechControlSource &parentSrc_)
00291         : Command(TtsString("axial", 3), TtsString("axial", 3), parentSrc_, true)       {}
00292 
00293         bool redo()
00294         {
00295                 originalEvent = getEvent();
00296                 getEvent().getOrientation()[0] = (float)0;
00297                 getEvent().getOrientation()[1] = (float)0;
00298                 getEvent().getOrientation()[2] = (float)0;
00299                 getEvent().getOrientation()[3] = (float)1;
00300                 return true;
00301         };
00302         bool undo()     { getEvent() = originalEvent; return true; };
00303 
00304 protected:
00305         Event   originalEvent;
00306 };
00307 
00308 
00309 // class *CmdSagittal*
00310 // *******************************************************************************************
00311 
00312 class CmdSagittal : public Command
00313 {
00314 public:
00315         CmdSagittal(SpeechControlSource &parentSrc_)
00316         : Command(TtsString("sagittal", 3), TtsString("sagittal", 3), parentSrc_, true) {}
00317 
00318         bool redo()
00319         {
00320                 originalEvent = getEvent();
00321                 getEvent().getOrientation()[0] = (float)0.5;
00322                 getEvent().getOrientation()[1] = (float)0.5;
00323                 getEvent().getOrientation()[2] = (float)0.5;
00324                 getEvent().getOrientation()[3] = (float)0.5;
00325                 return true;
00326         };
00327         bool undo()     { getEvent() = originalEvent; return true; };
00328 
00329 protected:
00330         Event   originalEvent;
00331 };
00332 
00333 
00334 // class *CmdCoronal*
00335 // *******************************************************************************************
00336 
00337 class CmdCoronal : public Command
00338 {
00339 public:
00340         CmdCoronal(SpeechControlSource &parentSrc_)
00341         : Command(TtsString("coronal", 3), TtsString("coronal", 3), parentSrc_, true)   {}
00342 
00343         bool redo()
00344         {
00345                 originalEvent = getEvent();
00346                 getEvent().getOrientation()[0] = (float)0.7;
00347                 getEvent().getOrientation()[1] = (float)0;
00348                 getEvent().getOrientation()[2] = (float)0;
00349                 getEvent().getOrientation()[3] = (float)0.7;
00350                 return true;
00351         };
00352         bool undo()     { getEvent() = originalEvent; return true; };
00353 
00354 protected:
00355         Event   originalEvent;
00356 };
00357 
00358 
00359 // class *CmdReset*
00360 // *******************************************************************************************
00361 
00362 class CmdReset : public Command
00363 {
00364 public:
00365         CmdReset(SpeechControlSource &parentSrc_)
00366         : Command(TtsString("reset", 2), TtsString("reset", 2), parentSrc_, true)       {}
00367 
00368         bool redo()
00369         {
00370                 originalEvent = getEvent();
00371                 getEvent().getPosition()[0] = (float)0;
00372                 getEvent().getPosition()[1] = (float)0;
00373                 getEvent().getPosition()[2] = (float)0;
00374                 getEvent().getOrientation()[0] = (float)0;
00375                 getEvent().getOrientation()[1] = (float)0;
00376                 getEvent().getOrientation()[2] = (float)0;
00377                 getEvent().getOrientation()[3] = (float)1;
00378                 getEvent().getButton() = 0;
00379                 getEvent().getConfidence() = 0;
00380                 return true;
00381         };
00382         bool undo()     { getEvent() = originalEvent; return true; };
00383 
00384 protected:
00385         Event   originalEvent;
00386 };
00387 
00388 
00389 // class *CmdRotation*
00390 // *******************************************************************************************
00391 
00392 class CmdRotation : public Command
00393 {
00394 public:
00395         CmdRotation(TtsString name_, TtsString class_, SpeechControlSource &parentSrc_, int step_)
00396         : Command(name_, class_, parentSrc_, true, true), step(step_), range(step_)     {}
00397 
00398         bool rotate(int axis, bool up, int step)
00399         {
00400                 assert(axis >= 0 && axis <= 2);
00401 
00402                 // set variables
00403                 float axisAngle[] = { 0, 0, 0, 0 };
00404                 std::vector<float> oldOrientation = getEvent().getOrientation();
00405                 std::vector<float> rotationQuaternion;
00406                 float angle = step * scale;
00407                 if (!up)
00408                         angle *= -1;
00409                 angle *= MathUtils::GradToRad;
00410 
00411                 // set axisAngle
00412                 axisAngle[3] = angle;
00413                 axisAngle[axis] = 1;
00414 
00415                 // rotate
00416                 MathUtils::axisAngleToQuaternion(copyA2V(axisAngle, 4), rotationQuaternion);
00417                 MathUtils::multiplyQuaternion(oldOrientation, rotationQuaternion, getEvent().getOrientation());
00418                 return true;
00419         };
00420         bool combine(Command &cmd)
00421         {
00422                 if (isCombinable(cmd))
00423                         range += ((CmdRotation*)&cmd)->range;
00424                 return isCombinable(cmd);
00425         };
00426 
00427 protected:
00428         int range;
00429         int step;
00430 };
00431 
00432 
00433 // class *CmdRightRotation*
00434 // *******************************************************************************************
00435 
00436 class CmdRightRotation : public CmdRotation
00437 {
00438 public:
00439         CmdRightRotation(TtsString name_, int step_, SpeechControlSource &parentSrc_)
00440         : CmdRotation(name_, TtsString("right rotation", 4), parentSrc_, step_) {}
00441 
00442         bool extend()   { range += step; return rotate(0, true, step); };
00443         bool redo()             { return rotate(0, true, range); };
00444         bool undo()             { return rotate(0, false, range); };
00445 };
00446 
00447 
00448 // class *CmdRotateRight*
00449 
00450 class CmdRotateRight : public CmdRightRotation
00451 {
00452 public:
00453         CmdRotateRight(SpeechControlSource &parentSrc_)
00454         : CmdRightRotation(TtsString("rotate right", 3), 1, parentSrc_) {}
00455 };
00456 
00457 
00458 // class *CmdRotateRightFast*
00459 
00460 class CmdRotateRightFast : public CmdRightRotation
00461 {
00462 public:
00463         CmdRotateRightFast(SpeechControlSource &parentSrc_)
00464         : CmdRightRotation(TtsString("rotate right fast", 4), 5, parentSrc_)    {}
00465 };
00466 
00467 
00468 // class *CmdLeftRotation*
00469 // *******************************************************************************************
00470 
00471 class CmdLeftRotation : public CmdRotation
00472 {
00473 public:
00474         CmdLeftRotation(TtsString name_, int step_, SpeechControlSource &parentSrc_)
00475         : CmdRotation(name_, TtsString("left rotation", 4), parentSrc_, step_) {}
00476 
00477         bool extend()   { range += step; return rotate(0, false, step); };
00478         bool redo()             { return rotate(0, false, range); };
00479         bool undo()             { return rotate(0, true, range); };
00480 };
00481 
00482 
00483 // class *CmdRotateLeft*
00484 
00485 class CmdRotateLeft : public CmdLeftRotation
00486 {
00487 public:
00488         CmdRotateLeft(SpeechControlSource &parentSrc_)
00489         : CmdLeftRotation(TtsString("rotate left", 3), 1, parentSrc_)   {}
00490 };
00491 
00492 
00493 // class *CmdRotateLeftFast*
00494 
00495 class CmdRotateLeftFast : public CmdLeftRotation
00496 {
00497 public:
00498         CmdRotateLeftFast(SpeechControlSource &parentSrc_)
00499         : CmdLeftRotation(TtsString("rotate left fast", 4), 5, parentSrc_)      {}
00500 };
00501 
00502 
00503 // class *CmdClockwiseRolling*
00504 // *******************************************************************************************
00505 
00506 class CmdClockwiseRolling : public CmdRotation
00507 {
00508 public:
00509         CmdClockwiseRolling(TtsString name_, int step_, SpeechControlSource &parentSrc_)
00510         : CmdRotation(name_, TtsString("clockwise rolling", 4), parentSrc_, step_) {}
00511 
00512         bool extend()   { range += step; return rotate(1, true, step); };
00513         bool redo()             { return rotate(1, true, range); };
00514         bool undo()             { return rotate(1, false, range); };
00515 };
00516 
00517 
00518 // class *CmdRollClockwise*
00519 
00520 class CmdRollClockwise : public CmdClockwiseRolling
00521 {
00522 public:
00523         CmdRollClockwise(SpeechControlSource &parentSrc_)
00524         : CmdClockwiseRolling(TtsString("roll clockwise", 3), 1, parentSrc_)    {}
00525 };
00526 
00527 
00528 // class *CmdRollClockwiseFast*
00529 
00530 class CmdRollClockwiseFast : public CmdClockwiseRolling
00531 {
00532 public:
00533         CmdRollClockwiseFast(SpeechControlSource &parentSrc_)
00534         : CmdClockwiseRolling(TtsString("roll clockwise fast", 4), 5, parentSrc_)       {}
00535 };
00536 
00537 
00538 // class *CmdCounterClockwiseRolling*
00539 // *******************************************************************************************
00540 
00541 class CmdCounterClockwiseRolling : public CmdRotation
00542 {
00543 public:
00544         CmdCounterClockwiseRolling(TtsString name_, int step_, SpeechControlSource &parentSrc_)
00545         : CmdRotation(name_, TtsString("counterclockwise rolling", 6), parentSrc_, step_) {}
00546 
00547         bool extend()   { range += step; return rotate(1, false, step); };
00548         bool redo()             { return rotate(1, false, range); };
00549         bool undo()             { return rotate(1, true, range); };
00550 };
00551 
00552 
00553 // class *CmdRollCounterClockwise*
00554 
00555 class CmdRollCounterClockwise : public CmdCounterClockwiseRolling
00556 {
00557 public:
00558         CmdRollCounterClockwise(SpeechControlSource &parentSrc_)
00559         : CmdCounterClockwiseRolling(TtsString("roll counterclockwise", 5), 1, parentSrc_)      {}
00560 };
00561 
00562 
00563 // class *CmdRollCounterClockwiseFast*
00564 
00565 class CmdRollCounterClockwiseFast : public CmdCounterClockwiseRolling
00566 {
00567 public:
00568         CmdRollCounterClockwiseFast(SpeechControlSource &parentSrc_)
00569         : CmdCounterClockwiseRolling(TtsString("roll counterclockwise fast", 6), 5, parentSrc_) {}
00570 };
00571 
00572 
00573 // class *CmdTildingUp*
00574 // *******************************************************************************************
00575 
00576 class CmdTildingUp : public CmdRotation
00577 {
00578 public:
00579         CmdTildingUp(TtsString name_, int step_, SpeechControlSource &parentSrc_)
00580         : CmdRotation(name_, TtsString("tilding up", 3), parentSrc_, 1) {}
00581 
00582         bool extend()   { range += step; return rotate(2, true, step); };
00583         bool redo()             { return rotate(2, true, range); };
00584         bool undo()             { return rotate(2, false, range); };
00585 };
00586 
00587 
00588 // class *CmdTildUp*
00589 
00590 class CmdTildUp : public CmdTildingUp
00591 {
00592 public:
00593         CmdTildUp(SpeechControlSource &parentSrc_)
00594         : CmdTildingUp(TtsString("tild up", 2), 1, parentSrc_)  {}
00595 };
00596 
00597 
00598 // class *CmdTildUpFast*
00599 
00600 class CmdTildUpFast : public CmdTildingUp
00601 {
00602 public:
00603         CmdTildUpFast(SpeechControlSource &parentSrc_)
00604         : CmdTildingUp(TtsString("tild up fast", 3), 5, parentSrc_)     {}
00605 };
00606 
00607 
00608 // class *CmdTildingDown*
00609 // *******************************************************************************************
00610 
00611 class CmdTildingDown : public CmdRotation
00612 {
00613 public:
00614         CmdTildingDown(TtsString name_, int step_, SpeechControlSource &parentSrc_)
00615         : CmdRotation(name_, TtsString("tilding down", 3), parentSrc_, 1) {}
00616 
00617         bool extend()   { range += step; return rotate(2, false, step); };
00618         bool redo()             { return rotate(2, false, range); };
00619         bool undo()             { return rotate(2, true, range); };
00620 };
00621 
00622 
00623 // class *CmdTildDown*
00624 
00625 class CmdTildDown : public CmdTildingDown
00626 {
00627 public:
00628         CmdTildDown(SpeechControlSource &parentSrc_)
00629         : CmdTildingDown(TtsString("tild down", 2), 1, parentSrc_)      {}
00630 };
00631 
00632 
00633 // class *CmdTildDownFast*
00634 
00635 class CmdTildDownFast : public CmdTildingDown
00636 {
00637 public:
00638         CmdTildDownFast(SpeechControlSource &parentSrc_)
00639         : CmdTildingDown(TtsString("tild down fast", 3), 5, parentSrc_) {}
00640 };
00641 
00642 
00643 // class *CmdSaveEvent*
00644 // *******************************************************************************************
00645 
00646 
00647 class CmdSaveEvent : public Command
00648 {
00649 public:
00650         CmdSaveEvent(TtsString name_, int index_, SpeechControlSource &parentSrc_)
00651         : Command(name_, TtsString("save event", 2), parentSrc_), index(index_) { assert(index >= 0 && index <= 4); };
00652 
00653         bool redo() { parentSrc.setSavedEvent(index, getEvent()); return true; };
00654 
00655 protected:
00656         int     index;
00657 };
00658 
00659 
00660 // class *CmdSaveOne*
00661 
00662 class CmdSaveOne : public CmdSaveEvent
00663 {
00664 public:
00665         CmdSaveOne(SpeechControlSource &parentSrc_)
00666         : CmdSaveEvent(TtsString("save one", 2), 0, parentSrc_) {};
00667 };
00668 
00669 
00670 // class *CmdSaveTwo*
00671 
00672 class CmdSaveTwo : public CmdSaveEvent
00673 {
00674 public:
00675         CmdSaveTwo(SpeechControlSource &parentSrc_)
00676         : CmdSaveEvent(TtsString("save two", 2), 1, parentSrc_) {};
00677 };
00678 
00679 
00680 // class *CmdSaveThree*
00681 
00682 class CmdSaveThree : public CmdSaveEvent
00683 {
00684 public:
00685         CmdSaveThree(SpeechControlSource &parentSrc_)
00686         : CmdSaveEvent(TtsString("save three", 2), 2, parentSrc_) {};
00687 };
00688 
00689 
00690 // class *CmdSaveFour*
00691 
00692 class CmdSaveFour : public CmdSaveEvent
00693 {
00694 public:
00695         CmdSaveFour(SpeechControlSource &parentSrc_)
00696         : CmdSaveEvent(TtsString("save four", 2), 3, parentSrc_) {};
00697 };
00698 
00699 
00700 // class *CmdSaveFive*
00701 
00702 class CmdSaveFive : public CmdSaveEvent
00703 {
00704 public:
00705         CmdSaveFive(SpeechControlSource &parentSrc_)
00706         : CmdSaveEvent(TtsString("save five", 2), 4, parentSrc_) {};
00707 };
00708 
00709 
00710 // class *CmdRestoreEvent*
00711 // *******************************************************************************************
00712 
00713 
00714 class CmdRestoreEvent : public Command
00715 {
00716 public:
00717         CmdRestoreEvent(TtsString name_, int index_, SpeechControlSource &parentSrc_)
00718         : Command(name_, TtsString("restore event", 3), parentSrc_, true), index(index_)
00719         {
00720                 assert(index >= 0 && index <= 4);
00721                 failureMsg.str = failureMsg.str + ", since no event was saved yet";
00722                 failureMsg.syl = failureMsg.syl + 6;
00723         };
00724 
00725         bool redo()
00726         {
00727                 if (!parentSrc.isSavedEventAvailable(index))
00728                         return false;
00729                 originalEvent = getEvent();
00730                 setEvent(parentSrc.getSavedEvent(index));
00731                 return true;
00732         };
00733         bool undo()     { setEvent(originalEvent); return true; };
00734 
00735 protected:
00736         int             index;
00737         Event   originalEvent;
00738 };
00739 
00740 
00741 // class *CmdRestoreOne*
00742 
00743 class CmdRestoreOne : public CmdRestoreEvent
00744 {
00745 public:
00746         CmdRestoreOne(SpeechControlSource &parentSrc_)
00747         : CmdRestoreEvent(TtsString("restore one", 3), 0, parentSrc_) {};
00748 };
00749 
00750 
00751 // class *CmdRestoreTwo*
00752 
00753 class CmdRestoreTwo : public CmdRestoreEvent
00754 {
00755 public:
00756         CmdRestoreTwo(SpeechControlSource &parentSrc_)
00757         : CmdRestoreEvent(TtsString("restore two", 3), 1, parentSrc_) {};
00758 };
00759 
00760 
00761 // class *CmdRestoreThree*
00762 
00763 class CmdRestoreThree : public CmdRestoreEvent
00764 {
00765 public:
00766         CmdRestoreThree(SpeechControlSource &parentSrc_)
00767         : CmdRestoreEvent(TtsString("restore three", 3), 2, parentSrc_) {};
00768 };
00769 
00770 
00771 // class *CmdRestoreFour*
00772 
00773 class CmdRestoreFour : public CmdRestoreEvent
00774 {
00775 public:
00776         CmdRestoreFour(SpeechControlSource &parentSrc_)
00777         : CmdRestoreEvent(TtsString("restore four", 3), 3, parentSrc_) {};
00778 };
00779 
00780 
00781 // class *CmdRestoreFive*
00782 
00783 class CmdRestoreFive : public CmdRestoreEvent
00784 {
00785 public:
00786         CmdRestoreFive(SpeechControlSource &parentSrc_)
00787         : CmdRestoreEvent(TtsString("restore five", 3), 4, parentSrc_) {};
00788 };
00789 
00790 
00791 // class *CmdScaleUp*
00792 // *******************************************************************************************
00793 
00794 class CmdScaleUp : public Command
00795 {
00796 public:
00797         CmdScaleUp(SpeechControlSource &parentSrc_)
00798         : Command(TtsString("scale up", 3), TtsString("scale up", 3), parentSrc_, true) {}
00799 
00800         bool redo()
00801         {
00802                 char chars[10];
00803                 std::string sentence;
00804 
00805                 scale *= 2;
00806                 sprintf(chars, "%8.4f", scale);
00807                 sentence = std::string(chars);
00808                 sentence = sentence.substr(0, sentence.find_last_not_of("0.") + 1);
00809                 if (scale >= 1.0)
00810                         sentence += ".0";
00811 
00812                 successMsg.str = "scale factor is now " + sentence;
00813                 successMsg.syl = 9 + sentence.length();
00814                 return true;
00815         };
00816         bool undo()
00817         {
00818                 char chars[10];
00819                 std::string sentence;
00820 
00821                 scale /= 2;
00822                 sprintf(chars, "%8.4f", scale);
00823                 sentence = std::string(chars);
00824                 sentence = sentence.substr(0, sentence.find_last_not_of("0.") + 1);
00825                 if (scale >= 1.0)
00826                         sentence += ".0";
00827 
00828                 successMsg.str = "scale factor is now " + sentence;
00829                 successMsg.syl = 9 + sentence.length();
00830                 return true;
00831         };
00832 };
00833 
00834 
00835 // class *CmdScaleDown*
00836 // *******************************************************************************************
00837 
00838 class CmdScaleDown : public Command
00839 {
00840 public:
00841         CmdScaleDown(SpeechControlSource &parentSrc_)
00842         : Command(TtsString("scale down", 3), TtsString("scale down", 3), parentSrc_, true)     {}
00843 
00844         bool redo()
00845         {
00846                 char chars[10];
00847                 std::string sentence;
00848 
00849                 scale /= 2;
00850                 sprintf(chars, "%8.4f", scale);
00851                 sentence = std::string(chars);
00852                 sentence = sentence.substr(0, sentence.find_last_not_of("0.") + 1);
00853                 if (scale >= 1.0)
00854                         sentence += ".0";
00855 
00856                 successMsg.str = "scale factor is now " + sentence;
00857                 successMsg.syl = 9 + sentence.length();
00858                 return true;
00859         }
00860         bool undo()
00861         {
00862                 char chars[10];
00863                 std::string sentence;
00864 
00865                 scale *= 2;
00866                 sprintf(chars, "%8.4f", scale);
00867                 sentence = std::string(chars);
00868                 sentence = sentence.substr(0, sentence.find_last_not_of("0.") + 1);
00869                 if (scale >= 1.0)
00870                         sentence += ".0";
00871 
00872                 successMsg.str = "scale factor is now " + sentence;
00873                 successMsg.syl = 9 + sentence.length();
00874                 return true;
00875         }
00876 };
00877 
00878 
00879 // class *CmdGoOn*
00880 // *******************************************************************************************
00881 
00882 class CmdGoOn : public Command
00883 {
00884 public:
00885         CmdGoOn(SpeechControlSource &parentSrc_)
00886         : Command(TtsString("go on", 2), TtsString("go on", 2), parentSrc_, false, false)
00887         {
00888                 successMsg = TtsString("going on", 3);
00889                 failureMsg = TtsString("no command to go on", 6);
00890         };
00891 
00892         bool redo()
00893         {
00894                 if (getLastCmd() && getLastCmd()->isExtendable())
00895                 {
00896                         parentSrc.setMoving(true);
00897                         getLastCmd()->extend();
00898                         return true;
00899                 }
00900                 else
00901                         return false;
00902         };
00903 };
00904 
00905 
00906 // class *CmdStop*
00907 // *******************************************************************************************
00908 
00909 class CmdStop : public Command
00910 {
00911 public:
00912         CmdStop(SpeechControlSource &parentSrc_)
00913         : Command(TtsString("stop", 1), TtsString("stop", 1), parentSrc_, false, false)
00914         {
00915                 successMsg = TtsString("stopped", 2.8);
00916                 failureMsg = TtsString("no continuous movement", 7);
00917         };
00918 
00919         bool redo()
00920         {
00921                 parentSrc.setMoving(false);
00922                 return parentSrc.isWasMoving();;
00923         };
00924 };
00925 
00926 
00927 // class *CmdAgain*
00928 // *******************************************************************************************
00929 
00930 class CmdAgain : public Command
00931 {
00932 public:
00933         CmdAgain(SpeechControlSource &parentSrc_)
00934         : Command(TtsString("again", 2), TtsString("again", 2), parentSrc_, false, false)
00935         {
00936                 successMsg = getLastCmd() ? getLastCmd()->getSuccessMsg() : TtsString();
00937                 failureMsg = TtsString("no command do be done again", 8);
00938         };
00939 
00940         bool redo()     { return parentSrc.getCmdStack().again(); };
00941 };
00942 
00943 
00944 // class *CmdQuit*
00945 // *******************************************************************************************
00946 
00947 class CmdQuit : public Command
00948 {
00949 public:
00950         CmdQuit(SpeechControlSource &parentSrc_)
00951         : Command(TtsString("quit", 1), TtsString("quit", 1), parentSrc_, false, false)
00952         {
00953                 successMsg = TtsString("quit system", 3);
00954         };
00955 
00956         bool redo()
00957         {
00958                 parentSrc.setListening(false);
00959                 return true;
00960         };
00961 };
00962 
00963 
00964 // class *CmdUndo*
00965 // *******************************************************************************************
00966 
00967 class CmdUndo : public Command
00968 {
00969 public:
00970         CmdUndo(SpeechControlSource &parentSrc_)
00971         : Command(TtsString("undo", 2), TtsString("undo", 2), parentSrc_, false, false)
00972         {
00973                 successMsg = getUndoCmd() ? getUndoCmd()->getName() + TtsString(" was undone", 3) : TtsString();
00974                 failureMsg = TtsString("no command to be undone", 7);
00975         };
00976 
00977         bool redo()
00978         {
00979                 return parentSrc.getCmdStack().undo();
00980         };
00981 };
00982 
00983 
00984 // class *CmdRedo*
00985 // *******************************************************************************************
00986 
00987 class CmdRedo : public Command
00988 {
00989 public:
00990         CmdRedo(SpeechControlSource &parentSrc_)
00991         : Command(TtsString("redo", 2), TtsString("redo", 2), parentSrc_, false, false)
00992         {
00993                 successMsg = getRedoCmd() ? getRedoCmd()->getName() + TtsString(" was redone", 3) : TtsString();
00994                 failureMsg = TtsString("no command to be redone", 7);
00995         };
00996 
00997         bool redo()
00998         {
00999                 return parentSrc.getCmdStack().redo();
01000         };
01001 };
01002 
01003 
01004 } // namespace ot
01005 
01006 
01007 #endif

Generated on Wed Feb 28 15:18:48 2007 for NaviTrack by  doxygen 1.4.6