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();
103 //EED 15 oct 2012 _sceneManager=new wxVtkSceneManager(this,baseview,_id);
104 _sceneManager=new wxVtkSceneManager(this,baseview,_id, _bbtkfactory);
108 printf("RaC-EED 21-06-2010 wxGEditorTabPanel::initWxVtkCanvas Remove the panelAUIMgr, and change to a normal sizer inside the wxGEditorTabPanel\n");
109 _panelAUIMgr->AddPane((wxWindow*)baseview->GetWxVTKRenderWindowInteractor(),wxAuiPaneInfo().Fixed().CenterPane());
111 _panelAUIMgr->Update();
114 //=========================================================================
116 bool wxGEditorTabPanel::OnDropText(wxCoord x, wxCoord y, const wxString& data)
118 std::string packageName="";
119 std::string boxType="";
121 wxString foo( (data) );
123 strcpy( str, (const char*)foo.mb_str(wxConvUTF8) );
127 result = strtok( str, delims );
128 packageName += result;
130 result = strtok( NULL, delims );
133 if ( _panelsManager->TryToOpenScriptApplication(packageName,boxType) == false )
135 _sceneManager->createGBlackBox(x,y,packageName, boxType);
136 saveTempandUpdate("drop box");
141 //=========================================================================
142 void wxGEditorTabPanel::saveTempandUpdate(const std::string &action)
144 _panelsManager->saveTempandUpdate(action);
146 //=========================================================================
148 void wxGEditorTabPanel::setPanelsManager(wxTabPanelsManager* panelsManager)
150 _panelsManager = panelsManager;
153 //=========================================================================
155 void wxGEditorTabPanel::displayBlackBoxInfo(std::string packageName, std::string boxName)
157 _panelsManager->displayBlackBoxInfo(packageName,boxName);
160 //=========================================================================
162 void wxGEditorTabPanel::updateStatusBar(std::string textStatus)
164 _panelsManager->updateStatusBar(textStatus);
167 //=========================================================================
169 std::string wxGEditorTabPanel::getDiagramBBS(bool wln)
171 return _sceneManager->getDiagramBBS(wln);
174 //=========================================================================
176 std::string wxGEditorTabPanel::saveComplexBoxBBS()
178 return _sceneManager->saveComplexBoxBBS();
181 //=========================================================================
183 void wxGEditorTabPanel::editBlackBox(GBlackBoxModel *bbmodel)
185 _panelsManager->editBlackBox(bbmodel);
188 //=========================================================================
190 void wxGEditorTabPanel::deleteAllBoxes()
192 _sceneManager->deleteAllBoxes();
195 //=========================================================================
197 void wxGEditorTabPanel::centerView()
201 _sceneManager->centerView();
205 //=========================================================================
207 void wxGEditorTabPanel::saveDiagram(std::string &content, const std::string &path) //DFCH
209 this->SetFullPath(path);
210 _sceneManager->saveDiagram(content);
213 //=========================================================================
215 void wxGEditorTabPanel::saveTempDiagram(const std::string &action) //FCY
217 std::string content = "";
218 // writing file header
219 content += "# ----------------------------------\n";
220 content += "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file\n";
224 content += "# ----------------------------------\n";
226 content += "APP_START\n";
227 _sceneManager->saveDiagram(content);
228 content += "APP_END\n"; //put here to avoid mistakes
229 if(_actualdo == states.end() ) // same size, write to the end
231 states.push_back (content);
232 saveStringAction(action);
236 std::vector<std::string>::iterator it = _actualdo+1;
237 states.erase(it, states.end());
238 states.push_back(content);
240 std::vector<std::string>::iterator sit = _sactualdo+1;
241 sstates.erase(sit, sstates.end());
242 saveStringAction(action);
244 _actualdo = states.end();
245 _sactualdo = sstates.end();
249 //=========================================================================
251 void wxGEditorTabPanel::loadDiagram(ifstream &inputStream, const std::string &path) //DFCH
253 this->SetFullPath(path);
255 ss << inputStream.rdbuf() ;
256 _sceneManager->loadDiagram(ss);
259 //=========================================================================
260 unsigned short wxGEditorTabPanel::getUndoState( std::string &stun)
265 if(_actualdo == states.begin() )
273 stun += _sactualdo->substr(0,(--_sactualdo)->find_last_of("."));
280 unsigned short wxGEditorTabPanel::getRedoState( std::string &stre)
285 if(_actualdo == --states.end() || states.size() == 1 || _actualdo == states.end())
290 stre += _sactualdo->substr(0,(++_sactualdo)->find_last_of("."));
297 //=========================================================================
298 void wxGEditorTabPanel::loadTempDiagram(unsigned short un) //FCY
300 unsigned short res = 1;
302 std::stringstream ss;
305 if(_actualdo == states.end() ) // same size, write to the end
310 if(_actualdo != states.begin() )
312 ss << *(--_actualdo);
325 if(_actualdo != states.end())
334 _sceneManager->loadDiagram(ss);
338 void wxGEditorTabPanel::saveStringAction(const std::string &action)
341 sprintf(temp,".%d", sstates.size());
342 sstates.push_back(action + temp);
345 //=========================================================================
347 int wxGEditorTabPanel::getPanelId()
354 //=========================================================================
356 bool wxGEditorTabPanel::isComplexBox()
358 return _sceneManager->isComplexBox();
361 //=========================================================================
363 void wxGEditorTabPanel::setComplexBox(bool val)
365 _sceneManager->setComplexBox(val);
368 //=========================================================================
370 void wxGEditorTabPanel::addComplexInputPort(std::string portName)
372 _sceneManager->createGComplexBoxInputPort(portName);
375 //=========================================================================
377 void wxGEditorTabPanel::addComplexOutputPort(std::string portName)
379 _sceneManager->createGComplexBoxOutputPort(portName);
382 //=========================================================================
384 std::map<int,GObjectController*> wxGEditorTabPanel::getSelectedObjects()
386 return _sceneManager->getSelectedObjects();
389 //=========================================================================
391 void wxGEditorTabPanel::addObjects(std::map<int,GObjectController*> objectsMap)
393 _sceneManager->addObjects(objectsMap);
396 //=========================================================================
398 int wxGEditorTabPanel::getNumSelectedObjects()
400 return _sceneManager->getNumSelectedObjects();
403 //=========================================================================
406 wxVtkSceneManager* wxGEditorTabPanel::getSceneManager()
408 return _sceneManager;
411 //=========================================================================
412 std::string wxGEditorTabPanel::GetCbName()
414 return _sceneManager->GetCbName();
418 //=========================================================================
419 std::string wxGEditorTabPanel::GetCbPackageName()
421 return _sceneManager->GetCbPackageName();
424 //=========================================================================
425 std::string wxGEditorTabPanel::GetAuthor()
427 return _sceneManager->GetAuthor();
430 //=========================================================================
431 std::string wxGEditorTabPanel::GetDescription()
433 return _sceneManager->GetDescription();
436 //=========================================================================
437 std::string wxGEditorTabPanel::GetCategory()
439 return _sceneManager->GetCategory();
442 //=========================================================================
443 void wxGEditorTabPanel::SetCbName(std::string cbName)
445 _sceneManager->SetCbName( cbName );
448 //=========================================================================
449 void wxGEditorTabPanel::SetCbPackageName(std::string packagename)
451 _sceneManager->SetCbPackageName( packagename );
455 //=========================================================================
456 void wxGEditorTabPanel::SetAuthor(std::string author)
458 _sceneManager->SetAuthor( author );
462 //=========================================================================
463 void wxGEditorTabPanel::SetCategory(std::string category)
465 _sceneManager->SetCategory( category );
469 //=========================================================================
470 void wxGEditorTabPanel::SetDescription(std::string description)
472 _sceneManager->SetDescription( description );
474 //=========================================================================
476 void wxGEditorTabPanel::SetFullPath( const std::string& fullpath )
478 this->_fullPath = fullpath;
480 //=========================================================================
482 void wxGEditorTabPanel::SetFileName( const std::string& filename )
484 this->_fileName = filename;
486 //=========================================================================
488 std::string wxGEditorTabPanel::GetFullPath( )
490 return( this->_fullPath );
492 //=========================================================================
494 std::string wxGEditorTabPanel::GetFileName( )
496 return( this->_fileName );
502 } // EO namespace bbtk