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