2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
8 # This software is governed by the CeCILL-B license under French law and
9 # abiding by the rules of distribution of free software. You can use,
10 # modify and/ or redistribute the software under the terms of the CeCILL-B
11 # license as circulated by CEA, CNRS and INRIA at the following URL
12 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
13 # or in the file LICENSE.txt.
15 # As a counterpart to the access to the source code and rights to copy,
16 # modify and redistribute granted by the license, users are provided only
17 # with a limited warranty and the software's author, the holder of the
18 # economic rights, and the successive licensors have only limited
21 # The fact that you are presently reading this means that you have had
22 # knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------
26 /*=========================================================================
32 =========================================================================*/
34 /* ---------------------------------------------------------------------
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
39 * This software is governed by the CeCILL-B license under French law and
40 * abiding by the rules of distribution of free software. You can use,
41 * modify and/ or redistribute the software under the terms of the CeCILL-B
42 * license as circulated by CEA, CNRS and INRIA at the following URL
43 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
44 * or in the file LICENSE.txt.
46 * As a counterpart to the access to the source code and rights to copy,
47 * modify and redistribute granted by the license, users are provided only
48 * with a limited warranty and the software's author, the holder of the
49 * economic rights, and the successive licensors have only limited
52 * The fact that you are presently reading this means that you have had
53 * knowledge of the CeCILL-B license and that you accept its terms.
54 * ------------------------------------------------------------------------ */
58 * \brief Class bbtk::wxVtkSceneManager .
61 #include "wxVtkSceneManager.h"
63 #include <vtkPolygon.h>
64 #include <vtkUnstructuredGrid.h>
68 #define POORT_MAX_LINE_SIZE_INTERPRETER 1500
70 //=========================================================================
72 // EED 15 oct 2012 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
74 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
76 _cbName = "ComplexBoxName";
77 _cbPackageName = "PackageName";
78 _Author = "Author ??";
80 _Description = "Description ??";
84 _bugTextActor_text = "void";
85 _bugTextActor_status = 0;
89 _idManager = idManager;
91 _bbtkfactory = bbtkfactory;
93 _startDragging = false;
94 _isComplexBox = false;
96 if (_baseView != NULL) {
99 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
102 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
106 _worldState = NOTHING_HAPPENS;
107 registerController(this);
110 _idConnectionInCreation = -1;
115 //=========================================================================
117 void wxVtkSceneManager::disconnectDrop()
119 printf("EED %p ~wxVtkSceneManager::disconnectDrop()\n", this);
120 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
121 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
124 //=========================================================================
126 wxVtkSceneManager::~wxVtkSceneManager()
129 printf("EED %p ~wxVtkSceneManager() START\n", this);
132 printf("EED %p ~wxVtkSceneManager() END\n", this);
135 //=========================================================================
137 void wxVtkSceneManager::configureBaseView()
139 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
141 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
143 // Important to activate the 2D interaction system
144 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();
219 _aPolygonMapper->SetInput(aPolygonGrid);
220 _fillObjectActor->SetMapper(_aPolygonMapper);
221 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
223 _fillObjectActor->GetProperty()->SetOpacity(0);
224 _aPolygonMapper->Modified();
226 _baseView->GetRenderer()->AddActor(_fillObjectActor);
229 //=========================================================================
231 std::string wxVtkSceneManager::generateANewNameForABox() {
232 std::stringstream boxname;
233 if (_numBoxes < 10) {
234 boxname << "Box0" << _numBoxes;
236 boxname << "Box" << _numBoxes;
239 return boxname.str();
242 //=========================================================================
244 std::string wxVtkSceneManager::findANewNameForABox() {
245 std::string boxname = generateANewNameForABox();
247 while (boxExist(boxname) == true) {
248 boxname = generateANewNameForABox();
254 //=========================================================================
255 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
256 double zIn, std::string name, bool boxExecutable, double xEn,
257 double yEn, double zEn) {
258 GObjectController *cont = _controllers[idBox];
259 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
260 bbmod->setBBTKName(name);
261 bbmod->setInicPoint(xIn, yIn, zIn);
262 bbmod->setFinalPoint(xEn, yEn, zEn);
263 bbmod->setExecutable(boxExecutable);
265 bbmod->notifyObservers(_idManager);
269 //=========================================================================
271 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,std::string boxType)
273 _worldState = NOTHING_HAPPENS;
274 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
275 int type = GBLACKBOX;
276 //Create the MVC Objects
277 GBlackBoxModel *model = (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
278 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
279 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
281 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
285 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
287 k = _bbtkfactory->GetPackage(packageName);
288 mapDesc = k->GetDescriptorMap();
290 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for package %s, NOT EXIST\n", packageName.c_str());
293 BlackBoxDescriptor::Pointer descriptor;
295 descriptor = mapDesc[boxType];
297 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for box %s of package %s, NOT EXIST\n", boxType.c_str(),packageName.c_str());
300 if (descriptor == NULL)
302 printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
305 //Prepares the initial model
306 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
309 double yy = windowHeight - y;
311 //z value is not important yet, because it is only used a parallel projection
312 double zz = GPOSITION_Z;
313 _baseView->TransCoordScreenToWorld(xx, yy, zz);
314 model->setInicPoint(xx, yy, zz);
316 std::stringstream stream;
318 std::string newBoxName;
319 newBoxName = findANewNameForABox();
321 stream << newBoxName;
323 std::string arraystring = stream.str();
325 model->setBBTKName(arraystring);
326 model->setBBTKType(boxType);
327 model->setBBTKPackage(packageName);
329 model->addObserver(view);
330 model->addObserver(this);
332 //Iterate and create the input ports
333 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
334 descriptor->GetInputDescriptorMap();
335 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
337 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) {
338 BlackBoxInputDescriptor *desc = itInput->second;
339 createGInputPort(GINPUTPORT, i, model, desc);
343 //Iterate and create the output ports
344 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
345 descriptor->GetOutputDescriptorMap();
346 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
348 for (itOutput = descriptorOutMap.begin(); itOutput
349 != descriptorOutMap.end(); ++itOutput) {
350 BlackBoxOutputDescriptor *desc = itOutput->second;
351 createGOutputPort(GOUTPUTPORT, i, model, desc);
355 //Associates the view with the correspondent renderer and the model.
356 //(NOTE: Refresh is only made by the view)
357 view->setModel(model);
358 view->setBaseView(_baseView);
360 view->initVtkObjects();
362 //Associates the controller with the correspondent model and view
363 controller->setModelAndView(model, view);
365 //Resgiter change to the observers of the actual model
366 model->notifyObservers(_idManager);
368 int newId = addObjectController(controller);
374 //=========================================================================
376 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
377 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
378 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
380 int type = GCOMPLEXINPUTPORT;
382 //Create the MVC Objects
384 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
385 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
386 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
388 //Prepares the initial model
391 double yy = windowHeight - 5;
393 //z value is not important yet, because it is only used a parallel projection
394 double zz = GPOSITION_Z;
396 _baseView->TransCoordScreenToWorld(xx, yy, zz);
397 model->setInicPoint(xx, yy, zz);
399 model->setBBTKName(inputName);
400 model->setBBTKType("ComplexInputPort");
401 model->setComplexPortType(type);
403 model->addObserver(view);
404 model->addObserver(this);
406 //create the output port
407 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
408 "ComplexOutputPortType","ComplexOutputPortDescriopton", 0, model);
409 model->addOutputPort((GPortModel*) portController->getModel());
411 //Associates the view with the correspondent renderer and the model.
412 //(NOTE: Refresh is only made by the view)
413 view->setModel(model);
414 view->setBaseView(_baseView);
415 view->initVtkObjects();
417 //Associates the controller with the correspondent model and view
418 controller->setModelAndView(model, view);
420 //Resgiter change to the observers of the actual model
421 model->notifyObservers(_idManager);
423 int newId = addObjectController(controller);
427 //=========================================================================
429 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
430 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
431 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
433 int type = GCOMPLEXOUTPUTPORT;
435 //Create the MVC Objects
437 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
438 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
439 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
441 //Prepares the initial model
444 double yy = windowHeight - 5;
446 //z value is not important yet, because it is only used a parallel projection
447 double zz = GPOSITION_Z;
449 _baseView->TransCoordScreenToWorld(xx, yy, zz);
450 model->setInicPoint(xx, yy, zz);
452 model->setBBTKName(outputName);
453 model->setBBTKType("ComplexOutputPort");
454 model->setComplexPortType(type);
456 model->addObserver(view);
457 model->addObserver(this);
459 //create the output port
460 GPortController* portController = createGPort(GINPUTPORT, outputName,
461 "ComplexInputPort","ComplexInputPortDescription", 0, model);
462 model->addInputPort((GPortModel*) portController->getModel());
464 //Associates the view with the correspondent renderer and the model.
465 //(NOTE: Refresh is only made by the view)
466 view->setModel(model);
467 view->setBaseView(_baseView);
468 view->initVtkObjects();
470 //Associates the controller with the correspondent model and view
471 controller->setModelAndView(model, view);
473 //Resgiter change to the observers of the actual model
474 model->notifyObservers(_idManager);
476 int newId = addObjectController(controller);
480 //=========================================================================
482 int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
484 GPortController* portController = createGPort(portType, desc->GetName(),
485 desc->GetTypeName(), desc->GetDescription(), posinBox, blackBox);
486 blackBox->addInputPort((GPortModel*) portController->getModel());
487 return portController->getId();
490 //=========================================================================
492 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
494 GPortController* portController = createGPort(portType, desc->GetName(),
495 desc->GetTypeName(),desc->GetDescription(), posinBox, blackBox);
496 blackBox->addOutputPort((GPortModel*) portController->getModel());
497 return portController->getId();
500 //=========================================================================
502 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posInBox,GBoxModel *blackBox)
506 //Create the MVC Objects
509 (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
511 vtkGObjectView *view =
512 GObjectsMVCFactory::getInstance()->createGObjectView(type);
513 GObjectController* controller =
514 GObjectsMVCFactory::getInstance()->createGObjectController(type);
516 model->registerInBox(blackBox, portType, posInBox);
518 model->setBBTKType(bbtkType);
519 model->setBBTKName(bbtkName);
520 model->setBBTKDescription(bbtkDescription);
522 model->addObserver(view);
523 model->addObserver(this);
525 //Associates the view with the correspondent renderer and the model.
526 //(NOTE: Refresh is only made by the view)
527 view->setModel(model);
528 view->setBaseView(_baseView);
530 //EED017 view->initVtkObjects();
531 view->createVtkObjects();
532 // view->addVtkActors();
535 //Associates the controller with the correspondent model and view
536 controller->setModelAndView(model, view);
538 model->notifyObservers(_idManager);
540 addObjectController(controller);
542 return (GPortController*) controller;
546 //=========================================================================
548 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
550 int type = GCONNECTOR;
552 manualConnectorContourController *manContourControl = new manualConnectorContourController();
553 manualConnectorContourView *manContourView = new manualConnectorContourView();
554 manualContourModel *manContourModel = new manualContourModel();
555 GConnectorController *connectorcontroller = new GConnectorController();
556 GConnectorModel *connectorModel = new GConnectorModel();
557 vtkGConnectorView *connectorView = new vtkGConnectorView();
558 connectorModel->setGObjectType(type);
560 manContourModel->SetCloseContour(false);
561 connectorModel->setStartPort(startPort);
563 manContourView->SetModel(manContourModel);
564 manContourView->SetWxVtkBaseView(_baseView);
565 manContourView->SetRange(0.5);
566 manContourView->SetZ(GPOSITION_Z);
568 manContourView->SetColorNormalContour(0, 0, 1);
569 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
570 manContourView->SetColorSelectContour(1, 0.8, 0);
576 * Width increased from 2 to 3, it simplifies line handling and spline control :P
580 manContourView->SetWidthLine( 3 ) ;
581 manContourView->SetShowText(false);
583 manContourControl->SetModelView(manContourModel, manContourView);
585 manContourControl->CreateNewManualContour();
589 connectorModel->getInicPoint(x, y, z);
592 manContourControl->SetState(1);
593 manContourModel->SetCloseContour(false);
595 manContourModel->AddPoint(x, y, z);
596 manContourView->AddPoint();
598 manContourModel->AddPoint(x, y, z);
599 manContourView->AddPoint();
601 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
602 manContourControl->_bakIdPoint = bak;
604 manContourControl->SetMoving(false);
606 connectorcontroller->setModelAndView(connectorModel, connectorView);
608 int newId = addObjectController(connectorcontroller);
610 connectorcontroller->setManualContourController(manContourControl);
611 connectorModel->setManualContourModel(manContourModel);
612 connectorView->setManualContourView(manContourView);
613 connectorView->setModel(connectorModel);
614 connectorView->setBaseView(_baseView);
616 connectorModel->addObserver(connectorView);
617 connectorModel->addObserver(this);
619 // manContourView->Refresh();
624 //=========================================================================
626 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
628 vtkInteractorStyleBaseView * baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
629 baseViewControlManager->AddInteractorStyleMaracas(param);
632 //=========================================================================
634 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
636 vtkInteractorStyleBaseView *baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
637 baseViewControlManager->RemoveInteractorStyleMaracas(param);
640 //=========================================================================
642 vtkRenderer* wxVtkSceneManager::getRenderer()
644 return _baseView->GetRenderer();
647 //=========================================================================
649 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
651 return _baseView->GetRenWin();
653 //=========================================================================
656 //=========================================================================
657 int wxVtkSceneManager::GetIndexInSelected(int idControler)
660 for (int i = 0; i < (int) _selectedObjects.size(); i++)
662 if (_selectedObjects[i] == idControler)
670 //=========================================================================
672 void wxVtkSceneManager::update(int idController, int command) {
674 if (command != NO_COMMAND)
676 if (command == ADD_TO_SELECTED)
678 if (GetIndexInSelected(idController) == -1)
680 _selectedObjects.push_back(idController);
682 } else if (command == REMOVE_FROM_SELECTED) {
683 int index = GetIndexInSelected(idController);
686 _selectedObjects.erase(_selectedObjects.begin() + index);
688 } else if (command == INIT_CREATION_CONTOUR) {
690 typedef std::map<int , GObjectController*>::iterator TIterator ;
693 // Find current item in the controller
694 iter = _controllers.find( idController ) ;
695 iter_end = _controllers.end( ) ;
697 if ( iter != iter_end ) {
698 GObjectController* gobjc = iter->second ;
700 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
701 // And if the item is a port
702 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
703 TIterator c_it = _controllers.begin( ) ;
704 // Go through all componets
705 for ( c_it ; c_it != iter_end ; c_it++ ) {
706 GObjectController* obc = c_it->second ;
707 int obc_type = obc->getModel( )->getGObjectType( ) ;
708 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
709 // if the component is a port and the type is the same of that selected
710 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
712 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
713 //obc->getView( )->setState( HIGHLIGHTED ) ;
721 _worldState = INIT_CREATION_CONTOUR;
722 GObjectController* cont = _controllers[idController];
723 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
725 // The last one is the controller of the connector
726 std::map<int, GObjectController*>::iterator it2;
728 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
730 GObjectController *cont = it2->second;
731 if (cont->getGObjectType() == GPORT)
733 GPortModel* port = (GPortModel*) cont->getModel();
734 if (port->getPortType() == GINPUTPORT)
736 cont->SetActive(true);
738 cont->getView()->setState(NOTHING_HAPPENS);
739 cont->getModel()->notifyObservers(_idManager);
740 cont->SetActive(false);
743 cont->getView()->setState(NOTHING_HAPPENS);
744 cont->getModel()->notifyObservers(_idManager);
745 cont->SetActive(false);
748 _selectedObjects.clear();
749 _idConnectionInCreation = createGConnector(startOutputPort);
750 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
751 _worldState = NOTHING_HAPPENS;
752 //int id = _controllers.size()-1;
753 GObjectController *cont = _controllers[_idConnectionInCreation];
754 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
755 GObjectController *finPort = _controllers[idController];
757 if (finPort->getGObjectType() == GPORT)
759 GPortModel* modelPort = (GPortModel*) finPort->getModel();
760 modelContour->setEndPort(modelPort);
763 typedef std::map<int, GObjectController*>::iterator TIterator;
764 TIterator c_it = _controllers.begin();
765 TIterator iter_end = _controllers.end();
766 // Go through all componets
767 for (c_it; c_it != iter_end; c_it++) {
768 GObjectController* obc = c_it->second;
769 int obc_type = obc->getModel()->getGObjectType();
770 int obc_state = obc->getView()->getState();
771 // if the component is a port and the type is the same of that selected
772 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
773 // Return element to neutral state if not selected
774 obc->getView()->setState(NOTHING_HAPPENS);
776 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
777 // Change element to connected state
778 obc->getView()->setState(HIGHLIGHTED);
785 _parent->saveTempandUpdate("create connection");
788 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
789 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
791 std::map<int, GObjectController*>::iterator it2;
793 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
795 GObjectController *cont = it2->second;
796 if (cont->getView() != NULL) {
797 cont->getView()->setState(NOTHING_HAPPENS);
798 cont->getModel()->notifyObservers(_idManager);
800 cont->SetActive(true);
809 //=========================================================================
811 bool wxVtkSceneManager::OnMouseMove()
814 bool okStatusMessage = false;
815 bool okPortMessage = false;
816 wxVTKRenderWindowInteractor *wxVTKiren;
817 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
818 wxVTKiren->GetEventPosition(X, Y);
820 if (_worldState == DRAG_OBJECTS) {
821 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
822 int id = _selectedObjects[i];
823 GObjectController* cont = _controllers[id];
824 if (_startDragging) {
825 cont->getView()->setStartDragging(true);
827 cont->getView()->moveObject(X, Y);
828 cont->getView()->setState(DRAG);
829 cont->getModel()->notifyObservers(_idManager);
832 std::map<int, GObjectController*>::iterator it;
834 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
835 GObjectController *desc = it->second;
836 if (desc->getGObjectType() == GCONNECTOR) {
837 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
838 vconn->updateStartEndPoints();
842 _startDragging = false;
844 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
845 std::map<int, GObjectController*>::iterator it;
847 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
848 GObjectController *desc = it->second;
849 int type = desc->getGObjectType();
850 int state = desc->getView()->getState();
851 desc->getModel()->getCenter(px, py, pz);
854 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
857 okStatusMessage = true;
858 updateStatusBar(desc->getStatusText());
859 if (type == GBLACKBOX)
861 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
862 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
867 if ( ( _bugTextActor_text==desc->getStatusText() ) || (_bugTextActor_status==0) )
869 _bugTextActor_status = 1;
870 okPortMessage = true;
872 _textActor->SetScale(0.1);
873 std::string tmp = desc->getStatusText()+"\n";
874 _textActor->SetInput( tmp.c_str() );
875 _textActor->SetPosition(px - 25, py + 1, pz + 2);
876 _textActor->Modified();
880 _fillObjectActor->SetScale(1);
881 _fillObjectActor->GetProperty()->SetOpacity(0.50);
882 _fillObjectActor->SetPosition(px, py, 1);
883 _aPolygonMapper->Modified();
885 _bugTextActor_status = 2;
886 } // _bugTextActor_tex
887 _bugTextActor_text = desc->getStatusText();
891 } // for controllers it
893 if (okStatusMessage == false)
898 if ((okPortMessage == false) || (_bugTextActor_status== 2 ) )
900 _bugTextActor_status = 0;
901 _textActor->SetScale(0.0001);
902 _textActor->SetInput("a\n");
903 _textActor->Modified();
904 _fillObjectActor->SetScale(0.0001);
909 //=========================================================================
911 bool wxVtkSceneManager::OnLeftButtonDown()
913 if (_worldState == INIT_CREATION_CONTOUR)
915 bool isOverPort = false;
916 std::map<int, GObjectController*>::iterator it;
917 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
919 GObjectController *desc = it->second;
920 if (desc->getGObjectType() == GPORT)
922 GPortModel *portmod = (GPortModel*) desc->getModel();
923 vtkGObjectView *portView = desc->getView();
924 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
929 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
931 portView->setState( HIGHLIGHTED);
938 if (isOverPort == false)
941 UnSelectBlackBoxes();
945 } else { //_worldState
947 _worldState = DRAG_OBJECTS;
948 _startDragging = true;
950 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
951 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
952 ctrlkey = ctrlkey + shiftkey;
954 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
957 int state = cont->getView()->getState();
958 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
959 UnSelectBlackBoxes();
962 UnSelectBlackBoxes(); // EED 12/07/2012
964 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
965 int id = _selectedObjects[i];
966 GObjectController *cont = _controllers[id];
967 cont->getView()->setState(DRAG);
968 cont->getModel()->notifyObservers(_idManager);
970 } // if _selectedObjects.size
976 //=========================================================================
978 bool wxVtkSceneManager::OnLeftButtonUp()
980 if (_worldState == DRAG_OBJECTS) {
981 _worldState = NOTHING_HAPPENS;
983 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
984 int id = _selectedObjects[i];
985 GObjectController* cont = _controllers[id];
986 cont->getView()->setState(SELECTED);
987 cont->getModel()->notifyObservers(_idManager);
993 //=========================================================================
994 void wxVtkSceneManager::CancelConnection()
996 if (_worldState == INIT_CREATION_CONTOUR)
998 _worldState = NOTHING_HAPPENS;
999 //int lastId = _controllers.size()-1;
1001 GConnectorController *connector =
1002 (GConnectorController*) _controllers[_idConnectionInCreation];
1003 connector->removeFromScene();
1004 unregisterController(connector);
1005 _controllers.erase(_idConnectionInCreation);
1007 std::map<int, GObjectController*>::iterator it;
1008 for (it = _controllers.begin(); it != _controllers.end(); ++it)
1010 GObjectController *desc = it->second;
1011 desc->SetActive(true);
1012 desc->getView()->setState(NOTHING_HAPPENS);
1013 desc->getModel()->notifyObservers(_idManager);
1018 //=========================================================================
1020 bool wxVtkSceneManager::OnRightButtonUp()
1022 if (_worldState == INIT_CREATION_CONTOUR)
1026 UnSelectBlackBoxes();
1032 bool wxVtkSceneManager::OnMiddleButtonDown() {
1035 this->_vtkInteractorStyleBaseView->StartPan();
1040 bool wxVtkSceneManager::OnMiddleButtonUp() {
1043 this->_vtkInteractorStyleBaseView->EndPan();
1050 //=========================================================================
1052 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1053 GObjectController *result = NULL;
1055 wxVTKRenderWindowInteractor *wxVTKiren;
1057 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1058 wxVTKiren->GetEventPosition(X, Y);
1060 std::map<int, GObjectController*>::iterator it;
1062 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1063 GObjectController *cont = it->second;
1064 int type = cont->getGObjectType();
1066 if (cont->getView()->isPointInside(X, Y) == true) {
1067 if (type == GBLACKBOX) {
1070 } // if isPointInside
1075 //=========================================================================
1076 void wxVtkSceneManager::UnSelectBlackBoxes() {
1077 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1078 int id = _selectedObjects[i];
1079 GObjectController* control = _controllers[id];
1080 control->getView()->setState(NOTHING_HAPPENS);
1081 control->getModel()->notifyObservers(_idManager);
1082 }// for _selectedObjects
1083 _selectedObjects.clear();
1086 //=========================================================================
1087 bool wxVtkSceneManager::OnLeftDClick() {
1088 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1090 UnSelectBlackBoxes();
1091 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1097 wxVTKRenderWindowInteractor *wxVTKiren;
1098 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1099 wxVTKiren->GetEventPosition(X,Y);
1101 std::map<int, GObjectController*>::iterator it;
1103 bool clickOnObject = false;
1105 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1107 GObjectController *cont = it->second;
1108 int type = cont->getGObjectType();
1110 if(cont->getView()->isPointInside(X,Y))
1114 for (int i=0; i< (int)_selectedObjects.size(); i++)
1116 int id = _selectedObjects[i];
1117 GObjectController* control = _controllers[id];
1118 control->getView()->setState(NOTHING_HAPPENS);
1120 _selectedObjects.clear();
1122 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1123 _parent->editBlackBox(bbmodel);
1125 clickOnObject = true;
1129 if(clickOnObject==false)
1131 //_parent->editDiagramParameters(this);
1137 //=========================================================================
1139 bool wxVtkSceneManager::OnChar()
1143 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1144 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1146 // KeyCode 127 : Delete Key
1147 // KeyCode 8 : Backspace Key
1150 if (keyCode == 8 || keyCode == 127 || keyCode == 27)
1152 if (_worldState == INIT_CREATION_CONTOUR)
1155 UnSelectBlackBoxes();
1160 if (keyCode == 8 || keyCode == 127)
1163 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1165 int id = _selectedObjects[i];
1166 std::map<int, GObjectController*>::iterator it;
1167 it = _controllers.find(id);
1168 if (it != _controllers.end())
1170 oktmp = deleteObject(id);
1173 }// for selected objects
1174 if (ok) _selectedObjects.clear();
1175 _parent->saveTempandUpdate("delete object");
1180 if((keyCode==0) && (ctrlkey==1)) {
1185 if(_selectedObjects.size()){
1186 std::cout<<"objects to copy :";
1187 for(int i=0;i<_selectedObjects.size();i++)
1189 std::cout<<_selectedObjects.at(i)<<" ";
1191 DuplicateObjects(getSelectedObjects());
1193 std::cout<<"No objects to copy\n";
1194 } // _selectedObjects.size
1200 //=========================================================================
1202 void wxVtkSceneManager::AddControlerToBeRemove(
1203 std::vector<int> *controllersToRemove, int id) {
1207 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1208 if (id == (*controllersToRemove)[i]) {
1214 controllersToRemove->push_back(id);
1219 //=========================================================================
1221 bool wxVtkSceneManager::deleteObject(int id)
1224 GObjectController *control = _controllers[id];
1225 std::vector<int> controllersToRemove;
1226 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1227 == GCOMPLEXINPUTPORT || control->getGObjectType()
1228 == GCOMPLEXOUTPUTPORT) {
1229 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1230 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1232 bool boxConnected = false;
1234 // Add box input controllers to be removed
1235 for (int i = 0; i < (int) inputs.size(); i++) {
1236 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1237 if (inputs[i]->isConnected()) {
1238 boxConnected = true;
1242 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1244 // Add box output controllers to be removed
1245 for (int i = 0; i < (int) outputs.size(); i++) {
1246 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1247 if (outputs[i]->isConnected()) {
1248 boxConnected = true;
1252 // Add connection controllers to be removed
1253 std::map<int, GObjectController*>::iterator it;
1254 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1255 GObjectController *cont = it->second;
1256 int type = cont->getGObjectType();
1257 if (type == GCONNECTOR) {
1258 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1259 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1261 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1263 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1265 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1270 // Add box controller to be removed
1271 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1272 } else if (control->getGObjectType() == GCONNECTOR) {
1273 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1274 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1276 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1277 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1279 gconnectorcontroler->getManualContourController()->OnChar();
1284 std::map<int, GObjectController*>::iterator it;
1286 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1287 int key = controllersToRemove[i];
1288 it = _controllers.find(key);
1289 GObjectController *cont = _controllers[key];
1291 cont->removeFromScene();
1292 unregisterController((InteractorStyleMaracas*) cont);
1293 _controllers.erase(it);
1301 //=========================================================================
1303 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1304 std::string boxName) {
1305 _parent->displayBlackBoxInfo(packageName, boxName);
1308 //=========================================================================
1310 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1311 _parent->updateStatusBar(textStatus);
1314 //=========================================================================
1315 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1316 std::string result = "";
1317 if (withLineNumber == true) {
1319 stringstream StrStream;
1321 std::string strValue = StrStream.str();
1324 } else if (value < 100) {
1328 result += strValue + ": ";
1332 //=========================================================================
1334 bool wxVtkSceneManager::MakeBoxExecutable() {
1335 std::map<int, GObjectController*> selected = getSelectedObjects();
1336 if( selected.empty() )
1339 std::map<int, GObjectController*>::iterator it;
1340 for (it = selected.begin(); it != selected.end(); ++it) {
1341 GObjectController* lastSelected = it->second;
1343 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1344 GBlackBoxModel *bbmodel =
1345 (GBlackBoxModel*) lastSelected->getModel();
1346 view->setState(HIGHLIGHTED);
1347 if (bbmodel->isExecutable()) {
1348 bbmodel->setExecutable(false);
1350 bbmodel->setExecutable(true);
1352 bbmodel->notifyObservers(lastSelected->getId());
1360 //=========================================================================
1362 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1363 std::cout << "wxVtkSceneManager::getDiagramBBS" << std::endl;
1364 bool existsExec = false;
1366 std::vector<std::string> packages;
1367 std::vector<int> boxes;
1368 std::vector<int> connections;
1369 std::vector<int> execBoxes;
1371 std::map<int, GObjectController*>::iterator it;
1373 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1374 GObjectController *desc = it->second;
1375 int type = desc->getGObjectType();
1377 if (type == GBLACKBOX) {
1378 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1380 std::string pkg = mod->getBBTKPackage();
1381 bool existsPkg = false;
1382 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1383 if (packages[t] == pkg) {
1388 packages.push_back(pkg);
1391 boxes.push_back(it->first);
1392 if (mod->isExecutable()) {
1393 execBoxes.push_back(it->first);
1396 } else if (type == GCONNECTOR) {
1397 connections.push_back(it->first);
1402 std::string script = "";
1403 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1404 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1405 script += LineNumber(wln, lnNmbr) + "\n";
1407 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1408 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1410 for (i = 0; i < (int) packages.size(); i++) {
1411 script += LineNumber(wln, lnNmbr);
1412 script += "include ";
1413 script += packages[i];
1417 script += LineNumber(wln, lnNmbr);
1422 script += LineNumber(wln, lnNmbr);
1423 script += "author \"";
1427 script += LineNumber(wln, lnNmbr);
1428 script += "description \"";
1429 script += _Description;
1432 script += LineNumber(wln, lnNmbr);
1433 script += "category \"";
1434 script += _Category;
1437 script += LineNumber(wln, lnNmbr);
1440 // script+="include std\n"; // JPR
1442 for (i = 0; i < (int) boxes.size(); i++) {
1443 script += LineNumber(wln, lnNmbr);
1446 GObjectController *control = _controllers[id];
1447 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1449 script += model->getBBTKPackage()+":";
1450 script += model->getBBTKType();
1452 script += model->getBBTKName();
1455 std::vector<GPortModel*> inputs = model->getInputPorts();
1456 for (int j = 0; j < (int) inputs.size(); j++) {
1457 GPortModel* inputPort = inputs[j];
1458 if (inputPort->isValueSet()) {
1459 script += LineNumber(wln, lnNmbr);
1461 script += model->getBBTKName();
1463 script += inputPort->getBBTKName();
1465 script += inputPort->getValue();
1470 script += LineNumber(wln, lnNmbr);
1475 script += LineNumber(wln, lnNmbr);
1479 std::string complexInputs="";
1481 for (i = 0; i < (int) connections.size(); i++) {
1482 //script += LineNumber(wln, lnNmbr);
1483 //script += "connect ";
1484 int id = connections[i];
1485 GObjectController *control = _controllers[id];
1486 GConnectorModel *model = (GConnectorModel*) control->getModel();
1490 GPortModel *start = model->getStartPort();
1491 GBoxModel *startBox = start->getParentBox();
1493 GPortModel *end = model->getEndPort();
1494 GBoxModel *endBox = end->getParentBox();
1496 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1498 complexInputs += "input ";
1499 complexInputs += startBox->getBBTKName();
1501 complexInputs += " ";
1502 complexInputs += endBox->getBBTKName();
1503 complexInputs += ".";
1504 complexInputs += end->getBBTKName();
1506 complexInputs += " ";
1507 complexInputs += "\" \"";
1509 complexInputs += "\n";
1513 script += LineNumber(wln, lnNmbr);
1514 script += "connect ";
1515 script += startBox->getBBTKName();
1517 script += start->getBBTKName();
1521 //End Connection info
1522 script += endBox->getBBTKName();
1524 script += end->getBBTKName();
1529 script += LineNumber(wln, lnNmbr);
1533 script += LineNumber(wln, lnNmbr);
1536 script += LineNumber(wln, lnNmbr);
1539 script += LineNumber(wln, lnNmbr);
1540 script += "# Complex input ports\n";
1541 script += complexInputs;
1543 if((_MessageKind!=" ")&&(_MessageLevel!=" ")){
1544 script += LineNumber(wln, lnNmbr);
1545 script += "message ";
1546 script += _MessageKind;
1548 script += _MessageLevel;
1552 for (i = 0; i < (int) execBoxes.size(); i++) {
1553 script += LineNumber(wln, lnNmbr);
1555 int id = execBoxes[i];
1556 GObjectController *control = _controllers[id];
1557 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1559 script += model->getBBTKName();
1568 //=========================================================================
1570 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1571 std::cout<<"wxVtkSceneManager::saveComplexBoxBBS"<<std::endl;
1572 std::vector<std::string> packages;
1573 std::vector<int> boxes;
1574 std::vector<int> connections;
1575 std::vector<int> execBoxes;
1577 std::map<int, GObjectController*>::iterator it;
1579 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1580 GObjectController *desc = it->second;
1581 int type = desc->getGObjectType();
1583 if (type == GBLACKBOX) {
1584 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1586 std::string pkg = mod->getBBTKPackage();
1587 bool existsPkg = false;
1588 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1589 if (packages[t] == pkg) {
1594 packages.push_back(pkg);
1597 boxes.push_back(it->first);
1598 if (mod->isExecutable()) {
1599 execBoxes.push_back(it->first);
1601 } else if (type == GCONNECTOR) {
1602 connections.push_back(it->first);
1606 std::string script = "";
1608 script += "include std\n"; // EED
1609 script += "include itkvtk\n"; // EED
1611 for (i = 0; i < (int) packages.size(); i++) {
1612 script += "include ";
1613 script += packages[i];
1618 // Definition of a complex box
1619 script += "define ";
1620 script += _cbName + " " + _cbPackageName;
1624 script += "author \"";
1628 script += "description \"";
1629 script += _Description;
1633 script += "category \"";
1634 script += _Category;
1639 for (i = 0; i < (int) boxes.size(); i++) {
1642 GObjectController *control = _controllers[id];
1643 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1645 script += model->getBBTKPackage()+":";
1646 script += model->getBBTKType();
1648 script += model->getBBTKName();
1651 std::vector<GPortModel*> inputs = model->getInputPorts();
1652 for (int j = 0; j < (int) inputs.size(); j++) {
1653 GPortModel* inputPort = inputs[j];
1654 if (inputPort->isValueSet()) {
1656 script += model->getBBTKName();
1658 script += inputPort->getBBTKName();
1660 script += inputPort->getValue();
1668 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1670 std::string complexInputs = "";
1671 std::string complexOutputs = "";
1674 for (i = 0; i < (int) connections.size(); i++) {
1675 int id = connections[i];
1676 GObjectController *control = _controllers[id];
1677 GConnectorModel *model = (GConnectorModel*) control->getModel();
1680 GPortModel *start = model->getStartPort();
1681 GBoxModel *startBox = start->getParentBox();
1683 GPortModel *end = model->getEndPort();
1684 GBoxModel *endBox = end->getParentBox();
1686 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1687 complexInputs += "input ";
1688 complexInputs += startBox->getBBTKName();
1690 complexInputs += " ";
1691 complexInputs += endBox->getBBTKName();
1692 complexInputs += ".";
1693 complexInputs += end->getBBTKName();
1695 complexInputs += " ";
1696 complexInputs += "\" \"";
1698 complexInputs += "\n";
1699 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1700 complexOutputs += "output ";
1701 complexOutputs += endBox->getBBTKName();
1703 complexOutputs += " ";
1704 complexOutputs += startBox->getBBTKName();
1705 complexOutputs += ".";
1706 complexOutputs += start->getBBTKName();
1708 complexOutputs += " ";
1709 complexOutputs += "\" \"";
1711 complexOutputs += "\n";
1713 script += "connect ";
1714 script += startBox->getBBTKName();
1716 script += start->getBBTKName();
1720 //End Connection info
1721 script += endBox->getBBTKName();
1723 script += end->getBBTKName();
1730 script += "# Complex input ports\n";
1731 script += complexInputs;
1734 script += "# Complex output ports\n";
1735 script += complexOutputs;
1739 script += "message ";
1740 script += _MessageKind;
1742 script += _MessageLevel;
1745 for (i = 0; i < (int) execBoxes.size(); i++) {
1747 int id = execBoxes[i];
1748 GObjectController *control = _controllers[id];
1749 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1751 script += model->getBBTKName();
1756 script += "endefine";
1762 //=========================================================================
1764 void wxVtkSceneManager::deleteAllBoxes() {
1765 std::map<int, GObjectController*>::iterator it;
1766 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1767 GObjectController *cont = it->second;
1768 cont->removeFromScene();
1769 unregisterController((InteractorStyleMaracas*) cont);
1771 _selectedObjects.clear();
1772 _controllers.clear();
1775 //=========================================================================
1778 void wxVtkSceneManager::refresh() {
1779 _baseView->Refresh();
1781 //=========================================================================
1783 void wxVtkSceneManager::refreshScene() {
1784 _baseView->RefreshView();
1787 //=========================================================================
1789 void wxVtkSceneManager::centerView() {
1791 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1792 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1793 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1794 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1797 //=========================================================================
1799 void wxVtkSceneManager::saveDiagram(std::string &content) {
1802 content += "CATEGORY:";
1803 content += GetCategory();
1806 content += "DESCRIPTION:";
1807 content += GetDescription();
1810 content += "AUTHOR:";
1811 content += GetAuthor();
1814 //Print info IF COMPLEX BOX
1815 content += "COMPLEXBOX:";
1816 if (_isComplexBox) {
1817 content += "TRUE\n";
1819 content += "COMPLEXBOXNAME:";
1820 content += GetCbName();
1823 content += "PACKAGENAME:";
1824 content += GetCbPackageName();
1827 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1828 * External inputs are possible for applications and complex boxes
1829 //Print info complex input ports
1830 std::vector<int> inputs = getComplexInputPorts();
1831 int insize = inputs.size();
1832 content += "COMPLEXINPUTS:";
1833 sprintf(buffer, "%d", insize);
1837 for (int i = 0; i < insize; i++) {
1839 GObjectController *cont = _controllers[id];
1840 cont->getModel()->save(content);
1844 //Print info complex output ports
1845 std::vector<int> outputs = getComplexOutputPorts();
1846 int outsize = outputs.size();
1847 content += "COMPLEXOUTPUTS:";
1848 sprintf(buffer, "%d", outsize);
1852 for (int i = 0; i < outsize; i++) {
1853 int id = outputs[i];
1854 GObjectController *cont = _controllers[id];
1855 cont->getModel()->save(content);
1859 content += "FALSE\n";
1862 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1863 // External inputs are possible for applications and complex boxes
1864 std::vector<int> inputs = getComplexInputPorts();
1865 int insize = inputs.size();
1866 content += "COMPLEXINPUTS:";
1867 sprintf(buffer, "%d", insize);
1871 for (int i = 0; i < insize; i++) {
1873 GObjectController *cont = _controllers[id];
1874 cont->getModel()->save(content);
1878 std::vector<int> boxes = getBlackBoxes();
1879 int bsize = boxes.size();
1880 content += "BOXES:";
1881 sprintf(buffer, "%d", bsize);
1885 for (int i = 0; i < bsize; i++) {
1887 // std::cout<<"id "<<id<<std::endl;//CFT
1888 GObjectController *cont = _controllers[id];
1889 // std::cout<<"nombre: "<<cont->getStatusText()<<std::endl;//CFT
1890 // std::cout<<"tipo: "<<cont->getModel()->getBBTKType()<<std::endl;//CFT
1891 // //boxesDiagram[i] = cont->getModel()->getBBTKType();//CFT
1892 // std::cout<<"nname: "<<cont->getModel()->getBBTKName()<<std::endl;//CFT
1893 // std::cout<<"categorie: "<<GetCategory()<<std::endl;//CFT
1894 // std::cout<<"type: "<<cont->getModel()->getGObjectType()<<std::endl;//CFT
1895 cont->getModel()->save(content);
1899 std::vector<int> connections = getConnections();
1900 int csize = connections.size();
1901 content += "CONNECTIONS:";
1902 sprintf(buffer, "%d", csize);
1906 for (int i = 0; i < csize; i++) {
1907 int id = connections[i];
1908 GObjectController *cont = _controllers[id];
1909 cont->getModel()->save(content);
1914 //=========================================================================
1915 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1917 getline(inputStream, line,'\n');
1918 int size = line.length();
1921 if ( line[ size-1 ]==13 )
1923 line.erase(size-1,1);
1928 //=========================================================================
1929 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1933 std::string version = "<void>";
1934 std::string line = "";
1935 char delims[] = ":";
1936 char *result = NULL;
1937 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1939 getCleanLine(inputStream, line);
1942 while (!inputStream.eof()) {
1943 if (line == "" || line[0] == '#') {
1945 getCleanLine(inputStream, line);
1947 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1948 version = line.substr(18, 3);
1950 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1951 version = line.substr(18, 3);
1953 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1954 version = line.substr(18, 3);
1956 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1957 version = line.substr(18, 3);
1959 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1960 version = line.substr(18, 3);
1962 } else if (line == "APP_START") {
1971 if ((version != "1.0") && (version != "1.1")) {
1972 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1973 char categoryTmp[30];
1974 strcpy(categoryTmp, line.c_str());
1975 result = strtok(categoryTmp, delims);
1976 result = strtok(NULL, delims);
1977 SetCategory(result);
1979 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1980 char descriptionTmp[1024];
1981 strcpy(descriptionTmp, line.c_str());
1982 result = strtok(descriptionTmp, delims);
1983 result = strtok(NULL, delims);
1984 SetDescription(result);
1986 getCleanLine(inputStream, line);//AUTHOR:<author>
1987 char authorTmp[255];
1988 strcpy(authorTmp, line.c_str());
1989 result = strtok(authorTmp, delims);
1990 result = strtok(NULL, delims);
1995 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1996 char complexTmp[30];
1997 strcpy(complexTmp, line.c_str());
1998 result = strtok(complexTmp, delims);
1999 result = strtok(NULL, delims);
2000 std::string isComplexBox(result);
2002 if (isComplexBox == "TRUE") {
2003 _isComplexBox = true;
2005 if ((version != "1.0") && (version != "1.1")) {
2006 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
2007 char complexboxnameTmp[255];
2008 strcpy(complexboxnameTmp, line.c_str());
2009 result = strtok(complexboxnameTmp, delims);
2010 result = strtok(NULL, delims);
2013 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
2014 char packagenameTmp[255];
2015 strcpy(packagenameTmp, line.c_str());
2016 result = strtok(packagenameTmp, delims);
2017 result = strtok(NULL, delims);
2018 SetCbPackageName(result);
2023 //-----------------------
2024 //- COMPLEX INPUT PORTS
2025 //-----------------------
2026 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2028 strcpy(inputs, line.c_str());
2029 result = strtok(inputs, delims);
2030 result = strtok(NULL, delims);
2033 std::istringstream inps(result);
2036 for (int i = 0; i < numInputs; i++) {
2038 getCleanLine(inputStream, line);//COMPLEX_PORT
2039 getCleanLine(inputStream, line);//name
2040 std::string inputPortName(line);
2043 getCleanLine(inputStream, line);//xInic:yInic:zInic
2045 strcpy(coord, line.c_str());
2046 result = strtok(coord, delims);//xInic
2047 std::string xInic(result);
2048 result = strtok(NULL, delims);//yInic
2049 std::string yInic(result);
2050 result = strtok(NULL, delims);//zInic
2051 std::string zInic(result);
2053 double xIn, yIn, zIn;
2054 std::istringstream xSt(xInic);
2056 std::istringstream ySt(yInic);
2058 std::istringstream zSt(zInic);
2063 if (zIn==900) zIn=GPOSITION_Z;
2066 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2068 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2070 } // for input complex box
2075 //-----------------------
2076 //- COMPLEX OUTPUT PORTS
2077 //-----------------------
2079 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2081 strcpy(outputs, line.c_str());
2082 result = strtok(outputs, delims);
2083 result = strtok(NULL, delims);
2086 std::istringstream outps(result);
2087 outps >> numOutputs;
2089 for (int i = 0; i < numOutputs; i++) {
2091 getCleanLine(inputStream, line);//COMPLEX_PORT
2092 getCleanLine(inputStream, line);//name
2093 std::string outputPortName(line);
2096 getCleanLine(inputStream, line);//xInic:yInic:zInic
2098 strcpy(coord, line.c_str());
2099 result = strtok(coord, delims);//xInic
2100 std::string xInic(result);
2101 result = strtok(NULL, delims);//yInic
2102 std::string yInic(result);
2103 result = strtok(NULL, delims);//zInic
2104 std::string zInic(result);
2106 double xIn, yIn, zIn;
2107 std::istringstream xSt(xInic);
2109 std::istringstream ySt(yInic);
2111 std::istringstream zSt(zInic);
2116 if (zIn==900) zIn=GPOSITION_Z;
2119 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2121 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2123 } // for output complex box
2127 // RaC2012 2nd Hackfest
2128 if(version >= "1.4")
2130 //-----------------------
2131 //- EXTERNAL INPUT PORTS
2132 //-----------------------
2133 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2135 strcpy(inputs, line.c_str());
2136 result = strtok(inputs, delims);
2137 result = strtok(NULL, delims);
2140 std::istringstream inps(result);
2143 for (int i = 0; i < numInputs; i++) {
2145 getCleanLine(inputStream, line);//COMPLEX_PORT
2146 getCleanLine(inputStream, line);//name
2147 std::string inputPortName(line);
2150 getCleanLine(inputStream, line);//xInic:yInic:zInic
2152 strcpy(coord, line.c_str());
2153 result = strtok(coord, delims);//xInic
2154 std::string xInic(result);
2155 result = strtok(NULL, delims);//yInic
2156 std::string yInic(result);
2157 result = strtok(NULL, delims);//zInic
2158 std::string zInic(result);
2160 double xIn, yIn, zIn;
2161 std::istringstream xSt(xInic);
2163 std::istringstream ySt(yInic);
2165 std::istringstream zSt(zInic);
2170 if (zIn==900) zIn=GPOSITION_Z;
2173 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2174 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2176 } // for external input
2181 getCleanLine(inputStream, line);//BOXES:num
2183 strcpy(boxes, line.c_str());
2184 result = strtok(boxes, delims);
2185 result = strtok(NULL, delims);
2188 std::istringstream is(result);
2191 for (int i = 0; i < numBoxes; i++)
2194 getCleanLine(inputStream, line);//BOX
2195 getCleanLine(inputStream, line);//package:type:name
2197 strcpy(box, line.c_str());
2198 result = strtok(box, delims);//package
2199 std::string package(result);
2200 result = strtok(NULL, delims);//type
2201 std::string type(result);
2202 result = strtok(NULL, delims);//name
2203 std::string name(result);
2206 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2208 strcpy(exec, line.c_str());
2209 result = strtok(exec, delims);//ISEXEC
2210 result = strtok(NULL, delims);//TRUE|FALSE
2211 std::string isExec(result);
2214 getCleanLine(inputStream, line);//xInic:yInic:zInic
2216 strcpy(coord, line.c_str());
2217 result = strtok(coord, delims);//xInic
2218 std::string xInic(result);
2219 result = strtok(NULL, delims);//yInic
2220 std::string yInic(result);
2221 result = strtok(NULL, delims);//zInic
2222 std::string zInic(result);
2224 double xIn, yIn, zIn;
2225 std::istringstream xSt(xInic);
2227 std::istringstream ySt(yInic);
2229 std::istringstream zSt(zInic);
2235 if (zIn==900) zIn=GPOSITION_Z;
2240 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2241 strcpy(coord, line.c_str());
2242 result = strtok(coord, delims);//xEnd
2243 std::string xEnd(result);
2244 result = strtok(NULL, delims);//yEnd
2245 std::string yEnd(result);
2246 result = strtok(NULL, delims);//zEnd
2247 std::string zEnd(result);
2249 double xEn, yEn, zEn;
2250 std::istringstream xEt(xEnd);
2252 std::istringstream yEt(yEnd);
2254 std::istringstream zEt(zEnd);
2259 if (zEn==900) zEn=GPOSITION_Z;
2263 bool boxExecutable = false;
2264 if (isExec == "TRUE")
2266 boxExecutable = true;
2269 int idBox = createGBlackBox(xIn, yIn, package, type);
2270 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2272 GObjectController *cont = _controllers[idBox];
2273 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2276 getCleanLine(inputStream, line);//PORT o FIN_BOX
2277 std::string port = line.substr(0, 4);
2278 while (port == "PORT")
2280 getCleanLine(inputStream, line);//name:value
2281 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2283 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2286 strcpy(poort, line.c_str());
2287 result = strtok(poort, delims);//name
2288 std::string name(result);
2290 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2291 result = strtok(NULL, delims);//value
2292 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2294 std::string tmpString=" ";
2295 tmpString[0]=34; // character "
2296 strcat(result,tmpString.c_str());
2298 std::string value(result);
2300 bbmod->setValueToInput(name, value);
2302 getCleanLine(inputStream, line);//PORT o FIN_BOX
2303 port = line.substr(0, 4);
2306 //EED bbmod->notifyObservers(_idManager);
2311 getCleanLine(inputStream, line);//CONNECTIONS:num
2313 strcpy(conns, line.c_str());
2314 result = strtok(conns, delims);
2315 result = strtok(NULL, delims);
2318 std::istringstream isCons(result);
2322 for (int i = 0; i < numConns; i++)
2325 getCleanLine(inputStream, line);//CONNECTION
2326 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2329 strcpy(connec, line.c_str());
2330 result = strtok(connec, delims);
2331 std::string nameStartBox(result);
2332 result = strtok(NULL, delims);
2333 std::string nameStartPort(result);
2334 result = strtok(NULL, delims);
2335 std::string nameEndBox(result);
2336 result = strtok(NULL, delims);
2337 std::string nameEndPort(result);
2339 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2341 if (version != "1.0") {
2342 //Readding control points of the manualContour
2343 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2344 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2345 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2346 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2347 strcpy(conns, line.c_str());
2348 result = strtok(conns, delims);
2349 result = strtok(NULL, delims);
2351 int numberOfControlPoints;
2352 std::istringstream isCons(result);
2353 isCons >> numberOfControlPoints;
2355 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2356 getCleanLine(inputStream, line); //XX:YY:ZZ
2358 strcpy(connec, line.c_str());
2361 result = strtok(connec, delims);
2362 std::istringstream isPointX(result);
2364 result = strtok(NULL, delims);
2365 std::istringstream isPointY(result);
2367 result = strtok(NULL, delims);
2368 std::istringstream isPointZ(result);
2373 if (pz==900) pz=GPOSITION_Z;
2376 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2377 conView->getManualContourView()->AddPoint();
2383 //=========================================================================
2386 //=========================================================================
2387 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2388 std::string portName, double xIn, double yIn, double zIn)
2391 if (inputoutput == true) {
2392 idPort = createGComplexBoxInputPort(portName);
2394 idPort = createGComplexBoxOutputPort(portName);
2396 GObjectController *cont = _controllers[idPort];
2397 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2398 cbmod->setInicPoint(xIn, yIn, zIn);
2399 cbmod->notifyObservers(_idManager);
2401 //=========================================================================
2404 //=========================================================================
2405 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2410 GBoxModel *boxModel = NULL;
2411 std::vector<int> lstB = getBlackBoxes();
2412 for (j = 0; j < (int) lstB.size(); j++) {
2414 bMod = (GBoxModel*) _controllers[idB]->getModel();
2415 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2423 if (boxModel == NULL) {
2424 std::vector<int> lstInputs = getComplexInputPorts();
2425 for (j = 0; j < (int) lstInputs.size(); j++) {
2427 bMod = (GBoxModel*) _controllers[idB]->getModel();
2428 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2436 std::vector<int> lstOutputs = getComplexOutputPorts();
2437 for (j = 0; j < (int) lstOutputs.size(); j++) {
2438 int idB = lstOutputs[j];
2439 bMod = (GBoxModel*) _controllers[idB]->getModel();
2440 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2452 //=========================================================================
2455 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2456 std::string nameStartPort, std::string nameEndBox,
2457 std::string nameEndPort) {
2459 GBoxModel *boxModel;
2460 GPortModel *startP = NULL;
2461 GPortModel *endP = NULL;
2463 boxModel = findGBox(nameStartBox);
2464 if(boxModel == NULL)
2466 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2468 if (boxModel != NULL) {
2469 startP = boxModel->getOutputPort(nameStartPort);
2471 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() );
2475 boxModel = findGBox(nameEndBox);
2476 if(boxModel == NULL)
2478 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2480 if (boxModel != NULL) {
2481 endP = boxModel->getInputPort(nameEndPort);
2483 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());
2488 int idCon = createGConnector(startP);
2490 _worldState = NOTHING_HAPPENS;
2491 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2493 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2494 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2495 tempp->endContourCreation();
2496 conMod->setEndPort(endP);
2497 conView->updateStartEndPoints();
2501 //=========================================================================
2503 bool wxVtkSceneManager::boxExist(std::string boxname) {
2505 std::map<int, GObjectController*>::iterator it;
2506 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2507 GObjectController *cont = it->second;
2508 if (cont->getModel()->getBBTKName() == boxname) {
2515 //=========================================================================
2517 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2518 std::vector<int> vect;
2519 std::map<int, GObjectController*>::iterator it;
2520 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2521 GObjectController *cont = it->second;
2522 if (cont->getGObjectType() == GBLACKBOX) {
2523 vect.push_back(cont->getId());
2529 //=========================================================================
2531 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2532 std::vector<int> vect;
2533 std::map<int, GObjectController*>::iterator it;
2534 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2535 GObjectController *cont = it->second;
2536 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2537 vect.push_back(cont->getId());
2543 //=========================================================================
2545 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2546 std::vector<int> vect;
2547 std::map<int, GObjectController*>::iterator it;
2548 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2549 GObjectController *cont = it->second;
2550 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2551 vect.push_back(cont->getId());
2557 //=========================================================================
2559 std::vector<int> wxVtkSceneManager::getConnections() {
2560 std::vector<int> vect;
2561 std::map<int, GObjectController*>::iterator it;
2562 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2563 GObjectController *cont = it->second;
2564 if (cont->getGObjectType() == GCONNECTOR) {
2565 vect.push_back(cont->getId());
2571 //=========================================================================
2573 bool wxVtkSceneManager::isComplexBox() {
2574 return _isComplexBox;
2577 //=========================================================================
2579 void wxVtkSceneManager::setComplexBox(bool val) {
2580 _isComplexBox = val;
2583 //=========================================================================
2585 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2586 //Register the controller of the new object
2587 registerController((InteractorStyleMaracas*) objController);
2588 //Add the object to the objects list
2589 int newId = _contLastId;//_controllers.size();
2590 objController->setId(newId);
2591 _controllers[newId] = objController;
2592 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2597 //=========================================================================
2599 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2601 std::map<int, int> oldIdNewIdBoxes;
2602 std::vector<int> connections;
2604 std::vector<int> newBoxesID;
2606 std::map<int, GObjectController*>::iterator it;
2607 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2608 GObjectController *cont = it->second;
2609 int type = cont->getGObjectType();
2611 if (type == GBLACKBOX) {
2613 double xInic, yInic, zInic;
2614 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2615 copyBox->getInicPoint(xInic, yInic, zInic);
2616 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2617 copyBox->getBBTKType());
2619 int idcB = copyBox->getObjectId();
2620 oldIdNewIdBoxes[idcB] = idBox;
2621 cont = _controllers[idBox];
2622 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2623 newbox->setInicPoint(xInic, yInic, zInic);
2624 int num = newbox->getNumInputPorts();
2625 for (int j = 0; j < num; j++) {
2626 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2628 newbox->move(xInic + 20, yInic + 20, zInic);
2629 newbox->notifyObservers(_idManager);
2630 newBoxesID.push_back(newbox->getObjectId());
2632 } else if (type == GCONNECTOR) {
2633 int idCon = cont->getId();
2634 connections.push_back(idCon);
2639 for (int i = 0; i < (int) connections.size(); i++) {
2640 int objId = connections[i];
2641 GObjectController *cont = objectsMap[objId];
2642 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2644 GPortModel* startPort = connectModel->getStartPort();
2645 int startPortIndex = startPort->getPosInBox();
2646 GPortModel* endPort = connectModel->getEndPort();
2647 int endPortIndex = endPort->getPosInBox();
2649 GBlackBoxModel* startPortParentBox =
2650 (GBlackBoxModel*) startPort->getParentBox();
2651 GBlackBoxModel* endPortParentBox =
2652 (GBlackBoxModel*) endPort->getParentBox();
2654 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2655 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2657 GBlackBoxModel* newStartBox =
2658 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2659 GBlackBoxModel* newEndBox =
2660 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2662 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2663 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2665 // Creates connection
2666 int idCon = createGConnector(newStartPort);
2667 GConnectorController *tempp =
2668 (GConnectorController*) _controllers[idCon];
2669 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2670 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2671 tempp->endContourCreation();
2672 conMod->setEndPort(newEndPort);
2673 conView->updateStartEndPoints();
2676 /// the new selected boxes are the duplicate ones
2678 UnSelectBlackBoxes();
2679 for (int i = 0; i < newBoxesID.size(); i++) {
2680 _selectedObjects.push_back(newBoxesID.at(i));
2683 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2684 int id = _selectedObjects[i];
2685 GObjectController* cont = _controllers[id];
2687 cont->getView()->setState(SELECTED);
2688 cont->getModel()->notifyObservers(_idManager);
2694 //=========================================================================
2696 int wxVtkSceneManager::getNumSelectedObjects() {
2697 return _selectedObjects.size();
2700 //=========================================================================
2702 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2703 std::map<int, GObjectController*> mapSelected;
2705 std::map<int, GObjectController*>::iterator it;
2706 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2707 GObjectController *cont = it->second;
2708 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2710 mapSelected[cont->getId()] = cont;
2714 std::map<int, GObjectController*>::iterator it2;
2715 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2716 GObjectController *cont = it2->second;
2717 if (cont->getGObjectType() == GCONNECTOR) {
2718 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2719 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2720 GBoxModel* startPortParentBox =
2721 cmod->getStartPort()->getParentBox();
2723 std::map<int, GObjectController*>::iterator iterOBJ1 =
2724 mapSelected.find(startPortParentBox->getObjectId());
2725 std::map<int, GObjectController*>::iterator iterOBJ2 =
2726 mapSelected.find(endPortParentBox->getObjectId());
2728 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2729 int ID = cont->getId();
2730 mapSelected[ID] = cont;
2737 //=========================================================================
2739 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2741 std::map<int, int> oldIdNewIdBoxes;
2742 std::vector<int> connections;
2744 std::map<int, GObjectController*>::iterator it;
2745 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2746 GObjectController *cont = it->second;
2747 int type = cont->getGObjectType();
2749 if (type == GBLACKBOX) {
2751 double xInic, yInic, zInic;
2752 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2753 copyBox->getInicPoint(xInic, yInic, zInic);
2754 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2756 int idcB = copyBox->getObjectId();
2757 oldIdNewIdBoxes[idcB] = idBox;
2758 cont = _controllers[idBox];
2759 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2760 newbox->setInicPoint(xInic, yInic, zInic);
2761 int num = newbox->getNumInputPorts();
2762 for (int j = 0; j < num; j++)
2764 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2766 newbox->notifyObservers(_idManager);
2767 } else if (type == GCONNECTOR) {
2768 int idCon = cont->getId();
2769 connections.push_back(idCon);
2774 for (int i = 0; i < (int) connections.size(); i++) {
2775 int objId = connections[i];
2776 GObjectController *cont = objectsMap[objId];
2777 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2779 GPortModel* startPort = connectModel->getStartPort();
2780 int startPortIndex = startPort->getPosInBox();
2781 GPortModel* endPort = connectModel->getEndPort();
2782 int endPortIndex = endPort->getPosInBox();
2784 GBlackBoxModel* startPortParentBox =
2785 (GBlackBoxModel*) startPort->getParentBox();
2786 GBlackBoxModel* endPortParentBox =
2787 (GBlackBoxModel*) endPort->getParentBox();
2789 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2790 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2792 GBlackBoxModel* newStartBox =
2793 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2794 GBlackBoxModel* newEndBox =
2795 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2797 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2798 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2800 // Creates connection
2801 int idCon = createGConnector(newStartPort);
2802 GConnectorController *tempp =
2803 (GConnectorController*) _controllers[idCon];
2804 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2805 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2806 tempp->endContourCreation();
2807 conMod->setEndPort(newEndPort);
2808 conView->updateStartEndPoints();
2811 std::map<int, int>::iterator itIds;
2812 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2813 int idOld = itIds->first;
2814 int idNew = itIds->second;
2816 GBlackBoxModel* oldBox =
2817 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2818 GBlackBoxModel* newBox =
2819 (GBlackBoxModel*) _controllers[idNew]->getModel();
2821 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2822 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2823 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2824 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2826 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2828 //EED int toCreate=-1;
2829 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2830 if (oldInputConnections[k] == newInputConnections[l]) {
2835 if (exist == false) {
2836 //Create complex input
2837 int posInBox = oldInputConnections[k];
2838 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2839 std::string inputPortName = inputPort->getBBTKName();
2840 int idInputPort = createGComplexBoxInputPort(inputPortName);
2841 GObjectController *cont = _controllers[idInputPort];
2842 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2843 double xIn, yIn, zIn;
2844 inputPort->getInicPoint(xIn, yIn, zIn);
2846 cbmod->setInicPoint(xIn, yIn, zIn);
2847 cbmod->notifyObservers(_idManager);
2849 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2851 // Creates connection
2852 int idCon = createGConnector(cbmod->getOutputPort(0));
2853 GConnectorController *tempp =
2854 (GConnectorController*) _controllers[idCon];
2855 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2856 vtkGConnectorView *conView =
2857 (vtkGConnectorView*) tempp->getView();
2858 tempp->endContourCreation();
2859 conMod->setEndPort(inputPortEnd);
2860 conView->updateStartEndPoints();
2866 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2868 //EED int toCreate=-1;
2869 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2870 if (oldOutputConnections[k] == newOutputConnections[l]) {
2875 if (exist == false) {
2876 //Create complex output
2877 int posInBox = oldOutputConnections[k];
2878 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2879 std::string outputPortName = outputPort->getBBTKName();
2880 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2881 GObjectController *cont = _controllers[idOutputPort];
2882 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2883 double xIn, yIn, zIn;
2884 outputPort->getInicPoint(xIn, yIn, zIn);
2886 cbmod->setInicPoint(xIn, yIn, zIn);
2887 cbmod->notifyObservers(_idManager);
2889 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2891 // Creates connection
2892 int idCon = createGConnector(outputPortEnd);
2893 GConnectorController *tempp =
2894 (GConnectorController*) _controllers[idCon];
2895 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2896 vtkGConnectorView *conView =
2897 (vtkGConnectorView*) tempp->getView();
2898 tempp->endContourCreation();
2899 conMod->setEndPort(cbmod->getInputPort(0));
2900 conView->updateStartEndPoints();
2910 //=========================================================================
2911 void wxVtkSceneManager::SetCbName(std::string cbName) {
2913 if (_cbName == "") {
2914 _cbName = "<complex box name>";
2918 //=========================================================================
2919 std::string wxVtkSceneManager::GetCbName() {
2923 //=========================================================================
2924 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2925 _cbPackageName = packagename;
2926 if (_cbPackageName == "") {
2927 _cbPackageName = "<package name of the complex box>";
2931 //=========================================================================
2932 std::string wxVtkSceneManager::GetCbPackageName() {
2933 return _cbPackageName;
2936 //=========================================================================
2937 void wxVtkSceneManager::SetAuthor(std::string author) {
2939 if (_Author == "") {
2940 _Author = "<author of the box>";
2944 //=========================================================================
2945 std::string wxVtkSceneManager::GetAuthor() {
2949 //=========================================================================
2950 void wxVtkSceneManager::SetCategory(std::string category) {
2951 _Category = category;
2952 if (_Category == "") {
2953 _Category = "<category of the box>";
2957 //=========================================================================
2958 std::string wxVtkSceneManager::GetCategory() {
2962 //=========================================================================
2963 void wxVtkSceneManager::SetDescription(std::string description) {
2964 _Description = description;
2965 if (_Description == "") {
2966 _Description = "<description of the box>";
2970 //=========================================================================
2971 std::string wxVtkSceneManager::GetDescription() {
2972 return _Description;
2975 //=========================================================================
2977 void wxVtkSceneManager::SetMessageKind(std::string kind) {
2978 _MessageKind = kind;
2982 //=========================================================================
2984 std::string wxVtkSceneManager::GetMessageKind(){
2985 return _MessageKind;
2988 //=========================================================================
2990 void wxVtkSceneManager::SetMessageLevel(std::string Level){
2991 _MessageLevel = Level;
2994 //=========================================================================
2996 std::string wxVtkSceneManager::GetMessageLevel(){
2997 return _MessageLevel;
3000 //=========================================================================
3002 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
3005 std::vector< std::string> extInputs;
3006 std::map<int, GObjectController*>::iterator it;
3007 for (it = _controllers.begin(); it != _controllers.end(); ++it)
3009 GObjectController *cont = it->second;
3010 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
3012 extInputs.push_back(cont->getModel()->getBBTKName());
3018 //=========================================================================
3022 void wxVtkSceneManager::printAll(int com , int sta ){
3024 int tmpState = sta ;
3025 if ( tmpState == NOTHING_HAPPENS ) {
3026 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
3028 if ( tmpState == HIGHLIGHTED ) {
3029 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
3031 if ( tmpState == POSSIBLE_CONNECTION ) {
3032 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
3034 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
3035 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
3037 if ( tmpState == CLICKED ) {
3038 std::cout << "CONTROLER STATE---->CLICKED\n" ;
3040 if ( tmpState == DRAG ) {
3041 std::cout << "CONTROLER STATE---->DRAG\n" ;
3043 if ( tmpState == SELECTED ) {
3044 std::cout << "CONTROLER STATE---->SELECTED\n" ;
3046 if ( tmpState == CREATING_CONTOUR ) {
3047 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
3053 if ( command == INIT_CREATION_CONTOUR ) {
3054 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
3056 if ( command == FIN_CREATION_CONTOUR ) {
3057 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
3059 if ( command == ADD_TO_SELECTED ) {
3060 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
3062 if ( command == DRAG_OBJECTS ) {
3063 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
3065 if ( command == EDIT_BLACKBOX ) {
3066 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
3068 if ( command == REMOVE_FROM_SELECTED ) {
3069 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
3075 } // EO namespace bbtk