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