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");
115 >>>>>> TryToOpenScriptApplication
117 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
118 BlackBoxDescriptor::Pointer descriptor;
119 k = _bbtkfactory->GetPackage(packageName);
120 mapDesc = k->GetDescriptorMap();
121 descriptor = mapDesc[boxType];
123 if (descriptor->IsTypeOfScript_Application()==true)
125 OpenScript(descriptor->GetScriptFileName(),boxType);
127 printf("EED wxGEditorTabPanel::OnDropText packageName=%s boxType=%s APPLI ScriptFileName=%s\n", packageName.c_str() , boxType.c_str() , descriptor->GetScriptFileName().c_str() );
128 std::string fileName = boxType+".bbg";
129 std::string filePathNameBBS = descriptor->GetScriptFileName();
130 std::string filePathNameBBG = filePathNameBBS;
131 filePathNameBBG[ filePathNameBBG.length()-1 ] = 'g';
133 wxMessageDialog windowMessage1(NULL,_T("The system is going to open a bbg or bbs for you. Be careful if you save this file."), _T("Alert !"), wxOK);
134 windowMessage1.ShowModal();
136 if ( Utilities::FileExists( filePathNameBBG ) )
138 _panelsManager->OpenDiagram( filePathNameBBG , fileName );
140 if ( Utilities::FileExists( filePathNameBBS ) )
142 _panelsManager->OpenBBS( filePathNameBBS , fileName );
144 wxMessageDialog windowMessage1(NULL,_T("..ERROR.. loading script bbg/bbs."), _T("Alert !"), wxOK);
145 windowMessage1.ShowModal();
153 // _sceneManager->createGBlackBox(x,y,packageName, boxType);
154 // saveTempandUpdate("drop box");
162 //=========================================================================
163 void wxGEditorTabPanel::saveTempandUpdate(const std::string &action)
165 _panelsManager->saveTempandUpdate(action);
167 //=========================================================================
169 void wxGEditorTabPanel::setPanelsManager(wxTabPanelsManager* panelsManager)
171 _panelsManager = panelsManager;
174 //=========================================================================
176 void wxGEditorTabPanel::displayBlackBoxInfo(std::string packageName, std::string boxName)
178 _panelsManager->displayBlackBoxInfo(packageName,boxName);
181 //=========================================================================
183 void wxGEditorTabPanel::updateStatusBar(std::string textStatus)
185 _panelsManager->updateStatusBar(textStatus);
188 //=========================================================================
190 std::string wxGEditorTabPanel::getDiagramBBS(bool wln)
192 return _sceneManager->getDiagramBBS(wln);
195 //=========================================================================
197 std::string wxGEditorTabPanel::saveComplexBoxBBS()
199 return _sceneManager->saveComplexBoxBBS();
202 //=========================================================================
204 void wxGEditorTabPanel::editBlackBox(GBlackBoxModel *bbmodel)
206 _panelsManager->editBlackBox(bbmodel);
209 //=========================================================================
211 void wxGEditorTabPanel::deleteAllBoxes()
213 _sceneManager->deleteAllBoxes();
216 //=========================================================================
218 void wxGEditorTabPanel::centerView()
222 _sceneManager->centerView();
226 //=========================================================================
228 void wxGEditorTabPanel::saveDiagram(std::string &content, const std::string &path) //DFCH
230 this->SetFullPath(path);
231 _sceneManager->saveDiagram(content);
234 //=========================================================================
236 void wxGEditorTabPanel::saveTempDiagram(const std::string &action) //FCY
238 std::string content = "";
239 // writing file header
240 content += "# ----------------------------------\n";
241 content += "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file\n";
245 content += "# ----------------------------------\n";
247 content += "APP_START\n";
248 _sceneManager->saveDiagram(content);
249 content += "APP_END\n"; //put here to avoid mistakes
250 if(_actualdo == states.end() ) // same size, write to the end
252 states.push_back (content);
253 saveStringAction(action);
257 std::vector<std::string>::iterator it = _actualdo+1;
258 states.erase(it, states.end());
259 states.push_back(content);
261 std::vector<std::string>::iterator sit = _sactualdo+1;
262 sstates.erase(sit, sstates.end());
263 saveStringAction(action);
265 _actualdo = states.end();
266 _sactualdo = sstates.end();
270 //=========================================================================
272 void wxGEditorTabPanel::loadDiagram(ifstream &inputStream, const std::string &path) //DFCH
274 this->SetFullPath(path);
276 ss << inputStream.rdbuf() ;
277 _sceneManager->loadDiagram(ss);
280 //=========================================================================
281 unsigned short wxGEditorTabPanel::getUndoState( std::string &stun)
286 if(_actualdo == states.begin() )
294 stun += _sactualdo->substr(0,(--_sactualdo)->find_last_of("."));
301 unsigned short wxGEditorTabPanel::getRedoState( std::string &stre)
306 if(_actualdo == --states.end() || states.size() == 1 || _actualdo == states.end())
311 stre += _sactualdo->substr(0,(++_sactualdo)->find_last_of("."));
318 //=========================================================================
319 void wxGEditorTabPanel::loadTempDiagram(unsigned short un) //FCY
321 unsigned short res = 1;
323 std::stringstream ss;
326 if(_actualdo == states.end() ) // same size, write to the end
331 if(_actualdo != states.begin() )
333 ss << *(--_actualdo);
346 if(_actualdo != states.end())
355 _sceneManager->loadDiagram(ss);
359 void wxGEditorTabPanel::saveStringAction(const std::string &action)
362 sprintf(temp,".%d", sstates.size());
363 sstates.push_back(action + temp);
366 //=========================================================================
368 int wxGEditorTabPanel::getPanelId()
375 //=========================================================================
377 bool wxGEditorTabPanel::isComplexBox()
379 return _sceneManager->isComplexBox();
382 //=========================================================================
384 void wxGEditorTabPanel::setComplexBox(bool val)
386 _sceneManager->setComplexBox(val);
389 //=========================================================================
391 void wxGEditorTabPanel::addComplexInputPort(std::string portName)
393 _sceneManager->createGComplexBoxInputPort(portName);
396 //=========================================================================
398 void wxGEditorTabPanel::addComplexOutputPort(std::string portName)
400 _sceneManager->createGComplexBoxOutputPort(portName);
403 //=========================================================================
405 std::map<int,GObjectController*> wxGEditorTabPanel::getSelectedObjects()
407 return _sceneManager->getSelectedObjects();
410 //=========================================================================
412 void wxGEditorTabPanel::addObjects(std::map<int,GObjectController*> objectsMap)
414 _sceneManager->addObjects(objectsMap);
417 //=========================================================================
419 int wxGEditorTabPanel::getNumSelectedObjects()
421 return _sceneManager->getNumSelectedObjects();
424 //=========================================================================
427 wxVtkSceneManager* wxGEditorTabPanel::getSceneManager()
429 return _sceneManager;
432 //=========================================================================
433 std::string wxGEditorTabPanel::GetCbName()
435 return _sceneManager->GetCbName();
439 //=========================================================================
440 std::string wxGEditorTabPanel::GetCbPackageName()
442 return _sceneManager->GetCbPackageName();
445 //=========================================================================
446 std::string wxGEditorTabPanel::GetAuthor()
448 return _sceneManager->GetAuthor();
451 //=========================================================================
452 std::string wxGEditorTabPanel::GetDescription()
454 return _sceneManager->GetDescription();
457 //=========================================================================
458 std::string wxGEditorTabPanel::GetCategory()
460 return _sceneManager->GetCategory();
463 //=========================================================================
464 void wxGEditorTabPanel::SetCbName(std::string cbName)
466 _sceneManager->SetCbName( cbName );
469 //=========================================================================
470 void wxGEditorTabPanel::SetCbPackageName(std::string packagename)
472 _sceneManager->SetCbPackageName( packagename );
476 //=========================================================================
477 void wxGEditorTabPanel::SetAuthor(std::string author)
479 _sceneManager->SetAuthor( author );
483 //=========================================================================
484 void wxGEditorTabPanel::SetCategory(std::string category)
486 _sceneManager->SetCategory( category );
490 //=========================================================================
491 void wxGEditorTabPanel::SetDescription(std::string description)
493 _sceneManager->SetDescription( description );
495 //=========================================================================
497 void wxGEditorTabPanel::SetFullPath( const std::string& fullpath )
499 this->_fullPath = fullpath;
501 //=========================================================================
503 void wxGEditorTabPanel::SetFileName( const std::string& filename )
505 this->_fileName = filename;
507 //=========================================================================
509 std::string wxGEditorTabPanel::GetFullPath( )
511 return( this->_fullPath );
513 //=========================================================================
515 std::string wxGEditorTabPanel::GetFileName( )
517 return( this->_fileName );
523 } // EO namespace bbtk