1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::WxInterfaceEditorGraphicBBS .
36 #include "bbtkwxGUIEditorGraphicBBS.h"
43 //=========================================================================
44 wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent)
45 : wxFrame(parent, -1, _T("bbtkGEditor"),wxDefaultPosition, wxSize(1200,800))
47 _frameAUIMgr = new wxAuiManager(this);
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;
56 #ifdef LINUX // assume this is OSX
57 datadir=datadir+"/../share/creaContours";
60 #ifdef MACOSX // assume this is OSX
61 datadir=datadir+"/../../../../share/creaContours";
68 initTabPanelsManager();
70 initHelpHTMLBrowser();
73 _frameAUIMgr->Update();
74 _actualPkgBrowserBoxName="";
75 _actualPkgBrowserPkgName="";
79 //=========================================================================
80 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS()
82 _frameAUIMgr->UnInit();
85 //=========================================================================
86 void wxGUIEditorGraphicBBS::initToolbar()
88 wxBitmap bmp_new(new_xpm);
89 wxBitmap bmp_open(open_xpm);
90 wxBitmap bmp_save(save_xpm);
91 wxBitmap bmp_run(run_xpm);
92 wxBitmap bmp_delete(delete_xpm);
93 wxBitmap bmp_centerview(centerview_xpm);
95 wxToolBar *_toolbar = new wxToolBar(this, wxID_ANY);
97 //Adds a tool btn to the toolbar
98 _toolbar->AddTool(ID_NEW,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
99 _toolbar->AddTool(ID_OPEN,_T("Open diagram"),bmp_open, wxNullBitmap, wxITEM_NORMAL,_T("Open a diagram"), _T("Open a diagram"));
100 _toolbar->AddTool(ID_SAVE,_T("Save diagram"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves actual diagram"), _T("Saves actual diagram"));
101 _toolbar->AddTool(ID_RUN,_T("Run"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram"));
102 _toolbar->AddTool(ID_DELETEALL,_T("Delete all"),bmp_delete, wxNullBitmap, wxITEM_NORMAL,_T("Delete all boxes"), _T("Delete all boxes"));
103 _toolbar->AddTool(ID_CENTERVIEW,_T("Center view"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Center view"), _T("Center view"));
106 _toolbar->SetMargins( 2, 2 );
108 SetToolBar(_toolbar);
110 // connect command event handlers
111 Connect(ID_NEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
112 Connect(ID_OPEN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
113 Connect(ID_SAVE,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
114 Connect(ID_RUN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
115 Connect(ID_DELETEALL,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
116 Connect(ID_CENTERVIEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
119 //=========================================================================
120 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
122 //TO FIX THE PATH OF BBTK BIN IN ORDER TO USE REGENERATE EXECUTABLES
124 _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
125 _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));
128 //=========================================================================
129 void wxGUIEditorGraphicBBS::initMenu()
132 wxMenu *fileMenu = new wxMenu;
134 // the "About" item should be in the help menu
135 wxMenu *helpMenu = new wxMenu;
136 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
137 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
139 Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
141 // now append the freshly created menu to the menu bar...
142 wxMenuBar *menuBar = new wxMenuBar();
143 menuBar->Append(fileMenu, _T("&File"));
144 menuBar->Append(helpMenu, _T("&Help"));
146 // attach this menu bar to the frame
150 //=========================================================================
151 void wxGUIEditorGraphicBBS::initTabPanelsManager()
153 _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);
154 _tabsMgr = new wxTabPanelsManager(this);
155 _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());
159 //=========================================================================
160 void wxGUIEditorGraphicBBS::initPackageBrowser()
162 _pkgBrowser = new WxGUIPackageBrowser2(this);
163 _pkgBrowser->IncludeAll();
164 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));
167 //================================================================
169 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
171 std::string mess("Regenerating doc for package '");
177 mess = "Regenerating doc for all packages";
180 mess += " ... please wait";
182 SetStatusText( std2wx(mess) );
190 command += ConfigurationFile::GetInstance().Get_bin_path();
191 command += ConfigurationFile::GetInstance().Get_file_separator();
192 command += "bbRegeneratePackageDoc";
197 command += " " + pack + " -q";
198 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
200 if ( ! system ( command.c_str() ) )
202 SetStatusText( _T("Done !"));
204 wxMessageBox(_T("Done !"),_T("Regenerate package '")
205 +std2wx(pack)+_T("' doc"),
206 wxOK | wxICON_INFORMATION);
211 SetStatusText( _T("Done !"));
212 wxString err(_T("An error occured while running '"));
213 err += bbtk::std2wx(command) + _T("'");
214 wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);
218 //================================================================
219 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
221 SetStatusText( _T("Regenerating boxes lists ... please wait") );
228 command += ConfigurationFile::GetInstance().Get_bin_path();
229 command += ConfigurationFile::GetInstance().Get_file_separator();
230 command += "bbRegenerateBoxesLists";
237 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
239 if ( ! system ( command.c_str() ) )
241 SetStatusText( _T("Done !"));
243 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
244 wxOK | wxICON_INFORMATION);
249 SetStatusText( _T("Done !"));
250 wxString err(_T("An error occured while running '"));
251 err += bbtk::std2wx(command) + _T("'");
252 wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);
256 //================================================================
257 void wxGUIEditorGraphicBBS::RegenerateAll()
259 DoRegeneratePackageDoc("-a");
260 DoRegenerateBoxesLists();
263 //================================================================
265 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
270 //================================================================
272 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
274 if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
276 _actualPkgBrowserPkgName = packageName;
277 _actualPkgBrowserBoxName = boxName;
279 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
280 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
284 //=========================================================================
286 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
288 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
292 //=========================================================================
294 void wxGUIEditorGraphicBBS::editDiagramParameters(wxVtkSceneManager* scene)
296 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,scene);
300 //=========================================================================
302 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
304 SetStatusText(crea::std2wx(textStatus));
307 //=========================================================================
309 void wxGUIEditorGraphicBBS::executeScript(std::string script)
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";
316 tempFile.open(filename.c_str());
320 std::string command = "\"";
326 //command += ConfigurationFile::GetInstance().Get_bin_path();
327 command +="C:/temp/bbtkBIN/RelWithDebInfo//";
330 command += separator + "bbi.app/Contents/MacOS/bbi\" ";
332 command += separator + "bbi\" ";
334 command += "\""+filename + "\"";
342 printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
343 system( command.c_str() );
346 //=========================================================================
348 //=========================================================================
350 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
352 _tabsMgr->addNewTab();
355 //=========================================================================
357 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
359 std::string script = _tabsMgr->getActualDiagramScript();
360 cout<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl;
363 executeScript(script);
366 //=========================================================================
368 /*****************************************************/
370 /*****************************************************/
371 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
373 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save actual diagram"),wxEmptyString,"NewDiagram","*.bbd",wxSAVE|wxOVERWRITE_PROMPT);
374 if (saveFileDialog->ShowModal() == wxID_OK)
376 wxString fileName = saveFileDialog->GetPath();
379 file.open(fileName.c_str());
381 std::string content="";
383 // writing file header
384 content += "# ----------------------------------\n";
385 content += "# - BBTKGEditor v 1.0 Diagram file\n";
389 content += "# ----------------------------------\n";
391 content += "APP_START\n";
392 _tabsMgr->saveActualDiagram(content);
393 content += "APP_END\n";
402 //=========================================================================
404 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
406 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);
407 if(dial->ShowModal() == wxID_YES)
409 _tabsMgr->deleteAllBoxesActualDiagram();
413 //=========================================================================
415 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
417 _tabsMgr->centerViewActualDiagram();
420 //=========================================================================
423 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
425 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open diagram"),wxEmptyString,"","*.bbd",wxOPEN|wxFILE_MUST_EXIST);
426 if (openFileDialog->ShowModal() == wxID_OK)
428 wxString fileName = openFileDialog->GetPath();
430 ifstream inputStream;
431 inputStream.open(fileName.c_str());
433 _tabsMgr->addNewTab();
434 _tabsMgr->loadDiagram(inputStream);
442 //=========================================================================
444 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
449 //=========================================================================
451 } // EO namespace bbtk