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