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");
1153 if((keyCode==0) && (ctrlkey==1)) {
1158 if(_selectedObjects.size()){
1159 std::cout<<"objects to copy :";
1160 for(int i=0;i<_selectedObjects.size();i++)
1162 std::cout<<_selectedObjects.at(i)<<" ";
1164 DuplicateObjects(getSelectedObjects());
1166 std::cout<<"No objects to copy\n";
1167 } // _selectedObjects.size
1173 //=========================================================================
1175 void wxVtkSceneManager::AddControlerToBeRemove(
1176 std::vector<int> *controllersToRemove, int id) {
1180 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1181 if (id == (*controllersToRemove)[i]) {
1187 controllersToRemove->push_back(id);
1192 //=========================================================================
1194 bool wxVtkSceneManager::deleteObject(int id)
1197 GObjectController *control = _controllers[id];
1198 std::vector<int> controllersToRemove;
1199 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1200 == GCOMPLEXINPUTPORT || control->getGObjectType()
1201 == GCOMPLEXOUTPUTPORT) {
1202 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1203 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1205 bool boxConnected = false;
1207 // Add box input controllers to be removed
1208 for (int i = 0; i < (int) inputs.size(); i++) {
1209 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1210 if (inputs[i]->isConnected()) {
1211 boxConnected = true;
1215 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1217 // Add box output controllers to be removed
1218 for (int i = 0; i < (int) outputs.size(); i++) {
1219 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1220 if (outputs[i]->isConnected()) {
1221 boxConnected = true;
1225 // Add connection controllers to be removed
1226 std::map<int, GObjectController*>::iterator it;
1227 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1228 GObjectController *cont = it->second;
1229 int type = cont->getGObjectType();
1230 if (type == GCONNECTOR) {
1231 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1232 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1234 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1236 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1238 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1243 // Add box controller to be removed
1244 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1245 } else if (control->getGObjectType() == GCONNECTOR) {
1246 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1247 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1249 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1250 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1252 gconnectorcontroler->getManualContourController()->OnChar();
1257 std::map<int, GObjectController*>::iterator it;
1259 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1260 int key = controllersToRemove[i];
1261 it = _controllers.find(key);
1262 GObjectController *cont = _controllers[key];
1264 cont->removeFromScene();
1265 unregisterController((InteractorStyleMaracas*) cont);
1266 _controllers.erase(it);
1274 //=========================================================================
1276 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1277 std::string boxName) {
1278 _parent->displayBlackBoxInfo(packageName, boxName);
1281 //=========================================================================
1283 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1284 _parent->updateStatusBar(textStatus);
1287 //=========================================================================
1288 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1289 std::string result = "";
1290 if (withLineNumber == true) {
1292 stringstream StrStream;
1294 std::string strValue = StrStream.str();
1297 } else if (value < 100) {
1301 result += strValue + ": ";
1305 //=========================================================================
1307 bool wxVtkSceneManager::MakeBoxExecutable() {
1308 std::map<int, GObjectController*> selected = getSelectedObjects();
1309 if( selected.empty() )
1312 std::map<int, GObjectController*>::iterator it;
1313 for (it = selected.begin(); it != selected.end(); ++it) {
1314 GObjectController* lastSelected = it->second;
1316 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1317 GBlackBoxModel *bbmodel =
1318 (GBlackBoxModel*) lastSelected->getModel();
1319 view->setState(HIGHLIGHTED);
1320 if (bbmodel->isExecutable()) {
1321 bbmodel->setExecutable(false);
1323 bbmodel->setExecutable(true);
1325 bbmodel->notifyObservers(lastSelected->getId());
1333 //=========================================================================
1335 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1336 std::cout << "wxVtkSceneManager::getDiagramBBS" << std::endl;
1337 bool existsExec = false;
1339 std::vector<std::string> packages;
1340 std::vector<int> boxes;
1341 std::vector<int> connections;
1342 std::vector<int> execBoxes;
1344 std::map<int, GObjectController*>::iterator it;
1346 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1347 GObjectController *desc = it->second;
1348 int type = desc->getGObjectType();
1350 if (type == GBLACKBOX) {
1351 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1353 std::string pkg = mod->getBBTKPackage();
1354 bool existsPkg = false;
1355 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1356 if (packages[t] == pkg) {
1361 packages.push_back(pkg);
1364 boxes.push_back(it->first);
1365 if (mod->isExecutable()) {
1366 execBoxes.push_back(it->first);
1369 } else if (type == GCONNECTOR) {
1370 connections.push_back(it->first);
1375 std::string script = "";
1376 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1377 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1378 script += LineNumber(wln, lnNmbr) + "\n";
1380 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1381 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1383 for (i = 0; i < (int) packages.size(); i++) {
1384 script += LineNumber(wln, lnNmbr);
1385 script += "include ";
1386 script += packages[i];
1390 script += LineNumber(wln, lnNmbr);
1395 script += LineNumber(wln, lnNmbr);
1396 script += "author \"";
1400 script += LineNumber(wln, lnNmbr);
1401 script += "description \"";
1402 script += _Description;
1405 script += LineNumber(wln, lnNmbr);
1406 script += "category \"";
1407 script += _Category;
1410 script += LineNumber(wln, lnNmbr);
1413 // script+="include std\n"; // JPR
1415 for (i = 0; i < (int) boxes.size(); i++) {
1416 script += LineNumber(wln, lnNmbr);
1419 GObjectController *control = _controllers[id];
1420 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1422 script += model->getBBTKPackage()+":";
1423 script += model->getBBTKType();
1425 script += model->getBBTKName();
1428 std::vector<GPortModel*> inputs = model->getInputPorts();
1429 for (int j = 0; j < (int) inputs.size(); j++) {
1430 GPortModel* inputPort = inputs[j];
1431 if (inputPort->isValueSet()) {
1432 script += LineNumber(wln, lnNmbr);
1434 script += model->getBBTKName();
1436 script += inputPort->getBBTKName();
1438 script += inputPort->getValue();
1443 script += LineNumber(wln, lnNmbr);
1448 script += LineNumber(wln, lnNmbr);
1452 std::string complexInputs="";
1454 for (i = 0; i < (int) connections.size(); i++) {
1455 //script += LineNumber(wln, lnNmbr);
1456 //script += "connect ";
1457 int id = connections[i];
1458 GObjectController *control = _controllers[id];
1459 GConnectorModel *model = (GConnectorModel*) control->getModel();
1463 GPortModel *start = model->getStartPort();
1464 GBoxModel *startBox = start->getParentBox();
1466 GPortModel *end = model->getEndPort();
1467 GBoxModel *endBox = end->getParentBox();
1469 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1471 complexInputs += "input ";
1472 complexInputs += startBox->getBBTKName();
1474 complexInputs += " ";
1475 complexInputs += endBox->getBBTKName();
1476 complexInputs += ".";
1477 complexInputs += end->getBBTKName();
1479 complexInputs += " ";
1480 complexInputs += "\" \"";
1482 complexInputs += "\n";
1486 script += LineNumber(wln, lnNmbr);
1487 script += "connect ";
1488 script += startBox->getBBTKName();
1490 script += start->getBBTKName();
1494 //End Connection info
1495 script += endBox->getBBTKName();
1497 script += end->getBBTKName();
1502 script += LineNumber(wln, lnNmbr);
1506 script += LineNumber(wln, lnNmbr);
1509 script += LineNumber(wln, lnNmbr);
1512 script += LineNumber(wln, lnNmbr);
1513 script += "# Complex input ports\n";
1514 script += complexInputs;
1516 if((_MessageKind!="-")&&(_MessageLevel!="-")){
1517 script += LineNumber(wln, lnNmbr);
1518 script += "message ";
1519 script += _MessageKind;
1521 script += _MessageLevel;
1525 for (i = 0; i < (int) execBoxes.size(); i++) {
1526 script += LineNumber(wln, lnNmbr);
1528 int id = execBoxes[i];
1529 GObjectController *control = _controllers[id];
1530 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1532 script += model->getBBTKName();
1541 //=========================================================================
1543 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1544 std::cout<<"wxVtkSceneManager::saveComplexBoxBBS"<<std::endl;
1545 std::vector<std::string> packages;
1546 std::vector<int> boxes;
1547 std::vector<int> connections;
1548 std::vector<int> execBoxes;
1550 std::map<int, GObjectController*>::iterator it;
1552 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1553 GObjectController *desc = it->second;
1554 int type = desc->getGObjectType();
1556 if (type == GBLACKBOX) {
1557 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1559 std::string pkg = mod->getBBTKPackage();
1560 bool existsPkg = false;
1561 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1562 if (packages[t] == pkg) {
1567 packages.push_back(pkg);
1570 boxes.push_back(it->first);
1571 if (mod->isExecutable()) {
1572 execBoxes.push_back(it->first);
1574 } else if (type == GCONNECTOR) {
1575 connections.push_back(it->first);
1579 std::string script = "";
1581 script += "include std\n"; // EED
1582 script += "include itkvtk\n"; // EED
1584 for (i = 0; i < (int) packages.size(); i++) {
1585 script += "include ";
1586 script += packages[i];
1591 // Definition of a complex box
1592 script += "define ";
1593 script += _cbName + " " + _cbPackageName;
1597 script += "author \"";
1601 script += "description \"";
1602 script += _Description;
1606 script += "category \"";
1607 script += _Category;
1612 for (i = 0; i < (int) boxes.size(); i++) {
1615 GObjectController *control = _controllers[id];
1616 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1618 script += model->getBBTKPackage()+":";
1619 script += model->getBBTKType();
1621 script += model->getBBTKName();
1624 std::vector<GPortModel*> inputs = model->getInputPorts();
1625 for (int j = 0; j < (int) inputs.size(); j++) {
1626 GPortModel* inputPort = inputs[j];
1627 if (inputPort->isValueSet()) {
1629 script += model->getBBTKName();
1631 script += inputPort->getBBTKName();
1633 script += inputPort->getValue();
1641 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1643 std::string complexInputs = "";
1644 std::string complexOutputs = "";
1647 for (i = 0; i < (int) connections.size(); i++) {
1648 int id = connections[i];
1649 GObjectController *control = _controllers[id];
1650 GConnectorModel *model = (GConnectorModel*) control->getModel();
1653 GPortModel *start = model->getStartPort();
1654 GBoxModel *startBox = start->getParentBox();
1656 GPortModel *end = model->getEndPort();
1657 GBoxModel *endBox = end->getParentBox();
1659 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1660 complexInputs += "input ";
1661 complexInputs += startBox->getBBTKName();
1663 complexInputs += " ";
1664 complexInputs += endBox->getBBTKName();
1665 complexInputs += ".";
1666 complexInputs += end->getBBTKName();
1668 complexInputs += " ";
1669 complexInputs += "\" \"";
1671 complexInputs += "\n";
1672 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1673 complexOutputs += "output ";
1674 complexOutputs += endBox->getBBTKName();
1676 complexOutputs += " ";
1677 complexOutputs += startBox->getBBTKName();
1678 complexOutputs += ".";
1679 complexOutputs += start->getBBTKName();
1681 complexOutputs += " ";
1682 complexOutputs += "\" \"";
1684 complexOutputs += "\n";
1686 script += "connect ";
1687 script += startBox->getBBTKName();
1689 script += start->getBBTKName();
1693 //End Connection info
1694 script += endBox->getBBTKName();
1696 script += end->getBBTKName();
1703 script += "# Complex input ports\n";
1704 script += complexInputs;
1707 script += "# Complex output ports\n";
1708 script += complexOutputs;
1712 if((_MessageKind!="-")&&(_MessageLevel!="-"))
1714 script += "message ";
1715 script += _MessageKind;
1717 script += _MessageLevel;
1721 for (i = 0; i < (int) execBoxes.size(); i++)
1724 int id = execBoxes[i];
1725 GObjectController *control = _controllers[id];
1726 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1728 script += model->getBBTKName();
1733 script += "endefine";
1739 //=========================================================================
1741 void wxVtkSceneManager::deleteAllBoxes() {
1742 std::map<int, GObjectController*>::iterator it;
1743 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1744 GObjectController *cont = it->second;
1745 cont->removeFromScene();
1746 unregisterController((InteractorStyleMaracas*) cont);
1748 _selectedObjects.clear();
1749 _controllers.clear();
1752 //=========================================================================
1755 void wxVtkSceneManager::refresh() {
1756 _baseView->Refresh();
1758 //=========================================================================
1760 void wxVtkSceneManager::refreshScene()
1762 _baseView->RefreshView();
1765 //=========================================================================
1767 void wxVtkSceneManager::centerView()
1770 _baseView->GetRenderer()->ComputeVisiblePropBounds(bb);
1773 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1774 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1775 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1776 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1778 _baseView->GetRenderer()->ResetCamera();
1779 _baseView->GetRenderer()->ResetCameraClippingRange();
1782 double tt=_baseView->GetRenderer()->GetNearClippingPlaneTolerance();
1783 printf("EED wxVtkSceneManager::centerView() tolerance=%f\n",tt);
1785 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1786 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1787 _baseView->GetRenderer()->GetActiveCamera()->SetClippingRange(0.01,100000);
1788 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1789 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1792 _baseView->GetRenderer()->Render();
1795 //=========================================================================
1797 void wxVtkSceneManager::saveDiagram(std::string &content)
1801 content += "CATEGORY:";
1802 content += GetCategory();
1805 content += "DESCRIPTION:";
1806 content += GetDescription();
1809 content += "AUTHOR:";
1810 content += GetAuthor();
1813 //Print info IF COMPLEX BOX
1814 content += "COMPLEXBOX:";
1815 if (_isComplexBox) {
1816 content += "TRUE\n";
1818 content += "COMPLEXBOXNAME:";
1819 content += GetCbName();
1822 content += "PACKAGENAME:";
1823 content += GetCbPackageName();
1826 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1827 * External inputs are possible for applications and complex boxes
1828 //Print info complex input ports
1829 std::vector<int> inputs = getComplexInputPorts();
1830 int insize = inputs.size();
1831 content += "COMPLEXINPUTS:";
1832 sprintf(buffer, "%d", insize);
1836 for (int i = 0; i < insize; i++) {
1838 GObjectController *cont = _controllers[id];
1839 cont->getModel()->save(content);
1843 //Print info complex output ports
1844 std::vector<int> outputs = getComplexOutputPorts();
1845 int outsize = outputs.size();
1846 content += "COMPLEXOUTPUTS:";
1847 sprintf(buffer, "%d", outsize);
1851 for (int i = 0; i < outsize; i++) {
1852 int id = outputs[i];
1853 GObjectController *cont = _controllers[id];
1854 cont->getModel()->save(content);
1858 content += "FALSE\n";
1861 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1862 // External inputs are possible for applications and complex boxes
1863 std::vector<int> inputs = getComplexInputPorts();
1864 int insize = inputs.size();
1865 content += "COMPLEXINPUTS:";
1866 sprintf(buffer, "%d", insize);
1870 for (int i = 0; i < insize; i++) {
1872 GObjectController *cont = _controllers[id];
1873 cont->getModel()->save(content);
1877 std::vector<int> boxes = getBlackBoxes();
1878 int bsize = boxes.size();
1879 content += "BOXES:";
1880 sprintf(buffer, "%d", bsize);
1884 for (int i = 0; i < bsize; i++) {
1886 // std::cout<<"id "<<id<<std::endl;//CFT
1887 GObjectController *cont = _controllers[id];
1888 // std::cout<<"nombre: "<<cont->getStatusText()<<std::endl;//CFT
1889 // std::cout<<"tipo: "<<cont->getModel()->getBBTKType()<<std::endl;//CFT
1890 // //boxesDiagram[i] = cont->getModel()->getBBTKType();//CFT
1891 // std::cout<<"nname: "<<cont->getModel()->getBBTKName()<<std::endl;//CFT
1892 // std::cout<<"categorie: "<<GetCategory()<<std::endl;//CFT
1893 // std::cout<<"type: "<<cont->getModel()->getGObjectType()<<std::endl;//CFT
1894 cont->getModel()->save(content);
1898 std::vector<int> connections = getConnections();
1899 int csize = connections.size();
1900 content += "CONNECTIONS:";
1901 sprintf(buffer, "%d", csize);
1905 for (int i = 0; i < csize; i++) {
1906 int id = connections[i];
1907 GObjectController *cont = _controllers[id];
1908 cont->getModel()->save(content);
1913 //=========================================================================
1914 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1916 getline(inputStream, line,'\n');
1917 int size = line.length();
1920 if ( line[ size-1 ]==13 )
1922 line.erase(size-1,1);
1927 //=========================================================================
1928 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1931 std::string version = "<void>";
1932 std::string line = "";
1933 char delims[] = ":";
1934 char *result = NULL;
1935 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1937 getCleanLine(inputStream, line);
1940 while (!inputStream.eof()) {
1941 if (line == "" || line[0] == '#') {
1943 getCleanLine(inputStream, line);
1945 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1946 version = line.substr(18, 3);
1948 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1949 version = line.substr(18, 3);
1951 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1952 version = line.substr(18, 3);
1954 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1955 version = line.substr(18, 3);
1957 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1958 version = line.substr(18, 3);
1960 } else if (line == "APP_START") {
1969 if ((version != "1.0") && (version != "1.1")) {
1970 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1971 char categoryTmp[30];
1972 strcpy(categoryTmp, line.c_str());
1973 result = strtok(categoryTmp, delims);
1974 result = strtok(NULL, delims);
1975 SetCategory(result);
1977 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1978 char descriptionTmp[1024];
1979 strcpy(descriptionTmp, line.c_str());
1980 result = strtok(descriptionTmp, delims);
1981 result = strtok(NULL, delims);
1982 SetDescription(result);
1984 getCleanLine(inputStream, line);//AUTHOR:<author>
1985 char authorTmp[255];
1986 strcpy(authorTmp, line.c_str());
1987 result = strtok(authorTmp, delims);
1988 result = strtok(NULL, delims);
1993 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1994 char complexTmp[30];
1995 strcpy(complexTmp, line.c_str());
1996 result = strtok(complexTmp, delims);
1997 result = strtok(NULL, delims);
1998 std::string isComplexBox(result);
2000 if (isComplexBox == "TRUE") {
2001 _isComplexBox = true;
2003 if ((version != "1.0") && (version != "1.1")) {
2004 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
2005 char complexboxnameTmp[255];
2006 strcpy(complexboxnameTmp, line.c_str());
2007 result = strtok(complexboxnameTmp, delims);
2008 result = strtok(NULL, delims);
2011 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
2012 char packagenameTmp[255];
2013 strcpy(packagenameTmp, line.c_str());
2014 result = strtok(packagenameTmp, delims);
2015 result = strtok(NULL, delims);
2016 SetCbPackageName(result);
2021 //-----------------------
2022 //- COMPLEX INPUT PORTS
2023 //-----------------------
2024 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2026 strcpy(inputs, line.c_str());
2027 result = strtok(inputs, delims);
2028 result = strtok(NULL, delims);
2031 std::istringstream inps(result);
2034 for (int i = 0; i < numInputs; i++) {
2036 getCleanLine(inputStream, line);//COMPLEX_PORT
2037 getCleanLine(inputStream, line);//name
2038 std::string inputPortName(line);
2041 getCleanLine(inputStream, line);//xInic:yInic:zInic
2043 strcpy(coord, line.c_str());
2044 result = strtok(coord, delims);//xInic
2045 std::string xInic(result);
2046 result = strtok(NULL, delims);//yInic
2047 std::string yInic(result);
2048 result = strtok(NULL, delims);//zInic
2049 std::string zInic(result);
2051 double xIn, yIn, zIn;
2052 std::istringstream xSt(xInic);
2054 std::istringstream ySt(yInic);
2056 std::istringstream zSt(zInic);
2061 if (zIn==900) zIn=GPOSITION_Z;
2064 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2066 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2068 } // for input complex box
2073 //-----------------------
2074 //- COMPLEX OUTPUT PORTS
2075 //-----------------------
2077 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2079 strcpy(outputs, line.c_str());
2080 result = strtok(outputs, delims);
2081 result = strtok(NULL, delims);
2084 std::istringstream outps(result);
2085 outps >> numOutputs;
2087 for (int i = 0; i < numOutputs; i++) {
2089 getCleanLine(inputStream, line);//COMPLEX_PORT
2090 getCleanLine(inputStream, line);//name
2091 std::string outputPortName(line);
2094 getCleanLine(inputStream, line);//xInic:yInic:zInic
2096 strcpy(coord, line.c_str());
2097 result = strtok(coord, delims);//xInic
2098 std::string xInic(result);
2099 result = strtok(NULL, delims);//yInic
2100 std::string yInic(result);
2101 result = strtok(NULL, delims);//zInic
2102 std::string zInic(result);
2104 double xIn, yIn, zIn;
2105 std::istringstream xSt(xInic);
2107 std::istringstream ySt(yInic);
2109 std::istringstream zSt(zInic);
2114 if (zIn==900) zIn=GPOSITION_Z;
2117 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2119 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2121 } // for output complex box
2125 // RaC2012 2nd Hackfest
2126 if(version >= "1.4")
2128 //-----------------------
2129 //- EXTERNAL INPUT PORTS
2130 //-----------------------
2131 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2133 strcpy(inputs, line.c_str());
2134 result = strtok(inputs, delims);
2135 result = strtok(NULL, delims);
2138 std::istringstream inps(result);
2141 for (int i = 0; i < numInputs; i++) {
2143 getCleanLine(inputStream, line);//COMPLEX_PORT
2144 getCleanLine(inputStream, line);//name
2145 std::string inputPortName(line);
2148 getCleanLine(inputStream, line);//xInic:yInic:zInic
2150 strcpy(coord, line.c_str());
2151 result = strtok(coord, delims);//xInic
2152 std::string xInic(result);
2153 result = strtok(NULL, delims);//yInic
2154 std::string yInic(result);
2155 result = strtok(NULL, delims);//zInic
2156 std::string zInic(result);
2158 double xIn, yIn, zIn;
2159 std::istringstream xSt(xInic);
2161 std::istringstream ySt(yInic);
2163 std::istringstream zSt(zInic);
2168 if (zIn==900) zIn=GPOSITION_Z;
2171 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2172 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2174 } // for external input
2179 getCleanLine(inputStream, line);//BOXES:num
2181 strcpy(boxes, line.c_str());
2182 result = strtok(boxes, delims);
2183 result = strtok(NULL, delims);
2186 std::istringstream is(result);
2189 for (int i = 0; i < numBoxes; i++)
2192 getCleanLine(inputStream, line);//BOX
2193 getCleanLine(inputStream, line);//package:type:name
2195 strcpy(box, line.c_str());
2196 result = strtok(box, delims);//package
2197 std::string package(result);
2198 result = strtok(NULL, delims);//type
2199 std::string type(result);
2200 result = strtok(NULL, delims);//name
2201 std::string name(result);
2204 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2206 strcpy(exec, line.c_str());
2207 result = strtok(exec, delims);//ISEXEC
2208 result = strtok(NULL, delims);//TRUE|FALSE
2209 std::string isExec(result);
2212 getCleanLine(inputStream, line);//xInic:yInic:zInic
2214 strcpy(coord, line.c_str());
2215 result = strtok(coord, delims);//xInic
2216 std::string xInic(result);
2217 result = strtok(NULL, delims);//yInic
2218 std::string yInic(result);
2219 result = strtok(NULL, delims);//zInic
2220 std::string zInic(result);
2222 double xIn, yIn, zIn;
2223 std::istringstream xSt(xInic);
2225 std::istringstream ySt(yInic);
2227 std::istringstream zSt(zInic);
2233 if (zIn==900) zIn=GPOSITION_Z;
2238 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2239 strcpy(coord, line.c_str());
2240 result = strtok(coord, delims);//xEnd
2241 std::string xEnd(result);
2242 result = strtok(NULL, delims);//yEnd
2243 std::string yEnd(result);
2244 result = strtok(NULL, delims);//zEnd
2245 std::string zEnd(result);
2247 double xEn, yEn, zEn;
2248 std::istringstream xEt(xEnd);
2250 std::istringstream yEt(yEnd);
2252 std::istringstream zEt(zEnd);
2257 if (zEn==900) zEn=GPOSITION_Z;
2261 bool boxExecutable = false;
2262 if (isExec == "TRUE")
2264 boxExecutable = true;
2267 int idBox = createGBlackBox(xIn, yIn, package, type);
2268 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2270 GObjectController *cont = _controllers[idBox];
2271 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2274 getCleanLine(inputStream, line);//PORT o FIN_BOX
2275 std::string port = line.substr(0, 4);
2276 while (port == "PORT")
2278 getCleanLine(inputStream, line);//name:value
2279 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2281 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2284 strcpy(poort, line.c_str());
2285 result = strtok(poort, delims);//name
2286 std::string name(result);
2288 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2289 result = strtok(NULL, delims);//value
2290 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2292 std::string tmpString=" ";
2293 tmpString[0]=34; // character "
2294 strcat(result,tmpString.c_str());
2296 std::string value(result);
2298 bbmod->setValueToInput(name, value);
2300 getCleanLine(inputStream, line);//PORT o FIN_BOX
2301 port = line.substr(0, 4);
2304 //EED bbmod->notifyObservers(_idManager);
2309 getCleanLine(inputStream, line);//CONNECTIONS:num
2311 strcpy(conns, line.c_str());
2312 result = strtok(conns, delims);
2313 result = strtok(NULL, delims);
2316 std::istringstream isCons(result);
2320 for (int i = 0; i < numConns; i++)
2323 getCleanLine(inputStream, line);//CONNECTION
2324 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2327 strcpy(connec, line.c_str());
2328 result = strtok(connec, delims);
2329 std::string nameStartBox(result);
2330 result = strtok(NULL, delims);
2331 std::string nameStartPort(result);
2332 result = strtok(NULL, delims);
2333 std::string nameEndBox(result);
2334 result = strtok(NULL, delims);
2335 std::string nameEndPort(result);
2337 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2339 if (version != "1.0") {
2340 //Readding control points of the manualContour
2341 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2342 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2343 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2344 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2345 strcpy(conns, line.c_str());
2346 result = strtok(conns, delims);
2347 result = strtok(NULL, delims);
2349 int numberOfControlPoints;
2350 std::istringstream isCons(result);
2351 isCons >> numberOfControlPoints;
2353 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2354 getCleanLine(inputStream, line); //XX:YY:ZZ
2356 strcpy(connec, line.c_str());
2359 result = strtok(connec, delims);
2360 std::istringstream isPointX(result);
2362 result = strtok(NULL, delims);
2363 std::istringstream isPointY(result);
2365 result = strtok(NULL, delims);
2366 std::istringstream isPointZ(result);
2371 if (pz==900) pz=GPOSITION_Z;
2374 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2375 conView->getManualContourView()->AddPoint();
2381 //=========================================================================
2384 //=========================================================================
2385 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2386 std::string portName, double xIn, double yIn, double zIn)
2389 if (inputoutput == true) {
2390 idPort = createGComplexBoxInputPort(portName);
2392 idPort = createGComplexBoxOutputPort(portName);
2394 GObjectController *cont = _controllers[idPort];
2395 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2396 cbmod->setInicPoint(xIn, yIn, zIn);
2397 cbmod->notifyObservers(_idManager);
2399 //=========================================================================
2402 //=========================================================================
2403 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2408 GBoxModel *boxModel = NULL;
2409 std::vector<int> lstB = getBlackBoxes();
2410 for (j = 0; j < (int) lstB.size(); j++) {
2412 bMod = (GBoxModel*) _controllers[idB]->getModel();
2413 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2421 if (boxModel == NULL) {
2422 std::vector<int> lstInputs = getComplexInputPorts();
2423 for (j = 0; j < (int) lstInputs.size(); j++) {
2425 bMod = (GBoxModel*) _controllers[idB]->getModel();
2426 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2434 std::vector<int> lstOutputs = getComplexOutputPorts();
2435 for (j = 0; j < (int) lstOutputs.size(); j++) {
2436 int idB = lstOutputs[j];
2437 bMod = (GBoxModel*) _controllers[idB]->getModel();
2438 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2450 //=========================================================================
2453 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2454 std::string nameStartPort, std::string nameEndBox,
2455 std::string nameEndPort) {
2457 GBoxModel *boxModel;
2458 GPortModel *startP = NULL;
2459 GPortModel *endP = NULL;
2461 boxModel = findGBox(nameStartBox);
2462 if(boxModel == NULL)
2464 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2466 if (boxModel != NULL) {
2467 startP = boxModel->getOutputPort(nameStartPort);
2469 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() );
2473 boxModel = findGBox(nameEndBox);
2474 if(boxModel == NULL)
2476 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2478 if (boxModel != NULL) {
2479 endP = boxModel->getInputPort(nameEndPort);
2481 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());
2486 int idCon = createGConnector(startP);
2488 _worldState = NOTHING_HAPPENS;
2489 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2491 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2492 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2493 tempp->endContourCreation();
2494 conMod->setEndPort(endP);
2495 conView->updateStartEndPoints();
2499 //=========================================================================
2501 bool wxVtkSceneManager::boxExist(std::string boxname) {
2503 std::map<int, GObjectController*>::iterator it;
2504 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2505 GObjectController *cont = it->second;
2506 if (cont->getModel()->getBBTKName() == boxname) {
2513 //=========================================================================
2515 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2516 std::vector<int> vect;
2517 std::map<int, GObjectController*>::iterator it;
2518 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2519 GObjectController *cont = it->second;
2520 if (cont->getGObjectType() == GBLACKBOX) {
2521 vect.push_back(cont->getId());
2527 //=========================================================================
2529 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2530 std::vector<int> vect;
2531 std::map<int, GObjectController*>::iterator it;
2532 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2533 GObjectController *cont = it->second;
2534 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2535 vect.push_back(cont->getId());
2541 //=========================================================================
2543 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2544 std::vector<int> vect;
2545 std::map<int, GObjectController*>::iterator it;
2546 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2547 GObjectController *cont = it->second;
2548 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2549 vect.push_back(cont->getId());
2555 //=========================================================================
2557 std::vector<int> wxVtkSceneManager::getConnections() {
2558 std::vector<int> vect;
2559 std::map<int, GObjectController*>::iterator it;
2560 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2561 GObjectController *cont = it->second;
2562 if (cont->getGObjectType() == GCONNECTOR) {
2563 vect.push_back(cont->getId());
2569 //=========================================================================
2571 bool wxVtkSceneManager::isComplexBox() {
2572 return _isComplexBox;
2575 //=========================================================================
2577 void wxVtkSceneManager::setComplexBox(bool val) {
2578 _isComplexBox = val;
2581 //=========================================================================
2583 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2584 //Register the controller of the new object
2585 registerController((InteractorStyleMaracas*) objController);
2586 //Add the object to the objects list
2587 int newId = _contLastId;//_controllers.size();
2588 objController->setId(newId);
2589 _controllers[newId] = objController;
2590 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2595 //=========================================================================
2597 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2599 std::map<int, int> oldIdNewIdBoxes;
2600 std::vector<int> connections;
2602 std::vector<int> newBoxesID;
2604 std::map<int, GObjectController*>::iterator it;
2605 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2606 GObjectController *cont = it->second;
2607 int type = cont->getGObjectType();
2609 if (type == GBLACKBOX) {
2611 double xInic, yInic, zInic;
2612 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2613 copyBox->getInicPoint(xInic, yInic, zInic);
2614 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2615 copyBox->getBBTKType());
2617 int idcB = copyBox->getObjectId();
2618 oldIdNewIdBoxes[idcB] = idBox;
2619 cont = _controllers[idBox];
2620 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2621 newbox->setInicPoint(xInic, yInic, zInic);
2622 int num = newbox->getNumInputPorts();
2623 for (int j = 0; j < num; j++) {
2624 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2626 newbox->move(xInic + 20, yInic + 20, zInic);
2627 newbox->notifyObservers(_idManager);
2628 newBoxesID.push_back(newbox->getObjectId());
2630 } else if (type == GCONNECTOR) {
2631 int idCon = cont->getId();
2632 connections.push_back(idCon);
2637 for (int i = 0; i < (int) connections.size(); i++) {
2638 int objId = connections[i];
2639 GObjectController *cont = objectsMap[objId];
2640 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2642 GPortModel* startPort = connectModel->getStartPort();
2643 int startPortIndex = startPort->getPosInBox();
2644 GPortModel* endPort = connectModel->getEndPort();
2645 int endPortIndex = endPort->getPosInBox();
2647 GBlackBoxModel* startPortParentBox =
2648 (GBlackBoxModel*) startPort->getParentBox();
2649 GBlackBoxModel* endPortParentBox =
2650 (GBlackBoxModel*) endPort->getParentBox();
2652 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2653 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2655 GBlackBoxModel* newStartBox =
2656 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2657 GBlackBoxModel* newEndBox =
2658 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2660 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2661 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2663 // Creates connection
2664 int idCon = createGConnector(newStartPort);
2665 GConnectorController *tempp =
2666 (GConnectorController*) _controllers[idCon];
2667 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2668 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2669 tempp->endContourCreation();
2670 conMod->setEndPort(newEndPort);
2671 conView->updateStartEndPoints();
2674 /// the new selected boxes are the duplicate ones
2676 UnSelectBlackBoxes();
2677 for (int i = 0; i < newBoxesID.size(); i++) {
2678 _selectedObjects.push_back(newBoxesID.at(i));
2681 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2682 int id = _selectedObjects[i];
2683 GObjectController* cont = _controllers[id];
2685 cont->getView()->setState(SELECTED);
2686 cont->getModel()->notifyObservers(_idManager);
2692 //=========================================================================
2694 int wxVtkSceneManager::getNumSelectedObjects() {
2695 return _selectedObjects.size();
2698 //=========================================================================
2700 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2701 std::map<int, GObjectController*> mapSelected;
2703 std::map<int, GObjectController*>::iterator it;
2704 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2705 GObjectController *cont = it->second;
2706 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2708 mapSelected[cont->getId()] = cont;
2712 std::map<int, GObjectController*>::iterator it2;
2713 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2714 GObjectController *cont = it2->second;
2715 if (cont->getGObjectType() == GCONNECTOR) {
2716 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2717 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2718 GBoxModel* startPortParentBox =
2719 cmod->getStartPort()->getParentBox();
2721 std::map<int, GObjectController*>::iterator iterOBJ1 =
2722 mapSelected.find(startPortParentBox->getObjectId());
2723 std::map<int, GObjectController*>::iterator iterOBJ2 =
2724 mapSelected.find(endPortParentBox->getObjectId());
2726 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2727 int ID = cont->getId();
2728 mapSelected[ID] = cont;
2735 //=========================================================================
2737 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2739 std::map<int, int> oldIdNewIdBoxes;
2740 std::vector<int> connections;
2742 std::map<int, GObjectController*>::iterator it;
2743 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2744 GObjectController *cont = it->second;
2745 int type = cont->getGObjectType();
2747 if (type == GBLACKBOX) {
2749 double xInic, yInic, zInic;
2750 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2751 copyBox->getInicPoint(xInic, yInic, zInic);
2752 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2754 int idcB = copyBox->getObjectId();
2755 oldIdNewIdBoxes[idcB] = idBox;
2756 cont = _controllers[idBox];
2757 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2758 newbox->setInicPoint(xInic, yInic, zInic);
2759 int num = newbox->getNumInputPorts();
2760 for (int j = 0; j < num; j++)
2762 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2764 newbox->notifyObservers(_idManager);
2765 } else if (type == GCONNECTOR) {
2766 int idCon = cont->getId();
2767 connections.push_back(idCon);
2772 for (int i = 0; i < (int) connections.size(); i++) {
2773 int objId = connections[i];
2774 GObjectController *cont = objectsMap[objId];
2775 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2777 GPortModel* startPort = connectModel->getStartPort();
2778 int startPortIndex = startPort->getPosInBox();
2779 GPortModel* endPort = connectModel->getEndPort();
2780 int endPortIndex = endPort->getPosInBox();
2782 GBlackBoxModel* startPortParentBox =
2783 (GBlackBoxModel*) startPort->getParentBox();
2784 GBlackBoxModel* endPortParentBox =
2785 (GBlackBoxModel*) endPort->getParentBox();
2787 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2788 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2790 GBlackBoxModel* newStartBox =
2791 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2792 GBlackBoxModel* newEndBox =
2793 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2795 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2796 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2798 // Creates connection
2799 int idCon = createGConnector(newStartPort);
2800 GConnectorController *tempp =
2801 (GConnectorController*) _controllers[idCon];
2802 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2803 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2804 tempp->endContourCreation();
2805 conMod->setEndPort(newEndPort);
2806 conView->updateStartEndPoints();
2809 std::map<int, int>::iterator itIds;
2810 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2811 int idOld = itIds->first;
2812 int idNew = itIds->second;
2814 GBlackBoxModel* oldBox =
2815 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2816 GBlackBoxModel* newBox =
2817 (GBlackBoxModel*) _controllers[idNew]->getModel();
2819 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2820 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2821 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2822 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2824 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2826 //EED int toCreate=-1;
2827 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2828 if (oldInputConnections[k] == newInputConnections[l]) {
2833 if (exist == false) {
2834 //Create complex input
2835 int posInBox = oldInputConnections[k];
2836 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2837 std::string inputPortName = inputPort->getBBTKName();
2838 int idInputPort = createGComplexBoxInputPort(inputPortName);
2839 GObjectController *cont = _controllers[idInputPort];
2840 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2841 double xIn, yIn, zIn;
2842 inputPort->getInicPoint(xIn, yIn, zIn);
2844 cbmod->setInicPoint(xIn, yIn, zIn);
2845 cbmod->notifyObservers(_idManager);
2847 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2849 // Creates connection
2850 int idCon = createGConnector(cbmod->getOutputPort(0));
2851 GConnectorController *tempp =
2852 (GConnectorController*) _controllers[idCon];
2853 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2854 vtkGConnectorView *conView =
2855 (vtkGConnectorView*) tempp->getView();
2856 tempp->endContourCreation();
2857 conMod->setEndPort(inputPortEnd);
2858 conView->updateStartEndPoints();
2864 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2866 //EED int toCreate=-1;
2867 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2868 if (oldOutputConnections[k] == newOutputConnections[l]) {
2873 if (exist == false) {
2874 //Create complex output
2875 int posInBox = oldOutputConnections[k];
2876 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2877 std::string outputPortName = outputPort->getBBTKName();
2878 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2879 GObjectController *cont = _controllers[idOutputPort];
2880 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2881 double xIn, yIn, zIn;
2882 outputPort->getInicPoint(xIn, yIn, zIn);
2884 cbmod->setInicPoint(xIn, yIn, zIn);
2885 cbmod->notifyObservers(_idManager);
2887 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2889 // Creates connection
2890 int idCon = createGConnector(outputPortEnd);
2891 GConnectorController *tempp =
2892 (GConnectorController*) _controllers[idCon];
2893 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2894 vtkGConnectorView *conView =
2895 (vtkGConnectorView*) tempp->getView();
2896 tempp->endContourCreation();
2897 conMod->setEndPort(cbmod->getInputPort(0));
2898 conView->updateStartEndPoints();
2908 //=========================================================================
2909 void wxVtkSceneManager::SetCbName(std::string cbName) {
2911 if (_cbName == "") {
2912 _cbName = "<complex box name>";
2916 //=========================================================================
2917 std::string wxVtkSceneManager::GetCbName() {
2921 //=========================================================================
2922 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2923 _cbPackageName = packagename;
2924 if (_cbPackageName == "") {
2925 _cbPackageName = "<package name of the complex box>";
2929 //=========================================================================
2930 std::string wxVtkSceneManager::GetCbPackageName() {
2931 return _cbPackageName;
2934 //=========================================================================
2935 void wxVtkSceneManager::SetAuthor(std::string author) {
2937 if (_Author == "") {
2938 _Author = "<author of the box>";
2942 //=========================================================================
2943 std::string wxVtkSceneManager::GetAuthor() {
2947 //=========================================================================
2948 void wxVtkSceneManager::SetCategory(std::string category) {
2949 _Category = category;
2950 if (_Category == "") {
2951 _Category = "<category of the box>";
2955 //=========================================================================
2956 std::string wxVtkSceneManager::GetCategory() {
2960 //=========================================================================
2961 void wxVtkSceneManager::SetDescription(std::string description) {
2962 _Description = description;
2963 if (_Description == "") {
2964 _Description = "<description of the box>";
2968 //=========================================================================
2969 std::string wxVtkSceneManager::GetDescription() {
2970 return _Description;
2973 //=========================================================================
2975 void wxVtkSceneManager::SetMessageKind(std::string kind) {
2976 _MessageKind = kind;
2980 //=========================================================================
2982 std::string wxVtkSceneManager::GetMessageKind(){
2983 return _MessageKind;
2986 //=========================================================================
2988 void wxVtkSceneManager::SetMessageLevel(std::string Level){
2989 _MessageLevel = Level;
2992 //=========================================================================
2994 std::string wxVtkSceneManager::GetMessageLevel(){
2995 return _MessageLevel;
2998 //=========================================================================
3000 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
3003 std::vector< std::string> extInputs;
3004 std::map<int, GObjectController*>::iterator it;
3005 for (it = _controllers.begin(); it != _controllers.end(); ++it)
3007 GObjectController *cont = it->second;
3008 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
3010 extInputs.push_back(cont->getModel()->getBBTKName());
3016 //=========================================================================
3020 void wxVtkSceneManager::printAll(int com , int sta ){
3022 int tmpState = sta ;
3023 if ( tmpState == NOTHING_HAPPENS ) {
3024 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
3026 if ( tmpState == HIGHLIGHTED ) {
3027 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
3029 if ( tmpState == POSSIBLE_CONNECTION ) {
3030 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
3032 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
3033 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
3035 if ( tmpState == CLICKED ) {
3036 std::cout << "CONTROLER STATE---->CLICKED\n" ;
3038 if ( tmpState == DRAG ) {
3039 std::cout << "CONTROLER STATE---->DRAG\n" ;
3041 if ( tmpState == SELECTED ) {
3042 std::cout << "CONTROLER STATE---->SELECTED\n" ;
3044 if ( tmpState == CREATING_CONTOUR ) {
3045 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
3051 if ( command == INIT_CREATION_CONTOUR ) {
3052 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
3054 if ( command == FIN_CREATION_CONTOUR ) {
3055 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
3057 if ( command == ADD_TO_SELECTED ) {
3058 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
3060 if ( command == DRAG_OBJECTS ) {
3061 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
3063 if ( command == EDIT_BLACKBOX ) {
3064 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
3066 if ( command == REMOVE_FROM_SELECTED ) {
3067 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
3073 } // EO namespace bbtk