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 crea::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 crea::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 crea::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());
1107 //=========================================================================
1109 bool wxVtkSceneManager::OnChar()
1113 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1114 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1116 // KeyCode 127 : Delete Key
1117 // KeyCode 8 : Backspace Key
1120 if (keyCode == 8 || keyCode == 127 || keyCode == 27)
1122 if (_worldState == INIT_CREATION_CONTOUR)
1125 UnSelectBlackBoxes();
1130 if (keyCode == 8 || keyCode == 127)
1133 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1135 int id = _selectedObjects[i];
1136 std::map<int, GObjectController*>::iterator it;
1137 it = _controllers.find(id);
1138 if (it != _controllers.end())
1140 oktmp = deleteObject(id);
1143 }// for selected objects
1144 if (ok) _selectedObjects.clear();
1145 _parent->saveTempandUpdate("delete object");
1150 if((keyCode==0) && (ctrlkey==1)) {
1155 if(_selectedObjects.size()){
1156 std::cout<<"objects to copy :";
1157 for(int i=0;i<_selectedObjects.size();i++)
1159 std::cout<<_selectedObjects.at(i)<<" ";
1161 DuplicateObjects(getSelectedObjects());
1163 std::cout<<"No objects to copy\n";
1164 } // _selectedObjects.size
1170 //=========================================================================
1172 void wxVtkSceneManager::AddControlerToBeRemove(
1173 std::vector<int> *controllersToRemove, int id) {
1177 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1178 if (id == (*controllersToRemove)[i]) {
1184 controllersToRemove->push_back(id);
1189 //=========================================================================
1191 bool wxVtkSceneManager::deleteObject(int id)
1194 GObjectController *control = _controllers[id];
1195 std::vector<int> controllersToRemove;
1196 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1197 == GCOMPLEXINPUTPORT || control->getGObjectType()
1198 == GCOMPLEXOUTPUTPORT) {
1199 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1200 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1202 bool boxConnected = false;
1204 // Add box input controllers to be removed
1205 for (int i = 0; i < (int) inputs.size(); i++) {
1206 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1207 if (inputs[i]->isConnected()) {
1208 boxConnected = true;
1212 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1214 // Add box output controllers to be removed
1215 for (int i = 0; i < (int) outputs.size(); i++) {
1216 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1217 if (outputs[i]->isConnected()) {
1218 boxConnected = true;
1222 // Add connection controllers to be removed
1223 std::map<int, GObjectController*>::iterator it;
1224 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1225 GObjectController *cont = it->second;
1226 int type = cont->getGObjectType();
1227 if (type == GCONNECTOR) {
1228 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1229 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1231 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1233 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1235 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1240 // Add box controller to be removed
1241 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1242 } else if (control->getGObjectType() == GCONNECTOR) {
1243 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1244 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1246 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1247 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1249 gconnectorcontroler->getManualContourController()->OnChar();
1254 std::map<int, GObjectController*>::iterator it;
1256 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1257 int key = controllersToRemove[i];
1258 it = _controllers.find(key);
1259 GObjectController *cont = _controllers[key];
1261 cont->removeFromScene();
1262 unregisterController((InteractorStyleMaracas*) cont);
1263 _controllers.erase(it);
1271 //=========================================================================
1273 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1274 std::string boxName) {
1275 _parent->displayBlackBoxInfo(packageName, boxName);
1278 //=========================================================================
1280 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1281 _parent->updateStatusBar(textStatus);
1284 //=========================================================================
1285 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1286 std::string result = "";
1287 if (withLineNumber == true) {
1289 stringstream StrStream;
1291 std::string strValue = StrStream.str();
1294 } else if (value < 100) {
1298 result += strValue + ": ";
1302 //=========================================================================
1304 bool wxVtkSceneManager::MakeBoxExecutable() {
1305 std::map<int, GObjectController*> selected = getSelectedObjects();
1306 if( selected.empty() )
1309 std::map<int, GObjectController*>::iterator it;
1310 for (it = selected.begin(); it != selected.end(); ++it) {
1311 GObjectController* lastSelected = it->second;
1313 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1314 GBlackBoxModel *bbmodel =
1315 (GBlackBoxModel*) lastSelected->getModel();
1316 view->setState(HIGHLIGHTED);
1317 if (bbmodel->isExecutable()) {
1318 bbmodel->setExecutable(false);
1320 bbmodel->setExecutable(true);
1322 bbmodel->notifyObservers(lastSelected->getId());
1330 //=========================================================================
1332 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1333 std::cout << "wxVtkSceneManager::getDiagramBBS" << std::endl;
1334 bool existsExec = false;
1336 std::vector<std::string> packages;
1337 std::vector<int> boxes;
1338 std::vector<int> connections;
1339 std::vector<int> execBoxes;
1341 std::map<int, GObjectController*>::iterator it;
1343 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1344 GObjectController *desc = it->second;
1345 int type = desc->getGObjectType();
1347 if (type == GBLACKBOX) {
1348 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1350 std::string pkg = mod->getBBTKPackage();
1351 bool existsPkg = false;
1352 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1353 if (packages[t] == pkg) {
1358 packages.push_back(pkg);
1361 boxes.push_back(it->first);
1362 if (mod->isExecutable()) {
1363 execBoxes.push_back(it->first);
1366 } else if (type == GCONNECTOR) {
1367 connections.push_back(it->first);
1372 std::string script = "";
1373 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1374 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1375 script += LineNumber(wln, lnNmbr) + "\n";
1377 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1378 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1380 for (i = 0; i < (int) packages.size(); i++) {
1381 script += LineNumber(wln, lnNmbr);
1382 script += "include ";
1383 script += packages[i];
1387 script += LineNumber(wln, lnNmbr);
1392 script += LineNumber(wln, lnNmbr);
1393 script += "author \"";
1397 script += LineNumber(wln, lnNmbr);
1398 script += "description \"";
1399 script += _Description;
1402 script += LineNumber(wln, lnNmbr);
1403 script += "category \"";
1404 script += _Category;
1407 script += LineNumber(wln, lnNmbr);
1410 // script+="include std\n"; // JPR
1412 for (i = 0; i < (int) boxes.size(); i++) {
1413 script += LineNumber(wln, lnNmbr);
1416 GObjectController *control = _controllers[id];
1417 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1419 script += model->getBBTKPackage()+":";
1420 script += model->getBBTKType();
1422 script += model->getBBTKName();
1425 std::vector<GPortModel*> inputs = model->getInputPorts();
1426 for (int j = 0; j < (int) inputs.size(); j++) {
1427 GPortModel* inputPort = inputs[j];
1428 if (inputPort->isValueSet()) {
1429 script += LineNumber(wln, lnNmbr);
1431 script += model->getBBTKName();
1433 script += inputPort->getBBTKName();
1435 script += inputPort->getValue();
1440 script += LineNumber(wln, lnNmbr);
1445 script += LineNumber(wln, lnNmbr);
1449 std::string complexInputs="";
1451 for (i = 0; i < (int) connections.size(); i++) {
1452 //script += LineNumber(wln, lnNmbr);
1453 //script += "connect ";
1454 int id = connections[i];
1455 GObjectController *control = _controllers[id];
1456 GConnectorModel *model = (GConnectorModel*) control->getModel();
1460 GPortModel *start = model->getStartPort();
1461 GBoxModel *startBox = start->getParentBox();
1463 GPortModel *end = model->getEndPort();
1464 GBoxModel *endBox = end->getParentBox();
1466 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1468 complexInputs += "input ";
1469 complexInputs += startBox->getBBTKName();
1471 complexInputs += " ";
1472 complexInputs += endBox->getBBTKName();
1473 complexInputs += ".";
1474 complexInputs += end->getBBTKName();
1476 complexInputs += " ";
1477 complexInputs += "\" \"";
1479 complexInputs += "\n";
1483 script += LineNumber(wln, lnNmbr);
1484 script += "connect ";
1485 script += startBox->getBBTKName();
1487 script += start->getBBTKName();
1491 //End Connection info
1492 script += endBox->getBBTKName();
1494 script += end->getBBTKName();
1499 script += LineNumber(wln, lnNmbr);
1503 script += LineNumber(wln, lnNmbr);
1506 script += LineNumber(wln, lnNmbr);
1509 script += LineNumber(wln, lnNmbr);
1510 script += "# Complex input ports\n";
1511 script += complexInputs;
1513 if((_MessageKind!="-")&&(_MessageLevel!="-")){
1514 script += LineNumber(wln, lnNmbr);
1515 script += "message ";
1516 script += _MessageKind;
1518 script += _MessageLevel;
1522 for (i = 0; i < (int) execBoxes.size(); i++) {
1523 script += LineNumber(wln, lnNmbr);
1525 int id = execBoxes[i];
1526 GObjectController *control = _controllers[id];
1527 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1529 script += model->getBBTKName();
1538 //=========================================================================
1540 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1541 std::cout<<"wxVtkSceneManager::saveComplexBoxBBS"<<std::endl;
1542 std::vector<std::string> packages;
1543 std::vector<int> boxes;
1544 std::vector<int> connections;
1545 std::vector<int> execBoxes;
1547 std::map<int, GObjectController*>::iterator it;
1549 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1550 GObjectController *desc = it->second;
1551 int type = desc->getGObjectType();
1553 if (type == GBLACKBOX) {
1554 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1556 std::string pkg = mod->getBBTKPackage();
1557 bool existsPkg = false;
1558 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1559 if (packages[t] == pkg) {
1564 packages.push_back(pkg);
1567 boxes.push_back(it->first);
1568 if (mod->isExecutable()) {
1569 execBoxes.push_back(it->first);
1571 } else if (type == GCONNECTOR) {
1572 connections.push_back(it->first);
1576 std::string script = "";
1578 script += "include std\n"; // EED
1579 script += "include itkvtk\n"; // EED
1581 for (i = 0; i < (int) packages.size(); i++) {
1582 script += "include ";
1583 script += packages[i];
1588 // Definition of a complex box
1589 script += "define ";
1590 script += _cbName + " " + _cbPackageName;
1594 script += "author \"";
1598 script += "description \"";
1599 script += _Description;
1603 script += "category \"";
1604 script += _Category;
1609 for (i = 0; i < (int) boxes.size(); i++) {
1612 GObjectController *control = _controllers[id];
1613 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1615 script += model->getBBTKPackage()+":";
1616 script += model->getBBTKType();
1618 script += model->getBBTKName();
1621 std::vector<GPortModel*> inputs = model->getInputPorts();
1622 for (int j = 0; j < (int) inputs.size(); j++) {
1623 GPortModel* inputPort = inputs[j];
1624 if (inputPort->isValueSet()) {
1626 script += model->getBBTKName();
1628 script += inputPort->getBBTKName();
1630 script += inputPort->getValue();
1638 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1640 std::string complexInputs = "";
1641 std::string complexOutputs = "";
1644 for (i = 0; i < (int) connections.size(); i++) {
1645 int id = connections[i];
1646 GObjectController *control = _controllers[id];
1647 GConnectorModel *model = (GConnectorModel*) control->getModel();
1650 GPortModel *start = model->getStartPort();
1651 GBoxModel *startBox = start->getParentBox();
1653 GPortModel *end = model->getEndPort();
1654 GBoxModel *endBox = end->getParentBox();
1656 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1657 complexInputs += "input ";
1658 complexInputs += startBox->getBBTKName();
1660 complexInputs += " ";
1661 complexInputs += endBox->getBBTKName();
1662 complexInputs += ".";
1663 complexInputs += end->getBBTKName();
1665 complexInputs += " ";
1666 complexInputs += "\" \"";
1668 complexInputs += "\n";
1669 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1670 complexOutputs += "output ";
1671 complexOutputs += endBox->getBBTKName();
1673 complexOutputs += " ";
1674 complexOutputs += startBox->getBBTKName();
1675 complexOutputs += ".";
1676 complexOutputs += start->getBBTKName();
1678 complexOutputs += " ";
1679 complexOutputs += "\" \"";
1681 complexOutputs += "\n";
1683 script += "connect ";
1684 script += startBox->getBBTKName();
1686 script += start->getBBTKName();
1690 //End Connection info
1691 script += endBox->getBBTKName();
1693 script += end->getBBTKName();
1700 script += "# Complex input ports\n";
1701 script += complexInputs;
1704 script += "# Complex output ports\n";
1705 script += complexOutputs;
1709 if((_MessageKind!="-")&&(_MessageLevel!="-"))
1711 script += "message ";
1712 script += _MessageKind;
1714 script += _MessageLevel;
1718 for (i = 0; i < (int) execBoxes.size(); i++)
1721 int id = execBoxes[i];
1722 GObjectController *control = _controllers[id];
1723 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1725 script += model->getBBTKName();
1730 script += "endefine";
1736 //=========================================================================
1738 void wxVtkSceneManager::deleteAllBoxes() {
1739 std::map<int, GObjectController*>::iterator it;
1740 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1741 GObjectController *cont = it->second;
1742 cont->removeFromScene();
1743 unregisterController((InteractorStyleMaracas*) cont);
1745 _selectedObjects.clear();
1746 _controllers.clear();
1749 //=========================================================================
1752 void wxVtkSceneManager::refresh() {
1753 _baseView->Refresh();
1755 //=========================================================================
1757 void wxVtkSceneManager::refreshScene()
1759 _baseView->RefreshView();
1762 //=========================================================================
1764 void wxVtkSceneManager::centerView()
1767 _baseView->GetRenderer()->ComputeVisiblePropBounds(bb);
1770 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1771 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1772 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1773 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1775 _baseView->GetRenderer()->ResetCamera();
1776 _baseView->GetRenderer()->ResetCameraClippingRange();
1779 double tt=_baseView->GetRenderer()->GetNearClippingPlaneTolerance();
1780 printf("EED wxVtkSceneManager::centerView() tolerance=%f\n",tt);
1782 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1783 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1784 _baseView->GetRenderer()->GetActiveCamera()->SetClippingRange(0.01,100000);
1785 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1786 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1789 _baseView->GetRenderer()->Render();
1792 //=========================================================================
1794 void wxVtkSceneManager::saveDiagram(std::string &content)
1798 content += "CATEGORY:";
1799 content += GetCategory();
1802 content += "DESCRIPTION:";
1803 content += GetDescription();
1806 content += "AUTHOR:";
1807 content += GetAuthor();
1810 //Print info IF COMPLEX BOX
1811 content += "COMPLEXBOX:";
1812 if (_isComplexBox) {
1813 content += "TRUE\n";
1815 content += "COMPLEXBOXNAME:";
1816 content += GetCbName();
1819 content += "PACKAGENAME:";
1820 content += GetCbPackageName();
1823 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1824 * External inputs are possible for applications and complex boxes
1825 //Print info complex input ports
1826 std::vector<int> inputs = getComplexInputPorts();
1827 int insize = inputs.size();
1828 content += "COMPLEXINPUTS:";
1829 sprintf(buffer, "%d", insize);
1833 for (int i = 0; i < insize; i++) {
1835 GObjectController *cont = _controllers[id];
1836 cont->getModel()->save(content);
1840 //Print info complex output ports
1841 std::vector<int> outputs = getComplexOutputPorts();
1842 int outsize = outputs.size();
1843 content += "COMPLEXOUTPUTS:";
1844 sprintf(buffer, "%d", outsize);
1848 for (int i = 0; i < outsize; i++) {
1849 int id = outputs[i];
1850 GObjectController *cont = _controllers[id];
1851 cont->getModel()->save(content);
1855 content += "FALSE\n";
1858 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1859 // External inputs are possible for applications and complex boxes
1860 std::vector<int> inputs = getComplexInputPorts();
1861 int insize = inputs.size();
1862 content += "COMPLEXINPUTS:";
1863 sprintf(buffer, "%d", insize);
1867 for (int i = 0; i < insize; i++) {
1869 GObjectController *cont = _controllers[id];
1870 cont->getModel()->save(content);
1874 std::vector<int> boxes = getBlackBoxes();
1875 int bsize = boxes.size();
1876 content += "BOXES:";
1877 sprintf(buffer, "%d", bsize);
1881 for (int i = 0; i < bsize; i++) {
1883 // std::cout<<"id "<<id<<std::endl;//CFT
1884 GObjectController *cont = _controllers[id];
1885 // std::cout<<"nombre: "<<cont->getStatusText()<<std::endl;//CFT
1886 // std::cout<<"tipo: "<<cont->getModel()->getBBTKType()<<std::endl;//CFT
1887 // //boxesDiagram[i] = cont->getModel()->getBBTKType();//CFT
1888 // std::cout<<"nname: "<<cont->getModel()->getBBTKName()<<std::endl;//CFT
1889 // std::cout<<"categorie: "<<GetCategory()<<std::endl;//CFT
1890 // std::cout<<"type: "<<cont->getModel()->getGObjectType()<<std::endl;//CFT
1891 cont->getModel()->save(content);
1895 std::vector<int> connections = getConnections();
1896 int csize = connections.size();
1897 content += "CONNECTIONS:";
1898 sprintf(buffer, "%d", csize);
1902 for (int i = 0; i < csize; i++) {
1903 int id = connections[i];
1904 GObjectController *cont = _controllers[id];
1905 cont->getModel()->save(content);
1910 //=========================================================================
1911 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1913 getline(inputStream, line,'\n');
1914 int size = line.length();
1917 if ( line[ size-1 ]==13 )
1919 line.erase(size-1,1);
1924 //=========================================================================
1925 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1928 std::string version = "<void>";
1929 std::string line = "";
1930 char delims[] = ":";
1931 char *result = NULL;
1932 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1934 getCleanLine(inputStream, line);
1937 while (!inputStream.eof()) {
1938 if (line == "" || line[0] == '#') {
1940 getCleanLine(inputStream, line);
1942 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1943 version = line.substr(18, 3);
1945 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1946 version = line.substr(18, 3);
1948 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1949 version = line.substr(18, 3);
1951 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1952 version = line.substr(18, 3);
1954 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1955 version = line.substr(18, 3);
1957 } else if (line == "APP_START") {
1966 if ((version != "1.0") && (version != "1.1")) {
1967 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1968 char categoryTmp[30];
1969 strcpy(categoryTmp, line.c_str());
1970 result = strtok(categoryTmp, delims);
1971 result = strtok(NULL, delims);
1972 SetCategory(result);
1974 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1975 char descriptionTmp[1024];
1976 strcpy(descriptionTmp, line.c_str());
1977 result = strtok(descriptionTmp, delims);
1978 result = strtok(NULL, delims);
1979 SetDescription(result);
1981 getCleanLine(inputStream, line);//AUTHOR:<author>
1982 char authorTmp[255];
1983 strcpy(authorTmp, line.c_str());
1984 result = strtok(authorTmp, delims);
1985 result = strtok(NULL, delims);
1990 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1991 char complexTmp[30];
1992 strcpy(complexTmp, line.c_str());
1993 result = strtok(complexTmp, delims);
1994 result = strtok(NULL, delims);
1995 std::string isComplexBox(result);
1997 if (isComplexBox == "TRUE") {
1998 _isComplexBox = true;
2000 if ((version != "1.0") && (version != "1.1")) {
2001 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
2002 char complexboxnameTmp[255];
2003 strcpy(complexboxnameTmp, line.c_str());
2004 result = strtok(complexboxnameTmp, delims);
2005 result = strtok(NULL, delims);
2008 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
2009 char packagenameTmp[255];
2010 strcpy(packagenameTmp, line.c_str());
2011 result = strtok(packagenameTmp, delims);
2012 result = strtok(NULL, delims);
2013 SetCbPackageName(result);
2018 //-----------------------
2019 //- COMPLEX INPUT PORTS
2020 //-----------------------
2021 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2023 strcpy(inputs, line.c_str());
2024 result = strtok(inputs, delims);
2025 result = strtok(NULL, delims);
2028 std::istringstream inps(result);
2031 for (int i = 0; i < numInputs; i++) {
2033 getCleanLine(inputStream, line);//COMPLEX_PORT
2034 getCleanLine(inputStream, line);//name
2035 std::string inputPortName(line);
2038 getCleanLine(inputStream, line);//xInic:yInic:zInic
2040 strcpy(coord, line.c_str());
2041 result = strtok(coord, delims);//xInic
2042 std::string xInic(result);
2043 result = strtok(NULL, delims);//yInic
2044 std::string yInic(result);
2045 result = strtok(NULL, delims);//zInic
2046 std::string zInic(result);
2048 double xIn, yIn, zIn;
2049 std::istringstream xSt(xInic);
2051 std::istringstream ySt(yInic);
2053 std::istringstream zSt(zInic);
2058 if (zIn==900) zIn=GPOSITION_Z;
2061 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2063 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2065 } // for input complex box
2070 //-----------------------
2071 //- COMPLEX OUTPUT PORTS
2072 //-----------------------
2074 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2076 strcpy(outputs, line.c_str());
2077 result = strtok(outputs, delims);
2078 result = strtok(NULL, delims);
2081 std::istringstream outps(result);
2082 outps >> numOutputs;
2084 for (int i = 0; i < numOutputs; i++) {
2086 getCleanLine(inputStream, line);//COMPLEX_PORT
2087 getCleanLine(inputStream, line);//name
2088 std::string outputPortName(line);
2091 getCleanLine(inputStream, line);//xInic:yInic:zInic
2093 strcpy(coord, line.c_str());
2094 result = strtok(coord, delims);//xInic
2095 std::string xInic(result);
2096 result = strtok(NULL, delims);//yInic
2097 std::string yInic(result);
2098 result = strtok(NULL, delims);//zInic
2099 std::string zInic(result);
2101 double xIn, yIn, zIn;
2102 std::istringstream xSt(xInic);
2104 std::istringstream ySt(yInic);
2106 std::istringstream zSt(zInic);
2111 if (zIn==900) zIn=GPOSITION_Z;
2114 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2116 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2118 } // for output complex box
2122 // RaC2012 2nd Hackfest
2123 if(version >= "1.4")
2125 //-----------------------
2126 //- EXTERNAL INPUT PORTS
2127 //-----------------------
2128 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2130 strcpy(inputs, line.c_str());
2131 result = strtok(inputs, delims);
2132 result = strtok(NULL, delims);
2135 std::istringstream inps(result);
2138 for (int i = 0; i < numInputs; i++) {
2140 getCleanLine(inputStream, line);//COMPLEX_PORT
2141 getCleanLine(inputStream, line);//name
2142 std::string inputPortName(line);
2145 getCleanLine(inputStream, line);//xInic:yInic:zInic
2147 strcpy(coord, line.c_str());
2148 result = strtok(coord, delims);//xInic
2149 std::string xInic(result);
2150 result = strtok(NULL, delims);//yInic
2151 std::string yInic(result);
2152 result = strtok(NULL, delims);//zInic
2153 std::string zInic(result);
2155 double xIn, yIn, zIn;
2156 std::istringstream xSt(xInic);
2158 std::istringstream ySt(yInic);
2160 std::istringstream zSt(zInic);
2165 if (zIn==900) zIn=GPOSITION_Z;
2168 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2169 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2171 } // for external input
2176 getCleanLine(inputStream, line);//BOXES:num
2178 strcpy(boxes, line.c_str());
2179 result = strtok(boxes, delims);
2180 result = strtok(NULL, delims);
2183 std::istringstream is(result);
2186 for (int i = 0; i < numBoxes; i++)
2189 getCleanLine(inputStream, line);//BOX
2190 getCleanLine(inputStream, line);//package:type:name
2192 strcpy(box, line.c_str());
2193 result = strtok(box, delims);//package
2194 std::string package(result);
2195 result = strtok(NULL, delims);//type
2196 std::string type(result);
2197 result = strtok(NULL, delims);//name
2198 std::string name(result);
2201 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2203 strcpy(exec, line.c_str());
2204 result = strtok(exec, delims);//ISEXEC
2205 result = strtok(NULL, delims);//TRUE|FALSE
2206 std::string isExec(result);
2209 getCleanLine(inputStream, line);//xInic:yInic:zInic
2211 strcpy(coord, line.c_str());
2212 result = strtok(coord, delims);//xInic
2213 std::string xInic(result);
2214 result = strtok(NULL, delims);//yInic
2215 std::string yInic(result);
2216 result = strtok(NULL, delims);//zInic
2217 std::string zInic(result);
2219 double xIn, yIn, zIn;
2220 std::istringstream xSt(xInic);
2222 std::istringstream ySt(yInic);
2224 std::istringstream zSt(zInic);
2230 if (zIn==900) zIn=GPOSITION_Z;
2235 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2236 strcpy(coord, line.c_str());
2237 result = strtok(coord, delims);//xEnd
2238 std::string xEnd(result);
2239 result = strtok(NULL, delims);//yEnd
2240 std::string yEnd(result);
2241 result = strtok(NULL, delims);//zEnd
2242 std::string zEnd(result);
2244 double xEn, yEn, zEn;
2245 std::istringstream xEt(xEnd);
2247 std::istringstream yEt(yEnd);
2249 std::istringstream zEt(zEnd);
2254 if (zEn==900) zEn=GPOSITION_Z;
2258 bool boxExecutable = false;
2259 if (isExec == "TRUE")
2261 boxExecutable = true;
2264 int idBox = createGBlackBox(xIn, yIn, package, type);
2265 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2267 GObjectController *cont = _controllers[idBox];
2268 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2271 getCleanLine(inputStream, line);//PORT o FIN_BOX
2272 std::string port = line.substr(0, 4);
2273 while (port == "PORT")
2275 getCleanLine(inputStream, line);//name:value
2276 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2278 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2281 strcpy(poort, line.c_str());
2282 result = strtok(poort, delims);//name
2283 std::string name(result);
2285 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2286 result = strtok(NULL, delims);//value
2287 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2289 std::string tmpString=" ";
2290 tmpString[0]=34; // character "
2291 strcat(result,tmpString.c_str());
2293 std::string value(result);
2295 bbmod->setValueToInput(name, value);
2297 getCleanLine(inputStream, line);//PORT o FIN_BOX
2298 port = line.substr(0, 4);
2301 //EED bbmod->notifyObservers(_idManager);
2306 getCleanLine(inputStream, line);//CONNECTIONS:num
2308 strcpy(conns, line.c_str());
2309 result = strtok(conns, delims);
2310 result = strtok(NULL, delims);
2313 std::istringstream isCons(result);
2317 for (int i = 0; i < numConns; i++)
2320 getCleanLine(inputStream, line);//CONNECTION
2321 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2324 strcpy(connec, line.c_str());
2325 result = strtok(connec, delims);
2326 std::string nameStartBox(result);
2327 result = strtok(NULL, delims);
2328 std::string nameStartPort(result);
2329 result = strtok(NULL, delims);
2330 std::string nameEndBox(result);
2331 result = strtok(NULL, delims);
2332 std::string nameEndPort(result);
2334 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2336 if (version != "1.0") {
2337 //Readding control points of the manualContour
2338 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2339 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2340 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2341 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2342 strcpy(conns, line.c_str());
2343 result = strtok(conns, delims);
2344 result = strtok(NULL, delims);
2346 int numberOfControlPoints;
2347 std::istringstream isCons(result);
2348 isCons >> numberOfControlPoints;
2350 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2351 getCleanLine(inputStream, line); //XX:YY:ZZ
2353 strcpy(connec, line.c_str());
2356 result = strtok(connec, delims);
2357 std::istringstream isPointX(result);
2359 result = strtok(NULL, delims);
2360 std::istringstream isPointY(result);
2362 result = strtok(NULL, delims);
2363 std::istringstream isPointZ(result);
2368 if (pz==900) pz=GPOSITION_Z;
2371 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2372 conView->getManualContourView()->AddPoint();
2378 //=========================================================================
2381 //=========================================================================
2382 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2383 std::string portName, double xIn, double yIn, double zIn)
2386 if (inputoutput == true) {
2387 idPort = createGComplexBoxInputPort(portName);
2389 idPort = createGComplexBoxOutputPort(portName);
2391 GObjectController *cont = _controllers[idPort];
2392 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2393 cbmod->setInicPoint(xIn, yIn, zIn);
2394 cbmod->notifyObservers(_idManager);
2396 //=========================================================================
2399 //=========================================================================
2400 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2405 GBoxModel *boxModel = NULL;
2406 std::vector<int> lstB = getBlackBoxes();
2407 for (j = 0; j < (int) lstB.size(); j++) {
2409 bMod = (GBoxModel*) _controllers[idB]->getModel();
2410 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2418 if (boxModel == NULL) {
2419 std::vector<int> lstInputs = getComplexInputPorts();
2420 for (j = 0; j < (int) lstInputs.size(); j++) {
2422 bMod = (GBoxModel*) _controllers[idB]->getModel();
2423 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2431 std::vector<int> lstOutputs = getComplexOutputPorts();
2432 for (j = 0; j < (int) lstOutputs.size(); j++) {
2433 int idB = lstOutputs[j];
2434 bMod = (GBoxModel*) _controllers[idB]->getModel();
2435 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2447 //=========================================================================
2450 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2451 std::string nameStartPort, std::string nameEndBox,
2452 std::string nameEndPort) {
2454 GBoxModel *boxModel;
2455 GPortModel *startP = NULL;
2456 GPortModel *endP = NULL;
2458 boxModel = findGBox(nameStartBox);
2459 if(boxModel == NULL)
2461 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2463 if (boxModel != NULL) {
2464 startP = boxModel->getOutputPort(nameStartPort);
2466 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() );
2470 boxModel = findGBox(nameEndBox);
2471 if(boxModel == NULL)
2473 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2475 if (boxModel != NULL) {
2476 endP = boxModel->getInputPort(nameEndPort);
2478 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());
2483 int idCon = createGConnector(startP);
2485 _worldState = NOTHING_HAPPENS;
2486 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2488 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2489 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2490 tempp->endContourCreation();
2491 conMod->setEndPort(endP);
2492 conView->updateStartEndPoints();
2496 //=========================================================================
2498 bool wxVtkSceneManager::boxExist(std::string boxname) {
2500 std::map<int, GObjectController*>::iterator it;
2501 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2502 GObjectController *cont = it->second;
2503 if (cont->getModel()->getBBTKName() == boxname) {
2510 //=========================================================================
2512 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2513 std::vector<int> vect;
2514 std::map<int, GObjectController*>::iterator it;
2515 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2516 GObjectController *cont = it->second;
2517 if (cont->getGObjectType() == GBLACKBOX) {
2518 vect.push_back(cont->getId());
2524 //=========================================================================
2526 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2527 std::vector<int> vect;
2528 std::map<int, GObjectController*>::iterator it;
2529 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2530 GObjectController *cont = it->second;
2531 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2532 vect.push_back(cont->getId());
2538 //=========================================================================
2540 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2541 std::vector<int> vect;
2542 std::map<int, GObjectController*>::iterator it;
2543 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2544 GObjectController *cont = it->second;
2545 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2546 vect.push_back(cont->getId());
2552 //=========================================================================
2554 std::vector<int> wxVtkSceneManager::getConnections() {
2555 std::vector<int> vect;
2556 std::map<int, GObjectController*>::iterator it;
2557 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2558 GObjectController *cont = it->second;
2559 if (cont->getGObjectType() == GCONNECTOR) {
2560 vect.push_back(cont->getId());
2566 //=========================================================================
2568 bool wxVtkSceneManager::isComplexBox() {
2569 return _isComplexBox;
2572 //=========================================================================
2574 void wxVtkSceneManager::setComplexBox(bool val) {
2575 _isComplexBox = val;
2578 //=========================================================================
2580 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2581 //Register the controller of the new object
2582 registerController((InteractorStyleMaracas*) objController);
2583 //Add the object to the objects list
2584 int newId = _contLastId;//_controllers.size();
2585 objController->setId(newId);
2586 _controllers[newId] = objController;
2587 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2592 //=========================================================================
2594 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2596 std::map<int, int> oldIdNewIdBoxes;
2597 std::vector<int> connections;
2599 std::vector<int> newBoxesID;
2601 std::map<int, GObjectController*>::iterator it;
2602 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2603 GObjectController *cont = it->second;
2604 int type = cont->getGObjectType();
2606 if (type == GBLACKBOX) {
2608 double xInic, yInic, zInic;
2609 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2610 copyBox->getInicPoint(xInic, yInic, zInic);
2611 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2612 copyBox->getBBTKType());
2614 int idcB = copyBox->getObjectId();
2615 oldIdNewIdBoxes[idcB] = idBox;
2616 cont = _controllers[idBox];
2617 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2618 newbox->setInicPoint(xInic, yInic, zInic);
2619 int num = newbox->getNumInputPorts();
2620 for (int j = 0; j < num; j++) {
2621 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2623 newbox->move(xInic + 20, yInic + 20, zInic);
2624 newbox->notifyObservers(_idManager);
2625 newBoxesID.push_back(newbox->getObjectId());
2627 } else if (type == GCONNECTOR) {
2628 int idCon = cont->getId();
2629 connections.push_back(idCon);
2634 for (int i = 0; i < (int) connections.size(); i++) {
2635 int objId = connections[i];
2636 GObjectController *cont = objectsMap[objId];
2637 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2639 GPortModel* startPort = connectModel->getStartPort();
2640 int startPortIndex = startPort->getPosInBox();
2641 GPortModel* endPort = connectModel->getEndPort();
2642 int endPortIndex = endPort->getPosInBox();
2644 GBlackBoxModel* startPortParentBox =
2645 (GBlackBoxModel*) startPort->getParentBox();
2646 GBlackBoxModel* endPortParentBox =
2647 (GBlackBoxModel*) endPort->getParentBox();
2649 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2650 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2652 GBlackBoxModel* newStartBox =
2653 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2654 GBlackBoxModel* newEndBox =
2655 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2657 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2658 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2660 // Creates connection
2661 int idCon = createGConnector(newStartPort);
2662 GConnectorController *tempp =
2663 (GConnectorController*) _controllers[idCon];
2664 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2665 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2666 tempp->endContourCreation();
2667 conMod->setEndPort(newEndPort);
2668 conView->updateStartEndPoints();
2671 /// the new selected boxes are the duplicate ones
2673 UnSelectBlackBoxes();
2674 for (int i = 0; i < newBoxesID.size(); i++) {
2675 _selectedObjects.push_back(newBoxesID.at(i));
2678 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2679 int id = _selectedObjects[i];
2680 GObjectController* cont = _controllers[id];
2682 cont->getView()->setState(SELECTED);
2683 cont->getModel()->notifyObservers(_idManager);
2689 //=========================================================================
2691 int wxVtkSceneManager::getNumSelectedObjects() {
2692 return _selectedObjects.size();
2695 //=========================================================================
2697 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2698 std::map<int, GObjectController*> mapSelected;
2700 std::map<int, GObjectController*>::iterator it;
2701 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2702 GObjectController *cont = it->second;
2703 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2705 mapSelected[cont->getId()] = cont;
2709 std::map<int, GObjectController*>::iterator it2;
2710 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2711 GObjectController *cont = it2->second;
2712 if (cont->getGObjectType() == GCONNECTOR) {
2713 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2714 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2715 GBoxModel* startPortParentBox =
2716 cmod->getStartPort()->getParentBox();
2718 std::map<int, GObjectController*>::iterator iterOBJ1 =
2719 mapSelected.find(startPortParentBox->getObjectId());
2720 std::map<int, GObjectController*>::iterator iterOBJ2 =
2721 mapSelected.find(endPortParentBox->getObjectId());
2723 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2724 int ID = cont->getId();
2725 mapSelected[ID] = cont;
2732 //=========================================================================
2734 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2736 std::map<int, int> oldIdNewIdBoxes;
2737 std::vector<int> connections;
2739 std::map<int, GObjectController*>::iterator it;
2740 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2741 GObjectController *cont = it->second;
2742 int type = cont->getGObjectType();
2744 if (type == GBLACKBOX) {
2746 double xInic, yInic, zInic;
2747 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2748 copyBox->getInicPoint(xInic, yInic, zInic);
2749 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2751 int idcB = copyBox->getObjectId();
2752 oldIdNewIdBoxes[idcB] = idBox;
2753 cont = _controllers[idBox];
2754 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2755 newbox->setInicPoint(xInic, yInic, zInic);
2756 int num = newbox->getNumInputPorts();
2757 for (int j = 0; j < num; j++)
2759 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2761 newbox->notifyObservers(_idManager);
2762 } else if (type == GCONNECTOR) {
2763 int idCon = cont->getId();
2764 connections.push_back(idCon);
2769 for (int i = 0; i < (int) connections.size(); i++) {
2770 int objId = connections[i];
2771 GObjectController *cont = objectsMap[objId];
2772 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2774 GPortModel* startPort = connectModel->getStartPort();
2775 int startPortIndex = startPort->getPosInBox();
2776 GPortModel* endPort = connectModel->getEndPort();
2777 int endPortIndex = endPort->getPosInBox();
2779 GBlackBoxModel* startPortParentBox =
2780 (GBlackBoxModel*) startPort->getParentBox();
2781 GBlackBoxModel* endPortParentBox =
2782 (GBlackBoxModel*) endPort->getParentBox();
2784 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2785 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2787 GBlackBoxModel* newStartBox =
2788 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2789 GBlackBoxModel* newEndBox =
2790 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2792 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2793 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2795 // Creates connection
2796 int idCon = createGConnector(newStartPort);
2797 GConnectorController *tempp =
2798 (GConnectorController*) _controllers[idCon];
2799 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2800 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2801 tempp->endContourCreation();
2802 conMod->setEndPort(newEndPort);
2803 conView->updateStartEndPoints();
2806 std::map<int, int>::iterator itIds;
2807 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2808 int idOld = itIds->first;
2809 int idNew = itIds->second;
2811 GBlackBoxModel* oldBox =
2812 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2813 GBlackBoxModel* newBox =
2814 (GBlackBoxModel*) _controllers[idNew]->getModel();
2816 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2817 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2818 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2819 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2821 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2823 //EED int toCreate=-1;
2824 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2825 if (oldInputConnections[k] == newInputConnections[l]) {
2830 if (exist == false) {
2831 //Create complex input
2832 int posInBox = oldInputConnections[k];
2833 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2834 std::string inputPortName = inputPort->getBBTKName();
2835 int idInputPort = createGComplexBoxInputPort(inputPortName);
2836 GObjectController *cont = _controllers[idInputPort];
2837 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2838 double xIn, yIn, zIn;
2839 inputPort->getInicPoint(xIn, yIn, zIn);
2841 cbmod->setInicPoint(xIn, yIn, zIn);
2842 cbmod->notifyObservers(_idManager);
2844 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2846 // Creates connection
2847 int idCon = createGConnector(cbmod->getOutputPort(0));
2848 GConnectorController *tempp =
2849 (GConnectorController*) _controllers[idCon];
2850 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2851 vtkGConnectorView *conView =
2852 (vtkGConnectorView*) tempp->getView();
2853 tempp->endContourCreation();
2854 conMod->setEndPort(inputPortEnd);
2855 conView->updateStartEndPoints();
2861 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2863 //EED int toCreate=-1;
2864 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2865 if (oldOutputConnections[k] == newOutputConnections[l]) {
2870 if (exist == false) {
2871 //Create complex output
2872 int posInBox = oldOutputConnections[k];
2873 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2874 std::string outputPortName = outputPort->getBBTKName();
2875 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2876 GObjectController *cont = _controllers[idOutputPort];
2877 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2878 double xIn, yIn, zIn;
2879 outputPort->getInicPoint(xIn, yIn, zIn);
2881 cbmod->setInicPoint(xIn, yIn, zIn);
2882 cbmod->notifyObservers(_idManager);
2884 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2886 // Creates connection
2887 int idCon = createGConnector(outputPortEnd);
2888 GConnectorController *tempp =
2889 (GConnectorController*) _controllers[idCon];
2890 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2891 vtkGConnectorView *conView =
2892 (vtkGConnectorView*) tempp->getView();
2893 tempp->endContourCreation();
2894 conMod->setEndPort(cbmod->getInputPort(0));
2895 conView->updateStartEndPoints();
2905 //=========================================================================
2906 void wxVtkSceneManager::SetCbName(std::string cbName) {
2908 if (_cbName == "") {
2909 _cbName = "<complex box name>";
2913 //=========================================================================
2914 std::string wxVtkSceneManager::GetCbName() {
2918 //=========================================================================
2919 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2920 _cbPackageName = packagename;
2921 if (_cbPackageName == "") {
2922 _cbPackageName = "<package name of the complex box>";
2926 //=========================================================================
2927 std::string wxVtkSceneManager::GetCbPackageName() {
2928 return _cbPackageName;
2931 //=========================================================================
2932 void wxVtkSceneManager::SetAuthor(std::string author) {
2934 if (_Author == "") {
2935 _Author = "<author of the box>";
2939 //=========================================================================
2940 std::string wxVtkSceneManager::GetAuthor() {
2944 //=========================================================================
2945 void wxVtkSceneManager::SetCategory(std::string category) {
2946 _Category = category;
2947 if (_Category == "") {
2948 _Category = "<category of the box>";
2952 //=========================================================================
2953 std::string wxVtkSceneManager::GetCategory() {
2957 //=========================================================================
2958 void wxVtkSceneManager::SetDescription(std::string description) {
2959 _Description = description;
2960 if (_Description == "") {
2961 _Description = "<description of the box>";
2965 //=========================================================================
2966 std::string wxVtkSceneManager::GetDescription() {
2967 return _Description;
2970 //=========================================================================
2972 void wxVtkSceneManager::SetMessageKind(std::string kind) {
2973 _MessageKind = kind;
2977 //=========================================================================
2979 std::string wxVtkSceneManager::GetMessageKind(){
2980 return _MessageKind;
2983 //=========================================================================
2985 void wxVtkSceneManager::SetMessageLevel(std::string Level){
2986 _MessageLevel = Level;
2989 //=========================================================================
2991 std::string wxVtkSceneManager::GetMessageLevel(){
2992 return _MessageLevel;
2995 //=========================================================================
2997 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
3000 std::vector< std::string> extInputs;
3001 std::map<int, GObjectController*>::iterator it;
3002 for (it = _controllers.begin(); it != _controllers.end(); ++it)
3004 GObjectController *cont = it->second;
3005 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
3007 extInputs.push_back(cont->getModel()->getBBTKName());
3013 //=========================================================================
3017 void wxVtkSceneManager::printAll(int com , int sta ){
3019 int tmpState = sta ;
3020 if ( tmpState == NOTHING_HAPPENS ) {
3021 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
3023 if ( tmpState == HIGHLIGHTED ) {
3024 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
3026 if ( tmpState == POSSIBLE_CONNECTION ) {
3027 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
3029 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
3030 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
3032 if ( tmpState == CLICKED ) {
3033 std::cout << "CONTROLER STATE---->CLICKED\n" ;
3035 if ( tmpState == DRAG ) {
3036 std::cout << "CONTROLER STATE---->DRAG\n" ;
3038 if ( tmpState == SELECTED ) {
3039 std::cout << "CONTROLER STATE---->SELECTED\n" ;
3041 if ( tmpState == CREATING_CONTOUR ) {
3042 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
3048 if ( command == INIT_CREATION_CONTOUR ) {
3049 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
3051 if ( command == FIN_CREATION_CONTOUR ) {
3052 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
3054 if ( command == ADD_TO_SELECTED ) {
3055 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
3057 if ( command == DRAG_OBJECTS ) {
3058 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
3060 if ( command == EDIT_BLACKBOX ) {
3061 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
3063 if ( command == REMOVE_FROM_SELECTED ) {
3064 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
3070 } // EO namespace bbtk