]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
Necessary changes to manage the basic action . First prototype totally completed...
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / bbtkwxGUIEditorGraphicBBS.cxx
1 /*=========================================================================                                                                               
2 Program:   bbtk
3 Module:    $RCSfile$
4 Language:  C++
5 Date:      $Date$
6 Version:   $Revision$
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
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.
20 *
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
25 *  liability. 
26 *
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 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32 *  \file 
33 *  \brief Class bbtk::WxInterfaceEditorGraphicBBS . 
34 */
35
36 #include "bbtkwxGUIEditorGraphicBBS.h"
37
38 namespace bbtk
39 {
40
41
42         //=========================================================================
43         wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent)
44                 : wxFrame(parent, -1, _T("bbtkGEditor"),wxDefaultPosition, wxSize(1200,800))
45         {
46                 _frameAUIMgr = new wxAuiManager(this);
47                 
48
49                 //std::string datadir( crea::System::GetExecutablePath() );
50                 std::string datadir (".");
51                 cout<<"RaC //------------------"<<endl;
52                 cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with  crea::System::GetExecutablePath() ."<<endl;
53                 cout<<"RaC //------------------"<<endl;
54
55             #ifdef LINUX /* assume this is OSX */
56                    datadir=datadir+"/../share/creaContours";
57             #endif // MACOSX    
58         
59                 #ifdef MACOSX /* assume this is OSX */
60                         datadir=datadir+"/../../../../share/creaContours";
61                 #endif // MACOSX        
62
63                 _dataDir = datadir;
64
65                 initMenu();
66                 initToolbar();
67                 initTabPanelsManager();
68                 initPackageBrowser();
69                 initHelpHTMLBrowser();
70                 initPropertiesPanel();
71
72                 CreateStatusBar();
73                 _frameAUIMgr->Update();
74         }
75
76
77         //=========================================================================
78         wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS()
79         {
80                 _frameAUIMgr->UnInit();
81         }
82
83         //=========================================================================
84         void wxGUIEditorGraphicBBS::initToolbar()
85         {       
86                 //std::string filename= _dataDir + "/data/icons/wxart_new.xpm";   
87                 wxBitmap bmp_new(new_xpm);
88
89                 wxToolBar  *_toolbar = new wxToolBar(this, wxID_ANY);
90
91                 //Adds a tool btn to the toolbar
92                 _toolbar->AddTool(wxID_NEW,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
93
94                 _toolbar->SetMargins( 2, 2 );
95                 _toolbar->Realize();
96                 SetToolBar(_toolbar);
97
98                 // connect command event handlers
99                 Connect(wxID_NEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnToolLeftClick));
100
101         }
102         //=========================================================================
103         void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
104         {
105                 //TO FIX THE PATH OF BBTK BIN  IN ORDER TO USE REGENERATE EXECUTABLES
106                 //RegenerateAll();
107                 _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
108                 _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));       
109         }
110
111         //=========================================================================
112         void wxGUIEditorGraphicBBS::initMenu()
113         {
114                 // create a menu bar
115                 wxMenu *fileMenu = new wxMenu;
116
117                 // the "About" item should be in the help menu
118                 wxMenu *helpMenu = new wxMenu;
119                 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
120                 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
121
122                 Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
123
124                 // now append the freshly created menu to the menu bar...
125                 wxMenuBar *menuBar = new wxMenuBar();
126                 menuBar->Append(fileMenu, _T("&File"));
127                 menuBar->Append(helpMenu, _T("&Help"));
128
129                 // attach this menu bar to the frame
130                 SetMenuBar(menuBar);
131         }
132
133         //=========================================================================
134         void wxGUIEditorGraphicBBS::initTabPanelsManager()
135         {
136                 wxAuiNotebook *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);
137                 _tabsMgr = new wxTabPanelsManager(notebook);
138                 _frameAUIMgr->AddPane(notebook,wxAuiPaneInfo().CenterPane());   
139
140         }
141         
142         //=========================================================================
143         void wxGUIEditorGraphicBBS::initPackageBrowser()
144         {
145                 _pkgBrowser = new WxGUIPackageBrowser2(this);
146                 _pkgBrowser->IncludeAll();
147                 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));          
148         }
149
150         //================================================================
151
152         void wxGUIEditorGraphicBBS::initPropertiesPanel()
153         {
154                 _propertiesPanel = new wxPropertiesPanel(this);
155                 _frameAUIMgr->AddPane(_propertiesPanel,wxAuiPaneInfo().Right().MinSize(200,200).CloseButton(false).Floatable(false));
156         }
157
158         //================================================================
159
160         void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
161         {
162                 std::string mess("Regenerating doc for package '");
163                 if (pack!="-a"){
164                         mess += pack + "'";
165                 }
166                 else
167                 {
168                         mess = "Regenerating doc for all packages";
169                 }
170                 
171                 mess += " ... please wait";             
172
173                 SetStatusText( std2wx(mess) );
174
175                 //BBTK_BUSY_CURSOR;
176
177                 std::string command;
178                 #if defined(WIN32)
179                         command = "\"";
180                 #endif
181                         command += ConfigurationFile::GetInstance().Get_bin_path();
182                         command += ConfigurationFile::GetInstance().Get_file_separator();
183                         command += "bbRegeneratePackageDoc";
184                 #if defined(WIN32)
185                         command += "\"";
186                 #endif
187
188                 command += " " + pack + " -q";
189             bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
190
191                 if ( ! system ( command.c_str() ) )
192                 {
193                         SetStatusText( _T("Done !"));
194                         /*
195                         wxMessageBox(_T("Done !"),_T("Regenerate package '")
196                                          +std2wx(pack)+_T("' doc"),
197                                          wxOK | wxICON_INFORMATION);
198                         */
199                 }
200                 else 
201                 {
202                         SetStatusText( _T("Done !"));
203                         wxString err(_T("An error occured while running '"));
204                         err +=  bbtk::std2wx(command) + _T("'");
205                         wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);      
206             }
207         }
208
209         //================================================================
210         void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
211         {
212                 SetStatusText( _T("Regenerating boxes lists ... please wait") );
213                 //BBTK_BUSY_CURSOR ;
214
215                 std::string command;
216                 #if defined(WIN32)
217                         command = "\"";
218                 #endif
219                         command += ConfigurationFile::GetInstance().Get_bin_path();
220                         command += ConfigurationFile::GetInstance().Get_file_separator();
221                         command += "bbRegenerateBoxesLists";
222
223                 #if defined(WIN32)
224                         command += "\"";
225                 #endif
226                         command += " -q";
227
228                 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
229
230                 if ( ! system ( command.c_str() ) )
231                 {
232                         SetStatusText( _T("Done !"));
233                         /*
234                         wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
235                                          wxOK | wxICON_INFORMATION);
236                         */
237                 }
238                 else 
239                 {
240                         SetStatusText( _T("Done !"));
241                         wxString err(_T("An error occured while running '"));
242                         err +=  bbtk::std2wx(command) + _T("'");
243                         wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);      
244                 }
245         }
246         
247   //================================================================
248         void wxGUIEditorGraphicBBS::RegenerateAll()
249         {
250                 DoRegeneratePackageDoc("-a");   
251                 DoRegenerateBoxesLists();
252         }
253
254   //================================================================
255
256         /*****************************************************
257         /* HANDLERS 
258         /*****************************************************/
259
260         void wxGUIEditorGraphicBBS::OnToolLeftClick(wxCommandEvent& event)
261         {
262                 switch (event.GetId())
263                 {
264                 case wxID_NEW :
265                         _tabsMgr->addNewTab();
266                         break;                  
267                 }
268         }
269
270         void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
271         {
272                 Close(true);
273         }
274
275
276 }  // EO namespace bbtk
277
278 // EOF
279