]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbcreaMaracasVisuwxPopupMenu.cxx
#3481 wxVtkBaseView_Info add events mouse observer
[creaMaracasVisu.git] / bbtk / src / bbcreaMaracasVisuwxPopupMenu.cxx
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbcreaMaracasVisuwxPopupMenu.h"
5 #include "bbcreaMaracasVisuPackage.h"
6
7 #include <wx/menu.h>
8 #include "InteractorStyleMaracas.h"
9 #include <vtkInteractorStyleBaseView.h>
10 #include "wxVtk2DBaseView.h"
11
12 namespace bbcreaMaracasVisu
13 {
14
15 class PopupMenuInteractor : public InteractorStyleMaracas , wxEvtHandler
16 {
17     public:
18 //        PopupMenuInteractor( );
19         PopupMenuInteractor( wxPopupMenu *box, wxVtkBaseView *wxvtkbaseview );
20         ~PopupMenuInteractor();
21 //      virtual bool    OnLeftButtonDown();
22 //      virtual bool    OnLeftButtonUp();
23 //      virtual bool    OnMouseMove();
24 //      virtual bool    OnRightButtonDown();
25         virtual bool    OnRightButtonUp();
26 //      virtual bool    OnLeftDClick();
27 //      virtual bool    OnRightDClick();
28                 void    OnPopupClick(wxCommandEvent &evt);
29     private:
30         wxVtkBaseView       *_wxvtkbaseview;
31         wxPopupMenu         *_box;
32         std::vector<double> lstPoint;
33 };
34
35 /*
36 PopupMenuInteractor::PopupMenuInteractor(  )
37 {
38     _wxvtkbaseview  = NULL;
39     _box            = NULL;
40 }
41 */
42 PopupMenuInteractor::PopupMenuInteractor( wxPopupMenu *box , wxVtkBaseView *wxvtkbaseview )
43 {
44     _wxvtkbaseview  = wxvtkbaseview;
45     _box            = box;
46 }
47
48 PopupMenuInteractor::~PopupMenuInteractor()
49 {
50 }
51
52 void PopupMenuInteractor::OnPopupClick(wxCommandEvent &evt)
53 {
54 //    void *data=static_cast<wxMenu *>(evt.GetEventObject())->GetClientData();
55 //    switch( evt.GetId()) {
56 //        case ID_SOMETHING:
57 //            break;
58 //        case ID_SOMETHING_ELSE:
59 //            break;
60 //    }
61     int id=evt.GetId()-1000;
62     _box->bbSetOutputOut( id );
63     std::vector<std::string>    lstItems    = _box->bbGetInputIn();
64     int                         size        = lstItems.size();
65     if ((id>=0) && (id<size))
66     {
67         _box->bbSetOutputSimpleText( lstItems[id] );
68     } else {
69         _box->bbSetOutputSimpleText( "void" );
70     }
71     _box->bbSetOutputPoint( lstPoint );
72     _box->bbSignalOutputModification();
73 }
74
75 bool PopupMenuInteractor::OnRightButtonUp()
76 {
77     if (_wxvtkbaseview!=NULL)
78     {
79         wxWindow                    *window     = _wxvtkbaseview->GetWxVTKRenderWindowInteractor();
80         const wxPoint               pt          = wxGetMousePosition();
81         int                         xWindow     = pt.x - window->GetScreenPosition().x;
82         int                         yWindow     = pt.y - window->GetScreenPosition().y;
83         std::vector<std::string>    lstItems    = _box->bbGetInputIn();
84         int                         size        = lstItems.size();
85         int                         i;
86         wxMenu                      menu;
87
88         /*
89         int X,Y,Z;
90         crea::wxVTKRenderWindowInteractor *wxVTKiren;
91         wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
92         wxVTKiren->GetEventPosition(X,Y);
93         Z = (int)((wxVtk2DBaseView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView()))->GetVtkBaseData()->GetZ();
94         double dxx     = X;
95         double dyy     = Y;
96         double dzz     = Z;
97         _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->TransFromCoordScreenToWorld(dxx,dyy,dzz,true);
98         _px    = (int)(dxx+0.5);
99         _py    = (int)(dyy+0.5);
100         _pz    = (int)(dzz+0.0);
101         */
102         int x,y,z;
103         ((wxVtk2DBaseView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView()))->GetVtkBaseData()->GetPointMouse(x,y,z);
104         lstPoint.clear();
105         lstPoint.push_back(x);
106         lstPoint.push_back(y);
107         lstPoint.push_back(z);
108
109         for (i=0;i<size;i++)
110         {
111             wxString itemString( lstItems[i].c_str() , wxConvUTF8 );
112             wxMenuItem *item = menu.Append(i+1000, itemString  );
113         } // for
114         menu.Connect( wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction) (wxCommandEventFunction) &PopupMenuInteractor::OnPopupClick,NULL,this );
115         window->PopupMenu(&menu,xWindow,yWindow);
116     } // if _vtkbaseview
117 }
118
119 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,wxPopupMenu)
120 BBTK_BLACK_BOX_IMPLEMENTATION(wxPopupMenu,bbtk::AtomicBlackBox);
121 //===== 
122 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
123 //===== 
124 void wxPopupMenu::Process()
125 {
126 // THE MAIN PROCESSING METHOD BODY
127 //   Here we simply set the input 'In' value to the output 'Out'
128 //   And print out the output value
129 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
130 //    void bbSet{Input|Output}NAME(const TYPE&)
131 //    const TYPE& bbGet{Input|Output}NAME() const 
132 //    Where :
133 //    * NAME is the name of the input/output
134 //      (the one provided in the attribute 'name' of the tag 'input')
135 //    * TYPE is the C++ type of the input/output
136 //      (the one provided in the attribute 'type' of the tag 'input')
137 //    bbSetOutputOut( bbGetInputIn() );
138 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
139     if (firsttime==true)
140     {
141         firsttime=false;
142         if (bbGetInputwxVtkBaseView()!=NULL)
143         {
144             PopupMenuInteractor* popupmenuinteractor                = new PopupMenuInteractor( this, bbGetInputwxVtkBaseView()  );
145             vtkInteractorStyleBaseView *vtkinteractorstylebaseview  = (vtkInteractorStyleBaseView*) (bbGetInputwxVtkBaseView()->GetInteractorStyleBaseView() );
146             vtkinteractorstylebaseview->AddInteractorStyleMaracas( popupmenuinteractor );
147         } // if wxVtkBaseView
148     } // if firsttime
149 }
150
151 //===== 
152 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
153 //===== 
154 void wxPopupMenu::bbUserSetDefaultValues()
155 {
156 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
157 //    Here we initialize the input 'In' to 0
158     firsttime=true;
159     bbSetInputwxVtkBaseView(NULL);
160     bbSetOutputOut(-1);
161 }
162
163 //===== 
164 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
165 //===== 
166 void wxPopupMenu::bbUserInitializeProcessing()
167 {
168 //  THE INITIALIZATION METHOD BODY :
169 //    Here does nothing 
170 //    but this is where you should allocate the internal/output pointers 
171 //    if any
172 }
173
174 //===== 
175 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
176 //===== 
177 void wxPopupMenu::bbUserFinalizeProcessing()
178 {
179 //  THE FINALIZATION METHOD BODY :
180 //    Here does nothing 
181 //    but this is where you should desallocate the internal/output pointers 
182 //    if any
183 }
184
185 }// EO namespace bbcreaMaracasVisu
186
187