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)
75 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
79 _cbName = "ComplexBoxName";
80 _cbPackageName = "PackageName";
81 _Author = "Author ??";
83 _Description = "Description ??";
87 _bugTextActor_text = "void";
88 _bugTextActor_status = 0;
92 _idManager = idManager;
94 _bbtkfactory = bbtkfactory;
96 _startDragging = false;
97 _isComplexBox = false;
99 if (_baseView != NULL) {
102 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
105 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
109 _worldState = NOTHING_HAPPENS;
110 registerController(this);
113 _idConnectionInCreation = -1;
118 //=========================================================================
120 void wxVtkSceneManager::disconnectDrop()
122 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
123 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
126 //=========================================================================
128 wxVtkSceneManager::~wxVtkSceneManager()
135 //=========================================================================
137 void wxVtkSceneManager::configureBaseView()
139 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
141 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
143 // Important to activate the 2D interaction system
144 crea::wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
145 interactorstylebaseview->SetInteractor(iren);
146 iren->SetInteractorStyle(interactorstylebaseview);
147 interactorstylebaseview->SetwxVtkBaseView(_baseView);
149 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
150 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, -1000, 1000);
151 _baseView->GetRenderer()->GetActiveCamera()->Zoom(10);
154 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
155 _baseView->GetRenderer()->GradientBackgroundOn();
158 _textActor = vtkTextActor3D::New();
159 // _textActor = vtkTextActor::New();
160 _textActor->SetPosition(-9999, -9999, GPOSITION_Z);
161 _textActor->SetInput("<void>");
162 _textActor->GetTextProperty()->SetFontSize(60);
163 _textActor->GetTextProperty()->BoldOn();
164 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,PORTTEXT_NH_B);
166 _baseView->GetRenderer()->AddActor(_textActor);
168 // Actor Fill_Port_Text
173 double zInic = GPOSITION_Z;
175 vtkPolygon *aPolygon = vtkPolygon::New();
176 _fillObjectActor = vtkActor::New();
178 _pts = vtkPoints::New();
180 double w = 100, h = 10, b = h / 15, t = 3;
181 _pts->SetNumberOfPoints(21);
182 _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
183 _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
184 _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
185 _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
186 _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
188 _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
189 _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
190 _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
191 _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
193 _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
194 _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
195 _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
196 _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
198 _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
199 _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
200 _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
201 _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
203 _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
204 _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
205 _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
206 _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
208 aPolygon->GetPointIds()->SetNumberOfIds(21);
209 for (int i = 0; i < 21; i++) {
210 aPolygon->GetPointIds()->SetId(i, i);
213 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
214 aPolygonGrid->Allocate(1, 1);
215 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),
216 aPolygon->GetPointIds());
217 aPolygonGrid->SetPoints(_pts);
218 _aPolygonMapper = vtkDataSetMapper::New();
220 //EED 2017-01-01 Migration VTK7
221 #if VTK_MAJOR_VERSION <= 5
222 _aPolygonMapper->SetInput(aPolygonGrid);
224 _aPolygonMapper->SetInputData(aPolygonGrid);
228 _fillObjectActor->SetMapper(_aPolygonMapper);
229 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
231 _fillObjectActor->GetProperty()->SetOpacity(0);
232 _aPolygonMapper->Modified();
234 _baseView->GetRenderer()->AddActor(_fillObjectActor);
237 //=========================================================================
239 std::string wxVtkSceneManager::generateANewNameForABox() {
240 std::stringstream boxname;
241 if (_numBoxes < 10) {
242 boxname << "Box0" << _numBoxes;
244 boxname << "Box" << _numBoxes;
247 return boxname.str();
250 //=========================================================================
252 std::string wxVtkSceneManager::findANewNameForABox() {
253 std::string boxname = generateANewNameForABox();
255 while (boxExist(boxname) == true) {
256 boxname = generateANewNameForABox();
262 //=========================================================================
263 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
264 double zIn, std::string name, bool boxExecutable, double xEn,
265 double yEn, double zEn) {
266 GObjectController *cont = _controllers[idBox];
267 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
268 bbmod->setBBTKName(name);
269 bbmod->setInicPoint(xIn, yIn, zIn);
270 bbmod->setFinalPoint(xEn, yEn, zEn);
271 bbmod->setExecutable(boxExecutable);
273 bbmod->notifyObservers(_idManager);
277 //=========================================================================
279 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,std::string boxType)
281 _worldState = NOTHING_HAPPENS;
282 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
283 int type = GBLACKBOX;
284 //Create the MVC Objects
285 GBlackBoxModel *model = (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
286 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
287 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
289 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
293 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
295 k = _bbtkfactory->GetPackage(packageName);
296 mapDesc = k->GetDescriptorMap();
298 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for package %s, NOT EXIST\n", packageName.c_str());
301 BlackBoxDescriptor::Pointer descriptor;
303 descriptor = mapDesc[boxType];
305 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for box %s of package %s, NOT EXIST\n", boxType.c_str(),packageName.c_str());
308 if (descriptor == NULL)
310 printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
313 //Prepares the initial model
314 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
317 double yy = windowHeight - y;
319 //z value is not important yet, because it is only used a parallel projection
320 double zz = GPOSITION_Z;
321 _baseView->TransCoordScreenToWorld(xx, yy, zz);
322 model->setInicPoint(xx, yy, zz);
324 std::stringstream stream;
326 std::string newBoxName;
327 newBoxName = findANewNameForABox();
329 stream << newBoxName;
331 std::string arraystring = stream.str();
333 model->setBBTKName(arraystring);
334 model->setBBTKType(boxType);
335 model->setBBTKPackage(packageName);
337 model->addObserver(view);
338 model->addObserver(this);
341 //EED2017 change order
342 //Associates the view with the correspondent renderer and the model.
343 //(NOTE: Refresh is only made by the view)
344 view->setModel(model);
345 view->setBaseView(_baseView);
347 //Associates the controller with the correspondent model and view
348 controller->setModelAndView(model, view);
351 //Iterate and create the input ports
352 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
353 descriptor->GetInputDescriptorMap();
354 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
356 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
358 BlackBoxInputDescriptor *desc = itInput->second;
360 // createGInputPort(GINPUTPORT, i, model, desc);
361 createGInputPort(GINPUTPORT, i, controller, desc);
365 //Iterate and create the output ports
366 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
367 descriptor->GetOutputDescriptorMap();
368 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
370 for (itOutput = descriptorOutMap.begin(); itOutput!= descriptorOutMap.end(); ++itOutput)
372 BlackBoxOutputDescriptor *desc = itOutput->second;
374 // createGOutputPort(GOUTPUTPORT, i, model, desc);
375 createGOutputPort(GOUTPUTPORT, i, controller, desc);
379 //EED2017 change order
380 view->initVtkObjects();
382 //Resgiter change to the observers of the actual model
383 model->notifyObservers(_idManager);
384 int newId = addObjectController(controller);
390 //=========================================================================
392 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
393 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
394 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
396 int type = GCOMPLEXINPUTPORT;
398 //Create the MVC Objects
400 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
401 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
402 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
404 //Prepares the initial model
407 double yy = windowHeight - 5;
409 //z value is not important yet, because it is only used a parallel projection
410 double zz = GPOSITION_Z;
412 _baseView->TransCoordScreenToWorld(xx, yy, zz);
413 model->setInicPoint(xx, yy, zz);
415 model->setBBTKName(inputName);
416 model->setBBTKType("ComplexInputPort");
417 model->setComplexPortType(type);
419 model->addObserver(view);
420 model->addObserver(this);
422 //create the output port
423 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
424 "ComplexOutputPortType","ComplexOutputPortDescriopton", 0, model);
425 model->addOutputPort((GPortModel*) portController->getModel());
427 //Associates the view with the correspondent renderer and the model.
428 //(NOTE: Refresh is only made by the view)
429 view->setModel(model);
430 view->setBaseView(_baseView);
431 view->initVtkObjects();
433 //Associates the controller with the correspondent model and view
434 controller->setModelAndView(model, view);
436 //Resgiter change to the observers of the actual model
437 model->notifyObservers(_idManager);
439 int newId = addObjectController(controller);
443 //=========================================================================
445 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
446 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
447 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
449 int type = GCOMPLEXOUTPUTPORT;
451 //Create the MVC Objects
453 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
454 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
455 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
457 //Prepares the initial model
460 double yy = windowHeight - 5;
462 //z value is not important yet, because it is only used a parallel projection
463 double zz = GPOSITION_Z;
465 _baseView->TransCoordScreenToWorld(xx, yy, zz);
466 model->setInicPoint(xx, yy, zz);
468 model->setBBTKName(outputName);
469 model->setBBTKType("ComplexOutputPort");
470 model->setComplexPortType(type);
472 model->addObserver(view);
473 model->addObserver(this);
475 //create the output port
476 GPortController* portController = createGPort(GINPUTPORT, outputName,
477 "ComplexInputPort","ComplexInputPortDescription", 0, model);
478 model->addInputPort((GPortModel*) portController->getModel());
480 //Associates the view with the correspondent renderer and the model.
481 //(NOTE: Refresh is only made by the view)
482 view->setModel(model);
483 view->setBaseView(_baseView);
484 view->initVtkObjects();
486 //Associates the controller with the correspondent model and view
487 controller->setModelAndView(model, view);
489 //Resgiter change to the observers of the actual model
490 model->notifyObservers(_idManager);
492 int newId = addObjectController(controller);
496 //=========================================================================
499 //int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
500 int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GObjectController *gBoxControler, BlackBoxInputDescriptor *desc)
502 GBoxModel *blackBox=(GBoxModel*)gBoxControler->getModel();
503 GPortController* portController = createGPort(portType, desc->GetName(),
504 desc->GetTypeName(), desc->GetDescription(), posinBox, blackBox);
505 blackBox->addInputPort( (GPortModel*)portController->getModel() );
507 vtkGBoxView *vtkgboxView=(vtkGBoxView*)gBoxControler->getView();
508 vtkgboxView->addInputPort( (vtkGPortView*)portController->getView() );
510 return portController->getId();
513 //=========================================================================
516 //int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
517 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GObjectController *gBoxControler, BlackBoxOutputDescriptor *desc)
519 GBoxModel *blackBox=(GBoxModel*)gBoxControler->getModel();
520 GPortController* portController = createGPort(portType, desc->GetName(),
521 desc->GetTypeName(),desc->GetDescription(), posinBox, blackBox);
522 blackBox->addOutputPort((GPortModel*) portController->getModel());
524 vtkGBoxView *vtkgboxView=(vtkGBoxView*)gBoxControler->getView();
525 vtkgboxView->addOutputPort( (vtkGPortView*)portController->getView() );
527 return portController->getId();
530 //=========================================================================
532 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posInBox,GBoxModel *blackBox)
536 //Create the MVC Objects
537 GPortModel *model = (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
538 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
539 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
540 model->registerInBox(blackBox, portType, posInBox);
541 model->setBBTKType(bbtkType);
542 model->setBBTKName(bbtkName);
543 model->setBBTKDescription(bbtkDescription);
544 model->addObserver(view);
545 model->addObserver(this);
546 //Associates the view with the correspondent renderer and the model.
547 //(NOTE: Refresh is only made by the view)
548 view->setModel(model);
549 view->setBaseView(_baseView);
550 //EED017 view->initVtkObjects();
551 view->createVtkObjects();
552 // view->addVtkActors();
554 //Associates the controller with the correspondent model and view
555 controller->setModelAndView(model, view);
556 model->notifyObservers(_idManager);
557 addObjectController(controller);
558 return (GPortController*) controller;
561 //=========================================================================
563 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
565 int type = GCONNECTOR;
567 manualConnectorContourController *manContourControl = new manualConnectorContourController();
568 manualConnectorContourView *manContourView = new manualConnectorContourView();
569 manualContourModel *manContourModel = new manualContourModel();
570 GConnectorController *connectorcontroller = new GConnectorController();
571 GConnectorModel *connectorModel = new GConnectorModel();
572 vtkGConnectorView *connectorView = new vtkGConnectorView();
573 connectorModel->setGObjectType(type);
575 manContourModel->SetCloseContour(false);
576 connectorModel->setStartPort(startPort);
578 manContourView->SetModel(manContourModel);
579 manContourView->SetWxVtkBaseView(_baseView);
580 manContourView->SetRange(0.5);
581 manContourView->SetZ(GPOSITION_Z);
583 manContourView->SetColorNormalContour(0, 0, 1);
584 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
585 manContourView->SetColorSelectContour(1, 0.8, 0);
591 * Width increased from 2 to 3, it simplifies line handling and spline control :P
595 manContourView->SetWidthLine( 3 ) ;
596 manContourView->SetShowText(false);
598 manContourControl->SetModelView(manContourModel, manContourView);
600 manContourControl->CreateNewManualContour();
604 connectorModel->getInicPoint(x, y, z);
607 manContourControl->SetState(1);
608 manContourModel->SetCloseContour(false);
610 manContourModel->AddPoint(x, y, z);
611 manContourView->AddPoint();
613 manContourModel->AddPoint(x, y, z);
614 manContourView->AddPoint();
616 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
617 manContourControl->_bakIdPoint = bak;
619 manContourControl->SetMoving(false);
621 connectorcontroller->setModelAndView(connectorModel, connectorView);
623 int newId = addObjectController(connectorcontroller);
625 connectorcontroller->setManualContourController(manContourControl);
626 connectorModel->setManualContourModel(manContourModel);
627 connectorView->setManualContourView(manContourView);
628 connectorView->setModel(connectorModel);
629 connectorView->setBaseView(_baseView);
631 connectorModel->addObserver(connectorView);
632 connectorModel->addObserver(this);
634 // manContourView->Refresh();
639 //=========================================================================
641 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
643 vtkInteractorStyleBaseView * baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
644 baseViewControlManager->AddInteractorStyleMaracas(param);
647 //=========================================================================
649 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
651 vtkInteractorStyleBaseView *baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
652 baseViewControlManager->RemoveInteractorStyleMaracas(param);
655 //=========================================================================
657 vtkRenderer* wxVtkSceneManager::getRenderer()
659 return _baseView->GetRenderer();
662 //=========================================================================
664 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
666 return _baseView->GetRenWin();
668 //=========================================================================
671 //=========================================================================
672 int wxVtkSceneManager::GetIndexInSelected(int idControler)
675 for (int i = 0; i < (int) _selectedObjects.size(); i++)
677 if (_selectedObjects[i] == idControler)
685 //=========================================================================
687 void wxVtkSceneManager::update(int idController, int command) {
689 if (command != NO_COMMAND)
691 if (command == ADD_TO_SELECTED)
693 if (GetIndexInSelected(idController) == -1)
695 _selectedObjects.push_back(idController);
697 } else if (command == REMOVE_FROM_SELECTED) {
698 int index = GetIndexInSelected(idController);
701 _selectedObjects.erase(_selectedObjects.begin() + index);
703 } else if (command == INIT_CREATION_CONTOUR) {
705 typedef std::map<int , GObjectController*>::iterator TIterator ;
708 // Find current item in the controller
709 iter = _controllers.find( idController ) ;
710 iter_end = _controllers.end( ) ;
712 if ( iter != iter_end ) {
713 GObjectController* gobjc = iter->second ;
715 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
716 // And if the item is a port
717 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
718 TIterator c_it = _controllers.begin( ) ;
719 // Go through all componets
720 for ( c_it ; c_it != iter_end ; c_it++ ) {
721 GObjectController* obc = c_it->second ;
722 int obc_type = obc->getModel( )->getGObjectType( ) ;
723 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
724 // if the component is a port and the type is the same of that selected
725 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
727 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
728 //obc->getView( )->setState( HIGHLIGHTED ) ;
736 _worldState = INIT_CREATION_CONTOUR;
737 GObjectController* cont = _controllers[idController];
738 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
740 // The last one is the controller of the connector
741 std::map<int, GObjectController*>::iterator it2;
743 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
745 GObjectController *cont = it2->second;
746 if (cont->getGObjectType() == GPORT)
748 GPortModel* port = (GPortModel*) cont->getModel();
749 if (port->getPortType() == GINPUTPORT)
751 cont->SetActive(true);
753 cont->getView()->setState(NOTHING_HAPPENS);
754 cont->getModel()->notifyObservers(_idManager);
755 cont->SetActive(false);
758 cont->getView()->setState(NOTHING_HAPPENS);
759 cont->getModel()->notifyObservers(_idManager);
760 cont->SetActive(false);
763 _selectedObjects.clear();
764 _idConnectionInCreation = createGConnector(startOutputPort);
765 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
766 _worldState = NOTHING_HAPPENS;
767 //int id = _controllers.size()-1;
768 GObjectController *cont = _controllers[_idConnectionInCreation];
769 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
770 GObjectController *finPort = _controllers[idController];
772 if (finPort->getGObjectType() == GPORT)
774 GPortModel* modelPort = (GPortModel*) finPort->getModel();
775 modelContour->setEndPort(modelPort);
778 typedef std::map<int, GObjectController*>::iterator TIterator;
779 TIterator c_it = _controllers.begin();
780 TIterator iter_end = _controllers.end();
781 // Go through all componets
782 for (c_it; c_it != iter_end; c_it++) {
783 GObjectController* obc = c_it->second;
784 int obc_type = obc->getModel()->getGObjectType();
785 int obc_state = obc->getView()->getState();
786 // if the component is a port and the type is the same of that selected
787 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
788 // Return element to neutral state if not selected
789 obc->getView()->setState(NOTHING_HAPPENS);
791 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
792 // Change element to connected state
793 obc->getView()->setState(HIGHLIGHTED);
799 _parent->saveTempandUpdate("create connection");
802 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
803 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
805 std::map<int, GObjectController*>::iterator it2;
807 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
809 GObjectController *cont = it2->second;
810 if (cont->getView() != NULL) {
811 cont->getView()->setState(NOTHING_HAPPENS);
812 cont->getModel()->notifyObservers(_idManager);
814 cont->SetActive(true);
823 //=========================================================================
825 bool wxVtkSceneManager::OnMouseMove()
828 bool okStatusMessage = false;
829 bool okPortMessage = false;
830 crea::wxVTKRenderWindowInteractor *wxVTKiren;
831 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
832 wxVTKiren->GetEventPosition(X, Y);
834 if (_worldState == DRAG_OBJECTS) {
835 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
836 int id = _selectedObjects[i];
837 GObjectController* cont = _controllers[id];
838 if (_startDragging) {
839 cont->getView()->setStartDragging(true);
841 cont->getView()->moveObject(X, Y);
842 cont->getView()->setState(DRAG);
843 cont->getModel()->notifyObservers(_idManager);
846 std::map<int, GObjectController*>::iterator it;
848 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
849 GObjectController *desc = it->second;
850 if (desc->getGObjectType() == GCONNECTOR) {
851 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
852 vconn->updateStartEndPoints();
856 _startDragging = false;
858 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
859 std::map<int, GObjectController*>::iterator it;
861 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
862 GObjectController *desc = it->second;
863 int type = desc->getGObjectType();
864 int state = desc->getView()->getState();
865 desc->getModel()->getCenter(px, py, pz);
868 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
871 okStatusMessage = true;
872 updateStatusBar(desc->getStatusText());
873 if (type == GBLACKBOX)
875 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
876 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
881 if ( ( _bugTextActor_text==desc->getStatusText() ) || (_bugTextActor_status==0) )
883 _bugTextActor_status = 1;
884 okPortMessage = true;
886 _textActor->SetScale(0.1);
887 std::string tmp = desc->getStatusText()+"\n";
888 _textActor->SetInput( tmp.c_str() );
889 _textActor->SetPosition(px - 25, py + 1, pz + 2);
890 _textActor->Modified();
894 _fillObjectActor->SetScale(1);
895 _fillObjectActor->GetProperty()->SetOpacity(0.50);
896 _fillObjectActor->SetPosition(px, py, 1);
897 _aPolygonMapper->Modified();
899 _bugTextActor_status = 2;
900 } // _bugTextActor_tex
901 _bugTextActor_text = desc->getStatusText();
905 } // for controllers it
907 if (okStatusMessage == false)
912 if ((okPortMessage == false) || (_bugTextActor_status== 2 ) )
914 _bugTextActor_status = 0;
915 _textActor->SetScale(0.0001);
916 _textActor->SetInput("a\n");
917 _textActor->Modified();
918 _fillObjectActor->SetScale(0.0001);
923 //=========================================================================
925 bool wxVtkSceneManager::OnLeftButtonDown()
927 if (_worldState == INIT_CREATION_CONTOUR)
929 bool isOverPort = false;
930 std::map<int, GObjectController*>::iterator it;
931 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
933 GObjectController *desc = it->second;
934 if (desc->getGObjectType() == GPORT)
936 GPortModel *portmod = (GPortModel*) desc->getModel();
937 vtkGObjectView *portView = desc->getView();
938 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
943 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
945 portView->setState( HIGHLIGHTED);
952 if (isOverPort == false)
955 UnSelectBlackBoxes();
959 } else { //_worldState
961 _worldState = DRAG_OBJECTS;
962 _startDragging = true;
964 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
965 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
966 ctrlkey = ctrlkey + shiftkey;
968 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
971 int state = cont->getView()->getState();
972 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
973 UnSelectBlackBoxes();
976 UnSelectBlackBoxes(); // EED 12/07/2012
978 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
979 int id = _selectedObjects[i];
980 GObjectController *cont = _controllers[id];
981 cont->getView()->setState(DRAG);
982 cont->getModel()->notifyObservers(_idManager);
984 } // if _selectedObjects.size
990 //=========================================================================
992 bool wxVtkSceneManager::OnLeftButtonUp()
994 if (_worldState == DRAG_OBJECTS) {
995 _worldState = NOTHING_HAPPENS;
997 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
998 int id = _selectedObjects[i];
999 GObjectController* cont = _controllers[id];
1000 cont->getView()->setState(SELECTED);
1001 cont->getModel()->notifyObservers(_idManager);
1007 //=========================================================================
1008 void wxVtkSceneManager::CancelConnection()
1010 if (_worldState == INIT_CREATION_CONTOUR)
1012 _worldState = NOTHING_HAPPENS;
1013 //int lastId = _controllers.size()-1;
1015 GConnectorController *connector =
1016 (GConnectorController*) _controllers[_idConnectionInCreation];
1017 connector->removeFromScene();
1018 unregisterController(connector);
1019 _controllers.erase(_idConnectionInCreation);
1021 std::map<int, GObjectController*>::iterator it;
1022 for (it = _controllers.begin(); it != _controllers.end(); ++it)
1024 GObjectController *desc = it->second;
1025 desc->SetActive(true);
1026 desc->getView()->setState(NOTHING_HAPPENS);
1027 desc->getModel()->notifyObservers(_idManager);
1032 //=========================================================================
1034 bool wxVtkSceneManager::OnRightButtonUp()
1036 if (_worldState == INIT_CREATION_CONTOUR)
1040 UnSelectBlackBoxes();
1046 bool wxVtkSceneManager::OnMiddleButtonDown() {
1049 this->_vtkInteractorStyleBaseView->StartPan();
1054 bool wxVtkSceneManager::OnMiddleButtonUp() {
1057 this->_vtkInteractorStyleBaseView->EndPan();
1064 //=========================================================================
1066 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1067 GObjectController *result = NULL;
1069 crea::wxVTKRenderWindowInteractor *wxVTKiren;
1071 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1072 wxVTKiren->GetEventPosition(X, Y);
1074 std::map<int, GObjectController*>::iterator it;
1076 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1077 GObjectController *cont = it->second;
1078 int type = cont->getGObjectType();
1080 if (cont->getView()->isPointInside(X, Y) == true) {
1081 if (type == GBLACKBOX) {
1084 } // if isPointInside
1089 //=========================================================================
1090 void wxVtkSceneManager::UnSelectBlackBoxes() {
1091 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1092 int id = _selectedObjects[i];
1093 GObjectController* control = _controllers[id];
1094 control->getView()->setState(NOTHING_HAPPENS);
1095 control->getModel()->notifyObservers(_idManager);
1096 }// for _selectedObjects
1097 _selectedObjects.clear();
1100 //=========================================================================
1101 bool wxVtkSceneManager::OnLeftDClick() {
1102 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1104 UnSelectBlackBoxes();
1105 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1110 //=========================================================================
1112 bool wxVtkSceneManager::OnChar()
1116 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1117 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1119 // KeyCode 127 : Delete Key
1120 // KeyCode 8 : Backspace Key
1123 if (keyCode == 8 || keyCode == 127 || keyCode == 27)
1125 if (_worldState == INIT_CREATION_CONTOUR)
1128 UnSelectBlackBoxes();
1133 if (keyCode == 8 || keyCode == 127)
1136 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1138 int id = _selectedObjects[i];
1139 std::map<int, GObjectController*>::iterator it;
1140 it = _controllers.find(id);
1141 if (it != _controllers.end())
1143 oktmp = deleteObject(id);
1146 }// for selected objects
1147 if (ok) _selectedObjects.clear();
1148 _parent->saveTempandUpdate("delete object");
1154 if(_selectedObjects.size()){
1155 std::cout<<"objects to copy :";
1156 for(int i=0;i<_selectedObjects.size();i++)
1158 std::cout<<_selectedObjects.at(i)<<" ";
1160 DuplicateObjects(getSelectedObjects());
1162 std::cout<<"No objects to copy\n";
1163 } // _selectedObjects.size
1169 //=========================================================================
1171 void wxVtkSceneManager::AddControlerToBeRemove(
1172 std::vector<int> *controllersToRemove, int id) {
1176 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1177 if (id == (*controllersToRemove)[i]) {
1183 controllersToRemove->push_back(id);
1188 //=========================================================================
1190 bool wxVtkSceneManager::deleteObject(int id)
1193 GObjectController *control = _controllers[id];
1194 std::vector<int> controllersToRemove;
1195 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1196 == GCOMPLEXINPUTPORT || control->getGObjectType()
1197 == GCOMPLEXOUTPUTPORT) {
1198 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1199 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1201 bool boxConnected = false;
1203 // Add box input controllers to be removed
1204 for (int i = 0; i < (int) inputs.size(); i++) {
1205 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1206 if (inputs[i]->isConnected()) {
1207 boxConnected = true;
1211 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1213 // Add box output controllers to be removed
1214 for (int i = 0; i < (int) outputs.size(); i++) {
1215 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1216 if (outputs[i]->isConnected()) {
1217 boxConnected = true;
1221 // Add connection controllers to be removed
1222 std::map<int, GObjectController*>::iterator it;
1223 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1224 GObjectController *cont = it->second;
1225 int type = cont->getGObjectType();
1226 if (type == GCONNECTOR) {
1227 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1228 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1230 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1232 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1234 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1239 // Add box controller to be removed
1240 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1241 } else if (control->getGObjectType() == GCONNECTOR) {
1242 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1243 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1245 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1246 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1248 gconnectorcontroler->getManualContourController()->OnChar();
1253 std::map<int, GObjectController*>::iterator it;
1255 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1256 int key = controllersToRemove[i];
1257 it = _controllers.find(key);
1258 GObjectController *cont = _controllers[key];
1260 cont->removeFromScene();
1261 unregisterController((InteractorStyleMaracas*) cont);
1262 _controllers.erase(it);
1270 //=========================================================================
1272 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1273 std::string boxName) {
1274 _parent->displayBlackBoxInfo(packageName, boxName);
1277 //=========================================================================
1279 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1280 _parent->updateStatusBar(textStatus);
1283 //=========================================================================
1284 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1285 std::string result = "";
1286 if (withLineNumber == true) {
1288 stringstream StrStream;
1290 std::string strValue = StrStream.str();
1293 } else if (value < 100) {
1297 result += strValue + ": ";
1301 //=========================================================================
1303 bool wxVtkSceneManager::MakeBoxExecutable() {
1304 std::map<int, GObjectController*> selected = getSelectedObjects();
1305 if( selected.empty() )
1308 std::map<int, GObjectController*>::iterator it;
1309 for (it = selected.begin(); it != selected.end(); ++it) {
1310 GObjectController* lastSelected = it->second;
1312 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1313 GBlackBoxModel *bbmodel =
1314 (GBlackBoxModel*) lastSelected->getModel();
1315 view->setState(HIGHLIGHTED);
1316 if (bbmodel->isExecutable()) {
1317 bbmodel->setExecutable(false);
1319 bbmodel->setExecutable(true);
1321 bbmodel->notifyObservers(lastSelected->getId());
1329 //=========================================================================
1331 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1332 std::cout << "wxVtkSceneManager::getDiagramBBS" << std::endl;
1333 bool existsExec = false;
1335 std::vector<std::string> packages;
1336 std::vector<int> boxes;
1337 std::vector<int> connections;
1338 std::vector<int> execBoxes;
1340 std::map<int, GObjectController*>::iterator it;
1342 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1343 GObjectController *desc = it->second;
1344 int type = desc->getGObjectType();
1346 if (type == GBLACKBOX) {
1347 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1349 std::string pkg = mod->getBBTKPackage();
1350 bool existsPkg = false;
1351 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1352 if (packages[t] == pkg) {
1357 packages.push_back(pkg);
1360 boxes.push_back(it->first);
1361 if (mod->isExecutable()) {
1362 execBoxes.push_back(it->first);
1365 } else if (type == GCONNECTOR) {
1366 connections.push_back(it->first);
1371 std::string script = "";
1372 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1373 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1374 script += LineNumber(wln, lnNmbr) + "\n";
1376 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1377 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1379 for (i = 0; i < (int) packages.size(); i++) {
1380 script += LineNumber(wln, lnNmbr);
1381 script += "include ";
1382 script += packages[i];
1386 script += LineNumber(wln, lnNmbr);
1391 script += LineNumber(wln, lnNmbr);
1392 script += "author \"";
1396 script += LineNumber(wln, lnNmbr);
1397 script += "description \"";
1398 script += _Description;
1401 script += LineNumber(wln, lnNmbr);
1402 script += "category \"";
1403 script += _Category;
1406 script += LineNumber(wln, lnNmbr);
1409 // script+="include std\n"; // JPR
1411 for (i = 0; i < (int) boxes.size(); i++) {
1412 script += LineNumber(wln, lnNmbr);
1415 GObjectController *control = _controllers[id];
1416 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1418 script += model->getBBTKPackage()+":";
1419 script += model->getBBTKType();
1421 script += model->getBBTKName();
1424 std::vector<GPortModel*> inputs = model->getInputPorts();
1425 for (int j = 0; j < (int) inputs.size(); j++) {
1426 GPortModel* inputPort = inputs[j];
1427 if (inputPort->isValueSet()) {
1428 script += LineNumber(wln, lnNmbr);
1430 script += model->getBBTKName();
1432 script += inputPort->getBBTKName();
1434 script += inputPort->getValue();
1439 script += LineNumber(wln, lnNmbr);
1444 script += LineNumber(wln, lnNmbr);
1448 std::string complexInputs="";
1450 for (i = 0; i < (int) connections.size(); i++) {
1451 //script += LineNumber(wln, lnNmbr);
1452 //script += "connect ";
1453 int id = connections[i];
1454 GObjectController *control = _controllers[id];
1455 GConnectorModel *model = (GConnectorModel*) control->getModel();
1459 GPortModel *start = model->getStartPort();
1460 GBoxModel *startBox = start->getParentBox();
1462 GPortModel *end = model->getEndPort();
1463 GBoxModel *endBox = end->getParentBox();
1465 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1467 complexInputs += "input ";
1468 complexInputs += startBox->getBBTKName();
1470 complexInputs += " ";
1471 complexInputs += endBox->getBBTKName();
1472 complexInputs += ".";
1473 complexInputs += end->getBBTKName();
1475 complexInputs += " ";
1476 complexInputs += "\" \"";
1478 complexInputs += "\n";
1482 script += LineNumber(wln, lnNmbr);
1483 script += "connect ";
1484 script += startBox->getBBTKName();
1486 script += start->getBBTKName();
1490 //End Connection info
1491 script += endBox->getBBTKName();
1493 script += end->getBBTKName();
1498 script += LineNumber(wln, lnNmbr);
1502 script += LineNumber(wln, lnNmbr);
1505 script += LineNumber(wln, lnNmbr);
1508 script += LineNumber(wln, lnNmbr);
1509 script += "# Complex input ports\n";
1510 script += complexInputs;
1512 if((_MessageKind!="-")&&(_MessageLevel!="-")){
1513 script += LineNumber(wln, lnNmbr);
1514 script += "message ";
1515 script += _MessageKind;
1517 script += _MessageLevel;
1521 for (i = 0; i < (int) execBoxes.size(); i++) {
1522 script += LineNumber(wln, lnNmbr);
1524 int id = execBoxes[i];
1525 GObjectController *control = _controllers[id];
1526 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1528 script += model->getBBTKName();
1537 //=========================================================================
1539 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1540 std::cout<<"wxVtkSceneManager::saveComplexBoxBBS"<<std::endl;
1541 std::vector<std::string> packages;
1542 std::vector<int> boxes;
1543 std::vector<int> connections;
1544 std::vector<int> execBoxes;
1546 std::map<int, GObjectController*>::iterator it;
1548 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1549 GObjectController *desc = it->second;
1550 int type = desc->getGObjectType();
1552 if (type == GBLACKBOX) {
1553 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1555 std::string pkg = mod->getBBTKPackage();
1556 bool existsPkg = false;
1557 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1558 if (packages[t] == pkg) {
1563 packages.push_back(pkg);
1566 boxes.push_back(it->first);
1567 if (mod->isExecutable()) {
1568 execBoxes.push_back(it->first);
1570 } else if (type == GCONNECTOR) {
1571 connections.push_back(it->first);
1575 std::string script = "";
1577 script += "include std\n"; // EED
1578 script += "include itkvtk\n"; // EED
1580 for (i = 0; i < (int) packages.size(); i++) {
1581 script += "include ";
1582 script += packages[i];
1587 // Definition of a complex box
1588 script += "define ";
1589 script += _cbName + " " + _cbPackageName;
1593 script += "author \"";
1597 script += "description \"";
1598 script += _Description;
1602 script += "category \"";
1603 script += _Category;
1608 for (i = 0; i < (int) boxes.size(); i++) {
1611 GObjectController *control = _controllers[id];
1612 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1614 script += model->getBBTKPackage()+":";
1615 script += model->getBBTKType();
1617 script += model->getBBTKName();
1620 std::vector<GPortModel*> inputs = model->getInputPorts();
1621 for (int j = 0; j < (int) inputs.size(); j++) {
1622 GPortModel* inputPort = inputs[j];
1623 if (inputPort->isValueSet()) {
1625 script += model->getBBTKName();
1627 script += inputPort->getBBTKName();
1629 script += inputPort->getValue();
1637 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1639 std::string complexInputs = "";
1640 std::string complexOutputs = "";
1643 for (i = 0; i < (int) connections.size(); i++) {
1644 int id = connections[i];
1645 GObjectController *control = _controllers[id];
1646 GConnectorModel *model = (GConnectorModel*) control->getModel();
1649 GPortModel *start = model->getStartPort();
1650 GBoxModel *startBox = start->getParentBox();
1652 GPortModel *end = model->getEndPort();
1653 GBoxModel *endBox = end->getParentBox();
1655 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1656 complexInputs += "input ";
1657 complexInputs += startBox->getBBTKName();
1659 complexInputs += " ";
1660 complexInputs += endBox->getBBTKName();
1661 complexInputs += ".";
1662 complexInputs += end->getBBTKName();
1664 complexInputs += " ";
1665 complexInputs += "\" \"";
1667 complexInputs += "\n";
1668 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1669 complexOutputs += "output ";
1670 complexOutputs += endBox->getBBTKName();
1672 complexOutputs += " ";
1673 complexOutputs += startBox->getBBTKName();
1674 complexOutputs += ".";
1675 complexOutputs += start->getBBTKName();
1677 complexOutputs += " ";
1678 complexOutputs += "\" \"";
1680 complexOutputs += "\n";
1682 script += "connect ";
1683 script += startBox->getBBTKName();
1685 script += start->getBBTKName();
1689 //End Connection info
1690 script += endBox->getBBTKName();
1692 script += end->getBBTKName();
1699 script += "# Complex input ports\n";
1700 script += complexInputs;
1703 script += "# Complex output ports\n";
1704 script += complexOutputs;
1708 if((_MessageKind!="-")&&(_MessageLevel!="-"))
1710 script += "message ";
1711 script += _MessageKind;
1713 script += _MessageLevel;
1717 for (i = 0; i < (int) execBoxes.size(); i++)
1720 int id = execBoxes[i];
1721 GObjectController *control = _controllers[id];
1722 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1724 script += model->getBBTKName();
1729 script += "endefine";
1735 //=========================================================================
1737 void wxVtkSceneManager::deleteAllBoxes() {
1738 std::map<int, GObjectController*>::iterator it;
1739 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1740 GObjectController *cont = it->second;
1741 cont->removeFromScene();
1742 unregisterController((InteractorStyleMaracas*) cont);
1744 _selectedObjects.clear();
1745 _controllers.clear();
1748 //=========================================================================
1751 void wxVtkSceneManager::refresh() {
1752 _baseView->Refresh();
1754 //=========================================================================
1756 void wxVtkSceneManager::refreshScene()
1758 _baseView->RefreshView();
1761 //=========================================================================
1763 void wxVtkSceneManager::centerView()
1766 _baseView->GetRenderer()->ComputeVisiblePropBounds(bb);
1769 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1770 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1771 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1772 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1774 _baseView->GetRenderer()->ResetCamera();
1775 _baseView->GetRenderer()->ResetCameraClippingRange();
1778 double tt=_baseView->GetRenderer()->GetNearClippingPlaneTolerance();
1779 printf("EED wxVtkSceneManager::centerView() tolerance=%f\n",tt);
1781 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1782 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1783 _baseView->GetRenderer()->GetActiveCamera()->SetClippingRange(0.01,100000);
1784 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1785 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1788 _baseView->GetRenderer()->Render();
1791 //=========================================================================
1793 void wxVtkSceneManager::saveDiagram(std::string &content)
1797 content += "CATEGORY:";
1798 content += GetCategory();
1801 content += "DESCRIPTION:";
1802 content += GetDescription();
1805 content += "AUTHOR:";
1806 content += GetAuthor();
1809 //Print info IF COMPLEX BOX
1810 content += "COMPLEXBOX:";
1811 if (_isComplexBox) {
1812 content += "TRUE\n";
1814 content += "COMPLEXBOXNAME:";
1815 content += GetCbName();
1818 content += "PACKAGENAME:";
1819 content += GetCbPackageName();
1822 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1823 * External inputs are possible for applications and complex boxes
1824 //Print info complex input ports
1825 std::vector<int> inputs = getComplexInputPorts();
1826 int insize = inputs.size();
1827 content += "COMPLEXINPUTS:";
1828 sprintf(buffer, "%d", insize);
1832 for (int i = 0; i < insize; i++) {
1834 GObjectController *cont = _controllers[id];
1835 cont->getModel()->save(content);
1839 //Print info complex output ports
1840 std::vector<int> outputs = getComplexOutputPorts();
1841 int outsize = outputs.size();
1842 content += "COMPLEXOUTPUTS:";
1843 sprintf(buffer, "%d", outsize);
1847 for (int i = 0; i < outsize; i++) {
1848 int id = outputs[i];
1849 GObjectController *cont = _controllers[id];
1850 cont->getModel()->save(content);
1854 content += "FALSE\n";
1857 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1858 // External inputs are possible for applications and complex boxes
1859 std::vector<int> inputs = getComplexInputPorts();
1860 int insize = inputs.size();
1861 content += "COMPLEXINPUTS:";
1862 sprintf(buffer, "%d", insize);
1866 for (int i = 0; i < insize; i++) {
1868 GObjectController *cont = _controllers[id];
1869 cont->getModel()->save(content);
1873 std::vector<int> boxes = getBlackBoxes();
1874 int bsize = boxes.size();
1875 content += "BOXES:";
1876 sprintf(buffer, "%d", bsize);
1880 for (int i = 0; i < bsize; i++) {
1882 // std::cout<<"id "<<id<<std::endl;//CFT
1883 GObjectController *cont = _controllers[id];
1884 // std::cout<<"nombre: "<<cont->getStatusText()<<std::endl;//CFT
1885 // std::cout<<"tipo: "<<cont->getModel()->getBBTKType()<<std::endl;//CFT
1886 // //boxesDiagram[i] = cont->getModel()->getBBTKType();//CFT
1887 // std::cout<<"nname: "<<cont->getModel()->getBBTKName()<<std::endl;//CFT
1888 // std::cout<<"categorie: "<<GetCategory()<<std::endl;//CFT
1889 // std::cout<<"type: "<<cont->getModel()->getGObjectType()<<std::endl;//CFT
1890 cont->getModel()->save(content);
1894 std::vector<int> connections = getConnections();
1895 int csize = connections.size();
1896 content += "CONNECTIONS:";
1897 sprintf(buffer, "%d", csize);
1901 for (int i = 0; i < csize; i++) {
1902 int id = connections[i];
1903 GObjectController *cont = _controllers[id];
1904 cont->getModel()->save(content);
1909 //=========================================================================
1910 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1912 getline(inputStream, line,'\n');
1913 int size = line.length();
1916 if ( line[ size-1 ]==13 )
1918 line.erase(size-1,1);
1923 //=========================================================================
1924 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1927 std::string version = "<void>";
1928 std::string line = "";
1929 char delims[] = ":";
1930 char *result = NULL;
1931 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1933 getCleanLine(inputStream, line);
1936 while (!inputStream.eof()) {
1937 if (line == "" || line[0] == '#') {
1939 getCleanLine(inputStream, line);
1941 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1942 version = line.substr(18, 3);
1944 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1945 version = line.substr(18, 3);
1947 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1948 version = line.substr(18, 3);
1950 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1951 version = line.substr(18, 3);
1953 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1954 version = line.substr(18, 3);
1956 } else if (line == "APP_START") {
1965 if ((version != "1.0") && (version != "1.1")) {
1966 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1967 char categoryTmp[30];
1968 strcpy(categoryTmp, line.c_str());
1969 result = strtok(categoryTmp, delims);
1970 result = strtok(NULL, delims);
1971 SetCategory(result);
1973 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1974 char descriptionTmp[1024];
1975 strcpy(descriptionTmp, line.c_str());
1976 result = strtok(descriptionTmp, delims);
1977 result = strtok(NULL, delims);
1978 SetDescription(result);
1980 getCleanLine(inputStream, line);//AUTHOR:<author>
1981 char authorTmp[255];
1982 strcpy(authorTmp, line.c_str());
1983 result = strtok(authorTmp, delims);
1984 result = strtok(NULL, delims);
1989 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1990 char complexTmp[30];
1991 strcpy(complexTmp, line.c_str());
1992 result = strtok(complexTmp, delims);
1993 result = strtok(NULL, delims);
1994 std::string isComplexBox(result);
1996 if (isComplexBox == "TRUE") {
1997 _isComplexBox = true;
1999 if ((version != "1.0") && (version != "1.1")) {
2000 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
2001 char complexboxnameTmp[255];
2002 strcpy(complexboxnameTmp, line.c_str());
2003 result = strtok(complexboxnameTmp, delims);
2004 result = strtok(NULL, delims);
2007 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
2008 char packagenameTmp[255];
2009 strcpy(packagenameTmp, line.c_str());
2010 result = strtok(packagenameTmp, delims);
2011 result = strtok(NULL, delims);
2012 SetCbPackageName(result);
2017 //-----------------------
2018 //- COMPLEX INPUT PORTS
2019 //-----------------------
2020 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2022 strcpy(inputs, line.c_str());
2023 result = strtok(inputs, delims);
2024 result = strtok(NULL, delims);
2027 std::istringstream inps(result);
2030 for (int i = 0; i < numInputs; i++) {
2032 getCleanLine(inputStream, line);//COMPLEX_PORT
2033 getCleanLine(inputStream, line);//name
2034 std::string inputPortName(line);
2037 getCleanLine(inputStream, line);//xInic:yInic:zInic
2039 strcpy(coord, line.c_str());
2040 result = strtok(coord, delims);//xInic
2041 std::string xInic(result);
2042 result = strtok(NULL, delims);//yInic
2043 std::string yInic(result);
2044 result = strtok(NULL, delims);//zInic
2045 std::string zInic(result);
2047 double xIn, yIn, zIn;
2048 std::istringstream xSt(xInic);
2050 std::istringstream ySt(yInic);
2052 std::istringstream zSt(zInic);
2057 if (zIn==900) zIn=GPOSITION_Z;
2060 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2062 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2064 } // for input complex box
2069 //-----------------------
2070 //- COMPLEX OUTPUT PORTS
2071 //-----------------------
2073 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2075 strcpy(outputs, line.c_str());
2076 result = strtok(outputs, delims);
2077 result = strtok(NULL, delims);
2080 std::istringstream outps(result);
2081 outps >> numOutputs;
2083 for (int i = 0; i < numOutputs; i++) {
2085 getCleanLine(inputStream, line);//COMPLEX_PORT
2086 getCleanLine(inputStream, line);//name
2087 std::string outputPortName(line);
2090 getCleanLine(inputStream, line);//xInic:yInic:zInic
2092 strcpy(coord, line.c_str());
2093 result = strtok(coord, delims);//xInic
2094 std::string xInic(result);
2095 result = strtok(NULL, delims);//yInic
2096 std::string yInic(result);
2097 result = strtok(NULL, delims);//zInic
2098 std::string zInic(result);
2100 double xIn, yIn, zIn;
2101 std::istringstream xSt(xInic);
2103 std::istringstream ySt(yInic);
2105 std::istringstream zSt(zInic);
2110 if (zIn==900) zIn=GPOSITION_Z;
2113 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2115 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2117 } // for output complex box
2121 // RaC2012 2nd Hackfest
2122 if(version >= "1.4")
2124 //-----------------------
2125 //- EXTERNAL INPUT PORTS
2126 //-----------------------
2127 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2129 strcpy(inputs, line.c_str());
2130 result = strtok(inputs, delims);
2131 result = strtok(NULL, delims);
2134 std::istringstream inps(result);
2137 for (int i = 0; i < numInputs; i++) {
2139 getCleanLine(inputStream, line);//COMPLEX_PORT
2140 getCleanLine(inputStream, line);//name
2141 std::string inputPortName(line);
2144 getCleanLine(inputStream, line);//xInic:yInic:zInic
2146 strcpy(coord, line.c_str());
2147 result = strtok(coord, delims);//xInic
2148 std::string xInic(result);
2149 result = strtok(NULL, delims);//yInic
2150 std::string yInic(result);
2151 result = strtok(NULL, delims);//zInic
2152 std::string zInic(result);
2154 double xIn, yIn, zIn;
2155 std::istringstream xSt(xInic);
2157 std::istringstream ySt(yInic);
2159 std::istringstream zSt(zInic);
2164 if (zIn==900) zIn=GPOSITION_Z;
2167 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2168 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2170 } // for external input
2175 getCleanLine(inputStream, line);//BOXES:num
2177 strcpy(boxes, line.c_str());
2178 result = strtok(boxes, delims);
2179 result = strtok(NULL, delims);
2182 std::istringstream is(result);
2185 for (int i = 0; i < numBoxes; i++)
2188 getCleanLine(inputStream, line);//BOX
2189 getCleanLine(inputStream, line);//package:type:name
2191 strcpy(box, line.c_str());
2192 result = strtok(box, delims);//package
2193 std::string package(result);
2194 result = strtok(NULL, delims);//type
2195 std::string type(result);
2196 result = strtok(NULL, delims);//name
2197 std::string name(result);
2200 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2202 strcpy(exec, line.c_str());
2203 result = strtok(exec, delims);//ISEXEC
2204 result = strtok(NULL, delims);//TRUE|FALSE
2205 std::string isExec(result);
2208 getCleanLine(inputStream, line);//xInic:yInic:zInic
2210 strcpy(coord, line.c_str());
2211 result = strtok(coord, delims);//xInic
2212 std::string xInic(result);
2213 result = strtok(NULL, delims);//yInic
2214 std::string yInic(result);
2215 result = strtok(NULL, delims);//zInic
2216 std::string zInic(result);
2218 double xIn, yIn, zIn;
2219 std::istringstream xSt(xInic);
2221 std::istringstream ySt(yInic);
2223 std::istringstream zSt(zInic);
2229 if (zIn==900) zIn=GPOSITION_Z;
2234 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2235 strcpy(coord, line.c_str());
2236 result = strtok(coord, delims);//xEnd
2237 std::string xEnd(result);
2238 result = strtok(NULL, delims);//yEnd
2239 std::string yEnd(result);
2240 result = strtok(NULL, delims);//zEnd
2241 std::string zEnd(result);
2243 double xEn, yEn, zEn;
2244 std::istringstream xEt(xEnd);
2246 std::istringstream yEt(yEnd);
2248 std::istringstream zEt(zEnd);
2253 if (zEn==900) zEn=GPOSITION_Z;
2257 bool boxExecutable = false;
2258 if (isExec == "TRUE")
2260 boxExecutable = true;
2263 int idBox = createGBlackBox(xIn, yIn, package, type);
2264 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2266 GObjectController *cont = _controllers[idBox];
2267 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2270 getCleanLine(inputStream, line);//PORT o FIN_BOX
2271 std::string port = line.substr(0, 4);
2272 while (port == "PORT")
2274 getCleanLine(inputStream, line);//name:value
2275 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2277 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2280 strcpy(poort, line.c_str());
2281 result = strtok(poort, delims);//name
2282 std::string name(result);
2284 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2285 result = strtok(NULL, delims);//value
2286 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2288 std::string tmpString=" ";
2289 tmpString[0]=34; // character "
2290 strcat(result,tmpString.c_str());
2292 std::string value(result);
2294 bbmod->setValueToInput(name, value);
2296 getCleanLine(inputStream, line);//PORT o FIN_BOX
2297 port = line.substr(0, 4);
2300 //EED bbmod->notifyObservers(_idManager);
2305 getCleanLine(inputStream, line);//CONNECTIONS:num
2307 strcpy(conns, line.c_str());
2308 result = strtok(conns, delims);
2309 result = strtok(NULL, delims);
2312 std::istringstream isCons(result);
2316 for (int i = 0; i < numConns; i++)
2319 getCleanLine(inputStream, line);//CONNECTION
2320 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2323 strcpy(connec, line.c_str());
2324 result = strtok(connec, delims);
2325 std::string nameStartBox(result);
2326 result = strtok(NULL, delims);
2327 std::string nameStartPort(result);
2328 result = strtok(NULL, delims);
2329 std::string nameEndBox(result);
2330 result = strtok(NULL, delims);
2331 std::string nameEndPort(result);
2333 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2335 if (version != "1.0") {
2336 //Readding control points of the manualContour
2337 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2338 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2339 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2340 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2341 strcpy(conns, line.c_str());
2342 result = strtok(conns, delims);
2343 result = strtok(NULL, delims);
2345 int numberOfControlPoints;
2346 std::istringstream isCons(result);
2347 isCons >> numberOfControlPoints;
2349 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2350 getCleanLine(inputStream, line); //XX:YY:ZZ
2352 strcpy(connec, line.c_str());
2355 result = strtok(connec, delims);
2356 std::istringstream isPointX(result);
2358 result = strtok(NULL, delims);
2359 std::istringstream isPointY(result);
2361 result = strtok(NULL, delims);
2362 std::istringstream isPointZ(result);
2367 if (pz==900) pz=GPOSITION_Z;
2370 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2371 conView->getManualContourView()->AddPoint();
2377 //=========================================================================
2380 //=========================================================================
2381 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2382 std::string portName, double xIn, double yIn, double zIn)
2385 if (inputoutput == true) {
2386 idPort = createGComplexBoxInputPort(portName);
2388 idPort = createGComplexBoxOutputPort(portName);
2390 GObjectController *cont = _controllers[idPort];
2391 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2392 cbmod->setInicPoint(xIn, yIn, zIn);
2393 cbmod->notifyObservers(_idManager);
2395 //=========================================================================
2398 //=========================================================================
2399 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2404 GBoxModel *boxModel = NULL;
2405 std::vector<int> lstB = getBlackBoxes();
2406 for (j = 0; j < (int) lstB.size(); j++) {
2408 bMod = (GBoxModel*) _controllers[idB]->getModel();
2409 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2417 if (boxModel == NULL) {
2418 std::vector<int> lstInputs = getComplexInputPorts();
2419 for (j = 0; j < (int) lstInputs.size(); j++) {
2421 bMod = (GBoxModel*) _controllers[idB]->getModel();
2422 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2430 std::vector<int> lstOutputs = getComplexOutputPorts();
2431 for (j = 0; j < (int) lstOutputs.size(); j++) {
2432 int idB = lstOutputs[j];
2433 bMod = (GBoxModel*) _controllers[idB]->getModel();
2434 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2446 //=========================================================================
2449 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2450 std::string nameStartPort, std::string nameEndBox,
2451 std::string nameEndPort) {
2453 GBoxModel *boxModel;
2454 GPortModel *startP = NULL;
2455 GPortModel *endP = NULL;
2457 boxModel = findGBox(nameStartBox);
2458 if(boxModel == NULL)
2460 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2462 if (boxModel != NULL) {
2463 startP = boxModel->getOutputPort(nameStartPort);
2465 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() );
2469 boxModel = findGBox(nameEndBox);
2470 if(boxModel == NULL)
2472 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2474 if (boxModel != NULL) {
2475 endP = boxModel->getInputPort(nameEndPort);
2477 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());
2482 int idCon = createGConnector(startP);
2484 _worldState = NOTHING_HAPPENS;
2485 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2487 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2488 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2489 tempp->endContourCreation();
2490 conMod->setEndPort(endP);
2491 conView->updateStartEndPoints();
2495 //=========================================================================
2497 bool wxVtkSceneManager::boxExist(std::string boxname) {
2499 std::map<int, GObjectController*>::iterator it;
2500 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2501 GObjectController *cont = it->second;
2502 if (cont->getModel()->getBBTKName() == boxname) {
2509 //=========================================================================
2511 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2512 std::vector<int> vect;
2513 std::map<int, GObjectController*>::iterator it;
2514 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2515 GObjectController *cont = it->second;
2516 if (cont->getGObjectType() == GBLACKBOX) {
2517 vect.push_back(cont->getId());
2523 //=========================================================================
2525 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2526 std::vector<int> vect;
2527 std::map<int, GObjectController*>::iterator it;
2528 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2529 GObjectController *cont = it->second;
2530 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2531 vect.push_back(cont->getId());
2537 //=========================================================================
2539 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2540 std::vector<int> vect;
2541 std::map<int, GObjectController*>::iterator it;
2542 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2543 GObjectController *cont = it->second;
2544 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2545 vect.push_back(cont->getId());
2551 //=========================================================================
2553 std::vector<int> wxVtkSceneManager::getConnections() {
2554 std::vector<int> vect;
2555 std::map<int, GObjectController*>::iterator it;
2556 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2557 GObjectController *cont = it->second;
2558 if (cont->getGObjectType() == GCONNECTOR) {
2559 vect.push_back(cont->getId());
2565 //=========================================================================
2567 bool wxVtkSceneManager::isComplexBox() {
2568 return _isComplexBox;
2571 //=========================================================================
2573 void wxVtkSceneManager::setComplexBox(bool val) {
2574 _isComplexBox = val;
2577 //=========================================================================
2579 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2580 //Register the controller of the new object
2581 registerController((InteractorStyleMaracas*) objController);
2582 //Add the object to the objects list
2583 int newId = _contLastId;//_controllers.size();
2584 objController->setId(newId);
2585 _controllers[newId] = objController;
2586 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2591 //=========================================================================
2593 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2595 std::map<int, int> oldIdNewIdBoxes;
2596 std::vector<int> connections;
2598 std::vector<int> newBoxesID;
2600 std::map<int, GObjectController*>::iterator it;
2601 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2602 GObjectController *cont = it->second;
2603 int type = cont->getGObjectType();
2605 if (type == GBLACKBOX) {
2607 double xInic, yInic, zInic;
2608 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2609 copyBox->getInicPoint(xInic, yInic, zInic);
2610 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2611 copyBox->getBBTKType());
2613 int idcB = copyBox->getObjectId();
2614 oldIdNewIdBoxes[idcB] = idBox;
2615 cont = _controllers[idBox];
2616 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2617 newbox->setInicPoint(xInic, yInic, zInic);
2618 int num = newbox->getNumInputPorts();
2619 for (int j = 0; j < num; j++) {
2620 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2622 newbox->move(xInic + 20, yInic + 20, zInic);
2623 newbox->notifyObservers(_idManager);
2624 newBoxesID.push_back(newbox->getObjectId());
2626 } else if (type == GCONNECTOR) {
2627 int idCon = cont->getId();
2628 connections.push_back(idCon);
2633 for (int i = 0; i < (int) connections.size(); i++) {
2634 int objId = connections[i];
2635 GObjectController *cont = objectsMap[objId];
2636 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2638 GPortModel* startPort = connectModel->getStartPort();
2639 int startPortIndex = startPort->getPosInBox();
2640 GPortModel* endPort = connectModel->getEndPort();
2641 int endPortIndex = endPort->getPosInBox();
2643 GBlackBoxModel* startPortParentBox =
2644 (GBlackBoxModel*) startPort->getParentBox();
2645 GBlackBoxModel* endPortParentBox =
2646 (GBlackBoxModel*) endPort->getParentBox();
2648 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2649 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2651 GBlackBoxModel* newStartBox =
2652 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2653 GBlackBoxModel* newEndBox =
2654 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2656 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2657 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2659 // Creates connection
2660 int idCon = createGConnector(newStartPort);
2661 GConnectorController *tempp =
2662 (GConnectorController*) _controllers[idCon];
2663 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2664 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2665 tempp->endContourCreation();
2666 conMod->setEndPort(newEndPort);
2667 conView->updateStartEndPoints();
2670 /// the new selected boxes are the duplicate ones
2672 UnSelectBlackBoxes();
2673 for (int i = 0; i < newBoxesID.size(); i++) {
2674 _selectedObjects.push_back(newBoxesID.at(i));
2677 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2678 int id = _selectedObjects[i];
2679 GObjectController* cont = _controllers[id];
2681 cont->getView()->setState(SELECTED);
2682 cont->getModel()->notifyObservers(_idManager);
2688 //=========================================================================
2690 int wxVtkSceneManager::getNumSelectedObjects() {
2691 return _selectedObjects.size();
2694 //=========================================================================
2696 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2697 std::map<int, GObjectController*> mapSelected;
2699 std::map<int, GObjectController*>::iterator it;
2700 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2701 GObjectController *cont = it->second;
2702 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2704 mapSelected[cont->getId()] = cont;
2708 std::map<int, GObjectController*>::iterator it2;
2709 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2710 GObjectController *cont = it2->second;
2711 if (cont->getGObjectType() == GCONNECTOR) {
2712 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2713 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2714 GBoxModel* startPortParentBox =
2715 cmod->getStartPort()->getParentBox();
2717 std::map<int, GObjectController*>::iterator iterOBJ1 =
2718 mapSelected.find(startPortParentBox->getObjectId());
2719 std::map<int, GObjectController*>::iterator iterOBJ2 =
2720 mapSelected.find(endPortParentBox->getObjectId());
2722 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2723 int ID = cont->getId();
2724 mapSelected[ID] = cont;
2731 //=========================================================================
2733 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2735 std::map<int, int> oldIdNewIdBoxes;
2736 std::vector<int> connections;
2738 std::map<int, GObjectController*>::iterator it;
2739 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2740 GObjectController *cont = it->second;
2741 int type = cont->getGObjectType();
2743 if (type == GBLACKBOX) {
2745 double xInic, yInic, zInic;
2746 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2747 copyBox->getInicPoint(xInic, yInic, zInic);
2748 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2750 int idcB = copyBox->getObjectId();
2751 oldIdNewIdBoxes[idcB] = idBox;
2752 cont = _controllers[idBox];
2753 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2754 newbox->setInicPoint(xInic, yInic, zInic);
2755 int num = newbox->getNumInputPorts();
2756 for (int j = 0; j < num; j++)
2758 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2760 newbox->notifyObservers(_idManager);
2761 } else if (type == GCONNECTOR) {
2762 int idCon = cont->getId();
2763 connections.push_back(idCon);
2768 for (int i = 0; i < (int) connections.size(); i++) {
2769 int objId = connections[i];
2770 GObjectController *cont = objectsMap[objId];
2771 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2773 GPortModel* startPort = connectModel->getStartPort();
2774 int startPortIndex = startPort->getPosInBox();
2775 GPortModel* endPort = connectModel->getEndPort();
2776 int endPortIndex = endPort->getPosInBox();
2778 GBlackBoxModel* startPortParentBox =
2779 (GBlackBoxModel*) startPort->getParentBox();
2780 GBlackBoxModel* endPortParentBox =
2781 (GBlackBoxModel*) endPort->getParentBox();
2783 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2784 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2786 GBlackBoxModel* newStartBox =
2787 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2788 GBlackBoxModel* newEndBox =
2789 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2791 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2792 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2794 // Creates connection
2795 int idCon = createGConnector(newStartPort);
2796 GConnectorController *tempp =
2797 (GConnectorController*) _controllers[idCon];
2798 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2799 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2800 tempp->endContourCreation();
2801 conMod->setEndPort(newEndPort);
2802 conView->updateStartEndPoints();
2805 std::map<int, int>::iterator itIds;
2806 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2807 int idOld = itIds->first;
2808 int idNew = itIds->second;
2810 GBlackBoxModel* oldBox =
2811 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2812 GBlackBoxModel* newBox =
2813 (GBlackBoxModel*) _controllers[idNew]->getModel();
2815 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2816 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2817 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2818 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2820 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2822 //EED int toCreate=-1;
2823 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2824 if (oldInputConnections[k] == newInputConnections[l]) {
2829 if (exist == false) {
2830 //Create complex input
2831 int posInBox = oldInputConnections[k];
2832 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2833 std::string inputPortName = inputPort->getBBTKName();
2834 int idInputPort = createGComplexBoxInputPort(inputPortName);
2835 GObjectController *cont = _controllers[idInputPort];
2836 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2837 double xIn, yIn, zIn;
2838 inputPort->getInicPoint(xIn, yIn, zIn);
2840 cbmod->setInicPoint(xIn, yIn, zIn);
2841 cbmod->notifyObservers(_idManager);
2843 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2845 // Creates connection
2846 int idCon = createGConnector(cbmod->getOutputPort(0));
2847 GConnectorController *tempp =
2848 (GConnectorController*) _controllers[idCon];
2849 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2850 vtkGConnectorView *conView =
2851 (vtkGConnectorView*) tempp->getView();
2852 tempp->endContourCreation();
2853 conMod->setEndPort(inputPortEnd);
2854 conView->updateStartEndPoints();
2860 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2862 //EED int toCreate=-1;
2863 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2864 if (oldOutputConnections[k] == newOutputConnections[l]) {
2869 if (exist == false) {
2870 //Create complex output
2871 int posInBox = oldOutputConnections[k];
2872 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2873 std::string outputPortName = outputPort->getBBTKName();
2874 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2875 GObjectController *cont = _controllers[idOutputPort];
2876 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2877 double xIn, yIn, zIn;
2878 outputPort->getInicPoint(xIn, yIn, zIn);
2880 cbmod->setInicPoint(xIn, yIn, zIn);
2881 cbmod->notifyObservers(_idManager);
2883 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2885 // Creates connection
2886 int idCon = createGConnector(outputPortEnd);
2887 GConnectorController *tempp =
2888 (GConnectorController*) _controllers[idCon];
2889 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2890 vtkGConnectorView *conView =
2891 (vtkGConnectorView*) tempp->getView();
2892 tempp->endContourCreation();
2893 conMod->setEndPort(cbmod->getInputPort(0));
2894 conView->updateStartEndPoints();
2904 //=========================================================================
2905 void wxVtkSceneManager::SetCbName(std::string cbName) {
2907 if (_cbName == "") {
2908 _cbName = "<complex box name>";
2912 //=========================================================================
2913 std::string wxVtkSceneManager::GetCbName() {
2917 //=========================================================================
2918 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2919 _cbPackageName = packagename;
2920 if (_cbPackageName == "") {
2921 _cbPackageName = "<package name of the complex box>";
2925 //=========================================================================
2926 std::string wxVtkSceneManager::GetCbPackageName() {
2927 return _cbPackageName;
2930 //=========================================================================
2931 void wxVtkSceneManager::SetAuthor(std::string author) {
2933 if (_Author == "") {
2934 _Author = "<author of the box>";
2938 //=========================================================================
2939 std::string wxVtkSceneManager::GetAuthor() {
2943 //=========================================================================
2944 void wxVtkSceneManager::SetCategory(std::string category) {
2945 _Category = category;
2946 if (_Category == "") {
2947 _Category = "<category of the box>";
2951 //=========================================================================
2952 std::string wxVtkSceneManager::GetCategory() {
2956 //=========================================================================
2957 void wxVtkSceneManager::SetDescription(std::string description) {
2958 _Description = description;
2959 if (_Description == "") {
2960 _Description = "<description of the box>";
2964 //=========================================================================
2965 std::string wxVtkSceneManager::GetDescription() {
2966 return _Description;
2969 //=========================================================================
2971 void wxVtkSceneManager::SetMessageKind(std::string kind) {
2972 _MessageKind = kind;
2976 //=========================================================================
2978 std::string wxVtkSceneManager::GetMessageKind(){
2979 return _MessageKind;
2982 //=========================================================================
2984 void wxVtkSceneManager::SetMessageLevel(std::string Level){
2985 _MessageLevel = Level;
2988 //=========================================================================
2990 std::string wxVtkSceneManager::GetMessageLevel(){
2991 return _MessageLevel;
2994 //=========================================================================
2996 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
2999 std::vector< std::string> extInputs;
3000 std::map<int, GObjectController*>::iterator it;
3001 for (it = _controllers.begin(); it != _controllers.end(); ++it)
3003 GObjectController *cont = it->second;
3004 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
3006 extInputs.push_back(cont->getModel()->getBBTKName());
3012 //=========================================================================
3016 void wxVtkSceneManager::printAll(int com , int sta ){
3018 int tmpState = sta ;
3019 if ( tmpState == NOTHING_HAPPENS ) {
3020 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
3022 if ( tmpState == HIGHLIGHTED ) {
3023 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
3025 if ( tmpState == POSSIBLE_CONNECTION ) {
3026 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
3028 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
3029 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
3031 if ( tmpState == CLICKED ) {
3032 std::cout << "CONTROLER STATE---->CLICKED\n" ;
3034 if ( tmpState == DRAG ) {
3035 std::cout << "CONTROLER STATE---->DRAG\n" ;
3037 if ( tmpState == SELECTED ) {
3038 std::cout << "CONTROLER STATE---->SELECTED\n" ;
3040 if ( tmpState == CREATING_CONTOUR ) {
3041 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
3047 if ( command == INIT_CREATION_CONTOUR ) {
3048 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
3050 if ( command == FIN_CREATION_CONTOUR ) {
3051 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
3053 if ( command == ADD_TO_SELECTED ) {
3054 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
3056 if ( command == DRAG_OBJECTS ) {
3057 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
3059 if ( command == EDIT_BLACKBOX ) {
3060 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
3062 if ( command == REMOVE_FROM_SELECTED ) {
3063 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
3069 } // EO namespace bbtk