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):wxPanel(parent),wxTextDropTarget()
52 printf("EED wxGEditorTabPanel::wxGEditorTabPanel 0\n");
53 printf ("EED %p wxGEditorTabPanel 2 ()\n" , this );
55 _panelAUIMgr = new wxAuiManager(this);
57 _actualdo = states.begin();
58 _sactualdo = sstates.begin();
60 printf("EED wxGEditorTabPanel::wxGEditorTabPanel 1\n");
63 //=========================================================================
64 wxGEditorTabPanel::~wxGEditorTabPanel()
66 printf ("EED %p ~wxGEditorTabPanel() START \n" , this );
67 //ED02JUIN2010 _sceneManager->disconnectDrop();
69 _panelsManager->VerifyLastTabPanel();
74 printf ("EED %p ~wxGEditorTabPanel() END\n" , this );
78 //=========================================================================
79 void wxGEditorTabPanel::initWxVtkCanvas()
81 printf("EED wxGEditorTabPanel::initWxVtkCanvas 0\n");
82 wxVtk3DBaseView *baseview = new wxVtk3DBaseView(this);
83 baseview->Configure();
84 _sceneManager=new wxVtkSceneManager(this,baseview,_id);
88 printf("RaC-EED 21-06-2010 wxGEditorTabPanel::initWxVtkCanvas Remove the panelAUIMgr, and change to a normal sizer inside the wxGEditorTabPanel\n");
89 _panelAUIMgr->AddPane((wxWindow*)baseview->GetWxVTKRenderWindowInteractor(),wxAuiPaneInfo().Fixed().CenterPane());
91 _panelAUIMgr->Update();
92 printf("EED wxGEditorTabPanel::initWxVtkCanvas 1\n");
95 //=========================================================================
97 bool wxGEditorTabPanel::OnDropText(wxCoord x, wxCoord y, const wxString& data)
99 std::string packageName="";
100 std::string boxType="";
102 wxString foo( (data) );
104 strcpy( str, (const char*)foo.mb_str(wxConvUTF8) );
108 result = strtok( str, delims );
109 packageName += result;
111 result = strtok( NULL, delims );
114 _sceneManager->createGBlackBox(x,y,packageName, boxType);
115 saveTempandUpdate("drop box");
119 //=========================================================================
120 void wxGEditorTabPanel::saveTempandUpdate(const std::string &action)
122 _panelsManager->saveTempandUpdate(action);
124 //=========================================================================
126 void wxGEditorTabPanel::setPanelsManager(wxTabPanelsManager* panelsManager)
128 _panelsManager = panelsManager;
131 //=========================================================================
133 void wxGEditorTabPanel::displayBlackBoxInfo(std::string packageName, std::string boxName)
135 _panelsManager->displayBlackBoxInfo(packageName,boxName);
138 //=========================================================================
140 void wxGEditorTabPanel::updateStatusBar(std::string textStatus)
142 _panelsManager->updateStatusBar(textStatus);
145 //=========================================================================
147 std::string wxGEditorTabPanel::getDiagramBBS(bool wln)
149 return _sceneManager->getDiagramBBS(wln);
152 //=========================================================================
154 std::string wxGEditorTabPanel::saveComplexBoxBBS()
156 return _sceneManager->saveComplexBoxBBS();
159 //=========================================================================
161 void wxGEditorTabPanel::editBlackBox(GBlackBoxModel *bbmodel)
163 _panelsManager->editBlackBox(bbmodel);
166 //=========================================================================
168 void wxGEditorTabPanel::deleteAllBoxes()
170 _sceneManager->deleteAllBoxes();
173 //=========================================================================
175 void wxGEditorTabPanel::centerView()
179 _sceneManager->centerView();
183 //=========================================================================
185 void wxGEditorTabPanel::saveDiagram(std::string &content, const std::string &path) //DFCH
187 this->SetFullPath(path);
188 _sceneManager->saveDiagram(content);
191 //=========================================================================
193 void wxGEditorTabPanel::saveTempDiagram(const std::string &action) //FCY
195 std::string content = "";
196 // writing file header
197 content += "# ----------------------------------\n";
198 content += "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file\n";
202 content += "# ----------------------------------\n";
204 content += "APP_START\n";
205 _sceneManager->saveDiagram(content);
206 content += "APP_END\n"; //put here to avoid mistakes
207 if(_actualdo == states.end() ) // same size, write to the end
209 states.push_back (content);
210 saveStringAction(action);
214 std::vector<std::string>::iterator it = _actualdo+1;
215 states.erase(it, states.end());
216 states.push_back(content);
218 std::vector<std::string>::iterator sit = _sactualdo+1;
219 sstates.erase(sit, sstates.end());
220 saveStringAction(action);
222 _actualdo = states.end();
223 _sactualdo = sstates.end();
227 //=========================================================================
229 void wxGEditorTabPanel::loadDiagram(ifstream &inputStream, const std::string &path) //DFCH
231 this->SetFullPath(path);
233 ss << inputStream.rdbuf() ;
234 _sceneManager->loadDiagram(ss);
237 //=========================================================================
238 unsigned short wxGEditorTabPanel::getUndoState( std::string &stun)
243 if(_actualdo == states.begin() )
251 stun += _sactualdo->substr(0,(--_sactualdo)->find_last_of("."));
258 unsigned short wxGEditorTabPanel::getRedoState( std::string &stre)
263 if(_actualdo == --states.end() || states.size() == 1 || _actualdo == states.end())
268 stre += _sactualdo->substr(0,(++_sactualdo)->find_last_of("."));
275 //=========================================================================
276 void wxGEditorTabPanel::loadTempDiagram(unsigned short un) //FCY
278 unsigned short res = 1;
280 std::stringstream ss;
283 if(_actualdo == states.end() ) // same size, write to the end
288 if(_actualdo != states.begin() )
290 ss << *(--_actualdo);
303 if(_actualdo != states.end())
312 _sceneManager->loadDiagram(ss);
316 void wxGEditorTabPanel::saveStringAction(const std::string &action)
319 sprintf(temp,".%d", sstates.size());
320 sstates.push_back(action + temp);
323 //=========================================================================
325 int wxGEditorTabPanel::getPanelId()
332 //=========================================================================
334 bool wxGEditorTabPanel::isComplexBox()
336 return _sceneManager->isComplexBox();
339 //=========================================================================
341 void wxGEditorTabPanel::setComplexBox(bool val)
343 _sceneManager->setComplexBox(val);
346 //=========================================================================
348 void wxGEditorTabPanel::addComplexInputPort(std::string portName)
350 _sceneManager->createGComplexBoxInputPort(portName);
353 //=========================================================================
355 void wxGEditorTabPanel::addComplexOutputPort(std::string portName)
357 _sceneManager->createGComplexBoxOutputPort(portName);
360 //=========================================================================
362 std::map<int,GObjectController*> wxGEditorTabPanel::getSelectedObjects()
364 return _sceneManager->getSelectedObjects();
367 //=========================================================================
369 void wxGEditorTabPanel::addObjects(std::map<int,GObjectController*> objectsMap)
371 _sceneManager->addObjects(objectsMap);
374 //=========================================================================
376 int wxGEditorTabPanel::getNumSelectedObjects()
378 return _sceneManager->getNumSelectedObjects();
381 //=========================================================================
384 wxVtkSceneManager* wxGEditorTabPanel::getSceneManager()
386 return _sceneManager;
389 //=========================================================================
390 std::string wxGEditorTabPanel::GetCbName()
392 return _sceneManager->GetCbName();
396 //=========================================================================
397 std::string wxGEditorTabPanel::GetCbPackageName()
399 return _sceneManager->GetCbPackageName();
402 //=========================================================================
403 std::string wxGEditorTabPanel::GetAuthor()
405 return _sceneManager->GetAuthor();
408 //=========================================================================
409 std::string wxGEditorTabPanel::GetDescription()
411 return _sceneManager->GetDescription();
414 //=========================================================================
415 std::string wxGEditorTabPanel::GetCategory()
417 return _sceneManager->GetCategory();
420 //=========================================================================
421 void wxGEditorTabPanel::SetCbName(std::string cbName)
423 _sceneManager->SetCbName( cbName );
426 //=========================================================================
427 void wxGEditorTabPanel::SetCbPackageName(std::string packagename)
429 _sceneManager->SetCbPackageName( packagename );
433 //=========================================================================
434 void wxGEditorTabPanel::SetAuthor(std::string author)
436 _sceneManager->SetAuthor( author );
440 //=========================================================================
441 void wxGEditorTabPanel::SetCategory(std::string category)
443 _sceneManager->SetCategory( category );
447 //=========================================================================
448 void wxGEditorTabPanel::SetDescription(std::string description)
450 _sceneManager->SetDescription( description );
452 //=========================================================================
454 void wxGEditorTabPanel::SetFullPath( const std::string& fullpath )
456 this->_fullPath = fullpath;
458 //=========================================================================
460 void wxGEditorTabPanel::SetFileName( const std::string& filename )
462 this->_fileName = filename;
464 //=========================================================================
466 std::string wxGEditorTabPanel::GetFullPath( )
468 return( this->_fullPath );
470 //=========================================================================
472 std::string wxGEditorTabPanel::GetFileName( )
474 return( this->_fileName );
480 } // EO namespace bbtk