]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxGEditorTabPanel.cxx
00f669bc64f9c19a0c96d42d89934c5f7dea8a71
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxGEditorTabPanel.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::wxGEditorTabPanel .
34 */
35
36
37 #include "wxGEditorTabPanel.h"
38 #include "creaWx.h"
39
40 namespace bbtk
41 {
42
43         //=========================================================================
44         wxGEditorTabPanel::wxGEditorTabPanel()
45         {
46                 printf ("EED %p wxGEditorTabPanel 1 ()\n" , this );
47         }
48
49         //=========================================================================
50         wxGEditorTabPanel::wxGEditorTabPanel(wxWindow *parent,int id, Factory::Pointer bbtkfactory)
51          : wxPanel(parent),wxTextDropTarget()
52         {
53 printf("EED wxGEditorTabPanel::wxGEditorTabPanel 0\n");
54                 printf ("EED %p wxGEditorTabPanel 2 ()\n" , this );
55                 _id=id;
56                 _panelAUIMgr    = new wxAuiManager(this);
57                 _sceneManager   = NULL;
58                 _actualdo               = states.begin();
59                 _sactualdo              = sstates.begin();
60                 _bbtkfactory    = bbtkfactory;
61                 initWxVtkCanvas();
62 printf("EED wxGEditorTabPanel::wxGEditorTabPanel 1\n");
63         }
64
65         //=========================================================================
66         wxGEditorTabPanel::~wxGEditorTabPanel()
67         {
68 printf ("EED %p ~wxGEditorTabPanel() START \n" , this );
69 //ED02JUIN2010          _sceneManager->disconnectDrop();
70
71         _panelsManager->VerifyLastTabPanel();
72                 //FCY memory leaks
73                 delete _panelAUIMgr;
74                 delete _sceneManager;
75
76                 printf ("EED %p ~wxGEditorTabPanel() END\n" , this );
77         }
78
79         //=========================================================================
80         void wxGEditorTabPanel::initWxVtkCanvas()
81         {
82 printf("EED wxGEditorTabPanel::initWxVtkCanvas 0\n");
83                 wxVtk3DBaseView *baseview = new wxVtk3DBaseView(this);
84                 baseview->Configure();
85 //EED 15 oct 2012               _sceneManager=new wxVtkSceneManager(this,baseview,_id);
86                 _sceneManager=new wxVtkSceneManager(this,baseview,_id, _bbtkfactory);
87
88
89 //EED02JUIN2010
90                 printf("RaC-EED 21-06-2010 wxGEditorTabPanel::initWxVtkCanvas Remove the panelAUIMgr, and change to a normal sizer inside the wxGEditorTabPanel\n");
91                 _panelAUIMgr->AddPane((wxWindow*)baseview->GetWxVTKRenderWindowInteractor(),wxAuiPaneInfo().Fixed().CenterPane());
92
93                 _panelAUIMgr->Update();
94 printf("EED wxGEditorTabPanel::initWxVtkCanvas 1\n");
95         }
96
97         //=========================================================================
98
99         bool wxGEditorTabPanel::OnDropText(wxCoord x, wxCoord y, const wxString& data)
100         {
101                 std::string packageName="";
102                 std::string boxType="";
103
104                 wxString foo( (data) );
105                 char str[150];
106                 strcpy( str, (const char*)foo.mb_str(wxConvUTF8) );
107
108                 char delims[] = ":";
109                  char *result = NULL;
110                  result = strtok( str, delims );
111                  packageName += result;
112
113                  result = strtok( NULL, delims );
114                  boxType += result;
115
116                 _sceneManager->createGBlackBox(x,y,packageName, boxType);
117                 saveTempandUpdate("drop box");
118           return true;
119         }
120
121         //=========================================================================
122         void wxGEditorTabPanel::saveTempandUpdate(const std::string &action)
123         {
124                 _panelsManager->saveTempandUpdate(action);
125         }
126         //=========================================================================
127
128         void wxGEditorTabPanel::setPanelsManager(wxTabPanelsManager* panelsManager)
129         {
130                 _panelsManager = panelsManager;
131         }
132
133         //=========================================================================
134
135         void wxGEditorTabPanel::displayBlackBoxInfo(std::string packageName, std::string boxName)
136         {
137                 _panelsManager->displayBlackBoxInfo(packageName,boxName);
138         }
139
140         //=========================================================================
141
142         void wxGEditorTabPanel::updateStatusBar(std::string textStatus)
143         {
144                 _panelsManager->updateStatusBar(textStatus);
145         }
146
147         //=========================================================================
148
149         std::string wxGEditorTabPanel::getDiagramBBS(bool wln)
150         {
151                 return _sceneManager->getDiagramBBS(wln);
152         }
153
154         //=========================================================================
155
156         std::string wxGEditorTabPanel::saveComplexBoxBBS()
157         {
158                 return _sceneManager->saveComplexBoxBBS();
159         }
160
161         //=========================================================================
162
163         void wxGEditorTabPanel::editBlackBox(GBlackBoxModel *bbmodel)
164         {
165                 _panelsManager->editBlackBox(bbmodel);
166         }
167
168         //=========================================================================
169
170         void wxGEditorTabPanel::deleteAllBoxes()
171         {
172                 _sceneManager->deleteAllBoxes();
173         }
174
175         //=========================================================================
176
177         void wxGEditorTabPanel::centerView()
178         {
179                 if(_sceneManager)
180                 {
181                         _sceneManager->centerView();
182                 }
183         }
184
185         //=========================================================================
186
187         void wxGEditorTabPanel::saveDiagram(std::string &content, const std::string &path) //DFCH
188         {
189                 this->SetFullPath(path);
190                 _sceneManager->saveDiagram(content);
191         }
192
193         //=========================================================================
194
195         void wxGEditorTabPanel::saveTempDiagram(const std::string &action) //FCY
196         {
197                 std::string content = "";
198                 // writing file header
199                 content += "# ----------------------------------\n";
200                 content += "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file\n";
201                 content += "# - ";
202                 content += "temp";
203                 content += "\n";
204                 content += "# ----------------------------------\n";
205                 content += "\n";
206                 content += "APP_START\n";
207                 _sceneManager->saveDiagram(content);
208                 content += "APP_END\n"; //put here to avoid mistakes
209                 if(_actualdo == states.end() ) // same size, write to the end
210                 {
211                         states.push_back (content);
212                         saveStringAction(action);
213                 }
214                 else
215                 {
216                         std::vector<std::string>::iterator it = _actualdo+1;
217                         states.erase(it, states.end());
218                         states.push_back(content);
219
220                         std::vector<std::string>::iterator sit = _sactualdo+1;
221                         sstates.erase(sit, sstates.end());
222                         saveStringAction(action);
223                 }
224                 _actualdo = states.end();
225                 _sactualdo = sstates.end();
226                         
227         }
228
229         //=========================================================================
230
231         void wxGEditorTabPanel::loadDiagram(ifstream &inputStream, const std::string &path) //DFCH
232         {
233                 this->SetFullPath(path);
234                 stringstream ss;
235                 ss << inputStream.rdbuf() ;
236                 _sceneManager->loadDiagram(ss);
237         }
238
239         //=========================================================================
240         unsigned short wxGEditorTabPanel::getUndoState( std::string &stun)
241         {
242                 stun = "Undo";
243                 if(states.size()>0)
244                 {
245                         if(_actualdo == states.begin() )
246                         {
247                                 
248                                 return 0;
249                         }
250                         else
251                         {
252                                 stun +=" - ";
253                                 stun += _sactualdo->substr(0,(--_sactualdo)->find_last_of("."));
254                                 _sactualdo++;
255                                 return 1;
256                         }
257                 }
258         }
259
260         unsigned short wxGEditorTabPanel::getRedoState( std::string &stre)
261         {
262                 stre = "Redo";
263                 if(states.size()>0)
264                 {
265                         if(_actualdo == --states.end() || states.size() == 1 || _actualdo == states.end())
266                                 return 0;
267                         else
268                         {
269                                 stre +=" - ";
270                                 stre += _sactualdo->substr(0,(++_sactualdo)->find_last_of("."));
271                                 --_sactualdo;
272                                 return 1;
273                         }
274                 }
275         }
276
277         //=========================================================================
278         void wxGEditorTabPanel::loadTempDiagram(unsigned short un) //FCY
279         {
280                 unsigned short res = 1;
281                 deleteAllBoxes();
282                 std::stringstream ss;
283                 if (un == 0) //undo
284                 {
285                         if(_actualdo == states.end() ) // same size, write to the end
286                         {
287                                 (_actualdo--);
288                                 (_sactualdo--);
289                         }
290                         if(_actualdo != states.begin() )
291                         {
292                                 ss << *(--_actualdo);
293                                 _sactualdo--;
294                         }
295                         else
296                         {
297                                 ss << *_actualdo;
298                                 res = 0;
299                         }
300                 }
301                 else //redo
302                 {
303                         _actualdo++;
304                         _sactualdo++;
305                         if(_actualdo != states.end())
306                         {
307                                 ss << *_actualdo;
308                         }
309                         else
310                         {
311                                 res = 0;
312                         }
313                 }
314                 _sceneManager->loadDiagram(ss);
315         
316         }
317
318         void wxGEditorTabPanel::saveStringAction(const std::string &action)
319         {
320                 char temp[50];
321                 sprintf(temp,".%d", sstates.size());
322                 sstates.push_back(action + temp);
323         }
324
325         //=========================================================================
326
327         int wxGEditorTabPanel::getPanelId()
328         {
329                 return _id;
330         }
331         
332
333
334         //=========================================================================
335
336         bool wxGEditorTabPanel::isComplexBox()
337         {
338                 return _sceneManager->isComplexBox();
339         }
340
341         //=========================================================================
342
343         void wxGEditorTabPanel::setComplexBox(bool val)
344         {
345                 _sceneManager->setComplexBox(val);
346         }
347
348         //=========================================================================
349
350         void wxGEditorTabPanel::addComplexInputPort(std::string portName)
351         {
352                 _sceneManager->createGComplexBoxInputPort(portName);
353         }
354
355         //=========================================================================
356
357         void wxGEditorTabPanel::addComplexOutputPort(std::string portName)
358         {
359                 _sceneManager->createGComplexBoxOutputPort(portName);
360         }
361
362         //=========================================================================
363
364         std::map<int,GObjectController*> wxGEditorTabPanel::getSelectedObjects()
365         {
366                 return _sceneManager->getSelectedObjects();
367         }
368
369         //=========================================================================
370
371         void wxGEditorTabPanel::addObjects(std::map<int,GObjectController*> objectsMap)
372         {
373                 _sceneManager->addObjects(objectsMap);
374         }
375
376         //=========================================================================
377
378         int wxGEditorTabPanel::getNumSelectedObjects()
379         {
380                 return _sceneManager->getNumSelectedObjects();
381         }
382
383         //=========================================================================
384
385
386         wxVtkSceneManager* wxGEditorTabPanel::getSceneManager()
387         {
388                 return _sceneManager;
389         }
390
391         //=========================================================================
392     std::string wxGEditorTabPanel::GetCbName()
393         {
394             return _sceneManager->GetCbName();
395         }
396
397
398         //=========================================================================
399     std::string wxGEditorTabPanel::GetCbPackageName()
400         {
401             return _sceneManager->GetCbPackageName();
402         }
403
404         //=========================================================================
405     std::string wxGEditorTabPanel::GetAuthor()
406         {
407             return _sceneManager->GetAuthor();
408         }
409
410         //=========================================================================
411     std::string wxGEditorTabPanel::GetDescription()
412         {
413             return _sceneManager->GetDescription();
414         }
415
416         //=========================================================================
417     std::string wxGEditorTabPanel::GetCategory()
418         {
419             return _sceneManager->GetCategory();
420         }
421
422         //=========================================================================
423     void wxGEditorTabPanel::SetCbName(std::string cbName)
424     {
425         _sceneManager->SetCbName( cbName );
426     }
427
428         //=========================================================================
429     void wxGEditorTabPanel::SetCbPackageName(std::string packagename)
430     {
431         _sceneManager->SetCbPackageName( packagename );
432     }
433
434
435         //=========================================================================
436     void wxGEditorTabPanel::SetAuthor(std::string author)
437     {
438         _sceneManager->SetAuthor( author );
439     }
440
441
442         //=========================================================================
443     void wxGEditorTabPanel::SetCategory(std::string category)
444     {
445         _sceneManager->SetCategory( category );
446     }
447
448
449         //=========================================================================
450     void wxGEditorTabPanel::SetDescription(std::string description)
451     {
452         _sceneManager->SetDescription( description );
453     }
454     //=========================================================================
455         //DFCH
456         void wxGEditorTabPanel::SetFullPath( const std::string& fullpath )
457         {
458                 this->_fullPath = fullpath;
459         }
460         //=========================================================================
461         //DFCH
462         void wxGEditorTabPanel::SetFileName( const std::string& filename )
463         {
464                 this->_fileName = filename;
465         }
466         //=========================================================================
467         //DFCH
468         std::string wxGEditorTabPanel::GetFullPath( )
469         {
470                 return( this->_fullPath );
471         }
472         //=========================================================================
473         //DFCH
474     std::string wxGEditorTabPanel::GetFileName( )
475     {
476                 return( this->_fileName );
477         }
478
479
480
481
482 }  // EO namespace bbtk
483
484 // EOF