1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 /*=========================================================================
29 Module: $RCSfile: wxMaracasRendererView.cxx,v $
32 =========================================================================*/
34 #include <wx/config.h>
36 #include <wx/tooltip.h>
38 #include "wxMaracasRendererView.h"
40 #include <wx/colordlg.h>
41 #include <wx/bmpbuttn.h>
43 #include <OpenImage.xpm>
46 wxMaracasRendererView* wxMaracasRendererView::instance=NULL;
51 wxMaracasRendererView::wxMaracasRendererView(wxWindow* parent,std::string path)
52 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
54 wxauimanager = new wxAuiManager(this);
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());
67 wxauimanager->Update();
73 wxMaracasRendererView::~wxMaracasRendererView( )
79 ** Gets class instance correponding to given parameters
81 wxMaracasRendererView* wxMaracasRendererView::getInstance(wxWindow* parent,std::string path)
85 instance = new wxMaracasRendererView(parent,path);
93 wxMaracasRendererView* wxMaracasRendererView::getInstance()
99 ** Gets path for the given panel
101 std::string wxMaracasRendererView::getPath()
107 ** Returns internal panel
109 wxMaracasRenderTabbedPanel* wxMaracasRendererView::getTabbedPanel(int id) throw(char*)
112 for(i = 0; i < (int)tabsVector.size(); i++)
114 if(tabsVector[i]->getPropIdV() == id)
115 return tabsVector[i];
117 throw "id not found";
125 void wxMaracasRendererView::setRenderer(vtkRenderer* renderer)
127 _renderer = renderer;
130 void wxMaracasRendererView::setVtkBaseView(wxVtk3DBaseView* vbv)
136 ** Called when an image file is opened
138 void wxMaracasRendererView::onLoadImageFile()
140 wxString mhd(_T("mhd"));
142 wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a MHD file")), wxString(_T("")),
143 wxString(_T("")), wxString(_T("MHD files (*.mhd)|*.mhd")) );
145 if(fildial->ShowModal()==wxID_OK)
147 wxString filename = fildial->GetFilename();
148 files.push_back( std::string(filename.mb_str()) );
149 wxString pathfile(fildial->GetDirectory() + _T("/") + filename);
151 if(filename.EndsWith(mhd))
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);
162 ** Constructs and adds internal panel
164 void wxMaracasRendererView::addPanels(wxMaracasRenderTabbedPanel* wxtabs, vtkImageData* img, std::string pathfile, std::string filename)
166 wxString s(filename.c_str(),wxConvUTF8);
168 wxtabs->createControls(img, pathfile, filename);
170 wxAuiPaneInfo paneinfo;
171 wxauimanager->AddPane(wxtabs, paneinfo.DefaultPane().Centre().DestroyOnClose().Caption(s));
172 wxauimanager->Update();
176 ** Returns internal panel
178 void wxMaracasRendererView::addVolumes(vtkImageData* img, std::string pathfile, std::string filename)
180 wxMaracasRenderTabbedPanel* wxtabs = new wxMaracasRenderTabbedPanel(this, _idCount, baseView);
181 wxtabs->setRenderer(_renderer);
183 tabsVector.push_back(wxtabs);
184 addPanels(wxtabs, img, pathfile, filename);
189 ** Deletes current volume
191 void wxMaracasRendererView::deleteVolume(int volid)
194 getTabbedPanel(volid)->deleteVolume(volid);
198 ** Gets opened file names
200 std::vector<std::string> wxMaracasRendererView::getFiles()
208 ToolBarRenderer::ToolBarRenderer(wxWindow * parent,std::string iconsdir)
209 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
211 std::string iconfil = iconsdir;
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")));
220 this->AddTool(1, wxString(_T("test")),bitmap0, wxString(_T("Open File")), wxITEM_NORMAL );
227 _evthand = new ToolBarEventHandlerRenderer();
228 this->SetEventHandler(_evthand);
232 ToolBarRenderer::~ToolBarRenderer(void){
235 ToolBarEventHandlerRenderer::ToolBarEventHandlerRenderer()
238 ToolBarEventHandlerRenderer::~ToolBarEventHandlerRenderer(){
241 void ToolBarEventHandlerRenderer::onLoadImageFile(wxCommandEvent& event){
242 wxMaracasRendererView::getInstance()->onLoadImageFile();
246 BEGIN_EVENT_TABLE(ToolBarEventHandlerRenderer, wxEvtHandler)
247 EVT_MENU(1, ToolBarEventHandlerRenderer::onLoadImageFile)