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()
144 // Create File menu and its items
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 // Create Help menu and its items
159 wxMenu *editMenu = new wxMenu;
160 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM, _T("Copy selected to complex box"), _T("Creates a new complex box diagram with selected boxes"));
162 Connect(ID_COPY_TO_COMPLEXDIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
164 // Create Help menu and its items
165 wxMenu *helpMenu = new wxMenu;
166 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
168 // Append the created menu to the menu bar
169 wxMenuBar *menuBar = new wxMenuBar();
170 menuBar->Append(fileMenu, _T("&File"));
171 menuBar->Append(editMenu, _T("&Edit"));
172 menuBar->Append(helpMenu, _T("&Help"));
174 // Attach this menu bar to the frame
178 //=========================================================================
179 void wxGUIEditorGraphicBBS::initTabPanelsManager()
181 _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);
182 _tabsMgr = new wxTabPanelsManager(this);
183 _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());
187 //=========================================================================
188 void wxGUIEditorGraphicBBS::initPackageBrowser()
190 _pkgBrowser = new WxGUIPackageBrowser2(this);
191 _pkgBrowser->IncludeAll();
192 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));
195 //================================================================
197 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
199 std::string mess("Regenerating doc for package '");
205 mess = "Regenerating doc for all packages";
208 mess += " ... please wait";
210 SetStatusText( std2wx(mess) );
218 command += ConfigurationFile::GetInstance().Get_bin_path();
219 command += ConfigurationFile::GetInstance().Get_file_separator();
220 command += "bbRegeneratePackageDoc";
225 command += " " + pack + " -q";
226 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
228 if ( ! system ( command.c_str() ) )
230 SetStatusText( _T("Done !"));
232 wxMessageBox(_T("Done !"),_T("Regenerate package '")
233 +std2wx(pack)+_T("' doc"),
234 wxOK | wxICON_INFORMATION);
239 SetStatusText( _T("Done !"));
240 wxString err(_T("An error occured while running '"));
241 err += bbtk::std2wx(command) + _T("'");
242 wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);
246 //================================================================
247 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
249 SetStatusText( _T("Regenerating boxes lists ... please wait") );
256 command += ConfigurationFile::GetInstance().Get_bin_path();
257 command += ConfigurationFile::GetInstance().Get_file_separator();
258 command += "bbRegenerateBoxesLists";
265 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
267 if ( ! system ( command.c_str() ) )
269 SetStatusText( _T("Done !"));
271 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
272 wxOK | wxICON_INFORMATION);
277 SetStatusText( _T("Done !"));
278 wxString err(_T("An error occured while running '"));
279 err += bbtk::std2wx(command) + _T("'");
280 wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);
284 //================================================================
285 void wxGUIEditorGraphicBBS::RegenerateAll()
287 DoRegeneratePackageDoc("-a");
288 DoRegenerateBoxesLists();
291 //================================================================
293 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
298 //================================================================
300 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
302 if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
304 _actualPkgBrowserPkgName = packageName;
305 _actualPkgBrowserBoxName = boxName;
307 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
308 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
312 //=========================================================================
314 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
316 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
320 //=========================================================================
322 void wxGUIEditorGraphicBBS::editDiagramParameters(wxVtkSceneManager* scene)
324 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,scene);
328 //=========================================================================
330 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
332 SetStatusText(crea::std2wx(textStatus));
335 //=========================================================================
337 void wxGUIEditorGraphicBBS::executeScript(std::string script)
339 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
340 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
341 std::string filename = dir + separator + "tmp_bbtk.bbs";
344 tempFile.open(filename.c_str());
348 std::string command = "\"";
354 //command += ConfigurationFile::GetInstance().Get_bin_path();
355 command +="C:/temp/bbtkBIN/RelWithDebInfo//";
358 command += separator + "bbi.app/Contents/MacOS/bbi\" ";
360 command += separator + "bbi\" ";
362 command += "\""+filename + "\"";
370 printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
371 system( command.c_str() );
374 //=========================================================================
376 //=========================================================================
378 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
380 _tabsMgr->addNewTab();
381 refreshGUIControls();
384 //=========================================================================
386 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
388 std::string script = _tabsMgr->getActualDiagramBBS();
389 cout<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl;
392 executeScript(script);
395 //=========================================================================
397 //=========================================================================
399 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event)
401 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save actual BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxSAVE|wxOVERWRITE_PROMPT);
402 if (saveFileDialog->ShowModal() == wxID_OK)
404 wxString fileName = saveFileDialog->GetPath();
408 //EED file.open(fileName.c_str());
409 file.open( (const char*) (fileName.mb_str()) );
411 std::string content="";
413 // writing file header
414 content += "# ----------------------------------\n";
415 content += "# - BBTKGEditor v 1.0 BBS BlackBox Script\n";
416 content += "# ----------------------------------\n";
418 content += _tabsMgr->getActualDiagramBBS();
425 //=========================================================================
427 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event)
429 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of complex box"));
430 std::string cbName="";
431 if (nameDialog->ShowModal() == wxID_OK)
433 wxString fileName = nameDialog->GetValue();
434 //EED cbName=fileName;
435 cbName=(const char*) (fileName.mb_str());
440 wxFileDialog * saveFileDialog = new wxFileDialog( this , _T("Save Complex Box BBS") ,_T(""), wxString( cbName.c_str(), wxConvUTF8),_T(""), wxSAVE | wxOVERWRITE_PROMPT);
441 if (saveFileDialog->ShowModal() == wxID_OK)
443 wxString fileName = saveFileDialog->GetPath();
446 //EED file.open(fileName.c_str());
447 file.open( (const char*) (fileName.mb_str()) );
449 std::string content="";
451 // writing file header
452 content += "# ----------------------------------\n";
453 content += "# - BBTKGEditor v 1.1 BBS BlackBox Script (Complex Box)\n";
454 content += "# ----------------------------------\n";
456 content += _tabsMgr->getActualComplexBoxBBS(cbName);
464 //=========================================================================
466 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
468 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save actual diagram"),wxEmptyString,wxT("NewDiagram"),wxT("*.bbg"),wxSAVE|wxOVERWRITE_PROMPT);
469 if (saveFileDialog->ShowModal() == wxID_OK)
471 wxString fileName = saveFileDialog->GetPath();
474 //EED file.open(fileName.c_str());
475 file.open( (const char*) (fileName.mb_str()) );
477 std::string content="";
479 // writing file header
480 content += "# ----------------------------------\n";
481 content += "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file\n";
484 //EED content += fileName;
485 content += (const char*) (fileName.mb_str());
488 content += "# ----------------------------------\n";
490 content += "APP_START\n";
491 _tabsMgr->saveActualDiagram(content);
492 content += "APP_END\n";
499 //=========================================================================
501 void wxGUIEditorGraphicBBS::refreshGUIControls()
503 wxToolBar* toolbar = GetToolBar();
504 if(_tabsMgr->isActualDiagramComplexBox())
506 toolbar->ToggleTool(ID_BTNCOMPLEXBOX,true);
507 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,true);
508 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,true);
510 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,true);
511 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,false);
515 toolbar->ToggleTool(ID_BTNCOMPLEXBOX,false);
516 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
517 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
519 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,false);
520 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,true);
523 if(_tabsMgr->getNumActualSelectedObjects()>0)
525 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
529 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
530 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
535 //=========================================================================
537 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
539 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);
540 if(dial->ShowModal() == wxID_YES)
542 _tabsMgr->deleteAllBoxesActualDiagram();
546 //=========================================================================
548 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
550 _tabsMgr->centerViewActualDiagram();
553 //=========================================================================
556 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
558 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open diagram"),wxEmptyString,wxT(""),wxT("*.bbg"),wxOPEN|wxFILE_MUST_EXIST);
559 if (openFileDialog->ShowModal() == wxID_OK)
561 wxString fileName = openFileDialog->GetPath();
563 ifstream inputStream;
565 //EED inputStream.open(fileName.c_str());
566 inputStream.open( (const char*) (fileName.mb_str()) );
570 _tabsMgr->addNewTab();
571 _tabsMgr->loadDiagram(inputStream);
575 refreshGUIControls();
578 //=========================================================================
580 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
582 wxToolBar* toolbar = GetToolBar();
583 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
586 _tabsMgr->setActualDiagramComplexBox(true);
590 _tabsMgr->setActualDiagramComplexBox(false);
592 refreshGUIControls();
595 //=========================================================================
597 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
599 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of input port"));
600 if (nameDialog->ShowModal() == wxID_OK)
602 wxString fileName = nameDialog->GetValue();
603 if(!fileName.IsEmpty())
605 std::string portName=(const char*) (fileName.mb_str());
606 _tabsMgr->addActualDiagramComplexInputPort(portName);
611 //=========================================================================
613 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
615 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of output port"));
616 if (nameDialog->ShowModal() == wxID_OK)
618 wxString fileName = nameDialog->GetValue();
619 if(!fileName.IsEmpty())
621 std::string portName=(const char*) (fileName.mb_str());
622 _tabsMgr->addActualDiagramComplexOutputPort(portName);
627 //=========================================================================
629 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(wxCommandEvent& event)
631 _tabsMgr->copySelectedBBoxesToComplexDiagram();
634 //=========================================================================
636 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
641 //=========================================================================
643 } // EO namespace bbtk