]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasRendererView.cxx
a786294da881208d53df4de3ead6388e777df961
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxMaracasRendererView.cxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: wxMaracasRendererView.cxx,v $
5   Language:  C++
6
7 =========================================================================*/
8
9 #include "wxMaracasRendererView.h"
10
11 #include <wx/colordlg.h>
12 #include <wx/bmpbuttn.h>
13
14 #include <OpenImage.xpm>
15 #include <Color.xpm>
16
17 wxMaracasRendererView* wxMaracasRendererView::instance=NULL;
18
19 /**
20 ** Class constructor
21 **/
22 wxMaracasRendererView::wxMaracasRendererView(wxWindow* parent,std::string path)
23 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
24
25         wxauimanager = new wxAuiManager(this);
26
27         _idCount = 0;
28         _path = path;
29
30         std::string iconsdir = path;
31         iconsdir+="/data/Icons";
32         this->_toolb = new ToolBarRenderer(this,iconsdir);
33         wxStaticText* txt = new wxStaticText(this, -1, wxString(_T("  Open File  ")));
34         wxAuiPaneInfo paneinfo;
35         wxauimanager->AddPane(txt,paneinfo.ToolbarPane().Top());
36         wxauimanager->AddPane(_toolb,paneinfo.ToolbarPane().Top());
37
38         wxauimanager->Update(); 
39 }
40
41 /**
42 ** Class destructor
43 **/
44 wxMaracasRendererView::~wxMaracasRendererView( )
45 {
46         delete _toolb;
47 }
48
49 /**
50 ** Gets class instance correponding to given parameters
51 **/
52 wxMaracasRendererView* wxMaracasRendererView::getInstance(wxWindow* parent,std::string path)
53 {
54         if(instance==NULL)
55         {
56                 instance = new wxMaracasRendererView(parent,path);
57         }
58         return instance;
59 }
60
61 /**
62 ** Gets class intance
63 **/
64 wxMaracasRendererView* wxMaracasRendererView::getInstance()
65 {
66         return instance;
67 }
68
69 /**
70 ** Gets path for the given panel
71 **/
72 std::string wxMaracasRendererView::getPath()
73 {
74         return _path;
75 }
76
77 /**
78 ** Returns internal panel
79 **/
80 wxMaracasRenderTabbedPanel* wxMaracasRendererView::getTabbedPanel(int id) throw(char*)
81 {
82         int i;
83         for(i = 0; i < (tabsVector.size()); i++)
84         {
85                 if(tabsVector[i]->getPropIdV() == id)
86                         return tabsVector[i];
87         }
88         throw "id not found";
89
90         return NULL;
91 }
92
93 /**
94 **
95 **/
96 void wxMaracasRendererView::setRenderer(vtkRenderer* renderer)
97 {
98         _renderer = renderer;
99 }
100
101 /**
102 ** Called when an image file is opened
103 **/
104 void wxMaracasRendererView::onLoadImageFile()
105 {
106         wxString mhd(_T("mhd"));        
107
108         wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a MHD file")), wxString(_T("")),
109                                         wxString(_T("")), wxString(_T("MHD files (*.mhd)|*.mhd")) );
110
111         if(fildial->ShowModal()==wxID_OK)
112         {
113                 wxString filename = fildial->GetFilename();
114                 files.push_back( std::string(filename.mb_str()) );
115                 wxString pathfile(fildial->GetDirectory() + _T("/") + filename);
116
117                 if(filename.EndsWith(mhd))
118                 {
119                         std::string sPath = std::string(pathfile.mb_str());
120                         std::string sFileName = std::string(filename.mb_str());
121                         printf("wxMaracasRendererView::onLoadImageFile->Opening file... \n");
122                         addVolumes(NULL, sPath, sFileName);
123                 }
124         }
125         delete fildial;
126 }
127 /**
128 ** Constructs and adds internal panel
129 **/
130 void wxMaracasRendererView::addPanels(wxMaracasRenderTabbedPanel* wxtabs, vtkImageData* img, std::string pathfile, std::string filename)
131 {
132         wxString s(filename.c_str(),wxConvUTF8);
133         
134         wxtabs->createControls(img, pathfile, filename);
135         
136         wxAuiPaneInfo paneinfo;
137         wxauimanager->AddPane(wxtabs, paneinfo.DefaultPane().Centre().DestroyOnClose().Caption(s));
138         wxauimanager->Update();
139 }
140
141 /**
142 ** Returns internal panel
143 **/
144 void wxMaracasRendererView::addVolumes(vtkImageData* img, std::string pathfile, std::string filename)
145 {
146         wxMaracasRenderTabbedPanel* wxtabs = new wxMaracasRenderTabbedPanel(this, _idCount);
147         wxtabs->setRenderer(_renderer);
148
149         tabsVector.push_back(wxtabs);
150         addPanels(wxtabs, img, pathfile, filename);     
151
152         _idCount++;
153 }
154 /**
155 ** Deletes current volume
156 **/
157 void wxMaracasRendererView::deleteVolume(int volid)
158 {
159         
160         getTabbedPanel(volid)->deleteVolume(volid);
161 }
162
163 /**
164 ** Adds or removes a volume rendering actor
165 **/
166 void wxMaracasRendererView::addRemoveActorVol(int id, bool addremove)
167 {
168         //wxtabs->addRemoveActorV(id, addremove);
169 }
170
171 /**
172 ** Adds or removes a surface rendering actor
173 **/
174 void wxMaracasRendererView::addRemoveSurf1Actor(int id, bool addremove)
175 {
176         //wxtabs->addRemoveActorSA(id, addremove);
177 }
178
179 /**
180 ** Adds or removes a surface rendering actor
181 **/
182 void wxMaracasRendererView::addRemoveSurf2Actor(int id, bool addremove)
183 {
184         //wxtabs->addRemoveActorSB(id, addremove);
185 }
186
187 /**
188 ** Adds or removes a surface rendering actor
189 **/
190 void wxMaracasRendererView::addRemoveSurf3Actor(int id, bool addremove)
191 {
192         //wxtabs->addRemoveActorSC(id, addremove);
193 }
194
195 /**
196 ** Gets opened file names
197 **/
198 std::vector<std::string> wxMaracasRendererView::getFiles()
199 {
200         return files;
201 }
202
203 /**
204 **
205 **/
206 ToolBarRenderer::ToolBarRenderer(wxWindow * parent,std::string iconsdir)
207 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
208 {
209         std::string iconfil = iconsdir;
210
211         //iconfil+= "/OpenImage.png";
212         //wxBitmap* bitmap0 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
213         wxBitmap bitmap0(OpenImage_xpm);
214         this->AddTool(1, wxString(_T("test")),bitmap0, NULL, wxITEM_NORMAL, wxString(_T("Open File")));
215
216         this->Realize();
217
218         _evthand = new ToolBarEventHandlerRenderer();
219         this->SetEventHandler(_evthand);
220
221 }
222
223 ToolBarRenderer::~ToolBarRenderer(void){
224 }
225
226 ToolBarEventHandlerRenderer::ToolBarEventHandlerRenderer()
227 : wxEvtHandler(){
228 }
229 ToolBarEventHandlerRenderer::~ToolBarEventHandlerRenderer(){
230 }
231
232 void ToolBarEventHandlerRenderer::onLoadImageFile(wxCommandEvent& event){
233         wxMaracasRendererView::getInstance()->onLoadImageFile();
234 }
235
236
237 BEGIN_EVENT_TABLE(ToolBarEventHandlerRenderer, wxEvtHandler)
238         EVT_MENU(1, ToolBarEventHandlerRenderer::onLoadImageFile)
239 END_EVENT_TABLE()
240
241