1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::wxVtkSceneManager .
36 #include "wxVtkSceneManager.h"
38 #include <vtkPolygon.h>
39 #include <vtkUnstructuredGrid.h>
43 //=========================================================================
44 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent,
45 wxVtk3DBaseView *baseView, int idManager) {
46 _cbName = "ComplexBoxName";
47 _cbPackageName = "PackageName";
48 _Author = "Author ??";
50 _Description = "Description ??";
54 _idManager = idManager;
56 _startDragging = false;
57 _isComplexBox = false;
59 if (_baseView != NULL) {
62 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
65 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
69 _worldState = NOTHING_HAPPENS;
70 registerController(this);
73 _idConnectionInCreation = -1;
78 //=========================================================================
80 void wxVtkSceneManager::disconnectDrop() {
81 printf("EED %p ~wxVtkSceneManager::disconnectDrop()\n", this);
82 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
83 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
86 //=========================================================================
88 wxVtkSceneManager::~wxVtkSceneManager() {
90 printf("EED %p ~wxVtkSceneManager() START\n", this);
93 printf("EED %p ~wxVtkSceneManager() END\n", this);
96 //=========================================================================
98 void wxVtkSceneManager::configureBaseView() {
99 printf("EED wxVtkSceneManager::configureBaseView 0\n");
100 vtkInteractorStyleBaseView2D *interactorstylebaseview =
101 vtkInteractorStyleBaseView2D::New();
103 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
105 // Important to activate the 2D interaction system
106 wxVTKRenderWindowInteractor *iren =
107 _baseView->GetWxVTKRenderWindowInteractor();
108 interactorstylebaseview->SetInteractor(iren);
109 iren->SetInteractorStyle(interactorstylebaseview);
110 interactorstylebaseview->SetwxVtkBaseView(_baseView);
112 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
113 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, -1000, 1000);
114 _baseView->GetRenderer()->GetActiveCamera()->Zoom(10);
117 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
118 _baseView->GetRenderer()->GradientBackgroundOn();
121 _textActor = vtkTextActor3D::New();
122 _textActor->SetPosition(-9999, -9999, GPOSITION_Z);
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
136 double zInic = GPOSITION_Z;
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);
257 if (descriptor == NULL){
258 printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
260 //Prepares the initial model
261 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
264 double yy = windowHeight - y;
266 //z value is not important yet, because it is only used a parallel projection
267 double zz = GPOSITION_Z;
268 _baseView->TransCoordScreenToWorld(xx, yy, zz);
269 model->setInicPoint(xx, yy, zz);
271 std::stringstream stream;
273 std::string newBoxName;
274 newBoxName = findANewNameForABox();
276 stream << newBoxName;
278 std::string arraystring = stream.str();
280 model->setBBTKName(arraystring);
281 model->setBBTKType(boxType);
282 model->setBBTKPackage(packageName);
284 model->addObserver(view);
285 model->addObserver(this);
287 //Iterate and create the input ports
288 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
289 descriptor->GetInputDescriptorMap();
290 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
293 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) {
294 BlackBoxInputDescriptor *desc = itInput->second;
295 createGInputPort(GINPUTPORT, i, model, desc);
299 //Iterate and create the output ports
300 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
301 descriptor->GetOutputDescriptorMap();
302 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
305 for (itOutput = descriptorOutMap.begin(); itOutput
306 != descriptorOutMap.end(); ++itOutput) {
307 BlackBoxOutputDescriptor *desc = itOutput->second;
308 createGOutputPort(GOUTPUTPORT, i, model, desc);
312 //Associates the view with the correspondent renderer and the model.
313 //(NOTE: Refresh is only made by the view)
314 view->setModel(model);
315 view->setBaseView(_baseView);
316 view->initVtkObjects();
318 //Associates the controller with the correspondent model and view
319 controller->setModelAndView(model, view);
321 //Resgiter change to the observers of the actual model
322 model->notifyObservers(_idManager);
324 int newId = addObjectController(controller);
330 //=========================================================================
332 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
333 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
334 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
336 int type = GCOMPLEXINPUTPORT;
338 //Create the MVC Objects
342 (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
344 vtkGObjectView *view =
345 GObjectsMVCFactory::getInstance()->createGObjectView(type);
346 GObjectController* controller =
347 GObjectsMVCFactory::getInstance()->createGObjectController(type);
349 //Prepares the initial model
352 double yy = windowHeight - 5;
354 //z value is not important yet, because it is only used a parallel projection
355 double zz = GPOSITION_Z;
357 _baseView->TransCoordScreenToWorld(xx, yy, zz);
358 model->setInicPoint(xx, yy, zz);
360 model->setBBTKName(inputName);
361 model->setBBTKType("ComplexInputPort");
362 model->setComplexPortType(type);
364 model->addObserver(view);
365 model->addObserver(this);
367 //create the output port
368 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
369 "ComplexOutputPortType","ComplexOutputPortDescriopton", 0, model);
370 model->addOutputPort((GPortModel*) portController->getModel());
372 //Associates the view with the correspondent renderer and the model.
373 //(NOTE: Refresh is only made by the view)
374 view->setModel(model);
375 view->setBaseView(_baseView);
376 view->initVtkObjects();
378 //Associates the controller with the correspondent model and view
379 controller->setModelAndView(model, view);
381 //Resgiter change to the observers of the actual model
382 model->notifyObservers(_idManager);
384 int newId = addObjectController(controller);
388 //=========================================================================
390 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
391 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
392 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
394 int type = GCOMPLEXOUTPUTPORT;
396 //Create the MVC Objects
400 (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
402 vtkGObjectView *view =
403 GObjectsMVCFactory::getInstance()->createGObjectView(type);
404 GObjectController *controller =
405 GObjectsMVCFactory::getInstance()->createGObjectController(type);
407 //Prepares the initial model
410 double yy = windowHeight - 5;
412 //z value is not important yet, because it is only used a parallel projection
413 double zz = GPOSITION_Z;
415 _baseView->TransCoordScreenToWorld(xx, yy, zz);
416 model->setInicPoint(xx, yy, zz);
418 model->setBBTKName(outputName);
419 model->setBBTKType("ComplexOutputPort");
420 model->setComplexPortType(type);
422 model->addObserver(view);
423 model->addObserver(this);
425 //create the output port
426 GPortController* portController = createGPort(GINPUTPORT, outputName,
427 "ComplexInputPort","ComplexInputPortDescription", 0, model);
428 model->addInputPort((GPortModel*) portController->getModel());
430 //Associates the view with the correspondent renderer and the model.
431 //(NOTE: Refresh is only made by the view)
432 view->setModel(model);
433 view->setBaseView(_baseView);
434 view->initVtkObjects();
436 //Associates the controller with the correspondent model and view
437 controller->setModelAndView(model, view);
439 //Resgiter change to the observers of the actual model
440 model->notifyObservers(_idManager);
442 int newId = addObjectController(controller);
446 //=========================================================================
448 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,
449 GBoxModel *blackBox, BlackBoxInputDescriptor *desc) {
450 GPortController* portController = createGPort(portType, desc->GetName(),
451 desc->GetTypeName(), desc->GetDescription(), posinBox, blackBox);
452 blackBox->addInputPort((GPortModel*) portController->getModel());
453 return portController->getId();
456 //=========================================================================
458 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,
459 GBoxModel *blackBox, BlackBoxOutputDescriptor *desc) {
460 GPortController* portController = createGPort(portType, desc->GetName(),
461 desc->GetTypeName(),desc->GetDescription(), posinBox, blackBox);
462 blackBox->addOutputPort((GPortModel*) portController->getModel());
463 return portController->getId();
466 //=========================================================================
468 GPortController* wxVtkSceneManager::createGPort(int portType,
469 std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posInBox,
470 GBoxModel *blackBox) {
473 //Create the MVC Objects
476 (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
478 vtkGObjectView *view =
479 GObjectsMVCFactory::getInstance()->createGObjectView(type);
480 GObjectController* controller =
481 GObjectsMVCFactory::getInstance()->createGObjectController(type);
483 model->registerInBox(blackBox, portType, posInBox);
485 model->setBBTKType(bbtkType);
486 model->setBBTKName(bbtkName);
487 model->setBBTKDescription(bbtkDescription);
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 = new manualConnectorContourController();
514 manualConnectorContourView *manContourView = new manualConnectorContourView();
515 manualContourModel *manContourModel = new manualContourModel();
516 GConnectorController *connectorcontroller = new GConnectorController();
517 GConnectorModel *connectorModel = new GConnectorModel();
518 vtkGConnectorView *connectorView = new vtkGConnectorView();
519 connectorModel->setGObjectType(type);
521 manContourModel->SetCloseContour(false);
522 connectorModel->setStartPort(startPort);
524 manContourView->SetModel(manContourModel);
525 manContourView->SetWxVtkBaseView(_baseView);
526 manContourView->SetRange(0.5);
527 manContourView->SetZ(GPOSITION_Z);
529 manContourView->SetColorNormalContour(0, 0, 1);
530 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
531 manContourView->SetColorSelectContour(1, 0.8, 0);
535 * Width increased from 2 to 3, it simplifies line handling and spline control :P
538 manContourView->SetWidthLine( 3 ) ;
539 manContourView->SetShowText(false);
541 manContourControl->SetModelView(manContourModel, manContourView);
543 manContourControl->CreateNewManualContour();
547 connectorModel->getInicPoint(x, y, z);
550 manContourControl->SetState(1);
551 manContourModel->SetCloseContour(false);
553 manContourModel->AddPoint(x, y, z);
554 manContourView->AddPoint();
556 manContourModel->AddPoint(x, y, z);
557 manContourView->AddPoint();
559 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
560 manContourControl->_bakIdPoint = bak;
562 manContourControl->SetMoving(false);
564 connectorcontroller->setModelAndView(connectorModel, connectorView);
566 int newId = addObjectController(connectorcontroller);
568 connectorcontroller->setManualContourController(manContourControl);
569 connectorModel->setManualContourModel(manContourModel);
570 connectorView->setManualContourView(manContourView);
571 connectorView->setModel(connectorModel);
572 connectorView->setBaseView(_baseView);
574 connectorModel->addObserver(connectorView);
575 connectorModel->addObserver(this);
577 // manContourView->Refresh();
582 //=========================================================================
584 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param) {
585 vtkInteractorStyleBaseView
586 * baseViewControlManager =
587 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
588 baseViewControlManager->AddInteractorStyleMaracas(param);
591 //=========================================================================
593 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param) {
594 vtkInteractorStyleBaseView
595 * baseViewControlManager =
596 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
597 baseViewControlManager->RemoveInteractorStyleMaracas(param);
600 //=========================================================================
602 vtkRenderer* wxVtkSceneManager::getRenderer() {
603 return _baseView->GetRenderer();
606 //=========================================================================
608 vtkRenderWindow* wxVtkSceneManager::getRenderWindow() {
609 return _baseView->GetRenWin();
611 //=========================================================================
614 //=========================================================================
615 int wxVtkSceneManager::GetIndexInSelected(int idControler) {
617 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
618 if (_selectedObjects[i] == idControler) {
625 //=========================================================================
627 void wxVtkSceneManager::update(int idController, int command) {
629 if (command != NO_COMMAND) {
630 if (command == ADD_TO_SELECTED) {
631 if (GetIndexInSelected(idController) == -1) {
632 _selectedObjects.push_back(idController);
634 } else if (command == REMOVE_FROM_SELECTED) {
635 int index = GetIndexInSelected(idController);
637 _selectedObjects.erase(_selectedObjects.begin() + index);
639 } else if (command == INIT_CREATION_CONTOUR) {
642 typedef std::map<int , GObjectController*>::iterator TIterator ;
645 // Find current item in the controller
646 iter = _controllers.find( idController ) ;
647 iter_end = _controllers.end( ) ;
649 if ( iter != iter_end ) {
650 GObjectController* gobjc = iter->second ;
652 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
653 // And if the item is a port
654 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
655 TIterator c_it = _controllers.begin( ) ;
656 // Go through all componets
657 for ( c_it ; c_it != iter_end ; c_it++ ) {
658 GObjectController* obc = c_it->second ;
659 int obc_type = obc->getModel( )->getGObjectType( ) ;
660 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
661 // if the component is a port and the type is the same of that selected
662 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
664 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
665 //obc->getView( )->setState( HIGHLIGHTED ) ;
673 _worldState = INIT_CREATION_CONTOUR;
674 GObjectController* cont = _controllers[idController];
675 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
677 // The last one is the controller of the connector
678 std::map<int, GObjectController*>::iterator it2;
680 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
681 GObjectController *cont = it2->second;
682 if (cont->getGObjectType() == GPORT) {
683 GPortModel* port = (GPortModel*) cont->getModel();
684 if (port->getPortType() == GINPUTPORT) {
685 cont->SetActive(true);
687 cont->getView()->setState(NOTHING_HAPPENS);
688 cont->getModel()->notifyObservers(_idManager);
689 cont->SetActive(false);
692 cont->getView()->setState(NOTHING_HAPPENS);
693 cont->getModel()->notifyObservers(_idManager);
694 cont->SetActive(false);
697 _selectedObjects.clear();
698 _idConnectionInCreation = createGConnector(startOutputPort);
699 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
700 _worldState = NOTHING_HAPPENS;
701 //int id = _controllers.size()-1;
702 GObjectController *cont = _controllers[_idConnectionInCreation];
703 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
704 GObjectController *finPort = _controllers[idController];
706 if (finPort->getGObjectType() == GPORT) {
707 GPortModel* modelPort = (GPortModel*) finPort->getModel();
708 modelContour->setEndPort(modelPort);
711 typedef std::map<int, GObjectController*>::iterator TIterator;
712 TIterator c_it = _controllers.begin();
713 TIterator iter_end = _controllers.end();
714 // Go through all componets
715 for (c_it; c_it != iter_end; c_it++) {
716 GObjectController* obc = c_it->second;
717 int obc_type = obc->getModel()->getGObjectType();
718 int obc_state = obc->getView()->getState();
719 // if the component is a port and the type is the same of that selected
720 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
721 // Return element to neutral state if not selected
722 obc->getView()->setState(NOTHING_HAPPENS);
724 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
725 // Change element to connected state
726 obc->getView()->setState(HIGHLIGHTED);
733 _parent->saveTempandUpdate("create connection");
736 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
737 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
739 std::map<int, GObjectController*>::iterator it2;
741 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
742 GObjectController *cont = it2->second;
743 if (cont->getView() != NULL) {
744 cont->getView()->setState(NOTHING_HAPPENS);
745 cont->getModel()->notifyObservers(_idManager);
747 cont->SetActive(true);
756 //=========================================================================
758 bool wxVtkSceneManager::OnMouseMove() {
760 bool okStatusMessage = false;
761 bool okPortMessage = false;
762 wxVTKRenderWindowInteractor *wxVTKiren;
763 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
764 wxVTKiren->GetEventPosition(X, Y);
766 if (_worldState == DRAG_OBJECTS) {
767 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
768 int id = _selectedObjects[i];
769 GObjectController* cont = _controllers[id];
770 if (_startDragging) {
771 cont->getView()->setStartDragging(true);
773 cont->getView()->moveObject(X, Y);
774 cont->getView()->setState(DRAG);
775 cont->getModel()->notifyObservers(_idManager);
778 std::map<int, GObjectController*>::iterator it;
780 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
781 GObjectController *desc = it->second;
782 if (desc->getGObjectType() == GCONNECTOR) {
783 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
784 vconn->updateStartEndPoints();
788 _startDragging = false;
790 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
791 std::map<int, GObjectController*>::iterator it;
793 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
794 GObjectController *desc = it->second;
795 int type = desc->getGObjectType();
796 int state = desc->getView()->getState();
797 desc->getModel()->getCenter(px, py, pz);
800 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION )) {
802 okStatusMessage = true;
803 updateStatusBar(desc->getStatusText());
804 if (type == GBLACKBOX) {
805 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
806 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),
811 okPortMessage = true;
813 _textActor->SetInput(desc->getStatusText().c_str());
814 _textActor->SetScale(0.1);
815 _textActor->SetPosition(px - 25, py + 1, pz + 2);
820 _fillObjectActor->SetScale(1);
821 _fillObjectActor->GetProperty()->SetOpacity(0.50);
822 _fillObjectActor->SetPosition(px, py, 1);
823 _aPolygonMapper->Modified();
826 } // for controllers it
829 if (okStatusMessage == false) {
833 if (okPortMessage == false) {
834 _textActor->SetScale(0.0001);
835 _fillObjectActor->SetScale(0.0001);
840 //=========================================================================
842 bool wxVtkSceneManager::OnLeftButtonDown() {
844 if (_worldState == INIT_CREATION_CONTOUR) {
845 bool isOverPort = false;
846 std::map<int, GObjectController*>::iterator it;
847 for (it = _controllers.begin(); it != _controllers.end() && isOverPort
849 GObjectController *desc = it->second;
850 if (desc->getGObjectType() == GPORT) {
851 GPortModel *portmod = (GPortModel*) desc->getModel();
852 vtkGObjectView *portView = desc->getView();
853 if (portmod->getPortType() == GINPUTPORT
854 && portView->getState() == HIGHLIGHTED) {
858 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
860 portView->setState( HIGHLIGHTED);
867 if (isOverPort == false) {
869 UnSelectBlackBoxes();
873 } else { //_worldState
875 _worldState = DRAG_OBJECTS;
876 _startDragging = true;
878 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
879 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
880 ctrlkey = ctrlkey + shiftkey;
882 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
884 if (GetGBlackBoxControlerPointedByMouse() != NULL) {
885 int state = cont->getView()->getState();
886 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
887 UnSelectBlackBoxes();
890 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
891 int id = _selectedObjects[i];
892 GObjectController* cont = _controllers[id];
893 cont->getView()->setState(DRAG);
894 cont->getModel()->notifyObservers(_idManager);
897 } // if _selectedObjects.size
903 //=========================================================================
905 bool wxVtkSceneManager::OnLeftButtonUp() {
906 if (_worldState == DRAG_OBJECTS) {
907 _worldState = NOTHING_HAPPENS;
909 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
910 int id = _selectedObjects[i];
911 GObjectController* cont = _controllers[id];
912 cont->getView()->setState(SELECTED);
913 cont->getModel()->notifyObservers(_idManager);
919 //=========================================================================
920 void wxVtkSceneManager::CancelConnection() {
921 if (_worldState == INIT_CREATION_CONTOUR) {
922 _worldState = NOTHING_HAPPENS;
923 //int lastId = _controllers.size()-1;
925 GConnectorController *connector =
926 (GConnectorController*) _controllers[_idConnectionInCreation];
927 connector->removeFromScene();
928 unregisterController(connector);
929 _controllers.erase(_idConnectionInCreation);
931 std::map<int, GObjectController*>::iterator it;
932 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
933 GObjectController *desc = it->second;
934 desc->SetActive(true);
935 desc->getView()->setState(NOTHING_HAPPENS);
936 desc->getModel()->notifyObservers(_idManager);
941 //=========================================================================
943 bool wxVtkSceneManager::OnRightButtonUp() {
944 if (_worldState == INIT_CREATION_CONTOUR) {
947 UnSelectBlackBoxes();
953 bool wxVtkSceneManager::OnMiddleButtonDown() {
956 this->_vtkInteractorStyleBaseView->StartPan();
961 bool wxVtkSceneManager::OnMiddleButtonUp() {
964 this->_vtkInteractorStyleBaseView->EndPan();
971 //=========================================================================
973 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
974 GObjectController *result = NULL;
976 wxVTKRenderWindowInteractor *wxVTKiren;
978 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
979 wxVTKiren->GetEventPosition(X, Y);
981 std::map<int, GObjectController*>::iterator it;
983 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
984 GObjectController *cont = it->second;
985 int type = cont->getGObjectType();
987 if (cont->getView()->isPointInside(X, Y) == true) {
988 if (type == GBLACKBOX) {
991 } // if isPointInside
996 //=========================================================================
997 void wxVtkSceneManager::UnSelectBlackBoxes() {
998 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
999 int id = _selectedObjects[i];
1000 GObjectController* control = _controllers[id];
1001 control->getView()->setState(NOTHING_HAPPENS);
1002 control->getModel()->notifyObservers(_idManager);
1003 }// for _selectedObjects
1004 _selectedObjects.clear();
1007 //=========================================================================
1008 bool wxVtkSceneManager::OnLeftDClick() {
1009 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1011 UnSelectBlackBoxes();
1012 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1018 wxVTKRenderWindowInteractor *wxVTKiren;
1019 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1020 wxVTKiren->GetEventPosition(X,Y);
1022 std::map<int, GObjectController*>::iterator it;
1024 bool clickOnObject = false;
1026 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1028 GObjectController *cont = it->second;
1029 int type = cont->getGObjectType();
1031 if(cont->getView()->isPointInside(X,Y))
1035 for (int i=0; i< (int)_selectedObjects.size(); i++)
1037 int id = _selectedObjects[i];
1038 GObjectController* control = _controllers[id];
1039 control->getView()->setState(NOTHING_HAPPENS);
1041 _selectedObjects.clear();
1043 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1044 _parent->editBlackBox(bbmodel);
1046 clickOnObject = true;
1050 if(clickOnObject==false)
1052 //_parent->editDiagramParameters(this);
1058 //=========================================================================
1060 bool wxVtkSceneManager::OnChar()
1064 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1065 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1067 // KeyCode 127 : Delete Key
1068 // KeyCode 8 : Backspace Key
1069 if (keyCode == 8 || keyCode == 127)
1071 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1073 int id = _selectedObjects[i];
1074 std::map<int, GObjectController*>::iterator it;
1075 it = _controllers.find(id);
1076 if (it != _controllers.end())
1078 oktmp = deleteObject(id);
1081 }// for selected objects
1082 if (ok) _selectedObjects.clear();
1083 _parent->saveTempandUpdate("delete object");
1088 if((keyCode==0) && (ctrlkey==1)) {
1093 if(_selectedObjects.size()){
1094 std::cout<<"objects to copy :";
1095 for(int i=0;i<_selectedObjects.size();i++){
1096 std::cout<<_selectedObjects.at(i)<<" ";
1098 DuplicateObjects(getSelectedObjects());
1100 std::cout<<"No objects to copy\n";
1101 } // _selectedObjects.size
1107 //=========================================================================
1109 void wxVtkSceneManager::AddControlerToBeRemove(
1110 std::vector<int> *controllersToRemove, int id) {
1114 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1115 if (id == (*controllersToRemove)[i]) {
1121 controllersToRemove->push_back(id);
1126 //=========================================================================
1128 bool wxVtkSceneManager::deleteObject(int id)
1131 GObjectController *control = _controllers[id];
1132 std::vector<int> controllersToRemove;
1133 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1134 == GCOMPLEXINPUTPORT || control->getGObjectType()
1135 == GCOMPLEXOUTPUTPORT) {
1136 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1137 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1139 bool boxConnected = false;
1141 // Add box input controllers to be removed
1142 for (int i = 0; i < (int) inputs.size(); i++) {
1143 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1144 if (inputs[i]->isConnected()) {
1145 boxConnected = true;
1149 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1151 // Add box output controllers to be removed
1152 for (int i = 0; i < (int) outputs.size(); i++) {
1153 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1154 if (outputs[i]->isConnected()) {
1155 boxConnected = true;
1159 // Add connection controllers to be removed
1160 std::map<int, GObjectController*>::iterator it;
1161 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1162 GObjectController *cont = it->second;
1163 int type = cont->getGObjectType();
1164 if (type == GCONNECTOR) {
1165 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1166 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1168 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1170 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1172 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1177 // Add box controller to be removed
1178 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1179 } else if (control->getGObjectType() == GCONNECTOR) {
1180 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1181 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1183 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1184 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1186 gconnectorcontroler->getManualContourController()->OnChar();
1191 std::map<int, GObjectController*>::iterator it;
1193 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1194 int key = controllersToRemove[i];
1195 it = _controllers.find(key);
1196 GObjectController *cont = _controllers[key];
1198 cont->removeFromScene();
1199 unregisterController((InteractorStyleMaracas*) cont);
1200 _controllers.erase(it);
1208 //=========================================================================
1210 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1211 std::string boxName) {
1212 _parent->displayBlackBoxInfo(packageName, boxName);
1215 //=========================================================================
1217 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1218 _parent->updateStatusBar(textStatus);
1221 //=========================================================================
1222 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1223 std::string result = "";
1224 if (withLineNumber == true) {
1226 stringstream StrStream;
1228 std::string strValue = StrStream.str();
1231 } else if (value < 100) {
1235 result += strValue + ": ";
1239 //=========================================================================
1241 bool wxVtkSceneManager::MakeBoxExecutable() {
1242 std::map<int, GObjectController*> selected = getSelectedObjects();
1243 if( selected.empty() )
1246 std::map<int, GObjectController*>::iterator it;
1247 for (it = selected.begin(); it != selected.end(); ++it) {
1248 GObjectController* lastSelected = it->second;
1250 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1251 GBlackBoxModel *bbmodel =
1252 (GBlackBoxModel*) lastSelected->getModel();
1253 view->setState(HIGHLIGHTED);
1254 if (bbmodel->isExecutable()) {
1255 bbmodel->setExecutable(false);
1257 bbmodel->setExecutable(true);
1259 bbmodel->notifyObservers(lastSelected->getId());
1267 //=========================================================================
1269 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1270 bool existsExec = false;
1272 std::vector<std::string> packages;
1273 std::vector<int> boxes;
1274 std::vector<int> connections;
1275 std::vector<int> execBoxes;
1277 std::map<int, GObjectController*>::iterator it;
1279 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1280 GObjectController *desc = it->second;
1281 int type = desc->getGObjectType();
1283 if (type == GBLACKBOX) {
1284 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1286 std::string pkg = mod->getBBTKPackage();
1287 bool existsPkg = false;
1288 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1289 if (packages[t] == pkg) {
1294 packages.push_back(pkg);
1297 boxes.push_back(it->first);
1298 if (mod->isExecutable()) {
1299 execBoxes.push_back(it->first);
1302 } else if (type == GCONNECTOR) {
1303 connections.push_back(it->first);
1308 std::string script = "";
1309 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1310 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1311 script += LineNumber(wln, lnNmbr) + "\n";
1313 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1314 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1316 for (i = 0; i < (int) packages.size(); i++) {
1317 script += LineNumber(wln, lnNmbr);
1318 script += "include ";
1319 script += packages[i];
1323 script += LineNumber(wln, lnNmbr);
1328 script += LineNumber(wln, lnNmbr);
1329 script += "author \"";
1333 script += LineNumber(wln, lnNmbr);
1334 script += "description \"";
1335 script += _Description;
1338 script += LineNumber(wln, lnNmbr);
1339 script += "category \"";
1340 script += _Category;
1343 script += LineNumber(wln, lnNmbr);
1346 // script+="include std\n"; // JPR
1348 for (i = 0; i < (int) boxes.size(); i++) {
1349 script += LineNumber(wln, lnNmbr);
1352 GObjectController *control = _controllers[id];
1353 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1355 script += model->getBBTKType();
1357 script += model->getBBTKName();
1360 std::vector<GPortModel*> inputs = model->getInputPorts();
1361 for (int j = 0; j < (int) inputs.size(); j++) {
1362 GPortModel* inputPort = inputs[j];
1363 if (inputPort->isValueSet()) {
1364 script += LineNumber(wln, lnNmbr);
1366 script += model->getBBTKName();
1368 script += inputPort->getBBTKName();
1370 script += inputPort->getValue();
1375 script += LineNumber(wln, lnNmbr);
1380 script += LineNumber(wln, lnNmbr);
1383 for (i = 0; i < (int) connections.size(); i++) {
1384 script += LineNumber(wln, lnNmbr);
1385 script += "connect ";
1386 int id = connections[i];
1387 GObjectController *control = _controllers[id];
1388 GConnectorModel *model = (GConnectorModel*) control->getModel();
1390 //Start Connection info
1391 GPortModel *start = model->getStartPort();
1392 script += start->getParentBox()->getBBTKName();
1394 script += start->getBBTKName();
1398 //End Connection info
1399 GPortModel *end = model->getEndPort();
1400 script += end->getParentBox()->getBBTKName();
1402 script += end->getBBTKName();
1407 script += LineNumber(wln, lnNmbr);
1409 for (i = 0; i < (int) execBoxes.size(); i++) {
1410 script += LineNumber(wln, lnNmbr);
1412 int id = execBoxes[i];
1413 GObjectController *control = _controllers[id];
1414 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1416 script += model->getBBTKName();
1425 //=========================================================================
1427 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1428 std::vector<std::string> packages;
1429 std::vector<int> boxes;
1430 std::vector<int> connections;
1431 std::vector<int> execBoxes;
1433 std::map<int, GObjectController*>::iterator it;
1435 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1436 GObjectController *desc = it->second;
1437 int type = desc->getGObjectType();
1439 if (type == GBLACKBOX) {
1440 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1442 std::string pkg = mod->getBBTKPackage();
1443 bool existsPkg = false;
1444 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1445 if (packages[t] == pkg) {
1450 packages.push_back(pkg);
1453 boxes.push_back(it->first);
1454 if (mod->isExecutable()) {
1455 execBoxes.push_back(it->first);
1457 } else if (type == GCONNECTOR) {
1458 connections.push_back(it->first);
1462 std::string script = "";
1464 script += "include std\n"; // EED
1465 script += "include itkvtk\n"; // EED
1467 for (i = 0; i < (int) packages.size(); i++) {
1468 script += "include ";
1469 script += packages[i];
1474 // Definition of a complex box
1475 script += "define ";
1476 script += _cbName + " " + _cbPackageName;
1480 script += "author \"";
1484 script += "description \"";
1485 script += _Description;
1489 script += "category \"";
1490 script += _Category;
1495 for (i = 0; i < (int) boxes.size(); i++) {
1498 GObjectController *control = _controllers[id];
1499 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1501 script += model->getBBTKType();
1503 script += model->getBBTKName();
1506 std::vector<GPortModel*> inputs = model->getInputPorts();
1507 for (int j = 0; j < (int) inputs.size(); j++) {
1508 GPortModel* inputPort = inputs[j];
1509 if (inputPort->isValueSet()) {
1511 script += model->getBBTKName();
1513 script += inputPort->getBBTKName();
1515 script += inputPort->getValue();
1523 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1525 std::string complexInputs = "";
1526 std::string complexOutputs = "";
1529 for (i = 0; i < (int) connections.size(); i++) {
1530 int id = connections[i];
1531 GObjectController *control = _controllers[id];
1532 GConnectorModel *model = (GConnectorModel*) control->getModel();
1535 GPortModel *start = model->getStartPort();
1536 GBoxModel *startBox = start->getParentBox();
1538 GPortModel *end = model->getEndPort();
1539 GBoxModel *endBox = end->getParentBox();
1541 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1542 complexInputs += "input ";
1543 complexInputs += startBox->getBBTKName();
1545 complexInputs += " ";
1546 complexInputs += endBox->getBBTKName();
1547 complexInputs += ".";
1548 complexInputs += end->getBBTKName();
1550 complexInputs += " ";
1551 complexInputs += "\" \"";
1553 complexInputs += "\n";
1554 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1555 complexOutputs += "output ";
1556 complexOutputs += endBox->getBBTKName();
1558 complexOutputs += " ";
1559 complexOutputs += startBox->getBBTKName();
1560 complexOutputs += ".";
1561 complexOutputs += start->getBBTKName();
1563 complexOutputs += " ";
1564 complexOutputs += "\" \"";
1566 complexOutputs += "\n";
1568 script += "connect ";
1569 script += startBox->getBBTKName();
1571 script += start->getBBTKName();
1575 //End Connection info
1576 script += endBox->getBBTKName();
1578 script += end->getBBTKName();
1586 for (i = 0; i < (int) execBoxes.size(); i++) {
1588 int id = execBoxes[i];
1589 GObjectController *control = _controllers[id];
1590 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1592 script += model->getBBTKName();
1597 script += "# Complex input ports\n";
1598 script += complexInputs;
1601 script += "# Complex output ports\n";
1602 script += complexOutputs;
1605 script += "endefine";
1611 //=========================================================================
1613 void wxVtkSceneManager::deleteAllBoxes() {
1614 std::map<int, GObjectController*>::iterator it;
1615 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1616 GObjectController *cont = it->second;
1617 cont->removeFromScene();
1618 unregisterController((InteractorStyleMaracas*) cont);
1620 _selectedObjects.clear();
1621 _controllers.clear();
1624 //=========================================================================
1627 void wxVtkSceneManager::refresh() {
1628 _baseView->Refresh();
1630 //=========================================================================
1632 void wxVtkSceneManager::refreshScene() {
1633 _baseView->RefreshView();
1636 //=========================================================================
1638 void wxVtkSceneManager::centerView() {
1640 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1641 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1642 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1643 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1646 //=========================================================================
1648 void wxVtkSceneManager::saveDiagram(std::string &content) {
1651 content += "CATEGORY:";
1652 content += GetCategory();
1655 content += "DESCRIPTION:";
1656 content += GetDescription();
1659 content += "AUTHOR:";
1660 content += GetAuthor();
1663 //Print info IF COMPLEX BOX
1664 content += "COMPLEXBOX:";
1665 if (_isComplexBox) {
1666 content += "TRUE\n";
1668 content += "COMPLEXBOXNAME:";
1669 content += GetCbName();
1672 content += "PACKAGENAME:";
1673 content += GetCbPackageName();
1676 //Print info complex input ports
1677 std::vector<int> inputs = getComplexInputPorts();
1678 int insize = inputs.size();
1679 content += "COMPLEXINPUTS:";
1680 sprintf(buffer, "%d", insize);
1684 for (int i = 0; i < insize; i++) {
1686 GObjectController *cont = _controllers[id];
1687 cont->getModel()->save(content);
1690 //Print info complex output ports
1691 std::vector<int> outputs = getComplexOutputPorts();
1692 int outsize = outputs.size();
1693 content += "COMPLEXOUTPUTS:";
1694 sprintf(buffer, "%d", outsize);
1698 for (int i = 0; i < outsize; i++) {
1699 int id = outputs[i];
1700 GObjectController *cont = _controllers[id];
1701 cont->getModel()->save(content);
1705 content += "FALSE\n";
1709 std::vector<int> boxes = getBlackBoxes();
1710 int bsize = boxes.size();
1711 content += "BOXES:";
1712 sprintf(buffer, "%d", bsize);
1716 for (int i = 0; i < bsize; i++) {
1718 GObjectController *cont = _controllers[id];
1719 cont->getModel()->save(content);
1723 std::vector<int> connections = getConnections();
1724 int csize = connections.size();
1725 content += "CONNECTIONS:";
1726 sprintf(buffer, "%d", csize);
1730 for (int i = 0; i < csize; i++) {
1731 int id = connections[i];
1732 GObjectController *cont = _controllers[id];
1733 cont->getModel()->save(content);
1738 //=========================================================================
1740 void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
1742 std::string version = "<void>";
1743 std::string line = "";
1744 char delims[] = ":";
1745 char *result = NULL;
1747 getline(inputStream, line);
1750 while (!inputStream.eof()) {
1751 if (line == "" || line[0] == '#') {
1752 getline(inputStream, line);
1753 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1754 version = line.substr(18, 3);
1756 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1757 version = line.substr(18, 3);
1759 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1760 version = line.substr(18, 3);
1762 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1763 version = line.substr(18, 3);
1765 } else if (line == "APP_START") {
1771 printf("EED wxVtkSceneManager::loadDiagram version=%s\n", version.c_str());
1775 if ((version != "1.0") && (version != "1.1")) {
1776 getline(inputStream, line);//CATEGORY:<category of the box>
1777 char categoryTmp[30];
1778 strcpy(categoryTmp, line.c_str());
1779 result = strtok(categoryTmp, delims);
1780 result = strtok(NULL, delims);
1781 SetCategory(result);
1783 getline(inputStream, line);//DESCRIPTION:<description of the box>
1784 char descriptionTmp[1024];
1785 strcpy(descriptionTmp, line.c_str());
1786 result = strtok(descriptionTmp, delims);
1787 result = strtok(NULL, delims);
1788 SetDescription(result);
1790 getline(inputStream, line);//AUTHOR:<author>
1791 char authorTmp[255];
1792 strcpy(authorTmp, line.c_str());
1793 result = strtok(authorTmp, delims);
1794 result = strtok(NULL, delims);
1799 getline(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1800 char complexTmp[30];
1801 strcpy(complexTmp, line.c_str());
1802 result = strtok(complexTmp, delims);
1803 result = strtok(NULL, delims);
1804 std::string isComplexBox(result);
1806 if (isComplexBox == "TRUE") {
1807 _isComplexBox = true;
1809 if ((version != "1.0") && (version != "1.1")) {
1810 getline(inputStream, line);//COMPLEXNAME:<name of the complex box>
1811 char complexboxnameTmp[255];
1812 strcpy(complexboxnameTmp, line.c_str());
1813 result = strtok(complexboxnameTmp, delims);
1814 result = strtok(NULL, delims);
1817 getline(inputStream, line);//PACKAGENAME:<name of the package of the box>
1818 char packagenameTmp[255];
1819 strcpy(packagenameTmp, line.c_str());
1820 result = strtok(packagenameTmp, delims);
1821 result = strtok(NULL, delims);
1822 SetCbPackageName(result);
1825 //-----------------------
1826 //- COMPLEX INPUT PORTS
1827 //-----------------------
1828 getline(inputStream, line);//COMPLEXINPUTS:num
1830 strcpy(inputs, line.c_str());
1831 result = strtok(inputs, delims);
1832 result = strtok(NULL, delims);
1835 std::istringstream inps(result);
1838 for (int i = 0; i < numInputs; i++) {
1840 getline(inputStream, line);//COMPLEX_PORT
1841 getline(inputStream, line);//name
1842 std::string inputPortName(line);
1845 getline(inputStream, line);//xInic:yInic:zInic
1847 strcpy(coord, line.c_str());
1848 result = strtok(coord, delims);//xInic
1849 std::string xInic(result);
1850 result = strtok(NULL, delims);//yInic
1851 std::string yInic(result);
1852 result = strtok(NULL, delims);//zInic
1853 std::string zInic(result);
1855 double xIn, yIn, zIn;
1856 std::istringstream xSt(xInic);
1858 std::istringstream ySt(yInic);
1860 std::istringstream zSt(zInic);
1865 if (zIn==900) zIn=GPOSITION_Z;
1868 getline(inputStream, line);//FIN_COMPLEX_PORT
1870 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
1872 } // for input complex box
1875 //-----------------------
1876 //- COMPLEX OUTPUT PORTS
1877 //-----------------------
1879 getline(inputStream, line);//COMPLEXOUTPUTS:num
1881 strcpy(outputs, line.c_str());
1882 result = strtok(outputs, delims);
1883 result = strtok(NULL, delims);
1886 std::istringstream outps(result);
1887 outps >> numOutputs;
1889 for (int i = 0; i < numOutputs; i++) {
1891 getline(inputStream, line);//COMPLEX_PORT
1892 getline(inputStream, line);//name
1893 std::string outputPortName(line);
1896 getline(inputStream, line);//xInic:yInic:zInic
1898 strcpy(coord, line.c_str());
1899 result = strtok(coord, delims);//xInic
1900 std::string xInic(result);
1901 result = strtok(NULL, delims);//yInic
1902 std::string yInic(result);
1903 result = strtok(NULL, delims);//zInic
1904 std::string zInic(result);
1906 double xIn, yIn, zIn;
1907 std::istringstream xSt(xInic);
1909 std::istringstream ySt(yInic);
1911 std::istringstream zSt(zInic);
1916 if (zIn==900) zIn=GPOSITION_Z;
1919 getline(inputStream, line);//FIN_COMPLEX_PORT
1921 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
1923 } // for output complex box
1928 getline(inputStream, line);//BOXES:num
1930 strcpy(boxes, line.c_str());
1931 result = strtok(boxes, delims);
1932 result = strtok(NULL, delims);
1935 std::istringstream is(result);
1938 for (int i = 0; i < numBoxes; i++) {
1940 getline(inputStream, line);//BOX
1941 getline(inputStream, line);//package:type:name
1943 strcpy(box, line.c_str());
1944 result = strtok(box, delims);//package
1945 std::string package(result);
1946 result = strtok(NULL, delims);//type
1947 std::string type(result);
1948 result = strtok(NULL, delims);//name
1949 std::string name(result);
1951 getline(inputStream, line);//ISEXEC:TRUE|FALSE
1953 strcpy(exec, line.c_str());
1954 result = strtok(exec, delims);//ISEXEC
1955 result = strtok(NULL, delims);//TRUE|FALSE
1956 std::string isExec(result);
1959 getline(inputStream, line);//xInic:yInic:zInic
1961 strcpy(coord, line.c_str());
1962 result = strtok(coord, delims);//xInic
1963 std::string xInic(result);
1964 result = strtok(NULL, delims);//yInic
1965 std::string yInic(result);
1966 result = strtok(NULL, delims);//zInic
1967 std::string zInic(result);
1969 double xIn, yIn, zIn;
1970 std::istringstream xSt(xInic);
1972 std::istringstream ySt(yInic);
1974 std::istringstream zSt(zInic);
1980 if (zIn==900) zIn=GPOSITION_Z;
1985 getline(inputStream, line);//xEnd:yEnd:zEnd
1986 strcpy(coord, line.c_str());
1987 result = strtok(coord, delims);//xEnd
1988 std::string xEnd(result);
1989 result = strtok(NULL, delims);//yEnd
1990 std::string yEnd(result);
1991 result = strtok(NULL, delims);//zEnd
1992 std::string zEnd(result);
1994 double xEn, yEn, zEn;
1995 std::istringstream xEt(xEnd);
1997 std::istringstream yEt(yEnd);
1999 std::istringstream zEt(zEnd);
2004 if (zEn==900) zEn=GPOSITION_Z;
2008 bool boxExecutable = false;
2009 if (isExec == "TRUE") {
2010 boxExecutable = true;
2013 int idBox = createGBlackBox(xIn, yIn, package, type);
2014 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
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);
2033 getline(inputStream, line);//PORT o FIN_BOX
2034 port = line.substr(0, 4);
2037 //EED bbmod->notifyObservers(_idManager);
2042 getline(inputStream, line);//CONNECTIONS:num
2044 strcpy(conns, line.c_str());
2045 result = strtok(conns, delims);
2046 result = strtok(NULL, delims);
2049 std::istringstream isCons(result);
2052 for (int i = 0; i < numConns; i++) {
2054 getline(inputStream, line);//CONNECTION
2055 getline(inputStream, line);//Startbox.PortName:EndBox.PortName
2058 strcpy(connec, line.c_str());
2059 result = strtok(connec, delims);
2060 std::string nameStartBox(result);
2061 result = strtok(NULL, delims);
2062 std::string nameStartPort(result);
2063 result = strtok(NULL, delims);
2064 std::string nameEndBox(result);
2065 result = strtok(NULL, delims);
2066 std::string nameEndPort(result);
2068 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2070 if (version != "1.0") {
2071 //Readding control points of the manualContour
2072 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2073 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2074 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2075 getline(inputStream, line); //NumberOfControlPoints:##
2076 strcpy(conns, line.c_str());
2077 result = strtok(conns, delims);
2078 result = strtok(NULL, delims);
2080 int numberOfControlPoints;
2081 std::istringstream isCons(result);
2082 isCons >> numberOfControlPoints;
2084 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2085 getline(inputStream, line); //XX:YY:ZZ
2087 strcpy(connec, line.c_str());
2090 result = strtok(connec, delims);
2091 std::istringstream isPointX(result);
2093 result = strtok(NULL, delims);
2094 std::istringstream isPointY(result);
2096 result = strtok(NULL, delims);
2097 std::istringstream isPointZ(result);
2102 if (pz==900) pz=GPOSITION_Z;
2105 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2106 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);
2189 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port %s is null. Port name is probably wrong.\n", nameStartPort.c_str());
2193 boxModel = findGBox(nameEndBox);
2194 if (boxModel != NULL) {
2195 endP = boxModel->getInputPort(nameEndPort);
2197 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port %s is null. Port name is probably wrong\n", nameStartPort.c_str(), nameEndPort.c_str());
2202 int idCon = createGConnector(startP);
2203 _worldState = NOTHING_HAPPENS;
2204 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2206 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2207 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2208 tempp->endContourCreation();
2209 conMod->setEndPort(endP);
2210 conView->updateStartEndPoints();
2214 //=========================================================================
2216 bool wxVtkSceneManager::boxExist(std::string boxname) {
2218 std::map<int, GObjectController*>::iterator it;
2219 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2220 GObjectController *cont = it->second;
2221 if (cont->getModel()->getBBTKName() == boxname) {
2228 //=========================================================================
2230 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
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() == GBLACKBOX) {
2236 vect.push_back(cont->getId());
2242 //=========================================================================
2244 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
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() == GCOMPLEXINPUTPORT) {
2250 vect.push_back(cont->getId());
2256 //=========================================================================
2258 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
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() == GCOMPLEXOUTPUTPORT) {
2264 vect.push_back(cont->getId());
2270 //=========================================================================
2272 std::vector<int> wxVtkSceneManager::getConnections() {
2273 std::vector<int> vect;
2274 std::map<int, GObjectController*>::iterator it;
2275 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2276 GObjectController *cont = it->second;
2277 if (cont->getGObjectType() == GCONNECTOR) {
2278 vect.push_back(cont->getId());
2284 //=========================================================================
2286 bool wxVtkSceneManager::isComplexBox() {
2287 return _isComplexBox;
2290 //=========================================================================
2292 void wxVtkSceneManager::setComplexBox(bool val) {
2293 _isComplexBox = val;
2296 //=========================================================================
2298 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2299 //Register the controller of the new object
2300 registerController((InteractorStyleMaracas*) objController);
2301 //Add the object to the objects list
2302 int newId = _contLastId;//_controllers.size();
2303 objController->setId(newId);
2304 _controllers[newId] = objController;
2305 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2310 //=========================================================================
2312 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2314 std::map<int, int> oldIdNewIdBoxes;
2315 std::vector<int> connections;
2317 std::vector<int> newBoxesID;
2319 std::map<int, GObjectController*>::iterator it;
2320 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2321 GObjectController *cont = it->second;
2322 int type = cont->getGObjectType();
2324 if (type == GBLACKBOX) {
2326 double xInic, yInic, zInic;
2327 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2328 copyBox->getInicPoint(xInic, yInic, zInic);
2329 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2330 copyBox->getBBTKType());
2332 int idcB = copyBox->getObjectId();
2333 oldIdNewIdBoxes[idcB] = idBox;
2334 cont = _controllers[idBox];
2335 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2336 newbox->setInicPoint(xInic, yInic, zInic);
2337 int num = newbox->getNumInputPorts();
2338 for (int j = 0; j < num; j++) {
2339 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2341 newbox->move(xInic + 20, yInic + 20, zInic);
2342 newbox->notifyObservers(_idManager);
2343 newBoxesID.push_back(newbox->getObjectId());
2345 } else if (type == GCONNECTOR) {
2346 int idCon = cont->getId();
2347 connections.push_back(idCon);
2352 for (int i = 0; i < (int) connections.size(); i++) {
2353 int objId = connections[i];
2354 GObjectController *cont = objectsMap[objId];
2355 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2357 GPortModel* startPort = connectModel->getStartPort();
2358 int startPortIndex = startPort->getPosInBox();
2359 GPortModel* endPort = connectModel->getEndPort();
2360 int endPortIndex = endPort->getPosInBox();
2362 GBlackBoxModel* startPortParentBox =
2363 (GBlackBoxModel*) startPort->getParentBox();
2364 GBlackBoxModel* endPortParentBox =
2365 (GBlackBoxModel*) endPort->getParentBox();
2367 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2368 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2370 GBlackBoxModel* newStartBox =
2371 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2372 GBlackBoxModel* newEndBox =
2373 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2375 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2376 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2378 // Creates connection
2379 int idCon = createGConnector(newStartPort);
2380 GConnectorController *tempp =
2381 (GConnectorController*) _controllers[idCon];
2382 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2383 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2384 tempp->endContourCreation();
2385 conMod->setEndPort(newEndPort);
2386 conView->updateStartEndPoints();
2389 /// the new selected boxes are the duplicate ones
2391 UnSelectBlackBoxes();
2392 for (int i = 0; i < newBoxesID.size(); i++) {
2393 _selectedObjects.push_back(newBoxesID.at(i));
2396 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2397 int id = _selectedObjects[i];
2398 GObjectController* cont = _controllers[id];
2400 cont->getView()->setState(SELECTED);
2401 cont->getModel()->notifyObservers(_idManager);
2407 //=========================================================================
2409 int wxVtkSceneManager::getNumSelectedObjects() {
2410 return _selectedObjects.size();
2413 //=========================================================================
2415 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2416 std::map<int, GObjectController*> mapSelected;
2418 std::map<int, GObjectController*>::iterator it;
2419 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2420 GObjectController *cont = it->second;
2421 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2423 mapSelected[cont->getId()] = cont;
2427 std::map<int, GObjectController*>::iterator it2;
2428 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2429 GObjectController *cont = it2->second;
2430 if (cont->getGObjectType() == GCONNECTOR) {
2431 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2432 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2433 GBoxModel* startPortParentBox =
2434 cmod->getStartPort()->getParentBox();
2436 std::map<int, GObjectController*>::iterator iterOBJ1 =
2437 mapSelected.find(startPortParentBox->getObjectId());
2438 std::map<int, GObjectController*>::iterator iterOBJ2 =
2439 mapSelected.find(endPortParentBox->getObjectId());
2441 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2442 int ID = cont->getId();
2443 mapSelected[ID] = cont;
2450 //=========================================================================
2452 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2454 std::map<int, int> oldIdNewIdBoxes;
2455 std::vector<int> connections;
2457 std::map<int, GObjectController*>::iterator it;
2458 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2459 GObjectController *cont = it->second;
2460 int type = cont->getGObjectType();
2462 if (type == GBLACKBOX) {
2464 double xInic, yInic, zInic;
2465 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2466 copyBox->getInicPoint(xInic, yInic, zInic);
2467 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2468 copyBox->getBBTKType());
2470 int idcB = copyBox->getObjectId();
2471 oldIdNewIdBoxes[idcB] = idBox;
2472 cont = _controllers[idBox];
2473 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2474 newbox->setInicPoint(xInic, yInic, zInic);
2475 int num = newbox->getNumInputPorts();
2476 for (int j = 0; j < num; j++) {
2477 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2479 newbox->notifyObservers(_idManager);
2480 } else if (type == GCONNECTOR) {
2481 int idCon = cont->getId();
2482 connections.push_back(idCon);
2487 for (int i = 0; i < (int) connections.size(); i++) {
2488 int objId = connections[i];
2489 GObjectController *cont = objectsMap[objId];
2490 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2492 GPortModel* startPort = connectModel->getStartPort();
2493 int startPortIndex = startPort->getPosInBox();
2494 GPortModel* endPort = connectModel->getEndPort();
2495 int endPortIndex = endPort->getPosInBox();
2497 GBlackBoxModel* startPortParentBox =
2498 (GBlackBoxModel*) startPort->getParentBox();
2499 GBlackBoxModel* endPortParentBox =
2500 (GBlackBoxModel*) endPort->getParentBox();
2502 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2503 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2505 GBlackBoxModel* newStartBox =
2506 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2507 GBlackBoxModel* newEndBox =
2508 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2510 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2511 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2513 // Creates connection
2514 int idCon = createGConnector(newStartPort);
2515 GConnectorController *tempp =
2516 (GConnectorController*) _controllers[idCon];
2517 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2518 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2519 tempp->endContourCreation();
2520 conMod->setEndPort(newEndPort);
2521 conView->updateStartEndPoints();
2524 std::map<int, int>::iterator itIds;
2525 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2526 int idOld = itIds->first;
2527 int idNew = itIds->second;
2529 GBlackBoxModel* oldBox =
2530 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2531 GBlackBoxModel* newBox =
2532 (GBlackBoxModel*) _controllers[idNew]->getModel();
2534 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2535 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2536 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2537 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2539 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2541 //EED int toCreate=-1;
2542 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2543 if (oldInputConnections[k] == newInputConnections[l]) {
2548 if (exist == false) {
2549 //Create complex input
2550 int posInBox = oldInputConnections[k];
2551 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2552 std::string inputPortName = inputPort->getBBTKName();
2553 int idInputPort = createGComplexBoxInputPort(inputPortName);
2554 GObjectController *cont = _controllers[idInputPort];
2555 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2556 double xIn, yIn, zIn;
2557 inputPort->getInicPoint(xIn, yIn, zIn);
2559 cbmod->setInicPoint(xIn, yIn, zIn);
2560 cbmod->notifyObservers(_idManager);
2562 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2564 // Creates connection
2565 int idCon = createGConnector(cbmod->getOutputPort(0));
2566 GConnectorController *tempp =
2567 (GConnectorController*) _controllers[idCon];
2568 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2569 vtkGConnectorView *conView =
2570 (vtkGConnectorView*) tempp->getView();
2571 tempp->endContourCreation();
2572 conMod->setEndPort(inputPortEnd);
2573 conView->updateStartEndPoints();
2579 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2581 //EED int toCreate=-1;
2582 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2583 if (oldOutputConnections[k] == newOutputConnections[l]) {
2588 if (exist == false) {
2589 //Create complex output
2590 int posInBox = oldOutputConnections[k];
2591 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2592 std::string outputPortName = outputPort->getBBTKName();
2593 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2594 GObjectController *cont = _controllers[idOutputPort];
2595 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2596 double xIn, yIn, zIn;
2597 outputPort->getInicPoint(xIn, yIn, zIn);
2599 cbmod->setInicPoint(xIn, yIn, zIn);
2600 cbmod->notifyObservers(_idManager);
2602 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2604 // Creates connection
2605 int idCon = createGConnector(outputPortEnd);
2606 GConnectorController *tempp =
2607 (GConnectorController*) _controllers[idCon];
2608 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2609 vtkGConnectorView *conView =
2610 (vtkGConnectorView*) tempp->getView();
2611 tempp->endContourCreation();
2612 conMod->setEndPort(cbmod->getInputPort(0));
2613 conView->updateStartEndPoints();
2623 //=========================================================================
2624 void wxVtkSceneManager::SetCbName(std::string cbName) {
2626 if (_cbName == "") {
2627 _cbName = "<complex box name>";
2631 //=========================================================================
2632 std::string wxVtkSceneManager::GetCbName() {
2636 //=========================================================================
2637 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2638 _cbPackageName = packagename;
2639 if (_cbPackageName == "") {
2640 _cbPackageName = "<package name of the complex box>";
2644 //=========================================================================
2645 std::string wxVtkSceneManager::GetCbPackageName() {
2646 return _cbPackageName;
2649 //=========================================================================
2650 void wxVtkSceneManager::SetAuthor(std::string author) {
2652 if (_Author == "") {
2653 _Author = "<author of the box>";
2657 //=========================================================================
2658 std::string wxVtkSceneManager::GetAuthor() {
2662 //=========================================================================
2663 void wxVtkSceneManager::SetCategory(std::string category) {
2664 _Category = category;
2665 if (_Category == "") {
2666 _Category = "<category of the box>";
2670 //=========================================================================
2671 std::string wxVtkSceneManager::GetCategory() {
2675 //=========================================================================
2676 void wxVtkSceneManager::SetDescription(std::string description) {
2677 _Description = description;
2678 if (_Description == "") {
2679 _Description = "<description of the box>";
2683 //=========================================================================
2684 std::string wxVtkSceneManager::GetDescription() {
2685 return _Description;
2688 //=========================================================================
2691 void wxVtkSceneManager::printAll(int com , int sta ){
2693 int tmpState = sta ;
2694 if ( tmpState == NOTHING_HAPPENS ) {
2695 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2697 if ( tmpState == HIGHLIGHTED ) {
2698 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2700 if ( tmpState == POSSIBLE_CONNECTION ) {
2701 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2703 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2704 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2706 if ( tmpState == CLICKED ) {
2707 std::cout << "CONTROLER STATE---->CLICKED\n" ;
2709 if ( tmpState == DRAG ) {
2710 std::cout << "CONTROLER STATE---->DRAG\n" ;
2712 if ( tmpState == SELECTED ) {
2713 std::cout << "CONTROLER STATE---->SELECTED\n" ;
2715 if ( tmpState == CREATING_CONTOUR ) {
2716 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2722 if ( command == INIT_CREATION_CONTOUR ) {
2723 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2725 if ( command == FIN_CREATION_CONTOUR ) {
2726 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2728 if ( command == ADD_TO_SELECTED ) {
2729 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2731 if ( command == DRAG_OBJECTS ) {
2732 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2734 if ( command == EDIT_BLACKBOX ) {
2735 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
2737 if ( command == REMOVE_FROM_SELECTED ) {
2738 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
2744 } // EO namespace bbtk