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"
38 #include "creaSystem.h"
40 #include <InterpreterBBS.h>
46 //=========================================================================
47 wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent)
48 : wxFrame(parent, -1, _T("bbtkGEditor"),wxDefaultPosition, wxSize(1200,800))
51 _frameAUIMgr = new wxAuiManager(this);
54 /*std::string datadir( crea::System::GetExecutablePath() );
55 std::string datadir (".");
56 cout<<"RaC //------------------"<<endl;
57 cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with crea::System::GetExecutablePath() ."<<endl;
58 cout<<"RaC //------------------"<<endl;
60 #ifdef LINUX // assume this is OSX
61 datadir=datadir+"/../share/creaContours";
64 #ifdef MACOSX // assume this is OSX
65 datadir=datadir+"/../../../../share/creaContours";
72 initTabPanelsManager();
74 initHelpHTMLBrowser();
77 _frameAUIMgr->Update();
78 _actualPkgBrowserBoxName="";
79 _actualPkgBrowserPkgName="";
84 //=========================================================================
85 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS()
87 printf ("EED %p ~wxGUIEditorGraphicBBS()\n" , this );
89 //EED02JUIN2010 delete _tabsMgr;
91 _frameAUIMgr->UnInit();
100 //=========================================================================
101 void wxGUIEditorGraphicBBS::initToolbar()
103 wxBitmap bmp_new(new_xpm);
104 wxBitmap bmp_open(open_xpm);
105 wxBitmap bmp_save(save_xpm);
106 wxBitmap bmp_run(run_xpm);
107 wxBitmap bmp_delete(delete_xpm);
108 wxBitmap bmp_centerview(centerview_xpm);
109 wxBitmap bmp_box(box_xpm);
110 wxBitmap bmp_executablebox(executablebox_xpm);
111 wxBitmap bmp_complexbox(complexbox_xpm);
112 wxBitmap bmp_complexinputport(complexinputport_xpm);
113 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
115 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
117 //Adds a tool btn to the toolbar
118 toolbar->AddTool(ID_NEW,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
119 toolbar->AddTool(ID_OPEN,_T("Open diagram"),bmp_open, wxNullBitmap, wxITEM_NORMAL,_T("Open a diagram"), _T("Open a diagram"));
120 toolbar->AddTool(ID_SAVE_DIAGRAM,_T("Save Diagram"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves the current diagram"), _T("Saves the current diagram")); //DFCH
121 //toolbar->AddTool(ID_SAVE_AS_DIAGRAM,_T("Save Diagram As"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves the current diagram"), _T("Saves the current diagram")); //DFCH
122 toolbar->AddTool(ID_RUN,_T("Run"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram"));
123 toolbar->AddTool(ID_DELETEALL,_T("Delete all"),bmp_delete, wxNullBitmap, wxITEM_NORMAL,_T("Delete all boxes"), _T("Delete all boxes"));
124 toolbar->AddTool(ID_CENTERVIEW,_T("Center view"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Center view"), _T("Center view"));
125 toolbar->AddSeparator();
126 toolbar->AddTool(ID_BTNBOX,_T("New Box"),bmp_box, wxNullBitmap, wxITEM_NORMAL,_T("New Box"), _T("Nex Box"));
127 toolbar->AddSeparator();
128 toolbar->AddTool(ID_BTEXECUTABLEBOX,_T("Select as executable Box"),bmp_executablebox, wxNullBitmap, wxITEM_NORMAL,_T("Select as executable Box"), _T("Select as executable Box"));
129 toolbar->AddSeparator();
130 toolbar->AddTool(ID_BTNCOMPLEXBOX,_T("Complex box"),complexbox_xpm, wxNullBitmap, wxITEM_NORMAL,_T("Complex box"), _T("Complex box"));
131 toolbar->SetToggle(ID_BTNCOMPLEXBOX,true);
132 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"));
133 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"));
134 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
135 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
137 toolbar->SetMargins( 2, 2 );
141 // connect command event handlers
142 Connect(ID_NEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
143 Connect(ID_OPEN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
144 Connect(ID_SAVE_DIAGRAM,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
145 Connect(ID_SAVE_AS_DIAGRAM,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
146 Connect(ID_RUN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
147 Connect(ID_DELETEALL,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
148 Connect(ID_CENTERVIEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
149 Connect(ID_BTNBOX,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
150 Connect(ID_BTEXECUTABLEBOX,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
151 Connect(ID_BTNCOMPLEXBOX,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
152 Connect(ID_ADDCOMPLEXBOXINPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
153 Connect(ID_ADDCOMPLEXBOXOUTPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
156 //=========================================================================
157 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
159 //TO FIX THE PATH OF BBTK BIN IN ORDER TO USE REGENERATE EXECUTABLES
161 _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
162 _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));
165 //=========================================================================
166 void wxGUIEditorGraphicBBS::initMenu()
168 // Create File menu and its items
169 wxMenu *fileMenu = new wxMenu();
170 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
171 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
172 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"), _T("Save Diagram As")); //DFCH
173 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
174 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
175 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"), _T("Save complex box"));
176 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
178 Connect(ID_NEW,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
179 Connect(ID_SAVE_DIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
180 Connect(ID_SAVE_AS_DIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
181 Connect(ID_OPEN_BBS,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
182 Connect(ID_SAVE_AS_BBS,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
183 Connect(ID_SAVE_AS_COMPLEXBOX,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
184 Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
186 // Create Help menu and its items
187 wxMenu *editMenu = new wxMenu;
188 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM, _T("Copy selected to complex box"), _T("Creates a new complex box diagram with selected boxes"));
190 Connect(ID_COPY_TO_COMPLEXDIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
192 // Create Help menu and its items
193 wxMenu *helpMenu = new wxMenu;
194 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
195 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
196 Connect(ID_HELP_BBEDITOR,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
199 wxMenu *menuTools = new wxMenu;
200 menuTools->Append( ID_bbEditor_Tool_Menu_CreatePackage, _T("Create &package") );
201 menuTools->Append( ID_bbEditor_Tool_Menu_CreateBlackBox, _T("Create &blackbox") );
202 menuTools->Append( ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
203 menuTools->Append( ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
204 menuTools->Append( ID_bbEditor_Tool_Menu_ShowHTMLDoc, _T("Show &HTML documentation") );
205 menuTools->Append( ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
207 Connect(ID_bbEditor_Tool_Menu_CreatePackage,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
208 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
209 Connect(ID_bbEditor_Tool_Menu_PlugPackage,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
210 Connect(ID_bbEditor_Tool_Menu_EditConfig,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
211 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
212 Connect(ID_bbEditor_Tool_Menu_CreateIndex,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
214 // Append the created menu to the menu bar
215 wxMenuBar *menuBar = new wxMenuBar();
216 menuBar->Append( fileMenu, _T("&File") );
217 menuBar->Append( editMenu, _T("&Edit") );
218 menuBar->Append( menuTools, _T("&Tool") );
219 menuBar->Append( helpMenu, _T("&Help") );
221 // Attach this menu bar to the frame
225 //=========================================================================
226 void wxGUIEditorGraphicBBS::initTabPanelsManager()
228 _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);
229 _tabsMgr = new wxTabPanelsManager(this);
230 _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());
234 //=========================================================================
235 void wxGUIEditorGraphicBBS::initPackageBrowser()
237 _pkgBrowser = new WxGUIPackageBrowser2(this);
238 _pkgBrowser->IncludeAll();
239 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));
242 //================================================================
244 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
246 std::string mess("Regenerating doc for package '");
252 mess = "Regenerating doc for all packages";
255 mess += " ... please wait";
257 SetStatusText( std2wx(mess) );
265 command += ConfigurationFile::GetInstance().Get_bin_path();
266 command += ConfigurationFile::GetInstance().Get_file_separator();
267 command += "bbRegeneratePackageDoc";
272 command += " " + pack + " -q";
273 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
275 if ( ! system ( command.c_str() ) )
277 SetStatusText( _T("Done !"));
279 wxMessageBox(_T("Done !"),_T("Regenerate package '")
280 +std2wx(pack)+_T("' doc"),
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 package doc"),wxOK | wxICON_ERROR);
293 //================================================================
294 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
296 SetStatusText( _T("Regenerating boxes lists ... please wait") );
303 command += ConfigurationFile::GetInstance().Get_bin_path();
304 command += ConfigurationFile::GetInstance().Get_file_separator();
305 command += "bbRegenerateBoxesLists";
312 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
314 if ( ! system ( command.c_str() ) )
316 SetStatusText( _T("Done !"));
318 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
319 wxOK | wxICON_INFORMATION);
324 SetStatusText( _T("Done !"));
325 wxString err(_T("An error occured while running '"));
326 err += bbtk::std2wx(command) + _T("'");
327 wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);
331 //================================================================
332 void wxGUIEditorGraphicBBS::RegenerateAll()
334 DoRegeneratePackageDoc("-a");
335 DoRegenerateBoxesLists();
338 //================================================================
340 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
345 //================================================================
347 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
349 if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
351 _actualPkgBrowserPkgName = packageName;
352 _actualPkgBrowserBoxName = boxName;
354 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
355 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
359 //=========================================================================
361 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
363 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
367 //=========================================================================
369 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
371 SetStatusText(crea::std2wx(textStatus));
374 //=========================================================================
376 void wxGUIEditorGraphicBBS::executeScript(std::string script)
378 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
379 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
380 std::string filename = dir + separator + "tmp_bbtk.bbs";
383 tempFile.open(filename.c_str());
387 std::string command = "";
390 command += "start /b ";
394 // command += "\""+ crea::System::GetExecutablePath();
396 // command += separator + "../../../bbi.app/Contents/MacOS";
402 //command += ConfigurationFile::GetInstance().Get_bin_path();
403 //EED command +="C:/temp/bbtkBIN/RelWithDebInfo//";
404 //EED command +="C:/Program Files/CreaTools/bbtk-0.9.5/bin";
408 command += separator + "usr/local/bin/bbi.app/Contents/MacOS/bbi\" ";
411 command += separator + "bbi\" ";
416 // command += separator;
421 command += "\""+filename + "\"";
431 printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
432 system( command.c_str() );
435 //=========================================================================
437 //=========================================================================
439 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
441 _tabsMgr->addNewTab();
442 refreshGUIControls();
445 //=========================================================================
447 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
449 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
450 cout<<endl<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl<<endl;
453 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
454 executeScript(script2);
458 //=========================================================================
460 //=========================================================================
461 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event)
463 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxOPEN);
464 if (openFileDialog->ShowModal() == wxID_OK)
466 wxString fileName = openFileDialog->GetPath( );
469 _tabsMgr->addNewTab( openFileDialog->GetFilename() );
471 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager() , _pkgBrowser->GetFactory());
473 // We tell the interpreter to throw exceptions on error
475 // Interpret the file supposed to define a box called 'Processing'
476 I->InterpretFile( (const char*) (fileName.mb_str()) );
478 refreshGUIControls();
483 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename)
487 //EED file.open(fileName.c_str());
488 file.open( filename.c_str() );
489 std::string content="";
490 // writing file header
491 content += "# ----------------------------------\n";
492 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script\n";
496 content += "# ----------------------------------\n";
498 content += _tabsMgr->getActualDiagramBBS();
504 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event)
506 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save actual BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxSAVE|wxOVERWRITE_PROMPT);
507 if (saveFileDialog->ShowModal() == wxID_OK)
509 wxString fileName = saveFileDialog->GetPath( );
510 SaveActualBBS( (const char*) (fileName.mb_str()) );
516 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration()
518 std::string cbName = _tabsMgr->GetCbName();
519 std::string paName = _tabsMgr->GetCbPackageName();
521 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,wxT("Complex Box name"));
522 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,wxT("Package name"));
524 cbNameDialog->SetValue( wxString(cbName.c_str(),wxConvUTF8) );
525 paNameDialog->SetValue( wxString(paName.c_str(),wxConvUTF8) );
527 if (cbNameDialog->ShowModal() == wxID_OK)
529 wxString complexboxname = cbNameDialog->GetValue();
530 cbName=(const char*) (complexboxname.mb_str());
534 if (paNameDialog->ShowModal() == wxID_OK)
536 wxString packagename = paNameDialog->GetValue();
537 paName=(const char*) (packagename.mb_str());
540 _tabsMgr->SetCbName(cbName);
541 _tabsMgr->SetCbPackageName(paName);
544 //=========================================================================
546 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename)
549 file.open( filename.c_str() );
551 std::string content="";
553 // writing file header
554 content += "# ----------------------------------\n";
555 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script (Complex Box)\n";
559 content += "# ----------------------------------\n";
561 content += _tabsMgr->getActualComplexBoxBBS();
566 //=========================================================================
568 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event)
570 wxFileDialog * saveFileDialog = new wxFileDialog(this ,wxT("Save Complex Box BBS") ,wxEmptyString, _T("ComplexBoxName") ,wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
571 if (saveFileDialog->ShowModal() == wxID_OK)
573 wxString fileName = saveFileDialog->GetPath();
574 SaveActualComplexBox( (const char*) (fileName.mb_str()) );
578 //=========================================================================
579 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename)
582 file.open( filename.c_str() );
584 std::string content="";
586 // writing file header
587 content += "# ----------------------------------\n";
588 content += "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file\n";
594 content += "# ----------------------------------\n";
596 content += "APP_START\n";
597 _tabsMgr->saveActualDiagram(content, filename); //DFCH
598 content += "APP_END\n";
603 //=========================================================================
605 //The following method allows to save the current diagram asking the filename
607 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs( )
609 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save current diagram"),wxEmptyString,wxT("NewDiagram"),wxT("*.bbg"),wxSAVE|wxOVERWRITE_PROMPT);
610 if (saveFileDialog->ShowModal() == wxID_OK)
612 _tabsMgr->SetNameTabPanel( saveFileDialog->GetFilename() );
613 wxString pathfileName = saveFileDialog->GetPath();
614 std::string pathfilename = (const char*) (pathfileName.mb_str());
615 std::string pathfilenamebbs = pathfilename;
616 pathfilenamebbs[pathfilenamebbs.length()-1]='s';
617 if (_tabsMgr->isActualDiagramComplexBox()==false)
619 SaveActualDiagram( pathfilename );
620 SaveActualBBS(pathfilenamebbs);
622 AskComplexBoxConfiguration();
623 SaveActualDiagram( pathfilename );
624 SaveActualComplexBox(pathfilenamebbs);
625 } //if isActualDiagramComplexBox
626 } // if saveFileDialog
628 //=========================================================================
630 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
632 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
633 if( pathfilename.empty() )
635 SaveCurrentDiagramAs();
639 std::string pathfilenamebbs = pathfilename;
640 pathfilenamebbs[pathfilenamebbs.length()-1]='s';
642 if (_tabsMgr->isActualDiagramComplexBox()==false)
644 SaveActualDiagram( pathfilename );
645 SaveActualBBS(pathfilenamebbs);
647 AskComplexBoxConfiguration();
648 SaveActualDiagram( pathfilename );
649 SaveActualComplexBox(pathfilenamebbs);
650 } //if isActualDiagramComplexBox
653 //=========================================================================
655 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event)
657 SaveCurrentDiagramAs();
659 //=========================================================================
661 void wxGUIEditorGraphicBBS::refreshGUIControls()
663 wxToolBar* toolbar = GetToolBar();
664 if(_tabsMgr->isActualDiagramComplexBox())
666 toolbar->ToggleTool(ID_BTNCOMPLEXBOX,true);
667 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,true);
668 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,true);
670 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,true);
671 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,false);
675 toolbar->ToggleTool(ID_BTNCOMPLEXBOX,false);
676 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
677 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
679 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,false);
680 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,true);
683 if(_tabsMgr->getNumActualSelectedObjects()>0)
685 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
689 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
690 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
695 //=========================================================================
697 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
699 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);
700 if(dial->ShowModal() == wxID_YES)
702 _tabsMgr->deleteAllBoxesActualDiagram();
706 //=========================================================================
708 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
710 _tabsMgr->centerViewActualDiagram();
713 //=========================================================================
715 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
717 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open diagram"),wxEmptyString,wxT(""),wxT("*.bbg"),wxOPEN|wxFILE_MUST_EXIST);
718 if (openFileDialog->ShowModal() == wxID_OK)
720 wxString fileName = openFileDialog->GetPath();
721 ifstream inputStream;
722 std::string fName=(const char*) (fileName.mb_str());
723 inputStream.open( fName.c_str() );
724 _tabsMgr->addNewTab( openFileDialog->GetFilename() );
726 _tabsMgr->loadDiagram(inputStream, fName);
730 refreshGUIControls();
733 //=========================================================================
736 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event)
738 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
741 std::string typeName = bbDes->GetTypeName();
742 std::string packageName = bbDes->GetPackage()->GetName();
745 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
749 wxVtkSceneManager *scn = pnl->getSceneManager();
750 scn->createGBlackBox(50,50,packageName, typeName);
756 //=========================================================================
758 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event)
760 printf("EED wxGUIEditorGraphicBBS::OnClickBtnExecutableBox .... not implemented ...\n");
763 //=========================================================================
765 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
767 wxToolBar* toolbar = GetToolBar();
768 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
771 _tabsMgr->setActualDiagramComplexBox(true);
775 _tabsMgr->setActualDiagramComplexBox(false);
777 refreshGUIControls();
780 //=========================================================================
782 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
784 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of input port"));
785 if (nameDialog->ShowModal() == wxID_OK)
787 wxString fileName = nameDialog->GetValue();
788 if(!fileName.IsEmpty())
790 std::string portName=(const char*) (fileName.mb_str());
791 _tabsMgr->addActualDiagramComplexInputPort(portName);
796 //=========================================================================
798 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
800 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of output port"));
801 if (nameDialog->ShowModal() == wxID_OK)
803 wxString fileName = nameDialog->GetValue();
804 if(!fileName.IsEmpty())
806 std::string portName=(const char*) (fileName.mb_str());
807 _tabsMgr->addActualDiagramComplexOutputPort(portName);
812 //=========================================================================
814 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(wxCommandEvent& event)
816 _tabsMgr->copySelectedBBoxesToComplexDiagram();
820 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event)
822 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
826 //=========================================================================
827 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event)
829 printf("EED wxGUIEditorGraphicBBS::OnCreatePackag ... not implemented ..\n");
833 //=========================================================================
834 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event)
836 printf("EED wxGUIEditorGraphicBBS::OnCreateBlackBox ... not implemented ..\n");
838 //=========================================================================
839 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event)
841 printf("EED wxGUIEditorGraphicBBS::OnPlugPackage ... not implemented ..\n");
843 //=========================================================================
844 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event)
846 printf("EED wxGUIEditorGraphicBBS::OnEditConfig ... not implemented ..\n");
848 //=========================================================================
849 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event)
851 printf("EED wxGUIEditorGraphicBBS::OnShowHTMLDoc ... not implemented ..\n");
853 //=========================================================================
854 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event)
856 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
862 //=========================================================================
864 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
871 //=========================================================================
873 } // EO namespace bbtk