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="";
79 //=========================================================================
80 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS()
82 _frameAUIMgr->UnInit();
85 //=========================================================================
86 void wxGUIEditorGraphicBBS::initToolbar()
88 wxBitmap bmp_new(new_xpm);
89 wxBitmap bmp_open(open_xpm);
90 wxBitmap bmp_save(save_xpm);
91 wxBitmap bmp_run(run_xpm);
92 wxBitmap bmp_delete(delete_xpm);
93 wxBitmap bmp_centerview(centerview_xpm);
94 wxBitmap bmp_complexbox(complexbox_xpm);
95 wxBitmap bmp_complexinputport(complexinputport_xpm);
96 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
98 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
100 //Adds a tool btn to the toolbar
101 toolbar->AddTool(ID_NEW,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
102 toolbar->AddTool(ID_OPEN,_T("Open diagram"),bmp_open, wxNullBitmap, wxITEM_NORMAL,_T("Open a diagram"), _T("Open a diagram"));
103 toolbar->AddTool(ID_SAVE,_T("Save diagram"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves actual diagram"), _T("Saves actual diagram"));
104 toolbar->AddTool(ID_RUN,_T("Run"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram"));
105 toolbar->AddTool(ID_DELETEALL,_T("Delete all"),bmp_delete, wxNullBitmap, wxITEM_NORMAL,_T("Delete all boxes"), _T("Delete all boxes"));
106 toolbar->AddTool(ID_CENTERVIEW,_T("Center view"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Center view"), _T("Center view"));
107 toolbar->AddSeparator();
108 toolbar->AddTool(ID_BTNCOMPLEXBOX,_T("Complex box"),complexbox_xpm, wxNullBitmap, wxITEM_NORMAL,_T("Complex box"), _T("Complex box"));
109 toolbar->SetToggle(ID_BTNCOMPLEXBOX,true);
110 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"));
111 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"));
112 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
113 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
115 toolbar->SetMargins( 2, 2 );
119 // connect command event handlers
120 Connect(ID_NEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
121 Connect(ID_OPEN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
122 Connect(ID_SAVE,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
123 Connect(ID_RUN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
124 Connect(ID_DELETEALL,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
125 Connect(ID_CENTERVIEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
126 Connect(ID_BTNCOMPLEXBOX,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
127 Connect(ID_ADDCOMPLEXBOXINPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
128 Connect(ID_ADDCOMPLEXBOXOUTPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
131 //=========================================================================
132 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
134 //TO FIX THE PATH OF BBTK BIN IN ORDER TO USE REGENERATE EXECUTABLES
136 _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
137 _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));
140 //=========================================================================
141 void wxGUIEditorGraphicBBS::initMenu()
144 wxMenu *fileMenu = new wxMenu;
146 // the "About" item should be in the help menu
147 wxMenu *helpMenu = new wxMenu;
148 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
149 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
151 Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
153 // now append the freshly created menu to the menu bar...
154 wxMenuBar *menuBar = new wxMenuBar();
155 menuBar->Append(fileMenu, _T("&File"));
156 menuBar->Append(helpMenu, _T("&Help"));
158 // attach this menu bar to the frame
162 //=========================================================================
163 void wxGUIEditorGraphicBBS::initTabPanelsManager()
165 _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);
166 _tabsMgr = new wxTabPanelsManager(this);
167 _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());
171 //=========================================================================
172 void wxGUIEditorGraphicBBS::initPackageBrowser()
174 _pkgBrowser = new WxGUIPackageBrowser2(this);
175 _pkgBrowser->IncludeAll();
176 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));
179 //================================================================
181 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
183 std::string mess("Regenerating doc for package '");
189 mess = "Regenerating doc for all packages";
192 mess += " ... please wait";
194 SetStatusText( std2wx(mess) );
202 command += ConfigurationFile::GetInstance().Get_bin_path();
203 command += ConfigurationFile::GetInstance().Get_file_separator();
204 command += "bbRegeneratePackageDoc";
209 command += " " + pack + " -q";
210 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
212 if ( ! system ( command.c_str() ) )
214 SetStatusText( _T("Done !"));
216 wxMessageBox(_T("Done !"),_T("Regenerate package '")
217 +std2wx(pack)+_T("' doc"),
218 wxOK | wxICON_INFORMATION);
223 SetStatusText( _T("Done !"));
224 wxString err(_T("An error occured while running '"));
225 err += bbtk::std2wx(command) + _T("'");
226 wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);
230 //================================================================
231 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
233 SetStatusText( _T("Regenerating boxes lists ... please wait") );
240 command += ConfigurationFile::GetInstance().Get_bin_path();
241 command += ConfigurationFile::GetInstance().Get_file_separator();
242 command += "bbRegenerateBoxesLists";
249 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
251 if ( ! system ( command.c_str() ) )
253 SetStatusText( _T("Done !"));
255 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
256 wxOK | wxICON_INFORMATION);
261 SetStatusText( _T("Done !"));
262 wxString err(_T("An error occured while running '"));
263 err += bbtk::std2wx(command) + _T("'");
264 wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);
268 //================================================================
269 void wxGUIEditorGraphicBBS::RegenerateAll()
271 DoRegeneratePackageDoc("-a");
272 DoRegenerateBoxesLists();
275 //================================================================
277 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
282 //================================================================
284 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
286 if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
288 _actualPkgBrowserPkgName = packageName;
289 _actualPkgBrowserBoxName = boxName;
291 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
292 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
296 //=========================================================================
298 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
300 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
304 //=========================================================================
306 void wxGUIEditorGraphicBBS::editDiagramParameters(wxVtkSceneManager* scene)
308 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,scene);
312 //=========================================================================
314 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
316 SetStatusText(crea::std2wx(textStatus));
319 //=========================================================================
321 void wxGUIEditorGraphicBBS::executeScript(std::string script)
323 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
324 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
325 std::string filename = dir + separator + "tmp_bbtk.bbs";
328 tempFile.open(filename.c_str());
332 std::string command = "\"";
338 //command += ConfigurationFile::GetInstance().Get_bin_path();
339 command +="C:/temp/bbtkBIN/RelWithDebInfo//";
342 command += separator + "bbi.app/Contents/MacOS/bbi\" ";
344 command += separator + "bbi\" ";
346 command += "\""+filename + "\"";
354 printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
355 system( command.c_str() );
358 //=========================================================================
360 //=========================================================================
362 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
364 _tabsMgr->addNewTab();
368 //=========================================================================
370 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
372 std::string script = _tabsMgr->getActualDiagramScript();
373 cout<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl;
376 executeScript(script);
379 //=========================================================================
381 /*****************************************************/
383 /*****************************************************/
384 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
386 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save actual diagram"),wxEmptyString,"NewDiagram","*.bbd",wxSAVE|wxOVERWRITE_PROMPT);
387 if (saveFileDialog->ShowModal() == wxID_OK)
389 wxString fileName = saveFileDialog->GetPath();
392 file.open(fileName.c_str());
394 std::string content="";
396 // writing file header
397 content += "# ----------------------------------\n";
398 content += "# - BBTKGEditor v 1.0 BBD BlackBox Diagram file\n";
402 content += "# ----------------------------------\n";
404 content += "APP_START\n";
405 _tabsMgr->saveActualDiagram(content);
406 content += "APP_END\n";
413 //=========================================================================
415 void wxGUIEditorGraphicBBS::refreshToolbar()
417 wxToolBar* toolbar = GetToolBar();
418 if(_tabsMgr->isActualDiagramComplexBox())
420 toolbar->ToggleTool(ID_BTNCOMPLEXBOX,true);
424 toolbar->ToggleTool(ID_BTNCOMPLEXBOX,false);
427 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
430 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,true);
431 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,true);
435 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
436 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
440 //=========================================================================
442 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
444 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);
445 if(dial->ShowModal() == wxID_YES)
447 _tabsMgr->deleteAllBoxesActualDiagram();
451 //=========================================================================
453 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
455 _tabsMgr->centerViewActualDiagram();
458 //=========================================================================
461 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
463 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open diagram"),wxEmptyString,"","*.bbd",wxOPEN|wxFILE_MUST_EXIST);
464 if (openFileDialog->ShowModal() == wxID_OK)
466 wxString fileName = openFileDialog->GetPath();
468 ifstream inputStream;
469 inputStream.open(fileName.c_str());
471 _tabsMgr->addNewTab();
472 _tabsMgr->loadDiagram(inputStream);
480 //=========================================================================
482 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
484 wxToolBar* toolbar = GetToolBar();
485 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
488 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,true);
489 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,true);
490 _tabsMgr->setActualDiagramComplexBox(true);
494 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
495 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
496 _tabsMgr->setActualDiagramComplexBox(false);
501 //=========================================================================
503 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
505 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of input port"));
506 if (nameDialog->ShowModal() == wxID_OK)
508 wxString fileName = nameDialog->GetValue();
509 if(!fileName.IsEmpty())
511 std::string portName=fileName;
512 _tabsMgr->addActualDiagramComplexInputPort(portName);
517 //=========================================================================
519 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
521 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of output port"));
522 if (nameDialog->ShowModal() == wxID_OK)
524 wxString fileName = nameDialog->GetValue();
525 if(!fileName.IsEmpty())
527 std::string portName=fileName;
528 _tabsMgr->addActualDiagramComplexOutputPort(portName);
533 //=========================================================================
535 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
540 //=========================================================================
542 } // EO namespace bbtk