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

  1. #pragma segment Matrix
  2. //**********************************************************************
  3. //    TDeleteGridCommand - Methods
  4. //**********************************************************************
  5. // -------------------------------------------------------------------------------------------------
  6. //    TDeleteGridCommand Methods.
  7. // -------------------------------------------------------------------------------------------------
  8. // -------------------------------------------------------------------------------------------------
  9. // Initialize the TDeleteGridCommand.
  10. // -------------------------------------------------------------------------------------------------
  11. Boolean TDeleteGridCommand::IDeleteGridCommand (TGeomView * itsGeometry, TPoint * tPt)
  12.     {
  13.     TPoint    *    oPt;
  14.     short        temp;
  15.     
  16.     fGeom             = itsGeometry;                                                                                // save geometry
  17.     fCDocument     = (TCFDFrontDocument *) fGeom->fCDocument;                            // save document
  18.     fPoint            = tPt;
  19.     fSide             = (TBoundry *) ((TPointMatrix *) fCDocument->fPointMatrix)->GetCurrentBoundry();
  20.     
  21.     HLock((Handle) this);
  22.     (TPointMatrix *) (fCDocument->fPointMatrix)->SetCornors(fPoint, &fInfo);        // find the surrounding points
  23.     HUnlock((Handle) this);
  24.     fPoint->RememberPoint();
  25.     fRow            = ((TPointMatrix *) fCDocument->fPointMatrix)->GetRow();        // get the current row
  26.     fColumn        = ((TPointMatrix *) fCDocument->fPointMatrix)->GetColumn();    // get the current column
  27.     oPt                = ((TPointMatrix *) fCDocument->fPointMatrix)->GetOpposite(fSide, fRow, fColumn);    // get point on opposite boundry    
  28.     
  29.     SysBeep (3);
  30.     if (oPt->IsSegment())
  31.         {
  32.         TWarning * tWarning;
  33.         TWindow    * aWindow;
  34.         
  35.         aWindow = NewTemplateWindow(kWarnMe, fCDocument);
  36.         tWarning = (TWarning *) aWindow->FindSubView('WARN');
  37.         tWarning->IWarning(7,NULL);
  38.         tWarning->ShowWarning();
  39.         return false;
  40.         }
  41.     else if ((temp = ((TPointMatrix *) fCDocument->fPointMatrix)->ObsBaffInLine(fSide)) != 0)
  42.         {
  43.         char    msg[80];
  44.         
  45.         if (temp == 1)
  46.             sprintf(msg,"Obstacle");
  47.         else
  48.             sprintf(msg,"Baffle");
  49.         TWarning * tWarning;
  50.         TWindow    * aWindow;
  51.         
  52.         aWindow = NewTemplateWindow(kWarnMe, fCDocument);
  53.         tWarning = (TWarning *) aWindow->FindSubView('WARN');
  54.         tWarning->IWarning(9,msg);
  55.         tWarning->ShowWarning();
  56.         return false;
  57.         }
  58.         
  59.     Boolean            dismiss;
  60.     TWindow        * aWindow;
  61.     TWarnDelete    * dWarn;
  62.     char                message[80];
  63.     
  64.     sprintf(message,"Delete Grid Line?");
  65.     aWindow = NewTemplateWindow(kWarnDelete, fCDocument);
  66.     if (aWindow == NULL)
  67.         return false;
  68.     dWarn = (TWarnDelete *) aWindow->FindSubView('delt');
  69.     dismiss = dWarn->ShowDelete(message);
  70.     if (!dismiss)
  71.         return false;
  72.         
  73.     ICommand (cDeleteSecCommand,fCDocument, fGeom, fGeom->GetScroller(true));
  74.     fConstrainsMouse = true;
  75.     return true;
  76.     }
  77. // --------------------------------------------------------------------------------------------------
  78. //    Do it.
  79. // --------------------------------------------------------------------------------------------------
  80. pascal void TDeleteGridCommand::DoIt (void)
  81.     {
  82.     fGeom->Focus();
  83.     ((TPointMatrix *) fCDocument->fPointMatrix)->SetCurrent(fPoint);
  84.     saveDeleted = ((TPointMatrix *) fCDocument->fPointMatrix)->DeleteCurrent(fSide);
  85.     fPoint = NULL;
  86.     
  87.     ((TInformationView *) fCDocument->fInfoView)->ShowDimension();
  88.     return;
  89.     }
  90.  
  91. // --------------------------------------------------------------------------------------------------
  92. //     Undo it.
  93. // --------------------------------------------------------------------------------------------------
  94. pascal void TDeleteGridCommand::UndoIt (void)
  95.     {
  96.     fGeom->Focus();
  97.     fPoint = ((TPointMatrix *) fCDocument->fPointMatrix)->AddLine(saveDeleted,fSide,fRow,fColumn);    
  98.     ((TPointMatrix *) fCDocument->fPointMatrix)->SetCurrent(fPoint);
  99.     ((TInformationView *) fCDocument->fInfoView)->ShowDimension();
  100.     ((TInformationView *) fCDocument->fInfoView)->StatusString(fPoint->fStart);    
  101.     }
  102.  
  103. // --------------------------------------------------------------------------------------------------
  104. //     Redo it.
  105. // --------------------------------------------------------------------------------------------------
  106. pascal void TDeleteGridCommand::RedoIt (void)
  107.     {
  108.     this->DoIt();
  109.     }
  110.  
  111. // --------------------------------------------------------------------------------------------------
  112. //     TrackMouse :    Do Nothing
  113. // --------------------------------------------------------------------------------------------------
  114. pascal TCommand * TDeleteGridCommand::TrackMouse (TrackPhase thePhase, VPoint * /*anchorPoint*/,
  115.     VPoint * /*previousPoint*/, VPoint * /*nextPoint*/, Boolean /*mouseDidMove*/)
  116.     {
  117.     if (!fGeom->IsDragging())                                                                        // starting the delete procedure?
  118.         {                                                                                                        // show trash cans
  119.         fGeom->lastCmd = 1;
  120.         fGeom->SetDragging(true);                                                                // turn dragging on
  121.         if (fGeom->fSPoint != NULL)                                                                // is there a selected point?
  122.             {
  123.             ((TPointMatrix *) fCDocument->fPointMatrix)->DoHighlight();        // unhighlight
  124.             fGeom->UnSelect();                                                                        // turn off selection
  125.             }
  126.         }
  127.     if (thePhase == trackRelease)
  128.         fGeom->SetDragging(false);
  129.     return this;
  130.     }
  131.     
  132. // --------------------------------------------------------------------------------------------------
  133. //    Give user feedback on the mouse drag
  134. // --------------------------------------------------------------------------------------------------
  135. pascal void TDeleteGridCommand::TrackFeedback(VPoint * /*anchorPoint*/,VPoint * /*nextPoint*/, 
  136.     Boolean /*turnItOn*/, Boolean /*mouseDidMove*/)
  137.     {
  138.     return;
  139.     }
  140.     
  141. // --------------------------------------------------------------------------------------------------
  142. //     Commit ObstacleCommand
  143. // --------------------------------------------------------------------------------------------------
  144. pascal void TDeleteGridCommand::Commit (void)
  145.     {
  146.     short x, side;
  147.     TPoint * t;
  148.     
  149.     side = fSide->GetSide();
  150.     for (x = (short) saveDeleted->fSize; x > 0; x--)
  151.         {
  152.         t = (TPoint *) saveDeleted->At(x);
  153.         saveDeleted->Delete(t);
  154.         FreeIfObject(t);
  155.         }
  156.  
  157.     if (side == cLeft || side == cRight)                                                                // if on right or left delete the list
  158.         FreeIfObject(saveDeleted);
  159.     }
  160.  
  161.