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 int 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;
196 //=========================================================================
198 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxInputDescriptor *desc)
200 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
201 blackBox->addInputPort((GPortModel*)portController->getModel());
202 return portController->getId();
205 //=========================================================================
207 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
209 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
210 blackBox->addOutputPort((GPortModel*)portController->getModel());
211 return portController->getId();
214 //=========================================================================
216 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBlackBoxModel *blackBox)
220 //Create the MVC Objects
221 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
222 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
223 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
225 model->registerInBox(blackBox,portType, posInBox);
227 model->setBBTKType(bbtkType);
228 model->setBBTKName(bbtkName);
230 model->addObserver(view);
231 model->addObserver(this);
233 //Associates the view with the correspondent renderer and the model.
234 //(NOTE: Refresh is only made by the view)
235 view->setModel(model);
236 view->setBaseView(_baseView);
237 view->initVtkObjects();
239 //Associates the controller with the correspondent model and view
240 controller->setModelAndView(model,view);
242 model->notifyObservers(_idManager);
244 //Register the controller of the new object
245 registerController((InteractorStyleMaracas*) controller);
247 int newId = _controllers.size();
248 controller->setId(newId);
249 _controllers[newId] = controller;
251 return (GPortController*)controller;
254 //=========================================================================
256 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
258 int type = GCONNECTOR;
260 manualConnectorContourController* manContourControl = new manualConnectorContourController();
261 manualConnectorContourView* manContourView = new manualConnectorContourView();
262 manualContourModel* manContourModel = new manualContourModel();
264 GConnectorController* connectorcontroller = new GConnectorController();
265 GConnectorModel* connectorModel = new GConnectorModel();
266 vtkGConnectorView* connectorView = new vtkGConnectorView();
267 connectorModel->setGObjectType(type);
269 manContourModel->SetCloseContour(false);
270 connectorModel->setStartPort(startPort);
272 manContourView->SetModel( manContourModel );
273 manContourView->SetWxVtkBaseView( _baseView );
274 manContourView->SetRange( 0.5 );
275 manContourView->SetZ( 900 );
277 manContourView->SetColorNormalContour(0, 0, 1);
278 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
279 manContourView->SetColorSelectContour(1, 0.8, 0);
280 manContourView->SetWidthLine(1);
281 manContourView->SetShowText(false);
283 manContourControl->SetModelView( manContourModel , manContourView );
285 manContourControl->CreateNewManualContour();
287 manContourView->RefreshContour();
291 connectorModel->getInicPoint(x,y,z);
293 manContourControl->SetState(1);
294 manContourModel->SetCloseContour(false);
296 manContourModel->AddPoint(x,y,z);
297 manContourView->AddPoint();
299 manContourModel->AddPoint(x,y,z);
300 manContourView->AddPoint();
302 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
303 manContourControl->_bakIdPoint=bak;
304 manContourView->Refresh();
306 manContourControl->SetMoving( false );
308 registerController((InteractorStyleMaracas*) connectorcontroller);
310 connectorcontroller->setManualContourController(manContourControl);
311 connectorModel->setManualContourModel(manContourModel);
312 connectorView->setManualContourView(manContourView);
313 connectorView->setModel(connectorModel);
314 connectorView->setBaseView(_baseView);
315 connectorcontroller->setModelAndView(connectorModel,connectorView);
317 connectorModel->addObserver(connectorView);
318 connectorModel->addObserver(this);
320 int newId = _controllers.size();
321 connectorcontroller->setId(newId);
322 _controllers[newId] = connectorcontroller;
327 //=========================================================================
329 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
331 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
332 baseViewControlManager->AddInteractorStyleMaracas( param );
335 //=========================================================================
337 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
339 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
340 baseViewControlManager->RemoveInteractorStyleMaracas( param );
343 //=========================================================================
345 vtkRenderer* wxVtkSceneManager::getRenderer()
347 return _baseView->GetRenderer();
350 //=========================================================================
352 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
354 return _baseView->GetRenWin();
356 //=========================================================================
359 void wxVtkSceneManager::update(int idController,int command)
361 if(command != NO_COMMAND)
363 if(command == ADD_TO_SELECTED)
365 GObjectController* cont = _controllers[idController];
368 for (int i=0; i<_selectedObjects.size() && foundID==false; i++)
370 int id = _selectedObjects[i];
378 int id = idController;
379 _selectedObjects.push_back(id);
383 else if(command == INIT_CREATION_CONTOUR)
385 _worldState = INIT_CREATION_CONTOUR;
386 GObjectController* cont = _controllers[idController];
387 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
390 // The last one is the controller of the connector
391 for(int i=0;i<_controllers.size();i++)
393 GObjectController* cont = _controllers[i];
394 if(cont->getGObjectType() == GPORT )
396 GPortModel* port = (GPortModel*)cont->getModel();
397 if(port->getPortType()==GINPUTPORT)
399 cont->SetActive(true);
403 cont->getView()->setState(NOTHING_HAPPENS);
404 cont->getModel()->notifyObservers(_idManager);
405 cont->SetActive(false);
410 cont->getView()->setState(NOTHING_HAPPENS);
411 cont->getModel()->notifyObservers(_idManager);
412 cont->SetActive(false);
416 _selectedObjects.clear();
418 createGConnector(startOutputPort);
421 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
423 _worldState = NOTHING_HAPPENS;
424 int id = _controllers.size()-1;
425 GObjectController* cont = _controllers[id];
426 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
428 GObjectController* finPort = _controllers[idController];
429 if(finPort->getGObjectType() == GPORT)
431 GPortModel* modelPort = (GPortModel*)finPort->getModel();
432 modelContour->setEndPort(modelPort);
435 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
436 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
439 for(int i=0;i<_controllers.size();i++)
441 GObjectController* cont = _controllers[i];
442 if(cont->getView()!=NULL)
444 cont->getView()->setState(NOTHING_HAPPENS);
445 cont->getModel()->notifyObservers(_idManager);
447 cont->SetActive(true);
454 //=========================================================================
456 bool wxVtkSceneManager::OnMouseMove()
459 wxVTKRenderWindowInteractor *wxVTKiren;
460 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
461 wxVTKiren->GetEventPosition(X,Y);
464 if(_worldState == DRAG_OBJECTS)
466 for (int i=0; i<_selectedObjects.size(); i++)
468 int id = _selectedObjects[i];
469 GObjectController* cont = _controllers[id];
472 cont->getView()->setStartDragging(true);
474 cont->getView()->moveObject(X,Y);
475 cont->getView()->setState(DRAG);
476 cont->getModel()->notifyObservers(_idManager);
479 std::map<int, GObjectController*>::iterator it;
481 for(it = _controllers.begin(); it != _controllers.end(); ++it)
483 GObjectController *desc = it->second;
484 if(desc->getGObjectType()==GCONNECTOR)
486 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
487 vconn->updateStartEndPoints();
491 _startDragging=false;
494 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
496 std::map<int, GObjectController*>::iterator it;
498 for(it = _controllers.begin(); it != _controllers.end(); ++it)
500 GObjectController *desc = it->second;
501 int type = desc->getGObjectType();
502 int state = desc->getView()->getState();
504 if(state == HIGHLIGHTED){
506 updateStatusBar(desc->getStatusText());
509 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
510 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
522 //=========================================================================
524 bool wxVtkSceneManager::OnLeftButtonDown()
526 if(_worldState==INIT_CREATION_CONTOUR)
528 bool isOverPort=false;
529 std::map<int, GObjectController*>::iterator it;
530 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
532 GObjectController *desc = it->second;
533 if(desc->getGObjectType()==GPORT)
535 GPortModel* portmod=(GPortModel*)desc->getModel();
536 vtkGObjectView* portView=desc->getView();
537 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
544 if(isOverPort==false)
546 _worldState=NOTHING_HAPPENS;
547 int lastId = _controllers.size()-1;
548 GConnectorController *connector = (GConnectorController*)_controllers[lastId];
549 connector->removeFromScene();
550 unregisterController(connector);
551 _controllers.erase(lastId);
553 for(it = _controllers.begin(); it != _controllers.end(); ++it)
555 GObjectController *desc = it->second;
556 desc->SetActive(true);
557 desc->getView()->setState(NOTHING_HAPPENS);
558 desc->getModel()->notifyObservers(_idManager);
563 if(_selectedObjects.size()!=0)
565 _worldState = DRAG_OBJECTS;
566 _startDragging = true;
568 for (int i = 0; i < _selectedObjects.size(); i++)
570 int id = _selectedObjects[i];
571 GObjectController* cont = _controllers[id];
572 cont->getView()->setState(DRAG);
573 cont->getModel()->notifyObservers(_idManager);
582 //=========================================================================
584 bool wxVtkSceneManager::OnLeftButtonUp()
586 if(_worldState == DRAG_OBJECTS)
588 _worldState = NOTHING_HAPPENS;
590 for (int i = 0; i < _selectedObjects.size(); i++)
592 int id = _selectedObjects[i];
593 GObjectController* cont = _controllers[id];
594 cont->getView()->setState(SELECTED);
595 cont->getModel()->notifyObservers(_idManager);
601 //=========================================================================
603 bool wxVtkSceneManager::OnRightButtonUp()
605 if(_worldState==INIT_CREATION_CONTOUR)
607 _worldState=NOTHING_HAPPENS;
608 int lastId = _controllers.size()-1;
609 GConnectorController *connector = (GConnectorController*)_controllers[lastId];
610 connector->removeFromScene();
611 unregisterController(connector);
612 _controllers.erase(lastId);
614 std::map<int, GObjectController*>::iterator it;
615 for(it = _controllers.begin(); it != _controllers.end(); ++it)
617 GObjectController *desc = it->second;
618 desc->SetActive(true);
619 desc->getView()->setState(NOTHING_HAPPENS);
620 desc->getModel()->notifyObservers(_idManager);
625 for (int i = 0; i < _selectedObjects.size(); i++)
627 int id = _selectedObjects[i];
628 GObjectController* cont = _controllers[id];
629 cont->SetActive(true);
630 cont->getView()->setState(NOTHING_HAPPENS);
631 cont->getModel()->notifyObservers(_idManager);
634 _selectedObjects.clear();
639 //=========================================================================
641 bool wxVtkSceneManager::OnLeftDClick()
644 wxVTKRenderWindowInteractor *wxVTKiren;
645 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
646 wxVTKiren->GetEventPosition(X,Y);
648 std::map<int, GObjectController*>::iterator it;
650 bool clickOnObject = false;
652 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
654 GObjectController *cont = it->second;
655 int type = cont->getGObjectType();
657 if(cont->getView()->isPointInside(X,Y))
661 for (int i=0; i<_selectedObjects.size(); i++)
663 int id = _selectedObjects[i];
664 GObjectController* control = _controllers[id];
665 control->getView()->setState(NOTHING_HAPPENS);
667 _selectedObjects.clear();
669 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
670 _parent->editBlackBox(bbmodel);
672 clickOnObject = true;
676 if(clickOnObject==false)
678 //_parent->editDiagramParameters(this);
684 //=========================================================================
686 bool wxVtkSceneManager::OnChar()
688 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
690 // KeyCode 127 : Delete Key
691 // KeyCode 8 : Backspace Key
692 if(keyCode == 8 || keyCode == 127)
694 if(_selectedObjects.size()>0)
696 for(int i=0;i<_selectedObjects.size();i++)
698 int id = _selectedObjects[i];
701 _selectedObjects.clear();
708 //=========================================================================
710 void wxVtkSceneManager::deleteObject(int id)
712 GObjectController *control = _controllers[id];
713 std::vector<int> controllersToRemove;
715 if(control->getGObjectType()==GBLACKBOX)
717 GBlackBoxModel *bbmod = (GBlackBoxModel*)control->getModel();
718 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
720 bool boxConnected = false;
722 // Add box input controllers to be removed
723 for(int i = 0;i<inputs.size();i++)
725 controllersToRemove.push_back(inputs[i]->getObjectId());
726 if(inputs[i]->isConnected())
732 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
734 // Add box output controllers to be removed
735 for(int i = 0;i<outputs.size();i++)
737 controllersToRemove.push_back(outputs[i]->getObjectId());
738 if(outputs[i]->isConnected())
744 // Add connection controllers to be removed
745 std::map<int, GObjectController*>::iterator it;
746 for(it = _controllers.begin(); it != _controllers.end(); ++it)
748 GObjectController *cont = it->second;
749 int type = cont->getGObjectType();
752 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
753 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
755 controllersToRemove.push_back(conMod->getObjectId());
757 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
759 controllersToRemove.push_back(conMod->getObjectId());
764 // Add box controller to be removed
765 controllersToRemove.push_back(bbmod->getObjectId());
767 else if(control->getGObjectType()==GCONNECTOR)
769 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
770 controllersToRemove.push_back(conMod->getObjectId());
773 for(int i = 0;i<controllersToRemove.size();i++)
775 int id = controllersToRemove[i];
776 GObjectController *cont = _controllers[id];
777 cont->removeFromScene();
778 unregisterController((InteractorStyleMaracas*)cont);
779 _controllers.erase(id);
785 //=========================================================================
787 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
789 _parent->displayBlackBoxInfo(packageName,boxName);
792 //=========================================================================
794 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
796 _parent->updateStatusBar(textStatus);
799 //=========================================================================
801 std::string wxVtkSceneManager::getDiagramScript()
803 bool existsExec=false;
805 std::vector<std::string> packages;
806 std::vector<int> boxes;
807 std::vector<int> connections;
808 std::vector<int> execBoxes;
810 std::map<int, GObjectController*>::iterator it;
812 for(it = _controllers.begin(); it != _controllers.end(); ++it)
814 GObjectController *desc = it->second;
815 int type = desc->getGObjectType();
819 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
821 std::string pkg = mod->getBBTKPackage();
822 bool existsPkg = false;
823 for(int t = 0;t<packages.size() && existsPkg == false;t++)
832 packages.push_back(pkg);
836 boxes.push_back(it->first);
837 if(mod->isExecutable())
839 execBoxes.push_back(it->first);
843 else if(type==GCONNECTOR)
845 connections.push_back(it->first);
849 std::string script = "";
850 script+="# BBTK GEditor Script\n";
851 script+="# ----------------------\n";
855 for(i = 0; i<packages.size();i++)
862 script+="include std\n";
864 for(i = 0; i<boxes.size();i++)
868 GObjectController *control = _controllers[id];
869 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
871 script+=model->getBBTKType();
873 script+=model->getBBTKName();
876 std::vector<GPortModel*> inputs = model->getInputPorts();
877 for(int j = 0; j<inputs.size();j++)
879 GPortModel* inputPort = inputs[j];
880 if(inputPort->isValueSet())
883 script+=model->getBBTKName();
885 script+=inputPort->getBBTKName();
887 script+=inputPort->getValue();
894 for(i = 0; i<connections.size();i++)
897 int id = connections[i];
898 GObjectController *control = _controllers[id];
899 GConnectorModel *model = (GConnectorModel*)control->getModel();
901 //Start Connection info
902 GPortModel *start = model->getStartPort();
903 script+=start->getParentBox()->getBBTKName();
905 script+=start->getBBTKName();
909 //End Connection info
910 GPortModel *end = model->getEndPort();
911 script+=end->getParentBox()->getBBTKName();
913 script+=end->getBBTKName();
918 for(i = 0; i<execBoxes.size();i++)
921 int id = execBoxes[i];
922 GObjectController *control = _controllers[id];
923 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
925 script+=model->getBBTKName();
934 //=========================================================================
936 void wxVtkSceneManager::deleteAllBoxes()
938 std::map<int, GObjectController*>::iterator it;
939 for(it = _controllers.begin(); it != _controllers.end(); ++it)
941 GObjectController *cont = it->second;
942 cont->removeFromScene();
943 unregisterController((InteractorStyleMaracas*)cont);
945 _selectedObjects.clear();
946 _controllers.clear();
950 //=========================================================================
952 void wxVtkSceneManager::refreshScene()
954 _baseView->RefreshView();
957 //=========================================================================
959 void wxVtkSceneManager::centerView()
962 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
963 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
964 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
965 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
966 _baseView->RefreshView();
970 //=========================================================================
972 void wxVtkSceneManager::saveDiagram(std::string &content)
976 std::vector<int> boxes = getBoxes();
977 int bsize = boxes.size();
979 sprintf (buffer, "%d", bsize);
983 for(int i = 0;i<bsize;i++)
986 GObjectController *cont = _controllers[id];
987 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 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1012 std::string line="";
1013 char delims[] = ":";
1014 char *result = NULL;
1015 getline(inputStream,line);
1018 while ( !inputStream.eof() )
1020 if(line=="" || line[0]=='#')
1022 getline(inputStream,line);
1024 else if(line=="APP_START")
1034 getline(inputStream,line);//BOXES:num
1036 strcpy( boxes, line.c_str() );
1037 result = strtok( boxes, delims );
1038 result = strtok( NULL, delims );
1041 std::istringstream is(result);
1044 for(int i = 0;i<numBoxes;i++)
1047 getline(inputStream,line);//BOX
1048 getline(inputStream,line);//package:type:name
1050 strcpy( box, line.c_str() );
1051 result = strtok( box, delims );//package
1052 std::string package(result);
1053 result = strtok( NULL, delims );//type
1054 std::string type(result);
1055 result = strtok( NULL, delims );//name
1056 std::string name(result);
1058 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1060 strcpy( exec, line.c_str() );
1061 result = strtok( exec, delims );//ISEXEC
1062 result = strtok( NULL, delims );//TRUE|FALSE
1063 std::string isExec(result);
1066 getline(inputStream,line);//xInic:yInic:zInic
1068 strcpy( coord, line.c_str() );
1069 result = strtok( coord, delims );//xInic
1070 std::string xInic(result);
1071 result = strtok( NULL, delims );//yInic
1072 std::string yInic(result);
1073 result = strtok( NULL, delims );//zInic
1074 std::string zInic(result);
1076 double xIn, yIn, zIn;
1077 std::istringstream xSt(xInic);
1079 std::istringstream ySt(yInic);
1081 std::istringstream zSt(zInic);
1085 getline(inputStream,line);//xEnd:yEnd:zEnd
1086 strcpy( coord, line.c_str() );
1087 result = strtok( coord, delims );//xEnd
1088 std::string xEnd(result);
1089 result = strtok( NULL, delims );//yEnd
1090 std::string yEnd(result);
1091 result = strtok( NULL, delims );//zEnd
1092 std::string zEnd(result);
1094 double xEn, yEn, zEn;
1095 std::istringstream xEt(xEnd);
1097 std::istringstream yEt(yEnd);
1099 std::istringstream zEt(zEnd);
1102 int idBox = createGBlackBox(0,0,package,type);
1103 GObjectController *cont = _controllers[idBox];
1104 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1105 bbmod->setBBTKName(name);
1106 bbmod->setInicPoint(xIn,yIn,zIn);
1107 bbmod->setFinalPoint(xEn,yEn,zEn);
1110 bbmod->setExecutable(true);
1112 else if(isExec=="FALSE")
1114 bbmod->setExecutable(false);
1118 getline(inputStream,line);//PORT o FIN_BOX
1119 std::string port=line.substr(0,4);
1122 getline(inputStream,line);//name:value
1124 strcpy( poort, line.c_str() );
1125 result = strtok( poort, delims );//name
1126 std::string name(result);
1127 result = strtok( NULL, delims );//value
1128 std::string value(result);
1130 bbmod->setValueToInput(name,value);
1132 getline(inputStream,line);//PORT o FIN_BOX
1133 port=line.substr(0,4);
1136 bbmod->notifyObservers(_idManager);
1141 getline(inputStream,line);//CONNECTIONS:num
1143 strcpy( conns, line.c_str() );
1144 result = strtok( conns, delims );
1145 result = strtok( NULL, delims );
1148 std::istringstream isCons(result);
1151 for(int i = 0;i<numConns;i++)
1154 getline(inputStream,line);//CONNECTION
1155 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1158 strcpy( connec, line.c_str() );
1159 result = strtok( connec, delims );
1160 std::string nameStartBox(result);
1161 result = strtok( NULL, delims );
1162 std::string nameStartPort(result);
1163 result = strtok( NULL, delims );
1164 std::string nameEndBox(result);
1165 result = strtok( NULL, delims );
1166 std::string nameEndPort(result);
1168 std::vector<int> lstB = getBoxes();
1170 GPortModel *startP=NULL;
1171 GPortModel *endP=NULL;
1172 for(int j = 0;j<lstB.size();j++)
1175 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1176 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1178 startP = bbMod->getOutputPort(nameStartPort);
1180 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1182 endP = bbMod->getInputPort(nameEndPort);
1186 int idCon = createGConnector(startP);
1187 _worldState = NOTHING_HAPPENS;
1188 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1190 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1191 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1192 tempp->endContourCreation();
1193 conMod->setEndPort(endP);
1194 conView->updateStartEndPoints();
1201 //=========================================================================
1203 std::vector<int> wxVtkSceneManager::getBoxes()
1205 std::vector<int> vect;
1206 std::map<int, GObjectController*>::iterator it;
1207 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1209 GObjectController *cont = it->second;
1210 if(cont->getGObjectType()==GBLACKBOX)
1212 vect.push_back(cont->getId());
1218 //=========================================================================
1220 std::vector<int> wxVtkSceneManager::getConnections()
1222 std::vector<int> vect;
1223 std::map<int, GObjectController*>::iterator it;
1224 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1226 GObjectController *cont = it->second;
1227 if(cont->getGObjectType()==GCONNECTOR)
1229 vect.push_back(cont->getId());
1235 //=========================================================================
1237 } // EO namespace bbtk