1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::wxGEditorTabPanel .
37 #include "wxGEditorTabPanel.h"
43 //=========================================================================
44 wxGEditorTabPanel::wxGEditorTabPanel()
46 printf ("EED %p wxGEditorTabPanel 1 ()\n" , this );
49 //=========================================================================
50 wxGEditorTabPanel::wxGEditorTabPanel(wxWindow *parent,int id, Factory::Pointer bbtkfactory)
51 : wxPanel(parent),wxTextDropTarget()
54 _panelAUIMgr = new wxAuiManager(this);
56 _actualdo = states.begin();
57 _sactualdo = sstates.begin();
58 _bbtkfactory = bbtkfactory;
62 //=========================================================================
63 wxGEditorTabPanel::~wxGEditorTabPanel()
65 //ED02JUIN2010 _sceneManager->disconnectDrop();
67 _panelsManager->VerifyLastTabPanel();
73 //=========================================================================
74 void wxGEditorTabPanel::initWxVtkCanvas()
76 wxVtk3DBaseView *baseview = new wxVtk3DBaseView(this);
77 baseview->Configure();
78 //EED 15 oct 2012 _sceneManager=new wxVtkSceneManager(this,baseview,_id);
79 _sceneManager=new wxVtkSceneManager(this,baseview,_id, _bbtkfactory);
83 printf("RaC-EED 21-06-2010 wxGEditorTabPanel::initWxVtkCanvas Remove the panelAUIMgr, and change to a normal sizer inside the wxGEditorTabPanel\n");
84 _panelAUIMgr->AddPane((wxWindow*)baseview->GetWxVTKRenderWindowInteractor(),wxAuiPaneInfo().Fixed().CenterPane());
86 _panelAUIMgr->Update();
89 //=========================================================================
91 bool wxGEditorTabPanel::OnDropText(wxCoord x, wxCoord y, const wxString& data)
93 std::string packageName="";
94 std::string boxType="";
96 wxString foo( (data) );
98 strcpy( str, (const char*)foo.mb_str(wxConvUTF8) );
102 result = strtok( str, delims );
103 packageName += result;
105 result = strtok( NULL, delims );
108 if ( _panelsManager->TryToOpenScriptApplication(packageName,boxType) == false )
110 _sceneManager->createGBlackBox(x,y,packageName, boxType);
111 saveTempandUpdate("drop box");
116 //=========================================================================
117 void wxGEditorTabPanel::saveTempandUpdate(const std::string &action)
119 _panelsManager->saveTempandUpdate(action);
121 //=========================================================================
123 void wxGEditorTabPanel::setPanelsManager(wxTabPanelsManager* panelsManager)
125 _panelsManager = panelsManager;
128 //=========================================================================
130 void wxGEditorTabPanel::displayBlackBoxInfo(std::string packageName, std::string boxName)
132 _panelsManager->displayBlackBoxInfo(packageName,boxName);
135 //=========================================================================
137 void wxGEditorTabPanel::updateStatusBar(std::string textStatus)
139 _panelsManager->updateStatusBar(textStatus);
142 //=========================================================================
144 std::string wxGEditorTabPanel::getDiagramBBS(bool wln)
146 return _sceneManager->getDiagramBBS(wln);
149 //=========================================================================
151 std::string wxGEditorTabPanel::saveComplexBoxBBS()
153 return _sceneManager->saveComplexBoxBBS();
156 //=========================================================================
158 void wxGEditorTabPanel::editBlackBox(GBlackBoxModel *bbmodel)
160 _panelsManager->editBlackBox(bbmodel);
163 //=========================================================================
165 void wxGEditorTabPanel::deleteAllBoxes()
167 _sceneManager->deleteAllBoxes();
170 //=========================================================================
172 void wxGEditorTabPanel::centerView()
176 _sceneManager->centerView();
180 //=========================================================================
182 void wxGEditorTabPanel::saveDiagram(std::string &content, const std::string &path) //DFCH
184 this->SetFullPath(path);
185 _sceneManager->saveDiagram(content);
188 //=========================================================================
190 void wxGEditorTabPanel::saveTempDiagram(const std::string &action) //FCY
192 std::string content = "";
193 // writing file header
194 content += "# ----------------------------------\n";
195 content += "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file\n";
199 content += "# ----------------------------------\n";
201 content += "APP_START\n";
202 _sceneManager->saveDiagram(content);
203 content += "APP_END\n"; //put here to avoid mistakes
204 if(_actualdo == states.end() ) // same size, write to the end
206 states.push_back (content);
207 saveStringAction(action);
211 std::vector<std::string>::iterator it = _actualdo+1;
212 states.erase(it, states.end());
213 states.push_back(content);
215 std::vector<std::string>::iterator sit = _sactualdo+1;
216 sstates.erase(sit, sstates.end());
217 saveStringAction(action);
219 _actualdo = states.end();
220 _sactualdo = sstates.end();
224 //=========================================================================
226 void wxGEditorTabPanel::loadDiagram(ifstream &inputStream, const std::string &path) //DFCH
228 this->SetFullPath(path);
230 ss << inputStream.rdbuf() ;
231 _sceneManager->loadDiagram(ss);
234 //=========================================================================
235 unsigned short wxGEditorTabPanel::getUndoState( std::string &stun)
240 if(_actualdo == states.begin() )
248 stun += _sactualdo->substr(0,(--_sactualdo)->find_last_of("."));
255 unsigned short wxGEditorTabPanel::getRedoState( std::string &stre)
260 if(_actualdo == --states.end() || states.size() == 1 || _actualdo == states.end())
265 stre += _sactualdo->substr(0,(++_sactualdo)->find_last_of("."));
272 //=========================================================================
273 void wxGEditorTabPanel::loadTempDiagram(unsigned short un) //FCY
275 unsigned short res = 1;
277 std::stringstream ss;
280 if(_actualdo == states.end() ) // same size, write to the end
285 if(_actualdo != states.begin() )
287 ss << *(--_actualdo);
300 if(_actualdo != states.end())
309 _sceneManager->loadDiagram(ss);
313 void wxGEditorTabPanel::saveStringAction(const std::string &action)
316 sprintf(temp,".%d", sstates.size());
317 sstates.push_back(action + temp);
320 //=========================================================================
322 int wxGEditorTabPanel::getPanelId()
329 //=========================================================================
331 bool wxGEditorTabPanel::isComplexBox()
333 return _sceneManager->isComplexBox();
336 //=========================================================================
338 void wxGEditorTabPanel::setComplexBox(bool val)
340 _sceneManager->setComplexBox(val);
343 //=========================================================================
345 void wxGEditorTabPanel::addComplexInputPort(std::string portName)
347 _sceneManager->createGComplexBoxInputPort(portName);
350 //=========================================================================
352 void wxGEditorTabPanel::addComplexOutputPort(std::string portName)
354 _sceneManager->createGComplexBoxOutputPort(portName);
357 //=========================================================================
359 std::map<int,GObjectController*> wxGEditorTabPanel::getSelectedObjects()
361 return _sceneManager->getSelectedObjects();
364 //=========================================================================
366 void wxGEditorTabPanel::addObjects(std::map<int,GObjectController*> objectsMap)
368 _sceneManager->addObjects(objectsMap);
371 //=========================================================================
373 int wxGEditorTabPanel::getNumSelectedObjects()
375 return _sceneManager->getNumSelectedObjects();
378 //=========================================================================
381 wxVtkSceneManager* wxGEditorTabPanel::getSceneManager()
383 return _sceneManager;
386 //=========================================================================
387 std::string wxGEditorTabPanel::GetCbName()
389 return _sceneManager->GetCbName();
393 //=========================================================================
394 std::string wxGEditorTabPanel::GetCbPackageName()
396 return _sceneManager->GetCbPackageName();
399 //=========================================================================
400 std::string wxGEditorTabPanel::GetAuthor()
402 return _sceneManager->GetAuthor();
405 //=========================================================================
406 std::string wxGEditorTabPanel::GetDescription()
408 return _sceneManager->GetDescription();
411 //=========================================================================
412 std::string wxGEditorTabPanel::GetCategory()
414 return _sceneManager->GetCategory();
417 //=========================================================================
418 void wxGEditorTabPanel::SetCbName(std::string cbName)
420 _sceneManager->SetCbName( cbName );
423 //=========================================================================
424 void wxGEditorTabPanel::SetCbPackageName(std::string packagename)
426 _sceneManager->SetCbPackageName( packagename );
430 //=========================================================================
431 void wxGEditorTabPanel::SetAuthor(std::string author)
433 _sceneManager->SetAuthor( author );
437 //=========================================================================
438 void wxGEditorTabPanel::SetCategory(std::string category)
440 _sceneManager->SetCategory( category );
444 //=========================================================================
445 void wxGEditorTabPanel::SetDescription(std::string description)
447 _sceneManager->SetDescription( description );
449 //=========================================================================
451 void wxGEditorTabPanel::SetFullPath( const std::string& fullpath )
453 this->_fullPath = fullpath;
455 //=========================================================================
457 void wxGEditorTabPanel::SetFileName( const std::string& filename )
459 this->_fileName = filename;
461 //=========================================================================
463 std::string wxGEditorTabPanel::GetFullPath( )
465 return( this->_fullPath );
467 //=========================================================================
469 std::string wxGEditorTabPanel::GetFileName( )
471 return( this->_fileName );
477 } // EO namespace bbtk