]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
Added the possibility to delete all the boxes in the scene
[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_run(run_xpm);
90                 wxBitmap bmp_delete(delete_xpm);
91
92                 wxToolBar  *_toolbar = new wxToolBar(this, wxID_ANY);
93
94                 //Adds a tool btn to the toolbar
95                 _toolbar->AddTool(1000,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
96                 _toolbar->AddTool(1001,_T("Execute"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram"));
97                 _toolbar->AddTool(1002,_T("Delete all"),bmp_delete, wxNullBitmap, wxITEM_NORMAL,_T("Delete all boxes"), _T("Delete all boxes"));
98
99                 _toolbar->SetMargins( 2, 2 );
100                 _toolbar->Realize();
101                 SetToolBar(_toolbar);
102
103                 // connect command event handlers
104                 Connect(1000,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
105                 Connect(1001,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
106                 Connect(1002,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
107
108         }
109         //=========================================================================
110         void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
111         {
112                 //TO FIX THE PATH OF BBTK BIN  IN ORDER TO USE REGENERATE EXECUTABLES
113                 //RegenerateAll();
114                 _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
115                 _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));       
116         }
117
118         //=========================================================================
119         void wxGUIEditorGraphicBBS::initMenu()
120         {
121                 // create a menu bar
122                 wxMenu *fileMenu = new wxMenu;
123
124                 // the "About" item should be in the help menu
125                 wxMenu *helpMenu = new wxMenu;
126                 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
127                 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
128
129                 Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
130
131                 // now append the freshly created menu to the menu bar...
132                 wxMenuBar *menuBar = new wxMenuBar();
133                 menuBar->Append(fileMenu, _T("&File"));
134                 menuBar->Append(helpMenu, _T("&Help"));
135
136                 // attach this menu bar to the frame
137                 SetMenuBar(menuBar);
138         }
139
140         //=========================================================================
141         void wxGUIEditorGraphicBBS::initTabPanelsManager()
142         {
143                 _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);
144                 _tabsMgr = new wxTabPanelsManager(this);
145                 _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());  
146
147         }
148         
149         //=========================================================================
150         void wxGUIEditorGraphicBBS::initPackageBrowser()
151         {
152                 _pkgBrowser = new WxGUIPackageBrowser2(this);
153                 _pkgBrowser->IncludeAll();
154                 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));          
155         }
156
157         //================================================================
158
159         void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
160         {
161                 std::string mess("Regenerating doc for package '");
162                 if (pack!="-a"){
163                         mess += pack + "'";
164                 }
165                 else
166                 {
167                         mess = "Regenerating doc for all packages";
168                 }
169                 
170                 mess += " ... please wait";             
171
172                 SetStatusText( std2wx(mess) );
173
174                 //BBTK_BUSY_CURSOR;
175
176                 std::string command;
177                 #if defined(WIN32)
178                         command = "\"";
179                 #endif
180                         command += ConfigurationFile::GetInstance().Get_bin_path();
181                         command += ConfigurationFile::GetInstance().Get_file_separator();
182                         command += "bbRegeneratePackageDoc";
183                 #if defined(WIN32)
184                         command += "\"";
185                 #endif
186
187                 command += " " + pack + " -q";
188             bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
189
190                 if ( ! system ( command.c_str() ) )
191                 {
192                         SetStatusText( _T("Done !"));
193                         /*
194                         wxMessageBox(_T("Done !"),_T("Regenerate package '")
195                                          +std2wx(pack)+_T("' doc"),
196                                          wxOK | wxICON_INFORMATION);
197                         */
198                 }
199                 else 
200                 {
201                         SetStatusText( _T("Done !"));
202                         wxString err(_T("An error occured while running '"));
203                         err +=  bbtk::std2wx(command) + _T("'");
204                         wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);      
205             }
206         }
207
208         //================================================================
209         void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
210         {
211                 SetStatusText( _T("Regenerating boxes lists ... please wait") );
212                 //BBTK_BUSY_CURSOR ;
213
214                 std::string command;
215                 #if defined(WIN32)
216                         command = "\"";
217                 #endif
218                         command += ConfigurationFile::GetInstance().Get_bin_path();
219                         command += ConfigurationFile::GetInstance().Get_file_separator();
220                         command += "bbRegenerateBoxesLists";
221
222                 #if defined(WIN32)
223                         command += "\"";
224                 #endif
225                         command += " -q";
226
227                 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
228
229                 if ( ! system ( command.c_str() ) )
230                 {
231                         SetStatusText( _T("Done !"));
232                         /*
233                         wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
234                                          wxOK | wxICON_INFORMATION);
235                         */
236                 }
237                 else 
238                 {
239                         SetStatusText( _T("Done !"));
240                         wxString err(_T("An error occured while running '"));
241                         err +=  bbtk::std2wx(command) + _T("'");
242                         wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);      
243                 }
244         }
245         
246   //================================================================
247         void wxGUIEditorGraphicBBS::RegenerateAll()
248         {
249                 DoRegeneratePackageDoc("-a");   
250                 DoRegenerateBoxesLists();
251         }
252
253         //================================================================
254
255         wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
256         {
257                 return _notebook;
258         }
259
260         //================================================================
261
262         void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
263         {
264                 if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
265                 {
266                         _actualPkgBrowserPkgName = packageName;
267                         _actualPkgBrowserBoxName = boxName;
268
269                         BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
270                         _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
271                 }
272         }
273
274         //=========================================================================
275
276         void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
277         {
278                 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
279                 dialog->Show();
280         }
281
282         //=========================================================================
283
284         void wxGUIEditorGraphicBBS::editDiagramParameters(wxVtkSceneManager* scene)
285         {
286                 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,scene);
287                 dialog->Show();
288         }
289
290         //=========================================================================
291
292         void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
293         {
294                 SetStatusText(crea::std2wx(textStatus));
295         }
296
297         //=========================================================================
298
299         void wxGUIEditorGraphicBBS::executeScript(std::string script)
300         {
301                 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
302                 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
303                 std::string filename = dir + separator + "tmp_bbtk.bbs";
304                 
305                 ofstream tempFile;
306                 tempFile.open(filename.c_str());
307                 tempFile << script;
308                 tempFile.close();
309                 
310                 std::string command = "\"";
311
312                 #ifdef WIN32
313                         command += "\"";
314                 #endif
315
316                 //command += ConfigurationFile::GetInstance().Get_bin_path();
317                 command +="C:/temp/bbtkBIN/RelWithDebInfo//";
318
319                 #ifdef MACOSX
320                         command += separator + "bbi.app/Contents/MacOS/bbi\" ";
321                 #else 
322                         command += separator + "bbi\" ";
323                 #endif
324                 command += "\""+filename + "\"";
325
326                 #ifdef WIN32
327                         command += "\"";
328                 #endif
329
330                 command += " & ";
331                   
332                 printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
333                 system( command.c_str() );
334         }
335
336         //=========================================================================
337         // EVENT HANDLERS 
338         //=========================================================================
339
340         void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
341         {
342                 _tabsMgr->addNewTab();          
343         }
344
345         //=========================================================================
346
347         void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
348         {
349                 std::string script = _tabsMgr->getActualDiagramScript();
350                 cout<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl;
351                 cout<<script<<endl;
352
353                 executeScript(script);          
354         }
355
356         //=========================================================================
357
358         void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
359         {
360                 _tabsMgr->deleteAllBoxesActualDiagram();
361         }
362
363         //=========================================================================
364
365         void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
366         {
367                 Close(true);
368         }
369
370
371 }  // EO namespace bbtk
372
373 // EOF
374