2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
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.
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
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 # ------------------------------------------------------------------------
26 /*=========================================================================
32 =========================================================================*/
34 /* ---------------------------------------------------------------------
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
58 * \brief Class bbtk::wxGEditorTabPanel .
62 #include "wxGEditorTabPanel.h"
68 //=========================================================================
69 wxGEditorTabPanel::wxGEditorTabPanel()
71 printf ("EED %p wxGEditorTabPanel 1 ()\n" , this );
74 //=========================================================================
75 wxGEditorTabPanel::wxGEditorTabPanel(wxWindow *parent,int id, Factory::Pointer bbtkfactory)
76 : wxPanel(parent),wxTextDropTarget()
79 _panelAUIMgr = new wxAuiManager(this);
81 _actualdo = states.begin();
82 _sactualdo = sstates.begin();
83 _bbtkfactory = bbtkfactory;
87 //=========================================================================
88 wxGEditorTabPanel::~wxGEditorTabPanel()
90 //ED02JUIN2010 _sceneManager->disconnectDrop();
92 _panelsManager->VerifyLastTabPanel();
98 //=========================================================================
99 void wxGEditorTabPanel::initWxVtkCanvas()
101 wxVtk3DBaseView *baseview = new wxVtk3DBaseView(this,NULL);
102 baseview->Configure();
104 baseview->GetCamera()->SetViewUp (0, 1, 0);
105 baseview->GetCamera()->SetPosition (0, 0, 1);
106 baseview->GetCamera()->SetFocalPoint (0, 0, 0);
108 //EED 15 oct 2012 _sceneManager=new wxVtkSceneManager(this,baseview,_id);
109 _sceneManager=new wxVtkSceneManager(this,baseview,_id, _bbtkfactory);
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());
116 _panelAUIMgr->Update();
119 //=========================================================================
121 bool wxGEditorTabPanel::OnDropText(wxCoord x, wxCoord y, const wxString& data)
126 * To handle bbs and bbg:
127 * handle data parameter to detect if incoming string is file or bbs or
130 * For a drag and drop tutorial read:
131 * http://zetcode.com/gui/wxwidgets/dragdrop/
134 //wxMessageBox(data);
136 std::string stdData = crea::wx2std(data);
138 //std::cout << "Text drop: '" << stdData << "'" << std::endl;
140 if(stdData.substr(0,4) == "box:")
142 int posT = stdData.find_first_of(':', 4);
143 std::string packageName = stdData.substr(4, posT-4);
144 posT = stdData.find_first_not_of(':', posT);
145 std::string boxType = stdData.substr(posT);
147 //std::cout << "box: Package='" << packageName << "' BoxType='" << boxType << "'" <<std::endl;
149 wxString foo( (data) );
151 strcpy( str, (const char*)foo.mb_str(wxConvUTF8) );
155 result = strtok( str, delims );
156 packageName += result;
158 result = strtok( NULL, delims );
161 if ( _panelsManager->TryToOpenScriptApplication(packageName,boxType) == false )
163 _sceneManager->createGBlackBox(x,y,packageName, boxType);
164 saveTempandUpdate("drop box");
167 // DFGO: file for linux
168 else if(stdData.substr(0,5) == "file:")
170 stdData=stdData.substr(0,stdData.size()-1);
171 std::cout << "Dropped file: " << stdData << std::endl;
172 std::stringstream ss(stdData);
173 std::getline(ss, stdData, (char)13);
176 std::string filePath = stdData.substr(7);
177 std::cout << filePath << ": ";
179 FILE *ff=fopen(filePath.c_str(),"r");
181 // wxFile::Exists( crea::std2wx(filePath))
186 std::cout << "File Exists." << std::endl;
187 wxFileName fileToOpen(crea::std2wx(filePath));
189 std::string filetype = crea::wx2std(fileToOpen.GetExt());
190 std::string filename = crea::wx2std(fileToOpen.GetFullName());
191 std::string filepath = crea::wx2std(fileToOpen.GetFullPath());
194 if(filetype == "bbs")
196 std::cout << "Importing bbs file." << std::endl;
197 wxMessageBox(crea::std2wx("You are opening a bbs file, "
198 "make sure not to overwrite an existing bbg file "
199 "when saving the pipeline."),
200 crea::std2wx("Opening File Warning"), wxICON_INFORMATION);
201 this->_panelsManager->GetParentGUIEditorGraphicBBS()->OpenBBS(filepath, filename);
203 else if(filetype == "bbg")
205 std::cout << "Opening bbg file." << std::endl;
206 this->_panelsManager->GetParentGUIEditorGraphicBBS()->OpenDiagram(filepath, filename);
210 std::cout << "Unknown file type: Can't open this kind of file: " << filetype << std::endl;
215 std::cout << "File Doesn't Exists. The given path is invalid: " << filePath << std::endl;
217 std::getline(ss, stdData, (char)13);
224 //=========================================================================
225 void wxGEditorTabPanel::saveTempandUpdate(const std::string &action)
227 _panelsManager->saveTempandUpdate(action);
229 //=========================================================================
231 void wxGEditorTabPanel::setPanelsManager(wxTabPanelsManager* panelsManager)
233 _panelsManager = panelsManager;
236 //=========================================================================
238 void wxGEditorTabPanel::displayBlackBoxInfo(std::string packageName, std::string boxName)
240 _panelsManager->displayBlackBoxInfo(packageName,boxName);
243 //=========================================================================
245 void wxGEditorTabPanel::updateStatusBar(std::string textStatus)
247 _panelsManager->updateStatusBar(textStatus);
250 //=========================================================================
252 std::string wxGEditorTabPanel::getDiagramBBS(bool wln)
254 return _sceneManager->getDiagramBBS(wln);
257 //=========================================================================
259 std::string wxGEditorTabPanel::saveComplexBoxBBS()
261 return _sceneManager->saveComplexBoxBBS();
264 //=========================================================================
266 void wxGEditorTabPanel::editBlackBox(GBlackBoxModel *bbmodel)
268 _panelsManager->editBlackBox(bbmodel);
271 //=========================================================================
273 void wxGEditorTabPanel::deleteAllBoxes()
275 _sceneManager->deleteAllBoxes();
278 //=========================================================================
280 void wxGEditorTabPanel::centerView()
284 _sceneManager->centerView();
288 //=========================================================================
290 void wxGEditorTabPanel::saveDiagram(std::string &content, const std::string &path) //DFCH
292 this->SetFullPath(path);
293 _sceneManager->saveDiagram(content);
296 //=========================================================================
298 void wxGEditorTabPanel::saveTempDiagram(const std::string &action) //FCY
300 std::string content = "";
301 // writing file header
302 content += "# ----------------------------------\n";
303 content += "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file\n";
307 content += "# ----------------------------------\n";
309 content += "APP_START\n";
310 _sceneManager->saveDiagram(content);
311 content += "APP_END\n"; //put here to avoid mistakes
312 if(_actualdo == states.end() ) // same size, write to the end
314 states.push_back (content);
315 saveStringAction(action);
319 std::vector<std::string>::iterator it = _actualdo+1;
320 states.erase(it, states.end());
321 states.push_back(content);
323 std::vector<std::string>::iterator sit = _sactualdo+1;
324 sstates.erase(sit, sstates.end());
325 saveStringAction(action);
327 _actualdo = states.end();
328 _sactualdo = sstates.end();
332 //=========================================================================
334 void wxGEditorTabPanel::loadDiagram(ifstream &inputStream, const std::string &path) //DFCH
336 this->SetFullPath(path);
338 ss << inputStream.rdbuf() ;
339 _sceneManager->loadDiagram(ss);
342 //=========================================================================
343 unsigned short wxGEditorTabPanel::getUndoState( std::string &stun)
348 if(_actualdo == states.begin() )
356 stun += _sactualdo->substr(0,(--_sactualdo)->find_last_of("."));
363 unsigned short wxGEditorTabPanel::getRedoState( std::string &stre)
368 if(_actualdo == --states.end() || states.size() == 1 || _actualdo == states.end())
373 stre += _sactualdo->substr(0,(++_sactualdo)->find_last_of("."));
380 //=========================================================================
381 void wxGEditorTabPanel::loadTempDiagram(unsigned short un) //FCY
383 unsigned short res = 1;
385 std::stringstream ss;
388 if(_actualdo == states.end() ) // same size, write to the end
393 if(_actualdo != states.begin() )
395 ss << *(--_actualdo);
408 if(_actualdo != states.end())
417 _sceneManager->loadDiagram(ss);
421 void wxGEditorTabPanel::saveStringAction(const std::string &action)
424 sprintf(temp,".%d", sstates.size());
425 sstates.push_back(action + temp);
428 //=========================================================================
430 int wxGEditorTabPanel::getPanelId()
437 //=========================================================================
439 bool wxGEditorTabPanel::isComplexBox()
441 return _sceneManager->isComplexBox();
444 //=========================================================================
446 void wxGEditorTabPanel::setComplexBox(bool val)
448 _sceneManager->setComplexBox(val);
451 //=========================================================================
453 void wxGEditorTabPanel::addComplexInputPort(std::string portName)
455 _sceneManager->createGComplexBoxInputPort(portName);
458 //=========================================================================
460 void wxGEditorTabPanel::addComplexOutputPort(std::string portName)
462 _sceneManager->createGComplexBoxOutputPort(portName);
465 //=========================================================================
467 std::map<int,GObjectController*> wxGEditorTabPanel::getSelectedObjects()
469 return _sceneManager->getSelectedObjects();
472 //=========================================================================
474 void wxGEditorTabPanel::addObjects(std::map<int,GObjectController*> objectsMap)
476 _sceneManager->addObjects(objectsMap);
479 //=========================================================================
481 int wxGEditorTabPanel::getNumSelectedObjects()
483 return _sceneManager->getNumSelectedObjects();
486 //=========================================================================
489 wxVtkSceneManager* wxGEditorTabPanel::getSceneManager()
491 return _sceneManager;
494 //=========================================================================
495 std::string wxGEditorTabPanel::GetCbName()
497 return _sceneManager->GetCbName();
501 //=========================================================================
502 std::string wxGEditorTabPanel::GetCbPackageName()
504 return _sceneManager->GetCbPackageName();
507 //=========================================================================
508 std::string wxGEditorTabPanel::GetAuthor()
510 return _sceneManager->GetAuthor();
513 //=========================================================================
514 std::string wxGEditorTabPanel::GetDescription()
516 return _sceneManager->GetDescription();
519 //=========================================================================
520 std::string wxGEditorTabPanel::GetCategory()
522 return _sceneManager->GetCategory();
524 //=========================================================================
525 std::string wxGEditorTabPanel::GetMessageKind()
527 return _sceneManager->GetMessageKind();
529 //=========================================================================
530 std::string wxGEditorTabPanel::GetMessageLevel()
532 return _sceneManager->GetMessageLevel();
535 //=========================================================================
536 void wxGEditorTabPanel::SetCbName(std::string cbName)
538 _sceneManager->SetCbName( cbName );
541 //=========================================================================
542 void wxGEditorTabPanel::SetCbPackageName(std::string packagename)
544 _sceneManager->SetCbPackageName( packagename );
548 //=========================================================================
549 void wxGEditorTabPanel::SetAuthor(std::string author)
551 _sceneManager->SetAuthor( author );
555 //=========================================================================
556 void wxGEditorTabPanel::SetCategory(std::string category)
558 _sceneManager->SetCategory( category );
562 //=========================================================================
563 void wxGEditorTabPanel::SetDescription(std::string description)
565 _sceneManager->SetDescription( description );
568 //=========================================================================
569 void wxGEditorTabPanel::SetMessageKind(std::string kind)
571 _sceneManager->SetMessageKind( kind );
574 //=========================================================================
575 void wxGEditorTabPanel::SetMessageLevel(std::string level)
577 _sceneManager->SetMessageLevel( level );
579 //=========================================================================
581 void wxGEditorTabPanel::SetFullPath( const std::string& fullpath )
583 this->_fullPath = fullpath;
585 //=========================================================================
587 void wxGEditorTabPanel::SetFileName( const std::string& filename )
589 this->_fileName = filename;
591 //=========================================================================
593 std::string wxGEditorTabPanel::GetFullPath( )
595 return( this->_fullPath );
597 //=========================================================================
599 std::string wxGEditorTabPanel::GetFileName( )
601 return( this->_fileName );
607 } // EO namespace bbtk