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 _frameAUIMgr = new wxAuiManager(this);
51 /*std::string datadir( crea::System::GetExecutablePath() );
52 std::string datadir (".");
53 cout<<"RaC //------------------"<<endl;
54 cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with crea::System::GetExecutablePath() ."<<endl;
55 cout<<"RaC //------------------"<<endl;
57 #ifdef LINUX // assume this is OSX
58 datadir=datadir+"/../share/creaContours";
61 #ifdef MACOSX // assume this is OSX
62 datadir=datadir+"/../../../../share/creaContours";
69 initTabPanelsManager();
71 initHelpHTMLBrowser();
74 _frameAUIMgr->Update();
75 _actualPkgBrowserBoxName="";
76 _actualPkgBrowserPkgName="";
81 //=========================================================================
82 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS()
84 printf ("EED %p ~wxGUIEditorGraphicBBS()\n" , this );
86 //EED02JUIN2010 delete _tabsMgr;
88 _frameAUIMgr->UnInit();
93 //=========================================================================
94 void wxGUIEditorGraphicBBS::initToolbar()
96 wxBitmap bmp_new(new_xpm);
97 wxBitmap bmp_open(open_xpm);
98 wxBitmap bmp_save(save_xpm);
99 wxBitmap bmp_run(run_xpm);
100 wxBitmap bmp_delete(delete_xpm);
101 wxBitmap bmp_centerview(centerview_xpm);
102 wxBitmap bmp_complexbox(complexbox_xpm);
103 wxBitmap bmp_complexinputport(complexinputport_xpm);
104 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
106 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
108 //Adds a tool btn to the toolbar
109 toolbar->AddTool(ID_NEW,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
110 toolbar->AddTool(ID_OPEN,_T("Open diagram"),bmp_open, wxNullBitmap, wxITEM_NORMAL,_T("Open a diagram"), _T("Open a diagram"));
111 toolbar->AddTool(ID_SAVE_AS_DIAGRAM,_T("Save diagram"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves actual diagram"), _T("Saves actual diagram"));
112 toolbar->AddTool(ID_RUN,_T("Run"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram"));
113 toolbar->AddTool(ID_DELETEALL,_T("Delete all"),bmp_delete, wxNullBitmap, wxITEM_NORMAL,_T("Delete all boxes"), _T("Delete all boxes"));
114 toolbar->AddTool(ID_CENTERVIEW,_T("Center view"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Center view"), _T("Center view"));
115 toolbar->AddSeparator();
116 toolbar->AddTool(ID_BTNCOMPLEXBOX,_T("Complex box"),complexbox_xpm, wxNullBitmap, wxITEM_NORMAL,_T("Complex box"), _T("Complex box"));
117 toolbar->SetToggle(ID_BTNCOMPLEXBOX,true);
118 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"));
119 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"));
120 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
121 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
123 toolbar->SetMargins( 2, 2 );
127 // connect command event handlers
128 Connect(ID_NEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
129 Connect(ID_OPEN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
130 Connect(ID_SAVE_AS_DIAGRAM,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
131 Connect(ID_RUN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
132 Connect(ID_DELETEALL,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
133 Connect(ID_CENTERVIEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
134 Connect(ID_BTNCOMPLEXBOX,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
135 Connect(ID_ADDCOMPLEXBOXINPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
136 Connect(ID_ADDCOMPLEXBOXOUTPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
139 //=========================================================================
140 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
142 //TO FIX THE PATH OF BBTK BIN IN ORDER TO USE REGENERATE EXECUTABLES
144 _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
145 _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));
148 //=========================================================================
149 void wxGUIEditorGraphicBBS::initMenu()
151 // Create File menu and its items
152 wxMenu *fileMenu = new wxMenu();
153 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
154 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save diagram"), _T("Save diagram"));
155 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
156 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"), _T("Save complex box"));
157 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
159 Connect(ID_NEW,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
160 Connect(ID_SAVE_AS_DIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
161 Connect(ID_SAVE_AS_BBS,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
162 Connect(ID_SAVE_AS_COMPLEXBOX,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
163 Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
165 // Create Help menu and its items
166 wxMenu *editMenu = new wxMenu;
167 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM, _T("Copy selected to complex box"), _T("Creates a new complex box diagram with selected boxes"));
169 Connect(ID_COPY_TO_COMPLEXDIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
171 // Create Help menu and its items
172 wxMenu *helpMenu = new wxMenu;
173 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
175 // Append the created menu to the menu bar
176 wxMenuBar *menuBar = new wxMenuBar();
177 menuBar->Append(fileMenu, _T("&File"));
178 menuBar->Append(editMenu, _T("&Edit"));
179 menuBar->Append(helpMenu, _T("&Help"));
181 // Attach this menu bar to the frame
185 //=========================================================================
186 void wxGUIEditorGraphicBBS::initTabPanelsManager()
188 _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);
189 _tabsMgr = new wxTabPanelsManager(this);
190 _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());
194 //=========================================================================
195 void wxGUIEditorGraphicBBS::initPackageBrowser()
197 _pkgBrowser = new WxGUIPackageBrowser2(this);
198 _pkgBrowser->IncludeAll();
199 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));
202 //================================================================
204 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
206 std::string mess("Regenerating doc for package '");
212 mess = "Regenerating doc for all packages";
215 mess += " ... please wait";
217 SetStatusText( std2wx(mess) );
225 command += ConfigurationFile::GetInstance().Get_bin_path();
226 command += ConfigurationFile::GetInstance().Get_file_separator();
227 command += "bbRegeneratePackageDoc";
232 command += " " + pack + " -q";
233 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
235 if ( ! system ( command.c_str() ) )
237 SetStatusText( _T("Done !"));
239 wxMessageBox(_T("Done !"),_T("Regenerate package '")
240 +std2wx(pack)+_T("' doc"),
241 wxOK | wxICON_INFORMATION);
246 SetStatusText( _T("Done !"));
247 wxString err(_T("An error occured while running '"));
248 err += bbtk::std2wx(command) + _T("'");
249 wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);
253 //================================================================
254 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
256 SetStatusText( _T("Regenerating boxes lists ... please wait") );
263 command += ConfigurationFile::GetInstance().Get_bin_path();
264 command += ConfigurationFile::GetInstance().Get_file_separator();
265 command += "bbRegenerateBoxesLists";
272 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
274 if ( ! system ( command.c_str() ) )
276 SetStatusText( _T("Done !"));
278 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
279 wxOK | wxICON_INFORMATION);
284 SetStatusText( _T("Done !"));
285 wxString err(_T("An error occured while running '"));
286 err += bbtk::std2wx(command) + _T("'");
287 wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);
291 //================================================================
292 void wxGUIEditorGraphicBBS::RegenerateAll()
294 DoRegeneratePackageDoc("-a");
295 DoRegenerateBoxesLists();
298 //================================================================
300 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
305 //================================================================
307 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
309 if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
311 _actualPkgBrowserPkgName = packageName;
312 _actualPkgBrowserBoxName = boxName;
314 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
315 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
319 //=========================================================================
321 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
323 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
327 //=========================================================================
329 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
331 SetStatusText(crea::std2wx(textStatus));
334 //=========================================================================
336 void wxGUIEditorGraphicBBS::executeScript(std::string script)
338 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
339 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
340 std::string filename = dir + separator + "tmp_bbtk.bbs";
343 tempFile.open(filename.c_str());
347 std::string command = "\"";
353 //command += ConfigurationFile::GetInstance().Get_bin_path();
354 //EED command +="C:/temp/bbtkBIN/RelWithDebInfo//";
355 //EED command +="C:/Program Files/CreaTools/bbtk-0.9.5/bin";
360 command += separator + "bbi.app/Contents/MacOS/bbi\" ";
362 command += separator + "bbi\" ";
364 command += "\""+filename + "\"";
372 printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
373 system( command.c_str() );
376 //=========================================================================
378 //=========================================================================
380 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
382 _tabsMgr->addNewTab();
383 refreshGUIControls();
386 //=========================================================================
388 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
390 std::string script = _tabsMgr->getActualDiagramBBS();
391 cout<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl;
394 executeScript(script);
397 //=========================================================================
399 //=========================================================================
401 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event)
403 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save actual BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxSAVE|wxOVERWRITE_PROMPT);
404 if (saveFileDialog->ShowModal() == wxID_OK)
406 wxString fileName = saveFileDialog->GetPath();
410 //EED file.open(fileName.c_str());
411 file.open( (const char*) (fileName.mb_str()) );
413 std::string content="";
415 // writing file header
416 content += "# ----------------------------------\n";
417 content += "# - BBTKGEditor v 1.0 BBS BlackBox Script\n";
418 content += "# ----------------------------------\n";
420 content += _tabsMgr->getActualDiagramBBS();
427 //=========================================================================
429 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event)
431 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of complex box"));
432 std::string cbName="";
433 if (nameDialog->ShowModal() == wxID_OK)
435 wxString fileName = nameDialog->GetValue();
436 //EED cbName=fileName;
437 cbName=(const char*) (fileName.mb_str());
442 wxFileDialog * saveFileDialog = new wxFileDialog(this ,wxT("Save Complex Box BBS") ,wxEmptyString, wxString( cbName.c_str(), wxConvUTF8),wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
443 if (saveFileDialog->ShowModal() == wxID_OK)
445 wxString fileName = saveFileDialog->GetPath();
448 //EED file.open(fileName.c_str());
449 file.open( (const char*) (fileName.mb_str()) );
451 std::string content="";
453 // writing file header
454 content += "# ----------------------------------\n";
455 content += "# - BBTKGEditor v 1.1 BBS BlackBox Script (Complex Box)\n";
456 content += "# ----------------------------------\n";
458 content += _tabsMgr->getActualComplexBoxBBS(cbName);
466 //=========================================================================
468 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
470 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save actual diagram"),wxEmptyString,wxT("NewDiagram"),wxT("*.bbg"),wxSAVE|wxOVERWRITE_PROMPT);
471 if (saveFileDialog->ShowModal() == wxID_OK)
473 wxString fileName = saveFileDialog->GetPath();
476 //EED file.open(fileName.c_str());
477 file.open( (const char*) (fileName.mb_str()) );
479 std::string content="";
481 // writing file header
482 content += "# ----------------------------------\n";
483 content += "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file\n";
486 //EED content += fileName;
487 content += (const char*) (fileName.mb_str());
490 content += "# ----------------------------------\n";
492 content += "APP_START\n";
493 _tabsMgr->saveActualDiagram(content);
494 content += "APP_END\n";
501 //=========================================================================
503 void wxGUIEditorGraphicBBS::refreshGUIControls()
505 wxToolBar* toolbar = GetToolBar();
506 if(_tabsMgr->isActualDiagramComplexBox())
508 toolbar->ToggleTool(ID_BTNCOMPLEXBOX,true);
509 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,true);
510 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,true);
512 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,true);
513 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,false);
517 toolbar->ToggleTool(ID_BTNCOMPLEXBOX,false);
518 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
519 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
521 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,false);
522 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,true);
525 if(_tabsMgr->getNumActualSelectedObjects()>0)
527 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
531 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
532 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
537 //=========================================================================
539 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
541 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);
542 if(dial->ShowModal() == wxID_YES)
544 _tabsMgr->deleteAllBoxesActualDiagram();
548 //=========================================================================
550 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
552 _tabsMgr->centerViewActualDiagram();
555 //=========================================================================
558 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
560 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open diagram"),wxEmptyString,wxT(""),wxT("*.bbg"),wxOPEN|wxFILE_MUST_EXIST);
561 if (openFileDialog->ShowModal() == wxID_OK)
563 wxString fileName = openFileDialog->GetPath();
565 ifstream inputStream;
567 //EED inputStream.open(fileName.c_str());
568 inputStream.open( (const char*) (fileName.mb_str()) );
572 _tabsMgr->addNewTab();
573 _tabsMgr->loadDiagram(inputStream);
577 refreshGUIControls();
580 //=========================================================================
582 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
584 wxToolBar* toolbar = GetToolBar();
585 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
588 _tabsMgr->setActualDiagramComplexBox(true);
592 _tabsMgr->setActualDiagramComplexBox(false);
594 refreshGUIControls();
597 //=========================================================================
599 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
601 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of input port"));
602 if (nameDialog->ShowModal() == wxID_OK)
604 wxString fileName = nameDialog->GetValue();
605 if(!fileName.IsEmpty())
607 std::string portName=(const char*) (fileName.mb_str());
608 _tabsMgr->addActualDiagramComplexInputPort(portName);
613 //=========================================================================
615 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
617 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of output port"));
618 if (nameDialog->ShowModal() == wxID_OK)
620 wxString fileName = nameDialog->GetValue();
621 if(!fileName.IsEmpty())
623 std::string portName=(const char*) (fileName.mb_str());
624 _tabsMgr->addActualDiagramComplexOutputPort(portName);
629 //=========================================================================
631 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(wxCommandEvent& event)
633 _tabsMgr->copySelectedBBoxesToComplexDiagram();
636 //=========================================================================
638 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
643 //=========================================================================
645 } // EO namespace bbtk