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 //std::string filename= _dataDir + "/data/icons/wxart_new.xpm";
89 wxBitmap bmp_new(new_xpm);
90 wxBitmap bmp_run(run_xpm);
92 wxToolBar *_toolbar = new wxToolBar(this, wxID_ANY);
94 //Adds a tool btn to the toolbar
95 _toolbar->AddTool(1000,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
96 _toolbar->AddTool(1001,_T("Execute"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram"));
98 _toolbar->SetMargins( 2, 2 );
100 SetToolBar(_toolbar);
102 // connect command event handlers
103 Connect(1000,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnToolLeftClick));
104 Connect(1001,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnToolLeftClick));
107 //=========================================================================
108 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
110 //TO FIX THE PATH OF BBTK BIN IN ORDER TO USE REGENERATE EXECUTABLES
112 _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
113 _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));
116 //=========================================================================
117 void wxGUIEditorGraphicBBS::initMenu()
120 wxMenu *fileMenu = new wxMenu;
122 // the "About" item should be in the help menu
123 wxMenu *helpMenu = new wxMenu;
124 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
125 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
127 Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
129 // now append the freshly created menu to the menu bar...
130 wxMenuBar *menuBar = new wxMenuBar();
131 menuBar->Append(fileMenu, _T("&File"));
132 menuBar->Append(helpMenu, _T("&Help"));
134 // attach this menu bar to the frame
138 //=========================================================================
139 void wxGUIEditorGraphicBBS::initTabPanelsManager()
141 _notebook = new wxAuiNotebook(this,wxID_ANY,wxDefaultPosition,wxDefaultSize,wxAUI_NB_TOP|wxAUI_NB_TAB_MOVE|wxAUI_NB_CLOSE_ON_ACTIVE_TAB|wxAUI_NB_TAB_FIXED_WIDTH|wxAUI_NB_WINDOWLIST_BUTTON);
142 _tabsMgr = new wxTabPanelsManager(this);
143 _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());
147 //=========================================================================
148 void wxGUIEditorGraphicBBS::initPackageBrowser()
150 _pkgBrowser = new WxGUIPackageBrowser2(this);
151 _pkgBrowser->IncludeAll();
152 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));
155 //================================================================
157 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
159 std::string mess("Regenerating doc for package '");
165 mess = "Regenerating doc for all packages";
168 mess += " ... please wait";
170 SetStatusText( std2wx(mess) );
178 command += ConfigurationFile::GetInstance().Get_bin_path();
179 command += ConfigurationFile::GetInstance().Get_file_separator();
180 command += "bbRegeneratePackageDoc";
185 command += " " + pack + " -q";
186 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
188 if ( ! system ( command.c_str() ) )
190 SetStatusText( _T("Done !"));
192 wxMessageBox(_T("Done !"),_T("Regenerate package '")
193 +std2wx(pack)+_T("' doc"),
194 wxOK | wxICON_INFORMATION);
199 SetStatusText( _T("Done !"));
200 wxString err(_T("An error occured while running '"));
201 err += bbtk::std2wx(command) + _T("'");
202 wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);
206 //================================================================
207 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
209 SetStatusText( _T("Regenerating boxes lists ... please wait") );
216 command += ConfigurationFile::GetInstance().Get_bin_path();
217 command += ConfigurationFile::GetInstance().Get_file_separator();
218 command += "bbRegenerateBoxesLists";
225 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
227 if ( ! system ( command.c_str() ) )
229 SetStatusText( _T("Done !"));
231 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
232 wxOK | wxICON_INFORMATION);
237 SetStatusText( _T("Done !"));
238 wxString err(_T("An error occured while running '"));
239 err += bbtk::std2wx(command) + _T("'");
240 wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);
244 //================================================================
245 void wxGUIEditorGraphicBBS::RegenerateAll()
247 DoRegeneratePackageDoc("-a");
248 DoRegenerateBoxesLists();
251 //================================================================
253 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
258 //================================================================
260 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
262 if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
264 _actualPkgBrowserPkgName = packageName;
265 _actualPkgBrowserBoxName = boxName;
267 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
268 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
272 //=========================================================================
274 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
276 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
280 //=========================================================================
282 void wxGUIEditorGraphicBBS::editDiagramParameters(wxVtkSceneManager* scene)
284 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,scene);
288 //=========================================================================
290 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
292 SetStatusText(crea::std2wx(textStatus));
295 //=========================================================================
297 void wxGUIEditorGraphicBBS::executeActualDiagram()
299 std::string script = _tabsMgr->getActualDiagramScript();
300 cout<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl;
304 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
305 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
306 std::string filename = dir + separator + "tmp_bbtk.bbs";
309 tempFile.open(filename.c_str());
313 std::string command = "\"";
319 //command += ConfigurationFile::GetInstance().Get_bin_path();
320 command +="C:/temp/bbtkBIN/RelWithDebInfo//";
323 command += separator + "bbi.app/Contents/MacOS/bbi\" ";
325 command += separator + "bbi\" ";
327 command += "\""+filename + "\"";
335 printf ("RaC wxGUIEditorGraphicBBS::executeActualDiagram %s \n" , command.c_str() );
336 system( command.c_str() );
339 //=========================================================================
341 /*****************************************************
343 /*****************************************************/
345 void wxGUIEditorGraphicBBS::OnToolLeftClick(wxCommandEvent& event)
347 switch (event.GetId())
350 _tabsMgr->addNewTab();
354 executeActualDiagram();
359 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
365 } // EO namespace bbtk