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();
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);
255 if (descriptor == NULL){
256 printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
258 //Prepares the initial model
259 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
262 double yy = windowHeight - y;
264 //z value is not important yet, because it is only used a parallel projection
266 _baseView->TransCoordScreenToWorld(xx, yy, zz);
267 model->setInicPoint(xx, yy, zz);
269 std::stringstream stream;
271 std::string newBoxName;
272 newBoxName = findANewNameForABox();
274 stream << newBoxName;
276 std::string arraystring = stream.str();
278 model->setBBTKName(arraystring);
279 model->setBBTKType(boxType);
280 model->setBBTKPackage(packageName);
282 model->addObserver(view);
283 model->addObserver(this);
285 //Iterate and create the input ports
286 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
287 descriptor->GetInputDescriptorMap();
288 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
291 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) {
292 BlackBoxInputDescriptor *desc = itInput->second;
293 createGInputPort(GINPUTPORT, i, model, desc);
297 //Iterate and create the output ports
298 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
299 descriptor->GetOutputDescriptorMap();
300 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
303 for (itOutput = descriptorOutMap.begin(); itOutput
304 != descriptorOutMap.end(); ++itOutput) {
305 BlackBoxOutputDescriptor *desc = itOutput->second;
306 createGOutputPort(GOUTPUTPORT, i, model, desc);
310 //Associates the view with the correspondent renderer and the model.
311 //(NOTE: Refresh is only made by the view)
312 view->setModel(model);
313 view->setBaseView(_baseView);
314 view->initVtkObjects();
316 //Associates the controller with the correspondent model and view
317 controller->setModelAndView(model, view);
319 //Resgiter change to the observers of the actual model
320 model->notifyObservers(_idManager);
322 int newId = addObjectController(controller);
328 //=========================================================================
330 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
331 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
332 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
334 int type = GCOMPLEXINPUTPORT;
336 //Create the MVC Objects
340 (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
342 vtkGObjectView *view =
343 GObjectsMVCFactory::getInstance()->createGObjectView(type);
344 GObjectController* controller =
345 GObjectsMVCFactory::getInstance()->createGObjectController(type);
347 //Prepares the initial model
350 double yy = windowHeight - 5;
352 //z value is not important yet, because it is only used a parallel projection
354 printf("EED wxVtkSceneManager::createGComplexBoxInputPort 900-450\n");
356 _baseView->TransCoordScreenToWorld(xx, yy, zz);
357 model->setInicPoint(xx, yy, zz);
359 model->setBBTKName(inputName);
360 model->setBBTKType("ComplexInputPort");
361 model->setComplexPortType(type);
363 model->addObserver(view);
364 model->addObserver(this);
366 //create the output port
367 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
368 "ComplexInputPort", 0, model);
369 model->addOutputPort((GPortModel*) portController->getModel());
371 //Associates the view with the correspondent renderer and the model.
372 //(NOTE: Refresh is only made by the view)
373 view->setModel(model);
374 view->setBaseView(_baseView);
375 view->initVtkObjects();
377 //Associates the controller with the correspondent model and view
378 controller->setModelAndView(model, view);
380 //Resgiter change to the observers of the actual model
381 model->notifyObservers(_idManager);
383 int newId = addObjectController(controller);
387 //=========================================================================
389 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
390 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
391 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
393 int type = GCOMPLEXOUTPUTPORT;
395 //Create the MVC Objects
399 (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
401 vtkGObjectView *view =
402 GObjectsMVCFactory::getInstance()->createGObjectView(type);
403 GObjectController *controller =
404 GObjectsMVCFactory::getInstance()->createGObjectController(type);
406 //Prepares the initial model
409 double yy = windowHeight - 5;
411 //z value is not important yet, because it is only used a parallel projection
414 printf("EED wxVtkSceneManager::createGComplexBoxOutputPort 900-450\n");
416 _baseView->TransCoordScreenToWorld(xx, yy, zz);
417 model->setInicPoint(xx, yy, zz);
419 model->setBBTKName(outputName);
420 model->setBBTKType("ComplexOutputPort");
421 model->setComplexPortType(type);
423 model->addObserver(view);
424 model->addObserver(this);
426 //create the output port
427 GPortController* portController = createGPort(GINPUTPORT, outputName,
428 "ComplexInputPort", 0, model);
429 model->addInputPort((GPortModel*) portController->getModel());
431 //Associates the view with the correspondent renderer and the model.
432 //(NOTE: Refresh is only made by the view)
433 view->setModel(model);
434 view->setBaseView(_baseView);
435 view->initVtkObjects();
437 //Associates the controller with the correspondent model and view
438 controller->setModelAndView(model, view);
440 //Resgiter change to the observers of the actual model
441 model->notifyObservers(_idManager);
443 int newId = addObjectController(controller);
447 //=========================================================================
449 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,
450 GBoxModel *blackBox, BlackBoxInputDescriptor *desc) {
451 GPortController* portController = createGPort(portType, desc->GetName(),
452 desc->GetTypeName(), posinBox, blackBox);
453 blackBox->addInputPort((GPortModel*) portController->getModel());
454 return portController->getId();
457 //=========================================================================
459 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,
460 GBoxModel *blackBox, BlackBoxOutputDescriptor *desc) {
461 GPortController* portController = createGPort(portType, desc->GetName(),
462 desc->GetTypeName(), posinBox, blackBox);
463 blackBox->addOutputPort((GPortModel*) portController->getModel());
464 return portController->getId();
467 //=========================================================================
469 GPortController* wxVtkSceneManager::createGPort(int portType,
470 std::string bbtkName, std::string bbtkType, int posInBox,
471 GBoxModel *blackBox) {
474 //Create the MVC Objects
477 (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
479 vtkGObjectView *view =
480 GObjectsMVCFactory::getInstance()->createGObjectView(type);
481 GObjectController* controller =
482 GObjectsMVCFactory::getInstance()->createGObjectController(type);
484 model->registerInBox(blackBox, portType, posInBox);
486 model->setBBTKType(bbtkType);
487 model->setBBTKName(bbtkName);
489 model->addObserver(view);
490 model->addObserver(this);
492 //Associates the view with the correspondent renderer and the model.
493 //(NOTE: Refresh is only made by the view)
494 view->setModel(model);
495 view->setBaseView(_baseView);
496 view->initVtkObjects();
498 //Associates the controller with the correspondent model and view
499 controller->setModelAndView(model, view);
501 model->notifyObservers(_idManager);
503 addObjectController(controller);
505 return (GPortController*) controller;
508 //=========================================================================
510 int wxVtkSceneManager::createGConnector(GPortModel* startPort) {
511 int type = GCONNECTOR;
513 manualConnectorContourController* manContourControl =
514 new manualConnectorContourController();
515 manualConnectorContourView* manContourView =
516 new manualConnectorContourView();
517 manualContourModel* manContourModel = new manualContourModel();
519 GConnectorController* connectorcontroller = new GConnectorController();
520 GConnectorModel* connectorModel = new GConnectorModel();
521 vtkGConnectorView* connectorView = new vtkGConnectorView();
522 connectorModel->setGObjectType(type);
524 manContourModel->SetCloseContour(false);
525 connectorModel->setStartPort(startPort);
527 manContourView->SetModel(manContourModel);
528 manContourView->SetWxVtkBaseView(_baseView);
529 manContourView->SetRange(0.5);
530 manContourView->SetZ(900);
532 manContourView->SetColorNormalContour(0, 0, 1);
533 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
534 manContourView->SetColorSelectContour(1, 0.8, 0);
538 * Width increased from 2 to 5, it simplifies line handling and spline control :P
541 manContourView->SetWidthLine( 3 ) ;
542 manContourView->SetShowText(false);
544 manContourControl->SetModelView(manContourModel, manContourView);
546 manContourControl->CreateNewManualContour();
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;
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);
579 manContourView->Refresh();
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->saveTempandUpdate("create connection");
755 manualConnectorContourController
757 ((GConnectorController*) cont)->getManualContourController();
758 manualConnectorContourView
760 (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);
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 control->getModel()->notifyObservers(_idManager);
1030 }// for _selectedObjects
1031 _selectedObjects.clear();
1034 //=========================================================================
1035 bool wxVtkSceneManager::OnLeftDClick() {
1036 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1038 UnSelectBlackBoxes();
1039 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1045 wxVTKRenderWindowInteractor *wxVTKiren;
1046 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1047 wxVTKiren->GetEventPosition(X,Y);
1049 std::map<int, GObjectController*>::iterator it;
1051 bool clickOnObject = false;
1053 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1055 GObjectController *cont = it->second;
1056 int type = cont->getGObjectType();
1058 if(cont->getView()->isPointInside(X,Y))
1062 for (int i=0; i< (int)_selectedObjects.size(); i++)
1064 int id = _selectedObjects[i];
1065 GObjectController* control = _controllers[id];
1066 control->getView()->setState(NOTHING_HAPPENS);
1068 _selectedObjects.clear();
1070 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1071 _parent->editBlackBox(bbmodel);
1073 clickOnObject = true;
1077 if(clickOnObject==false)
1079 //_parent->editDiagramParameters(this);
1085 //=========================================================================
1087 bool wxVtkSceneManager::OnChar() {
1088 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1089 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1091 // KeyCode 127 : Delete Key
1092 // KeyCode 8 : Backspace Key
1093 if (keyCode == 8 || keyCode == 127) {
1094 if (_selectedObjects.size() > 0) {
1095 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1096 int id = _selectedObjects[i];
1097 std::map<int, GObjectController*>::iterator it;
1098 it = _controllers.find(id);
1099 if (it != _controllers.end()) {
1103 _selectedObjects.clear();
1109 if(_selectedObjects.size()){
1110 std::cout<<"objects to copy :";
1111 for(int i=0;i<_selectedObjects.size();i++){
1112 std::cout<<_selectedObjects.at(i)<<" ";
1114 DuplicateObjects(getSelectedObjects());
1116 std::cout<<"No objects to copy\n";
1123 //=========================================================================
1125 void wxVtkSceneManager::AddControlerToBeRemove(
1126 std::vector<int> *controllersToRemove, int id) {
1130 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1131 if (id == (*controllersToRemove)[i]) {
1137 controllersToRemove->push_back(id);
1142 //=========================================================================
1144 void wxVtkSceneManager::deleteObject(int id) {
1145 GObjectController *control = _controllers[id];
1146 std::vector<int> controllersToRemove;
1148 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1149 == GCOMPLEXINPUTPORT || control->getGObjectType()
1150 == GCOMPLEXOUTPUTPORT) {
1151 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1152 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1154 bool boxConnected = false;
1156 // Add box input controllers to be removed
1157 for (int i = 0; i < (int) inputs.size(); i++) {
1158 AddControlerToBeRemove(&controllersToRemove,
1159 inputs[i]->getObjectId());
1160 if (inputs[i]->isConnected()) {
1161 boxConnected = true;
1165 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1167 // Add box output controllers to be removed
1168 for (int i = 0; i < (int) outputs.size(); i++) {
1169 AddControlerToBeRemove(&controllersToRemove,
1170 outputs[i]->getObjectId());
1171 if (outputs[i]->isConnected()) {
1172 boxConnected = true;
1176 // Add connection controllers to be removed
1177 std::map<int, GObjectController*>::iterator it;
1178 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1179 GObjectController *cont = it->second;
1180 int type = cont->getGObjectType();
1181 if (type == GCONNECTOR) {
1182 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1183 if (conMod->getStartPort() != NULL
1184 && conMod->getStartPort()->getParentBox()->getObjectId()
1185 == bbmod->getObjectId()) {
1186 AddControlerToBeRemove(&controllersToRemove,
1187 conMod->getObjectId());
1189 if (conMod->getEndPort() != NULL
1190 && conMod->getEndPort()->getParentBox()->getObjectId()
1191 == bbmod->getObjectId()) {
1192 AddControlerToBeRemove(&controllersToRemove,
1193 conMod->getObjectId());
1198 // Add box controller to be removed
1199 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1200 } else if (control->getGObjectType() == GCONNECTOR) {
1201 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1202 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1205 std::map<int, GObjectController*>::iterator it;
1207 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1208 int key = controllersToRemove[i];
1209 it = _controllers.find(key);
1210 GObjectController *cont = _controllers[key];
1212 cont->removeFromScene();
1213 unregisterController((InteractorStyleMaracas*) cont);
1214 _controllers.erase(it);
1217 _parent->saveTempandUpdate("delete object");
1220 //=========================================================================
1222 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1223 std::string boxName) {
1224 _parent->displayBlackBoxInfo(packageName, boxName);
1227 //=========================================================================
1229 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1230 _parent->updateStatusBar(textStatus);
1233 //=========================================================================
1234 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1235 std::string result = "";
1236 if (withLineNumber == true) {
1238 stringstream StrStream;
1240 std::string strValue = StrStream.str();
1243 } else if (value < 100) {
1247 result += strValue + ": ";
1251 //=========================================================================
1253 bool wxVtkSceneManager::MakeBoxExecutable() {
1254 std::map<int, GObjectController*> selected = getSelectedObjects();
1255 if( selected.empty() )
1258 std::map<int, GObjectController*>::iterator it;
1259 for (it = selected.begin(); it != selected.end(); ++it) {
1260 GObjectController* lastSelected = it->second;
1262 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1263 GBlackBoxModel *bbmodel =
1264 (GBlackBoxModel*) lastSelected->getModel();
1265 view->setState(HIGHLIGHTED);
1266 if (bbmodel->isExecutable()) {
1267 bbmodel->setExecutable(false);
1269 bbmodel->setExecutable(true);
1271 bbmodel->notifyObservers(lastSelected->getId());
1279 //=========================================================================
1281 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1282 bool existsExec = false;
1284 std::vector<std::string> packages;
1285 std::vector<int> boxes;
1286 std::vector<int> connections;
1287 std::vector<int> execBoxes;
1289 std::map<int, GObjectController*>::iterator it;
1291 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1292 GObjectController *desc = it->second;
1293 int type = desc->getGObjectType();
1295 if (type == GBLACKBOX) {
1296 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1298 std::string pkg = mod->getBBTKPackage();
1299 bool existsPkg = false;
1300 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1301 if (packages[t] == pkg) {
1306 packages.push_back(pkg);
1309 boxes.push_back(it->first);
1310 if (mod->isExecutable()) {
1311 execBoxes.push_back(it->first);
1314 } else if (type == GCONNECTOR) {
1315 connections.push_back(it->first);
1320 std::string script = "";
1321 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1322 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1323 script += LineNumber(wln, lnNmbr) + "\n";
1325 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1326 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1328 for (i = 0; i < (int) packages.size(); i++) {
1329 script += LineNumber(wln, lnNmbr);
1330 script += "include ";
1331 script += packages[i];
1335 script += LineNumber(wln, lnNmbr);
1340 script += LineNumber(wln, lnNmbr);
1341 script += "author \"";
1345 script += LineNumber(wln, lnNmbr);
1346 script += "description \"";
1347 script += _Description;
1350 script += LineNumber(wln, lnNmbr);
1351 script += "category \"";
1352 script += _Category;
1355 script += LineNumber(wln, lnNmbr);
1358 // script+="include std\n"; // JPR
1360 for (i = 0; i < (int) boxes.size(); i++) {
1361 script += LineNumber(wln, lnNmbr);
1364 GObjectController *control = _controllers[id];
1365 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1367 script += model->getBBTKType();
1369 script += model->getBBTKName();
1372 std::vector<GPortModel*> inputs = model->getInputPorts();
1373 for (int j = 0; j < (int) inputs.size(); j++) {
1374 GPortModel* inputPort = inputs[j];
1375 if (inputPort->isValueSet()) {
1376 script += LineNumber(wln, lnNmbr);
1378 script += model->getBBTKName();
1380 script += inputPort->getBBTKName();
1382 script += inputPort->getValue();
1387 script += LineNumber(wln, lnNmbr);
1392 script += LineNumber(wln, lnNmbr);
1395 for (i = 0; i < (int) connections.size(); i++) {
1396 script += LineNumber(wln, lnNmbr);
1397 script += "connect ";
1398 int id = connections[i];
1399 GObjectController *control = _controllers[id];
1400 GConnectorModel *model = (GConnectorModel*) control->getModel();
1402 //Start Connection info
1403 GPortModel *start = model->getStartPort();
1404 script += start->getParentBox()->getBBTKName();
1406 script += start->getBBTKName();
1410 //End Connection info
1411 GPortModel *end = model->getEndPort();
1412 script += end->getParentBox()->getBBTKName();
1414 script += end->getBBTKName();
1419 script += LineNumber(wln, lnNmbr);
1421 for (i = 0; i < (int) execBoxes.size(); i++) {
1422 script += LineNumber(wln, lnNmbr);
1424 int id = execBoxes[i];
1425 GObjectController *control = _controllers[id];
1426 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1428 script += model->getBBTKName();
1437 //=========================================================================
1439 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1440 std::vector<std::string> packages;
1441 std::vector<int> boxes;
1442 std::vector<int> connections;
1443 std::vector<int> execBoxes;
1445 std::map<int, GObjectController*>::iterator it;
1447 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1448 GObjectController *desc = it->second;
1449 int type = desc->getGObjectType();
1451 if (type == GBLACKBOX) {
1452 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1454 std::string pkg = mod->getBBTKPackage();
1455 bool existsPkg = false;
1456 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1457 if (packages[t] == pkg) {
1462 packages.push_back(pkg);
1465 boxes.push_back(it->first);
1466 if (mod->isExecutable()) {
1467 execBoxes.push_back(it->first);
1469 } else if (type == GCONNECTOR) {
1470 connections.push_back(it->first);
1474 std::string script = "";
1476 script += "include std\n"; // EED
1477 script += "include itkvtk\n"; // EED
1479 for (i = 0; i < (int) packages.size(); i++) {
1480 script += "include ";
1481 script += packages[i];
1486 // Definition of a complex box
1487 script += "define ";
1488 script += _cbName + " " + _cbPackageName;
1492 script += "author \"";
1496 script += "description \"";
1497 script += _Description;
1501 script += "category \"";
1502 script += _Category;
1507 for (i = 0; i < (int) boxes.size(); i++) {
1510 GObjectController *control = _controllers[id];
1511 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1513 script += model->getBBTKType();
1515 script += model->getBBTKName();
1518 std::vector<GPortModel*> inputs = model->getInputPorts();
1519 for (int j = 0; j < (int) inputs.size(); j++) {
1520 GPortModel* inputPort = inputs[j];
1521 if (inputPort->isValueSet()) {
1523 script += model->getBBTKName();
1525 script += inputPort->getBBTKName();
1527 script += inputPort->getValue();
1535 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1537 std::string complexInputs = "";
1538 std::string complexOutputs = "";
1541 for (i = 0; i < (int) connections.size(); i++) {
1542 int id = connections[i];
1543 GObjectController *control = _controllers[id];
1544 GConnectorModel *model = (GConnectorModel*) control->getModel();
1547 GPortModel *start = model->getStartPort();
1548 GBoxModel *startBox = start->getParentBox();
1550 GPortModel *end = model->getEndPort();
1551 GBoxModel *endBox = end->getParentBox();
1553 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1554 complexInputs += "input ";
1555 complexInputs += startBox->getBBTKName();
1557 complexInputs += " ";
1558 complexInputs += endBox->getBBTKName();
1559 complexInputs += ".";
1560 complexInputs += end->getBBTKName();
1562 complexInputs += " ";
1563 complexInputs += "\" \"";
1565 complexInputs += "\n";
1566 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1567 complexOutputs += "output ";
1568 complexOutputs += endBox->getBBTKName();
1570 complexOutputs += " ";
1571 complexOutputs += startBox->getBBTKName();
1572 complexOutputs += ".";
1573 complexOutputs += start->getBBTKName();
1575 complexOutputs += " ";
1576 complexOutputs += "\" \"";
1578 complexOutputs += "\n";
1580 script += "connect ";
1581 script += startBox->getBBTKName();
1583 script += start->getBBTKName();
1587 //End Connection info
1588 script += endBox->getBBTKName();
1590 script += end->getBBTKName();
1598 for (i = 0; i < (int) execBoxes.size(); i++) {
1600 int id = execBoxes[i];
1601 GObjectController *control = _controllers[id];
1602 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1604 script += model->getBBTKName();
1609 script += "# Complex input ports\n";
1610 script += complexInputs;
1613 script += "# Complex output ports\n";
1614 script += complexOutputs;
1617 script += "endefine";
1623 //=========================================================================
1625 void wxVtkSceneManager::deleteAllBoxes() {
1626 std::map<int, GObjectController*>::iterator it;
1627 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1628 GObjectController *cont = it->second;
1629 cont->removeFromScene();
1630 unregisterController((InteractorStyleMaracas*) cont);
1632 _selectedObjects.clear();
1633 _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]);
1658 //=========================================================================
1660 void wxVtkSceneManager::saveDiagram(std::string &content) {
1663 content += "CATEGORY:";
1664 content += GetCategory();
1667 content += "DESCRIPTION:";
1668 content += GetDescription();
1671 content += "AUTHOR:";
1672 content += GetAuthor();
1675 //Print info IF COMPLEX BOX
1676 content += "COMPLEXBOX:";
1677 if (_isComplexBox) {
1678 content += "TRUE\n";
1680 content += "COMPLEXBOXNAME:";
1681 content += GetCbName();
1684 content += "PACKAGENAME:";
1685 content += GetCbPackageName();
1688 //Print info complex input ports
1689 std::vector<int> inputs = getComplexInputPorts();
1690 int insize = inputs.size();
1691 content += "COMPLEXINPUTS:";
1692 sprintf(buffer, "%d", insize);
1696 for (int i = 0; i < insize; i++) {
1698 GObjectController *cont = _controllers[id];
1699 cont->getModel()->save(content);
1702 //Print info complex output ports
1703 std::vector<int> outputs = getComplexOutputPorts();
1704 int outsize = outputs.size();
1705 content += "COMPLEXOUTPUTS:";
1706 sprintf(buffer, "%d", outsize);
1710 for (int i = 0; i < outsize; i++) {
1711 int id = outputs[i];
1712 GObjectController *cont = _controllers[id];
1713 cont->getModel()->save(content);
1717 content += "FALSE\n";
1721 std::vector<int> boxes = getBlackBoxes();
1722 int bsize = boxes.size();
1723 content += "BOXES:";
1724 sprintf(buffer, "%d", bsize);
1728 for (int i = 0; i < bsize; i++) {
1730 GObjectController *cont = _controllers[id];
1731 cont->getModel()->save(content);
1735 std::vector<int> connections = getConnections();
1736 int csize = connections.size();
1737 content += "CONNECTIONS:";
1738 sprintf(buffer, "%d", csize);
1742 for (int i = 0; i < csize; i++) {
1743 int id = connections[i];
1744 GObjectController *cont = _controllers[id];
1745 cont->getModel()->save(content);
1750 //=========================================================================
1752 void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
1754 std::string version = "<void>";
1755 std::string line = "";
1756 char delims[] = ":";
1757 char *result = NULL;
1759 getline(inputStream, line);
1762 while (!inputStream.eof()) {
1763 if (line == "" || line[0] == '#') {
1764 getline(inputStream, line);
1765 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1766 version = line.substr(18, 3);
1768 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1769 version = line.substr(18, 3);
1771 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1772 version = line.substr(18, 3);
1774 } else if (line == "APP_START") {
1780 printf("EED wxVtkSceneManager::loadDiagram version=%s\n", version.c_str());
1784 if ((version != "1.0") && (version != "1.1")) {
1785 getline(inputStream, line);//CATEGORY:<category of the box>
1786 char categoryTmp[30];
1787 strcpy(categoryTmp, line.c_str());
1788 result = strtok(categoryTmp, delims);
1789 result = strtok(NULL, delims);
1790 SetCategory(result);
1792 getline(inputStream, line);//DESCRIPTION:<description of the box>
1793 char descriptionTmp[1024];
1794 strcpy(descriptionTmp, line.c_str());
1795 result = strtok(descriptionTmp, delims);
1796 result = strtok(NULL, delims);
1797 SetDescription(result);
1799 getline(inputStream, line);//AUTHOR:<author>
1800 char authorTmp[255];
1801 strcpy(authorTmp, line.c_str());
1802 result = strtok(authorTmp, delims);
1803 result = strtok(NULL, delims);
1808 getline(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1809 char complexTmp[30];
1810 strcpy(complexTmp, line.c_str());
1811 result = strtok(complexTmp, delims);
1812 result = strtok(NULL, delims);
1813 std::string isComplexBox(result);
1815 if (isComplexBox == "TRUE") {
1816 _isComplexBox = true;
1818 if ((version != "1.0") && (version != "1.1")) {
1819 getline(inputStream, line);//COMPLEXNAME:<name of the complex box>
1820 char complexboxnameTmp[255];
1821 strcpy(complexboxnameTmp, line.c_str());
1822 result = strtok(complexboxnameTmp, delims);
1823 result = strtok(NULL, delims);
1826 getline(inputStream, line);//PACKAGENAME:<name of the package of the box>
1827 char packagenameTmp[255];
1828 strcpy(packagenameTmp, line.c_str());
1829 result = strtok(packagenameTmp, delims);
1830 result = strtok(NULL, delims);
1831 SetCbPackageName(result);
1834 //-----------------------
1835 //- COMPLEX INPUT PORTS
1836 //-----------------------
1837 getline(inputStream, line);//COMPLEXINPUTS:num
1839 strcpy(inputs, line.c_str());
1840 result = strtok(inputs, delims);
1841 result = strtok(NULL, delims);
1844 std::istringstream inps(result);
1847 for (int i = 0; i < numInputs; i++) {
1849 getline(inputStream, line);//COMPLEX_PORT
1850 getline(inputStream, line);//name
1851 std::string inputPortName(line);
1854 getline(inputStream, line);//xInic:yInic:zInic
1856 strcpy(coord, line.c_str());
1857 result = strtok(coord, delims);//xInic
1858 std::string xInic(result);
1859 result = strtok(NULL, delims);//yInic
1860 std::string yInic(result);
1861 result = strtok(NULL, delims);//zInic
1862 std::string zInic(result);
1864 double xIn, yIn, zIn;
1865 std::istringstream xSt(xInic);
1867 std::istringstream ySt(yInic);
1869 std::istringstream zSt(zInic);
1872 getline(inputStream, line);//FIN_COMPLEX_PORT
1874 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
1876 } // for input complex box
1879 //-----------------------
1880 //- COMPLEX OUTPUT PORTS
1881 //-----------------------
1883 getline(inputStream, line);//COMPLEXOUTPUTS:num
1885 strcpy(outputs, line.c_str());
1886 result = strtok(outputs, delims);
1887 result = strtok(NULL, delims);
1890 std::istringstream outps(result);
1891 outps >> numOutputs;
1893 for (int i = 0; i < numOutputs; i++) {
1895 getline(inputStream, line);//COMPLEX_PORT
1896 getline(inputStream, line);//name
1897 std::string outputPortName(line);
1900 getline(inputStream, line);//xInic:yInic:zInic
1902 strcpy(coord, line.c_str());
1903 result = strtok(coord, delims);//xInic
1904 std::string xInic(result);
1905 result = strtok(NULL, delims);//yInic
1906 std::string yInic(result);
1907 result = strtok(NULL, delims);//zInic
1908 std::string zInic(result);
1910 double xIn, yIn, zIn;
1911 std::istringstream xSt(xInic);
1913 std::istringstream ySt(yInic);
1915 std::istringstream zSt(zInic);
1918 getline(inputStream, line);//FIN_COMPLEX_PORT
1920 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn,
1923 } // for output complex box
1928 getline(inputStream, line);//BOXES:num
1930 strcpy(boxes, line.c_str());
1931 result = strtok(boxes, delims);
1932 result = strtok(NULL, delims);
1935 std::istringstream is(result);
1938 for (int i = 0; i < numBoxes; i++) {
1940 getline(inputStream, line);//BOX
1941 getline(inputStream, line);//package:type:name
1943 strcpy(box, line.c_str());
1944 result = strtok(box, delims);//package
1945 std::string package(result);
1946 result = strtok(NULL, delims);//type
1947 std::string type(result);
1948 result = strtok(NULL, delims);//name
1949 std::string name(result);
1951 getline(inputStream, line);//ISEXEC:TRUE|FALSE
1953 strcpy(exec, line.c_str());
1954 result = strtok(exec, delims);//ISEXEC
1955 result = strtok(NULL, delims);//TRUE|FALSE
1956 std::string isExec(result);
1959 getline(inputStream, line);//xInic:yInic:zInic
1961 strcpy(coord, line.c_str());
1962 result = strtok(coord, delims);//xInic
1963 std::string xInic(result);
1964 result = strtok(NULL, delims);//yInic
1965 std::string yInic(result);
1966 result = strtok(NULL, delims);//zInic
1967 std::string zInic(result);
1969 double xIn, yIn, zIn;
1970 std::istringstream xSt(xInic);
1972 std::istringstream ySt(yInic);
1974 std::istringstream zSt(zInic);
1978 getline(inputStream, line);//xEnd:yEnd:zEnd
1979 strcpy(coord, line.c_str());
1980 result = strtok(coord, delims);//xEnd
1981 std::string xEnd(result);
1982 result = strtok(NULL, delims);//yEnd
1983 std::string yEnd(result);
1984 result = strtok(NULL, delims);//zEnd
1985 std::string zEnd(result);
1987 double xEn, yEn, zEn;
1988 std::istringstream xEt(xEnd);
1990 std::istringstream yEt(yEnd);
1992 std::istringstream zEt(zEnd);
1995 bool boxExecutable = false;
1996 if (isExec == "TRUE") {
1997 boxExecutable = true;
2000 int idBox = createGBlackBox(xIn, yIn, package, type);
2001 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn,
2004 GObjectController *cont = _controllers[idBox];
2005 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2008 getline(inputStream, line);//PORT o FIN_BOX
2009 std::string port = line.substr(0, 4);
2010 while (port == "PORT") {
2011 getline(inputStream, line);//name:value
2013 strcpy(poort, line.c_str());
2014 result = strtok(poort, delims);//name
2015 std::string name(result);
2016 result = strtok(NULL, delims);//value
2017 std::string value(result);
2019 bbmod->setValueToInput(name, value);
2021 getline(inputStream, line);//PORT o FIN_BOX
2022 port = line.substr(0, 4);
2025 //EED bbmod->notifyObservers(_idManager);
2030 getline(inputStream, line);//CONNECTIONS:num
2032 strcpy(conns, line.c_str());
2033 result = strtok(conns, delims);
2034 result = strtok(NULL, delims);
2037 std::istringstream isCons(result);
2040 for (int i = 0; i < numConns; i++) {
2042 getline(inputStream, line);//CONNECTION
2043 getline(inputStream, line);//Startbox.PortName:EndBox.PortName
2046 strcpy(connec, line.c_str());
2047 result = strtok(connec, delims);
2048 std::string nameStartBox(result);
2049 result = strtok(NULL, delims);
2050 std::string nameStartPort(result);
2051 result = strtok(NULL, delims);
2052 std::string nameEndBox(result);
2053 result = strtok(NULL, delims);
2054 std::string nameEndPort(result);
2056 int idCon = configGConnetion(nameStartBox, nameStartPort,
2057 nameEndBox, nameEndPort);
2059 if (version != "1.0") {
2060 //Readding control points of the manualContour
2062 GConnectorController *tempp =
2063 (GConnectorController*) _controllers[idCon];
2064 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2065 vtkGConnectorView *conView =
2066 (vtkGConnectorView*) tempp->getView();
2067 getline(inputStream, line); //NumberOfControlPoints:##
2068 strcpy(conns, line.c_str());
2069 result = strtok(conns, delims);
2070 result = strtok(NULL, delims);
2072 int numberOfControlPoints;
2073 std::istringstream isCons(result);
2074 isCons >> numberOfControlPoints;
2076 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2077 getline(inputStream, line); //XX:YY:ZZ
2079 strcpy(connec, line.c_str());
2082 result = strtok(connec, delims);
2083 std::istringstream isPointX(result);
2085 result = strtok(NULL, delims);
2086 std::istringstream isPointY(result);
2088 result = strtok(NULL, delims);
2089 std::istringstream isPointZ(result);
2092 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px,
2094 conView->getManualContourView()->AddPoint();
2103 //=========================================================================
2106 //=========================================================================
2107 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2108 std::string portName, double xIn, double yIn, double zIn) {
2110 if (inputoutput == true) {
2111 idPort = createGComplexBoxInputPort(portName);
2113 idPort = createGComplexBoxOutputPort(portName);
2115 GObjectController *cont = _controllers[idPort];
2116 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2117 cbmod->setInicPoint(xIn, yIn, zIn);
2118 cbmod->notifyObservers(_idManager);
2120 //=========================================================================
2123 //=========================================================================
2124 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
2128 GBoxModel *boxModel = NULL;
2129 std::vector<int> lstB = getBlackBoxes();
2130 for (j = 0; j < (int) lstB.size(); j++) {
2132 bMod = (GBoxModel*) _controllers[idB]->getModel();
2133 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2138 if ((_isComplexBox) && (boxModel == NULL)) {
2139 std::vector<int> lstInputs = getComplexInputPorts();
2140 for (j = 0; j < (int) lstInputs.size(); j++) {
2142 bMod = (GBoxModel*) _controllers[idB]->getModel();
2143 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2148 std::vector<int> lstOutputs = getComplexOutputPorts();
2149 for (j = 0; j < (int) lstOutputs.size(); j++) {
2150 int idB = lstOutputs[j];
2151 bMod = (GBoxModel*) _controllers[idB]->getModel();
2152 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2162 //=========================================================================
2165 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2166 std::string nameStartPort, std::string nameEndBox,
2167 std::string nameEndPort) {
2169 GBoxModel *boxModel;
2170 GPortModel *startP = NULL;
2171 GPortModel *endP = NULL;
2173 boxModel = findGBox(nameStartBox);
2174 if (boxModel != NULL) {
2175 startP = boxModel->getOutputPort(nameStartPort);
2177 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port %s is null. Port name is probably wrong.\n", nameStartPort.c_str());
2181 boxModel = findGBox(nameEndBox);
2182 if (boxModel != NULL) {
2183 endP = boxModel->getInputPort(nameEndPort);
2185 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port %s is null. Port name is probably wrong\n", nameStartPort.c_str(), nameEndPort.c_str());
2190 int idCon = createGConnector(startP);
2191 _worldState = NOTHING_HAPPENS;
2192 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2194 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2195 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2196 tempp->endContourCreation();
2197 conMod->setEndPort(endP);
2198 conView->updateStartEndPoints();
2202 //=========================================================================
2204 bool wxVtkSceneManager::boxExist(std::string boxname) {
2206 std::map<int, GObjectController*>::iterator it;
2207 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2208 GObjectController *cont = it->second;
2209 if (cont->getModel()->getBBTKName() == boxname) {
2216 //=========================================================================
2218 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2219 std::vector<int> vect;
2220 std::map<int, GObjectController*>::iterator it;
2221 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2222 GObjectController *cont = it->second;
2223 if (cont->getGObjectType() == GBLACKBOX) {
2224 vect.push_back(cont->getId());
2230 //=========================================================================
2232 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2233 std::vector<int> vect;
2234 std::map<int, GObjectController*>::iterator it;
2235 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2236 GObjectController *cont = it->second;
2237 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2238 vect.push_back(cont->getId());
2244 //=========================================================================
2246 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2247 std::vector<int> vect;
2248 std::map<int, GObjectController*>::iterator it;
2249 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2250 GObjectController *cont = it->second;
2251 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2252 vect.push_back(cont->getId());
2258 //=========================================================================
2260 std::vector<int> wxVtkSceneManager::getConnections() {
2261 std::vector<int> vect;
2262 std::map<int, GObjectController*>::iterator it;
2263 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2264 GObjectController *cont = it->second;
2265 if (cont->getGObjectType() == GCONNECTOR) {
2266 vect.push_back(cont->getId());
2272 //=========================================================================
2274 bool wxVtkSceneManager::isComplexBox() {
2275 return _isComplexBox;
2278 //=========================================================================
2280 void wxVtkSceneManager::setComplexBox(bool val) {
2281 _isComplexBox = val;
2284 //=========================================================================
2286 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2287 //Register the controller of the new object
2288 registerController((InteractorStyleMaracas*) objController);
2289 //Add the object to the objects list
2290 int newId = _contLastId;//_controllers.size();
2291 objController->setId(newId);
2292 _controllers[newId] = objController;
2293 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2298 //=========================================================================
2300 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2302 std::map<int, int> oldIdNewIdBoxes;
2303 std::vector<int> connections;
2305 std::vector<int> newBoxesID;
2307 std::map<int, GObjectController*>::iterator it;
2308 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2309 GObjectController *cont = it->second;
2310 int type = cont->getGObjectType();
2312 if (type == GBLACKBOX) {
2314 double xInic, yInic, zInic;
2315 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2316 copyBox->getInicPoint(xInic, yInic, zInic);
2317 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2318 copyBox->getBBTKType());
2320 int idcB = copyBox->getObjectId();
2321 oldIdNewIdBoxes[idcB] = idBox;
2322 cont = _controllers[idBox];
2323 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2324 newbox->setInicPoint(xInic, yInic, zInic);
2325 int num = newbox->getNumInputPorts();
2326 for (int j = 0; j < num; j++) {
2327 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2329 newbox->move(xInic + 20, yInic + 20, zInic);
2330 newbox->notifyObservers(_idManager);
2331 newBoxesID.push_back(newbox->getObjectId());
2333 } else if (type == GCONNECTOR) {
2334 int idCon = cont->getId();
2335 connections.push_back(idCon);
2340 for (int i = 0; i < (int) connections.size(); i++) {
2341 int objId = connections[i];
2342 GObjectController *cont = objectsMap[objId];
2343 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2345 GPortModel* startPort = connectModel->getStartPort();
2346 int startPortIndex = startPort->getPosInBox();
2347 GPortModel* endPort = connectModel->getEndPort();
2348 int endPortIndex = endPort->getPosInBox();
2350 GBlackBoxModel* startPortParentBox =
2351 (GBlackBoxModel*) startPort->getParentBox();
2352 GBlackBoxModel* endPortParentBox =
2353 (GBlackBoxModel*) endPort->getParentBox();
2355 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2356 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2358 GBlackBoxModel* newStartBox =
2359 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2360 GBlackBoxModel* newEndBox =
2361 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2363 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2364 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2366 // Creates connection
2367 int idCon = createGConnector(newStartPort);
2368 GConnectorController *tempp =
2369 (GConnectorController*) _controllers[idCon];
2370 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2371 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2372 tempp->endContourCreation();
2373 conMod->setEndPort(newEndPort);
2374 conView->updateStartEndPoints();
2377 /// the new selected boxes are the duplicate ones
2379 UnSelectBlackBoxes();
2380 for (int i = 0; i < newBoxesID.size(); i++) {
2381 _selectedObjects.push_back(newBoxesID.at(i));
2384 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2385 int id = _selectedObjects[i];
2386 GObjectController* cont = _controllers[id];
2388 cont->getView()->setState(SELECTED);
2389 cont->getModel()->notifyObservers(_idManager);
2395 //=========================================================================
2397 int wxVtkSceneManager::getNumSelectedObjects() {
2398 return _selectedObjects.size();
2401 //=========================================================================
2403 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2404 std::map<int, GObjectController*> mapSelected;
2406 std::map<int, GObjectController*>::iterator it;
2407 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2408 GObjectController *cont = it->second;
2409 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2411 mapSelected[cont->getId()] = cont;
2415 std::map<int, GObjectController*>::iterator it2;
2416 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2417 GObjectController *cont = it2->second;
2418 if (cont->getGObjectType() == GCONNECTOR) {
2419 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2420 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2421 GBoxModel* startPortParentBox =
2422 cmod->getStartPort()->getParentBox();
2424 std::map<int, GObjectController*>::iterator iterOBJ1 =
2425 mapSelected.find(startPortParentBox->getObjectId());
2426 std::map<int, GObjectController*>::iterator iterOBJ2 =
2427 mapSelected.find(endPortParentBox->getObjectId());
2429 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2430 int ID = cont->getId();
2431 mapSelected[ID] = cont;
2438 //=========================================================================
2440 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2442 std::map<int, int> oldIdNewIdBoxes;
2443 std::vector<int> connections;
2445 std::map<int, GObjectController*>::iterator it;
2446 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2447 GObjectController *cont = it->second;
2448 int type = cont->getGObjectType();
2450 if (type == GBLACKBOX) {
2452 double xInic, yInic, zInic;
2453 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2454 copyBox->getInicPoint(xInic, yInic, zInic);
2455 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2456 copyBox->getBBTKType());
2458 int idcB = copyBox->getObjectId();
2459 oldIdNewIdBoxes[idcB] = idBox;
2460 cont = _controllers[idBox];
2461 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2462 newbox->setInicPoint(xInic, yInic, zInic);
2463 int num = newbox->getNumInputPorts();
2464 for (int j = 0; j < num; j++) {
2465 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2467 newbox->notifyObservers(_idManager);
2468 } else if (type == GCONNECTOR) {
2469 int idCon = cont->getId();
2470 connections.push_back(idCon);
2475 for (int i = 0; i < (int) connections.size(); i++) {
2476 int objId = connections[i];
2477 GObjectController *cont = objectsMap[objId];
2478 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2480 GPortModel* startPort = connectModel->getStartPort();
2481 int startPortIndex = startPort->getPosInBox();
2482 GPortModel* endPort = connectModel->getEndPort();
2483 int endPortIndex = endPort->getPosInBox();
2485 GBlackBoxModel* startPortParentBox =
2486 (GBlackBoxModel*) startPort->getParentBox();
2487 GBlackBoxModel* endPortParentBox =
2488 (GBlackBoxModel*) endPort->getParentBox();
2490 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2491 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2493 GBlackBoxModel* newStartBox =
2494 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2495 GBlackBoxModel* newEndBox =
2496 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2498 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2499 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2501 // Creates connection
2502 int idCon = createGConnector(newStartPort);
2503 GConnectorController *tempp =
2504 (GConnectorController*) _controllers[idCon];
2505 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2506 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2507 tempp->endContourCreation();
2508 conMod->setEndPort(newEndPort);
2509 conView->updateStartEndPoints();
2512 std::map<int, int>::iterator itIds;
2513 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2514 int idOld = itIds->first;
2515 int idNew = itIds->second;
2517 GBlackBoxModel* oldBox =
2518 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2519 GBlackBoxModel* newBox =
2520 (GBlackBoxModel*) _controllers[idNew]->getModel();
2522 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2523 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2524 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2525 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2527 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2529 //EED int toCreate=-1;
2530 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2531 if (oldInputConnections[k] == newInputConnections[l]) {
2536 if (exist == false) {
2537 //Create complex input
2538 int posInBox = oldInputConnections[k];
2539 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2540 std::string inputPortName = inputPort->getBBTKName();
2541 int idInputPort = createGComplexBoxInputPort(inputPortName);
2542 GObjectController *cont = _controllers[idInputPort];
2543 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2544 double xIn, yIn, zIn;
2545 inputPort->getInicPoint(xIn, yIn, zIn);
2547 cbmod->setInicPoint(xIn, yIn, zIn);
2548 cbmod->notifyObservers(_idManager);
2550 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2552 // Creates connection
2553 int idCon = createGConnector(cbmod->getOutputPort(0));
2554 GConnectorController *tempp =
2555 (GConnectorController*) _controllers[idCon];
2556 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2557 vtkGConnectorView *conView =
2558 (vtkGConnectorView*) tempp->getView();
2559 tempp->endContourCreation();
2560 conMod->setEndPort(inputPortEnd);
2561 conView->updateStartEndPoints();
2567 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2569 //EED int toCreate=-1;
2570 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2571 if (oldOutputConnections[k] == newOutputConnections[l]) {
2576 if (exist == false) {
2577 //Create complex output
2578 int posInBox = oldOutputConnections[k];
2579 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2580 std::string outputPortName = outputPort->getBBTKName();
2581 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2582 GObjectController *cont = _controllers[idOutputPort];
2583 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2584 double xIn, yIn, zIn;
2585 outputPort->getInicPoint(xIn, yIn, zIn);
2587 cbmod->setInicPoint(xIn, yIn, zIn);
2588 cbmod->notifyObservers(_idManager);
2590 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2592 // Creates connection
2593 int idCon = createGConnector(outputPortEnd);
2594 GConnectorController *tempp =
2595 (GConnectorController*) _controllers[idCon];
2596 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2597 vtkGConnectorView *conView =
2598 (vtkGConnectorView*) tempp->getView();
2599 tempp->endContourCreation();
2600 conMod->setEndPort(cbmod->getInputPort(0));
2601 conView->updateStartEndPoints();
2611 //=========================================================================
2612 void wxVtkSceneManager::SetCbName(std::string cbName) {
2614 if (_cbName == "") {
2615 _cbName = "<complex box name>";
2619 //=========================================================================
2620 std::string wxVtkSceneManager::GetCbName() {
2624 //=========================================================================
2625 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2626 _cbPackageName = packagename;
2627 if (_cbPackageName == "") {
2628 _cbPackageName = "<package name of the complex box>";
2632 //=========================================================================
2633 std::string wxVtkSceneManager::GetCbPackageName() {
2634 return _cbPackageName;
2637 //=========================================================================
2638 void wxVtkSceneManager::SetAuthor(std::string author) {
2640 if (_Author == "") {
2641 _Author = "<author of the box>";
2645 //=========================================================================
2646 std::string wxVtkSceneManager::GetAuthor() {
2650 //=========================================================================
2651 void wxVtkSceneManager::SetCategory(std::string category) {
2652 _Category = category;
2653 if (_Category == "") {
2654 _Category = "<category of the box>";
2658 //=========================================================================
2659 std::string wxVtkSceneManager::GetCategory() {
2663 //=========================================================================
2664 void wxVtkSceneManager::SetDescription(std::string description) {
2665 _Description = description;
2666 if (_Description == "") {
2667 _Description = "<description of the box>";
2671 //=========================================================================
2672 std::string wxVtkSceneManager::GetDescription() {
2673 return _Description;
2676 //=========================================================================
2679 void wxVtkSceneManager::printAll(int com , int sta ){
2681 int tmpState = sta ;
2682 if ( tmpState == NOTHING_HAPPENS ) {
2683 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2685 if ( tmpState == HIGHLIGHTED ) {
2686 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2688 if ( tmpState == POSSIBLE_CONNECTION ) {
2689 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2691 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2692 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2694 if ( tmpState == CLICKED ) {
2695 std::cout << "CONTROLER STATE---->CLICKED\n" ;
2697 if ( tmpState == DRAG ) {
2698 std::cout << "CONTROLER STATE---->DRAG\n" ;
2700 if ( tmpState == SELECTED ) {
2701 std::cout << "CONTROLER STATE---->SELECTED\n" ;
2703 if ( tmpState == CREATING_CONTOUR ) {
2704 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2710 if ( command == INIT_CREATION_CONTOUR ) {
2711 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2713 if ( command == FIN_CREATION_CONTOUR ) {
2714 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2716 if ( command == ADD_TO_SELECTED ) {
2717 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2719 if ( command == DRAG_OBJECTS ) {
2720 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2722 if ( command == EDIT_BLACKBOX ) {
2723 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
2725 if ( command == REMOVE_FROM_SELECTED ) {
2726 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
2732 } // EO namespace bbtk