]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
Setting values in a blackbox and almost setting values in the scene properties
[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                 initPropertiesPanel();
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::initPropertiesPanel()
157         {
158                 _propertiesPanel = new wxPropertiesPanel(this);
159                 //_frameAUIMgr->AddPane(_propertiesPanel,wxAuiPaneInfo().Right().MinSize(200,200).CloseButton(false).Floatable(false));
160         }
161
162         //================================================================
163
164         void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
165         {
166                 std::string mess("Regenerating doc for package '");
167                 if (pack!="-a"){
168                         mess += pack + "'";
169                 }
170                 else
171                 {
172                         mess = "Regenerating doc for all packages";
173                 }
174                 
175                 mess += " ... please wait";             
176
177                 SetStatusText( std2wx(mess) );
178
179                 //BBTK_BUSY_CURSOR;
180
181                 std::string command;
182                 #if defined(WIN32)
183                         command = "\"";
184                 #endif
185                         command += ConfigurationFile::GetInstance().Get_bin_path();
186                         command += ConfigurationFile::GetInstance().Get_file_separator();
187                         command += "bbRegeneratePackageDoc";
188                 #if defined(WIN32)
189                         command += "\"";
190                 #endif
191
192                 command += " " + pack + " -q";
193             bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
194
195                 if ( ! system ( command.c_str() ) )
196                 {
197                         SetStatusText( _T("Done !"));
198                         /*
199                         wxMessageBox(_T("Done !"),_T("Regenerate package '")
200                                          +std2wx(pack)+_T("' doc"),
201                                          wxOK | wxICON_INFORMATION);
202                         */
203                 }
204                 else 
205                 {
206                         SetStatusText( _T("Done !"));
207                         wxString err(_T("An error occured while running '"));
208                         err +=  bbtk::std2wx(command) + _T("'");
209                         wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);      
210             }
211         }
212
213         //================================================================
214         void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
215         {
216                 SetStatusText( _T("Regenerating boxes lists ... please wait") );
217                 //BBTK_BUSY_CURSOR ;
218
219                 std::string command;
220                 #if defined(WIN32)
221                         command = "\"";
222                 #endif
223                         command += ConfigurationFile::GetInstance().Get_bin_path();
224                         command += ConfigurationFile::GetInstance().Get_file_separator();
225                         command += "bbRegenerateBoxesLists";
226
227                 #if defined(WIN32)
228                         command += "\"";
229                 #endif
230                         command += " -q";
231
232                 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
233
234                 if ( ! system ( command.c_str() ) )
235                 {
236                         SetStatusText( _T("Done !"));
237                         /*
238                         wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
239                                          wxOK | wxICON_INFORMATION);
240                         */
241                 }
242                 else 
243                 {
244                         SetStatusText( _T("Done !"));
245                         wxString err(_T("An error occured while running '"));
246                         err +=  bbtk::std2wx(command) + _T("'");
247                         wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);      
248                 }
249         }
250         
251   //================================================================
252         void wxGUIEditorGraphicBBS::RegenerateAll()
253         {
254                 DoRegeneratePackageDoc("-a");   
255                 DoRegenerateBoxesLists();
256         }
257
258         //================================================================
259
260         wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
261         {
262                 return _notebook;
263         }
264
265         //================================================================
266
267         void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
268         {
269                 if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
270                 {
271                         _actualPkgBrowserPkgName = packageName;
272                         _actualPkgBrowserBoxName = boxName;
273
274                         BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
275                         _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
276                 }
277         }
278
279         //=========================================================================
280
281         void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
282         {
283                 wxEditionDialog* dialog = new wxEditionDialog(this,bbmodel);
284                 dialog->Show();
285         }
286
287         //=========================================================================
288
289         void wxGUIEditorGraphicBBS::editDiagramParameters(wxVtkSceneManager* scene)
290         {
291                 wxEditionDialog* dialog = new wxEditionDialog(this,scene);
292                 dialog->Show();
293         }
294
295         //=========================================================================
296
297         void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
298         {
299                 SetStatusText(_T(textStatus));
300         }
301
302         //=========================================================================
303
304         void wxGUIEditorGraphicBBS::executeActualDiagram()
305         {
306                 std::string script = _tabsMgr->getActualDiagramScript();
307                 cout<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl;
308                 cout<<script<<endl;
309
310
311                 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
312                 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
313                 std::string filename = dir + separator + "tmp_bbtk.bbs";
314                 
315                 ofstream tempFile;
316                 tempFile.open(filename.c_str());
317                 tempFile << script;
318                 tempFile.close();
319                 
320                 std::string command = "\"";
321
322                 #ifdef WIN32
323                         command += "\"";
324                 #endif
325
326                 //command += ConfigurationFile::GetInstance().Get_bin_path();
327                 command +="C:/RaC/CREATIS/bbtkBIN/RelWithDebInfo//";
328
329                 #ifdef MACOSX
330                         command += separator + "bbi.app/Contents/MacOS/bbi\" ";
331                 #else 
332                         command += separator + "bbi\" ";
333                 #endif
334                 command += "\""+filename + "\"";
335
336                 #ifdef WIN32
337                         command += "\"";
338                 #endif
339
340                 command += " & ";
341                   
342                 printf ("RaC wxGUIEditorGraphicBBS::executeActualDiagram %s \n" , command.c_str() );
343                 system( command.c_str() );
344         }
345
346         //=========================================================================
347
348         /*****************************************************
349         /* HANDLERS 
350         /*****************************************************/
351
352         void wxGUIEditorGraphicBBS::OnToolLeftClick(wxCommandEvent& event)
353         {
354                 switch (event.GetId())
355                 {
356                         case 1000 :
357                                 _tabsMgr->addNewTab();
358                         break;  
359
360                         case 1001 :
361                                 executeActualDiagram();
362                         break;  
363                 }
364         }
365
366         void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
367         {
368                 Close(true);
369         }
370
371
372 }  // EO namespace bbtk
373
374 // EOF
375