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