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);
95 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
97 //Adds a tool btn to the toolbar
98 toolbar->AddTool(ID_NEW,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
99 toolbar->AddTool(ID_OPEN,_T("Open diagram"),bmp_open, wxNullBitmap, wxITEM_NORMAL,_T("Open a diagram"), _T("Open a diagram"));
100 toolbar->AddTool(ID_SAVE,_T("Save diagram"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves actual diagram"), _T("Saves actual diagram"));
101 toolbar->AddTool(ID_RUN,_T("Run"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram"));
102 toolbar->AddTool(ID_DELETEALL,_T("Delete all"),bmp_delete, wxNullBitmap, wxITEM_NORMAL,_T("Delete all boxes"), _T("Delete all boxes"));
103 toolbar->AddTool(ID_CENTERVIEW,_T("Center view"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Center view"), _T("Center view"));
104 toolbar->AddSeparator();
105 toolbar->AddTool(ID_BTNCOMPLEXBOX,_T("Complex box"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Complex box"), _T("Complex box"));
106 toolbar->SetToggle(ID_BTNCOMPLEXBOX,true);
108 toolbar->SetMargins( 2, 2 );
112 // connect command event handlers
113 Connect(ID_NEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
114 Connect(ID_OPEN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
115 Connect(ID_SAVE,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
116 Connect(ID_RUN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
117 Connect(ID_DELETEALL,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
118 Connect(ID_CENTERVIEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
119 Connect(ID_BTNCOMPLEXBOX,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnActivateComplexBox));
122 //=========================================================================
123 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
125 //TO FIX THE PATH OF BBTK BIN IN ORDER TO USE REGENERATE EXECUTABLES
127 _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
128 _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));
131 //=========================================================================
132 void wxGUIEditorGraphicBBS::initMenu()
135 wxMenu *fileMenu = new wxMenu;
137 // the "About" item should be in the help menu
138 wxMenu *helpMenu = new wxMenu;
139 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
140 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
142 Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
144 // now append the freshly created menu to the menu bar...
145 wxMenuBar *menuBar = new wxMenuBar();
146 menuBar->Append(fileMenu, _T("&File"));
147 menuBar->Append(helpMenu, _T("&Help"));
149 // attach this menu bar to the frame
153 //=========================================================================
154 void wxGUIEditorGraphicBBS::initTabPanelsManager()
156 _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);
157 _tabsMgr = new wxTabPanelsManager(this);
158 _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());
162 //=========================================================================
163 void wxGUIEditorGraphicBBS::initPackageBrowser()
165 _pkgBrowser = new WxGUIPackageBrowser2(this);
166 _pkgBrowser->IncludeAll();
167 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));
170 //================================================================
172 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
174 std::string mess("Regenerating doc for package '");
180 mess = "Regenerating doc for all packages";
183 mess += " ... please wait";
185 SetStatusText( std2wx(mess) );
193 command += ConfigurationFile::GetInstance().Get_bin_path();
194 command += ConfigurationFile::GetInstance().Get_file_separator();
195 command += "bbRegeneratePackageDoc";
200 command += " " + pack + " -q";
201 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
203 if ( ! system ( command.c_str() ) )
205 SetStatusText( _T("Done !"));
207 wxMessageBox(_T("Done !"),_T("Regenerate package '")
208 +std2wx(pack)+_T("' doc"),
209 wxOK | wxICON_INFORMATION);
214 SetStatusText( _T("Done !"));
215 wxString err(_T("An error occured while running '"));
216 err += bbtk::std2wx(command) + _T("'");
217 wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);
221 //================================================================
222 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
224 SetStatusText( _T("Regenerating boxes lists ... please wait") );
231 command += ConfigurationFile::GetInstance().Get_bin_path();
232 command += ConfigurationFile::GetInstance().Get_file_separator();
233 command += "bbRegenerateBoxesLists";
240 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
242 if ( ! system ( command.c_str() ) )
244 SetStatusText( _T("Done !"));
246 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
247 wxOK | wxICON_INFORMATION);
252 SetStatusText( _T("Done !"));
253 wxString err(_T("An error occured while running '"));
254 err += bbtk::std2wx(command) + _T("'");
255 wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);
259 //================================================================
260 void wxGUIEditorGraphicBBS::RegenerateAll()
262 DoRegeneratePackageDoc("-a");
263 DoRegenerateBoxesLists();
266 //================================================================
268 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
273 //================================================================
275 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
277 if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
279 _actualPkgBrowserPkgName = packageName;
280 _actualPkgBrowserBoxName = boxName;
282 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
283 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
287 //=========================================================================
289 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
291 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
295 //=========================================================================
297 void wxGUIEditorGraphicBBS::editDiagramParameters(wxVtkSceneManager* scene)
299 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,scene);
303 //=========================================================================
305 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
307 SetStatusText(crea::std2wx(textStatus));
310 //=========================================================================
312 void wxGUIEditorGraphicBBS::executeScript(std::string script)
314 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
315 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
316 std::string filename = dir + separator + "tmp_bbtk.bbs";
319 tempFile.open(filename.c_str());
323 std::string command = "\"";
329 //command += ConfigurationFile::GetInstance().Get_bin_path();
330 command +="C:/temp/bbtkBIN/RelWithDebInfo//";
333 command += separator + "bbi.app/Contents/MacOS/bbi\" ";
335 command += separator + "bbi\" ";
337 command += "\""+filename + "\"";
345 printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
346 system( command.c_str() );
349 //=========================================================================
351 //=========================================================================
353 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
355 _tabsMgr->addNewTab();
358 //=========================================================================
360 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
362 std::string script = _tabsMgr->getActualDiagramScript();
363 cout<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl;
366 executeScript(script);
369 //=========================================================================
371 /*****************************************************/
373 /*****************************************************/
374 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
376 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save actual diagram"),wxEmptyString,"NewDiagram","*.bbd",wxSAVE|wxOVERWRITE_PROMPT);
377 if (saveFileDialog->ShowModal() == wxID_OK)
379 wxString fileName = saveFileDialog->GetPath();
382 file.open(fileName.c_str());
384 std::string content="";
386 // writing file header
387 content += "# ----------------------------------\n";
388 content += "# - BBTKGEditor v 1.0 BBD BlackBox Diagram file\n";
392 content += "# ----------------------------------\n";
394 content += "APP_START\n";
395 _tabsMgr->saveActualDiagram(content);
396 content += "APP_END\n";
403 //=========================================================================
405 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
407 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);
408 if(dial->ShowModal() == wxID_YES)
410 _tabsMgr->deleteAllBoxesActualDiagram();
414 //=========================================================================
416 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
418 _tabsMgr->centerViewActualDiagram();
421 //=========================================================================
424 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
426 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open diagram"),wxEmptyString,"","*.bbd",wxOPEN|wxFILE_MUST_EXIST);
427 if (openFileDialog->ShowModal() == wxID_OK)
429 wxString fileName = openFileDialog->GetPath();
431 ifstream inputStream;
432 inputStream.open(fileName.c_str());
434 _tabsMgr->addNewTab();
435 _tabsMgr->loadDiagram(inputStream);
443 //=========================================================================
445 void wxGUIEditorGraphicBBS::OnActivateComplexBox(wxCommandEvent& event)
450 //=========================================================================
452 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
457 //=========================================================================
459 } // EO namespace bbtk