]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.cxx
6548a8d406b5317f12dc1bb081ce97d87de36b1c
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxTabPanelsManager.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::wxTabPanelsManager .
34 */
35
36
37 #include "wxTabPanelsManager.h"
38
39 namespace bbtk
40 {
41
42
43         //=========================================================================
44         wxTabPanelsManager::wxTabPanelsManager(wxGUIEditorGraphicBBS *parent)
45         {
46                 _parent         = parent;
47                 _lastId         = 0;
48                 _notebook       = _parent->getAuiNotebook();
49                 addNewTab();
50                 _notebook->Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED,wxAuiNotebookEventHandler(wxTabPanelsManager::OnTabChanged),0,this);
51                 _notebook->Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE,wxAuiNotebookEventHandler(wxTabPanelsManager::OnTabClose),0,this);
52
53         }
54
55         //=========================================================================
56         wxTabPanelsManager::~wxTabPanelsManager()
57         {
58         }
59
60         //=========================================================================
61         void wxTabPanelsManager::addNewTab(wxString tabName)
62         {
63
64                 _lastId++;
65                 wxGEditorTabPanel *newPanel         = new wxGEditorTabPanel(_notebook,_lastId);
66                 newPanel->setPanelsManager(this);
67                 _panels[_lastId]                    = newPanel;
68                 _actual                             = newPanel;
69
70                 _notebook->AddPage(newPanel, tabName  ,true);
71         }
72
73
74
75
76
77         //=========================================================================
78         wxAuiNotebook* wxTabPanelsManager::getAuiNotebook()
79         {
80                 return _notebook;
81         }
82
83         //=========================================================================
84         wxGEditorTabPanel* wxTabPanelsManager::getActualTabPanel()
85         {
86                 return _actual;
87         }
88
89         //=========================================================================
90
91         void wxTabPanelsManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
92         {
93                 _parent->displayBlackBoxInfo(packageName,boxName);
94         }
95
96         //=========================================================================
97
98         void wxTabPanelsManager::updateStatusBar(std::string textStatus)
99         {
100                 _parent->updateStatusBar(textStatus);
101         }
102
103         //=========================================================================
104
105         std::string wxTabPanelsManager::getActualDiagramBBS(bool wln)
106         {
107                 return _actual->getDiagramBBS(wln);
108         }
109
110         //=========================================================================
111
112         std::string wxTabPanelsManager::getActualComplexBoxBBS()
113         {
114                 return _actual->saveComplexBoxBBS();
115         }
116
117         //=========================================================================
118
119         void wxTabPanelsManager::editBlackBox(GBlackBoxModel *bbmodel)
120         {
121                 _parent->editBlackBox(bbmodel);
122         }
123
124         //=========================================================================
125
126         void wxTabPanelsManager::deleteAllBoxesActualDiagram()
127         {
128                 _actual->deleteAllBoxes();
129         }
130
131         //=========================================================================
132
133         void wxTabPanelsManager::centerViewActualDiagram()
134         {
135                 _actual->centerView();
136         }
137
138         //=========================================================================
139
140         void wxTabPanelsManager::saveActualDiagram(std::string &content, const std::string &path) //DFCH
141         {
142                 _actual->saveDiagram(content, path);
143         }
144
145         //=========================================================================
146
147         void wxTabPanelsManager::loadDiagram(ifstream &inputStream, const std::string &path) //DFCH
148         {
149                 _actual->loadDiagram(inputStream, path);
150         }
151
152         //=========================================================================
153         void wxTabPanelsManager::saveTempandUpdate(const std::string &action) //FCY
154         {
155                 _parent->SaveTempActualDiagram(action);
156         }
157         //=========================================================================
158         void wxTabPanelsManager::saveTempActualDiagram(const std::string &action) //FCY
159         {
160                 _actual->saveTempDiagram(action);
161         }
162         //=========================================================================
163         void wxTabPanelsManager::loadTempDiagram(unsigned short un) //FCY
164         {
165                  _actual->loadTempDiagram(un);
166         }
167
168         //=========================================================================
169         unsigned short wxTabPanelsManager::getUndoState( std::string &stun) //FCY
170         {
171                  return _actual->getUndoState(stun);
172         }
173                 //=========================================================================
174         unsigned short wxTabPanelsManager::getRedoState(std::string &stre) //FCY
175         {
176                  return _actual->getRedoState(stre);
177         }
178         //=========================================================================
179
180         bool wxTabPanelsManager::isActualDiagramComplexBox()
181         {
182                 return _actual->isComplexBox();
183         }
184
185         //=========================================================================
186
187         void wxTabPanelsManager::setActualDiagramComplexBox(bool val)
188         {
189                 _actual->setComplexBox(val);
190         }
191
192         //=========================================================================
193
194         void wxTabPanelsManager::addActualDiagramComplexInputPort(std::string portName)
195         {
196                 _actual->addComplexInputPort(portName);
197         }
198
199         //=========================================================================
200
201         void wxTabPanelsManager::addActualDiagramComplexOutputPort(std::string portName)
202         {
203                 _actual->addComplexOutputPort(portName);
204         }
205
206         //=========================================================================
207
208         void wxTabPanelsManager::copySelectedBBoxesToComplexDiagram()
209         {
210                 std::map<int,GObjectController*> mapSelected = _actual->getSelectedObjects();
211                 addNewTab();
212                 setActualDiagramComplexBox(true);
213                 _actual->addObjects(mapSelected);
214                 _parent->refreshGUIControls();
215         }
216
217         //=========================================================================
218
219         int wxTabPanelsManager::getNumActualSelectedObjects()
220         {
221                 return _actual->getNumSelectedObjects();
222         }
223
224         //=========================================================================
225
226         void wxTabPanelsManager::VerifyLastTabPanel()
227         {
228 printf("wxTabPanelsManager::VerifyActualTabPanel  %d \n", this->_notebook->GetPageCount() );
229             if (this->_notebook->GetPageCount()==0)
230             {
231                 this->_actual=NULL;
232             }
233         }
234
235         //=========================================================================
236
237         void wxTabPanelsManager::OnTabChanged(wxAuiNotebookEvent& event)
238         {
239                 int index                   = event.GetSelection();
240                 wxGEditorTabPanel* tab      = (wxGEditorTabPanel*)_notebook->GetPage(index);
241                 int id                      = tab->getPanelId();
242                 _actual                     = _panels[id];
243                 _parent->refreshGUIControls();
244
245         }
246
247         //=========================================================================
248
249         void wxTabPanelsManager::OnTabClose(wxAuiNotebookEvent& event)
250         {
251
252                 std::cout<<"RaC wxTabPanelsManager::OnTabClose Start... "<<_panels.size()<<std::endl;
253                 int index = event.GetSelection();
254
255                 if(_panels.size()>0)
256                 {
257                         wxGEditorTabPanel* tab      = (wxGEditorTabPanel*)_notebook->GetPage(index);
258                         int id                      = tab->getPanelId();
259                         tab->deleteAllBoxes();
260                         _panels.erase(id);
261
262                         _notebook->RemovePage(index);
263
264                         std::cout<<"RaC wxTabPanelsManager::OnTabClose  IMPORTANT. The complete tab is not erased from memory... "<<std::endl;
265                         //////////////////////////////
266                         // TO FIX . RaC May 2012 - IMPORTANT. The complete tab is not erased from memory.
267                         // Only the objects are deleted and the tab is hidden
268                         // Execution problems when a tab is deleted using delete or DeletePage
269                         // delete tab;
270
271                         map<int, wxGEditorTabPanel*>::iterator it = _panels.begin() ;
272                         _actual=(*it).second;
273
274                         std::cout<<"RaC wxTabPanelsManager::OnTabClose End..."<< std::endl;
275                 }
276         }
277
278         //=========================================================================
279     std::string wxTabPanelsManager::GetCbName()
280         {
281             return _actual->GetCbName();
282         }
283         
284         //=========================================================================
285         void wxTabPanelsManager::SetNameTabPanel(wxString tabpanelname)
286         {
287             int id          = _notebook->GetSelection();
288             _notebook->SetPageText( id , tabpanelname );
289         }
290
291         std::string wxTabPanelsManager::GetNameTabPanel() 
292         {
293                  int id = _notebook->GetSelection();
294                 return crea::wx2std(_notebook->GetPageText(id));
295         }
296
297         //=========================================================================
298         //DFCH
299         std::string wxTabPanelsManager::GetCurrentTabPanelPath( )
300         {
301                 int id          = _notebook->GetSelection();
302                 wxGEditorTabPanel* auxPanel = (wxGEditorTabPanel*) _notebook->GetPage(id);
303                 return( auxPanel->GetFullPath( ) );
304             //return ( (wxGEditorTabPanel) _notebook->GetPage(id)->GetFullPath( ) );
305         }
306
307
308         //=========================================================================
309     std::string wxTabPanelsManager::GetCbPackageName()
310         {
311             return _actual->GetCbPackageName();
312         }
313
314         //=========================================================================
315     std::string wxTabPanelsManager::GetAuthor()
316         {
317             return _actual->GetAuthor();
318         }
319
320         //=========================================================================
321     std::string wxTabPanelsManager::GetDescription()
322         {
323             return _actual->GetDescription();
324         }
325
326         //=========================================================================
327     std::string wxTabPanelsManager::GetCategory()
328         {
329             return _actual->GetCategory();
330         }
331
332         //=========================================================================
333     void wxTabPanelsManager::SetCbName(std::string cbName)
334     {
335         _actual->SetCbName( cbName );
336     }
337
338         //=========================================================================
339     void wxTabPanelsManager::SetCbPackageName(std::string packagename)
340     {
341         _actual->SetCbPackageName( packagename );
342     }
343
344
345         //=========================================================================
346     void wxTabPanelsManager::SetAuthor(std::string author)
347     {
348         _actual->SetAuthor( author );
349     }
350
351
352         //=========================================================================
353     void wxTabPanelsManager::SetCategory(std::string category)
354     {
355         _actual->SetCategory( category );
356     }
357
358
359         //=========================================================================
360     void wxTabPanelsManager::SetDescription(std::string description)
361     {
362         _actual->SetDescription( description );
363     }
364
365
366
367
368
369
370
371
372
373
374 }  // EO namespace bbtk
375
376 // EOF
377