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