]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxGEditorTabPanel.cxx
Feature #1771 Add licence terms for all files.
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxGEditorTabPanel.cxx
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 #
8 #  This software is governed by the CeCILL-B license under French law and 
9 #  abiding by the rules of distribution of free software. You can  use, 
10 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
11 #  license as circulated by CEA, CNRS and INRIA at the following URL 
12 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
13 #  or in the file LICENSE.txt.
14 #
15 #  As a counterpart to the access to the source code and  rights to copy,
16 #  modify and redistribute granted by the license, users are provided only
17 #  with a limited warranty  and the software's author,  the holder of the
18 #  economic rights,  and the successive licensors  have only  limited
19 #  liability. 
20 #
21 #  The fact that you are presently reading this means that you have had
22 #  knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------  
24 */
25
26 /*=========================================================================
27 Program:   bbtk
28 Module:    $RCSfile$
29 Language:  C++
30 Date:      $Date$
31 Version:   $Revision$
32 =========================================================================*/
33
34 /* ---------------------------------------------------------------------
35
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
38 *
39 *  This software is governed by the CeCILL-B license under French law and
40 *  abiding by the rules of distribution of free software. You can  use,
41 *  modify and/ or redistribute the software under the terms of the CeCILL-B
42 *  license as circulated by CEA, CNRS and INRIA at the following URL
43 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
44 *  or in the file LICENSE.txt.
45 *
46 *  As a counterpart to the access to the source code and  rights to copy,
47 *  modify and redistribute granted by the license, users are provided only
48 *  with a limited warranty  and the software's author,  the holder of the
49 *  economic rights,  and the successive licensors  have only  limited
50 *  liability.
51 *
52 *  The fact that you are presently reading this means that you have had
53 *  knowledge of the CeCILL-B license and that you accept its terms.
54 * ------------------------------------------------------------------------ */
55
56 /**
57 *  \file
58 *  \brief Class bbtk::wxGEditorTabPanel .
59 */
60
61
62 #include "wxGEditorTabPanel.h"
63 #include "creaWx.h"
64
65 namespace bbtk
66 {
67
68         //=========================================================================
69         wxGEditorTabPanel::wxGEditorTabPanel()
70         {
71                 printf ("EED %p wxGEditorTabPanel 1 ()\n" , this );
72         }
73
74         //=========================================================================
75         wxGEditorTabPanel::wxGEditorTabPanel(wxWindow *parent,int id, Factory::Pointer bbtkfactory)
76          : wxPanel(parent),wxTextDropTarget()
77         {
78                 _id=id;
79                 _panelAUIMgr    = new wxAuiManager(this);
80                 _sceneManager   = NULL;
81                 _actualdo               = states.begin();
82                 _sactualdo              = sstates.begin();
83                 _bbtkfactory    = bbtkfactory;
84                 initWxVtkCanvas();
85         }
86
87         //=========================================================================
88         wxGEditorTabPanel::~wxGEditorTabPanel()
89         {
90 //ED02JUIN2010          _sceneManager->disconnectDrop();
91
92         _panelsManager->VerifyLastTabPanel();
93                 //FCY memory leaks
94                 delete _panelAUIMgr;
95                 delete _sceneManager;
96         }
97
98         //=========================================================================
99         void wxGEditorTabPanel::initWxVtkCanvas()
100         {
101                 wxVtk3DBaseView *baseview = new wxVtk3DBaseView(this);
102                 baseview->Configure();
103 //EED 15 oct 2012               _sceneManager=new wxVtkSceneManager(this,baseview,_id);
104                 _sceneManager=new wxVtkSceneManager(this,baseview,_id, _bbtkfactory);
105
106
107 //EED02JUIN2010
108                 printf("RaC-EED 21-06-2010 wxGEditorTabPanel::initWxVtkCanvas Remove the panelAUIMgr, and change to a normal sizer inside the wxGEditorTabPanel\n");
109                 _panelAUIMgr->AddPane((wxWindow*)baseview->GetWxVTKRenderWindowInteractor(),wxAuiPaneInfo().Fixed().CenterPane());
110
111                 _panelAUIMgr->Update();
112         }
113
114         //=========================================================================
115
116         bool wxGEditorTabPanel::OnDropText(wxCoord x, wxCoord y, const wxString& data)
117         {
118                 std::string packageName="";
119                 std::string boxType="";
120
121                 wxString foo( (data) );
122                 char str[150];
123                 strcpy( str, (const char*)foo.mb_str(wxConvUTF8) );
124
125                 char delims[] = ":";
126                  char *result = NULL;
127                  result = strtok( str, delims );
128                  packageName += result;
129
130                  result = strtok( NULL, delims );
131                  boxType += result;
132
133                 if ( _panelsManager->TryToOpenScriptApplication(packageName,boxType) == false )
134                 {
135                         _sceneManager->createGBlackBox(x,y,packageName, boxType);
136                         saveTempandUpdate("drop box");
137                 }               
138           return true;
139         }
140
141         //=========================================================================
142         void wxGEditorTabPanel::saveTempandUpdate(const std::string &action)
143         {
144                 _panelsManager->saveTempandUpdate(action);
145         }
146         //=========================================================================
147
148         void wxGEditorTabPanel::setPanelsManager(wxTabPanelsManager* panelsManager)
149         {
150                 _panelsManager = panelsManager;
151         }
152
153         //=========================================================================
154
155         void wxGEditorTabPanel::displayBlackBoxInfo(std::string packageName, std::string boxName)
156         {
157                 _panelsManager->displayBlackBoxInfo(packageName,boxName);
158         }
159
160         //=========================================================================
161
162         void wxGEditorTabPanel::updateStatusBar(std::string textStatus)
163         {
164                 _panelsManager->updateStatusBar(textStatus);
165         }
166
167         //=========================================================================
168
169         std::string wxGEditorTabPanel::getDiagramBBS(bool wln)
170         {
171                 return _sceneManager->getDiagramBBS(wln);
172         }
173
174         //=========================================================================
175
176         std::string wxGEditorTabPanel::saveComplexBoxBBS()
177         {
178                 return _sceneManager->saveComplexBoxBBS();
179         }
180
181         //=========================================================================
182
183         void wxGEditorTabPanel::editBlackBox(GBlackBoxModel *bbmodel)
184         {
185                 _panelsManager->editBlackBox(bbmodel);
186         }
187
188         //=========================================================================
189
190         void wxGEditorTabPanel::deleteAllBoxes()
191         {
192                 _sceneManager->deleteAllBoxes();
193         }
194
195         //=========================================================================
196
197         void wxGEditorTabPanel::centerView()
198         {
199                 if(_sceneManager)
200                 {
201                         _sceneManager->centerView();
202                 }
203         }
204
205         //=========================================================================
206
207         void wxGEditorTabPanel::saveDiagram(std::string &content, const std::string &path) //DFCH
208         {
209                 this->SetFullPath(path);
210                 _sceneManager->saveDiagram(content);
211         }
212
213         //=========================================================================
214
215         void wxGEditorTabPanel::saveTempDiagram(const std::string &action) //FCY
216         {
217                 std::string content = "";
218                 // writing file header
219                 content += "# ----------------------------------\n";
220                 content += "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file\n";
221                 content += "# - ";
222                 content += "temp";
223                 content += "\n";
224                 content += "# ----------------------------------\n";
225                 content += "\n";
226                 content += "APP_START\n";
227                 _sceneManager->saveDiagram(content);
228                 content += "APP_END\n"; //put here to avoid mistakes
229                 if(_actualdo == states.end() ) // same size, write to the end
230                 {
231                         states.push_back (content);
232                         saveStringAction(action);
233                 }
234                 else
235                 {
236                         std::vector<std::string>::iterator it = _actualdo+1;
237                         states.erase(it, states.end());
238                         states.push_back(content);
239
240                         std::vector<std::string>::iterator sit = _sactualdo+1;
241                         sstates.erase(sit, sstates.end());
242                         saveStringAction(action);
243                 }
244                 _actualdo = states.end();
245                 _sactualdo = sstates.end();
246                         
247         }
248
249         //=========================================================================
250
251         void wxGEditorTabPanel::loadDiagram(ifstream &inputStream, const std::string &path) //DFCH
252         {
253                 this->SetFullPath(path);
254                 stringstream ss;
255                 ss << inputStream.rdbuf() ;
256                 _sceneManager->loadDiagram(ss);
257         }
258
259         //=========================================================================
260         unsigned short wxGEditorTabPanel::getUndoState( std::string &stun)
261         {
262                 stun = "Undo";
263                 if(states.size()>0)
264                 {
265                         if(_actualdo == states.begin() )
266                         {
267                                 
268                                 return 0;
269                         }
270                         else
271                         {
272                                 stun +=" - ";
273                                 stun += _sactualdo->substr(0,(--_sactualdo)->find_last_of("."));
274                                 _sactualdo++;
275                                 return 1;
276                         }
277                 }
278         }
279
280         unsigned short wxGEditorTabPanel::getRedoState( std::string &stre)
281         {
282                 stre = "Redo";
283                 if(states.size()>0)
284                 {
285                         if(_actualdo == --states.end() || states.size() == 1 || _actualdo == states.end())
286                                 return 0;
287                         else
288                         {
289                                 stre +=" - ";
290                                 stre += _sactualdo->substr(0,(++_sactualdo)->find_last_of("."));
291                                 --_sactualdo;
292                                 return 1;
293                         }
294                 }
295         }
296
297         //=========================================================================
298         void wxGEditorTabPanel::loadTempDiagram(unsigned short un) //FCY
299         {
300                 unsigned short res = 1;
301                 deleteAllBoxes();
302                 std::stringstream ss;
303                 if (un == 0) //undo
304                 {
305                         if(_actualdo == states.end() ) // same size, write to the end
306                         {
307                                 (_actualdo--);
308                                 (_sactualdo--);
309                         }
310                         if(_actualdo != states.begin() )
311                         {
312                                 ss << *(--_actualdo);
313                                 _sactualdo--;
314                         }
315                         else
316                         {
317                                 ss << *_actualdo;
318                                 res = 0;
319                         }
320                 }
321                 else //redo
322                 {
323                         _actualdo++;
324                         _sactualdo++;
325                         if(_actualdo != states.end())
326                         {
327                                 ss << *_actualdo;
328                         }
329                         else
330                         {
331                                 res = 0;
332                         }
333                 }
334                 _sceneManager->loadDiagram(ss);
335         
336         }
337
338         void wxGEditorTabPanel::saveStringAction(const std::string &action)
339         {
340                 char temp[50];
341                 sprintf(temp,".%d", sstates.size());
342                 sstates.push_back(action + temp);
343         }
344
345         //=========================================================================
346
347         int wxGEditorTabPanel::getPanelId()
348         {
349                 return _id;
350         }
351         
352
353
354         //=========================================================================
355
356         bool wxGEditorTabPanel::isComplexBox()
357         {
358                 return _sceneManager->isComplexBox();
359         }
360
361         //=========================================================================
362
363         void wxGEditorTabPanel::setComplexBox(bool val)
364         {
365                 _sceneManager->setComplexBox(val);
366         }
367
368         //=========================================================================
369
370         void wxGEditorTabPanel::addComplexInputPort(std::string portName)
371         {
372                 _sceneManager->createGComplexBoxInputPort(portName);
373         }
374
375         //=========================================================================
376
377         void wxGEditorTabPanel::addComplexOutputPort(std::string portName)
378         {
379                 _sceneManager->createGComplexBoxOutputPort(portName);
380         }
381
382         //=========================================================================
383
384         std::map<int,GObjectController*> wxGEditorTabPanel::getSelectedObjects()
385         {
386                 return _sceneManager->getSelectedObjects();
387         }
388
389         //=========================================================================
390
391         void wxGEditorTabPanel::addObjects(std::map<int,GObjectController*> objectsMap)
392         {
393                 _sceneManager->addObjects(objectsMap);
394         }
395
396         //=========================================================================
397
398         int wxGEditorTabPanel::getNumSelectedObjects()
399         {
400                 return _sceneManager->getNumSelectedObjects();
401         }
402
403         //=========================================================================
404
405
406         wxVtkSceneManager* wxGEditorTabPanel::getSceneManager()
407         {
408                 return _sceneManager;
409         }
410
411         //=========================================================================
412     std::string wxGEditorTabPanel::GetCbName()
413         {
414             return _sceneManager->GetCbName();
415         }
416
417
418         //=========================================================================
419     std::string wxGEditorTabPanel::GetCbPackageName()
420         {
421             return _sceneManager->GetCbPackageName();
422         }
423
424         //=========================================================================
425     std::string wxGEditorTabPanel::GetAuthor()
426         {
427             return _sceneManager->GetAuthor();
428         }
429
430         //=========================================================================
431     std::string wxGEditorTabPanel::GetDescription()
432         {
433             return _sceneManager->GetDescription();
434         }
435
436         //=========================================================================
437     std::string wxGEditorTabPanel::GetCategory()
438         {
439             return _sceneManager->GetCategory();
440         }
441
442         //=========================================================================
443     void wxGEditorTabPanel::SetCbName(std::string cbName)
444     {
445         _sceneManager->SetCbName( cbName );
446     }
447
448         //=========================================================================
449     void wxGEditorTabPanel::SetCbPackageName(std::string packagename)
450     {
451         _sceneManager->SetCbPackageName( packagename );
452     }
453
454
455         //=========================================================================
456     void wxGEditorTabPanel::SetAuthor(std::string author)
457     {
458         _sceneManager->SetAuthor( author );
459     }
460
461
462         //=========================================================================
463     void wxGEditorTabPanel::SetCategory(std::string category)
464     {
465         _sceneManager->SetCategory( category );
466     }
467
468
469         //=========================================================================
470     void wxGEditorTabPanel::SetDescription(std::string description)
471     {
472         _sceneManager->SetDescription( description );
473     }
474     //=========================================================================
475         //DFCH
476         void wxGEditorTabPanel::SetFullPath( const std::string& fullpath )
477         {
478                 this->_fullPath = fullpath;
479         }
480         //=========================================================================
481         //DFCH
482         void wxGEditorTabPanel::SetFileName( const std::string& filename )
483         {
484                 this->_fileName = filename;
485         }
486         //=========================================================================
487         //DFCH
488         std::string wxGEditorTabPanel::GetFullPath( )
489         {
490                 return( this->_fullPath );
491         }
492         //=========================================================================
493         //DFCH
494     std::string wxGEditorTabPanel::GetFileName( )
495     {
496                 return( this->_fileName );
497         }
498
499
500
501
502 }  // EO namespace bbtk
503
504 // EOF