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