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 //=========================================================================
45 // EED 15 oct 2012 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
47 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
49 _cbName = "ComplexBoxName";
50 _cbPackageName = "PackageName";
51 _Author = "Author ??";
53 _Description = "Description ??";
57 _idManager = idManager;
59 _bbtkfactory = bbtkfactory;
61 _startDragging = false;
62 _isComplexBox = false;
64 if (_baseView != NULL) {
67 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
70 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
74 _worldState = NOTHING_HAPPENS;
75 registerController(this);
78 _idConnectionInCreation = -1;
83 //=========================================================================
85 void wxVtkSceneManager::disconnectDrop()
87 printf("EED %p ~wxVtkSceneManager::disconnectDrop()\n", this);
88 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
89 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
92 //=========================================================================
94 wxVtkSceneManager::~wxVtkSceneManager()
97 printf("EED %p ~wxVtkSceneManager() START\n", this);
100 printf("EED %p ~wxVtkSceneManager() END\n", this);
103 //=========================================================================
105 void wxVtkSceneManager::configureBaseView()
107 printf("EED wxVtkSceneManager::configureBaseView 0\n");
108 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
110 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
112 // Important to activate the 2D interaction system
113 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
114 interactorstylebaseview->SetInteractor(iren);
115 iren->SetInteractorStyle(interactorstylebaseview);
116 interactorstylebaseview->SetwxVtkBaseView(_baseView);
118 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
119 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, -1000, 1000);
120 _baseView->GetRenderer()->GetActiveCamera()->Zoom(10);
123 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
124 _baseView->GetRenderer()->GradientBackgroundOn();
127 _textActor = vtkTextActor3D::New();
128 _textActor->SetPosition(-9999, -9999, GPOSITION_Z);
129 _textActor->SetInput("<void>");
130 _textActor->GetTextProperty()->SetFontSize(60);
131 _textActor->GetTextProperty()->BoldOn();
132 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,PORTTEXT_NH_B);
134 _baseView->GetRenderer()->AddActor(_textActor);
136 // Actor Fill_Port_Text
141 double zInic = GPOSITION_Z;
143 vtkPolygon *aPolygon = vtkPolygon::New();
144 _fillObjectActor = vtkActor::New();
146 _pts = vtkPoints::New();
148 double w = 100, h = 10, b = h / 15, t = 3;
149 _pts->SetNumberOfPoints(21);
150 _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
151 _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
152 _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
153 _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
154 _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
156 _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
157 _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
158 _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
159 _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
161 _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
162 _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
163 _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
164 _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
166 _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
167 _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
168 _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
169 _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
171 _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
172 _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
173 _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
174 _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
176 aPolygon->GetPointIds()->SetNumberOfIds(21);
177 for (int i = 0; i < 21; i++) {
178 aPolygon->GetPointIds()->SetId(i, i);
181 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
182 aPolygonGrid->Allocate(1, 1);
183 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),
184 aPolygon->GetPointIds());
185 aPolygonGrid->SetPoints(_pts);
186 _aPolygonMapper = vtkDataSetMapper::New();
187 _aPolygonMapper->SetInput(aPolygonGrid);
188 _fillObjectActor->SetMapper(_aPolygonMapper);
189 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
191 _fillObjectActor->GetProperty()->SetOpacity(0);
192 _aPolygonMapper->Modified();
194 _baseView->GetRenderer()->AddActor(_fillObjectActor);
195 printf("EED wxVtkSceneManager::configureBaseView 1\n");
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)
1852 printf("EED wxVtkSceneManager::loadDiagram Start \n");
1854 std::string version = "<void>";
1855 std::string line = "";
1856 char delims[] = ":";
1857 char *result = NULL;
1858 int MAX_LINE_SIZE=1500;
1859 char poort[MAX_LINE_SIZE];
1861 getCleanLine(inputStream, line);
1864 while (!inputStream.eof()) {
1865 if (line == "" || line[0] == '#') {
1867 getCleanLine(inputStream, line);
1869 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1870 version = line.substr(18, 3);
1872 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1873 version = line.substr(18, 3);
1875 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1876 version = line.substr(18, 3);
1878 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1879 version = line.substr(18, 3);
1881 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1882 version = line.substr(18, 3);
1884 } else if (line == "APP_START") {
1893 if ((version != "1.0") && (version != "1.1")) {
1894 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1895 char categoryTmp[30];
1896 strcpy(categoryTmp, line.c_str());
1897 result = strtok(categoryTmp, delims);
1898 result = strtok(NULL, delims);
1899 SetCategory(result);
1901 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1902 char descriptionTmp[1024];
1903 strcpy(descriptionTmp, line.c_str());
1904 result = strtok(descriptionTmp, delims);
1905 result = strtok(NULL, delims);
1906 SetDescription(result);
1908 getCleanLine(inputStream, line);//AUTHOR:<author>
1909 char authorTmp[255];
1910 strcpy(authorTmp, line.c_str());
1911 result = strtok(authorTmp, delims);
1912 result = strtok(NULL, delims);
1917 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1918 char complexTmp[30];
1919 strcpy(complexTmp, line.c_str());
1920 result = strtok(complexTmp, delims);
1921 result = strtok(NULL, delims);
1922 std::string isComplexBox(result);
1924 if (isComplexBox == "TRUE") {
1925 _isComplexBox = true;
1927 if ((version != "1.0") && (version != "1.1")) {
1928 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
1929 char complexboxnameTmp[255];
1930 strcpy(complexboxnameTmp, line.c_str());
1931 result = strtok(complexboxnameTmp, delims);
1932 result = strtok(NULL, delims);
1935 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
1936 char packagenameTmp[255];
1937 strcpy(packagenameTmp, line.c_str());
1938 result = strtok(packagenameTmp, delims);
1939 result = strtok(NULL, delims);
1940 SetCbPackageName(result);
1945 //-----------------------
1946 //- COMPLEX INPUT PORTS
1947 //-----------------------
1948 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
1950 strcpy(inputs, line.c_str());
1951 result = strtok(inputs, delims);
1952 result = strtok(NULL, delims);
1955 std::istringstream inps(result);
1958 for (int i = 0; i < numInputs; i++) {
1960 getCleanLine(inputStream, line);//COMPLEX_PORT
1961 getCleanLine(inputStream, line);//name
1962 std::string inputPortName(line);
1965 getCleanLine(inputStream, line);//xInic:yInic:zInic
1967 strcpy(coord, line.c_str());
1968 result = strtok(coord, delims);//xInic
1969 std::string xInic(result);
1970 result = strtok(NULL, delims);//yInic
1971 std::string yInic(result);
1972 result = strtok(NULL, delims);//zInic
1973 std::string zInic(result);
1975 double xIn, yIn, zIn;
1976 std::istringstream xSt(xInic);
1978 std::istringstream ySt(yInic);
1980 std::istringstream zSt(zInic);
1985 if (zIn==900) zIn=GPOSITION_Z;
1988 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
1990 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
1992 } // for input complex box
1996 //-----------------------
1997 //- COMPLEX OUTPUT PORTS
1998 //-----------------------
2000 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2002 strcpy(outputs, line.c_str());
2003 result = strtok(outputs, delims);
2004 result = strtok(NULL, delims);
2007 std::istringstream outps(result);
2008 outps >> numOutputs;
2010 for (int i = 0; i < numOutputs; i++) {
2012 getCleanLine(inputStream, line);//COMPLEX_PORT
2013 getCleanLine(inputStream, line);//name
2014 std::string outputPortName(line);
2017 getCleanLine(inputStream, line);//xInic:yInic:zInic
2019 strcpy(coord, line.c_str());
2020 result = strtok(coord, delims);//xInic
2021 std::string xInic(result);
2022 result = strtok(NULL, delims);//yInic
2023 std::string yInic(result);
2024 result = strtok(NULL, delims);//zInic
2025 std::string zInic(result);
2027 double xIn, yIn, zIn;
2028 std::istringstream xSt(xInic);
2030 std::istringstream ySt(yInic);
2032 std::istringstream zSt(zInic);
2037 if (zIn==900) zIn=GPOSITION_Z;
2040 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2042 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2044 } // for output complex box
2048 // RaC2012 2nd Hackfest
2049 if(version >= "1.4")
2051 //-----------------------
2052 //- EXTERNAL INPUT PORTS
2053 //-----------------------
2054 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2056 strcpy(inputs, line.c_str());
2057 result = strtok(inputs, delims);
2058 result = strtok(NULL, delims);
2061 std::istringstream inps(result);
2064 for (int i = 0; i < numInputs; i++) {
2066 getCleanLine(inputStream, line);//COMPLEX_PORT
2067 getCleanLine(inputStream, line);//name
2068 std::string inputPortName(line);
2071 getCleanLine(inputStream, line);//xInic:yInic:zInic
2073 strcpy(coord, line.c_str());
2074 result = strtok(coord, delims);//xInic
2075 std::string xInic(result);
2076 result = strtok(NULL, delims);//yInic
2077 std::string yInic(result);
2078 result = strtok(NULL, delims);//zInic
2079 std::string zInic(result);
2081 double xIn, yIn, zIn;
2082 std::istringstream xSt(xInic);
2084 std::istringstream ySt(yInic);
2086 std::istringstream zSt(zInic);
2091 if (zIn==900) zIn=GPOSITION_Z;
2094 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2095 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2097 } // for external input
2102 getCleanLine(inputStream, line);//BOXES:num
2104 strcpy(boxes, line.c_str());
2105 result = strtok(boxes, delims);
2106 result = strtok(NULL, delims);
2109 std::istringstream is(result);
2112 for (int i = 0; i < numBoxes; i++) {
2114 getCleanLine(inputStream, line);//BOX
2115 getCleanLine(inputStream, line);//package:type:name
2117 strcpy(box, line.c_str());
2118 result = strtok(box, delims);//package
2119 std::string package(result);
2120 result = strtok(NULL, delims);//type
2121 std::string type(result);
2122 result = strtok(NULL, delims);//name
2123 std::string name(result);
2125 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2127 strcpy(exec, line.c_str());
2128 result = strtok(exec, delims);//ISEXEC
2129 result = strtok(NULL, delims);//TRUE|FALSE
2130 std::string isExec(result);
2133 getCleanLine(inputStream, line);//xInic:yInic:zInic
2135 strcpy(coord, line.c_str());
2136 result = strtok(coord, delims);//xInic
2137 std::string xInic(result);
2138 result = strtok(NULL, delims);//yInic
2139 std::string yInic(result);
2140 result = strtok(NULL, delims);//zInic
2141 std::string zInic(result);
2143 double xIn, yIn, zIn;
2144 std::istringstream xSt(xInic);
2146 std::istringstream ySt(yInic);
2148 std::istringstream zSt(zInic);
2154 if (zIn==900) zIn=GPOSITION_Z;
2159 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2160 strcpy(coord, line.c_str());
2161 result = strtok(coord, delims);//xEnd
2162 std::string xEnd(result);
2163 result = strtok(NULL, delims);//yEnd
2164 std::string yEnd(result);
2165 result = strtok(NULL, delims);//zEnd
2166 std::string zEnd(result);
2168 double xEn, yEn, zEn;
2169 std::istringstream xEt(xEnd);
2171 std::istringstream yEt(yEnd);
2173 std::istringstream zEt(zEnd);
2178 if (zEn==900) zEn=GPOSITION_Z;
2182 bool boxExecutable = false;
2183 if (isExec == "TRUE") {
2184 boxExecutable = true;
2187 int idBox = createGBlackBox(xIn, yIn, package, type);
2188 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2190 GObjectController *cont = _controllers[idBox];
2191 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2194 getCleanLine(inputStream, line);//PORT o FIN_BOX
2195 std::string port = line.substr(0, 4);
2196 while (port == "PORT")
2198 getCleanLine(inputStream, line);//name:value
2199 if (line.length()>=MAX_LINE_SIZE-1)
2201 line=line.substr(0, MAX_LINE_SIZE-1);
2204 strcpy(poort, line.c_str());
2205 result = strtok(poort, delims);//name
2206 std::string name(result);
2208 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2209 result = strtok(NULL, delims);//value
2210 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2212 std::string tmpString=" ";
2213 tmpString[0]=34; // character "
2214 strcat(result,tmpString.c_str());
2216 std::string value(result);
2218 bbmod->setValueToInput(name, value);
2220 getCleanLine(inputStream, line);//PORT o FIN_BOX
2221 port = line.substr(0, 4);
2224 //EED bbmod->notifyObservers(_idManager);
2229 getCleanLine(inputStream, line);//CONNECTIONS:num
2231 strcpy(conns, line.c_str());
2232 result = strtok(conns, delims);
2233 result = strtok(NULL, delims);
2236 std::istringstream isCons(result);
2240 for (int i = 0; i < numConns; i++) {
2242 getCleanLine(inputStream, line);//CONNECTION
2243 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2246 strcpy(connec, line.c_str());
2247 result = strtok(connec, delims);
2248 std::string nameStartBox(result);
2249 result = strtok(NULL, delims);
2250 std::string nameStartPort(result);
2251 result = strtok(NULL, delims);
2252 std::string nameEndBox(result);
2253 result = strtok(NULL, delims);
2254 std::string nameEndPort(result);
2256 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2258 if (version != "1.0") {
2259 //Readding control points of the manualContour
2260 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2261 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2262 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2263 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2264 strcpy(conns, line.c_str());
2265 result = strtok(conns, delims);
2266 result = strtok(NULL, delims);
2268 int numberOfControlPoints;
2269 std::istringstream isCons(result);
2270 isCons >> numberOfControlPoints;
2272 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2273 getCleanLine(inputStream, line); //XX:YY:ZZ
2275 strcpy(connec, line.c_str());
2278 result = strtok(connec, delims);
2279 std::istringstream isPointX(result);
2281 result = strtok(NULL, delims);
2282 std::istringstream isPointY(result);
2284 result = strtok(NULL, delims);
2285 std::istringstream isPointZ(result);
2290 if (pz==900) pz=GPOSITION_Z;
2293 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2294 conView->getManualContourView()->AddPoint();
2302 printf("EED wxVtkSceneManager::loadDiagram End \n");
2305 //=========================================================================
2308 //=========================================================================
2309 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2310 std::string portName, double xIn, double yIn, double zIn) {
2312 if (inputoutput == true) {
2313 idPort = createGComplexBoxInputPort(portName);
2315 idPort = createGComplexBoxOutputPort(portName);
2317 GObjectController *cont = _controllers[idPort];
2318 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2319 cbmod->setInicPoint(xIn, yIn, zIn);
2320 cbmod->notifyObservers(_idManager);
2322 //=========================================================================
2325 //=========================================================================
2326 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
2330 GBoxModel *boxModel = NULL;
2331 std::vector<int> lstB = getBlackBoxes();
2332 for (j = 0; j < (int) lstB.size(); j++) {
2334 bMod = (GBoxModel*) _controllers[idB]->getModel();
2335 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2342 if (boxModel == NULL) {
2343 std::vector<int> lstInputs = getComplexInputPorts();
2344 for (j = 0; j < (int) lstInputs.size(); j++) {
2346 bMod = (GBoxModel*) _controllers[idB]->getModel();
2347 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2354 std::vector<int> lstOutputs = getComplexOutputPorts();
2355 for (j = 0; j < (int) lstOutputs.size(); j++) {
2356 int idB = lstOutputs[j];
2357 bMod = (GBoxModel*) _controllers[idB]->getModel();
2358 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2369 //=========================================================================
2372 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2373 std::string nameStartPort, std::string nameEndBox,
2374 std::string nameEndPort) {
2376 GBoxModel *boxModel;
2377 GPortModel *startP = NULL;
2378 GPortModel *endP = NULL;
2380 boxModel = findGBox(nameStartBox);
2381 if(boxModel == NULL)
2383 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2385 if (boxModel != NULL) {
2386 startP = boxModel->getOutputPort(nameStartPort);
2388 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port %s is null. Port name is probably wrong.\n", nameStartPort.c_str());
2392 boxModel = findGBox(nameEndBox);
2393 if(boxModel == NULL)
2395 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2397 if (boxModel != NULL) {
2398 endP = boxModel->getInputPort(nameEndPort);
2400 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port %s is null. Port name is probably wrong\n", nameStartPort.c_str(), nameEndPort.c_str());
2405 int idCon = createGConnector(startP);
2407 _worldState = NOTHING_HAPPENS;
2408 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2410 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2411 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2412 tempp->endContourCreation();
2413 conMod->setEndPort(endP);
2414 conView->updateStartEndPoints();
2418 //=========================================================================
2420 bool wxVtkSceneManager::boxExist(std::string boxname) {
2422 std::map<int, GObjectController*>::iterator it;
2423 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2424 GObjectController *cont = it->second;
2425 if (cont->getModel()->getBBTKName() == boxname) {
2432 //=========================================================================
2434 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2435 std::vector<int> vect;
2436 std::map<int, GObjectController*>::iterator it;
2437 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2438 GObjectController *cont = it->second;
2439 if (cont->getGObjectType() == GBLACKBOX) {
2440 vect.push_back(cont->getId());
2446 //=========================================================================
2448 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2449 std::vector<int> vect;
2450 std::map<int, GObjectController*>::iterator it;
2451 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2452 GObjectController *cont = it->second;
2453 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2454 vect.push_back(cont->getId());
2460 //=========================================================================
2462 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2463 std::vector<int> vect;
2464 std::map<int, GObjectController*>::iterator it;
2465 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2466 GObjectController *cont = it->second;
2467 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2468 vect.push_back(cont->getId());
2474 //=========================================================================
2476 std::vector<int> wxVtkSceneManager::getConnections() {
2477 std::vector<int> vect;
2478 std::map<int, GObjectController*>::iterator it;
2479 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2480 GObjectController *cont = it->second;
2481 if (cont->getGObjectType() == GCONNECTOR) {
2482 vect.push_back(cont->getId());
2488 //=========================================================================
2490 bool wxVtkSceneManager::isComplexBox() {
2491 return _isComplexBox;
2494 //=========================================================================
2496 void wxVtkSceneManager::setComplexBox(bool val) {
2497 _isComplexBox = val;
2500 //=========================================================================
2502 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2503 //Register the controller of the new object
2504 registerController((InteractorStyleMaracas*) objController);
2505 //Add the object to the objects list
2506 int newId = _contLastId;//_controllers.size();
2507 objController->setId(newId);
2508 _controllers[newId] = objController;
2509 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2514 //=========================================================================
2516 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2518 std::map<int, int> oldIdNewIdBoxes;
2519 std::vector<int> connections;
2521 std::vector<int> newBoxesID;
2523 std::map<int, GObjectController*>::iterator it;
2524 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2525 GObjectController *cont = it->second;
2526 int type = cont->getGObjectType();
2528 if (type == GBLACKBOX) {
2530 double xInic, yInic, zInic;
2531 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2532 copyBox->getInicPoint(xInic, yInic, zInic);
2533 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2534 copyBox->getBBTKType());
2536 int idcB = copyBox->getObjectId();
2537 oldIdNewIdBoxes[idcB] = idBox;
2538 cont = _controllers[idBox];
2539 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2540 newbox->setInicPoint(xInic, yInic, zInic);
2541 int num = newbox->getNumInputPorts();
2542 for (int j = 0; j < num; j++) {
2543 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2545 newbox->move(xInic + 20, yInic + 20, zInic);
2546 newbox->notifyObservers(_idManager);
2547 newBoxesID.push_back(newbox->getObjectId());
2549 } else if (type == GCONNECTOR) {
2550 int idCon = cont->getId();
2551 connections.push_back(idCon);
2556 for (int i = 0; i < (int) connections.size(); i++) {
2557 int objId = connections[i];
2558 GObjectController *cont = objectsMap[objId];
2559 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2561 GPortModel* startPort = connectModel->getStartPort();
2562 int startPortIndex = startPort->getPosInBox();
2563 GPortModel* endPort = connectModel->getEndPort();
2564 int endPortIndex = endPort->getPosInBox();
2566 GBlackBoxModel* startPortParentBox =
2567 (GBlackBoxModel*) startPort->getParentBox();
2568 GBlackBoxModel* endPortParentBox =
2569 (GBlackBoxModel*) endPort->getParentBox();
2571 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2572 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2574 GBlackBoxModel* newStartBox =
2575 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2576 GBlackBoxModel* newEndBox =
2577 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2579 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2580 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2582 // Creates connection
2583 int idCon = createGConnector(newStartPort);
2584 GConnectorController *tempp =
2585 (GConnectorController*) _controllers[idCon];
2586 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2587 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2588 tempp->endContourCreation();
2589 conMod->setEndPort(newEndPort);
2590 conView->updateStartEndPoints();
2593 /// the new selected boxes are the duplicate ones
2595 UnSelectBlackBoxes();
2596 for (int i = 0; i < newBoxesID.size(); i++) {
2597 _selectedObjects.push_back(newBoxesID.at(i));
2600 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2601 int id = _selectedObjects[i];
2602 GObjectController* cont = _controllers[id];
2604 cont->getView()->setState(SELECTED);
2605 cont->getModel()->notifyObservers(_idManager);
2611 //=========================================================================
2613 int wxVtkSceneManager::getNumSelectedObjects() {
2614 return _selectedObjects.size();
2617 //=========================================================================
2619 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2620 std::map<int, GObjectController*> mapSelected;
2622 std::map<int, GObjectController*>::iterator it;
2623 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2624 GObjectController *cont = it->second;
2625 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2627 mapSelected[cont->getId()] = cont;
2631 std::map<int, GObjectController*>::iterator it2;
2632 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2633 GObjectController *cont = it2->second;
2634 if (cont->getGObjectType() == GCONNECTOR) {
2635 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2636 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2637 GBoxModel* startPortParentBox =
2638 cmod->getStartPort()->getParentBox();
2640 std::map<int, GObjectController*>::iterator iterOBJ1 =
2641 mapSelected.find(startPortParentBox->getObjectId());
2642 std::map<int, GObjectController*>::iterator iterOBJ2 =
2643 mapSelected.find(endPortParentBox->getObjectId());
2645 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2646 int ID = cont->getId();
2647 mapSelected[ID] = cont;
2654 //=========================================================================
2656 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2658 std::map<int, int> oldIdNewIdBoxes;
2659 std::vector<int> connections;
2661 std::map<int, GObjectController*>::iterator it;
2662 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2663 GObjectController *cont = it->second;
2664 int type = cont->getGObjectType();
2666 if (type == GBLACKBOX) {
2668 double xInic, yInic, zInic;
2669 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2670 copyBox->getInicPoint(xInic, yInic, zInic);
2671 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2673 int idcB = copyBox->getObjectId();
2674 oldIdNewIdBoxes[idcB] = idBox;
2675 cont = _controllers[idBox];
2676 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2677 newbox->setInicPoint(xInic, yInic, zInic);
2678 int num = newbox->getNumInputPorts();
2679 for (int j = 0; j < num; j++)
2681 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2683 newbox->notifyObservers(_idManager);
2684 } else if (type == GCONNECTOR) {
2685 int idCon = cont->getId();
2686 connections.push_back(idCon);
2691 for (int i = 0; i < (int) connections.size(); i++) {
2692 int objId = connections[i];
2693 GObjectController *cont = objectsMap[objId];
2694 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2696 GPortModel* startPort = connectModel->getStartPort();
2697 int startPortIndex = startPort->getPosInBox();
2698 GPortModel* endPort = connectModel->getEndPort();
2699 int endPortIndex = endPort->getPosInBox();
2701 GBlackBoxModel* startPortParentBox =
2702 (GBlackBoxModel*) startPort->getParentBox();
2703 GBlackBoxModel* endPortParentBox =
2704 (GBlackBoxModel*) endPort->getParentBox();
2706 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2707 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2709 GBlackBoxModel* newStartBox =
2710 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2711 GBlackBoxModel* newEndBox =
2712 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2714 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2715 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2717 // Creates connection
2718 int idCon = createGConnector(newStartPort);
2719 GConnectorController *tempp =
2720 (GConnectorController*) _controllers[idCon];
2721 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2722 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2723 tempp->endContourCreation();
2724 conMod->setEndPort(newEndPort);
2725 conView->updateStartEndPoints();
2728 std::map<int, int>::iterator itIds;
2729 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2730 int idOld = itIds->first;
2731 int idNew = itIds->second;
2733 GBlackBoxModel* oldBox =
2734 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2735 GBlackBoxModel* newBox =
2736 (GBlackBoxModel*) _controllers[idNew]->getModel();
2738 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2739 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2740 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2741 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2743 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2745 //EED int toCreate=-1;
2746 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2747 if (oldInputConnections[k] == newInputConnections[l]) {
2752 if (exist == false) {
2753 //Create complex input
2754 int posInBox = oldInputConnections[k];
2755 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2756 std::string inputPortName = inputPort->getBBTKName();
2757 int idInputPort = createGComplexBoxInputPort(inputPortName);
2758 GObjectController *cont = _controllers[idInputPort];
2759 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2760 double xIn, yIn, zIn;
2761 inputPort->getInicPoint(xIn, yIn, zIn);
2763 cbmod->setInicPoint(xIn, yIn, zIn);
2764 cbmod->notifyObservers(_idManager);
2766 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2768 // Creates connection
2769 int idCon = createGConnector(cbmod->getOutputPort(0));
2770 GConnectorController *tempp =
2771 (GConnectorController*) _controllers[idCon];
2772 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2773 vtkGConnectorView *conView =
2774 (vtkGConnectorView*) tempp->getView();
2775 tempp->endContourCreation();
2776 conMod->setEndPort(inputPortEnd);
2777 conView->updateStartEndPoints();
2783 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2785 //EED int toCreate=-1;
2786 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2787 if (oldOutputConnections[k] == newOutputConnections[l]) {
2792 if (exist == false) {
2793 //Create complex output
2794 int posInBox = oldOutputConnections[k];
2795 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2796 std::string outputPortName = outputPort->getBBTKName();
2797 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2798 GObjectController *cont = _controllers[idOutputPort];
2799 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2800 double xIn, yIn, zIn;
2801 outputPort->getInicPoint(xIn, yIn, zIn);
2803 cbmod->setInicPoint(xIn, yIn, zIn);
2804 cbmod->notifyObservers(_idManager);
2806 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2808 // Creates connection
2809 int idCon = createGConnector(outputPortEnd);
2810 GConnectorController *tempp =
2811 (GConnectorController*) _controllers[idCon];
2812 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2813 vtkGConnectorView *conView =
2814 (vtkGConnectorView*) tempp->getView();
2815 tempp->endContourCreation();
2816 conMod->setEndPort(cbmod->getInputPort(0));
2817 conView->updateStartEndPoints();
2827 //=========================================================================
2828 void wxVtkSceneManager::SetCbName(std::string cbName) {
2830 if (_cbName == "") {
2831 _cbName = "<complex box name>";
2835 //=========================================================================
2836 std::string wxVtkSceneManager::GetCbName() {
2840 //=========================================================================
2841 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2842 _cbPackageName = packagename;
2843 if (_cbPackageName == "") {
2844 _cbPackageName = "<package name of the complex box>";
2848 //=========================================================================
2849 std::string wxVtkSceneManager::GetCbPackageName() {
2850 return _cbPackageName;
2853 //=========================================================================
2854 void wxVtkSceneManager::SetAuthor(std::string author) {
2856 if (_Author == "") {
2857 _Author = "<author of the box>";
2861 //=========================================================================
2862 std::string wxVtkSceneManager::GetAuthor() {
2866 //=========================================================================
2867 void wxVtkSceneManager::SetCategory(std::string category) {
2868 _Category = category;
2869 if (_Category == "") {
2870 _Category = "<category of the box>";
2874 //=========================================================================
2875 std::string wxVtkSceneManager::GetCategory() {
2879 //=========================================================================
2880 void wxVtkSceneManager::SetDescription(std::string description) {
2881 _Description = description;
2882 if (_Description == "") {
2883 _Description = "<description of the box>";
2887 //=========================================================================
2888 std::string wxVtkSceneManager::GetDescription() {
2889 return _Description;
2892 //=========================================================================
2894 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
2897 std::vector< std::string> extInputs;
2898 std::map<int, GObjectController*>::iterator it;
2899 for (it = _controllers.begin(); it != _controllers.end(); ++it)
2901 GObjectController *cont = it->second;
2902 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
2904 extInputs.push_back(cont->getModel()->getBBTKName());
2910 //=========================================================================
2914 void wxVtkSceneManager::printAll(int com , int sta ){
2916 int tmpState = sta ;
2917 if ( tmpState == NOTHING_HAPPENS ) {
2918 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2920 if ( tmpState == HIGHLIGHTED ) {
2921 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2923 if ( tmpState == POSSIBLE_CONNECTION ) {
2924 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2926 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2927 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2929 if ( tmpState == CLICKED ) {
2930 std::cout << "CONTROLER STATE---->CLICKED\n" ;
2932 if ( tmpState == DRAG ) {
2933 std::cout << "CONTROLER STATE---->DRAG\n" ;
2935 if ( tmpState == SELECTED ) {
2936 std::cout << "CONTROLER STATE---->SELECTED\n" ;
2938 if ( tmpState == CREATING_CONTOUR ) {
2939 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2945 if ( command == INIT_CREATION_CONTOUR ) {
2946 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2948 if ( command == FIN_CREATION_CONTOUR ) {
2949 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2951 if ( command == ADD_TO_SELECTED ) {
2952 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2954 if ( command == DRAG_OBJECTS ) {
2955 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2957 if ( command == EDIT_BLACKBOX ) {
2958 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
2960 if ( command == REMOVE_FROM_SELECTED ) {
2961 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
2967 } // EO namespace bbtk