1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::wxVtkSceneManager .
36 #include "wxVtkSceneManager.h"
38 #include <vtkPolygon.h>
39 #include <vtkUnstructuredGrid.h>
43 #define POORT_MAX_LINE_SIZE_INTERPRETER 1500
45 //=========================================================================
47 // EED 15 oct 2012 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
49 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
51 _cbName = "ComplexBoxName";
52 _cbPackageName = "PackageName";
53 _Author = "Author ??";
55 _Description = "Description ??";
59 _idManager = idManager;
61 _bbtkfactory = bbtkfactory;
63 _startDragging = false;
64 _isComplexBox = false;
66 if (_baseView != NULL) {
69 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
72 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
76 _worldState = NOTHING_HAPPENS;
77 registerController(this);
80 _idConnectionInCreation = -1;
85 //=========================================================================
87 void wxVtkSceneManager::disconnectDrop()
89 printf("EED %p ~wxVtkSceneManager::disconnectDrop()\n", this);
90 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
91 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
94 //=========================================================================
96 wxVtkSceneManager::~wxVtkSceneManager()
99 printf("EED %p ~wxVtkSceneManager() START\n", this);
102 printf("EED %p ~wxVtkSceneManager() END\n", this);
105 //=========================================================================
107 void wxVtkSceneManager::configureBaseView()
109 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
111 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
113 // Important to activate the 2D interaction system
114 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
115 interactorstylebaseview->SetInteractor(iren);
116 iren->SetInteractorStyle(interactorstylebaseview);
117 interactorstylebaseview->SetwxVtkBaseView(_baseView);
119 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
120 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, -1000, 1000);
121 _baseView->GetRenderer()->GetActiveCamera()->Zoom(10);
124 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
125 _baseView->GetRenderer()->GradientBackgroundOn();
128 _textActor = vtkTextActor3D::New();
129 _textActor->SetPosition(-9999, -9999, GPOSITION_Z);
130 _textActor->SetInput("<void>");
131 _textActor->GetTextProperty()->SetFontSize(60);
132 _textActor->GetTextProperty()->BoldOn();
133 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,PORTTEXT_NH_B);
135 _baseView->GetRenderer()->AddActor(_textActor);
137 // Actor Fill_Port_Text
142 double zInic = GPOSITION_Z;
144 vtkPolygon *aPolygon = vtkPolygon::New();
145 _fillObjectActor = vtkActor::New();
147 _pts = vtkPoints::New();
149 double w = 100, h = 10, b = h / 15, t = 3;
150 _pts->SetNumberOfPoints(21);
151 _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
152 _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
153 _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
154 _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
155 _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
157 _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
158 _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
159 _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
160 _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
162 _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
163 _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
164 _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
165 _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
167 _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
168 _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
169 _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
170 _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
172 _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
173 _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
174 _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
175 _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
177 aPolygon->GetPointIds()->SetNumberOfIds(21);
178 for (int i = 0; i < 21; i++) {
179 aPolygon->GetPointIds()->SetId(i, i);
182 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
183 aPolygonGrid->Allocate(1, 1);
184 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),
185 aPolygon->GetPointIds());
186 aPolygonGrid->SetPoints(_pts);
187 _aPolygonMapper = vtkDataSetMapper::New();
188 _aPolygonMapper->SetInput(aPolygonGrid);
189 _fillObjectActor->SetMapper(_aPolygonMapper);
190 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
192 _fillObjectActor->GetProperty()->SetOpacity(0);
193 _aPolygonMapper->Modified();
195 _baseView->GetRenderer()->AddActor(_fillObjectActor);
198 //=========================================================================
200 std::string wxVtkSceneManager::generateANewNameForABox() {
201 std::stringstream boxname;
202 if (_numBoxes < 10) {
203 boxname << "Box0" << _numBoxes;
205 boxname << "Box" << _numBoxes;
208 return boxname.str();
211 //=========================================================================
213 std::string wxVtkSceneManager::findANewNameForABox() {
214 std::string boxname = generateANewNameForABox();
216 while (boxExist(boxname) == true) {
217 boxname = generateANewNameForABox();
223 //=========================================================================
224 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
225 double zIn, std::string name, bool boxExecutable, double xEn,
226 double yEn, double zEn) {
227 GObjectController *cont = _controllers[idBox];
228 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
229 bbmod->setBBTKName(name);
230 bbmod->setInicPoint(xIn, yIn, zIn);
231 bbmod->setFinalPoint(xEn, yEn, zEn);
232 bbmod->setExecutable(boxExecutable);
234 bbmod->notifyObservers(_idManager);
238 //=========================================================================
240 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,std::string boxType)
242 _worldState = NOTHING_HAPPENS;
243 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
244 int type = GBLACKBOX;
245 //Create the MVC Objects
246 GBlackBoxModel *model = (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
247 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
248 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
250 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
253 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
255 k = _bbtkfactory->GetPackage(packageName);
256 mapDesc = k->GetDescriptorMap();
258 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for package %s, NOT EXIST\n", packageName.c_str());
261 BlackBoxDescriptor::Pointer descriptor;
263 descriptor = mapDesc[boxType];
265 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for box %s of package %s, NOT EXIST\n", boxType.c_str(),packageName.c_str());
268 if (descriptor == NULL)
270 printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
273 //Prepares the initial model
274 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
277 double yy = windowHeight - y;
279 //z value is not important yet, because it is only used a parallel projection
280 double zz = GPOSITION_Z;
281 _baseView->TransCoordScreenToWorld(xx, yy, zz);
282 model->setInicPoint(xx, yy, zz);
284 std::stringstream stream;
286 std::string newBoxName;
287 newBoxName = findANewNameForABox();
289 stream << newBoxName;
291 std::string arraystring = stream.str();
293 model->setBBTKName(arraystring);
294 model->setBBTKType(boxType);
295 model->setBBTKPackage(packageName);
297 model->addObserver(view);
298 model->addObserver(this);
300 //Iterate and create the input ports
301 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
302 descriptor->GetInputDescriptorMap();
303 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
306 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) {
307 BlackBoxInputDescriptor *desc = itInput->second;
308 createGInputPort(GINPUTPORT, i, model, desc);
312 //Iterate and create the output ports
313 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
314 descriptor->GetOutputDescriptorMap();
315 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
318 for (itOutput = descriptorOutMap.begin(); itOutput
319 != descriptorOutMap.end(); ++itOutput) {
320 BlackBoxOutputDescriptor *desc = itOutput->second;
321 createGOutputPort(GOUTPUTPORT, i, model, desc);
325 //Associates the view with the correspondent renderer and the model.
326 //(NOTE: Refresh is only made by the view)
327 view->setModel(model);
328 view->setBaseView(_baseView);
329 view->initVtkObjects();
331 //Associates the controller with the correspondent model and view
332 controller->setModelAndView(model, view);
334 //Resgiter change to the observers of the actual model
335 model->notifyObservers(_idManager);
337 int newId = addObjectController(controller);
343 //=========================================================================
345 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
346 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
347 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
349 int type = GCOMPLEXINPUTPORT;
351 //Create the MVC Objects
353 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
354 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
355 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
357 //Prepares the initial model
360 double yy = windowHeight - 5;
362 //z value is not important yet, because it is only used a parallel projection
363 double zz = GPOSITION_Z;
365 _baseView->TransCoordScreenToWorld(xx, yy, zz);
366 model->setInicPoint(xx, yy, zz);
368 model->setBBTKName(inputName);
369 model->setBBTKType("ComplexInputPort");
370 model->setComplexPortType(type);
372 model->addObserver(view);
373 model->addObserver(this);
375 //create the output port
376 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
377 "ComplexOutputPortType","ComplexOutputPortDescriopton", 0, model);
378 model->addOutputPort((GPortModel*) portController->getModel());
380 //Associates the view with the correspondent renderer and the model.
381 //(NOTE: Refresh is only made by the view)
382 view->setModel(model);
383 view->setBaseView(_baseView);
384 view->initVtkObjects();
386 //Associates the controller with the correspondent model and view
387 controller->setModelAndView(model, view);
389 //Resgiter change to the observers of the actual model
390 model->notifyObservers(_idManager);
392 int newId = addObjectController(controller);
396 //=========================================================================
398 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
399 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
400 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
402 int type = GCOMPLEXOUTPUTPORT;
404 //Create the MVC Objects
406 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
407 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
408 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
410 //Prepares the initial model
413 double yy = windowHeight - 5;
415 //z value is not important yet, because it is only used a parallel projection
416 double zz = GPOSITION_Z;
418 _baseView->TransCoordScreenToWorld(xx, yy, zz);
419 model->setInicPoint(xx, yy, zz);
421 model->setBBTKName(outputName);
422 model->setBBTKType("ComplexOutputPort");
423 model->setComplexPortType(type);
425 model->addObserver(view);
426 model->addObserver(this);
428 //create the output port
429 GPortController* portController = createGPort(GINPUTPORT, outputName,
430 "ComplexInputPort","ComplexInputPortDescription", 0, model);
431 model->addInputPort((GPortModel*) portController->getModel());
433 //Associates the view with the correspondent renderer and the model.
434 //(NOTE: Refresh is only made by the view)
435 view->setModel(model);
436 view->setBaseView(_baseView);
437 view->initVtkObjects();
439 //Associates the controller with the correspondent model and view
440 controller->setModelAndView(model, view);
442 //Resgiter change to the observers of the actual model
443 model->notifyObservers(_idManager);
445 int newId = addObjectController(controller);
449 //=========================================================================
451 int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
453 GPortController* portController = createGPort(portType, desc->GetName(),
454 desc->GetTypeName(), desc->GetDescription(), posinBox, blackBox);
455 blackBox->addInputPort((GPortModel*) portController->getModel());
456 return portController->getId();
459 //=========================================================================
461 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
463 GPortController* portController = createGPort(portType, desc->GetName(),
464 desc->GetTypeName(),desc->GetDescription(), posinBox, blackBox);
465 blackBox->addOutputPort((GPortModel*) portController->getModel());
466 return portController->getId();
469 //=========================================================================
471 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posInBox,GBoxModel *blackBox)
475 //Create the MVC Objects
478 (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
480 vtkGObjectView *view =
481 GObjectsMVCFactory::getInstance()->createGObjectView(type);
482 GObjectController* controller =
483 GObjectsMVCFactory::getInstance()->createGObjectController(type);
485 model->registerInBox(blackBox, portType, posInBox);
487 model->setBBTKType(bbtkType);
488 model->setBBTKName(bbtkName);
489 model->setBBTKDescription(bbtkDescription);
491 model->addObserver(view);
492 model->addObserver(this);
494 //Associates the view with the correspondent renderer and the model.
495 //(NOTE: Refresh is only made by the view)
496 view->setModel(model);
497 view->setBaseView(_baseView);
498 view->initVtkObjects();
500 //Associates the controller with the correspondent model and view
501 controller->setModelAndView(model, view);
503 model->notifyObservers(_idManager);
505 addObjectController(controller);
507 return (GPortController*) controller;
510 //=========================================================================
512 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
514 int type = GCONNECTOR;
516 manualConnectorContourController *manContourControl = new manualConnectorContourController();
517 manualConnectorContourView *manContourView = new manualConnectorContourView();
518 manualContourModel *manContourModel = new manualContourModel();
519 GConnectorController *connectorcontroller = new GConnectorController();
520 GConnectorModel *connectorModel = new GConnectorModel();
521 vtkGConnectorView *connectorView = new vtkGConnectorView();
522 connectorModel->setGObjectType(type);
524 manContourModel->SetCloseContour(false);
525 connectorModel->setStartPort(startPort);
527 manContourView->SetModel(manContourModel);
528 manContourView->SetWxVtkBaseView(_baseView);
529 manContourView->SetRange(0.5);
530 manContourView->SetZ(GPOSITION_Z);
532 manContourView->SetColorNormalContour(0, 0, 1);
533 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
534 manContourView->SetColorSelectContour(1, 0.8, 0);
540 * Width increased from 2 to 3, it simplifies line handling and spline control :P
543 manContourView->SetWidthLine( 3 ) ;
544 manContourView->SetShowText(false);
546 manContourControl->SetModelView(manContourModel, manContourView);
548 manContourControl->CreateNewManualContour();
552 connectorModel->getInicPoint(x, y, z);
555 manContourControl->SetState(1);
556 manContourModel->SetCloseContour(false);
558 manContourModel->AddPoint(x, y, z);
559 manContourView->AddPoint();
561 manContourModel->AddPoint(x, y, z);
562 manContourView->AddPoint();
564 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
565 manContourControl->_bakIdPoint = bak;
567 manContourControl->SetMoving(false);
569 connectorcontroller->setModelAndView(connectorModel, connectorView);
571 int newId = addObjectController(connectorcontroller);
573 connectorcontroller->setManualContourController(manContourControl);
574 connectorModel->setManualContourModel(manContourModel);
575 connectorView->setManualContourView(manContourView);
576 connectorView->setModel(connectorModel);
577 connectorView->setBaseView(_baseView);
579 connectorModel->addObserver(connectorView);
580 connectorModel->addObserver(this);
582 // manContourView->Refresh();
587 //=========================================================================
589 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
591 vtkInteractorStyleBaseView * baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
592 baseViewControlManager->AddInteractorStyleMaracas(param);
595 //=========================================================================
597 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
599 vtkInteractorStyleBaseView *baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
600 baseViewControlManager->RemoveInteractorStyleMaracas(param);
603 //=========================================================================
605 vtkRenderer* wxVtkSceneManager::getRenderer()
607 return _baseView->GetRenderer();
610 //=========================================================================
612 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
614 return _baseView->GetRenWin();
616 //=========================================================================
619 //=========================================================================
620 int wxVtkSceneManager::GetIndexInSelected(int idControler)
623 for (int i = 0; i < (int) _selectedObjects.size(); i++)
625 if (_selectedObjects[i] == idControler)
633 //=========================================================================
635 void wxVtkSceneManager::update(int idController, int command) {
637 if (command != NO_COMMAND)
639 if (command == ADD_TO_SELECTED)
641 if (GetIndexInSelected(idController) == -1)
643 _selectedObjects.push_back(idController);
645 } else if (command == REMOVE_FROM_SELECTED) {
646 int index = GetIndexInSelected(idController);
649 _selectedObjects.erase(_selectedObjects.begin() + index);
651 } else if (command == INIT_CREATION_CONTOUR) {
653 typedef std::map<int , GObjectController*>::iterator TIterator ;
656 // Find current item in the controller
657 iter = _controllers.find( idController ) ;
658 iter_end = _controllers.end( ) ;
660 if ( iter != iter_end ) {
661 GObjectController* gobjc = iter->second ;
663 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
664 // And if the item is a port
665 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
666 TIterator c_it = _controllers.begin( ) ;
667 // Go through all componets
668 for ( c_it ; c_it != iter_end ; c_it++ ) {
669 GObjectController* obc = c_it->second ;
670 int obc_type = obc->getModel( )->getGObjectType( ) ;
671 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
672 // if the component is a port and the type is the same of that selected
673 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
675 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
676 //obc->getView( )->setState( HIGHLIGHTED ) ;
684 _worldState = INIT_CREATION_CONTOUR;
685 GObjectController* cont = _controllers[idController];
686 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
688 // The last one is the controller of the connector
689 std::map<int, GObjectController*>::iterator it2;
691 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
693 GObjectController *cont = it2->second;
694 if (cont->getGObjectType() == GPORT)
696 GPortModel* port = (GPortModel*) cont->getModel();
697 if (port->getPortType() == GINPUTPORT)
699 cont->SetActive(true);
701 cont->getView()->setState(NOTHING_HAPPENS);
702 cont->getModel()->notifyObservers(_idManager);
703 cont->SetActive(false);
706 cont->getView()->setState(NOTHING_HAPPENS);
707 cont->getModel()->notifyObservers(_idManager);
708 cont->SetActive(false);
711 _selectedObjects.clear();
712 _idConnectionInCreation = createGConnector(startOutputPort);
713 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
714 _worldState = NOTHING_HAPPENS;
715 //int id = _controllers.size()-1;
716 GObjectController *cont = _controllers[_idConnectionInCreation];
717 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
718 GObjectController *finPort = _controllers[idController];
720 if (finPort->getGObjectType() == GPORT)
722 GPortModel* modelPort = (GPortModel*) finPort->getModel();
723 modelContour->setEndPort(modelPort);
726 typedef std::map<int, GObjectController*>::iterator TIterator;
727 TIterator c_it = _controllers.begin();
728 TIterator iter_end = _controllers.end();
729 // Go through all componets
730 for (c_it; c_it != iter_end; c_it++) {
731 GObjectController* obc = c_it->second;
732 int obc_type = obc->getModel()->getGObjectType();
733 int obc_state = obc->getView()->getState();
734 // if the component is a port and the type is the same of that selected
735 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
736 // Return element to neutral state if not selected
737 obc->getView()->setState(NOTHING_HAPPENS);
739 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
740 // Change element to connected state
741 obc->getView()->setState(HIGHLIGHTED);
748 _parent->saveTempandUpdate("create connection");
751 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
752 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
754 std::map<int, GObjectController*>::iterator it2;
756 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
758 GObjectController *cont = it2->second;
759 if (cont->getView() != NULL) {
760 cont->getView()->setState(NOTHING_HAPPENS);
761 cont->getModel()->notifyObservers(_idManager);
763 cont->SetActive(true);
772 //=========================================================================
774 bool wxVtkSceneManager::OnMouseMove()
777 bool okStatusMessage = false;
778 bool okPortMessage = false;
779 wxVTKRenderWindowInteractor *wxVTKiren;
780 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
781 wxVTKiren->GetEventPosition(X, Y);
783 if (_worldState == DRAG_OBJECTS) {
784 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
785 int id = _selectedObjects[i];
786 GObjectController* cont = _controllers[id];
787 if (_startDragging) {
788 cont->getView()->setStartDragging(true);
790 cont->getView()->moveObject(X, Y);
791 cont->getView()->setState(DRAG);
792 cont->getModel()->notifyObservers(_idManager);
795 std::map<int, GObjectController*>::iterator it;
797 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
798 GObjectController *desc = it->second;
799 if (desc->getGObjectType() == GCONNECTOR) {
800 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
801 vconn->updateStartEndPoints();
805 _startDragging = false;
807 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
808 std::map<int, GObjectController*>::iterator it;
810 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
811 GObjectController *desc = it->second;
812 int type = desc->getGObjectType();
813 int state = desc->getView()->getState();
814 desc->getModel()->getCenter(px, py, pz);
817 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
820 okStatusMessage = true;
821 updateStatusBar(desc->getStatusText());
822 if (type == GBLACKBOX)
824 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
825 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
830 okPortMessage = true;
832 _textActor->SetInput(desc->getStatusText().c_str());
833 _textActor->SetScale(0.1);
834 _textActor->SetPosition(px - 25, py + 1, pz + 2);
839 _fillObjectActor->SetScale(1);
840 _fillObjectActor->GetProperty()->SetOpacity(0.50);
841 _fillObjectActor->SetPosition(px, py, 1);
842 _aPolygonMapper->Modified();
845 } // for controllers it
848 if (okStatusMessage == false)
853 if (okPortMessage == false)
855 _textActor->SetScale(0.0001);
856 _fillObjectActor->SetScale(0.0001);
861 //=========================================================================
863 bool wxVtkSceneManager::OnLeftButtonDown()
865 if (_worldState == INIT_CREATION_CONTOUR)
867 bool isOverPort = false;
868 std::map<int, GObjectController*>::iterator it;
869 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
871 GObjectController *desc = it->second;
872 if (desc->getGObjectType() == GPORT)
874 GPortModel *portmod = (GPortModel*) desc->getModel();
875 vtkGObjectView *portView = desc->getView();
876 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
881 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
883 portView->setState( HIGHLIGHTED);
890 if (isOverPort == false)
893 UnSelectBlackBoxes();
897 } else { //_worldState
899 _worldState = DRAG_OBJECTS;
900 _startDragging = true;
902 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
903 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
904 ctrlkey = ctrlkey + shiftkey;
906 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
909 int state = cont->getView()->getState();
910 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
911 UnSelectBlackBoxes();
914 UnSelectBlackBoxes(); // EED 12/07/2012
916 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
917 int id = _selectedObjects[i];
918 GObjectController *cont = _controllers[id];
919 cont->getView()->setState(DRAG);
920 cont->getModel()->notifyObservers(_idManager);
922 } // if _selectedObjects.size
928 //=========================================================================
930 bool wxVtkSceneManager::OnLeftButtonUp()
932 if (_worldState == DRAG_OBJECTS) {
933 _worldState = NOTHING_HAPPENS;
935 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
936 int id = _selectedObjects[i];
937 GObjectController* cont = _controllers[id];
938 cont->getView()->setState(SELECTED);
939 cont->getModel()->notifyObservers(_idManager);
945 //=========================================================================
946 void wxVtkSceneManager::CancelConnection()
948 if (_worldState == INIT_CREATION_CONTOUR)
950 _worldState = NOTHING_HAPPENS;
951 //int lastId = _controllers.size()-1;
953 GConnectorController *connector =
954 (GConnectorController*) _controllers[_idConnectionInCreation];
955 connector->removeFromScene();
956 unregisterController(connector);
957 _controllers.erase(_idConnectionInCreation);
959 std::map<int, GObjectController*>::iterator it;
960 for (it = _controllers.begin(); it != _controllers.end(); ++it)
962 GObjectController *desc = it->second;
963 desc->SetActive(true);
964 desc->getView()->setState(NOTHING_HAPPENS);
965 desc->getModel()->notifyObservers(_idManager);
970 //=========================================================================
972 bool wxVtkSceneManager::OnRightButtonUp()
974 if (_worldState == INIT_CREATION_CONTOUR)
978 UnSelectBlackBoxes();
984 bool wxVtkSceneManager::OnMiddleButtonDown() {
987 this->_vtkInteractorStyleBaseView->StartPan();
992 bool wxVtkSceneManager::OnMiddleButtonUp() {
995 this->_vtkInteractorStyleBaseView->EndPan();
1002 //=========================================================================
1004 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1005 GObjectController *result = NULL;
1007 wxVTKRenderWindowInteractor *wxVTKiren;
1009 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1010 wxVTKiren->GetEventPosition(X, Y);
1012 std::map<int, GObjectController*>::iterator it;
1014 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1015 GObjectController *cont = it->second;
1016 int type = cont->getGObjectType();
1018 if (cont->getView()->isPointInside(X, Y) == true) {
1019 if (type == GBLACKBOX) {
1022 } // if isPointInside
1027 //=========================================================================
1028 void wxVtkSceneManager::UnSelectBlackBoxes() {
1029 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1030 int id = _selectedObjects[i];
1031 GObjectController* control = _controllers[id];
1032 control->getView()->setState(NOTHING_HAPPENS);
1033 control->getModel()->notifyObservers(_idManager);
1034 }// for _selectedObjects
1035 _selectedObjects.clear();
1038 //=========================================================================
1039 bool wxVtkSceneManager::OnLeftDClick() {
1040 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1042 UnSelectBlackBoxes();
1043 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1049 wxVTKRenderWindowInteractor *wxVTKiren;
1050 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1051 wxVTKiren->GetEventPosition(X,Y);
1053 std::map<int, GObjectController*>::iterator it;
1055 bool clickOnObject = false;
1057 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1059 GObjectController *cont = it->second;
1060 int type = cont->getGObjectType();
1062 if(cont->getView()->isPointInside(X,Y))
1066 for (int i=0; i< (int)_selectedObjects.size(); i++)
1068 int id = _selectedObjects[i];
1069 GObjectController* control = _controllers[id];
1070 control->getView()->setState(NOTHING_HAPPENS);
1072 _selectedObjects.clear();
1074 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1075 _parent->editBlackBox(bbmodel);
1077 clickOnObject = true;
1081 if(clickOnObject==false)
1083 //_parent->editDiagramParameters(this);
1089 //=========================================================================
1091 bool wxVtkSceneManager::OnChar()
1095 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1096 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1098 // KeyCode 127 : Delete Key
1099 // KeyCode 8 : Backspace Key
1102 if (keyCode == 8 || keyCode == 127 || keyCode == 27)
1104 if (_worldState == INIT_CREATION_CONTOUR)
1107 UnSelectBlackBoxes();
1112 if (keyCode == 8 || keyCode == 127)
1115 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1117 int id = _selectedObjects[i];
1118 std::map<int, GObjectController*>::iterator it;
1119 it = _controllers.find(id);
1120 if (it != _controllers.end())
1122 oktmp = deleteObject(id);
1125 }// for selected objects
1126 if (ok) _selectedObjects.clear();
1127 _parent->saveTempandUpdate("delete object");
1132 if((keyCode==0) && (ctrlkey==1)) {
1137 if(_selectedObjects.size()){
1138 std::cout<<"objects to copy :";
1139 for(int i=0;i<_selectedObjects.size();i++)
1141 std::cout<<_selectedObjects.at(i)<<" ";
1143 DuplicateObjects(getSelectedObjects());
1145 std::cout<<"No objects to copy\n";
1146 } // _selectedObjects.size
1152 //=========================================================================
1154 void wxVtkSceneManager::AddControlerToBeRemove(
1155 std::vector<int> *controllersToRemove, int id) {
1159 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1160 if (id == (*controllersToRemove)[i]) {
1166 controllersToRemove->push_back(id);
1171 //=========================================================================
1173 bool wxVtkSceneManager::deleteObject(int id)
1176 GObjectController *control = _controllers[id];
1177 std::vector<int> controllersToRemove;
1178 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1179 == GCOMPLEXINPUTPORT || control->getGObjectType()
1180 == GCOMPLEXOUTPUTPORT) {
1181 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1182 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1184 bool boxConnected = false;
1186 // Add box input controllers to be removed
1187 for (int i = 0; i < (int) inputs.size(); i++) {
1188 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1189 if (inputs[i]->isConnected()) {
1190 boxConnected = true;
1194 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1196 // Add box output controllers to be removed
1197 for (int i = 0; i < (int) outputs.size(); i++) {
1198 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1199 if (outputs[i]->isConnected()) {
1200 boxConnected = true;
1204 // Add connection controllers to be removed
1205 std::map<int, GObjectController*>::iterator it;
1206 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1207 GObjectController *cont = it->second;
1208 int type = cont->getGObjectType();
1209 if (type == GCONNECTOR) {
1210 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1211 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1213 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1215 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1217 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1222 // Add box controller to be removed
1223 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1224 } else if (control->getGObjectType() == GCONNECTOR) {
1225 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1226 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1228 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1229 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1231 gconnectorcontroler->getManualContourController()->OnChar();
1236 std::map<int, GObjectController*>::iterator it;
1238 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1239 int key = controllersToRemove[i];
1240 it = _controllers.find(key);
1241 GObjectController *cont = _controllers[key];
1243 cont->removeFromScene();
1244 unregisterController((InteractorStyleMaracas*) cont);
1245 _controllers.erase(it);
1253 //=========================================================================
1255 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1256 std::string boxName) {
1257 _parent->displayBlackBoxInfo(packageName, boxName);
1260 //=========================================================================
1262 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1263 _parent->updateStatusBar(textStatus);
1266 //=========================================================================
1267 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1268 std::string result = "";
1269 if (withLineNumber == true) {
1271 stringstream StrStream;
1273 std::string strValue = StrStream.str();
1276 } else if (value < 100) {
1280 result += strValue + ": ";
1284 //=========================================================================
1286 bool wxVtkSceneManager::MakeBoxExecutable() {
1287 std::map<int, GObjectController*> selected = getSelectedObjects();
1288 if( selected.empty() )
1291 std::map<int, GObjectController*>::iterator it;
1292 for (it = selected.begin(); it != selected.end(); ++it) {
1293 GObjectController* lastSelected = it->second;
1295 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1296 GBlackBoxModel *bbmodel =
1297 (GBlackBoxModel*) lastSelected->getModel();
1298 view->setState(HIGHLIGHTED);
1299 if (bbmodel->isExecutable()) {
1300 bbmodel->setExecutable(false);
1302 bbmodel->setExecutable(true);
1304 bbmodel->notifyObservers(lastSelected->getId());
1312 //=========================================================================
1314 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1315 bool existsExec = false;
1317 std::vector<std::string> packages;
1318 std::vector<int> boxes;
1319 std::vector<int> connections;
1320 std::vector<int> execBoxes;
1322 std::map<int, GObjectController*>::iterator it;
1324 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1325 GObjectController *desc = it->second;
1326 int type = desc->getGObjectType();
1328 if (type == GBLACKBOX) {
1329 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1331 std::string pkg = mod->getBBTKPackage();
1332 bool existsPkg = false;
1333 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1334 if (packages[t] == pkg) {
1339 packages.push_back(pkg);
1342 boxes.push_back(it->first);
1343 if (mod->isExecutable()) {
1344 execBoxes.push_back(it->first);
1347 } else if (type == GCONNECTOR) {
1348 connections.push_back(it->first);
1353 std::string script = "";
1354 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1355 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1356 script += LineNumber(wln, lnNmbr) + "\n";
1358 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1359 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1361 for (i = 0; i < (int) packages.size(); i++) {
1362 script += LineNumber(wln, lnNmbr);
1363 script += "include ";
1364 script += packages[i];
1368 script += LineNumber(wln, lnNmbr);
1373 script += LineNumber(wln, lnNmbr);
1374 script += "author \"";
1378 script += LineNumber(wln, lnNmbr);
1379 script += "description \"";
1380 script += _Description;
1383 script += LineNumber(wln, lnNmbr);
1384 script += "category \"";
1385 script += _Category;
1388 script += LineNumber(wln, lnNmbr);
1391 // script+="include std\n"; // JPR
1393 for (i = 0; i < (int) boxes.size(); i++) {
1394 script += LineNumber(wln, lnNmbr);
1397 GObjectController *control = _controllers[id];
1398 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1400 script += model->getBBTKType();
1402 script += model->getBBTKName();
1405 std::vector<GPortModel*> inputs = model->getInputPorts();
1406 for (int j = 0; j < (int) inputs.size(); j++) {
1407 GPortModel* inputPort = inputs[j];
1408 if (inputPort->isValueSet()) {
1409 script += LineNumber(wln, lnNmbr);
1411 script += model->getBBTKName();
1413 script += inputPort->getBBTKName();
1415 script += inputPort->getValue();
1420 script += LineNumber(wln, lnNmbr);
1425 script += LineNumber(wln, lnNmbr);
1429 std::string complexInputs="";
1431 for (i = 0; i < (int) connections.size(); i++) {
1432 //script += LineNumber(wln, lnNmbr);
1433 //script += "connect ";
1434 int id = connections[i];
1435 GObjectController *control = _controllers[id];
1436 GConnectorModel *model = (GConnectorModel*) control->getModel();
1440 GPortModel *start = model->getStartPort();
1441 GBoxModel *startBox = start->getParentBox();
1443 GPortModel *end = model->getEndPort();
1444 GBoxModel *endBox = end->getParentBox();
1446 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1448 complexInputs += "input ";
1449 complexInputs += startBox->getBBTKName();
1451 complexInputs += " ";
1452 complexInputs += endBox->getBBTKName();
1453 complexInputs += ".";
1454 complexInputs += end->getBBTKName();
1456 complexInputs += " ";
1457 complexInputs += "\" \"";
1459 complexInputs += "\n";
1463 script += "connect ";
1464 script += startBox->getBBTKName();
1466 script += start->getBBTKName();
1470 //End Connection info
1471 script += endBox->getBBTKName();
1473 script += end->getBBTKName();
1481 script += LineNumber(wln, lnNmbr);
1485 script += "# Complex input ports\n";
1486 script += complexInputs;
1488 for (i = 0; i < (int) execBoxes.size(); i++) {
1489 script += LineNumber(wln, lnNmbr);
1491 int id = execBoxes[i];
1492 GObjectController *control = _controllers[id];
1493 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1495 script += model->getBBTKName();
1504 //=========================================================================
1506 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1507 std::vector<std::string> packages;
1508 std::vector<int> boxes;
1509 std::vector<int> connections;
1510 std::vector<int> execBoxes;
1512 std::map<int, GObjectController*>::iterator it;
1514 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1515 GObjectController *desc = it->second;
1516 int type = desc->getGObjectType();
1518 if (type == GBLACKBOX) {
1519 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1521 std::string pkg = mod->getBBTKPackage();
1522 bool existsPkg = false;
1523 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1524 if (packages[t] == pkg) {
1529 packages.push_back(pkg);
1532 boxes.push_back(it->first);
1533 if (mod->isExecutable()) {
1534 execBoxes.push_back(it->first);
1536 } else if (type == GCONNECTOR) {
1537 connections.push_back(it->first);
1541 std::string script = "";
1543 script += "include std\n"; // EED
1544 script += "include itkvtk\n"; // EED
1546 for (i = 0; i < (int) packages.size(); i++) {
1547 script += "include ";
1548 script += packages[i];
1553 // Definition of a complex box
1554 script += "define ";
1555 script += _cbName + " " + _cbPackageName;
1559 script += "author \"";
1563 script += "description \"";
1564 script += _Description;
1568 script += "category \"";
1569 script += _Category;
1574 for (i = 0; i < (int) boxes.size(); i++) {
1577 GObjectController *control = _controllers[id];
1578 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1580 script += model->getBBTKType();
1582 script += model->getBBTKName();
1585 std::vector<GPortModel*> inputs = model->getInputPorts();
1586 for (int j = 0; j < (int) inputs.size(); j++) {
1587 GPortModel* inputPort = inputs[j];
1588 if (inputPort->isValueSet()) {
1590 script += model->getBBTKName();
1592 script += inputPort->getBBTKName();
1594 script += inputPort->getValue();
1602 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1604 std::string complexInputs = "";
1605 std::string complexOutputs = "";
1608 for (i = 0; i < (int) connections.size(); i++) {
1609 int id = connections[i];
1610 GObjectController *control = _controllers[id];
1611 GConnectorModel *model = (GConnectorModel*) control->getModel();
1614 GPortModel *start = model->getStartPort();
1615 GBoxModel *startBox = start->getParentBox();
1617 GPortModel *end = model->getEndPort();
1618 GBoxModel *endBox = end->getParentBox();
1620 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1621 complexInputs += "input ";
1622 complexInputs += startBox->getBBTKName();
1624 complexInputs += " ";
1625 complexInputs += endBox->getBBTKName();
1626 complexInputs += ".";
1627 complexInputs += end->getBBTKName();
1629 complexInputs += " ";
1630 complexInputs += "\" \"";
1632 complexInputs += "\n";
1633 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1634 complexOutputs += "output ";
1635 complexOutputs += endBox->getBBTKName();
1637 complexOutputs += " ";
1638 complexOutputs += startBox->getBBTKName();
1639 complexOutputs += ".";
1640 complexOutputs += start->getBBTKName();
1642 complexOutputs += " ";
1643 complexOutputs += "\" \"";
1645 complexOutputs += "\n";
1647 script += "connect ";
1648 script += startBox->getBBTKName();
1650 script += start->getBBTKName();
1654 //End Connection info
1655 script += endBox->getBBTKName();
1657 script += end->getBBTKName();
1664 script += "# Complex input ports\n";
1665 script += complexInputs;
1668 script += "# Complex output ports\n";
1669 script += complexOutputs;
1673 for (i = 0; i < (int) execBoxes.size(); i++) {
1675 int id = execBoxes[i];
1676 GObjectController *control = _controllers[id];
1677 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1679 script += model->getBBTKName();
1684 script += "endefine";
1690 //=========================================================================
1692 void wxVtkSceneManager::deleteAllBoxes() {
1693 std::map<int, GObjectController*>::iterator it;
1694 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1695 GObjectController *cont = it->second;
1696 cont->removeFromScene();
1697 unregisterController((InteractorStyleMaracas*) cont);
1699 _selectedObjects.clear();
1700 _controllers.clear();
1703 //=========================================================================
1706 void wxVtkSceneManager::refresh() {
1707 _baseView->Refresh();
1709 //=========================================================================
1711 void wxVtkSceneManager::refreshScene() {
1712 _baseView->RefreshView();
1715 //=========================================================================
1717 void wxVtkSceneManager::centerView() {
1719 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1720 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1721 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1722 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1725 //=========================================================================
1727 void wxVtkSceneManager::saveDiagram(std::string &content) {
1730 content += "CATEGORY:";
1731 content += GetCategory();
1734 content += "DESCRIPTION:";
1735 content += GetDescription();
1738 content += "AUTHOR:";
1739 content += GetAuthor();
1742 //Print info IF COMPLEX BOX
1743 content += "COMPLEXBOX:";
1744 if (_isComplexBox) {
1745 content += "TRUE\n";
1747 content += "COMPLEXBOXNAME:";
1748 content += GetCbName();
1751 content += "PACKAGENAME:";
1752 content += GetCbPackageName();
1755 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1756 * External inputs are possible for applications and complex boxes
1757 //Print info complex input ports
1758 std::vector<int> inputs = getComplexInputPorts();
1759 int insize = inputs.size();
1760 content += "COMPLEXINPUTS:";
1761 sprintf(buffer, "%d", insize);
1765 for (int i = 0; i < insize; i++) {
1767 GObjectController *cont = _controllers[id];
1768 cont->getModel()->save(content);
1772 //Print info complex output ports
1773 std::vector<int> outputs = getComplexOutputPorts();
1774 int outsize = outputs.size();
1775 content += "COMPLEXOUTPUTS:";
1776 sprintf(buffer, "%d", outsize);
1780 for (int i = 0; i < outsize; i++) {
1781 int id = outputs[i];
1782 GObjectController *cont = _controllers[id];
1783 cont->getModel()->save(content);
1787 content += "FALSE\n";
1790 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1791 // External inputs are possible for applications and complex boxes
1792 std::vector<int> inputs = getComplexInputPorts();
1793 int insize = inputs.size();
1794 content += "COMPLEXINPUTS:";
1795 sprintf(buffer, "%d", insize);
1799 for (int i = 0; i < insize; i++) {
1801 GObjectController *cont = _controllers[id];
1802 cont->getModel()->save(content);
1806 std::vector<int> boxes = getBlackBoxes();
1807 int bsize = boxes.size();
1808 content += "BOXES:";
1809 sprintf(buffer, "%d", bsize);
1813 for (int i = 0; i < bsize; i++) {
1815 GObjectController *cont = _controllers[id];
1816 cont->getModel()->save(content);
1820 std::vector<int> connections = getConnections();
1821 int csize = connections.size();
1822 content += "CONNECTIONS:";
1823 sprintf(buffer, "%d", csize);
1827 for (int i = 0; i < csize; i++) {
1828 int id = connections[i];
1829 GObjectController *cont = _controllers[id];
1830 cont->getModel()->save(content);
1835 //=========================================================================
1836 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1838 getline(inputStream, line,'\n');
1839 int size = line.length();
1842 if ( line[ size-1 ]==13 )
1844 line.erase(size-1,1);
1849 //=========================================================================
1850 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1853 std::string version = "<void>";
1854 std::string line = "";
1855 char delims[] = ":";
1856 char *result = NULL;
1857 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1859 getCleanLine(inputStream, line);
1862 while (!inputStream.eof()) {
1863 if (line == "" || line[0] == '#') {
1865 getCleanLine(inputStream, line);
1867 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1868 version = line.substr(18, 3);
1870 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1871 version = line.substr(18, 3);
1873 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1874 version = line.substr(18, 3);
1876 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1877 version = line.substr(18, 3);
1879 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1880 version = line.substr(18, 3);
1882 } else if (line == "APP_START") {
1891 if ((version != "1.0") && (version != "1.1")) {
1892 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1893 char categoryTmp[30];
1894 strcpy(categoryTmp, line.c_str());
1895 result = strtok(categoryTmp, delims);
1896 result = strtok(NULL, delims);
1897 SetCategory(result);
1899 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1900 char descriptionTmp[1024];
1901 strcpy(descriptionTmp, line.c_str());
1902 result = strtok(descriptionTmp, delims);
1903 result = strtok(NULL, delims);
1904 SetDescription(result);
1906 getCleanLine(inputStream, line);//AUTHOR:<author>
1907 char authorTmp[255];
1908 strcpy(authorTmp, line.c_str());
1909 result = strtok(authorTmp, delims);
1910 result = strtok(NULL, delims);
1915 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1916 char complexTmp[30];
1917 strcpy(complexTmp, line.c_str());
1918 result = strtok(complexTmp, delims);
1919 result = strtok(NULL, delims);
1920 std::string isComplexBox(result);
1922 if (isComplexBox == "TRUE") {
1923 _isComplexBox = true;
1925 if ((version != "1.0") && (version != "1.1")) {
1926 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
1927 char complexboxnameTmp[255];
1928 strcpy(complexboxnameTmp, line.c_str());
1929 result = strtok(complexboxnameTmp, delims);
1930 result = strtok(NULL, delims);
1933 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
1934 char packagenameTmp[255];
1935 strcpy(packagenameTmp, line.c_str());
1936 result = strtok(packagenameTmp, delims);
1937 result = strtok(NULL, delims);
1938 SetCbPackageName(result);
1943 //-----------------------
1944 //- COMPLEX INPUT PORTS
1945 //-----------------------
1946 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
1948 strcpy(inputs, line.c_str());
1949 result = strtok(inputs, delims);
1950 result = strtok(NULL, delims);
1953 std::istringstream inps(result);
1956 for (int i = 0; i < numInputs; i++) {
1958 getCleanLine(inputStream, line);//COMPLEX_PORT
1959 getCleanLine(inputStream, line);//name
1960 std::string inputPortName(line);
1963 getCleanLine(inputStream, line);//xInic:yInic:zInic
1965 strcpy(coord, line.c_str());
1966 result = strtok(coord, delims);//xInic
1967 std::string xInic(result);
1968 result = strtok(NULL, delims);//yInic
1969 std::string yInic(result);
1970 result = strtok(NULL, delims);//zInic
1971 std::string zInic(result);
1973 double xIn, yIn, zIn;
1974 std::istringstream xSt(xInic);
1976 std::istringstream ySt(yInic);
1978 std::istringstream zSt(zInic);
1983 if (zIn==900) zIn=GPOSITION_Z;
1986 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
1988 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
1990 } // for input complex box
1994 //-----------------------
1995 //- COMPLEX OUTPUT PORTS
1996 //-----------------------
1998 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2000 strcpy(outputs, line.c_str());
2001 result = strtok(outputs, delims);
2002 result = strtok(NULL, delims);
2005 std::istringstream outps(result);
2006 outps >> numOutputs;
2008 for (int i = 0; i < numOutputs; i++) {
2010 getCleanLine(inputStream, line);//COMPLEX_PORT
2011 getCleanLine(inputStream, line);//name
2012 std::string outputPortName(line);
2015 getCleanLine(inputStream, line);//xInic:yInic:zInic
2017 strcpy(coord, line.c_str());
2018 result = strtok(coord, delims);//xInic
2019 std::string xInic(result);
2020 result = strtok(NULL, delims);//yInic
2021 std::string yInic(result);
2022 result = strtok(NULL, delims);//zInic
2023 std::string zInic(result);
2025 double xIn, yIn, zIn;
2026 std::istringstream xSt(xInic);
2028 std::istringstream ySt(yInic);
2030 std::istringstream zSt(zInic);
2035 if (zIn==900) zIn=GPOSITION_Z;
2038 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2040 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2042 } // for output complex box
2046 // RaC2012 2nd Hackfest
2047 if(version >= "1.4")
2049 //-----------------------
2050 //- EXTERNAL INPUT PORTS
2051 //-----------------------
2052 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2054 strcpy(inputs, line.c_str());
2055 result = strtok(inputs, delims);
2056 result = strtok(NULL, delims);
2059 std::istringstream inps(result);
2062 for (int i = 0; i < numInputs; i++) {
2064 getCleanLine(inputStream, line);//COMPLEX_PORT
2065 getCleanLine(inputStream, line);//name
2066 std::string inputPortName(line);
2069 getCleanLine(inputStream, line);//xInic:yInic:zInic
2071 strcpy(coord, line.c_str());
2072 result = strtok(coord, delims);//xInic
2073 std::string xInic(result);
2074 result = strtok(NULL, delims);//yInic
2075 std::string yInic(result);
2076 result = strtok(NULL, delims);//zInic
2077 std::string zInic(result);
2079 double xIn, yIn, zIn;
2080 std::istringstream xSt(xInic);
2082 std::istringstream ySt(yInic);
2084 std::istringstream zSt(zInic);
2089 if (zIn==900) zIn=GPOSITION_Z;
2092 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2093 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2095 } // for external input
2100 getCleanLine(inputStream, line);//BOXES:num
2102 strcpy(boxes, line.c_str());
2103 result = strtok(boxes, delims);
2104 result = strtok(NULL, delims);
2107 std::istringstream is(result);
2110 for (int i = 0; i < numBoxes; i++) {
2112 getCleanLine(inputStream, line);//BOX
2113 getCleanLine(inputStream, line);//package:type:name
2115 strcpy(box, line.c_str());
2116 result = strtok(box, delims);//package
2117 std::string package(result);
2118 result = strtok(NULL, delims);//type
2119 std::string type(result);
2120 result = strtok(NULL, delims);//name
2121 std::string name(result);
2123 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2125 strcpy(exec, line.c_str());
2126 result = strtok(exec, delims);//ISEXEC
2127 result = strtok(NULL, delims);//TRUE|FALSE
2128 std::string isExec(result);
2131 getCleanLine(inputStream, line);//xInic:yInic:zInic
2133 strcpy(coord, line.c_str());
2134 result = strtok(coord, delims);//xInic
2135 std::string xInic(result);
2136 result = strtok(NULL, delims);//yInic
2137 std::string yInic(result);
2138 result = strtok(NULL, delims);//zInic
2139 std::string zInic(result);
2141 double xIn, yIn, zIn;
2142 std::istringstream xSt(xInic);
2144 std::istringstream ySt(yInic);
2146 std::istringstream zSt(zInic);
2152 if (zIn==900) zIn=GPOSITION_Z;
2157 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2158 strcpy(coord, line.c_str());
2159 result = strtok(coord, delims);//xEnd
2160 std::string xEnd(result);
2161 result = strtok(NULL, delims);//yEnd
2162 std::string yEnd(result);
2163 result = strtok(NULL, delims);//zEnd
2164 std::string zEnd(result);
2166 double xEn, yEn, zEn;
2167 std::istringstream xEt(xEnd);
2169 std::istringstream yEt(yEnd);
2171 std::istringstream zEt(zEnd);
2176 if (zEn==900) zEn=GPOSITION_Z;
2180 bool boxExecutable = false;
2181 if (isExec == "TRUE") {
2182 boxExecutable = true;
2185 int idBox = createGBlackBox(xIn, yIn, package, type);
2186 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2188 GObjectController *cont = _controllers[idBox];
2189 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2192 getCleanLine(inputStream, line);//PORT o FIN_BOX
2193 std::string port = line.substr(0, 4);
2194 while (port == "PORT")
2196 getCleanLine(inputStream, line);//name:value
2197 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2199 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2202 strcpy(poort, line.c_str());
2203 result = strtok(poort, delims);//name
2204 std::string name(result);
2206 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2207 result = strtok(NULL, delims);//value
2208 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2210 std::string tmpString=" ";
2211 tmpString[0]=34; // character "
2212 strcat(result,tmpString.c_str());
2214 std::string value(result);
2216 bbmod->setValueToInput(name, value);
2218 getCleanLine(inputStream, line);//PORT o FIN_BOX
2219 port = line.substr(0, 4);
2222 //EED bbmod->notifyObservers(_idManager);
2227 getCleanLine(inputStream, line);//CONNECTIONS:num
2229 strcpy(conns, line.c_str());
2230 result = strtok(conns, delims);
2231 result = strtok(NULL, delims);
2234 std::istringstream isCons(result);
2238 for (int i = 0; i < numConns; i++) {
2240 getCleanLine(inputStream, line);//CONNECTION
2241 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2244 strcpy(connec, line.c_str());
2245 result = strtok(connec, delims);
2246 std::string nameStartBox(result);
2247 result = strtok(NULL, delims);
2248 std::string nameStartPort(result);
2249 result = strtok(NULL, delims);
2250 std::string nameEndBox(result);
2251 result = strtok(NULL, delims);
2252 std::string nameEndPort(result);
2254 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2256 if (version != "1.0") {
2257 //Readding control points of the manualContour
2258 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2259 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2260 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2261 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2262 strcpy(conns, line.c_str());
2263 result = strtok(conns, delims);
2264 result = strtok(NULL, delims);
2266 int numberOfControlPoints;
2267 std::istringstream isCons(result);
2268 isCons >> numberOfControlPoints;
2270 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2271 getCleanLine(inputStream, line); //XX:YY:ZZ
2273 strcpy(connec, line.c_str());
2276 result = strtok(connec, delims);
2277 std::istringstream isPointX(result);
2279 result = strtok(NULL, delims);
2280 std::istringstream isPointY(result);
2282 result = strtok(NULL, delims);
2283 std::istringstream isPointZ(result);
2288 if (pz==900) pz=GPOSITION_Z;
2291 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2292 conView->getManualContourView()->AddPoint();
2298 //=========================================================================
2301 //=========================================================================
2302 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2303 std::string portName, double xIn, double yIn, double zIn)
2306 if (inputoutput == true) {
2307 idPort = createGComplexBoxInputPort(portName);
2309 idPort = createGComplexBoxOutputPort(portName);
2311 GObjectController *cont = _controllers[idPort];
2312 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2313 cbmod->setInicPoint(xIn, yIn, zIn);
2314 cbmod->notifyObservers(_idManager);
2316 //=========================================================================
2319 //=========================================================================
2320 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2325 GBoxModel *boxModel = NULL;
2326 std::vector<int> lstB = getBlackBoxes();
2327 for (j = 0; j < (int) lstB.size(); j++) {
2329 bMod = (GBoxModel*) _controllers[idB]->getModel();
2330 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2337 if (boxModel == NULL) {
2338 std::vector<int> lstInputs = getComplexInputPorts();
2339 for (j = 0; j < (int) lstInputs.size(); j++) {
2341 bMod = (GBoxModel*) _controllers[idB]->getModel();
2342 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2349 std::vector<int> lstOutputs = getComplexOutputPorts();
2350 for (j = 0; j < (int) lstOutputs.size(); j++) {
2351 int idB = lstOutputs[j];
2352 bMod = (GBoxModel*) _controllers[idB]->getModel();
2353 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2364 //=========================================================================
2367 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2368 std::string nameStartPort, std::string nameEndBox,
2369 std::string nameEndPort) {
2371 GBoxModel *boxModel;
2372 GPortModel *startP = NULL;
2373 GPortModel *endP = NULL;
2375 boxModel = findGBox(nameStartBox);
2376 if(boxModel == NULL)
2378 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2380 if (boxModel != NULL) {
2381 startP = boxModel->getOutputPort(nameStartPort);
2383 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port %s is null. Port name is probably wrong.\n", nameStartPort.c_str());
2387 boxModel = findGBox(nameEndBox);
2388 if(boxModel == NULL)
2390 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2392 if (boxModel != NULL) {
2393 endP = boxModel->getInputPort(nameEndPort);
2395 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port %s is null. Port name is probably wrong\n", nameStartPort.c_str(), nameEndPort.c_str());
2400 int idCon = createGConnector(startP);
2402 _worldState = NOTHING_HAPPENS;
2403 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2405 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2406 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2407 tempp->endContourCreation();
2408 conMod->setEndPort(endP);
2409 conView->updateStartEndPoints();
2413 //=========================================================================
2415 bool wxVtkSceneManager::boxExist(std::string boxname) {
2417 std::map<int, GObjectController*>::iterator it;
2418 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2419 GObjectController *cont = it->second;
2420 if (cont->getModel()->getBBTKName() == boxname) {
2427 //=========================================================================
2429 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2430 std::vector<int> vect;
2431 std::map<int, GObjectController*>::iterator it;
2432 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2433 GObjectController *cont = it->second;
2434 if (cont->getGObjectType() == GBLACKBOX) {
2435 vect.push_back(cont->getId());
2441 //=========================================================================
2443 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2444 std::vector<int> vect;
2445 std::map<int, GObjectController*>::iterator it;
2446 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2447 GObjectController *cont = it->second;
2448 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2449 vect.push_back(cont->getId());
2455 //=========================================================================
2457 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2458 std::vector<int> vect;
2459 std::map<int, GObjectController*>::iterator it;
2460 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2461 GObjectController *cont = it->second;
2462 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2463 vect.push_back(cont->getId());
2469 //=========================================================================
2471 std::vector<int> wxVtkSceneManager::getConnections() {
2472 std::vector<int> vect;
2473 std::map<int, GObjectController*>::iterator it;
2474 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2475 GObjectController *cont = it->second;
2476 if (cont->getGObjectType() == GCONNECTOR) {
2477 vect.push_back(cont->getId());
2483 //=========================================================================
2485 bool wxVtkSceneManager::isComplexBox() {
2486 return _isComplexBox;
2489 //=========================================================================
2491 void wxVtkSceneManager::setComplexBox(bool val) {
2492 _isComplexBox = val;
2495 //=========================================================================
2497 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2498 //Register the controller of the new object
2499 registerController((InteractorStyleMaracas*) objController);
2500 //Add the object to the objects list
2501 int newId = _contLastId;//_controllers.size();
2502 objController->setId(newId);
2503 _controllers[newId] = objController;
2504 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2509 //=========================================================================
2511 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2513 std::map<int, int> oldIdNewIdBoxes;
2514 std::vector<int> connections;
2516 std::vector<int> newBoxesID;
2518 std::map<int, GObjectController*>::iterator it;
2519 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2520 GObjectController *cont = it->second;
2521 int type = cont->getGObjectType();
2523 if (type == GBLACKBOX) {
2525 double xInic, yInic, zInic;
2526 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2527 copyBox->getInicPoint(xInic, yInic, zInic);
2528 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2529 copyBox->getBBTKType());
2531 int idcB = copyBox->getObjectId();
2532 oldIdNewIdBoxes[idcB] = idBox;
2533 cont = _controllers[idBox];
2534 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2535 newbox->setInicPoint(xInic, yInic, zInic);
2536 int num = newbox->getNumInputPorts();
2537 for (int j = 0; j < num; j++) {
2538 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2540 newbox->move(xInic + 20, yInic + 20, zInic);
2541 newbox->notifyObservers(_idManager);
2542 newBoxesID.push_back(newbox->getObjectId());
2544 } else if (type == GCONNECTOR) {
2545 int idCon = cont->getId();
2546 connections.push_back(idCon);
2551 for (int i = 0; i < (int) connections.size(); i++) {
2552 int objId = connections[i];
2553 GObjectController *cont = objectsMap[objId];
2554 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2556 GPortModel* startPort = connectModel->getStartPort();
2557 int startPortIndex = startPort->getPosInBox();
2558 GPortModel* endPort = connectModel->getEndPort();
2559 int endPortIndex = endPort->getPosInBox();
2561 GBlackBoxModel* startPortParentBox =
2562 (GBlackBoxModel*) startPort->getParentBox();
2563 GBlackBoxModel* endPortParentBox =
2564 (GBlackBoxModel*) endPort->getParentBox();
2566 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2567 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2569 GBlackBoxModel* newStartBox =
2570 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2571 GBlackBoxModel* newEndBox =
2572 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2574 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2575 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2577 // Creates connection
2578 int idCon = createGConnector(newStartPort);
2579 GConnectorController *tempp =
2580 (GConnectorController*) _controllers[idCon];
2581 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2582 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2583 tempp->endContourCreation();
2584 conMod->setEndPort(newEndPort);
2585 conView->updateStartEndPoints();
2588 /// the new selected boxes are the duplicate ones
2590 UnSelectBlackBoxes();
2591 for (int i = 0; i < newBoxesID.size(); i++) {
2592 _selectedObjects.push_back(newBoxesID.at(i));
2595 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2596 int id = _selectedObjects[i];
2597 GObjectController* cont = _controllers[id];
2599 cont->getView()->setState(SELECTED);
2600 cont->getModel()->notifyObservers(_idManager);
2606 //=========================================================================
2608 int wxVtkSceneManager::getNumSelectedObjects() {
2609 return _selectedObjects.size();
2612 //=========================================================================
2614 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2615 std::map<int, GObjectController*> mapSelected;
2617 std::map<int, GObjectController*>::iterator it;
2618 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2619 GObjectController *cont = it->second;
2620 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2622 mapSelected[cont->getId()] = cont;
2626 std::map<int, GObjectController*>::iterator it2;
2627 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2628 GObjectController *cont = it2->second;
2629 if (cont->getGObjectType() == GCONNECTOR) {
2630 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2631 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2632 GBoxModel* startPortParentBox =
2633 cmod->getStartPort()->getParentBox();
2635 std::map<int, GObjectController*>::iterator iterOBJ1 =
2636 mapSelected.find(startPortParentBox->getObjectId());
2637 std::map<int, GObjectController*>::iterator iterOBJ2 =
2638 mapSelected.find(endPortParentBox->getObjectId());
2640 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2641 int ID = cont->getId();
2642 mapSelected[ID] = cont;
2649 //=========================================================================
2651 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2653 std::map<int, int> oldIdNewIdBoxes;
2654 std::vector<int> connections;
2656 std::map<int, GObjectController*>::iterator it;
2657 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2658 GObjectController *cont = it->second;
2659 int type = cont->getGObjectType();
2661 if (type == GBLACKBOX) {
2663 double xInic, yInic, zInic;
2664 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2665 copyBox->getInicPoint(xInic, yInic, zInic);
2666 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2668 int idcB = copyBox->getObjectId();
2669 oldIdNewIdBoxes[idcB] = idBox;
2670 cont = _controllers[idBox];
2671 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2672 newbox->setInicPoint(xInic, yInic, zInic);
2673 int num = newbox->getNumInputPorts();
2674 for (int j = 0; j < num; j++)
2676 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2678 newbox->notifyObservers(_idManager);
2679 } else if (type == GCONNECTOR) {
2680 int idCon = cont->getId();
2681 connections.push_back(idCon);
2686 for (int i = 0; i < (int) connections.size(); i++) {
2687 int objId = connections[i];
2688 GObjectController *cont = objectsMap[objId];
2689 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2691 GPortModel* startPort = connectModel->getStartPort();
2692 int startPortIndex = startPort->getPosInBox();
2693 GPortModel* endPort = connectModel->getEndPort();
2694 int endPortIndex = endPort->getPosInBox();
2696 GBlackBoxModel* startPortParentBox =
2697 (GBlackBoxModel*) startPort->getParentBox();
2698 GBlackBoxModel* endPortParentBox =
2699 (GBlackBoxModel*) endPort->getParentBox();
2701 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2702 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2704 GBlackBoxModel* newStartBox =
2705 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2706 GBlackBoxModel* newEndBox =
2707 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2709 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2710 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2712 // Creates connection
2713 int idCon = createGConnector(newStartPort);
2714 GConnectorController *tempp =
2715 (GConnectorController*) _controllers[idCon];
2716 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2717 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2718 tempp->endContourCreation();
2719 conMod->setEndPort(newEndPort);
2720 conView->updateStartEndPoints();
2723 std::map<int, int>::iterator itIds;
2724 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2725 int idOld = itIds->first;
2726 int idNew = itIds->second;
2728 GBlackBoxModel* oldBox =
2729 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2730 GBlackBoxModel* newBox =
2731 (GBlackBoxModel*) _controllers[idNew]->getModel();
2733 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2734 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2735 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2736 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2738 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2740 //EED int toCreate=-1;
2741 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2742 if (oldInputConnections[k] == newInputConnections[l]) {
2747 if (exist == false) {
2748 //Create complex input
2749 int posInBox = oldInputConnections[k];
2750 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2751 std::string inputPortName = inputPort->getBBTKName();
2752 int idInputPort = createGComplexBoxInputPort(inputPortName);
2753 GObjectController *cont = _controllers[idInputPort];
2754 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2755 double xIn, yIn, zIn;
2756 inputPort->getInicPoint(xIn, yIn, zIn);
2758 cbmod->setInicPoint(xIn, yIn, zIn);
2759 cbmod->notifyObservers(_idManager);
2761 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2763 // Creates connection
2764 int idCon = createGConnector(cbmod->getOutputPort(0));
2765 GConnectorController *tempp =
2766 (GConnectorController*) _controllers[idCon];
2767 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2768 vtkGConnectorView *conView =
2769 (vtkGConnectorView*) tempp->getView();
2770 tempp->endContourCreation();
2771 conMod->setEndPort(inputPortEnd);
2772 conView->updateStartEndPoints();
2778 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2780 //EED int toCreate=-1;
2781 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2782 if (oldOutputConnections[k] == newOutputConnections[l]) {
2787 if (exist == false) {
2788 //Create complex output
2789 int posInBox = oldOutputConnections[k];
2790 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2791 std::string outputPortName = outputPort->getBBTKName();
2792 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2793 GObjectController *cont = _controllers[idOutputPort];
2794 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2795 double xIn, yIn, zIn;
2796 outputPort->getInicPoint(xIn, yIn, zIn);
2798 cbmod->setInicPoint(xIn, yIn, zIn);
2799 cbmod->notifyObservers(_idManager);
2801 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2803 // Creates connection
2804 int idCon = createGConnector(outputPortEnd);
2805 GConnectorController *tempp =
2806 (GConnectorController*) _controllers[idCon];
2807 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2808 vtkGConnectorView *conView =
2809 (vtkGConnectorView*) tempp->getView();
2810 tempp->endContourCreation();
2811 conMod->setEndPort(cbmod->getInputPort(0));
2812 conView->updateStartEndPoints();
2822 //=========================================================================
2823 void wxVtkSceneManager::SetCbName(std::string cbName) {
2825 if (_cbName == "") {
2826 _cbName = "<complex box name>";
2830 //=========================================================================
2831 std::string wxVtkSceneManager::GetCbName() {
2835 //=========================================================================
2836 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2837 _cbPackageName = packagename;
2838 if (_cbPackageName == "") {
2839 _cbPackageName = "<package name of the complex box>";
2843 //=========================================================================
2844 std::string wxVtkSceneManager::GetCbPackageName() {
2845 return _cbPackageName;
2848 //=========================================================================
2849 void wxVtkSceneManager::SetAuthor(std::string author) {
2851 if (_Author == "") {
2852 _Author = "<author of the box>";
2856 //=========================================================================
2857 std::string wxVtkSceneManager::GetAuthor() {
2861 //=========================================================================
2862 void wxVtkSceneManager::SetCategory(std::string category) {
2863 _Category = category;
2864 if (_Category == "") {
2865 _Category = "<category of the box>";
2869 //=========================================================================
2870 std::string wxVtkSceneManager::GetCategory() {
2874 //=========================================================================
2875 void wxVtkSceneManager::SetDescription(std::string description) {
2876 _Description = description;
2877 if (_Description == "") {
2878 _Description = "<description of the box>";
2882 //=========================================================================
2883 std::string wxVtkSceneManager::GetDescription() {
2884 return _Description;
2887 //=========================================================================
2889 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
2892 std::vector< std::string> extInputs;
2893 std::map<int, GObjectController*>::iterator it;
2894 for (it = _controllers.begin(); it != _controllers.end(); ++it)
2896 GObjectController *cont = it->second;
2897 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
2899 extInputs.push_back(cont->getModel()->getBBTKName());
2905 //=========================================================================
2909 void wxVtkSceneManager::printAll(int com , int sta ){
2911 int tmpState = sta ;
2912 if ( tmpState == NOTHING_HAPPENS ) {
2913 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2915 if ( tmpState == HIGHLIGHTED ) {
2916 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2918 if ( tmpState == POSSIBLE_CONNECTION ) {
2919 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2921 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2922 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2924 if ( tmpState == CLICKED ) {
2925 std::cout << "CONTROLER STATE---->CLICKED\n" ;
2927 if ( tmpState == DRAG ) {
2928 std::cout << "CONTROLER STATE---->DRAG\n" ;
2930 if ( tmpState == SELECTED ) {
2931 std::cout << "CONTROLER STATE---->SELECTED\n" ;
2933 if ( tmpState == CREATING_CONTOUR ) {
2934 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2940 if ( command == INIT_CREATION_CONTOUR ) {
2941 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2943 if ( command == FIN_CREATION_CONTOUR ) {
2944 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2946 if ( command == ADD_TO_SELECTED ) {
2947 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2949 if ( command == DRAG_OBJECTS ) {
2950 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2952 if ( command == EDIT_BLACKBOX ) {
2953 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
2955 if ( command == REMOVE_FROM_SELECTED ) {
2956 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
2962 } // EO namespace bbtk