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="";
80 //=========================================================================
81 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS()
83 _frameAUIMgr->UnInit();
86 //=========================================================================
87 void wxGUIEditorGraphicBBS::initToolbar()
89 wxBitmap bmp_new(new_xpm);
90 wxBitmap bmp_open(open_xpm);
91 wxBitmap bmp_save(save_xpm);
92 wxBitmap bmp_run(run_xpm);
93 wxBitmap bmp_delete(delete_xpm);
94 wxBitmap bmp_centerview(centerview_xpm);
95 wxBitmap bmp_complexbox(complexbox_xpm);
96 wxBitmap bmp_complexinputport(complexinputport_xpm);
97 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
99 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
101 //Adds a tool btn to the toolbar
102 toolbar->AddTool(ID_NEW,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
103 toolbar->AddTool(ID_OPEN,_T("Open diagram"),bmp_open, wxNullBitmap, wxITEM_NORMAL,_T("Open a diagram"), _T("Open a diagram"));
104 toolbar->AddTool(ID_SAVE_AS_DIAGRAM,_T("Save diagram"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves actual diagram"), _T("Saves actual diagram"));
105 toolbar->AddTool(ID_RUN,_T("Run"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram"));
106 toolbar->AddTool(ID_DELETEALL,_T("Delete all"),bmp_delete, wxNullBitmap, wxITEM_NORMAL,_T("Delete all boxes"), _T("Delete all boxes"));
107 toolbar->AddTool(ID_CENTERVIEW,_T("Center view"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Center view"), _T("Center view"));
108 toolbar->AddSeparator();
109 toolbar->AddTool(ID_BTNCOMPLEXBOX,_T("Complex box"),complexbox_xpm, wxNullBitmap, wxITEM_NORMAL,_T("Complex box"), _T("Complex box"));
110 toolbar->SetToggle(ID_BTNCOMPLEXBOX,true);
111 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT,_T("Add input to Complex box"),bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,_T("Add input to Complex box"), _T("Add input to Complex box"));
112 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT,_T("Add output to Complex box"),bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,_T("Add output Complex box"), _T("Add output Complex box"));
113 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
114 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
116 toolbar->SetMargins( 2, 2 );
120 // connect command event handlers
121 Connect(ID_NEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
122 Connect(ID_OPEN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
123 Connect(ID_SAVE_AS_DIAGRAM,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
124 Connect(ID_RUN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
125 Connect(ID_DELETEALL,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
126 Connect(ID_CENTERVIEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
127 Connect(ID_BTNCOMPLEXBOX,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
128 Connect(ID_ADDCOMPLEXBOXINPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
129 Connect(ID_ADDCOMPLEXBOXOUTPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
132 //=========================================================================
133 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
135 //TO FIX THE PATH OF BBTK BIN IN ORDER TO USE REGENERATE EXECUTABLES
137 _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
138 _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));
141 //=========================================================================
142 void wxGUIEditorGraphicBBS::initMenu()
145 wxMenu *fileMenu = new wxMenu();
146 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
147 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save diagram"), _T("Save diagram"));
148 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
149 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"), _T("Save complex box"));
150 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
152 Connect(ID_NEW,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
153 Connect(ID_SAVE_AS_DIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
154 Connect(ID_SAVE_AS_BBS,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
155 Connect(ID_SAVE_AS_COMPLEXBOX,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
156 Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
158 // the "About" item should be in the help menu
159 wxMenu *helpMenu = new wxMenu;
160 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
162 // now append the freshly created menu to the menu bar...
163 wxMenuBar *menuBar = new wxMenuBar();
164 menuBar->Append(fileMenu, _T("&File"));
165 menuBar->Append(helpMenu, _T("&Help"));
167 // attach this menu bar to the frame
171 //=========================================================================
172 void wxGUIEditorGraphicBBS::initTabPanelsManager()
174 _notebook = new wxAuiNotebook(this,wxID_NOTEBOOK,wxDefaultPosition,wxDefaultSize,wxAUI_NB_TOP|wxAUI_NB_TAB_MOVE|wxAUI_NB_CLOSE_ON_ACTIVE_TAB|wxAUI_NB_TAB_FIXED_WIDTH|wxAUI_NB_WINDOWLIST_BUTTON);
175 _tabsMgr = new wxTabPanelsManager(this);
176 _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());
180 //=========================================================================
181 void wxGUIEditorGraphicBBS::initPackageBrowser()
183 _pkgBrowser = new WxGUIPackageBrowser2(this);
184 _pkgBrowser->IncludeAll();
185 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));
188 //================================================================
190 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
192 std::string mess("Regenerating doc for package '");
198 mess = "Regenerating doc for all packages";
201 mess += " ... please wait";
203 SetStatusText( std2wx(mess) );
211 command += ConfigurationFile::GetInstance().Get_bin_path();
212 command += ConfigurationFile::GetInstance().Get_file_separator();
213 command += "bbRegeneratePackageDoc";
218 command += " " + pack + " -q";
219 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
221 if ( ! system ( command.c_str() ) )
223 SetStatusText( _T("Done !"));
225 wxMessageBox(_T("Done !"),_T("Regenerate package '")
226 +std2wx(pack)+_T("' doc"),
227 wxOK | wxICON_INFORMATION);
232 SetStatusText( _T("Done !"));
233 wxString err(_T("An error occured while running '"));
234 err += bbtk::std2wx(command) + _T("'");
235 wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);
239 //================================================================
240 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
242 SetStatusText( _T("Regenerating boxes lists ... please wait") );
249 command += ConfigurationFile::GetInstance().Get_bin_path();
250 command += ConfigurationFile::GetInstance().Get_file_separator();
251 command += "bbRegenerateBoxesLists";
258 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
260 if ( ! system ( command.c_str() ) )
262 SetStatusText( _T("Done !"));
264 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
265 wxOK | wxICON_INFORMATION);
270 SetStatusText( _T("Done !"));
271 wxString err(_T("An error occured while running '"));
272 err += bbtk::std2wx(command) + _T("'");
273 wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);
277 //================================================================
278 void wxGUIEditorGraphicBBS::RegenerateAll()
280 DoRegeneratePackageDoc("-a");
281 DoRegenerateBoxesLists();
284 //================================================================
286 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
291 //================================================================
293 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
295 if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
297 _actualPkgBrowserPkgName = packageName;
298 _actualPkgBrowserBoxName = boxName;
300 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
301 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
305 //=========================================================================
307 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
309 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
313 //=========================================================================
315 void wxGUIEditorGraphicBBS::editDiagramParameters(wxVtkSceneManager* scene)
317 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,scene);
321 //=========================================================================
323 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
325 SetStatusText(crea::std2wx(textStatus));
328 //=========================================================================
330 void wxGUIEditorGraphicBBS::executeScript(std::string script)
332 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
333 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
334 std::string filename = dir + separator + "tmp_bbtk.bbs";
337 tempFile.open(filename.c_str());
341 std::string command = "\"";
347 //command += ConfigurationFile::GetInstance().Get_bin_path();
348 command +="C:/temp/bbtkBIN/RelWithDebInfo//";
351 command += separator + "bbi.app/Contents/MacOS/bbi\" ";
353 command += separator + "bbi\" ";
355 command += "\""+filename + "\"";
363 printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
364 system( command.c_str() );
367 //=========================================================================
369 //=========================================================================
371 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
373 _tabsMgr->addNewTab();
374 refreshGUIControls();
377 //=========================================================================
379 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
381 std::string script = _tabsMgr->getActualDiagramBBS();
382 cout<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl;
385 executeScript(script);
388 //=========================================================================
390 //=========================================================================
392 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event)
394 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save actual BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxSAVE|wxOVERWRITE_PROMPT);
395 if (saveFileDialog->ShowModal() == wxID_OK)
397 wxString fileName = saveFileDialog->GetPath();
400 file.open(fileName.c_str());
402 std::string content="";
404 // writing file header
405 content += "# ----------------------------------\n";
406 content += "# - BBTKGEditor v 1.0 BBS BlackBox Script\n";
407 content += "# ----------------------------------\n";
409 content += _tabsMgr->getActualDiagramBBS();
416 //=========================================================================
418 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event)
420 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of complex box"));
421 std::string cbName="";
422 if (nameDialog->ShowModal() == wxID_OK)
424 wxString fileName = nameDialog->GetValue();
430 wxFileDialog * saveFileDialog = new wxFileDialog( this , _T("Save Complex Box BBS") ,_T(""), wxString( cbName.c_str(), wxConvUTF8),_T(""), wxSAVE | wxOVERWRITE_PROMPT);
431 if (saveFileDialog->ShowModal() == wxID_OK)
433 wxString fileName = saveFileDialog->GetPath();
436 file.open(fileName.c_str());
438 std::string content="";
440 // writing file header
441 content += "# ----------------------------------\n";
442 content += "# - BBTKGEditor v 1.1 BBS BlackBox Script (Complex Box)\n";
443 content += "# ----------------------------------\n";
445 content += _tabsMgr->getActualComplexBoxBBS(cbName);
453 //=========================================================================
455 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
457 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save actual diagram"),wxEmptyString,"NewDiagram","*.bbd",wxSAVE|wxOVERWRITE_PROMPT);
458 if (saveFileDialog->ShowModal() == wxID_OK)
460 wxString fileName = saveFileDialog->GetPath();
463 file.open(fileName.c_str());
465 std::string content="";
467 // writing file header
468 content += "# ----------------------------------\n";
469 content += "# - BBTKGEditor v 1.0 BBD BlackBox Diagram file\n";
473 content += "# ----------------------------------\n";
475 content += "APP_START\n";
476 _tabsMgr->saveActualDiagram(content);
477 content += "APP_END\n";
484 //=========================================================================
486 void wxGUIEditorGraphicBBS::refreshGUIControls()
488 wxToolBar* toolbar = GetToolBar();
489 if(_tabsMgr->isActualDiagramComplexBox())
491 toolbar->ToggleTool(ID_BTNCOMPLEXBOX,true);
492 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,true);
493 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,true);
495 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,true);
496 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,false);
500 toolbar->ToggleTool(ID_BTNCOMPLEXBOX,false);
501 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
502 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
504 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,false);
505 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,true);
510 //=========================================================================
512 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
514 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);
515 if(dial->ShowModal() == wxID_YES)
517 _tabsMgr->deleteAllBoxesActualDiagram();
521 //=========================================================================
523 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
525 _tabsMgr->centerViewActualDiagram();
528 //=========================================================================
531 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
533 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open diagram"),wxEmptyString,"","*.bbd",wxOPEN|wxFILE_MUST_EXIST);
534 if (openFileDialog->ShowModal() == wxID_OK)
536 wxString fileName = openFileDialog->GetPath();
538 ifstream inputStream;
539 inputStream.open(fileName.c_str());
541 _tabsMgr->addNewTab();
542 _tabsMgr->loadDiagram(inputStream);
546 refreshGUIControls();
549 //=========================================================================
551 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
553 wxToolBar* toolbar = GetToolBar();
554 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
557 _tabsMgr->setActualDiagramComplexBox(true);
561 _tabsMgr->setActualDiagramComplexBox(false);
563 refreshGUIControls();
566 //=========================================================================
568 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
570 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of input port"));
571 if (nameDialog->ShowModal() == wxID_OK)
573 wxString fileName = nameDialog->GetValue();
574 if(!fileName.IsEmpty())
576 std::string portName=(const char*) (fileName.mb_str());
577 _tabsMgr->addActualDiagramComplexInputPort(portName);
582 //=========================================================================
584 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
586 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of output port"));
587 if (nameDialog->ShowModal() == wxID_OK)
589 wxString fileName = nameDialog->GetValue();
590 if(!fileName.IsEmpty())
592 std::string portName=(const char*) (fileName.mb_str());
593 _tabsMgr->addActualDiagramComplexOutputPort(portName);
598 //=========================================================================
600 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
605 //=========================================================================
607 } // EO namespace bbtk