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