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()\n", this);
95 //=========================================================================
97 void wxVtkSceneManager::configureBaseView() {
98 printf("EED wxVtkSceneManager::configureBaseView 0\n");
99 vtkInteractorStyleBaseView2D *interactorstylebaseview =
100 vtkInteractorStyleBaseView2D::New();
102 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
104 // Important to activate the 2D interaction system
105 wxVTKRenderWindowInteractor *iren =
106 _baseView->GetWxVTKRenderWindowInteractor();
107 interactorstylebaseview->SetInteractor(iren);
108 iren->SetInteractorStyle(interactorstylebaseview);
109 interactorstylebaseview->SetwxVtkBaseView(_baseView);
111 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
112 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, 800, 1100);
114 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
115 _baseView->GetRenderer()->GradientBackgroundOn();
116 _baseView->Refresh();
119 _textActor = vtkTextActor3D::New();
120 _textActor->SetPosition(-9999, -9999, 900);
121 _textActor->SetInput("<void>");
122 _textActor->GetTextProperty()->SetFontSize(60);
123 _textActor->GetTextProperty()->BoldOn();
124 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,
127 _baseView->GetRenderer()->AddActor(_textActor);
129 // Actor Fill_Port_Text
136 vtkPolygon *aPolygon = vtkPolygon::New();
137 _fillObjectActor = vtkActor::New();
139 _pts = vtkPoints::New();
141 double w = 100, h = 10, b = h / 15, t = 3;
142 _pts->SetNumberOfPoints(21);
143 _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
144 _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
145 _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
146 _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
147 _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
149 _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
150 _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
151 _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
152 _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
154 _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
155 _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
156 _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
157 _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
159 _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
160 _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
161 _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
162 _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
164 _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
165 _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
166 _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
167 _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
169 aPolygon->GetPointIds()->SetNumberOfIds(21);
170 for (int i = 0; i < 21; i++) {
171 aPolygon->GetPointIds()->SetId(i, i);
174 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
175 aPolygonGrid->Allocate(1, 1);
176 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),
177 aPolygon->GetPointIds());
178 aPolygonGrid->SetPoints(_pts);
179 _aPolygonMapper = vtkDataSetMapper::New();
180 _aPolygonMapper->SetInput(aPolygonGrid);
181 _fillObjectActor->SetMapper(_aPolygonMapper);
182 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
184 _fillObjectActor->GetProperty()->SetOpacity(0);
185 _aPolygonMapper->Modified();
187 _baseView->GetRenderer()->AddActor(_fillObjectActor);
188 printf("EED wxVtkSceneManager::configureBaseView 1\n");
191 //=========================================================================
193 std::string wxVtkSceneManager::generateANewNameForABox() {
194 std::stringstream boxname;
195 if (_numBoxes < 10) {
196 boxname << "Box0" << _numBoxes;
198 boxname << "Box" << _numBoxes;
201 return boxname.str();
204 //=========================================================================
206 std::string wxVtkSceneManager::findANewNameForABox() {
207 std::string boxname = generateANewNameForABox();
209 while (boxExist(boxname) == true) {
210 boxname = generateANewNameForABox();
216 //=========================================================================
217 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
218 double zIn, std::string name, bool boxExecutable, double xEn,
219 double yEn, double zEn) {
220 GObjectController *cont = _controllers[idBox];
221 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
222 bbmod->setBBTKName(name);
223 bbmod->setInicPoint(xIn, yIn, zIn);
224 bbmod->setFinalPoint(xEn, yEn, zEn);
225 bbmod->setExecutable(boxExecutable);
227 bbmod->notifyObservers(_idManager);
231 //=========================================================================
233 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,
234 std::string boxType) {
235 _worldState = NOTHING_HAPPENS;
236 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
237 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
239 int type = GBLACKBOX;
241 //Create the MVC Objects
245 (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
247 vtkGObjectView *view =
248 GObjectsMVCFactory::getInstance()->createGObjectView(type);
249 GObjectController* controller =
250 GObjectsMVCFactory::getInstance()->createGObjectController(type);
252 BlackBoxDescriptor::Pointer descriptor =
253 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
254 packageName, boxType);
256 //Prepares the initial model
257 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
260 double yy = windowHeight - y;
262 //z value is not important yet, because it is only used a parallel projection
264 _baseView->TransCoordScreenToWorld(xx, yy, zz);
265 model->setInicPoint(xx, yy, zz);
267 std::stringstream stream;
269 std::string newBoxName;
270 newBoxName = findANewNameForABox();
272 stream << newBoxName;
274 std::string arraystring = stream.str();
276 model->setBBTKName(arraystring);
277 model->setBBTKType(boxType);
278 model->setBBTKPackage(packageName);
280 model->addObserver(view);
281 model->addObserver(this);
283 //Iterate and create the input ports
284 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
285 descriptor->GetInputDescriptorMap();
286 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
289 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) {
290 BlackBoxInputDescriptor *desc = itInput->second;
291 createGInputPort(GINPUTPORT, i, model, desc);
295 //Iterate and create the output ports
296 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
297 descriptor->GetOutputDescriptorMap();
298 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
301 for (itOutput = descriptorOutMap.begin(); itOutput
302 != descriptorOutMap.end(); ++itOutput) {
303 BlackBoxOutputDescriptor *desc = itOutput->second;
304 createGOutputPort(GOUTPUTPORT, i, model, desc);
308 //Associates the view with the correspondent renderer and the model.
309 //(NOTE: Refresh is only made by the view)
310 view->setModel(model);
311 view->setBaseView(_baseView);
312 view->initVtkObjects();
314 //Associates the controller with the correspondent model and view
315 controller->setModelAndView(model, view);
317 //Resgiter change to the observers of the actual model
318 model->notifyObservers(_idManager);
320 int newId = addObjectController(controller);
326 //=========================================================================
328 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
329 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
330 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
332 int type = GCOMPLEXINPUTPORT;
334 //Create the MVC Objects
338 (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
340 vtkGObjectView *view =
341 GObjectsMVCFactory::getInstance()->createGObjectView(type);
342 GObjectController* controller =
343 GObjectsMVCFactory::getInstance()->createGObjectController(type);
345 //Prepares the initial model
348 double yy = windowHeight - 5;
350 //z value is not important yet, because it is only used a parallel projection
352 printf("EED wxVtkSceneManager::createGComplexBoxInputPort 900-450\n");
354 _baseView->TransCoordScreenToWorld(xx, yy, zz);
355 model->setInicPoint(xx, yy, zz);
357 model->setBBTKName(inputName);
358 model->setBBTKType("ComplexInputPort");
359 model->setComplexPortType(type);
361 model->addObserver(view);
362 model->addObserver(this);
364 //create the output port
365 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
366 "ComplexInputPort", 0, model);
367 model->addOutputPort((GPortModel*) portController->getModel());
369 //Associates the view with the correspondent renderer and the model.
370 //(NOTE: Refresh is only made by the view)
371 view->setModel(model);
372 view->setBaseView(_baseView);
373 view->initVtkObjects();
375 //Associates the controller with the correspondent model and view
376 controller->setModelAndView(model, view);
378 //Resgiter change to the observers of the actual model
379 model->notifyObservers(_idManager);
381 int newId = addObjectController(controller);
385 //=========================================================================
387 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
388 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
389 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
391 int type = GCOMPLEXOUTPUTPORT;
393 //Create the MVC Objects
397 (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
399 vtkGObjectView *view =
400 GObjectsMVCFactory::getInstance()->createGObjectView(type);
401 GObjectController *controller =
402 GObjectsMVCFactory::getInstance()->createGObjectController(type);
404 //Prepares the initial model
407 double yy = windowHeight - 5;
409 //z value is not important yet, because it is only used a parallel projection
412 printf("EED wxVtkSceneManager::createGComplexBoxOutputPort 900-450\n");
414 _baseView->TransCoordScreenToWorld(xx, yy, zz);
415 model->setInicPoint(xx, yy, zz);
417 model->setBBTKName(outputName);
418 model->setBBTKType("ComplexOutputPort");
419 model->setComplexPortType(type);
421 model->addObserver(view);
422 model->addObserver(this);
424 //create the output port
425 GPortController* portController = createGPort(GINPUTPORT, outputName,
426 "ComplexInputPort", 0, model);
427 model->addInputPort((GPortModel*) portController->getModel());
429 //Associates the view with the correspondent renderer and the model.
430 //(NOTE: Refresh is only made by the view)
431 view->setModel(model);
432 view->setBaseView(_baseView);
433 view->initVtkObjects();
435 //Associates the controller with the correspondent model and view
436 controller->setModelAndView(model, view);
438 //Resgiter change to the observers of the actual model
439 model->notifyObservers(_idManager);
441 int newId = addObjectController(controller);
445 //=========================================================================
447 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,
448 GBoxModel *blackBox, BlackBoxInputDescriptor *desc) {
449 GPortController* portController = createGPort(portType, desc->GetName(),
450 desc->GetTypeName(), posinBox, blackBox);
451 blackBox->addInputPort((GPortModel*) portController->getModel());
452 return portController->getId();
455 //=========================================================================
457 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,
458 GBoxModel *blackBox, BlackBoxOutputDescriptor *desc) {
459 GPortController* portController = createGPort(portType, desc->GetName(),
460 desc->GetTypeName(), posinBox, blackBox);
461 blackBox->addOutputPort((GPortModel*) portController->getModel());
462 return portController->getId();
465 //=========================================================================
467 GPortController* wxVtkSceneManager::createGPort(int portType,
468 std::string bbtkName, std::string bbtkType, int posInBox,
469 GBoxModel *blackBox) {
472 //Create the MVC Objects
475 (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
477 vtkGObjectView *view =
478 GObjectsMVCFactory::getInstance()->createGObjectView(type);
479 GObjectController* controller =
480 GObjectsMVCFactory::getInstance()->createGObjectController(type);
482 model->registerInBox(blackBox, portType, posInBox);
484 model->setBBTKType(bbtkType);
485 model->setBBTKName(bbtkName);
487 model->addObserver(view);
488 model->addObserver(this);
490 //Associates the view with the correspondent renderer and the model.
491 //(NOTE: Refresh is only made by the view)
492 view->setModel(model);
493 view->setBaseView(_baseView);
494 view->initVtkObjects();
496 //Associates the controller with the correspondent model and view
497 controller->setModelAndView(model, view);
499 model->notifyObservers(_idManager);
501 addObjectController(controller);
503 return (GPortController*) controller;
506 //=========================================================================
508 int wxVtkSceneManager::createGConnector(GPortModel* startPort) {
509 int type = GCONNECTOR;
511 manualConnectorContourController* manContourControl =
512 new manualConnectorContourController();
513 manualConnectorContourView* manContourView =
514 new manualConnectorContourView();
515 manualContourModel* manContourModel = new manualContourModel();
517 GConnectorController* connectorcontroller = new GConnectorController();
518 GConnectorModel* connectorModel = new GConnectorModel();
519 vtkGConnectorView* connectorView = new vtkGConnectorView();
520 connectorModel->setGObjectType(type);
522 manContourModel->SetCloseContour(false);
523 connectorModel->setStartPort(startPort);
525 manContourView->SetModel(manContourModel);
526 manContourView->SetWxVtkBaseView(_baseView);
527 manContourView->SetRange(0.5);
528 manContourView->SetZ(900);
530 manContourView->SetColorNormalContour(0, 0, 1);
531 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
532 manContourView->SetColorSelectContour(1, 0.8, 0);
536 * Width increased from 2 to 5, it simplifies line handling and spline control :P
539 manContourView->SetWidthLine( 3 ) ;
540 manContourView->SetShowText(false);
542 manContourControl->SetModelView(manContourModel, manContourView);
544 manContourControl->CreateNewManualContour();
546 manContourView->RefreshContour();
549 connectorModel->getInicPoint(x, y, z);
551 manContourControl->SetState(1);
552 manContourModel->SetCloseContour(false);
554 manContourModel->AddPoint(x, y, z);
555 manContourView->AddPoint();
557 manContourModel->AddPoint(x, y, z);
558 manContourView->AddPoint();
560 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
561 manContourControl->_bakIdPoint = bak;
562 manContourView->Refresh();
564 manContourControl->SetMoving(false);
566 connectorcontroller->setModelAndView(connectorModel, connectorView);
568 int newId = addObjectController(connectorcontroller);
570 connectorcontroller->setManualContourController(manContourControl);
571 connectorModel->setManualContourModel(manContourModel);
572 connectorView->setManualContourView(manContourView);
573 connectorView->setModel(connectorModel);
574 connectorView->setBaseView(_baseView);
576 connectorModel->addObserver(connectorView);
577 connectorModel->addObserver(this);
582 //=========================================================================
584 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param) {
585 vtkInteractorStyleBaseView
586 * baseViewControlManager =
587 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
588 baseViewControlManager->AddInteractorStyleMaracas(param);
591 //=========================================================================
593 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param) {
594 vtkInteractorStyleBaseView
595 * baseViewControlManager =
596 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
597 baseViewControlManager->RemoveInteractorStyleMaracas(param);
600 //=========================================================================
602 vtkRenderer* wxVtkSceneManager::getRenderer() {
603 return _baseView->GetRenderer();
606 //=========================================================================
608 vtkRenderWindow* wxVtkSceneManager::getRenderWindow() {
609 return _baseView->GetRenWin();
611 //=========================================================================
614 //=========================================================================
615 int wxVtkSceneManager::GetIndexInSelected(int idControler) {
617 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
618 if (_selectedObjects[i] == idControler) {
625 //=========================================================================
627 void wxVtkSceneManager::update(int idController, int command) {
629 if (command != NO_COMMAND) {
630 if (command == ADD_TO_SELECTED) {
631 //EEDBorrame GObjectController* cont = _controllers[idController];
633 if (GetIndexInSelected(idController) == -1) {
634 _selectedObjects.push_back(idController);
638 // bool foundID=false;
639 // for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
641 // if(_selectedObjects[i]==idController)
648 // _selectedObjects.push_back(idController);
651 } else if (command == REMOVE_FROM_SELECTED) {
652 int index = GetIndexInSelected(idController);
654 _selectedObjects.erase(_selectedObjects.begin() + index);
656 } else if (command == INIT_CREATION_CONTOUR) {
659 typedef std::map<int , GObjectController*>::iterator TIterator ;
662 // Find current item in the controller
663 iter = _controllers.find( idController ) ;
664 iter_end = _controllers.end( ) ;
666 if ( iter != iter_end ) {
667 GObjectController* gobjc = iter->second ;
669 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
670 // And if the item is a port
671 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
672 TIterator c_it = _controllers.begin( ) ;
673 // Go through all componets
674 for ( c_it ; c_it != iter_end ; c_it++ ) {
675 GObjectController* obc = c_it->second ;
676 int obc_type = obc->getModel( )->getGObjectType( ) ;
677 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
678 // if the component is a port and the type is the same of that selected
679 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
681 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
682 //obc->getView( )->setState( HIGHLIGHTED ) ;
690 _worldState = INIT_CREATION_CONTOUR;
691 GObjectController* cont = _controllers[idController];
692 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
694 // The last one is the controller of the connector
695 std::map<int, GObjectController*>::iterator it2;
697 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
698 GObjectController *cont = it2->second;
699 if (cont->getGObjectType() == GPORT) {
700 GPortModel* port = (GPortModel*) cont->getModel();
701 if (port->getPortType() == GINPUTPORT) {
702 cont->SetActive(true);
704 cont->getView()->setState(NOTHING_HAPPENS);
705 cont->getModel()->notifyObservers(_idManager);
706 cont->SetActive(false);
709 cont->getView()->setState(NOTHING_HAPPENS);
710 cont->getModel()->notifyObservers(_idManager);
711 cont->SetActive(false);
714 _selectedObjects.clear();
715 _idConnectionInCreation = createGConnector(startOutputPort);
716 } else if (command == FIN_CREATION_CONTOUR && _worldState
717 == INIT_CREATION_CONTOUR) {
718 _worldState = NOTHING_HAPPENS;
719 //int id = _controllers.size()-1;
720 GObjectController *cont = _controllers[_idConnectionInCreation];
721 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
722 GObjectController *finPort = _controllers[idController];
724 if (finPort->getGObjectType() == GPORT) {
725 GPortModel* modelPort = (GPortModel*) finPort->getModel();
726 modelContour->setEndPort(modelPort);
729 typedef std::map<int, GObjectController*>::iterator TIterator;
730 TIterator c_it = _controllers.begin();
731 TIterator iter_end = _controllers.end();
732 // Go through all componets
733 for (c_it; c_it != iter_end; c_it++) {
734 GObjectController* obc = c_it->second;
735 int obc_type = obc->getModel()->getGObjectType();
736 int obc_state = obc->getView()->getState();
737 // if the component is a port and the type is the same of that selected
738 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
739 // Return element to neutral state if not selected
740 obc->getView()->setState(NOTHING_HAPPENS);
742 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
743 // Change element to connected state
744 obc->getView()->setState(HIGHLIGHTED);
751 _parent->saveTempDiagram();
754 manualConnectorContourController
756 ((GConnectorController*) cont)->getManualContourController();
757 manualConnectorContourView
759 (manualConnectorContourView*) manCont->GetManualViewBaseContour();
762 std::map<int, GObjectController*>::iterator it2;
764 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
765 GObjectController *cont = it2->second;
766 if (cont->getView() != NULL) {
767 cont->getView()->setState(NOTHING_HAPPENS);
768 cont->getModel()->notifyObservers(_idManager);
770 cont->SetActive(true);
778 //=========================================================================
780 bool wxVtkSceneManager::OnMouseMove() {
782 bool okStatusMessage = false;
783 bool okPortMessage = false;
784 wxVTKRenderWindowInteractor *wxVTKiren;
786 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
787 wxVTKiren->GetEventPosition(X, Y);
789 if (_worldState == DRAG_OBJECTS) {
790 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
791 int id = _selectedObjects[i];
792 GObjectController* cont = _controllers[id];
793 if (_startDragging) {
794 cont->getView()->setStartDragging(true);
796 cont->getView()->moveObject(X, Y);
797 cont->getView()->setState(DRAG);
798 cont->getModel()->notifyObservers(_idManager);
801 std::map<int, GObjectController*>::iterator it;
803 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
804 GObjectController *desc = it->second;
805 if (desc->getGObjectType() == GCONNECTOR) {
806 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
807 vconn->updateStartEndPoints();
811 _startDragging = false;
813 } else if (_worldState == NOTHING_HAPPENS || _worldState
814 == INIT_CREATION_CONTOUR) {
815 std::map<int, GObjectController*>::iterator it;
817 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
818 GObjectController *desc = it->second;
819 int type = desc->getGObjectType();
820 int state = desc->getView()->getState();
821 desc->getModel()->getCenter(px, py, pz);
824 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION )) {
826 okStatusMessage = true;
827 updateStatusBar(desc->getStatusText());
828 if (type == GBLACKBOX) {
829 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
830 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),
835 okPortMessage = true;
837 _textActor->SetInput(desc->getStatusText().c_str());
838 _textActor->SetScale(0.1);
839 _textActor->SetPosition(px - 25, py + 1, pz + 2);
844 _fillObjectActor->SetScale(1);
845 _fillObjectActor->GetProperty()->SetOpacity(0.50);
846 _fillObjectActor->SetPosition(px, py, 1);
847 _aPolygonMapper->Modified();
850 } // for controllers it
853 if (okStatusMessage == false) {
857 if (okPortMessage == false) {
858 _textActor->SetScale(0.0001);
859 _fillObjectActor->SetScale(0.0001);
864 //=========================================================================
866 bool wxVtkSceneManager::OnLeftButtonDown() {
868 if (_worldState == INIT_CREATION_CONTOUR) {
869 bool isOverPort = false;
870 std::map<int, GObjectController*>::iterator it;
871 for (it = _controllers.begin(); it != _controllers.end() && isOverPort
873 GObjectController *desc = it->second;
874 if (desc->getGObjectType() == GPORT) {
875 GPortModel *portmod = (GPortModel*) desc->getModel();
876 vtkGObjectView *portView = desc->getView();
877 if (portmod->getPortType() == GINPUTPORT
878 && portView->getState() == HIGHLIGHTED) {
882 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
884 portView->setState( HIGHLIGHTED);
891 if (isOverPort == false) {
893 UnSelectBlackBoxes();
897 } else { //_worldState
899 _worldState = DRAG_OBJECTS;
900 _startDragging = true;
903 _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
905 _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
906 ctrlkey = ctrlkey + shiftkey;
908 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
910 if (GetGBlackBoxControlerPointedByMouse() != NULL) {
911 int state = cont->getView()->getState();
912 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
913 UnSelectBlackBoxes();
916 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
917 int id = _selectedObjects[i];
918 GObjectController* cont = _controllers[id];
919 cont->getView()->setState(DRAG);
920 cont->getModel()->notifyObservers(_idManager);
923 } // if _selectedObjects.size
929 //=========================================================================
931 bool wxVtkSceneManager::OnLeftButtonUp() {
932 if (_worldState == DRAG_OBJECTS) {
933 _worldState = NOTHING_HAPPENS;
935 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
936 int id = _selectedObjects[i];
937 GObjectController* cont = _controllers[id];
938 cont->getView()->setState(SELECTED);
939 cont->getModel()->notifyObservers(_idManager);
945 //=========================================================================
946 void wxVtkSceneManager::CancelConnection() {
947 if (_worldState == INIT_CREATION_CONTOUR) {
948 _worldState = NOTHING_HAPPENS;
949 //int lastId = _controllers.size()-1;
951 GConnectorController *connector =
952 (GConnectorController*) _controllers[_idConnectionInCreation];
953 connector->removeFromScene();
954 unregisterController(connector);
955 _controllers.erase(_idConnectionInCreation);
957 std::map<int, GObjectController*>::iterator it;
958 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
959 GObjectController *desc = it->second;
960 desc->SetActive(true);
961 desc->getView()->setState(NOTHING_HAPPENS);
962 desc->getModel()->notifyObservers(_idManager);
967 //=========================================================================
969 bool wxVtkSceneManager::OnRightButtonUp() {
970 if (_worldState == INIT_CREATION_CONTOUR) {
973 UnSelectBlackBoxes();
979 bool wxVtkSceneManager::OnMiddleButtonDown() {
982 this->_vtkInteractorStyleBaseView->StartPan();
987 bool wxVtkSceneManager::OnMiddleButtonUp() {
990 this->_vtkInteractorStyleBaseView->EndPan();
997 //=========================================================================
999 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1000 GObjectController *result = NULL;
1002 wxVTKRenderWindowInteractor *wxVTKiren;
1004 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1005 wxVTKiren->GetEventPosition(X, Y);
1007 std::map<int, GObjectController*>::iterator it;
1009 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1010 GObjectController *cont = it->second;
1011 int type = cont->getGObjectType();
1013 if (cont->getView()->isPointInside(X, Y) == true) {
1014 if (type == GBLACKBOX) {
1017 } // if isPointInside
1022 //=========================================================================
1023 void wxVtkSceneManager::UnSelectBlackBoxes() {
1024 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1025 int id = _selectedObjects[i];
1026 GObjectController* control = _controllers[id];
1027 control->getView()->setState(NOTHING_HAPPENS);
1028 }// for _selectedObjects
1029 _selectedObjects.clear();
1032 //=========================================================================
1033 bool wxVtkSceneManager::OnLeftDClick() {
1034 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1036 UnSelectBlackBoxes();
1037 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1043 wxVTKRenderWindowInteractor *wxVTKiren;
1044 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1045 wxVTKiren->GetEventPosition(X,Y);
1047 std::map<int, GObjectController*>::iterator it;
1049 bool clickOnObject = false;
1051 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1053 GObjectController *cont = it->second;
1054 int type = cont->getGObjectType();
1056 if(cont->getView()->isPointInside(X,Y))
1060 for (int i=0; i< (int)_selectedObjects.size(); i++)
1062 int id = _selectedObjects[i];
1063 GObjectController* control = _controllers[id];
1064 control->getView()->setState(NOTHING_HAPPENS);
1066 _selectedObjects.clear();
1068 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1069 _parent->editBlackBox(bbmodel);
1071 clickOnObject = true;
1075 if(clickOnObject==false)
1077 //_parent->editDiagramParameters(this);
1083 //=========================================================================
1085 bool wxVtkSceneManager::OnChar() {
1086 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1087 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1089 // KeyCode 127 : Delete Key
1090 // KeyCode 8 : Backspace Key
1091 if (keyCode == 8 || keyCode == 127) {
1092 if (_selectedObjects.size() > 0) {
1093 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1094 int id = _selectedObjects[i];
1095 std::map<int, GObjectController*>::iterator it;
1096 it = _controllers.find(id);
1097 if (it != _controllers.end()) {
1101 _selectedObjects.clear();
1107 if(_selectedObjects.size()){
1108 std::cout<<"objects to copy :";
1109 for(int i=0;i<_selectedObjects.size();i++){
1110 std::cout<<_selectedObjects.at(i)<<" ";
1112 DuplicateObjects(getSelectedObjects());
1114 std::cout<<"No objects to copy\n";
1121 //=========================================================================
1123 void wxVtkSceneManager::AddControlerToBeRemove(
1124 std::vector<int> *controllersToRemove, int id) {
1128 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1129 if (id == (*controllersToRemove)[i]) {
1135 controllersToRemove->push_back(id);
1140 //=========================================================================
1142 void wxVtkSceneManager::deleteObject(int id) {
1143 GObjectController *control = _controllers[id];
1144 std::vector<int> controllersToRemove;
1146 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1147 == GCOMPLEXINPUTPORT || control->getGObjectType()
1148 == GCOMPLEXOUTPUTPORT) {
1149 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1150 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1152 bool boxConnected = false;
1154 // Add box input controllers to be removed
1155 for (int i = 0; i < (int) inputs.size(); i++) {
1156 AddControlerToBeRemove(&controllersToRemove,
1157 inputs[i]->getObjectId());
1158 if (inputs[i]->isConnected()) {
1159 boxConnected = true;
1163 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1165 // Add box output controllers to be removed
1166 for (int i = 0; i < (int) outputs.size(); i++) {
1167 AddControlerToBeRemove(&controllersToRemove,
1168 outputs[i]->getObjectId());
1169 if (outputs[i]->isConnected()) {
1170 boxConnected = true;
1174 // Add connection controllers to be removed
1175 std::map<int, GObjectController*>::iterator it;
1176 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1177 GObjectController *cont = it->second;
1178 int type = cont->getGObjectType();
1179 if (type == GCONNECTOR) {
1180 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1181 if (conMod->getStartPort() != NULL
1182 && conMod->getStartPort()->getParentBox()->getObjectId()
1183 == bbmod->getObjectId()) {
1184 AddControlerToBeRemove(&controllersToRemove,
1185 conMod->getObjectId());
1187 if (conMod->getEndPort() != NULL
1188 && conMod->getEndPort()->getParentBox()->getObjectId()
1189 == bbmod->getObjectId()) {
1190 AddControlerToBeRemove(&controllersToRemove,
1191 conMod->getObjectId());
1196 // Add box controller to be removed
1197 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1198 } else if (control->getGObjectType() == GCONNECTOR) {
1199 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1200 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1203 std::map<int, GObjectController*>::iterator it;
1205 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1206 int key = controllersToRemove[i];
1207 it = _controllers.find(key);
1208 GObjectController *cont = _controllers[key];
1210 cont->removeFromScene();
1211 unregisterController((InteractorStyleMaracas*) cont);
1212 _controllers.erase(it);
1215 _parent->saveTempDiagram();
1218 //=========================================================================
1220 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1221 std::string boxName) {
1222 _parent->displayBlackBoxInfo(packageName, boxName);
1225 //=========================================================================
1227 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1228 _parent->updateStatusBar(textStatus);
1231 //=========================================================================
1232 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1233 std::string result = "";
1234 if (withLineNumber == true) {
1236 stringstream StrStream;
1238 std::string strValue = StrStream.str();
1241 } else if (value < 100) {
1245 result += strValue + ": ";
1249 //=========================================================================
1251 bool wxVtkSceneManager::MakeBoxExecutable() {
1252 std::map<int, GObjectController*> selected = getSelectedObjects();
1253 if( selected.empty() )
1256 std::map<int, GObjectController*>::iterator it;
1257 for (it = selected.begin(); it != selected.end(); ++it) {
1258 GObjectController* lastSelected = it->second;
1260 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1261 GBlackBoxModel *bbmodel =
1262 (GBlackBoxModel*) lastSelected->getModel();
1263 view->setState(HIGHLIGHTED);
1264 if (bbmodel->isExecutable()) {
1265 bbmodel->setExecutable(false);
1267 bbmodel->setExecutable(true);
1269 bbmodel->notifyObservers(lastSelected->getId());
1277 //=========================================================================
1279 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1280 bool existsExec = false;
1282 std::vector<std::string> packages;
1283 std::vector<int> boxes;
1284 std::vector<int> connections;
1285 std::vector<int> execBoxes;
1287 std::map<int, GObjectController*>::iterator it;
1289 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1290 GObjectController *desc = it->second;
1291 int type = desc->getGObjectType();
1293 if (type == GBLACKBOX) {
1294 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1296 std::string pkg = mod->getBBTKPackage();
1297 bool existsPkg = false;
1298 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1299 if (packages[t] == pkg) {
1304 packages.push_back(pkg);
1307 boxes.push_back(it->first);
1308 if (mod->isExecutable()) {
1309 execBoxes.push_back(it->first);
1312 } else if (type == GCONNECTOR) {
1313 connections.push_back(it->first);
1318 std::string script = "";
1319 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1320 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1321 script += LineNumber(wln, lnNmbr) + "\n";
1323 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1324 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1326 for (i = 0; i < (int) packages.size(); i++) {
1327 script += LineNumber(wln, lnNmbr);
1328 script += "include ";
1329 script += packages[i];
1333 script += LineNumber(wln, lnNmbr);
1338 script += LineNumber(wln, lnNmbr);
1339 script += "author \"";
1343 script += LineNumber(wln, lnNmbr);
1344 script += "description \"";
1345 script += _Description;
1348 script += LineNumber(wln, lnNmbr);
1349 script += "category \"";
1350 script += _Category;
1353 script += LineNumber(wln, lnNmbr);
1356 // script+="include std\n"; // JPR
1358 for (i = 0; i < (int) boxes.size(); i++) {
1359 script += LineNumber(wln, lnNmbr);
1362 GObjectController *control = _controllers[id];
1363 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1365 script += model->getBBTKType();
1367 script += model->getBBTKName();
1370 std::vector<GPortModel*> inputs = model->getInputPorts();
1371 for (int j = 0; j < (int) inputs.size(); j++) {
1372 GPortModel* inputPort = inputs[j];
1373 if (inputPort->isValueSet()) {
1374 script += LineNumber(wln, lnNmbr);
1376 script += model->getBBTKName();
1378 script += inputPort->getBBTKName();
1380 script += inputPort->getValue();
1385 script += LineNumber(wln, lnNmbr);
1390 script += LineNumber(wln, lnNmbr);
1393 for (i = 0; i < (int) connections.size(); i++) {
1394 script += LineNumber(wln, lnNmbr);
1395 script += "connect ";
1396 int id = connections[i];
1397 GObjectController *control = _controllers[id];
1398 GConnectorModel *model = (GConnectorModel*) control->getModel();
1400 //Start Connection info
1401 GPortModel *start = model->getStartPort();
1402 script += start->getParentBox()->getBBTKName();
1404 script += start->getBBTKName();
1408 //End Connection info
1409 GPortModel *end = model->getEndPort();
1410 script += end->getParentBox()->getBBTKName();
1412 script += end->getBBTKName();
1417 script += LineNumber(wln, lnNmbr);
1419 for (i = 0; i < (int) execBoxes.size(); i++) {
1420 script += LineNumber(wln, lnNmbr);
1422 int id = execBoxes[i];
1423 GObjectController *control = _controllers[id];
1424 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1426 script += model->getBBTKName();
1435 //=========================================================================
1437 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1438 std::vector<std::string> packages;
1439 std::vector<int> boxes;
1440 std::vector<int> connections;
1441 std::vector<int> execBoxes;
1443 std::map<int, GObjectController*>::iterator it;
1445 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1446 GObjectController *desc = it->second;
1447 int type = desc->getGObjectType();
1449 if (type == GBLACKBOX) {
1450 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1452 std::string pkg = mod->getBBTKPackage();
1453 bool existsPkg = false;
1454 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1455 if (packages[t] == pkg) {
1460 packages.push_back(pkg);
1463 boxes.push_back(it->first);
1464 if (mod->isExecutable()) {
1465 execBoxes.push_back(it->first);
1467 } else if (type == GCONNECTOR) {
1468 connections.push_back(it->first);
1472 std::string script = "";
1474 script += "include std\n"; // EED
1475 script += "include itkvtk\n"; // EED
1477 for (i = 0; i < (int) packages.size(); i++) {
1478 script += "include ";
1479 script += packages[i];
1484 // Definition of a complex box
1485 script += "define ";
1486 script += _cbName + " " + _cbPackageName;
1490 script += "author \"";
1494 script += "description \"";
1495 script += _Description;
1499 script += "category \"";
1500 script += _Category;
1505 for (i = 0; i < (int) boxes.size(); i++) {
1508 GObjectController *control = _controllers[id];
1509 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1511 script += model->getBBTKType();
1513 script += model->getBBTKName();
1516 std::vector<GPortModel*> inputs = model->getInputPorts();
1517 for (int j = 0; j < (int) inputs.size(); j++) {
1518 GPortModel* inputPort = inputs[j];
1519 if (inputPort->isValueSet()) {
1521 script += model->getBBTKName();
1523 script += inputPort->getBBTKName();
1525 script += inputPort->getValue();
1533 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1535 std::string complexInputs = "";
1536 std::string complexOutputs = "";
1539 for (i = 0; i < (int) connections.size(); i++) {
1540 int id = connections[i];
1541 GObjectController *control = _controllers[id];
1542 GConnectorModel *model = (GConnectorModel*) control->getModel();
1545 GPortModel *start = model->getStartPort();
1546 GBoxModel *startBox = start->getParentBox();
1548 GPortModel *end = model->getEndPort();
1549 GBoxModel *endBox = end->getParentBox();
1551 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1552 complexInputs += "input ";
1553 complexInputs += startBox->getBBTKName();
1555 complexInputs += " ";
1556 complexInputs += endBox->getBBTKName();
1557 complexInputs += ".";
1558 complexInputs += end->getBBTKName();
1560 complexInputs += " ";
1561 complexInputs += "\" \"";
1563 complexInputs += "\n";
1564 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1565 complexOutputs += "output ";
1566 complexOutputs += endBox->getBBTKName();
1568 complexOutputs += " ";
1569 complexOutputs += startBox->getBBTKName();
1570 complexOutputs += ".";
1571 complexOutputs += start->getBBTKName();
1573 complexOutputs += " ";
1574 complexOutputs += "\" \"";
1576 complexOutputs += "\n";
1578 script += "connect ";
1579 script += startBox->getBBTKName();
1581 script += start->getBBTKName();
1585 //End Connection info
1586 script += endBox->getBBTKName();
1588 script += end->getBBTKName();
1596 for (i = 0; i < (int) execBoxes.size(); i++) {
1598 int id = execBoxes[i];
1599 GObjectController *control = _controllers[id];
1600 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1602 script += model->getBBTKName();
1607 script += "# Complex input ports\n";
1608 script += complexInputs;
1611 script += "# Complex output ports\n";
1612 script += complexOutputs;
1615 script += "endefine";
1621 //=========================================================================
1623 void wxVtkSceneManager::deleteAllBoxes() {
1624 std::map<int, GObjectController*>::iterator it;
1625 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1626 GObjectController *cont = it->second;
1627 cont->removeFromScene();
1628 unregisterController((InteractorStyleMaracas*) cont);
1630 _selectedObjects.clear();
1631 _controllers.clear();
1635 //=========================================================================
1638 void wxVtkSceneManager::refresh() {
1639 _baseView->Refresh();
1641 //=========================================================================
1643 void wxVtkSceneManager::refreshScene() {
1644 _baseView->RefreshView();
1647 //=========================================================================
1649 void wxVtkSceneManager::centerView() {
1651 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1652 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1653 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1654 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1655 _baseView->RefreshView();
1659 //=========================================================================
1661 void wxVtkSceneManager::saveDiagram(std::string &content) {
1664 content += "CATEGORY:";
1665 content += GetCategory();
1668 content += "DESCRIPTION:";
1669 content += GetDescription();
1672 content += "AUTHOR:";
1673 content += GetAuthor();
1676 //Print info IF COMPLEX BOX
1677 content += "COMPLEXBOX:";
1678 if (_isComplexBox) {
1679 content += "TRUE\n";
1681 content += "COMPLEXBOXNAME:";
1682 content += GetCbName();
1685 content += "PACKAGENAME:";
1686 content += GetCbPackageName();
1689 //Print info complex input ports
1690 std::vector<int> inputs = getComplexInputPorts();
1691 int insize = inputs.size();
1692 content += "COMPLEXINPUTS:";
1693 sprintf(buffer, "%d", insize);
1697 for (int i = 0; i < insize; i++) {
1699 GObjectController *cont = _controllers[id];
1700 cont->getModel()->save(content);
1703 //Print info complex output ports
1704 std::vector<int> outputs = getComplexOutputPorts();
1705 int outsize = outputs.size();
1706 content += "COMPLEXOUTPUTS:";
1707 sprintf(buffer, "%d", outsize);
1711 for (int i = 0; i < outsize; i++) {
1712 int id = outputs[i];
1713 GObjectController *cont = _controllers[id];
1714 cont->getModel()->save(content);
1718 content += "FALSE\n";
1722 std::vector<int> boxes = getBlackBoxes();
1723 int bsize = boxes.size();
1724 content += "BOXES:";
1725 sprintf(buffer, "%d", bsize);
1729 for (int i = 0; i < bsize; i++) {
1731 GObjectController *cont = _controllers[id];
1732 cont->getModel()->save(content);
1736 std::vector<int> connections = getConnections();
1737 int csize = connections.size();
1738 content += "CONNECTIONS:";
1739 sprintf(buffer, "%d", csize);
1743 for (int i = 0; i < csize; i++) {
1744 int id = connections[i];
1745 GObjectController *cont = _controllers[id];
1746 cont->getModel()->save(content);
1751 //=========================================================================
1753 void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
1755 std::string version = "<void>";
1756 std::string line = "";
1757 char delims[] = ":";
1758 char *result = NULL;
1760 getline(inputStream, line);
1763 while (!inputStream.eof()) {
1764 if (line == "" || line[0] == '#') {
1765 getline(inputStream, line);
1766 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1767 version = line.substr(18, 3);
1769 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1770 version = line.substr(18, 3);
1772 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1773 version = line.substr(18, 3);
1775 } else if (line == "APP_START") {
1781 printf("EED wxVtkSceneManager::loadDiagram version=%s\n", version.c_str());
1785 if ((version != "1.0") && (version != "1.1")) {
1786 getline(inputStream, line);//CATEGORY:<category of the box>
1787 char categoryTmp[30];
1788 strcpy(categoryTmp, line.c_str());
1789 result = strtok(categoryTmp, delims);
1790 result = strtok(NULL, delims);
1791 SetCategory(result);
1793 getline(inputStream, line);//DESCRIPTION:<description of the box>
1794 char descriptionTmp[1024];
1795 strcpy(descriptionTmp, line.c_str());
1796 result = strtok(descriptionTmp, delims);
1797 result = strtok(NULL, delims);
1798 SetDescription(result);
1800 getline(inputStream, line);//AUTHOR:<author>
1801 char authorTmp[255];
1802 strcpy(authorTmp, line.c_str());
1803 result = strtok(authorTmp, delims);
1804 result = strtok(NULL, delims);
1809 getline(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1810 char complexTmp[30];
1811 strcpy(complexTmp, line.c_str());
1812 result = strtok(complexTmp, delims);
1813 result = strtok(NULL, delims);
1814 std::string isComplexBox(result);
1816 if (isComplexBox == "TRUE") {
1817 _isComplexBox = true;
1819 if ((version != "1.0") && (version != "1.1")) {
1820 getline(inputStream, line);//COMPLEXNAME:<name of the complex box>
1821 char complexboxnameTmp[255];
1822 strcpy(complexboxnameTmp, line.c_str());
1823 result = strtok(complexboxnameTmp, delims);
1824 result = strtok(NULL, delims);
1827 getline(inputStream, line);//PACKAGENAME:<name of the package of the box>
1828 char packagenameTmp[255];
1829 strcpy(packagenameTmp, line.c_str());
1830 result = strtok(packagenameTmp, delims);
1831 result = strtok(NULL, delims);
1832 SetCbPackageName(result);
1835 //-----------------------
1836 //- COMPLEX INPUT PORTS
1837 //-----------------------
1838 getline(inputStream, line);//COMPLEXINPUTS:num
1840 strcpy(inputs, line.c_str());
1841 result = strtok(inputs, delims);
1842 result = strtok(NULL, delims);
1845 std::istringstream inps(result);
1848 for (int i = 0; i < numInputs; i++) {
1850 getline(inputStream, line);//COMPLEX_PORT
1851 getline(inputStream, line);//name
1852 std::string inputPortName(line);
1855 getline(inputStream, line);//xInic:yInic:zInic
1857 strcpy(coord, line.c_str());
1858 result = strtok(coord, delims);//xInic
1859 std::string xInic(result);
1860 result = strtok(NULL, delims);//yInic
1861 std::string yInic(result);
1862 result = strtok(NULL, delims);//zInic
1863 std::string zInic(result);
1865 double xIn, yIn, zIn;
1866 std::istringstream xSt(xInic);
1868 std::istringstream ySt(yInic);
1870 std::istringstream zSt(zInic);
1873 getline(inputStream, line);//FIN_COMPLEX_PORT
1875 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
1877 } // for input complex box
1880 //-----------------------
1881 //- COMPLEX OUTPUT PORTS
1882 //-----------------------
1884 getline(inputStream, line);//COMPLEXOUTPUTS:num
1886 strcpy(outputs, line.c_str());
1887 result = strtok(outputs, delims);
1888 result = strtok(NULL, delims);
1891 std::istringstream outps(result);
1892 outps >> numOutputs;
1894 for (int i = 0; i < numOutputs; i++) {
1896 getline(inputStream, line);//COMPLEX_PORT
1897 getline(inputStream, line);//name
1898 std::string outputPortName(line);
1901 getline(inputStream, line);//xInic:yInic:zInic
1903 strcpy(coord, line.c_str());
1904 result = strtok(coord, delims);//xInic
1905 std::string xInic(result);
1906 result = strtok(NULL, delims);//yInic
1907 std::string yInic(result);
1908 result = strtok(NULL, delims);//zInic
1909 std::string zInic(result);
1911 double xIn, yIn, zIn;
1912 std::istringstream xSt(xInic);
1914 std::istringstream ySt(yInic);
1916 std::istringstream zSt(zInic);
1919 getline(inputStream, line);//FIN_COMPLEX_PORT
1921 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn,
1924 } // for output complex box
1929 getline(inputStream, line);//BOXES:num
1931 strcpy(boxes, line.c_str());
1932 result = strtok(boxes, delims);
1933 result = strtok(NULL, delims);
1936 std::istringstream is(result);
1939 for (int i = 0; i < numBoxes; i++) {
1941 getline(inputStream, line);//BOX
1942 getline(inputStream, line);//package:type:name
1944 strcpy(box, line.c_str());
1945 result = strtok(box, delims);//package
1946 std::string package(result);
1947 result = strtok(NULL, delims);//type
1948 std::string type(result);
1949 result = strtok(NULL, delims);//name
1950 std::string name(result);
1952 getline(inputStream, line);//ISEXEC:TRUE|FALSE
1954 strcpy(exec, line.c_str());
1955 result = strtok(exec, delims);//ISEXEC
1956 result = strtok(NULL, delims);//TRUE|FALSE
1957 std::string isExec(result);
1960 getline(inputStream, line);//xInic:yInic:zInic
1962 strcpy(coord, line.c_str());
1963 result = strtok(coord, delims);//xInic
1964 std::string xInic(result);
1965 result = strtok(NULL, delims);//yInic
1966 std::string yInic(result);
1967 result = strtok(NULL, delims);//zInic
1968 std::string zInic(result);
1970 double xIn, yIn, zIn;
1971 std::istringstream xSt(xInic);
1973 std::istringstream ySt(yInic);
1975 std::istringstream zSt(zInic);
1979 getline(inputStream, line);//xEnd:yEnd:zEnd
1980 strcpy(coord, line.c_str());
1981 result = strtok(coord, delims);//xEnd
1982 std::string xEnd(result);
1983 result = strtok(NULL, delims);//yEnd
1984 std::string yEnd(result);
1985 result = strtok(NULL, delims);//zEnd
1986 std::string zEnd(result);
1988 double xEn, yEn, zEn;
1989 std::istringstream xEt(xEnd);
1991 std::istringstream yEt(yEnd);
1993 std::istringstream zEt(zEnd);
1996 bool boxExecutable = false;
1997 if (isExec == "TRUE") {
1998 boxExecutable = true;
2001 int idBox = createGBlackBox(xIn, yIn, package, type);
2002 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn,
2005 GObjectController *cont = _controllers[idBox];
2006 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2009 getline(inputStream, line);//PORT o FIN_BOX
2010 std::string port = line.substr(0, 4);
2011 while (port == "PORT") {
2012 getline(inputStream, line);//name:value
2014 strcpy(poort, line.c_str());
2015 result = strtok(poort, delims);//name
2016 std::string name(result);
2017 result = strtok(NULL, delims);//value
2018 std::string value(result);
2020 bbmod->setValueToInput(name, value);
2022 getline(inputStream, line);//PORT o FIN_BOX
2023 port = line.substr(0, 4);
2026 //EED bbmod->notifyObservers(_idManager);
2031 getline(inputStream, line);//CONNECTIONS:num
2033 strcpy(conns, line.c_str());
2034 result = strtok(conns, delims);
2035 result = strtok(NULL, delims);
2038 std::istringstream isCons(result);
2041 for (int i = 0; i < numConns; i++) {
2043 getline(inputStream, line);//CONNECTION
2044 getline(inputStream, line);//Startbox.PortName:EndBox.PortName
2047 strcpy(connec, line.c_str());
2048 result = strtok(connec, delims);
2049 std::string nameStartBox(result);
2050 result = strtok(NULL, delims);
2051 std::string nameStartPort(result);
2052 result = strtok(NULL, delims);
2053 std::string nameEndBox(result);
2054 result = strtok(NULL, delims);
2055 std::string nameEndPort(result);
2057 int idCon = configGConnetion(nameStartBox, nameStartPort,
2058 nameEndBox, nameEndPort);
2060 if (version != "1.0") {
2061 //Readding control points of the manualContour
2063 GConnectorController *tempp =
2064 (GConnectorController*) _controllers[idCon];
2065 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2066 vtkGConnectorView *conView =
2067 (vtkGConnectorView*) tempp->getView();
2068 getline(inputStream, line); //NumberOfControlPoints:##
2069 strcpy(conns, line.c_str());
2070 result = strtok(conns, delims);
2071 result = strtok(NULL, delims);
2073 int numberOfControlPoints;
2074 std::istringstream isCons(result);
2075 isCons >> numberOfControlPoints;
2077 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2078 getline(inputStream, line); //XX:YY:ZZ
2080 strcpy(connec, line.c_str());
2083 result = strtok(connec, delims);
2084 std::istringstream isPointX(result);
2086 result = strtok(NULL, delims);
2087 std::istringstream isPointY(result);
2089 result = strtok(NULL, delims);
2090 std::istringstream isPointZ(result);
2093 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px,
2095 conView->getManualContourView()->AddPoint();
2105 //=========================================================================
2108 //=========================================================================
2109 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2110 std::string portName, double xIn, double yIn, double zIn) {
2112 if (inputoutput == true) {
2113 idPort = createGComplexBoxInputPort(portName);
2115 idPort = createGComplexBoxOutputPort(portName);
2117 GObjectController *cont = _controllers[idPort];
2118 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2119 cbmod->setInicPoint(xIn, yIn, zIn);
2120 cbmod->notifyObservers(_idManager);
2122 //=========================================================================
2125 //=========================================================================
2126 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
2130 GBoxModel *boxModel = NULL;
2131 std::vector<int> lstB = getBlackBoxes();
2132 for (j = 0; j < (int) lstB.size(); j++) {
2134 bMod = (GBoxModel*) _controllers[idB]->getModel();
2135 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2140 if ((_isComplexBox) && (boxModel == NULL)) {
2141 std::vector<int> lstInputs = getComplexInputPorts();
2142 for (j = 0; j < (int) lstInputs.size(); j++) {
2144 bMod = (GBoxModel*) _controllers[idB]->getModel();
2145 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2150 std::vector<int> lstOutputs = getComplexOutputPorts();
2151 for (j = 0; j < (int) lstOutputs.size(); j++) {
2152 int idB = lstOutputs[j];
2153 bMod = (GBoxModel*) _controllers[idB]->getModel();
2154 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2164 //=========================================================================
2167 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2168 std::string nameStartPort, std::string nameEndBox,
2169 std::string nameEndPort) {
2171 GBoxModel *boxModel;
2172 GPortModel *startP = NULL;
2173 GPortModel *endP = NULL;
2175 boxModel = findGBox(nameStartBox);
2176 if (boxModel != NULL) {
2177 startP = boxModel->getOutputPort(nameStartPort);
2180 boxModel = findGBox(nameEndBox);
2181 if (boxModel != NULL) {
2182 endP = boxModel->getInputPort(nameEndPort);
2186 int idCon = createGConnector(startP);
2187 _worldState = NOTHING_HAPPENS;
2188 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2190 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2191 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2192 tempp->endContourCreation();
2193 conMod->setEndPort(endP);
2194 conView->updateStartEndPoints();
2198 //=========================================================================
2200 bool wxVtkSceneManager::boxExist(std::string boxname) {
2202 std::map<int, GObjectController*>::iterator it;
2203 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2204 GObjectController *cont = it->second;
2205 if (cont->getModel()->getBBTKName() == boxname) {
2212 //=========================================================================
2214 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2215 std::vector<int> vect;
2216 std::map<int, GObjectController*>::iterator it;
2217 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2218 GObjectController *cont = it->second;
2219 if (cont->getGObjectType() == GBLACKBOX) {
2220 vect.push_back(cont->getId());
2226 //=========================================================================
2228 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2229 std::vector<int> vect;
2230 std::map<int, GObjectController*>::iterator it;
2231 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2232 GObjectController *cont = it->second;
2233 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2234 vect.push_back(cont->getId());
2240 //=========================================================================
2242 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2243 std::vector<int> vect;
2244 std::map<int, GObjectController*>::iterator it;
2245 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2246 GObjectController *cont = it->second;
2247 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2248 vect.push_back(cont->getId());
2254 //=========================================================================
2256 std::vector<int> wxVtkSceneManager::getConnections() {
2257 std::vector<int> vect;
2258 std::map<int, GObjectController*>::iterator it;
2259 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2260 GObjectController *cont = it->second;
2261 if (cont->getGObjectType() == GCONNECTOR) {
2262 vect.push_back(cont->getId());
2268 //=========================================================================
2270 bool wxVtkSceneManager::isComplexBox() {
2271 return _isComplexBox;
2274 //=========================================================================
2276 void wxVtkSceneManager::setComplexBox(bool val) {
2277 _isComplexBox = val;
2280 //=========================================================================
2282 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2283 //Register the controller of the new object
2284 registerController((InteractorStyleMaracas*) objController);
2285 //Add the object to the objects list
2286 int newId = _contLastId;//_controllers.size();
2287 objController->setId(newId);
2288 _controllers[newId] = objController;
2289 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2294 //=========================================================================
2296 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2298 std::map<int, int> oldIdNewIdBoxes;
2299 std::vector<int> connections;
2301 std::vector<int> newBoxesID;
2303 std::map<int, GObjectController*>::iterator it;
2304 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2305 GObjectController *cont = it->second;
2306 int type = cont->getGObjectType();
2308 if (type == GBLACKBOX) {
2310 double xInic, yInic, zInic;
2311 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2312 copyBox->getInicPoint(xInic, yInic, zInic);
2313 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2314 copyBox->getBBTKType());
2316 int idcB = copyBox->getObjectId();
2317 oldIdNewIdBoxes[idcB] = idBox;
2318 cont = _controllers[idBox];
2319 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2320 newbox->setInicPoint(xInic, yInic, zInic);
2321 int num = newbox->getNumInputPorts();
2322 for (int j = 0; j < num; j++) {
2323 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2325 newbox->move(xInic + 20, yInic + 20, zInic);
2326 newbox->notifyObservers(_idManager);
2327 newBoxesID.push_back(newbox->getObjectId());
2329 } else if (type == GCONNECTOR) {
2330 int idCon = cont->getId();
2331 connections.push_back(idCon);
2336 for (int i = 0; i < (int) connections.size(); i++) {
2337 int objId = connections[i];
2338 GObjectController *cont = objectsMap[objId];
2339 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2341 GPortModel* startPort = connectModel->getStartPort();
2342 int startPortIndex = startPort->getPosInBox();
2343 GPortModel* endPort = connectModel->getEndPort();
2344 int endPortIndex = endPort->getPosInBox();
2346 GBlackBoxModel* startPortParentBox =
2347 (GBlackBoxModel*) startPort->getParentBox();
2348 GBlackBoxModel* endPortParentBox =
2349 (GBlackBoxModel*) endPort->getParentBox();
2351 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2352 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2354 GBlackBoxModel* newStartBox =
2355 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2356 GBlackBoxModel* newEndBox =
2357 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2359 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2360 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2362 // Creates connection
2363 int idCon = createGConnector(newStartPort);
2364 GConnectorController *tempp =
2365 (GConnectorController*) _controllers[idCon];
2366 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2367 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2368 tempp->endContourCreation();
2369 conMod->setEndPort(newEndPort);
2370 conView->updateStartEndPoints();
2373 /// the new selected boxes are the duplicate ones
2375 UnSelectBlackBoxes();
2376 for (int i = 0; i < newBoxesID.size(); i++) {
2377 _selectedObjects.push_back(newBoxesID.at(i));
2380 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2381 int id = _selectedObjects[i];
2382 GObjectController* cont = _controllers[id];
2384 cont->getView()->setState(SELECTED);
2385 cont->getModel()->notifyObservers(_idManager);
2392 //=========================================================================
2394 int wxVtkSceneManager::getNumSelectedObjects() {
2395 return _selectedObjects.size();
2398 //=========================================================================
2400 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2401 std::map<int, GObjectController*> mapSelected;
2403 std::map<int, GObjectController*>::iterator it;
2404 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2405 GObjectController *cont = it->second;
2406 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2408 mapSelected[cont->getId()] = cont;
2412 std::map<int, GObjectController*>::iterator it2;
2413 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2414 GObjectController *cont = it2->second;
2415 if (cont->getGObjectType() == GCONNECTOR) {
2416 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2417 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2418 GBoxModel* startPortParentBox =
2419 cmod->getStartPort()->getParentBox();
2421 std::map<int, GObjectController*>::iterator iterOBJ1 =
2422 mapSelected.find(startPortParentBox->getObjectId());
2423 std::map<int, GObjectController*>::iterator iterOBJ2 =
2424 mapSelected.find(endPortParentBox->getObjectId());
2426 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2427 int ID = cont->getId();
2428 mapSelected[ID] = cont;
2435 //=========================================================================
2437 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2439 std::map<int, int> oldIdNewIdBoxes;
2440 std::vector<int> connections;
2442 std::map<int, GObjectController*>::iterator it;
2443 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2444 GObjectController *cont = it->second;
2445 int type = cont->getGObjectType();
2447 if (type == GBLACKBOX) {
2449 double xInic, yInic, zInic;
2450 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2451 copyBox->getInicPoint(xInic, yInic, zInic);
2452 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2453 copyBox->getBBTKType());
2455 int idcB = copyBox->getObjectId();
2456 oldIdNewIdBoxes[idcB] = idBox;
2457 cont = _controllers[idBox];
2458 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2459 newbox->setInicPoint(xInic, yInic, zInic);
2460 int num = newbox->getNumInputPorts();
2461 for (int j = 0; j < num; j++) {
2462 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2464 newbox->notifyObservers(_idManager);
2465 } else if (type == GCONNECTOR) {
2466 int idCon = cont->getId();
2467 connections.push_back(idCon);
2472 for (int i = 0; i < (int) connections.size(); i++) {
2473 int objId = connections[i];
2474 GObjectController *cont = objectsMap[objId];
2475 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2477 GPortModel* startPort = connectModel->getStartPort();
2478 int startPortIndex = startPort->getPosInBox();
2479 GPortModel* endPort = connectModel->getEndPort();
2480 int endPortIndex = endPort->getPosInBox();
2482 GBlackBoxModel* startPortParentBox =
2483 (GBlackBoxModel*) startPort->getParentBox();
2484 GBlackBoxModel* endPortParentBox =
2485 (GBlackBoxModel*) endPort->getParentBox();
2487 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2488 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2490 GBlackBoxModel* newStartBox =
2491 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2492 GBlackBoxModel* newEndBox =
2493 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2495 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2496 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2498 // Creates connection
2499 int idCon = createGConnector(newStartPort);
2500 GConnectorController *tempp =
2501 (GConnectorController*) _controllers[idCon];
2502 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2503 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2504 tempp->endContourCreation();
2505 conMod->setEndPort(newEndPort);
2506 conView->updateStartEndPoints();
2509 std::map<int, int>::iterator itIds;
2510 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2511 int idOld = itIds->first;
2512 int idNew = itIds->second;
2514 GBlackBoxModel* oldBox =
2515 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2516 GBlackBoxModel* newBox =
2517 (GBlackBoxModel*) _controllers[idNew]->getModel();
2519 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2520 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2521 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2522 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2524 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2526 //EED int toCreate=-1;
2527 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2528 if (oldInputConnections[k] == newInputConnections[l]) {
2533 if (exist == false) {
2534 //Create complex input
2535 int posInBox = oldInputConnections[k];
2536 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2537 std::string inputPortName = inputPort->getBBTKName();
2538 int idInputPort = createGComplexBoxInputPort(inputPortName);
2539 GObjectController *cont = _controllers[idInputPort];
2540 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2541 double xIn, yIn, zIn;
2542 inputPort->getInicPoint(xIn, yIn, zIn);
2544 cbmod->setInicPoint(xIn, yIn, zIn);
2545 cbmod->notifyObservers(_idManager);
2547 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2549 // Creates connection
2550 int idCon = createGConnector(cbmod->getOutputPort(0));
2551 GConnectorController *tempp =
2552 (GConnectorController*) _controllers[idCon];
2553 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2554 vtkGConnectorView *conView =
2555 (vtkGConnectorView*) tempp->getView();
2556 tempp->endContourCreation();
2557 conMod->setEndPort(inputPortEnd);
2558 conView->updateStartEndPoints();
2564 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2566 //EED int toCreate=-1;
2567 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2568 if (oldOutputConnections[k] == newOutputConnections[l]) {
2573 if (exist == false) {
2574 //Create complex output
2575 int posInBox = oldOutputConnections[k];
2576 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2577 std::string outputPortName = outputPort->getBBTKName();
2578 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2579 GObjectController *cont = _controllers[idOutputPort];
2580 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2581 double xIn, yIn, zIn;
2582 outputPort->getInicPoint(xIn, yIn, zIn);
2584 cbmod->setInicPoint(xIn, yIn, zIn);
2585 cbmod->notifyObservers(_idManager);
2587 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2589 // Creates connection
2590 int idCon = createGConnector(outputPortEnd);
2591 GConnectorController *tempp =
2592 (GConnectorController*) _controllers[idCon];
2593 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2594 vtkGConnectorView *conView =
2595 (vtkGConnectorView*) tempp->getView();
2596 tempp->endContourCreation();
2597 conMod->setEndPort(cbmod->getInputPort(0));
2598 conView->updateStartEndPoints();
2608 //=========================================================================
2609 void wxVtkSceneManager::SetCbName(std::string cbName) {
2611 if (_cbName == "") {
2612 _cbName = "<complex box name>";
2616 //=========================================================================
2617 std::string wxVtkSceneManager::GetCbName() {
2621 //=========================================================================
2622 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2623 _cbPackageName = packagename;
2624 if (_cbPackageName == "") {
2625 _cbPackageName = "<package name of the complex box>";
2629 //=========================================================================
2630 std::string wxVtkSceneManager::GetCbPackageName() {
2631 return _cbPackageName;
2634 //=========================================================================
2635 void wxVtkSceneManager::SetAuthor(std::string author) {
2637 if (_Author == "") {
2638 _Author = "<author of the box>";
2642 //=========================================================================
2643 std::string wxVtkSceneManager::GetAuthor() {
2647 //=========================================================================
2648 void wxVtkSceneManager::SetCategory(std::string category) {
2649 _Category = category;
2650 if (_Category == "") {
2651 _Category = "<category of the box>";
2655 //=========================================================================
2656 std::string wxVtkSceneManager::GetCategory() {
2660 //=========================================================================
2661 void wxVtkSceneManager::SetDescription(std::string description) {
2662 _Description = description;
2663 if (_Description == "") {
2664 _Description = "<description of the box>";
2668 //=========================================================================
2669 std::string wxVtkSceneManager::GetDescription() {
2670 return _Description;
2673 //=========================================================================
2676 void wxVtkSceneManager::printAll(int com , int sta ){
2678 int tmpState = sta ;
2679 if ( tmpState == NOTHING_HAPPENS ) {
2680 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2682 if ( tmpState == HIGHLIGHTED ) {
2683 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2685 if ( tmpState == POSSIBLE_CONNECTION ) {
2686 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2688 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2689 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2691 if ( tmpState == CLICKED ) {
2692 std::cout << "CONTROLER STATE---->CLICKED\n" ;
2694 if ( tmpState == DRAG ) {
2695 std::cout << "CONTROLER STATE---->DRAG\n" ;
2697 if ( tmpState == SELECTED ) {
2698 std::cout << "CONTROLER STATE---->SELECTED\n" ;
2700 if ( tmpState == CREATING_CONTOUR ) {
2701 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2707 if ( command == INIT_CREATION_CONTOUR ) {
2708 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2710 if ( command == FIN_CREATION_CONTOUR ) {
2711 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2713 if ( command == ADD_TO_SELECTED ) {
2714 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2716 if ( command == DRAG_OBJECTS ) {
2717 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2719 if ( command == EDIT_BLACKBOX ) {
2720 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
2722 if ( command == REMOVE_FROM_SELECTED ) {
2723 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
2729 } // EO namespace bbtk