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)
1878 std::string version = "<void>";
1879 std::string line = "";
1880 char delims[] = ":";
1881 char *result = NULL;
1882 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1884 getCleanLine(inputStream, line);
1887 while (!inputStream.eof()) {
1888 if (line == "" || line[0] == '#') {
1890 getCleanLine(inputStream, line);
1892 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1893 version = line.substr(18, 3);
1895 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1896 version = line.substr(18, 3);
1898 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1899 version = line.substr(18, 3);
1901 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1902 version = line.substr(18, 3);
1904 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1905 version = line.substr(18, 3);
1907 } else if (line == "APP_START") {
1916 if ((version != "1.0") && (version != "1.1")) {
1917 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1918 char categoryTmp[30];
1919 strcpy(categoryTmp, line.c_str());
1920 result = strtok(categoryTmp, delims);
1921 result = strtok(NULL, delims);
1922 SetCategory(result);
1924 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1925 char descriptionTmp[1024];
1926 strcpy(descriptionTmp, line.c_str());
1927 result = strtok(descriptionTmp, delims);
1928 result = strtok(NULL, delims);
1929 SetDescription(result);
1931 getCleanLine(inputStream, line);//AUTHOR:<author>
1932 char authorTmp[255];
1933 strcpy(authorTmp, line.c_str());
1934 result = strtok(authorTmp, delims);
1935 result = strtok(NULL, delims);
1940 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1941 char complexTmp[30];
1942 strcpy(complexTmp, line.c_str());
1943 result = strtok(complexTmp, delims);
1944 result = strtok(NULL, delims);
1945 std::string isComplexBox(result);
1947 if (isComplexBox == "TRUE") {
1948 _isComplexBox = true;
1950 if ((version != "1.0") && (version != "1.1")) {
1951 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
1952 char complexboxnameTmp[255];
1953 strcpy(complexboxnameTmp, line.c_str());
1954 result = strtok(complexboxnameTmp, delims);
1955 result = strtok(NULL, delims);
1958 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
1959 char packagenameTmp[255];
1960 strcpy(packagenameTmp, line.c_str());
1961 result = strtok(packagenameTmp, delims);
1962 result = strtok(NULL, delims);
1963 SetCbPackageName(result);
1968 //-----------------------
1969 //- COMPLEX INPUT PORTS
1970 //-----------------------
1971 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
1973 strcpy(inputs, line.c_str());
1974 result = strtok(inputs, delims);
1975 result = strtok(NULL, delims);
1978 std::istringstream inps(result);
1981 for (int i = 0; i < numInputs; i++) {
1983 getCleanLine(inputStream, line);//COMPLEX_PORT
1984 getCleanLine(inputStream, line);//name
1985 std::string inputPortName(line);
1988 getCleanLine(inputStream, line);//xInic:yInic:zInic
1990 strcpy(coord, line.c_str());
1991 result = strtok(coord, delims);//xInic
1992 std::string xInic(result);
1993 result = strtok(NULL, delims);//yInic
1994 std::string yInic(result);
1995 result = strtok(NULL, delims);//zInic
1996 std::string zInic(result);
1998 double xIn, yIn, zIn;
1999 std::istringstream xSt(xInic);
2001 std::istringstream ySt(yInic);
2003 std::istringstream zSt(zInic);
2008 if (zIn==900) zIn=GPOSITION_Z;
2011 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2013 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2015 } // for input complex box
2019 //-----------------------
2020 //- COMPLEX OUTPUT PORTS
2021 //-----------------------
2023 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2025 strcpy(outputs, line.c_str());
2026 result = strtok(outputs, delims);
2027 result = strtok(NULL, delims);
2030 std::istringstream outps(result);
2031 outps >> numOutputs;
2033 for (int i = 0; i < numOutputs; i++) {
2035 getCleanLine(inputStream, line);//COMPLEX_PORT
2036 getCleanLine(inputStream, line);//name
2037 std::string outputPortName(line);
2040 getCleanLine(inputStream, line);//xInic:yInic:zInic
2042 strcpy(coord, line.c_str());
2043 result = strtok(coord, delims);//xInic
2044 std::string xInic(result);
2045 result = strtok(NULL, delims);//yInic
2046 std::string yInic(result);
2047 result = strtok(NULL, delims);//zInic
2048 std::string zInic(result);
2050 double xIn, yIn, zIn;
2051 std::istringstream xSt(xInic);
2053 std::istringstream ySt(yInic);
2055 std::istringstream zSt(zInic);
2060 if (zIn==900) zIn=GPOSITION_Z;
2063 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2065 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2067 } // for output complex box
2071 // RaC2012 2nd Hackfest
2072 if(version >= "1.4")
2074 //-----------------------
2075 //- EXTERNAL INPUT PORTS
2076 //-----------------------
2077 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2079 strcpy(inputs, line.c_str());
2080 result = strtok(inputs, delims);
2081 result = strtok(NULL, delims);
2084 std::istringstream inps(result);
2087 for (int i = 0; i < numInputs; i++) {
2089 getCleanLine(inputStream, line);//COMPLEX_PORT
2090 getCleanLine(inputStream, line);//name
2091 std::string inputPortName(line);
2094 getCleanLine(inputStream, line);//xInic:yInic:zInic
2096 strcpy(coord, line.c_str());
2097 result = strtok(coord, delims);//xInic
2098 std::string xInic(result);
2099 result = strtok(NULL, delims);//yInic
2100 std::string yInic(result);
2101 result = strtok(NULL, delims);//zInic
2102 std::string zInic(result);
2104 double xIn, yIn, zIn;
2105 std::istringstream xSt(xInic);
2107 std::istringstream ySt(yInic);
2109 std::istringstream zSt(zInic);
2114 if (zIn==900) zIn=GPOSITION_Z;
2117 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2118 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2120 } // for external input
2125 getCleanLine(inputStream, line);//BOXES:num
2127 strcpy(boxes, line.c_str());
2128 result = strtok(boxes, delims);
2129 result = strtok(NULL, delims);
2132 std::istringstream is(result);
2135 for (int i = 0; i < numBoxes; i++) {
2137 getCleanLine(inputStream, line);//BOX
2138 getCleanLine(inputStream, line);//package:type:name
2140 strcpy(box, line.c_str());
2141 result = strtok(box, delims);//package
2142 std::string package(result);
2143 result = strtok(NULL, delims);//type
2144 std::string type(result);
2145 result = strtok(NULL, delims);//name
2146 std::string name(result);
2148 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2150 strcpy(exec, line.c_str());
2151 result = strtok(exec, delims);//ISEXEC
2152 result = strtok(NULL, delims);//TRUE|FALSE
2153 std::string isExec(result);
2156 getCleanLine(inputStream, line);//xInic:yInic:zInic
2158 strcpy(coord, line.c_str());
2159 result = strtok(coord, delims);//xInic
2160 std::string xInic(result);
2161 result = strtok(NULL, delims);//yInic
2162 std::string yInic(result);
2163 result = strtok(NULL, delims);//zInic
2164 std::string zInic(result);
2166 double xIn, yIn, zIn;
2167 std::istringstream xSt(xInic);
2169 std::istringstream ySt(yInic);
2171 std::istringstream zSt(zInic);
2177 if (zIn==900) zIn=GPOSITION_Z;
2182 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2183 strcpy(coord, line.c_str());
2184 result = strtok(coord, delims);//xEnd
2185 std::string xEnd(result);
2186 result = strtok(NULL, delims);//yEnd
2187 std::string yEnd(result);
2188 result = strtok(NULL, delims);//zEnd
2189 std::string zEnd(result);
2191 double xEn, yEn, zEn;
2192 std::istringstream xEt(xEnd);
2194 std::istringstream yEt(yEnd);
2196 std::istringstream zEt(zEnd);
2201 if (zEn==900) zEn=GPOSITION_Z;
2205 bool boxExecutable = false;
2206 if (isExec == "TRUE") {
2207 boxExecutable = true;
2210 int idBox = createGBlackBox(xIn, yIn, package, type);
2211 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2213 GObjectController *cont = _controllers[idBox];
2214 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2217 getCleanLine(inputStream, line);//PORT o FIN_BOX
2218 std::string port = line.substr(0, 4);
2219 while (port == "PORT")
2221 getCleanLine(inputStream, line);//name:value
2222 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2224 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2227 strcpy(poort, line.c_str());
2228 result = strtok(poort, delims);//name
2229 std::string name(result);
2231 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2232 result = strtok(NULL, delims);//value
2233 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2235 std::string tmpString=" ";
2236 tmpString[0]=34; // character "
2237 strcat(result,tmpString.c_str());
2239 std::string value(result);
2241 bbmod->setValueToInput(name, value);
2243 getCleanLine(inputStream, line);//PORT o FIN_BOX
2244 port = line.substr(0, 4);
2247 //EED bbmod->notifyObservers(_idManager);
2252 getCleanLine(inputStream, line);//CONNECTIONS:num
2254 strcpy(conns, line.c_str());
2255 result = strtok(conns, delims);
2256 result = strtok(NULL, delims);
2259 std::istringstream isCons(result);
2263 for (int i = 0; i < numConns; i++) {
2265 getCleanLine(inputStream, line);//CONNECTION
2266 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2269 strcpy(connec, line.c_str());
2270 result = strtok(connec, delims);
2271 std::string nameStartBox(result);
2272 result = strtok(NULL, delims);
2273 std::string nameStartPort(result);
2274 result = strtok(NULL, delims);
2275 std::string nameEndBox(result);
2276 result = strtok(NULL, delims);
2277 std::string nameEndPort(result);
2279 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2281 if (version != "1.0") {
2282 //Readding control points of the manualContour
2283 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2284 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2285 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2286 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2287 strcpy(conns, line.c_str());
2288 result = strtok(conns, delims);
2289 result = strtok(NULL, delims);
2291 int numberOfControlPoints;
2292 std::istringstream isCons(result);
2293 isCons >> numberOfControlPoints;
2295 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2296 getCleanLine(inputStream, line); //XX:YY:ZZ
2298 strcpy(connec, line.c_str());
2301 result = strtok(connec, delims);
2302 std::istringstream isPointX(result);
2304 result = strtok(NULL, delims);
2305 std::istringstream isPointY(result);
2307 result = strtok(NULL, delims);
2308 std::istringstream isPointZ(result);
2313 if (pz==900) pz=GPOSITION_Z;
2316 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2317 conView->getManualContourView()->AddPoint();
2323 //=========================================================================
2326 //=========================================================================
2327 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2328 std::string portName, double xIn, double yIn, double zIn)
2331 if (inputoutput == true) {
2332 idPort = createGComplexBoxInputPort(portName);
2334 idPort = createGComplexBoxOutputPort(portName);
2336 GObjectController *cont = _controllers[idPort];
2337 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2338 cbmod->setInicPoint(xIn, yIn, zIn);
2339 cbmod->notifyObservers(_idManager);
2341 //=========================================================================
2344 //=========================================================================
2345 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2350 GBoxModel *boxModel = NULL;
2351 std::vector<int> lstB = getBlackBoxes();
2352 for (j = 0; j < (int) lstB.size(); j++) {
2354 bMod = (GBoxModel*) _controllers[idB]->getModel();
2355 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2362 if (boxModel == NULL) {
2363 std::vector<int> lstInputs = getComplexInputPorts();
2364 for (j = 0; j < (int) lstInputs.size(); j++) {
2366 bMod = (GBoxModel*) _controllers[idB]->getModel();
2367 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2374 std::vector<int> lstOutputs = getComplexOutputPorts();
2375 for (j = 0; j < (int) lstOutputs.size(); j++) {
2376 int idB = lstOutputs[j];
2377 bMod = (GBoxModel*) _controllers[idB]->getModel();
2378 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2389 //=========================================================================
2392 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2393 std::string nameStartPort, std::string nameEndBox,
2394 std::string nameEndPort) {
2396 GBoxModel *boxModel;
2397 GPortModel *startP = NULL;
2398 GPortModel *endP = NULL;
2400 boxModel = findGBox(nameStartBox);
2401 if(boxModel == NULL)
2403 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2405 if (boxModel != NULL) {
2406 startP = boxModel->getOutputPort(nameStartPort);
2408 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port %s is null. Port name is probably wrong.\n", nameStartPort.c_str());
2412 boxModel = findGBox(nameEndBox);
2413 if(boxModel == NULL)
2415 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2417 if (boxModel != NULL) {
2418 endP = boxModel->getInputPort(nameEndPort);
2420 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port %s is null. Port name is probably wrong\n", nameStartPort.c_str(), nameEndPort.c_str());
2425 int idCon = createGConnector(startP);
2427 _worldState = NOTHING_HAPPENS;
2428 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2430 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2431 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2432 tempp->endContourCreation();
2433 conMod->setEndPort(endP);
2434 conView->updateStartEndPoints();
2438 //=========================================================================
2440 bool wxVtkSceneManager::boxExist(std::string boxname) {
2442 std::map<int, GObjectController*>::iterator it;
2443 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2444 GObjectController *cont = it->second;
2445 if (cont->getModel()->getBBTKName() == boxname) {
2452 //=========================================================================
2454 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2455 std::vector<int> vect;
2456 std::map<int, GObjectController*>::iterator it;
2457 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2458 GObjectController *cont = it->second;
2459 if (cont->getGObjectType() == GBLACKBOX) {
2460 vect.push_back(cont->getId());
2466 //=========================================================================
2468 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2469 std::vector<int> vect;
2470 std::map<int, GObjectController*>::iterator it;
2471 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2472 GObjectController *cont = it->second;
2473 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2474 vect.push_back(cont->getId());
2480 //=========================================================================
2482 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2483 std::vector<int> vect;
2484 std::map<int, GObjectController*>::iterator it;
2485 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2486 GObjectController *cont = it->second;
2487 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2488 vect.push_back(cont->getId());
2494 //=========================================================================
2496 std::vector<int> wxVtkSceneManager::getConnections() {
2497 std::vector<int> vect;
2498 std::map<int, GObjectController*>::iterator it;
2499 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2500 GObjectController *cont = it->second;
2501 if (cont->getGObjectType() == GCONNECTOR) {
2502 vect.push_back(cont->getId());
2508 //=========================================================================
2510 bool wxVtkSceneManager::isComplexBox() {
2511 return _isComplexBox;
2514 //=========================================================================
2516 void wxVtkSceneManager::setComplexBox(bool val) {
2517 _isComplexBox = val;
2520 //=========================================================================
2522 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2523 //Register the controller of the new object
2524 registerController((InteractorStyleMaracas*) objController);
2525 //Add the object to the objects list
2526 int newId = _contLastId;//_controllers.size();
2527 objController->setId(newId);
2528 _controllers[newId] = objController;
2529 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2534 //=========================================================================
2536 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2538 std::map<int, int> oldIdNewIdBoxes;
2539 std::vector<int> connections;
2541 std::vector<int> newBoxesID;
2543 std::map<int, GObjectController*>::iterator it;
2544 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2545 GObjectController *cont = it->second;
2546 int type = cont->getGObjectType();
2548 if (type == GBLACKBOX) {
2550 double xInic, yInic, zInic;
2551 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2552 copyBox->getInicPoint(xInic, yInic, zInic);
2553 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2554 copyBox->getBBTKType());
2556 int idcB = copyBox->getObjectId();
2557 oldIdNewIdBoxes[idcB] = idBox;
2558 cont = _controllers[idBox];
2559 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2560 newbox->setInicPoint(xInic, yInic, zInic);
2561 int num = newbox->getNumInputPorts();
2562 for (int j = 0; j < num; j++) {
2563 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2565 newbox->move(xInic + 20, yInic + 20, zInic);
2566 newbox->notifyObservers(_idManager);
2567 newBoxesID.push_back(newbox->getObjectId());
2569 } else if (type == GCONNECTOR) {
2570 int idCon = cont->getId();
2571 connections.push_back(idCon);
2576 for (int i = 0; i < (int) connections.size(); i++) {
2577 int objId = connections[i];
2578 GObjectController *cont = objectsMap[objId];
2579 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2581 GPortModel* startPort = connectModel->getStartPort();
2582 int startPortIndex = startPort->getPosInBox();
2583 GPortModel* endPort = connectModel->getEndPort();
2584 int endPortIndex = endPort->getPosInBox();
2586 GBlackBoxModel* startPortParentBox =
2587 (GBlackBoxModel*) startPort->getParentBox();
2588 GBlackBoxModel* endPortParentBox =
2589 (GBlackBoxModel*) endPort->getParentBox();
2591 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2592 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2594 GBlackBoxModel* newStartBox =
2595 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2596 GBlackBoxModel* newEndBox =
2597 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2599 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2600 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2602 // Creates connection
2603 int idCon = createGConnector(newStartPort);
2604 GConnectorController *tempp =
2605 (GConnectorController*) _controllers[idCon];
2606 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2607 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2608 tempp->endContourCreation();
2609 conMod->setEndPort(newEndPort);
2610 conView->updateStartEndPoints();
2613 /// the new selected boxes are the duplicate ones
2615 UnSelectBlackBoxes();
2616 for (int i = 0; i < newBoxesID.size(); i++) {
2617 _selectedObjects.push_back(newBoxesID.at(i));
2620 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2621 int id = _selectedObjects[i];
2622 GObjectController* cont = _controllers[id];
2624 cont->getView()->setState(SELECTED);
2625 cont->getModel()->notifyObservers(_idManager);
2631 //=========================================================================
2633 int wxVtkSceneManager::getNumSelectedObjects() {
2634 return _selectedObjects.size();
2637 //=========================================================================
2639 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2640 std::map<int, GObjectController*> mapSelected;
2642 std::map<int, GObjectController*>::iterator it;
2643 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2644 GObjectController *cont = it->second;
2645 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2647 mapSelected[cont->getId()] = cont;
2651 std::map<int, GObjectController*>::iterator it2;
2652 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2653 GObjectController *cont = it2->second;
2654 if (cont->getGObjectType() == GCONNECTOR) {
2655 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2656 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2657 GBoxModel* startPortParentBox =
2658 cmod->getStartPort()->getParentBox();
2660 std::map<int, GObjectController*>::iterator iterOBJ1 =
2661 mapSelected.find(startPortParentBox->getObjectId());
2662 std::map<int, GObjectController*>::iterator iterOBJ2 =
2663 mapSelected.find(endPortParentBox->getObjectId());
2665 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2666 int ID = cont->getId();
2667 mapSelected[ID] = cont;
2674 //=========================================================================
2676 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2678 std::map<int, int> oldIdNewIdBoxes;
2679 std::vector<int> connections;
2681 std::map<int, GObjectController*>::iterator it;
2682 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2683 GObjectController *cont = it->second;
2684 int type = cont->getGObjectType();
2686 if (type == GBLACKBOX) {
2688 double xInic, yInic, zInic;
2689 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2690 copyBox->getInicPoint(xInic, yInic, zInic);
2691 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2693 int idcB = copyBox->getObjectId();
2694 oldIdNewIdBoxes[idcB] = idBox;
2695 cont = _controllers[idBox];
2696 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2697 newbox->setInicPoint(xInic, yInic, zInic);
2698 int num = newbox->getNumInputPorts();
2699 for (int j = 0; j < num; j++)
2701 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2703 newbox->notifyObservers(_idManager);
2704 } else if (type == GCONNECTOR) {
2705 int idCon = cont->getId();
2706 connections.push_back(idCon);
2711 for (int i = 0; i < (int) connections.size(); i++) {
2712 int objId = connections[i];
2713 GObjectController *cont = objectsMap[objId];
2714 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2716 GPortModel* startPort = connectModel->getStartPort();
2717 int startPortIndex = startPort->getPosInBox();
2718 GPortModel* endPort = connectModel->getEndPort();
2719 int endPortIndex = endPort->getPosInBox();
2721 GBlackBoxModel* startPortParentBox =
2722 (GBlackBoxModel*) startPort->getParentBox();
2723 GBlackBoxModel* endPortParentBox =
2724 (GBlackBoxModel*) endPort->getParentBox();
2726 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2727 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2729 GBlackBoxModel* newStartBox =
2730 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2731 GBlackBoxModel* newEndBox =
2732 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2734 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2735 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2737 // Creates connection
2738 int idCon = createGConnector(newStartPort);
2739 GConnectorController *tempp =
2740 (GConnectorController*) _controllers[idCon];
2741 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2742 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2743 tempp->endContourCreation();
2744 conMod->setEndPort(newEndPort);
2745 conView->updateStartEndPoints();
2748 std::map<int, int>::iterator itIds;
2749 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2750 int idOld = itIds->first;
2751 int idNew = itIds->second;
2753 GBlackBoxModel* oldBox =
2754 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2755 GBlackBoxModel* newBox =
2756 (GBlackBoxModel*) _controllers[idNew]->getModel();
2758 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2759 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2760 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2761 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2763 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2765 //EED int toCreate=-1;
2766 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2767 if (oldInputConnections[k] == newInputConnections[l]) {
2772 if (exist == false) {
2773 //Create complex input
2774 int posInBox = oldInputConnections[k];
2775 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2776 std::string inputPortName = inputPort->getBBTKName();
2777 int idInputPort = createGComplexBoxInputPort(inputPortName);
2778 GObjectController *cont = _controllers[idInputPort];
2779 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2780 double xIn, yIn, zIn;
2781 inputPort->getInicPoint(xIn, yIn, zIn);
2783 cbmod->setInicPoint(xIn, yIn, zIn);
2784 cbmod->notifyObservers(_idManager);
2786 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2788 // Creates connection
2789 int idCon = createGConnector(cbmod->getOutputPort(0));
2790 GConnectorController *tempp =
2791 (GConnectorController*) _controllers[idCon];
2792 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2793 vtkGConnectorView *conView =
2794 (vtkGConnectorView*) tempp->getView();
2795 tempp->endContourCreation();
2796 conMod->setEndPort(inputPortEnd);
2797 conView->updateStartEndPoints();
2803 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2805 //EED int toCreate=-1;
2806 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2807 if (oldOutputConnections[k] == newOutputConnections[l]) {
2812 if (exist == false) {
2813 //Create complex output
2814 int posInBox = oldOutputConnections[k];
2815 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2816 std::string outputPortName = outputPort->getBBTKName();
2817 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2818 GObjectController *cont = _controllers[idOutputPort];
2819 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2820 double xIn, yIn, zIn;
2821 outputPort->getInicPoint(xIn, yIn, zIn);
2823 cbmod->setInicPoint(xIn, yIn, zIn);
2824 cbmod->notifyObservers(_idManager);
2826 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2828 // Creates connection
2829 int idCon = createGConnector(outputPortEnd);
2830 GConnectorController *tempp =
2831 (GConnectorController*) _controllers[idCon];
2832 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2833 vtkGConnectorView *conView =
2834 (vtkGConnectorView*) tempp->getView();
2835 tempp->endContourCreation();
2836 conMod->setEndPort(cbmod->getInputPort(0));
2837 conView->updateStartEndPoints();
2847 //=========================================================================
2848 void wxVtkSceneManager::SetCbName(std::string cbName) {
2850 if (_cbName == "") {
2851 _cbName = "<complex box name>";
2855 //=========================================================================
2856 std::string wxVtkSceneManager::GetCbName() {
2860 //=========================================================================
2861 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2862 _cbPackageName = packagename;
2863 if (_cbPackageName == "") {
2864 _cbPackageName = "<package name of the complex box>";
2868 //=========================================================================
2869 std::string wxVtkSceneManager::GetCbPackageName() {
2870 return _cbPackageName;
2873 //=========================================================================
2874 void wxVtkSceneManager::SetAuthor(std::string author) {
2876 if (_Author == "") {
2877 _Author = "<author of the box>";
2881 //=========================================================================
2882 std::string wxVtkSceneManager::GetAuthor() {
2886 //=========================================================================
2887 void wxVtkSceneManager::SetCategory(std::string category) {
2888 _Category = category;
2889 if (_Category == "") {
2890 _Category = "<category of the box>";
2894 //=========================================================================
2895 std::string wxVtkSceneManager::GetCategory() {
2899 //=========================================================================
2900 void wxVtkSceneManager::SetDescription(std::string description) {
2901 _Description = description;
2902 if (_Description == "") {
2903 _Description = "<description of the box>";
2907 //=========================================================================
2908 std::string wxVtkSceneManager::GetDescription() {
2909 return _Description;
2912 //=========================================================================
2914 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
2917 std::vector< std::string> extInputs;
2918 std::map<int, GObjectController*>::iterator it;
2919 for (it = _controllers.begin(); it != _controllers.end(); ++it)
2921 GObjectController *cont = it->second;
2922 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
2924 extInputs.push_back(cont->getModel()->getBBTKName());
2930 //=========================================================================
2934 void wxVtkSceneManager::printAll(int com , int sta ){
2936 int tmpState = sta ;
2937 if ( tmpState == NOTHING_HAPPENS ) {
2938 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2940 if ( tmpState == HIGHLIGHTED ) {
2941 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2943 if ( tmpState == POSSIBLE_CONNECTION ) {
2944 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2946 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2947 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2949 if ( tmpState == CLICKED ) {
2950 std::cout << "CONTROLER STATE---->CLICKED\n" ;
2952 if ( tmpState == DRAG ) {
2953 std::cout << "CONTROLER STATE---->DRAG\n" ;
2955 if ( tmpState == SELECTED ) {
2956 std::cout << "CONTROLER STATE---->SELECTED\n" ;
2958 if ( tmpState == CREATING_CONTOUR ) {
2959 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2965 if ( command == INIT_CREATION_CONTOUR ) {
2966 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2968 if ( command == FIN_CREATION_CONTOUR ) {
2969 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2971 if ( command == ADD_TO_SELECTED ) {
2972 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2974 if ( command == DRAG_OBJECTS ) {
2975 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2977 if ( command == EDIT_BLACKBOX ) {
2978 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
2980 if ( command == REMOVE_FROM_SELECTED ) {
2981 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
2987 } // EO namespace bbtk