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);
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/
133 std::string stdData = crea::wx2std(data);
134 //std::cout << "Text drop: " << stdData << std::endl;
136 if(stdData.substr(0,4) == "box:")
138 int posT = stdData.find_first_of(':', 4);
139 std::string packageName = stdData.substr(4, posT-4);
140 posT = stdData.find_first_not_of(':', posT);
141 std::string boxType = stdData.substr(posT);
143 std::cout << "box: Package='" << packageName << "' BoxType='" << boxType << "'" <<std::endl;
145 wxString foo( (data) );
147 strcpy( str, (const char*)foo.mb_str(wxConvUTF8) );
151 result = strtok( str, delims );
152 packageName += result;
154 result = strtok( NULL, delims );
157 if ( _panelsManager->TryToOpenScriptApplication(packageName,boxType) == false )
159 _sceneManager->createGBlackBox(x,y,packageName, boxType);
160 saveTempandUpdate("drop box");
163 // DFGO: file for linux
164 else if(stdData.substr(0,5) == "file:")
166 std::cout << "file to open: " << stdData << std::endl;
172 //=========================================================================
173 void wxGEditorTabPanel::saveTempandUpdate(const std::string &action)
175 _panelsManager->saveTempandUpdate(action);
177 //=========================================================================
179 void wxGEditorTabPanel::setPanelsManager(wxTabPanelsManager* panelsManager)
181 _panelsManager = panelsManager;
184 //=========================================================================
186 void wxGEditorTabPanel::displayBlackBoxInfo(std::string packageName, std::string boxName)
188 _panelsManager->displayBlackBoxInfo(packageName,boxName);
191 //=========================================================================
193 void wxGEditorTabPanel::updateStatusBar(std::string textStatus)
195 _panelsManager->updateStatusBar(textStatus);
198 //=========================================================================
200 std::string wxGEditorTabPanel::getDiagramBBS(bool wln)
202 return _sceneManager->getDiagramBBS(wln);
205 //=========================================================================
207 std::string wxGEditorTabPanel::saveComplexBoxBBS()
209 return _sceneManager->saveComplexBoxBBS();
212 //=========================================================================
214 void wxGEditorTabPanel::editBlackBox(GBlackBoxModel *bbmodel)
216 _panelsManager->editBlackBox(bbmodel);
219 //=========================================================================
221 void wxGEditorTabPanel::deleteAllBoxes()
223 _sceneManager->deleteAllBoxes();
226 //=========================================================================
228 void wxGEditorTabPanel::centerView()
232 _sceneManager->centerView();
236 //=========================================================================
238 void wxGEditorTabPanel::saveDiagram(std::string &content, const std::string &path) //DFCH
240 this->SetFullPath(path);
241 _sceneManager->saveDiagram(content);
244 //=========================================================================
246 void wxGEditorTabPanel::saveTempDiagram(const std::string &action) //FCY
248 std::string content = "";
249 // writing file header
250 content += "# ----------------------------------\n";
251 content += "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file\n";
255 content += "# ----------------------------------\n";
257 content += "APP_START\n";
258 _sceneManager->saveDiagram(content);
259 content += "APP_END\n"; //put here to avoid mistakes
260 if(_actualdo == states.end() ) // same size, write to the end
262 states.push_back (content);
263 saveStringAction(action);
267 std::vector<std::string>::iterator it = _actualdo+1;
268 states.erase(it, states.end());
269 states.push_back(content);
271 std::vector<std::string>::iterator sit = _sactualdo+1;
272 sstates.erase(sit, sstates.end());
273 saveStringAction(action);
275 _actualdo = states.end();
276 _sactualdo = sstates.end();
280 //=========================================================================
282 void wxGEditorTabPanel::loadDiagram(ifstream &inputStream, const std::string &path) //DFCH
284 this->SetFullPath(path);
286 ss << inputStream.rdbuf() ;
287 _sceneManager->loadDiagram(ss);
290 //=========================================================================
291 unsigned short wxGEditorTabPanel::getUndoState( std::string &stun)
296 if(_actualdo == states.begin() )
304 stun += _sactualdo->substr(0,(--_sactualdo)->find_last_of("."));
311 unsigned short wxGEditorTabPanel::getRedoState( std::string &stre)
316 if(_actualdo == --states.end() || states.size() == 1 || _actualdo == states.end())
321 stre += _sactualdo->substr(0,(++_sactualdo)->find_last_of("."));
328 //=========================================================================
329 void wxGEditorTabPanel::loadTempDiagram(unsigned short un) //FCY
331 unsigned short res = 1;
333 std::stringstream ss;
336 if(_actualdo == states.end() ) // same size, write to the end
341 if(_actualdo != states.begin() )
343 ss << *(--_actualdo);
356 if(_actualdo != states.end())
365 _sceneManager->loadDiagram(ss);
369 void wxGEditorTabPanel::saveStringAction(const std::string &action)
372 sprintf(temp,".%d", sstates.size());
373 sstates.push_back(action + temp);
376 //=========================================================================
378 int wxGEditorTabPanel::getPanelId()
385 //=========================================================================
387 bool wxGEditorTabPanel::isComplexBox()
389 return _sceneManager->isComplexBox();
392 //=========================================================================
394 void wxGEditorTabPanel::setComplexBox(bool val)
396 _sceneManager->setComplexBox(val);
399 //=========================================================================
401 void wxGEditorTabPanel::addComplexInputPort(std::string portName)
403 _sceneManager->createGComplexBoxInputPort(portName);
406 //=========================================================================
408 void wxGEditorTabPanel::addComplexOutputPort(std::string portName)
410 _sceneManager->createGComplexBoxOutputPort(portName);
413 //=========================================================================
415 std::map<int,GObjectController*> wxGEditorTabPanel::getSelectedObjects()
417 return _sceneManager->getSelectedObjects();
420 //=========================================================================
422 void wxGEditorTabPanel::addObjects(std::map<int,GObjectController*> objectsMap)
424 _sceneManager->addObjects(objectsMap);
427 //=========================================================================
429 int wxGEditorTabPanel::getNumSelectedObjects()
431 return _sceneManager->getNumSelectedObjects();
434 //=========================================================================
437 wxVtkSceneManager* wxGEditorTabPanel::getSceneManager()
439 return _sceneManager;
442 //=========================================================================
443 std::string wxGEditorTabPanel::GetCbName()
445 return _sceneManager->GetCbName();
449 //=========================================================================
450 std::string wxGEditorTabPanel::GetCbPackageName()
452 return _sceneManager->GetCbPackageName();
455 //=========================================================================
456 std::string wxGEditorTabPanel::GetAuthor()
458 return _sceneManager->GetAuthor();
461 //=========================================================================
462 std::string wxGEditorTabPanel::GetDescription()
464 return _sceneManager->GetDescription();
467 //=========================================================================
468 std::string wxGEditorTabPanel::GetCategory()
470 return _sceneManager->GetCategory();
473 //=========================================================================
474 void wxGEditorTabPanel::SetCbName(std::string cbName)
476 _sceneManager->SetCbName( cbName );
479 //=========================================================================
480 void wxGEditorTabPanel::SetCbPackageName(std::string packagename)
482 _sceneManager->SetCbPackageName( packagename );
486 //=========================================================================
487 void wxGEditorTabPanel::SetAuthor(std::string author)
489 _sceneManager->SetAuthor( author );
493 //=========================================================================
494 void wxGEditorTabPanel::SetCategory(std::string category)
496 _sceneManager->SetCategory( category );
500 //=========================================================================
501 void wxGEditorTabPanel::SetDescription(std::string description)
503 _sceneManager->SetDescription( description );
505 //=========================================================================
507 void wxGEditorTabPanel::SetFullPath( const std::string& fullpath )
509 this->_fullPath = fullpath;
511 //=========================================================================
513 void wxGEditorTabPanel::SetFileName( const std::string& filename )
515 this->_fileName = filename;
517 //=========================================================================
519 std::string wxGEditorTabPanel::GetFullPath( )
521 return( this->_fullPath );
523 //=========================================================================
525 std::string wxGEditorTabPanel::GetFileName( )
527 return( this->_fileName );
533 } // EO namespace bbtk