home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / freedraft.tar.gz / freedraft.tar / FREEdraft-050298 / VIEWPORT / vdcmdwin.cpp < prev    next >
C/C++ Source or Header  |  1998-05-01  |  13KB  |  549 lines

  1. // vdcmdwin.cpp
  2.  
  3. // Copyright (C) 1997  Cliff Johnson                                       //
  4. //                                                                         //
  5. // This program is free software; you can redistribute it and/or           //
  6. // modify it under the terms of the GNU  General Public                    //
  7. // License as published by the Free Software Foundation; either            //
  8. // version 2 of the License, or (at your option) any later version.        //
  9. //                                                                         //
  10. // This software is distributed in the hope that it will be useful,        //
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of          //
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       //
  13. // General Public License for more details.                                //
  14. //                                                                         //
  15. // You should have received a copy of the GNU General Public License       //
  16. // along with this software (see COPYING.LIB); if not, write to the        //
  17. // Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
  18.  
  19. #include <iostream.h>
  20. #include <v/vnotice.h>  // so we can use notice
  21. #include <v/vkeys.h>    // to map keys
  22. #include <v/vutil.h>    // for utilities
  23. #include <v/vicon.h>
  24. #include <v/vfilesel.h> // for file select
  25.  
  26. #include <vdcmdwin.h>            // our header file
  27. #include <vdapp_enum.h>
  28. #include <data_enum.h>
  29. #include <geom_enum.h>
  30. #include <saverecallmenu_enum.h>
  31. #include <attrib_enum.h>
  32. //#include <geommenu_enum.h>
  33.  
  34. #include <attributes.h>        //ITO
  35. #include <handle.h>        //ITO
  36. #include <point.h>        //ITO
  37. #include <line.h>        //ITO
  38. #include <canvasregister.h>     //ITO
  39. #include <selection.h>
  40. //#include <menuhandler.h>
  41.  
  42. #include <geommenuhandler.h>
  43. #include <nomenuhandler.h>
  44. #include <saverecallmenuhandler.h>
  45. #include <measurementmenuhandler.h>
  46.  
  47. #include <selectionfilter.h>
  48.  
  49. #include <coreexception.h>
  50.  
  51. #include <tabledrawables.h>
  52.  
  53. // main menu definitions
  54. #include <vdmainmenu.cpp_>    // sub classed
  55.  
  56. // entity selection / modifier menu definitions
  57. #include <vdtypemaskbar.cpp_>    // sub classed
  58.  
  59. // function menu definitions
  60. #include <vdfunctionmenu.cpp_>    // sub classed
  61.  
  62.  
  63.  
  64.  
  65. static vStatus InputStatusBar[] = 
  66. {
  67.   {"                                                  ",m_InputStatusPane,CA_None,isSens,0},
  68.   {0,0,0,0,0}
  69. };
  70.  
  71.   vdCmdWindow::vdCmdWindow(char* name, int width, int height) :
  72.         vCmdWindow(name, width, height),
  73. //    inputString(),  ... moved to menuhandler 
  74.     typeMaskBehavior()
  75.   {
  76.     currentColor =  FD_WHITE;
  77.    currentLineStyle = FD_LINESTYLE_SOLID;
  78.     currentThick = FD_LINETHICK_NORMAL;
  79.     currentPointSize = FD_POINTSIZE_NORMAL;
  80.     currentLayer = 1;
  81.     currentFileName = string();
  82.     
  83.     // constructor for vdCmdWindow. 
  84.  
  85.     snapResolution = DEFAULT_SNAP_RESOLUTION;
  86.  
  87.     UserDebug1(Constructor,"vdCmdWindow::vdCmdWindow(%s) Constructor\n",name)
  88.  
  89.     // Create and add the standard Menu Bar to this window
  90.     vdMainMenu = new vMenuPane(StandardMenu);
  91.     AddPane(vdMainMenu);
  92.  
  93.     // Create and add our Canvas pane to this window
  94.  
  95.     drawregister = new CanvasRegister();
  96.  
  97.     vdglcanvas = new VDGLCanvas(drawregister);
  98.     
  99.     AddPane(vdglcanvas);
  100.  
  101.  // Create and add the typemask command pane
  102.     typeMaskCmdPane = new vCommandPane(TypeMaskCommandBar);
  103.     AddPane(typeMaskCmdPane);
  104.  
  105. // function menu 
  106.     functionMenuCmdPane = new vCommandPane(FunctionMenuCommandBar);
  107.     AddPane(functionMenuCmdPane);
  108.  
  109. // input status pane
  110.     inputStatusPane = new vStatusPane(InputStatusBar);
  111.     AddPane(inputStatusPane);
  112.  
  113.     // FINALLY, after all the panes have been constructed and
  114.     // added, we must show the window!
  115.  
  116.     ShowWindow();
  117.  
  118. // Create the geometry bank
  119.  
  120.     bank = new GeomBank();
  121.  
  122. // initialize the drawables
  123.     tableDrawables = new TableDrawables();
  124.  
  125. // Create the menu handler;
  126.  
  127.     menuHandler = new GeomMenuHandler(this,-1);
  128.   }
  129.  
  130. //=====================>>> vdCmdWindow::~vdCmdWindow <<<====================
  131.   vdCmdWindow::~vdCmdWindow()
  132.   {
  133.     UserDebug(Destructor,"vdCmdWindow::~vdCmdWindow() destructor\n")
  134.  
  135.     // Now put a delete for each new in the constructor.
  136.     delete menuHandler;
  137.     delete tableDrawables;
  138.     delete bank;
  139.     delete functionMenuCmdPane;
  140.     delete typeMaskCmdPane;
  141.     delete vdglcanvas;
  142.     delete vdMainMenu;
  143.     delete inputStatusPane;
  144.   }
  145.  
  146. //************************>>> vdCmdWindow::KeyIn <<<********************************************
  147.   void vdCmdWindow::KeyIn(vKey keysym, unsigned int shift)
  148.   {
  149. //cout << "void vdCmdWindow::KeyIn( " << (unsigned int) keysym << " , " << shift << " ) " << endl;
  150.  
  151. // intersept some codes for direct action by viewer
  152.     switch(keysym)
  153.     {
  154. //    case KB_CenterView:
  155.         case KB_ZoomUp:
  156.         case KB_ZoomDown:
  157.         case KB_LeftArrow:
  158.         case KB_UpArrow:
  159.         case KB_RightArrow:
  160.         case KB_DownArrow:
  161.         {
  162.         vdglcanvas->ModifyView(keysym);
  163.         break;
  164.         }
  165.     case KB_SpaceBar:
  166.         {
  167.             menuHandler->LoadModifier(FD_KEYBOARD);
  168.             break;
  169.         }
  170.     }
  171.  
  172. //cout << "KeyIn--> " << endl;
  173.   }
  174.  
  175. //====================>>> vdCmdWindow::WindowCommand <<<===================
  176.   void vdCmdWindow::WindowCommand(ItemVal id, ItemVal val, CmdType cType)
  177.   {
  178.  
  179. // calling sub-handler functions makes this much easier to read!
  180.  
  181.     switch (id)                 // The main switch to handle commands
  182.     {
  183.  
  184. // File Menu commands ------------------------------------
  185.  
  186.         case M_New:
  187.         case M_Open:            // This demos vFileSelect dialog
  188.         case M_Save:            // This would usually save a file
  189.         case M_SaveAs:          // Save to a specified name
  190.         case M_SetDebug:
  191.         case M_Exit:            // Standard exit command
  192.           {
  193.         FileMenuCommand(id, val, cType);
  194.         break;
  195.           }    
  196.  
  197. // Attribute Menu Commands ----------------------------------
  198.  
  199.  
  200.     case m_ColorAttribute:
  201.     case m_LayerAttribute:
  202.     case m_LineTypeAttribute:
  203.         {
  204.         AttributeMenuCommand(id, val, cType);
  205.         break;
  206.         }
  207.  
  208.  
  209. // View Menu Commands ----------------------------------
  210.  
  211.     case m_ViewReset:
  212.     case m_ViewScale:
  213.         {
  214.         ViewMenuCommand(id, val, cType);
  215.         break;
  216.         }
  217.  
  218. // module Menu Commands -------------------------------
  219.     case m_GeometryModule:
  220.         {
  221.         delete menuHandler;
  222.         menuHandler = new GeomMenuHandler(this, -1);
  223.         break;
  224.         }
  225.  
  226.     case m_MeasurementModule:
  227.         {
  228.         delete menuHandler;
  229.         menuHandler = new MeasurementMenuHandler(this, -1);
  230.         break;
  231.         }
  232.         
  233.  
  234.     case m_NoModule:
  235.         {
  236.         delete menuHandler;
  237.         menuHandler = new NoMenuHandler(this, -1);
  238.         break;
  239.         }
  240.  
  241. // Action button bar commands ----------------------------------
  242.     case m_ClearMask:
  243.     case m_Wildcard:    
  244.         case m_Sum:           
  245.         case m_Point:        
  246.     case m_Line:        
  247.     case m_Circle:        
  248.     case m_Segment:
  249.     case m_Arc:
  250.     case m_Ellipse:        
  251.     case m_Curve:        
  252.     case m_Group:        
  253.     case m_Pan:
  254.     case m_CView:
  255.     case m_ZoomIn:
  256.     case m_ZoomOut:
  257.     case m_MaxZoom:
  258.         {
  259.         ButtonBarCommand(id, val, cType);
  260.         break;
  261.         }
  262. //Modifier buttons
  263.     case FD_ENDPOINT:
  264.     case FD_MIDPOINT:
  265.     case FD_CENTER:
  266.     case FD_INTERSECTION:
  267.     case FD_SUPPORT:
  268.     case FD_KEYBOARD:
  269.         {
  270.         menuHandler->LoadModifier(id);
  271.         break;
  272.         }
  273. //Function Menus-------------------------------------------------
  274.  
  275.     case MENUBUTTON00:
  276.     case MENUBUTTON01:
  277.     case MENUBUTTON10:
  278.     case MENUBUTTON11:
  279.     case MENUBUTTON20:
  280.     case MENUBUTTON21:
  281.     case MENUBUTTON30:
  282.     case MENUBUTTON31:
  283.     case MENUBUTTON40:
  284.     case MENUBUTTON41:
  285.     case MENUBUTTON50:
  286.     case MENUBUTTON51:
  287.     case MENUBUTTON60:
  288.     case MENUBUTTON61:
  289.     case MENUBUTTON70:
  290.     case MENUBUTTON71:
  291.     case MENUBUTTON80:
  292.     case MENUBUTTON81:
  293.     case MENUBUTTON90:
  294.     case MENUBUTTON91:
  295.     case FD_CANCEL:
  296.     case FD_CONFIRM:
  297.     case FD_DELETE:
  298.     case FD_QUERY:
  299.     case FD_COLORBUTTON:
  300.         {
  301.         menuHandler->MenuCommand(id);
  302.         break;
  303.         }
  304.  
  305.         default:   // route unhandled commands up to superclass
  306.         {
  307.                 vCmdWindow::WindowCommand(id, val, cType);
  308.                 break;
  309.               }
  310.     }
  311. }
  312.  
  313. //==============vdCmdWindow::FileMenuCommands=================================================
  314.  
  315.  
  316. void vdCmdWindow::FileMenuCommand(ItemVal id, ItemVal val, CmdType cType)
  317. {
  318.     vNoticeDialog note(this);
  319.  
  320. // default file filters for save recall
  321.         static char* defaultSaveRecallFilter[] = { "*.fdf", "*", 0 };
  322.     int fI = 0;            // Filter index
  323.     char name[100] = ""; // initial name string is null
  324.  
  325.     char * filedir = getenv("FD_FILES"); 
  326.  
  327. cerr << "filedir = " << filedir << endl;
  328.     switch(id)
  329.     {
  330.  
  331.     case M_New:             // For this example, we will open a
  332.         {                     // new window using our NewAppWin.
  333.             (void)theApp->NewAppWin(0,"",250, 100);
  334.             break;
  335.         }
  336.  
  337.     case M_Open:            // This demos vFileSelect dialog
  338.         {
  339.             vFileSelect fsel(this);     // an instance of vFileSelect
  340.  
  341. // Show the file select dialog
  342.             int ans = fsel.FileSelect("Open file",name,99,defaultSaveRecallFilter,fI,filedir);
  343.  
  344.             if (!ans || !(*name))   // User did not pick a file name
  345.             {
  346.                 return;
  347.             }
  348.             currentFileName = string(name);
  349.  
  350. // open the save/recall menuhandler
  351.             delete menuHandler;
  352.             menuHandler = new SaveRecallMenuHandler(this, -1);
  353. // pass the save command to the menuhandler
  354.             menuHandler->MenuCommand(FD_RECALL);
  355.  
  356.             break;
  357.         }
  358.  
  359.     case M_Save:            // This would usually save a file
  360.     case M_SaveAs:          // Save to a specified name
  361.         {
  362. //            note.Notice("Save");
  363. // initialize the save/recall menu
  364. // if there is not a current file name, do the file selection thingy - let the user select/enter a file
  365.             if(currentFileName == string() || id == M_SaveAs)
  366.             {
  367.     
  368.                 vFileSelect fsel(this);     // an instance of vFileSelect
  369.  
  370. // Show the file select dialog
  371.                 int ans = fsel.FileSelect("Open file",name,99,defaultSaveRecallFilter,fI,filedir);
  372.                 if (!ans || !(*name))   // User did not pick a file name
  373.                 {
  374.                     return;
  375.                 }
  376. // copy the name into the currentFileName string
  377.                 currentFileName = string(name);
  378.             }
  379.  
  380. // open the save menuhandler
  381.             delete menuHandler;
  382.             menuHandler = new SaveRecallMenuHandler(this, -1);
  383. // pass the save command to the menuhandler
  384.             menuHandler->MenuCommand(FD_SAVE);
  385.             break;
  386.         }
  387.  
  388. #ifdef vDEBUG                   // Include debugging like this
  389.         case M_SetDebug:
  390.           {
  391.             vDebugDialog debug(this);   // an instance of debug 
  392.             debug.SetDebug();           // dialog - let user set
  393.             break;
  394.           }
  395. #endif
  396.  
  397.         case M_Exit:            // Standard exit command
  398.           {                     // Invoke the standard app Exit
  399.             theApp->Exit();     // to close all windows
  400.             break;              // will never get here
  401.           }
  402.     }
  403. }
  404.  
  405. //============vdCmdWindow::AttributeMenuCommands=================================================
  406.  
  407.  
  408. void vdCmdWindow::AttributeMenuCommand(ItemVal id, ItemVal val, CmdType cType)
  409. {
  410.         menuHandler->MenuCommand(id);
  411. }
  412. //==============vdCmdWindow::ViewMenuCommands=================================================
  413.  
  414.  
  415.  
  416. void vdCmdWindow::ViewMenuCommand(ItemVal id, ItemVal val, CmdType cType)
  417. {
  418.     switch(id)
  419.     {
  420.     case m_ViewReset:
  421.         {
  422.         vdglcanvas->ResetView();    
  423.         break;
  424.         }
  425.     }
  426. }
  427.  
  428.  
  429. //================vdCmdWindow::ButtonBarCommands=========================================
  430.  
  431.  
  432. void vdCmdWindow::ButtonBarCommand(ItemVal id, ItemVal val, CmdType cType)
  433. {
  434.     switch(id)
  435.     {
  436.  
  437. // Operators
  438.     case m_ClearMask:
  439.         {    // set all the toggle buttons off
  440.         typeMaskBehavior.Clear(this);
  441.         break;
  442.         }
  443.  
  444.     case m_Wildcard:    
  445.         {    // set all the toggle buttons on
  446.         typeMaskBehavior.All(this);
  447.         break;
  448.         }
  449.         case m_Sum:           
  450.         {
  451.         // toggle the sumMode;
  452.         typeMaskBehavior.SetSumMode(this,GetValue(m_Sum));
  453.         break;
  454.         }
  455.         
  456.         case m_Point:        
  457.     case m_Line:        
  458.     case m_Circle:        
  459.     case m_Segment:
  460.     case m_Arc:
  461.     case m_Ellipse:        
  462.     case m_Curve:        
  463.     case m_Group:        
  464.         {    
  465.         typeMaskBehavior.Selected(this,id);
  466.         break;
  467.         }
  468.  
  469.     case m_Pan:
  470.         {
  471.         functionMapBehavior.Selected(this,id);
  472.         vdglcanvas->CancelAction();
  473.         vdglcanvas->PickPan();
  474.         break;
  475.         }
  476.     case m_CView:
  477.         {
  478.         functionMapBehavior.Selected(this,id);
  479.         vdglcanvas->CancelAction();
  480.         vdglcanvas->PickCenter();
  481.         break;
  482.         }
  483.     case m_ZoomIn:
  484.         {
  485.         functionMapBehavior.Selected(this,id);
  486.         vdglcanvas->CancelAction();
  487.         vdglcanvas->ZoomIn();
  488.         break;
  489.         }
  490.     case m_ZoomOut:
  491.         {
  492.         functionMapBehavior.Selected(this,id);
  493.         vdglcanvas->CancelAction();
  494.         vdglcanvas->ZoomOut();
  495.         break;
  496.         }
  497.     case m_MaxZoom:
  498.         {
  499.         functionMapBehavior.Clear(this);
  500.         vdglcanvas->CancelAction();
  501.         break;
  502.         }
  503.     }
  504. }
  505.  
  506.  
  507. //====================vdCmdWindow::CanvasPick=============================
  508.  
  509. void vdCmdWindow::CanvasPick(const SelectStack& ss)
  510. {
  511.  
  512. cerr << "-->CanvasPick()" << endl;
  513.  
  514.     Selection s = Selection(Handle(),ss.GetPoint(),ss.GetButton());
  515.  
  516. // filter the select stack according to the current button settings
  517.     SelectionFilter sf = typeMaskBehavior.GetFilter();
  518.  
  519.     sf.SetCriteria(CLOSEST);
  520.  
  521.     SelectStack ssx  = ss.Filter(sf);
  522.  
  523.     try 
  524.     {
  525.         s = ssx.SelectTop(); 
  526.     }
  527.     catch (CoreException & ce)
  528.     {
  529.                 //cerr << "CoreException raised in vdCmdWindow::CanvasPick()" << endl;
  530.                 //cerr << "       " << ce << endl;
  531.         }
  532.  
  533.     menuHandler->DoPick(s);
  534. }
  535.  
  536.  
  537. //====================vdCmdWindow::LoadMenuLabel=============================
  538.  
  539. //void vdCmdWindow::LoadMenuLabel(int id,  const char* label, int sensitive)
  540. //{
  541. //
  542. //
  543. //}
  544. //void vdCmdWindow::LoadMenuButtons(int id,  const char* label, int sensitive)
  545. //{
  546. //
  547. //
  548. //}
  549.