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))
48 printf ("EED %p wxGUIEditorGraphicBBS()\n" , this );
50 _frameAUIMgr = new wxAuiManager(this);
53 /*std::string datadir( crea::System::GetExecutablePath() );
54 std::string datadir (".");
55 cout<<"RaC //------------------"<<endl;
56 cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with crea::System::GetExecutablePath() ."<<endl;
57 cout<<"RaC //------------------"<<endl;
59 #ifdef LINUX // assume this is OSX
60 datadir=datadir+"/../share/creaContours";
63 #ifdef MACOSX // assume this is OSX
64 datadir=datadir+"/../../../../share/creaContours";
71 initTabPanelsManager();
73 initHelpHTMLBrowser();
76 _frameAUIMgr->Update();
77 _actualPkgBrowserBoxName="";
78 _actualPkgBrowserPkgName="";
83 //=========================================================================
84 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS()
86 printf ("EED %p ~wxGUIEditorGraphicBBS()\n" , this );
88 //EED02JUIN2010 delete _tabsMgr;
90 _frameAUIMgr->UnInit();
95 //=========================================================================
96 void wxGUIEditorGraphicBBS::initToolbar()
98 wxBitmap bmp_new(new_xpm);
99 wxBitmap bmp_open(open_xpm);
100 wxBitmap bmp_save(save_xpm);
101 wxBitmap bmp_run(run_xpm);
102 wxBitmap bmp_delete(delete_xpm);
103 wxBitmap bmp_centerview(centerview_xpm);
104 wxBitmap bmp_complexbox(complexbox_xpm);
105 wxBitmap bmp_complexinputport(complexinputport_xpm);
106 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
108 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
110 //Adds a tool btn to the toolbar
111 toolbar->AddTool(ID_NEW,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
112 toolbar->AddTool(ID_OPEN,_T("Open diagram"),bmp_open, wxNullBitmap, wxITEM_NORMAL,_T("Open a diagram"), _T("Open a diagram"));
113 toolbar->AddTool(ID_SAVE_AS_DIAGRAM,_T("Save diagram"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves actual diagram"), _T("Saves actual diagram"));
114 toolbar->AddTool(ID_RUN,_T("Run"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram"));
115 toolbar->AddTool(ID_DELETEALL,_T("Delete all"),bmp_delete, wxNullBitmap, wxITEM_NORMAL,_T("Delete all boxes"), _T("Delete all boxes"));
116 toolbar->AddTool(ID_CENTERVIEW,_T("Center view"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Center view"), _T("Center view"));
117 toolbar->AddSeparator();
118 toolbar->AddTool(ID_BTNCOMPLEXBOX,_T("Complex box"),complexbox_xpm, wxNullBitmap, wxITEM_NORMAL,_T("Complex box"), _T("Complex box"));
119 toolbar->SetToggle(ID_BTNCOMPLEXBOX,true);
120 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"));
121 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"));
122 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
123 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
125 toolbar->SetMargins( 2, 2 );
129 // connect command event handlers
130 Connect(ID_NEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
131 Connect(ID_OPEN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
132 Connect(ID_SAVE_AS_DIAGRAM,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
133 Connect(ID_RUN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
134 Connect(ID_DELETEALL,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
135 Connect(ID_CENTERVIEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
136 Connect(ID_BTNCOMPLEXBOX,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
137 Connect(ID_ADDCOMPLEXBOXINPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
138 Connect(ID_ADDCOMPLEXBOXOUTPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
141 //=========================================================================
142 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
144 //TO FIX THE PATH OF BBTK BIN IN ORDER TO USE REGENERATE EXECUTABLES
146 _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
147 _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));
150 //=========================================================================
151 void wxGUIEditorGraphicBBS::initMenu()
153 // Create File menu and its items
154 wxMenu *fileMenu = new wxMenu();
155 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
156 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save diagram"), _T("Save diagram"));
157 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
158 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"), _T("Save complex box"));
159 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
161 Connect(ID_NEW,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
162 Connect(ID_SAVE_AS_DIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
163 Connect(ID_SAVE_AS_BBS,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
164 Connect(ID_SAVE_AS_COMPLEXBOX,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
165 Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
167 // Create Help menu and its items
168 wxMenu *editMenu = new wxMenu;
169 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM, _T("Copy selected to complex box"), _T("Creates a new complex box diagram with selected boxes"));
171 Connect(ID_COPY_TO_COMPLEXDIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
173 // Create Help menu and its items
174 wxMenu *helpMenu = new wxMenu;
175 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
177 // Append the created menu to the menu bar
178 wxMenuBar *menuBar = new wxMenuBar();
179 menuBar->Append(fileMenu, _T("&File"));
180 menuBar->Append(editMenu, _T("&Edit"));
181 menuBar->Append(helpMenu, _T("&Help"));
183 // Attach this menu bar to the frame
187 //=========================================================================
188 void wxGUIEditorGraphicBBS::initTabPanelsManager()
190 _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);
191 _tabsMgr = new wxTabPanelsManager(this);
192 _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());
196 //=========================================================================
197 void wxGUIEditorGraphicBBS::initPackageBrowser()
199 _pkgBrowser = new WxGUIPackageBrowser2(this);
200 _pkgBrowser->IncludeAll();
201 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));
204 //================================================================
206 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
208 std::string mess("Regenerating doc for package '");
214 mess = "Regenerating doc for all packages";
217 mess += " ... please wait";
219 SetStatusText( std2wx(mess) );
227 command += ConfigurationFile::GetInstance().Get_bin_path();
228 command += ConfigurationFile::GetInstance().Get_file_separator();
229 command += "bbRegeneratePackageDoc";
234 command += " " + pack + " -q";
235 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
237 if ( ! system ( command.c_str() ) )
239 SetStatusText( _T("Done !"));
241 wxMessageBox(_T("Done !"),_T("Regenerate package '")
242 +std2wx(pack)+_T("' doc"),
243 wxOK | wxICON_INFORMATION);
248 SetStatusText( _T("Done !"));
249 wxString err(_T("An error occured while running '"));
250 err += bbtk::std2wx(command) + _T("'");
251 wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);
255 //================================================================
256 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
258 SetStatusText( _T("Regenerating boxes lists ... please wait") );
265 command += ConfigurationFile::GetInstance().Get_bin_path();
266 command += ConfigurationFile::GetInstance().Get_file_separator();
267 command += "bbRegenerateBoxesLists";
274 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
276 if ( ! system ( command.c_str() ) )
278 SetStatusText( _T("Done !"));
280 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
281 wxOK | wxICON_INFORMATION);
286 SetStatusText( _T("Done !"));
287 wxString err(_T("An error occured while running '"));
288 err += bbtk::std2wx(command) + _T("'");
289 wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);
293 //================================================================
294 void wxGUIEditorGraphicBBS::RegenerateAll()
296 DoRegeneratePackageDoc("-a");
297 DoRegenerateBoxesLists();
300 //================================================================
302 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
307 //================================================================
309 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
311 if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
313 _actualPkgBrowserPkgName = packageName;
314 _actualPkgBrowserBoxName = boxName;
316 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
317 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
321 //=========================================================================
323 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
325 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
329 //=========================================================================
331 void wxGUIEditorGraphicBBS::editDiagramParameters(wxVtkSceneManager* scene)
333 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,scene);
337 //=========================================================================
339 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
341 SetStatusText(crea::std2wx(textStatus));
344 //=========================================================================
346 void wxGUIEditorGraphicBBS::executeScript(std::string script)
348 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
349 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
350 std::string filename = dir + separator + "tmp_bbtk.bbs";
353 tempFile.open(filename.c_str());
357 std::string command = "\"";
363 //command += ConfigurationFile::GetInstance().Get_bin_path();
364 //EED command +="C:/temp/bbtkBIN/RelWithDebInfo//";
365 //EED command +="C:/Program Files/CreaTools/bbtk-0.9.5/bin";
370 command += separator + "bbi.app/Contents/MacOS/bbi\" ";
372 command += separator + "bbi\" ";
374 command += "\""+filename + "\"";
382 printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
383 system( command.c_str() );
386 //=========================================================================
388 //=========================================================================
390 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
392 _tabsMgr->addNewTab();
393 refreshGUIControls();
396 //=========================================================================
398 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
400 std::string script = _tabsMgr->getActualDiagramBBS();
401 cout<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl;
404 executeScript(script);
407 //=========================================================================
409 //=========================================================================
411 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event)
413 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save actual BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxSAVE|wxOVERWRITE_PROMPT);
414 if (saveFileDialog->ShowModal() == wxID_OK)
416 wxString fileName = saveFileDialog->GetPath();
420 //EED file.open(fileName.c_str());
421 file.open( (const char*) (fileName.mb_str()) );
423 std::string content="";
425 // writing file header
426 content += "# ----------------------------------\n";
427 content += "# - BBTKGEditor v 1.0 BBS BlackBox Script\n";
428 content += "# ----------------------------------\n";
430 content += _tabsMgr->getActualDiagramBBS();
437 //=========================================================================
439 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event)
441 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of complex box"));
442 std::string cbName="";
443 if (nameDialog->ShowModal() == wxID_OK)
445 wxString fileName = nameDialog->GetValue();
446 //EED cbName=fileName;
447 cbName=(const char*) (fileName.mb_str());
452 wxFileDialog * saveFileDialog = new wxFileDialog( this , _T("Save Complex Box BBS") ,_T(""), wxString( cbName.c_str(), wxConvUTF8),_T(""), wxSAVE | wxOVERWRITE_PROMPT);
453 if (saveFileDialog->ShowModal() == wxID_OK)
455 wxString fileName = saveFileDialog->GetPath();
458 //EED file.open(fileName.c_str());
459 file.open( (const char*) (fileName.mb_str()) );
461 std::string content="";
463 // writing file header
464 content += "# ----------------------------------\n";
465 content += "# - BBTKGEditor v 1.1 BBS BlackBox Script (Complex Box)\n";
466 content += "# ----------------------------------\n";
468 content += _tabsMgr->getActualComplexBoxBBS(cbName);
476 //=========================================================================
478 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
480 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save actual diagram"),wxEmptyString,wxT("NewDiagram"),wxT("*.bbg"),wxSAVE|wxOVERWRITE_PROMPT);
481 if (saveFileDialog->ShowModal() == wxID_OK)
483 wxString fileName = saveFileDialog->GetPath();
486 //EED file.open(fileName.c_str());
487 file.open( (const char*) (fileName.mb_str()) );
489 std::string content="";
491 // writing file header
492 content += "# ----------------------------------\n";
493 content += "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file\n";
496 //EED content += fileName;
497 content += (const char*) (fileName.mb_str());
500 content += "# ----------------------------------\n";
502 content += "APP_START\n";
503 _tabsMgr->saveActualDiagram(content);
504 content += "APP_END\n";
511 //=========================================================================
513 void wxGUIEditorGraphicBBS::refreshGUIControls()
515 wxToolBar* toolbar = GetToolBar();
516 if(_tabsMgr->isActualDiagramComplexBox())
518 toolbar->ToggleTool(ID_BTNCOMPLEXBOX,true);
519 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,true);
520 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,true);
522 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,true);
523 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,false);
527 toolbar->ToggleTool(ID_BTNCOMPLEXBOX,false);
528 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
529 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
531 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,false);
532 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,true);
535 if(_tabsMgr->getNumActualSelectedObjects()>0)
537 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
541 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
542 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
547 //=========================================================================
549 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
551 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);
552 if(dial->ShowModal() == wxID_YES)
554 _tabsMgr->deleteAllBoxesActualDiagram();
558 //=========================================================================
560 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
562 _tabsMgr->centerViewActualDiagram();
565 //=========================================================================
568 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
570 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open diagram"),wxEmptyString,wxT(""),wxT("*.bbg"),wxOPEN|wxFILE_MUST_EXIST);
571 if (openFileDialog->ShowModal() == wxID_OK)
573 wxString fileName = openFileDialog->GetPath();
575 ifstream inputStream;
577 //EED inputStream.open(fileName.c_str());
578 inputStream.open( (const char*) (fileName.mb_str()) );
582 _tabsMgr->addNewTab();
583 _tabsMgr->loadDiagram(inputStream);
587 refreshGUIControls();
590 //=========================================================================
592 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
594 wxToolBar* toolbar = GetToolBar();
595 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
598 _tabsMgr->setActualDiagramComplexBox(true);
602 _tabsMgr->setActualDiagramComplexBox(false);
604 refreshGUIControls();
607 //=========================================================================
609 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
611 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of input port"));
612 if (nameDialog->ShowModal() == wxID_OK)
614 wxString fileName = nameDialog->GetValue();
615 if(!fileName.IsEmpty())
617 std::string portName=(const char*) (fileName.mb_str());
618 _tabsMgr->addActualDiagramComplexInputPort(portName);
623 //=========================================================================
625 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
627 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of output port"));
628 if (nameDialog->ShowModal() == wxID_OK)
630 wxString fileName = nameDialog->GetValue();
631 if(!fileName.IsEmpty())
633 std::string portName=(const char*) (fileName.mb_str());
634 _tabsMgr->addActualDiagramComplexOutputPort(portName);
639 //=========================================================================
641 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(wxCommandEvent& event)
643 _tabsMgr->copySelectedBBoxesToComplexDiagram();
646 //=========================================================================
648 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
653 //=========================================================================
655 } // EO namespace bbtk