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();
216 _aPolygonMapper->SetInput(aPolygonGrid);
217 _fillObjectActor->SetMapper(_aPolygonMapper);
218 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
220 _fillObjectActor->GetProperty()->SetOpacity(0);
221 _aPolygonMapper->Modified();
223 _baseView->GetRenderer()->AddActor(_fillObjectActor);
226 //=========================================================================
228 std::string wxVtkSceneManager::generateANewNameForABox() {
229 std::stringstream boxname;
230 if (_numBoxes < 10) {
231 boxname << "Box0" << _numBoxes;
233 boxname << "Box" << _numBoxes;
236 return boxname.str();
239 //=========================================================================
241 std::string wxVtkSceneManager::findANewNameForABox() {
242 std::string boxname = generateANewNameForABox();
244 while (boxExist(boxname) == true) {
245 boxname = generateANewNameForABox();
251 //=========================================================================
252 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
253 double zIn, std::string name, bool boxExecutable, double xEn,
254 double yEn, double zEn) {
255 GObjectController *cont = _controllers[idBox];
256 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
257 bbmod->setBBTKName(name);
258 bbmod->setInicPoint(xIn, yIn, zIn);
259 bbmod->setFinalPoint(xEn, yEn, zEn);
260 bbmod->setExecutable(boxExecutable);
262 bbmod->notifyObservers(_idManager);
266 //=========================================================================
268 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,std::string boxType)
270 _worldState = NOTHING_HAPPENS;
271 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
272 int type = GBLACKBOX;
273 //Create the MVC Objects
274 GBlackBoxModel *model = (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
275 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
276 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
278 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
282 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
284 k = _bbtkfactory->GetPackage(packageName);
285 mapDesc = k->GetDescriptorMap();
287 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for package %s, NOT EXIST\n", packageName.c_str());
290 BlackBoxDescriptor::Pointer descriptor;
292 descriptor = mapDesc[boxType];
294 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for box %s of package %s, NOT EXIST\n", boxType.c_str(),packageName.c_str());
297 if (descriptor == NULL)
299 printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
302 //Prepares the initial model
303 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
306 double yy = windowHeight - y;
308 //z value is not important yet, because it is only used a parallel projection
309 double zz = GPOSITION_Z;
310 _baseView->TransCoordScreenToWorld(xx, yy, zz);
311 model->setInicPoint(xx, yy, zz);
313 std::stringstream stream;
315 std::string newBoxName;
316 newBoxName = findANewNameForABox();
318 stream << newBoxName;
320 std::string arraystring = stream.str();
322 model->setBBTKName(arraystring);
323 model->setBBTKType(boxType);
324 model->setBBTKPackage(packageName);
326 model->addObserver(view);
327 model->addObserver(this);
330 //EED2017 change order
331 //Associates the view with the correspondent renderer and the model.
332 //(NOTE: Refresh is only made by the view)
333 view->setModel(model);
334 view->setBaseView(_baseView);
336 //Associates the controller with the correspondent model and view
337 controller->setModelAndView(model, view);
340 //Iterate and create the input ports
341 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
342 descriptor->GetInputDescriptorMap();
343 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
345 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
347 BlackBoxInputDescriptor *desc = itInput->second;
349 // createGInputPort(GINPUTPORT, i, model, desc);
350 createGInputPort(GINPUTPORT, i, controller, desc);
354 //Iterate and create the output ports
355 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
356 descriptor->GetOutputDescriptorMap();
357 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
359 for (itOutput = descriptorOutMap.begin(); itOutput!= descriptorOutMap.end(); ++itOutput)
361 BlackBoxOutputDescriptor *desc = itOutput->second;
363 // createGOutputPort(GOUTPUTPORT, i, model, desc);
364 createGOutputPort(GOUTPUTPORT, i, controller, desc);
368 //EED2017 change order
369 view->initVtkObjects();
371 //Resgiter change to the observers of the actual model
372 model->notifyObservers(_idManager);
373 int newId = addObjectController(controller);
379 //=========================================================================
381 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
382 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
383 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
385 int type = GCOMPLEXINPUTPORT;
387 //Create the MVC Objects
389 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
390 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
391 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
393 //Prepares the initial model
396 double yy = windowHeight - 5;
398 //z value is not important yet, because it is only used a parallel projection
399 double zz = GPOSITION_Z;
401 _baseView->TransCoordScreenToWorld(xx, yy, zz);
402 model->setInicPoint(xx, yy, zz);
404 model->setBBTKName(inputName);
405 model->setBBTKType("ComplexInputPort");
406 model->setComplexPortType(type);
408 model->addObserver(view);
409 model->addObserver(this);
411 //create the output port
412 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
413 "ComplexOutputPortType","ComplexOutputPortDescriopton", 0, model);
414 model->addOutputPort((GPortModel*) portController->getModel());
416 //Associates the view with the correspondent renderer and the model.
417 //(NOTE: Refresh is only made by the view)
418 view->setModel(model);
419 view->setBaseView(_baseView);
420 view->initVtkObjects();
422 //Associates the controller with the correspondent model and view
423 controller->setModelAndView(model, view);
425 //Resgiter change to the observers of the actual model
426 model->notifyObservers(_idManager);
428 int newId = addObjectController(controller);
432 //=========================================================================
434 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
435 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
436 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
438 int type = GCOMPLEXOUTPUTPORT;
440 //Create the MVC Objects
442 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
443 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
444 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
446 //Prepares the initial model
449 double yy = windowHeight - 5;
451 //z value is not important yet, because it is only used a parallel projection
452 double zz = GPOSITION_Z;
454 _baseView->TransCoordScreenToWorld(xx, yy, zz);
455 model->setInicPoint(xx, yy, zz);
457 model->setBBTKName(outputName);
458 model->setBBTKType("ComplexOutputPort");
459 model->setComplexPortType(type);
461 model->addObserver(view);
462 model->addObserver(this);
464 //create the output port
465 GPortController* portController = createGPort(GINPUTPORT, outputName,
466 "ComplexInputPort","ComplexInputPortDescription", 0, model);
467 model->addInputPort((GPortModel*) portController->getModel());
469 //Associates the view with the correspondent renderer and the model.
470 //(NOTE: Refresh is only made by the view)
471 view->setModel(model);
472 view->setBaseView(_baseView);
473 view->initVtkObjects();
475 //Associates the controller with the correspondent model and view
476 controller->setModelAndView(model, view);
478 //Resgiter change to the observers of the actual model
479 model->notifyObservers(_idManager);
481 int newId = addObjectController(controller);
485 //=========================================================================
488 //int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
489 int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GObjectController *gBoxControler, BlackBoxInputDescriptor *desc)
491 GBoxModel *blackBox=(GBoxModel*)gBoxControler->getModel();
492 GPortController* portController = createGPort(portType, desc->GetName(),
493 desc->GetTypeName(), desc->GetDescription(), posinBox, blackBox);
494 blackBox->addInputPort( (GPortModel*)portController->getModel() );
496 vtkGBoxView *vtkgboxView=(vtkGBoxView*)gBoxControler->getView();
497 vtkgboxView->addInputPort( (vtkGPortView*)portController->getView() );
499 return portController->getId();
502 //=========================================================================
505 //int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
506 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GObjectController *gBoxControler, BlackBoxOutputDescriptor *desc)
508 GBoxModel *blackBox=(GBoxModel*)gBoxControler->getModel();
509 GPortController* portController = createGPort(portType, desc->GetName(),
510 desc->GetTypeName(),desc->GetDescription(), posinBox, blackBox);
511 blackBox->addOutputPort((GPortModel*) portController->getModel());
513 vtkGBoxView *vtkgboxView=(vtkGBoxView*)gBoxControler->getView();
514 vtkgboxView->addOutputPort( (vtkGPortView*)portController->getView() );
516 return portController->getId();
519 //=========================================================================
521 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posInBox,GBoxModel *blackBox)
525 //Create the MVC Objects
526 GPortModel *model = (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
527 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
528 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
529 model->registerInBox(blackBox, portType, posInBox);
530 model->setBBTKType(bbtkType);
531 model->setBBTKName(bbtkName);
532 model->setBBTKDescription(bbtkDescription);
533 model->addObserver(view);
534 model->addObserver(this);
535 //Associates the view with the correspondent renderer and the model.
536 //(NOTE: Refresh is only made by the view)
537 view->setModel(model);
538 view->setBaseView(_baseView);
539 //EED017 view->initVtkObjects();
540 view->createVtkObjects();
541 // view->addVtkActors();
543 //Associates the controller with the correspondent model and view
544 controller->setModelAndView(model, view);
545 model->notifyObservers(_idManager);
546 addObjectController(controller);
547 return (GPortController*) controller;
550 //=========================================================================
552 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
554 int type = GCONNECTOR;
556 manualConnectorContourController *manContourControl = new manualConnectorContourController();
557 manualConnectorContourView *manContourView = new manualConnectorContourView();
558 manualContourModel *manContourModel = new manualContourModel();
559 GConnectorController *connectorcontroller = new GConnectorController();
560 GConnectorModel *connectorModel = new GConnectorModel();
561 vtkGConnectorView *connectorView = new vtkGConnectorView();
562 connectorModel->setGObjectType(type);
564 manContourModel->SetCloseContour(false);
565 connectorModel->setStartPort(startPort);
567 manContourView->SetModel(manContourModel);
568 manContourView->SetWxVtkBaseView(_baseView);
569 manContourView->SetRange(0.5);
570 manContourView->SetZ(GPOSITION_Z);
572 manContourView->SetColorNormalContour(0, 0, 1);
573 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
574 manContourView->SetColorSelectContour(1, 0.8, 0);
580 * Width increased from 2 to 3, it simplifies line handling and spline control :P
584 manContourView->SetWidthLine( 3 ) ;
585 manContourView->SetShowText(false);
587 manContourControl->SetModelView(manContourModel, manContourView);
589 manContourControl->CreateNewManualContour();
593 connectorModel->getInicPoint(x, y, z);
596 manContourControl->SetState(1);
597 manContourModel->SetCloseContour(false);
599 manContourModel->AddPoint(x, y, z);
600 manContourView->AddPoint();
602 manContourModel->AddPoint(x, y, z);
603 manContourView->AddPoint();
605 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
606 manContourControl->_bakIdPoint = bak;
608 manContourControl->SetMoving(false);
610 connectorcontroller->setModelAndView(connectorModel, connectorView);
612 int newId = addObjectController(connectorcontroller);
614 connectorcontroller->setManualContourController(manContourControl);
615 connectorModel->setManualContourModel(manContourModel);
616 connectorView->setManualContourView(manContourView);
617 connectorView->setModel(connectorModel);
618 connectorView->setBaseView(_baseView);
620 connectorModel->addObserver(connectorView);
621 connectorModel->addObserver(this);
623 // manContourView->Refresh();
628 //=========================================================================
630 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
632 vtkInteractorStyleBaseView * baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
633 baseViewControlManager->AddInteractorStyleMaracas(param);
636 //=========================================================================
638 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
640 vtkInteractorStyleBaseView *baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
641 baseViewControlManager->RemoveInteractorStyleMaracas(param);
644 //=========================================================================
646 vtkRenderer* wxVtkSceneManager::getRenderer()
648 return _baseView->GetRenderer();
651 //=========================================================================
653 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
655 return _baseView->GetRenWin();
657 //=========================================================================
660 //=========================================================================
661 int wxVtkSceneManager::GetIndexInSelected(int idControler)
664 for (int i = 0; i < (int) _selectedObjects.size(); i++)
666 if (_selectedObjects[i] == idControler)
674 //=========================================================================
676 void wxVtkSceneManager::update(int idController, int command) {
678 if (command != NO_COMMAND)
680 if (command == ADD_TO_SELECTED)
682 if (GetIndexInSelected(idController) == -1)
684 _selectedObjects.push_back(idController);
686 } else if (command == REMOVE_FROM_SELECTED) {
687 int index = GetIndexInSelected(idController);
690 _selectedObjects.erase(_selectedObjects.begin() + index);
692 } else if (command == INIT_CREATION_CONTOUR) {
694 typedef std::map<int , GObjectController*>::iterator TIterator ;
697 // Find current item in the controller
698 iter = _controllers.find( idController ) ;
699 iter_end = _controllers.end( ) ;
701 if ( iter != iter_end ) {
702 GObjectController* gobjc = iter->second ;
704 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
705 // And if the item is a port
706 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
707 TIterator c_it = _controllers.begin( ) ;
708 // Go through all componets
709 for ( c_it ; c_it != iter_end ; c_it++ ) {
710 GObjectController* obc = c_it->second ;
711 int obc_type = obc->getModel( )->getGObjectType( ) ;
712 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
713 // if the component is a port and the type is the same of that selected
714 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
716 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
717 //obc->getView( )->setState( HIGHLIGHTED ) ;
725 _worldState = INIT_CREATION_CONTOUR;
726 GObjectController* cont = _controllers[idController];
727 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
729 // The last one is the controller of the connector
730 std::map<int, GObjectController*>::iterator it2;
732 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
734 GObjectController *cont = it2->second;
735 if (cont->getGObjectType() == GPORT)
737 GPortModel* port = (GPortModel*) cont->getModel();
738 if (port->getPortType() == GINPUTPORT)
740 cont->SetActive(true);
742 cont->getView()->setState(NOTHING_HAPPENS);
743 cont->getModel()->notifyObservers(_idManager);
744 cont->SetActive(false);
747 cont->getView()->setState(NOTHING_HAPPENS);
748 cont->getModel()->notifyObservers(_idManager);
749 cont->SetActive(false);
752 _selectedObjects.clear();
753 _idConnectionInCreation = createGConnector(startOutputPort);
754 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
755 _worldState = NOTHING_HAPPENS;
756 //int id = _controllers.size()-1;
757 GObjectController *cont = _controllers[_idConnectionInCreation];
758 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
759 GObjectController *finPort = _controllers[idController];
761 if (finPort->getGObjectType() == GPORT)
763 GPortModel* modelPort = (GPortModel*) finPort->getModel();
764 modelContour->setEndPort(modelPort);
767 typedef std::map<int, GObjectController*>::iterator TIterator;
768 TIterator c_it = _controllers.begin();
769 TIterator iter_end = _controllers.end();
770 // Go through all componets
771 for (c_it; c_it != iter_end; c_it++) {
772 GObjectController* obc = c_it->second;
773 int obc_type = obc->getModel()->getGObjectType();
774 int obc_state = obc->getView()->getState();
775 // if the component is a port and the type is the same of that selected
776 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
777 // Return element to neutral state if not selected
778 obc->getView()->setState(NOTHING_HAPPENS);
780 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
781 // Change element to connected state
782 obc->getView()->setState(HIGHLIGHTED);
788 _parent->saveTempandUpdate("create connection");
791 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
792 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
794 std::map<int, GObjectController*>::iterator it2;
796 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
798 GObjectController *cont = it2->second;
799 if (cont->getView() != NULL) {
800 cont->getView()->setState(NOTHING_HAPPENS);
801 cont->getModel()->notifyObservers(_idManager);
803 cont->SetActive(true);
812 //=========================================================================
814 bool wxVtkSceneManager::OnMouseMove()
817 bool okStatusMessage = false;
818 bool okPortMessage = false;
819 crea::wxVTKRenderWindowInteractor *wxVTKiren;
820 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
821 wxVTKiren->GetEventPosition(X, Y);
823 if (_worldState == DRAG_OBJECTS) {
824 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
825 int id = _selectedObjects[i];
826 GObjectController* cont = _controllers[id];
827 if (_startDragging) {
828 cont->getView()->setStartDragging(true);
830 cont->getView()->moveObject(X, Y);
831 cont->getView()->setState(DRAG);
832 cont->getModel()->notifyObservers(_idManager);
835 std::map<int, GObjectController*>::iterator it;
837 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
838 GObjectController *desc = it->second;
839 if (desc->getGObjectType() == GCONNECTOR) {
840 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
841 vconn->updateStartEndPoints();
845 _startDragging = false;
847 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
848 std::map<int, GObjectController*>::iterator it;
850 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
851 GObjectController *desc = it->second;
852 int type = desc->getGObjectType();
853 int state = desc->getView()->getState();
854 desc->getModel()->getCenter(px, py, pz);
857 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
860 okStatusMessage = true;
861 updateStatusBar(desc->getStatusText());
862 if (type == GBLACKBOX)
864 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
865 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
870 if ( ( _bugTextActor_text==desc->getStatusText() ) || (_bugTextActor_status==0) )
872 _bugTextActor_status = 1;
873 okPortMessage = true;
875 _textActor->SetScale(0.1);
876 std::string tmp = desc->getStatusText()+"\n";
877 _textActor->SetInput( tmp.c_str() );
878 _textActor->SetPosition(px - 25, py + 1, pz + 2);
879 _textActor->Modified();
883 _fillObjectActor->SetScale(1);
884 _fillObjectActor->GetProperty()->SetOpacity(0.50);
885 _fillObjectActor->SetPosition(px, py, 1);
886 _aPolygonMapper->Modified();
888 _bugTextActor_status = 2;
889 } // _bugTextActor_tex
890 _bugTextActor_text = desc->getStatusText();
894 } // for controllers it
896 if (okStatusMessage == false)
901 if ((okPortMessage == false) || (_bugTextActor_status== 2 ) )
903 _bugTextActor_status = 0;
904 _textActor->SetScale(0.0001);
905 _textActor->SetInput("a\n");
906 _textActor->Modified();
907 _fillObjectActor->SetScale(0.0001);
912 //=========================================================================
914 bool wxVtkSceneManager::OnLeftButtonDown()
916 if (_worldState == INIT_CREATION_CONTOUR)
918 bool isOverPort = false;
919 std::map<int, GObjectController*>::iterator it;
920 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
922 GObjectController *desc = it->second;
923 if (desc->getGObjectType() == GPORT)
925 GPortModel *portmod = (GPortModel*) desc->getModel();
926 vtkGObjectView *portView = desc->getView();
927 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
932 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
934 portView->setState( HIGHLIGHTED);
941 if (isOverPort == false)
944 UnSelectBlackBoxes();
948 } else { //_worldState
950 _worldState = DRAG_OBJECTS;
951 _startDragging = true;
953 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
954 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
955 ctrlkey = ctrlkey + shiftkey;
957 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
960 int state = cont->getView()->getState();
961 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
962 UnSelectBlackBoxes();
965 UnSelectBlackBoxes(); // EED 12/07/2012
967 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
968 int id = _selectedObjects[i];
969 GObjectController *cont = _controllers[id];
970 cont->getView()->setState(DRAG);
971 cont->getModel()->notifyObservers(_idManager);
973 } // if _selectedObjects.size
979 //=========================================================================
981 bool wxVtkSceneManager::OnLeftButtonUp()
983 if (_worldState == DRAG_OBJECTS) {
984 _worldState = NOTHING_HAPPENS;
986 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
987 int id = _selectedObjects[i];
988 GObjectController* cont = _controllers[id];
989 cont->getView()->setState(SELECTED);
990 cont->getModel()->notifyObservers(_idManager);
996 //=========================================================================
997 void wxVtkSceneManager::CancelConnection()
999 if (_worldState == INIT_CREATION_CONTOUR)
1001 _worldState = NOTHING_HAPPENS;
1002 //int lastId = _controllers.size()-1;
1004 GConnectorController *connector =
1005 (GConnectorController*) _controllers[_idConnectionInCreation];
1006 connector->removeFromScene();
1007 unregisterController(connector);
1008 _controllers.erase(_idConnectionInCreation);
1010 std::map<int, GObjectController*>::iterator it;
1011 for (it = _controllers.begin(); it != _controllers.end(); ++it)
1013 GObjectController *desc = it->second;
1014 desc->SetActive(true);
1015 desc->getView()->setState(NOTHING_HAPPENS);
1016 desc->getModel()->notifyObservers(_idManager);
1021 //=========================================================================
1023 bool wxVtkSceneManager::OnRightButtonUp()
1025 if (_worldState == INIT_CREATION_CONTOUR)
1029 UnSelectBlackBoxes();
1035 bool wxVtkSceneManager::OnMiddleButtonDown() {
1038 this->_vtkInteractorStyleBaseView->StartPan();
1043 bool wxVtkSceneManager::OnMiddleButtonUp() {
1046 this->_vtkInteractorStyleBaseView->EndPan();
1053 //=========================================================================
1055 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1056 GObjectController *result = NULL;
1058 crea::wxVTKRenderWindowInteractor *wxVTKiren;
1060 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1061 wxVTKiren->GetEventPosition(X, Y);
1063 std::map<int, GObjectController*>::iterator it;
1065 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1066 GObjectController *cont = it->second;
1067 int type = cont->getGObjectType();
1069 if (cont->getView()->isPointInside(X, Y) == true) {
1070 if (type == GBLACKBOX) {
1073 } // if isPointInside
1078 //=========================================================================
1079 void wxVtkSceneManager::UnSelectBlackBoxes() {
1080 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1081 int id = _selectedObjects[i];
1082 GObjectController* control = _controllers[id];
1083 control->getView()->setState(NOTHING_HAPPENS);
1084 control->getModel()->notifyObservers(_idManager);
1085 }// for _selectedObjects
1086 _selectedObjects.clear();
1089 //=========================================================================
1090 bool wxVtkSceneManager::OnLeftDClick() {
1091 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1093 UnSelectBlackBoxes();
1094 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1099 //=========================================================================
1101 bool wxVtkSceneManager::OnChar()
1105 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1106 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1108 // KeyCode 127 : Delete Key
1109 // KeyCode 8 : Backspace Key
1112 if (keyCode == 8 || keyCode == 127 || keyCode == 27)
1114 if (_worldState == INIT_CREATION_CONTOUR)
1117 UnSelectBlackBoxes();
1122 if (keyCode == 8 || keyCode == 127)
1125 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1127 int id = _selectedObjects[i];
1128 std::map<int, GObjectController*>::iterator it;
1129 it = _controllers.find(id);
1130 if (it != _controllers.end())
1132 oktmp = deleteObject(id);
1135 }// for selected objects
1136 if (ok) _selectedObjects.clear();
1137 _parent->saveTempandUpdate("delete object");
1142 if((keyCode==0) && (ctrlkey==1)) {
1147 if(_selectedObjects.size()){
1148 std::cout<<"objects to copy :";
1149 for(int i=0;i<_selectedObjects.size();i++)
1151 std::cout<<_selectedObjects.at(i)<<" ";
1153 DuplicateObjects(getSelectedObjects());
1155 std::cout<<"No objects to copy\n";
1156 } // _selectedObjects.size
1162 //=========================================================================
1164 void wxVtkSceneManager::AddControlerToBeRemove(
1165 std::vector<int> *controllersToRemove, int id) {
1169 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1170 if (id == (*controllersToRemove)[i]) {
1176 controllersToRemove->push_back(id);
1181 //=========================================================================
1183 bool wxVtkSceneManager::deleteObject(int id)
1186 GObjectController *control = _controllers[id];
1187 std::vector<int> controllersToRemove;
1188 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1189 == GCOMPLEXINPUTPORT || control->getGObjectType()
1190 == GCOMPLEXOUTPUTPORT) {
1191 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1192 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1194 bool boxConnected = false;
1196 // Add box input controllers to be removed
1197 for (int i = 0; i < (int) inputs.size(); i++) {
1198 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1199 if (inputs[i]->isConnected()) {
1200 boxConnected = true;
1204 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1206 // Add box output controllers to be removed
1207 for (int i = 0; i < (int) outputs.size(); i++) {
1208 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1209 if (outputs[i]->isConnected()) {
1210 boxConnected = true;
1214 // Add connection controllers to be removed
1215 std::map<int, GObjectController*>::iterator it;
1216 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1217 GObjectController *cont = it->second;
1218 int type = cont->getGObjectType();
1219 if (type == GCONNECTOR) {
1220 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1221 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1223 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1225 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1227 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1232 // Add box controller to be removed
1233 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1234 } else if (control->getGObjectType() == GCONNECTOR) {
1235 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1236 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1238 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1239 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1241 gconnectorcontroler->getManualContourController()->OnChar();
1246 std::map<int, GObjectController*>::iterator it;
1248 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1249 int key = controllersToRemove[i];
1250 it = _controllers.find(key);
1251 GObjectController *cont = _controllers[key];
1253 cont->removeFromScene();
1254 unregisterController((InteractorStyleMaracas*) cont);
1255 _controllers.erase(it);
1263 //=========================================================================
1265 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1266 std::string boxName) {
1267 _parent->displayBlackBoxInfo(packageName, boxName);
1270 //=========================================================================
1272 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1273 _parent->updateStatusBar(textStatus);
1276 //=========================================================================
1277 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1278 std::string result = "";
1279 if (withLineNumber == true) {
1281 stringstream StrStream;
1283 std::string strValue = StrStream.str();
1286 } else if (value < 100) {
1290 result += strValue + ": ";
1294 //=========================================================================
1296 bool wxVtkSceneManager::MakeBoxExecutable() {
1297 std::map<int, GObjectController*> selected = getSelectedObjects();
1298 if( selected.empty() )
1301 std::map<int, GObjectController*>::iterator it;
1302 for (it = selected.begin(); it != selected.end(); ++it) {
1303 GObjectController* lastSelected = it->second;
1305 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1306 GBlackBoxModel *bbmodel =
1307 (GBlackBoxModel*) lastSelected->getModel();
1308 view->setState(HIGHLIGHTED);
1309 if (bbmodel->isExecutable()) {
1310 bbmodel->setExecutable(false);
1312 bbmodel->setExecutable(true);
1314 bbmodel->notifyObservers(lastSelected->getId());
1322 //=========================================================================
1324 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1325 std::cout << "wxVtkSceneManager::getDiagramBBS" << std::endl;
1326 bool existsExec = false;
1328 std::vector<std::string> packages;
1329 std::vector<int> boxes;
1330 std::vector<int> connections;
1331 std::vector<int> execBoxes;
1333 std::map<int, GObjectController*>::iterator it;
1335 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1336 GObjectController *desc = it->second;
1337 int type = desc->getGObjectType();
1339 if (type == GBLACKBOX) {
1340 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1342 std::string pkg = mod->getBBTKPackage();
1343 bool existsPkg = false;
1344 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1345 if (packages[t] == pkg) {
1350 packages.push_back(pkg);
1353 boxes.push_back(it->first);
1354 if (mod->isExecutable()) {
1355 execBoxes.push_back(it->first);
1358 } else if (type == GCONNECTOR) {
1359 connections.push_back(it->first);
1364 std::string script = "";
1365 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1366 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1367 script += LineNumber(wln, lnNmbr) + "\n";
1369 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1370 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1372 for (i = 0; i < (int) packages.size(); i++) {
1373 script += LineNumber(wln, lnNmbr);
1374 script += "include ";
1375 script += packages[i];
1379 script += LineNumber(wln, lnNmbr);
1384 script += LineNumber(wln, lnNmbr);
1385 script += "author \"";
1389 script += LineNumber(wln, lnNmbr);
1390 script += "description \"";
1391 script += _Description;
1394 script += LineNumber(wln, lnNmbr);
1395 script += "category \"";
1396 script += _Category;
1399 script += LineNumber(wln, lnNmbr);
1402 // script+="include std\n"; // JPR
1404 for (i = 0; i < (int) boxes.size(); i++) {
1405 script += LineNumber(wln, lnNmbr);
1408 GObjectController *control = _controllers[id];
1409 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1411 script += model->getBBTKPackage()+":";
1412 script += model->getBBTKType();
1414 script += model->getBBTKName();
1417 std::vector<GPortModel*> inputs = model->getInputPorts();
1418 for (int j = 0; j < (int) inputs.size(); j++) {
1419 GPortModel* inputPort = inputs[j];
1420 if (inputPort->isValueSet()) {
1421 script += LineNumber(wln, lnNmbr);
1423 script += model->getBBTKName();
1425 script += inputPort->getBBTKName();
1427 script += inputPort->getValue();
1432 script += LineNumber(wln, lnNmbr);
1437 script += LineNumber(wln, lnNmbr);
1441 std::string complexInputs="";
1443 for (i = 0; i < (int) connections.size(); i++) {
1444 //script += LineNumber(wln, lnNmbr);
1445 //script += "connect ";
1446 int id = connections[i];
1447 GObjectController *control = _controllers[id];
1448 GConnectorModel *model = (GConnectorModel*) control->getModel();
1452 GPortModel *start = model->getStartPort();
1453 GBoxModel *startBox = start->getParentBox();
1455 GPortModel *end = model->getEndPort();
1456 GBoxModel *endBox = end->getParentBox();
1458 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1460 complexInputs += "input ";
1461 complexInputs += startBox->getBBTKName();
1463 complexInputs += " ";
1464 complexInputs += endBox->getBBTKName();
1465 complexInputs += ".";
1466 complexInputs += end->getBBTKName();
1468 complexInputs += " ";
1469 complexInputs += "\" \"";
1471 complexInputs += "\n";
1475 script += LineNumber(wln, lnNmbr);
1476 script += "connect ";
1477 script += startBox->getBBTKName();
1479 script += start->getBBTKName();
1483 //End Connection info
1484 script += endBox->getBBTKName();
1486 script += end->getBBTKName();
1491 script += LineNumber(wln, lnNmbr);
1495 script += LineNumber(wln, lnNmbr);
1498 script += LineNumber(wln, lnNmbr);
1501 script += LineNumber(wln, lnNmbr);
1502 script += "# Complex input ports\n";
1503 script += complexInputs;
1505 if((_MessageKind!="-")&&(_MessageLevel!="-")){
1506 script += LineNumber(wln, lnNmbr);
1507 script += "message ";
1508 script += _MessageKind;
1510 script += _MessageLevel;
1514 for (i = 0; i < (int) execBoxes.size(); i++) {
1515 script += LineNumber(wln, lnNmbr);
1517 int id = execBoxes[i];
1518 GObjectController *control = _controllers[id];
1519 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1521 script += model->getBBTKName();
1530 //=========================================================================
1532 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1533 std::cout<<"wxVtkSceneManager::saveComplexBoxBBS"<<std::endl;
1534 std::vector<std::string> packages;
1535 std::vector<int> boxes;
1536 std::vector<int> connections;
1537 std::vector<int> execBoxes;
1539 std::map<int, GObjectController*>::iterator it;
1541 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1542 GObjectController *desc = it->second;
1543 int type = desc->getGObjectType();
1545 if (type == GBLACKBOX) {
1546 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1548 std::string pkg = mod->getBBTKPackage();
1549 bool existsPkg = false;
1550 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1551 if (packages[t] == pkg) {
1556 packages.push_back(pkg);
1559 boxes.push_back(it->first);
1560 if (mod->isExecutable()) {
1561 execBoxes.push_back(it->first);
1563 } else if (type == GCONNECTOR) {
1564 connections.push_back(it->first);
1568 std::string script = "";
1570 script += "include std\n"; // EED
1571 script += "include itkvtk\n"; // EED
1573 for (i = 0; i < (int) packages.size(); i++) {
1574 script += "include ";
1575 script += packages[i];
1580 // Definition of a complex box
1581 script += "define ";
1582 script += _cbName + " " + _cbPackageName;
1586 script += "author \"";
1590 script += "description \"";
1591 script += _Description;
1595 script += "category \"";
1596 script += _Category;
1601 for (i = 0; i < (int) boxes.size(); i++) {
1604 GObjectController *control = _controllers[id];
1605 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1607 script += model->getBBTKPackage()+":";
1608 script += model->getBBTKType();
1610 script += model->getBBTKName();
1613 std::vector<GPortModel*> inputs = model->getInputPorts();
1614 for (int j = 0; j < (int) inputs.size(); j++) {
1615 GPortModel* inputPort = inputs[j];
1616 if (inputPort->isValueSet()) {
1618 script += model->getBBTKName();
1620 script += inputPort->getBBTKName();
1622 script += inputPort->getValue();
1630 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1632 std::string complexInputs = "";
1633 std::string complexOutputs = "";
1636 for (i = 0; i < (int) connections.size(); i++) {
1637 int id = connections[i];
1638 GObjectController *control = _controllers[id];
1639 GConnectorModel *model = (GConnectorModel*) control->getModel();
1642 GPortModel *start = model->getStartPort();
1643 GBoxModel *startBox = start->getParentBox();
1645 GPortModel *end = model->getEndPort();
1646 GBoxModel *endBox = end->getParentBox();
1648 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1649 complexInputs += "input ";
1650 complexInputs += startBox->getBBTKName();
1652 complexInputs += " ";
1653 complexInputs += endBox->getBBTKName();
1654 complexInputs += ".";
1655 complexInputs += end->getBBTKName();
1657 complexInputs += " ";
1658 complexInputs += "\" \"";
1660 complexInputs += "\n";
1661 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1662 complexOutputs += "output ";
1663 complexOutputs += endBox->getBBTKName();
1665 complexOutputs += " ";
1666 complexOutputs += startBox->getBBTKName();
1667 complexOutputs += ".";
1668 complexOutputs += start->getBBTKName();
1670 complexOutputs += " ";
1671 complexOutputs += "\" \"";
1673 complexOutputs += "\n";
1675 script += "connect ";
1676 script += startBox->getBBTKName();
1678 script += start->getBBTKName();
1682 //End Connection info
1683 script += endBox->getBBTKName();
1685 script += end->getBBTKName();
1692 script += "# Complex input ports\n";
1693 script += complexInputs;
1696 script += "# Complex output ports\n";
1697 script += complexOutputs;
1701 if((_MessageKind!="-")&&(_MessageLevel!="-"))
1703 script += "message ";
1704 script += _MessageKind;
1706 script += _MessageLevel;
1710 for (i = 0; i < (int) execBoxes.size(); i++)
1713 int id = execBoxes[i];
1714 GObjectController *control = _controllers[id];
1715 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1717 script += model->getBBTKName();
1722 script += "endefine";
1728 //=========================================================================
1730 void wxVtkSceneManager::deleteAllBoxes() {
1731 std::map<int, GObjectController*>::iterator it;
1732 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1733 GObjectController *cont = it->second;
1734 cont->removeFromScene();
1735 unregisterController((InteractorStyleMaracas*) cont);
1737 _selectedObjects.clear();
1738 _controllers.clear();
1741 //=========================================================================
1744 void wxVtkSceneManager::refresh() {
1745 _baseView->Refresh();
1747 //=========================================================================
1749 void wxVtkSceneManager::refreshScene()
1751 _baseView->RefreshView();
1754 //=========================================================================
1756 void wxVtkSceneManager::centerView()
1759 _baseView->GetRenderer()->ComputeVisiblePropBounds(bb);
1762 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1763 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1764 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1765 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1767 _baseView->GetRenderer()->ResetCamera();
1768 _baseView->GetRenderer()->ResetCameraClippingRange();
1771 double tt=_baseView->GetRenderer()->GetNearClippingPlaneTolerance();
1772 printf("EED wxVtkSceneManager::centerView() tolerance=%f\n",tt);
1774 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1775 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1776 _baseView->GetRenderer()->GetActiveCamera()->SetClippingRange(0.01,100000);
1777 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1778 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1781 _baseView->GetRenderer()->Render();
1784 //=========================================================================
1786 void wxVtkSceneManager::saveDiagram(std::string &content)
1790 content += "CATEGORY:";
1791 content += GetCategory();
1794 content += "DESCRIPTION:";
1795 content += GetDescription();
1798 content += "AUTHOR:";
1799 content += GetAuthor();
1802 //Print info IF COMPLEX BOX
1803 content += "COMPLEXBOX:";
1804 if (_isComplexBox) {
1805 content += "TRUE\n";
1807 content += "COMPLEXBOXNAME:";
1808 content += GetCbName();
1811 content += "PACKAGENAME:";
1812 content += GetCbPackageName();
1815 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1816 * External inputs are possible for applications and complex boxes
1817 //Print info complex input ports
1818 std::vector<int> inputs = getComplexInputPorts();
1819 int insize = inputs.size();
1820 content += "COMPLEXINPUTS:";
1821 sprintf(buffer, "%d", insize);
1825 for (int i = 0; i < insize; i++) {
1827 GObjectController *cont = _controllers[id];
1828 cont->getModel()->save(content);
1832 //Print info complex output ports
1833 std::vector<int> outputs = getComplexOutputPorts();
1834 int outsize = outputs.size();
1835 content += "COMPLEXOUTPUTS:";
1836 sprintf(buffer, "%d", outsize);
1840 for (int i = 0; i < outsize; i++) {
1841 int id = outputs[i];
1842 GObjectController *cont = _controllers[id];
1843 cont->getModel()->save(content);
1847 content += "FALSE\n";
1850 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1851 // External inputs are possible for applications and complex boxes
1852 std::vector<int> inputs = getComplexInputPorts();
1853 int insize = inputs.size();
1854 content += "COMPLEXINPUTS:";
1855 sprintf(buffer, "%d", insize);
1859 for (int i = 0; i < insize; i++) {
1861 GObjectController *cont = _controllers[id];
1862 cont->getModel()->save(content);
1866 std::vector<int> boxes = getBlackBoxes();
1867 int bsize = boxes.size();
1868 content += "BOXES:";
1869 sprintf(buffer, "%d", bsize);
1873 for (int i = 0; i < bsize; i++) {
1875 // std::cout<<"id "<<id<<std::endl;//CFT
1876 GObjectController *cont = _controllers[id];
1877 // std::cout<<"nombre: "<<cont->getStatusText()<<std::endl;//CFT
1878 // std::cout<<"tipo: "<<cont->getModel()->getBBTKType()<<std::endl;//CFT
1879 // //boxesDiagram[i] = cont->getModel()->getBBTKType();//CFT
1880 // std::cout<<"nname: "<<cont->getModel()->getBBTKName()<<std::endl;//CFT
1881 // std::cout<<"categorie: "<<GetCategory()<<std::endl;//CFT
1882 // std::cout<<"type: "<<cont->getModel()->getGObjectType()<<std::endl;//CFT
1883 cont->getModel()->save(content);
1887 std::vector<int> connections = getConnections();
1888 int csize = connections.size();
1889 content += "CONNECTIONS:";
1890 sprintf(buffer, "%d", csize);
1894 for (int i = 0; i < csize; i++) {
1895 int id = connections[i];
1896 GObjectController *cont = _controllers[id];
1897 cont->getModel()->save(content);
1902 //=========================================================================
1903 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1905 getline(inputStream, line,'\n');
1906 int size = line.length();
1909 if ( line[ size-1 ]==13 )
1911 line.erase(size-1,1);
1916 //=========================================================================
1917 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1920 std::string version = "<void>";
1921 std::string line = "";
1922 char delims[] = ":";
1923 char *result = NULL;
1924 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1926 getCleanLine(inputStream, line);
1929 while (!inputStream.eof()) {
1930 if (line == "" || line[0] == '#') {
1932 getCleanLine(inputStream, line);
1934 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1935 version = line.substr(18, 3);
1937 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1938 version = line.substr(18, 3);
1940 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1941 version = line.substr(18, 3);
1943 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1944 version = line.substr(18, 3);
1946 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1947 version = line.substr(18, 3);
1949 } else if (line == "APP_START") {
1958 if ((version != "1.0") && (version != "1.1")) {
1959 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1960 char categoryTmp[30];
1961 strcpy(categoryTmp, line.c_str());
1962 result = strtok(categoryTmp, delims);
1963 result = strtok(NULL, delims);
1964 SetCategory(result);
1966 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1967 char descriptionTmp[1024];
1968 strcpy(descriptionTmp, line.c_str());
1969 result = strtok(descriptionTmp, delims);
1970 result = strtok(NULL, delims);
1971 SetDescription(result);
1973 getCleanLine(inputStream, line);//AUTHOR:<author>
1974 char authorTmp[255];
1975 strcpy(authorTmp, line.c_str());
1976 result = strtok(authorTmp, delims);
1977 result = strtok(NULL, delims);
1982 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1983 char complexTmp[30];
1984 strcpy(complexTmp, line.c_str());
1985 result = strtok(complexTmp, delims);
1986 result = strtok(NULL, delims);
1987 std::string isComplexBox(result);
1989 if (isComplexBox == "TRUE") {
1990 _isComplexBox = true;
1992 if ((version != "1.0") && (version != "1.1")) {
1993 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
1994 char complexboxnameTmp[255];
1995 strcpy(complexboxnameTmp, line.c_str());
1996 result = strtok(complexboxnameTmp, delims);
1997 result = strtok(NULL, delims);
2000 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
2001 char packagenameTmp[255];
2002 strcpy(packagenameTmp, line.c_str());
2003 result = strtok(packagenameTmp, delims);
2004 result = strtok(NULL, delims);
2005 SetCbPackageName(result);
2010 //-----------------------
2011 //- COMPLEX INPUT PORTS
2012 //-----------------------
2013 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2015 strcpy(inputs, line.c_str());
2016 result = strtok(inputs, delims);
2017 result = strtok(NULL, delims);
2020 std::istringstream inps(result);
2023 for (int i = 0; i < numInputs; i++) {
2025 getCleanLine(inputStream, line);//COMPLEX_PORT
2026 getCleanLine(inputStream, line);//name
2027 std::string inputPortName(line);
2030 getCleanLine(inputStream, line);//xInic:yInic:zInic
2032 strcpy(coord, line.c_str());
2033 result = strtok(coord, delims);//xInic
2034 std::string xInic(result);
2035 result = strtok(NULL, delims);//yInic
2036 std::string yInic(result);
2037 result = strtok(NULL, delims);//zInic
2038 std::string zInic(result);
2040 double xIn, yIn, zIn;
2041 std::istringstream xSt(xInic);
2043 std::istringstream ySt(yInic);
2045 std::istringstream zSt(zInic);
2050 if (zIn==900) zIn=GPOSITION_Z;
2053 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2055 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2057 } // for input complex box
2062 //-----------------------
2063 //- COMPLEX OUTPUT PORTS
2064 //-----------------------
2066 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2068 strcpy(outputs, line.c_str());
2069 result = strtok(outputs, delims);
2070 result = strtok(NULL, delims);
2073 std::istringstream outps(result);
2074 outps >> numOutputs;
2076 for (int i = 0; i < numOutputs; i++) {
2078 getCleanLine(inputStream, line);//COMPLEX_PORT
2079 getCleanLine(inputStream, line);//name
2080 std::string outputPortName(line);
2083 getCleanLine(inputStream, line);//xInic:yInic:zInic
2085 strcpy(coord, line.c_str());
2086 result = strtok(coord, delims);//xInic
2087 std::string xInic(result);
2088 result = strtok(NULL, delims);//yInic
2089 std::string yInic(result);
2090 result = strtok(NULL, delims);//zInic
2091 std::string zInic(result);
2093 double xIn, yIn, zIn;
2094 std::istringstream xSt(xInic);
2096 std::istringstream ySt(yInic);
2098 std::istringstream zSt(zInic);
2103 if (zIn==900) zIn=GPOSITION_Z;
2106 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2108 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2110 } // for output complex box
2114 // RaC2012 2nd Hackfest
2115 if(version >= "1.4")
2117 //-----------------------
2118 //- EXTERNAL INPUT PORTS
2119 //-----------------------
2120 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2122 strcpy(inputs, line.c_str());
2123 result = strtok(inputs, delims);
2124 result = strtok(NULL, delims);
2127 std::istringstream inps(result);
2130 for (int i = 0; i < numInputs; i++) {
2132 getCleanLine(inputStream, line);//COMPLEX_PORT
2133 getCleanLine(inputStream, line);//name
2134 std::string inputPortName(line);
2137 getCleanLine(inputStream, line);//xInic:yInic:zInic
2139 strcpy(coord, line.c_str());
2140 result = strtok(coord, delims);//xInic
2141 std::string xInic(result);
2142 result = strtok(NULL, delims);//yInic
2143 std::string yInic(result);
2144 result = strtok(NULL, delims);//zInic
2145 std::string zInic(result);
2147 double xIn, yIn, zIn;
2148 std::istringstream xSt(xInic);
2150 std::istringstream ySt(yInic);
2152 std::istringstream zSt(zInic);
2157 if (zIn==900) zIn=GPOSITION_Z;
2160 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2161 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2163 } // for external input
2168 getCleanLine(inputStream, line);//BOXES:num
2170 strcpy(boxes, line.c_str());
2171 result = strtok(boxes, delims);
2172 result = strtok(NULL, delims);
2175 std::istringstream is(result);
2178 for (int i = 0; i < numBoxes; i++)
2181 getCleanLine(inputStream, line);//BOX
2182 getCleanLine(inputStream, line);//package:type:name
2184 strcpy(box, line.c_str());
2185 result = strtok(box, delims);//package
2186 std::string package(result);
2187 result = strtok(NULL, delims);//type
2188 std::string type(result);
2189 result = strtok(NULL, delims);//name
2190 std::string name(result);
2193 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2195 strcpy(exec, line.c_str());
2196 result = strtok(exec, delims);//ISEXEC
2197 result = strtok(NULL, delims);//TRUE|FALSE
2198 std::string isExec(result);
2201 getCleanLine(inputStream, line);//xInic:yInic:zInic
2203 strcpy(coord, line.c_str());
2204 result = strtok(coord, delims);//xInic
2205 std::string xInic(result);
2206 result = strtok(NULL, delims);//yInic
2207 std::string yInic(result);
2208 result = strtok(NULL, delims);//zInic
2209 std::string zInic(result);
2211 double xIn, yIn, zIn;
2212 std::istringstream xSt(xInic);
2214 std::istringstream ySt(yInic);
2216 std::istringstream zSt(zInic);
2222 if (zIn==900) zIn=GPOSITION_Z;
2227 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2228 strcpy(coord, line.c_str());
2229 result = strtok(coord, delims);//xEnd
2230 std::string xEnd(result);
2231 result = strtok(NULL, delims);//yEnd
2232 std::string yEnd(result);
2233 result = strtok(NULL, delims);//zEnd
2234 std::string zEnd(result);
2236 double xEn, yEn, zEn;
2237 std::istringstream xEt(xEnd);
2239 std::istringstream yEt(yEnd);
2241 std::istringstream zEt(zEnd);
2246 if (zEn==900) zEn=GPOSITION_Z;
2250 bool boxExecutable = false;
2251 if (isExec == "TRUE")
2253 boxExecutable = true;
2256 int idBox = createGBlackBox(xIn, yIn, package, type);
2257 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2259 GObjectController *cont = _controllers[idBox];
2260 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2263 getCleanLine(inputStream, line);//PORT o FIN_BOX
2264 std::string port = line.substr(0, 4);
2265 while (port == "PORT")
2267 getCleanLine(inputStream, line);//name:value
2268 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2270 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2273 strcpy(poort, line.c_str());
2274 result = strtok(poort, delims);//name
2275 std::string name(result);
2277 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2278 result = strtok(NULL, delims);//value
2279 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2281 std::string tmpString=" ";
2282 tmpString[0]=34; // character "
2283 strcat(result,tmpString.c_str());
2285 std::string value(result);
2287 bbmod->setValueToInput(name, value);
2289 getCleanLine(inputStream, line);//PORT o FIN_BOX
2290 port = line.substr(0, 4);
2293 //EED bbmod->notifyObservers(_idManager);
2298 getCleanLine(inputStream, line);//CONNECTIONS:num
2300 strcpy(conns, line.c_str());
2301 result = strtok(conns, delims);
2302 result = strtok(NULL, delims);
2305 std::istringstream isCons(result);
2309 for (int i = 0; i < numConns; i++)
2312 getCleanLine(inputStream, line);//CONNECTION
2313 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2316 strcpy(connec, line.c_str());
2317 result = strtok(connec, delims);
2318 std::string nameStartBox(result);
2319 result = strtok(NULL, delims);
2320 std::string nameStartPort(result);
2321 result = strtok(NULL, delims);
2322 std::string nameEndBox(result);
2323 result = strtok(NULL, delims);
2324 std::string nameEndPort(result);
2326 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2328 if (version != "1.0") {
2329 //Readding control points of the manualContour
2330 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2331 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2332 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2333 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2334 strcpy(conns, line.c_str());
2335 result = strtok(conns, delims);
2336 result = strtok(NULL, delims);
2338 int numberOfControlPoints;
2339 std::istringstream isCons(result);
2340 isCons >> numberOfControlPoints;
2342 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2343 getCleanLine(inputStream, line); //XX:YY:ZZ
2345 strcpy(connec, line.c_str());
2348 result = strtok(connec, delims);
2349 std::istringstream isPointX(result);
2351 result = strtok(NULL, delims);
2352 std::istringstream isPointY(result);
2354 result = strtok(NULL, delims);
2355 std::istringstream isPointZ(result);
2360 if (pz==900) pz=GPOSITION_Z;
2363 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2364 conView->getManualContourView()->AddPoint();
2370 //=========================================================================
2373 //=========================================================================
2374 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2375 std::string portName, double xIn, double yIn, double zIn)
2378 if (inputoutput == true) {
2379 idPort = createGComplexBoxInputPort(portName);
2381 idPort = createGComplexBoxOutputPort(portName);
2383 GObjectController *cont = _controllers[idPort];
2384 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2385 cbmod->setInicPoint(xIn, yIn, zIn);
2386 cbmod->notifyObservers(_idManager);
2388 //=========================================================================
2391 //=========================================================================
2392 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2397 GBoxModel *boxModel = NULL;
2398 std::vector<int> lstB = getBlackBoxes();
2399 for (j = 0; j < (int) lstB.size(); j++) {
2401 bMod = (GBoxModel*) _controllers[idB]->getModel();
2402 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2410 if (boxModel == NULL) {
2411 std::vector<int> lstInputs = getComplexInputPorts();
2412 for (j = 0; j < (int) lstInputs.size(); j++) {
2414 bMod = (GBoxModel*) _controllers[idB]->getModel();
2415 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2423 std::vector<int> lstOutputs = getComplexOutputPorts();
2424 for (j = 0; j < (int) lstOutputs.size(); j++) {
2425 int idB = lstOutputs[j];
2426 bMod = (GBoxModel*) _controllers[idB]->getModel();
2427 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2439 //=========================================================================
2442 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2443 std::string nameStartPort, std::string nameEndBox,
2444 std::string nameEndPort) {
2446 GBoxModel *boxModel;
2447 GPortModel *startP = NULL;
2448 GPortModel *endP = NULL;
2450 boxModel = findGBox(nameStartBox);
2451 if(boxModel == NULL)
2453 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2455 if (boxModel != NULL) {
2456 startP = boxModel->getOutputPort(nameStartPort);
2458 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() );
2462 boxModel = findGBox(nameEndBox);
2463 if(boxModel == NULL)
2465 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2467 if (boxModel != NULL) {
2468 endP = boxModel->getInputPort(nameEndPort);
2470 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());
2475 int idCon = createGConnector(startP);
2477 _worldState = NOTHING_HAPPENS;
2478 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2480 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2481 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2482 tempp->endContourCreation();
2483 conMod->setEndPort(endP);
2484 conView->updateStartEndPoints();
2488 //=========================================================================
2490 bool wxVtkSceneManager::boxExist(std::string boxname) {
2492 std::map<int, GObjectController*>::iterator it;
2493 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2494 GObjectController *cont = it->second;
2495 if (cont->getModel()->getBBTKName() == boxname) {
2502 //=========================================================================
2504 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2505 std::vector<int> vect;
2506 std::map<int, GObjectController*>::iterator it;
2507 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2508 GObjectController *cont = it->second;
2509 if (cont->getGObjectType() == GBLACKBOX) {
2510 vect.push_back(cont->getId());
2516 //=========================================================================
2518 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2519 std::vector<int> vect;
2520 std::map<int, GObjectController*>::iterator it;
2521 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2522 GObjectController *cont = it->second;
2523 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2524 vect.push_back(cont->getId());
2530 //=========================================================================
2532 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2533 std::vector<int> vect;
2534 std::map<int, GObjectController*>::iterator it;
2535 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2536 GObjectController *cont = it->second;
2537 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2538 vect.push_back(cont->getId());
2544 //=========================================================================
2546 std::vector<int> wxVtkSceneManager::getConnections() {
2547 std::vector<int> vect;
2548 std::map<int, GObjectController*>::iterator it;
2549 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2550 GObjectController *cont = it->second;
2551 if (cont->getGObjectType() == GCONNECTOR) {
2552 vect.push_back(cont->getId());
2558 //=========================================================================
2560 bool wxVtkSceneManager::isComplexBox() {
2561 return _isComplexBox;
2564 //=========================================================================
2566 void wxVtkSceneManager::setComplexBox(bool val) {
2567 _isComplexBox = val;
2570 //=========================================================================
2572 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2573 //Register the controller of the new object
2574 registerController((InteractorStyleMaracas*) objController);
2575 //Add the object to the objects list
2576 int newId = _contLastId;//_controllers.size();
2577 objController->setId(newId);
2578 _controllers[newId] = objController;
2579 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2584 //=========================================================================
2586 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2588 std::map<int, int> oldIdNewIdBoxes;
2589 std::vector<int> connections;
2591 std::vector<int> newBoxesID;
2593 std::map<int, GObjectController*>::iterator it;
2594 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2595 GObjectController *cont = it->second;
2596 int type = cont->getGObjectType();
2598 if (type == GBLACKBOX) {
2600 double xInic, yInic, zInic;
2601 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2602 copyBox->getInicPoint(xInic, yInic, zInic);
2603 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2604 copyBox->getBBTKType());
2606 int idcB = copyBox->getObjectId();
2607 oldIdNewIdBoxes[idcB] = idBox;
2608 cont = _controllers[idBox];
2609 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2610 newbox->setInicPoint(xInic, yInic, zInic);
2611 int num = newbox->getNumInputPorts();
2612 for (int j = 0; j < num; j++) {
2613 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2615 newbox->move(xInic + 20, yInic + 20, zInic);
2616 newbox->notifyObservers(_idManager);
2617 newBoxesID.push_back(newbox->getObjectId());
2619 } else if (type == GCONNECTOR) {
2620 int idCon = cont->getId();
2621 connections.push_back(idCon);
2626 for (int i = 0; i < (int) connections.size(); i++) {
2627 int objId = connections[i];
2628 GObjectController *cont = objectsMap[objId];
2629 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2631 GPortModel* startPort = connectModel->getStartPort();
2632 int startPortIndex = startPort->getPosInBox();
2633 GPortModel* endPort = connectModel->getEndPort();
2634 int endPortIndex = endPort->getPosInBox();
2636 GBlackBoxModel* startPortParentBox =
2637 (GBlackBoxModel*) startPort->getParentBox();
2638 GBlackBoxModel* endPortParentBox =
2639 (GBlackBoxModel*) endPort->getParentBox();
2641 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2642 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2644 GBlackBoxModel* newStartBox =
2645 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2646 GBlackBoxModel* newEndBox =
2647 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2649 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2650 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2652 // Creates connection
2653 int idCon = createGConnector(newStartPort);
2654 GConnectorController *tempp =
2655 (GConnectorController*) _controllers[idCon];
2656 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2657 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2658 tempp->endContourCreation();
2659 conMod->setEndPort(newEndPort);
2660 conView->updateStartEndPoints();
2663 /// the new selected boxes are the duplicate ones
2665 UnSelectBlackBoxes();
2666 for (int i = 0; i < newBoxesID.size(); i++) {
2667 _selectedObjects.push_back(newBoxesID.at(i));
2670 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2671 int id = _selectedObjects[i];
2672 GObjectController* cont = _controllers[id];
2674 cont->getView()->setState(SELECTED);
2675 cont->getModel()->notifyObservers(_idManager);
2681 //=========================================================================
2683 int wxVtkSceneManager::getNumSelectedObjects() {
2684 return _selectedObjects.size();
2687 //=========================================================================
2689 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2690 std::map<int, GObjectController*> mapSelected;
2692 std::map<int, GObjectController*>::iterator it;
2693 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2694 GObjectController *cont = it->second;
2695 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2697 mapSelected[cont->getId()] = cont;
2701 std::map<int, GObjectController*>::iterator it2;
2702 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2703 GObjectController *cont = it2->second;
2704 if (cont->getGObjectType() == GCONNECTOR) {
2705 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2706 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2707 GBoxModel* startPortParentBox =
2708 cmod->getStartPort()->getParentBox();
2710 std::map<int, GObjectController*>::iterator iterOBJ1 =
2711 mapSelected.find(startPortParentBox->getObjectId());
2712 std::map<int, GObjectController*>::iterator iterOBJ2 =
2713 mapSelected.find(endPortParentBox->getObjectId());
2715 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2716 int ID = cont->getId();
2717 mapSelected[ID] = cont;
2724 //=========================================================================
2726 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2728 std::map<int, int> oldIdNewIdBoxes;
2729 std::vector<int> connections;
2731 std::map<int, GObjectController*>::iterator it;
2732 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2733 GObjectController *cont = it->second;
2734 int type = cont->getGObjectType();
2736 if (type == GBLACKBOX) {
2738 double xInic, yInic, zInic;
2739 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2740 copyBox->getInicPoint(xInic, yInic, zInic);
2741 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2743 int idcB = copyBox->getObjectId();
2744 oldIdNewIdBoxes[idcB] = idBox;
2745 cont = _controllers[idBox];
2746 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2747 newbox->setInicPoint(xInic, yInic, zInic);
2748 int num = newbox->getNumInputPorts();
2749 for (int j = 0; j < num; j++)
2751 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2753 newbox->notifyObservers(_idManager);
2754 } else if (type == GCONNECTOR) {
2755 int idCon = cont->getId();
2756 connections.push_back(idCon);
2761 for (int i = 0; i < (int) connections.size(); i++) {
2762 int objId = connections[i];
2763 GObjectController *cont = objectsMap[objId];
2764 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2766 GPortModel* startPort = connectModel->getStartPort();
2767 int startPortIndex = startPort->getPosInBox();
2768 GPortModel* endPort = connectModel->getEndPort();
2769 int endPortIndex = endPort->getPosInBox();
2771 GBlackBoxModel* startPortParentBox =
2772 (GBlackBoxModel*) startPort->getParentBox();
2773 GBlackBoxModel* endPortParentBox =
2774 (GBlackBoxModel*) endPort->getParentBox();
2776 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2777 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2779 GBlackBoxModel* newStartBox =
2780 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2781 GBlackBoxModel* newEndBox =
2782 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2784 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2785 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2787 // Creates connection
2788 int idCon = createGConnector(newStartPort);
2789 GConnectorController *tempp =
2790 (GConnectorController*) _controllers[idCon];
2791 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2792 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2793 tempp->endContourCreation();
2794 conMod->setEndPort(newEndPort);
2795 conView->updateStartEndPoints();
2798 std::map<int, int>::iterator itIds;
2799 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2800 int idOld = itIds->first;
2801 int idNew = itIds->second;
2803 GBlackBoxModel* oldBox =
2804 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2805 GBlackBoxModel* newBox =
2806 (GBlackBoxModel*) _controllers[idNew]->getModel();
2808 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2809 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2810 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2811 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2813 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2815 //EED int toCreate=-1;
2816 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2817 if (oldInputConnections[k] == newInputConnections[l]) {
2822 if (exist == false) {
2823 //Create complex input
2824 int posInBox = oldInputConnections[k];
2825 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2826 std::string inputPortName = inputPort->getBBTKName();
2827 int idInputPort = createGComplexBoxInputPort(inputPortName);
2828 GObjectController *cont = _controllers[idInputPort];
2829 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2830 double xIn, yIn, zIn;
2831 inputPort->getInicPoint(xIn, yIn, zIn);
2833 cbmod->setInicPoint(xIn, yIn, zIn);
2834 cbmod->notifyObservers(_idManager);
2836 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2838 // Creates connection
2839 int idCon = createGConnector(cbmod->getOutputPort(0));
2840 GConnectorController *tempp =
2841 (GConnectorController*) _controllers[idCon];
2842 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2843 vtkGConnectorView *conView =
2844 (vtkGConnectorView*) tempp->getView();
2845 tempp->endContourCreation();
2846 conMod->setEndPort(inputPortEnd);
2847 conView->updateStartEndPoints();
2853 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2855 //EED int toCreate=-1;
2856 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2857 if (oldOutputConnections[k] == newOutputConnections[l]) {
2862 if (exist == false) {
2863 //Create complex output
2864 int posInBox = oldOutputConnections[k];
2865 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2866 std::string outputPortName = outputPort->getBBTKName();
2867 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2868 GObjectController *cont = _controllers[idOutputPort];
2869 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2870 double xIn, yIn, zIn;
2871 outputPort->getInicPoint(xIn, yIn, zIn);
2873 cbmod->setInicPoint(xIn, yIn, zIn);
2874 cbmod->notifyObservers(_idManager);
2876 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2878 // Creates connection
2879 int idCon = createGConnector(outputPortEnd);
2880 GConnectorController *tempp =
2881 (GConnectorController*) _controllers[idCon];
2882 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2883 vtkGConnectorView *conView =
2884 (vtkGConnectorView*) tempp->getView();
2885 tempp->endContourCreation();
2886 conMod->setEndPort(cbmod->getInputPort(0));
2887 conView->updateStartEndPoints();
2897 //=========================================================================
2898 void wxVtkSceneManager::SetCbName(std::string cbName) {
2900 if (_cbName == "") {
2901 _cbName = "<complex box name>";
2905 //=========================================================================
2906 std::string wxVtkSceneManager::GetCbName() {
2910 //=========================================================================
2911 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2912 _cbPackageName = packagename;
2913 if (_cbPackageName == "") {
2914 _cbPackageName = "<package name of the complex box>";
2918 //=========================================================================
2919 std::string wxVtkSceneManager::GetCbPackageName() {
2920 return _cbPackageName;
2923 //=========================================================================
2924 void wxVtkSceneManager::SetAuthor(std::string author) {
2926 if (_Author == "") {
2927 _Author = "<author of the box>";
2931 //=========================================================================
2932 std::string wxVtkSceneManager::GetAuthor() {
2936 //=========================================================================
2937 void wxVtkSceneManager::SetCategory(std::string category) {
2938 _Category = category;
2939 if (_Category == "") {
2940 _Category = "<category of the box>";
2944 //=========================================================================
2945 std::string wxVtkSceneManager::GetCategory() {
2949 //=========================================================================
2950 void wxVtkSceneManager::SetDescription(std::string description) {
2951 _Description = description;
2952 if (_Description == "") {
2953 _Description = "<description of the box>";
2957 //=========================================================================
2958 std::string wxVtkSceneManager::GetDescription() {
2959 return _Description;
2962 //=========================================================================
2964 void wxVtkSceneManager::SetMessageKind(std::string kind) {
2965 _MessageKind = kind;
2969 //=========================================================================
2971 std::string wxVtkSceneManager::GetMessageKind(){
2972 return _MessageKind;
2975 //=========================================================================
2977 void wxVtkSceneManager::SetMessageLevel(std::string Level){
2978 _MessageLevel = Level;
2981 //=========================================================================
2983 std::string wxVtkSceneManager::GetMessageLevel(){
2984 return _MessageLevel;
2987 //=========================================================================
2989 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
2992 std::vector< std::string> extInputs;
2993 std::map<int, GObjectController*>::iterator it;
2994 for (it = _controllers.begin(); it != _controllers.end(); ++it)
2996 GObjectController *cont = it->second;
2997 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
2999 extInputs.push_back(cont->getModel()->getBBTKName());
3005 //=========================================================================
3009 void wxVtkSceneManager::printAll(int com , int sta ){
3011 int tmpState = sta ;
3012 if ( tmpState == NOTHING_HAPPENS ) {
3013 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
3015 if ( tmpState == HIGHLIGHTED ) {
3016 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
3018 if ( tmpState == POSSIBLE_CONNECTION ) {
3019 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
3021 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
3022 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
3024 if ( tmpState == CLICKED ) {
3025 std::cout << "CONTROLER STATE---->CLICKED\n" ;
3027 if ( tmpState == DRAG ) {
3028 std::cout << "CONTROLER STATE---->DRAG\n" ;
3030 if ( tmpState == SELECTED ) {
3031 std::cout << "CONTROLER STATE---->SELECTED\n" ;
3033 if ( tmpState == CREATING_CONTOUR ) {
3034 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
3040 if ( command == INIT_CREATION_CONTOUR ) {
3041 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
3043 if ( command == FIN_CREATION_CONTOUR ) {
3044 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
3046 if ( command == ADD_TO_SELECTED ) {
3047 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
3049 if ( command == DRAG_OBJECTS ) {
3050 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
3052 if ( command == EDIT_BLACKBOX ) {
3053 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
3055 if ( command == REMOVE_FROM_SELECTED ) {
3056 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
3062 } // EO namespace bbtk