1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::wxVtkSceneManager .
36 #include "wxVtkSceneManager.h"
39 #include <vtkPolygon.h>
40 #include <vtkUnstructuredGrid.h>
46 //=========================================================================
47 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent,
48 wxVtk3DBaseView *baseView, int idManager) {
49 _cbName = "ComplexBoxName";
50 _cbPackageName = "PackageName";
51 _Author = "Author ??";
53 _Description = "Description ??";
57 _idManager = idManager;
59 _startDragging = false;
60 _isComplexBox = false;
62 if (_baseView != NULL) {
65 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n", this);
69 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
74 _worldState = NOTHING_HAPPENS;
75 registerController(this);
78 _idConnectionInCreation = -1;
83 //=========================================================================
85 void wxVtkSceneManager::disconnectDrop() {
86 printf("EED %p ~wxVtkSceneManager::disconnectDrop()\n", this);
87 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
88 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
91 //=========================================================================
93 wxVtkSceneManager::~wxVtkSceneManager() {
95 printf("EED %p ~wxVtkSceneManager()\n", this);
100 //=========================================================================
102 void wxVtkSceneManager::configureBaseView() {
103 printf("EED wxVtkSceneManager::configureBaseView 0\n");
104 vtkInteractorStyleBaseView2D *interactorstylebaseview =
105 vtkInteractorStyleBaseView2D::New();
107 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
109 // Important to activate the 2D interaction system
110 wxVTKRenderWindowInteractor *iren =
111 _baseView->GetWxVTKRenderWindowInteractor();
112 interactorstylebaseview->SetInteractor(iren);
113 iren->SetInteractorStyle(interactorstylebaseview);
114 interactorstylebaseview->SetwxVtkBaseView(_baseView);
116 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
117 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, 800, 1100);
119 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
120 _baseView->GetRenderer()->GradientBackgroundOn();
121 _baseView->Refresh();
124 _textActor = vtkTextActor3D::New();
125 _textActor->SetPosition(-9999, -9999, 900);
126 _textActor->SetInput("<void>");
127 _textActor->GetTextProperty()->SetFontSize(60);
128 _textActor->GetTextProperty()->BoldOn();
129 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,
132 _baseView->GetRenderer()->AddActor(_textActor);
134 // Actor Fill_Port_Text
141 vtkPolygon *aPolygon = vtkPolygon::New();
142 _fillObjectActor = vtkActor::New();
144 _pts = vtkPoints::New();
146 double w = 100, h = 10, b = h / 15, t = 3;
147 _pts->SetNumberOfPoints(21);
148 _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
149 _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
150 _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
151 _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
152 _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
154 _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
155 _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
156 _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
157 _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
159 _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
160 _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
161 _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
162 _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
164 _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
165 _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
166 _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
167 _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
169 _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
170 _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
171 _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
172 _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
174 aPolygon->GetPointIds()->SetNumberOfIds(21);
175 for (int i = 0; i < 21; i++) {
176 aPolygon->GetPointIds()->SetId(i, i);
179 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
180 aPolygonGrid->Allocate(1, 1);
181 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),
182 aPolygon->GetPointIds());
183 aPolygonGrid->SetPoints(_pts);
184 _aPolygonMapper = vtkDataSetMapper::New();
185 _aPolygonMapper->SetInput(aPolygonGrid);
186 _fillObjectActor->SetMapper(_aPolygonMapper);
187 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
189 _fillObjectActor->GetProperty()->SetOpacity(0);
190 _aPolygonMapper->Modified();
192 _baseView->GetRenderer()->AddActor(_fillObjectActor);
193 printf("EED wxVtkSceneManager::configureBaseView 1\n");
196 //=========================================================================
198 std::string wxVtkSceneManager::generateANewNameForABox() {
199 std::stringstream boxname;
200 if (_numBoxes < 10) {
201 boxname << "Box0" << _numBoxes;
203 boxname << "Box" << _numBoxes;
206 return boxname.str();
209 //=========================================================================
211 std::string wxVtkSceneManager::findANewNameForABox() {
212 std::string boxname = generateANewNameForABox();
214 while (boxExist(boxname) == true) {
215 boxname = generateANewNameForABox();
221 //=========================================================================
222 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
223 double zIn, std::string name, bool boxExecutable, double xEn,
224 double yEn, double zEn) {
225 GObjectController *cont = _controllers[idBox];
226 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
227 bbmod->setBBTKName(name);
228 bbmod->setInicPoint(xIn, yIn, zIn);
229 bbmod->setFinalPoint(xEn, yEn, zEn);
230 bbmod->setExecutable(boxExecutable);
232 bbmod->notifyObservers(_idManager);
236 //=========================================================================
238 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,
239 std::string boxType) {
240 _worldState = NOTHING_HAPPENS;
241 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
242 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
244 int type = GBLACKBOX;
246 //Create the MVC Objects
250 (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
252 vtkGObjectView *view =
253 GObjectsMVCFactory::getInstance()->createGObjectView(type);
254 GObjectController* controller =
255 GObjectsMVCFactory::getInstance()->createGObjectController(type);
257 BlackBoxDescriptor::Pointer descriptor =
258 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
259 packageName, boxType);
261 //Prepares the initial model
262 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
265 double yy = windowHeight - y;
267 //z value is not important yet, because it is only used a parallel projection
269 _baseView->TransCoordScreenToWorld(xx, yy, zz);
270 model->setInicPoint(xx, yy, zz);
272 std::stringstream stream;
274 std::string newBoxName;
275 newBoxName = findANewNameForABox();
277 stream << newBoxName;
279 std::string arraystring = stream.str();
281 model->setBBTKName(arraystring);
282 model->setBBTKType(boxType);
283 model->setBBTKPackage(packageName);
285 model->addObserver(view);
286 model->addObserver(this);
288 //Iterate and create the input ports
289 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
290 descriptor->GetInputDescriptorMap();
291 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
294 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) {
295 BlackBoxInputDescriptor *desc = itInput->second;
296 createGInputPort(GINPUTPORT, i, model, desc);
300 //Iterate and create the output ports
301 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
302 descriptor->GetOutputDescriptorMap();
303 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
306 for (itOutput = descriptorOutMap.begin(); itOutput
307 != descriptorOutMap.end(); ++itOutput) {
308 BlackBoxOutputDescriptor *desc = itOutput->second;
309 createGOutputPort(GOUTPUTPORT, i, model, desc);
313 //Associates the view with the correspondent renderer and the model.
314 //(NOTE: Refresh is only made by the view)
315 view->setModel(model);
316 view->setBaseView(_baseView);
317 view->initVtkObjects();
319 //Associates the controller with the correspondent model and view
320 controller->setModelAndView(model, view);
322 //Resgiter change to the observers of the actual model
323 model->notifyObservers(_idManager);
325 int newId = addObjectController(controller);
331 //=========================================================================
333 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
334 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
335 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
337 int type = GCOMPLEXINPUTPORT;
339 //Create the MVC Objects
343 (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
345 vtkGObjectView *view =
346 GObjectsMVCFactory::getInstance()->createGObjectView(type);
347 GObjectController* controller =
348 GObjectsMVCFactory::getInstance()->createGObjectController(type);
350 //Prepares the initial model
353 double yy = windowHeight - 5;
355 //z value is not important yet, because it is only used a parallel projection
357 printf("EED wxVtkSceneManager::createGComplexBoxInputPort 900-450\n");
359 _baseView->TransCoordScreenToWorld(xx, yy, zz);
360 model->setInicPoint(xx, yy, zz);
362 model->setBBTKName(inputName);
363 model->setBBTKType("ComplexInputPort");
364 model->setComplexPortType(type);
366 model->addObserver(view);
367 model->addObserver(this);
369 //create the output port
370 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
371 "ComplexInputPort", 0, model);
372 model->addOutputPort((GPortModel*) portController->getModel());
374 //Associates the view with the correspondent renderer and the model.
375 //(NOTE: Refresh is only made by the view)
376 view->setModel(model);
377 view->setBaseView(_baseView);
378 view->initVtkObjects();
380 //Associates the controller with the correspondent model and view
381 controller->setModelAndView(model, view);
383 //Resgiter change to the observers of the actual model
384 model->notifyObservers(_idManager);
386 int newId = addObjectController(controller);
390 //=========================================================================
392 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
393 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
394 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
396 int type = GCOMPLEXOUTPUTPORT;
398 //Create the MVC Objects
402 (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
404 vtkGObjectView *view =
405 GObjectsMVCFactory::getInstance()->createGObjectView(type);
406 GObjectController *controller =
407 GObjectsMVCFactory::getInstance()->createGObjectController(type);
409 //Prepares the initial model
412 double yy = windowHeight - 5;
414 //z value is not important yet, because it is only used a parallel projection
417 printf("EED wxVtkSceneManager::createGComplexBoxOutputPort 900-450\n");
419 _baseView->TransCoordScreenToWorld(xx, yy, zz);
420 model->setInicPoint(xx, yy, zz);
422 model->setBBTKName(outputName);
423 model->setBBTKType("ComplexOutputPort");
424 model->setComplexPortType(type);
426 model->addObserver(view);
427 model->addObserver(this);
429 //create the output port
430 GPortController* portController = createGPort(GINPUTPORT, outputName,
431 "ComplexInputPort", 0, model);
432 model->addInputPort((GPortModel*) portController->getModel());
434 //Associates the view with the correspondent renderer and the model.
435 //(NOTE: Refresh is only made by the view)
436 view->setModel(model);
437 view->setBaseView(_baseView);
438 view->initVtkObjects();
440 //Associates the controller with the correspondent model and view
441 controller->setModelAndView(model, view);
443 //Resgiter change to the observers of the actual model
444 model->notifyObservers(_idManager);
446 int newId = addObjectController(controller);
450 //=========================================================================
452 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,
453 GBoxModel *blackBox, BlackBoxInputDescriptor *desc) {
454 GPortController* portController = createGPort(portType, desc->GetName(),
455 desc->GetTypeName(), posinBox, blackBox);
456 blackBox->addInputPort((GPortModel*) portController->getModel());
457 return portController->getId();
460 //=========================================================================
462 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,
463 GBoxModel *blackBox, BlackBoxOutputDescriptor *desc) {
464 GPortController* portController = createGPort(portType, desc->GetName(),
465 desc->GetTypeName(), posinBox, blackBox);
466 blackBox->addOutputPort((GPortModel*) portController->getModel());
467 return portController->getId();
470 //=========================================================================
472 GPortController* wxVtkSceneManager::createGPort(int portType,
473 std::string bbtkName, std::string bbtkType, int posInBox,
474 GBoxModel *blackBox) {
477 //Create the MVC Objects
480 (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
482 vtkGObjectView *view =
483 GObjectsMVCFactory::getInstance()->createGObjectView(type);
484 GObjectController* controller =
485 GObjectsMVCFactory::getInstance()->createGObjectController(type);
487 model->registerInBox(blackBox, portType, posInBox);
489 model->setBBTKType(bbtkType);
490 model->setBBTKName(bbtkName);
492 model->addObserver(view);
493 model->addObserver(this);
495 //Associates the view with the correspondent renderer and the model.
496 //(NOTE: Refresh is only made by the view)
497 view->setModel(model);
498 view->setBaseView(_baseView);
499 view->initVtkObjects();
501 //Associates the controller with the correspondent model and view
502 controller->setModelAndView(model, view);
504 model->notifyObservers(_idManager);
506 addObjectController(controller);
508 return (GPortController*) controller;
511 //=========================================================================
513 int wxVtkSceneManager::createGConnector(GPortModel* startPort) {
514 int type = GCONNECTOR;
516 manualConnectorContourController* manContourControl =
517 new manualConnectorContourController();
518 manualConnectorContourView* manContourView =
519 new manualConnectorContourView();
520 manualContourModel* manContourModel = new manualContourModel();
522 GConnectorController* connectorcontroller = new GConnectorController();
523 GConnectorModel* connectorModel = new GConnectorModel();
524 vtkGConnectorView* connectorView = new vtkGConnectorView();
525 connectorModel->setGObjectType(type);
527 manContourModel->SetCloseContour(false);
528 connectorModel->setStartPort(startPort);
530 manContourView->SetModel(manContourModel);
531 manContourView->SetWxVtkBaseView(_baseView);
532 manContourView->SetRange(0.5);
533 manContourView->SetZ(900);
535 manContourView->SetColorNormalContour(0, 0, 1);
536 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
537 manContourView->SetColorSelectContour(1, 0.8, 0);
542 * Width increased from 2 to 5, it simplifies line handling and spline control :P
546 manContourView->SetWidthLine( 5 ) ;
549 manContourView->SetShowText(false);
551 manContourControl->SetModelView(manContourModel, manContourView);
553 manContourControl->CreateNewManualContour();
555 manContourView->RefreshContour();
558 connectorModel->getInicPoint(x, y, z);
560 manContourControl->SetState(1);
561 manContourModel->SetCloseContour(false);
563 manContourModel->AddPoint(x, y, z);
564 manContourView->AddPoint();
566 manContourModel->AddPoint(x, y, z);
567 manContourView->AddPoint();
569 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
570 manContourControl->_bakIdPoint = bak;
571 manContourView->Refresh();
573 manContourControl->SetMoving(false);
575 connectorcontroller->setModelAndView(connectorModel, connectorView);
577 int newId = addObjectController(connectorcontroller);
579 connectorcontroller->setManualContourController(manContourControl);
580 connectorModel->setManualContourModel(manContourModel);
581 connectorView->setManualContourView(manContourView);
582 connectorView->setModel(connectorModel);
583 connectorView->setBaseView(_baseView);
585 connectorModel->addObserver(connectorView);
586 connectorModel->addObserver(this);
591 //=========================================================================
593 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param) {
594 vtkInteractorStyleBaseView
595 * baseViewControlManager =
596 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
597 baseViewControlManager->AddInteractorStyleMaracas(param);
600 //=========================================================================
602 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param) {
603 vtkInteractorStyleBaseView
604 * baseViewControlManager =
605 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
606 baseViewControlManager->RemoveInteractorStyleMaracas(param);
609 //=========================================================================
611 vtkRenderer* wxVtkSceneManager::getRenderer() {
612 return _baseView->GetRenderer();
615 //=========================================================================
617 vtkRenderWindow* wxVtkSceneManager::getRenderWindow() {
618 return _baseView->GetRenWin();
620 //=========================================================================
623 //=========================================================================
624 int wxVtkSceneManager::GetIndexInSelected(int idControler) {
626 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
627 if (_selectedObjects[i] == idControler) {
634 //=========================================================================
636 void wxVtkSceneManager::update(int idController, int command) {
638 if (command != NO_COMMAND) {
639 if (command == ADD_TO_SELECTED) {
640 //EEDBorrame GObjectController* cont = _controllers[idController];
642 if (GetIndexInSelected(idController) == -1) {
643 _selectedObjects.push_back(idController);
647 // bool foundID=false;
648 // for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
650 // if(_selectedObjects[i]==idController)
657 // _selectedObjects.push_back(idController);
660 } else if (command == REMOVE_FROM_SELECTED) {
661 int index = GetIndexInSelected(idController);
663 _selectedObjects.erase(_selectedObjects.begin() + index);
665 } else if (command == INIT_CREATION_CONTOUR) {
669 typedef std::map<int , GObjectController*>::iterator TIterator ;
672 // Find current item in the controller
673 iter = _controllers.find( idController ) ;
674 iter_end = _controllers.end( ) ;
676 if ( iter != iter_end ) {
677 GObjectController* gobjc = iter->second ;
679 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
680 // And if the item is a port
681 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
682 TIterator c_it = _controllers.begin( ) ;
683 // Go through all componets
684 for ( c_it ; c_it != iter_end ; c_it++ ) {
685 GObjectController* obc = c_it->second ;
686 int obc_type = obc->getModel( )->getGObjectType( ) ;
687 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
688 // if the component is a port and the type is the same of that selected
689 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
691 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
692 //obc->getView( )->setState( HIGHLIGHTED ) ;
701 _worldState = INIT_CREATION_CONTOUR;
702 GObjectController* cont = _controllers[idController];
703 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
705 // The last one is the controller of the connector
706 std::map<int, GObjectController*>::iterator it2;
708 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
709 GObjectController *cont = it2->second;
710 if (cont->getGObjectType() == GPORT) {
711 GPortModel* port = (GPortModel*) cont->getModel();
712 if (port->getPortType() == GINPUTPORT) {
713 cont->SetActive(true);
715 cont->getView()->setState(NOTHING_HAPPENS);
716 cont->getModel()->notifyObservers(_idManager);
717 cont->SetActive(false);
720 cont->getView()->setState(NOTHING_HAPPENS);
721 cont->getModel()->notifyObservers(_idManager);
722 cont->SetActive(false);
725 _selectedObjects.clear();
726 _idConnectionInCreation = createGConnector(startOutputPort);
727 } else if (command == FIN_CREATION_CONTOUR && _worldState
728 == INIT_CREATION_CONTOUR) {
729 _worldState = NOTHING_HAPPENS;
730 //int id = _controllers.size()-1;
731 GObjectController *cont = _controllers[_idConnectionInCreation];
732 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
733 GObjectController *finPort = _controllers[idController];
735 if (finPort->getGObjectType() == GPORT) {
736 GPortModel* modelPort = (GPortModel*) finPort->getModel();
737 modelContour->setEndPort(modelPort);
741 typedef std::map<int , GObjectController*>::iterator TIterator ;
742 TIterator c_it = _controllers.begin( ) ;
743 TIterator iter_end = _controllers.end( ) ;
744 // Go through all componets
745 for ( c_it ; c_it != iter_end ; c_it++ ) {
746 GObjectController* obc = c_it->second ;
747 int obc_type = obc->getModel( )->getGObjectType( ) ;
748 int obc_state = obc->getView( )->getState( ) ;
749 // if the component is a port and the type is the same of that selected
750 if ( ( obc_type == GPORT ) && ( obc_state == POSSIBLE_CONNECTION )) {
751 // Return element to neutral state if not selected
752 obc->getView( )->setState( NOTHING_HAPPENS ) ;
754 if ( ( obc_type == GPORT ) && (obc_state == SELECTED_POSSIBLE_CONNECTION )) {
755 // Change element to connected state
756 obc->getView( )->setState( HIGHLIGHTED ) ;
763 _parent->saveTempDiagram();
766 manualConnectorContourController
768 ((GConnectorController*) cont)->getManualContourController();
769 manualConnectorContourView
771 (manualConnectorContourView*) manCont->GetManualViewBaseContour();
774 std::map<int, GObjectController*>::iterator it2;
776 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
777 GObjectController *cont = it2->second;
778 if (cont->getView() != NULL) {
779 cont->getView()->setState(NOTHING_HAPPENS);
780 cont->getModel()->notifyObservers(_idManager);
782 cont->SetActive(true);
790 //=========================================================================
792 bool wxVtkSceneManager::OnMouseMove() {
794 bool okStatusMessage = false;
795 bool okPortMessage = false;
796 wxVTKRenderWindowInteractor *wxVTKiren;
798 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
799 wxVTKiren->GetEventPosition(X, Y);
801 if (_worldState == DRAG_OBJECTS) {
802 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
803 int id = _selectedObjects[i];
804 GObjectController* cont = _controllers[id];
805 if (_startDragging) {
806 cont->getView()->setStartDragging(true);
808 cont->getView()->moveObject(X, Y);
809 cont->getView()->setState(DRAG);
810 cont->getModel()->notifyObservers(_idManager);
813 std::map<int, GObjectController*>::iterator it;
815 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
816 GObjectController *desc = it->second;
817 if (desc->getGObjectType() == GCONNECTOR) {
818 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
819 vconn->updateStartEndPoints();
823 _startDragging = false;
825 } else if (_worldState == NOTHING_HAPPENS || _worldState
826 == INIT_CREATION_CONTOUR) {
827 std::map<int, GObjectController*>::iterator it;
829 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
830 GObjectController *desc = it->second;
831 int type = desc->getGObjectType();
832 int state = desc->getView()->getState();
833 desc->getModel()->getCenter(px, py, pz);
835 if (state == HIGHLIGHTED) {
836 okStatusMessage = true;
837 updateStatusBar(desc->getStatusText());
838 if (type == GBLACKBOX) {
839 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
840 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),
845 okPortMessage = true;
847 _textActor->SetInput(desc->getStatusText().c_str());
848 _textActor->SetScale(0.1);
849 _textActor->SetPosition(px - 25, py + 1, pz + 2);
854 _fillObjectActor->SetScale(1);
855 _fillObjectActor->GetProperty()->SetOpacity(0.50);
856 _fillObjectActor->SetPosition(px, py, 1);
857 _aPolygonMapper->Modified();
860 } // for controllers it
863 if (okStatusMessage == false) {
867 if (okPortMessage == false) {
868 _textActor->SetScale(0.0001);
869 _fillObjectActor->SetScale(0.0001);
874 //=========================================================================
876 bool wxVtkSceneManager::OnLeftButtonDown() {
878 if (_worldState == INIT_CREATION_CONTOUR) {
879 bool isOverPort = false;
880 std::map<int, GObjectController*>::iterator it;
881 for (it = _controllers.begin(); it != _controllers.end() && isOverPort
883 GObjectController *desc = it->second;
884 if (desc->getGObjectType() == GPORT) {
885 GPortModel *portmod = (GPortModel*) desc->getModel();
886 vtkGObjectView *portView = desc->getView();
887 if (portmod->getPortType() == GINPUTPORT
888 && portView->getState() == HIGHLIGHTED) {
893 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
895 portView->setState( HIGHLIGHTED);
902 if (isOverPort == false) {
904 UnSelectBlackBoxes();
908 } else { //_worldState
910 _worldState = DRAG_OBJECTS;
911 _startDragging = true;
914 _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
916 _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
917 ctrlkey = ctrlkey + shiftkey;
919 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
921 if (GetGBlackBoxControlerPointedByMouse() != NULL) {
922 int state = cont->getView()->getState();
923 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
924 UnSelectBlackBoxes();
927 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
928 int id = _selectedObjects[i];
929 GObjectController* cont = _controllers[id];
930 cont->getView()->setState(DRAG);
931 cont->getModel()->notifyObservers(_idManager);
934 } // if _selectedObjects.size
940 //=========================================================================
942 bool wxVtkSceneManager::OnLeftButtonUp() {
943 if (_worldState == DRAG_OBJECTS) {
944 _worldState = NOTHING_HAPPENS;
946 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
947 int id = _selectedObjects[i];
948 GObjectController* cont = _controllers[id];
949 cont->getView()->setState(SELECTED);
950 cont->getModel()->notifyObservers(_idManager);
956 //=========================================================================
957 void wxVtkSceneManager::CancelConnection() {
958 if (_worldState == INIT_CREATION_CONTOUR) {
959 _worldState = NOTHING_HAPPENS;
960 //int lastId = _controllers.size()-1;
962 GConnectorController *connector =
963 (GConnectorController*) _controllers[_idConnectionInCreation];
964 connector->removeFromScene();
965 unregisterController(connector);
966 _controllers.erase(_idConnectionInCreation);
968 std::map<int, GObjectController*>::iterator it;
969 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
970 GObjectController *desc = it->second;
971 desc->SetActive(true);
972 desc->getView()->setState(NOTHING_HAPPENS);
973 desc->getModel()->notifyObservers(_idManager);
978 //=========================================================================
980 bool wxVtkSceneManager::OnRightButtonUp() {
981 if (_worldState == INIT_CREATION_CONTOUR) {
984 UnSelectBlackBoxes();
990 bool wxVtkSceneManager::OnMiddleButtonDown() {
993 this->_vtkInteractorStyleBaseView->StartPan();
998 bool wxVtkSceneManager::OnMiddleButtonUp() {
1001 this->_vtkInteractorStyleBaseView->EndPan();
1008 //=========================================================================
1010 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1011 GObjectController *result = NULL;
1013 wxVTKRenderWindowInteractor *wxVTKiren;
1015 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1016 wxVTKiren->GetEventPosition(X, Y);
1018 std::map<int, GObjectController*>::iterator it;
1020 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1021 GObjectController *cont = it->second;
1022 int type = cont->getGObjectType();
1024 if (cont->getView()->isPointInside(X, Y) == true) {
1025 if (type == GBLACKBOX) {
1028 } // if isPointInside
1033 //=========================================================================
1034 void wxVtkSceneManager::UnSelectBlackBoxes() {
1035 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1036 int id = _selectedObjects[i];
1037 GObjectController* control = _controllers[id];
1038 control->getView()->setState(NOTHING_HAPPENS);
1039 }// for _selectedObjects
1040 _selectedObjects.clear();
1043 //=========================================================================
1044 bool wxVtkSceneManager::OnLeftDClick() {
1045 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1047 UnSelectBlackBoxes();
1048 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1054 wxVTKRenderWindowInteractor *wxVTKiren;
1055 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1056 wxVTKiren->GetEventPosition(X,Y);
1058 std::map<int, GObjectController*>::iterator it;
1060 bool clickOnObject = false;
1062 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1064 GObjectController *cont = it->second;
1065 int type = cont->getGObjectType();
1067 if(cont->getView()->isPointInside(X,Y))
1071 for (int i=0; i< (int)_selectedObjects.size(); i++)
1073 int id = _selectedObjects[i];
1074 GObjectController* control = _controllers[id];
1075 control->getView()->setState(NOTHING_HAPPENS);
1077 _selectedObjects.clear();
1079 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1080 _parent->editBlackBox(bbmodel);
1082 clickOnObject = true;
1086 if(clickOnObject==false)
1088 //_parent->editDiagramParameters(this);
1094 //=========================================================================
1096 bool wxVtkSceneManager::OnChar() {
1097 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1098 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1100 // KeyCode 127 : Delete Key
1101 // KeyCode 8 : Backspace Key
1102 if (keyCode == 8 || keyCode == 127) {
1103 if (_selectedObjects.size() > 0) {
1104 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1105 int id = _selectedObjects[i];
1106 std::map<int, GObjectController*>::iterator it;
1107 it = _controllers.find(id);
1108 if (it != _controllers.end()) {
1112 _selectedObjects.clear();
1118 if(_selectedObjects.size()){
1119 std::cout<<"objects to copy :";
1120 for(int i=0;i<_selectedObjects.size();i++){
1121 std::cout<<_selectedObjects.at(i)<<" ";
1123 DuplicateObjects(getSelectedObjects());
1125 std::cout<<"No objects to copy\n";
1132 //=========================================================================
1134 void wxVtkSceneManager::AddControlerToBeRemove(
1135 std::vector<int> *controllersToRemove, int id) {
1139 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1140 if (id == (*controllersToRemove)[i]) {
1146 controllersToRemove->push_back(id);
1151 //=========================================================================
1153 void wxVtkSceneManager::deleteObject(int id) {
1154 GObjectController *control = _controllers[id];
1155 std::vector<int> controllersToRemove;
1157 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1158 == GCOMPLEXINPUTPORT || control->getGObjectType()
1159 == GCOMPLEXOUTPUTPORT) {
1160 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1161 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1163 bool boxConnected = false;
1165 // Add box input controllers to be removed
1166 for (int i = 0; i < (int) inputs.size(); i++) {
1167 AddControlerToBeRemove(&controllersToRemove,
1168 inputs[i]->getObjectId());
1169 if (inputs[i]->isConnected()) {
1170 boxConnected = true;
1174 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1176 // Add box output controllers to be removed
1177 for (int i = 0; i < (int) outputs.size(); i++) {
1178 AddControlerToBeRemove(&controllersToRemove,
1179 outputs[i]->getObjectId());
1180 if (outputs[i]->isConnected()) {
1181 boxConnected = true;
1185 // Add connection controllers to be removed
1186 std::map<int, GObjectController*>::iterator it;
1187 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1188 GObjectController *cont = it->second;
1189 int type = cont->getGObjectType();
1190 if (type == GCONNECTOR) {
1191 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1192 if (conMod->getStartPort() != NULL
1193 && conMod->getStartPort()->getParentBox()->getObjectId()
1194 == bbmod->getObjectId()) {
1195 AddControlerToBeRemove(&controllersToRemove,
1196 conMod->getObjectId());
1198 if (conMod->getEndPort() != NULL
1199 && conMod->getEndPort()->getParentBox()->getObjectId()
1200 == bbmod->getObjectId()) {
1201 AddControlerToBeRemove(&controllersToRemove,
1202 conMod->getObjectId());
1207 // Add box controller to be removed
1208 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1209 } else if (control->getGObjectType() == GCONNECTOR) {
1210 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1211 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1214 std::map<int, GObjectController*>::iterator it;
1216 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1217 int key = controllersToRemove[i];
1218 it = _controllers.find(key);
1219 GObjectController *cont = _controllers[key];
1221 cont->removeFromScene();
1222 unregisterController((InteractorStyleMaracas*) cont);
1223 _controllers.erase(it);
1226 _parent->saveTempDiagram();
1229 //=========================================================================
1231 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1232 std::string boxName) {
1233 _parent->displayBlackBoxInfo(packageName, boxName);
1236 //=========================================================================
1238 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1239 _parent->updateStatusBar(textStatus);
1242 //=========================================================================
1243 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1244 std::string result = "";
1245 if (withLineNumber == true) {
1247 stringstream StrStream;
1249 std::string strValue = StrStream.str();
1252 } else if (value < 100) {
1256 result += strValue + ": ";
1260 //=========================================================================
1262 bool wxVtkSceneManager::MakeBoxExecutable() {
1263 std::map<int, GObjectController*> selected = getSelectedObjects();
1264 if( selected.empty() )
1267 std::map<int, GObjectController*>::iterator it;
1268 for (it = selected.begin(); it != selected.end(); ++it) {
1269 GObjectController* lastSelected = it->second;
1271 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1272 GBlackBoxModel *bbmodel =
1273 (GBlackBoxModel*) lastSelected->getModel();
1274 view->setState(HIGHLIGHTED);
1275 if (bbmodel->isExecutable()) {
1276 bbmodel->setExecutable(false);
1278 bbmodel->setExecutable(true);
1280 bbmodel->notifyObservers(lastSelected->getId());
1288 //=========================================================================
1290 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1291 bool existsExec = false;
1293 std::vector<std::string> packages;
1294 std::vector<int> boxes;
1295 std::vector<int> connections;
1296 std::vector<int> execBoxes;
1298 std::map<int, GObjectController*>::iterator it;
1300 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1301 GObjectController *desc = it->second;
1302 int type = desc->getGObjectType();
1304 if (type == GBLACKBOX) {
1305 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1307 std::string pkg = mod->getBBTKPackage();
1308 bool existsPkg = false;
1309 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1310 if (packages[t] == pkg) {
1315 packages.push_back(pkg);
1318 boxes.push_back(it->first);
1319 if (mod->isExecutable()) {
1320 execBoxes.push_back(it->first);
1323 } else if (type == GCONNECTOR) {
1324 connections.push_back(it->first);
1329 std::string script = "";
1330 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1331 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1332 script += LineNumber(wln, lnNmbr) + "\n";
1334 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1335 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1337 for (i = 0; i < (int) packages.size(); i++) {
1338 script += LineNumber(wln, lnNmbr);
1339 script += "include ";
1340 script += packages[i];
1344 script += LineNumber(wln, lnNmbr);
1349 script += LineNumber(wln, lnNmbr);
1350 script += "author \"";
1354 script += LineNumber(wln, lnNmbr);
1355 script += "description \"";
1356 script += _Description;
1359 script += LineNumber(wln, lnNmbr);
1360 script += "category \"";
1361 script += _Category;
1364 script += LineNumber(wln, lnNmbr);
1367 // script+="include std\n"; // JPR
1369 for (i = 0; i < (int) boxes.size(); i++) {
1370 script += LineNumber(wln, lnNmbr);
1373 GObjectController *control = _controllers[id];
1374 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1376 script += model->getBBTKType();
1378 script += model->getBBTKName();
1381 std::vector<GPortModel*> inputs = model->getInputPorts();
1382 for (int j = 0; j < (int) inputs.size(); j++) {
1383 GPortModel* inputPort = inputs[j];
1384 if (inputPort->isValueSet()) {
1385 script += LineNumber(wln, lnNmbr);
1387 script += model->getBBTKName();
1389 script += inputPort->getBBTKName();
1391 script += inputPort->getValue();
1396 script += LineNumber(wln, lnNmbr);
1401 script += LineNumber(wln, lnNmbr);
1404 for (i = 0; i < (int) connections.size(); i++) {
1405 script += LineNumber(wln, lnNmbr);
1406 script += "connect ";
1407 int id = connections[i];
1408 GObjectController *control = _controllers[id];
1409 GConnectorModel *model = (GConnectorModel*) control->getModel();
1411 //Start Connection info
1412 GPortModel *start = model->getStartPort();
1413 script += start->getParentBox()->getBBTKName();
1415 script += start->getBBTKName();
1419 //End Connection info
1420 GPortModel *end = model->getEndPort();
1421 script += end->getParentBox()->getBBTKName();
1423 script += end->getBBTKName();
1428 script += LineNumber(wln, lnNmbr);
1430 for (i = 0; i < (int) execBoxes.size(); i++) {
1431 script += LineNumber(wln, lnNmbr);
1433 int id = execBoxes[i];
1434 GObjectController *control = _controllers[id];
1435 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1437 script += model->getBBTKName();
1446 //=========================================================================
1448 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1449 std::vector<std::string> packages;
1450 std::vector<int> boxes;
1451 std::vector<int> connections;
1452 std::vector<int> execBoxes;
1454 std::map<int, GObjectController*>::iterator it;
1456 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1457 GObjectController *desc = it->second;
1458 int type = desc->getGObjectType();
1460 if (type == GBLACKBOX) {
1461 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1463 std::string pkg = mod->getBBTKPackage();
1464 bool existsPkg = false;
1465 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1466 if (packages[t] == pkg) {
1471 packages.push_back(pkg);
1474 boxes.push_back(it->first);
1475 if (mod->isExecutable()) {
1476 execBoxes.push_back(it->first);
1478 } else if (type == GCONNECTOR) {
1479 connections.push_back(it->first);
1483 std::string script = "";
1485 script += "include std\n"; // EED
1486 script += "include itkvtk\n"; // EED
1488 for (i = 0; i < (int) packages.size(); i++) {
1489 script += "include ";
1490 script += packages[i];
1495 // Definition of a complex box
1496 script += "define ";
1497 script += _cbName + " " + _cbPackageName;
1501 script += "author \"";
1505 script += "description \"";
1506 script += _Description;
1510 script += "category \"";
1511 script += _Category;
1516 for (i = 0; i < (int) boxes.size(); i++) {
1519 GObjectController *control = _controllers[id];
1520 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1522 script += model->getBBTKType();
1524 script += model->getBBTKName();
1527 std::vector<GPortModel*> inputs = model->getInputPorts();
1528 for (int j = 0; j < (int) inputs.size(); j++) {
1529 GPortModel* inputPort = inputs[j];
1530 if (inputPort->isValueSet()) {
1532 script += model->getBBTKName();
1534 script += inputPort->getBBTKName();
1536 script += inputPort->getValue();
1544 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1546 std::string complexInputs = "";
1547 std::string complexOutputs = "";
1550 for (i = 0; i < (int) connections.size(); i++) {
1551 int id = connections[i];
1552 GObjectController *control = _controllers[id];
1553 GConnectorModel *model = (GConnectorModel*) control->getModel();
1556 GPortModel *start = model->getStartPort();
1557 GBoxModel *startBox = start->getParentBox();
1559 GPortModel *end = model->getEndPort();
1560 GBoxModel *endBox = end->getParentBox();
1562 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1563 complexInputs += "input ";
1564 complexInputs += startBox->getBBTKName();
1566 complexInputs += " ";
1567 complexInputs += endBox->getBBTKName();
1568 complexInputs += ".";
1569 complexInputs += end->getBBTKName();
1571 complexInputs += " ";
1572 complexInputs += "\" \"";
1574 complexInputs += "\n";
1575 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1576 complexOutputs += "output ";
1577 complexOutputs += endBox->getBBTKName();
1579 complexOutputs += " ";
1580 complexOutputs += startBox->getBBTKName();
1581 complexOutputs += ".";
1582 complexOutputs += start->getBBTKName();
1584 complexOutputs += " ";
1585 complexOutputs += "\" \"";
1587 complexOutputs += "\n";
1589 script += "connect ";
1590 script += startBox->getBBTKName();
1592 script += start->getBBTKName();
1596 //End Connection info
1597 script += endBox->getBBTKName();
1599 script += end->getBBTKName();
1607 for (i = 0; i < (int) execBoxes.size(); i++) {
1609 int id = execBoxes[i];
1610 GObjectController *control = _controllers[id];
1611 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1613 script += model->getBBTKName();
1618 script += "# Complex input ports\n";
1619 script += complexInputs;
1622 script += "# Complex output ports\n";
1623 script += complexOutputs;
1626 script += "endefine";
1632 //=========================================================================
1634 void wxVtkSceneManager::deleteAllBoxes() {
1635 std::map<int, GObjectController*>::iterator it;
1636 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1637 GObjectController *cont = it->second;
1638 cont->removeFromScene();
1639 unregisterController((InteractorStyleMaracas*) cont);
1641 _selectedObjects.clear();
1642 _controllers.clear();
1646 //=========================================================================
1649 void wxVtkSceneManager::refresh() {
1650 _baseView->Refresh();
1652 //=========================================================================
1654 void wxVtkSceneManager::refreshScene() {
1655 _baseView->RefreshView();
1658 //=========================================================================
1660 void wxVtkSceneManager::centerView() {
1662 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1663 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1664 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1665 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1666 _baseView->RefreshView();
1670 //=========================================================================
1672 void wxVtkSceneManager::saveDiagram(std::string &content) {
1675 content += "CATEGORY:";
1676 content += GetCategory();
1679 content += "DESCRIPTION:";
1680 content += GetDescription();
1683 content += "AUTHOR:";
1684 content += GetAuthor();
1687 //Print info IF COMPLEX BOX
1688 content += "COMPLEXBOX:";
1689 if (_isComplexBox) {
1690 content += "TRUE\n";
1692 content += "COMPLEXBOXNAME:";
1693 content += GetCbName();
1696 content += "PACKAGENAME:";
1697 content += GetCbPackageName();
1700 //Print info complex input ports
1701 std::vector<int> inputs = getComplexInputPorts();
1702 int insize = inputs.size();
1703 content += "COMPLEXINPUTS:";
1704 sprintf(buffer, "%d", insize);
1708 for (int i = 0; i < insize; i++) {
1710 GObjectController *cont = _controllers[id];
1711 cont->getModel()->save(content);
1714 //Print info complex output ports
1715 std::vector<int> outputs = getComplexOutputPorts();
1716 int outsize = outputs.size();
1717 content += "COMPLEXOUTPUTS:";
1718 sprintf(buffer, "%d", outsize);
1722 for (int i = 0; i < outsize; i++) {
1723 int id = outputs[i];
1724 GObjectController *cont = _controllers[id];
1725 cont->getModel()->save(content);
1729 content += "FALSE\n";
1733 std::vector<int> boxes = getBlackBoxes();
1734 int bsize = boxes.size();
1735 content += "BOXES:";
1736 sprintf(buffer, "%d", bsize);
1740 for (int i = 0; i < bsize; i++) {
1742 GObjectController *cont = _controllers[id];
1743 cont->getModel()->save(content);
1747 std::vector<int> connections = getConnections();
1748 int csize = connections.size();
1749 content += "CONNECTIONS:";
1750 sprintf(buffer, "%d", csize);
1754 for (int i = 0; i < csize; i++) {
1755 int id = connections[i];
1756 GObjectController *cont = _controllers[id];
1757 cont->getModel()->save(content);
1762 //=========================================================================
1764 void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
1766 std::string version = "<void>";
1767 std::string line = "";
1768 char delims[] = ":";
1769 char *result = NULL;
1771 getline(inputStream, line);
1774 while (!inputStream.eof()) {
1775 if (line == "" || line[0] == '#') {
1776 getline(inputStream, line);
1777 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1778 version = line.substr(18, 3);
1780 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1781 version = line.substr(18, 3);
1783 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1784 version = line.substr(18, 3);
1786 } else if (line == "APP_START") {
1792 printf("EED wxVtkSceneManager::loadDiagram version=%s\n", version.c_str());
1796 if ((version != "1.0") && (version != "1.1")) {
1797 getline(inputStream, line);//CATEGORY:<category of the box>
1798 char categoryTmp[30];
1799 strcpy(categoryTmp, line.c_str());
1800 result = strtok(categoryTmp, delims);
1801 result = strtok(NULL, delims);
1802 SetCategory(result);
1804 getline(inputStream, line);//DESCRIPTION:<description of the box>
1805 char descriptionTmp[1024];
1806 strcpy(descriptionTmp, line.c_str());
1807 result = strtok(descriptionTmp, delims);
1808 result = strtok(NULL, delims);
1809 SetDescription(result);
1811 getline(inputStream, line);//AUTHOR:<author>
1812 char authorTmp[255];
1813 strcpy(authorTmp, line.c_str());
1814 result = strtok(authorTmp, delims);
1815 result = strtok(NULL, delims);
1820 getline(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1821 char complexTmp[30];
1822 strcpy(complexTmp, line.c_str());
1823 result = strtok(complexTmp, delims);
1824 result = strtok(NULL, delims);
1825 std::string isComplexBox(result);
1827 if (isComplexBox == "TRUE") {
1828 _isComplexBox = true;
1830 if ((version != "1.0") && (version != "1.1")) {
1831 getline(inputStream, line);//COMPLEXNAME:<name of the complex box>
1832 char complexboxnameTmp[255];
1833 strcpy(complexboxnameTmp, line.c_str());
1834 result = strtok(complexboxnameTmp, delims);
1835 result = strtok(NULL, delims);
1838 getline(inputStream, line);//PACKAGENAME:<name of the package of the box>
1839 char packagenameTmp[255];
1840 strcpy(packagenameTmp, line.c_str());
1841 result = strtok(packagenameTmp, delims);
1842 result = strtok(NULL, delims);
1843 SetCbPackageName(result);
1846 //-----------------------
1847 //- COMPLEX INPUT PORTS
1848 //-----------------------
1849 getline(inputStream, line);//COMPLEXINPUTS:num
1851 strcpy(inputs, line.c_str());
1852 result = strtok(inputs, delims);
1853 result = strtok(NULL, delims);
1856 std::istringstream inps(result);
1859 for (int i = 0; i < numInputs; i++) {
1861 getline(inputStream, line);//COMPLEX_PORT
1862 getline(inputStream, line);//name
1863 std::string inputPortName(line);
1866 getline(inputStream, line);//xInic:yInic:zInic
1868 strcpy(coord, line.c_str());
1869 result = strtok(coord, delims);//xInic
1870 std::string xInic(result);
1871 result = strtok(NULL, delims);//yInic
1872 std::string yInic(result);
1873 result = strtok(NULL, delims);//zInic
1874 std::string zInic(result);
1876 double xIn, yIn, zIn;
1877 std::istringstream xSt(xInic);
1879 std::istringstream ySt(yInic);
1881 std::istringstream zSt(zInic);
1884 getline(inputStream, line);//FIN_COMPLEX_PORT
1886 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
1888 } // for input complex box
1891 //-----------------------
1892 //- COMPLEX OUTPUT PORTS
1893 //-----------------------
1895 getline(inputStream, line);//COMPLEXOUTPUTS:num
1897 strcpy(outputs, line.c_str());
1898 result = strtok(outputs, delims);
1899 result = strtok(NULL, delims);
1902 std::istringstream outps(result);
1903 outps >> numOutputs;
1905 for (int i = 0; i < numOutputs; i++) {
1907 getline(inputStream, line);//COMPLEX_PORT
1908 getline(inputStream, line);//name
1909 std::string outputPortName(line);
1912 getline(inputStream, line);//xInic:yInic:zInic
1914 strcpy(coord, line.c_str());
1915 result = strtok(coord, delims);//xInic
1916 std::string xInic(result);
1917 result = strtok(NULL, delims);//yInic
1918 std::string yInic(result);
1919 result = strtok(NULL, delims);//zInic
1920 std::string zInic(result);
1922 double xIn, yIn, zIn;
1923 std::istringstream xSt(xInic);
1925 std::istringstream ySt(yInic);
1927 std::istringstream zSt(zInic);
1930 getline(inputStream, line);//FIN_COMPLEX_PORT
1932 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn,
1935 } // for output complex box
1940 getline(inputStream, line);//BOXES:num
1942 strcpy(boxes, line.c_str());
1943 result = strtok(boxes, delims);
1944 result = strtok(NULL, delims);
1947 std::istringstream is(result);
1950 for (int i = 0; i < numBoxes; i++) {
1952 getline(inputStream, line);//BOX
1953 getline(inputStream, line);//package:type:name
1955 strcpy(box, line.c_str());
1956 result = strtok(box, delims);//package
1957 std::string package(result);
1958 result = strtok(NULL, delims);//type
1959 std::string type(result);
1960 result = strtok(NULL, delims);//name
1961 std::string name(result);
1963 getline(inputStream, line);//ISEXEC:TRUE|FALSE
1965 strcpy(exec, line.c_str());
1966 result = strtok(exec, delims);//ISEXEC
1967 result = strtok(NULL, delims);//TRUE|FALSE
1968 std::string isExec(result);
1971 getline(inputStream, line);//xInic:yInic:zInic
1973 strcpy(coord, line.c_str());
1974 result = strtok(coord, delims);//xInic
1975 std::string xInic(result);
1976 result = strtok(NULL, delims);//yInic
1977 std::string yInic(result);
1978 result = strtok(NULL, delims);//zInic
1979 std::string zInic(result);
1981 double xIn, yIn, zIn;
1982 std::istringstream xSt(xInic);
1984 std::istringstream ySt(yInic);
1986 std::istringstream zSt(zInic);
1990 getline(inputStream, line);//xEnd:yEnd:zEnd
1991 strcpy(coord, line.c_str());
1992 result = strtok(coord, delims);//xEnd
1993 std::string xEnd(result);
1994 result = strtok(NULL, delims);//yEnd
1995 std::string yEnd(result);
1996 result = strtok(NULL, delims);//zEnd
1997 std::string zEnd(result);
1999 double xEn, yEn, zEn;
2000 std::istringstream xEt(xEnd);
2002 std::istringstream yEt(yEnd);
2004 std::istringstream zEt(zEnd);
2007 bool boxExecutable = false;
2008 if (isExec == "TRUE") {
2009 boxExecutable = true;
2012 int idBox = createGBlackBox(xIn, yIn, package, type);
2013 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn,
2016 GObjectController *cont = _controllers[idBox];
2017 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2020 getline(inputStream, line);//PORT o FIN_BOX
2021 std::string port = line.substr(0, 4);
2022 while (port == "PORT") {
2023 getline(inputStream, line);//name:value
2025 strcpy(poort, line.c_str());
2026 result = strtok(poort, delims);//name
2027 std::string name(result);
2028 result = strtok(NULL, delims);//value
2029 std::string value(result);
2031 bbmod->setValueToInput(name, value);
2032 getline(inputStream, line);//PORT o FIN_BOX
2033 port = line.substr(0, 4);
2036 //EED bbmod->notifyObservers(_idManager);
2041 getline(inputStream, line);//CONNECTIONS:num
2043 strcpy(conns, line.c_str());
2044 result = strtok(conns, delims);
2045 result = strtok(NULL, delims);
2048 std::istringstream isCons(result);
2051 for (int i = 0; i < numConns; i++) {
2053 getline(inputStream, line);//CONNECTION
2054 getline(inputStream, line);//Startbox.PortName:EndBox.PortName
2057 strcpy(connec, line.c_str());
2058 result = strtok(connec, delims);
2059 std::string nameStartBox(result);
2060 result = strtok(NULL, delims);
2061 std::string nameStartPort(result);
2062 result = strtok(NULL, delims);
2063 std::string nameEndBox(result);
2064 result = strtok(NULL, delims);
2065 std::string nameEndPort(result);
2067 int idCon = configGConnetion(nameStartBox, nameStartPort,
2068 nameEndBox, nameEndPort);
2070 if (version != "1.0") {
2071 //Readding control points of the manualContour
2073 GConnectorController *tempp =
2074 (GConnectorController*) _controllers[idCon];
2075 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2076 vtkGConnectorView *conView =
2077 (vtkGConnectorView*) tempp->getView();
2078 getline(inputStream, line); //NumberOfControlPoints:##
2079 strcpy(conns, line.c_str());
2080 result = strtok(conns, delims);
2081 result = strtok(NULL, delims);
2083 int numberOfControlPoints;
2084 std::istringstream isCons(result);
2085 isCons >> numberOfControlPoints;
2087 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2088 getline(inputStream, line); //XX:YY:ZZ
2090 strcpy(connec, line.c_str());
2093 result = strtok(connec, delims);
2094 std::istringstream isPointX(result);
2096 result = strtok(NULL, delims);
2097 std::istringstream isPointY(result);
2099 result = strtok(NULL, delims);
2100 std::istringstream isPointZ(result);
2103 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px,
2105 conView->getManualContourView()->AddPoint();
2115 //=========================================================================
2118 //=========================================================================
2119 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2120 std::string portName, double xIn, double yIn, double zIn) {
2122 if (inputoutput == true) {
2123 idPort = createGComplexBoxInputPort(portName);
2125 idPort = createGComplexBoxOutputPort(portName);
2127 GObjectController *cont = _controllers[idPort];
2128 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2129 cbmod->setInicPoint(xIn, yIn, zIn);
2130 cbmod->notifyObservers(_idManager);
2132 //=========================================================================
2135 //=========================================================================
2136 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
2140 GBoxModel *boxModel = NULL;
2141 std::vector<int> lstB = getBlackBoxes();
2142 for (j = 0; j < (int) lstB.size(); j++) {
2144 bMod = (GBoxModel*) _controllers[idB]->getModel();
2145 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2150 if ((_isComplexBox) && (boxModel == NULL)) {
2151 std::vector<int> lstInputs = getComplexInputPorts();
2152 for (j = 0; j < (int) lstInputs.size(); j++) {
2154 bMod = (GBoxModel*) _controllers[idB]->getModel();
2155 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2160 std::vector<int> lstOutputs = getComplexOutputPorts();
2161 for (j = 0; j < (int) lstOutputs.size(); j++) {
2162 int idB = lstOutputs[j];
2163 bMod = (GBoxModel*) _controllers[idB]->getModel();
2164 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2174 //=========================================================================
2177 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2178 std::string nameStartPort, std::string nameEndBox,
2179 std::string nameEndPort) {
2181 GBoxModel *boxModel;
2182 GPortModel *startP = NULL;
2183 GPortModel *endP = NULL;
2185 boxModel = findGBox(nameStartBox);
2186 if (boxModel != NULL) {
2187 startP = boxModel->getOutputPort(nameStartPort);
2190 boxModel = findGBox(nameEndBox);
2191 if (boxModel != NULL) {
2192 endP = boxModel->getInputPort(nameEndPort);
2196 int idCon = createGConnector(startP);
2197 _worldState = NOTHING_HAPPENS;
2198 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2200 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2201 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2202 tempp->endContourCreation();
2203 conMod->setEndPort(endP);
2204 conView->updateStartEndPoints();
2208 //=========================================================================
2210 bool wxVtkSceneManager::boxExist(std::string boxname) {
2212 std::map<int, GObjectController*>::iterator it;
2213 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2214 GObjectController *cont = it->second;
2215 if (cont->getModel()->getBBTKName() == boxname) {
2222 //=========================================================================
2224 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2225 std::vector<int> vect;
2226 std::map<int, GObjectController*>::iterator it;
2227 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2228 GObjectController *cont = it->second;
2229 if (cont->getGObjectType() == GBLACKBOX) {
2230 vect.push_back(cont->getId());
2236 //=========================================================================
2238 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2239 std::vector<int> vect;
2240 std::map<int, GObjectController*>::iterator it;
2241 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2242 GObjectController *cont = it->second;
2243 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2244 vect.push_back(cont->getId());
2250 //=========================================================================
2252 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2253 std::vector<int> vect;
2254 std::map<int, GObjectController*>::iterator it;
2255 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2256 GObjectController *cont = it->second;
2257 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2258 vect.push_back(cont->getId());
2264 //=========================================================================
2266 std::vector<int> wxVtkSceneManager::getConnections() {
2267 std::vector<int> vect;
2268 std::map<int, GObjectController*>::iterator it;
2269 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2270 GObjectController *cont = it->second;
2271 if (cont->getGObjectType() == GCONNECTOR) {
2272 vect.push_back(cont->getId());
2278 //=========================================================================
2280 bool wxVtkSceneManager::isComplexBox() {
2281 return _isComplexBox;
2284 //=========================================================================
2286 void wxVtkSceneManager::setComplexBox(bool val) {
2287 _isComplexBox = val;
2290 //=========================================================================
2292 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2293 //Register the controller of the new object
2294 registerController((InteractorStyleMaracas*) objController);
2295 //Add the object to the objects list
2296 int newId = _contLastId;//_controllers.size();
2297 objController->setId(newId);
2298 _controllers[newId] = objController;
2300 << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = "
2301 << _contLastId << std::endl;
2306 //=========================================================================
2308 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2310 std::map<int, int> oldIdNewIdBoxes;
2311 std::vector<int> connections;
2313 std::vector<int> newBoxesID;
2315 std::map<int, GObjectController*>::iterator it;
2316 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2317 GObjectController *cont = it->second;
2318 int type = cont->getGObjectType();
2320 if (type == GBLACKBOX) {
2322 double xInic, yInic, zInic;
2323 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2324 copyBox->getInicPoint(xInic, yInic, zInic);
2325 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2326 copyBox->getBBTKType());
2328 int idcB = copyBox->getObjectId();
2329 oldIdNewIdBoxes[idcB] = idBox;
2330 cont = _controllers[idBox];
2331 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2332 newbox->setInicPoint(xInic, yInic, zInic);
2333 int num = newbox->getNumInputPorts();
2334 for (int j = 0; j < num; j++) {
2335 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2337 newbox->move(xInic + 20, yInic + 20, zInic);
2338 newbox->notifyObservers(_idManager);
2339 newBoxesID.push_back(newbox->getObjectId());
2341 } else if (type == GCONNECTOR) {
2342 int idCon = cont->getId();
2343 connections.push_back(idCon);
2348 for (int i = 0; i < (int) connections.size(); i++) {
2349 int objId = connections[i];
2350 GObjectController *cont = objectsMap[objId];
2351 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2353 GPortModel* startPort = connectModel->getStartPort();
2354 int startPortIndex = startPort->getPosInBox();
2355 GPortModel* endPort = connectModel->getEndPort();
2356 int endPortIndex = endPort->getPosInBox();
2358 GBlackBoxModel* startPortParentBox =
2359 (GBlackBoxModel*) startPort->getParentBox();
2360 GBlackBoxModel* endPortParentBox =
2361 (GBlackBoxModel*) endPort->getParentBox();
2363 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2364 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2366 GBlackBoxModel* newStartBox =
2367 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2368 GBlackBoxModel* newEndBox =
2369 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2371 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2372 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2374 // Creates connection
2375 int idCon = createGConnector(newStartPort);
2376 GConnectorController *tempp =
2377 (GConnectorController*) _controllers[idCon];
2378 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2379 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2380 tempp->endContourCreation();
2381 conMod->setEndPort(newEndPort);
2382 conView->updateStartEndPoints();
2385 /// the new selected boxes are the duplicate ones
2387 UnSelectBlackBoxes();
2388 for (int i = 0; i < newBoxesID.size(); i++) {
2389 _selectedObjects.push_back(newBoxesID.at(i));
2392 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2393 int id = _selectedObjects[i];
2394 GObjectController* cont = _controllers[id];
2396 cont->getView()->setState(SELECTED);
2397 cont->getModel()->notifyObservers(_idManager);
2404 //=========================================================================
2406 int wxVtkSceneManager::getNumSelectedObjects() {
2407 return _selectedObjects.size();
2410 //=========================================================================
2412 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2413 std::map<int, GObjectController*> mapSelected;
2415 std::map<int, GObjectController*>::iterator it;
2416 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2417 GObjectController *cont = it->second;
2418 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2420 mapSelected[cont->getId()] = cont;
2424 std::map<int, GObjectController*>::iterator it2;
2425 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2426 GObjectController *cont = it2->second;
2427 if (cont->getGObjectType() == GCONNECTOR) {
2428 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2429 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2430 GBoxModel* startPortParentBox =
2431 cmod->getStartPort()->getParentBox();
2433 std::map<int, GObjectController*>::iterator iterOBJ1 =
2434 mapSelected.find(startPortParentBox->getObjectId());
2435 std::map<int, GObjectController*>::iterator iterOBJ2 =
2436 mapSelected.find(endPortParentBox->getObjectId());
2438 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2439 int ID = cont->getId();
2440 mapSelected[ID] = cont;
2447 //=========================================================================
2449 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2451 std::map<int, int> oldIdNewIdBoxes;
2452 std::vector<int> connections;
2454 std::map<int, GObjectController*>::iterator it;
2455 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2456 GObjectController *cont = it->second;
2457 int type = cont->getGObjectType();
2459 if (type == GBLACKBOX) {
2461 double xInic, yInic, zInic;
2462 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2463 copyBox->getInicPoint(xInic, yInic, zInic);
2464 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2465 copyBox->getBBTKType());
2467 int idcB = copyBox->getObjectId();
2468 oldIdNewIdBoxes[idcB] = idBox;
2469 cont = _controllers[idBox];
2470 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2471 newbox->setInicPoint(xInic, yInic, zInic);
2472 int num = newbox->getNumInputPorts();
2473 for (int j = 0; j < num; j++) {
2474 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2476 newbox->notifyObservers(_idManager);
2477 } else if (type == GCONNECTOR) {
2478 int idCon = cont->getId();
2479 connections.push_back(idCon);
2484 for (int i = 0; i < (int) connections.size(); i++) {
2485 int objId = connections[i];
2486 GObjectController *cont = objectsMap[objId];
2487 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2489 GPortModel* startPort = connectModel->getStartPort();
2490 int startPortIndex = startPort->getPosInBox();
2491 GPortModel* endPort = connectModel->getEndPort();
2492 int endPortIndex = endPort->getPosInBox();
2494 GBlackBoxModel* startPortParentBox =
2495 (GBlackBoxModel*) startPort->getParentBox();
2496 GBlackBoxModel* endPortParentBox =
2497 (GBlackBoxModel*) endPort->getParentBox();
2499 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2500 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2502 GBlackBoxModel* newStartBox =
2503 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2504 GBlackBoxModel* newEndBox =
2505 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2507 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2508 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2510 // Creates connection
2511 int idCon = createGConnector(newStartPort);
2512 GConnectorController *tempp =
2513 (GConnectorController*) _controllers[idCon];
2514 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2515 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2516 tempp->endContourCreation();
2517 conMod->setEndPort(newEndPort);
2518 conView->updateStartEndPoints();
2521 std::map<int, int>::iterator itIds;
2522 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2523 int idOld = itIds->first;
2524 int idNew = itIds->second;
2526 GBlackBoxModel* oldBox =
2527 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2528 GBlackBoxModel* newBox =
2529 (GBlackBoxModel*) _controllers[idNew]->getModel();
2531 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2532 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2533 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2534 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2536 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2538 //EED int toCreate=-1;
2539 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2540 if (oldInputConnections[k] == newInputConnections[l]) {
2545 if (exist == false) {
2546 //Create complex input
2547 int posInBox = oldInputConnections[k];
2548 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2549 std::string inputPortName = inputPort->getBBTKName();
2550 int idInputPort = createGComplexBoxInputPort(inputPortName);
2551 GObjectController *cont = _controllers[idInputPort];
2552 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2553 double xIn, yIn, zIn;
2554 inputPort->getInicPoint(xIn, yIn, zIn);
2556 cbmod->setInicPoint(xIn, yIn, zIn);
2557 cbmod->notifyObservers(_idManager);
2559 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2561 // Creates connection
2562 int idCon = createGConnector(cbmod->getOutputPort(0));
2563 GConnectorController *tempp =
2564 (GConnectorController*) _controllers[idCon];
2565 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2566 vtkGConnectorView *conView =
2567 (vtkGConnectorView*) tempp->getView();
2568 tempp->endContourCreation();
2569 conMod->setEndPort(inputPortEnd);
2570 conView->updateStartEndPoints();
2576 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2578 //EED int toCreate=-1;
2579 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2580 if (oldOutputConnections[k] == newOutputConnections[l]) {
2585 if (exist == false) {
2586 //Create complex output
2587 int posInBox = oldOutputConnections[k];
2588 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2589 std::string outputPortName = outputPort->getBBTKName();
2590 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2591 GObjectController *cont = _controllers[idOutputPort];
2592 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2593 double xIn, yIn, zIn;
2594 outputPort->getInicPoint(xIn, yIn, zIn);
2596 cbmod->setInicPoint(xIn, yIn, zIn);
2597 cbmod->notifyObservers(_idManager);
2599 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2601 // Creates connection
2602 int idCon = createGConnector(outputPortEnd);
2603 GConnectorController *tempp =
2604 (GConnectorController*) _controllers[idCon];
2605 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2606 vtkGConnectorView *conView =
2607 (vtkGConnectorView*) tempp->getView();
2608 tempp->endContourCreation();
2609 conMod->setEndPort(cbmod->getInputPort(0));
2610 conView->updateStartEndPoints();
2620 //=========================================================================
2621 void wxVtkSceneManager::SetCbName(std::string cbName) {
2623 if (_cbName == "") {
2624 _cbName = "<complex box name>";
2628 //=========================================================================
2629 std::string wxVtkSceneManager::GetCbName() {
2633 //=========================================================================
2634 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2635 _cbPackageName = packagename;
2636 if (_cbPackageName == "") {
2637 _cbPackageName = "<package name of the complex box>";
2642 //=========================================================================
2643 std::string wxVtkSceneManager::GetCbPackageName() {
2644 return _cbPackageName;
2647 //=========================================================================
2648 void wxVtkSceneManager::SetAuthor(std::string author) {
2650 if (_Author == "") {
2651 _Author = "<author of the box>";
2655 //=========================================================================
2656 std::string wxVtkSceneManager::GetAuthor() {
2660 //=========================================================================
2661 void wxVtkSceneManager::SetCategory(std::string category) {
2662 _Category = category;
2663 if (_Category == "") {
2664 _Category = "<category of the box>";
2668 //=========================================================================
2669 std::string wxVtkSceneManager::GetCategory() {
2673 //=========================================================================
2674 void wxVtkSceneManager::SetDescription(std::string description) {
2675 _Description = description;
2676 if (_Description == "") {
2677 _Description = "<description of the box>";
2682 //=========================================================================
2683 std::string wxVtkSceneManager::GetDescription() {
2684 return _Description;
2687 //=========================================================================
2689 void wxVtkSceneManager::printAll(int com , int sta ){
2691 int tmpState = sta ;
2692 if ( tmpState == NOTHING_HAPPENS ) {
2693 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2695 if ( tmpState == HIGHLIGHTED ) {
2696 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2698 if ( tmpState == POSSIBLE_CONNECTION ) {
2699 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2701 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2702 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2704 if ( tmpState == CLICKED ) {
2705 std::cout << "CONTROLER STATE---->CLICKED\n" ;
2707 if ( tmpState == DRAG ) {
2708 std::cout << "CONTROLER STATE---->DRAG\n" ;
2710 if ( tmpState == SELECTED ) {
2711 std::cout << "CONTROLER STATE---->SELECTED\n" ;
2713 if ( tmpState == CREATING_CONTOUR ) {
2714 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2720 if ( command == INIT_CREATION_CONTOUR ) {
2721 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2723 if ( command == FIN_CREATION_CONTOUR ) {
2724 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2726 if ( command == ADD_TO_SELECTED ) {
2727 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2729 if ( command == DRAG_OBJECTS ) {
2730 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2732 if ( command == EDIT_BLACKBOX ) {
2733 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
2735 if ( command == REMOVE_FROM_SELECTED ) {
2736 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
2742 } // EO namespace bbtk