]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasRendererView.cxx
#3128 creaMaracasVisu Feature New Normal - branch changeWx28to30 compilation with...
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxMaracasRendererView.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 /*=========================================================================
27
28   Program:   wxMaracas
29   Module:    $RCSfile: wxMaracasRendererView.cxx,v $
30   Language:  C++
31
32 =========================================================================*/
33
34 #include "wxMaracasRendererView.h"
35
36 #include <wx/colordlg.h>
37 #include <wx/bmpbuttn.h>
38
39 #include <OpenImage.xpm>
40 #include <Color.xpm>
41
42 wxMaracasRendererView* wxMaracasRendererView::instance=NULL;
43
44 /**
45 ** Class constructor
46 **/
47 wxMaracasRendererView::wxMaracasRendererView(wxWindow* parent,std::string path)
48 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
49
50         wxauimanager = new wxAuiManager(this);
51
52         _idCount = 0;
53         _path = path;
54
55         std::string iconsdir = path;
56         iconsdir+="/data/Icons";
57         this->_toolb = new ToolBarRenderer(this,iconsdir);
58         wxStaticText* txt = new wxStaticText(this, -1, wxString(_T("  Open File  ")));
59         wxAuiPaneInfo paneinfo;
60         wxauimanager->AddPane(txt,paneinfo.ToolbarPane().Top());
61         wxauimanager->AddPane(_toolb,paneinfo.ToolbarPane().Top());
62
63         wxauimanager->Update(); 
64 }
65
66 /**
67 ** Class destructor
68 **/
69 wxMaracasRendererView::~wxMaracasRendererView( )
70 {
71         delete _toolb;
72 }
73
74 /**
75 ** Gets class instance correponding to given parameters
76 **/
77 wxMaracasRendererView* wxMaracasRendererView::getInstance(wxWindow* parent,std::string path)
78 {
79         if(instance==NULL)
80         {
81                 instance = new wxMaracasRendererView(parent,path);
82         }
83         return instance;
84 }
85
86 /**
87 ** Gets class intance
88 **/
89 wxMaracasRendererView* wxMaracasRendererView::getInstance()
90 {
91         return instance;
92 }
93
94 /**
95 ** Gets path for the given panel
96 **/
97 std::string wxMaracasRendererView::getPath()
98 {
99         return _path;
100 }
101
102 /**
103 ** Returns internal panel
104 **/
105 wxMaracasRenderTabbedPanel* wxMaracasRendererView::getTabbedPanel(int id) throw(char*)
106 {
107         int i;
108         for(i = 0; i < (int)tabsVector.size(); i++)
109         {
110                 if(tabsVector[i]->getPropIdV() == id)
111                         return tabsVector[i];
112         }
113         throw "id not found";
114
115         return NULL;
116 }
117
118 /**
119 **
120 **/
121 void wxMaracasRendererView::setRenderer(vtkRenderer* renderer)
122 {
123         _renderer = renderer;
124 }
125
126 void wxMaracasRendererView::setVtkBaseView(wxVtk3DBaseView* vbv)
127 {
128         baseView = vbv;
129 }
130
131 /**
132 ** Called when an image file is opened
133 **/
134 void wxMaracasRendererView::onLoadImageFile()
135 {
136         wxString mhd(_T("mhd"));        
137
138         wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a MHD file")), wxString(_T("")),
139                                         wxString(_T("")), wxString(_T("MHD files (*.mhd)|*.mhd")) );
140
141         if(fildial->ShowModal()==wxID_OK)
142         {
143                 wxString filename = fildial->GetFilename();
144                 files.push_back( std::string(filename.mb_str()) );
145                 wxString pathfile(fildial->GetDirectory() + _T("/") + filename);
146
147                 if(filename.EndsWith(mhd))
148                 {
149                         std::string sPath = std::string(pathfile.mb_str());
150                         std::string sFileName = std::string(filename.mb_str());
151                         printf("wxMaracasRendererView::onLoadImageFile->Opening file... \n");
152                         addVolumes(NULL, sPath, sFileName);
153                 }
154         }
155         delete fildial;
156 }
157 /**
158 ** Constructs and adds internal panel
159 **/
160 void wxMaracasRendererView::addPanels(wxMaracasRenderTabbedPanel* wxtabs, vtkImageData* img, std::string pathfile, std::string filename)
161 {
162         wxString s(filename.c_str(),wxConvUTF8);
163         
164         wxtabs->createControls(img, pathfile, filename);
165         
166         wxAuiPaneInfo paneinfo;
167         wxauimanager->AddPane(wxtabs, paneinfo.DefaultPane().Centre().DestroyOnClose().Caption(s));
168         wxauimanager->Update();
169 }
170
171 /**
172 ** Returns internal panel
173 **/
174 void wxMaracasRendererView::addVolumes(vtkImageData* img, std::string pathfile, std::string filename)
175 {
176         wxMaracasRenderTabbedPanel* wxtabs = new wxMaracasRenderTabbedPanel(this, _idCount, baseView);
177         wxtabs->setRenderer(_renderer);
178
179         tabsVector.push_back(wxtabs);
180         addPanels(wxtabs, img, pathfile, filename);     
181
182         _idCount++;
183 }
184 /**
185 ** Deletes current volume
186 **/
187 void wxMaracasRendererView::deleteVolume(int volid)
188 {
189         
190         getTabbedPanel(volid)->deleteVolume(volid);
191 }
192
193 /**
194 ** Gets opened file names
195 **/
196 std::vector<std::string> wxMaracasRendererView::getFiles()
197 {
198         return files;
199 }
200
201 /**
202 **
203 **/
204 ToolBarRenderer::ToolBarRenderer(wxWindow * parent,std::string iconsdir)
205 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
206 {
207         std::string iconfil = iconsdir;
208
209         //iconfil+= "/OpenImage.png";
210         //wxBitmap* bitmap0 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
211         wxBitmap bitmap0(OpenImage_xpm);
212 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
213 #if wxMAJOR_VERSION <= 2
214         this->AddTool(1, wxString(_T("test")),bitmap0, NULL, wxITEM_NORMAL, wxString(_T("Open File")));
215 #else
216         this->AddTool(1, wxString(_T("test")),bitmap0, wxString(_T("Open File")), wxITEM_NORMAL );
217 #endif
218
219
220
221         this->Realize();
222
223         _evthand = new ToolBarEventHandlerRenderer();
224         this->SetEventHandler(_evthand);
225
226 }
227
228 ToolBarRenderer::~ToolBarRenderer(void){
229 }
230
231 ToolBarEventHandlerRenderer::ToolBarEventHandlerRenderer()
232 : wxEvtHandler(){
233 }
234 ToolBarEventHandlerRenderer::~ToolBarEventHandlerRenderer(){
235 }
236
237 void ToolBarEventHandlerRenderer::onLoadImageFile(wxCommandEvent& event){
238         wxMaracasRendererView::getInstance()->onLoadImageFile();
239 }
240
241
242 BEGIN_EVENT_TABLE(ToolBarEventHandlerRenderer, wxEvtHandler)
243         EVT_MENU(1, ToolBarEventHandlerRenderer::onLoadImageFile)
244 END_EVENT_TABLE()
245
246