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