]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
New icon to save the actual diagram and modal dialog to ask if the user want to delet...
[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 #include "creaWx.h"
38
39 namespace bbtk
40 {
41
42
43         //=========================================================================
44         wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent)
45                 : wxFrame(parent, -1, _T("bbtkGEditor"),wxDefaultPosition, wxSize(1200,800))
46         {
47                 _frameAUIMgr = new wxAuiManager(this);
48                 
49
50                 /*std::string datadir( crea::System::GetExecutablePath() );
51                 std::string datadir (".");
52                 cout<<"RaC //------------------"<<endl;
53                 cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with  crea::System::GetExecutablePath() ."<<endl;
54                 cout<<"RaC //------------------"<<endl;
55
56             #ifdef LINUX // assume this is OSX 
57                    datadir=datadir+"/../share/creaContours";
58             #endif // MACOSX    
59         
60                 #ifdef MACOSX // assume this is OSX 
61                         datadir=datadir+"/../../../../share/creaContours";
62                 #endif // MACOSX        
63
64                 _dataDir = datadir;*/
65
66                 initMenu();
67                 initToolbar();
68                 initTabPanelsManager();
69                 initPackageBrowser();
70                 initHelpHTMLBrowser();
71
72                 CreateStatusBar();
73                 _frameAUIMgr->Update();
74                 _actualPkgBrowserBoxName="";
75                 _actualPkgBrowserPkgName="";
76         }
77
78
79         //=========================================================================
80         wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS()
81         {
82                 _frameAUIMgr->UnInit();
83         }
84
85         //=========================================================================
86         void wxGUIEditorGraphicBBS::initToolbar()
87         {        
88                 wxBitmap bmp_new(new_xpm);
89                 wxBitmap bmp_save(save_xpm);
90                 wxBitmap bmp_run(run_xpm);
91                 wxBitmap bmp_delete(delete_xpm);
92                 wxBitmap bmp_centerview(centerview_xpm);
93
94                 wxToolBar  *_toolbar = new wxToolBar(this, wxID_ANY);
95
96                 //Adds a tool btn to the toolbar
97                 _toolbar->AddTool(1000,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
98                 _toolbar->AddTool(1001,_T("Save diagram"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves actual diagram"), _T("Saves actual diagram"));
99                 _toolbar->AddTool(1002,_T("Execute"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram"));
100                 _toolbar->AddTool(1003,_T("Delete all"),bmp_delete, wxNullBitmap, wxITEM_NORMAL,_T("Delete all boxes"), _T("Delete all boxes"));
101                 _toolbar->AddTool(1004,_T("Center view"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Center view"), _T("Center view"));
102                 
103
104                 _toolbar->SetMargins( 2, 2 );
105                 _toolbar->Realize();
106                 SetToolBar(_toolbar);
107
108                 // connect command event handlers
109                 Connect(1000,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
110                 Connect(1001,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
111                 Connect(1002,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
112                 Connect(1003,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
113                 Connect(1004,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
114
115         }
116         //=========================================================================
117         void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
118         {
119                 //TO FIX THE PATH OF BBTK BIN  IN ORDER TO USE REGENERATE EXECUTABLES
120                 //RegenerateAll();
121                 _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
122                 _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));       
123         }
124
125         //=========================================================================
126         void wxGUIEditorGraphicBBS::initMenu()
127         {
128                 // create a menu bar
129                 wxMenu *fileMenu = new wxMenu;
130
131                 // the "About" item should be in the help menu
132                 wxMenu *helpMenu = new wxMenu;
133                 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
134                 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
135
136                 Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
137
138                 // now append the freshly created menu to the menu bar...
139                 wxMenuBar *menuBar = new wxMenuBar();
140                 menuBar->Append(fileMenu, _T("&File"));
141                 menuBar->Append(helpMenu, _T("&Help"));
142
143                 // attach this menu bar to the frame
144                 SetMenuBar(menuBar);
145         }
146
147         //=========================================================================
148         void wxGUIEditorGraphicBBS::initTabPanelsManager()
149         {
150                 _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);
151                 _tabsMgr = new wxTabPanelsManager(this);
152                 _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());  
153
154         }
155         
156         //=========================================================================
157         void wxGUIEditorGraphicBBS::initPackageBrowser()
158         {
159                 _pkgBrowser = new WxGUIPackageBrowser2(this);
160                 _pkgBrowser->IncludeAll();
161                 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));          
162         }
163
164         //================================================================
165
166         void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
167         {
168                 std::string mess("Regenerating doc for package '");
169                 if (pack!="-a"){
170                         mess += pack + "'";
171                 }
172                 else
173                 {
174                         mess = "Regenerating doc for all packages";
175                 }
176                 
177                 mess += " ... please wait";             
178
179                 SetStatusText( std2wx(mess) );
180
181                 //BBTK_BUSY_CURSOR;
182
183                 std::string command;
184                 #if defined(WIN32)
185                         command = "\"";
186                 #endif
187                         command += ConfigurationFile::GetInstance().Get_bin_path();
188                         command += ConfigurationFile::GetInstance().Get_file_separator();
189                         command += "bbRegeneratePackageDoc";
190                 #if defined(WIN32)
191                         command += "\"";
192                 #endif
193
194                 command += " " + pack + " -q";
195             bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
196
197                 if ( ! system ( command.c_str() ) )
198                 {
199                         SetStatusText( _T("Done !"));
200                         /*
201                         wxMessageBox(_T("Done !"),_T("Regenerate package '")
202                                          +std2wx(pack)+_T("' doc"),
203                                          wxOK | wxICON_INFORMATION);
204                         */
205                 }
206                 else 
207                 {
208                         SetStatusText( _T("Done !"));
209                         wxString err(_T("An error occured while running '"));
210                         err +=  bbtk::std2wx(command) + _T("'");
211                         wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);      
212             }
213         }
214
215         //================================================================
216         void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
217         {
218                 SetStatusText( _T("Regenerating boxes lists ... please wait") );
219                 //BBTK_BUSY_CURSOR ;
220
221                 std::string command;
222                 #if defined(WIN32)
223                         command = "\"";
224                 #endif
225                         command += ConfigurationFile::GetInstance().Get_bin_path();
226                         command += ConfigurationFile::GetInstance().Get_file_separator();
227                         command += "bbRegenerateBoxesLists";
228
229                 #if defined(WIN32)
230                         command += "\"";
231                 #endif
232                         command += " -q";
233
234                 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
235
236                 if ( ! system ( command.c_str() ) )
237                 {
238                         SetStatusText( _T("Done !"));
239                         /*
240                         wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
241                                          wxOK | wxICON_INFORMATION);
242                         */
243                 }
244                 else 
245                 {
246                         SetStatusText( _T("Done !"));
247                         wxString err(_T("An error occured while running '"));
248                         err +=  bbtk::std2wx(command) + _T("'");
249                         wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);      
250                 }
251         }
252         
253   //================================================================
254         void wxGUIEditorGraphicBBS::RegenerateAll()
255         {
256                 DoRegeneratePackageDoc("-a");   
257                 DoRegenerateBoxesLists();
258         }
259
260         //================================================================
261
262         wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
263         {
264                 return _notebook;
265         }
266
267         //================================================================
268
269         void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
270         {
271                 if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
272                 {
273                         _actualPkgBrowserPkgName = packageName;
274                         _actualPkgBrowserBoxName = boxName;
275
276                         BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
277                         _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
278                 }
279         }
280
281         //=========================================================================
282
283         void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
284         {
285                 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
286                 dialog->Show();
287         }
288
289         //=========================================================================
290
291         void wxGUIEditorGraphicBBS::editDiagramParameters(wxVtkSceneManager* scene)
292         {
293                 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,scene);
294                 dialog->Show();
295         }
296
297         //=========================================================================
298
299         void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
300         {
301                 SetStatusText(crea::std2wx(textStatus));
302         }
303
304         //=========================================================================
305
306         void wxGUIEditorGraphicBBS::executeScript(std::string script)
307         {
308                 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
309                 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
310                 std::string filename = dir + separator + "tmp_bbtk.bbs";
311                 
312                 ofstream tempFile;
313                 tempFile.open(filename.c_str());
314                 tempFile << script;
315                 tempFile.close();
316                 
317                 std::string command = "\"";
318
319                 #ifdef WIN32
320                         command += "\"";
321                 #endif
322
323                 //command += ConfigurationFile::GetInstance().Get_bin_path();
324                 command +="C:/temp/bbtkBIN/RelWithDebInfo//";
325
326                 #ifdef MACOSX
327                         command += separator + "bbi.app/Contents/MacOS/bbi\" ";
328                 #else 
329                         command += separator + "bbi\" ";
330                 #endif
331                 command += "\""+filename + "\"";
332
333                 #ifdef WIN32
334                         command += "\"";
335                 #endif
336
337                 command += " & ";
338                   
339                 printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
340                 system( command.c_str() );
341         }
342
343         //=========================================================================
344         // EVENT HANDLERS 
345         //=========================================================================
346
347         void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
348         {
349                 _tabsMgr->addNewTab();          
350         }
351
352         //=========================================================================
353
354         void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
355         {
356                 std::string script = _tabsMgr->getActualDiagramScript();
357                 cout<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl;
358                 cout<<script<<endl;
359
360                 executeScript(script);          
361         }
362
363         //=========================================================================
364
365         void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
366         {
367                         
368         }
369
370         //=========================================================================
371
372         void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
373         {
374                 wxMessageDialog *dial = new wxMessageDialog(NULL, wxT("Are you sure to delete all boxes of the diagram?"), wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
375                 if(dial->ShowModal() == wxID_YES)
376                 {
377                         _tabsMgr->deleteAllBoxesActualDiagram();
378                 }
379         }
380
381         //=========================================================================
382
383         void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
384         {
385                 _tabsMgr->centerViewActualDiagram();
386         }
387
388         //=========================================================================
389
390         void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
391         {
392                 Close(true);
393         }
394
395
396
397 }  // EO namespace bbtk
398
399 // EOF
400