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();
217 //EED 2017-01-01 Migration VTK7
218 #if VTK_MAJOR_VERSION <= 5
219 _aPolygonMapper->SetInput(aPolygonGrid);
221 _aPolygonMapper->SetInputData(aPolygonGrid);
225 _fillObjectActor->SetMapper(_aPolygonMapper);
226 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
228 _fillObjectActor->GetProperty()->SetOpacity(0);
229 _aPolygonMapper->Modified();
231 _baseView->GetRenderer()->AddActor(_fillObjectActor);
234 //=========================================================================
236 std::string wxVtkSceneManager::generateANewNameForABox() {
237 std::stringstream boxname;
238 if (_numBoxes < 10) {
239 boxname << "Box0" << _numBoxes;
241 boxname << "Box" << _numBoxes;
244 return boxname.str();
247 //=========================================================================
249 std::string wxVtkSceneManager::findANewNameForABox() {
250 std::string boxname = generateANewNameForABox();
252 while (boxExist(boxname) == true) {
253 boxname = generateANewNameForABox();
259 //=========================================================================
260 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
261 double zIn, std::string name, bool boxExecutable, double xEn,
262 double yEn, double zEn) {
263 GObjectController *cont = _controllers[idBox];
264 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
265 bbmod->setBBTKName(name);
266 bbmod->setInicPoint(xIn, yIn, zIn);
267 bbmod->setFinalPoint(xEn, yEn, zEn);
268 bbmod->setExecutable(boxExecutable);
270 bbmod->notifyObservers(_idManager);
274 //=========================================================================
276 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,std::string boxType)
278 _worldState = NOTHING_HAPPENS;
279 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
280 int type = GBLACKBOX;
281 //Create the MVC Objects
282 GBlackBoxModel *model = (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
283 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
284 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
286 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
290 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
292 k = _bbtkfactory->GetPackage(packageName);
293 mapDesc = k->GetDescriptorMap();
295 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for package %s, NOT EXIST\n", packageName.c_str());
298 BlackBoxDescriptor::Pointer descriptor;
300 descriptor = mapDesc[boxType];
302 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for box %s of package %s, NOT EXIST\n", boxType.c_str(),packageName.c_str());
305 if (descriptor == NULL)
307 printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
310 //Prepares the initial model
311 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
314 double yy = windowHeight - y;
316 //z value is not important yet, because it is only used a parallel projection
317 double zz = GPOSITION_Z;
318 _baseView->TransCoordScreenToWorld(xx, yy, zz);
319 model->setInicPoint(xx, yy, zz);
321 std::stringstream stream;
323 std::string newBoxName;
324 newBoxName = findANewNameForABox();
326 stream << newBoxName;
328 std::string arraystring = stream.str();
330 model->setBBTKName(arraystring);
331 model->setBBTKType(boxType);
332 model->setBBTKPackage(packageName);
334 model->addObserver(view);
335 model->addObserver(this);
338 //EED2017 change order
339 //Associates the view with the correspondent renderer and the model.
340 //(NOTE: Refresh is only made by the view)
341 view->setModel(model);
342 view->setBaseView(_baseView);
344 //Associates the controller with the correspondent model and view
345 controller->setModelAndView(model, view);
348 //Iterate and create the input ports
349 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
350 descriptor->GetInputDescriptorMap();
351 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
353 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
355 BlackBoxInputDescriptor *desc = itInput->second;
357 // createGInputPort(GINPUTPORT, i, model, desc);
358 createGInputPort(GINPUTPORT, i, controller, desc);
362 //Iterate and create the output ports
363 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
364 descriptor->GetOutputDescriptorMap();
365 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
367 for (itOutput = descriptorOutMap.begin(); itOutput!= descriptorOutMap.end(); ++itOutput)
369 BlackBoxOutputDescriptor *desc = itOutput->second;
371 // createGOutputPort(GOUTPUTPORT, i, model, desc);
372 createGOutputPort(GOUTPUTPORT, i, controller, desc);
376 //EED2017 change order
377 view->initVtkObjects();
379 //Resgiter change to the observers of the actual model
380 model->notifyObservers(_idManager);
381 int newId = addObjectController(controller);
387 //=========================================================================
389 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
390 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
391 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
393 int type = GCOMPLEXINPUTPORT;
395 //Create the MVC Objects
397 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
398 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
399 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
401 //Prepares the initial model
404 double yy = windowHeight - 5;
406 //z value is not important yet, because it is only used a parallel projection
407 double zz = GPOSITION_Z;
409 _baseView->TransCoordScreenToWorld(xx, yy, zz);
410 model->setInicPoint(xx, yy, zz);
412 model->setBBTKName(inputName);
413 model->setBBTKType("ComplexInputPort");
414 model->setComplexPortType(type);
416 model->addObserver(view);
417 model->addObserver(this);
419 //create the output port
420 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
421 "ComplexOutputPortType","ComplexOutputPortDescriopton", 0, model);
422 model->addOutputPort((GPortModel*) portController->getModel());
424 //Associates the view with the correspondent renderer and the model.
425 //(NOTE: Refresh is only made by the view)
426 view->setModel(model);
427 view->setBaseView(_baseView);
428 view->initVtkObjects();
430 //Associates the controller with the correspondent model and view
431 controller->setModelAndView(model, view);
433 //Resgiter change to the observers of the actual model
434 model->notifyObservers(_idManager);
436 int newId = addObjectController(controller);
440 //=========================================================================
442 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
443 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
444 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
446 int type = GCOMPLEXOUTPUTPORT;
448 //Create the MVC Objects
450 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
451 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
452 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
454 //Prepares the initial model
457 double yy = windowHeight - 5;
459 //z value is not important yet, because it is only used a parallel projection
460 double zz = GPOSITION_Z;
462 _baseView->TransCoordScreenToWorld(xx, yy, zz);
463 model->setInicPoint(xx, yy, zz);
465 model->setBBTKName(outputName);
466 model->setBBTKType("ComplexOutputPort");
467 model->setComplexPortType(type);
469 model->addObserver(view);
470 model->addObserver(this);
472 //create the output port
473 GPortController* portController = createGPort(GINPUTPORT, outputName,
474 "ComplexInputPort","ComplexInputPortDescription", 0, model);
475 model->addInputPort((GPortModel*) portController->getModel());
477 //Associates the view with the correspondent renderer and the model.
478 //(NOTE: Refresh is only made by the view)
479 view->setModel(model);
480 view->setBaseView(_baseView);
481 view->initVtkObjects();
483 //Associates the controller with the correspondent model and view
484 controller->setModelAndView(model, view);
486 //Resgiter change to the observers of the actual model
487 model->notifyObservers(_idManager);
489 int newId = addObjectController(controller);
493 //=========================================================================
496 //int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
497 int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GObjectController *gBoxControler, BlackBoxInputDescriptor *desc)
499 GBoxModel *blackBox=(GBoxModel*)gBoxControler->getModel();
500 GPortController* portController = createGPort(portType, desc->GetName(),
501 desc->GetTypeName(), desc->GetDescription(), posinBox, blackBox);
502 blackBox->addInputPort( (GPortModel*)portController->getModel() );
504 vtkGBoxView *vtkgboxView=(vtkGBoxView*)gBoxControler->getView();
505 vtkgboxView->addInputPort( (vtkGPortView*)portController->getView() );
507 return portController->getId();
510 //=========================================================================
513 //int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
514 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GObjectController *gBoxControler, BlackBoxOutputDescriptor *desc)
516 GBoxModel *blackBox=(GBoxModel*)gBoxControler->getModel();
517 GPortController* portController = createGPort(portType, desc->GetName(),
518 desc->GetTypeName(),desc->GetDescription(), posinBox, blackBox);
519 blackBox->addOutputPort((GPortModel*) portController->getModel());
521 vtkGBoxView *vtkgboxView=(vtkGBoxView*)gBoxControler->getView();
522 vtkgboxView->addOutputPort( (vtkGPortView*)portController->getView() );
524 return portController->getId();
527 //=========================================================================
529 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posInBox,GBoxModel *blackBox)
533 //Create the MVC Objects
534 GPortModel *model = (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
535 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
536 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
537 model->registerInBox(blackBox, portType, posInBox);
538 model->setBBTKType(bbtkType);
539 model->setBBTKName(bbtkName);
540 model->setBBTKDescription(bbtkDescription);
541 model->addObserver(view);
542 model->addObserver(this);
543 //Associates the view with the correspondent renderer and the model.
544 //(NOTE: Refresh is only made by the view)
545 view->setModel(model);
546 view->setBaseView(_baseView);
547 //EED017 view->initVtkObjects();
548 view->createVtkObjects();
549 // view->addVtkActors();
551 //Associates the controller with the correspondent model and view
552 controller->setModelAndView(model, view);
553 model->notifyObservers(_idManager);
554 addObjectController(controller);
555 return (GPortController*) controller;
558 //=========================================================================
560 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
562 int type = GCONNECTOR;
564 manualConnectorContourController *manContourControl = new manualConnectorContourController();
565 manualConnectorContourView *manContourView = new manualConnectorContourView();
566 manualContourModel *manContourModel = new manualContourModel();
567 GConnectorController *connectorcontroller = new GConnectorController();
568 GConnectorModel *connectorModel = new GConnectorModel();
569 vtkGConnectorView *connectorView = new vtkGConnectorView();
570 connectorModel->setGObjectType(type);
572 manContourModel->SetCloseContour(false);
573 connectorModel->setStartPort(startPort);
575 manContourView->SetModel(manContourModel);
576 manContourView->SetWxVtkBaseView(_baseView);
577 manContourView->SetRange(0.5);
578 manContourView->SetZ(GPOSITION_Z);
580 manContourView->SetColorNormalContour(0, 0, 1);
581 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
582 manContourView->SetColorSelectContour(1, 0.8, 0);
588 * Width increased from 2 to 3, it simplifies line handling and spline control :P
592 manContourView->SetWidthLine( 3 ) ;
593 manContourView->SetShowText(false);
595 manContourControl->SetModelView(manContourModel, manContourView);
597 manContourControl->CreateNewManualContour();
601 connectorModel->getInicPoint(x, y, z);
604 manContourControl->SetState(1);
605 manContourModel->SetCloseContour(false);
607 manContourModel->AddPoint(x, y, z);
608 manContourView->AddPoint();
610 manContourModel->AddPoint(x, y, z);
611 manContourView->AddPoint();
613 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
614 manContourControl->_bakIdPoint = bak;
616 manContourControl->SetMoving(false);
618 connectorcontroller->setModelAndView(connectorModel, connectorView);
620 int newId = addObjectController(connectorcontroller);
622 connectorcontroller->setManualContourController(manContourControl);
623 connectorModel->setManualContourModel(manContourModel);
624 connectorView->setManualContourView(manContourView);
625 connectorView->setModel(connectorModel);
626 connectorView->setBaseView(_baseView);
628 connectorModel->addObserver(connectorView);
629 connectorModel->addObserver(this);
631 // manContourView->Refresh();
636 //=========================================================================
638 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
640 vtkInteractorStyleBaseView * baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
641 baseViewControlManager->AddInteractorStyleMaracas(param);
644 //=========================================================================
646 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
648 vtkInteractorStyleBaseView *baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
649 baseViewControlManager->RemoveInteractorStyleMaracas(param);
652 //=========================================================================
654 vtkRenderer* wxVtkSceneManager::getRenderer()
656 return _baseView->GetRenderer();
659 //=========================================================================
661 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
663 return _baseView->GetRenWin();
665 //=========================================================================
668 //=========================================================================
669 int wxVtkSceneManager::GetIndexInSelected(int idControler)
672 for (int i = 0; i < (int) _selectedObjects.size(); i++)
674 if (_selectedObjects[i] == idControler)
682 //=========================================================================
684 void wxVtkSceneManager::update(int idController, int command) {
686 if (command != NO_COMMAND)
688 if (command == ADD_TO_SELECTED)
690 if (GetIndexInSelected(idController) == -1)
692 _selectedObjects.push_back(idController);
694 } else if (command == REMOVE_FROM_SELECTED) {
695 int index = GetIndexInSelected(idController);
698 _selectedObjects.erase(_selectedObjects.begin() + index);
700 } else if (command == INIT_CREATION_CONTOUR) {
702 typedef std::map<int , GObjectController*>::iterator TIterator ;
705 // Find current item in the controller
706 iter = _controllers.find( idController ) ;
707 iter_end = _controllers.end( ) ;
709 if ( iter != iter_end ) {
710 GObjectController* gobjc = iter->second ;
712 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
713 // And if the item is a port
714 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
715 TIterator c_it = _controllers.begin( ) ;
716 // Go through all componets
717 for ( c_it ; c_it != iter_end ; c_it++ ) {
718 GObjectController* obc = c_it->second ;
719 int obc_type = obc->getModel( )->getGObjectType( ) ;
720 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
721 // if the component is a port and the type is the same of that selected
722 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
724 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
725 //obc->getView( )->setState( HIGHLIGHTED ) ;
733 _worldState = INIT_CREATION_CONTOUR;
734 GObjectController* cont = _controllers[idController];
735 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
737 // The last one is the controller of the connector
738 std::map<int, GObjectController*>::iterator it2;
740 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
742 GObjectController *cont = it2->second;
743 if (cont->getGObjectType() == GPORT)
745 GPortModel* port = (GPortModel*) cont->getModel();
746 if (port->getPortType() == GINPUTPORT)
748 cont->SetActive(true);
750 cont->getView()->setState(NOTHING_HAPPENS);
751 cont->getModel()->notifyObservers(_idManager);
752 cont->SetActive(false);
755 cont->getView()->setState(NOTHING_HAPPENS);
756 cont->getModel()->notifyObservers(_idManager);
757 cont->SetActive(false);
760 _selectedObjects.clear();
761 _idConnectionInCreation = createGConnector(startOutputPort);
762 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
763 _worldState = NOTHING_HAPPENS;
764 //int id = _controllers.size()-1;
765 GObjectController *cont = _controllers[_idConnectionInCreation];
766 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
767 GObjectController *finPort = _controllers[idController];
769 if (finPort->getGObjectType() == GPORT)
771 GPortModel* modelPort = (GPortModel*) finPort->getModel();
772 modelContour->setEndPort(modelPort);
775 typedef std::map<int, GObjectController*>::iterator TIterator;
776 TIterator c_it = _controllers.begin();
777 TIterator iter_end = _controllers.end();
778 // Go through all componets
779 for (c_it; c_it != iter_end; c_it++) {
780 GObjectController* obc = c_it->second;
781 int obc_type = obc->getModel()->getGObjectType();
782 int obc_state = obc->getView()->getState();
783 // if the component is a port and the type is the same of that selected
784 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
785 // Return element to neutral state if not selected
786 obc->getView()->setState(NOTHING_HAPPENS);
788 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
789 // Change element to connected state
790 obc->getView()->setState(HIGHLIGHTED);
796 _parent->saveTempandUpdate("create connection");
799 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
800 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
802 std::map<int, GObjectController*>::iterator it2;
804 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
806 GObjectController *cont = it2->second;
807 if (cont->getView() != NULL) {
808 cont->getView()->setState(NOTHING_HAPPENS);
809 cont->getModel()->notifyObservers(_idManager);
811 cont->SetActive(true);
820 //=========================================================================
822 bool wxVtkSceneManager::OnMouseMove()
825 bool okStatusMessage = false;
826 bool okPortMessage = false;
827 wxVTKRenderWindowInteractor *wxVTKiren;
828 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
829 wxVTKiren->GetEventPosition(X, Y);
831 if (_worldState == DRAG_OBJECTS) {
832 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
833 int id = _selectedObjects[i];
834 GObjectController* cont = _controllers[id];
835 if (_startDragging) {
836 cont->getView()->setStartDragging(true);
838 cont->getView()->moveObject(X, Y);
839 cont->getView()->setState(DRAG);
840 cont->getModel()->notifyObservers(_idManager);
843 std::map<int, GObjectController*>::iterator it;
845 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
846 GObjectController *desc = it->second;
847 if (desc->getGObjectType() == GCONNECTOR) {
848 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
849 vconn->updateStartEndPoints();
853 _startDragging = false;
855 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
856 std::map<int, GObjectController*>::iterator it;
858 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
859 GObjectController *desc = it->second;
860 int type = desc->getGObjectType();
861 int state = desc->getView()->getState();
862 desc->getModel()->getCenter(px, py, pz);
865 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
868 okStatusMessage = true;
869 updateStatusBar(desc->getStatusText());
870 if (type == GBLACKBOX)
872 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
873 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
878 if ( ( _bugTextActor_text==desc->getStatusText() ) || (_bugTextActor_status==0) )
880 _bugTextActor_status = 1;
881 okPortMessage = true;
883 _textActor->SetScale(0.1);
884 std::string tmp = desc->getStatusText()+"\n";
885 _textActor->SetInput( tmp.c_str() );
886 _textActor->SetPosition(px - 25, py + 1, pz + 2);
887 _textActor->Modified();
891 _fillObjectActor->SetScale(1);
892 _fillObjectActor->GetProperty()->SetOpacity(0.50);
893 _fillObjectActor->SetPosition(px, py, 1);
894 _aPolygonMapper->Modified();
896 _bugTextActor_status = 2;
897 } // _bugTextActor_tex
898 _bugTextActor_text = desc->getStatusText();
902 } // for controllers it
904 if (okStatusMessage == false)
909 if ((okPortMessage == false) || (_bugTextActor_status== 2 ) )
911 _bugTextActor_status = 0;
912 _textActor->SetScale(0.0001);
913 _textActor->SetInput("a\n");
914 _textActor->Modified();
915 _fillObjectActor->SetScale(0.0001);
920 //=========================================================================
922 bool wxVtkSceneManager::OnLeftButtonDown()
924 if (_worldState == INIT_CREATION_CONTOUR)
926 bool isOverPort = false;
927 std::map<int, GObjectController*>::iterator it;
928 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
930 GObjectController *desc = it->second;
931 if (desc->getGObjectType() == GPORT)
933 GPortModel *portmod = (GPortModel*) desc->getModel();
934 vtkGObjectView *portView = desc->getView();
935 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
940 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
942 portView->setState( HIGHLIGHTED);
949 if (isOverPort == false)
952 UnSelectBlackBoxes();
956 } else { //_worldState
958 _worldState = DRAG_OBJECTS;
959 _startDragging = true;
961 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
962 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
963 ctrlkey = ctrlkey + shiftkey;
965 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
968 int state = cont->getView()->getState();
969 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
970 UnSelectBlackBoxes();
973 UnSelectBlackBoxes(); // EED 12/07/2012
975 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
976 int id = _selectedObjects[i];
977 GObjectController *cont = _controllers[id];
978 cont->getView()->setState(DRAG);
979 cont->getModel()->notifyObservers(_idManager);
981 } // if _selectedObjects.size
987 //=========================================================================
989 bool wxVtkSceneManager::OnLeftButtonUp()
991 if (_worldState == DRAG_OBJECTS) {
992 _worldState = NOTHING_HAPPENS;
994 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
995 int id = _selectedObjects[i];
996 GObjectController* cont = _controllers[id];
997 cont->getView()->setState(SELECTED);
998 cont->getModel()->notifyObservers(_idManager);
1004 //=========================================================================
1005 void wxVtkSceneManager::CancelConnection()
1007 if (_worldState == INIT_CREATION_CONTOUR)
1009 _worldState = NOTHING_HAPPENS;
1010 //int lastId = _controllers.size()-1;
1012 GConnectorController *connector =
1013 (GConnectorController*) _controllers[_idConnectionInCreation];
1014 connector->removeFromScene();
1015 unregisterController(connector);
1016 _controllers.erase(_idConnectionInCreation);
1018 std::map<int, GObjectController*>::iterator it;
1019 for (it = _controllers.begin(); it != _controllers.end(); ++it)
1021 GObjectController *desc = it->second;
1022 desc->SetActive(true);
1023 desc->getView()->setState(NOTHING_HAPPENS);
1024 desc->getModel()->notifyObservers(_idManager);
1029 //=========================================================================
1031 bool wxVtkSceneManager::OnRightButtonUp()
1033 if (_worldState == INIT_CREATION_CONTOUR)
1037 UnSelectBlackBoxes();
1043 bool wxVtkSceneManager::OnMiddleButtonDown() {
1046 this->_vtkInteractorStyleBaseView->StartPan();
1051 bool wxVtkSceneManager::OnMiddleButtonUp() {
1054 this->_vtkInteractorStyleBaseView->EndPan();
1061 //=========================================================================
1063 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1064 GObjectController *result = NULL;
1066 wxVTKRenderWindowInteractor *wxVTKiren;
1068 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1069 wxVTKiren->GetEventPosition(X, Y);
1071 std::map<int, GObjectController*>::iterator it;
1073 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1074 GObjectController *cont = it->second;
1075 int type = cont->getGObjectType();
1077 if (cont->getView()->isPointInside(X, Y) == true) {
1078 if (type == GBLACKBOX) {
1081 } // if isPointInside
1086 //=========================================================================
1087 void wxVtkSceneManager::UnSelectBlackBoxes() {
1088 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1089 int id = _selectedObjects[i];
1090 GObjectController* control = _controllers[id];
1091 control->getView()->setState(NOTHING_HAPPENS);
1092 control->getModel()->notifyObservers(_idManager);
1093 }// for _selectedObjects
1094 _selectedObjects.clear();
1097 //=========================================================================
1098 bool wxVtkSceneManager::OnLeftDClick() {
1099 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1101 UnSelectBlackBoxes();
1102 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1108 wxVTKRenderWindowInteractor *wxVTKiren;
1109 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1110 wxVTKiren->GetEventPosition(X,Y);
1112 std::map<int, GObjectController*>::iterator it;
1114 bool clickOnObject = false;
1116 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1118 GObjectController *cont = it->second;
1119 int type = cont->getGObjectType();
1121 if(cont->getView()->isPointInside(X,Y))
1125 for (int i=0; i< (int)_selectedObjects.size(); i++)
1127 int id = _selectedObjects[i];
1128 GObjectController* control = _controllers[id];
1129 control->getView()->setState(NOTHING_HAPPENS);
1131 _selectedObjects.clear();
1133 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1134 _parent->editBlackBox(bbmodel);
1136 clickOnObject = true;
1140 if(clickOnObject==false)
1142 //_parent->editDiagramParameters(this);
1148 //=========================================================================
1150 bool wxVtkSceneManager::OnChar()
1154 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1155 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1157 // KeyCode 127 : Delete Key
1158 // KeyCode 8 : Backspace Key
1161 if (keyCode == 8 || keyCode == 127 || keyCode == 27)
1163 if (_worldState == INIT_CREATION_CONTOUR)
1166 UnSelectBlackBoxes();
1171 if (keyCode == 8 || keyCode == 127)
1174 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1176 int id = _selectedObjects[i];
1177 std::map<int, GObjectController*>::iterator it;
1178 it = _controllers.find(id);
1179 if (it != _controllers.end())
1181 oktmp = deleteObject(id);
1184 }// for selected objects
1185 if (ok) _selectedObjects.clear();
1186 _parent->saveTempandUpdate("delete object");
1191 if((keyCode==0) && (ctrlkey==1)) {
1196 if(_selectedObjects.size()){
1197 std::cout<<"objects to copy :";
1198 for(int i=0;i<_selectedObjects.size();i++)
1200 std::cout<<_selectedObjects.at(i)<<" ";
1202 DuplicateObjects(getSelectedObjects());
1204 std::cout<<"No objects to copy\n";
1205 } // _selectedObjects.size
1211 //=========================================================================
1213 void wxVtkSceneManager::AddControlerToBeRemove(
1214 std::vector<int> *controllersToRemove, int id) {
1218 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1219 if (id == (*controllersToRemove)[i]) {
1225 controllersToRemove->push_back(id);
1230 //=========================================================================
1232 bool wxVtkSceneManager::deleteObject(int id)
1235 GObjectController *control = _controllers[id];
1236 std::vector<int> controllersToRemove;
1237 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1238 == GCOMPLEXINPUTPORT || control->getGObjectType()
1239 == GCOMPLEXOUTPUTPORT) {
1240 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1241 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1243 bool boxConnected = false;
1245 // Add box input controllers to be removed
1246 for (int i = 0; i < (int) inputs.size(); i++) {
1247 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1248 if (inputs[i]->isConnected()) {
1249 boxConnected = true;
1253 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1255 // Add box output controllers to be removed
1256 for (int i = 0; i < (int) outputs.size(); i++) {
1257 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1258 if (outputs[i]->isConnected()) {
1259 boxConnected = true;
1263 // Add connection controllers to be removed
1264 std::map<int, GObjectController*>::iterator it;
1265 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1266 GObjectController *cont = it->second;
1267 int type = cont->getGObjectType();
1268 if (type == GCONNECTOR) {
1269 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1270 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1272 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1274 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1276 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1281 // Add box controller to be removed
1282 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1283 } else if (control->getGObjectType() == GCONNECTOR) {
1284 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1285 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1287 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1288 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1290 gconnectorcontroler->getManualContourController()->OnChar();
1295 std::map<int, GObjectController*>::iterator it;
1297 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1298 int key = controllersToRemove[i];
1299 it = _controllers.find(key);
1300 GObjectController *cont = _controllers[key];
1302 cont->removeFromScene();
1303 unregisterController((InteractorStyleMaracas*) cont);
1304 _controllers.erase(it);
1312 //=========================================================================
1314 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1315 std::string boxName) {
1316 _parent->displayBlackBoxInfo(packageName, boxName);
1319 //=========================================================================
1321 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1322 _parent->updateStatusBar(textStatus);
1325 //=========================================================================
1326 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1327 std::string result = "";
1328 if (withLineNumber == true) {
1330 stringstream StrStream;
1332 std::string strValue = StrStream.str();
1335 } else if (value < 100) {
1339 result += strValue + ": ";
1343 //=========================================================================
1345 bool wxVtkSceneManager::MakeBoxExecutable() {
1346 std::map<int, GObjectController*> selected = getSelectedObjects();
1347 if( selected.empty() )
1350 std::map<int, GObjectController*>::iterator it;
1351 for (it = selected.begin(); it != selected.end(); ++it) {
1352 GObjectController* lastSelected = it->second;
1354 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1355 GBlackBoxModel *bbmodel =
1356 (GBlackBoxModel*) lastSelected->getModel();
1357 view->setState(HIGHLIGHTED);
1358 if (bbmodel->isExecutable()) {
1359 bbmodel->setExecutable(false);
1361 bbmodel->setExecutable(true);
1363 bbmodel->notifyObservers(lastSelected->getId());
1371 //=========================================================================
1373 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1374 std::cout << "wxVtkSceneManager::getDiagramBBS" << std::endl;
1375 bool existsExec = false;
1377 std::vector<std::string> packages;
1378 std::vector<int> boxes;
1379 std::vector<int> connections;
1380 std::vector<int> execBoxes;
1382 std::map<int, GObjectController*>::iterator it;
1384 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1385 GObjectController *desc = it->second;
1386 int type = desc->getGObjectType();
1388 if (type == GBLACKBOX) {
1389 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1391 std::string pkg = mod->getBBTKPackage();
1392 bool existsPkg = false;
1393 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1394 if (packages[t] == pkg) {
1399 packages.push_back(pkg);
1402 boxes.push_back(it->first);
1403 if (mod->isExecutable()) {
1404 execBoxes.push_back(it->first);
1407 } else if (type == GCONNECTOR) {
1408 connections.push_back(it->first);
1413 std::string script = "";
1414 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1415 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1416 script += LineNumber(wln, lnNmbr) + "\n";
1418 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1419 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1421 for (i = 0; i < (int) packages.size(); i++) {
1422 script += LineNumber(wln, lnNmbr);
1423 script += "include ";
1424 script += packages[i];
1428 script += LineNumber(wln, lnNmbr);
1433 script += LineNumber(wln, lnNmbr);
1434 script += "author \"";
1438 script += LineNumber(wln, lnNmbr);
1439 script += "description \"";
1440 script += _Description;
1443 script += LineNumber(wln, lnNmbr);
1444 script += "category \"";
1445 script += _Category;
1448 script += LineNumber(wln, lnNmbr);
1451 // script+="include std\n"; // JPR
1453 for (i = 0; i < (int) boxes.size(); i++) {
1454 script += LineNumber(wln, lnNmbr);
1457 GObjectController *control = _controllers[id];
1458 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1460 script += model->getBBTKPackage()+":";
1461 script += model->getBBTKType();
1463 script += model->getBBTKName();
1466 std::vector<GPortModel*> inputs = model->getInputPorts();
1467 for (int j = 0; j < (int) inputs.size(); j++) {
1468 GPortModel* inputPort = inputs[j];
1469 if (inputPort->isValueSet()) {
1470 script += LineNumber(wln, lnNmbr);
1472 script += model->getBBTKName();
1474 script += inputPort->getBBTKName();
1476 script += inputPort->getValue();
1481 script += LineNumber(wln, lnNmbr);
1486 script += LineNumber(wln, lnNmbr);
1490 std::string complexInputs="";
1492 for (i = 0; i < (int) connections.size(); i++) {
1493 //script += LineNumber(wln, lnNmbr);
1494 //script += "connect ";
1495 int id = connections[i];
1496 GObjectController *control = _controllers[id];
1497 GConnectorModel *model = (GConnectorModel*) control->getModel();
1501 GPortModel *start = model->getStartPort();
1502 GBoxModel *startBox = start->getParentBox();
1504 GPortModel *end = model->getEndPort();
1505 GBoxModel *endBox = end->getParentBox();
1507 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1509 complexInputs += "input ";
1510 complexInputs += startBox->getBBTKName();
1512 complexInputs += " ";
1513 complexInputs += endBox->getBBTKName();
1514 complexInputs += ".";
1515 complexInputs += end->getBBTKName();
1517 complexInputs += " ";
1518 complexInputs += "\" \"";
1520 complexInputs += "\n";
1524 script += LineNumber(wln, lnNmbr);
1525 script += "connect ";
1526 script += startBox->getBBTKName();
1528 script += start->getBBTKName();
1532 //End Connection info
1533 script += endBox->getBBTKName();
1535 script += end->getBBTKName();
1540 script += LineNumber(wln, lnNmbr);
1544 script += LineNumber(wln, lnNmbr);
1547 script += LineNumber(wln, lnNmbr);
1550 script += LineNumber(wln, lnNmbr);
1551 script += "# Complex input ports\n";
1552 script += complexInputs;
1554 if((_MessageKind!="-")&&(_MessageLevel!="-")){
1555 script += LineNumber(wln, lnNmbr);
1556 script += "message ";
1557 script += _MessageKind;
1559 script += _MessageLevel;
1563 for (i = 0; i < (int) execBoxes.size(); i++) {
1564 script += LineNumber(wln, lnNmbr);
1566 int id = execBoxes[i];
1567 GObjectController *control = _controllers[id];
1568 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1570 script += model->getBBTKName();
1579 //=========================================================================
1581 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1582 std::cout<<"wxVtkSceneManager::saveComplexBoxBBS"<<std::endl;
1583 std::vector<std::string> packages;
1584 std::vector<int> boxes;
1585 std::vector<int> connections;
1586 std::vector<int> execBoxes;
1588 std::map<int, GObjectController*>::iterator it;
1590 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1591 GObjectController *desc = it->second;
1592 int type = desc->getGObjectType();
1594 if (type == GBLACKBOX) {
1595 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1597 std::string pkg = mod->getBBTKPackage();
1598 bool existsPkg = false;
1599 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1600 if (packages[t] == pkg) {
1605 packages.push_back(pkg);
1608 boxes.push_back(it->first);
1609 if (mod->isExecutable()) {
1610 execBoxes.push_back(it->first);
1612 } else if (type == GCONNECTOR) {
1613 connections.push_back(it->first);
1617 std::string script = "";
1619 script += "include std\n"; // EED
1620 script += "include itkvtk\n"; // EED
1622 for (i = 0; i < (int) packages.size(); i++) {
1623 script += "include ";
1624 script += packages[i];
1629 // Definition of a complex box
1630 script += "define ";
1631 script += _cbName + " " + _cbPackageName;
1635 script += "author \"";
1639 script += "description \"";
1640 script += _Description;
1644 script += "category \"";
1645 script += _Category;
1650 for (i = 0; i < (int) boxes.size(); i++) {
1653 GObjectController *control = _controllers[id];
1654 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1656 script += model->getBBTKPackage()+":";
1657 script += model->getBBTKType();
1659 script += model->getBBTKName();
1662 std::vector<GPortModel*> inputs = model->getInputPorts();
1663 for (int j = 0; j < (int) inputs.size(); j++) {
1664 GPortModel* inputPort = inputs[j];
1665 if (inputPort->isValueSet()) {
1667 script += model->getBBTKName();
1669 script += inputPort->getBBTKName();
1671 script += inputPort->getValue();
1679 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1681 std::string complexInputs = "";
1682 std::string complexOutputs = "";
1685 for (i = 0; i < (int) connections.size(); i++) {
1686 int id = connections[i];
1687 GObjectController *control = _controllers[id];
1688 GConnectorModel *model = (GConnectorModel*) control->getModel();
1691 GPortModel *start = model->getStartPort();
1692 GBoxModel *startBox = start->getParentBox();
1694 GPortModel *end = model->getEndPort();
1695 GBoxModel *endBox = end->getParentBox();
1697 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1698 complexInputs += "input ";
1699 complexInputs += startBox->getBBTKName();
1701 complexInputs += " ";
1702 complexInputs += endBox->getBBTKName();
1703 complexInputs += ".";
1704 complexInputs += end->getBBTKName();
1706 complexInputs += " ";
1707 complexInputs += "\" \"";
1709 complexInputs += "\n";
1710 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1711 complexOutputs += "output ";
1712 complexOutputs += endBox->getBBTKName();
1714 complexOutputs += " ";
1715 complexOutputs += startBox->getBBTKName();
1716 complexOutputs += ".";
1717 complexOutputs += start->getBBTKName();
1719 complexOutputs += " ";
1720 complexOutputs += "\" \"";
1722 complexOutputs += "\n";
1724 script += "connect ";
1725 script += startBox->getBBTKName();
1727 script += start->getBBTKName();
1731 //End Connection info
1732 script += endBox->getBBTKName();
1734 script += end->getBBTKName();
1741 script += "# Complex input ports\n";
1742 script += complexInputs;
1745 script += "# Complex output ports\n";
1746 script += complexOutputs;
1750 if((_MessageKind!="-")&&(_MessageLevel!="-"))
1752 script += "message ";
1753 script += _MessageKind;
1755 script += _MessageLevel;
1759 for (i = 0; i < (int) execBoxes.size(); i++)
1762 int id = execBoxes[i];
1763 GObjectController *control = _controllers[id];
1764 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1766 script += model->getBBTKName();
1771 script += "endefine";
1777 //=========================================================================
1779 void wxVtkSceneManager::deleteAllBoxes() {
1780 std::map<int, GObjectController*>::iterator it;
1781 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1782 GObjectController *cont = it->second;
1783 cont->removeFromScene();
1784 unregisterController((InteractorStyleMaracas*) cont);
1786 _selectedObjects.clear();
1787 _controllers.clear();
1790 //=========================================================================
1793 void wxVtkSceneManager::refresh() {
1794 _baseView->Refresh();
1796 //=========================================================================
1798 void wxVtkSceneManager::refreshScene()
1800 _baseView->RefreshView();
1803 //=========================================================================
1805 void wxVtkSceneManager::centerView()
1808 _baseView->GetRenderer()->ComputeVisiblePropBounds(bb);
1811 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1812 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1813 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1814 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1816 _baseView->GetRenderer()->ResetCamera();
1817 _baseView->GetRenderer()->ResetCameraClippingRange();
1820 double tt=_baseView->GetRenderer()->GetNearClippingPlaneTolerance();
1821 printf("EED wxVtkSceneManager::centerView() tolerance=%f\n",tt);
1823 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1824 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1825 _baseView->GetRenderer()->GetActiveCamera()->SetClippingRange(0.01,100000);
1826 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1827 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1830 _baseView->GetRenderer()->Render();
1833 //=========================================================================
1835 void wxVtkSceneManager::saveDiagram(std::string &content)
1839 content += "CATEGORY:";
1840 content += GetCategory();
1843 content += "DESCRIPTION:";
1844 content += GetDescription();
1847 content += "AUTHOR:";
1848 content += GetAuthor();
1851 //Print info IF COMPLEX BOX
1852 content += "COMPLEXBOX:";
1853 if (_isComplexBox) {
1854 content += "TRUE\n";
1856 content += "COMPLEXBOXNAME:";
1857 content += GetCbName();
1860 content += "PACKAGENAME:";
1861 content += GetCbPackageName();
1864 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1865 * External inputs are possible for applications and complex boxes
1866 //Print info complex input ports
1867 std::vector<int> inputs = getComplexInputPorts();
1868 int insize = inputs.size();
1869 content += "COMPLEXINPUTS:";
1870 sprintf(buffer, "%d", insize);
1874 for (int i = 0; i < insize; i++) {
1876 GObjectController *cont = _controllers[id];
1877 cont->getModel()->save(content);
1881 //Print info complex output ports
1882 std::vector<int> outputs = getComplexOutputPorts();
1883 int outsize = outputs.size();
1884 content += "COMPLEXOUTPUTS:";
1885 sprintf(buffer, "%d", outsize);
1889 for (int i = 0; i < outsize; i++) {
1890 int id = outputs[i];
1891 GObjectController *cont = _controllers[id];
1892 cont->getModel()->save(content);
1896 content += "FALSE\n";
1899 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1900 // External inputs are possible for applications and complex boxes
1901 std::vector<int> inputs = getComplexInputPorts();
1902 int insize = inputs.size();
1903 content += "COMPLEXINPUTS:";
1904 sprintf(buffer, "%d", insize);
1908 for (int i = 0; i < insize; i++) {
1910 GObjectController *cont = _controllers[id];
1911 cont->getModel()->save(content);
1915 std::vector<int> boxes = getBlackBoxes();
1916 int bsize = boxes.size();
1917 content += "BOXES:";
1918 sprintf(buffer, "%d", bsize);
1922 for (int i = 0; i < bsize; i++) {
1924 // std::cout<<"id "<<id<<std::endl;//CFT
1925 GObjectController *cont = _controllers[id];
1926 // std::cout<<"nombre: "<<cont->getStatusText()<<std::endl;//CFT
1927 // std::cout<<"tipo: "<<cont->getModel()->getBBTKType()<<std::endl;//CFT
1928 // //boxesDiagram[i] = cont->getModel()->getBBTKType();//CFT
1929 // std::cout<<"nname: "<<cont->getModel()->getBBTKName()<<std::endl;//CFT
1930 // std::cout<<"categorie: "<<GetCategory()<<std::endl;//CFT
1931 // std::cout<<"type: "<<cont->getModel()->getGObjectType()<<std::endl;//CFT
1932 cont->getModel()->save(content);
1936 std::vector<int> connections = getConnections();
1937 int csize = connections.size();
1938 content += "CONNECTIONS:";
1939 sprintf(buffer, "%d", csize);
1943 for (int i = 0; i < csize; i++) {
1944 int id = connections[i];
1945 GObjectController *cont = _controllers[id];
1946 cont->getModel()->save(content);
1951 //=========================================================================
1952 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1954 getline(inputStream, line,'\n');
1955 int size = line.length();
1958 if ( line[ size-1 ]==13 )
1960 line.erase(size-1,1);
1965 //=========================================================================
1966 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1969 std::string version = "<void>";
1970 std::string line = "";
1971 char delims[] = ":";
1972 char *result = NULL;
1973 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1975 getCleanLine(inputStream, line);
1978 while (!inputStream.eof()) {
1979 if (line == "" || line[0] == '#') {
1981 getCleanLine(inputStream, line);
1983 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1984 version = line.substr(18, 3);
1986 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1987 version = line.substr(18, 3);
1989 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1990 version = line.substr(18, 3);
1992 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1993 version = line.substr(18, 3);
1995 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1996 version = line.substr(18, 3);
1998 } else if (line == "APP_START") {
2007 if ((version != "1.0") && (version != "1.1")) {
2008 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
2009 char categoryTmp[30];
2010 strcpy(categoryTmp, line.c_str());
2011 result = strtok(categoryTmp, delims);
2012 result = strtok(NULL, delims);
2013 SetCategory(result);
2015 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
2016 char descriptionTmp[1024];
2017 strcpy(descriptionTmp, line.c_str());
2018 result = strtok(descriptionTmp, delims);
2019 result = strtok(NULL, delims);
2020 SetDescription(result);
2022 getCleanLine(inputStream, line);//AUTHOR:<author>
2023 char authorTmp[255];
2024 strcpy(authorTmp, line.c_str());
2025 result = strtok(authorTmp, delims);
2026 result = strtok(NULL, delims);
2031 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
2032 char complexTmp[30];
2033 strcpy(complexTmp, line.c_str());
2034 result = strtok(complexTmp, delims);
2035 result = strtok(NULL, delims);
2036 std::string isComplexBox(result);
2038 if (isComplexBox == "TRUE") {
2039 _isComplexBox = true;
2041 if ((version != "1.0") && (version != "1.1")) {
2042 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
2043 char complexboxnameTmp[255];
2044 strcpy(complexboxnameTmp, line.c_str());
2045 result = strtok(complexboxnameTmp, delims);
2046 result = strtok(NULL, delims);
2049 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
2050 char packagenameTmp[255];
2051 strcpy(packagenameTmp, line.c_str());
2052 result = strtok(packagenameTmp, delims);
2053 result = strtok(NULL, delims);
2054 SetCbPackageName(result);
2059 //-----------------------
2060 //- COMPLEX INPUT PORTS
2061 //-----------------------
2062 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2064 strcpy(inputs, line.c_str());
2065 result = strtok(inputs, delims);
2066 result = strtok(NULL, delims);
2069 std::istringstream inps(result);
2072 for (int i = 0; i < numInputs; i++) {
2074 getCleanLine(inputStream, line);//COMPLEX_PORT
2075 getCleanLine(inputStream, line);//name
2076 std::string inputPortName(line);
2079 getCleanLine(inputStream, line);//xInic:yInic:zInic
2081 strcpy(coord, line.c_str());
2082 result = strtok(coord, delims);//xInic
2083 std::string xInic(result);
2084 result = strtok(NULL, delims);//yInic
2085 std::string yInic(result);
2086 result = strtok(NULL, delims);//zInic
2087 std::string zInic(result);
2089 double xIn, yIn, zIn;
2090 std::istringstream xSt(xInic);
2092 std::istringstream ySt(yInic);
2094 std::istringstream zSt(zInic);
2099 if (zIn==900) zIn=GPOSITION_Z;
2102 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2104 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2106 } // for input complex box
2111 //-----------------------
2112 //- COMPLEX OUTPUT PORTS
2113 //-----------------------
2115 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2117 strcpy(outputs, line.c_str());
2118 result = strtok(outputs, delims);
2119 result = strtok(NULL, delims);
2122 std::istringstream outps(result);
2123 outps >> numOutputs;
2125 for (int i = 0; i < numOutputs; i++) {
2127 getCleanLine(inputStream, line);//COMPLEX_PORT
2128 getCleanLine(inputStream, line);//name
2129 std::string outputPortName(line);
2132 getCleanLine(inputStream, line);//xInic:yInic:zInic
2134 strcpy(coord, line.c_str());
2135 result = strtok(coord, delims);//xInic
2136 std::string xInic(result);
2137 result = strtok(NULL, delims);//yInic
2138 std::string yInic(result);
2139 result = strtok(NULL, delims);//zInic
2140 std::string zInic(result);
2142 double xIn, yIn, zIn;
2143 std::istringstream xSt(xInic);
2145 std::istringstream ySt(yInic);
2147 std::istringstream zSt(zInic);
2152 if (zIn==900) zIn=GPOSITION_Z;
2155 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2157 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2159 } // for output complex box
2163 // RaC2012 2nd Hackfest
2164 if(version >= "1.4")
2166 //-----------------------
2167 //- EXTERNAL INPUT PORTS
2168 //-----------------------
2169 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2171 strcpy(inputs, line.c_str());
2172 result = strtok(inputs, delims);
2173 result = strtok(NULL, delims);
2176 std::istringstream inps(result);
2179 for (int i = 0; i < numInputs; i++) {
2181 getCleanLine(inputStream, line);//COMPLEX_PORT
2182 getCleanLine(inputStream, line);//name
2183 std::string inputPortName(line);
2186 getCleanLine(inputStream, line);//xInic:yInic:zInic
2188 strcpy(coord, line.c_str());
2189 result = strtok(coord, delims);//xInic
2190 std::string xInic(result);
2191 result = strtok(NULL, delims);//yInic
2192 std::string yInic(result);
2193 result = strtok(NULL, delims);//zInic
2194 std::string zInic(result);
2196 double xIn, yIn, zIn;
2197 std::istringstream xSt(xInic);
2199 std::istringstream ySt(yInic);
2201 std::istringstream zSt(zInic);
2206 if (zIn==900) zIn=GPOSITION_Z;
2209 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2210 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2212 } // for external input
2217 getCleanLine(inputStream, line);//BOXES:num
2219 strcpy(boxes, line.c_str());
2220 result = strtok(boxes, delims);
2221 result = strtok(NULL, delims);
2224 std::istringstream is(result);
2227 for (int i = 0; i < numBoxes; i++)
2230 getCleanLine(inputStream, line);//BOX
2231 getCleanLine(inputStream, line);//package:type:name
2233 strcpy(box, line.c_str());
2234 result = strtok(box, delims);//package
2235 std::string package(result);
2236 result = strtok(NULL, delims);//type
2237 std::string type(result);
2238 result = strtok(NULL, delims);//name
2239 std::string name(result);
2242 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2244 strcpy(exec, line.c_str());
2245 result = strtok(exec, delims);//ISEXEC
2246 result = strtok(NULL, delims);//TRUE|FALSE
2247 std::string isExec(result);
2250 getCleanLine(inputStream, line);//xInic:yInic:zInic
2252 strcpy(coord, line.c_str());
2253 result = strtok(coord, delims);//xInic
2254 std::string xInic(result);
2255 result = strtok(NULL, delims);//yInic
2256 std::string yInic(result);
2257 result = strtok(NULL, delims);//zInic
2258 std::string zInic(result);
2260 double xIn, yIn, zIn;
2261 std::istringstream xSt(xInic);
2263 std::istringstream ySt(yInic);
2265 std::istringstream zSt(zInic);
2271 if (zIn==900) zIn=GPOSITION_Z;
2276 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2277 strcpy(coord, line.c_str());
2278 result = strtok(coord, delims);//xEnd
2279 std::string xEnd(result);
2280 result = strtok(NULL, delims);//yEnd
2281 std::string yEnd(result);
2282 result = strtok(NULL, delims);//zEnd
2283 std::string zEnd(result);
2285 double xEn, yEn, zEn;
2286 std::istringstream xEt(xEnd);
2288 std::istringstream yEt(yEnd);
2290 std::istringstream zEt(zEnd);
2295 if (zEn==900) zEn=GPOSITION_Z;
2299 bool boxExecutable = false;
2300 if (isExec == "TRUE")
2302 boxExecutable = true;
2305 int idBox = createGBlackBox(xIn, yIn, package, type);
2306 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2308 GObjectController *cont = _controllers[idBox];
2309 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2312 getCleanLine(inputStream, line);//PORT o FIN_BOX
2313 std::string port = line.substr(0, 4);
2314 while (port == "PORT")
2316 getCleanLine(inputStream, line);//name:value
2317 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2319 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2322 strcpy(poort, line.c_str());
2323 result = strtok(poort, delims);//name
2324 std::string name(result);
2326 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2327 result = strtok(NULL, delims);//value
2328 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2330 std::string tmpString=" ";
2331 tmpString[0]=34; // character "
2332 strcat(result,tmpString.c_str());
2334 std::string value(result);
2336 bbmod->setValueToInput(name, value);
2338 getCleanLine(inputStream, line);//PORT o FIN_BOX
2339 port = line.substr(0, 4);
2342 //EED bbmod->notifyObservers(_idManager);
2347 getCleanLine(inputStream, line);//CONNECTIONS:num
2349 strcpy(conns, line.c_str());
2350 result = strtok(conns, delims);
2351 result = strtok(NULL, delims);
2354 std::istringstream isCons(result);
2358 for (int i = 0; i < numConns; i++)
2361 getCleanLine(inputStream, line);//CONNECTION
2362 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2365 strcpy(connec, line.c_str());
2366 result = strtok(connec, delims);
2367 std::string nameStartBox(result);
2368 result = strtok(NULL, delims);
2369 std::string nameStartPort(result);
2370 result = strtok(NULL, delims);
2371 std::string nameEndBox(result);
2372 result = strtok(NULL, delims);
2373 std::string nameEndPort(result);
2375 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2377 if (version != "1.0") {
2378 //Readding control points of the manualContour
2379 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2380 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2381 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2382 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2383 strcpy(conns, line.c_str());
2384 result = strtok(conns, delims);
2385 result = strtok(NULL, delims);
2387 int numberOfControlPoints;
2388 std::istringstream isCons(result);
2389 isCons >> numberOfControlPoints;
2391 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2392 getCleanLine(inputStream, line); //XX:YY:ZZ
2394 strcpy(connec, line.c_str());
2397 result = strtok(connec, delims);
2398 std::istringstream isPointX(result);
2400 result = strtok(NULL, delims);
2401 std::istringstream isPointY(result);
2403 result = strtok(NULL, delims);
2404 std::istringstream isPointZ(result);
2409 if (pz==900) pz=GPOSITION_Z;
2412 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2413 conView->getManualContourView()->AddPoint();
2419 //=========================================================================
2422 //=========================================================================
2423 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2424 std::string portName, double xIn, double yIn, double zIn)
2427 if (inputoutput == true) {
2428 idPort = createGComplexBoxInputPort(portName);
2430 idPort = createGComplexBoxOutputPort(portName);
2432 GObjectController *cont = _controllers[idPort];
2433 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2434 cbmod->setInicPoint(xIn, yIn, zIn);
2435 cbmod->notifyObservers(_idManager);
2437 //=========================================================================
2440 //=========================================================================
2441 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2446 GBoxModel *boxModel = NULL;
2447 std::vector<int> lstB = getBlackBoxes();
2448 for (j = 0; j < (int) lstB.size(); j++) {
2450 bMod = (GBoxModel*) _controllers[idB]->getModel();
2451 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2459 if (boxModel == NULL) {
2460 std::vector<int> lstInputs = getComplexInputPorts();
2461 for (j = 0; j < (int) lstInputs.size(); j++) {
2463 bMod = (GBoxModel*) _controllers[idB]->getModel();
2464 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2472 std::vector<int> lstOutputs = getComplexOutputPorts();
2473 for (j = 0; j < (int) lstOutputs.size(); j++) {
2474 int idB = lstOutputs[j];
2475 bMod = (GBoxModel*) _controllers[idB]->getModel();
2476 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2488 //=========================================================================
2491 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2492 std::string nameStartPort, std::string nameEndBox,
2493 std::string nameEndPort) {
2495 GBoxModel *boxModel;
2496 GPortModel *startP = NULL;
2497 GPortModel *endP = NULL;
2499 boxModel = findGBox(nameStartBox);
2500 if(boxModel == NULL)
2502 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2504 if (boxModel != NULL) {
2505 startP = boxModel->getOutputPort(nameStartPort);
2507 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() );
2511 boxModel = findGBox(nameEndBox);
2512 if(boxModel == NULL)
2514 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2516 if (boxModel != NULL) {
2517 endP = boxModel->getInputPort(nameEndPort);
2519 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());
2524 int idCon = createGConnector(startP);
2526 _worldState = NOTHING_HAPPENS;
2527 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2529 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2530 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2531 tempp->endContourCreation();
2532 conMod->setEndPort(endP);
2533 conView->updateStartEndPoints();
2537 //=========================================================================
2539 bool wxVtkSceneManager::boxExist(std::string boxname) {
2541 std::map<int, GObjectController*>::iterator it;
2542 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2543 GObjectController *cont = it->second;
2544 if (cont->getModel()->getBBTKName() == boxname) {
2551 //=========================================================================
2553 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2554 std::vector<int> vect;
2555 std::map<int, GObjectController*>::iterator it;
2556 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2557 GObjectController *cont = it->second;
2558 if (cont->getGObjectType() == GBLACKBOX) {
2559 vect.push_back(cont->getId());
2565 //=========================================================================
2567 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2568 std::vector<int> vect;
2569 std::map<int, GObjectController*>::iterator it;
2570 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2571 GObjectController *cont = it->second;
2572 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2573 vect.push_back(cont->getId());
2579 //=========================================================================
2581 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2582 std::vector<int> vect;
2583 std::map<int, GObjectController*>::iterator it;
2584 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2585 GObjectController *cont = it->second;
2586 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2587 vect.push_back(cont->getId());
2593 //=========================================================================
2595 std::vector<int> wxVtkSceneManager::getConnections() {
2596 std::vector<int> vect;
2597 std::map<int, GObjectController*>::iterator it;
2598 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2599 GObjectController *cont = it->second;
2600 if (cont->getGObjectType() == GCONNECTOR) {
2601 vect.push_back(cont->getId());
2607 //=========================================================================
2609 bool wxVtkSceneManager::isComplexBox() {
2610 return _isComplexBox;
2613 //=========================================================================
2615 void wxVtkSceneManager::setComplexBox(bool val) {
2616 _isComplexBox = val;
2619 //=========================================================================
2621 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2622 //Register the controller of the new object
2623 registerController((InteractorStyleMaracas*) objController);
2624 //Add the object to the objects list
2625 int newId = _contLastId;//_controllers.size();
2626 objController->setId(newId);
2627 _controllers[newId] = objController;
2628 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2633 //=========================================================================
2635 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2637 std::map<int, int> oldIdNewIdBoxes;
2638 std::vector<int> connections;
2640 std::vector<int> newBoxesID;
2642 std::map<int, GObjectController*>::iterator it;
2643 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2644 GObjectController *cont = it->second;
2645 int type = cont->getGObjectType();
2647 if (type == GBLACKBOX) {
2649 double xInic, yInic, zInic;
2650 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2651 copyBox->getInicPoint(xInic, yInic, zInic);
2652 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2653 copyBox->getBBTKType());
2655 int idcB = copyBox->getObjectId();
2656 oldIdNewIdBoxes[idcB] = idBox;
2657 cont = _controllers[idBox];
2658 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2659 newbox->setInicPoint(xInic, yInic, zInic);
2660 int num = newbox->getNumInputPorts();
2661 for (int j = 0; j < num; j++) {
2662 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2664 newbox->move(xInic + 20, yInic + 20, zInic);
2665 newbox->notifyObservers(_idManager);
2666 newBoxesID.push_back(newbox->getObjectId());
2668 } else if (type == GCONNECTOR) {
2669 int idCon = cont->getId();
2670 connections.push_back(idCon);
2675 for (int i = 0; i < (int) connections.size(); i++) {
2676 int objId = connections[i];
2677 GObjectController *cont = objectsMap[objId];
2678 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2680 GPortModel* startPort = connectModel->getStartPort();
2681 int startPortIndex = startPort->getPosInBox();
2682 GPortModel* endPort = connectModel->getEndPort();
2683 int endPortIndex = endPort->getPosInBox();
2685 GBlackBoxModel* startPortParentBox =
2686 (GBlackBoxModel*) startPort->getParentBox();
2687 GBlackBoxModel* endPortParentBox =
2688 (GBlackBoxModel*) endPort->getParentBox();
2690 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2691 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2693 GBlackBoxModel* newStartBox =
2694 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2695 GBlackBoxModel* newEndBox =
2696 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2698 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2699 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2701 // Creates connection
2702 int idCon = createGConnector(newStartPort);
2703 GConnectorController *tempp =
2704 (GConnectorController*) _controllers[idCon];
2705 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2706 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2707 tempp->endContourCreation();
2708 conMod->setEndPort(newEndPort);
2709 conView->updateStartEndPoints();
2712 /// the new selected boxes are the duplicate ones
2714 UnSelectBlackBoxes();
2715 for (int i = 0; i < newBoxesID.size(); i++) {
2716 _selectedObjects.push_back(newBoxesID.at(i));
2719 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2720 int id = _selectedObjects[i];
2721 GObjectController* cont = _controllers[id];
2723 cont->getView()->setState(SELECTED);
2724 cont->getModel()->notifyObservers(_idManager);
2730 //=========================================================================
2732 int wxVtkSceneManager::getNumSelectedObjects() {
2733 return _selectedObjects.size();
2736 //=========================================================================
2738 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2739 std::map<int, GObjectController*> mapSelected;
2741 std::map<int, GObjectController*>::iterator it;
2742 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2743 GObjectController *cont = it->second;
2744 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2746 mapSelected[cont->getId()] = cont;
2750 std::map<int, GObjectController*>::iterator it2;
2751 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2752 GObjectController *cont = it2->second;
2753 if (cont->getGObjectType() == GCONNECTOR) {
2754 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2755 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2756 GBoxModel* startPortParentBox =
2757 cmod->getStartPort()->getParentBox();
2759 std::map<int, GObjectController*>::iterator iterOBJ1 =
2760 mapSelected.find(startPortParentBox->getObjectId());
2761 std::map<int, GObjectController*>::iterator iterOBJ2 =
2762 mapSelected.find(endPortParentBox->getObjectId());
2764 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2765 int ID = cont->getId();
2766 mapSelected[ID] = cont;
2773 //=========================================================================
2775 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2777 std::map<int, int> oldIdNewIdBoxes;
2778 std::vector<int> connections;
2780 std::map<int, GObjectController*>::iterator it;
2781 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2782 GObjectController *cont = it->second;
2783 int type = cont->getGObjectType();
2785 if (type == GBLACKBOX) {
2787 double xInic, yInic, zInic;
2788 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2789 copyBox->getInicPoint(xInic, yInic, zInic);
2790 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2792 int idcB = copyBox->getObjectId();
2793 oldIdNewIdBoxes[idcB] = idBox;
2794 cont = _controllers[idBox];
2795 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2796 newbox->setInicPoint(xInic, yInic, zInic);
2797 int num = newbox->getNumInputPorts();
2798 for (int j = 0; j < num; j++)
2800 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2802 newbox->notifyObservers(_idManager);
2803 } else if (type == GCONNECTOR) {
2804 int idCon = cont->getId();
2805 connections.push_back(idCon);
2810 for (int i = 0; i < (int) connections.size(); i++) {
2811 int objId = connections[i];
2812 GObjectController *cont = objectsMap[objId];
2813 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2815 GPortModel* startPort = connectModel->getStartPort();
2816 int startPortIndex = startPort->getPosInBox();
2817 GPortModel* endPort = connectModel->getEndPort();
2818 int endPortIndex = endPort->getPosInBox();
2820 GBlackBoxModel* startPortParentBox =
2821 (GBlackBoxModel*) startPort->getParentBox();
2822 GBlackBoxModel* endPortParentBox =
2823 (GBlackBoxModel*) endPort->getParentBox();
2825 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2826 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2828 GBlackBoxModel* newStartBox =
2829 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2830 GBlackBoxModel* newEndBox =
2831 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2833 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2834 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2836 // Creates connection
2837 int idCon = createGConnector(newStartPort);
2838 GConnectorController *tempp =
2839 (GConnectorController*) _controllers[idCon];
2840 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2841 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2842 tempp->endContourCreation();
2843 conMod->setEndPort(newEndPort);
2844 conView->updateStartEndPoints();
2847 std::map<int, int>::iterator itIds;
2848 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2849 int idOld = itIds->first;
2850 int idNew = itIds->second;
2852 GBlackBoxModel* oldBox =
2853 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2854 GBlackBoxModel* newBox =
2855 (GBlackBoxModel*) _controllers[idNew]->getModel();
2857 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2858 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2859 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2860 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2862 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2864 //EED int toCreate=-1;
2865 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2866 if (oldInputConnections[k] == newInputConnections[l]) {
2871 if (exist == false) {
2872 //Create complex input
2873 int posInBox = oldInputConnections[k];
2874 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2875 std::string inputPortName = inputPort->getBBTKName();
2876 int idInputPort = createGComplexBoxInputPort(inputPortName);
2877 GObjectController *cont = _controllers[idInputPort];
2878 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2879 double xIn, yIn, zIn;
2880 inputPort->getInicPoint(xIn, yIn, zIn);
2882 cbmod->setInicPoint(xIn, yIn, zIn);
2883 cbmod->notifyObservers(_idManager);
2885 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2887 // Creates connection
2888 int idCon = createGConnector(cbmod->getOutputPort(0));
2889 GConnectorController *tempp =
2890 (GConnectorController*) _controllers[idCon];
2891 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2892 vtkGConnectorView *conView =
2893 (vtkGConnectorView*) tempp->getView();
2894 tempp->endContourCreation();
2895 conMod->setEndPort(inputPortEnd);
2896 conView->updateStartEndPoints();
2902 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2904 //EED int toCreate=-1;
2905 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2906 if (oldOutputConnections[k] == newOutputConnections[l]) {
2911 if (exist == false) {
2912 //Create complex output
2913 int posInBox = oldOutputConnections[k];
2914 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2915 std::string outputPortName = outputPort->getBBTKName();
2916 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2917 GObjectController *cont = _controllers[idOutputPort];
2918 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2919 double xIn, yIn, zIn;
2920 outputPort->getInicPoint(xIn, yIn, zIn);
2922 cbmod->setInicPoint(xIn, yIn, zIn);
2923 cbmod->notifyObservers(_idManager);
2925 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2927 // Creates connection
2928 int idCon = createGConnector(outputPortEnd);
2929 GConnectorController *tempp =
2930 (GConnectorController*) _controllers[idCon];
2931 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2932 vtkGConnectorView *conView =
2933 (vtkGConnectorView*) tempp->getView();
2934 tempp->endContourCreation();
2935 conMod->setEndPort(cbmod->getInputPort(0));
2936 conView->updateStartEndPoints();
2946 //=========================================================================
2947 void wxVtkSceneManager::SetCbName(std::string cbName) {
2949 if (_cbName == "") {
2950 _cbName = "<complex box name>";
2954 //=========================================================================
2955 std::string wxVtkSceneManager::GetCbName() {
2959 //=========================================================================
2960 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2961 _cbPackageName = packagename;
2962 if (_cbPackageName == "") {
2963 _cbPackageName = "<package name of the complex box>";
2967 //=========================================================================
2968 std::string wxVtkSceneManager::GetCbPackageName() {
2969 return _cbPackageName;
2972 //=========================================================================
2973 void wxVtkSceneManager::SetAuthor(std::string author) {
2975 if (_Author == "") {
2976 _Author = "<author of the box>";
2980 //=========================================================================
2981 std::string wxVtkSceneManager::GetAuthor() {
2985 //=========================================================================
2986 void wxVtkSceneManager::SetCategory(std::string category) {
2987 _Category = category;
2988 if (_Category == "") {
2989 _Category = "<category of the box>";
2993 //=========================================================================
2994 std::string wxVtkSceneManager::GetCategory() {
2998 //=========================================================================
2999 void wxVtkSceneManager::SetDescription(std::string description) {
3000 _Description = description;
3001 if (_Description == "") {
3002 _Description = "<description of the box>";
3006 //=========================================================================
3007 std::string wxVtkSceneManager::GetDescription() {
3008 return _Description;
3011 //=========================================================================
3013 void wxVtkSceneManager::SetMessageKind(std::string kind) {
3014 _MessageKind = kind;
3018 //=========================================================================
3020 std::string wxVtkSceneManager::GetMessageKind(){
3021 return _MessageKind;
3024 //=========================================================================
3026 void wxVtkSceneManager::SetMessageLevel(std::string Level){
3027 _MessageLevel = Level;
3030 //=========================================================================
3032 std::string wxVtkSceneManager::GetMessageLevel(){
3033 return _MessageLevel;
3036 //=========================================================================
3038 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
3041 std::vector< std::string> extInputs;
3042 std::map<int, GObjectController*>::iterator it;
3043 for (it = _controllers.begin(); it != _controllers.end(); ++it)
3045 GObjectController *cont = it->second;
3046 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
3048 extInputs.push_back(cont->getModel()->getBBTKName());
3054 //=========================================================================
3058 void wxVtkSceneManager::printAll(int com , int sta ){
3060 int tmpState = sta ;
3061 if ( tmpState == NOTHING_HAPPENS ) {
3062 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
3064 if ( tmpState == HIGHLIGHTED ) {
3065 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
3067 if ( tmpState == POSSIBLE_CONNECTION ) {
3068 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
3070 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
3071 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
3073 if ( tmpState == CLICKED ) {
3074 std::cout << "CONTROLER STATE---->CLICKED\n" ;
3076 if ( tmpState == DRAG ) {
3077 std::cout << "CONTROLER STATE---->DRAG\n" ;
3079 if ( tmpState == SELECTED ) {
3080 std::cout << "CONTROLER STATE---->SELECTED\n" ;
3082 if ( tmpState == CREATING_CONTOUR ) {
3083 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
3089 if ( command == INIT_CREATION_CONTOUR ) {
3090 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
3092 if ( command == FIN_CREATION_CONTOUR ) {
3093 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
3095 if ( command == ADD_TO_SELECTED ) {
3096 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
3098 if ( command == DRAG_OBJECTS ) {
3099 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
3101 if ( command == EDIT_BLACKBOX ) {
3102 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
3104 if ( command == REMOVE_FROM_SELECTED ) {
3105 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
3111 } // EO namespace bbtk