2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
8 # This software is governed by the CeCILL-B license under French law and
9 # abiding by the rules of distribution of free software. You can use,
10 # modify and/ or redistribute the software under the terms of the CeCILL-B
11 # license as circulated by CEA, CNRS and INRIA at the following URL
12 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
13 # or in the file LICENSE.txt.
15 # As a counterpart to the access to the source code and rights to copy,
16 # modify and redistribute granted by the license, users are provided only
17 # with a limited warranty and the software's author, the holder of the
18 # economic rights, and the successive licensors have only limited
21 # The fact that you are presently reading this means that you have had
22 # knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------
26 /*=========================================================================
32 =========================================================================*/
34 /* ---------------------------------------------------------------------
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
39 * This software is governed by the CeCILL-B license under French law and
40 * abiding by the rules of distribution of free software. You can use,
41 * modify and/ or redistribute the software under the terms of the CeCILL-B
42 * license as circulated by CEA, CNRS and INRIA at the following URL
43 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
44 * or in the file LICENSE.txt.
46 * As a counterpart to the access to the source code and rights to copy,
47 * modify and redistribute granted by the license, users are provided only
48 * with a limited warranty and the software's author, the holder of the
49 * economic rights, and the successive licensors have only limited
52 * The fact that you are presently reading this means that you have had
53 * knowledge of the CeCILL-B license and that you accept its terms.
54 * ------------------------------------------------------------------------ */
58 * \brief Class bbtk::wxVtkSceneManager .
61 #include "wxVtkSceneManager.h"
63 #include <vtkPolygon.h>
64 #include <vtkUnstructuredGrid.h>
68 #define POORT_MAX_LINE_SIZE_INTERPRETER 1500
70 //=========================================================================
72 // EED 15 oct 2012 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
74 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
76 _cbName = "ComplexBoxName";
77 _cbPackageName = "PackageName";
78 _Author = "Author ??";
80 _Description = "Description ??";
84 _idManager = idManager;
86 _bbtkfactory = bbtkfactory;
88 _startDragging = false;
89 _isComplexBox = false;
91 if (_baseView != NULL) {
94 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
97 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
101 _worldState = NOTHING_HAPPENS;
102 registerController(this);
105 _idConnectionInCreation = -1;
110 //=========================================================================
112 void wxVtkSceneManager::disconnectDrop()
114 printf("EED %p ~wxVtkSceneManager::disconnectDrop()\n", this);
115 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
116 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
119 //=========================================================================
121 wxVtkSceneManager::~wxVtkSceneManager()
124 printf("EED %p ~wxVtkSceneManager() START\n", this);
127 printf("EED %p ~wxVtkSceneManager() END\n", this);
130 //=========================================================================
132 void wxVtkSceneManager::configureBaseView()
134 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
136 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
138 // Important to activate the 2D interaction system
139 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
140 interactorstylebaseview->SetInteractor(iren);
141 iren->SetInteractorStyle(interactorstylebaseview);
142 interactorstylebaseview->SetwxVtkBaseView(_baseView);
144 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
145 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, -1000, 1000);
146 _baseView->GetRenderer()->GetActiveCamera()->Zoom(10);
149 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
150 _baseView->GetRenderer()->GradientBackgroundOn();
153 _textActor = vtkTextActor3D::New();
154 _textActor->SetPosition(-9999, -9999, GPOSITION_Z);
155 _textActor->SetInput("<void>");
156 _textActor->GetTextProperty()->SetFontSize(60);
157 _textActor->GetTextProperty()->BoldOn();
158 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,PORTTEXT_NH_B);
160 _baseView->GetRenderer()->AddActor(_textActor);
162 // Actor Fill_Port_Text
167 double zInic = GPOSITION_Z;
169 vtkPolygon *aPolygon = vtkPolygon::New();
170 _fillObjectActor = vtkActor::New();
172 _pts = vtkPoints::New();
174 double w = 100, h = 10, b = h / 15, t = 3;
175 _pts->SetNumberOfPoints(21);
176 _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
177 _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
178 _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
179 _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
180 _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
182 _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
183 _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
184 _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
185 _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
187 _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
188 _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
189 _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
190 _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
192 _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
193 _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
194 _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
195 _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
197 _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
198 _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
199 _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
200 _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
202 aPolygon->GetPointIds()->SetNumberOfIds(21);
203 for (int i = 0; i < 21; i++) {
204 aPolygon->GetPointIds()->SetId(i, i);
207 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
208 aPolygonGrid->Allocate(1, 1);
209 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),
210 aPolygon->GetPointIds());
211 aPolygonGrid->SetPoints(_pts);
212 _aPolygonMapper = vtkDataSetMapper::New();
213 _aPolygonMapper->SetInput(aPolygonGrid);
214 _fillObjectActor->SetMapper(_aPolygonMapper);
215 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
217 _fillObjectActor->GetProperty()->SetOpacity(0);
218 _aPolygonMapper->Modified();
220 _baseView->GetRenderer()->AddActor(_fillObjectActor);
223 //=========================================================================
225 std::string wxVtkSceneManager::generateANewNameForABox() {
226 std::stringstream boxname;
227 if (_numBoxes < 10) {
228 boxname << "Box0" << _numBoxes;
230 boxname << "Box" << _numBoxes;
233 return boxname.str();
236 //=========================================================================
238 std::string wxVtkSceneManager::findANewNameForABox() {
239 std::string boxname = generateANewNameForABox();
241 while (boxExist(boxname) == true) {
242 boxname = generateANewNameForABox();
248 //=========================================================================
249 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
250 double zIn, std::string name, bool boxExecutable, double xEn,
251 double yEn, double zEn) {
252 GObjectController *cont = _controllers[idBox];
253 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
254 bbmod->setBBTKName(name);
255 bbmod->setInicPoint(xIn, yIn, zIn);
256 bbmod->setFinalPoint(xEn, yEn, zEn);
257 bbmod->setExecutable(boxExecutable);
259 bbmod->notifyObservers(_idManager);
263 //=========================================================================
265 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,std::string boxType)
267 _worldState = NOTHING_HAPPENS;
268 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
269 int type = GBLACKBOX;
270 //Create the MVC Objects
271 GBlackBoxModel *model = (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
272 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
273 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
275 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
278 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
280 k = _bbtkfactory->GetPackage(packageName);
281 mapDesc = k->GetDescriptorMap();
283 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for package %s, NOT EXIST\n", packageName.c_str());
286 BlackBoxDescriptor::Pointer descriptor;
288 descriptor = mapDesc[boxType];
290 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for box %s of package %s, NOT EXIST\n", boxType.c_str(),packageName.c_str());
293 if (descriptor == NULL)
295 printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
298 //Prepares the initial model
299 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
302 double yy = windowHeight - y;
304 //z value is not important yet, because it is only used a parallel projection
305 double zz = GPOSITION_Z;
306 _baseView->TransCoordScreenToWorld(xx, yy, zz);
307 model->setInicPoint(xx, yy, zz);
309 std::stringstream stream;
311 std::string newBoxName;
312 newBoxName = findANewNameForABox();
314 stream << newBoxName;
316 std::string arraystring = stream.str();
318 model->setBBTKName(arraystring);
319 model->setBBTKType(boxType);
320 model->setBBTKPackage(packageName);
322 model->addObserver(view);
323 model->addObserver(this);
325 //Iterate and create the input ports
326 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
327 descriptor->GetInputDescriptorMap();
328 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
331 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) {
332 BlackBoxInputDescriptor *desc = itInput->second;
333 createGInputPort(GINPUTPORT, i, model, desc);
337 //Iterate and create the output ports
338 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
339 descriptor->GetOutputDescriptorMap();
340 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
343 for (itOutput = descriptorOutMap.begin(); itOutput
344 != descriptorOutMap.end(); ++itOutput) {
345 BlackBoxOutputDescriptor *desc = itOutput->second;
346 createGOutputPort(GOUTPUTPORT, i, model, desc);
350 //Associates the view with the correspondent renderer and the model.
351 //(NOTE: Refresh is only made by the view)
352 view->setModel(model);
353 view->setBaseView(_baseView);
354 view->initVtkObjects();
356 //Associates the controller with the correspondent model and view
357 controller->setModelAndView(model, view);
359 //Resgiter change to the observers of the actual model
360 model->notifyObservers(_idManager);
362 int newId = addObjectController(controller);
368 //=========================================================================
370 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
371 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
372 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
374 int type = GCOMPLEXINPUTPORT;
376 //Create the MVC Objects
378 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
379 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
380 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
382 //Prepares the initial model
385 double yy = windowHeight - 5;
387 //z value is not important yet, because it is only used a parallel projection
388 double zz = GPOSITION_Z;
390 _baseView->TransCoordScreenToWorld(xx, yy, zz);
391 model->setInicPoint(xx, yy, zz);
393 model->setBBTKName(inputName);
394 model->setBBTKType("ComplexInputPort");
395 model->setComplexPortType(type);
397 model->addObserver(view);
398 model->addObserver(this);
400 //create the output port
401 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
402 "ComplexOutputPortType","ComplexOutputPortDescriopton", 0, model);
403 model->addOutputPort((GPortModel*) portController->getModel());
405 //Associates the view with the correspondent renderer and the model.
406 //(NOTE: Refresh is only made by the view)
407 view->setModel(model);
408 view->setBaseView(_baseView);
409 view->initVtkObjects();
411 //Associates the controller with the correspondent model and view
412 controller->setModelAndView(model, view);
414 //Resgiter change to the observers of the actual model
415 model->notifyObservers(_idManager);
417 int newId = addObjectController(controller);
421 //=========================================================================
423 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
424 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
425 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
427 int type = GCOMPLEXOUTPUTPORT;
429 //Create the MVC Objects
431 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
432 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
433 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
435 //Prepares the initial model
438 double yy = windowHeight - 5;
440 //z value is not important yet, because it is only used a parallel projection
441 double zz = GPOSITION_Z;
443 _baseView->TransCoordScreenToWorld(xx, yy, zz);
444 model->setInicPoint(xx, yy, zz);
446 model->setBBTKName(outputName);
447 model->setBBTKType("ComplexOutputPort");
448 model->setComplexPortType(type);
450 model->addObserver(view);
451 model->addObserver(this);
453 //create the output port
454 GPortController* portController = createGPort(GINPUTPORT, outputName,
455 "ComplexInputPort","ComplexInputPortDescription", 0, model);
456 model->addInputPort((GPortModel*) portController->getModel());
458 //Associates the view with the correspondent renderer and the model.
459 //(NOTE: Refresh is only made by the view)
460 view->setModel(model);
461 view->setBaseView(_baseView);
462 view->initVtkObjects();
464 //Associates the controller with the correspondent model and view
465 controller->setModelAndView(model, view);
467 //Resgiter change to the observers of the actual model
468 model->notifyObservers(_idManager);
470 int newId = addObjectController(controller);
474 //=========================================================================
476 int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
478 GPortController* portController = createGPort(portType, desc->GetName(),
479 desc->GetTypeName(), desc->GetDescription(), posinBox, blackBox);
480 blackBox->addInputPort((GPortModel*) portController->getModel());
481 return portController->getId();
484 //=========================================================================
486 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
488 GPortController* portController = createGPort(portType, desc->GetName(),
489 desc->GetTypeName(),desc->GetDescription(), posinBox, blackBox);
490 blackBox->addOutputPort((GPortModel*) portController->getModel());
491 return portController->getId();
494 //=========================================================================
496 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posInBox,GBoxModel *blackBox)
500 //Create the MVC Objects
503 (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
505 vtkGObjectView *view =
506 GObjectsMVCFactory::getInstance()->createGObjectView(type);
507 GObjectController* controller =
508 GObjectsMVCFactory::getInstance()->createGObjectController(type);
510 model->registerInBox(blackBox, portType, posInBox);
512 model->setBBTKType(bbtkType);
513 model->setBBTKName(bbtkName);
514 model->setBBTKDescription(bbtkDescription);
516 model->addObserver(view);
517 model->addObserver(this);
519 //Associates the view with the correspondent renderer and the model.
520 //(NOTE: Refresh is only made by the view)
521 view->setModel(model);
522 view->setBaseView(_baseView);
523 view->initVtkObjects();
525 //Associates the controller with the correspondent model and view
526 controller->setModelAndView(model, view);
528 model->notifyObservers(_idManager);
530 addObjectController(controller);
532 return (GPortController*) controller;
535 //=========================================================================
537 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
539 int type = GCONNECTOR;
541 manualConnectorContourController *manContourControl = new manualConnectorContourController();
542 manualConnectorContourView *manContourView = new manualConnectorContourView();
543 manualContourModel *manContourModel = new manualContourModel();
544 GConnectorController *connectorcontroller = new GConnectorController();
545 GConnectorModel *connectorModel = new GConnectorModel();
546 vtkGConnectorView *connectorView = new vtkGConnectorView();
547 connectorModel->setGObjectType(type);
549 manContourModel->SetCloseContour(false);
550 connectorModel->setStartPort(startPort);
552 manContourView->SetModel(manContourModel);
553 manContourView->SetWxVtkBaseView(_baseView);
554 manContourView->SetRange(0.5);
555 manContourView->SetZ(GPOSITION_Z);
557 manContourView->SetColorNormalContour(0, 0, 1);
558 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
559 manContourView->SetColorSelectContour(1, 0.8, 0);
565 * Width increased from 2 to 3, it simplifies line handling and spline control :P
568 manContourView->SetWidthLine( 3 ) ;
569 manContourView->SetShowText(false);
571 manContourControl->SetModelView(manContourModel, manContourView);
573 manContourControl->CreateNewManualContour();
577 connectorModel->getInicPoint(x, y, z);
580 manContourControl->SetState(1);
581 manContourModel->SetCloseContour(false);
583 manContourModel->AddPoint(x, y, z);
584 manContourView->AddPoint();
586 manContourModel->AddPoint(x, y, z);
587 manContourView->AddPoint();
589 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
590 manContourControl->_bakIdPoint = bak;
592 manContourControl->SetMoving(false);
594 connectorcontroller->setModelAndView(connectorModel, connectorView);
596 int newId = addObjectController(connectorcontroller);
598 connectorcontroller->setManualContourController(manContourControl);
599 connectorModel->setManualContourModel(manContourModel);
600 connectorView->setManualContourView(manContourView);
601 connectorView->setModel(connectorModel);
602 connectorView->setBaseView(_baseView);
604 connectorModel->addObserver(connectorView);
605 connectorModel->addObserver(this);
607 // manContourView->Refresh();
612 //=========================================================================
614 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
616 vtkInteractorStyleBaseView * baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
617 baseViewControlManager->AddInteractorStyleMaracas(param);
620 //=========================================================================
622 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
624 vtkInteractorStyleBaseView *baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
625 baseViewControlManager->RemoveInteractorStyleMaracas(param);
628 //=========================================================================
630 vtkRenderer* wxVtkSceneManager::getRenderer()
632 return _baseView->GetRenderer();
635 //=========================================================================
637 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
639 return _baseView->GetRenWin();
641 //=========================================================================
644 //=========================================================================
645 int wxVtkSceneManager::GetIndexInSelected(int idControler)
648 for (int i = 0; i < (int) _selectedObjects.size(); i++)
650 if (_selectedObjects[i] == idControler)
658 //=========================================================================
660 void wxVtkSceneManager::update(int idController, int command) {
662 if (command != NO_COMMAND)
664 if (command == ADD_TO_SELECTED)
666 if (GetIndexInSelected(idController) == -1)
668 _selectedObjects.push_back(idController);
670 } else if (command == REMOVE_FROM_SELECTED) {
671 int index = GetIndexInSelected(idController);
674 _selectedObjects.erase(_selectedObjects.begin() + index);
676 } else if (command == INIT_CREATION_CONTOUR) {
678 typedef std::map<int , GObjectController*>::iterator TIterator ;
681 // Find current item in the controller
682 iter = _controllers.find( idController ) ;
683 iter_end = _controllers.end( ) ;
685 if ( iter != iter_end ) {
686 GObjectController* gobjc = iter->second ;
688 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
689 // And if the item is a port
690 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
691 TIterator c_it = _controllers.begin( ) ;
692 // Go through all componets
693 for ( c_it ; c_it != iter_end ; c_it++ ) {
694 GObjectController* obc = c_it->second ;
695 int obc_type = obc->getModel( )->getGObjectType( ) ;
696 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
697 // if the component is a port and the type is the same of that selected
698 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
700 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
701 //obc->getView( )->setState( HIGHLIGHTED ) ;
709 _worldState = INIT_CREATION_CONTOUR;
710 GObjectController* cont = _controllers[idController];
711 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
713 // The last one is the controller of the connector
714 std::map<int, GObjectController*>::iterator it2;
716 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
718 GObjectController *cont = it2->second;
719 if (cont->getGObjectType() == GPORT)
721 GPortModel* port = (GPortModel*) cont->getModel();
722 if (port->getPortType() == GINPUTPORT)
724 cont->SetActive(true);
726 cont->getView()->setState(NOTHING_HAPPENS);
727 cont->getModel()->notifyObservers(_idManager);
728 cont->SetActive(false);
731 cont->getView()->setState(NOTHING_HAPPENS);
732 cont->getModel()->notifyObservers(_idManager);
733 cont->SetActive(false);
736 _selectedObjects.clear();
737 _idConnectionInCreation = createGConnector(startOutputPort);
738 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
739 _worldState = NOTHING_HAPPENS;
740 //int id = _controllers.size()-1;
741 GObjectController *cont = _controllers[_idConnectionInCreation];
742 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
743 GObjectController *finPort = _controllers[idController];
745 if (finPort->getGObjectType() == GPORT)
747 GPortModel* modelPort = (GPortModel*) finPort->getModel();
748 modelContour->setEndPort(modelPort);
751 typedef std::map<int, GObjectController*>::iterator TIterator;
752 TIterator c_it = _controllers.begin();
753 TIterator iter_end = _controllers.end();
754 // Go through all componets
755 for (c_it; c_it != iter_end; c_it++) {
756 GObjectController* obc = c_it->second;
757 int obc_type = obc->getModel()->getGObjectType();
758 int obc_state = obc->getView()->getState();
759 // if the component is a port and the type is the same of that selected
760 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
761 // Return element to neutral state if not selected
762 obc->getView()->setState(NOTHING_HAPPENS);
764 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
765 // Change element to connected state
766 obc->getView()->setState(HIGHLIGHTED);
773 _parent->saveTempandUpdate("create connection");
776 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
777 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
779 std::map<int, GObjectController*>::iterator it2;
781 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
783 GObjectController *cont = it2->second;
784 if (cont->getView() != NULL) {
785 cont->getView()->setState(NOTHING_HAPPENS);
786 cont->getModel()->notifyObservers(_idManager);
788 cont->SetActive(true);
797 //=========================================================================
799 bool wxVtkSceneManager::OnMouseMove()
802 bool okStatusMessage = false;
803 bool okPortMessage = false;
804 wxVTKRenderWindowInteractor *wxVTKiren;
805 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
806 wxVTKiren->GetEventPosition(X, Y);
808 if (_worldState == DRAG_OBJECTS) {
809 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
810 int id = _selectedObjects[i];
811 GObjectController* cont = _controllers[id];
812 if (_startDragging) {
813 cont->getView()->setStartDragging(true);
815 cont->getView()->moveObject(X, Y);
816 cont->getView()->setState(DRAG);
817 cont->getModel()->notifyObservers(_idManager);
820 std::map<int, GObjectController*>::iterator it;
822 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
823 GObjectController *desc = it->second;
824 if (desc->getGObjectType() == GCONNECTOR) {
825 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
826 vconn->updateStartEndPoints();
830 _startDragging = false;
832 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
833 std::map<int, GObjectController*>::iterator it;
835 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
836 GObjectController *desc = it->second;
837 int type = desc->getGObjectType();
838 int state = desc->getView()->getState();
839 desc->getModel()->getCenter(px, py, pz);
842 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
845 okStatusMessage = true;
846 updateStatusBar(desc->getStatusText());
847 if (type == GBLACKBOX)
849 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
850 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
855 okPortMessage = true;
857 _textActor->SetInput(desc->getStatusText().c_str());
858 _textActor->SetScale(0.1);
859 _textActor->SetPosition(px - 25, py + 1, pz + 2);
864 _fillObjectActor->SetScale(1);
865 _fillObjectActor->GetProperty()->SetOpacity(0.50);
866 _fillObjectActor->SetPosition(px, py, 1);
867 _aPolygonMapper->Modified();
870 } // for controllers it
873 if (okStatusMessage == false)
878 if (okPortMessage == false)
880 _textActor->SetScale(0.0001);
881 _fillObjectActor->SetScale(0.0001);
886 //=========================================================================
888 bool wxVtkSceneManager::OnLeftButtonDown()
890 if (_worldState == INIT_CREATION_CONTOUR)
892 bool isOverPort = false;
893 std::map<int, GObjectController*>::iterator it;
894 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
896 GObjectController *desc = it->second;
897 if (desc->getGObjectType() == GPORT)
899 GPortModel *portmod = (GPortModel*) desc->getModel();
900 vtkGObjectView *portView = desc->getView();
901 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
906 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
908 portView->setState( HIGHLIGHTED);
915 if (isOverPort == false)
918 UnSelectBlackBoxes();
922 } else { //_worldState
924 _worldState = DRAG_OBJECTS;
925 _startDragging = true;
927 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
928 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
929 ctrlkey = ctrlkey + shiftkey;
931 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
934 int state = cont->getView()->getState();
935 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
936 UnSelectBlackBoxes();
939 UnSelectBlackBoxes(); // EED 12/07/2012
941 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
942 int id = _selectedObjects[i];
943 GObjectController *cont = _controllers[id];
944 cont->getView()->setState(DRAG);
945 cont->getModel()->notifyObservers(_idManager);
947 } // if _selectedObjects.size
953 //=========================================================================
955 bool wxVtkSceneManager::OnLeftButtonUp()
957 if (_worldState == DRAG_OBJECTS) {
958 _worldState = NOTHING_HAPPENS;
960 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
961 int id = _selectedObjects[i];
962 GObjectController* cont = _controllers[id];
963 cont->getView()->setState(SELECTED);
964 cont->getModel()->notifyObservers(_idManager);
970 //=========================================================================
971 void wxVtkSceneManager::CancelConnection()
973 if (_worldState == INIT_CREATION_CONTOUR)
975 _worldState = NOTHING_HAPPENS;
976 //int lastId = _controllers.size()-1;
978 GConnectorController *connector =
979 (GConnectorController*) _controllers[_idConnectionInCreation];
980 connector->removeFromScene();
981 unregisterController(connector);
982 _controllers.erase(_idConnectionInCreation);
984 std::map<int, GObjectController*>::iterator it;
985 for (it = _controllers.begin(); it != _controllers.end(); ++it)
987 GObjectController *desc = it->second;
988 desc->SetActive(true);
989 desc->getView()->setState(NOTHING_HAPPENS);
990 desc->getModel()->notifyObservers(_idManager);
995 //=========================================================================
997 bool wxVtkSceneManager::OnRightButtonUp()
999 if (_worldState == INIT_CREATION_CONTOUR)
1003 UnSelectBlackBoxes();
1009 bool wxVtkSceneManager::OnMiddleButtonDown() {
1012 this->_vtkInteractorStyleBaseView->StartPan();
1017 bool wxVtkSceneManager::OnMiddleButtonUp() {
1020 this->_vtkInteractorStyleBaseView->EndPan();
1027 //=========================================================================
1029 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1030 GObjectController *result = NULL;
1032 wxVTKRenderWindowInteractor *wxVTKiren;
1034 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1035 wxVTKiren->GetEventPosition(X, Y);
1037 std::map<int, GObjectController*>::iterator it;
1039 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1040 GObjectController *cont = it->second;
1041 int type = cont->getGObjectType();
1043 if (cont->getView()->isPointInside(X, Y) == true) {
1044 if (type == GBLACKBOX) {
1047 } // if isPointInside
1052 //=========================================================================
1053 void wxVtkSceneManager::UnSelectBlackBoxes() {
1054 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1055 int id = _selectedObjects[i];
1056 GObjectController* control = _controllers[id];
1057 control->getView()->setState(NOTHING_HAPPENS);
1058 control->getModel()->notifyObservers(_idManager);
1059 }// for _selectedObjects
1060 _selectedObjects.clear();
1063 //=========================================================================
1064 bool wxVtkSceneManager::OnLeftDClick() {
1065 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1067 UnSelectBlackBoxes();
1068 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1074 wxVTKRenderWindowInteractor *wxVTKiren;
1075 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1076 wxVTKiren->GetEventPosition(X,Y);
1078 std::map<int, GObjectController*>::iterator it;
1080 bool clickOnObject = false;
1082 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1084 GObjectController *cont = it->second;
1085 int type = cont->getGObjectType();
1087 if(cont->getView()->isPointInside(X,Y))
1091 for (int i=0; i< (int)_selectedObjects.size(); i++)
1093 int id = _selectedObjects[i];
1094 GObjectController* control = _controllers[id];
1095 control->getView()->setState(NOTHING_HAPPENS);
1097 _selectedObjects.clear();
1099 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1100 _parent->editBlackBox(bbmodel);
1102 clickOnObject = true;
1106 if(clickOnObject==false)
1108 //_parent->editDiagramParameters(this);
1114 //=========================================================================
1116 bool wxVtkSceneManager::OnChar()
1120 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1121 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1123 // KeyCode 127 : Delete Key
1124 // KeyCode 8 : Backspace Key
1127 if (keyCode == 8 || keyCode == 127 || keyCode == 27)
1129 if (_worldState == INIT_CREATION_CONTOUR)
1132 UnSelectBlackBoxes();
1137 if (keyCode == 8 || keyCode == 127)
1140 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1142 int id = _selectedObjects[i];
1143 std::map<int, GObjectController*>::iterator it;
1144 it = _controllers.find(id);
1145 if (it != _controllers.end())
1147 oktmp = deleteObject(id);
1150 }// for selected objects
1151 if (ok) _selectedObjects.clear();
1152 _parent->saveTempandUpdate("delete object");
1157 if((keyCode==0) && (ctrlkey==1)) {
1162 if(_selectedObjects.size()){
1163 std::cout<<"objects to copy :";
1164 for(int i=0;i<_selectedObjects.size();i++)
1166 std::cout<<_selectedObjects.at(i)<<" ";
1168 DuplicateObjects(getSelectedObjects());
1170 std::cout<<"No objects to copy\n";
1171 } // _selectedObjects.size
1177 //=========================================================================
1179 void wxVtkSceneManager::AddControlerToBeRemove(
1180 std::vector<int> *controllersToRemove, int id) {
1184 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1185 if (id == (*controllersToRemove)[i]) {
1191 controllersToRemove->push_back(id);
1196 //=========================================================================
1198 bool wxVtkSceneManager::deleteObject(int id)
1201 GObjectController *control = _controllers[id];
1202 std::vector<int> controllersToRemove;
1203 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1204 == GCOMPLEXINPUTPORT || control->getGObjectType()
1205 == GCOMPLEXOUTPUTPORT) {
1206 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1207 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1209 bool boxConnected = false;
1211 // Add box input controllers to be removed
1212 for (int i = 0; i < (int) inputs.size(); i++) {
1213 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1214 if (inputs[i]->isConnected()) {
1215 boxConnected = true;
1219 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1221 // Add box output controllers to be removed
1222 for (int i = 0; i < (int) outputs.size(); i++) {
1223 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1224 if (outputs[i]->isConnected()) {
1225 boxConnected = true;
1229 // Add connection controllers to be removed
1230 std::map<int, GObjectController*>::iterator it;
1231 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1232 GObjectController *cont = it->second;
1233 int type = cont->getGObjectType();
1234 if (type == GCONNECTOR) {
1235 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1236 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1238 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1240 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1242 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1247 // Add box controller to be removed
1248 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1249 } else if (control->getGObjectType() == GCONNECTOR) {
1250 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1251 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1253 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1254 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1256 gconnectorcontroler->getManualContourController()->OnChar();
1261 std::map<int, GObjectController*>::iterator it;
1263 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1264 int key = controllersToRemove[i];
1265 it = _controllers.find(key);
1266 GObjectController *cont = _controllers[key];
1268 cont->removeFromScene();
1269 unregisterController((InteractorStyleMaracas*) cont);
1270 _controllers.erase(it);
1278 //=========================================================================
1280 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1281 std::string boxName) {
1282 _parent->displayBlackBoxInfo(packageName, boxName);
1285 //=========================================================================
1287 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1288 _parent->updateStatusBar(textStatus);
1291 //=========================================================================
1292 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1293 std::string result = "";
1294 if (withLineNumber == true) {
1296 stringstream StrStream;
1298 std::string strValue = StrStream.str();
1301 } else if (value < 100) {
1305 result += strValue + ": ";
1309 //=========================================================================
1311 bool wxVtkSceneManager::MakeBoxExecutable() {
1312 std::map<int, GObjectController*> selected = getSelectedObjects();
1313 if( selected.empty() )
1316 std::map<int, GObjectController*>::iterator it;
1317 for (it = selected.begin(); it != selected.end(); ++it) {
1318 GObjectController* lastSelected = it->second;
1320 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1321 GBlackBoxModel *bbmodel =
1322 (GBlackBoxModel*) lastSelected->getModel();
1323 view->setState(HIGHLIGHTED);
1324 if (bbmodel->isExecutable()) {
1325 bbmodel->setExecutable(false);
1327 bbmodel->setExecutable(true);
1329 bbmodel->notifyObservers(lastSelected->getId());
1337 //=========================================================================
1339 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1340 bool existsExec = false;
1342 std::vector<std::string> packages;
1343 std::vector<int> boxes;
1344 std::vector<int> connections;
1345 std::vector<int> execBoxes;
1347 std::map<int, GObjectController*>::iterator it;
1349 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1350 GObjectController *desc = it->second;
1351 int type = desc->getGObjectType();
1353 if (type == GBLACKBOX) {
1354 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1356 std::string pkg = mod->getBBTKPackage();
1357 bool existsPkg = false;
1358 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1359 if (packages[t] == pkg) {
1364 packages.push_back(pkg);
1367 boxes.push_back(it->first);
1368 if (mod->isExecutable()) {
1369 execBoxes.push_back(it->first);
1372 } else if (type == GCONNECTOR) {
1373 connections.push_back(it->first);
1378 std::string script = "";
1379 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1380 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1381 script += LineNumber(wln, lnNmbr) + "\n";
1383 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1384 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1386 for (i = 0; i < (int) packages.size(); i++) {
1387 script += LineNumber(wln, lnNmbr);
1388 script += "include ";
1389 script += packages[i];
1393 script += LineNumber(wln, lnNmbr);
1398 script += LineNumber(wln, lnNmbr);
1399 script += "author \"";
1403 script += LineNumber(wln, lnNmbr);
1404 script += "description \"";
1405 script += _Description;
1408 script += LineNumber(wln, lnNmbr);
1409 script += "category \"";
1410 script += _Category;
1413 script += LineNumber(wln, lnNmbr);
1416 // script+="include std\n"; // JPR
1418 for (i = 0; i < (int) boxes.size(); i++) {
1419 script += LineNumber(wln, lnNmbr);
1422 GObjectController *control = _controllers[id];
1423 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1425 script += model->getBBTKType();
1427 script += model->getBBTKName();
1430 std::vector<GPortModel*> inputs = model->getInputPorts();
1431 for (int j = 0; j < (int) inputs.size(); j++) {
1432 GPortModel* inputPort = inputs[j];
1433 if (inputPort->isValueSet()) {
1434 script += LineNumber(wln, lnNmbr);
1436 script += model->getBBTKName();
1438 script += inputPort->getBBTKName();
1440 script += inputPort->getValue();
1445 script += LineNumber(wln, lnNmbr);
1450 script += LineNumber(wln, lnNmbr);
1454 std::string complexInputs="";
1456 for (i = 0; i < (int) connections.size(); i++) {
1457 //script += LineNumber(wln, lnNmbr);
1458 //script += "connect ";
1459 int id = connections[i];
1460 GObjectController *control = _controllers[id];
1461 GConnectorModel *model = (GConnectorModel*) control->getModel();
1465 GPortModel *start = model->getStartPort();
1466 GBoxModel *startBox = start->getParentBox();
1468 GPortModel *end = model->getEndPort();
1469 GBoxModel *endBox = end->getParentBox();
1471 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1473 complexInputs += "input ";
1474 complexInputs += startBox->getBBTKName();
1476 complexInputs += " ";
1477 complexInputs += endBox->getBBTKName();
1478 complexInputs += ".";
1479 complexInputs += end->getBBTKName();
1481 complexInputs += " ";
1482 complexInputs += "\" \"";
1484 complexInputs += "\n";
1488 script += "connect ";
1489 script += startBox->getBBTKName();
1491 script += start->getBBTKName();
1495 //End Connection info
1496 script += endBox->getBBTKName();
1498 script += end->getBBTKName();
1506 script += LineNumber(wln, lnNmbr);
1510 script += "# Complex input ports\n";
1511 script += complexInputs;
1513 for (i = 0; i < (int) execBoxes.size(); i++) {
1514 script += LineNumber(wln, lnNmbr);
1516 int id = execBoxes[i];
1517 GObjectController *control = _controllers[id];
1518 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1520 script += model->getBBTKName();
1529 //=========================================================================
1531 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1532 std::vector<std::string> packages;
1533 std::vector<int> boxes;
1534 std::vector<int> connections;
1535 std::vector<int> execBoxes;
1537 std::map<int, GObjectController*>::iterator it;
1539 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1540 GObjectController *desc = it->second;
1541 int type = desc->getGObjectType();
1543 if (type == GBLACKBOX) {
1544 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1546 std::string pkg = mod->getBBTKPackage();
1547 bool existsPkg = false;
1548 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1549 if (packages[t] == pkg) {
1554 packages.push_back(pkg);
1557 boxes.push_back(it->first);
1558 if (mod->isExecutable()) {
1559 execBoxes.push_back(it->first);
1561 } else if (type == GCONNECTOR) {
1562 connections.push_back(it->first);
1566 std::string script = "";
1568 script += "include std\n"; // EED
1569 script += "include itkvtk\n"; // EED
1571 for (i = 0; i < (int) packages.size(); i++) {
1572 script += "include ";
1573 script += packages[i];
1578 // Definition of a complex box
1579 script += "define ";
1580 script += _cbName + " " + _cbPackageName;
1584 script += "author \"";
1588 script += "description \"";
1589 script += _Description;
1593 script += "category \"";
1594 script += _Category;
1599 for (i = 0; i < (int) boxes.size(); i++) {
1602 GObjectController *control = _controllers[id];
1603 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1605 script += model->getBBTKType();
1607 script += model->getBBTKName();
1610 std::vector<GPortModel*> inputs = model->getInputPorts();
1611 for (int j = 0; j < (int) inputs.size(); j++) {
1612 GPortModel* inputPort = inputs[j];
1613 if (inputPort->isValueSet()) {
1615 script += model->getBBTKName();
1617 script += inputPort->getBBTKName();
1619 script += inputPort->getValue();
1627 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1629 std::string complexInputs = "";
1630 std::string complexOutputs = "";
1633 for (i = 0; i < (int) connections.size(); i++) {
1634 int id = connections[i];
1635 GObjectController *control = _controllers[id];
1636 GConnectorModel *model = (GConnectorModel*) control->getModel();
1639 GPortModel *start = model->getStartPort();
1640 GBoxModel *startBox = start->getParentBox();
1642 GPortModel *end = model->getEndPort();
1643 GBoxModel *endBox = end->getParentBox();
1645 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1646 complexInputs += "input ";
1647 complexInputs += startBox->getBBTKName();
1649 complexInputs += " ";
1650 complexInputs += endBox->getBBTKName();
1651 complexInputs += ".";
1652 complexInputs += end->getBBTKName();
1654 complexInputs += " ";
1655 complexInputs += "\" \"";
1657 complexInputs += "\n";
1658 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1659 complexOutputs += "output ";
1660 complexOutputs += endBox->getBBTKName();
1662 complexOutputs += " ";
1663 complexOutputs += startBox->getBBTKName();
1664 complexOutputs += ".";
1665 complexOutputs += start->getBBTKName();
1667 complexOutputs += " ";
1668 complexOutputs += "\" \"";
1670 complexOutputs += "\n";
1672 script += "connect ";
1673 script += startBox->getBBTKName();
1675 script += start->getBBTKName();
1679 //End Connection info
1680 script += endBox->getBBTKName();
1682 script += end->getBBTKName();
1689 script += "# Complex input ports\n";
1690 script += complexInputs;
1693 script += "# Complex output ports\n";
1694 script += complexOutputs;
1698 for (i = 0; i < (int) execBoxes.size(); i++) {
1700 int id = execBoxes[i];
1701 GObjectController *control = _controllers[id];
1702 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1704 script += model->getBBTKName();
1709 script += "endefine";
1715 //=========================================================================
1717 void wxVtkSceneManager::deleteAllBoxes() {
1718 std::map<int, GObjectController*>::iterator it;
1719 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1720 GObjectController *cont = it->second;
1721 cont->removeFromScene();
1722 unregisterController((InteractorStyleMaracas*) cont);
1724 _selectedObjects.clear();
1725 _controllers.clear();
1728 //=========================================================================
1731 void wxVtkSceneManager::refresh() {
1732 _baseView->Refresh();
1734 //=========================================================================
1736 void wxVtkSceneManager::refreshScene() {
1737 _baseView->RefreshView();
1740 //=========================================================================
1742 void wxVtkSceneManager::centerView() {
1744 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1745 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1746 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1747 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1750 //=========================================================================
1752 void wxVtkSceneManager::saveDiagram(std::string &content) {
1755 content += "CATEGORY:";
1756 content += GetCategory();
1759 content += "DESCRIPTION:";
1760 content += GetDescription();
1763 content += "AUTHOR:";
1764 content += GetAuthor();
1767 //Print info IF COMPLEX BOX
1768 content += "COMPLEXBOX:";
1769 if (_isComplexBox) {
1770 content += "TRUE\n";
1772 content += "COMPLEXBOXNAME:";
1773 content += GetCbName();
1776 content += "PACKAGENAME:";
1777 content += GetCbPackageName();
1780 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1781 * External inputs are possible for applications and complex boxes
1782 //Print info complex input ports
1783 std::vector<int> inputs = getComplexInputPorts();
1784 int insize = inputs.size();
1785 content += "COMPLEXINPUTS:";
1786 sprintf(buffer, "%d", insize);
1790 for (int i = 0; i < insize; i++) {
1792 GObjectController *cont = _controllers[id];
1793 cont->getModel()->save(content);
1797 //Print info complex output ports
1798 std::vector<int> outputs = getComplexOutputPorts();
1799 int outsize = outputs.size();
1800 content += "COMPLEXOUTPUTS:";
1801 sprintf(buffer, "%d", outsize);
1805 for (int i = 0; i < outsize; i++) {
1806 int id = outputs[i];
1807 GObjectController *cont = _controllers[id];
1808 cont->getModel()->save(content);
1812 content += "FALSE\n";
1815 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1816 // External inputs are possible for applications and complex boxes
1817 std::vector<int> inputs = getComplexInputPorts();
1818 int insize = inputs.size();
1819 content += "COMPLEXINPUTS:";
1820 sprintf(buffer, "%d", insize);
1824 for (int i = 0; i < insize; i++) {
1826 GObjectController *cont = _controllers[id];
1827 cont->getModel()->save(content);
1831 std::vector<int> boxes = getBlackBoxes();
1832 int bsize = boxes.size();
1833 content += "BOXES:";
1834 sprintf(buffer, "%d", bsize);
1838 for (int i = 0; i < bsize; i++) {
1840 GObjectController *cont = _controllers[id];
1841 cont->getModel()->save(content);
1845 std::vector<int> connections = getConnections();
1846 int csize = connections.size();
1847 content += "CONNECTIONS:";
1848 sprintf(buffer, "%d", csize);
1852 for (int i = 0; i < csize; i++) {
1853 int id = connections[i];
1854 GObjectController *cont = _controllers[id];
1855 cont->getModel()->save(content);
1860 //=========================================================================
1861 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1863 getline(inputStream, line,'\n');
1864 int size = line.length();
1867 if ( line[ size-1 ]==13 )
1869 line.erase(size-1,1);
1874 //=========================================================================
1875 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1879 std::string version = "<void>";
1880 std::string line = "";
1881 char delims[] = ":";
1882 char *result = NULL;
1883 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1885 getCleanLine(inputStream, line);
1888 while (!inputStream.eof()) {
1889 if (line == "" || line[0] == '#') {
1891 getCleanLine(inputStream, line);
1893 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1894 version = line.substr(18, 3);
1896 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1897 version = line.substr(18, 3);
1899 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1900 version = line.substr(18, 3);
1902 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1903 version = line.substr(18, 3);
1905 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1906 version = line.substr(18, 3);
1908 } else if (line == "APP_START") {
1917 if ((version != "1.0") && (version != "1.1")) {
1918 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1919 char categoryTmp[30];
1920 strcpy(categoryTmp, line.c_str());
1921 result = strtok(categoryTmp, delims);
1922 result = strtok(NULL, delims);
1923 SetCategory(result);
1925 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1926 char descriptionTmp[1024];
1927 strcpy(descriptionTmp, line.c_str());
1928 result = strtok(descriptionTmp, delims);
1929 result = strtok(NULL, delims);
1930 SetDescription(result);
1932 getCleanLine(inputStream, line);//AUTHOR:<author>
1933 char authorTmp[255];
1934 strcpy(authorTmp, line.c_str());
1935 result = strtok(authorTmp, delims);
1936 result = strtok(NULL, delims);
1941 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1942 char complexTmp[30];
1943 strcpy(complexTmp, line.c_str());
1944 result = strtok(complexTmp, delims);
1945 result = strtok(NULL, delims);
1946 std::string isComplexBox(result);
1948 if (isComplexBox == "TRUE") {
1949 _isComplexBox = true;
1951 if ((version != "1.0") && (version != "1.1")) {
1952 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
1953 char complexboxnameTmp[255];
1954 strcpy(complexboxnameTmp, line.c_str());
1955 result = strtok(complexboxnameTmp, delims);
1956 result = strtok(NULL, delims);
1959 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
1960 char packagenameTmp[255];
1961 strcpy(packagenameTmp, line.c_str());
1962 result = strtok(packagenameTmp, delims);
1963 result = strtok(NULL, delims);
1964 SetCbPackageName(result);
1969 //-----------------------
1970 //- COMPLEX INPUT PORTS
1971 //-----------------------
1972 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
1974 strcpy(inputs, line.c_str());
1975 result = strtok(inputs, delims);
1976 result = strtok(NULL, delims);
1979 std::istringstream inps(result);
1982 for (int i = 0; i < numInputs; i++) {
1984 getCleanLine(inputStream, line);//COMPLEX_PORT
1985 getCleanLine(inputStream, line);//name
1986 std::string inputPortName(line);
1989 getCleanLine(inputStream, line);//xInic:yInic:zInic
1991 strcpy(coord, line.c_str());
1992 result = strtok(coord, delims);//xInic
1993 std::string xInic(result);
1994 result = strtok(NULL, delims);//yInic
1995 std::string yInic(result);
1996 result = strtok(NULL, delims);//zInic
1997 std::string zInic(result);
1999 double xIn, yIn, zIn;
2000 std::istringstream xSt(xInic);
2002 std::istringstream ySt(yInic);
2004 std::istringstream zSt(zInic);
2009 if (zIn==900) zIn=GPOSITION_Z;
2012 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2014 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2016 } // for input complex box
2021 //-----------------------
2022 //- COMPLEX OUTPUT PORTS
2023 //-----------------------
2025 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2027 strcpy(outputs, line.c_str());
2028 result = strtok(outputs, delims);
2029 result = strtok(NULL, delims);
2032 std::istringstream outps(result);
2033 outps >> numOutputs;
2035 for (int i = 0; i < numOutputs; i++) {
2037 getCleanLine(inputStream, line);//COMPLEX_PORT
2038 getCleanLine(inputStream, line);//name
2039 std::string outputPortName(line);
2042 getCleanLine(inputStream, line);//xInic:yInic:zInic
2044 strcpy(coord, line.c_str());
2045 result = strtok(coord, delims);//xInic
2046 std::string xInic(result);
2047 result = strtok(NULL, delims);//yInic
2048 std::string yInic(result);
2049 result = strtok(NULL, delims);//zInic
2050 std::string zInic(result);
2052 double xIn, yIn, zIn;
2053 std::istringstream xSt(xInic);
2055 std::istringstream ySt(yInic);
2057 std::istringstream zSt(zInic);
2062 if (zIn==900) zIn=GPOSITION_Z;
2065 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2067 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2069 } // for output complex box
2073 // RaC2012 2nd Hackfest
2074 if(version >= "1.4")
2076 //-----------------------
2077 //- EXTERNAL INPUT PORTS
2078 //-----------------------
2079 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2081 strcpy(inputs, line.c_str());
2082 result = strtok(inputs, delims);
2083 result = strtok(NULL, delims);
2086 std::istringstream inps(result);
2089 for (int i = 0; i < numInputs; i++) {
2091 getCleanLine(inputStream, line);//COMPLEX_PORT
2092 getCleanLine(inputStream, line);//name
2093 std::string inputPortName(line);
2096 getCleanLine(inputStream, line);//xInic:yInic:zInic
2098 strcpy(coord, line.c_str());
2099 result = strtok(coord, delims);//xInic
2100 std::string xInic(result);
2101 result = strtok(NULL, delims);//yInic
2102 std::string yInic(result);
2103 result = strtok(NULL, delims);//zInic
2104 std::string zInic(result);
2106 double xIn, yIn, zIn;
2107 std::istringstream xSt(xInic);
2109 std::istringstream ySt(yInic);
2111 std::istringstream zSt(zInic);
2116 if (zIn==900) zIn=GPOSITION_Z;
2119 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2120 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2122 } // for external input
2127 getCleanLine(inputStream, line);//BOXES:num
2129 strcpy(boxes, line.c_str());
2130 result = strtok(boxes, delims);
2131 result = strtok(NULL, delims);
2134 std::istringstream is(result);
2137 for (int i = 0; i < numBoxes; i++) {
2139 getCleanLine(inputStream, line);//BOX
2140 getCleanLine(inputStream, line);//package:type:name
2142 strcpy(box, line.c_str());
2143 result = strtok(box, delims);//package
2144 std::string package(result);
2145 result = strtok(NULL, delims);//type
2146 std::string type(result);
2147 result = strtok(NULL, delims);//name
2148 std::string name(result);
2151 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2153 strcpy(exec, line.c_str());
2154 result = strtok(exec, delims);//ISEXEC
2155 result = strtok(NULL, delims);//TRUE|FALSE
2156 std::string isExec(result);
2159 getCleanLine(inputStream, line);//xInic:yInic:zInic
2161 strcpy(coord, line.c_str());
2162 result = strtok(coord, delims);//xInic
2163 std::string xInic(result);
2164 result = strtok(NULL, delims);//yInic
2165 std::string yInic(result);
2166 result = strtok(NULL, delims);//zInic
2167 std::string zInic(result);
2169 double xIn, yIn, zIn;
2170 std::istringstream xSt(xInic);
2172 std::istringstream ySt(yInic);
2174 std::istringstream zSt(zInic);
2180 if (zIn==900) zIn=GPOSITION_Z;
2185 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2186 strcpy(coord, line.c_str());
2187 result = strtok(coord, delims);//xEnd
2188 std::string xEnd(result);
2189 result = strtok(NULL, delims);//yEnd
2190 std::string yEnd(result);
2191 result = strtok(NULL, delims);//zEnd
2192 std::string zEnd(result);
2194 double xEn, yEn, zEn;
2195 std::istringstream xEt(xEnd);
2197 std::istringstream yEt(yEnd);
2199 std::istringstream zEt(zEnd);
2204 if (zEn==900) zEn=GPOSITION_Z;
2208 bool boxExecutable = false;
2209 if (isExec == "TRUE") {
2210 boxExecutable = true;
2213 int idBox = createGBlackBox(xIn, yIn, package, type);
2214 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2216 GObjectController *cont = _controllers[idBox];
2217 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2220 getCleanLine(inputStream, line);//PORT o FIN_BOX
2221 std::string port = line.substr(0, 4);
2222 while (port == "PORT")
2224 getCleanLine(inputStream, line);//name:value
2225 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2227 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2230 strcpy(poort, line.c_str());
2231 result = strtok(poort, delims);//name
2232 std::string name(result);
2234 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2235 result = strtok(NULL, delims);//value
2236 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2238 std::string tmpString=" ";
2239 tmpString[0]=34; // character "
2240 strcat(result,tmpString.c_str());
2242 std::string value(result);
2244 bbmod->setValueToInput(name, value);
2246 getCleanLine(inputStream, line);//PORT o FIN_BOX
2247 port = line.substr(0, 4);
2250 //EED bbmod->notifyObservers(_idManager);
2255 getCleanLine(inputStream, line);//CONNECTIONS:num
2257 strcpy(conns, line.c_str());
2258 result = strtok(conns, delims);
2259 result = strtok(NULL, delims);
2262 std::istringstream isCons(result);
2266 for (int i = 0; i < numConns; i++) {
2268 getCleanLine(inputStream, line);//CONNECTION
2269 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2272 strcpy(connec, line.c_str());
2273 result = strtok(connec, delims);
2274 std::string nameStartBox(result);
2275 result = strtok(NULL, delims);
2276 std::string nameStartPort(result);
2277 result = strtok(NULL, delims);
2278 std::string nameEndBox(result);
2279 result = strtok(NULL, delims);
2280 std::string nameEndPort(result);
2283 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2285 if (version != "1.0") {
2286 //Readding control points of the manualContour
2287 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2288 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2289 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2290 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2291 strcpy(conns, line.c_str());
2292 result = strtok(conns, delims);
2293 result = strtok(NULL, delims);
2295 int numberOfControlPoints;
2296 std::istringstream isCons(result);
2297 isCons >> numberOfControlPoints;
2299 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2300 getCleanLine(inputStream, line); //XX:YY:ZZ
2302 strcpy(connec, line.c_str());
2305 result = strtok(connec, delims);
2306 std::istringstream isPointX(result);
2308 result = strtok(NULL, delims);
2309 std::istringstream isPointY(result);
2311 result = strtok(NULL, delims);
2312 std::istringstream isPointZ(result);
2317 if (pz==900) pz=GPOSITION_Z;
2320 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2321 conView->getManualContourView()->AddPoint();
2327 //=========================================================================
2330 //=========================================================================
2331 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2332 std::string portName, double xIn, double yIn, double zIn)
2335 if (inputoutput == true) {
2336 idPort = createGComplexBoxInputPort(portName);
2338 idPort = createGComplexBoxOutputPort(portName);
2340 GObjectController *cont = _controllers[idPort];
2341 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2342 cbmod->setInicPoint(xIn, yIn, zIn);
2343 cbmod->notifyObservers(_idManager);
2345 //=========================================================================
2348 //=========================================================================
2349 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2354 GBoxModel *boxModel = NULL;
2355 std::vector<int> lstB = getBlackBoxes();
2356 for (j = 0; j < (int) lstB.size(); j++) {
2358 bMod = (GBoxModel*) _controllers[idB]->getModel();
2359 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2367 if (boxModel == NULL) {
2368 std::vector<int> lstInputs = getComplexInputPorts();
2369 for (j = 0; j < (int) lstInputs.size(); j++) {
2371 bMod = (GBoxModel*) _controllers[idB]->getModel();
2372 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2380 std::vector<int> lstOutputs = getComplexOutputPorts();
2381 for (j = 0; j < (int) lstOutputs.size(); j++) {
2382 int idB = lstOutputs[j];
2383 bMod = (GBoxModel*) _controllers[idB]->getModel();
2384 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2396 //=========================================================================
2399 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2400 std::string nameStartPort, std::string nameEndBox,
2401 std::string nameEndPort) {
2403 GBoxModel *boxModel;
2404 GPortModel *startP = NULL;
2405 GPortModel *endP = NULL;
2407 boxModel = findGBox(nameStartBox);
2408 if(boxModel == NULL)
2410 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2412 if (boxModel != NULL) {
2413 startP = boxModel->getOutputPort(nameStartPort);
2415 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port is null. Port name is probably wrong. Start>%s::%s End>%s::%s\n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str() );
2419 boxModel = findGBox(nameEndBox);
2420 if(boxModel == NULL)
2422 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2424 if (boxModel != NULL) {
2425 endP = boxModel->getInputPort(nameEndPort);
2427 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port is null. Port name is probably wrong. Start>%s::%s End>%s::%s \n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str());
2432 int idCon = createGConnector(startP);
2434 _worldState = NOTHING_HAPPENS;
2435 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2437 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2438 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2439 tempp->endContourCreation();
2440 conMod->setEndPort(endP);
2441 conView->updateStartEndPoints();
2445 //=========================================================================
2447 bool wxVtkSceneManager::boxExist(std::string boxname) {
2449 std::map<int, GObjectController*>::iterator it;
2450 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2451 GObjectController *cont = it->second;
2452 if (cont->getModel()->getBBTKName() == boxname) {
2459 //=========================================================================
2461 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2462 std::vector<int> vect;
2463 std::map<int, GObjectController*>::iterator it;
2464 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2465 GObjectController *cont = it->second;
2466 if (cont->getGObjectType() == GBLACKBOX) {
2467 vect.push_back(cont->getId());
2473 //=========================================================================
2475 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2476 std::vector<int> vect;
2477 std::map<int, GObjectController*>::iterator it;
2478 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2479 GObjectController *cont = it->second;
2480 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2481 vect.push_back(cont->getId());
2487 //=========================================================================
2489 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2490 std::vector<int> vect;
2491 std::map<int, GObjectController*>::iterator it;
2492 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2493 GObjectController *cont = it->second;
2494 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2495 vect.push_back(cont->getId());
2501 //=========================================================================
2503 std::vector<int> wxVtkSceneManager::getConnections() {
2504 std::vector<int> vect;
2505 std::map<int, GObjectController*>::iterator it;
2506 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2507 GObjectController *cont = it->second;
2508 if (cont->getGObjectType() == GCONNECTOR) {
2509 vect.push_back(cont->getId());
2515 //=========================================================================
2517 bool wxVtkSceneManager::isComplexBox() {
2518 return _isComplexBox;
2521 //=========================================================================
2523 void wxVtkSceneManager::setComplexBox(bool val) {
2524 _isComplexBox = val;
2527 //=========================================================================
2529 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2530 //Register the controller of the new object
2531 registerController((InteractorStyleMaracas*) objController);
2532 //Add the object to the objects list
2533 int newId = _contLastId;//_controllers.size();
2534 objController->setId(newId);
2535 _controllers[newId] = objController;
2536 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2541 //=========================================================================
2543 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2545 std::map<int, int> oldIdNewIdBoxes;
2546 std::vector<int> connections;
2548 std::vector<int> newBoxesID;
2550 std::map<int, GObjectController*>::iterator it;
2551 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2552 GObjectController *cont = it->second;
2553 int type = cont->getGObjectType();
2555 if (type == GBLACKBOX) {
2557 double xInic, yInic, zInic;
2558 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2559 copyBox->getInicPoint(xInic, yInic, zInic);
2560 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2561 copyBox->getBBTKType());
2563 int idcB = copyBox->getObjectId();
2564 oldIdNewIdBoxes[idcB] = idBox;
2565 cont = _controllers[idBox];
2566 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2567 newbox->setInicPoint(xInic, yInic, zInic);
2568 int num = newbox->getNumInputPorts();
2569 for (int j = 0; j < num; j++) {
2570 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2572 newbox->move(xInic + 20, yInic + 20, zInic);
2573 newbox->notifyObservers(_idManager);
2574 newBoxesID.push_back(newbox->getObjectId());
2576 } else if (type == GCONNECTOR) {
2577 int idCon = cont->getId();
2578 connections.push_back(idCon);
2583 for (int i = 0; i < (int) connections.size(); i++) {
2584 int objId = connections[i];
2585 GObjectController *cont = objectsMap[objId];
2586 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2588 GPortModel* startPort = connectModel->getStartPort();
2589 int startPortIndex = startPort->getPosInBox();
2590 GPortModel* endPort = connectModel->getEndPort();
2591 int endPortIndex = endPort->getPosInBox();
2593 GBlackBoxModel* startPortParentBox =
2594 (GBlackBoxModel*) startPort->getParentBox();
2595 GBlackBoxModel* endPortParentBox =
2596 (GBlackBoxModel*) endPort->getParentBox();
2598 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2599 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2601 GBlackBoxModel* newStartBox =
2602 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2603 GBlackBoxModel* newEndBox =
2604 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2606 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2607 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2609 // Creates connection
2610 int idCon = createGConnector(newStartPort);
2611 GConnectorController *tempp =
2612 (GConnectorController*) _controllers[idCon];
2613 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2614 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2615 tempp->endContourCreation();
2616 conMod->setEndPort(newEndPort);
2617 conView->updateStartEndPoints();
2620 /// the new selected boxes are the duplicate ones
2622 UnSelectBlackBoxes();
2623 for (int i = 0; i < newBoxesID.size(); i++) {
2624 _selectedObjects.push_back(newBoxesID.at(i));
2627 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2628 int id = _selectedObjects[i];
2629 GObjectController* cont = _controllers[id];
2631 cont->getView()->setState(SELECTED);
2632 cont->getModel()->notifyObservers(_idManager);
2638 //=========================================================================
2640 int wxVtkSceneManager::getNumSelectedObjects() {
2641 return _selectedObjects.size();
2644 //=========================================================================
2646 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2647 std::map<int, GObjectController*> mapSelected;
2649 std::map<int, GObjectController*>::iterator it;
2650 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2651 GObjectController *cont = it->second;
2652 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2654 mapSelected[cont->getId()] = cont;
2658 std::map<int, GObjectController*>::iterator it2;
2659 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2660 GObjectController *cont = it2->second;
2661 if (cont->getGObjectType() == GCONNECTOR) {
2662 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2663 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2664 GBoxModel* startPortParentBox =
2665 cmod->getStartPort()->getParentBox();
2667 std::map<int, GObjectController*>::iterator iterOBJ1 =
2668 mapSelected.find(startPortParentBox->getObjectId());
2669 std::map<int, GObjectController*>::iterator iterOBJ2 =
2670 mapSelected.find(endPortParentBox->getObjectId());
2672 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2673 int ID = cont->getId();
2674 mapSelected[ID] = cont;
2681 //=========================================================================
2683 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2685 std::map<int, int> oldIdNewIdBoxes;
2686 std::vector<int> connections;
2688 std::map<int, GObjectController*>::iterator it;
2689 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2690 GObjectController *cont = it->second;
2691 int type = cont->getGObjectType();
2693 if (type == GBLACKBOX) {
2695 double xInic, yInic, zInic;
2696 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2697 copyBox->getInicPoint(xInic, yInic, zInic);
2698 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2700 int idcB = copyBox->getObjectId();
2701 oldIdNewIdBoxes[idcB] = idBox;
2702 cont = _controllers[idBox];
2703 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2704 newbox->setInicPoint(xInic, yInic, zInic);
2705 int num = newbox->getNumInputPorts();
2706 for (int j = 0; j < num; j++)
2708 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2710 newbox->notifyObservers(_idManager);
2711 } else if (type == GCONNECTOR) {
2712 int idCon = cont->getId();
2713 connections.push_back(idCon);
2718 for (int i = 0; i < (int) connections.size(); i++) {
2719 int objId = connections[i];
2720 GObjectController *cont = objectsMap[objId];
2721 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2723 GPortModel* startPort = connectModel->getStartPort();
2724 int startPortIndex = startPort->getPosInBox();
2725 GPortModel* endPort = connectModel->getEndPort();
2726 int endPortIndex = endPort->getPosInBox();
2728 GBlackBoxModel* startPortParentBox =
2729 (GBlackBoxModel*) startPort->getParentBox();
2730 GBlackBoxModel* endPortParentBox =
2731 (GBlackBoxModel*) endPort->getParentBox();
2733 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2734 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2736 GBlackBoxModel* newStartBox =
2737 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2738 GBlackBoxModel* newEndBox =
2739 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2741 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2742 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2744 // Creates connection
2745 int idCon = createGConnector(newStartPort);
2746 GConnectorController *tempp =
2747 (GConnectorController*) _controllers[idCon];
2748 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2749 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2750 tempp->endContourCreation();
2751 conMod->setEndPort(newEndPort);
2752 conView->updateStartEndPoints();
2755 std::map<int, int>::iterator itIds;
2756 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2757 int idOld = itIds->first;
2758 int idNew = itIds->second;
2760 GBlackBoxModel* oldBox =
2761 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2762 GBlackBoxModel* newBox =
2763 (GBlackBoxModel*) _controllers[idNew]->getModel();
2765 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2766 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2767 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2768 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2770 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2772 //EED int toCreate=-1;
2773 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2774 if (oldInputConnections[k] == newInputConnections[l]) {
2779 if (exist == false) {
2780 //Create complex input
2781 int posInBox = oldInputConnections[k];
2782 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2783 std::string inputPortName = inputPort->getBBTKName();
2784 int idInputPort = createGComplexBoxInputPort(inputPortName);
2785 GObjectController *cont = _controllers[idInputPort];
2786 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2787 double xIn, yIn, zIn;
2788 inputPort->getInicPoint(xIn, yIn, zIn);
2790 cbmod->setInicPoint(xIn, yIn, zIn);
2791 cbmod->notifyObservers(_idManager);
2793 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2795 // Creates connection
2796 int idCon = createGConnector(cbmod->getOutputPort(0));
2797 GConnectorController *tempp =
2798 (GConnectorController*) _controllers[idCon];
2799 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2800 vtkGConnectorView *conView =
2801 (vtkGConnectorView*) tempp->getView();
2802 tempp->endContourCreation();
2803 conMod->setEndPort(inputPortEnd);
2804 conView->updateStartEndPoints();
2810 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2812 //EED int toCreate=-1;
2813 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2814 if (oldOutputConnections[k] == newOutputConnections[l]) {
2819 if (exist == false) {
2820 //Create complex output
2821 int posInBox = oldOutputConnections[k];
2822 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2823 std::string outputPortName = outputPort->getBBTKName();
2824 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2825 GObjectController *cont = _controllers[idOutputPort];
2826 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2827 double xIn, yIn, zIn;
2828 outputPort->getInicPoint(xIn, yIn, zIn);
2830 cbmod->setInicPoint(xIn, yIn, zIn);
2831 cbmod->notifyObservers(_idManager);
2833 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2835 // Creates connection
2836 int idCon = createGConnector(outputPortEnd);
2837 GConnectorController *tempp =
2838 (GConnectorController*) _controllers[idCon];
2839 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2840 vtkGConnectorView *conView =
2841 (vtkGConnectorView*) tempp->getView();
2842 tempp->endContourCreation();
2843 conMod->setEndPort(cbmod->getInputPort(0));
2844 conView->updateStartEndPoints();
2854 //=========================================================================
2855 void wxVtkSceneManager::SetCbName(std::string cbName) {
2857 if (_cbName == "") {
2858 _cbName = "<complex box name>";
2862 //=========================================================================
2863 std::string wxVtkSceneManager::GetCbName() {
2867 //=========================================================================
2868 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2869 _cbPackageName = packagename;
2870 if (_cbPackageName == "") {
2871 _cbPackageName = "<package name of the complex box>";
2875 //=========================================================================
2876 std::string wxVtkSceneManager::GetCbPackageName() {
2877 return _cbPackageName;
2880 //=========================================================================
2881 void wxVtkSceneManager::SetAuthor(std::string author) {
2883 if (_Author == "") {
2884 _Author = "<author of the box>";
2888 //=========================================================================
2889 std::string wxVtkSceneManager::GetAuthor() {
2893 //=========================================================================
2894 void wxVtkSceneManager::SetCategory(std::string category) {
2895 _Category = category;
2896 if (_Category == "") {
2897 _Category = "<category of the box>";
2901 //=========================================================================
2902 std::string wxVtkSceneManager::GetCategory() {
2906 //=========================================================================
2907 void wxVtkSceneManager::SetDescription(std::string description) {
2908 _Description = description;
2909 if (_Description == "") {
2910 _Description = "<description of the box>";
2914 //=========================================================================
2915 std::string wxVtkSceneManager::GetDescription() {
2916 return _Description;
2919 //=========================================================================
2921 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
2924 std::vector< std::string> extInputs;
2925 std::map<int, GObjectController*>::iterator it;
2926 for (it = _controllers.begin(); it != _controllers.end(); ++it)
2928 GObjectController *cont = it->second;
2929 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
2931 extInputs.push_back(cont->getModel()->getBBTKName());
2937 //=========================================================================
2941 void wxVtkSceneManager::printAll(int com , int sta ){
2943 int tmpState = sta ;
2944 if ( tmpState == NOTHING_HAPPENS ) {
2945 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2947 if ( tmpState == HIGHLIGHTED ) {
2948 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2950 if ( tmpState == POSSIBLE_CONNECTION ) {
2951 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2953 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2954 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2956 if ( tmpState == CLICKED ) {
2957 std::cout << "CONTROLER STATE---->CLICKED\n" ;
2959 if ( tmpState == DRAG ) {
2960 std::cout << "CONTROLER STATE---->DRAG\n" ;
2962 if ( tmpState == SELECTED ) {
2963 std::cout << "CONTROLER STATE---->SELECTED\n" ;
2965 if ( tmpState == CREATING_CONTOUR ) {
2966 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2972 if ( command == INIT_CREATION_CONTOUR ) {
2973 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2975 if ( command == FIN_CREATION_CONTOUR ) {
2976 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2978 if ( command == ADD_TO_SELECTED ) {
2979 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2981 if ( command == DRAG_OBJECTS ) {
2982 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2984 if ( command == EDIT_BLACKBOX ) {
2985 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
2987 if ( command == REMOVE_FROM_SELECTED ) {
2988 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
2994 } // EO namespace bbtk