]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
*** empty log message ***
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / bbtkwxGUIEditorGraphicBBS.cxx
1 /*=========================================================================                                                                               
2 Program:   bbtk
3 Module:    $RCSfile$
4 Language:  C++
5 Date:      $Date$
6 Version:   $Revision$
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32 *  \file 
33 *  \brief Class bbtk::WxInterfaceEditorGraphicBBS . 
34 */
35
36 #include "bbtkwxGUIEditorGraphicBBS.h"
37
38 namespace bbtk
39 {
40
41
42         //=========================================================================
43         wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent)
44                 : wxFrame(parent, -1, _T("bbtkGEditor"),wxDefaultPosition, wxSize(1200,800))
45         {
46                 _frameAUIMgr = new wxAuiManager(this);
47                 
48
49                 //std::string datadir( crea::System::GetExecutablePath() );
50                 std::string datadir (".");
51                 cout<<"RaC //------------------"<<endl;
52                 cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with  crea::System::GetExecutablePath() ."<<endl;
53                 cout<<"RaC //------------------"<<endl;
54
55             #ifdef LINUX /* assume this is OSX */
56                    datadir=datadir+"/../share/creaContours";
57             #endif // MACOSX    
58         
59                 #ifdef MACOSX /* assume this is OSX */
60                         datadir=datadir+"/../../../../share/creaContours";
61                 #endif // MACOSX        
62
63                 _dataDir = datadir;
64
65                 initMenu();
66                 initToolbar();
67                 initTabPanelsManager();
68                 initPackageBrowser();
69                 initHelpHTMLBrowser();
70
71                 CreateStatusBar();
72                 _frameAUIMgr->Update();
73         }
74
75
76         //=========================================================================
77         wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS()
78         {
79                 _frameAUIMgr->UnInit();
80         }
81
82         //=========================================================================
83         void wxGUIEditorGraphicBBS::initToolbar()
84         {       
85                 //std::string filename= _dataDir + "/data/icons/wxart_new.xpm";   
86                 wxBitmap bmp_new(new_xpm);
87
88                 wxToolBar  *_toolbar = new wxToolBar(this, wxID_ANY);
89
90                 //Adds a tool btn to the toolbar
91                 _toolbar->AddTool(wxID_NEW,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
92
93                 _toolbar->SetMargins( 2, 2 );
94                 _toolbar->Realize();
95                 SetToolBar(_toolbar);
96
97                 // connect command event handlers
98                 Connect(wxID_NEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnToolLeftClick));
99
100         }
101         //=========================================================================
102         void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
103         {
104                 //TO FIX THE PATH OF BBTK BIN  IN ORDER TO USE REGENERATE EXECUTABLES
105                 //RegenerateAll();
106                 _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
107                 _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));       
108         }
109
110         //=========================================================================
111         void wxGUIEditorGraphicBBS::initMenu()
112         {
113                 // create a menu bar
114                 wxMenu *fileMenu = new wxMenu;
115
116                 // the "About" item should be in the help menu
117                 wxMenu *helpMenu = new wxMenu;
118                 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
119                 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
120
121                 Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
122
123                 // now append the freshly created menu to the menu bar...
124                 wxMenuBar *menuBar = new wxMenuBar();
125                 menuBar->Append(fileMenu, _T("&File"));
126                 menuBar->Append(helpMenu, _T("&Help"));
127
128                 // attach this menu bar to the frame
129                 SetMenuBar(menuBar);
130         }
131
132         //=========================================================================
133         void wxGUIEditorGraphicBBS::initTabPanelsManager()
134         {
135                 wxAuiNotebook *notebook = new wxAuiNotebook(this,wxID_ANY,wxDefaultPosition,wxDefaultSize,wxAUI_NB_TOP|wxAUI_NB_TAB_MOVE|wxAUI_NB_CLOSE_ON_ACTIVE_TAB|wxAUI_NB_TAB_FIXED_WIDTH|wxAUI_NB_WINDOWLIST_BUTTON);
136                 _tabsMgr = new wxTabPanelsManager(notebook);
137                 _frameAUIMgr->AddPane(notebook,wxAuiPaneInfo().CenterPane());   
138
139         }
140         
141         //=========================================================================
142         void wxGUIEditorGraphicBBS::initPackageBrowser()
143         {
144                 _pkgBrowser = new WxGUIPackageBrowser2(this);
145                 _pkgBrowser->IncludeAll();
146                 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));          
147         }
148
149         //================================================================
150
151         void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
152         {
153                 std::string mess("Regenerating doc for package '");
154                 if (pack!="-a"){
155                         mess += pack + "'";
156                 }
157                 else
158                 {
159                         mess = "Regenerating doc for all packages";
160                 }
161                 
162                 mess += " ... please wait";             
163
164                 SetStatusText( std2wx(mess) );
165
166                 //BBTK_BUSY_CURSOR;
167
168                 std::string command;
169                 #if defined(WIN32)
170                         command = "\"";
171                 #endif
172                         command += ConfigurationFile::GetInstance().Get_bin_path();
173                         command += ConfigurationFile::GetInstance().Get_file_separator();
174                         command += "bbRegeneratePackageDoc";
175                 #if defined(WIN32)
176                         command += "\"";
177                 #endif
178
179                 command += " " + pack + " -q";
180             bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
181
182                 if ( ! system ( command.c_str() ) )
183                 {
184                         SetStatusText( _T("Done !"));
185                         /*
186                         wxMessageBox(_T("Done !"),_T("Regenerate package '")
187                                          +std2wx(pack)+_T("' doc"),
188                                          wxOK | wxICON_INFORMATION);
189                         */
190                 }
191                 else 
192                 {
193                         SetStatusText( _T("Done !"));
194                         wxString err(_T("An error occured while running '"));
195                         err +=  bbtk::std2wx(command) + _T("'");
196                         wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);      
197             }
198         }
199
200         //================================================================
201         void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
202         {
203                 SetStatusText( _T("Regenerating boxes lists ... please wait") );
204                 //BBTK_BUSY_CURSOR ;
205
206                 std::string command;
207                 #if defined(WIN32)
208                         command = "\"";
209                 #endif
210                         command += ConfigurationFile::GetInstance().Get_bin_path();
211                         command += ConfigurationFile::GetInstance().Get_file_separator();
212                         command += "bbRegenerateBoxesLists";
213
214                 #if defined(WIN32)
215                         command += "\"";
216                 #endif
217                         command += " -q";
218
219                 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
220
221                 if ( ! system ( command.c_str() ) )
222                 {
223                         SetStatusText( _T("Done !"));
224                         /*
225                         wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
226                                          wxOK | wxICON_INFORMATION);
227                         */
228                 }
229                 else 
230                 {
231                         SetStatusText( _T("Done !"));
232                         wxString err(_T("An error occured while running '"));
233                         err +=  bbtk::std2wx(command) + _T("'");
234                         wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);      
235                 }
236         }
237         
238   //================================================================
239         void wxGUIEditorGraphicBBS::RegenerateAll()
240         {
241                 DoRegeneratePackageDoc("-a");   
242                 DoRegenerateBoxesLists();
243         }
244
245   //================================================================
246
247         /*****************************************************
248         /* HANDLERS 
249         /*****************************************************/
250
251         void wxGUIEditorGraphicBBS::OnToolLeftClick(wxCommandEvent& event)
252         {
253                 switch (event.GetId())
254                 {
255                 case wxID_NEW :
256                         std::cout<<"RaC New"<<std::endl;
257                         _tabsMgr->addNewTab();
258                         break;                  
259                 }
260         }
261
262         void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
263         {
264                 Close(true);
265         }
266
267
268 }  // EO namespace bbtk
269
270 // EOF
271