]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.cxx
Feature #1771 Add licence terms for all files.
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxTabPanelsManager.cxx
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 #
8 #  This software is governed by the CeCILL-B license under French law and 
9 #  abiding by the rules of distribution of free software. You can  use, 
10 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
11 #  license as circulated by CEA, CNRS and INRIA at the following URL 
12 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
13 #  or in the file LICENSE.txt.
14 #
15 #  As a counterpart to the access to the source code and  rights to copy,
16 #  modify and redistribute granted by the license, users are provided only
17 #  with a limited warranty  and the software's author,  the holder of the
18 #  economic rights,  and the successive licensors  have only  limited
19 #  liability. 
20 #
21 #  The fact that you are presently reading this means that you have had
22 #  knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------  
24 */
25
26 /*=========================================================================
27 Program:   bbtk
28 Module:    $RCSfile$
29 Language:  C++
30 Date:      $Date$
31 Version:   $Revision$
32 =========================================================================*/
33
34 /* ---------------------------------------------------------------------
35
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
38 *
39 *  This software is governed by the CeCILL-B license under French law and
40 *  abiding by the rules of distribution of free software. You can  use,
41 *  modify and/ or redistribute the software under the terms of the CeCILL-B
42 *  license as circulated by CEA, CNRS and INRIA at the following URL
43 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
44 *  or in the file LICENSE.txt.
45 *
46 *  As a counterpart to the access to the source code and  rights to copy,
47 *  modify and redistribute granted by the license, users are provided only
48 *  with a limited warranty  and the software's author,  the holder of the
49 *  economic rights,  and the successive licensors  have only  limited
50 *  liability.
51 *
52 *  The fact that you are presently reading this means that you have had
53 *  knowledge of the CeCILL-B license and that you accept its terms.
54 * ------------------------------------------------------------------------ */
55
56 /**
57 *  \file
58 *  \brief Class bbtk::wxTabPanelsManager .
59 */
60
61
62 #include "wxTabPanelsManager.h"
63
64 namespace bbtk
65 {
66
67
68         //=========================================================================
69         wxTabPanelsManager::wxTabPanelsManager(wxGUIEditorGraphicBBS *parent)
70         {
71                 _parent         = parent;
72                 _lastId         = 0;
73                 _notebook       = _parent->getAuiNotebook();
74                 addNewTab();
75                 _notebook->Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED,wxAuiNotebookEventHandler(wxTabPanelsManager::OnTabChanged),0,this);
76                 _notebook->Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE,wxAuiNotebookEventHandler(wxTabPanelsManager::OnTabClose),0,this);
77
78         }
79
80         //=========================================================================
81         wxTabPanelsManager::~wxTabPanelsManager()
82         {
83         }
84
85         //=========================================================================
86         void wxTabPanelsManager::addNewTab(wxString tabName)
87         {
88                 _lastId++;
89
90                 //EED 13/10/2012                wxGEditorTabPanel *newPanel         = new wxGEditorTabPanel( _notebook,_lastId );
91                 wxGEditorTabPanel *newPanel         = new wxGEditorTabPanel( _notebook,_lastId, _parent->GetBBTKFactory() );
92
93                 newPanel->setPanelsManager(this);
94                 _panels[_lastId]                    = newPanel;
95                 _actual                             = newPanel;
96                 _notebook->AddPage(newPanel, tabName  ,true);
97         }
98
99
100
101
102
103         //=========================================================================
104         wxAuiNotebook* wxTabPanelsManager::getAuiNotebook()
105         {
106                 return _notebook;
107         }
108
109         //=========================================================================
110         wxGEditorTabPanel* wxTabPanelsManager::getActualTabPanel()
111         {
112                 return _actual;
113         }
114
115         //=========================================================================
116
117         void wxTabPanelsManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
118         {
119                 _parent->displayBlackBoxInfo(packageName,boxName);
120         }
121
122         //=========================================================================
123
124         void wxTabPanelsManager::updateStatusBar(std::string textStatus)
125         {
126                 _parent->updateStatusBar(textStatus);
127         }
128
129         //=========================================================================
130
131         std::string wxTabPanelsManager::getActualDiagramBBS(bool wln)
132         {
133                 return _actual->getDiagramBBS(wln);
134         }
135
136         //=========================================================================
137
138         std::string wxTabPanelsManager::getActualComplexBoxBBS()
139         {
140                 return _actual->saveComplexBoxBBS();
141         }
142
143         //=========================================================================
144
145         void wxTabPanelsManager::editBlackBox(GBlackBoxModel *bbmodel)
146         {
147                 _parent->editBlackBox(bbmodel);
148         }
149
150         //=========================================================================
151
152         void wxTabPanelsManager::deleteAllBoxesActualDiagram()
153         {
154                 _actual->deleteAllBoxes();
155         }
156
157         //=========================================================================
158
159         void wxTabPanelsManager::centerViewActualDiagram()
160         {
161                 _actual->centerView();
162         }
163
164         //=========================================================================
165
166         void wxTabPanelsManager::saveActualDiagram(std::string &content, const std::string &path) //DFCH
167         {
168                 _actual->saveDiagram(content, path);
169         }
170
171         //=========================================================================
172
173         void wxTabPanelsManager::loadDiagram(ifstream &inputStream, const std::string &path) //DFCH
174         {
175                 _actual->loadDiagram(inputStream, path);
176         }
177
178         //=========================================================================
179         void wxTabPanelsManager::saveTempandUpdate(const std::string &action) //FCY
180         {
181                 _parent->SaveTempActualDiagram(action);
182         }
183         //=========================================================================
184         void wxTabPanelsManager::saveTempActualDiagram(const std::string &action) //FCY
185         {
186                 _actual->saveTempDiagram(action);
187         }
188         //=========================================================================
189         void wxTabPanelsManager::loadTempDiagram(unsigned short un) //FCY
190         {
191                  _actual->loadTempDiagram(un);
192         }
193
194         //=========================================================================
195         unsigned short wxTabPanelsManager::getUndoState( std::string &stun) //FCY
196         {
197                  return _actual->getUndoState(stun);
198         }
199                 //=========================================================================
200         unsigned short wxTabPanelsManager::getRedoState(std::string &stre) //FCY
201         {
202                  return _actual->getRedoState(stre);
203         }
204         //=========================================================================
205
206         bool wxTabPanelsManager::isActualDiagramComplexBox()
207         {
208                 return _actual->isComplexBox();
209         }
210
211         //=========================================================================
212
213         void wxTabPanelsManager::setActualDiagramComplexBox(bool val)
214         {
215                 _actual->setComplexBox(val);
216         }
217
218         //=========================================================================
219
220         void wxTabPanelsManager::addActualDiagramComplexInputPort(std::string portName)
221         {
222                 _actual->addComplexInputPort(portName);
223         }
224
225         //=========================================================================
226
227         void wxTabPanelsManager::addActualDiagramComplexOutputPort(std::string portName)
228         {
229                 _actual->addComplexOutputPort(portName);
230         }
231
232         //=========================================================================
233
234         void wxTabPanelsManager::copySelectedBBoxesToComplexDiagram()
235         {
236                 std::map<int,GObjectController*> mapSelected = _actual->getSelectedObjects();
237                 addNewTab();
238                 setActualDiagramComplexBox(true);
239                 _actual->addObjects(mapSelected);
240                 _parent->refreshGUIControls();
241         }
242
243         //=========================================================================
244
245         int wxTabPanelsManager::getNumActualSelectedObjects()
246         {
247                 return _actual->getNumSelectedObjects();
248         }
249
250         //=========================================================================
251
252         void wxTabPanelsManager::VerifyLastTabPanel()
253         {
254 printf("wxTabPanelsManager::VerifyActualTabPanel  %d \n", this->_notebook->GetPageCount() );
255             if (this->_notebook->GetPageCount()==0)
256             {
257                 this->_actual=NULL;
258             }
259         }
260
261         //=========================================================================
262
263         void wxTabPanelsManager::OnTabChanged(wxAuiNotebookEvent& event)
264         {
265                 int index                   = event.GetSelection();
266                 wxGEditorTabPanel* tab      = (wxGEditorTabPanel*)_notebook->GetPage(index);
267                 int id                      = tab->getPanelId();
268                 _actual                     = _panels[id];
269                 _parent->refreshGUIControls();
270
271         }
272
273         //=========================================================================
274
275         void wxTabPanelsManager::OnTabClose(wxAuiNotebookEvent& event)
276         {
277
278                 std::cout<<"RaC wxTabPanelsManager::OnTabClose Start... "<<_panels.size()<<std::endl;
279                 int index = event.GetSelection();
280
281                 if(_panels.size()>0)
282                 {
283                         wxGEditorTabPanel* tab      = (wxGEditorTabPanel*)_notebook->GetPage(index);
284                         int id                      = tab->getPanelId();
285                         tab->deleteAllBoxes();
286                         _panels.erase(id);
287
288                         _notebook->RemovePage(index);
289
290                         std::cout<<"RaC wxTabPanelsManager::OnTabClose  IMPORTANT. The complete tab is not erased from memory... "<<std::endl;
291                         //////////////////////////////
292                         // TO FIX . RaC May 2012 - IMPORTANT. The complete tab is not erased from memory.
293                         // Only the objects are deleted and the tab is hidden
294                         // Execution problems when a tab is deleted using delete or DeletePage
295                         // delete tab;
296
297                         map<int, wxGEditorTabPanel*>::iterator it = _panels.begin() ;
298                         _actual=(*it).second;
299
300                         std::cout<<"RaC wxTabPanelsManager::OnTabClose End..."<< std::endl;
301                 }
302         }
303
304         //=========================================================================
305     std::string wxTabPanelsManager::GetCbName()
306         {
307             return _actual->GetCbName();
308         }
309         
310         //=========================================================================
311         void wxTabPanelsManager::SetNameTabPanel(wxString tabpanelname)
312         {
313             int id          = _notebook->GetSelection();
314             _notebook->SetPageText( id , tabpanelname );
315         }
316
317         std::string wxTabPanelsManager::GetNameTabPanel() 
318         {
319                  int id = _notebook->GetSelection();
320                 return crea::wx2std(_notebook->GetPageText(id));
321         }
322
323         //=========================================================================
324         //DFCH
325         std::string wxTabPanelsManager::GetCurrentTabPanelPath( )
326         {
327                 int id          = _notebook->GetSelection();
328                 wxGEditorTabPanel* auxPanel = (wxGEditorTabPanel*) _notebook->GetPage(id);
329                 return( auxPanel->GetFullPath( ) );
330             //return ( (wxGEditorTabPanel) _notebook->GetPage(id)->GetFullPath( ) );
331         }
332
333         //=========================================================================
334
335         int  wxTabPanelsManager::FindTab(std::string filename)
336         {
337                 std::map<int, wxGEditorTabPanel*>::iterator it;
338                 for (it = _panels.begin(); it != _panels.end(); ++it)
339                 {
340                         wxGEditorTabPanel *obj = it->second;
341                         int id = it->first;
342                         if(obj->GetFullPath()==filename)
343                                 return id;
344                 }
345                 return -1;
346         }
347
348         //=========================================================================
349     std::string wxTabPanelsManager::GetCbPackageName()
350         {
351             return _actual->GetCbPackageName();
352         }
353
354         //=========================================================================
355     std::string wxTabPanelsManager::GetAuthor()
356         {
357             return _actual->GetAuthor();
358         }
359
360         //=========================================================================
361     std::string wxTabPanelsManager::GetDescription()
362         {
363             return _actual->GetDescription();
364         }
365
366         //=========================================================================
367     std::string wxTabPanelsManager::GetCategory()
368         {
369             return _actual->GetCategory();
370         }
371
372         //=========================================================================
373     void wxTabPanelsManager::SetCbName(std::string cbName)
374     {
375         _actual->SetCbName( cbName );
376     }
377
378         //=========================================================================
379     void wxTabPanelsManager::SetCbPackageName(std::string packagename)
380     {
381         _actual->SetCbPackageName( packagename );
382     }
383
384
385         //=========================================================================
386     void wxTabPanelsManager::SetAuthor(std::string author)
387     {
388         _actual->SetAuthor( author );
389     }
390
391
392         //=========================================================================
393     void wxTabPanelsManager::SetCategory(std::string category)
394     {
395         _actual->SetCategory( category );
396     }
397
398         //=========================================================================
399     void wxTabPanelsManager::SetDescription(std::string description)
400     {
401         _actual->SetDescription( description );
402     }
403
404         //=========================================================================
405         bool wxTabPanelsManager::TryToOpenScriptApplication(std::string packageName ,std::string boxType)
406     {
407         return _parent->TryToOpenScriptApplication( packageName, boxType );
408     }
409                 
410 }  // EO namespace bbtk
411
412 // EOF
413