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