]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxGEditorTabPanel.cxx
#3213 bbGEditor Feature New Normal - vtk8itk4wx3-mingw64 MACOS
[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,NULL);
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
124           /*
125            * DFGO
126            * To handle bbs and bbg:
127            * handle data parameter to detect if incoming string is file or bbs or
128            * bbg or blackbox.
129            *
130            * For a drag and drop tutorial read:
131            * http://zetcode.com/gui/wxwidgets/dragdrop/
132            */
133
134           //wxMessageBox(data);
135
136
137
138                 int posEndEED=data.find("<EndEED>");
139                 wxString data2( data.substr(0,posEndEED) );
140                 std::string stdData = crea::wx2std(data2);
141
142           if(stdData.substr(0,4) == "box:")
143             {
144               int posT = stdData.find_first_of(':', 4);
145               std::string packageName = stdData.substr(4, posT-4);
146               posT = stdData.find_first_not_of(':', posT);
147               std::string boxType = stdData.substr(posT, data.Len()-posT );
148               
149               //std::cout << "box: Package='" << packageName << "' BoxType='" << boxType << "'" <<std::endl;
150               /*
151                     wxString foo( (data) );
152                     char str[150];
153                     strcpy( str, (const char*)foo.mb_str(wxConvUTF8) );
154
155                     char delims[] = ":";
156                      char *result = NULL;
157                      result = strtok( str, delims );
158                      packageName += result;
159
160                      result = strtok( NULL, delims );
161                      boxType += result;
162                */
163             printf("EED wxGEditorTabPanel::OnDropText  <%s>  length %d %d \n", stdData.c_str(), stdData.length(), data.Len() ); 
164             printf("EED wxGEditorTabPanel::OnDropText  <%s>  wxString\n",(const char*)data.mb_str() ); 
165               if ( _panelsManager->TryToOpenScriptApplication(packageName,boxType) == false )
166                 {
167                   _sceneManager->createGBlackBox(x,y,packageName, boxType);
168                   saveTempandUpdate("drop box");
169                 }
170             }
171           // DFGO: file for linux
172           else if(stdData.substr(0,5) == "file:")
173             {
174               stdData=stdData.substr(0,stdData.size()-1);
175               std::cout << "Dropped file: " << stdData << std::endl;
176               std::stringstream ss(stdData);
177               std::getline(ss, stdData, (char)13);
178               while(!ss.eof())
179                 {
180                   std::string filePath = stdData.substr(7);
181                   std::cout << filePath << ": ";
182
183                           FILE *ff=fopen(filePath.c_str(),"r");
184                   if(
185 //                                wxFile::Exists( crea::std2wx(filePath)) 
186                                   ff!=NULL
187                                   )
188                     {
189                                   fclose(ff);
190                       std::cout << "File Exists." << std::endl;
191                       wxFileName fileToOpen(crea::std2wx(filePath));
192
193                       std::string filetype = crea::wx2std(fileToOpen.GetExt());
194                       std::string filename = crea::wx2std(fileToOpen.GetFullName());
195                       std::string filepath = crea::wx2std(fileToOpen.GetFullPath());
196
197
198                       if(filetype == "bbs")
199                         {
200                           std::cout << "Importing bbs file." << std::endl;
201                           wxMessageBox(crea::std2wx("You are opening a bbs file, "
202                               "make sure not to overwrite an existing bbg file "
203                               "when saving the pipeline."),
204                               crea::std2wx("Opening File Warning"), wxICON_INFORMATION);
205                           this->_panelsManager->GetParentGUIEditorGraphicBBS()->OpenBBS(filepath, filename);
206                         }
207                       else if(filetype == "bbg")
208                         {
209                           std::cout << "Opening bbg file." << std::endl;
210                           this->_panelsManager->GetParentGUIEditorGraphicBBS()->OpenDiagram(filepath, filename);
211                         }
212                       else
213                         {
214                           std::cout << "Unknown file type: Can't open this kind of file: " << filetype << std::endl;
215                         }
216                     }
217                   else
218                     {
219                       std::cout << "File Doesn't Exists. The given path is invalid: " << filePath << std::endl;
220                     }
221                   std::getline(ss, stdData, (char)13);
222                 }
223             }
224
225           return true;
226         }
227
228         //=========================================================================
229         void wxGEditorTabPanel::saveTempandUpdate(const std::string &action)
230         {
231                 _panelsManager->saveTempandUpdate(action);
232         }
233         //=========================================================================
234
235         void wxGEditorTabPanel::setPanelsManager(wxTabPanelsManager* panelsManager)
236         {
237                 _panelsManager = panelsManager;
238         }
239
240         //=========================================================================
241
242         void wxGEditorTabPanel::displayBlackBoxInfo(std::string packageName, std::string boxName)
243         {
244                 _panelsManager->displayBlackBoxInfo(packageName,boxName);
245         }
246
247         //=========================================================================
248
249         void wxGEditorTabPanel::updateStatusBar(std::string textStatus)
250         {
251                 _panelsManager->updateStatusBar(textStatus);
252         }
253
254         //=========================================================================
255
256         std::string wxGEditorTabPanel::getDiagramBBS(bool wln)
257         {
258                 return _sceneManager->getDiagramBBS(wln);
259         }
260
261         //=========================================================================
262
263         std::string wxGEditorTabPanel::saveComplexBoxBBS()
264         {
265                 return _sceneManager->saveComplexBoxBBS();
266         }
267
268         //=========================================================================
269
270         void wxGEditorTabPanel::editBlackBox(GBlackBoxModel *bbmodel)
271         {
272                 _panelsManager->editBlackBox(bbmodel);
273         }
274
275         //=========================================================================
276
277         void wxGEditorTabPanel::deleteAllBoxes()
278         {
279                 _sceneManager->deleteAllBoxes();
280         }
281
282         //=========================================================================
283
284         void wxGEditorTabPanel::centerView()
285         {
286                 if(_sceneManager)
287                 {
288                         _sceneManager->centerView();
289                 }
290         }
291
292         //=========================================================================
293
294         void wxGEditorTabPanel::saveDiagram(std::string &content, const std::string &path) //DFCH
295         {
296                 this->SetFullPath(path);
297                 _sceneManager->saveDiagram(content);
298         }
299
300         //=========================================================================
301
302         void wxGEditorTabPanel::saveTempDiagram(const std::string &action) //FCY
303         {
304                 std::string content = "";
305                 // writing file header
306                 content += "# ----------------------------------\n";
307                 content += "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file\n";
308                 content += "# - ";
309                 content += "temp";
310                 content += "\n";
311                 content += "# ----------------------------------\n";
312                 content += "\n";
313                 content += "APP_START\n";
314                 _sceneManager->saveDiagram(content);
315                 content += "APP_END\n"; //put here to avoid mistakes
316                 if(_actualdo == states.end() ) // same size, write to the end
317                 {
318                         states.push_back (content);
319                         saveStringAction(action);
320                 }
321                 else
322                 {
323                         std::vector<std::string>::iterator it = _actualdo+1;
324                         states.erase(it, states.end());
325                         states.push_back(content);
326
327                         std::vector<std::string>::iterator sit = _sactualdo+1;
328                         sstates.erase(sit, sstates.end());
329                         saveStringAction(action);
330                 }
331                 _actualdo = states.end();
332                 _sactualdo = sstates.end();
333                         
334         }
335
336         //=========================================================================
337
338         void wxGEditorTabPanel::loadDiagram(ifstream &inputStream, const std::string &path) //DFCH
339         {
340                 this->SetFullPath(path);
341                 stringstream ss;
342                 ss << inputStream.rdbuf() ;
343                 _sceneManager->loadDiagram(ss);
344         }
345
346         //=========================================================================
347         unsigned short wxGEditorTabPanel::getUndoState( std::string &stun)
348         {
349                 stun = "Undo";
350                 if(sstates.size()>0)
351                 {
352                         if(_actualdo == states.begin() )
353 //                      if(sstates.size()==1 )
354                         {
355 //                              _sactualdo=sstates.begin();
356                                 return 0;
357                         } else {
358                                 stun +=" - ";
359 printf("EED wxGEditorTabPanel::getUndoState This mecanisme is not working  ??????    _sactualdo sstates      _actualdo state \n");              
360 //                              stun += _sactualdo->substr(0,(--_sactualdo)->find_last_of("."));                                
361                                 _sactualdo++;
362                                 return 1;
363                         }
364                 }
365         return 0;
366         }
367
368         unsigned short wxGEditorTabPanel::getRedoState( std::string &stre)
369         {
370                 stre = "Redo";
371                 if(states.size()>0)
372                 {
373                         if(_actualdo == --states.end() || states.size() == 1 || _actualdo == states.end())
374                                 return 0;
375                         else
376                         {
377                                 stre +=" - ";
378                                 stre += _sactualdo->substr(0,(++_sactualdo)->find_last_of("."));
379                                 --_sactualdo;
380                                 return 1;
381                         }
382                 }
383         }
384
385         //=========================================================================
386         void wxGEditorTabPanel::loadTempDiagram(unsigned short un) //FCY
387         {
388                 unsigned short res = 1;
389                 deleteAllBoxes();
390                 std::stringstream ss;
391                 if (un == 0) //undo
392                 {
393                         if(_actualdo == states.end() ) // same size, write to the end
394                         {
395                                 (_actualdo--);
396                                 (_sactualdo--);
397                         }
398                         if(_actualdo != states.begin() )
399                         {
400                                 ss << *(--_actualdo);
401                                 _sactualdo--;
402                         }
403                         else
404                         {
405                                 ss << *_actualdo;
406                                 res = 0;
407                         }
408                 }
409                 else //redo
410                 {
411                         _actualdo++;
412                         _sactualdo++;
413                         if(_actualdo != states.end())
414                         {
415                                 ss << *_actualdo;
416                         }
417                         else
418                         {
419                                 res = 0;
420                         }
421                 }
422                 _sceneManager->loadDiagram(ss);
423         
424         }
425
426         void wxGEditorTabPanel::saveStringAction(const std::string &action)
427         {
428                 char temp[50];
429                 sprintf(temp,".%d", sstates.size());
430                 sstates.push_back(action + temp);
431         }
432
433         //=========================================================================
434
435         int wxGEditorTabPanel::getPanelId()
436         {
437                 return _id;
438         }
439         
440
441
442         //=========================================================================
443
444         bool wxGEditorTabPanel::isComplexBox()
445         {
446                 return _sceneManager->isComplexBox();
447         }
448
449         //=========================================================================
450
451         void wxGEditorTabPanel::setComplexBox(bool val)
452         {
453                 _sceneManager->setComplexBox(val);
454         }
455
456         //=========================================================================
457
458         void wxGEditorTabPanel::addComplexInputPort(std::string portName)
459         {
460                 _sceneManager->createGComplexBoxInputPort(portName);
461         }
462
463         //=========================================================================
464
465         void wxGEditorTabPanel::addComplexOutputPort(std::string portName)
466         {
467                 _sceneManager->createGComplexBoxOutputPort(portName);
468         }
469
470         //=========================================================================
471
472         std::map<int,GObjectController*> wxGEditorTabPanel::getSelectedObjects()
473         {
474                 return _sceneManager->getSelectedObjects();
475         }
476
477         //=========================================================================
478
479         void wxGEditorTabPanel::addObjects(std::map<int,GObjectController*> objectsMap)
480         {
481                 _sceneManager->addObjects(objectsMap);
482         }
483
484         //=========================================================================
485
486         int wxGEditorTabPanel::getNumSelectedObjects()
487         {
488                 return _sceneManager->getNumSelectedObjects();
489         }
490
491         //=========================================================================
492
493
494         wxVtkSceneManager* wxGEditorTabPanel::getSceneManager()
495         {
496                 return _sceneManager;
497         }
498
499         //=========================================================================
500     std::string wxGEditorTabPanel::GetCbName()
501         {
502             return _sceneManager->GetCbName();
503         }
504
505
506         //=========================================================================
507     std::string wxGEditorTabPanel::GetCbPackageName()
508         {
509             return _sceneManager->GetCbPackageName();
510         }
511
512         //=========================================================================
513     std::string wxGEditorTabPanel::GetAuthor()
514         {
515             return _sceneManager->GetAuthor();
516         }
517
518         //=========================================================================
519     std::string wxGEditorTabPanel::GetDescription()
520         {
521             return _sceneManager->GetDescription();
522         }
523
524         //=========================================================================
525     std::string wxGEditorTabPanel::GetCategory()
526         {
527             return _sceneManager->GetCategory();
528         }
529         //=========================================================================
530                 std::string wxGEditorTabPanel::GetMessageKind()
531                 {
532             return _sceneManager->GetMessageKind();
533                 }
534         //=========================================================================
535      std::string wxGEditorTabPanel::GetMessageLevel()
536                 {
537             return _sceneManager->GetMessageLevel();
538                 }
539
540         //=========================================================================
541     void wxGEditorTabPanel::SetCbName(std::string cbName)
542     {
543         _sceneManager->SetCbName( cbName );
544     }
545
546         //=========================================================================
547     void wxGEditorTabPanel::SetCbPackageName(std::string packagename)
548     {
549         _sceneManager->SetCbPackageName( packagename );
550     }
551
552
553         //=========================================================================
554     void wxGEditorTabPanel::SetAuthor(std::string author)
555     {
556         _sceneManager->SetAuthor( author );
557     }
558
559
560         //=========================================================================
561     void wxGEditorTabPanel::SetCategory(std::string category)
562     {
563         _sceneManager->SetCategory( category );
564     }
565
566
567         //=========================================================================
568     void wxGEditorTabPanel::SetDescription(std::string description)
569     {
570         _sceneManager->SetDescription( description );
571     }
572
573         //=========================================================================
574                 void wxGEditorTabPanel::SetMessageKind(std::string kind)
575                 {
576         _sceneManager->SetMessageKind( kind );
577     }
578
579         //=========================================================================    
580     void wxGEditorTabPanel::SetMessageLevel(std::string level)
581                 {
582         _sceneManager->SetMessageLevel( level );
583     }
584     //=========================================================================
585         //DFCH
586         void wxGEditorTabPanel::SetFullPath( const std::string& fullpath )
587         {
588                 this->_fullPath = fullpath;
589         }
590         //=========================================================================
591         //DFCH
592         void wxGEditorTabPanel::SetFileName( const std::string& filename )
593         {
594                 this->_fileName = filename;
595         }
596         //=========================================================================
597         //DFCH
598         std::string wxGEditorTabPanel::GetFullPath( )
599         {
600                 return( this->_fullPath );
601         }
602         //=========================================================================
603         //DFCH
604     std::string wxGEditorTabPanel::GetFileName( )
605     {
606                 return( this->_fileName );
607         }
608
609
610
611
612 }  // EO namespace bbtk
613
614 // EOF