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