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",
66 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
70 _worldState = NOTHING_HAPPENS;
71 registerController(this);
74 _idConnectionInCreation = -1;
79 //=========================================================================
81 void wxVtkSceneManager::disconnectDrop() {
82 printf("EED %p ~wxVtkSceneManager::disconnectDrop()\n", this);
83 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
84 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
87 //=========================================================================
89 wxVtkSceneManager::~wxVtkSceneManager() {
91 printf("EED %p ~wxVtkSceneManager() START\n", this);
94 printf("EED %p ~wxVtkSceneManager() END\n", this);
97 //=========================================================================
99 void wxVtkSceneManager::configureBaseView() {
100 printf("EED wxVtkSceneManager::configureBaseView 0\n");
101 vtkInteractorStyleBaseView2D *interactorstylebaseview =
102 vtkInteractorStyleBaseView2D::New();
104 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
106 // Important to activate the 2D interaction system
107 wxVTKRenderWindowInteractor *iren =
108 _baseView->GetWxVTKRenderWindowInteractor();
109 interactorstylebaseview->SetInteractor(iren);
110 iren->SetInteractorStyle(interactorstylebaseview);
111 interactorstylebaseview->SetwxVtkBaseView(_baseView);
113 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
114 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, 800, 1100);
116 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
117 _baseView->GetRenderer()->GradientBackgroundOn();
118 _baseView->Refresh();
121 _textActor = vtkTextActor3D::New();
122 _textActor->SetPosition(-9999, -9999, 900);
123 _textActor->SetInput("<void>");
124 _textActor->GetTextProperty()->SetFontSize(60);
125 _textActor->GetTextProperty()->BoldOn();
126 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,
129 _baseView->GetRenderer()->AddActor(_textActor);
131 // Actor Fill_Port_Text
138 vtkPolygon *aPolygon = vtkPolygon::New();
139 _fillObjectActor = vtkActor::New();
141 _pts = vtkPoints::New();
143 double w = 100, h = 10, b = h / 15, t = 3;
144 _pts->SetNumberOfPoints(21);
145 _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
146 _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
147 _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
148 _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
149 _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
151 _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
152 _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
153 _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
154 _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
156 _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
157 _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
158 _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
159 _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
161 _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
162 _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
163 _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
164 _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
166 _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
167 _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
168 _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
169 _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
171 aPolygon->GetPointIds()->SetNumberOfIds(21);
172 for (int i = 0; i < 21; i++) {
173 aPolygon->GetPointIds()->SetId(i, i);
176 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
177 aPolygonGrid->Allocate(1, 1);
178 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),
179 aPolygon->GetPointIds());
180 aPolygonGrid->SetPoints(_pts);
181 _aPolygonMapper = vtkDataSetMapper::New();
182 _aPolygonMapper->SetInput(aPolygonGrid);
183 _fillObjectActor->SetMapper(_aPolygonMapper);
184 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
186 _fillObjectActor->GetProperty()->SetOpacity(0);
187 _aPolygonMapper->Modified();
189 _baseView->GetRenderer()->AddActor(_fillObjectActor);
190 printf("EED wxVtkSceneManager::configureBaseView 1\n");
193 //=========================================================================
195 std::string wxVtkSceneManager::generateANewNameForABox() {
196 std::stringstream boxname;
197 if (_numBoxes < 10) {
198 boxname << "Box0" << _numBoxes;
200 boxname << "Box" << _numBoxes;
203 return boxname.str();
206 //=========================================================================
208 std::string wxVtkSceneManager::findANewNameForABox() {
209 std::string boxname = generateANewNameForABox();
211 while (boxExist(boxname) == true) {
212 boxname = generateANewNameForABox();
218 //=========================================================================
219 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
220 double zIn, std::string name, bool boxExecutable, double xEn,
221 double yEn, double zEn) {
222 GObjectController *cont = _controllers[idBox];
223 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
224 bbmod->setBBTKName(name);
225 bbmod->setInicPoint(xIn, yIn, zIn);
226 bbmod->setFinalPoint(xEn, yEn, zEn);
227 bbmod->setExecutable(boxExecutable);
229 bbmod->notifyObservers(_idManager);
233 //=========================================================================
235 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,
236 std::string boxType) {
237 _worldState = NOTHING_HAPPENS;
238 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
239 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
241 int type = GBLACKBOX;
243 //Create the MVC Objects
247 (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
249 vtkGObjectView *view =
250 GObjectsMVCFactory::getInstance()->createGObjectView(type);
251 GObjectController* controller =
252 GObjectsMVCFactory::getInstance()->createGObjectController(type);
254 BlackBoxDescriptor::Pointer descriptor =
255 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
256 packageName, boxType);
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();
548 manContourView->RefreshContour();
551 connectorModel->getInicPoint(x, y, z);
553 manContourControl->SetState(1);
554 manContourModel->SetCloseContour(false);
556 manContourModel->AddPoint(x, y, z);
557 manContourView->AddPoint();
559 manContourModel->AddPoint(x, y, z);
560 manContourView->AddPoint();
562 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
563 manContourControl->_bakIdPoint = bak;
564 manContourView->Refresh();
566 manContourControl->SetMoving(false);
568 connectorcontroller->setModelAndView(connectorModel, connectorView);
570 int newId = addObjectController(connectorcontroller);
572 connectorcontroller->setManualContourController(manContourControl);
573 connectorModel->setManualContourModel(manContourModel);
574 connectorView->setManualContourView(manContourView);
575 connectorView->setModel(connectorModel);
576 connectorView->setBaseView(_baseView);
578 connectorModel->addObserver(connectorView);
579 connectorModel->addObserver(this);
584 //=========================================================================
586 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param) {
587 vtkInteractorStyleBaseView
588 * baseViewControlManager =
589 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
590 baseViewControlManager->AddInteractorStyleMaracas(param);
593 //=========================================================================
595 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param) {
596 vtkInteractorStyleBaseView
597 * baseViewControlManager =
598 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
599 baseViewControlManager->RemoveInteractorStyleMaracas(param);
602 //=========================================================================
604 vtkRenderer* wxVtkSceneManager::getRenderer() {
605 return _baseView->GetRenderer();
608 //=========================================================================
610 vtkRenderWindow* wxVtkSceneManager::getRenderWindow() {
611 return _baseView->GetRenWin();
613 //=========================================================================
616 //=========================================================================
617 int wxVtkSceneManager::GetIndexInSelected(int idControler) {
619 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
620 if (_selectedObjects[i] == idControler) {
627 //=========================================================================
629 void wxVtkSceneManager::update(int idController, int command) {
631 if (command != NO_COMMAND) {
632 if (command == ADD_TO_SELECTED) {
633 //EEDBorrame GObjectController* cont = _controllers[idController];
635 if (GetIndexInSelected(idController) == -1) {
636 _selectedObjects.push_back(idController);
640 // bool foundID=false;
641 // for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
643 // if(_selectedObjects[i]==idController)
650 // _selectedObjects.push_back(idController);
653 } else if (command == REMOVE_FROM_SELECTED) {
654 int index = GetIndexInSelected(idController);
656 _selectedObjects.erase(_selectedObjects.begin() + index);
658 } else if (command == INIT_CREATION_CONTOUR) {
661 typedef std::map<int , GObjectController*>::iterator TIterator ;
664 // Find current item in the controller
665 iter = _controllers.find( idController ) ;
666 iter_end = _controllers.end( ) ;
668 if ( iter != iter_end ) {
669 GObjectController* gobjc = iter->second ;
671 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
672 // And if the item is a port
673 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
674 TIterator c_it = _controllers.begin( ) ;
675 // Go through all componets
676 for ( c_it ; c_it != iter_end ; c_it++ ) {
677 GObjectController* obc = c_it->second ;
678 int obc_type = obc->getModel( )->getGObjectType( ) ;
679 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
680 // if the component is a port and the type is the same of that selected
681 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
683 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
684 //obc->getView( )->setState( HIGHLIGHTED ) ;
692 _worldState = INIT_CREATION_CONTOUR;
693 GObjectController* cont = _controllers[idController];
694 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
696 // The last one is the controller of the connector
697 std::map<int, GObjectController*>::iterator it2;
699 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
700 GObjectController *cont = it2->second;
701 if (cont->getGObjectType() == GPORT) {
702 GPortModel* port = (GPortModel*) cont->getModel();
703 if (port->getPortType() == GINPUTPORT) {
704 cont->SetActive(true);
706 cont->getView()->setState(NOTHING_HAPPENS);
707 cont->getModel()->notifyObservers(_idManager);
708 cont->SetActive(false);
711 cont->getView()->setState(NOTHING_HAPPENS);
712 cont->getModel()->notifyObservers(_idManager);
713 cont->SetActive(false);
716 _selectedObjects.clear();
717 _idConnectionInCreation = createGConnector(startOutputPort);
718 } else if (command == FIN_CREATION_CONTOUR && _worldState
719 == INIT_CREATION_CONTOUR) {
720 _worldState = NOTHING_HAPPENS;
721 //int id = _controllers.size()-1;
722 GObjectController *cont = _controllers[_idConnectionInCreation];
723 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
724 GObjectController *finPort = _controllers[idController];
726 if (finPort->getGObjectType() == GPORT) {
727 GPortModel* modelPort = (GPortModel*) finPort->getModel();
728 modelContour->setEndPort(modelPort);
731 typedef std::map<int, GObjectController*>::iterator TIterator;
732 TIterator c_it = _controllers.begin();
733 TIterator iter_end = _controllers.end();
734 // Go through all componets
735 for (c_it; c_it != iter_end; c_it++) {
736 GObjectController* obc = c_it->second;
737 int obc_type = obc->getModel()->getGObjectType();
738 int obc_state = obc->getView()->getState();
739 // if the component is a port and the type is the same of that selected
740 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
741 // Return element to neutral state if not selected
742 obc->getView()->setState(NOTHING_HAPPENS);
744 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
745 // Change element to connected state
746 obc->getView()->setState(HIGHLIGHTED);
753 _parent->saveTempDiagram();
756 manualConnectorContourController
758 ((GConnectorController*) cont)->getManualContourController();
759 manualConnectorContourView
761 (manualConnectorContourView*) manCont->GetManualViewBaseContour();
764 std::map<int, GObjectController*>::iterator it2;
766 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
767 GObjectController *cont = it2->second;
768 if (cont->getView() != NULL) {
769 cont->getView()->setState(NOTHING_HAPPENS);
770 cont->getModel()->notifyObservers(_idManager);
772 cont->SetActive(true);
780 //=========================================================================
782 bool wxVtkSceneManager::OnMouseMove() {
784 bool okStatusMessage = false;
785 bool okPortMessage = false;
786 wxVTKRenderWindowInteractor *wxVTKiren;
788 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
789 wxVTKiren->GetEventPosition(X, Y);
791 if (_worldState == DRAG_OBJECTS) {
792 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
793 int id = _selectedObjects[i];
794 GObjectController* cont = _controllers[id];
795 if (_startDragging) {
796 cont->getView()->setStartDragging(true);
798 cont->getView()->moveObject(X, Y);
799 cont->getView()->setState(DRAG);
800 cont->getModel()->notifyObservers(_idManager);
803 std::map<int, GObjectController*>::iterator it;
805 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
806 GObjectController *desc = it->second;
807 if (desc->getGObjectType() == GCONNECTOR) {
808 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
809 vconn->updateStartEndPoints();
813 _startDragging = false;
815 } else if (_worldState == NOTHING_HAPPENS || _worldState
816 == INIT_CREATION_CONTOUR) {
817 std::map<int, GObjectController*>::iterator it;
819 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
820 GObjectController *desc = it->second;
821 int type = desc->getGObjectType();
822 int state = desc->getView()->getState();
823 desc->getModel()->getCenter(px, py, pz);
826 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION )) {
828 okStatusMessage = true;
829 updateStatusBar(desc->getStatusText());
830 if (type == GBLACKBOX) {
831 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
832 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),
837 okPortMessage = true;
839 _textActor->SetInput(desc->getStatusText().c_str());
840 _textActor->SetScale(0.1);
841 _textActor->SetPosition(px - 25, py + 1, pz + 2);
846 _fillObjectActor->SetScale(1);
847 _fillObjectActor->GetProperty()->SetOpacity(0.50);
848 _fillObjectActor->SetPosition(px, py, 1);
849 _aPolygonMapper->Modified();
852 } // for controllers it
855 if (okStatusMessage == false) {
859 if (okPortMessage == false) {
860 _textActor->SetScale(0.0001);
861 _fillObjectActor->SetScale(0.0001);
866 //=========================================================================
868 bool wxVtkSceneManager::OnLeftButtonDown() {
870 if (_worldState == INIT_CREATION_CONTOUR) {
871 bool isOverPort = false;
872 std::map<int, GObjectController*>::iterator it;
873 for (it = _controllers.begin(); it != _controllers.end() && isOverPort
875 GObjectController *desc = it->second;
876 if (desc->getGObjectType() == GPORT) {
877 GPortModel *portmod = (GPortModel*) desc->getModel();
878 vtkGObjectView *portView = desc->getView();
879 if (portmod->getPortType() == GINPUTPORT
880 && portView->getState() == HIGHLIGHTED) {
884 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
886 portView->setState( HIGHLIGHTED);
893 if (isOverPort == false) {
895 UnSelectBlackBoxes();
899 } else { //_worldState
901 _worldState = DRAG_OBJECTS;
902 _startDragging = true;
905 _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
907 _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
908 ctrlkey = ctrlkey + shiftkey;
910 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
912 if (GetGBlackBoxControlerPointedByMouse() != NULL) {
913 int state = cont->getView()->getState();
914 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
915 UnSelectBlackBoxes();
918 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
919 int id = _selectedObjects[i];
920 GObjectController* cont = _controllers[id];
921 cont->getView()->setState(DRAG);
922 cont->getModel()->notifyObservers(_idManager);
925 } // if _selectedObjects.size
931 //=========================================================================
933 bool wxVtkSceneManager::OnLeftButtonUp() {
934 if (_worldState == DRAG_OBJECTS) {
935 _worldState = NOTHING_HAPPENS;
937 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
938 int id = _selectedObjects[i];
939 GObjectController* cont = _controllers[id];
940 cont->getView()->setState(SELECTED);
941 cont->getModel()->notifyObservers(_idManager);
947 //=========================================================================
948 void wxVtkSceneManager::CancelConnection() {
949 if (_worldState == INIT_CREATION_CONTOUR) {
950 _worldState = NOTHING_HAPPENS;
951 //int lastId = _controllers.size()-1;
953 GConnectorController *connector =
954 (GConnectorController*) _controllers[_idConnectionInCreation];
955 connector->removeFromScene();
956 unregisterController(connector);
957 _controllers.erase(_idConnectionInCreation);
959 std::map<int, GObjectController*>::iterator it;
960 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
961 GObjectController *desc = it->second;
962 desc->SetActive(true);
963 desc->getView()->setState(NOTHING_HAPPENS);
964 desc->getModel()->notifyObservers(_idManager);
969 //=========================================================================
971 bool wxVtkSceneManager::OnRightButtonUp() {
972 if (_worldState == INIT_CREATION_CONTOUR) {
975 UnSelectBlackBoxes();
981 bool wxVtkSceneManager::OnMiddleButtonDown() {
984 this->_vtkInteractorStyleBaseView->StartPan();
989 bool wxVtkSceneManager::OnMiddleButtonUp() {
992 this->_vtkInteractorStyleBaseView->EndPan();
999 //=========================================================================
1001 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1002 GObjectController *result = NULL;
1004 wxVTKRenderWindowInteractor *wxVTKiren;
1006 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1007 wxVTKiren->GetEventPosition(X, Y);
1009 std::map<int, GObjectController*>::iterator it;
1011 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1012 GObjectController *cont = it->second;
1013 int type = cont->getGObjectType();
1015 if (cont->getView()->isPointInside(X, Y) == true) {
1016 if (type == GBLACKBOX) {
1019 } // if isPointInside
1024 //=========================================================================
1025 void wxVtkSceneManager::UnSelectBlackBoxes() {
1026 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1027 int id = _selectedObjects[i];
1028 GObjectController* control = _controllers[id];
1029 control->getView()->setState(NOTHING_HAPPENS);
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->saveTempDiagram();
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();
1637 //=========================================================================
1640 void wxVtkSceneManager::refresh() {
1641 _baseView->Refresh();
1643 //=========================================================================
1645 void wxVtkSceneManager::refreshScene() {
1646 _baseView->RefreshView();
1649 //=========================================================================
1651 void wxVtkSceneManager::centerView() {
1653 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1654 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1655 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1656 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1657 _baseView->RefreshView();
1661 //=========================================================================
1663 void wxVtkSceneManager::saveDiagram(std::string &content) {
1666 content += "CATEGORY:";
1667 content += GetCategory();
1670 content += "DESCRIPTION:";
1671 content += GetDescription();
1674 content += "AUTHOR:";
1675 content += GetAuthor();
1678 //Print info IF COMPLEX BOX
1679 content += "COMPLEXBOX:";
1680 if (_isComplexBox) {
1681 content += "TRUE\n";
1683 content += "COMPLEXBOXNAME:";
1684 content += GetCbName();
1687 content += "PACKAGENAME:";
1688 content += GetCbPackageName();
1691 //Print info complex input ports
1692 std::vector<int> inputs = getComplexInputPorts();
1693 int insize = inputs.size();
1694 content += "COMPLEXINPUTS:";
1695 sprintf(buffer, "%d", insize);
1699 for (int i = 0; i < insize; i++) {
1701 GObjectController *cont = _controllers[id];
1702 cont->getModel()->save(content);
1705 //Print info complex output ports
1706 std::vector<int> outputs = getComplexOutputPorts();
1707 int outsize = outputs.size();
1708 content += "COMPLEXOUTPUTS:";
1709 sprintf(buffer, "%d", outsize);
1713 for (int i = 0; i < outsize; i++) {
1714 int id = outputs[i];
1715 GObjectController *cont = _controllers[id];
1716 cont->getModel()->save(content);
1720 content += "FALSE\n";
1724 std::vector<int> boxes = getBlackBoxes();
1725 int bsize = boxes.size();
1726 content += "BOXES:";
1727 sprintf(buffer, "%d", bsize);
1731 for (int i = 0; i < bsize; i++) {
1733 GObjectController *cont = _controllers[id];
1734 cont->getModel()->save(content);
1738 std::vector<int> connections = getConnections();
1739 int csize = connections.size();
1740 content += "CONNECTIONS:";
1741 sprintf(buffer, "%d", csize);
1745 for (int i = 0; i < csize; i++) {
1746 int id = connections[i];
1747 GObjectController *cont = _controllers[id];
1748 cont->getModel()->save(content);
1753 //=========================================================================
1755 void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
1757 std::string version = "<void>";
1758 std::string line = "";
1759 char delims[] = ":";
1760 char *result = NULL;
1762 getline(inputStream, line);
1765 while (!inputStream.eof()) {
1766 if (line == "" || line[0] == '#') {
1767 getline(inputStream, line);
1768 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1769 version = line.substr(18, 3);
1771 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1772 version = line.substr(18, 3);
1774 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1775 version = line.substr(18, 3);
1777 } else if (line == "APP_START") {
1783 printf("EED wxVtkSceneManager::loadDiagram version=%s\n", version.c_str());
1787 if ((version != "1.0") && (version != "1.1")) {
1788 getline(inputStream, line);//CATEGORY:<category of the box>
1789 char categoryTmp[30];
1790 strcpy(categoryTmp, line.c_str());
1791 result = strtok(categoryTmp, delims);
1792 result = strtok(NULL, delims);
1793 SetCategory(result);
1795 getline(inputStream, line);//DESCRIPTION:<description of the box>
1796 char descriptionTmp[1024];
1797 strcpy(descriptionTmp, line.c_str());
1798 result = strtok(descriptionTmp, delims);
1799 result = strtok(NULL, delims);
1800 SetDescription(result);
1802 getline(inputStream, line);//AUTHOR:<author>
1803 char authorTmp[255];
1804 strcpy(authorTmp, line.c_str());
1805 result = strtok(authorTmp, delims);
1806 result = strtok(NULL, delims);
1811 getline(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1812 char complexTmp[30];
1813 strcpy(complexTmp, line.c_str());
1814 result = strtok(complexTmp, delims);
1815 result = strtok(NULL, delims);
1816 std::string isComplexBox(result);
1818 if (isComplexBox == "TRUE") {
1819 _isComplexBox = true;
1821 if ((version != "1.0") && (version != "1.1")) {
1822 getline(inputStream, line);//COMPLEXNAME:<name of the complex box>
1823 char complexboxnameTmp[255];
1824 strcpy(complexboxnameTmp, line.c_str());
1825 result = strtok(complexboxnameTmp, delims);
1826 result = strtok(NULL, delims);
1829 getline(inputStream, line);//PACKAGENAME:<name of the package of the box>
1830 char packagenameTmp[255];
1831 strcpy(packagenameTmp, line.c_str());
1832 result = strtok(packagenameTmp, delims);
1833 result = strtok(NULL, delims);
1834 SetCbPackageName(result);
1837 //-----------------------
1838 //- COMPLEX INPUT PORTS
1839 //-----------------------
1840 getline(inputStream, line);//COMPLEXINPUTS:num
1842 strcpy(inputs, line.c_str());
1843 result = strtok(inputs, delims);
1844 result = strtok(NULL, delims);
1847 std::istringstream inps(result);
1850 for (int i = 0; i < numInputs; i++) {
1852 getline(inputStream, line);//COMPLEX_PORT
1853 getline(inputStream, line);//name
1854 std::string inputPortName(line);
1857 getline(inputStream, line);//xInic:yInic:zInic
1859 strcpy(coord, line.c_str());
1860 result = strtok(coord, delims);//xInic
1861 std::string xInic(result);
1862 result = strtok(NULL, delims);//yInic
1863 std::string yInic(result);
1864 result = strtok(NULL, delims);//zInic
1865 std::string zInic(result);
1867 double xIn, yIn, zIn;
1868 std::istringstream xSt(xInic);
1870 std::istringstream ySt(yInic);
1872 std::istringstream zSt(zInic);
1875 getline(inputStream, line);//FIN_COMPLEX_PORT
1877 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
1879 } // for input complex box
1882 //-----------------------
1883 //- COMPLEX OUTPUT PORTS
1884 //-----------------------
1886 getline(inputStream, line);//COMPLEXOUTPUTS:num
1888 strcpy(outputs, line.c_str());
1889 result = strtok(outputs, delims);
1890 result = strtok(NULL, delims);
1893 std::istringstream outps(result);
1894 outps >> numOutputs;
1896 for (int i = 0; i < numOutputs; i++) {
1898 getline(inputStream, line);//COMPLEX_PORT
1899 getline(inputStream, line);//name
1900 std::string outputPortName(line);
1903 getline(inputStream, line);//xInic:yInic:zInic
1905 strcpy(coord, line.c_str());
1906 result = strtok(coord, delims);//xInic
1907 std::string xInic(result);
1908 result = strtok(NULL, delims);//yInic
1909 std::string yInic(result);
1910 result = strtok(NULL, delims);//zInic
1911 std::string zInic(result);
1913 double xIn, yIn, zIn;
1914 std::istringstream xSt(xInic);
1916 std::istringstream ySt(yInic);
1918 std::istringstream zSt(zInic);
1921 getline(inputStream, line);//FIN_COMPLEX_PORT
1923 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn,
1926 } // for output complex box
1931 getline(inputStream, line);//BOXES:num
1933 strcpy(boxes, line.c_str());
1934 result = strtok(boxes, delims);
1935 result = strtok(NULL, delims);
1938 std::istringstream is(result);
1941 for (int i = 0; i < numBoxes; i++) {
1943 getline(inputStream, line);//BOX
1944 getline(inputStream, line);//package:type:name
1946 strcpy(box, line.c_str());
1947 result = strtok(box, delims);//package
1948 std::string package(result);
1949 result = strtok(NULL, delims);//type
1950 std::string type(result);
1951 result = strtok(NULL, delims);//name
1952 std::string name(result);
1954 getline(inputStream, line);//ISEXEC:TRUE|FALSE
1956 strcpy(exec, line.c_str());
1957 result = strtok(exec, delims);//ISEXEC
1958 result = strtok(NULL, delims);//TRUE|FALSE
1959 std::string isExec(result);
1962 getline(inputStream, line);//xInic:yInic:zInic
1964 strcpy(coord, line.c_str());
1965 result = strtok(coord, delims);//xInic
1966 std::string xInic(result);
1967 result = strtok(NULL, delims);//yInic
1968 std::string yInic(result);
1969 result = strtok(NULL, delims);//zInic
1970 std::string zInic(result);
1972 double xIn, yIn, zIn;
1973 std::istringstream xSt(xInic);
1975 std::istringstream ySt(yInic);
1977 std::istringstream zSt(zInic);
1981 getline(inputStream, line);//xEnd:yEnd:zEnd
1982 strcpy(coord, line.c_str());
1983 result = strtok(coord, delims);//xEnd
1984 std::string xEnd(result);
1985 result = strtok(NULL, delims);//yEnd
1986 std::string yEnd(result);
1987 result = strtok(NULL, delims);//zEnd
1988 std::string zEnd(result);
1990 double xEn, yEn, zEn;
1991 std::istringstream xEt(xEnd);
1993 std::istringstream yEt(yEnd);
1995 std::istringstream zEt(zEnd);
1998 bool boxExecutable = false;
1999 if (isExec == "TRUE") {
2000 boxExecutable = true;
2003 int idBox = createGBlackBox(xIn, yIn, package, type);
2004 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn,
2007 GObjectController *cont = _controllers[idBox];
2008 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2011 getline(inputStream, line);//PORT o FIN_BOX
2012 std::string port = line.substr(0, 4);
2013 while (port == "PORT") {
2014 getline(inputStream, line);//name:value
2016 strcpy(poort, line.c_str());
2017 result = strtok(poort, delims);//name
2018 std::string name(result);
2019 result = strtok(NULL, delims);//value
2020 std::string value(result);
2022 bbmod->setValueToInput(name, value);
2024 getline(inputStream, line);//PORT o FIN_BOX
2025 port = line.substr(0, 4);
2028 //EED bbmod->notifyObservers(_idManager);
2033 getline(inputStream, line);//CONNECTIONS:num
2035 strcpy(conns, line.c_str());
2036 result = strtok(conns, delims);
2037 result = strtok(NULL, delims);
2040 std::istringstream isCons(result);
2043 for (int i = 0; i < numConns; i++) {
2045 getline(inputStream, line);//CONNECTION
2046 getline(inputStream, line);//Startbox.PortName:EndBox.PortName
2049 strcpy(connec, line.c_str());
2050 result = strtok(connec, delims);
2051 std::string nameStartBox(result);
2052 result = strtok(NULL, delims);
2053 std::string nameStartPort(result);
2054 result = strtok(NULL, delims);
2055 std::string nameEndBox(result);
2056 result = strtok(NULL, delims);
2057 std::string nameEndPort(result);
2059 int idCon = configGConnetion(nameStartBox, nameStartPort,
2060 nameEndBox, nameEndPort);
2062 if (version != "1.0") {
2063 //Readding control points of the manualContour
2065 GConnectorController *tempp =
2066 (GConnectorController*) _controllers[idCon];
2067 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2068 vtkGConnectorView *conView =
2069 (vtkGConnectorView*) tempp->getView();
2070 getline(inputStream, line); //NumberOfControlPoints:##
2071 strcpy(conns, line.c_str());
2072 result = strtok(conns, delims);
2073 result = strtok(NULL, delims);
2075 int numberOfControlPoints;
2076 std::istringstream isCons(result);
2077 isCons >> numberOfControlPoints;
2079 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2080 getline(inputStream, line); //XX:YY:ZZ
2082 strcpy(connec, line.c_str());
2085 result = strtok(connec, delims);
2086 std::istringstream isPointX(result);
2088 result = strtok(NULL, delims);
2089 std::istringstream isPointY(result);
2091 result = strtok(NULL, delims);
2092 std::istringstream isPointZ(result);
2095 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px,
2097 conView->getManualContourView()->AddPoint();
2107 //=========================================================================
2110 //=========================================================================
2111 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2112 std::string portName, double xIn, double yIn, double zIn) {
2114 if (inputoutput == true) {
2115 idPort = createGComplexBoxInputPort(portName);
2117 idPort = createGComplexBoxOutputPort(portName);
2119 GObjectController *cont = _controllers[idPort];
2120 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2121 cbmod->setInicPoint(xIn, yIn, zIn);
2122 cbmod->notifyObservers(_idManager);
2124 //=========================================================================
2127 //=========================================================================
2128 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
2132 GBoxModel *boxModel = NULL;
2133 std::vector<int> lstB = getBlackBoxes();
2134 for (j = 0; j < (int) lstB.size(); j++) {
2136 bMod = (GBoxModel*) _controllers[idB]->getModel();
2137 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2142 if ((_isComplexBox) && (boxModel == NULL)) {
2143 std::vector<int> lstInputs = getComplexInputPorts();
2144 for (j = 0; j < (int) lstInputs.size(); j++) {
2146 bMod = (GBoxModel*) _controllers[idB]->getModel();
2147 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2152 std::vector<int> lstOutputs = getComplexOutputPorts();
2153 for (j = 0; j < (int) lstOutputs.size(); j++) {
2154 int idB = lstOutputs[j];
2155 bMod = (GBoxModel*) _controllers[idB]->getModel();
2156 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2166 //=========================================================================
2169 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2170 std::string nameStartPort, std::string nameEndBox,
2171 std::string nameEndPort) {
2173 GBoxModel *boxModel;
2174 GPortModel *startP = NULL;
2175 GPortModel *endP = NULL;
2177 boxModel = findGBox(nameStartBox);
2178 if (boxModel != NULL) {
2179 startP = boxModel->getOutputPort(nameStartPort);
2182 boxModel = findGBox(nameEndBox);
2183 if (boxModel != NULL) {
2184 endP = boxModel->getInputPort(nameEndPort);
2188 int idCon = createGConnector(startP);
2189 _worldState = NOTHING_HAPPENS;
2190 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2192 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2193 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2194 tempp->endContourCreation();
2195 conMod->setEndPort(endP);
2196 conView->updateStartEndPoints();
2200 //=========================================================================
2202 bool wxVtkSceneManager::boxExist(std::string boxname) {
2204 std::map<int, GObjectController*>::iterator it;
2205 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2206 GObjectController *cont = it->second;
2207 if (cont->getModel()->getBBTKName() == boxname) {
2214 //=========================================================================
2216 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2217 std::vector<int> vect;
2218 std::map<int, GObjectController*>::iterator it;
2219 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2220 GObjectController *cont = it->second;
2221 if (cont->getGObjectType() == GBLACKBOX) {
2222 vect.push_back(cont->getId());
2228 //=========================================================================
2230 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2231 std::vector<int> vect;
2232 std::map<int, GObjectController*>::iterator it;
2233 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2234 GObjectController *cont = it->second;
2235 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2236 vect.push_back(cont->getId());
2242 //=========================================================================
2244 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2245 std::vector<int> vect;
2246 std::map<int, GObjectController*>::iterator it;
2247 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2248 GObjectController *cont = it->second;
2249 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2250 vect.push_back(cont->getId());
2256 //=========================================================================
2258 std::vector<int> wxVtkSceneManager::getConnections() {
2259 std::vector<int> vect;
2260 std::map<int, GObjectController*>::iterator it;
2261 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2262 GObjectController *cont = it->second;
2263 if (cont->getGObjectType() == GCONNECTOR) {
2264 vect.push_back(cont->getId());
2270 //=========================================================================
2272 bool wxVtkSceneManager::isComplexBox() {
2273 return _isComplexBox;
2276 //=========================================================================
2278 void wxVtkSceneManager::setComplexBox(bool val) {
2279 _isComplexBox = val;
2282 //=========================================================================
2284 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2285 //Register the controller of the new object
2286 registerController((InteractorStyleMaracas*) objController);
2287 //Add the object to the objects list
2288 int newId = _contLastId;//_controllers.size();
2289 objController->setId(newId);
2290 _controllers[newId] = objController;
2291 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2296 //=========================================================================
2298 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2300 std::map<int, int> oldIdNewIdBoxes;
2301 std::vector<int> connections;
2303 std::vector<int> newBoxesID;
2305 std::map<int, GObjectController*>::iterator it;
2306 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2307 GObjectController *cont = it->second;
2308 int type = cont->getGObjectType();
2310 if (type == GBLACKBOX) {
2312 double xInic, yInic, zInic;
2313 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2314 copyBox->getInicPoint(xInic, yInic, zInic);
2315 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2316 copyBox->getBBTKType());
2318 int idcB = copyBox->getObjectId();
2319 oldIdNewIdBoxes[idcB] = idBox;
2320 cont = _controllers[idBox];
2321 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2322 newbox->setInicPoint(xInic, yInic, zInic);
2323 int num = newbox->getNumInputPorts();
2324 for (int j = 0; j < num; j++) {
2325 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2327 newbox->move(xInic + 20, yInic + 20, zInic);
2328 newbox->notifyObservers(_idManager);
2329 newBoxesID.push_back(newbox->getObjectId());
2331 } else if (type == GCONNECTOR) {
2332 int idCon = cont->getId();
2333 connections.push_back(idCon);
2338 for (int i = 0; i < (int) connections.size(); i++) {
2339 int objId = connections[i];
2340 GObjectController *cont = objectsMap[objId];
2341 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2343 GPortModel* startPort = connectModel->getStartPort();
2344 int startPortIndex = startPort->getPosInBox();
2345 GPortModel* endPort = connectModel->getEndPort();
2346 int endPortIndex = endPort->getPosInBox();
2348 GBlackBoxModel* startPortParentBox =
2349 (GBlackBoxModel*) startPort->getParentBox();
2350 GBlackBoxModel* endPortParentBox =
2351 (GBlackBoxModel*) endPort->getParentBox();
2353 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2354 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2356 GBlackBoxModel* newStartBox =
2357 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2358 GBlackBoxModel* newEndBox =
2359 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2361 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2362 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2364 // Creates connection
2365 int idCon = createGConnector(newStartPort);
2366 GConnectorController *tempp =
2367 (GConnectorController*) _controllers[idCon];
2368 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2369 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2370 tempp->endContourCreation();
2371 conMod->setEndPort(newEndPort);
2372 conView->updateStartEndPoints();
2375 /// the new selected boxes are the duplicate ones
2377 UnSelectBlackBoxes();
2378 for (int i = 0; i < newBoxesID.size(); i++) {
2379 _selectedObjects.push_back(newBoxesID.at(i));
2382 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2383 int id = _selectedObjects[i];
2384 GObjectController* cont = _controllers[id];
2386 cont->getView()->setState(SELECTED);
2387 cont->getModel()->notifyObservers(_idManager);
2394 //=========================================================================
2396 int wxVtkSceneManager::getNumSelectedObjects() {
2397 return _selectedObjects.size();
2400 //=========================================================================
2402 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2403 std::map<int, GObjectController*> mapSelected;
2405 std::map<int, GObjectController*>::iterator it;
2406 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2407 GObjectController *cont = it->second;
2408 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2410 mapSelected[cont->getId()] = cont;
2414 std::map<int, GObjectController*>::iterator it2;
2415 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2416 GObjectController *cont = it2->second;
2417 if (cont->getGObjectType() == GCONNECTOR) {
2418 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2419 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2420 GBoxModel* startPortParentBox =
2421 cmod->getStartPort()->getParentBox();
2423 std::map<int, GObjectController*>::iterator iterOBJ1 =
2424 mapSelected.find(startPortParentBox->getObjectId());
2425 std::map<int, GObjectController*>::iterator iterOBJ2 =
2426 mapSelected.find(endPortParentBox->getObjectId());
2428 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2429 int ID = cont->getId();
2430 mapSelected[ID] = cont;
2437 //=========================================================================
2439 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2441 std::map<int, int> oldIdNewIdBoxes;
2442 std::vector<int> connections;
2444 std::map<int, GObjectController*>::iterator it;
2445 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2446 GObjectController *cont = it->second;
2447 int type = cont->getGObjectType();
2449 if (type == GBLACKBOX) {
2451 double xInic, yInic, zInic;
2452 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2453 copyBox->getInicPoint(xInic, yInic, zInic);
2454 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2455 copyBox->getBBTKType());
2457 int idcB = copyBox->getObjectId();
2458 oldIdNewIdBoxes[idcB] = idBox;
2459 cont = _controllers[idBox];
2460 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2461 newbox->setInicPoint(xInic, yInic, zInic);
2462 int num = newbox->getNumInputPorts();
2463 for (int j = 0; j < num; j++) {
2464 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2466 newbox->notifyObservers(_idManager);
2467 } else if (type == GCONNECTOR) {
2468 int idCon = cont->getId();
2469 connections.push_back(idCon);
2474 for (int i = 0; i < (int) connections.size(); i++) {
2475 int objId = connections[i];
2476 GObjectController *cont = objectsMap[objId];
2477 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2479 GPortModel* startPort = connectModel->getStartPort();
2480 int startPortIndex = startPort->getPosInBox();
2481 GPortModel* endPort = connectModel->getEndPort();
2482 int endPortIndex = endPort->getPosInBox();
2484 GBlackBoxModel* startPortParentBox =
2485 (GBlackBoxModel*) startPort->getParentBox();
2486 GBlackBoxModel* endPortParentBox =
2487 (GBlackBoxModel*) endPort->getParentBox();
2489 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2490 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2492 GBlackBoxModel* newStartBox =
2493 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2494 GBlackBoxModel* newEndBox =
2495 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2497 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2498 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2500 // Creates connection
2501 int idCon = createGConnector(newStartPort);
2502 GConnectorController *tempp =
2503 (GConnectorController*) _controllers[idCon];
2504 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2505 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2506 tempp->endContourCreation();
2507 conMod->setEndPort(newEndPort);
2508 conView->updateStartEndPoints();
2511 std::map<int, int>::iterator itIds;
2512 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2513 int idOld = itIds->first;
2514 int idNew = itIds->second;
2516 GBlackBoxModel* oldBox =
2517 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2518 GBlackBoxModel* newBox =
2519 (GBlackBoxModel*) _controllers[idNew]->getModel();
2521 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2522 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2523 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2524 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2526 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2528 //EED int toCreate=-1;
2529 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2530 if (oldInputConnections[k] == newInputConnections[l]) {
2535 if (exist == false) {
2536 //Create complex input
2537 int posInBox = oldInputConnections[k];
2538 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2539 std::string inputPortName = inputPort->getBBTKName();
2540 int idInputPort = createGComplexBoxInputPort(inputPortName);
2541 GObjectController *cont = _controllers[idInputPort];
2542 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2543 double xIn, yIn, zIn;
2544 inputPort->getInicPoint(xIn, yIn, zIn);
2546 cbmod->setInicPoint(xIn, yIn, zIn);
2547 cbmod->notifyObservers(_idManager);
2549 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2551 // Creates connection
2552 int idCon = createGConnector(cbmod->getOutputPort(0));
2553 GConnectorController *tempp =
2554 (GConnectorController*) _controllers[idCon];
2555 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2556 vtkGConnectorView *conView =
2557 (vtkGConnectorView*) tempp->getView();
2558 tempp->endContourCreation();
2559 conMod->setEndPort(inputPortEnd);
2560 conView->updateStartEndPoints();
2566 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2568 //EED int toCreate=-1;
2569 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2570 if (oldOutputConnections[k] == newOutputConnections[l]) {
2575 if (exist == false) {
2576 //Create complex output
2577 int posInBox = oldOutputConnections[k];
2578 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2579 std::string outputPortName = outputPort->getBBTKName();
2580 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2581 GObjectController *cont = _controllers[idOutputPort];
2582 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2583 double xIn, yIn, zIn;
2584 outputPort->getInicPoint(xIn, yIn, zIn);
2586 cbmod->setInicPoint(xIn, yIn, zIn);
2587 cbmod->notifyObservers(_idManager);
2589 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2591 // Creates connection
2592 int idCon = createGConnector(outputPortEnd);
2593 GConnectorController *tempp =
2594 (GConnectorController*) _controllers[idCon];
2595 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2596 vtkGConnectorView *conView =
2597 (vtkGConnectorView*) tempp->getView();
2598 tempp->endContourCreation();
2599 conMod->setEndPort(cbmod->getInputPort(0));
2600 conView->updateStartEndPoints();
2610 //=========================================================================
2611 void wxVtkSceneManager::SetCbName(std::string cbName) {
2613 if (_cbName == "") {
2614 _cbName = "<complex box name>";
2618 //=========================================================================
2619 std::string wxVtkSceneManager::GetCbName() {
2623 //=========================================================================
2624 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2625 _cbPackageName = packagename;
2626 if (_cbPackageName == "") {
2627 _cbPackageName = "<package name of the complex box>";
2631 //=========================================================================
2632 std::string wxVtkSceneManager::GetCbPackageName() {
2633 return _cbPackageName;
2636 //=========================================================================
2637 void wxVtkSceneManager::SetAuthor(std::string author) {
2639 if (_Author == "") {
2640 _Author = "<author of the box>";
2644 //=========================================================================
2645 std::string wxVtkSceneManager::GetAuthor() {
2649 //=========================================================================
2650 void wxVtkSceneManager::SetCategory(std::string category) {
2651 _Category = category;
2652 if (_Category == "") {
2653 _Category = "<category of the box>";
2657 //=========================================================================
2658 std::string wxVtkSceneManager::GetCategory() {
2662 //=========================================================================
2663 void wxVtkSceneManager::SetDescription(std::string description) {
2664 _Description = description;
2665 if (_Description == "") {
2666 _Description = "<description of the box>";
2670 //=========================================================================
2671 std::string wxVtkSceneManager::GetDescription() {
2672 return _Description;
2675 //=========================================================================
2678 void wxVtkSceneManager::printAll(int com , int sta ){
2680 int tmpState = sta ;
2681 if ( tmpState == NOTHING_HAPPENS ) {
2682 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2684 if ( tmpState == HIGHLIGHTED ) {
2685 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2687 if ( tmpState == POSSIBLE_CONNECTION ) {
2688 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2690 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2691 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2693 if ( tmpState == CLICKED ) {
2694 std::cout << "CONTROLER STATE---->CLICKED\n" ;
2696 if ( tmpState == DRAG ) {
2697 std::cout << "CONTROLER STATE---->DRAG\n" ;
2699 if ( tmpState == SELECTED ) {
2700 std::cout << "CONTROLER STATE---->SELECTED\n" ;
2702 if ( tmpState == CREATING_CONTOUR ) {
2703 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2709 if ( command == INIT_CREATION_CONTOUR ) {
2710 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2712 if ( command == FIN_CREATION_CONTOUR ) {
2713 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2715 if ( command == ADD_TO_SELECTED ) {
2716 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2718 if ( command == DRAG_OBJECTS ) {
2719 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2721 if ( command == EDIT_BLACKBOX ) {
2722 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
2724 if ( command == REMOVE_FROM_SELECTED ) {
2725 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
2731 } // EO namespace bbtk