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 //=========================================================================
44 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent,
45 wxVtk3DBaseView *baseView, int idManager) {
46 _cbName = "ComplexBoxName";
47 _cbPackageName = "PackageName";
48 _Author = "Author ??";
50 _Description = "Description ??";
54 _idManager = idManager;
56 _startDragging = false;
57 _isComplexBox = false;
59 if (_baseView != NULL) {
62 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
65 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
69 _worldState = NOTHING_HAPPENS;
70 registerController(this);
73 _idConnectionInCreation = -1;
78 //=========================================================================
80 void wxVtkSceneManager::disconnectDrop() {
81 printf("EED %p ~wxVtkSceneManager::disconnectDrop()\n", this);
82 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
83 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
86 //=========================================================================
88 wxVtkSceneManager::~wxVtkSceneManager() {
90 printf("EED %p ~wxVtkSceneManager() START\n", this);
93 printf("EED %p ~wxVtkSceneManager() END\n", this);
96 //=========================================================================
98 void wxVtkSceneManager::configureBaseView() {
99 printf("EED wxVtkSceneManager::configureBaseView 0\n");
100 vtkInteractorStyleBaseView2D *interactorstylebaseview =
101 vtkInteractorStyleBaseView2D::New();
103 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
105 // Important to activate the 2D interaction system
106 wxVTKRenderWindowInteractor *iren =
107 _baseView->GetWxVTKRenderWindowInteractor();
108 interactorstylebaseview->SetInteractor(iren);
109 iren->SetInteractorStyle(interactorstylebaseview);
110 interactorstylebaseview->SetwxVtkBaseView(_baseView);
112 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
113 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, 800, 1100);
115 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
116 _baseView->GetRenderer()->GradientBackgroundOn();
117 _baseView->Refresh();
120 _textActor = vtkTextActor3D::New();
121 _textActor->SetPosition(-9999, -9999, 900);
122 _textActor->SetInput("<void>");
123 _textActor->GetTextProperty()->SetFontSize(60);
124 _textActor->GetTextProperty()->BoldOn();
125 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,
128 _baseView->GetRenderer()->AddActor(_textActor);
130 // Actor Fill_Port_Text
137 vtkPolygon *aPolygon = vtkPolygon::New();
138 _fillObjectActor = vtkActor::New();
140 _pts = vtkPoints::New();
142 double w = 100, h = 10, b = h / 15, t = 3;
143 _pts->SetNumberOfPoints(21);
144 _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
145 _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
146 _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
147 _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
148 _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
150 _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
151 _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
152 _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
153 _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
155 _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
156 _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
157 _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
158 _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
160 _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
161 _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
162 _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
163 _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
165 _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
166 _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
167 _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
168 _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
170 aPolygon->GetPointIds()->SetNumberOfIds(21);
171 for (int i = 0; i < 21; i++) {
172 aPolygon->GetPointIds()->SetId(i, i);
175 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
176 aPolygonGrid->Allocate(1, 1);
177 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),
178 aPolygon->GetPointIds());
179 aPolygonGrid->SetPoints(_pts);
180 _aPolygonMapper = vtkDataSetMapper::New();
181 _aPolygonMapper->SetInput(aPolygonGrid);
182 _fillObjectActor->SetMapper(_aPolygonMapper);
183 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
185 _fillObjectActor->GetProperty()->SetOpacity(0);
186 _aPolygonMapper->Modified();
188 _baseView->GetRenderer()->AddActor(_fillObjectActor);
189 printf("EED wxVtkSceneManager::configureBaseView 1\n");
192 //=========================================================================
194 std::string wxVtkSceneManager::generateANewNameForABox() {
195 std::stringstream boxname;
196 if (_numBoxes < 10) {
197 boxname << "Box0" << _numBoxes;
199 boxname << "Box" << _numBoxes;
202 return boxname.str();
205 //=========================================================================
207 std::string wxVtkSceneManager::findANewNameForABox() {
208 std::string boxname = generateANewNameForABox();
210 while (boxExist(boxname) == true) {
211 boxname = generateANewNameForABox();
217 //=========================================================================
218 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
219 double zIn, std::string name, bool boxExecutable, double xEn,
220 double yEn, double zEn) {
221 GObjectController *cont = _controllers[idBox];
222 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
223 bbmod->setBBTKName(name);
224 bbmod->setInicPoint(xIn, yIn, zIn);
225 bbmod->setFinalPoint(xEn, yEn, zEn);
226 bbmod->setExecutable(boxExecutable);
228 bbmod->notifyObservers(_idManager);
232 //=========================================================================
234 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,
235 std::string boxType) {
236 _worldState = NOTHING_HAPPENS;
237 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
238 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
240 int type = GBLACKBOX;
242 //Create the MVC Objects
246 (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
248 vtkGObjectView *view =
249 GObjectsMVCFactory::getInstance()->createGObjectView(type);
250 GObjectController* controller =
251 GObjectsMVCFactory::getInstance()->createGObjectController(type);
253 BlackBoxDescriptor::Pointer descriptor =
254 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
255 packageName, boxType);
257 //Prepares the initial model
258 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
261 double yy = windowHeight - y;
263 //z value is not important yet, because it is only used a parallel projection
265 _baseView->TransCoordScreenToWorld(xx, yy, zz);
266 model->setInicPoint(xx, yy, zz);
268 std::stringstream stream;
270 std::string newBoxName;
271 newBoxName = findANewNameForABox();
273 stream << newBoxName;
275 std::string arraystring = stream.str();
277 model->setBBTKName(arraystring);
278 model->setBBTKType(boxType);
279 model->setBBTKPackage(packageName);
281 model->addObserver(view);
282 model->addObserver(this);
284 //Iterate and create the input ports
285 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
286 descriptor->GetInputDescriptorMap();
287 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
290 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) {
291 BlackBoxInputDescriptor *desc = itInput->second;
292 createGInputPort(GINPUTPORT, i, model, desc);
296 //Iterate and create the output ports
297 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
298 descriptor->GetOutputDescriptorMap();
299 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
302 for (itOutput = descriptorOutMap.begin(); itOutput
303 != descriptorOutMap.end(); ++itOutput) {
304 BlackBoxOutputDescriptor *desc = itOutput->second;
305 createGOutputPort(GOUTPUTPORT, i, model, desc);
309 //Associates the view with the correspondent renderer and the model.
310 //(NOTE: Refresh is only made by the view)
311 view->setModel(model);
312 view->setBaseView(_baseView);
313 view->initVtkObjects();
315 //Associates the controller with the correspondent model and view
316 controller->setModelAndView(model, view);
318 //Resgiter change to the observers of the actual model
319 model->notifyObservers(_idManager);
321 int newId = addObjectController(controller);
327 //=========================================================================
329 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
330 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
331 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
333 int type = GCOMPLEXINPUTPORT;
335 //Create the MVC Objects
339 (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
341 vtkGObjectView *view =
342 GObjectsMVCFactory::getInstance()->createGObjectView(type);
343 GObjectController* controller =
344 GObjectsMVCFactory::getInstance()->createGObjectController(type);
346 //Prepares the initial model
349 double yy = windowHeight - 5;
351 //z value is not important yet, because it is only used a parallel projection
353 printf("EED wxVtkSceneManager::createGComplexBoxInputPort 900-450\n");
355 _baseView->TransCoordScreenToWorld(xx, yy, zz);
356 model->setInicPoint(xx, yy, zz);
358 model->setBBTKName(inputName);
359 model->setBBTKType("ComplexInputPort");
360 model->setComplexPortType(type);
362 model->addObserver(view);
363 model->addObserver(this);
365 //create the output port
366 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
367 "ComplexInputPort", 0, model);
368 model->addOutputPort((GPortModel*) portController->getModel());
370 //Associates the view with the correspondent renderer and the model.
371 //(NOTE: Refresh is only made by the view)
372 view->setModel(model);
373 view->setBaseView(_baseView);
374 view->initVtkObjects();
376 //Associates the controller with the correspondent model and view
377 controller->setModelAndView(model, view);
379 //Resgiter change to the observers of the actual model
380 model->notifyObservers(_idManager);
382 int newId = addObjectController(controller);
386 //=========================================================================
388 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
389 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
390 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
392 int type = GCOMPLEXOUTPUTPORT;
394 //Create the MVC Objects
398 (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
400 vtkGObjectView *view =
401 GObjectsMVCFactory::getInstance()->createGObjectView(type);
402 GObjectController *controller =
403 GObjectsMVCFactory::getInstance()->createGObjectController(type);
405 //Prepares the initial model
408 double yy = windowHeight - 5;
410 //z value is not important yet, because it is only used a parallel projection
413 printf("EED wxVtkSceneManager::createGComplexBoxOutputPort 900-450\n");
415 _baseView->TransCoordScreenToWorld(xx, yy, zz);
416 model->setInicPoint(xx, yy, zz);
418 model->setBBTKName(outputName);
419 model->setBBTKType("ComplexOutputPort");
420 model->setComplexPortType(type);
422 model->addObserver(view);
423 model->addObserver(this);
425 //create the output port
426 GPortController* portController = createGPort(GINPUTPORT, outputName,
427 "ComplexInputPort", 0, model);
428 model->addInputPort((GPortModel*) portController->getModel());
430 //Associates the view with the correspondent renderer and the model.
431 //(NOTE: Refresh is only made by the view)
432 view->setModel(model);
433 view->setBaseView(_baseView);
434 view->initVtkObjects();
436 //Associates the controller with the correspondent model and view
437 controller->setModelAndView(model, view);
439 //Resgiter change to the observers of the actual model
440 model->notifyObservers(_idManager);
442 int newId = addObjectController(controller);
446 //=========================================================================
448 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,
449 GBoxModel *blackBox, BlackBoxInputDescriptor *desc) {
450 GPortController* portController = createGPort(portType, desc->GetName(),
451 desc->GetTypeName(), posinBox, blackBox);
452 blackBox->addInputPort((GPortModel*) portController->getModel());
453 return portController->getId();
456 //=========================================================================
458 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,
459 GBoxModel *blackBox, BlackBoxOutputDescriptor *desc) {
460 GPortController* portController = createGPort(portType, desc->GetName(),
461 desc->GetTypeName(), posinBox, blackBox);
462 blackBox->addOutputPort((GPortModel*) portController->getModel());
463 return portController->getId();
466 //=========================================================================
468 GPortController* wxVtkSceneManager::createGPort(int portType,
469 std::string bbtkName, std::string bbtkType, int posInBox,
470 GBoxModel *blackBox) {
473 //Create the MVC Objects
476 (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
478 vtkGObjectView *view =
479 GObjectsMVCFactory::getInstance()->createGObjectView(type);
480 GObjectController* controller =
481 GObjectsMVCFactory::getInstance()->createGObjectController(type);
483 model->registerInBox(blackBox, portType, posInBox);
485 model->setBBTKType(bbtkType);
486 model->setBBTKName(bbtkName);
488 model->addObserver(view);
489 model->addObserver(this);
491 //Associates the view with the correspondent renderer and the model.
492 //(NOTE: Refresh is only made by the view)
493 view->setModel(model);
494 view->setBaseView(_baseView);
495 view->initVtkObjects();
497 //Associates the controller with the correspondent model and view
498 controller->setModelAndView(model, view);
500 model->notifyObservers(_idManager);
502 addObjectController(controller);
504 return (GPortController*) controller;
507 //=========================================================================
509 int wxVtkSceneManager::createGConnector(GPortModel* startPort) {
510 int type = GCONNECTOR;
512 manualConnectorContourController* manContourControl =
513 new manualConnectorContourController();
514 manualConnectorContourView* manContourView =
515 new manualConnectorContourView();
516 manualContourModel* manContourModel = new manualContourModel();
518 GConnectorController* connectorcontroller = new GConnectorController();
519 GConnectorModel* connectorModel = new GConnectorModel();
520 vtkGConnectorView* connectorView = new vtkGConnectorView();
521 connectorModel->setGObjectType(type);
523 manContourModel->SetCloseContour(false);
524 connectorModel->setStartPort(startPort);
526 manContourView->SetModel(manContourModel);
527 manContourView->SetWxVtkBaseView(_baseView);
528 manContourView->SetRange(0.5);
529 manContourView->SetZ(900);
531 manContourView->SetColorNormalContour(0, 0, 1);
532 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
533 manContourView->SetColorSelectContour(1, 0.8, 0);
537 * Width increased from 2 to 5, it simplifies line handling and spline control :P
540 manContourView->SetWidthLine( 3 ) ;
541 manContourView->SetShowText(false);
543 manContourControl->SetModelView(manContourModel, manContourView);
545 manContourControl->CreateNewManualContour();
547 manContourView->RefreshContour();
550 connectorModel->getInicPoint(x, y, z);
552 manContourControl->SetState(1);
553 manContourModel->SetCloseContour(false);
555 manContourModel->AddPoint(x, y, z);
556 manContourView->AddPoint();
558 manContourModel->AddPoint(x, y, z);
559 manContourView->AddPoint();
561 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
562 manContourControl->_bakIdPoint = bak;
563 manContourView->Refresh();
565 manContourControl->SetMoving(false);
567 connectorcontroller->setModelAndView(connectorModel, connectorView);
569 int newId = addObjectController(connectorcontroller);
571 connectorcontroller->setManualContourController(manContourControl);
572 connectorModel->setManualContourModel(manContourModel);
573 connectorView->setManualContourView(manContourView);
574 connectorView->setModel(connectorModel);
575 connectorView->setBaseView(_baseView);
577 connectorModel->addObserver(connectorView);
578 connectorModel->addObserver(this);
583 //=========================================================================
585 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param) {
586 vtkInteractorStyleBaseView
587 * baseViewControlManager =
588 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
589 baseViewControlManager->AddInteractorStyleMaracas(param);
592 //=========================================================================
594 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param) {
595 vtkInteractorStyleBaseView
596 * baseViewControlManager =
597 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
598 baseViewControlManager->RemoveInteractorStyleMaracas(param);
601 //=========================================================================
603 vtkRenderer* wxVtkSceneManager::getRenderer() {
604 return _baseView->GetRenderer();
607 //=========================================================================
609 vtkRenderWindow* wxVtkSceneManager::getRenderWindow() {
610 return _baseView->GetRenWin();
612 //=========================================================================
615 //=========================================================================
616 int wxVtkSceneManager::GetIndexInSelected(int idControler) {
618 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
619 if (_selectedObjects[i] == idControler) {
626 //=========================================================================
628 void wxVtkSceneManager::update(int idController, int command) {
630 if (command != NO_COMMAND) {
631 if (command == ADD_TO_SELECTED) {
632 //EEDBorrame GObjectController* cont = _controllers[idController];
634 if (GetIndexInSelected(idController) == -1) {
635 _selectedObjects.push_back(idController);
639 // bool foundID=false;
640 // for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
642 // if(_selectedObjects[i]==idController)
649 // _selectedObjects.push_back(idController);
652 } else if (command == REMOVE_FROM_SELECTED) {
653 int index = GetIndexInSelected(idController);
655 _selectedObjects.erase(_selectedObjects.begin() + index);
657 } else if (command == INIT_CREATION_CONTOUR) {
660 typedef std::map<int , GObjectController*>::iterator TIterator ;
663 // Find current item in the controller
664 iter = _controllers.find( idController ) ;
665 iter_end = _controllers.end( ) ;
667 if ( iter != iter_end ) {
668 GObjectController* gobjc = iter->second ;
670 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
671 // And if the item is a port
672 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
673 TIterator c_it = _controllers.begin( ) ;
674 // Go through all componets
675 for ( c_it ; c_it != iter_end ; c_it++ ) {
676 GObjectController* obc = c_it->second ;
677 int obc_type = obc->getModel( )->getGObjectType( ) ;
678 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
679 // if the component is a port and the type is the same of that selected
680 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
682 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
683 //obc->getView( )->setState( HIGHLIGHTED ) ;
691 _worldState = INIT_CREATION_CONTOUR;
692 GObjectController* cont = _controllers[idController];
693 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
695 // The last one is the controller of the connector
696 std::map<int, GObjectController*>::iterator it2;
698 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
699 GObjectController *cont = it2->second;
700 if (cont->getGObjectType() == GPORT) {
701 GPortModel* port = (GPortModel*) cont->getModel();
702 if (port->getPortType() == GINPUTPORT) {
703 cont->SetActive(true);
705 cont->getView()->setState(NOTHING_HAPPENS);
706 cont->getModel()->notifyObservers(_idManager);
707 cont->SetActive(false);
710 cont->getView()->setState(NOTHING_HAPPENS);
711 cont->getModel()->notifyObservers(_idManager);
712 cont->SetActive(false);
715 _selectedObjects.clear();
716 _idConnectionInCreation = createGConnector(startOutputPort);
717 } else if (command == FIN_CREATION_CONTOUR && _worldState
718 == INIT_CREATION_CONTOUR) {
719 _worldState = NOTHING_HAPPENS;
720 //int id = _controllers.size()-1;
721 GObjectController *cont = _controllers[_idConnectionInCreation];
722 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
723 GObjectController *finPort = _controllers[idController];
725 if (finPort->getGObjectType() == GPORT) {
726 GPortModel* modelPort = (GPortModel*) finPort->getModel();
727 modelContour->setEndPort(modelPort);
730 typedef std::map<int, GObjectController*>::iterator TIterator;
731 TIterator c_it = _controllers.begin();
732 TIterator iter_end = _controllers.end();
733 // Go through all componets
734 for (c_it; c_it != iter_end; c_it++) {
735 GObjectController* obc = c_it->second;
736 int obc_type = obc->getModel()->getGObjectType();
737 int obc_state = obc->getView()->getState();
738 // if the component is a port and the type is the same of that selected
739 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
740 // Return element to neutral state if not selected
741 obc->getView()->setState(NOTHING_HAPPENS);
743 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
744 // Change element to connected state
745 obc->getView()->setState(HIGHLIGHTED);
752 _parent->saveTempDiagram();
755 manualConnectorContourController
757 ((GConnectorController*) cont)->getManualContourController();
758 manualConnectorContourView
760 (manualConnectorContourView*) manCont->GetManualViewBaseContour();
763 std::map<int, GObjectController*>::iterator it2;
765 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
766 GObjectController *cont = it2->second;
767 if (cont->getView() != NULL) {
768 cont->getView()->setState(NOTHING_HAPPENS);
769 cont->getModel()->notifyObservers(_idManager);
771 cont->SetActive(true);
779 //=========================================================================
781 bool wxVtkSceneManager::OnMouseMove() {
783 bool okStatusMessage = false;
784 bool okPortMessage = false;
785 wxVTKRenderWindowInteractor *wxVTKiren;
787 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
788 wxVTKiren->GetEventPosition(X, Y);
790 if (_worldState == DRAG_OBJECTS) {
791 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
792 int id = _selectedObjects[i];
793 GObjectController* cont = _controllers[id];
794 if (_startDragging) {
795 cont->getView()->setStartDragging(true);
797 cont->getView()->moveObject(X, Y);
798 cont->getView()->setState(DRAG);
799 cont->getModel()->notifyObservers(_idManager);
802 std::map<int, GObjectController*>::iterator it;
804 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
805 GObjectController *desc = it->second;
806 if (desc->getGObjectType() == GCONNECTOR) {
807 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
808 vconn->updateStartEndPoints();
812 _startDragging = false;
814 } else if (_worldState == NOTHING_HAPPENS || _worldState
815 == INIT_CREATION_CONTOUR) {
816 std::map<int, GObjectController*>::iterator it;
818 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
819 GObjectController *desc = it->second;
820 int type = desc->getGObjectType();
821 int state = desc->getView()->getState();
822 desc->getModel()->getCenter(px, py, pz);
825 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION )) {
827 okStatusMessage = true;
828 updateStatusBar(desc->getStatusText());
829 if (type == GBLACKBOX) {
830 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
831 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),
836 okPortMessage = true;
838 _textActor->SetInput(desc->getStatusText().c_str());
839 _textActor->SetScale(0.1);
840 _textActor->SetPosition(px - 25, py + 1, pz + 2);
845 _fillObjectActor->SetScale(1);
846 _fillObjectActor->GetProperty()->SetOpacity(0.50);
847 _fillObjectActor->SetPosition(px, py, 1);
848 _aPolygonMapper->Modified();
851 } // for controllers it
854 if (okStatusMessage == false) {
858 if (okPortMessage == false) {
859 _textActor->SetScale(0.0001);
860 _fillObjectActor->SetScale(0.0001);
865 //=========================================================================
867 bool wxVtkSceneManager::OnLeftButtonDown() {
869 if (_worldState == INIT_CREATION_CONTOUR) {
870 bool isOverPort = false;
871 std::map<int, GObjectController*>::iterator it;
872 for (it = _controllers.begin(); it != _controllers.end() && isOverPort
874 GObjectController *desc = it->second;
875 if (desc->getGObjectType() == GPORT) {
876 GPortModel *portmod = (GPortModel*) desc->getModel();
877 vtkGObjectView *portView = desc->getView();
878 if (portmod->getPortType() == GINPUTPORT
879 && portView->getState() == HIGHLIGHTED) {
883 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
885 portView->setState( HIGHLIGHTED);
892 if (isOverPort == false) {
894 UnSelectBlackBoxes();
898 } else { //_worldState
900 _worldState = DRAG_OBJECTS;
901 _startDragging = true;
904 _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
906 _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
907 ctrlkey = ctrlkey + shiftkey;
909 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
911 if (GetGBlackBoxControlerPointedByMouse() != NULL) {
912 int state = cont->getView()->getState();
913 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
914 UnSelectBlackBoxes();
917 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
918 int id = _selectedObjects[i];
919 GObjectController* cont = _controllers[id];
920 cont->getView()->setState(DRAG);
921 cont->getModel()->notifyObservers(_idManager);
924 } // if _selectedObjects.size
930 //=========================================================================
932 bool wxVtkSceneManager::OnLeftButtonUp() {
933 if (_worldState == DRAG_OBJECTS) {
934 _worldState = NOTHING_HAPPENS;
936 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
937 int id = _selectedObjects[i];
938 GObjectController* cont = _controllers[id];
939 cont->getView()->setState(SELECTED);
940 cont->getModel()->notifyObservers(_idManager);
946 //=========================================================================
947 void wxVtkSceneManager::CancelConnection() {
948 if (_worldState == INIT_CREATION_CONTOUR) {
949 _worldState = NOTHING_HAPPENS;
950 //int lastId = _controllers.size()-1;
952 GConnectorController *connector =
953 (GConnectorController*) _controllers[_idConnectionInCreation];
954 connector->removeFromScene();
955 unregisterController(connector);
956 _controllers.erase(_idConnectionInCreation);
958 std::map<int, GObjectController*>::iterator it;
959 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
960 GObjectController *desc = it->second;
961 desc->SetActive(true);
962 desc->getView()->setState(NOTHING_HAPPENS);
963 desc->getModel()->notifyObservers(_idManager);
968 //=========================================================================
970 bool wxVtkSceneManager::OnRightButtonUp() {
971 if (_worldState == INIT_CREATION_CONTOUR) {
974 UnSelectBlackBoxes();
980 bool wxVtkSceneManager::OnMiddleButtonDown() {
983 this->_vtkInteractorStyleBaseView->StartPan();
988 bool wxVtkSceneManager::OnMiddleButtonUp() {
991 this->_vtkInteractorStyleBaseView->EndPan();
998 //=========================================================================
1000 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1001 GObjectController *result = NULL;
1003 wxVTKRenderWindowInteractor *wxVTKiren;
1005 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1006 wxVTKiren->GetEventPosition(X, Y);
1008 std::map<int, GObjectController*>::iterator it;
1010 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1011 GObjectController *cont = it->second;
1012 int type = cont->getGObjectType();
1014 if (cont->getView()->isPointInside(X, Y) == true) {
1015 if (type == GBLACKBOX) {
1018 } // if isPointInside
1023 //=========================================================================
1024 void wxVtkSceneManager::UnSelectBlackBoxes() {
1025 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1026 int id = _selectedObjects[i];
1027 GObjectController* control = _controllers[id];
1028 control->getView()->setState(NOTHING_HAPPENS);
1029 }// for _selectedObjects
1030 _selectedObjects.clear();
1033 //=========================================================================
1034 bool wxVtkSceneManager::OnLeftDClick() {
1035 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1037 UnSelectBlackBoxes();
1038 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1044 wxVTKRenderWindowInteractor *wxVTKiren;
1045 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1046 wxVTKiren->GetEventPosition(X,Y);
1048 std::map<int, GObjectController*>::iterator it;
1050 bool clickOnObject = false;
1052 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1054 GObjectController *cont = it->second;
1055 int type = cont->getGObjectType();
1057 if(cont->getView()->isPointInside(X,Y))
1061 for (int i=0; i< (int)_selectedObjects.size(); i++)
1063 int id = _selectedObjects[i];
1064 GObjectController* control = _controllers[id];
1065 control->getView()->setState(NOTHING_HAPPENS);
1067 _selectedObjects.clear();
1069 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1070 _parent->editBlackBox(bbmodel);
1072 clickOnObject = true;
1076 if(clickOnObject==false)
1078 //_parent->editDiagramParameters(this);
1084 //=========================================================================
1086 bool wxVtkSceneManager::OnChar() {
1087 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1088 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1090 // KeyCode 127 : Delete Key
1091 // KeyCode 8 : Backspace Key
1092 if (keyCode == 8 || keyCode == 127) {
1093 if (_selectedObjects.size() > 0) {
1094 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1095 int id = _selectedObjects[i];
1096 std::map<int, GObjectController*>::iterator it;
1097 it = _controllers.find(id);
1098 if (it != _controllers.end()) {
1102 _selectedObjects.clear();
1108 if(_selectedObjects.size()){
1109 std::cout<<"objects to copy :";
1110 for(int i=0;i<_selectedObjects.size();i++){
1111 std::cout<<_selectedObjects.at(i)<<" ";
1113 DuplicateObjects(getSelectedObjects());
1115 std::cout<<"No objects to copy\n";
1122 //=========================================================================
1124 void wxVtkSceneManager::AddControlerToBeRemove(
1125 std::vector<int> *controllersToRemove, int id) {
1129 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1130 if (id == (*controllersToRemove)[i]) {
1136 controllersToRemove->push_back(id);
1141 //=========================================================================
1143 void wxVtkSceneManager::deleteObject(int id) {
1144 GObjectController *control = _controllers[id];
1145 std::vector<int> controllersToRemove;
1147 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1148 == GCOMPLEXINPUTPORT || control->getGObjectType()
1149 == GCOMPLEXOUTPUTPORT) {
1150 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1151 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1153 bool boxConnected = false;
1155 // Add box input controllers to be removed
1156 for (int i = 0; i < (int) inputs.size(); i++) {
1157 AddControlerToBeRemove(&controllersToRemove,
1158 inputs[i]->getObjectId());
1159 if (inputs[i]->isConnected()) {
1160 boxConnected = true;
1164 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1166 // Add box output controllers to be removed
1167 for (int i = 0; i < (int) outputs.size(); i++) {
1168 AddControlerToBeRemove(&controllersToRemove,
1169 outputs[i]->getObjectId());
1170 if (outputs[i]->isConnected()) {
1171 boxConnected = true;
1175 // Add connection controllers to be removed
1176 std::map<int, GObjectController*>::iterator it;
1177 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1178 GObjectController *cont = it->second;
1179 int type = cont->getGObjectType();
1180 if (type == GCONNECTOR) {
1181 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1182 if (conMod->getStartPort() != NULL
1183 && conMod->getStartPort()->getParentBox()->getObjectId()
1184 == bbmod->getObjectId()) {
1185 AddControlerToBeRemove(&controllersToRemove,
1186 conMod->getObjectId());
1188 if (conMod->getEndPort() != NULL
1189 && conMod->getEndPort()->getParentBox()->getObjectId()
1190 == bbmod->getObjectId()) {
1191 AddControlerToBeRemove(&controllersToRemove,
1192 conMod->getObjectId());
1197 // Add box controller to be removed
1198 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1199 } else if (control->getGObjectType() == GCONNECTOR) {
1200 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1201 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1204 std::map<int, GObjectController*>::iterator it;
1206 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1207 int key = controllersToRemove[i];
1208 it = _controllers.find(key);
1209 GObjectController *cont = _controllers[key];
1211 cont->removeFromScene();
1212 unregisterController((InteractorStyleMaracas*) cont);
1213 _controllers.erase(it);
1216 _parent->saveTempDiagram();
1219 //=========================================================================
1221 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1222 std::string boxName) {
1223 _parent->displayBlackBoxInfo(packageName, boxName);
1226 //=========================================================================
1228 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1229 _parent->updateStatusBar(textStatus);
1232 //=========================================================================
1233 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1234 std::string result = "";
1235 if (withLineNumber == true) {
1237 stringstream StrStream;
1239 std::string strValue = StrStream.str();
1242 } else if (value < 100) {
1246 result += strValue + ": ";
1250 //=========================================================================
1252 bool wxVtkSceneManager::MakeBoxExecutable() {
1253 std::map<int, GObjectController*> selected = getSelectedObjects();
1254 if( selected.empty() )
1257 std::map<int, GObjectController*>::iterator it;
1258 for (it = selected.begin(); it != selected.end(); ++it) {
1259 GObjectController* lastSelected = it->second;
1261 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1262 GBlackBoxModel *bbmodel =
1263 (GBlackBoxModel*) lastSelected->getModel();
1264 view->setState(HIGHLIGHTED);
1265 if (bbmodel->isExecutable()) {
1266 bbmodel->setExecutable(false);
1268 bbmodel->setExecutable(true);
1270 bbmodel->notifyObservers(lastSelected->getId());
1278 //=========================================================================
1280 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1281 bool existsExec = false;
1283 std::vector<std::string> packages;
1284 std::vector<int> boxes;
1285 std::vector<int> connections;
1286 std::vector<int> execBoxes;
1288 std::map<int, GObjectController*>::iterator it;
1290 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1291 GObjectController *desc = it->second;
1292 int type = desc->getGObjectType();
1294 if (type == GBLACKBOX) {
1295 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1297 std::string pkg = mod->getBBTKPackage();
1298 bool existsPkg = false;
1299 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1300 if (packages[t] == pkg) {
1305 packages.push_back(pkg);
1308 boxes.push_back(it->first);
1309 if (mod->isExecutable()) {
1310 execBoxes.push_back(it->first);
1313 } else if (type == GCONNECTOR) {
1314 connections.push_back(it->first);
1319 std::string script = "";
1320 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1321 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1322 script += LineNumber(wln, lnNmbr) + "\n";
1324 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1325 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1327 for (i = 0; i < (int) packages.size(); i++) {
1328 script += LineNumber(wln, lnNmbr);
1329 script += "include ";
1330 script += packages[i];
1334 script += LineNumber(wln, lnNmbr);
1339 script += LineNumber(wln, lnNmbr);
1340 script += "author \"";
1344 script += LineNumber(wln, lnNmbr);
1345 script += "description \"";
1346 script += _Description;
1349 script += LineNumber(wln, lnNmbr);
1350 script += "category \"";
1351 script += _Category;
1354 script += LineNumber(wln, lnNmbr);
1357 // script+="include std\n"; // JPR
1359 for (i = 0; i < (int) boxes.size(); i++) {
1360 script += LineNumber(wln, lnNmbr);
1363 GObjectController *control = _controllers[id];
1364 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1366 script += model->getBBTKType();
1368 script += model->getBBTKName();
1371 std::vector<GPortModel*> inputs = model->getInputPorts();
1372 for (int j = 0; j < (int) inputs.size(); j++) {
1373 GPortModel* inputPort = inputs[j];
1374 if (inputPort->isValueSet()) {
1375 script += LineNumber(wln, lnNmbr);
1377 script += model->getBBTKName();
1379 script += inputPort->getBBTKName();
1381 script += inputPort->getValue();
1386 script += LineNumber(wln, lnNmbr);
1391 script += LineNumber(wln, lnNmbr);
1394 for (i = 0; i < (int) connections.size(); i++) {
1395 script += LineNumber(wln, lnNmbr);
1396 script += "connect ";
1397 int id = connections[i];
1398 GObjectController *control = _controllers[id];
1399 GConnectorModel *model = (GConnectorModel*) control->getModel();
1401 //Start Connection info
1402 GPortModel *start = model->getStartPort();
1403 script += start->getParentBox()->getBBTKName();
1405 script += start->getBBTKName();
1409 //End Connection info
1410 GPortModel *end = model->getEndPort();
1411 script += end->getParentBox()->getBBTKName();
1413 script += end->getBBTKName();
1418 script += LineNumber(wln, lnNmbr);
1420 for (i = 0; i < (int) execBoxes.size(); i++) {
1421 script += LineNumber(wln, lnNmbr);
1423 int id = execBoxes[i];
1424 GObjectController *control = _controllers[id];
1425 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1427 script += model->getBBTKName();
1436 //=========================================================================
1438 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1439 std::vector<std::string> packages;
1440 std::vector<int> boxes;
1441 std::vector<int> connections;
1442 std::vector<int> execBoxes;
1444 std::map<int, GObjectController*>::iterator it;
1446 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1447 GObjectController *desc = it->second;
1448 int type = desc->getGObjectType();
1450 if (type == GBLACKBOX) {
1451 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1453 std::string pkg = mod->getBBTKPackage();
1454 bool existsPkg = false;
1455 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1456 if (packages[t] == pkg) {
1461 packages.push_back(pkg);
1464 boxes.push_back(it->first);
1465 if (mod->isExecutable()) {
1466 execBoxes.push_back(it->first);
1468 } else if (type == GCONNECTOR) {
1469 connections.push_back(it->first);
1473 std::string script = "";
1475 script += "include std\n"; // EED
1476 script += "include itkvtk\n"; // EED
1478 for (i = 0; i < (int) packages.size(); i++) {
1479 script += "include ";
1480 script += packages[i];
1485 // Definition of a complex box
1486 script += "define ";
1487 script += _cbName + " " + _cbPackageName;
1491 script += "author \"";
1495 script += "description \"";
1496 script += _Description;
1500 script += "category \"";
1501 script += _Category;
1506 for (i = 0; i < (int) boxes.size(); i++) {
1509 GObjectController *control = _controllers[id];
1510 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1512 script += model->getBBTKType();
1514 script += model->getBBTKName();
1517 std::vector<GPortModel*> inputs = model->getInputPorts();
1518 for (int j = 0; j < (int) inputs.size(); j++) {
1519 GPortModel* inputPort = inputs[j];
1520 if (inputPort->isValueSet()) {
1522 script += model->getBBTKName();
1524 script += inputPort->getBBTKName();
1526 script += inputPort->getValue();
1534 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1536 std::string complexInputs = "";
1537 std::string complexOutputs = "";
1540 for (i = 0; i < (int) connections.size(); i++) {
1541 int id = connections[i];
1542 GObjectController *control = _controllers[id];
1543 GConnectorModel *model = (GConnectorModel*) control->getModel();
1546 GPortModel *start = model->getStartPort();
1547 GBoxModel *startBox = start->getParentBox();
1549 GPortModel *end = model->getEndPort();
1550 GBoxModel *endBox = end->getParentBox();
1552 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1553 complexInputs += "input ";
1554 complexInputs += startBox->getBBTKName();
1556 complexInputs += " ";
1557 complexInputs += endBox->getBBTKName();
1558 complexInputs += ".";
1559 complexInputs += end->getBBTKName();
1561 complexInputs += " ";
1562 complexInputs += "\" \"";
1564 complexInputs += "\n";
1565 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1566 complexOutputs += "output ";
1567 complexOutputs += endBox->getBBTKName();
1569 complexOutputs += " ";
1570 complexOutputs += startBox->getBBTKName();
1571 complexOutputs += ".";
1572 complexOutputs += start->getBBTKName();
1574 complexOutputs += " ";
1575 complexOutputs += "\" \"";
1577 complexOutputs += "\n";
1579 script += "connect ";
1580 script += startBox->getBBTKName();
1582 script += start->getBBTKName();
1586 //End Connection info
1587 script += endBox->getBBTKName();
1589 script += end->getBBTKName();
1597 for (i = 0; i < (int) execBoxes.size(); i++) {
1599 int id = execBoxes[i];
1600 GObjectController *control = _controllers[id];
1601 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1603 script += model->getBBTKName();
1608 script += "# Complex input ports\n";
1609 script += complexInputs;
1612 script += "# Complex output ports\n";
1613 script += complexOutputs;
1616 script += "endefine";
1622 //=========================================================================
1624 void wxVtkSceneManager::deleteAllBoxes() {
1625 std::map<int, GObjectController*>::iterator it;
1626 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1627 GObjectController *cont = it->second;
1628 cont->removeFromScene();
1629 unregisterController((InteractorStyleMaracas*) cont);
1631 _selectedObjects.clear();
1632 _controllers.clear();
1636 //=========================================================================
1639 void wxVtkSceneManager::refresh() {
1640 _baseView->Refresh();
1642 //=========================================================================
1644 void wxVtkSceneManager::refreshScene() {
1645 _baseView->RefreshView();
1648 //=========================================================================
1650 void wxVtkSceneManager::centerView() {
1652 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1653 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1654 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1655 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1656 _baseView->RefreshView();
1660 //=========================================================================
1662 void wxVtkSceneManager::saveDiagram(std::string &content) {
1665 content += "CATEGORY:";
1666 content += GetCategory();
1669 content += "DESCRIPTION:";
1670 content += GetDescription();
1673 content += "AUTHOR:";
1674 content += GetAuthor();
1677 //Print info IF COMPLEX BOX
1678 content += "COMPLEXBOX:";
1679 if (_isComplexBox) {
1680 content += "TRUE\n";
1682 content += "COMPLEXBOXNAME:";
1683 content += GetCbName();
1686 content += "PACKAGENAME:";
1687 content += GetCbPackageName();
1690 //Print info complex input ports
1691 std::vector<int> inputs = getComplexInputPorts();
1692 int insize = inputs.size();
1693 content += "COMPLEXINPUTS:";
1694 sprintf(buffer, "%d", insize);
1698 for (int i = 0; i < insize; i++) {
1700 GObjectController *cont = _controllers[id];
1701 cont->getModel()->save(content);
1704 //Print info complex output ports
1705 std::vector<int> outputs = getComplexOutputPorts();
1706 int outsize = outputs.size();
1707 content += "COMPLEXOUTPUTS:";
1708 sprintf(buffer, "%d", outsize);
1712 for (int i = 0; i < outsize; i++) {
1713 int id = outputs[i];
1714 GObjectController *cont = _controllers[id];
1715 cont->getModel()->save(content);
1719 content += "FALSE\n";
1723 std::vector<int> boxes = getBlackBoxes();
1724 int bsize = boxes.size();
1725 content += "BOXES:";
1726 sprintf(buffer, "%d", bsize);
1730 for (int i = 0; i < bsize; i++) {
1732 GObjectController *cont = _controllers[id];
1733 cont->getModel()->save(content);
1737 std::vector<int> connections = getConnections();
1738 int csize = connections.size();
1739 content += "CONNECTIONS:";
1740 sprintf(buffer, "%d", csize);
1744 for (int i = 0; i < csize; i++) {
1745 int id = connections[i];
1746 GObjectController *cont = _controllers[id];
1747 cont->getModel()->save(content);
1752 //=========================================================================
1754 void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
1756 std::string version = "<void>";
1757 std::string line = "";
1758 char delims[] = ":";
1759 char *result = NULL;
1761 getline(inputStream, line);
1764 while (!inputStream.eof()) {
1765 if (line == "" || line[0] == '#') {
1766 getline(inputStream, line);
1767 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1768 version = line.substr(18, 3);
1770 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1771 version = line.substr(18, 3);
1773 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1774 version = line.substr(18, 3);
1776 } else if (line == "APP_START") {
1782 printf("EED wxVtkSceneManager::loadDiagram version=%s\n", version.c_str());
1786 if ((version != "1.0") && (version != "1.1")) {
1787 getline(inputStream, line);//CATEGORY:<category of the box>
1788 char categoryTmp[30];
1789 strcpy(categoryTmp, line.c_str());
1790 result = strtok(categoryTmp, delims);
1791 result = strtok(NULL, delims);
1792 SetCategory(result);
1794 getline(inputStream, line);//DESCRIPTION:<description of the box>
1795 char descriptionTmp[1024];
1796 strcpy(descriptionTmp, line.c_str());
1797 result = strtok(descriptionTmp, delims);
1798 result = strtok(NULL, delims);
1799 SetDescription(result);
1801 getline(inputStream, line);//AUTHOR:<author>
1802 char authorTmp[255];
1803 strcpy(authorTmp, line.c_str());
1804 result = strtok(authorTmp, delims);
1805 result = strtok(NULL, delims);
1810 getline(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1811 char complexTmp[30];
1812 strcpy(complexTmp, line.c_str());
1813 result = strtok(complexTmp, delims);
1814 result = strtok(NULL, delims);
1815 std::string isComplexBox(result);
1817 if (isComplexBox == "TRUE") {
1818 _isComplexBox = true;
1820 if ((version != "1.0") && (version != "1.1")) {
1821 getline(inputStream, line);//COMPLEXNAME:<name of the complex box>
1822 char complexboxnameTmp[255];
1823 strcpy(complexboxnameTmp, line.c_str());
1824 result = strtok(complexboxnameTmp, delims);
1825 result = strtok(NULL, delims);
1828 getline(inputStream, line);//PACKAGENAME:<name of the package of the box>
1829 char packagenameTmp[255];
1830 strcpy(packagenameTmp, line.c_str());
1831 result = strtok(packagenameTmp, delims);
1832 result = strtok(NULL, delims);
1833 SetCbPackageName(result);
1836 //-----------------------
1837 //- COMPLEX INPUT PORTS
1838 //-----------------------
1839 getline(inputStream, line);//COMPLEXINPUTS:num
1841 strcpy(inputs, line.c_str());
1842 result = strtok(inputs, delims);
1843 result = strtok(NULL, delims);
1846 std::istringstream inps(result);
1849 for (int i = 0; i < numInputs; i++) {
1851 getline(inputStream, line);//COMPLEX_PORT
1852 getline(inputStream, line);//name
1853 std::string inputPortName(line);
1856 getline(inputStream, line);//xInic:yInic:zInic
1858 strcpy(coord, line.c_str());
1859 result = strtok(coord, delims);//xInic
1860 std::string xInic(result);
1861 result = strtok(NULL, delims);//yInic
1862 std::string yInic(result);
1863 result = strtok(NULL, delims);//zInic
1864 std::string zInic(result);
1866 double xIn, yIn, zIn;
1867 std::istringstream xSt(xInic);
1869 std::istringstream ySt(yInic);
1871 std::istringstream zSt(zInic);
1874 getline(inputStream, line);//FIN_COMPLEX_PORT
1876 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
1878 } // for input complex box
1881 //-----------------------
1882 //- COMPLEX OUTPUT PORTS
1883 //-----------------------
1885 getline(inputStream, line);//COMPLEXOUTPUTS:num
1887 strcpy(outputs, line.c_str());
1888 result = strtok(outputs, delims);
1889 result = strtok(NULL, delims);
1892 std::istringstream outps(result);
1893 outps >> numOutputs;
1895 for (int i = 0; i < numOutputs; i++) {
1897 getline(inputStream, line);//COMPLEX_PORT
1898 getline(inputStream, line);//name
1899 std::string outputPortName(line);
1902 getline(inputStream, line);//xInic:yInic:zInic
1904 strcpy(coord, line.c_str());
1905 result = strtok(coord, delims);//xInic
1906 std::string xInic(result);
1907 result = strtok(NULL, delims);//yInic
1908 std::string yInic(result);
1909 result = strtok(NULL, delims);//zInic
1910 std::string zInic(result);
1912 double xIn, yIn, zIn;
1913 std::istringstream xSt(xInic);
1915 std::istringstream ySt(yInic);
1917 std::istringstream zSt(zInic);
1920 getline(inputStream, line);//FIN_COMPLEX_PORT
1922 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn,
1925 } // for output complex box
1930 getline(inputStream, line);//BOXES:num
1932 strcpy(boxes, line.c_str());
1933 result = strtok(boxes, delims);
1934 result = strtok(NULL, delims);
1937 std::istringstream is(result);
1940 for (int i = 0; i < numBoxes; i++) {
1942 getline(inputStream, line);//BOX
1943 getline(inputStream, line);//package:type:name
1945 strcpy(box, line.c_str());
1946 result = strtok(box, delims);//package
1947 std::string package(result);
1948 result = strtok(NULL, delims);//type
1949 std::string type(result);
1950 result = strtok(NULL, delims);//name
1951 std::string name(result);
1953 getline(inputStream, line);//ISEXEC:TRUE|FALSE
1955 strcpy(exec, line.c_str());
1956 result = strtok(exec, delims);//ISEXEC
1957 result = strtok(NULL, delims);//TRUE|FALSE
1958 std::string isExec(result);
1961 getline(inputStream, line);//xInic:yInic:zInic
1963 strcpy(coord, line.c_str());
1964 result = strtok(coord, delims);//xInic
1965 std::string xInic(result);
1966 result = strtok(NULL, delims);//yInic
1967 std::string yInic(result);
1968 result = strtok(NULL, delims);//zInic
1969 std::string zInic(result);
1971 double xIn, yIn, zIn;
1972 std::istringstream xSt(xInic);
1974 std::istringstream ySt(yInic);
1976 std::istringstream zSt(zInic);
1980 getline(inputStream, line);//xEnd:yEnd:zEnd
1981 strcpy(coord, line.c_str());
1982 result = strtok(coord, delims);//xEnd
1983 std::string xEnd(result);
1984 result = strtok(NULL, delims);//yEnd
1985 std::string yEnd(result);
1986 result = strtok(NULL, delims);//zEnd
1987 std::string zEnd(result);
1989 double xEn, yEn, zEn;
1990 std::istringstream xEt(xEnd);
1992 std::istringstream yEt(yEnd);
1994 std::istringstream zEt(zEnd);
1997 bool boxExecutable = false;
1998 if (isExec == "TRUE") {
1999 boxExecutable = true;
2002 int idBox = createGBlackBox(xIn, yIn, package, type);
2003 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn,
2006 GObjectController *cont = _controllers[idBox];
2007 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2010 getline(inputStream, line);//PORT o FIN_BOX
2011 std::string port = line.substr(0, 4);
2012 while (port == "PORT") {
2013 getline(inputStream, line);//name:value
2015 strcpy(poort, line.c_str());
2016 result = strtok(poort, delims);//name
2017 std::string name(result);
2018 result = strtok(NULL, delims);//value
2019 std::string value(result);
2021 bbmod->setValueToInput(name, value);
2023 getline(inputStream, line);//PORT o FIN_BOX
2024 port = line.substr(0, 4);
2027 //EED bbmod->notifyObservers(_idManager);
2032 getline(inputStream, line);//CONNECTIONS:num
2034 strcpy(conns, line.c_str());
2035 result = strtok(conns, delims);
2036 result = strtok(NULL, delims);
2039 std::istringstream isCons(result);
2042 for (int i = 0; i < numConns; i++) {
2044 getline(inputStream, line);//CONNECTION
2045 getline(inputStream, line);//Startbox.PortName:EndBox.PortName
2048 strcpy(connec, line.c_str());
2049 result = strtok(connec, delims);
2050 std::string nameStartBox(result);
2051 result = strtok(NULL, delims);
2052 std::string nameStartPort(result);
2053 result = strtok(NULL, delims);
2054 std::string nameEndBox(result);
2055 result = strtok(NULL, delims);
2056 std::string nameEndPort(result);
2058 int idCon = configGConnetion(nameStartBox, nameStartPort,
2059 nameEndBox, nameEndPort);
2061 if (version != "1.0") {
2062 //Readding control points of the manualContour
2064 GConnectorController *tempp =
2065 (GConnectorController*) _controllers[idCon];
2066 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2067 vtkGConnectorView *conView =
2068 (vtkGConnectorView*) tempp->getView();
2069 getline(inputStream, line); //NumberOfControlPoints:##
2070 strcpy(conns, line.c_str());
2071 result = strtok(conns, delims);
2072 result = strtok(NULL, delims);
2074 int numberOfControlPoints;
2075 std::istringstream isCons(result);
2076 isCons >> numberOfControlPoints;
2078 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2079 getline(inputStream, line); //XX:YY:ZZ
2081 strcpy(connec, line.c_str());
2084 result = strtok(connec, delims);
2085 std::istringstream isPointX(result);
2087 result = strtok(NULL, delims);
2088 std::istringstream isPointY(result);
2090 result = strtok(NULL, delims);
2091 std::istringstream isPointZ(result);
2094 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px,
2096 conView->getManualContourView()->AddPoint();
2106 //=========================================================================
2109 //=========================================================================
2110 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2111 std::string portName, double xIn, double yIn, double zIn) {
2113 if (inputoutput == true) {
2114 idPort = createGComplexBoxInputPort(portName);
2116 idPort = createGComplexBoxOutputPort(portName);
2118 GObjectController *cont = _controllers[idPort];
2119 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2120 cbmod->setInicPoint(xIn, yIn, zIn);
2121 cbmod->notifyObservers(_idManager);
2123 //=========================================================================
2126 //=========================================================================
2127 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
2131 GBoxModel *boxModel = NULL;
2132 std::vector<int> lstB = getBlackBoxes();
2133 for (j = 0; j < (int) lstB.size(); j++) {
2135 bMod = (GBoxModel*) _controllers[idB]->getModel();
2136 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2141 if ((_isComplexBox) && (boxModel == NULL)) {
2142 std::vector<int> lstInputs = getComplexInputPorts();
2143 for (j = 0; j < (int) lstInputs.size(); j++) {
2145 bMod = (GBoxModel*) _controllers[idB]->getModel();
2146 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2151 std::vector<int> lstOutputs = getComplexOutputPorts();
2152 for (j = 0; j < (int) lstOutputs.size(); j++) {
2153 int idB = lstOutputs[j];
2154 bMod = (GBoxModel*) _controllers[idB]->getModel();
2155 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2165 //=========================================================================
2168 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2169 std::string nameStartPort, std::string nameEndBox,
2170 std::string nameEndPort) {
2172 GBoxModel *boxModel;
2173 GPortModel *startP = NULL;
2174 GPortModel *endP = NULL;
2176 boxModel = findGBox(nameStartBox);
2177 if (boxModel != NULL) {
2178 startP = boxModel->getOutputPort(nameStartPort);
2181 boxModel = findGBox(nameEndBox);
2182 if (boxModel != NULL) {
2183 endP = boxModel->getInputPort(nameEndPort);
2187 int idCon = createGConnector(startP);
2188 _worldState = NOTHING_HAPPENS;
2189 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2191 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2192 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2193 tempp->endContourCreation();
2194 conMod->setEndPort(endP);
2195 conView->updateStartEndPoints();
2199 //=========================================================================
2201 bool wxVtkSceneManager::boxExist(std::string boxname) {
2203 std::map<int, GObjectController*>::iterator it;
2204 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2205 GObjectController *cont = it->second;
2206 if (cont->getModel()->getBBTKName() == boxname) {
2213 //=========================================================================
2215 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2216 std::vector<int> vect;
2217 std::map<int, GObjectController*>::iterator it;
2218 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2219 GObjectController *cont = it->second;
2220 if (cont->getGObjectType() == GBLACKBOX) {
2221 vect.push_back(cont->getId());
2227 //=========================================================================
2229 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2230 std::vector<int> vect;
2231 std::map<int, GObjectController*>::iterator it;
2232 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2233 GObjectController *cont = it->second;
2234 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2235 vect.push_back(cont->getId());
2241 //=========================================================================
2243 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2244 std::vector<int> vect;
2245 std::map<int, GObjectController*>::iterator it;
2246 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2247 GObjectController *cont = it->second;
2248 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2249 vect.push_back(cont->getId());
2255 //=========================================================================
2257 std::vector<int> wxVtkSceneManager::getConnections() {
2258 std::vector<int> vect;
2259 std::map<int, GObjectController*>::iterator it;
2260 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2261 GObjectController *cont = it->second;
2262 if (cont->getGObjectType() == GCONNECTOR) {
2263 vect.push_back(cont->getId());
2269 //=========================================================================
2271 bool wxVtkSceneManager::isComplexBox() {
2272 return _isComplexBox;
2275 //=========================================================================
2277 void wxVtkSceneManager::setComplexBox(bool val) {
2278 _isComplexBox = val;
2281 //=========================================================================
2283 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2284 //Register the controller of the new object
2285 registerController((InteractorStyleMaracas*) objController);
2286 //Add the object to the objects list
2287 int newId = _contLastId;//_controllers.size();
2288 objController->setId(newId);
2289 _controllers[newId] = objController;
2290 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2295 //=========================================================================
2297 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2299 std::map<int, int> oldIdNewIdBoxes;
2300 std::vector<int> connections;
2302 std::vector<int> newBoxesID;
2304 std::map<int, GObjectController*>::iterator it;
2305 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2306 GObjectController *cont = it->second;
2307 int type = cont->getGObjectType();
2309 if (type == GBLACKBOX) {
2311 double xInic, yInic, zInic;
2312 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2313 copyBox->getInicPoint(xInic, yInic, zInic);
2314 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2315 copyBox->getBBTKType());
2317 int idcB = copyBox->getObjectId();
2318 oldIdNewIdBoxes[idcB] = idBox;
2319 cont = _controllers[idBox];
2320 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2321 newbox->setInicPoint(xInic, yInic, zInic);
2322 int num = newbox->getNumInputPorts();
2323 for (int j = 0; j < num; j++) {
2324 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2326 newbox->move(xInic + 20, yInic + 20, zInic);
2327 newbox->notifyObservers(_idManager);
2328 newBoxesID.push_back(newbox->getObjectId());
2330 } else if (type == GCONNECTOR) {
2331 int idCon = cont->getId();
2332 connections.push_back(idCon);
2337 for (int i = 0; i < (int) connections.size(); i++) {
2338 int objId = connections[i];
2339 GObjectController *cont = objectsMap[objId];
2340 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2342 GPortModel* startPort = connectModel->getStartPort();
2343 int startPortIndex = startPort->getPosInBox();
2344 GPortModel* endPort = connectModel->getEndPort();
2345 int endPortIndex = endPort->getPosInBox();
2347 GBlackBoxModel* startPortParentBox =
2348 (GBlackBoxModel*) startPort->getParentBox();
2349 GBlackBoxModel* endPortParentBox =
2350 (GBlackBoxModel*) endPort->getParentBox();
2352 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2353 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2355 GBlackBoxModel* newStartBox =
2356 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2357 GBlackBoxModel* newEndBox =
2358 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2360 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2361 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2363 // Creates connection
2364 int idCon = createGConnector(newStartPort);
2365 GConnectorController *tempp =
2366 (GConnectorController*) _controllers[idCon];
2367 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2368 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2369 tempp->endContourCreation();
2370 conMod->setEndPort(newEndPort);
2371 conView->updateStartEndPoints();
2374 /// the new selected boxes are the duplicate ones
2376 UnSelectBlackBoxes();
2377 for (int i = 0; i < newBoxesID.size(); i++) {
2378 _selectedObjects.push_back(newBoxesID.at(i));
2381 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2382 int id = _selectedObjects[i];
2383 GObjectController* cont = _controllers[id];
2385 cont->getView()->setState(SELECTED);
2386 cont->getModel()->notifyObservers(_idManager);
2393 //=========================================================================
2395 int wxVtkSceneManager::getNumSelectedObjects() {
2396 return _selectedObjects.size();
2399 //=========================================================================
2401 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2402 std::map<int, GObjectController*> mapSelected;
2404 std::map<int, GObjectController*>::iterator it;
2405 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2406 GObjectController *cont = it->second;
2407 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2409 mapSelected[cont->getId()] = cont;
2413 std::map<int, GObjectController*>::iterator it2;
2414 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2415 GObjectController *cont = it2->second;
2416 if (cont->getGObjectType() == GCONNECTOR) {
2417 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2418 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2419 GBoxModel* startPortParentBox =
2420 cmod->getStartPort()->getParentBox();
2422 std::map<int, GObjectController*>::iterator iterOBJ1 =
2423 mapSelected.find(startPortParentBox->getObjectId());
2424 std::map<int, GObjectController*>::iterator iterOBJ2 =
2425 mapSelected.find(endPortParentBox->getObjectId());
2427 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2428 int ID = cont->getId();
2429 mapSelected[ID] = cont;
2436 //=========================================================================
2438 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2440 std::map<int, int> oldIdNewIdBoxes;
2441 std::vector<int> connections;
2443 std::map<int, GObjectController*>::iterator it;
2444 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2445 GObjectController *cont = it->second;
2446 int type = cont->getGObjectType();
2448 if (type == GBLACKBOX) {
2450 double xInic, yInic, zInic;
2451 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2452 copyBox->getInicPoint(xInic, yInic, zInic);
2453 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2454 copyBox->getBBTKType());
2456 int idcB = copyBox->getObjectId();
2457 oldIdNewIdBoxes[idcB] = idBox;
2458 cont = _controllers[idBox];
2459 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2460 newbox->setInicPoint(xInic, yInic, zInic);
2461 int num = newbox->getNumInputPorts();
2462 for (int j = 0; j < num; j++) {
2463 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2465 newbox->notifyObservers(_idManager);
2466 } else if (type == GCONNECTOR) {
2467 int idCon = cont->getId();
2468 connections.push_back(idCon);
2473 for (int i = 0; i < (int) connections.size(); i++) {
2474 int objId = connections[i];
2475 GObjectController *cont = objectsMap[objId];
2476 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2478 GPortModel* startPort = connectModel->getStartPort();
2479 int startPortIndex = startPort->getPosInBox();
2480 GPortModel* endPort = connectModel->getEndPort();
2481 int endPortIndex = endPort->getPosInBox();
2483 GBlackBoxModel* startPortParentBox =
2484 (GBlackBoxModel*) startPort->getParentBox();
2485 GBlackBoxModel* endPortParentBox =
2486 (GBlackBoxModel*) endPort->getParentBox();
2488 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2489 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2491 GBlackBoxModel* newStartBox =
2492 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2493 GBlackBoxModel* newEndBox =
2494 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2496 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2497 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2499 // Creates connection
2500 int idCon = createGConnector(newStartPort);
2501 GConnectorController *tempp =
2502 (GConnectorController*) _controllers[idCon];
2503 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2504 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2505 tempp->endContourCreation();
2506 conMod->setEndPort(newEndPort);
2507 conView->updateStartEndPoints();
2510 std::map<int, int>::iterator itIds;
2511 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2512 int idOld = itIds->first;
2513 int idNew = itIds->second;
2515 GBlackBoxModel* oldBox =
2516 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2517 GBlackBoxModel* newBox =
2518 (GBlackBoxModel*) _controllers[idNew]->getModel();
2520 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2521 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2522 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2523 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2525 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2527 //EED int toCreate=-1;
2528 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2529 if (oldInputConnections[k] == newInputConnections[l]) {
2534 if (exist == false) {
2535 //Create complex input
2536 int posInBox = oldInputConnections[k];
2537 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2538 std::string inputPortName = inputPort->getBBTKName();
2539 int idInputPort = createGComplexBoxInputPort(inputPortName);
2540 GObjectController *cont = _controllers[idInputPort];
2541 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2542 double xIn, yIn, zIn;
2543 inputPort->getInicPoint(xIn, yIn, zIn);
2545 cbmod->setInicPoint(xIn, yIn, zIn);
2546 cbmod->notifyObservers(_idManager);
2548 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2550 // Creates connection
2551 int idCon = createGConnector(cbmod->getOutputPort(0));
2552 GConnectorController *tempp =
2553 (GConnectorController*) _controllers[idCon];
2554 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2555 vtkGConnectorView *conView =
2556 (vtkGConnectorView*) tempp->getView();
2557 tempp->endContourCreation();
2558 conMod->setEndPort(inputPortEnd);
2559 conView->updateStartEndPoints();
2565 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2567 //EED int toCreate=-1;
2568 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2569 if (oldOutputConnections[k] == newOutputConnections[l]) {
2574 if (exist == false) {
2575 //Create complex output
2576 int posInBox = oldOutputConnections[k];
2577 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2578 std::string outputPortName = outputPort->getBBTKName();
2579 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2580 GObjectController *cont = _controllers[idOutputPort];
2581 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2582 double xIn, yIn, zIn;
2583 outputPort->getInicPoint(xIn, yIn, zIn);
2585 cbmod->setInicPoint(xIn, yIn, zIn);
2586 cbmod->notifyObservers(_idManager);
2588 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2590 // Creates connection
2591 int idCon = createGConnector(outputPortEnd);
2592 GConnectorController *tempp =
2593 (GConnectorController*) _controllers[idCon];
2594 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2595 vtkGConnectorView *conView =
2596 (vtkGConnectorView*) tempp->getView();
2597 tempp->endContourCreation();
2598 conMod->setEndPort(cbmod->getInputPort(0));
2599 conView->updateStartEndPoints();
2609 //=========================================================================
2610 void wxVtkSceneManager::SetCbName(std::string cbName) {
2612 if (_cbName == "") {
2613 _cbName = "<complex box name>";
2617 //=========================================================================
2618 std::string wxVtkSceneManager::GetCbName() {
2622 //=========================================================================
2623 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2624 _cbPackageName = packagename;
2625 if (_cbPackageName == "") {
2626 _cbPackageName = "<package name of the complex box>";
2630 //=========================================================================
2631 std::string wxVtkSceneManager::GetCbPackageName() {
2632 return _cbPackageName;
2635 //=========================================================================
2636 void wxVtkSceneManager::SetAuthor(std::string author) {
2638 if (_Author == "") {
2639 _Author = "<author of the box>";
2643 //=========================================================================
2644 std::string wxVtkSceneManager::GetAuthor() {
2648 //=========================================================================
2649 void wxVtkSceneManager::SetCategory(std::string category) {
2650 _Category = category;
2651 if (_Category == "") {
2652 _Category = "<category of the box>";
2656 //=========================================================================
2657 std::string wxVtkSceneManager::GetCategory() {
2661 //=========================================================================
2662 void wxVtkSceneManager::SetDescription(std::string description) {
2663 _Description = description;
2664 if (_Description == "") {
2665 _Description = "<description of the box>";
2669 //=========================================================================
2670 std::string wxVtkSceneManager::GetDescription() {
2671 return _Description;
2674 //=========================================================================
2677 void wxVtkSceneManager::printAll(int com , int sta ){
2679 int tmpState = sta ;
2680 if ( tmpState == NOTHING_HAPPENS ) {
2681 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2683 if ( tmpState == HIGHLIGHTED ) {
2684 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2686 if ( tmpState == POSSIBLE_CONNECTION ) {
2687 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2689 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2690 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2692 if ( tmpState == CLICKED ) {
2693 std::cout << "CONTROLER STATE---->CLICKED\n" ;
2695 if ( tmpState == DRAG ) {
2696 std::cout << "CONTROLER STATE---->DRAG\n" ;
2698 if ( tmpState == SELECTED ) {
2699 std::cout << "CONTROLER STATE---->SELECTED\n" ;
2701 if ( tmpState == CREATING_CONTOUR ) {
2702 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2708 if ( command == INIT_CREATION_CONTOUR ) {
2709 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2711 if ( command == FIN_CREATION_CONTOUR ) {
2712 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2714 if ( command == ADD_TO_SELECTED ) {
2715 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2717 if ( command == DRAG_OBJECTS ) {
2718 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2720 if ( command == EDIT_BLACKBOX ) {
2721 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
2723 if ( command == REMOVE_FROM_SELECTED ) {
2724 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
2730 } // EO namespace bbtk