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