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::wxVtkSceneManager .
37 #include "wxVtkSceneManager.h"
43 //=========================================================================
44 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView,int idManager)
54 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
56 _worldState=NOTHING_HAPPENS;
57 registerController(this);
63 //=========================================================================
65 void wxVtkSceneManager::disconnectDrop()
67 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
70 //=========================================================================
72 wxVtkSceneManager::~wxVtkSceneManager()
76 //=========================================================================
78 void wxVtkSceneManager::configureBaseView()
80 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
82 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
84 // Important to activate the 2D interaction system
85 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
86 interactorstylebaseview->SetInteractor ( iren );
87 iren->SetInteractorStyle(interactorstylebaseview);
88 interactorstylebaseview->SetwxVtkBaseView(_baseView);
90 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
91 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,900,1000);
93 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
94 _baseView->GetRenderer()->GradientBackgroundOff();
98 //=========================================================================
100 void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
103 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
104 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
106 int type = GBLACKBOX;
108 //Create the MVC Objects
110 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
111 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
112 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
114 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
116 //Prepares the initial model
117 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
120 double yy = windowHeight-y;
122 //z value is not important yet, because it is only used a parallel projection
125 _baseView->TransCoordScreenToWorld(xx,yy,zz);
126 model->setInicPoint(xx,yy,zz);
129 std::stringstream stream;
133 stream << "Box0" << _numBoxes;
137 stream << "Box" << _numBoxes;
139 std::string arraystring = stream.str();
141 model->setBBTKName(arraystring);
142 model->setBBTKType(boxType);
143 model->setBBTKPackage(packageName);
145 model->addObserver(view);
146 model->addObserver(this);
148 //Iterate and create the input ports
149 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
150 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
153 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
155 BlackBoxInputDescriptor *desc = itInput->second;
156 createGInputPort(GINPUTPORT,i,model,desc);
160 //Iterate and create the output ports
161 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
162 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
165 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
167 BlackBoxOutputDescriptor *desc = itOutput->second;
168 createGOutputPort(GOUTPUTPORT,i,model,desc);
173 //Associates the view with the correspondent renderer and the model.
174 //(NOTE: Refresh is only made by the view)
175 view->setModel(model);
176 view->setBaseView(_baseView);
177 view->initVtkObjects();
179 //Associates the controller with the correspondent model and view
180 controller->setModelAndView(model,view);
182 //Resgiter change to the observers of the actual model
183 model->notifyObservers(_idManager);
185 //Register the controller of the new object
186 registerController((InteractorStyleMaracas*) controller);
188 //Add the object to the objects list
189 int newId = _controllers.size();
190 controller->setId(newId);
191 _controllers[newId] = controller;
195 //=========================================================================
197 void wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxInputDescriptor *desc)
199 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
200 blackBox->addInputPort((GPortModel*)portController->getModel());
203 //=========================================================================
205 void wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
207 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
208 blackBox->addOutputPort((GPortModel*)portController->getModel());
211 //=========================================================================
213 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBlackBoxModel *blackBox)
217 //Create the MVC Objects
218 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
219 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
220 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
222 model->registerInBox(blackBox,portType, posInBox);
224 model->setBBTKType(bbtkType);
225 model->setBBTKName(bbtkName);
227 model->addObserver(view);
228 model->addObserver(this);
230 //Associates the view with the correspondent renderer and the model.
231 //(NOTE: Refresh is only made by the view)
232 view->setModel(model);
233 view->setBaseView(_baseView);
234 view->initVtkObjects();
236 //Associates the controller with the correspondent model and view
237 controller->setModelAndView(model,view);
239 model->notifyObservers(_idManager);
241 //Register the controller of the new object
242 registerController((InteractorStyleMaracas*) controller);
244 int newId = _controllers.size();
245 controller->setId(newId);
246 _controllers[newId] = controller;
248 return (GPortController*)controller;
251 //=========================================================================
253 void wxVtkSceneManager::createGConnector(GPortModel* startPort)
255 int type = GCONNECTOR;
257 manualConnectorContourController* manContourControl = new manualConnectorContourController();
258 manualConnectorContourView* manContourView = new manualConnectorContourView();
259 manualContourModel* manContourModel = new manualContourModel();
261 GConnectorController* connectorcontroller = new GConnectorController();
262 GConnectorModel* connectorModel = new GConnectorModel();
263 GConnectorView* connectorView = new GConnectorView();
264 connectorModel->setGObjectType(type);
266 manContourModel->SetCloseContour(false);
267 connectorModel->setStartPort(startPort);
269 manContourView->SetModel( manContourModel );
270 manContourView->SetWxVtkBaseView( _baseView );
271 manContourView->SetRange( 0.5 );
272 manContourView->SetZ( 900 );
274 manContourView->SetColorNormalContour(0, 0, 1);
275 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
276 manContourView->SetColorSelectContour(1, 0.8, 0);
277 manContourView->SetWidthLine(1);
278 manContourView->SetShowText(false);
280 manContourControl->SetModelView( manContourModel , manContourView );
282 manContourControl->CreateNewManualContour();
284 manContourView->RefreshContour();
288 connectorModel->getInicPoint(x,y,z);
290 manContourControl->SetState(1);
291 manContourModel->SetCloseContour(false);
293 manContourModel->AddPoint(x,y,z);
294 manContourView->AddPoint();
296 manContourModel->AddPoint(x,y,z);
297 manContourView->AddPoint();
299 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
300 manContourControl->_bakIdPoint=bak;
301 manContourView->Refresh();
303 manContourControl->SetMoving( false );
305 registerController((InteractorStyleMaracas*) connectorcontroller);
307 connectorcontroller->setManualContourController(manContourControl);
308 connectorModel->setManualContourModel(manContourModel);
309 connectorView->setManualContourView(manContourView);
310 connectorView->setModel(connectorModel);
311 connectorView->setBaseView(_baseView);
312 connectorcontroller->setModelAndView(connectorModel,connectorView);
314 connectorModel->addObserver(connectorView);
315 connectorModel->addObserver(this);
317 int newId = _controllers.size();
318 connectorcontroller->setId(newId);
319 _controllers[newId] = connectorcontroller;
323 //=========================================================================
325 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
327 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
328 baseViewControlManager->AddInteractorStyleMaracas( param );
331 //=========================================================================
333 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
335 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
336 baseViewControlManager->RemoveInteractorStyleMaracas( param );
339 //=========================================================================
341 vtkRenderer* wxVtkSceneManager::getRenderer()
343 return _baseView->GetRenderer();
346 //=========================================================================
348 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
350 return _baseView->GetRenWin();
352 //=========================================================================
355 void wxVtkSceneManager::update(int idController,int command)
357 if(command != NO_COMMAND)
359 if(command == ADD_TO_SELECTED)
361 GObjectController* cont = _controllers[idController];
364 for (int i=0; i<_selectedObjects.size() && foundID==false; i++)
366 int id = _selectedObjects[i];
374 int id = idController;
375 _selectedObjects.push_back(id);
376 cout<<"RaC wxVtkSceneManager::update _selectedObjects.push_back id:"<<id<<endl;
380 else if(command == INIT_CREATION_CONTOUR)
382 _worldState = INIT_CREATION_CONTOUR;
383 GObjectController* cont = _controllers[idController];
384 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
387 // The last one is the controller of the connector
388 for(int i=0;i<_controllers.size();i++)
390 GObjectController* cont = _controllers[i];
391 if(cont->getGObjectType() == GPORT )
393 GPortModel* port = (GPortModel*)cont->getModel();
394 if(port->getPortType()==GINPUTPORT)
396 cont->SetActive(true);
400 cont->getView()->setState(NOTHING_HAPPENS);
401 cont->getModel()->notifyObservers(_idManager);
402 cont->SetActive(false);
407 cont->getView()->setState(NOTHING_HAPPENS);
408 cont->getModel()->notifyObservers(_idManager);
409 cont->SetActive(false);
413 _selectedObjects.clear();
415 createGConnector(startOutputPort);
418 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
420 _worldState = NOTHING_HAPPENS;
421 int id = _controllers.size()-1;
422 GObjectController* cont = _controllers[id];
423 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
425 GObjectController* finPort = _controllers[idController];
426 if(finPort->getGObjectType() == GPORT)
428 GPortModel* modelPort = (GPortModel*)finPort->getModel();
429 modelContour->setEndPort(modelPort);
432 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
433 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
436 for(int i=0;i<_controllers.size();i++)
438 GObjectController* cont = _controllers[i];
439 if(cont->getView()!=NULL)
441 cont->getView()->setState(NOTHING_HAPPENS);
442 cont->getModel()->notifyObservers(_idManager);
444 cont->SetActive(true);
451 //=========================================================================
453 bool wxVtkSceneManager::OnMouseMove()
456 wxVTKRenderWindowInteractor *wxVTKiren;
457 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
458 wxVTKiren->GetEventPosition(X,Y);
461 if(_worldState == DRAG_OBJECTS)
463 for (int i=0; i<_selectedObjects.size(); i++)
465 int id = _selectedObjects[i];
466 GObjectController* cont = _controllers[id];
469 cont->getView()->setStartDragging(true);
471 cont->getView()->moveObject(X,Y);
472 cont->getView()->setState(DRAG);
473 cont->getModel()->notifyObservers(_idManager);
476 std::map<int, GObjectController*>::iterator it;
478 for(it = _controllers.begin(); it != _controllers.end(); ++it)
480 GObjectController *desc = it->second;
481 if(desc->getGObjectType()==GCONNECTOR)
483 GConnectorView* vconn = (GConnectorView*)desc->getView();
484 vconn->updateStartEndPoints();
488 _startDragging=false;
491 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
493 std::map<int, GObjectController*>::iterator it;
495 for(it = _controllers.begin(); it != _controllers.end(); ++it)
497 GObjectController *desc = it->second;
498 int type = desc->getGObjectType();
499 int state = desc->getView()->getState();
501 if(state == HIGHLIGHTED){
503 updateStatusBar(desc->getStatusText());
506 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
507 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
519 //=========================================================================
521 bool wxVtkSceneManager::OnLeftButtonDown()
523 if(_worldState==INIT_CREATION_CONTOUR)
525 bool isOverPort=false;
526 std::map<int, GObjectController*>::iterator it;
527 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
529 GObjectController *desc = it->second;
530 if(desc->getGObjectType()==GPORT)
532 GPortModel* portmod=(GPortModel*)desc->getModel();
533 vtkGObjectView* portView=desc->getView();
534 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
541 if(isOverPort==false)
543 _worldState=NOTHING_HAPPENS;
544 int lastId = _controllers.size()-1;
545 GConnectorController *connector = (GConnectorController*)_controllers[lastId];
546 connector->removeFromScene();
547 unregisterController(connector);
548 _controllers.erase(lastId);
550 for(it = _controllers.begin(); it != _controllers.end(); ++it)
552 GObjectController *desc = it->second;
553 desc->SetActive(true);
554 desc->getView()->setState(NOTHING_HAPPENS);
555 desc->getModel()->notifyObservers(_idManager);
560 if(_selectedObjects.size()!=0)
562 _worldState = DRAG_OBJECTS;
563 _startDragging = true;
565 for (int i = 0; i < _selectedObjects.size(); i++)
567 int id = _selectedObjects[i];
568 GObjectController* cont = _controllers[id];
569 cont->getView()->setState(DRAG);
570 cont->getModel()->notifyObservers(_idManager);
579 //=========================================================================
581 bool wxVtkSceneManager::OnLeftButtonUp()
583 if(_worldState == DRAG_OBJECTS)
585 _worldState = NOTHING_HAPPENS;
587 for (int i = 0; i < _selectedObjects.size(); i++)
589 int id = _selectedObjects[i];
590 GObjectController* cont = _controllers[id];
591 cont->getView()->setState(SELECTED);
592 cont->getModel()->notifyObservers(_idManager);
598 //=========================================================================
600 bool wxVtkSceneManager::OnRightButtonUp()
602 if(_worldState==INIT_CREATION_CONTOUR)
604 _worldState=NOTHING_HAPPENS;
605 int lastId = _controllers.size()-1;
606 GConnectorController *connector = (GConnectorController*)_controllers[lastId];
607 connector->removeFromScene();
608 unregisterController(connector);
609 _controllers.erase(lastId);
611 std::map<int, GObjectController*>::iterator it;
612 for(it = _controllers.begin(); it != _controllers.end(); ++it)
614 GObjectController *desc = it->second;
615 desc->SetActive(true);
616 desc->getView()->setState(NOTHING_HAPPENS);
617 desc->getModel()->notifyObservers(_idManager);
622 for (int i = 0; i < _selectedObjects.size(); i++)
624 int id = _selectedObjects[i];
625 GObjectController* cont = _controllers[id];
626 cont->SetActive(true);
627 cont->getView()->setState(NOTHING_HAPPENS);
628 cont->getModel()->notifyObservers(_idManager);
631 _selectedObjects.clear();
636 //=========================================================================
638 bool wxVtkSceneManager::OnLeftDClick()
641 wxVTKRenderWindowInteractor *wxVTKiren;
642 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
643 wxVTKiren->GetEventPosition(X,Y);
645 std::map<int, GObjectController*>::iterator it;
647 bool clickOnObject = false;
649 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
651 GObjectController *cont = it->second;
652 int type = cont->getGObjectType();
654 if(cont->getView()->isPointInside(X,Y))
658 for (int i=0; i<_selectedObjects.size(); i++)
660 int id = _selectedObjects[i];
661 GObjectController* control = _controllers[id];
662 control->getView()->setState(NOTHING_HAPPENS);
664 _selectedObjects.clear();
666 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
667 _parent->editBlackBox(bbmodel);
669 clickOnObject = true;
673 if(clickOnObject==false)
675 //_parent->editDiagramParameters(this);
681 //=========================================================================
683 bool wxVtkSceneManager::OnChar()
685 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
687 // KeyCode 127 : Delete Key
688 // KeyCode 8 : Backspace Key
689 if(keyCode == 8 || keyCode == 127)
691 if(_selectedObjects.size()>0)
693 for(int i=0;i<_selectedObjects.size();i++)
695 int id = _selectedObjects[i];
698 _selectedObjects.clear();
705 //=========================================================================
707 void wxVtkSceneManager::deleteObject(int id)
709 GObjectController *control = _controllers[id];
710 std::vector<int> controllersToRemove;
712 if(control->getGObjectType()==GBLACKBOX)
714 GBlackBoxModel *bbmod = (GBlackBoxModel*)control->getModel();
715 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
717 bool boxConnected = false;
719 // Add box input controllers to be removed
720 for(int i = 0;i<inputs.size();i++)
722 controllersToRemove.push_back(inputs[i]->getObjectId());
723 if(inputs[i]->isConnected())
729 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
731 // Add box output controllers to be removed
732 for(int i = 0;i<outputs.size();i++)
734 controllersToRemove.push_back(outputs[i]->getObjectId());
735 if(outputs[i]->isConnected())
741 // Add connection controllers to be removed
742 std::map<int, GObjectController*>::iterator it;
743 for(it = _controllers.begin(); it != _controllers.end(); ++it)
745 GObjectController *cont = it->second;
746 int type = cont->getGObjectType();
749 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
750 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
752 controllersToRemove.push_back(conMod->getObjectId());
754 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
756 controllersToRemove.push_back(conMod->getObjectId());
761 // Add box controller to be removed
762 controllersToRemove.push_back(bbmod->getObjectId());
764 else if(control->getGObjectType()==GCONNECTOR)
766 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
767 cout<<"RaC wxVtkSceneManager::deleteObject id:"<<id<<" modelId:" <<conMod->getObjectId()<<endl;
768 controllersToRemove.push_back(conMod->getObjectId());
771 for(int i = 0;i<controllersToRemove.size();i++)
773 int id = controllersToRemove[i];
774 GObjectController *cont = _controllers[id];
775 cont->removeFromScene();
776 unregisterController((InteractorStyleMaracas*)cont);
777 _controllers.erase(id);
783 //=========================================================================
785 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
787 _parent->displayBlackBoxInfo(packageName,boxName);
790 //=========================================================================
792 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
794 _parent->updateStatusBar(textStatus);
797 //=========================================================================
799 std::string wxVtkSceneManager::getDiagramScript()
801 bool existsExec=false;
803 std::vector<std::string> packages;
804 std::vector<int> boxes;
805 std::vector<int> connections;
806 std::vector<int> execBoxes;
808 std::map<int, GObjectController*>::iterator it;
810 for(it = _controllers.begin(); it != _controllers.end(); ++it)
812 GObjectController *desc = it->second;
813 int type = desc->getGObjectType();
817 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
819 std::string pkg = mod->getBBTKPackage();
820 bool existsPkg = false;
821 for(int t = 0;t<packages.size() && existsPkg == false;t++)
830 packages.push_back(pkg);
834 boxes.push_back(it->first);
835 if(mod->isExecutable())
837 execBoxes.push_back(it->first);
841 else if(type==GCONNECTOR)
843 connections.push_back(it->first);
847 std::string script = "";
848 script+="# BBTK GEditor Script\n";
849 script+="# ----------------------\n";
853 for(i = 0; i<packages.size();i++)
860 script+="include std\n";
862 for(i = 0; i<boxes.size();i++)
866 GObjectController *control = _controllers[id];
867 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
869 script+=model->getBBTKType();
871 script+=model->getBBTKName();
874 std::vector<GPortModel*> inputs = model->getInputPorts();
875 for(int j = 0; j<inputs.size();j++)
877 GPortModel* inputPort = inputs[j];
878 if(inputPort->isValueSet())
881 script+=model->getBBTKName();
883 script+=inputPort->getBBTKName();
885 script+=inputPort->getValue();
892 for(i = 0; i<connections.size();i++)
895 int id = connections[i];
896 GObjectController *control = _controllers[id];
897 GConnectorModel *model = (GConnectorModel*)control->getModel();
899 //Start Connection info
900 GPortModel *start = model->getStartPort();
901 script+=start->getParentBox()->getBBTKName();
903 script+=start->getBBTKName();
907 //End Connection info
908 GPortModel *end = model->getEndPort();
909 script+=end->getParentBox()->getBBTKName();
911 script+=end->getBBTKName();
916 for(i = 0; i<execBoxes.size();i++)
919 int id = execBoxes[i];
920 GObjectController *control = _controllers[id];
921 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
923 script+=model->getBBTKName();
932 //=========================================================================
934 void wxVtkSceneManager::deleteAllBoxes()
936 std::map<int, GObjectController*>::iterator it;
937 for(it = _controllers.begin(); it != _controllers.end(); ++it)
939 GObjectController *cont = it->second;
940 cont->removeFromScene();
941 unregisterController((InteractorStyleMaracas*)cont);
943 _selectedObjects.clear();
944 _controllers.clear();
948 //=========================================================================
950 void wxVtkSceneManager::refreshScene()
952 _baseView->RefreshView();
955 //=========================================================================
957 void wxVtkSceneManager::centerView()
960 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
961 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
962 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
963 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
964 _baseView->RefreshView();
968 //=========================================================================
970 void wxVtkSceneManager::saveDiagram(std::string &content)
974 std::vector<int> boxes = getBoxes();
975 int bsize = boxes.size();
977 sprintf (buffer, "%d", bsize);
981 for(int i = 0;i<bsize;i++)
984 GObjectController *cont = _controllers[id];
985 cont->getModel()->save(content);
991 std::vector<int> connections = getConnections();
992 int csize = connections.size();
993 content+="CONNECTIONS ";
994 sprintf (buffer, "%d", csize);
998 for(int i = 0;i<csize;i++)
1000 int id = connections[i];
1001 GObjectController *cont = _controllers[id];
1002 cont->getModel()->save(content);
1007 //=========================================================================
1009 std::vector<int> wxVtkSceneManager::getBoxes()
1011 std::vector<int> vect;
1012 std::map<int, GObjectController*>::iterator it;
1013 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1015 GObjectController *cont = it->second;
1016 if(cont->getGObjectType()==GBLACKBOX)
1018 vect.push_back(cont->getId());
1024 //=========================================================================
1026 std::vector<int> wxVtkSceneManager::getConnections()
1028 std::vector<int> vect;
1029 std::map<int, GObjectController*>::iterator it;
1030 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1032 GObjectController *cont = it->second;
1033 if(cont->getGObjectType()==GCONNECTOR)
1035 vect.push_back(cont->getId());
1041 //=========================================================================
1043 } // EO namespace bbtk