1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::wxVtkSceneManager .
36 #include "wxVtkSceneManager.h"
38 #include <vtkPolygon.h>
39 #include <vtkUnstructuredGrid.h>
43 #define POORT_MAX_LINE_SIZE_INTERPRETER 1500
45 //=========================================================================
47 // EED 15 oct 2012 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
49 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
51 _cbName = "ComplexBoxName";
52 _cbPackageName = "PackageName";
53 _Author = "Author ??";
55 _Description = "Description ??";
59 _idManager = idManager;
61 _bbtkfactory = bbtkfactory;
63 _startDragging = false;
64 _isComplexBox = false;
66 if (_baseView != NULL) {
69 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
72 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
76 _worldState = NOTHING_HAPPENS;
77 registerController(this);
80 _idConnectionInCreation = -1;
85 //=========================================================================
87 void wxVtkSceneManager::disconnectDrop()
89 printf("EED %p ~wxVtkSceneManager::disconnectDrop()\n", this);
90 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
91 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
94 //=========================================================================
96 wxVtkSceneManager::~wxVtkSceneManager()
99 printf("EED %p ~wxVtkSceneManager() START\n", this);
102 printf("EED %p ~wxVtkSceneManager() END\n", this);
105 //=========================================================================
107 void wxVtkSceneManager::configureBaseView()
109 printf("EED wxVtkSceneManager::configureBaseView 0\n");
110 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
112 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
114 // Important to activate the 2D interaction system
115 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
116 interactorstylebaseview->SetInteractor(iren);
117 iren->SetInteractorStyle(interactorstylebaseview);
118 interactorstylebaseview->SetwxVtkBaseView(_baseView);
120 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
121 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, -1000, 1000);
122 _baseView->GetRenderer()->GetActiveCamera()->Zoom(10);
125 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
126 _baseView->GetRenderer()->GradientBackgroundOn();
129 _textActor = vtkTextActor3D::New();
130 _textActor->SetPosition(-9999, -9999, GPOSITION_Z);
131 _textActor->SetInput("<void>");
132 _textActor->GetTextProperty()->SetFontSize(60);
133 _textActor->GetTextProperty()->BoldOn();
134 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,PORTTEXT_NH_B);
136 _baseView->GetRenderer()->AddActor(_textActor);
138 // Actor Fill_Port_Text
143 double zInic = GPOSITION_Z;
145 vtkPolygon *aPolygon = vtkPolygon::New();
146 _fillObjectActor = vtkActor::New();
148 _pts = vtkPoints::New();
150 double w = 100, h = 10, b = h / 15, t = 3;
151 _pts->SetNumberOfPoints(21);
152 _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
153 _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
154 _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
155 _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
156 _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
158 _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
159 _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
160 _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
161 _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
163 _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
164 _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
165 _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
166 _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
168 _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
169 _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
170 _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
171 _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
173 _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
174 _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
175 _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
176 _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
178 aPolygon->GetPointIds()->SetNumberOfIds(21);
179 for (int i = 0; i < 21; i++) {
180 aPolygon->GetPointIds()->SetId(i, i);
183 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
184 aPolygonGrid->Allocate(1, 1);
185 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),
186 aPolygon->GetPointIds());
187 aPolygonGrid->SetPoints(_pts);
188 _aPolygonMapper = vtkDataSetMapper::New();
189 _aPolygonMapper->SetInput(aPolygonGrid);
190 _fillObjectActor->SetMapper(_aPolygonMapper);
191 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
193 _fillObjectActor->GetProperty()->SetOpacity(0);
194 _aPolygonMapper->Modified();
196 _baseView->GetRenderer()->AddActor(_fillObjectActor);
197 printf("EED wxVtkSceneManager::configureBaseView 1\n");
200 //=========================================================================
202 std::string wxVtkSceneManager::generateANewNameForABox() {
203 std::stringstream boxname;
204 if (_numBoxes < 10) {
205 boxname << "Box0" << _numBoxes;
207 boxname << "Box" << _numBoxes;
210 return boxname.str();
213 //=========================================================================
215 std::string wxVtkSceneManager::findANewNameForABox() {
216 std::string boxname = generateANewNameForABox();
218 while (boxExist(boxname) == true) {
219 boxname = generateANewNameForABox();
225 //=========================================================================
226 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
227 double zIn, std::string name, bool boxExecutable, double xEn,
228 double yEn, double zEn) {
229 GObjectController *cont = _controllers[idBox];
230 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
231 bbmod->setBBTKName(name);
232 bbmod->setInicPoint(xIn, yIn, zIn);
233 bbmod->setFinalPoint(xEn, yEn, zEn);
234 bbmod->setExecutable(boxExecutable);
236 bbmod->notifyObservers(_idManager);
240 //=========================================================================
242 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,std::string boxType)
244 _worldState = NOTHING_HAPPENS;
245 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
246 int type = GBLACKBOX;
247 //Create the MVC Objects
248 GBlackBoxModel *model = (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
249 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
250 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
252 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
255 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
257 k = _bbtkfactory->GetPackage(packageName);
258 mapDesc = k->GetDescriptorMap();
260 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for package %s, NOT EXIST\n", packageName.c_str());
263 BlackBoxDescriptor::Pointer descriptor;
265 descriptor = mapDesc[boxType];
267 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for box %s of package %s, NOT EXIST\n", boxType.c_str(),packageName.c_str());
270 if (descriptor == NULL)
272 printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
275 //Prepares the initial model
276 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
279 double yy = windowHeight - y;
281 //z value is not important yet, because it is only used a parallel projection
282 double zz = GPOSITION_Z;
283 _baseView->TransCoordScreenToWorld(xx, yy, zz);
284 model->setInicPoint(xx, yy, zz);
286 std::stringstream stream;
288 std::string newBoxName;
289 newBoxName = findANewNameForABox();
291 stream << newBoxName;
293 std::string arraystring = stream.str();
295 model->setBBTKName(arraystring);
296 model->setBBTKType(boxType);
297 model->setBBTKPackage(packageName);
299 model->addObserver(view);
300 model->addObserver(this);
302 //Iterate and create the input ports
303 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
304 descriptor->GetInputDescriptorMap();
305 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
308 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) {
309 BlackBoxInputDescriptor *desc = itInput->second;
310 createGInputPort(GINPUTPORT, i, model, desc);
314 //Iterate and create the output ports
315 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
316 descriptor->GetOutputDescriptorMap();
317 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
320 for (itOutput = descriptorOutMap.begin(); itOutput
321 != descriptorOutMap.end(); ++itOutput) {
322 BlackBoxOutputDescriptor *desc = itOutput->second;
323 createGOutputPort(GOUTPUTPORT, i, model, desc);
327 //Associates the view with the correspondent renderer and the model.
328 //(NOTE: Refresh is only made by the view)
329 view->setModel(model);
330 view->setBaseView(_baseView);
331 view->initVtkObjects();
333 //Associates the controller with the correspondent model and view
334 controller->setModelAndView(model, view);
336 //Resgiter change to the observers of the actual model
337 model->notifyObservers(_idManager);
339 int newId = addObjectController(controller);
345 //=========================================================================
347 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
348 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
349 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
351 int type = GCOMPLEXINPUTPORT;
353 //Create the MVC Objects
355 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
356 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
357 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
359 //Prepares the initial model
362 double yy = windowHeight - 5;
364 //z value is not important yet, because it is only used a parallel projection
365 double zz = GPOSITION_Z;
367 _baseView->TransCoordScreenToWorld(xx, yy, zz);
368 model->setInicPoint(xx, yy, zz);
370 model->setBBTKName(inputName);
371 model->setBBTKType("ComplexInputPort");
372 model->setComplexPortType(type);
374 model->addObserver(view);
375 model->addObserver(this);
377 //create the output port
378 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
379 "ComplexOutputPortType","ComplexOutputPortDescriopton", 0, model);
380 model->addOutputPort((GPortModel*) portController->getModel());
382 //Associates the view with the correspondent renderer and the model.
383 //(NOTE: Refresh is only made by the view)
384 view->setModel(model);
385 view->setBaseView(_baseView);
386 view->initVtkObjects();
388 //Associates the controller with the correspondent model and view
389 controller->setModelAndView(model, view);
391 //Resgiter change to the observers of the actual model
392 model->notifyObservers(_idManager);
394 int newId = addObjectController(controller);
398 //=========================================================================
400 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
401 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
402 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
404 int type = GCOMPLEXOUTPUTPORT;
406 //Create the MVC Objects
408 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
409 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
410 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
412 //Prepares the initial model
415 double yy = windowHeight - 5;
417 //z value is not important yet, because it is only used a parallel projection
418 double zz = GPOSITION_Z;
420 _baseView->TransCoordScreenToWorld(xx, yy, zz);
421 model->setInicPoint(xx, yy, zz);
423 model->setBBTKName(outputName);
424 model->setBBTKType("ComplexOutputPort");
425 model->setComplexPortType(type);
427 model->addObserver(view);
428 model->addObserver(this);
430 //create the output port
431 GPortController* portController = createGPort(GINPUTPORT, outputName,
432 "ComplexInputPort","ComplexInputPortDescription", 0, model);
433 model->addInputPort((GPortModel*) portController->getModel());
435 //Associates the view with the correspondent renderer and the model.
436 //(NOTE: Refresh is only made by the view)
437 view->setModel(model);
438 view->setBaseView(_baseView);
439 view->initVtkObjects();
441 //Associates the controller with the correspondent model and view
442 controller->setModelAndView(model, view);
444 //Resgiter change to the observers of the actual model
445 model->notifyObservers(_idManager);
447 int newId = addObjectController(controller);
451 //=========================================================================
453 int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
455 GPortController* portController = createGPort(portType, desc->GetName(),
456 desc->GetTypeName(), desc->GetDescription(), posinBox, blackBox);
457 blackBox->addInputPort((GPortModel*) portController->getModel());
458 return portController->getId();
461 //=========================================================================
463 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
465 GPortController* portController = createGPort(portType, desc->GetName(),
466 desc->GetTypeName(),desc->GetDescription(), posinBox, blackBox);
467 blackBox->addOutputPort((GPortModel*) portController->getModel());
468 return portController->getId();
471 //=========================================================================
473 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posInBox,GBoxModel *blackBox)
477 //Create the MVC Objects
480 (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
482 vtkGObjectView *view =
483 GObjectsMVCFactory::getInstance()->createGObjectView(type);
484 GObjectController* controller =
485 GObjectsMVCFactory::getInstance()->createGObjectController(type);
487 model->registerInBox(blackBox, portType, posInBox);
489 model->setBBTKType(bbtkType);
490 model->setBBTKName(bbtkName);
491 model->setBBTKDescription(bbtkDescription);
493 model->addObserver(view);
494 model->addObserver(this);
496 //Associates the view with the correspondent renderer and the model.
497 //(NOTE: Refresh is only made by the view)
498 view->setModel(model);
499 view->setBaseView(_baseView);
500 view->initVtkObjects();
502 //Associates the controller with the correspondent model and view
503 controller->setModelAndView(model, view);
505 model->notifyObservers(_idManager);
507 addObjectController(controller);
509 return (GPortController*) controller;
512 //=========================================================================
514 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
516 int type = GCONNECTOR;
518 manualConnectorContourController *manContourControl = new manualConnectorContourController();
519 manualConnectorContourView *manContourView = new manualConnectorContourView();
520 manualContourModel *manContourModel = new manualContourModel();
521 GConnectorController *connectorcontroller = new GConnectorController();
522 GConnectorModel *connectorModel = new GConnectorModel();
523 vtkGConnectorView *connectorView = new vtkGConnectorView();
524 connectorModel->setGObjectType(type);
526 manContourModel->SetCloseContour(false);
527 connectorModel->setStartPort(startPort);
529 manContourView->SetModel(manContourModel);
530 manContourView->SetWxVtkBaseView(_baseView);
531 manContourView->SetRange(0.5);
532 manContourView->SetZ(GPOSITION_Z);
534 manContourView->SetColorNormalContour(0, 0, 1);
535 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
536 manContourView->SetColorSelectContour(1, 0.8, 0);
542 * Width increased from 2 to 3, it simplifies line handling and spline control :P
545 manContourView->SetWidthLine( 3 ) ;
546 manContourView->SetShowText(false);
548 manContourControl->SetModelView(manContourModel, manContourView);
550 manContourControl->CreateNewManualContour();
554 connectorModel->getInicPoint(x, y, z);
557 manContourControl->SetState(1);
558 manContourModel->SetCloseContour(false);
560 manContourModel->AddPoint(x, y, z);
561 manContourView->AddPoint();
563 manContourModel->AddPoint(x, y, z);
564 manContourView->AddPoint();
566 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
567 manContourControl->_bakIdPoint = bak;
569 manContourControl->SetMoving(false);
571 connectorcontroller->setModelAndView(connectorModel, connectorView);
573 int newId = addObjectController(connectorcontroller);
575 connectorcontroller->setManualContourController(manContourControl);
576 connectorModel->setManualContourModel(manContourModel);
577 connectorView->setManualContourView(manContourView);
578 connectorView->setModel(connectorModel);
579 connectorView->setBaseView(_baseView);
581 connectorModel->addObserver(connectorView);
582 connectorModel->addObserver(this);
584 // manContourView->Refresh();
589 //=========================================================================
591 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
593 vtkInteractorStyleBaseView * baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
594 baseViewControlManager->AddInteractorStyleMaracas(param);
597 //=========================================================================
599 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
601 vtkInteractorStyleBaseView *baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
602 baseViewControlManager->RemoveInteractorStyleMaracas(param);
605 //=========================================================================
607 vtkRenderer* wxVtkSceneManager::getRenderer()
609 return _baseView->GetRenderer();
612 //=========================================================================
614 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
616 return _baseView->GetRenWin();
618 //=========================================================================
621 //=========================================================================
622 int wxVtkSceneManager::GetIndexInSelected(int idControler)
625 for (int i = 0; i < (int) _selectedObjects.size(); i++)
627 if (_selectedObjects[i] == idControler)
635 //=========================================================================
637 void wxVtkSceneManager::update(int idController, int command) {
639 if (command != NO_COMMAND)
641 if (command == ADD_TO_SELECTED)
643 if (GetIndexInSelected(idController) == -1)
645 _selectedObjects.push_back(idController);
647 } else if (command == REMOVE_FROM_SELECTED) {
648 int index = GetIndexInSelected(idController);
651 _selectedObjects.erase(_selectedObjects.begin() + index);
653 } else if (command == INIT_CREATION_CONTOUR) {
655 typedef std::map<int , GObjectController*>::iterator TIterator ;
658 // Find current item in the controller
659 iter = _controllers.find( idController ) ;
660 iter_end = _controllers.end( ) ;
662 if ( iter != iter_end ) {
663 GObjectController* gobjc = iter->second ;
665 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
666 // And if the item is a port
667 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
668 TIterator c_it = _controllers.begin( ) ;
669 // Go through all componets
670 for ( c_it ; c_it != iter_end ; c_it++ ) {
671 GObjectController* obc = c_it->second ;
672 int obc_type = obc->getModel( )->getGObjectType( ) ;
673 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
674 // if the component is a port and the type is the same of that selected
675 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
677 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
678 //obc->getView( )->setState( HIGHLIGHTED ) ;
686 _worldState = INIT_CREATION_CONTOUR;
687 GObjectController* cont = _controllers[idController];
688 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
690 // The last one is the controller of the connector
691 std::map<int, GObjectController*>::iterator it2;
693 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
695 GObjectController *cont = it2->second;
696 if (cont->getGObjectType() == GPORT)
698 GPortModel* port = (GPortModel*) cont->getModel();
699 if (port->getPortType() == GINPUTPORT)
701 cont->SetActive(true);
703 cont->getView()->setState(NOTHING_HAPPENS);
704 cont->getModel()->notifyObservers(_idManager);
705 cont->SetActive(false);
708 cont->getView()->setState(NOTHING_HAPPENS);
709 cont->getModel()->notifyObservers(_idManager);
710 cont->SetActive(false);
713 _selectedObjects.clear();
714 _idConnectionInCreation = createGConnector(startOutputPort);
715 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
716 _worldState = NOTHING_HAPPENS;
717 //int id = _controllers.size()-1;
718 GObjectController *cont = _controllers[_idConnectionInCreation];
719 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
720 GObjectController *finPort = _controllers[idController];
722 if (finPort->getGObjectType() == GPORT)
724 GPortModel* modelPort = (GPortModel*) finPort->getModel();
725 modelContour->setEndPort(modelPort);
728 typedef std::map<int, GObjectController*>::iterator TIterator;
729 TIterator c_it = _controllers.begin();
730 TIterator iter_end = _controllers.end();
731 // Go through all componets
732 for (c_it; c_it != iter_end; c_it++) {
733 GObjectController* obc = c_it->second;
734 int obc_type = obc->getModel()->getGObjectType();
735 int obc_state = obc->getView()->getState();
736 // if the component is a port and the type is the same of that selected
737 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
738 // Return element to neutral state if not selected
739 obc->getView()->setState(NOTHING_HAPPENS);
741 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
742 // Change element to connected state
743 obc->getView()->setState(HIGHLIGHTED);
750 _parent->saveTempandUpdate("create connection");
753 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
754 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
756 std::map<int, GObjectController*>::iterator it2;
758 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
760 GObjectController *cont = it2->second;
761 if (cont->getView() != NULL) {
762 cont->getView()->setState(NOTHING_HAPPENS);
763 cont->getModel()->notifyObservers(_idManager);
765 cont->SetActive(true);
774 //=========================================================================
776 bool wxVtkSceneManager::OnMouseMove()
779 bool okStatusMessage = false;
780 bool okPortMessage = false;
781 wxVTKRenderWindowInteractor *wxVTKiren;
782 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
783 wxVTKiren->GetEventPosition(X, Y);
785 if (_worldState == DRAG_OBJECTS) {
786 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
787 int id = _selectedObjects[i];
788 GObjectController* cont = _controllers[id];
789 if (_startDragging) {
790 cont->getView()->setStartDragging(true);
792 cont->getView()->moveObject(X, Y);
793 cont->getView()->setState(DRAG);
794 cont->getModel()->notifyObservers(_idManager);
797 std::map<int, GObjectController*>::iterator it;
799 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
800 GObjectController *desc = it->second;
801 if (desc->getGObjectType() == GCONNECTOR) {
802 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
803 vconn->updateStartEndPoints();
807 _startDragging = false;
809 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
810 std::map<int, GObjectController*>::iterator it;
812 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
813 GObjectController *desc = it->second;
814 int type = desc->getGObjectType();
815 int state = desc->getView()->getState();
816 desc->getModel()->getCenter(px, py, pz);
819 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
822 okStatusMessage = true;
823 updateStatusBar(desc->getStatusText());
824 if (type == GBLACKBOX)
826 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
827 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
832 okPortMessage = true;
834 _textActor->SetInput(desc->getStatusText().c_str());
835 _textActor->SetScale(0.1);
836 _textActor->SetPosition(px - 25, py + 1, pz + 2);
841 _fillObjectActor->SetScale(1);
842 _fillObjectActor->GetProperty()->SetOpacity(0.50);
843 _fillObjectActor->SetPosition(px, py, 1);
844 _aPolygonMapper->Modified();
847 } // for controllers it
850 if (okStatusMessage == false)
855 if (okPortMessage == false)
857 _textActor->SetScale(0.0001);
858 _fillObjectActor->SetScale(0.0001);
863 //=========================================================================
865 bool wxVtkSceneManager::OnLeftButtonDown()
867 if (_worldState == INIT_CREATION_CONTOUR)
869 bool isOverPort = false;
870 std::map<int, GObjectController*>::iterator it;
871 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
873 GObjectController *desc = it->second;
874 if (desc->getGObjectType() == GPORT)
876 GPortModel *portmod = (GPortModel*) desc->getModel();
877 vtkGObjectView *portView = desc->getView();
878 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
883 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
885 portView->setState( HIGHLIGHTED);
892 if (isOverPort == false)
895 UnSelectBlackBoxes();
899 } else { //_worldState
901 _worldState = DRAG_OBJECTS;
902 _startDragging = true;
904 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
905 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
906 ctrlkey = ctrlkey + shiftkey;
908 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
911 int state = cont->getView()->getState();
912 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
913 UnSelectBlackBoxes();
916 UnSelectBlackBoxes(); // EED 12/07/2012
918 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
919 int id = _selectedObjects[i];
920 GObjectController *cont = _controllers[id];
921 cont->getView()->setState(DRAG);
922 cont->getModel()->notifyObservers(_idManager);
924 } // if _selectedObjects.size
930 //=========================================================================
932 bool wxVtkSceneManager::OnLeftButtonUp()
934 if (_worldState == DRAG_OBJECTS) {
935 _worldState = NOTHING_HAPPENS;
937 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
938 int id = _selectedObjects[i];
939 GObjectController* cont = _controllers[id];
940 cont->getView()->setState(SELECTED);
941 cont->getModel()->notifyObservers(_idManager);
947 //=========================================================================
948 void wxVtkSceneManager::CancelConnection()
950 if (_worldState == INIT_CREATION_CONTOUR)
952 _worldState = NOTHING_HAPPENS;
953 //int lastId = _controllers.size()-1;
955 GConnectorController *connector =
956 (GConnectorController*) _controllers[_idConnectionInCreation];
957 connector->removeFromScene();
958 unregisterController(connector);
959 _controllers.erase(_idConnectionInCreation);
961 std::map<int, GObjectController*>::iterator it;
962 for (it = _controllers.begin(); it != _controllers.end(); ++it)
964 GObjectController *desc = it->second;
965 desc->SetActive(true);
966 desc->getView()->setState(NOTHING_HAPPENS);
967 desc->getModel()->notifyObservers(_idManager);
972 //=========================================================================
974 bool wxVtkSceneManager::OnRightButtonUp()
976 if (_worldState == INIT_CREATION_CONTOUR)
980 UnSelectBlackBoxes();
986 bool wxVtkSceneManager::OnMiddleButtonDown() {
989 this->_vtkInteractorStyleBaseView->StartPan();
994 bool wxVtkSceneManager::OnMiddleButtonUp() {
997 this->_vtkInteractorStyleBaseView->EndPan();
1004 //=========================================================================
1006 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1007 GObjectController *result = NULL;
1009 wxVTKRenderWindowInteractor *wxVTKiren;
1011 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1012 wxVTKiren->GetEventPosition(X, Y);
1014 std::map<int, GObjectController*>::iterator it;
1016 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1017 GObjectController *cont = it->second;
1018 int type = cont->getGObjectType();
1020 if (cont->getView()->isPointInside(X, Y) == true) {
1021 if (type == GBLACKBOX) {
1024 } // if isPointInside
1029 //=========================================================================
1030 void wxVtkSceneManager::UnSelectBlackBoxes() {
1031 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1032 int id = _selectedObjects[i];
1033 GObjectController* control = _controllers[id];
1034 control->getView()->setState(NOTHING_HAPPENS);
1035 control->getModel()->notifyObservers(_idManager);
1036 }// for _selectedObjects
1037 _selectedObjects.clear();
1040 //=========================================================================
1041 bool wxVtkSceneManager::OnLeftDClick() {
1042 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1044 UnSelectBlackBoxes();
1045 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1051 wxVTKRenderWindowInteractor *wxVTKiren;
1052 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1053 wxVTKiren->GetEventPosition(X,Y);
1055 std::map<int, GObjectController*>::iterator it;
1057 bool clickOnObject = false;
1059 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1061 GObjectController *cont = it->second;
1062 int type = cont->getGObjectType();
1064 if(cont->getView()->isPointInside(X,Y))
1068 for (int i=0; i< (int)_selectedObjects.size(); i++)
1070 int id = _selectedObjects[i];
1071 GObjectController* control = _controllers[id];
1072 control->getView()->setState(NOTHING_HAPPENS);
1074 _selectedObjects.clear();
1076 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1077 _parent->editBlackBox(bbmodel);
1079 clickOnObject = true;
1083 if(clickOnObject==false)
1085 //_parent->editDiagramParameters(this);
1091 //=========================================================================
1093 bool wxVtkSceneManager::OnChar()
1097 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1098 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1100 // KeyCode 127 : Delete Key
1101 // KeyCode 8 : Backspace Key
1104 if (keyCode == 8 || keyCode == 127 || keyCode == 27)
1106 if (_worldState == INIT_CREATION_CONTOUR)
1109 UnSelectBlackBoxes();
1114 if (keyCode == 8 || keyCode == 127)
1117 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1119 int id = _selectedObjects[i];
1120 std::map<int, GObjectController*>::iterator it;
1121 it = _controllers.find(id);
1122 if (it != _controllers.end())
1124 oktmp = deleteObject(id);
1127 }// for selected objects
1128 if (ok) _selectedObjects.clear();
1129 _parent->saveTempandUpdate("delete object");
1134 if((keyCode==0) && (ctrlkey==1)) {
1139 if(_selectedObjects.size()){
1140 std::cout<<"objects to copy :";
1141 for(int i=0;i<_selectedObjects.size();i++)
1143 std::cout<<_selectedObjects.at(i)<<" ";
1145 DuplicateObjects(getSelectedObjects());
1147 std::cout<<"No objects to copy\n";
1148 } // _selectedObjects.size
1154 //=========================================================================
1156 void wxVtkSceneManager::AddControlerToBeRemove(
1157 std::vector<int> *controllersToRemove, int id) {
1161 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1162 if (id == (*controllersToRemove)[i]) {
1168 controllersToRemove->push_back(id);
1173 //=========================================================================
1175 bool wxVtkSceneManager::deleteObject(int id)
1178 GObjectController *control = _controllers[id];
1179 std::vector<int> controllersToRemove;
1180 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1181 == GCOMPLEXINPUTPORT || control->getGObjectType()
1182 == GCOMPLEXOUTPUTPORT) {
1183 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1184 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1186 bool boxConnected = false;
1188 // Add box input controllers to be removed
1189 for (int i = 0; i < (int) inputs.size(); i++) {
1190 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1191 if (inputs[i]->isConnected()) {
1192 boxConnected = true;
1196 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1198 // Add box output controllers to be removed
1199 for (int i = 0; i < (int) outputs.size(); i++) {
1200 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1201 if (outputs[i]->isConnected()) {
1202 boxConnected = true;
1206 // Add connection controllers to be removed
1207 std::map<int, GObjectController*>::iterator it;
1208 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1209 GObjectController *cont = it->second;
1210 int type = cont->getGObjectType();
1211 if (type == GCONNECTOR) {
1212 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1213 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1215 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1217 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1219 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1224 // Add box controller to be removed
1225 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1226 } else if (control->getGObjectType() == GCONNECTOR) {
1227 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1228 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1230 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1231 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1233 gconnectorcontroler->getManualContourController()->OnChar();
1238 std::map<int, GObjectController*>::iterator it;
1240 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1241 int key = controllersToRemove[i];
1242 it = _controllers.find(key);
1243 GObjectController *cont = _controllers[key];
1245 cont->removeFromScene();
1246 unregisterController((InteractorStyleMaracas*) cont);
1247 _controllers.erase(it);
1255 //=========================================================================
1257 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1258 std::string boxName) {
1259 _parent->displayBlackBoxInfo(packageName, boxName);
1262 //=========================================================================
1264 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1265 _parent->updateStatusBar(textStatus);
1268 //=========================================================================
1269 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1270 std::string result = "";
1271 if (withLineNumber == true) {
1273 stringstream StrStream;
1275 std::string strValue = StrStream.str();
1278 } else if (value < 100) {
1282 result += strValue + ": ";
1286 //=========================================================================
1288 bool wxVtkSceneManager::MakeBoxExecutable() {
1289 std::map<int, GObjectController*> selected = getSelectedObjects();
1290 if( selected.empty() )
1293 std::map<int, GObjectController*>::iterator it;
1294 for (it = selected.begin(); it != selected.end(); ++it) {
1295 GObjectController* lastSelected = it->second;
1297 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1298 GBlackBoxModel *bbmodel =
1299 (GBlackBoxModel*) lastSelected->getModel();
1300 view->setState(HIGHLIGHTED);
1301 if (bbmodel->isExecutable()) {
1302 bbmodel->setExecutable(false);
1304 bbmodel->setExecutable(true);
1306 bbmodel->notifyObservers(lastSelected->getId());
1314 //=========================================================================
1316 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1317 bool existsExec = false;
1319 std::vector<std::string> packages;
1320 std::vector<int> boxes;
1321 std::vector<int> connections;
1322 std::vector<int> execBoxes;
1324 std::map<int, GObjectController*>::iterator it;
1326 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1327 GObjectController *desc = it->second;
1328 int type = desc->getGObjectType();
1330 if (type == GBLACKBOX) {
1331 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1333 std::string pkg = mod->getBBTKPackage();
1334 bool existsPkg = false;
1335 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1336 if (packages[t] == pkg) {
1341 packages.push_back(pkg);
1344 boxes.push_back(it->first);
1345 if (mod->isExecutable()) {
1346 execBoxes.push_back(it->first);
1349 } else if (type == GCONNECTOR) {
1350 connections.push_back(it->first);
1355 std::string script = "";
1356 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1357 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1358 script += LineNumber(wln, lnNmbr) + "\n";
1360 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1361 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1363 for (i = 0; i < (int) packages.size(); i++) {
1364 script += LineNumber(wln, lnNmbr);
1365 script += "include ";
1366 script += packages[i];
1370 script += LineNumber(wln, lnNmbr);
1375 script += LineNumber(wln, lnNmbr);
1376 script += "author \"";
1380 script += LineNumber(wln, lnNmbr);
1381 script += "description \"";
1382 script += _Description;
1385 script += LineNumber(wln, lnNmbr);
1386 script += "category \"";
1387 script += _Category;
1390 script += LineNumber(wln, lnNmbr);
1393 // script+="include std\n"; // JPR
1395 for (i = 0; i < (int) boxes.size(); i++) {
1396 script += LineNumber(wln, lnNmbr);
1399 GObjectController *control = _controllers[id];
1400 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1402 script += model->getBBTKType();
1404 script += model->getBBTKName();
1407 std::vector<GPortModel*> inputs = model->getInputPorts();
1408 for (int j = 0; j < (int) inputs.size(); j++) {
1409 GPortModel* inputPort = inputs[j];
1410 if (inputPort->isValueSet()) {
1411 script += LineNumber(wln, lnNmbr);
1413 script += model->getBBTKName();
1415 script += inputPort->getBBTKName();
1417 script += inputPort->getValue();
1422 script += LineNumber(wln, lnNmbr);
1427 script += LineNumber(wln, lnNmbr);
1431 std::string complexInputs="";
1433 for (i = 0; i < (int) connections.size(); i++) {
1434 //script += LineNumber(wln, lnNmbr);
1435 //script += "connect ";
1436 int id = connections[i];
1437 GObjectController *control = _controllers[id];
1438 GConnectorModel *model = (GConnectorModel*) control->getModel();
1442 GPortModel *start = model->getStartPort();
1443 GBoxModel *startBox = start->getParentBox();
1445 GPortModel *end = model->getEndPort();
1446 GBoxModel *endBox = end->getParentBox();
1448 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1450 complexInputs += "input ";
1451 complexInputs += startBox->getBBTKName();
1453 complexInputs += " ";
1454 complexInputs += endBox->getBBTKName();
1455 complexInputs += ".";
1456 complexInputs += end->getBBTKName();
1458 complexInputs += " ";
1459 complexInputs += "\" \"";
1461 complexInputs += "\n";
1465 script += "connect ";
1466 script += startBox->getBBTKName();
1468 script += start->getBBTKName();
1472 //End Connection info
1473 script += endBox->getBBTKName();
1475 script += end->getBBTKName();
1483 script += LineNumber(wln, lnNmbr);
1487 script += "# Complex input ports\n";
1488 script += complexInputs;
1490 for (i = 0; i < (int) execBoxes.size(); i++) {
1491 script += LineNumber(wln, lnNmbr);
1493 int id = execBoxes[i];
1494 GObjectController *control = _controllers[id];
1495 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1497 script += model->getBBTKName();
1506 //=========================================================================
1508 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1509 std::vector<std::string> packages;
1510 std::vector<int> boxes;
1511 std::vector<int> connections;
1512 std::vector<int> execBoxes;
1514 std::map<int, GObjectController*>::iterator it;
1516 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1517 GObjectController *desc = it->second;
1518 int type = desc->getGObjectType();
1520 if (type == GBLACKBOX) {
1521 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1523 std::string pkg = mod->getBBTKPackage();
1524 bool existsPkg = false;
1525 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1526 if (packages[t] == pkg) {
1531 packages.push_back(pkg);
1534 boxes.push_back(it->first);
1535 if (mod->isExecutable()) {
1536 execBoxes.push_back(it->first);
1538 } else if (type == GCONNECTOR) {
1539 connections.push_back(it->first);
1543 std::string script = "";
1545 script += "include std\n"; // EED
1546 script += "include itkvtk\n"; // EED
1548 for (i = 0; i < (int) packages.size(); i++) {
1549 script += "include ";
1550 script += packages[i];
1555 // Definition of a complex box
1556 script += "define ";
1557 script += _cbName + " " + _cbPackageName;
1561 script += "author \"";
1565 script += "description \"";
1566 script += _Description;
1570 script += "category \"";
1571 script += _Category;
1576 for (i = 0; i < (int) boxes.size(); i++) {
1579 GObjectController *control = _controllers[id];
1580 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1582 script += model->getBBTKType();
1584 script += model->getBBTKName();
1587 std::vector<GPortModel*> inputs = model->getInputPorts();
1588 for (int j = 0; j < (int) inputs.size(); j++) {
1589 GPortModel* inputPort = inputs[j];
1590 if (inputPort->isValueSet()) {
1592 script += model->getBBTKName();
1594 script += inputPort->getBBTKName();
1596 script += inputPort->getValue();
1604 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1606 std::string complexInputs = "";
1607 std::string complexOutputs = "";
1610 for (i = 0; i < (int) connections.size(); i++) {
1611 int id = connections[i];
1612 GObjectController *control = _controllers[id];
1613 GConnectorModel *model = (GConnectorModel*) control->getModel();
1616 GPortModel *start = model->getStartPort();
1617 GBoxModel *startBox = start->getParentBox();
1619 GPortModel *end = model->getEndPort();
1620 GBoxModel *endBox = end->getParentBox();
1622 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1623 complexInputs += "input ";
1624 complexInputs += startBox->getBBTKName();
1626 complexInputs += " ";
1627 complexInputs += endBox->getBBTKName();
1628 complexInputs += ".";
1629 complexInputs += end->getBBTKName();
1631 complexInputs += " ";
1632 complexInputs += "\" \"";
1634 complexInputs += "\n";
1635 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1636 complexOutputs += "output ";
1637 complexOutputs += endBox->getBBTKName();
1639 complexOutputs += " ";
1640 complexOutputs += startBox->getBBTKName();
1641 complexOutputs += ".";
1642 complexOutputs += start->getBBTKName();
1644 complexOutputs += " ";
1645 complexOutputs += "\" \"";
1647 complexOutputs += "\n";
1649 script += "connect ";
1650 script += startBox->getBBTKName();
1652 script += start->getBBTKName();
1656 //End Connection info
1657 script += endBox->getBBTKName();
1659 script += end->getBBTKName();
1666 script += "# Complex input ports\n";
1667 script += complexInputs;
1670 script += "# Complex output ports\n";
1671 script += complexOutputs;
1675 for (i = 0; i < (int) execBoxes.size(); i++) {
1677 int id = execBoxes[i];
1678 GObjectController *control = _controllers[id];
1679 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1681 script += model->getBBTKName();
1686 script += "endefine";
1692 //=========================================================================
1694 void wxVtkSceneManager::deleteAllBoxes() {
1695 std::map<int, GObjectController*>::iterator it;
1696 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1697 GObjectController *cont = it->second;
1698 cont->removeFromScene();
1699 unregisterController((InteractorStyleMaracas*) cont);
1701 _selectedObjects.clear();
1702 _controllers.clear();
1705 //=========================================================================
1708 void wxVtkSceneManager::refresh() {
1709 _baseView->Refresh();
1711 //=========================================================================
1713 void wxVtkSceneManager::refreshScene() {
1714 _baseView->RefreshView();
1717 //=========================================================================
1719 void wxVtkSceneManager::centerView() {
1721 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1722 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1723 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1724 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1727 //=========================================================================
1729 void wxVtkSceneManager::saveDiagram(std::string &content) {
1732 content += "CATEGORY:";
1733 content += GetCategory();
1736 content += "DESCRIPTION:";
1737 content += GetDescription();
1740 content += "AUTHOR:";
1741 content += GetAuthor();
1744 //Print info IF COMPLEX BOX
1745 content += "COMPLEXBOX:";
1746 if (_isComplexBox) {
1747 content += "TRUE\n";
1749 content += "COMPLEXBOXNAME:";
1750 content += GetCbName();
1753 content += "PACKAGENAME:";
1754 content += GetCbPackageName();
1757 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1758 * External inputs are possible for applications and complex boxes
1759 //Print info complex input ports
1760 std::vector<int> inputs = getComplexInputPorts();
1761 int insize = inputs.size();
1762 content += "COMPLEXINPUTS:";
1763 sprintf(buffer, "%d", insize);
1767 for (int i = 0; i < insize; i++) {
1769 GObjectController *cont = _controllers[id];
1770 cont->getModel()->save(content);
1774 //Print info complex output ports
1775 std::vector<int> outputs = getComplexOutputPorts();
1776 int outsize = outputs.size();
1777 content += "COMPLEXOUTPUTS:";
1778 sprintf(buffer, "%d", outsize);
1782 for (int i = 0; i < outsize; i++) {
1783 int id = outputs[i];
1784 GObjectController *cont = _controllers[id];
1785 cont->getModel()->save(content);
1789 content += "FALSE\n";
1792 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1793 // External inputs are possible for applications and complex boxes
1794 std::vector<int> inputs = getComplexInputPorts();
1795 int insize = inputs.size();
1796 content += "COMPLEXINPUTS:";
1797 sprintf(buffer, "%d", insize);
1801 for (int i = 0; i < insize; i++) {
1803 GObjectController *cont = _controllers[id];
1804 cont->getModel()->save(content);
1808 std::vector<int> boxes = getBlackBoxes();
1809 int bsize = boxes.size();
1810 content += "BOXES:";
1811 sprintf(buffer, "%d", bsize);
1815 for (int i = 0; i < bsize; i++) {
1817 GObjectController *cont = _controllers[id];
1818 cont->getModel()->save(content);
1822 std::vector<int> connections = getConnections();
1823 int csize = connections.size();
1824 content += "CONNECTIONS:";
1825 sprintf(buffer, "%d", csize);
1829 for (int i = 0; i < csize; i++) {
1830 int id = connections[i];
1831 GObjectController *cont = _controllers[id];
1832 cont->getModel()->save(content);
1837 //=========================================================================
1838 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1840 getline(inputStream, line,'\n');
1841 int size = line.length();
1844 if ( line[ size-1 ]==13 )
1846 line.erase(size-1,1);
1851 //=========================================================================
1852 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1854 printf("EED wxVtkSceneManager::loadDiagram Start \n");
1856 std::string version = "<void>";
1857 std::string line = "";
1858 char delims[] = ":";
1859 char *result = NULL;
1860 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1862 getCleanLine(inputStream, line);
1865 while (!inputStream.eof()) {
1866 if (line == "" || line[0] == '#') {
1868 getCleanLine(inputStream, line);
1870 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1871 version = line.substr(18, 3);
1873 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1874 version = line.substr(18, 3);
1876 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1877 version = line.substr(18, 3);
1879 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1880 version = line.substr(18, 3);
1882 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1883 version = line.substr(18, 3);
1885 } else if (line == "APP_START") {
1894 if ((version != "1.0") && (version != "1.1")) {
1895 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1896 char categoryTmp[30];
1897 strcpy(categoryTmp, line.c_str());
1898 result = strtok(categoryTmp, delims);
1899 result = strtok(NULL, delims);
1900 SetCategory(result);
1902 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1903 char descriptionTmp[1024];
1904 strcpy(descriptionTmp, line.c_str());
1905 result = strtok(descriptionTmp, delims);
1906 result = strtok(NULL, delims);
1907 SetDescription(result);
1909 getCleanLine(inputStream, line);//AUTHOR:<author>
1910 char authorTmp[255];
1911 strcpy(authorTmp, line.c_str());
1912 result = strtok(authorTmp, delims);
1913 result = strtok(NULL, delims);
1918 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1919 char complexTmp[30];
1920 strcpy(complexTmp, line.c_str());
1921 result = strtok(complexTmp, delims);
1922 result = strtok(NULL, delims);
1923 std::string isComplexBox(result);
1925 if (isComplexBox == "TRUE") {
1926 _isComplexBox = true;
1928 if ((version != "1.0") && (version != "1.1")) {
1929 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
1930 char complexboxnameTmp[255];
1931 strcpy(complexboxnameTmp, line.c_str());
1932 result = strtok(complexboxnameTmp, delims);
1933 result = strtok(NULL, delims);
1936 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
1937 char packagenameTmp[255];
1938 strcpy(packagenameTmp, line.c_str());
1939 result = strtok(packagenameTmp, delims);
1940 result = strtok(NULL, delims);
1941 SetCbPackageName(result);
1946 //-----------------------
1947 //- COMPLEX INPUT PORTS
1948 //-----------------------
1949 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
1951 strcpy(inputs, line.c_str());
1952 result = strtok(inputs, delims);
1953 result = strtok(NULL, delims);
1956 std::istringstream inps(result);
1959 for (int i = 0; i < numInputs; i++) {
1961 getCleanLine(inputStream, line);//COMPLEX_PORT
1962 getCleanLine(inputStream, line);//name
1963 std::string inputPortName(line);
1966 getCleanLine(inputStream, line);//xInic:yInic:zInic
1968 strcpy(coord, line.c_str());
1969 result = strtok(coord, delims);//xInic
1970 std::string xInic(result);
1971 result = strtok(NULL, delims);//yInic
1972 std::string yInic(result);
1973 result = strtok(NULL, delims);//zInic
1974 std::string zInic(result);
1976 double xIn, yIn, zIn;
1977 std::istringstream xSt(xInic);
1979 std::istringstream ySt(yInic);
1981 std::istringstream zSt(zInic);
1986 if (zIn==900) zIn=GPOSITION_Z;
1989 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
1991 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
1993 } // for input complex box
1997 //-----------------------
1998 //- COMPLEX OUTPUT PORTS
1999 //-----------------------
2001 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2003 strcpy(outputs, line.c_str());
2004 result = strtok(outputs, delims);
2005 result = strtok(NULL, delims);
2008 std::istringstream outps(result);
2009 outps >> numOutputs;
2011 for (int i = 0; i < numOutputs; i++) {
2013 getCleanLine(inputStream, line);//COMPLEX_PORT
2014 getCleanLine(inputStream, line);//name
2015 std::string outputPortName(line);
2018 getCleanLine(inputStream, line);//xInic:yInic:zInic
2020 strcpy(coord, line.c_str());
2021 result = strtok(coord, delims);//xInic
2022 std::string xInic(result);
2023 result = strtok(NULL, delims);//yInic
2024 std::string yInic(result);
2025 result = strtok(NULL, delims);//zInic
2026 std::string zInic(result);
2028 double xIn, yIn, zIn;
2029 std::istringstream xSt(xInic);
2031 std::istringstream ySt(yInic);
2033 std::istringstream zSt(zInic);
2038 if (zIn==900) zIn=GPOSITION_Z;
2041 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2043 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2045 } // for output complex box
2049 // RaC2012 2nd Hackfest
2050 if(version >= "1.4")
2052 //-----------------------
2053 //- EXTERNAL INPUT PORTS
2054 //-----------------------
2055 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2057 strcpy(inputs, line.c_str());
2058 result = strtok(inputs, delims);
2059 result = strtok(NULL, delims);
2062 std::istringstream inps(result);
2065 for (int i = 0; i < numInputs; i++) {
2067 getCleanLine(inputStream, line);//COMPLEX_PORT
2068 getCleanLine(inputStream, line);//name
2069 std::string inputPortName(line);
2072 getCleanLine(inputStream, line);//xInic:yInic:zInic
2074 strcpy(coord, line.c_str());
2075 result = strtok(coord, delims);//xInic
2076 std::string xInic(result);
2077 result = strtok(NULL, delims);//yInic
2078 std::string yInic(result);
2079 result = strtok(NULL, delims);//zInic
2080 std::string zInic(result);
2082 double xIn, yIn, zIn;
2083 std::istringstream xSt(xInic);
2085 std::istringstream ySt(yInic);
2087 std::istringstream zSt(zInic);
2092 if (zIn==900) zIn=GPOSITION_Z;
2095 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2096 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2098 } // for external input
2103 getCleanLine(inputStream, line);//BOXES:num
2105 strcpy(boxes, line.c_str());
2106 result = strtok(boxes, delims);
2107 result = strtok(NULL, delims);
2110 std::istringstream is(result);
2113 for (int i = 0; i < numBoxes; i++) {
2115 getCleanLine(inputStream, line);//BOX
2116 getCleanLine(inputStream, line);//package:type:name
2118 strcpy(box, line.c_str());
2119 result = strtok(box, delims);//package
2120 std::string package(result);
2121 result = strtok(NULL, delims);//type
2122 std::string type(result);
2123 result = strtok(NULL, delims);//name
2124 std::string name(result);
2126 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2128 strcpy(exec, line.c_str());
2129 result = strtok(exec, delims);//ISEXEC
2130 result = strtok(NULL, delims);//TRUE|FALSE
2131 std::string isExec(result);
2134 getCleanLine(inputStream, line);//xInic:yInic:zInic
2136 strcpy(coord, line.c_str());
2137 result = strtok(coord, delims);//xInic
2138 std::string xInic(result);
2139 result = strtok(NULL, delims);//yInic
2140 std::string yInic(result);
2141 result = strtok(NULL, delims);//zInic
2142 std::string zInic(result);
2144 double xIn, yIn, zIn;
2145 std::istringstream xSt(xInic);
2147 std::istringstream ySt(yInic);
2149 std::istringstream zSt(zInic);
2155 if (zIn==900) zIn=GPOSITION_Z;
2160 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2161 strcpy(coord, line.c_str());
2162 result = strtok(coord, delims);//xEnd
2163 std::string xEnd(result);
2164 result = strtok(NULL, delims);//yEnd
2165 std::string yEnd(result);
2166 result = strtok(NULL, delims);//zEnd
2167 std::string zEnd(result);
2169 double xEn, yEn, zEn;
2170 std::istringstream xEt(xEnd);
2172 std::istringstream yEt(yEnd);
2174 std::istringstream zEt(zEnd);
2179 if (zEn==900) zEn=GPOSITION_Z;
2183 bool boxExecutable = false;
2184 if (isExec == "TRUE") {
2185 boxExecutable = true;
2188 int idBox = createGBlackBox(xIn, yIn, package, type);
2189 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2191 GObjectController *cont = _controllers[idBox];
2192 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2195 getCleanLine(inputStream, line);//PORT o FIN_BOX
2196 std::string port = line.substr(0, 4);
2197 while (port == "PORT")
2199 getCleanLine(inputStream, line);//name:value
2200 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2202 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2205 strcpy(poort, line.c_str());
2206 result = strtok(poort, delims);//name
2207 std::string name(result);
2209 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2210 result = strtok(NULL, delims);//value
2211 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2213 std::string tmpString=" ";
2214 tmpString[0]=34; // character "
2215 strcat(result,tmpString.c_str());
2217 std::string value(result);
2219 bbmod->setValueToInput(name, value);
2221 getCleanLine(inputStream, line);//PORT o FIN_BOX
2222 port = line.substr(0, 4);
2225 //EED bbmod->notifyObservers(_idManager);
2230 getCleanLine(inputStream, line);//CONNECTIONS:num
2232 strcpy(conns, line.c_str());
2233 result = strtok(conns, delims);
2234 result = strtok(NULL, delims);
2237 std::istringstream isCons(result);
2241 for (int i = 0; i < numConns; i++) {
2243 getCleanLine(inputStream, line);//CONNECTION
2244 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2247 strcpy(connec, line.c_str());
2248 result = strtok(connec, delims);
2249 std::string nameStartBox(result);
2250 result = strtok(NULL, delims);
2251 std::string nameStartPort(result);
2252 result = strtok(NULL, delims);
2253 std::string nameEndBox(result);
2254 result = strtok(NULL, delims);
2255 std::string nameEndPort(result);
2257 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2259 if (version != "1.0") {
2260 //Readding control points of the manualContour
2261 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2262 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2263 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2264 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2265 strcpy(conns, line.c_str());
2266 result = strtok(conns, delims);
2267 result = strtok(NULL, delims);
2269 int numberOfControlPoints;
2270 std::istringstream isCons(result);
2271 isCons >> numberOfControlPoints;
2273 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2274 getCleanLine(inputStream, line); //XX:YY:ZZ
2276 strcpy(connec, line.c_str());
2279 result = strtok(connec, delims);
2280 std::istringstream isPointX(result);
2282 result = strtok(NULL, delims);
2283 std::istringstream isPointY(result);
2285 result = strtok(NULL, delims);
2286 std::istringstream isPointZ(result);
2291 if (pz==900) pz=GPOSITION_Z;
2294 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2295 conView->getManualContourView()->AddPoint();
2303 printf("EED wxVtkSceneManager::loadDiagram End \n");
2306 //=========================================================================
2309 //=========================================================================
2310 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2311 std::string portName, double xIn, double yIn, double zIn) {
2313 if (inputoutput == true) {
2314 idPort = createGComplexBoxInputPort(portName);
2316 idPort = createGComplexBoxOutputPort(portName);
2318 GObjectController *cont = _controllers[idPort];
2319 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2320 cbmod->setInicPoint(xIn, yIn, zIn);
2321 cbmod->notifyObservers(_idManager);
2323 //=========================================================================
2326 //=========================================================================
2327 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
2331 GBoxModel *boxModel = NULL;
2332 std::vector<int> lstB = getBlackBoxes();
2333 for (j = 0; j < (int) lstB.size(); j++) {
2335 bMod = (GBoxModel*) _controllers[idB]->getModel();
2336 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2343 if (boxModel == NULL) {
2344 std::vector<int> lstInputs = getComplexInputPorts();
2345 for (j = 0; j < (int) lstInputs.size(); j++) {
2347 bMod = (GBoxModel*) _controllers[idB]->getModel();
2348 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2355 std::vector<int> lstOutputs = getComplexOutputPorts();
2356 for (j = 0; j < (int) lstOutputs.size(); j++) {
2357 int idB = lstOutputs[j];
2358 bMod = (GBoxModel*) _controllers[idB]->getModel();
2359 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2370 //=========================================================================
2373 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2374 std::string nameStartPort, std::string nameEndBox,
2375 std::string nameEndPort) {
2377 GBoxModel *boxModel;
2378 GPortModel *startP = NULL;
2379 GPortModel *endP = NULL;
2381 boxModel = findGBox(nameStartBox);
2382 if(boxModel == NULL)
2384 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2386 if (boxModel != NULL) {
2387 startP = boxModel->getOutputPort(nameStartPort);
2389 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port %s is null. Port name is probably wrong.\n", nameStartPort.c_str());
2393 boxModel = findGBox(nameEndBox);
2394 if(boxModel == NULL)
2396 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2398 if (boxModel != NULL) {
2399 endP = boxModel->getInputPort(nameEndPort);
2401 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port %s is null. Port name is probably wrong\n", nameStartPort.c_str(), nameEndPort.c_str());
2406 int idCon = createGConnector(startP);
2408 _worldState = NOTHING_HAPPENS;
2409 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2411 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2412 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2413 tempp->endContourCreation();
2414 conMod->setEndPort(endP);
2415 conView->updateStartEndPoints();
2419 //=========================================================================
2421 bool wxVtkSceneManager::boxExist(std::string boxname) {
2423 std::map<int, GObjectController*>::iterator it;
2424 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2425 GObjectController *cont = it->second;
2426 if (cont->getModel()->getBBTKName() == boxname) {
2433 //=========================================================================
2435 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2436 std::vector<int> vect;
2437 std::map<int, GObjectController*>::iterator it;
2438 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2439 GObjectController *cont = it->second;
2440 if (cont->getGObjectType() == GBLACKBOX) {
2441 vect.push_back(cont->getId());
2447 //=========================================================================
2449 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2450 std::vector<int> vect;
2451 std::map<int, GObjectController*>::iterator it;
2452 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2453 GObjectController *cont = it->second;
2454 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2455 vect.push_back(cont->getId());
2461 //=========================================================================
2463 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2464 std::vector<int> vect;
2465 std::map<int, GObjectController*>::iterator it;
2466 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2467 GObjectController *cont = it->second;
2468 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2469 vect.push_back(cont->getId());
2475 //=========================================================================
2477 std::vector<int> wxVtkSceneManager::getConnections() {
2478 std::vector<int> vect;
2479 std::map<int, GObjectController*>::iterator it;
2480 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2481 GObjectController *cont = it->second;
2482 if (cont->getGObjectType() == GCONNECTOR) {
2483 vect.push_back(cont->getId());
2489 //=========================================================================
2491 bool wxVtkSceneManager::isComplexBox() {
2492 return _isComplexBox;
2495 //=========================================================================
2497 void wxVtkSceneManager::setComplexBox(bool val) {
2498 _isComplexBox = val;
2501 //=========================================================================
2503 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2504 //Register the controller of the new object
2505 registerController((InteractorStyleMaracas*) objController);
2506 //Add the object to the objects list
2507 int newId = _contLastId;//_controllers.size();
2508 objController->setId(newId);
2509 _controllers[newId] = objController;
2510 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2515 //=========================================================================
2517 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2519 std::map<int, int> oldIdNewIdBoxes;
2520 std::vector<int> connections;
2522 std::vector<int> newBoxesID;
2524 std::map<int, GObjectController*>::iterator it;
2525 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2526 GObjectController *cont = it->second;
2527 int type = cont->getGObjectType();
2529 if (type == GBLACKBOX) {
2531 double xInic, yInic, zInic;
2532 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2533 copyBox->getInicPoint(xInic, yInic, zInic);
2534 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2535 copyBox->getBBTKType());
2537 int idcB = copyBox->getObjectId();
2538 oldIdNewIdBoxes[idcB] = idBox;
2539 cont = _controllers[idBox];
2540 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2541 newbox->setInicPoint(xInic, yInic, zInic);
2542 int num = newbox->getNumInputPorts();
2543 for (int j = 0; j < num; j++) {
2544 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2546 newbox->move(xInic + 20, yInic + 20, zInic);
2547 newbox->notifyObservers(_idManager);
2548 newBoxesID.push_back(newbox->getObjectId());
2550 } else if (type == GCONNECTOR) {
2551 int idCon = cont->getId();
2552 connections.push_back(idCon);
2557 for (int i = 0; i < (int) connections.size(); i++) {
2558 int objId = connections[i];
2559 GObjectController *cont = objectsMap[objId];
2560 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2562 GPortModel* startPort = connectModel->getStartPort();
2563 int startPortIndex = startPort->getPosInBox();
2564 GPortModel* endPort = connectModel->getEndPort();
2565 int endPortIndex = endPort->getPosInBox();
2567 GBlackBoxModel* startPortParentBox =
2568 (GBlackBoxModel*) startPort->getParentBox();
2569 GBlackBoxModel* endPortParentBox =
2570 (GBlackBoxModel*) endPort->getParentBox();
2572 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2573 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2575 GBlackBoxModel* newStartBox =
2576 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2577 GBlackBoxModel* newEndBox =
2578 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2580 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2581 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2583 // Creates connection
2584 int idCon = createGConnector(newStartPort);
2585 GConnectorController *tempp =
2586 (GConnectorController*) _controllers[idCon];
2587 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2588 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2589 tempp->endContourCreation();
2590 conMod->setEndPort(newEndPort);
2591 conView->updateStartEndPoints();
2594 /// the new selected boxes are the duplicate ones
2596 UnSelectBlackBoxes();
2597 for (int i = 0; i < newBoxesID.size(); i++) {
2598 _selectedObjects.push_back(newBoxesID.at(i));
2601 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2602 int id = _selectedObjects[i];
2603 GObjectController* cont = _controllers[id];
2605 cont->getView()->setState(SELECTED);
2606 cont->getModel()->notifyObservers(_idManager);
2612 //=========================================================================
2614 int wxVtkSceneManager::getNumSelectedObjects() {
2615 return _selectedObjects.size();
2618 //=========================================================================
2620 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2621 std::map<int, GObjectController*> mapSelected;
2623 std::map<int, GObjectController*>::iterator it;
2624 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2625 GObjectController *cont = it->second;
2626 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2628 mapSelected[cont->getId()] = cont;
2632 std::map<int, GObjectController*>::iterator it2;
2633 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2634 GObjectController *cont = it2->second;
2635 if (cont->getGObjectType() == GCONNECTOR) {
2636 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2637 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2638 GBoxModel* startPortParentBox =
2639 cmod->getStartPort()->getParentBox();
2641 std::map<int, GObjectController*>::iterator iterOBJ1 =
2642 mapSelected.find(startPortParentBox->getObjectId());
2643 std::map<int, GObjectController*>::iterator iterOBJ2 =
2644 mapSelected.find(endPortParentBox->getObjectId());
2646 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2647 int ID = cont->getId();
2648 mapSelected[ID] = cont;
2655 //=========================================================================
2657 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2659 std::map<int, int> oldIdNewIdBoxes;
2660 std::vector<int> connections;
2662 std::map<int, GObjectController*>::iterator it;
2663 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2664 GObjectController *cont = it->second;
2665 int type = cont->getGObjectType();
2667 if (type == GBLACKBOX) {
2669 double xInic, yInic, zInic;
2670 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2671 copyBox->getInicPoint(xInic, yInic, zInic);
2672 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2674 int idcB = copyBox->getObjectId();
2675 oldIdNewIdBoxes[idcB] = idBox;
2676 cont = _controllers[idBox];
2677 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2678 newbox->setInicPoint(xInic, yInic, zInic);
2679 int num = newbox->getNumInputPorts();
2680 for (int j = 0; j < num; j++)
2682 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2684 newbox->notifyObservers(_idManager);
2685 } else if (type == GCONNECTOR) {
2686 int idCon = cont->getId();
2687 connections.push_back(idCon);
2692 for (int i = 0; i < (int) connections.size(); i++) {
2693 int objId = connections[i];
2694 GObjectController *cont = objectsMap[objId];
2695 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2697 GPortModel* startPort = connectModel->getStartPort();
2698 int startPortIndex = startPort->getPosInBox();
2699 GPortModel* endPort = connectModel->getEndPort();
2700 int endPortIndex = endPort->getPosInBox();
2702 GBlackBoxModel* startPortParentBox =
2703 (GBlackBoxModel*) startPort->getParentBox();
2704 GBlackBoxModel* endPortParentBox =
2705 (GBlackBoxModel*) endPort->getParentBox();
2707 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2708 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2710 GBlackBoxModel* newStartBox =
2711 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2712 GBlackBoxModel* newEndBox =
2713 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2715 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2716 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2718 // Creates connection
2719 int idCon = createGConnector(newStartPort);
2720 GConnectorController *tempp =
2721 (GConnectorController*) _controllers[idCon];
2722 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2723 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2724 tempp->endContourCreation();
2725 conMod->setEndPort(newEndPort);
2726 conView->updateStartEndPoints();
2729 std::map<int, int>::iterator itIds;
2730 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2731 int idOld = itIds->first;
2732 int idNew = itIds->second;
2734 GBlackBoxModel* oldBox =
2735 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2736 GBlackBoxModel* newBox =
2737 (GBlackBoxModel*) _controllers[idNew]->getModel();
2739 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2740 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2741 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2742 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2744 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2746 //EED int toCreate=-1;
2747 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2748 if (oldInputConnections[k] == newInputConnections[l]) {
2753 if (exist == false) {
2754 //Create complex input
2755 int posInBox = oldInputConnections[k];
2756 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2757 std::string inputPortName = inputPort->getBBTKName();
2758 int idInputPort = createGComplexBoxInputPort(inputPortName);
2759 GObjectController *cont = _controllers[idInputPort];
2760 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2761 double xIn, yIn, zIn;
2762 inputPort->getInicPoint(xIn, yIn, zIn);
2764 cbmod->setInicPoint(xIn, yIn, zIn);
2765 cbmod->notifyObservers(_idManager);
2767 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2769 // Creates connection
2770 int idCon = createGConnector(cbmod->getOutputPort(0));
2771 GConnectorController *tempp =
2772 (GConnectorController*) _controllers[idCon];
2773 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2774 vtkGConnectorView *conView =
2775 (vtkGConnectorView*) tempp->getView();
2776 tempp->endContourCreation();
2777 conMod->setEndPort(inputPortEnd);
2778 conView->updateStartEndPoints();
2784 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2786 //EED int toCreate=-1;
2787 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2788 if (oldOutputConnections[k] == newOutputConnections[l]) {
2793 if (exist == false) {
2794 //Create complex output
2795 int posInBox = oldOutputConnections[k];
2796 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2797 std::string outputPortName = outputPort->getBBTKName();
2798 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2799 GObjectController *cont = _controllers[idOutputPort];
2800 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2801 double xIn, yIn, zIn;
2802 outputPort->getInicPoint(xIn, yIn, zIn);
2804 cbmod->setInicPoint(xIn, yIn, zIn);
2805 cbmod->notifyObservers(_idManager);
2807 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2809 // Creates connection
2810 int idCon = createGConnector(outputPortEnd);
2811 GConnectorController *tempp =
2812 (GConnectorController*) _controllers[idCon];
2813 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2814 vtkGConnectorView *conView =
2815 (vtkGConnectorView*) tempp->getView();
2816 tempp->endContourCreation();
2817 conMod->setEndPort(cbmod->getInputPort(0));
2818 conView->updateStartEndPoints();
2828 //=========================================================================
2829 void wxVtkSceneManager::SetCbName(std::string cbName) {
2831 if (_cbName == "") {
2832 _cbName = "<complex box name>";
2836 //=========================================================================
2837 std::string wxVtkSceneManager::GetCbName() {
2841 //=========================================================================
2842 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2843 _cbPackageName = packagename;
2844 if (_cbPackageName == "") {
2845 _cbPackageName = "<package name of the complex box>";
2849 //=========================================================================
2850 std::string wxVtkSceneManager::GetCbPackageName() {
2851 return _cbPackageName;
2854 //=========================================================================
2855 void wxVtkSceneManager::SetAuthor(std::string author) {
2857 if (_Author == "") {
2858 _Author = "<author of the box>";
2862 //=========================================================================
2863 std::string wxVtkSceneManager::GetAuthor() {
2867 //=========================================================================
2868 void wxVtkSceneManager::SetCategory(std::string category) {
2869 _Category = category;
2870 if (_Category == "") {
2871 _Category = "<category of the box>";
2875 //=========================================================================
2876 std::string wxVtkSceneManager::GetCategory() {
2880 //=========================================================================
2881 void wxVtkSceneManager::SetDescription(std::string description) {
2882 _Description = description;
2883 if (_Description == "") {
2884 _Description = "<description of the box>";
2888 //=========================================================================
2889 std::string wxVtkSceneManager::GetDescription() {
2890 return _Description;
2893 //=========================================================================
2895 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
2898 std::vector< std::string> extInputs;
2899 std::map<int, GObjectController*>::iterator it;
2900 for (it = _controllers.begin(); it != _controllers.end(); ++it)
2902 GObjectController *cont = it->second;
2903 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
2905 extInputs.push_back(cont->getModel()->getBBTKName());
2911 //=========================================================================
2915 void wxVtkSceneManager::printAll(int com , int sta ){
2917 int tmpState = sta ;
2918 if ( tmpState == NOTHING_HAPPENS ) {
2919 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2921 if ( tmpState == HIGHLIGHTED ) {
2922 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2924 if ( tmpState == POSSIBLE_CONNECTION ) {
2925 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2927 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2928 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2930 if ( tmpState == CLICKED ) {
2931 std::cout << "CONTROLER STATE---->CLICKED\n" ;
2933 if ( tmpState == DRAG ) {
2934 std::cout << "CONTROLER STATE---->DRAG\n" ;
2936 if ( tmpState == SELECTED ) {
2937 std::cout << "CONTROLER STATE---->SELECTED\n" ;
2939 if ( tmpState == CREATING_CONTOUR ) {
2940 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2946 if ( command == INIT_CREATION_CONTOUR ) {
2947 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2949 if ( command == FIN_CREATION_CONTOUR ) {
2950 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2952 if ( command == ADD_TO_SELECTED ) {
2953 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2955 if ( command == DRAG_OBJECTS ) {
2956 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2958 if ( command == EDIT_BLACKBOX ) {
2959 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
2961 if ( command == REMOVE_FROM_SELECTED ) {
2962 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
2968 } // EO namespace bbtk