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()
53 printf("EED wxGEditorTabPanel::wxGEditorTabPanel 0\n");
54 printf ("EED %p wxGEditorTabPanel 2 ()\n" , this );
56 _panelAUIMgr = new wxAuiManager(this);
58 _actualdo = states.begin();
59 _sactualdo = sstates.begin();
60 _bbtkfactory = bbtkfactory;
62 printf("EED wxGEditorTabPanel::wxGEditorTabPanel 1\n");
65 //=========================================================================
66 wxGEditorTabPanel::~wxGEditorTabPanel()
68 printf ("EED %p ~wxGEditorTabPanel() START \n" , this );
69 //ED02JUIN2010 _sceneManager->disconnectDrop();
71 _panelsManager->VerifyLastTabPanel();
76 printf ("EED %p ~wxGEditorTabPanel() END\n" , this );
79 //=========================================================================
80 void wxGEditorTabPanel::initWxVtkCanvas()
82 printf("EED wxGEditorTabPanel::initWxVtkCanvas 0\n");
83 wxVtk3DBaseView *baseview = new wxVtk3DBaseView(this);
84 baseview->Configure();
85 //EED 15 oct 2012 _sceneManager=new wxVtkSceneManager(this,baseview,_id);
86 _sceneManager=new wxVtkSceneManager(this,baseview,_id, _bbtkfactory);
90 printf("RaC-EED 21-06-2010 wxGEditorTabPanel::initWxVtkCanvas Remove the panelAUIMgr, and change to a normal sizer inside the wxGEditorTabPanel\n");
91 _panelAUIMgr->AddPane((wxWindow*)baseview->GetWxVTKRenderWindowInteractor(),wxAuiPaneInfo().Fixed().CenterPane());
93 _panelAUIMgr->Update();
94 printf("EED wxGEditorTabPanel::initWxVtkCanvas 1\n");
97 //=========================================================================
99 bool wxGEditorTabPanel::OnDropText(wxCoord x, wxCoord y, const wxString& data)
101 std::string packageName="";
102 std::string boxType="";
104 wxString foo( (data) );
106 strcpy( str, (const char*)foo.mb_str(wxConvUTF8) );
110 result = strtok( str, delims );
111 packageName += result;
113 result = strtok( NULL, delims );
116 _sceneManager->createGBlackBox(x,y,packageName, boxType);
117 saveTempandUpdate("drop box");
121 //=========================================================================
122 void wxGEditorTabPanel::saveTempandUpdate(const std::string &action)
124 _panelsManager->saveTempandUpdate(action);
126 //=========================================================================
128 void wxGEditorTabPanel::setPanelsManager(wxTabPanelsManager* panelsManager)
130 _panelsManager = panelsManager;
133 //=========================================================================
135 void wxGEditorTabPanel::displayBlackBoxInfo(std::string packageName, std::string boxName)
137 _panelsManager->displayBlackBoxInfo(packageName,boxName);
140 //=========================================================================
142 void wxGEditorTabPanel::updateStatusBar(std::string textStatus)
144 _panelsManager->updateStatusBar(textStatus);
147 //=========================================================================
149 std::string wxGEditorTabPanel::getDiagramBBS(bool wln)
151 return _sceneManager->getDiagramBBS(wln);
154 //=========================================================================
156 std::string wxGEditorTabPanel::saveComplexBoxBBS()
158 return _sceneManager->saveComplexBoxBBS();
161 //=========================================================================
163 void wxGEditorTabPanel::editBlackBox(GBlackBoxModel *bbmodel)
165 _panelsManager->editBlackBox(bbmodel);
168 //=========================================================================
170 void wxGEditorTabPanel::deleteAllBoxes()
172 _sceneManager->deleteAllBoxes();
175 //=========================================================================
177 void wxGEditorTabPanel::centerView()
181 _sceneManager->centerView();
185 //=========================================================================
187 void wxGEditorTabPanel::saveDiagram(std::string &content, const std::string &path) //DFCH
189 this->SetFullPath(path);
190 _sceneManager->saveDiagram(content);
193 //=========================================================================
195 void wxGEditorTabPanel::saveTempDiagram(const std::string &action) //FCY
197 std::string content = "";
198 // writing file header
199 content += "# ----------------------------------\n";
200 content += "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file\n";
204 content += "# ----------------------------------\n";
206 content += "APP_START\n";
207 _sceneManager->saveDiagram(content);
208 content += "APP_END\n"; //put here to avoid mistakes
209 if(_actualdo == states.end() ) // same size, write to the end
211 states.push_back (content);
212 saveStringAction(action);
216 std::vector<std::string>::iterator it = _actualdo+1;
217 states.erase(it, states.end());
218 states.push_back(content);
220 std::vector<std::string>::iterator sit = _sactualdo+1;
221 sstates.erase(sit, sstates.end());
222 saveStringAction(action);
224 _actualdo = states.end();
225 _sactualdo = sstates.end();
229 //=========================================================================
231 void wxGEditorTabPanel::loadDiagram(ifstream &inputStream, const std::string &path) //DFCH
233 this->SetFullPath(path);
235 ss << inputStream.rdbuf() ;
236 _sceneManager->loadDiagram(ss);
239 //=========================================================================
240 unsigned short wxGEditorTabPanel::getUndoState( std::string &stun)
245 if(_actualdo == states.begin() )
253 stun += _sactualdo->substr(0,(--_sactualdo)->find_last_of("."));
260 unsigned short wxGEditorTabPanel::getRedoState( std::string &stre)
265 if(_actualdo == --states.end() || states.size() == 1 || _actualdo == states.end())
270 stre += _sactualdo->substr(0,(++_sactualdo)->find_last_of("."));
277 //=========================================================================
278 void wxGEditorTabPanel::loadTempDiagram(unsigned short un) //FCY
280 unsigned short res = 1;
282 std::stringstream ss;
285 if(_actualdo == states.end() ) // same size, write to the end
290 if(_actualdo != states.begin() )
292 ss << *(--_actualdo);
305 if(_actualdo != states.end())
314 _sceneManager->loadDiagram(ss);
318 void wxGEditorTabPanel::saveStringAction(const std::string &action)
321 sprintf(temp,".%d", sstates.size());
322 sstates.push_back(action + temp);
325 //=========================================================================
327 int wxGEditorTabPanel::getPanelId()
334 //=========================================================================
336 bool wxGEditorTabPanel::isComplexBox()
338 return _sceneManager->isComplexBox();
341 //=========================================================================
343 void wxGEditorTabPanel::setComplexBox(bool val)
345 _sceneManager->setComplexBox(val);
348 //=========================================================================
350 void wxGEditorTabPanel::addComplexInputPort(std::string portName)
352 _sceneManager->createGComplexBoxInputPort(portName);
355 //=========================================================================
357 void wxGEditorTabPanel::addComplexOutputPort(std::string portName)
359 _sceneManager->createGComplexBoxOutputPort(portName);
362 //=========================================================================
364 std::map<int,GObjectController*> wxGEditorTabPanel::getSelectedObjects()
366 return _sceneManager->getSelectedObjects();
369 //=========================================================================
371 void wxGEditorTabPanel::addObjects(std::map<int,GObjectController*> objectsMap)
373 _sceneManager->addObjects(objectsMap);
376 //=========================================================================
378 int wxGEditorTabPanel::getNumSelectedObjects()
380 return _sceneManager->getNumSelectedObjects();
383 //=========================================================================
386 wxVtkSceneManager* wxGEditorTabPanel::getSceneManager()
388 return _sceneManager;
391 //=========================================================================
392 std::string wxGEditorTabPanel::GetCbName()
394 return _sceneManager->GetCbName();
398 //=========================================================================
399 std::string wxGEditorTabPanel::GetCbPackageName()
401 return _sceneManager->GetCbPackageName();
404 //=========================================================================
405 std::string wxGEditorTabPanel::GetAuthor()
407 return _sceneManager->GetAuthor();
410 //=========================================================================
411 std::string wxGEditorTabPanel::GetDescription()
413 return _sceneManager->GetDescription();
416 //=========================================================================
417 std::string wxGEditorTabPanel::GetCategory()
419 return _sceneManager->GetCategory();
422 //=========================================================================
423 void wxGEditorTabPanel::SetCbName(std::string cbName)
425 _sceneManager->SetCbName( cbName );
428 //=========================================================================
429 void wxGEditorTabPanel::SetCbPackageName(std::string packagename)
431 _sceneManager->SetCbPackageName( packagename );
435 //=========================================================================
436 void wxGEditorTabPanel::SetAuthor(std::string author)
438 _sceneManager->SetAuthor( author );
442 //=========================================================================
443 void wxGEditorTabPanel::SetCategory(std::string category)
445 _sceneManager->SetCategory( category );
449 //=========================================================================
450 void wxGEditorTabPanel::SetDescription(std::string description)
452 _sceneManager->SetDescription( description );
454 //=========================================================================
456 void wxGEditorTabPanel::SetFullPath( const std::string& fullpath )
458 this->_fullPath = fullpath;
460 //=========================================================================
462 void wxGEditorTabPanel::SetFileName( const std::string& filename )
464 this->_fileName = filename;
466 //=========================================================================
468 std::string wxGEditorTabPanel::GetFullPath( )
470 return( this->_fullPath );
472 //=========================================================================
474 std::string wxGEditorTabPanel::GetFileName( )
476 return( this->_fileName );
482 } // EO namespace bbtk