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);
96 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
98 //Adds a tool btn to the toolbar
99 toolbar->AddTool(ID_NEW,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
100 toolbar->AddTool(ID_OPEN,_T("Open diagram"),bmp_open, wxNullBitmap, wxITEM_NORMAL,_T("Open a diagram"), _T("Open a diagram"));
101 toolbar->AddTool(ID_SAVE,_T("Save diagram"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves actual diagram"), _T("Saves actual diagram"));
102 toolbar->AddTool(ID_RUN,_T("Run"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram"));
103 toolbar->AddTool(ID_DELETEALL,_T("Delete all"),bmp_delete, wxNullBitmap, wxITEM_NORMAL,_T("Delete all boxes"), _T("Delete all boxes"));
104 toolbar->AddTool(ID_CENTERVIEW,_T("Center view"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Center view"), _T("Center view"));
105 toolbar->AddSeparator();
106 toolbar->AddTool(ID_BTNCOMPLEXBOX,_T("Complex box"),complexbox_xpm, wxNullBitmap, wxITEM_NORMAL,_T("Complex box"), _T("Complex box"));
107 toolbar->SetToggle(ID_BTNCOMPLEXBOX,true);
108 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT,_T("Add input to Complex box"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Add input to Complex box"), _T("Add input to Complex box"));
109 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT,_T("Add output to Complex box"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Add output Complex box"), _T("Add output Complex box"));
110 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
111 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
113 toolbar->SetMargins( 2, 2 );
117 // connect command event handlers
118 Connect(ID_NEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
119 Connect(ID_OPEN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
120 Connect(ID_SAVE,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
121 Connect(ID_RUN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
122 Connect(ID_DELETEALL,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
123 Connect(ID_CENTERVIEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
124 Connect(ID_BTNCOMPLEXBOX,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
125 Connect(ID_ADDCOMPLEXBOXINPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
126 Connect(ID_ADDCOMPLEXBOXOUTPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
129 //=========================================================================
130 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
132 //TO FIX THE PATH OF BBTK BIN IN ORDER TO USE REGENERATE EXECUTABLES
134 _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
135 _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));
138 //=========================================================================
139 void wxGUIEditorGraphicBBS::initMenu()
142 wxMenu *fileMenu = new wxMenu;
144 // the "About" item should be in the help menu
145 wxMenu *helpMenu = new wxMenu;
146 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
147 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
149 Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
151 // now append the freshly created menu to the menu bar...
152 wxMenuBar *menuBar = new wxMenuBar();
153 menuBar->Append(fileMenu, _T("&File"));
154 menuBar->Append(helpMenu, _T("&Help"));
156 // attach this menu bar to the frame
160 //=========================================================================
161 void wxGUIEditorGraphicBBS::initTabPanelsManager()
163 _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);
164 _tabsMgr = new wxTabPanelsManager(this);
165 _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());
169 //=========================================================================
170 void wxGUIEditorGraphicBBS::initPackageBrowser()
172 _pkgBrowser = new WxGUIPackageBrowser2(this);
173 _pkgBrowser->IncludeAll();
174 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));
177 //================================================================
179 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
181 std::string mess("Regenerating doc for package '");
187 mess = "Regenerating doc for all packages";
190 mess += " ... please wait";
192 SetStatusText( std2wx(mess) );
200 command += ConfigurationFile::GetInstance().Get_bin_path();
201 command += ConfigurationFile::GetInstance().Get_file_separator();
202 command += "bbRegeneratePackageDoc";
207 command += " " + pack + " -q";
208 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
210 if ( ! system ( command.c_str() ) )
212 SetStatusText( _T("Done !"));
214 wxMessageBox(_T("Done !"),_T("Regenerate package '")
215 +std2wx(pack)+_T("' doc"),
216 wxOK | wxICON_INFORMATION);
221 SetStatusText( _T("Done !"));
222 wxString err(_T("An error occured while running '"));
223 err += bbtk::std2wx(command) + _T("'");
224 wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);
228 //================================================================
229 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
231 SetStatusText( _T("Regenerating boxes lists ... please wait") );
238 command += ConfigurationFile::GetInstance().Get_bin_path();
239 command += ConfigurationFile::GetInstance().Get_file_separator();
240 command += "bbRegenerateBoxesLists";
247 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
249 if ( ! system ( command.c_str() ) )
251 SetStatusText( _T("Done !"));
253 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
254 wxOK | wxICON_INFORMATION);
259 SetStatusText( _T("Done !"));
260 wxString err(_T("An error occured while running '"));
261 err += bbtk::std2wx(command) + _T("'");
262 wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);
266 //================================================================
267 void wxGUIEditorGraphicBBS::RegenerateAll()
269 DoRegeneratePackageDoc("-a");
270 DoRegenerateBoxesLists();
273 //================================================================
275 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
280 //================================================================
282 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
284 if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
286 _actualPkgBrowserPkgName = packageName;
287 _actualPkgBrowserBoxName = boxName;
289 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
290 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
294 //=========================================================================
296 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
298 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
302 //=========================================================================
304 void wxGUIEditorGraphicBBS::editDiagramParameters(wxVtkSceneManager* scene)
306 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,scene);
310 //=========================================================================
312 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
314 SetStatusText(crea::std2wx(textStatus));
317 //=========================================================================
319 void wxGUIEditorGraphicBBS::executeScript(std::string script)
321 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
322 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
323 std::string filename = dir + separator + "tmp_bbtk.bbs";
326 tempFile.open(filename.c_str());
330 std::string command = "\"";
336 //command += ConfigurationFile::GetInstance().Get_bin_path();
337 command +="C:/temp/bbtkBIN/RelWithDebInfo//";
340 command += separator + "bbi.app/Contents/MacOS/bbi\" ";
342 command += separator + "bbi\" ";
344 command += "\""+filename + "\"";
352 printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
353 system( command.c_str() );
356 //=========================================================================
358 //=========================================================================
360 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
362 _tabsMgr->addNewTab();
366 //=========================================================================
368 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
370 std::string script = _tabsMgr->getActualDiagramScript();
371 cout<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl;
374 executeScript(script);
377 //=========================================================================
379 /*****************************************************/
381 /*****************************************************/
382 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
384 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save actual diagram"),wxEmptyString,"NewDiagram","*.bbd",wxSAVE|wxOVERWRITE_PROMPT);
385 if (saveFileDialog->ShowModal() == wxID_OK)
387 wxString fileName = saveFileDialog->GetPath();
390 file.open(fileName.c_str());
392 std::string content="";
394 // writing file header
395 content += "# ----------------------------------\n";
396 content += "# - BBTKGEditor v 1.0 BBD BlackBox Diagram file\n";
400 content += "# ----------------------------------\n";
402 content += "APP_START\n";
403 _tabsMgr->saveActualDiagram(content);
404 content += "APP_END\n";
411 //=========================================================================
413 void wxGUIEditorGraphicBBS::refreshToolbar()
415 wxToolBar* toolbar = GetToolBar();
416 if(_tabsMgr->isActualDiagramComplexBox())
418 toolbar->ToggleTool(ID_BTNCOMPLEXBOX,true);
422 toolbar->ToggleTool(ID_BTNCOMPLEXBOX,false);
425 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
428 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,true);
429 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,true);
433 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
434 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
438 //=========================================================================
440 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
442 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);
443 if(dial->ShowModal() == wxID_YES)
445 _tabsMgr->deleteAllBoxesActualDiagram();
449 //=========================================================================
451 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
453 _tabsMgr->centerViewActualDiagram();
456 //=========================================================================
459 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
461 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open diagram"),wxEmptyString,"","*.bbd",wxOPEN|wxFILE_MUST_EXIST);
462 if (openFileDialog->ShowModal() == wxID_OK)
464 wxString fileName = openFileDialog->GetPath();
466 ifstream inputStream;
467 inputStream.open(fileName.c_str());
469 _tabsMgr->addNewTab();
470 _tabsMgr->loadDiagram(inputStream);
478 //=========================================================================
480 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
482 wxToolBar* toolbar = GetToolBar();
483 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
486 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,true);
487 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,true);
488 _tabsMgr->setActualDiagramComplexBox(true);
492 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
493 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
494 _tabsMgr->setActualDiagramComplexBox(false);
499 //=========================================================================
501 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
505 //=========================================================================
507 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
511 //=========================================================================
513 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
518 //=========================================================================
520 } // EO namespace bbtk