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