home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / UIFlow 1.0.1 / UIFlow Source / CFDFront / TObstacleCommand.cp < prev    next >
Encoding:
Text File  |  1992-02-21  |  7.6 KB  |  215 lines  |  [TEXT/MPS ]

  1. #pragma segment Matrix
  2. //**********************************************************************
  3. //    TNewSegmentCommand - Methods
  4. //**********************************************************************
  5. // -------------------------------------------------------------------------------------------------
  6. //    TObstacleCommand Methods.
  7. // -------------------------------------------------------------------------------------------------
  8. // -------------------------------------------------------------------------------------------------
  9. // Initialize the TObstacleCommand.
  10. // -------------------------------------------------------------------------------------------------
  11. pascal void TObstacleCommand::IObstacleCommand (TGeomView * itsGeometry, TCFDFrontDocument * itsDocument, PointInfo * info)
  12.     {
  13.     fGeom             = itsGeometry;                                                                        // save geometry
  14.     fCDocument     = itsDocument;                                                                        // save document
  15.     fInfo.oPt        = info->oPt;
  16.     fInfo.above    = info->above;
  17.     fInfo.left        = info->left;
  18.     fInfo.below    = info->below;
  19.     ICommand (cMakeObstacle,fCDocument, fGeom, fGeom->GetScroller(true));
  20.     fConstrainsMouse = true;
  21.     }
  22.  
  23. // --------------------------------------------------------------------------------------------------
  24. //    Do it.
  25. // --------------------------------------------------------------------------------------------------
  26. pascal void TObstacleCommand::DoIt (void)
  27.     {
  28.     fObstacle = new TObstacle;
  29.     if (fObstacle == NULL)
  30.         {
  31.         SysBeep (3);
  32.         TWarning * tWarning;
  33.         TWindow    * aWindow;
  34.         
  35.         aWindow = NewTemplateWindow(kWarnMe, fCDocument);
  36.         tWarning = (TWarning *) aWindow->FindSubView('WARN');
  37.         tWarning->IWarning(6,"Obstacle");
  38.         tWarning->ShowWarning();
  39.         return;
  40.         }
  41.         
  42.     HLock((Handle) this);
  43.     fObstacle->IObstacle(&fInfo);                                                                    // initialize obstacle
  44.     HUnlock((Handle) this);
  45.     fGeom->Focus();
  46.     fObstacle->Draw();                                                                                    // draw the obstacle
  47.     return;
  48.     }
  49.  
  50. // --------------------------------------------------------------------------------------------------
  51. //     Undo it.
  52. // --------------------------------------------------------------------------------------------------
  53. pascal void TObstacleCommand::UndoIt (void)
  54.     {
  55.     fGeom->Focus();
  56.     fObstacle->ReleaseObstacle();
  57.     fObstacle->Draw();
  58.     }
  59.  
  60. // --------------------------------------------------------------------------------------------------
  61. //     Redo it.
  62. // --------------------------------------------------------------------------------------------------
  63. pascal void TObstacleCommand::RedoIt (void)
  64.     {
  65.     fGeom->Focus();
  66.     fObstacle->SetObstacle();
  67.     fObstacle->Draw();
  68.     }
  69.  
  70. // --------------------------------------------------------------------------------------------------
  71. //     Commit ObstacleCommand
  72. // --------------------------------------------------------------------------------------------------
  73. pascal void TObstacleCommand::TrackFeedback(VPoint * /*anchorPoint*/,VPoint * /*nextPoint*/, 
  74.     Boolean /*turnItOn*/, Boolean /*mouseDidMove*/)
  75.     {
  76.     fGeom->lastCmd = 1;
  77.     return;                                                                                                    // do nothing
  78.     }
  79.  
  80. // --------------------------------------------------------------------------------------------------
  81. //     Commit ObstacleCommand
  82. // --------------------------------------------------------------------------------------------------
  83. pascal void TObstacleCommand::Commit (void)
  84.     {
  85.     fObstacle = NULL;                                                                                    // don't want to free the object
  86.     }
  87.  
  88. // --------------------------------------------------------------------------------------------------
  89. //     Free ObstacleCommand
  90. // --------------------------------------------------------------------------------------------------
  91. pascal void TObstacleCommand::Free (void)
  92.     {
  93.     if (!fCmdDone)
  94.         FreeIfObject(fObstacle);
  95.     inherited::Free();
  96.     }
  97.  
  98. //**********************************************************************
  99. //    TDeleteObstacleCommand - Methods
  100. //**********************************************************************
  101. // -------------------------------------------------------------------------------------------------
  102. //    TDeleteObstacleCommand Methods.
  103. // -------------------------------------------------------------------------------------------------
  104. // -------------------------------------------------------------------------------------------------
  105. // Initialize the TDeleteObstacleCommand.
  106. // -------------------------------------------------------------------------------------------------
  107. Boolean TDeleteObstacleCommand::IDeleteObstacleCommand (TGeomView * itsGeometry, TCFDFrontDocument * itsDocument, PointInfo * info)
  108.     {
  109.     fGeom             = itsGeometry;                                                                        // save geometry
  110.     fCDocument     = itsDocument;                                                                        // save document
  111.     fInfo.oPt        = info->oPt;
  112.     fInfo.above    = info->above;
  113.     fInfo.left        = info->left;
  114.     fInfo.below    = info->below;
  115.  
  116.     fObstacle = (TObstacle *) fInfo.oPt->fObsLwRight;
  117.     SysBeep (3);
  118.  
  119.     Boolean            dismiss;
  120.     TWindow        * aWindow;
  121.     TWarnDelete    * dWarn;
  122.     char                message[80];
  123.     
  124.     sprintf(message,"Delete Obstacle?");
  125.     aWindow = NewTemplateWindow(kWarnDelete, fCDocument);
  126.     if (aWindow == NULL)
  127.         return false;
  128.     dWarn = (TWarnDelete *) aWindow->FindSubView('delt');
  129.     dismiss = dWarn->ShowDelete(message);
  130.     if (!dismiss)
  131.         return false;
  132.         
  133.     ICommand (cMakeObstacle,fCDocument, fGeom, fGeom->GetScroller(true));
  134.     fConstrainsMouse = true;
  135.     return true;
  136.     }
  137. // --------------------------------------------------------------------------------------------------
  138. //    Do it.
  139. // --------------------------------------------------------------------------------------------------
  140. pascal void TDeleteObstacleCommand::DoIt (void)
  141.     {
  142.     StringPtr pString;
  143.     char            string[80];
  144.     
  145.     sprintf(string,"Undo Delete Obstacle");
  146.     pString = c2pstr(string);
  147.     SetCmdName(cUndo,pString);
  148.  
  149.     fGeom->Focus();
  150.     fObstacle->ReleaseObstacle();
  151.     fObstacle->Draw();                                                                    // draw the obstacle
  152.     return;
  153.     }
  154.  
  155. // --------------------------------------------------------------------------------------------------
  156. //     Undo it.
  157. // --------------------------------------------------------------------------------------------------
  158. pascal void TDeleteObstacleCommand::UndoIt (void)
  159.     {
  160.     StringPtr pString;
  161.     char            string[80];
  162.     
  163.     sprintf(string,"Redo Delete Obstacle");
  164.     pString = c2pstr(string);
  165.     SetCmdName(cUndo,pString);
  166.  
  167.     fGeom->Focus();
  168.     fObstacle->SetObstacle();
  169.     fObstacle->Draw();
  170.     }
  171.  
  172. // --------------------------------------------------------------------------------------------------
  173. //     Redo it.
  174. // --------------------------------------------------------------------------------------------------
  175. pascal void TDeleteObstacleCommand::RedoIt (void)
  176.     {
  177.     StringPtr pString;
  178.     char            string[80];
  179.     
  180.     sprintf(string,"Undo Delete Obstacle");
  181.     pString = c2pstr(string);
  182.     SetCmdName(cUndo,pString);
  183.  
  184.     fGeom->Focus();
  185.     fObstacle->ReleaseObstacle();
  186.     fObstacle->Draw();
  187.     }
  188.  
  189. // --------------------------------------------------------------------------------------------------
  190. //     Commit ObstacleCommand
  191. // --------------------------------------------------------------------------------------------------
  192. pascal void TDeleteObstacleCommand::TrackFeedback(VPoint * /*anchorPoint*/,VPoint * /*nextPoint*/, 
  193.     Boolean /*turnItOn*/, Boolean /*mouseDidMove*/)
  194.     {
  195.     fGeom->lastCmd = 1;
  196.     return;                                                                                                    // do nothing
  197.     }
  198.  
  199. // --------------------------------------------------------------------------------------------------
  200. //     Commit ObstacleCommand
  201. // --------------------------------------------------------------------------------------------------
  202. pascal void TDeleteObstacleCommand::Commit (void)
  203.     {
  204.     FreeIfObject(fObstacle);
  205.     }
  206.  
  207. // --------------------------------------------------------------------------------------------------
  208. //     Free ObstacleCommand
  209. // --------------------------------------------------------------------------------------------------
  210. pascal void TDeleteObstacleCommand::Free (void)
  211.     {
  212.     inherited::Free();
  213.     }
  214.  
  215.