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