taxplot3d_widget.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:10k
源码类别:

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: taxplot3d_widget.cpp,v $
  4.  * PRODUCTION Revision 1000.1  2004/06/01 21:13:47  gouriano
  5.  * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. /*  $Id: taxplot3d_widget.cpp,v 1000.1 2004/06/01 21:13:47 gouriano Exp $
  10.  * ===========================================================================
  11.  *
  12.  *                            PUBLIC DOMAIN NOTICE
  13.  *               National Center for Biotechnology Information
  14.  *
  15.  *  This software/database is a "United States Government Work" under the
  16.  *  terms of the United States Copyright Act.  It was written as part of
  17.  *  the author's official duties as a United States Government employee and
  18.  *  thus cannot be copyrighted.  This software/database is freely available
  19.  *  to the public for use. The National Library of Medicine and the U.S.
  20.  *  Government have not placed any restriction on its use or reproduction.
  21.  *
  22.  *  Although all reasonable efforts have been taken to ensure the accuracy
  23.  *  and reliability of the software and data, the NLM and the U.S.
  24.  *  Government do not and cannot warrant the performance or results that
  25.  *  may be obtained by using this software or data. The NLM and the U.S.
  26.  *  Government disclaim all warranties, express or implied, including
  27.  *  warranties of performance, merchantability or fitness for any particular
  28.  *  purpose.
  29.  *
  30.  *  Please cite the author in any work or product based on this material.
  31.  *
  32.  * ===========================================================================
  33.  *
  34.  * Authors:  Vladimir Tereshkov
  35.  *
  36.  * File Description:  
  37.  *   Taxplot 3-dimensional widget 
  38.  */
  39. #include <ncbi_pch.hpp>
  40. #include <gui/opengl/glfont.hpp>
  41. #include <gui/graph/igraph_utils.hpp>
  42. #include <gui/widgets/taxplot3d/taxplot3d_widget.hpp>
  43. #include <gui/types.hpp>
  44. #include <FL/Fl.H>
  45. #include "taxplot3d_pane.hpp"
  46. BEGIN_NCBI_SCOPE
  47. Fl_Menu_Item pulldown[] = {
  48.   {"&View",0,0,0,FL_SUBMENU},
  49. {"Perspective",     0, 0,  (void*)CMD_PERSP_PROJECTION},
  50. {"Orthographic (XY)", 0, 0,  (void*)CMD_ORTOXY_PROJECTION},
  51. {"Orthographic (YZ)", 0, 0,  (void*)CMD_ORTOYZ_PROJECTION},
  52. {"Orthographic (XZ)", 0, 0,  (void*)CMD_ORTOXZ_PROJECTION},
  53.         {0},
  54.     {"&Objects",0,0,0,FL_SUBMENU},
  55.         {"Show",0,0,0,FL_SUBMENU},
  56.     {"Axes", 0, 0,  (void*)CMD_VIEW_AXES,   FL_MENU_TOGGLE|FL_MENU_VALUE},
  57.     {"Grid", 0, 0,  (void*)CMD_VIEW_GRID,   FL_MENU_TOGGLE|FL_MENU_VALUE},
  58.     {"Arrows", 0, 0,  (void*)CMD_VIEW_ARROWS, FL_MENU_TOGGLE|FL_MENU_VALUE},
  59.     {"Labels", 0, 0,  (void*)CMD_VIEW_LABELS, FL_MENU_TOGGLE|FL_MENU_VALUE},
  60.             {"Scale", 0, 0,  (void*)CMD_VIEW_SCALE,  FL_MENU_TOGGLE|FL_MENU_VALUE},
  61.             {0},
  62.         {"Shape",0,0,0,FL_SUBMENU},
  63.               {"Sphere", 0,0,   (void*)CMD_SHAPE_SPHERE,    FL_MENU_RADIO|FL_MENU_VALUE},
  64.               {"Cube",   0,0,   (void*)CMD_SHAPE_CUBE,      FL_MENU_RADIO},
  65.               {"Cross",  0,0,   (void*)CMD_SHAPE_CROSS,     FL_MENU_RADIO},
  66.               {0},
  67.         {0},
  68.     {"&Pivot Point", 0,0,0,FL_SUBMENU},    
  69.         {"&Position",0,0,0, FL_SUBMENU},
  70.           {"Floating",0,0,  (void*)CMD_PIVOT_FLOATING,  FL_MENU_RADIO|FL_MENU_VALUE},
  71.           {"Fixed",0,0,     (void*)CMD_PIVOT_FIXED,     FL_MENU_RADIO},
  72.           {0},
  73.         {"&Attach to selected object",0,0, (void*)CMD_PIVOT_ATTACHED, FL_MENU_TOGGLE|FL_MENU_VALUE},
  74.         {0},        
  75.     {"Color scheme", 0,0,0,FL_SUBMENU|FL_MENU_DIVIDER},
  76.         {"Scheme 1",  0, 0,  (void*)CMD_COLOR_SCHEME1,  FL_MENU_RADIO},
  77. {"Scheme 2", 0, 0,  (void*)CMD_COLOR_SCHEME2, FL_MENU_RADIO},
  78.         {"Scheme 3", 0, 0,  (void*)CMD_COLOR_SCHEME3, FL_MENU_RADIO},
  79.         {0},
  80.     {"&Refresh",0,0,(void*)CMD_REFRESH_VIEW},
  81.     {0}
  82. };
  83. void cb_Popup(Fl_Widget * widget, void * data)
  84. {
  85.     Fl_Menu_* mw = (Fl_Menu_*)widget;
  86.     const   Fl_Menu_Item* m = mw->mvalue();
  87.     switch (m->argument()){
  88.     case CMD_REFRESH_VIEW:
  89.         ((CTaxplot3dWidget*)data)->SlowRedraw();  
  90.         break;
  91.     case CMD_PERSP_PROJECTION:
  92.         ((CTaxplot3dWidget*)data)->SetViewMode(CTaxplot3dPanel::eCamera);
  93.         ((CTaxplot3dWidget*)data)->SlowRedraw();
  94.         break;
  95.     case CMD_ORTOXY_PROJECTION:
  96.         ((CTaxplot3dWidget*)data)->SetViewMode(CTaxplot3dPanel::eViewZ);
  97.         ((CTaxplot3dWidget*)data)->SlowRedraw();
  98.         break;
  99.     case CMD_ORTOYZ_PROJECTION:
  100.         ((CTaxplot3dWidget*)data)->SetViewMode(CTaxplot3dPanel::eViewX);
  101.         ((CTaxplot3dWidget*)data)->SlowRedraw();
  102.         break;
  103.     case CMD_ORTOXZ_PROJECTION:
  104.         ((CTaxplot3dWidget*)data)->SetViewMode(CTaxplot3dPanel::eViewY);  
  105.         ((CTaxplot3dWidget*)data)->SlowRedraw();
  106.         break;
  107.     case CMD_VIEW_AXES:
  108.         ((CTaxplot3dWidget*)data)->getPanel()->setVisible(CTaxplot3dPanel::eAxes, !((CTaxplot3dWidget*)data)->getPanel()->getVisible(CTaxplot3dPanel::eAxes));
  109.         ((CTaxplot3dWidget*)data)->SlowRedraw();
  110.         break;
  111.     case CMD_VIEW_GRID:
  112.         ((CTaxplot3dWidget*)data)->getPanel()->setVisible(CTaxplot3dPanel::eGrid, !((CTaxplot3dWidget*)data)->getPanel()->getVisible(CTaxplot3dPanel::eGrid));
  113.         ((CTaxplot3dWidget*)data)->SlowRedraw();
  114.         break;
  115.     case CMD_VIEW_ARROWS:
  116.         ((CTaxplot3dWidget*)data)->getPanel()->setVisible(CTaxplot3dPanel::eArrows, !((CTaxplot3dWidget*)data)->getPanel()->getVisible(CTaxplot3dPanel::eArrows));
  117.         ((CTaxplot3dWidget*)data)->SlowRedraw();
  118.         break;
  119.     case CMD_VIEW_LABELS:
  120.         ((CTaxplot3dWidget*)data)->getPanel()->setVisible(CTaxplot3dPanel::eLabels, !((CTaxplot3dWidget*)data)->getPanel()->getVisible(CTaxplot3dPanel::eLabels));
  121.         ((CTaxplot3dWidget*)data)->SlowRedraw();
  122.         break;
  123.     case CMD_VIEW_SCALE:
  124.         ((CTaxplot3dWidget*)data)->getPanel()->setVisible(CTaxplot3dPanel::eScale, !((CTaxplot3dWidget*)data)->getPanel()->getVisible(CTaxplot3dPanel::eScale));
  125.         ((CTaxplot3dWidget*)data)->SlowRedraw();
  126.         break;
  127.         break;
  128.     case CMD_SHAPE_SPHERE:
  129.         ((CTaxplot3dWidget*)data)->getPanel()->setPrimitiveShape(CTaxplot3dPanel::eSphere);
  130.         ((CTaxplot3dWidget*)data)->SlowRedraw();
  131.         break;
  132.     case CMD_SHAPE_CUBE:
  133.         ((CTaxplot3dWidget*)data)->getPanel()->setPrimitiveShape(CTaxplot3dPanel::eCube);
  134.         ((CTaxplot3dWidget*)data)->SlowRedraw();
  135.         break;
  136.     case CMD_SHAPE_CROSS:
  137.         ((CTaxplot3dWidget*)data)->getPanel()->setPrimitiveShape(CTaxplot3dPanel::eCross);
  138.         ((CTaxplot3dWidget*)data)->SlowRedraw();
  139.         break;
  140.     case CMD_PIVOT_FLOATING:
  141.         ((CTaxplot3dWidget*)data)->getPanel()->setPivotPoint(CTaxplot3dPanel::eFloating);
  142.         ((CTaxplot3dWidget*)data)->SlowRedraw();
  143.         break;
  144.     case CMD_PIVOT_FIXED:
  145.         ((CTaxplot3dWidget*)data)->getPanel()->setPivotPoint(CTaxplot3dPanel::eFixed);
  146.         ((CTaxplot3dWidget*)data)->SlowRedraw();
  147.         break;
  148.         break;
  149.     case CMD_PIVOT_ATTACHED:
  150.         ((CTaxplot3dWidget*)data)->getPanel()->setPivotAttach(!((CTaxplot3dWidget*)data)->getPanel()->getPivotAttach());
  151.         ((CTaxplot3dWidget*)data)->SlowRedraw();
  152.         break;
  153.     case CMD_COLOR_SCHEME1:
  154.     case CMD_COLOR_SCHEME2:
  155.     case CMD_COLOR_SCHEME3:
  156.         break;
  157.     }  
  158. }
  159. CTaxplot3dWidget::CTaxplot3dWidget(int x, int y,  int w, int h,
  160.                                    const char* label)
  161.     : Fl_Group(x, y, w, h, label)
  162. {     
  163.     m_3DPanel =  new CTaxplot3dPanel(x, y, w, h, label);    
  164.     m_3DPanel->box(FL_DOWN_BOX);
  165.     m_3DPanel->labeltype(FL_NORMAL_LABEL);
  166.     m_3DPanel->align(FL_ALIGN_CLIP);    
  167.     Fl_Group::current()->resizable(m_3DPanel);
  168.     end(); 
  169.     m_Event.StandardConfig();
  170.    
  171. }
  172. CTaxplot3dWidget::~CTaxplot3dWidget()
  173. {     
  174.     if (m_3DPanel)    delete m_3DPanel;
  175. }
  176. void CTaxplot3dWidget::SetDataSource(CTaxplot3dDataSource * ds)
  177. {
  178.     m_3DPanel->SetDataSource(ds);    
  179. }
  180. void CTaxplot3dWidget::SetViewMode(int mode)
  181. {
  182.     m_3DPanel->setViewMode(static_cast<CTaxplot3dPanel::EViewMode>(mode));
  183. }
  184. void CTaxplot3dWidget::SlowRedraw(void)
  185. {
  186.     m_3DPanel->slowRedraw();
  187. }
  188. int CTaxplot3dWidget::handle(int event)
  189. {
  190.     m_Event.OnFLTKEvent(event);
  191.     switch(event)   {
  192.         case FL_RELEASE: {
  193.            if(m_Event.GetGUISignal() ==  CGUIEvent::ePopupSignal)   {
  194.                     fl_cursor(FL_CURSOR_DEFAULT, FL_BLACK, FL_WHITE);
  195.                     
  196.                     Fl_Menu_Button popup(x(), y(), w(), h(), NULL);
  197.                     popup.type(Fl_Menu_Button::POPUP3);
  198.                     popup.box(FL_NO_BOX);
  199.                     popup.menu(pulldown);
  200.                     popup.callback(cb_Popup, (void*)this);
  201.                     popup.popup();  
  202.                     /*
  203.                     CMenuItem* root = new CMenuItem("root");
  204.                     root->AddSubItem("1", 2);
  205.                     root->AddSubItem("2", 2);
  206.                     root->AddSubItem("3", 2);
  207.                     CPopupMenu  Popup(x(), y(), w(), h());
  208.     
  209.                     Fl_Group::add(&Popup);
  210.     
  211.                     //Popup.SetCmdTarget(this);
  212.                     Popup.SetItems(root);
  213.                     Popup.popup();
  214.     
  215.                     Fl_Group::remove(Popup);
  216.                     */
  217.                     
  218.                 }
  219.             }
  220.     }    
  221.     Fl_Group::handle(event);
  222.     return 1; // event handled
  223. }
  224. END_NCBI_SCOPE
  225. /*
  226.  * ===========================================================================
  227.  * $Log: taxplot3d_widget.cpp,v $
  228.  * Revision 1000.1  2004/06/01 21:13:47  gouriano
  229.  * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7
  230.  *
  231.  * Revision 1.7  2004/05/21 22:27:55  gorelenk
  232.  * Added PCH ncbi_pch.hpp
  233.  *
  234.  * Revision 1.6  2004/03/11 17:54:04  dicuccio
  235.  * Deprecated typedefs TDimension, TPosition
  236.  *
  237.  * Revision 1.5  2004/01/28 17:39:42  tereshko
  238.  * Fixed popup menu
  239.  *
  240.  * Revision 1.4  2004/01/28 16:13:47  tereshko
  241.  * Eliminated padding to work correctly with CSplitter
  242.  *
  243.  * Revision 1.3  2004/01/15 13:04:44  ucko
  244.  * Tweak to work on 64-bit systems.
  245.  *
  246.  * Revision 1.2  2004/01/14 16:39:23  tereshko
  247.  * Minor changes due to integration with Taxplot viewer
  248.  *
  249.  * Revision 1.1  2004/01/05 16:20:50  tereshko
  250.  * Initial revision
  251.  *
  252.  * ===========================================================================
  253.  */