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"
39 #include <vtkPolygon.h>
40 #include <vtkUnstructuredGrid.h>
46 //=========================================================================
47 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent,
48 wxVtk3DBaseView *baseView, int idManager) {
49 _cbName = "ComplexBoxName";
50 _cbPackageName = "PackageName";
51 _Author = "Author ??";
53 _Description = "Description ??";
57 _idManager = idManager;
59 _startDragging = false;
60 _isComplexBox = false;
62 if (_baseView != NULL) {
65 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n", this);
69 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
74 _worldState = NOTHING_HAPPENS;
75 registerController(this);
78 _idConnectionInCreation = -1;
83 //=========================================================================
85 void wxVtkSceneManager::disconnectDrop() {
86 printf("EED %p ~wxVtkSceneManager::disconnectDrop()\n", this);
87 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
88 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
91 //=========================================================================
93 wxVtkSceneManager::~wxVtkSceneManager() {
95 printf("EED %p ~wxVtkSceneManager()\n", this);
100 //=========================================================================
102 void wxVtkSceneManager::configureBaseView() {
103 printf("EED wxVtkSceneManager::configureBaseView 0\n");
104 vtkInteractorStyleBaseView2D *interactorstylebaseview =
105 vtkInteractorStyleBaseView2D::New();
107 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
109 // Important to activate the 2D interaction system
110 wxVTKRenderWindowInteractor *iren =
111 _baseView->GetWxVTKRenderWindowInteractor();
112 interactorstylebaseview->SetInteractor(iren);
113 iren->SetInteractorStyle(interactorstylebaseview);
114 interactorstylebaseview->SetwxVtkBaseView(_baseView);
116 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
117 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, 800, 1100);
119 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
120 _baseView->GetRenderer()->GradientBackgroundOn();
121 _baseView->Refresh();
124 _textActor = vtkTextActor3D::New();
125 _textActor->SetPosition(-9999, -9999, 900);
126 _textActor->SetInput("<void>");
127 _textActor->GetTextProperty()->SetFontSize(60);
128 _textActor->GetTextProperty()->BoldOn();
129 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,
132 _baseView->GetRenderer()->AddActor(_textActor);
134 // Actor Fill_Port_Text
141 vtkPolygon *aPolygon = vtkPolygon::New();
142 _fillObjectActor = vtkActor::New();
144 _pts = vtkPoints::New();
146 double w = 100, h = 10, b = h / 15, t = 3;
147 _pts->SetNumberOfPoints(21);
148 _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
149 _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
150 _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
151 _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
152 _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
154 _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
155 _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
156 _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
157 _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
159 _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
160 _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
161 _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
162 _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
164 _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
165 _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
166 _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
167 _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
169 _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
170 _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
171 _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
172 _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
174 aPolygon->GetPointIds()->SetNumberOfIds(21);
175 for (int i = 0; i < 21; i++) {
176 aPolygon->GetPointIds()->SetId(i, i);
179 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
180 aPolygonGrid->Allocate(1, 1);
181 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),
182 aPolygon->GetPointIds());
183 aPolygonGrid->SetPoints(_pts);
184 _aPolygonMapper = vtkDataSetMapper::New();
185 _aPolygonMapper->SetInput(aPolygonGrid);
186 _fillObjectActor->SetMapper(_aPolygonMapper);
187 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
189 _fillObjectActor->GetProperty()->SetOpacity(0);
190 _aPolygonMapper->Modified();
192 _baseView->GetRenderer()->AddActor(_fillObjectActor);
193 printf("EED wxVtkSceneManager::configureBaseView 1\n");
196 //=========================================================================
198 std::string wxVtkSceneManager::generateANewNameForABox() {
199 std::stringstream boxname;
200 if (_numBoxes < 10) {
201 boxname << "Box0" << _numBoxes;
203 boxname << "Box" << _numBoxes;
206 return boxname.str();
209 //=========================================================================
211 std::string wxVtkSceneManager::findANewNameForABox() {
212 std::string boxname = generateANewNameForABox();
214 while (boxExist(boxname) == true) {
215 boxname = generateANewNameForABox();
221 //=========================================================================
222 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
223 double zIn, std::string name, bool boxExecutable, double xEn,
224 double yEn, double zEn) {
225 GObjectController *cont = _controllers[idBox];
226 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
227 bbmod->setBBTKName(name);
228 bbmod->setInicPoint(xIn, yIn, zIn);
229 bbmod->setFinalPoint(xEn, yEn, zEn);
230 bbmod->setExecutable(boxExecutable);
232 bbmod->notifyObservers(_idManager);
236 //=========================================================================
238 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,
239 std::string boxType) {
240 _worldState = NOTHING_HAPPENS;
241 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
242 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
244 int type = GBLACKBOX;
246 //Create the MVC Objects
250 (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
252 vtkGObjectView *view =
253 GObjectsMVCFactory::getInstance()->createGObjectView(type);
254 GObjectController* controller =
255 GObjectsMVCFactory::getInstance()->createGObjectController(type);
257 BlackBoxDescriptor::Pointer descriptor =
258 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
259 packageName, boxType);
261 //Prepares the initial model
262 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
265 double yy = windowHeight - y;
267 //z value is not important yet, because it is only used a parallel projection
269 _baseView->TransCoordScreenToWorld(xx, yy, zz);
270 model->setInicPoint(xx, yy, zz);
272 std::stringstream stream;
274 std::string newBoxName;
275 newBoxName = findANewNameForABox();
277 stream << newBoxName;
279 std::string arraystring = stream.str();
281 model->setBBTKName(arraystring);
282 model->setBBTKType(boxType);
283 model->setBBTKPackage(packageName);
285 model->addObserver(view);
286 model->addObserver(this);
288 //Iterate and create the input ports
289 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
290 descriptor->GetInputDescriptorMap();
291 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
294 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) {
295 BlackBoxInputDescriptor *desc = itInput->second;
296 createGInputPort(GINPUTPORT, i, model, desc);
300 //Iterate and create the output ports
301 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
302 descriptor->GetOutputDescriptorMap();
303 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
306 for (itOutput = descriptorOutMap.begin(); itOutput
307 != descriptorOutMap.end(); ++itOutput) {
308 BlackBoxOutputDescriptor *desc = itOutput->second;
309 createGOutputPort(GOUTPUTPORT, i, model, desc);
313 //Associates the view with the correspondent renderer and the model.
314 //(NOTE: Refresh is only made by the view)
315 view->setModel(model);
316 view->setBaseView(_baseView);
317 view->initVtkObjects();
319 //Associates the controller with the correspondent model and view
320 controller->setModelAndView(model, view);
322 //Resgiter change to the observers of the actual model
323 model->notifyObservers(_idManager);
325 int newId = addObjectController(controller);
331 //=========================================================================
333 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
334 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
335 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
337 int type = GCOMPLEXINPUTPORT;
339 //Create the MVC Objects
343 (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
345 vtkGObjectView *view =
346 GObjectsMVCFactory::getInstance()->createGObjectView(type);
347 GObjectController* controller =
348 GObjectsMVCFactory::getInstance()->createGObjectController(type);
350 //Prepares the initial model
353 double yy = windowHeight - 5;
355 //z value is not important yet, because it is only used a parallel projection
357 printf("EED wxVtkSceneManager::createGComplexBoxInputPort 900-450\n");
359 _baseView->TransCoordScreenToWorld(xx, yy, zz);
360 model->setInicPoint(xx, yy, zz);
362 model->setBBTKName(inputName);
363 model->setBBTKType("ComplexInputPort");
364 model->setComplexPortType(type);
366 model->addObserver(view);
367 model->addObserver(this);
369 //create the output port
370 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
371 "ComplexInputPort", 0, model);
372 model->addOutputPort((GPortModel*) portController->getModel());
374 //Associates the view with the correspondent renderer and the model.
375 //(NOTE: Refresh is only made by the view)
376 view->setModel(model);
377 view->setBaseView(_baseView);
378 view->initVtkObjects();
380 //Associates the controller with the correspondent model and view
381 controller->setModelAndView(model, view);
383 //Resgiter change to the observers of the actual model
384 model->notifyObservers(_idManager);
386 int newId = addObjectController(controller);
390 //=========================================================================
392 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
393 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
394 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
396 int type = GCOMPLEXOUTPUTPORT;
398 //Create the MVC Objects
402 (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
404 vtkGObjectView *view =
405 GObjectsMVCFactory::getInstance()->createGObjectView(type);
406 GObjectController *controller =
407 GObjectsMVCFactory::getInstance()->createGObjectController(type);
409 //Prepares the initial model
412 double yy = windowHeight - 5;
414 //z value is not important yet, because it is only used a parallel projection
417 printf("EED wxVtkSceneManager::createGComplexBoxOutputPort 900-450\n");
419 _baseView->TransCoordScreenToWorld(xx, yy, zz);
420 model->setInicPoint(xx, yy, zz);
422 model->setBBTKName(outputName);
423 model->setBBTKType("ComplexOutputPort");
424 model->setComplexPortType(type);
426 model->addObserver(view);
427 model->addObserver(this);
429 //create the output port
430 GPortController* portController = createGPort(GINPUTPORT, outputName,
431 "ComplexInputPort", 0, model);
432 model->addInputPort((GPortModel*) portController->getModel());
434 //Associates the view with the correspondent renderer and the model.
435 //(NOTE: Refresh is only made by the view)
436 view->setModel(model);
437 view->setBaseView(_baseView);
438 view->initVtkObjects();
440 //Associates the controller with the correspondent model and view
441 controller->setModelAndView(model, view);
443 //Resgiter change to the observers of the actual model
444 model->notifyObservers(_idManager);
446 int newId = addObjectController(controller);
450 //=========================================================================
452 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,
453 GBoxModel *blackBox, BlackBoxInputDescriptor *desc) {
454 GPortController* portController = createGPort(portType, desc->GetName(),
455 desc->GetTypeName(), posinBox, blackBox);
456 blackBox->addInputPort((GPortModel*) portController->getModel());
457 return portController->getId();
460 //=========================================================================
462 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,
463 GBoxModel *blackBox, BlackBoxOutputDescriptor *desc) {
464 GPortController* portController = createGPort(portType, desc->GetName(),
465 desc->GetTypeName(), posinBox, blackBox);
466 blackBox->addOutputPort((GPortModel*) portController->getModel());
467 return portController->getId();
470 //=========================================================================
472 GPortController* wxVtkSceneManager::createGPort(int portType,
473 std::string bbtkName, std::string bbtkType, int posInBox,
474 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);
492 model->addObserver(view);
493 model->addObserver(this);
495 //Associates the view with the correspondent renderer and the model.
496 //(NOTE: Refresh is only made by the view)
497 view->setModel(model);
498 view->setBaseView(_baseView);
499 view->initVtkObjects();
501 //Associates the controller with the correspondent model and view
502 controller->setModelAndView(model, view);
504 model->notifyObservers(_idManager);
506 addObjectController(controller);
508 return (GPortController*) controller;
511 //=========================================================================
513 int wxVtkSceneManager::createGConnector(GPortModel* startPort) {
514 int type = GCONNECTOR;
516 manualConnectorContourController* manContourControl =
517 new manualConnectorContourController();
518 manualConnectorContourView* manContourView =
519 new manualConnectorContourView();
520 manualContourModel* manContourModel = new manualContourModel();
522 GConnectorController* connectorcontroller = new GConnectorController();
523 GConnectorModel* connectorModel = new GConnectorModel();
524 vtkGConnectorView* connectorView = new vtkGConnectorView();
525 connectorModel->setGObjectType(type);
527 manContourModel->SetCloseContour(false);
528 connectorModel->setStartPort(startPort);
530 manContourView->SetModel(manContourModel);
531 manContourView->SetWxVtkBaseView(_baseView);
532 manContourView->SetRange(0.5);
533 manContourView->SetZ(900);
535 manContourView->SetColorNormalContour(0, 0, 1);
536 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
537 manContourView->SetColorSelectContour(1, 0.8, 0);
542 * Width increased from 2 to 5, it simplifies line handling and spline control :P
546 manContourView->SetWidthLine( 5 ) ;
549 manContourView->SetShowText(false);
551 manContourControl->SetModelView(manContourModel, manContourView);
553 manContourControl->CreateNewManualContour();
555 manContourView->RefreshContour();
558 connectorModel->getInicPoint(x, y, z);
560 manContourControl->SetState(1);
561 manContourModel->SetCloseContour(false);
563 manContourModel->AddPoint(x, y, z);
564 manContourView->AddPoint();
566 manContourModel->AddPoint(x, y, z);
567 manContourView->AddPoint();
569 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
570 manContourControl->_bakIdPoint = bak;
571 manContourView->Refresh();
573 manContourControl->SetMoving(false);
575 connectorcontroller->setModelAndView(connectorModel, connectorView);
577 int newId = addObjectController(connectorcontroller);
579 connectorcontroller->setManualContourController(manContourControl);
580 connectorModel->setManualContourModel(manContourModel);
581 connectorView->setManualContourView(manContourView);
582 connectorView->setModel(connectorModel);
583 connectorView->setBaseView(_baseView);
585 connectorModel->addObserver(connectorView);
586 connectorModel->addObserver(this);
591 //=========================================================================
593 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param) {
594 vtkInteractorStyleBaseView
595 * baseViewControlManager =
596 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
597 baseViewControlManager->AddInteractorStyleMaracas(param);
600 //=========================================================================
602 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param) {
603 vtkInteractorStyleBaseView
604 * baseViewControlManager =
605 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
606 baseViewControlManager->RemoveInteractorStyleMaracas(param);
609 //=========================================================================
611 vtkRenderer* wxVtkSceneManager::getRenderer() {
612 return _baseView->GetRenderer();
615 //=========================================================================
617 vtkRenderWindow* wxVtkSceneManager::getRenderWindow() {
618 return _baseView->GetRenWin();
620 //=========================================================================
623 //=========================================================================
624 int wxVtkSceneManager::GetIndexInSelected(int idControler) {
626 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
627 if (_selectedObjects[i] == idControler) {
634 //=========================================================================
636 void wxVtkSceneManager::update(int idController, int command) {
638 if (command != NO_COMMAND) {
639 if (command == ADD_TO_SELECTED) {
640 //EEDBorrame GObjectController* cont = _controllers[idController];
642 if (GetIndexInSelected(idController) == -1) {
643 _selectedObjects.push_back(idController);
647 // bool foundID=false;
648 // for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
650 // if(_selectedObjects[i]==idController)
657 // _selectedObjects.push_back(idController);
660 } else if (command == REMOVE_FROM_SELECTED) {
661 int index = GetIndexInSelected(idController);
663 _selectedObjects.erase(_selectedObjects.begin() + index);
665 } else if (command == INIT_CREATION_CONTOUR) {
666 _worldState = INIT_CREATION_CONTOUR;
667 GObjectController* cont = _controllers[idController];
668 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
670 // The last one is the controller of the connector
671 std::map<int, GObjectController*>::iterator it2;
673 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
674 GObjectController *cont = it2->second;
675 if (cont->getGObjectType() == GPORT) {
676 GPortModel* port = (GPortModel*) cont->getModel();
677 if (port->getPortType() == GINPUTPORT) {
678 cont->SetActive(true);
680 cont->getView()->setState(NOTHING_HAPPENS);
681 cont->getModel()->notifyObservers(_idManager);
682 cont->SetActive(false);
685 cont->getView()->setState(NOTHING_HAPPENS);
686 cont->getModel()->notifyObservers(_idManager);
687 cont->SetActive(false);
690 _selectedObjects.clear();
691 _idConnectionInCreation = createGConnector(startOutputPort);
692 } else if (command == FIN_CREATION_CONTOUR && _worldState
693 == INIT_CREATION_CONTOUR) {
694 _worldState = NOTHING_HAPPENS;
695 //int id = _controllers.size()-1;
696 GObjectController *cont = _controllers[_idConnectionInCreation];
697 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
698 GObjectController *finPort = _controllers[idController];
700 if (finPort->getGObjectType() == GPORT) {
701 GPortModel* modelPort = (GPortModel*) finPort->getModel();
702 modelContour->setEndPort(modelPort);
703 _parent->saveTempDiagram();
706 manualConnectorContourController
708 ((GConnectorController*) cont)->getManualContourController();
709 manualConnectorContourView
711 (manualConnectorContourView*) manCont->GetManualViewBaseContour();
714 std::map<int, GObjectController*>::iterator it2;
716 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
717 GObjectController *cont = it2->second;
718 if (cont->getView() != NULL) {
719 cont->getView()->setState(NOTHING_HAPPENS);
720 cont->getModel()->notifyObservers(_idManager);
722 cont->SetActive(true);
730 //=========================================================================
732 bool wxVtkSceneManager::OnMouseMove() {
734 bool okStatusMessage = false;
735 bool okPortMessage = false;
736 wxVTKRenderWindowInteractor *wxVTKiren;
738 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
739 wxVTKiren->GetEventPosition(X, Y);
741 if (_worldState == DRAG_OBJECTS) {
742 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
743 int id = _selectedObjects[i];
744 GObjectController* cont = _controllers[id];
745 if (_startDragging) {
746 cont->getView()->setStartDragging(true);
748 cont->getView()->moveObject(X, Y);
749 cont->getView()->setState(DRAG);
750 cont->getModel()->notifyObservers(_idManager);
753 std::map<int, GObjectController*>::iterator it;
755 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
756 GObjectController *desc = it->second;
757 if (desc->getGObjectType() == GCONNECTOR) {
758 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
759 vconn->updateStartEndPoints();
763 _startDragging = false;
765 } else if (_worldState == NOTHING_HAPPENS || _worldState
766 == INIT_CREATION_CONTOUR) {
767 std::map<int, GObjectController*>::iterator it;
769 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
770 GObjectController *desc = it->second;
771 int type = desc->getGObjectType();
772 int state = desc->getView()->getState();
773 desc->getModel()->getCenter(px, py, pz);
775 if (state == HIGHLIGHTED) {
776 okStatusMessage = true;
777 updateStatusBar(desc->getStatusText());
778 if (type == GBLACKBOX) {
779 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
780 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),
785 okPortMessage = true;
787 _textActor->SetInput(desc->getStatusText().c_str());
788 _textActor->SetScale(0.1);
789 _textActor->SetPosition(px - 25, py + 1, pz + 2);
794 _fillObjectActor->SetScale(1);
795 _fillObjectActor->GetProperty()->SetOpacity(0.50);
796 _fillObjectActor->SetPosition(px, py, 1);
797 _aPolygonMapper->Modified();
800 } // for controllers it
803 if (okStatusMessage == false) {
807 if (okPortMessage == false) {
808 _textActor->SetScale(0.0001);
809 _fillObjectActor->SetScale(0.0001);
814 //=========================================================================
816 bool wxVtkSceneManager::OnLeftButtonDown() {
818 if (_worldState == INIT_CREATION_CONTOUR) {
819 bool isOverPort = false;
820 std::map<int, GObjectController*>::iterator it;
821 for (it = _controllers.begin(); it != _controllers.end() && isOverPort
823 GObjectController *desc = it->second;
824 if (desc->getGObjectType() == GPORT) {
825 GPortModel *portmod = (GPortModel*) desc->getModel();
826 vtkGObjectView *portView = desc->getView();
827 if (portmod->getPortType() == GINPUTPORT
828 && portView->getState() == HIGHLIGHTED) {
834 if (isOverPort == false) {
836 UnSelectBlackBoxes();
840 } else { //_worldState
842 _worldState = DRAG_OBJECTS;
843 _startDragging = true;
846 _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
848 _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
849 ctrlkey = ctrlkey + shiftkey;
851 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
853 if (GetGBlackBoxControlerPointedByMouse() != NULL) {
854 int state = cont->getView()->getState();
855 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
856 UnSelectBlackBoxes();
859 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
860 int id = _selectedObjects[i];
861 GObjectController* cont = _controllers[id];
862 cont->getView()->setState(DRAG);
863 cont->getModel()->notifyObservers(_idManager);
866 } // if _selectedObjects.size
872 //=========================================================================
874 bool wxVtkSceneManager::OnLeftButtonUp() {
875 if (_worldState == DRAG_OBJECTS) {
876 _worldState = NOTHING_HAPPENS;
878 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
879 int id = _selectedObjects[i];
880 GObjectController* cont = _controllers[id];
881 cont->getView()->setState(SELECTED);
882 cont->getModel()->notifyObservers(_idManager);
888 //=========================================================================
889 void wxVtkSceneManager::CancelConnection() {
890 if (_worldState == INIT_CREATION_CONTOUR) {
891 _worldState = NOTHING_HAPPENS;
892 //int lastId = _controllers.size()-1;
894 GConnectorController *connector =
895 (GConnectorController*) _controllers[_idConnectionInCreation];
896 connector->removeFromScene();
897 unregisterController(connector);
898 _controllers.erase(_idConnectionInCreation);
900 std::map<int, GObjectController*>::iterator it;
901 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
902 GObjectController *desc = it->second;
903 desc->SetActive(true);
904 desc->getView()->setState(NOTHING_HAPPENS);
905 desc->getModel()->notifyObservers(_idManager);
910 //=========================================================================
912 bool wxVtkSceneManager::OnRightButtonUp() {
913 if (_worldState == INIT_CREATION_CONTOUR) {
916 UnSelectBlackBoxes();
922 bool wxVtkSceneManager::OnMiddleButtonDown() {
925 this->_vtkInteractorStyleBaseView->StartPan();
930 bool wxVtkSceneManager::OnMiddleButtonUp() {
933 this->_vtkInteractorStyleBaseView->EndPan();
940 //=========================================================================
942 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
943 GObjectController *result = NULL;
945 wxVTKRenderWindowInteractor *wxVTKiren;
947 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
948 wxVTKiren->GetEventPosition(X, Y);
950 std::map<int, GObjectController*>::iterator it;
952 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
953 GObjectController *cont = it->second;
954 int type = cont->getGObjectType();
956 if (cont->getView()->isPointInside(X, Y) == true) {
957 if (type == GBLACKBOX) {
960 } // if isPointInside
965 //=========================================================================
966 void wxVtkSceneManager::UnSelectBlackBoxes() {
967 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
968 int id = _selectedObjects[i];
969 GObjectController* control = _controllers[id];
970 control->getView()->setState(NOTHING_HAPPENS);
971 }// for _selectedObjects
972 _selectedObjects.clear();
975 //=========================================================================
976 bool wxVtkSceneManager::OnLeftDClick() {
977 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
979 UnSelectBlackBoxes();
980 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
986 wxVTKRenderWindowInteractor *wxVTKiren;
987 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
988 wxVTKiren->GetEventPosition(X,Y);
990 std::map<int, GObjectController*>::iterator it;
992 bool clickOnObject = false;
994 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
996 GObjectController *cont = it->second;
997 int type = cont->getGObjectType();
999 if(cont->getView()->isPointInside(X,Y))
1003 for (int i=0; i< (int)_selectedObjects.size(); i++)
1005 int id = _selectedObjects[i];
1006 GObjectController* control = _controllers[id];
1007 control->getView()->setState(NOTHING_HAPPENS);
1009 _selectedObjects.clear();
1011 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1012 _parent->editBlackBox(bbmodel);
1014 clickOnObject = true;
1018 if(clickOnObject==false)
1020 //_parent->editDiagramParameters(this);
1026 //=========================================================================
1028 bool wxVtkSceneManager::OnChar() {
1029 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1030 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1032 // KeyCode 127 : Delete Key
1033 // KeyCode 8 : Backspace Key
1034 if (keyCode == 8 || keyCode == 127) {
1035 if (_selectedObjects.size() > 0) {
1036 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1037 int id = _selectedObjects[i];
1038 std::map<int, GObjectController*>::iterator it;
1039 it = _controllers.find(id);
1040 if (it != _controllers.end()) {
1044 _selectedObjects.clear();
1050 if(_selectedObjects.size()){
1051 std::cout<<"objects to copy :";
1052 for(int i=0;i<_selectedObjects.size();i++){
1053 std::cout<<_selectedObjects.at(i)<<" ";
1055 DuplicateObjects(getSelectedObjects());
1057 std::cout<<"No objects to copy\n";
1064 //=========================================================================
1066 void wxVtkSceneManager::AddControlerToBeRemove(
1067 std::vector<int> *controllersToRemove, int id) {
1071 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1072 if (id == (*controllersToRemove)[i]) {
1078 controllersToRemove->push_back(id);
1083 //=========================================================================
1085 void wxVtkSceneManager::deleteObject(int id) {
1086 GObjectController *control = _controllers[id];
1087 std::vector<int> controllersToRemove;
1089 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1090 == GCOMPLEXINPUTPORT || control->getGObjectType()
1091 == GCOMPLEXOUTPUTPORT) {
1092 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1093 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1095 bool boxConnected = false;
1097 // Add box input controllers to be removed
1098 for (int i = 0; i < (int) inputs.size(); i++) {
1099 AddControlerToBeRemove(&controllersToRemove,
1100 inputs[i]->getObjectId());
1101 if (inputs[i]->isConnected()) {
1102 boxConnected = true;
1106 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1108 // Add box output controllers to be removed
1109 for (int i = 0; i < (int) outputs.size(); i++) {
1110 AddControlerToBeRemove(&controllersToRemove,
1111 outputs[i]->getObjectId());
1112 if (outputs[i]->isConnected()) {
1113 boxConnected = true;
1117 // Add connection controllers to be removed
1118 std::map<int, GObjectController*>::iterator it;
1119 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1120 GObjectController *cont = it->second;
1121 int type = cont->getGObjectType();
1122 if (type == GCONNECTOR) {
1123 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1124 if (conMod->getStartPort() != NULL
1125 && conMod->getStartPort()->getParentBox()->getObjectId()
1126 == bbmod->getObjectId()) {
1127 AddControlerToBeRemove(&controllersToRemove,
1128 conMod->getObjectId());
1130 if (conMod->getEndPort() != NULL
1131 && conMod->getEndPort()->getParentBox()->getObjectId()
1132 == bbmod->getObjectId()) {
1133 AddControlerToBeRemove(&controllersToRemove,
1134 conMod->getObjectId());
1139 // Add box controller to be removed
1140 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1141 } else if (control->getGObjectType() == GCONNECTOR) {
1142 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1143 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1146 std::map<int, GObjectController*>::iterator it;
1148 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1149 int key = controllersToRemove[i];
1150 it = _controllers.find(key);
1151 GObjectController *cont = _controllers[key];
1153 cont->removeFromScene();
1154 unregisterController((InteractorStyleMaracas*) cont);
1155 _controllers.erase(it);
1158 _parent->saveTempDiagram();
1161 //=========================================================================
1163 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1164 std::string boxName) {
1165 _parent->displayBlackBoxInfo(packageName, boxName);
1168 //=========================================================================
1170 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1171 _parent->updateStatusBar(textStatus);
1174 //=========================================================================
1175 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1176 std::string result = "";
1177 if (withLineNumber == true) {
1179 stringstream StrStream;
1181 std::string strValue = StrStream.str();
1184 } else if (value < 100) {
1188 result += strValue + ": ";
1192 //=========================================================================
1194 bool wxVtkSceneManager::MakeBoxExecutable() {
1195 std::map<int, GObjectController*> selected = getSelectedObjects();
1196 if( selected.empty() )
1199 std::map<int, GObjectController*>::iterator it;
1200 for (it = selected.begin(); it != selected.end(); ++it) {
1201 GObjectController* lastSelected = it->second;
1203 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1204 GBlackBoxModel *bbmodel =
1205 (GBlackBoxModel*) lastSelected->getModel();
1206 view->setState(HIGHLIGHTED);
1207 if (bbmodel->isExecutable()) {
1208 bbmodel->setExecutable(false);
1210 bbmodel->setExecutable(true);
1212 bbmodel->notifyObservers(lastSelected->getId());
1220 //=========================================================================
1222 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1223 bool existsExec = false;
1225 std::vector<std::string> packages;
1226 std::vector<int> boxes;
1227 std::vector<int> connections;
1228 std::vector<int> execBoxes;
1230 std::map<int, GObjectController*>::iterator it;
1232 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1233 GObjectController *desc = it->second;
1234 int type = desc->getGObjectType();
1236 if (type == GBLACKBOX) {
1237 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1239 std::string pkg = mod->getBBTKPackage();
1240 bool existsPkg = false;
1241 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1242 if (packages[t] == pkg) {
1247 packages.push_back(pkg);
1250 boxes.push_back(it->first);
1251 if (mod->isExecutable()) {
1252 execBoxes.push_back(it->first);
1255 } else if (type == GCONNECTOR) {
1256 connections.push_back(it->first);
1261 std::string script = "";
1262 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1263 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1264 script += LineNumber(wln, lnNmbr) + "\n";
1266 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1267 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1269 for (i = 0; i < (int) packages.size(); i++) {
1270 script += LineNumber(wln, lnNmbr);
1271 script += "include ";
1272 script += packages[i];
1276 script += LineNumber(wln, lnNmbr);
1281 script += LineNumber(wln, lnNmbr);
1282 script += "author \"";
1286 script += LineNumber(wln, lnNmbr);
1287 script += "description \"";
1288 script += _Description;
1291 script += LineNumber(wln, lnNmbr);
1292 script += "category \"";
1293 script += _Category;
1296 script += LineNumber(wln, lnNmbr);
1299 // script+="include std\n"; // JPR
1301 for (i = 0; i < (int) boxes.size(); i++) {
1302 script += LineNumber(wln, lnNmbr);
1305 GObjectController *control = _controllers[id];
1306 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1308 script += model->getBBTKType();
1310 script += model->getBBTKName();
1313 std::vector<GPortModel*> inputs = model->getInputPorts();
1314 for (int j = 0; j < (int) inputs.size(); j++) {
1315 GPortModel* inputPort = inputs[j];
1316 if (inputPort->isValueSet()) {
1317 script += LineNumber(wln, lnNmbr);
1319 script += model->getBBTKName();
1321 script += inputPort->getBBTKName();
1323 script += inputPort->getValue();
1328 script += LineNumber(wln, lnNmbr);
1333 script += LineNumber(wln, lnNmbr);
1336 for (i = 0; i < (int) connections.size(); i++) {
1337 script += LineNumber(wln, lnNmbr);
1338 script += "connect ";
1339 int id = connections[i];
1340 GObjectController *control = _controllers[id];
1341 GConnectorModel *model = (GConnectorModel*) control->getModel();
1343 //Start Connection info
1344 GPortModel *start = model->getStartPort();
1345 script += start->getParentBox()->getBBTKName();
1347 script += start->getBBTKName();
1351 //End Connection info
1352 GPortModel *end = model->getEndPort();
1353 script += end->getParentBox()->getBBTKName();
1355 script += end->getBBTKName();
1360 script += LineNumber(wln, lnNmbr);
1362 for (i = 0; i < (int) execBoxes.size(); i++) {
1363 script += LineNumber(wln, lnNmbr);
1365 int id = execBoxes[i];
1366 GObjectController *control = _controllers[id];
1367 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1369 script += model->getBBTKName();
1378 //=========================================================================
1380 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1381 std::vector<std::string> packages;
1382 std::vector<int> boxes;
1383 std::vector<int> connections;
1384 std::vector<int> execBoxes;
1386 std::map<int, GObjectController*>::iterator it;
1388 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1389 GObjectController *desc = it->second;
1390 int type = desc->getGObjectType();
1392 if (type == GBLACKBOX) {
1393 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1395 std::string pkg = mod->getBBTKPackage();
1396 bool existsPkg = false;
1397 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1398 if (packages[t] == pkg) {
1403 packages.push_back(pkg);
1406 boxes.push_back(it->first);
1407 if (mod->isExecutable()) {
1408 execBoxes.push_back(it->first);
1410 } else if (type == GCONNECTOR) {
1411 connections.push_back(it->first);
1415 std::string script = "";
1417 script += "include std\n"; // EED
1418 script += "include itkvtk\n"; // EED
1420 for (i = 0; i < (int) packages.size(); i++) {
1421 script += "include ";
1422 script += packages[i];
1427 // Definition of a complex box
1428 script += "define ";
1429 script += _cbName + " " + _cbPackageName;
1433 script += "author \"";
1437 script += "description \"";
1438 script += _Description;
1442 script += "category \"";
1443 script += _Category;
1448 for (i = 0; i < (int) boxes.size(); i++) {
1451 GObjectController *control = _controllers[id];
1452 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1454 script += model->getBBTKType();
1456 script += model->getBBTKName();
1459 std::vector<GPortModel*> inputs = model->getInputPorts();
1460 for (int j = 0; j < (int) inputs.size(); j++) {
1461 GPortModel* inputPort = inputs[j];
1462 if (inputPort->isValueSet()) {
1464 script += model->getBBTKName();
1466 script += inputPort->getBBTKName();
1468 script += inputPort->getValue();
1476 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1478 std::string complexInputs = "";
1479 std::string complexOutputs = "";
1482 for (i = 0; i < (int) connections.size(); i++) {
1483 int id = connections[i];
1484 GObjectController *control = _controllers[id];
1485 GConnectorModel *model = (GConnectorModel*) control->getModel();
1488 GPortModel *start = model->getStartPort();
1489 GBoxModel *startBox = start->getParentBox();
1491 GPortModel *end = model->getEndPort();
1492 GBoxModel *endBox = end->getParentBox();
1494 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1495 complexInputs += "input ";
1496 complexInputs += startBox->getBBTKName();
1498 complexInputs += " ";
1499 complexInputs += endBox->getBBTKName();
1500 complexInputs += ".";
1501 complexInputs += end->getBBTKName();
1503 complexInputs += " ";
1504 complexInputs += "\" \"";
1506 complexInputs += "\n";
1507 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1508 complexOutputs += "output ";
1509 complexOutputs += endBox->getBBTKName();
1511 complexOutputs += " ";
1512 complexOutputs += startBox->getBBTKName();
1513 complexOutputs += ".";
1514 complexOutputs += start->getBBTKName();
1516 complexOutputs += " ";
1517 complexOutputs += "\" \"";
1519 complexOutputs += "\n";
1521 script += "connect ";
1522 script += startBox->getBBTKName();
1524 script += start->getBBTKName();
1528 //End Connection info
1529 script += endBox->getBBTKName();
1531 script += end->getBBTKName();
1539 for (i = 0; i < (int) execBoxes.size(); i++) {
1541 int id = execBoxes[i];
1542 GObjectController *control = _controllers[id];
1543 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1545 script += model->getBBTKName();
1550 script += "# Complex input ports\n";
1551 script += complexInputs;
1554 script += "# Complex output ports\n";
1555 script += complexOutputs;
1558 script += "endefine";
1564 //=========================================================================
1566 void wxVtkSceneManager::deleteAllBoxes() {
1567 std::map<int, GObjectController*>::iterator it;
1568 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1569 GObjectController *cont = it->second;
1570 cont->removeFromScene();
1571 unregisterController((InteractorStyleMaracas*) cont);
1573 _selectedObjects.clear();
1574 _controllers.clear();
1578 //=========================================================================
1581 void wxVtkSceneManager::refresh() {
1582 _baseView->Refresh();
1584 //=========================================================================
1586 void wxVtkSceneManager::refreshScene() {
1587 _baseView->RefreshView();
1590 //=========================================================================
1592 void wxVtkSceneManager::centerView() {
1594 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1595 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1596 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1597 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1598 _baseView->RefreshView();
1602 //=========================================================================
1604 void wxVtkSceneManager::saveDiagram(std::string &content) {
1607 content += "CATEGORY:";
1608 content += GetCategory();
1611 content += "DESCRIPTION:";
1612 content += GetDescription();
1615 content += "AUTHOR:";
1616 content += GetAuthor();
1619 //Print info IF COMPLEX BOX
1620 content += "COMPLEXBOX:";
1621 if (_isComplexBox) {
1622 content += "TRUE\n";
1624 content += "COMPLEXBOXNAME:";
1625 content += GetCbName();
1628 content += "PACKAGENAME:";
1629 content += GetCbPackageName();
1632 //Print info complex input ports
1633 std::vector<int> inputs = getComplexInputPorts();
1634 int insize = inputs.size();
1635 content += "COMPLEXINPUTS:";
1636 sprintf(buffer, "%d", insize);
1640 for (int i = 0; i < insize; i++) {
1642 GObjectController *cont = _controllers[id];
1643 cont->getModel()->save(content);
1646 //Print info complex output ports
1647 std::vector<int> outputs = getComplexOutputPorts();
1648 int outsize = outputs.size();
1649 content += "COMPLEXOUTPUTS:";
1650 sprintf(buffer, "%d", outsize);
1654 for (int i = 0; i < outsize; i++) {
1655 int id = outputs[i];
1656 GObjectController *cont = _controllers[id];
1657 cont->getModel()->save(content);
1661 content += "FALSE\n";
1665 std::vector<int> boxes = getBlackBoxes();
1666 int bsize = boxes.size();
1667 content += "BOXES:";
1668 sprintf(buffer, "%d", bsize);
1672 for (int i = 0; i < bsize; i++) {
1674 GObjectController *cont = _controllers[id];
1675 cont->getModel()->save(content);
1679 std::vector<int> connections = getConnections();
1680 int csize = connections.size();
1681 content += "CONNECTIONS:";
1682 sprintf(buffer, "%d", csize);
1686 for (int i = 0; i < csize; i++) {
1687 int id = connections[i];
1688 GObjectController *cont = _controllers[id];
1689 cont->getModel()->save(content);
1694 //=========================================================================
1696 void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
1698 std::string version = "<void>";
1699 std::string line = "";
1700 char delims[] = ":";
1701 char *result = NULL;
1703 getline(inputStream, line);
1706 while (!inputStream.eof()) {
1707 if (line == "" || line[0] == '#') {
1708 getline(inputStream, line);
1709 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1710 version = line.substr(18, 3);
1712 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1713 version = line.substr(18, 3);
1715 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1716 version = line.substr(18, 3);
1718 } else if (line == "APP_START") {
1724 printf("EED wxVtkSceneManager::loadDiagram version=%s\n", version.c_str());
1728 if ((version != "1.0") && (version != "1.1")) {
1729 getline(inputStream, line);//CATEGORY:<category of the box>
1730 char categoryTmp[30];
1731 strcpy(categoryTmp, line.c_str());
1732 result = strtok(categoryTmp, delims);
1733 result = strtok(NULL, delims);
1734 SetCategory(result);
1736 getline(inputStream, line);//DESCRIPTION:<description of the box>
1737 char descriptionTmp[1024];
1738 strcpy(descriptionTmp, line.c_str());
1739 result = strtok(descriptionTmp, delims);
1740 result = strtok(NULL, delims);
1741 SetDescription(result);
1743 getline(inputStream, line);//AUTHOR:<author>
1744 char authorTmp[255];
1745 strcpy(authorTmp, line.c_str());
1746 result = strtok(authorTmp, delims);
1747 result = strtok(NULL, delims);
1752 getline(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1753 char complexTmp[30];
1754 strcpy(complexTmp, line.c_str());
1755 result = strtok(complexTmp, delims);
1756 result = strtok(NULL, delims);
1757 std::string isComplexBox(result);
1759 if (isComplexBox == "TRUE") {
1760 _isComplexBox = true;
1762 if ((version != "1.0") && (version != "1.1")) {
1763 getline(inputStream, line);//COMPLEXNAME:<name of the complex box>
1764 char complexboxnameTmp[255];
1765 strcpy(complexboxnameTmp, line.c_str());
1766 result = strtok(complexboxnameTmp, delims);
1767 result = strtok(NULL, delims);
1770 getline(inputStream, line);//PACKAGENAME:<name of the package of the box>
1771 char packagenameTmp[255];
1772 strcpy(packagenameTmp, line.c_str());
1773 result = strtok(packagenameTmp, delims);
1774 result = strtok(NULL, delims);
1775 SetCbPackageName(result);
1778 //-----------------------
1779 //- COMPLEX INPUT PORTS
1780 //-----------------------
1781 getline(inputStream, line);//COMPLEXINPUTS:num
1783 strcpy(inputs, line.c_str());
1784 result = strtok(inputs, delims);
1785 result = strtok(NULL, delims);
1788 std::istringstream inps(result);
1791 for (int i = 0; i < numInputs; i++) {
1793 getline(inputStream, line);//COMPLEX_PORT
1794 getline(inputStream, line);//name
1795 std::string inputPortName(line);
1798 getline(inputStream, line);//xInic:yInic:zInic
1800 strcpy(coord, line.c_str());
1801 result = strtok(coord, delims);//xInic
1802 std::string xInic(result);
1803 result = strtok(NULL, delims);//yInic
1804 std::string yInic(result);
1805 result = strtok(NULL, delims);//zInic
1806 std::string zInic(result);
1808 double xIn, yIn, zIn;
1809 std::istringstream xSt(xInic);
1811 std::istringstream ySt(yInic);
1813 std::istringstream zSt(zInic);
1816 getline(inputStream, line);//FIN_COMPLEX_PORT
1818 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
1820 } // for input complex box
1823 //-----------------------
1824 //- COMPLEX OUTPUT PORTS
1825 //-----------------------
1827 getline(inputStream, line);//COMPLEXOUTPUTS:num
1829 strcpy(outputs, line.c_str());
1830 result = strtok(outputs, delims);
1831 result = strtok(NULL, delims);
1834 std::istringstream outps(result);
1835 outps >> numOutputs;
1837 for (int i = 0; i < numOutputs; i++) {
1839 getline(inputStream, line);//COMPLEX_PORT
1840 getline(inputStream, line);//name
1841 std::string outputPortName(line);
1844 getline(inputStream, line);//xInic:yInic:zInic
1846 strcpy(coord, line.c_str());
1847 result = strtok(coord, delims);//xInic
1848 std::string xInic(result);
1849 result = strtok(NULL, delims);//yInic
1850 std::string yInic(result);
1851 result = strtok(NULL, delims);//zInic
1852 std::string zInic(result);
1854 double xIn, yIn, zIn;
1855 std::istringstream xSt(xInic);
1857 std::istringstream ySt(yInic);
1859 std::istringstream zSt(zInic);
1862 getline(inputStream, line);//FIN_COMPLEX_PORT
1864 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn,
1867 } // for output complex box
1872 getline(inputStream, line);//BOXES:num
1874 strcpy(boxes, line.c_str());
1875 result = strtok(boxes, delims);
1876 result = strtok(NULL, delims);
1879 std::istringstream is(result);
1882 for (int i = 0; i < numBoxes; i++) {
1884 getline(inputStream, line);//BOX
1885 getline(inputStream, line);//package:type:name
1887 strcpy(box, line.c_str());
1888 result = strtok(box, delims);//package
1889 std::string package(result);
1890 result = strtok(NULL, delims);//type
1891 std::string type(result);
1892 result = strtok(NULL, delims);//name
1893 std::string name(result);
1895 getline(inputStream, line);//ISEXEC:TRUE|FALSE
1897 strcpy(exec, line.c_str());
1898 result = strtok(exec, delims);//ISEXEC
1899 result = strtok(NULL, delims);//TRUE|FALSE
1900 std::string isExec(result);
1903 getline(inputStream, line);//xInic:yInic:zInic
1905 strcpy(coord, line.c_str());
1906 result = strtok(coord, delims);//xInic
1907 std::string xInic(result);
1908 result = strtok(NULL, delims);//yInic
1909 std::string yInic(result);
1910 result = strtok(NULL, delims);//zInic
1911 std::string zInic(result);
1913 double xIn, yIn, zIn;
1914 std::istringstream xSt(xInic);
1916 std::istringstream ySt(yInic);
1918 std::istringstream zSt(zInic);
1922 getline(inputStream, line);//xEnd:yEnd:zEnd
1923 strcpy(coord, line.c_str());
1924 result = strtok(coord, delims);//xEnd
1925 std::string xEnd(result);
1926 result = strtok(NULL, delims);//yEnd
1927 std::string yEnd(result);
1928 result = strtok(NULL, delims);//zEnd
1929 std::string zEnd(result);
1931 double xEn, yEn, zEn;
1932 std::istringstream xEt(xEnd);
1934 std::istringstream yEt(yEnd);
1936 std::istringstream zEt(zEnd);
1939 bool boxExecutable = false;
1940 if (isExec == "TRUE") {
1941 boxExecutable = true;
1944 int idBox = createGBlackBox(xIn, yIn, package, type);
1945 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn,
1948 GObjectController *cont = _controllers[idBox];
1949 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
1952 getline(inputStream, line);//PORT o FIN_BOX
1953 std::string port = line.substr(0, 4);
1954 while (port == "PORT") {
1955 getline(inputStream, line);//name:value
1957 strcpy(poort, line.c_str());
1958 result = strtok(poort, delims);//name
1959 std::string name(result);
1960 result = strtok(NULL, delims);//value
1961 std::string value(result);
1963 bbmod->setValueToInput(name, value);
1964 getline(inputStream, line);//PORT o FIN_BOX
1965 port = line.substr(0, 4);
1968 //EED bbmod->notifyObservers(_idManager);
1973 getline(inputStream, line);//CONNECTIONS:num
1975 strcpy(conns, line.c_str());
1976 result = strtok(conns, delims);
1977 result = strtok(NULL, delims);
1980 std::istringstream isCons(result);
1983 for (int i = 0; i < numConns; i++) {
1985 getline(inputStream, line);//CONNECTION
1986 getline(inputStream, line);//Startbox.PortName:EndBox.PortName
1989 strcpy(connec, line.c_str());
1990 result = strtok(connec, delims);
1991 std::string nameStartBox(result);
1992 result = strtok(NULL, delims);
1993 std::string nameStartPort(result);
1994 result = strtok(NULL, delims);
1995 std::string nameEndBox(result);
1996 result = strtok(NULL, delims);
1997 std::string nameEndPort(result);
1999 int idCon = configGConnetion(nameStartBox, nameStartPort,
2000 nameEndBox, nameEndPort);
2002 if (version != "1.0") {
2003 //Readding control points of the manualContour
2005 GConnectorController *tempp =
2006 (GConnectorController*) _controllers[idCon];
2007 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2008 vtkGConnectorView *conView =
2009 (vtkGConnectorView*) tempp->getView();
2010 getline(inputStream, line); //NumberOfControlPoints:##
2011 strcpy(conns, line.c_str());
2012 result = strtok(conns, delims);
2013 result = strtok(NULL, delims);
2015 int numberOfControlPoints;
2016 std::istringstream isCons(result);
2017 isCons >> numberOfControlPoints;
2019 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2020 getline(inputStream, line); //XX:YY:ZZ
2022 strcpy(connec, line.c_str());
2025 result = strtok(connec, delims);
2026 std::istringstream isPointX(result);
2028 result = strtok(NULL, delims);
2029 std::istringstream isPointY(result);
2031 result = strtok(NULL, delims);
2032 std::istringstream isPointZ(result);
2035 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px,
2037 conView->getManualContourView()->AddPoint();
2047 //=========================================================================
2050 //=========================================================================
2051 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2052 std::string portName, double xIn, double yIn, double zIn) {
2054 if (inputoutput == true) {
2055 idPort = createGComplexBoxInputPort(portName);
2057 idPort = createGComplexBoxOutputPort(portName);
2059 GObjectController *cont = _controllers[idPort];
2060 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2061 cbmod->setInicPoint(xIn, yIn, zIn);
2062 cbmod->notifyObservers(_idManager);
2064 //=========================================================================
2067 //=========================================================================
2068 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
2072 GBoxModel *boxModel = NULL;
2073 std::vector<int> lstB = getBlackBoxes();
2074 for (j = 0; j < (int) lstB.size(); j++) {
2076 bMod = (GBoxModel*) _controllers[idB]->getModel();
2077 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2082 if ((_isComplexBox) && (boxModel == NULL)) {
2083 std::vector<int> lstInputs = getComplexInputPorts();
2084 for (j = 0; j < (int) lstInputs.size(); j++) {
2086 bMod = (GBoxModel*) _controllers[idB]->getModel();
2087 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2092 std::vector<int> lstOutputs = getComplexOutputPorts();
2093 for (j = 0; j < (int) lstOutputs.size(); j++) {
2094 int idB = lstOutputs[j];
2095 bMod = (GBoxModel*) _controllers[idB]->getModel();
2096 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2106 //=========================================================================
2109 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2110 std::string nameStartPort, std::string nameEndBox,
2111 std::string nameEndPort) {
2113 GBoxModel *boxModel;
2114 GPortModel *startP = NULL;
2115 GPortModel *endP = NULL;
2117 boxModel = findGBox(nameStartBox);
2118 if (boxModel != NULL) {
2119 startP = boxModel->getOutputPort(nameStartPort);
2122 boxModel = findGBox(nameEndBox);
2123 if (boxModel != NULL) {
2124 endP = boxModel->getInputPort(nameEndPort);
2128 int idCon = createGConnector(startP);
2129 _worldState = NOTHING_HAPPENS;
2130 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2132 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2133 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2134 tempp->endContourCreation();
2135 conMod->setEndPort(endP);
2136 conView->updateStartEndPoints();
2140 //=========================================================================
2142 bool wxVtkSceneManager::boxExist(std::string boxname) {
2144 std::map<int, GObjectController*>::iterator it;
2145 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2146 GObjectController *cont = it->second;
2147 if (cont->getModel()->getBBTKName() == boxname) {
2154 //=========================================================================
2156 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2157 std::vector<int> vect;
2158 std::map<int, GObjectController*>::iterator it;
2159 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2160 GObjectController *cont = it->second;
2161 if (cont->getGObjectType() == GBLACKBOX) {
2162 vect.push_back(cont->getId());
2168 //=========================================================================
2170 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2171 std::vector<int> vect;
2172 std::map<int, GObjectController*>::iterator it;
2173 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2174 GObjectController *cont = it->second;
2175 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2176 vect.push_back(cont->getId());
2182 //=========================================================================
2184 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2185 std::vector<int> vect;
2186 std::map<int, GObjectController*>::iterator it;
2187 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2188 GObjectController *cont = it->second;
2189 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2190 vect.push_back(cont->getId());
2196 //=========================================================================
2198 std::vector<int> wxVtkSceneManager::getConnections() {
2199 std::vector<int> vect;
2200 std::map<int, GObjectController*>::iterator it;
2201 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2202 GObjectController *cont = it->second;
2203 if (cont->getGObjectType() == GCONNECTOR) {
2204 vect.push_back(cont->getId());
2210 //=========================================================================
2212 bool wxVtkSceneManager::isComplexBox() {
2213 return _isComplexBox;
2216 //=========================================================================
2218 void wxVtkSceneManager::setComplexBox(bool val) {
2219 _isComplexBox = val;
2222 //=========================================================================
2224 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2225 //Register the controller of the new object
2226 registerController((InteractorStyleMaracas*) objController);
2227 //Add the object to the objects list
2228 int newId = _contLastId;//_controllers.size();
2229 objController->setId(newId);
2230 _controllers[newId] = objController;
2232 << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = "
2233 << _contLastId << std::endl;
2238 //=========================================================================
2240 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2242 std::map<int, int> oldIdNewIdBoxes;
2243 std::vector<int> connections;
2245 std::vector<int> newBoxesID;
2247 std::map<int, GObjectController*>::iterator it;
2248 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2249 GObjectController *cont = it->second;
2250 int type = cont->getGObjectType();
2252 if (type == GBLACKBOX) {
2254 double xInic, yInic, zInic;
2255 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2256 copyBox->getInicPoint(xInic, yInic, zInic);
2257 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2258 copyBox->getBBTKType());
2260 int idcB = copyBox->getObjectId();
2261 oldIdNewIdBoxes[idcB] = idBox;
2262 cont = _controllers[idBox];
2263 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2264 newbox->setInicPoint(xInic, yInic, zInic);
2265 int num = newbox->getNumInputPorts();
2266 for (int j = 0; j < num; j++) {
2267 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2269 newbox->move(xInic + 20, yInic + 20, zInic);
2270 newbox->notifyObservers(_idManager);
2271 newBoxesID.push_back(newbox->getObjectId());
2273 } else if (type == GCONNECTOR) {
2274 int idCon = cont->getId();
2275 connections.push_back(idCon);
2280 for (int i = 0; i < (int) connections.size(); i++) {
2281 int objId = connections[i];
2282 GObjectController *cont = objectsMap[objId];
2283 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2285 GPortModel* startPort = connectModel->getStartPort();
2286 int startPortIndex = startPort->getPosInBox();
2287 GPortModel* endPort = connectModel->getEndPort();
2288 int endPortIndex = endPort->getPosInBox();
2290 GBlackBoxModel* startPortParentBox =
2291 (GBlackBoxModel*) startPort->getParentBox();
2292 GBlackBoxModel* endPortParentBox =
2293 (GBlackBoxModel*) endPort->getParentBox();
2295 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2296 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2298 GBlackBoxModel* newStartBox =
2299 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2300 GBlackBoxModel* newEndBox =
2301 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2303 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2304 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2306 // Creates connection
2307 int idCon = createGConnector(newStartPort);
2308 GConnectorController *tempp =
2309 (GConnectorController*) _controllers[idCon];
2310 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2311 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2312 tempp->endContourCreation();
2313 conMod->setEndPort(newEndPort);
2314 conView->updateStartEndPoints();
2317 /// the new selected boxes are the duplicate ones
2319 UnSelectBlackBoxes();
2320 for (int i = 0; i < newBoxesID.size(); i++) {
2321 _selectedObjects.push_back(newBoxesID.at(i));
2324 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2325 int id = _selectedObjects[i];
2326 GObjectController* cont = _controllers[id];
2328 cont->getView()->setState(SELECTED);
2329 cont->getModel()->notifyObservers(_idManager);
2336 //=========================================================================
2338 int wxVtkSceneManager::getNumSelectedObjects() {
2339 return _selectedObjects.size();
2342 //=========================================================================
2344 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2345 std::map<int, GObjectController*> mapSelected;
2347 std::map<int, GObjectController*>::iterator it;
2348 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2349 GObjectController *cont = it->second;
2350 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2352 mapSelected[cont->getId()] = cont;
2356 std::map<int, GObjectController*>::iterator it2;
2357 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2358 GObjectController *cont = it2->second;
2359 if (cont->getGObjectType() == GCONNECTOR) {
2360 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2361 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2362 GBoxModel* startPortParentBox =
2363 cmod->getStartPort()->getParentBox();
2365 std::map<int, GObjectController*>::iterator iterOBJ1 =
2366 mapSelected.find(startPortParentBox->getObjectId());
2367 std::map<int, GObjectController*>::iterator iterOBJ2 =
2368 mapSelected.find(endPortParentBox->getObjectId());
2370 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2371 int ID = cont->getId();
2372 mapSelected[ID] = cont;
2379 //=========================================================================
2381 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2383 std::map<int, int> oldIdNewIdBoxes;
2384 std::vector<int> connections;
2386 std::map<int, GObjectController*>::iterator it;
2387 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2388 GObjectController *cont = it->second;
2389 int type = cont->getGObjectType();
2391 if (type == GBLACKBOX) {
2393 double xInic, yInic, zInic;
2394 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2395 copyBox->getInicPoint(xInic, yInic, zInic);
2396 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2397 copyBox->getBBTKType());
2399 int idcB = copyBox->getObjectId();
2400 oldIdNewIdBoxes[idcB] = idBox;
2401 cont = _controllers[idBox];
2402 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2403 newbox->setInicPoint(xInic, yInic, zInic);
2404 int num = newbox->getNumInputPorts();
2405 for (int j = 0; j < num; j++) {
2406 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2408 newbox->notifyObservers(_idManager);
2409 } else if (type == GCONNECTOR) {
2410 int idCon = cont->getId();
2411 connections.push_back(idCon);
2416 for (int i = 0; i < (int) connections.size(); i++) {
2417 int objId = connections[i];
2418 GObjectController *cont = objectsMap[objId];
2419 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2421 GPortModel* startPort = connectModel->getStartPort();
2422 int startPortIndex = startPort->getPosInBox();
2423 GPortModel* endPort = connectModel->getEndPort();
2424 int endPortIndex = endPort->getPosInBox();
2426 GBlackBoxModel* startPortParentBox =
2427 (GBlackBoxModel*) startPort->getParentBox();
2428 GBlackBoxModel* endPortParentBox =
2429 (GBlackBoxModel*) endPort->getParentBox();
2431 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2432 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2434 GBlackBoxModel* newStartBox =
2435 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2436 GBlackBoxModel* newEndBox =
2437 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2439 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2440 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2442 // Creates connection
2443 int idCon = createGConnector(newStartPort);
2444 GConnectorController *tempp =
2445 (GConnectorController*) _controllers[idCon];
2446 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2447 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2448 tempp->endContourCreation();
2449 conMod->setEndPort(newEndPort);
2450 conView->updateStartEndPoints();
2453 std::map<int, int>::iterator itIds;
2454 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2455 int idOld = itIds->first;
2456 int idNew = itIds->second;
2458 GBlackBoxModel* oldBox =
2459 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2460 GBlackBoxModel* newBox =
2461 (GBlackBoxModel*) _controllers[idNew]->getModel();
2463 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2464 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2465 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2466 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2468 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2470 //EED int toCreate=-1;
2471 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2472 if (oldInputConnections[k] == newInputConnections[l]) {
2477 if (exist == false) {
2478 //Create complex input
2479 int posInBox = oldInputConnections[k];
2480 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2481 std::string inputPortName = inputPort->getBBTKName();
2482 int idInputPort = createGComplexBoxInputPort(inputPortName);
2483 GObjectController *cont = _controllers[idInputPort];
2484 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2485 double xIn, yIn, zIn;
2486 inputPort->getInicPoint(xIn, yIn, zIn);
2488 cbmod->setInicPoint(xIn, yIn, zIn);
2489 cbmod->notifyObservers(_idManager);
2491 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2493 // Creates connection
2494 int idCon = createGConnector(cbmod->getOutputPort(0));
2495 GConnectorController *tempp =
2496 (GConnectorController*) _controllers[idCon];
2497 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2498 vtkGConnectorView *conView =
2499 (vtkGConnectorView*) tempp->getView();
2500 tempp->endContourCreation();
2501 conMod->setEndPort(inputPortEnd);
2502 conView->updateStartEndPoints();
2508 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2510 //EED int toCreate=-1;
2511 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2512 if (oldOutputConnections[k] == newOutputConnections[l]) {
2517 if (exist == false) {
2518 //Create complex output
2519 int posInBox = oldOutputConnections[k];
2520 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2521 std::string outputPortName = outputPort->getBBTKName();
2522 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2523 GObjectController *cont = _controllers[idOutputPort];
2524 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2525 double xIn, yIn, zIn;
2526 outputPort->getInicPoint(xIn, yIn, zIn);
2528 cbmod->setInicPoint(xIn, yIn, zIn);
2529 cbmod->notifyObservers(_idManager);
2531 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2533 // Creates connection
2534 int idCon = createGConnector(outputPortEnd);
2535 GConnectorController *tempp =
2536 (GConnectorController*) _controllers[idCon];
2537 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2538 vtkGConnectorView *conView =
2539 (vtkGConnectorView*) tempp->getView();
2540 tempp->endContourCreation();
2541 conMod->setEndPort(cbmod->getInputPort(0));
2542 conView->updateStartEndPoints();
2552 //=========================================================================
2553 void wxVtkSceneManager::SetCbName(std::string cbName) {
2555 if (_cbName == "") {
2556 _cbName = "<complex box name>";
2560 //=========================================================================
2561 std::string wxVtkSceneManager::GetCbName() {
2565 //=========================================================================
2566 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2567 _cbPackageName = packagename;
2568 if (_cbPackageName == "") {
2569 _cbPackageName = "<package name of the complex box>";
2574 //=========================================================================
2575 std::string wxVtkSceneManager::GetCbPackageName() {
2576 return _cbPackageName;
2579 //=========================================================================
2580 void wxVtkSceneManager::SetAuthor(std::string author) {
2582 if (_Author == "") {
2583 _Author = "<author of the box>";
2587 //=========================================================================
2588 std::string wxVtkSceneManager::GetAuthor() {
2592 //=========================================================================
2593 void wxVtkSceneManager::SetCategory(std::string category) {
2594 _Category = category;
2595 if (_Category == "") {
2596 _Category = "<category of the box>";
2600 //=========================================================================
2601 std::string wxVtkSceneManager::GetCategory() {
2605 //=========================================================================
2606 void wxVtkSceneManager::SetDescription(std::string description) {
2607 _Description = description;
2608 if (_Description == "") {
2609 _Description = "<description of the box>";
2614 //=========================================================================
2615 std::string wxVtkSceneManager::GetDescription() {
2616 return _Description;
2619 //=========================================================================
2622 } // EO namespace bbtk