2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
8 # This software is governed by the CeCILL-B license under French law and
9 # abiding by the rules of distribution of free software. You can use,
10 # modify and/ or redistribute the software under the terms of the CeCILL-B
11 # license as circulated by CEA, CNRS and INRIA at the following URL
12 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
13 # or in the file LICENSE.txt.
15 # As a counterpart to the access to the source code and rights to copy,
16 # modify and redistribute granted by the license, users are provided only
17 # with a limited warranty and the software's author, the holder of the
18 # economic rights, and the successive licensors have only limited
21 # The fact that you are presently reading this means that you have had
22 # knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------
26 /*=========================================================================
32 =========================================================================*/
34 /* ---------------------------------------------------------------------
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
39 * This software is governed by the CeCILL-B license under French law and
40 * abiding by the rules of distribution of free software. You can use,
41 * modify and/ or redistribute the software under the terms of the CeCILL-B
42 * license as circulated by CEA, CNRS and INRIA at the following URL
43 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
44 * or in the file LICENSE.txt.
46 * As a counterpart to the access to the source code and rights to copy,
47 * modify and redistribute granted by the license, users are provided only
48 * with a limited warranty and the software's author, the holder of the
49 * economic rights, and the successive licensors have only limited
52 * The fact that you are presently reading this means that you have had
53 * knowledge of the CeCILL-B license and that you accept its terms.
54 * ------------------------------------------------------------------------ */
58 * \brief Class bbtk::wxVtkSceneManager .
61 #include "wxVtkSceneManager.h"
63 #include <vtkPolygon.h>
64 #include <vtkUnstructuredGrid.h>
68 #define POORT_MAX_LINE_SIZE_INTERPRETER 1500
70 //=========================================================================
72 // EED 15 oct 2012 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
74 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
76 _cbName = "ComplexBoxName";
77 _cbPackageName = "PackageName";
78 _Author = "Author ??";
80 _Description = "Description ??";
84 _bugTextActor_text = "void";
85 _bugTextActor_status = 0;
89 _idManager = idManager;
91 _bbtkfactory = bbtkfactory;
93 _startDragging = false;
94 _isComplexBox = false;
96 if (_baseView != NULL) {
99 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
102 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
106 _worldState = NOTHING_HAPPENS;
107 registerController(this);
110 _idConnectionInCreation = -1;
115 //=========================================================================
117 void wxVtkSceneManager::disconnectDrop()
119 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
120 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
123 //=========================================================================
125 wxVtkSceneManager::~wxVtkSceneManager()
132 //=========================================================================
134 void wxVtkSceneManager::configureBaseView()
136 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
138 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
140 // Important to activate the 2D interaction system
141 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
142 interactorstylebaseview->SetInteractor(iren);
143 iren->SetInteractorStyle(interactorstylebaseview);
144 interactorstylebaseview->SetwxVtkBaseView(_baseView);
146 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
147 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, -1000, 1000);
148 _baseView->GetRenderer()->GetActiveCamera()->Zoom(10);
151 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
152 _baseView->GetRenderer()->GradientBackgroundOn();
155 _textActor = vtkTextActor3D::New();
156 // _textActor = vtkTextActor::New();
157 _textActor->SetPosition(-9999, -9999, GPOSITION_Z);
158 _textActor->SetInput("<void>");
159 _textActor->GetTextProperty()->SetFontSize(60);
160 _textActor->GetTextProperty()->BoldOn();
161 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,PORTTEXT_NH_B);
163 _baseView->GetRenderer()->AddActor(_textActor);
165 // Actor Fill_Port_Text
170 double zInic = GPOSITION_Z;
172 vtkPolygon *aPolygon = vtkPolygon::New();
173 _fillObjectActor = vtkActor::New();
175 _pts = vtkPoints::New();
177 double w = 100, h = 10, b = h / 15, t = 3;
178 _pts->SetNumberOfPoints(21);
179 _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
180 _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
181 _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
182 _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
183 _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
185 _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
186 _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
187 _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
188 _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
190 _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
191 _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
192 _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
193 _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
195 _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
196 _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
197 _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
198 _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
200 _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
201 _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
202 _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
203 _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
205 aPolygon->GetPointIds()->SetNumberOfIds(21);
206 for (int i = 0; i < 21; i++) {
207 aPolygon->GetPointIds()->SetId(i, i);
210 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
211 aPolygonGrid->Allocate(1, 1);
212 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),
213 aPolygon->GetPointIds());
214 aPolygonGrid->SetPoints(_pts);
215 _aPolygonMapper = vtkDataSetMapper::New();
216 _aPolygonMapper->SetInput(aPolygonGrid);
217 _fillObjectActor->SetMapper(_aPolygonMapper);
218 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
220 _fillObjectActor->GetProperty()->SetOpacity(0);
221 _aPolygonMapper->Modified();
223 _baseView->GetRenderer()->AddActor(_fillObjectActor);
226 //=========================================================================
228 std::string wxVtkSceneManager::generateANewNameForABox() {
229 std::stringstream boxname;
230 if (_numBoxes < 10) {
231 boxname << "Box0" << _numBoxes;
233 boxname << "Box" << _numBoxes;
236 return boxname.str();
239 //=========================================================================
241 std::string wxVtkSceneManager::findANewNameForABox() {
242 std::string boxname = generateANewNameForABox();
244 while (boxExist(boxname) == true) {
245 boxname = generateANewNameForABox();
251 //=========================================================================
252 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
253 double zIn, std::string name, bool boxExecutable, double xEn,
254 double yEn, double zEn) {
255 GObjectController *cont = _controllers[idBox];
256 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
257 bbmod->setBBTKName(name);
258 bbmod->setInicPoint(xIn, yIn, zIn);
259 bbmod->setFinalPoint(xEn, yEn, zEn);
260 bbmod->setExecutable(boxExecutable);
262 bbmod->notifyObservers(_idManager);
266 //=========================================================================
268 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,std::string boxType)
270 _worldState = NOTHING_HAPPENS;
271 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
272 int type = GBLACKBOX;
273 //Create the MVC Objects
274 GBlackBoxModel *model = (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
275 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
276 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
278 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
282 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
284 k = _bbtkfactory->GetPackage(packageName);
285 mapDesc = k->GetDescriptorMap();
287 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for package %s, NOT EXIST\n", packageName.c_str());
290 BlackBoxDescriptor::Pointer descriptor;
292 descriptor = mapDesc[boxType];
294 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for box %s of package %s, NOT EXIST\n", boxType.c_str(),packageName.c_str());
297 if (descriptor == NULL)
299 printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
302 //Prepares the initial model
303 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
306 double yy = windowHeight - y;
308 //z value is not important yet, because it is only used a parallel projection
309 double zz = GPOSITION_Z;
310 _baseView->TransCoordScreenToWorld(xx, yy, zz);
311 model->setInicPoint(xx, yy, zz);
313 std::stringstream stream;
315 std::string newBoxName;
316 newBoxName = findANewNameForABox();
318 stream << newBoxName;
320 std::string arraystring = stream.str();
322 model->setBBTKName(arraystring);
323 model->setBBTKType(boxType);
324 model->setBBTKPackage(packageName);
326 model->addObserver(view);
327 model->addObserver(this);
330 //EED2017 change order
331 //Associates the view with the correspondent renderer and the model.
332 //(NOTE: Refresh is only made by the view)
333 view->setModel(model);
334 view->setBaseView(_baseView);
336 //Associates the controller with the correspondent model and view
337 controller->setModelAndView(model, view);
340 //Iterate and create the input ports
341 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
342 descriptor->GetInputDescriptorMap();
343 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
345 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
347 BlackBoxInputDescriptor *desc = itInput->second;
349 // createGInputPort(GINPUTPORT, i, model, desc);
350 createGInputPort(GINPUTPORT, i, controller, desc);
354 //Iterate and create the output ports
355 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
356 descriptor->GetOutputDescriptorMap();
357 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
359 for (itOutput = descriptorOutMap.begin(); itOutput!= descriptorOutMap.end(); ++itOutput)
361 BlackBoxOutputDescriptor *desc = itOutput->second;
363 // createGOutputPort(GOUTPUTPORT, i, model, desc);
364 createGOutputPort(GOUTPUTPORT, i, controller, desc);
368 //EED2017 change order
369 view->initVtkObjects();
371 //Resgiter change to the observers of the actual model
372 model->notifyObservers(_idManager);
373 int newId = addObjectController(controller);
379 //=========================================================================
381 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
382 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
383 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
385 int type = GCOMPLEXINPUTPORT;
387 //Create the MVC Objects
389 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
390 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
391 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
393 //Prepares the initial model
396 double yy = windowHeight - 5;
398 //z value is not important yet, because it is only used a parallel projection
399 double zz = GPOSITION_Z;
401 _baseView->TransCoordScreenToWorld(xx, yy, zz);
402 model->setInicPoint(xx, yy, zz);
404 model->setBBTKName(inputName);
405 model->setBBTKType("ComplexInputPort");
406 model->setComplexPortType(type);
408 model->addObserver(view);
409 model->addObserver(this);
411 //create the output port
412 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
413 "ComplexOutputPortType","ComplexOutputPortDescriopton", 0, model);
414 model->addOutputPort((GPortModel*) portController->getModel());
416 //Associates the view with the correspondent renderer and the model.
417 //(NOTE: Refresh is only made by the view)
418 view->setModel(model);
419 view->setBaseView(_baseView);
420 view->initVtkObjects();
422 //Associates the controller with the correspondent model and view
423 controller->setModelAndView(model, view);
425 //Resgiter change to the observers of the actual model
426 model->notifyObservers(_idManager);
428 int newId = addObjectController(controller);
432 //=========================================================================
434 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
435 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
436 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
438 int type = GCOMPLEXOUTPUTPORT;
440 //Create the MVC Objects
442 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
443 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
444 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
446 //Prepares the initial model
449 double yy = windowHeight - 5;
451 //z value is not important yet, because it is only used a parallel projection
452 double zz = GPOSITION_Z;
454 _baseView->TransCoordScreenToWorld(xx, yy, zz);
455 model->setInicPoint(xx, yy, zz);
457 model->setBBTKName(outputName);
458 model->setBBTKType("ComplexOutputPort");
459 model->setComplexPortType(type);
461 model->addObserver(view);
462 model->addObserver(this);
464 //create the output port
465 GPortController* portController = createGPort(GINPUTPORT, outputName,
466 "ComplexInputPort","ComplexInputPortDescription", 0, model);
467 model->addInputPort((GPortModel*) portController->getModel());
469 //Associates the view with the correspondent renderer and the model.
470 //(NOTE: Refresh is only made by the view)
471 view->setModel(model);
472 view->setBaseView(_baseView);
473 view->initVtkObjects();
475 //Associates the controller with the correspondent model and view
476 controller->setModelAndView(model, view);
478 //Resgiter change to the observers of the actual model
479 model->notifyObservers(_idManager);
481 int newId = addObjectController(controller);
485 //=========================================================================
488 //int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
489 int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GObjectController *gBoxControler, BlackBoxInputDescriptor *desc)
491 GBoxModel *blackBox=(GBoxModel*)gBoxControler->getModel();
492 GPortController* portController = createGPort(portType, desc->GetName(),
493 desc->GetTypeName(), desc->GetDescription(), posinBox, blackBox);
494 blackBox->addInputPort( (GPortModel*)portController->getModel() );
496 vtkGBoxView *vtkgboxView=(vtkGBoxView*)gBoxControler->getView();
497 vtkgboxView->addInputPort( (vtkGPortView*)portController->getView() );
499 return portController->getId();
502 //=========================================================================
505 //int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
506 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GObjectController *gBoxControler, BlackBoxOutputDescriptor *desc)
508 GBoxModel *blackBox=(GBoxModel*)gBoxControler->getModel();
509 GPortController* portController = createGPort(portType, desc->GetName(),
510 desc->GetTypeName(),desc->GetDescription(), posinBox, blackBox);
511 blackBox->addOutputPort((GPortModel*) portController->getModel());
513 vtkGBoxView *vtkgboxView=(vtkGBoxView*)gBoxControler->getView();
514 vtkgboxView->addOutputPort( (vtkGPortView*)portController->getView() );
516 return portController->getId();
519 //=========================================================================
521 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posInBox,GBoxModel *blackBox)
525 //Create the MVC Objects
526 GPortModel *model = (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
527 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
528 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
529 model->registerInBox(blackBox, portType, posInBox);
530 model->setBBTKType(bbtkType);
531 model->setBBTKName(bbtkName);
532 model->setBBTKDescription(bbtkDescription);
533 model->addObserver(view);
534 model->addObserver(this);
535 //Associates the view with the correspondent renderer and the model.
536 //(NOTE: Refresh is only made by the view)
537 view->setModel(model);
538 view->setBaseView(_baseView);
539 //EED017 view->initVtkObjects();
540 view->createVtkObjects();
541 // view->addVtkActors();
543 //Associates the controller with the correspondent model and view
544 controller->setModelAndView(model, view);
545 model->notifyObservers(_idManager);
546 addObjectController(controller);
547 return (GPortController*) controller;
550 //=========================================================================
552 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
554 int type = GCONNECTOR;
556 manualConnectorContourController *manContourControl = new manualConnectorContourController();
557 manualConnectorContourView *manContourView = new manualConnectorContourView();
558 manualContourModel *manContourModel = new manualContourModel();
559 GConnectorController *connectorcontroller = new GConnectorController();
560 GConnectorModel *connectorModel = new GConnectorModel();
561 vtkGConnectorView *connectorView = new vtkGConnectorView();
562 connectorModel->setGObjectType(type);
564 manContourModel->SetCloseContour(false);
565 connectorModel->setStartPort(startPort);
567 manContourView->SetModel(manContourModel);
568 manContourView->SetWxVtkBaseView(_baseView);
569 manContourView->SetRange(0.5);
570 manContourView->SetZ(GPOSITION_Z);
572 manContourView->SetColorNormalContour(0, 0, 1);
573 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
574 manContourView->SetColorSelectContour(1, 0.8, 0);
580 * Width increased from 2 to 3, it simplifies line handling and spline control :P
584 manContourView->SetWidthLine( 3 ) ;
585 manContourView->SetShowText(false);
587 manContourControl->SetModelView(manContourModel, manContourView);
589 manContourControl->CreateNewManualContour();
593 connectorModel->getInicPoint(x, y, z);
596 manContourControl->SetState(1);
597 manContourModel->SetCloseContour(false);
599 manContourModel->AddPoint(x, y, z);
600 manContourView->AddPoint();
602 manContourModel->AddPoint(x, y, z);
603 manContourView->AddPoint();
605 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
606 manContourControl->_bakIdPoint = bak;
608 manContourControl->SetMoving(false);
610 connectorcontroller->setModelAndView(connectorModel, connectorView);
612 int newId = addObjectController(connectorcontroller);
614 connectorcontroller->setManualContourController(manContourControl);
615 connectorModel->setManualContourModel(manContourModel);
616 connectorView->setManualContourView(manContourView);
617 connectorView->setModel(connectorModel);
618 connectorView->setBaseView(_baseView);
620 connectorModel->addObserver(connectorView);
621 connectorModel->addObserver(this);
623 // manContourView->Refresh();
628 //=========================================================================
630 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
632 vtkInteractorStyleBaseView * baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
633 baseViewControlManager->AddInteractorStyleMaracas(param);
636 //=========================================================================
638 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
640 vtkInteractorStyleBaseView *baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
641 baseViewControlManager->RemoveInteractorStyleMaracas(param);
644 //=========================================================================
646 vtkRenderer* wxVtkSceneManager::getRenderer()
648 return _baseView->GetRenderer();
651 //=========================================================================
653 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
655 return _baseView->GetRenWin();
657 //=========================================================================
660 //=========================================================================
661 int wxVtkSceneManager::GetIndexInSelected(int idControler)
664 for (int i = 0; i < (int) _selectedObjects.size(); i++)
666 if (_selectedObjects[i] == idControler)
674 //=========================================================================
676 void wxVtkSceneManager::update(int idController, int command) {
678 if (command != NO_COMMAND)
680 if (command == ADD_TO_SELECTED)
682 if (GetIndexInSelected(idController) == -1)
684 _selectedObjects.push_back(idController);
686 } else if (command == REMOVE_FROM_SELECTED) {
687 int index = GetIndexInSelected(idController);
690 _selectedObjects.erase(_selectedObjects.begin() + index);
692 } else if (command == INIT_CREATION_CONTOUR) {
694 typedef std::map<int , GObjectController*>::iterator TIterator ;
697 // Find current item in the controller
698 iter = _controllers.find( idController ) ;
699 iter_end = _controllers.end( ) ;
701 if ( iter != iter_end ) {
702 GObjectController* gobjc = iter->second ;
704 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
705 // And if the item is a port
706 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
707 TIterator c_it = _controllers.begin( ) ;
708 // Go through all componets
709 for ( c_it ; c_it != iter_end ; c_it++ ) {
710 GObjectController* obc = c_it->second ;
711 int obc_type = obc->getModel( )->getGObjectType( ) ;
712 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
713 // if the component is a port and the type is the same of that selected
714 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
716 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
717 //obc->getView( )->setState( HIGHLIGHTED ) ;
725 _worldState = INIT_CREATION_CONTOUR;
726 GObjectController* cont = _controllers[idController];
727 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
729 // The last one is the controller of the connector
730 std::map<int, GObjectController*>::iterator it2;
732 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
734 GObjectController *cont = it2->second;
735 if (cont->getGObjectType() == GPORT)
737 GPortModel* port = (GPortModel*) cont->getModel();
738 if (port->getPortType() == GINPUTPORT)
740 cont->SetActive(true);
742 cont->getView()->setState(NOTHING_HAPPENS);
743 cont->getModel()->notifyObservers(_idManager);
744 cont->SetActive(false);
747 cont->getView()->setState(NOTHING_HAPPENS);
748 cont->getModel()->notifyObservers(_idManager);
749 cont->SetActive(false);
752 _selectedObjects.clear();
753 _idConnectionInCreation = createGConnector(startOutputPort);
754 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
755 _worldState = NOTHING_HAPPENS;
756 //int id = _controllers.size()-1;
757 GObjectController *cont = _controllers[_idConnectionInCreation];
758 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
759 GObjectController *finPort = _controllers[idController];
761 if (finPort->getGObjectType() == GPORT)
763 GPortModel* modelPort = (GPortModel*) finPort->getModel();
764 modelContour->setEndPort(modelPort);
767 typedef std::map<int, GObjectController*>::iterator TIterator;
768 TIterator c_it = _controllers.begin();
769 TIterator iter_end = _controllers.end();
770 // Go through all componets
771 for (c_it; c_it != iter_end; c_it++) {
772 GObjectController* obc = c_it->second;
773 int obc_type = obc->getModel()->getGObjectType();
774 int obc_state = obc->getView()->getState();
775 // if the component is a port and the type is the same of that selected
776 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
777 // Return element to neutral state if not selected
778 obc->getView()->setState(NOTHING_HAPPENS);
780 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
781 // Change element to connected state
782 obc->getView()->setState(HIGHLIGHTED);
788 _parent->saveTempandUpdate("create connection");
791 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
792 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
794 std::map<int, GObjectController*>::iterator it2;
796 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
798 GObjectController *cont = it2->second;
799 if (cont->getView() != NULL) {
800 cont->getView()->setState(NOTHING_HAPPENS);
801 cont->getModel()->notifyObservers(_idManager);
803 cont->SetActive(true);
812 //=========================================================================
814 bool wxVtkSceneManager::OnMouseMove()
817 bool okStatusMessage = false;
818 bool okPortMessage = false;
819 wxVTKRenderWindowInteractor *wxVTKiren;
820 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
821 wxVTKiren->GetEventPosition(X, Y);
823 if (_worldState == DRAG_OBJECTS) {
824 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
825 int id = _selectedObjects[i];
826 GObjectController* cont = _controllers[id];
827 if (_startDragging) {
828 cont->getView()->setStartDragging(true);
830 cont->getView()->moveObject(X, Y);
831 cont->getView()->setState(DRAG);
832 cont->getModel()->notifyObservers(_idManager);
835 std::map<int, GObjectController*>::iterator it;
837 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
838 GObjectController *desc = it->second;
839 if (desc->getGObjectType() == GCONNECTOR) {
840 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
841 vconn->updateStartEndPoints();
845 _startDragging = false;
847 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
848 std::map<int, GObjectController*>::iterator it;
850 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
851 GObjectController *desc = it->second;
852 int type = desc->getGObjectType();
853 int state = desc->getView()->getState();
854 desc->getModel()->getCenter(px, py, pz);
857 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
860 okStatusMessage = true;
861 updateStatusBar(desc->getStatusText());
862 if (type == GBLACKBOX)
864 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
865 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
870 if ( ( _bugTextActor_text==desc->getStatusText() ) || (_bugTextActor_status==0) )
872 _bugTextActor_status = 1;
873 okPortMessage = true;
875 _textActor->SetScale(0.1);
876 std::string tmp = desc->getStatusText()+"\n";
877 _textActor->SetInput( tmp.c_str() );
878 _textActor->SetPosition(px - 25, py + 1, pz + 2);
879 _textActor->Modified();
883 _fillObjectActor->SetScale(1);
884 _fillObjectActor->GetProperty()->SetOpacity(0.50);
885 _fillObjectActor->SetPosition(px, py, 1);
886 _aPolygonMapper->Modified();
888 _bugTextActor_status = 2;
889 } // _bugTextActor_tex
890 _bugTextActor_text = desc->getStatusText();
894 } // for controllers it
896 if (okStatusMessage == false)
901 if ((okPortMessage == false) || (_bugTextActor_status== 2 ) )
903 _bugTextActor_status = 0;
904 _textActor->SetScale(0.0001);
905 _textActor->SetInput("a\n");
906 _textActor->Modified();
907 _fillObjectActor->SetScale(0.0001);
912 //=========================================================================
914 bool wxVtkSceneManager::OnLeftButtonDown()
916 if (_worldState == INIT_CREATION_CONTOUR)
918 bool isOverPort = false;
919 std::map<int, GObjectController*>::iterator it;
920 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
922 GObjectController *desc = it->second;
923 if (desc->getGObjectType() == GPORT)
925 GPortModel *portmod = (GPortModel*) desc->getModel();
926 vtkGObjectView *portView = desc->getView();
927 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
932 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
934 portView->setState( HIGHLIGHTED);
941 if (isOverPort == false)
944 UnSelectBlackBoxes();
948 } else { //_worldState
950 _worldState = DRAG_OBJECTS;
951 _startDragging = true;
953 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
954 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
955 ctrlkey = ctrlkey + shiftkey;
957 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
960 int state = cont->getView()->getState();
961 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
962 UnSelectBlackBoxes();
965 UnSelectBlackBoxes(); // EED 12/07/2012
967 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
968 int id = _selectedObjects[i];
969 GObjectController *cont = _controllers[id];
970 cont->getView()->setState(DRAG);
971 cont->getModel()->notifyObservers(_idManager);
973 } // if _selectedObjects.size
979 //=========================================================================
981 bool wxVtkSceneManager::OnLeftButtonUp()
983 if (_worldState == DRAG_OBJECTS) {
984 _worldState = NOTHING_HAPPENS;
986 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
987 int id = _selectedObjects[i];
988 GObjectController* cont = _controllers[id];
989 cont->getView()->setState(SELECTED);
990 cont->getModel()->notifyObservers(_idManager);
996 //=========================================================================
997 void wxVtkSceneManager::CancelConnection()
999 if (_worldState == INIT_CREATION_CONTOUR)
1001 _worldState = NOTHING_HAPPENS;
1002 //int lastId = _controllers.size()-1;
1004 GConnectorController *connector =
1005 (GConnectorController*) _controllers[_idConnectionInCreation];
1006 connector->removeFromScene();
1007 unregisterController(connector);
1008 _controllers.erase(_idConnectionInCreation);
1010 std::map<int, GObjectController*>::iterator it;
1011 for (it = _controllers.begin(); it != _controllers.end(); ++it)
1013 GObjectController *desc = it->second;
1014 desc->SetActive(true);
1015 desc->getView()->setState(NOTHING_HAPPENS);
1016 desc->getModel()->notifyObservers(_idManager);
1021 //=========================================================================
1023 bool wxVtkSceneManager::OnRightButtonUp()
1025 if (_worldState == INIT_CREATION_CONTOUR)
1029 UnSelectBlackBoxes();
1035 bool wxVtkSceneManager::OnMiddleButtonDown() {
1038 this->_vtkInteractorStyleBaseView->StartPan();
1043 bool wxVtkSceneManager::OnMiddleButtonUp() {
1046 this->_vtkInteractorStyleBaseView->EndPan();
1053 //=========================================================================
1055 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1056 GObjectController *result = NULL;
1058 wxVTKRenderWindowInteractor *wxVTKiren;
1060 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1061 wxVTKiren->GetEventPosition(X, Y);
1063 std::map<int, GObjectController*>::iterator it;
1065 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1066 GObjectController *cont = it->second;
1067 int type = cont->getGObjectType();
1069 if (cont->getView()->isPointInside(X, Y) == true) {
1070 if (type == GBLACKBOX) {
1073 } // if isPointInside
1078 //=========================================================================
1079 void wxVtkSceneManager::UnSelectBlackBoxes() {
1080 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1081 int id = _selectedObjects[i];
1082 GObjectController* control = _controllers[id];
1083 control->getView()->setState(NOTHING_HAPPENS);
1084 control->getModel()->notifyObservers(_idManager);
1085 }// for _selectedObjects
1086 _selectedObjects.clear();
1089 //=========================================================================
1090 bool wxVtkSceneManager::OnLeftDClick() {
1091 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1093 UnSelectBlackBoxes();
1094 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1100 wxVTKRenderWindowInteractor *wxVTKiren;
1101 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1102 wxVTKiren->GetEventPosition(X,Y);
1104 std::map<int, GObjectController*>::iterator it;
1106 bool clickOnObject = false;
1108 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1110 GObjectController *cont = it->second;
1111 int type = cont->getGObjectType();
1113 if(cont->getView()->isPointInside(X,Y))
1117 for (int i=0; i< (int)_selectedObjects.size(); i++)
1119 int id = _selectedObjects[i];
1120 GObjectController* control = _controllers[id];
1121 control->getView()->setState(NOTHING_HAPPENS);
1123 _selectedObjects.clear();
1125 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1126 _parent->editBlackBox(bbmodel);
1128 clickOnObject = true;
1132 if(clickOnObject==false)
1134 //_parent->editDiagramParameters(this);
1140 //=========================================================================
1142 bool wxVtkSceneManager::OnChar()
1146 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1147 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1149 // KeyCode 127 : Delete Key
1150 // KeyCode 8 : Backspace Key
1153 if (keyCode == 8 || keyCode == 127 || keyCode == 27)
1155 if (_worldState == INIT_CREATION_CONTOUR)
1158 UnSelectBlackBoxes();
1163 if (keyCode == 8 || keyCode == 127)
1166 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1168 int id = _selectedObjects[i];
1169 std::map<int, GObjectController*>::iterator it;
1170 it = _controllers.find(id);
1171 if (it != _controllers.end())
1173 oktmp = deleteObject(id);
1176 }// for selected objects
1177 if (ok) _selectedObjects.clear();
1178 _parent->saveTempandUpdate("delete object");
1183 if((keyCode==0) && (ctrlkey==1)) {
1188 if(_selectedObjects.size()){
1189 std::cout<<"objects to copy :";
1190 for(int i=0;i<_selectedObjects.size();i++)
1192 std::cout<<_selectedObjects.at(i)<<" ";
1194 DuplicateObjects(getSelectedObjects());
1196 std::cout<<"No objects to copy\n";
1197 } // _selectedObjects.size
1203 //=========================================================================
1205 void wxVtkSceneManager::AddControlerToBeRemove(
1206 std::vector<int> *controllersToRemove, int id) {
1210 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1211 if (id == (*controllersToRemove)[i]) {
1217 controllersToRemove->push_back(id);
1222 //=========================================================================
1224 bool wxVtkSceneManager::deleteObject(int id)
1227 GObjectController *control = _controllers[id];
1228 std::vector<int> controllersToRemove;
1229 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1230 == GCOMPLEXINPUTPORT || control->getGObjectType()
1231 == GCOMPLEXOUTPUTPORT) {
1232 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1233 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1235 bool boxConnected = false;
1237 // Add box input controllers to be removed
1238 for (int i = 0; i < (int) inputs.size(); i++) {
1239 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1240 if (inputs[i]->isConnected()) {
1241 boxConnected = true;
1245 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1247 // Add box output controllers to be removed
1248 for (int i = 0; i < (int) outputs.size(); i++) {
1249 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1250 if (outputs[i]->isConnected()) {
1251 boxConnected = true;
1255 // Add connection controllers to be removed
1256 std::map<int, GObjectController*>::iterator it;
1257 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1258 GObjectController *cont = it->second;
1259 int type = cont->getGObjectType();
1260 if (type == GCONNECTOR) {
1261 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1262 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1264 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1266 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1268 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1273 // Add box controller to be removed
1274 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1275 } else if (control->getGObjectType() == GCONNECTOR) {
1276 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1277 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1279 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1280 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1282 gconnectorcontroler->getManualContourController()->OnChar();
1287 std::map<int, GObjectController*>::iterator it;
1289 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1290 int key = controllersToRemove[i];
1291 it = _controllers.find(key);
1292 GObjectController *cont = _controllers[key];
1294 cont->removeFromScene();
1295 unregisterController((InteractorStyleMaracas*) cont);
1296 _controllers.erase(it);
1304 //=========================================================================
1306 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1307 std::string boxName) {
1308 _parent->displayBlackBoxInfo(packageName, boxName);
1311 //=========================================================================
1313 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1314 _parent->updateStatusBar(textStatus);
1317 //=========================================================================
1318 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1319 std::string result = "";
1320 if (withLineNumber == true) {
1322 stringstream StrStream;
1324 std::string strValue = StrStream.str();
1327 } else if (value < 100) {
1331 result += strValue + ": ";
1335 //=========================================================================
1337 bool wxVtkSceneManager::MakeBoxExecutable() {
1338 std::map<int, GObjectController*> selected = getSelectedObjects();
1339 if( selected.empty() )
1342 std::map<int, GObjectController*>::iterator it;
1343 for (it = selected.begin(); it != selected.end(); ++it) {
1344 GObjectController* lastSelected = it->second;
1346 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1347 GBlackBoxModel *bbmodel =
1348 (GBlackBoxModel*) lastSelected->getModel();
1349 view->setState(HIGHLIGHTED);
1350 if (bbmodel->isExecutable()) {
1351 bbmodel->setExecutable(false);
1353 bbmodel->setExecutable(true);
1355 bbmodel->notifyObservers(lastSelected->getId());
1363 //=========================================================================
1365 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1366 std::cout << "wxVtkSceneManager::getDiagramBBS" << std::endl;
1367 bool existsExec = false;
1369 std::vector<std::string> packages;
1370 std::vector<int> boxes;
1371 std::vector<int> connections;
1372 std::vector<int> execBoxes;
1374 std::map<int, GObjectController*>::iterator it;
1376 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1377 GObjectController *desc = it->second;
1378 int type = desc->getGObjectType();
1380 if (type == GBLACKBOX) {
1381 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1383 std::string pkg = mod->getBBTKPackage();
1384 bool existsPkg = false;
1385 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1386 if (packages[t] == pkg) {
1391 packages.push_back(pkg);
1394 boxes.push_back(it->first);
1395 if (mod->isExecutable()) {
1396 execBoxes.push_back(it->first);
1399 } else if (type == GCONNECTOR) {
1400 connections.push_back(it->first);
1405 std::string script = "";
1406 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1407 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1408 script += LineNumber(wln, lnNmbr) + "\n";
1410 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1411 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1413 for (i = 0; i < (int) packages.size(); i++) {
1414 script += LineNumber(wln, lnNmbr);
1415 script += "include ";
1416 script += packages[i];
1420 script += LineNumber(wln, lnNmbr);
1425 script += LineNumber(wln, lnNmbr);
1426 script += "author \"";
1430 script += LineNumber(wln, lnNmbr);
1431 script += "description \"";
1432 script += _Description;
1435 script += LineNumber(wln, lnNmbr);
1436 script += "category \"";
1437 script += _Category;
1440 script += LineNumber(wln, lnNmbr);
1443 // script+="include std\n"; // JPR
1445 for (i = 0; i < (int) boxes.size(); i++) {
1446 script += LineNumber(wln, lnNmbr);
1449 GObjectController *control = _controllers[id];
1450 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1452 script += model->getBBTKPackage()+":";
1453 script += model->getBBTKType();
1455 script += model->getBBTKName();
1458 std::vector<GPortModel*> inputs = model->getInputPorts();
1459 for (int j = 0; j < (int) inputs.size(); j++) {
1460 GPortModel* inputPort = inputs[j];
1461 if (inputPort->isValueSet()) {
1462 script += LineNumber(wln, lnNmbr);
1464 script += model->getBBTKName();
1466 script += inputPort->getBBTKName();
1468 script += inputPort->getValue();
1473 script += LineNumber(wln, lnNmbr);
1478 script += LineNumber(wln, lnNmbr);
1482 std::string complexInputs="";
1484 for (i = 0; i < (int) connections.size(); i++) {
1485 //script += LineNumber(wln, lnNmbr);
1486 //script += "connect ";
1487 int id = connections[i];
1488 GObjectController *control = _controllers[id];
1489 GConnectorModel *model = (GConnectorModel*) control->getModel();
1493 GPortModel *start = model->getStartPort();
1494 GBoxModel *startBox = start->getParentBox();
1496 GPortModel *end = model->getEndPort();
1497 GBoxModel *endBox = end->getParentBox();
1499 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1501 complexInputs += "input ";
1502 complexInputs += startBox->getBBTKName();
1504 complexInputs += " ";
1505 complexInputs += endBox->getBBTKName();
1506 complexInputs += ".";
1507 complexInputs += end->getBBTKName();
1509 complexInputs += " ";
1510 complexInputs += "\" \"";
1512 complexInputs += "\n";
1516 script += LineNumber(wln, lnNmbr);
1517 script += "connect ";
1518 script += startBox->getBBTKName();
1520 script += start->getBBTKName();
1524 //End Connection info
1525 script += endBox->getBBTKName();
1527 script += end->getBBTKName();
1532 script += LineNumber(wln, lnNmbr);
1536 script += LineNumber(wln, lnNmbr);
1539 script += LineNumber(wln, lnNmbr);
1542 script += LineNumber(wln, lnNmbr);
1543 script += "# Complex input ports\n";
1544 script += complexInputs;
1546 if((_MessageKind!="-")&&(_MessageLevel!="-")){
1547 script += LineNumber(wln, lnNmbr);
1548 script += "message ";
1549 script += _MessageKind;
1551 script += _MessageLevel;
1555 for (i = 0; i < (int) execBoxes.size(); i++) {
1556 script += LineNumber(wln, lnNmbr);
1558 int id = execBoxes[i];
1559 GObjectController *control = _controllers[id];
1560 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1562 script += model->getBBTKName();
1571 //=========================================================================
1573 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1574 std::cout<<"wxVtkSceneManager::saveComplexBoxBBS"<<std::endl;
1575 std::vector<std::string> packages;
1576 std::vector<int> boxes;
1577 std::vector<int> connections;
1578 std::vector<int> execBoxes;
1580 std::map<int, GObjectController*>::iterator it;
1582 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1583 GObjectController *desc = it->second;
1584 int type = desc->getGObjectType();
1586 if (type == GBLACKBOX) {
1587 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1589 std::string pkg = mod->getBBTKPackage();
1590 bool existsPkg = false;
1591 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1592 if (packages[t] == pkg) {
1597 packages.push_back(pkg);
1600 boxes.push_back(it->first);
1601 if (mod->isExecutable()) {
1602 execBoxes.push_back(it->first);
1604 } else if (type == GCONNECTOR) {
1605 connections.push_back(it->first);
1609 std::string script = "";
1611 script += "include std\n"; // EED
1612 script += "include itkvtk\n"; // EED
1614 for (i = 0; i < (int) packages.size(); i++) {
1615 script += "include ";
1616 script += packages[i];
1621 // Definition of a complex box
1622 script += "define ";
1623 script += _cbName + " " + _cbPackageName;
1627 script += "author \"";
1631 script += "description \"";
1632 script += _Description;
1636 script += "category \"";
1637 script += _Category;
1642 for (i = 0; i < (int) boxes.size(); i++) {
1645 GObjectController *control = _controllers[id];
1646 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1648 script += model->getBBTKPackage()+":";
1649 script += model->getBBTKType();
1651 script += model->getBBTKName();
1654 std::vector<GPortModel*> inputs = model->getInputPorts();
1655 for (int j = 0; j < (int) inputs.size(); j++) {
1656 GPortModel* inputPort = inputs[j];
1657 if (inputPort->isValueSet()) {
1659 script += model->getBBTKName();
1661 script += inputPort->getBBTKName();
1663 script += inputPort->getValue();
1671 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1673 std::string complexInputs = "";
1674 std::string complexOutputs = "";
1677 for (i = 0; i < (int) connections.size(); i++) {
1678 int id = connections[i];
1679 GObjectController *control = _controllers[id];
1680 GConnectorModel *model = (GConnectorModel*) control->getModel();
1683 GPortModel *start = model->getStartPort();
1684 GBoxModel *startBox = start->getParentBox();
1686 GPortModel *end = model->getEndPort();
1687 GBoxModel *endBox = end->getParentBox();
1689 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1690 complexInputs += "input ";
1691 complexInputs += startBox->getBBTKName();
1693 complexInputs += " ";
1694 complexInputs += endBox->getBBTKName();
1695 complexInputs += ".";
1696 complexInputs += end->getBBTKName();
1698 complexInputs += " ";
1699 complexInputs += "\" \"";
1701 complexInputs += "\n";
1702 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1703 complexOutputs += "output ";
1704 complexOutputs += endBox->getBBTKName();
1706 complexOutputs += " ";
1707 complexOutputs += startBox->getBBTKName();
1708 complexOutputs += ".";
1709 complexOutputs += start->getBBTKName();
1711 complexOutputs += " ";
1712 complexOutputs += "\" \"";
1714 complexOutputs += "\n";
1716 script += "connect ";
1717 script += startBox->getBBTKName();
1719 script += start->getBBTKName();
1723 //End Connection info
1724 script += endBox->getBBTKName();
1726 script += end->getBBTKName();
1733 script += "# Complex input ports\n";
1734 script += complexInputs;
1737 script += "# Complex output ports\n";
1738 script += complexOutputs;
1742 if((_MessageKind!="-")&&(_MessageLevel!="-"))
1744 script += "message ";
1745 script += _MessageKind;
1747 script += _MessageLevel;
1751 for (i = 0; i < (int) execBoxes.size(); i++)
1754 int id = execBoxes[i];
1755 GObjectController *control = _controllers[id];
1756 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1758 script += model->getBBTKName();
1763 script += "endefine";
1769 //=========================================================================
1771 void wxVtkSceneManager::deleteAllBoxes() {
1772 std::map<int, GObjectController*>::iterator it;
1773 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1774 GObjectController *cont = it->second;
1775 cont->removeFromScene();
1776 unregisterController((InteractorStyleMaracas*) cont);
1778 _selectedObjects.clear();
1779 _controllers.clear();
1782 //=========================================================================
1785 void wxVtkSceneManager::refresh() {
1786 _baseView->Refresh();
1788 //=========================================================================
1790 void wxVtkSceneManager::refreshScene()
1792 _baseView->RefreshView();
1795 //=========================================================================
1797 void wxVtkSceneManager::centerView()
1800 _baseView->GetRenderer()->ComputeVisiblePropBounds(bb);
1803 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1804 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1805 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1806 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1808 _baseView->GetRenderer()->ResetCamera();
1809 _baseView->GetRenderer()->ResetCameraClippingRange();
1812 double tt=_baseView->GetRenderer()->GetNearClippingPlaneTolerance();
1813 printf("EED wxVtkSceneManager::centerView() tolerance=%f\n",tt);
1815 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1816 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1817 _baseView->GetRenderer()->GetActiveCamera()->SetClippingRange(0.01,100000);
1818 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1819 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1822 _baseView->GetRenderer()->Render();
1825 //=========================================================================
1827 void wxVtkSceneManager::saveDiagram(std::string &content)
1831 content += "CATEGORY:";
1832 content += GetCategory();
1835 content += "DESCRIPTION:";
1836 content += GetDescription();
1839 content += "AUTHOR:";
1840 content += GetAuthor();
1843 //Print info IF COMPLEX BOX
1844 content += "COMPLEXBOX:";
1845 if (_isComplexBox) {
1846 content += "TRUE\n";
1848 content += "COMPLEXBOXNAME:";
1849 content += GetCbName();
1852 content += "PACKAGENAME:";
1853 content += GetCbPackageName();
1856 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1857 * External inputs are possible for applications and complex boxes
1858 //Print info complex input ports
1859 std::vector<int> inputs = getComplexInputPorts();
1860 int insize = inputs.size();
1861 content += "COMPLEXINPUTS:";
1862 sprintf(buffer, "%d", insize);
1866 for (int i = 0; i < insize; i++) {
1868 GObjectController *cont = _controllers[id];
1869 cont->getModel()->save(content);
1873 //Print info complex output ports
1874 std::vector<int> outputs = getComplexOutputPorts();
1875 int outsize = outputs.size();
1876 content += "COMPLEXOUTPUTS:";
1877 sprintf(buffer, "%d", outsize);
1881 for (int i = 0; i < outsize; i++) {
1882 int id = outputs[i];
1883 GObjectController *cont = _controllers[id];
1884 cont->getModel()->save(content);
1888 content += "FALSE\n";
1891 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1892 // External inputs are possible for applications and complex boxes
1893 std::vector<int> inputs = getComplexInputPorts();
1894 int insize = inputs.size();
1895 content += "COMPLEXINPUTS:";
1896 sprintf(buffer, "%d", insize);
1900 for (int i = 0; i < insize; i++) {
1902 GObjectController *cont = _controllers[id];
1903 cont->getModel()->save(content);
1907 std::vector<int> boxes = getBlackBoxes();
1908 int bsize = boxes.size();
1909 content += "BOXES:";
1910 sprintf(buffer, "%d", bsize);
1914 for (int i = 0; i < bsize; i++) {
1916 // std::cout<<"id "<<id<<std::endl;//CFT
1917 GObjectController *cont = _controllers[id];
1918 // std::cout<<"nombre: "<<cont->getStatusText()<<std::endl;//CFT
1919 // std::cout<<"tipo: "<<cont->getModel()->getBBTKType()<<std::endl;//CFT
1920 // //boxesDiagram[i] = cont->getModel()->getBBTKType();//CFT
1921 // std::cout<<"nname: "<<cont->getModel()->getBBTKName()<<std::endl;//CFT
1922 // std::cout<<"categorie: "<<GetCategory()<<std::endl;//CFT
1923 // std::cout<<"type: "<<cont->getModel()->getGObjectType()<<std::endl;//CFT
1924 cont->getModel()->save(content);
1928 std::vector<int> connections = getConnections();
1929 int csize = connections.size();
1930 content += "CONNECTIONS:";
1931 sprintf(buffer, "%d", csize);
1935 for (int i = 0; i < csize; i++) {
1936 int id = connections[i];
1937 GObjectController *cont = _controllers[id];
1938 cont->getModel()->save(content);
1943 //=========================================================================
1944 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1946 getline(inputStream, line,'\n');
1947 int size = line.length();
1950 if ( line[ size-1 ]==13 )
1952 line.erase(size-1,1);
1957 //=========================================================================
1958 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1961 std::string version = "<void>";
1962 std::string line = "";
1963 char delims[] = ":";
1964 char *result = NULL;
1965 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1967 getCleanLine(inputStream, line);
1970 while (!inputStream.eof()) {
1971 if (line == "" || line[0] == '#') {
1973 getCleanLine(inputStream, line);
1975 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1976 version = line.substr(18, 3);
1978 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1979 version = line.substr(18, 3);
1981 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1982 version = line.substr(18, 3);
1984 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1985 version = line.substr(18, 3);
1987 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1988 version = line.substr(18, 3);
1990 } else if (line == "APP_START") {
1999 if ((version != "1.0") && (version != "1.1")) {
2000 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
2001 char categoryTmp[30];
2002 strcpy(categoryTmp, line.c_str());
2003 result = strtok(categoryTmp, delims);
2004 result = strtok(NULL, delims);
2005 SetCategory(result);
2007 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
2008 char descriptionTmp[1024];
2009 strcpy(descriptionTmp, line.c_str());
2010 result = strtok(descriptionTmp, delims);
2011 result = strtok(NULL, delims);
2012 SetDescription(result);
2014 getCleanLine(inputStream, line);//AUTHOR:<author>
2015 char authorTmp[255];
2016 strcpy(authorTmp, line.c_str());
2017 result = strtok(authorTmp, delims);
2018 result = strtok(NULL, delims);
2023 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
2024 char complexTmp[30];
2025 strcpy(complexTmp, line.c_str());
2026 result = strtok(complexTmp, delims);
2027 result = strtok(NULL, delims);
2028 std::string isComplexBox(result);
2030 if (isComplexBox == "TRUE") {
2031 _isComplexBox = true;
2033 if ((version != "1.0") && (version != "1.1")) {
2034 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
2035 char complexboxnameTmp[255];
2036 strcpy(complexboxnameTmp, line.c_str());
2037 result = strtok(complexboxnameTmp, delims);
2038 result = strtok(NULL, delims);
2041 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
2042 char packagenameTmp[255];
2043 strcpy(packagenameTmp, line.c_str());
2044 result = strtok(packagenameTmp, delims);
2045 result = strtok(NULL, delims);
2046 SetCbPackageName(result);
2051 //-----------------------
2052 //- COMPLEX 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
2096 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2098 } // for input complex box
2103 //-----------------------
2104 //- COMPLEX OUTPUT PORTS
2105 //-----------------------
2107 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2109 strcpy(outputs, line.c_str());
2110 result = strtok(outputs, delims);
2111 result = strtok(NULL, delims);
2114 std::istringstream outps(result);
2115 outps >> numOutputs;
2117 for (int i = 0; i < numOutputs; i++) {
2119 getCleanLine(inputStream, line);//COMPLEX_PORT
2120 getCleanLine(inputStream, line);//name
2121 std::string outputPortName(line);
2124 getCleanLine(inputStream, line);//xInic:yInic:zInic
2126 strcpy(coord, line.c_str());
2127 result = strtok(coord, delims);//xInic
2128 std::string xInic(result);
2129 result = strtok(NULL, delims);//yInic
2130 std::string yInic(result);
2131 result = strtok(NULL, delims);//zInic
2132 std::string zInic(result);
2134 double xIn, yIn, zIn;
2135 std::istringstream xSt(xInic);
2137 std::istringstream ySt(yInic);
2139 std::istringstream zSt(zInic);
2144 if (zIn==900) zIn=GPOSITION_Z;
2147 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2149 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2151 } // for output complex box
2155 // RaC2012 2nd Hackfest
2156 if(version >= "1.4")
2158 //-----------------------
2159 //- EXTERNAL INPUT PORTS
2160 //-----------------------
2161 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2163 strcpy(inputs, line.c_str());
2164 result = strtok(inputs, delims);
2165 result = strtok(NULL, delims);
2168 std::istringstream inps(result);
2171 for (int i = 0; i < numInputs; i++) {
2173 getCleanLine(inputStream, line);//COMPLEX_PORT
2174 getCleanLine(inputStream, line);//name
2175 std::string inputPortName(line);
2178 getCleanLine(inputStream, line);//xInic:yInic:zInic
2180 strcpy(coord, line.c_str());
2181 result = strtok(coord, delims);//xInic
2182 std::string xInic(result);
2183 result = strtok(NULL, delims);//yInic
2184 std::string yInic(result);
2185 result = strtok(NULL, delims);//zInic
2186 std::string zInic(result);
2188 double xIn, yIn, zIn;
2189 std::istringstream xSt(xInic);
2191 std::istringstream ySt(yInic);
2193 std::istringstream zSt(zInic);
2198 if (zIn==900) zIn=GPOSITION_Z;
2201 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2202 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2204 } // for external input
2209 getCleanLine(inputStream, line);//BOXES:num
2211 strcpy(boxes, line.c_str());
2212 result = strtok(boxes, delims);
2213 result = strtok(NULL, delims);
2216 std::istringstream is(result);
2219 for (int i = 0; i < numBoxes; i++)
2222 getCleanLine(inputStream, line);//BOX
2223 getCleanLine(inputStream, line);//package:type:name
2225 strcpy(box, line.c_str());
2226 result = strtok(box, delims);//package
2227 std::string package(result);
2228 result = strtok(NULL, delims);//type
2229 std::string type(result);
2230 result = strtok(NULL, delims);//name
2231 std::string name(result);
2234 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2236 strcpy(exec, line.c_str());
2237 result = strtok(exec, delims);//ISEXEC
2238 result = strtok(NULL, delims);//TRUE|FALSE
2239 std::string isExec(result);
2242 getCleanLine(inputStream, line);//xInic:yInic:zInic
2244 strcpy(coord, line.c_str());
2245 result = strtok(coord, delims);//xInic
2246 std::string xInic(result);
2247 result = strtok(NULL, delims);//yInic
2248 std::string yInic(result);
2249 result = strtok(NULL, delims);//zInic
2250 std::string zInic(result);
2252 double xIn, yIn, zIn;
2253 std::istringstream xSt(xInic);
2255 std::istringstream ySt(yInic);
2257 std::istringstream zSt(zInic);
2263 if (zIn==900) zIn=GPOSITION_Z;
2268 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2269 strcpy(coord, line.c_str());
2270 result = strtok(coord, delims);//xEnd
2271 std::string xEnd(result);
2272 result = strtok(NULL, delims);//yEnd
2273 std::string yEnd(result);
2274 result = strtok(NULL, delims);//zEnd
2275 std::string zEnd(result);
2277 double xEn, yEn, zEn;
2278 std::istringstream xEt(xEnd);
2280 std::istringstream yEt(yEnd);
2282 std::istringstream zEt(zEnd);
2287 if (zEn==900) zEn=GPOSITION_Z;
2291 bool boxExecutable = false;
2292 if (isExec == "TRUE")
2294 boxExecutable = true;
2297 int idBox = createGBlackBox(xIn, yIn, package, type);
2298 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2300 GObjectController *cont = _controllers[idBox];
2301 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2304 getCleanLine(inputStream, line);//PORT o FIN_BOX
2305 std::string port = line.substr(0, 4);
2306 while (port == "PORT")
2308 getCleanLine(inputStream, line);//name:value
2309 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2311 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2314 strcpy(poort, line.c_str());
2315 result = strtok(poort, delims);//name
2316 std::string name(result);
2318 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2319 result = strtok(NULL, delims);//value
2320 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2322 std::string tmpString=" ";
2323 tmpString[0]=34; // character "
2324 strcat(result,tmpString.c_str());
2326 std::string value(result);
2328 bbmod->setValueToInput(name, value);
2330 getCleanLine(inputStream, line);//PORT o FIN_BOX
2331 port = line.substr(0, 4);
2334 //EED bbmod->notifyObservers(_idManager);
2339 getCleanLine(inputStream, line);//CONNECTIONS:num
2341 strcpy(conns, line.c_str());
2342 result = strtok(conns, delims);
2343 result = strtok(NULL, delims);
2346 std::istringstream isCons(result);
2350 for (int i = 0; i < numConns; i++)
2353 getCleanLine(inputStream, line);//CONNECTION
2354 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2357 strcpy(connec, line.c_str());
2358 result = strtok(connec, delims);
2359 std::string nameStartBox(result);
2360 result = strtok(NULL, delims);
2361 std::string nameStartPort(result);
2362 result = strtok(NULL, delims);
2363 std::string nameEndBox(result);
2364 result = strtok(NULL, delims);
2365 std::string nameEndPort(result);
2367 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2369 if (version != "1.0") {
2370 //Readding control points of the manualContour
2371 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2372 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2373 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2374 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2375 strcpy(conns, line.c_str());
2376 result = strtok(conns, delims);
2377 result = strtok(NULL, delims);
2379 int numberOfControlPoints;
2380 std::istringstream isCons(result);
2381 isCons >> numberOfControlPoints;
2383 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2384 getCleanLine(inputStream, line); //XX:YY:ZZ
2386 strcpy(connec, line.c_str());
2389 result = strtok(connec, delims);
2390 std::istringstream isPointX(result);
2392 result = strtok(NULL, delims);
2393 std::istringstream isPointY(result);
2395 result = strtok(NULL, delims);
2396 std::istringstream isPointZ(result);
2401 if (pz==900) pz=GPOSITION_Z;
2404 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2405 conView->getManualContourView()->AddPoint();
2411 //=========================================================================
2414 //=========================================================================
2415 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2416 std::string portName, double xIn, double yIn, double zIn)
2419 if (inputoutput == true) {
2420 idPort = createGComplexBoxInputPort(portName);
2422 idPort = createGComplexBoxOutputPort(portName);
2424 GObjectController *cont = _controllers[idPort];
2425 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2426 cbmod->setInicPoint(xIn, yIn, zIn);
2427 cbmod->notifyObservers(_idManager);
2429 //=========================================================================
2432 //=========================================================================
2433 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2438 GBoxModel *boxModel = NULL;
2439 std::vector<int> lstB = getBlackBoxes();
2440 for (j = 0; j < (int) lstB.size(); j++) {
2442 bMod = (GBoxModel*) _controllers[idB]->getModel();
2443 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2451 if (boxModel == NULL) {
2452 std::vector<int> lstInputs = getComplexInputPorts();
2453 for (j = 0; j < (int) lstInputs.size(); j++) {
2455 bMod = (GBoxModel*) _controllers[idB]->getModel();
2456 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2464 std::vector<int> lstOutputs = getComplexOutputPorts();
2465 for (j = 0; j < (int) lstOutputs.size(); j++) {
2466 int idB = lstOutputs[j];
2467 bMod = (GBoxModel*) _controllers[idB]->getModel();
2468 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2480 //=========================================================================
2483 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2484 std::string nameStartPort, std::string nameEndBox,
2485 std::string nameEndPort) {
2487 GBoxModel *boxModel;
2488 GPortModel *startP = NULL;
2489 GPortModel *endP = NULL;
2491 boxModel = findGBox(nameStartBox);
2492 if(boxModel == NULL)
2494 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2496 if (boxModel != NULL) {
2497 startP = boxModel->getOutputPort(nameStartPort);
2499 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port is null. Port name is probably wrong. Start>%s::%s End>%s::%s\n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str() );
2503 boxModel = findGBox(nameEndBox);
2504 if(boxModel == NULL)
2506 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2508 if (boxModel != NULL) {
2509 endP = boxModel->getInputPort(nameEndPort);
2511 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port is null. Port name is probably wrong. Start>%s::%s End>%s::%s \n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str());
2516 int idCon = createGConnector(startP);
2518 _worldState = NOTHING_HAPPENS;
2519 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2521 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2522 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2523 tempp->endContourCreation();
2524 conMod->setEndPort(endP);
2525 conView->updateStartEndPoints();
2529 //=========================================================================
2531 bool wxVtkSceneManager::boxExist(std::string boxname) {
2533 std::map<int, GObjectController*>::iterator it;
2534 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2535 GObjectController *cont = it->second;
2536 if (cont->getModel()->getBBTKName() == boxname) {
2543 //=========================================================================
2545 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2546 std::vector<int> vect;
2547 std::map<int, GObjectController*>::iterator it;
2548 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2549 GObjectController *cont = it->second;
2550 if (cont->getGObjectType() == GBLACKBOX) {
2551 vect.push_back(cont->getId());
2557 //=========================================================================
2559 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2560 std::vector<int> vect;
2561 std::map<int, GObjectController*>::iterator it;
2562 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2563 GObjectController *cont = it->second;
2564 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2565 vect.push_back(cont->getId());
2571 //=========================================================================
2573 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2574 std::vector<int> vect;
2575 std::map<int, GObjectController*>::iterator it;
2576 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2577 GObjectController *cont = it->second;
2578 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2579 vect.push_back(cont->getId());
2585 //=========================================================================
2587 std::vector<int> wxVtkSceneManager::getConnections() {
2588 std::vector<int> vect;
2589 std::map<int, GObjectController*>::iterator it;
2590 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2591 GObjectController *cont = it->second;
2592 if (cont->getGObjectType() == GCONNECTOR) {
2593 vect.push_back(cont->getId());
2599 //=========================================================================
2601 bool wxVtkSceneManager::isComplexBox() {
2602 return _isComplexBox;
2605 //=========================================================================
2607 void wxVtkSceneManager::setComplexBox(bool val) {
2608 _isComplexBox = val;
2611 //=========================================================================
2613 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2614 //Register the controller of the new object
2615 registerController((InteractorStyleMaracas*) objController);
2616 //Add the object to the objects list
2617 int newId = _contLastId;//_controllers.size();
2618 objController->setId(newId);
2619 _controllers[newId] = objController;
2620 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2625 //=========================================================================
2627 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2629 std::map<int, int> oldIdNewIdBoxes;
2630 std::vector<int> connections;
2632 std::vector<int> newBoxesID;
2634 std::map<int, GObjectController*>::iterator it;
2635 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2636 GObjectController *cont = it->second;
2637 int type = cont->getGObjectType();
2639 if (type == GBLACKBOX) {
2641 double xInic, yInic, zInic;
2642 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2643 copyBox->getInicPoint(xInic, yInic, zInic);
2644 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2645 copyBox->getBBTKType());
2647 int idcB = copyBox->getObjectId();
2648 oldIdNewIdBoxes[idcB] = idBox;
2649 cont = _controllers[idBox];
2650 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2651 newbox->setInicPoint(xInic, yInic, zInic);
2652 int num = newbox->getNumInputPorts();
2653 for (int j = 0; j < num; j++) {
2654 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2656 newbox->move(xInic + 20, yInic + 20, zInic);
2657 newbox->notifyObservers(_idManager);
2658 newBoxesID.push_back(newbox->getObjectId());
2660 } else if (type == GCONNECTOR) {
2661 int idCon = cont->getId();
2662 connections.push_back(idCon);
2667 for (int i = 0; i < (int) connections.size(); i++) {
2668 int objId = connections[i];
2669 GObjectController *cont = objectsMap[objId];
2670 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2672 GPortModel* startPort = connectModel->getStartPort();
2673 int startPortIndex = startPort->getPosInBox();
2674 GPortModel* endPort = connectModel->getEndPort();
2675 int endPortIndex = endPort->getPosInBox();
2677 GBlackBoxModel* startPortParentBox =
2678 (GBlackBoxModel*) startPort->getParentBox();
2679 GBlackBoxModel* endPortParentBox =
2680 (GBlackBoxModel*) endPort->getParentBox();
2682 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2683 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2685 GBlackBoxModel* newStartBox =
2686 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2687 GBlackBoxModel* newEndBox =
2688 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2690 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2691 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2693 // Creates connection
2694 int idCon = createGConnector(newStartPort);
2695 GConnectorController *tempp =
2696 (GConnectorController*) _controllers[idCon];
2697 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2698 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2699 tempp->endContourCreation();
2700 conMod->setEndPort(newEndPort);
2701 conView->updateStartEndPoints();
2704 /// the new selected boxes are the duplicate ones
2706 UnSelectBlackBoxes();
2707 for (int i = 0; i < newBoxesID.size(); i++) {
2708 _selectedObjects.push_back(newBoxesID.at(i));
2711 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2712 int id = _selectedObjects[i];
2713 GObjectController* cont = _controllers[id];
2715 cont->getView()->setState(SELECTED);
2716 cont->getModel()->notifyObservers(_idManager);
2722 //=========================================================================
2724 int wxVtkSceneManager::getNumSelectedObjects() {
2725 return _selectedObjects.size();
2728 //=========================================================================
2730 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2731 std::map<int, GObjectController*> mapSelected;
2733 std::map<int, GObjectController*>::iterator it;
2734 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2735 GObjectController *cont = it->second;
2736 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2738 mapSelected[cont->getId()] = cont;
2742 std::map<int, GObjectController*>::iterator it2;
2743 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2744 GObjectController *cont = it2->second;
2745 if (cont->getGObjectType() == GCONNECTOR) {
2746 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2747 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2748 GBoxModel* startPortParentBox =
2749 cmod->getStartPort()->getParentBox();
2751 std::map<int, GObjectController*>::iterator iterOBJ1 =
2752 mapSelected.find(startPortParentBox->getObjectId());
2753 std::map<int, GObjectController*>::iterator iterOBJ2 =
2754 mapSelected.find(endPortParentBox->getObjectId());
2756 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2757 int ID = cont->getId();
2758 mapSelected[ID] = cont;
2765 //=========================================================================
2767 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2769 std::map<int, int> oldIdNewIdBoxes;
2770 std::vector<int> connections;
2772 std::map<int, GObjectController*>::iterator it;
2773 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2774 GObjectController *cont = it->second;
2775 int type = cont->getGObjectType();
2777 if (type == GBLACKBOX) {
2779 double xInic, yInic, zInic;
2780 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2781 copyBox->getInicPoint(xInic, yInic, zInic);
2782 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2784 int idcB = copyBox->getObjectId();
2785 oldIdNewIdBoxes[idcB] = idBox;
2786 cont = _controllers[idBox];
2787 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2788 newbox->setInicPoint(xInic, yInic, zInic);
2789 int num = newbox->getNumInputPorts();
2790 for (int j = 0; j < num; j++)
2792 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2794 newbox->notifyObservers(_idManager);
2795 } else if (type == GCONNECTOR) {
2796 int idCon = cont->getId();
2797 connections.push_back(idCon);
2802 for (int i = 0; i < (int) connections.size(); i++) {
2803 int objId = connections[i];
2804 GObjectController *cont = objectsMap[objId];
2805 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2807 GPortModel* startPort = connectModel->getStartPort();
2808 int startPortIndex = startPort->getPosInBox();
2809 GPortModel* endPort = connectModel->getEndPort();
2810 int endPortIndex = endPort->getPosInBox();
2812 GBlackBoxModel* startPortParentBox =
2813 (GBlackBoxModel*) startPort->getParentBox();
2814 GBlackBoxModel* endPortParentBox =
2815 (GBlackBoxModel*) endPort->getParentBox();
2817 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2818 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2820 GBlackBoxModel* newStartBox =
2821 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2822 GBlackBoxModel* newEndBox =
2823 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2825 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2826 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2828 // Creates connection
2829 int idCon = createGConnector(newStartPort);
2830 GConnectorController *tempp =
2831 (GConnectorController*) _controllers[idCon];
2832 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2833 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2834 tempp->endContourCreation();
2835 conMod->setEndPort(newEndPort);
2836 conView->updateStartEndPoints();
2839 std::map<int, int>::iterator itIds;
2840 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2841 int idOld = itIds->first;
2842 int idNew = itIds->second;
2844 GBlackBoxModel* oldBox =
2845 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2846 GBlackBoxModel* newBox =
2847 (GBlackBoxModel*) _controllers[idNew]->getModel();
2849 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2850 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2851 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2852 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2854 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2856 //EED int toCreate=-1;
2857 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2858 if (oldInputConnections[k] == newInputConnections[l]) {
2863 if (exist == false) {
2864 //Create complex input
2865 int posInBox = oldInputConnections[k];
2866 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2867 std::string inputPortName = inputPort->getBBTKName();
2868 int idInputPort = createGComplexBoxInputPort(inputPortName);
2869 GObjectController *cont = _controllers[idInputPort];
2870 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2871 double xIn, yIn, zIn;
2872 inputPort->getInicPoint(xIn, yIn, zIn);
2874 cbmod->setInicPoint(xIn, yIn, zIn);
2875 cbmod->notifyObservers(_idManager);
2877 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2879 // Creates connection
2880 int idCon = createGConnector(cbmod->getOutputPort(0));
2881 GConnectorController *tempp =
2882 (GConnectorController*) _controllers[idCon];
2883 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2884 vtkGConnectorView *conView =
2885 (vtkGConnectorView*) tempp->getView();
2886 tempp->endContourCreation();
2887 conMod->setEndPort(inputPortEnd);
2888 conView->updateStartEndPoints();
2894 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2896 //EED int toCreate=-1;
2897 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2898 if (oldOutputConnections[k] == newOutputConnections[l]) {
2903 if (exist == false) {
2904 //Create complex output
2905 int posInBox = oldOutputConnections[k];
2906 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2907 std::string outputPortName = outputPort->getBBTKName();
2908 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2909 GObjectController *cont = _controllers[idOutputPort];
2910 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2911 double xIn, yIn, zIn;
2912 outputPort->getInicPoint(xIn, yIn, zIn);
2914 cbmod->setInicPoint(xIn, yIn, zIn);
2915 cbmod->notifyObservers(_idManager);
2917 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2919 // Creates connection
2920 int idCon = createGConnector(outputPortEnd);
2921 GConnectorController *tempp =
2922 (GConnectorController*) _controllers[idCon];
2923 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2924 vtkGConnectorView *conView =
2925 (vtkGConnectorView*) tempp->getView();
2926 tempp->endContourCreation();
2927 conMod->setEndPort(cbmod->getInputPort(0));
2928 conView->updateStartEndPoints();
2938 //=========================================================================
2939 void wxVtkSceneManager::SetCbName(std::string cbName) {
2941 if (_cbName == "") {
2942 _cbName = "<complex box name>";
2946 //=========================================================================
2947 std::string wxVtkSceneManager::GetCbName() {
2951 //=========================================================================
2952 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2953 _cbPackageName = packagename;
2954 if (_cbPackageName == "") {
2955 _cbPackageName = "<package name of the complex box>";
2959 //=========================================================================
2960 std::string wxVtkSceneManager::GetCbPackageName() {
2961 return _cbPackageName;
2964 //=========================================================================
2965 void wxVtkSceneManager::SetAuthor(std::string author) {
2967 if (_Author == "") {
2968 _Author = "<author of the box>";
2972 //=========================================================================
2973 std::string wxVtkSceneManager::GetAuthor() {
2977 //=========================================================================
2978 void wxVtkSceneManager::SetCategory(std::string category) {
2979 _Category = category;
2980 if (_Category == "") {
2981 _Category = "<category of the box>";
2985 //=========================================================================
2986 std::string wxVtkSceneManager::GetCategory() {
2990 //=========================================================================
2991 void wxVtkSceneManager::SetDescription(std::string description) {
2992 _Description = description;
2993 if (_Description == "") {
2994 _Description = "<description of the box>";
2998 //=========================================================================
2999 std::string wxVtkSceneManager::GetDescription() {
3000 return _Description;
3003 //=========================================================================
3005 void wxVtkSceneManager::SetMessageKind(std::string kind) {
3006 _MessageKind = kind;
3010 //=========================================================================
3012 std::string wxVtkSceneManager::GetMessageKind(){
3013 return _MessageKind;
3016 //=========================================================================
3018 void wxVtkSceneManager::SetMessageLevel(std::string Level){
3019 _MessageLevel = Level;
3022 //=========================================================================
3024 std::string wxVtkSceneManager::GetMessageLevel(){
3025 return _MessageLevel;
3028 //=========================================================================
3030 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
3033 std::vector< std::string> extInputs;
3034 std::map<int, GObjectController*>::iterator it;
3035 for (it = _controllers.begin(); it != _controllers.end(); ++it)
3037 GObjectController *cont = it->second;
3038 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
3040 extInputs.push_back(cont->getModel()->getBBTKName());
3046 //=========================================================================
3050 void wxVtkSceneManager::printAll(int com , int sta ){
3052 int tmpState = sta ;
3053 if ( tmpState == NOTHING_HAPPENS ) {
3054 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
3056 if ( tmpState == HIGHLIGHTED ) {
3057 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
3059 if ( tmpState == POSSIBLE_CONNECTION ) {
3060 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
3062 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
3063 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
3065 if ( tmpState == CLICKED ) {
3066 std::cout << "CONTROLER STATE---->CLICKED\n" ;
3068 if ( tmpState == DRAG ) {
3069 std::cout << "CONTROLER STATE---->DRAG\n" ;
3071 if ( tmpState == SELECTED ) {
3072 std::cout << "CONTROLER STATE---->SELECTED\n" ;
3074 if ( tmpState == CREATING_CONTOUR ) {
3075 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
3081 if ( command == INIT_CREATION_CONTOUR ) {
3082 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
3084 if ( command == FIN_CREATION_CONTOUR ) {
3085 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
3087 if ( command == ADD_TO_SELECTED ) {
3088 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
3090 if ( command == DRAG_OBJECTS ) {
3091 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
3093 if ( command == EDIT_BLACKBOX ) {
3094 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
3096 if ( command == REMOVE_FROM_SELECTED ) {
3097 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
3103 } // EO namespace bbtk