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);
138 int posEndEED=data.find("<EndEED>");
139 wxString data2( data.substr(0,posEndEED) );
140 std::string stdData = crea::wx2std(data2);
142 if(stdData.substr(0,4) == "box:")
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 );
149 //std::cout << "box: Package='" << packageName << "' BoxType='" << boxType << "'" <<std::endl;
151 wxString foo( (data) );
153 strcpy( str, (const char*)foo.mb_str(wxConvUTF8) );
157 result = strtok( str, delims );
158 packageName += result;
160 result = strtok( NULL, delims );
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 )
167 _sceneManager->createGBlackBox(x,y,packageName, boxType);
168 saveTempandUpdate("drop box");
171 // DFGO: file for linux
172 else if(stdData.substr(0,5) == "file:")
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);
180 std::string filePath = stdData.substr(7);
181 std::cout << filePath << ": ";
183 FILE *ff=fopen(filePath.c_str(),"r");
185 // wxFile::Exists( crea::std2wx(filePath))
190 std::cout << "File Exists." << std::endl;
191 wxFileName fileToOpen(crea::std2wx(filePath));
193 std::string filetype = crea::wx2std(fileToOpen.GetExt());
194 std::string filename = crea::wx2std(fileToOpen.GetFullName());
195 std::string filepath = crea::wx2std(fileToOpen.GetFullPath());
198 if(filetype == "bbs")
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);
207 else if(filetype == "bbg")
209 std::cout << "Opening bbg file." << std::endl;
210 this->_panelsManager->GetParentGUIEditorGraphicBBS()->OpenDiagram(filepath, filename);
214 std::cout << "Unknown file type: Can't open this kind of file: " << filetype << std::endl;
219 std::cout << "File Doesn't Exists. The given path is invalid: " << filePath << std::endl;
221 std::getline(ss, stdData, (char)13);
228 //=========================================================================
229 void wxGEditorTabPanel::saveTempandUpdate(const std::string &action)
231 _panelsManager->saveTempandUpdate(action);
233 //=========================================================================
235 void wxGEditorTabPanel::setPanelsManager(wxTabPanelsManager* panelsManager)
237 _panelsManager = panelsManager;
240 //=========================================================================
242 void wxGEditorTabPanel::displayBlackBoxInfo(std::string packageName, std::string boxName)
244 _panelsManager->displayBlackBoxInfo(packageName,boxName);
247 //=========================================================================
249 void wxGEditorTabPanel::updateStatusBar(std::string textStatus)
251 _panelsManager->updateStatusBar(textStatus);
254 //=========================================================================
256 std::string wxGEditorTabPanel::getDiagramBBS(bool wln)
258 return _sceneManager->getDiagramBBS(wln);
261 //=========================================================================
263 std::string wxGEditorTabPanel::saveComplexBoxBBS()
265 return _sceneManager->saveComplexBoxBBS();
268 //=========================================================================
270 void wxGEditorTabPanel::editBlackBox(GBlackBoxModel *bbmodel)
272 _panelsManager->editBlackBox(bbmodel);
275 //=========================================================================
277 void wxGEditorTabPanel::deleteAllBoxes()
279 _sceneManager->deleteAllBoxes();
282 //=========================================================================
284 void wxGEditorTabPanel::centerView()
288 _sceneManager->centerView();
292 //=========================================================================
294 void wxGEditorTabPanel::saveDiagram(std::string &content, const std::string &path) //DFCH
296 this->SetFullPath(path);
297 _sceneManager->saveDiagram(content);
300 //=========================================================================
302 void wxGEditorTabPanel::saveTempDiagram(const std::string &action) //FCY
304 std::string content = "";
305 // writing file header
306 content += "# ----------------------------------\n";
307 content += "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file\n";
311 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
318 states.push_back (content);
319 saveStringAction(action);
323 std::vector<std::string>::iterator it = _actualdo+1;
324 states.erase(it, states.end());
325 states.push_back(content);
327 std::vector<std::string>::iterator sit = _sactualdo+1;
328 sstates.erase(sit, sstates.end());
329 saveStringAction(action);
331 _actualdo = states.end();
332 _sactualdo = sstates.end();
336 //=========================================================================
338 void wxGEditorTabPanel::loadDiagram(std::ifstream &inputStream, const std::string &path) //DFCH
340 this->SetFullPath(path);
342 ss << inputStream.rdbuf() ;
343 _sceneManager->loadDiagram(ss);
346 //=========================================================================
347 unsigned short wxGEditorTabPanel::getUndoState( std::string &stun)
352 if(_actualdo == states.begin() )
353 // if(sstates.size()==1 )
355 // _sactualdo=sstates.begin();
359 printf("EED wxGEditorTabPanel::getUndoState This mecanisme is not working ?????? _sactualdo sstates _actualdo state \n");
360 // stun += _sactualdo->substr(0,(--_sactualdo)->find_last_of("."));
368 unsigned short wxGEditorTabPanel::getRedoState( std::string &stre)
373 if(_actualdo == --states.end() || states.size() == 1 || _actualdo == states.end())
378 stre += _sactualdo->substr(0,(++_sactualdo)->find_last_of("."));
385 //=========================================================================
386 void wxGEditorTabPanel::loadTempDiagram(unsigned short un) //FCY
388 unsigned short res = 1;
390 std::stringstream ss;
393 if(_actualdo == states.end() ) // same size, write to the end
398 if(_actualdo != states.begin() )
400 ss << *(--_actualdo);
413 if(_actualdo != states.end())
422 _sceneManager->loadDiagram(ss);
426 void wxGEditorTabPanel::saveStringAction(const std::string &action)
429 sprintf(temp,".%d", sstates.size());
430 sstates.push_back(action + temp);
433 //=========================================================================
435 int wxGEditorTabPanel::getPanelId()
442 //=========================================================================
444 bool wxGEditorTabPanel::isComplexBox()
446 return _sceneManager->isComplexBox();
449 //=========================================================================
451 void wxGEditorTabPanel::setComplexBox(bool val)
453 _sceneManager->setComplexBox(val);
456 //=========================================================================
458 void wxGEditorTabPanel::addComplexInputPort(std::string portName)
460 _sceneManager->createGComplexBoxInputPort(portName);
463 //=========================================================================
465 void wxGEditorTabPanel::addComplexOutputPort(std::string portName)
467 _sceneManager->createGComplexBoxOutputPort(portName);
470 //=========================================================================
472 std::map<int,GObjectController*> wxGEditorTabPanel::getSelectedObjects()
474 return _sceneManager->getSelectedObjects();
477 //=========================================================================
479 void wxGEditorTabPanel::addObjects(std::map<int,GObjectController*> objectsMap)
481 _sceneManager->addObjects(objectsMap);
484 //=========================================================================
486 int wxGEditorTabPanel::getNumSelectedObjects()
488 return _sceneManager->getNumSelectedObjects();
491 //=========================================================================
494 wxVtkSceneManager* wxGEditorTabPanel::getSceneManager()
496 return _sceneManager;
499 //=========================================================================
500 std::string wxGEditorTabPanel::GetCbName()
502 return _sceneManager->GetCbName();
506 //=========================================================================
507 std::string wxGEditorTabPanel::GetCbPackageName()
509 return _sceneManager->GetCbPackageName();
512 //=========================================================================
513 std::string wxGEditorTabPanel::GetAuthor()
515 return _sceneManager->GetAuthor();
518 //=========================================================================
519 std::string wxGEditorTabPanel::GetDescription()
521 return _sceneManager->GetDescription();
524 //=========================================================================
525 std::string wxGEditorTabPanel::GetCategory()
527 return _sceneManager->GetCategory();
529 //=========================================================================
530 std::string wxGEditorTabPanel::GetMessageKind()
532 return _sceneManager->GetMessageKind();
534 //=========================================================================
535 std::string wxGEditorTabPanel::GetMessageLevel()
537 return _sceneManager->GetMessageLevel();
540 //=========================================================================
541 void wxGEditorTabPanel::SetCbName(std::string cbName)
543 _sceneManager->SetCbName( cbName );
546 //=========================================================================
547 void wxGEditorTabPanel::SetCbPackageName(std::string packagename)
549 _sceneManager->SetCbPackageName( packagename );
553 //=========================================================================
554 void wxGEditorTabPanel::SetAuthor(std::string author)
556 _sceneManager->SetAuthor( author );
560 //=========================================================================
561 void wxGEditorTabPanel::SetCategory(std::string category)
563 _sceneManager->SetCategory( category );
567 //=========================================================================
568 void wxGEditorTabPanel::SetDescription(std::string description)
570 _sceneManager->SetDescription( description );
573 //=========================================================================
574 void wxGEditorTabPanel::SetMessageKind(std::string kind)
576 _sceneManager->SetMessageKind( kind );
579 //=========================================================================
580 void wxGEditorTabPanel::SetMessageLevel(std::string level)
582 _sceneManager->SetMessageLevel( level );
584 //=========================================================================
586 void wxGEditorTabPanel::SetFullPath( const std::string& fullpath )
588 this->_fullPath = fullpath;
590 //=========================================================================
592 void wxGEditorTabPanel::SetFileName( const std::string& filename )
594 this->_fileName = filename;
596 //=========================================================================
598 std::string wxGEditorTabPanel::GetFullPath( )
600 return( this->_fullPath );
602 //=========================================================================
604 std::string wxGEditorTabPanel::GetFileName( )
606 return( this->_fileName );
612 } // EO namespace bbtk