]> 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
11 namespace bbcreaMaracasVisu
12 {
13
14 class PopupMenuInteractor : public InteractorStyleMaracas , wxEvtHandler
15 {
16     public:
17         PopupMenuInteractor( );
18         PopupMenuInteractor( wxPopupMenu *box, wxVtkBaseView *wxvtkbaseview );
19         ~PopupMenuInteractor();
20 //      virtual bool    OnLeftButtonDown();
21 //      virtual bool    OnLeftButtonUp();
22 //      virtual bool    OnMouseMove();
23 //      virtual bool    OnRightButtonDown();
24         virtual bool    OnRightButtonUp();
25 //      virtual bool    OnLeftDClick();
26 //      virtual bool    OnRightDClick();
27                 void    OnPopupClick(wxCommandEvent &evt);
28     private:
29         wxVtkBaseView   *_wxvtkbaseview;
30         wxPopupMenu     *_box;
31 };
32
33 PopupMenuInteractor::PopupMenuInteractor(  )
34 {
35     _wxvtkbaseview = NULL;
36     _box           = NULL;
37 }
38
39 PopupMenuInteractor::PopupMenuInteractor( wxPopupMenu *box , wxVtkBaseView *wxvtkbaseview )
40 {
41     _wxvtkbaseview = wxvtkbaseview;
42     _box           = box;
43 }
44
45 PopupMenuInteractor::~PopupMenuInteractor()
46 {
47 }
48
49 void PopupMenuInteractor::OnPopupClick(wxCommandEvent &evt)
50 {
51 //    void *data=static_cast<wxMenu *>(evt.GetEventObject())->GetClientData();
52 //    switch( evt.GetId()) {
53 //        case ID_SOMETHING:
54 //            break;
55 //        case ID_SOMETHING_ELSE:
56 //            break;
57 //    }
58     int id=evt.GetId()-1000;
59     _box->bbSetOutputOut( id );
60     std::vector<std::string>    lstItems    = _box->bbGetInputIn();
61     int                         size        = lstItems.size();
62     if ((id>=0) && (id<size))
63     {
64         _box->bbSetOutputSimpleText( lstItems[id] );
65     } else {
66         _box->bbSetOutputSimpleText( "void" );
67     }
68     _box->bbSignalOutputModification();
69 }
70
71 bool PopupMenuInteractor::OnRightButtonUp()
72 {
73     if (_wxvtkbaseview!=NULL)
74     {
75         wxWindow                    *window     = _wxvtkbaseview->GetWxVTKRenderWindowInteractor();
76         const wxPoint               pt          = wxGetMousePosition();
77         int                         xWindow     = pt.x - window->GetScreenPosition().x;
78         int                         yWindow     = pt.y - window->GetScreenPosition().y;
79         std::vector<std::string>    lstItems    = _box->bbGetInputIn();
80         int                         size        = lstItems.size();
81         int                         i;
82         wxMenu                      menu;
83         for (i=0;i<size;i++)
84         {
85             wxString itemString( lstItems[i].c_str() , wxConvUTF8 );
86             wxMenuItem *item = menu.Append(i+1000, itemString  );
87         } // for
88         menu.Connect( wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction) (wxCommandEventFunction) &PopupMenuInteractor::OnPopupClick,NULL,this );
89         window->PopupMenu(&menu,xWindow,yWindow);
90     } // if _vtkbaseview
91 }
92
93 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,wxPopupMenu)
94 BBTK_BLACK_BOX_IMPLEMENTATION(wxPopupMenu,bbtk::AtomicBlackBox);
95 //===== 
96 // 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)
97 //===== 
98 void wxPopupMenu::Process()
99 {
100
101 // THE MAIN PROCESSING METHOD BODY
102 //   Here we simply set the input 'In' value to the output 'Out'
103 //   And print out the output value
104 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
105 //    void bbSet{Input|Output}NAME(const TYPE&)
106 //    const TYPE& bbGet{Input|Output}NAME() const 
107 //    Where :
108 //    * NAME is the name of the input/output
109 //      (the one provided in the attribute 'name' of the tag 'input')
110 //    * TYPE is the C++ type of the input/output
111 //      (the one provided in the attribute 'type' of the tag 'input')
112 //    bbSetOutputOut( bbGetInputIn() );
113 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
114     if (firsttime==true)
115     {
116         firsttime=false;
117         if (bbGetInputwxVtkBaseView()!=NULL)
118         {
119             PopupMenuInteractor* popupmenuinteractor = new PopupMenuInteractor( this, bbGetInputwxVtkBaseView()  );
120             vtkInteractorStyleBaseView *vtkinteractorstylebaseview = (vtkInteractorStyleBaseView*) (bbGetInputwxVtkBaseView()->GetInteractorStyleBaseView() );
121             vtkinteractorstylebaseview->AddInteractorStyleMaracas( popupmenuinteractor );
122         } // if wxVtkBaseView
123     } // if firsttime
124 }
125
126 //===== 
127 // 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)
128 //===== 
129 void wxPopupMenu::bbUserSetDefaultValues()
130 {
131 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
132 //    Here we initialize the input 'In' to 0
133     firsttime=true;
134     bbSetInputwxVtkBaseView(NULL);
135     bbSetOutputOut(-1);
136 }
137
138 //===== 
139 // 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)
140 //===== 
141 void wxPopupMenu::bbUserInitializeProcessing()
142 {
143
144 //  THE INITIALIZATION METHOD BODY :
145 //    Here does nothing 
146 //    but this is where you should allocate the internal/output pointers 
147 //    if any 
148
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::bbUserFinalizeProcessing()
155 {
156
157 //  THE FINALIZATION METHOD BODY :
158 //    Here does nothing 
159 //    but this is where you should desallocate the internal/output pointers 
160 //    if any
161   
162 }
163 }
164 // EO namespace bbcreaMaracasVisu
165
166