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()
761 bool okStatusMessage = false;
762 bool okPortMessage = false;
763 wxVTKRenderWindowInteractor *wxVTKiren;
764 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
765 wxVTKiren->GetEventPosition(X, Y);
767 if (_worldState == DRAG_OBJECTS) {
768 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
769 int id = _selectedObjects[i];
770 GObjectController* cont = _controllers[id];
771 if (_startDragging) {
772 cont->getView()->setStartDragging(true);
774 cont->getView()->moveObject(X, Y);
775 cont->getView()->setState(DRAG);
776 cont->getModel()->notifyObservers(_idManager);
779 std::map<int, GObjectController*>::iterator it;
781 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
782 GObjectController *desc = it->second;
783 if (desc->getGObjectType() == GCONNECTOR) {
784 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
785 vconn->updateStartEndPoints();
789 _startDragging = false;
791 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
792 std::map<int, GObjectController*>::iterator it;
794 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
795 GObjectController *desc = it->second;
796 int type = desc->getGObjectType();
797 int state = desc->getView()->getState();
798 desc->getModel()->getCenter(px, py, pz);
801 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
804 okStatusMessage = true;
805 updateStatusBar(desc->getStatusText());
806 if (type == GBLACKBOX)
808 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
809 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
814 okPortMessage = true;
816 _textActor->SetInput(desc->getStatusText().c_str());
817 _textActor->SetScale(0.1);
818 _textActor->SetPosition(px - 25, py + 1, pz + 2);
823 _fillObjectActor->SetScale(1);
824 _fillObjectActor->GetProperty()->SetOpacity(0.50);
825 _fillObjectActor->SetPosition(px, py, 1);
826 _aPolygonMapper->Modified();
829 } // for controllers it
832 if (okStatusMessage == false)
837 if (okPortMessage == false)
839 _textActor->SetScale(0.0001);
840 _fillObjectActor->SetScale(0.0001);
845 //=========================================================================
847 bool wxVtkSceneManager::OnLeftButtonDown()
849 if (_worldState == INIT_CREATION_CONTOUR)
851 bool isOverPort = false;
852 std::map<int, GObjectController*>::iterator it;
853 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
855 GObjectController *desc = it->second;
856 if (desc->getGObjectType() == GPORT)
858 GPortModel *portmod = (GPortModel*) desc->getModel();
859 vtkGObjectView *portView = desc->getView();
860 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
865 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
867 portView->setState( HIGHLIGHTED);
874 if (isOverPort == false)
877 UnSelectBlackBoxes();
881 } else { //_worldState
883 _worldState = DRAG_OBJECTS;
884 _startDragging = true;
886 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
887 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
888 ctrlkey = ctrlkey + shiftkey;
890 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
893 int state = cont->getView()->getState();
894 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
895 UnSelectBlackBoxes();
898 UnSelectBlackBoxes(); // EED 12/07/2012
900 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
901 int id = _selectedObjects[i];
902 GObjectController *cont = _controllers[id];
903 cont->getView()->setState(DRAG);
904 cont->getModel()->notifyObservers(_idManager);
906 } // if _selectedObjects.size
912 //=========================================================================
914 bool wxVtkSceneManager::OnLeftButtonUp()
916 if (_worldState == DRAG_OBJECTS) {
917 _worldState = NOTHING_HAPPENS;
919 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
920 int id = _selectedObjects[i];
921 GObjectController* cont = _controllers[id];
922 cont->getView()->setState(SELECTED);
923 cont->getModel()->notifyObservers(_idManager);
929 //=========================================================================
930 void wxVtkSceneManager::CancelConnection()
932 if (_worldState == INIT_CREATION_CONTOUR)
934 _worldState = NOTHING_HAPPENS;
935 //int lastId = _controllers.size()-1;
937 GConnectorController *connector =
938 (GConnectorController*) _controllers[_idConnectionInCreation];
939 connector->removeFromScene();
940 unregisterController(connector);
941 _controllers.erase(_idConnectionInCreation);
943 std::map<int, GObjectController*>::iterator it;
944 for (it = _controllers.begin(); it != _controllers.end(); ++it)
946 GObjectController *desc = it->second;
947 desc->SetActive(true);
948 desc->getView()->setState(NOTHING_HAPPENS);
949 desc->getModel()->notifyObservers(_idManager);
954 //=========================================================================
956 bool wxVtkSceneManager::OnRightButtonUp() {
957 if (_worldState == INIT_CREATION_CONTOUR) {
960 UnSelectBlackBoxes();
966 bool wxVtkSceneManager::OnMiddleButtonDown() {
969 this->_vtkInteractorStyleBaseView->StartPan();
974 bool wxVtkSceneManager::OnMiddleButtonUp() {
977 this->_vtkInteractorStyleBaseView->EndPan();
984 //=========================================================================
986 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
987 GObjectController *result = NULL;
989 wxVTKRenderWindowInteractor *wxVTKiren;
991 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
992 wxVTKiren->GetEventPosition(X, Y);
994 std::map<int, GObjectController*>::iterator it;
996 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
997 GObjectController *cont = it->second;
998 int type = cont->getGObjectType();
1000 if (cont->getView()->isPointInside(X, Y) == true) {
1001 if (type == GBLACKBOX) {
1004 } // if isPointInside
1009 //=========================================================================
1010 void wxVtkSceneManager::UnSelectBlackBoxes() {
1011 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1012 int id = _selectedObjects[i];
1013 GObjectController* control = _controllers[id];
1014 control->getView()->setState(NOTHING_HAPPENS);
1015 control->getModel()->notifyObservers(_idManager);
1016 }// for _selectedObjects
1017 _selectedObjects.clear();
1020 //=========================================================================
1021 bool wxVtkSceneManager::OnLeftDClick() {
1022 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1024 UnSelectBlackBoxes();
1025 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1031 wxVTKRenderWindowInteractor *wxVTKiren;
1032 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1033 wxVTKiren->GetEventPosition(X,Y);
1035 std::map<int, GObjectController*>::iterator it;
1037 bool clickOnObject = false;
1039 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1041 GObjectController *cont = it->second;
1042 int type = cont->getGObjectType();
1044 if(cont->getView()->isPointInside(X,Y))
1048 for (int i=0; i< (int)_selectedObjects.size(); i++)
1050 int id = _selectedObjects[i];
1051 GObjectController* control = _controllers[id];
1052 control->getView()->setState(NOTHING_HAPPENS);
1054 _selectedObjects.clear();
1056 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1057 _parent->editBlackBox(bbmodel);
1059 clickOnObject = true;
1063 if(clickOnObject==false)
1065 //_parent->editDiagramParameters(this);
1071 //=========================================================================
1073 bool wxVtkSceneManager::OnChar()
1077 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1078 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1080 // KeyCode 127 : Delete Key
1081 // KeyCode 8 : Backspace Key
1082 if (keyCode == 8 || keyCode == 127)
1084 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1086 int id = _selectedObjects[i];
1087 std::map<int, GObjectController*>::iterator it;
1088 it = _controllers.find(id);
1089 if (it != _controllers.end())
1091 oktmp = deleteObject(id);
1094 }// for selected objects
1095 if (ok) _selectedObjects.clear();
1096 _parent->saveTempandUpdate("delete object");
1101 if((keyCode==0) && (ctrlkey==1)) {
1106 if(_selectedObjects.size()){
1107 std::cout<<"objects to copy :";
1108 for(int i=0;i<_selectedObjects.size();i++)
1110 std::cout<<_selectedObjects.at(i)<<" ";
1112 DuplicateObjects(getSelectedObjects());
1114 std::cout<<"No objects to copy\n";
1115 } // _selectedObjects.size
1121 //=========================================================================
1123 void wxVtkSceneManager::AddControlerToBeRemove(
1124 std::vector<int> *controllersToRemove, int id) {
1128 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1129 if (id == (*controllersToRemove)[i]) {
1135 controllersToRemove->push_back(id);
1140 //=========================================================================
1142 bool wxVtkSceneManager::deleteObject(int id)
1145 GObjectController *control = _controllers[id];
1146 std::vector<int> controllersToRemove;
1147 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1148 == GCOMPLEXINPUTPORT || control->getGObjectType()
1149 == GCOMPLEXOUTPUTPORT) {
1150 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1151 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1153 bool boxConnected = false;
1155 // Add box input controllers to be removed
1156 for (int i = 0; i < (int) inputs.size(); i++) {
1157 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1158 if (inputs[i]->isConnected()) {
1159 boxConnected = true;
1163 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1165 // Add box output controllers to be removed
1166 for (int i = 0; i < (int) outputs.size(); i++) {
1167 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1168 if (outputs[i]->isConnected()) {
1169 boxConnected = true;
1173 // Add connection controllers to be removed
1174 std::map<int, GObjectController*>::iterator it;
1175 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1176 GObjectController *cont = it->second;
1177 int type = cont->getGObjectType();
1178 if (type == GCONNECTOR) {
1179 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1180 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1182 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1184 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1186 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1191 // Add box controller to be removed
1192 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1193 } else if (control->getGObjectType() == GCONNECTOR) {
1194 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1195 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1197 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1198 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1200 gconnectorcontroler->getManualContourController()->OnChar();
1205 std::map<int, GObjectController*>::iterator it;
1207 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1208 int key = controllersToRemove[i];
1209 it = _controllers.find(key);
1210 GObjectController *cont = _controllers[key];
1212 cont->removeFromScene();
1213 unregisterController((InteractorStyleMaracas*) cont);
1214 _controllers.erase(it);
1222 //=========================================================================
1224 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1225 std::string boxName) {
1226 _parent->displayBlackBoxInfo(packageName, boxName);
1229 //=========================================================================
1231 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1232 _parent->updateStatusBar(textStatus);
1235 //=========================================================================
1236 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1237 std::string result = "";
1238 if (withLineNumber == true) {
1240 stringstream StrStream;
1242 std::string strValue = StrStream.str();
1245 } else if (value < 100) {
1249 result += strValue + ": ";
1253 //=========================================================================
1255 bool wxVtkSceneManager::MakeBoxExecutable() {
1256 std::map<int, GObjectController*> selected = getSelectedObjects();
1257 if( selected.empty() )
1260 std::map<int, GObjectController*>::iterator it;
1261 for (it = selected.begin(); it != selected.end(); ++it) {
1262 GObjectController* lastSelected = it->second;
1264 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1265 GBlackBoxModel *bbmodel =
1266 (GBlackBoxModel*) lastSelected->getModel();
1267 view->setState(HIGHLIGHTED);
1268 if (bbmodel->isExecutable()) {
1269 bbmodel->setExecutable(false);
1271 bbmodel->setExecutable(true);
1273 bbmodel->notifyObservers(lastSelected->getId());
1281 //=========================================================================
1283 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1284 bool existsExec = false;
1286 std::vector<std::string> packages;
1287 std::vector<int> boxes;
1288 std::vector<int> connections;
1289 std::vector<int> execBoxes;
1291 std::map<int, GObjectController*>::iterator it;
1293 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1294 GObjectController *desc = it->second;
1295 int type = desc->getGObjectType();
1297 if (type == GBLACKBOX) {
1298 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1300 std::string pkg = mod->getBBTKPackage();
1301 bool existsPkg = false;
1302 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1303 if (packages[t] == pkg) {
1308 packages.push_back(pkg);
1311 boxes.push_back(it->first);
1312 if (mod->isExecutable()) {
1313 execBoxes.push_back(it->first);
1316 } else if (type == GCONNECTOR) {
1317 connections.push_back(it->first);
1322 std::string script = "";
1323 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1324 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1325 script += LineNumber(wln, lnNmbr) + "\n";
1327 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1328 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1330 for (i = 0; i < (int) packages.size(); i++) {
1331 script += LineNumber(wln, lnNmbr);
1332 script += "include ";
1333 script += packages[i];
1337 script += LineNumber(wln, lnNmbr);
1342 script += LineNumber(wln, lnNmbr);
1343 script += "author \"";
1347 script += LineNumber(wln, lnNmbr);
1348 script += "description \"";
1349 script += _Description;
1352 script += LineNumber(wln, lnNmbr);
1353 script += "category \"";
1354 script += _Category;
1357 script += LineNumber(wln, lnNmbr);
1360 // script+="include std\n"; // JPR
1362 for (i = 0; i < (int) boxes.size(); i++) {
1363 script += LineNumber(wln, lnNmbr);
1366 GObjectController *control = _controllers[id];
1367 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1369 script += model->getBBTKType();
1371 script += model->getBBTKName();
1374 std::vector<GPortModel*> inputs = model->getInputPorts();
1375 for (int j = 0; j < (int) inputs.size(); j++) {
1376 GPortModel* inputPort = inputs[j];
1377 if (inputPort->isValueSet()) {
1378 script += LineNumber(wln, lnNmbr);
1380 script += model->getBBTKName();
1382 script += inputPort->getBBTKName();
1384 script += inputPort->getValue();
1389 script += LineNumber(wln, lnNmbr);
1394 script += LineNumber(wln, lnNmbr);
1397 for (i = 0; i < (int) connections.size(); i++) {
1398 script += LineNumber(wln, lnNmbr);
1399 script += "connect ";
1400 int id = connections[i];
1401 GObjectController *control = _controllers[id];
1402 GConnectorModel *model = (GConnectorModel*) control->getModel();
1404 //Start Connection info
1405 GPortModel *start = model->getStartPort();
1406 script += start->getParentBox()->getBBTKName();
1408 script += start->getBBTKName();
1412 //End Connection info
1413 GPortModel *end = model->getEndPort();
1414 script += end->getParentBox()->getBBTKName();
1416 script += end->getBBTKName();
1421 script += LineNumber(wln, lnNmbr);
1423 for (i = 0; i < (int) execBoxes.size(); i++) {
1424 script += LineNumber(wln, lnNmbr);
1426 int id = execBoxes[i];
1427 GObjectController *control = _controllers[id];
1428 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1430 script += model->getBBTKName();
1439 //=========================================================================
1441 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1442 std::vector<std::string> packages;
1443 std::vector<int> boxes;
1444 std::vector<int> connections;
1445 std::vector<int> execBoxes;
1447 std::map<int, GObjectController*>::iterator it;
1449 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1450 GObjectController *desc = it->second;
1451 int type = desc->getGObjectType();
1453 if (type == GBLACKBOX) {
1454 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1456 std::string pkg = mod->getBBTKPackage();
1457 bool existsPkg = false;
1458 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1459 if (packages[t] == pkg) {
1464 packages.push_back(pkg);
1467 boxes.push_back(it->first);
1468 if (mod->isExecutable()) {
1469 execBoxes.push_back(it->first);
1471 } else if (type == GCONNECTOR) {
1472 connections.push_back(it->first);
1476 std::string script = "";
1478 script += "include std\n"; // EED
1479 script += "include itkvtk\n"; // EED
1481 for (i = 0; i < (int) packages.size(); i++) {
1482 script += "include ";
1483 script += packages[i];
1488 // Definition of a complex box
1489 script += "define ";
1490 script += _cbName + " " + _cbPackageName;
1494 script += "author \"";
1498 script += "description \"";
1499 script += _Description;
1503 script += "category \"";
1504 script += _Category;
1509 for (i = 0; i < (int) boxes.size(); i++) {
1512 GObjectController *control = _controllers[id];
1513 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1515 script += model->getBBTKType();
1517 script += model->getBBTKName();
1520 std::vector<GPortModel*> inputs = model->getInputPorts();
1521 for (int j = 0; j < (int) inputs.size(); j++) {
1522 GPortModel* inputPort = inputs[j];
1523 if (inputPort->isValueSet()) {
1525 script += model->getBBTKName();
1527 script += inputPort->getBBTKName();
1529 script += inputPort->getValue();
1537 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1539 std::string complexInputs = "";
1540 std::string complexOutputs = "";
1543 for (i = 0; i < (int) connections.size(); i++) {
1544 int id = connections[i];
1545 GObjectController *control = _controllers[id];
1546 GConnectorModel *model = (GConnectorModel*) control->getModel();
1549 GPortModel *start = model->getStartPort();
1550 GBoxModel *startBox = start->getParentBox();
1552 GPortModel *end = model->getEndPort();
1553 GBoxModel *endBox = end->getParentBox();
1555 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1556 complexInputs += "input ";
1557 complexInputs += startBox->getBBTKName();
1559 complexInputs += " ";
1560 complexInputs += endBox->getBBTKName();
1561 complexInputs += ".";
1562 complexInputs += end->getBBTKName();
1564 complexInputs += " ";
1565 complexInputs += "\" \"";
1567 complexInputs += "\n";
1568 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1569 complexOutputs += "output ";
1570 complexOutputs += endBox->getBBTKName();
1572 complexOutputs += " ";
1573 complexOutputs += startBox->getBBTKName();
1574 complexOutputs += ".";
1575 complexOutputs += start->getBBTKName();
1577 complexOutputs += " ";
1578 complexOutputs += "\" \"";
1580 complexOutputs += "\n";
1582 script += "connect ";
1583 script += startBox->getBBTKName();
1585 script += start->getBBTKName();
1589 //End Connection info
1590 script += endBox->getBBTKName();
1592 script += end->getBBTKName();
1600 for (i = 0; i < (int) execBoxes.size(); i++) {
1602 int id = execBoxes[i];
1603 GObjectController *control = _controllers[id];
1604 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1606 script += model->getBBTKName();
1611 script += "# Complex input ports\n";
1612 script += complexInputs;
1615 script += "# Complex output ports\n";
1616 script += complexOutputs;
1619 script += "endefine";
1625 //=========================================================================
1627 void wxVtkSceneManager::deleteAllBoxes() {
1628 std::map<int, GObjectController*>::iterator it;
1629 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1630 GObjectController *cont = it->second;
1631 cont->removeFromScene();
1632 unregisterController((InteractorStyleMaracas*) cont);
1634 _selectedObjects.clear();
1635 _controllers.clear();
1638 //=========================================================================
1641 void wxVtkSceneManager::refresh() {
1642 _baseView->Refresh();
1644 //=========================================================================
1646 void wxVtkSceneManager::refreshScene() {
1647 _baseView->RefreshView();
1650 //=========================================================================
1652 void wxVtkSceneManager::centerView() {
1654 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1655 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1656 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1657 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1660 //=========================================================================
1662 void wxVtkSceneManager::saveDiagram(std::string &content) {
1665 content += "CATEGORY:";
1666 content += GetCategory();
1669 content += "DESCRIPTION:";
1670 content += GetDescription();
1673 content += "AUTHOR:";
1674 content += GetAuthor();
1677 //Print info IF COMPLEX BOX
1678 content += "COMPLEXBOX:";
1679 if (_isComplexBox) {
1680 content += "TRUE\n";
1682 content += "COMPLEXBOXNAME:";
1683 content += GetCbName();
1686 content += "PACKAGENAME:";
1687 content += GetCbPackageName();
1690 //Print info complex input ports
1691 std::vector<int> inputs = getComplexInputPorts();
1692 int insize = inputs.size();
1693 content += "COMPLEXINPUTS:";
1694 sprintf(buffer, "%d", insize);
1698 for (int i = 0; i < insize; i++) {
1700 GObjectController *cont = _controllers[id];
1701 cont->getModel()->save(content);
1704 //Print info complex output ports
1705 std::vector<int> outputs = getComplexOutputPorts();
1706 int outsize = outputs.size();
1707 content += "COMPLEXOUTPUTS:";
1708 sprintf(buffer, "%d", outsize);
1712 for (int i = 0; i < outsize; i++) {
1713 int id = outputs[i];
1714 GObjectController *cont = _controllers[id];
1715 cont->getModel()->save(content);
1719 content += "FALSE\n";
1723 std::vector<int> boxes = getBlackBoxes();
1724 int bsize = boxes.size();
1725 content += "BOXES:";
1726 sprintf(buffer, "%d", bsize);
1730 for (int i = 0; i < bsize; i++) {
1732 GObjectController *cont = _controllers[id];
1733 cont->getModel()->save(content);
1737 std::vector<int> connections = getConnections();
1738 int csize = connections.size();
1739 content += "CONNECTIONS:";
1740 sprintf(buffer, "%d", csize);
1744 for (int i = 0; i < csize; i++) {
1745 int id = connections[i];
1746 GObjectController *cont = _controllers[id];
1747 cont->getModel()->save(content);
1752 //=========================================================================
1753 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1755 getline(inputStream, line,'\n');
1756 int size = line.length();
1757 printf(" wxVtkSceneManager::getCleanLine Start %d %s\n",size, line.c_str() );
1760 if ( line[ size-1 ]==13 )
1762 line.erase(size-1,1);
1765 printf(" wxVtkSceneManager::getCleanLine End\n", line.c_str() );
1768 //=========================================================================
1769 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1771 printf("wxVtkSceneManager::loadDiagram Start\n");
1773 std::string version = "<void>";
1774 std::string line = "";
1775 char delims[] = ":";
1776 char *result = NULL;
1778 printf("wxVtkSceneManager::loadDiagram 1\n");
1779 getCleanLine(inputStream, line);
1780 printf("wxVtkSceneManager::loadDiagram 2 %s\n",line.c_str());
1783 while (!inputStream.eof()) {
1784 if (line == "" || line[0] == '#') {
1786 getCleanLine(inputStream, line);
1787 printf("wxVtkSceneManager::loadDiagram line> %s\n",line.c_str());
1789 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1790 version = line.substr(18, 3);
1792 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1793 version = line.substr(18, 3);
1795 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1796 version = line.substr(18, 3);
1798 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1799 version = line.substr(18, 3);
1801 } else if (line == "APP_START") {
1810 if ((version != "1.0") && (version != "1.1")) {
1811 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1812 char categoryTmp[30];
1813 strcpy(categoryTmp, line.c_str());
1814 result = strtok(categoryTmp, delims);
1815 result = strtok(NULL, delims);
1816 SetCategory(result);
1818 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1819 char descriptionTmp[1024];
1820 strcpy(descriptionTmp, line.c_str());
1821 result = strtok(descriptionTmp, delims);
1822 result = strtok(NULL, delims);
1823 SetDescription(result);
1825 getCleanLine(inputStream, line);//AUTHOR:<author>
1826 char authorTmp[255];
1827 strcpy(authorTmp, line.c_str());
1828 result = strtok(authorTmp, delims);
1829 result = strtok(NULL, delims);
1834 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1835 char complexTmp[30];
1836 strcpy(complexTmp, line.c_str());
1837 result = strtok(complexTmp, delims);
1838 result = strtok(NULL, delims);
1839 std::string isComplexBox(result);
1841 if (isComplexBox == "TRUE") {
1842 _isComplexBox = true;
1844 if ((version != "1.0") && (version != "1.1")) {
1845 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
1846 char complexboxnameTmp[255];
1847 strcpy(complexboxnameTmp, line.c_str());
1848 result = strtok(complexboxnameTmp, delims);
1849 result = strtok(NULL, delims);
1852 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
1853 char packagenameTmp[255];
1854 strcpy(packagenameTmp, line.c_str());
1855 result = strtok(packagenameTmp, delims);
1856 result = strtok(NULL, delims);
1857 SetCbPackageName(result);
1860 //-----------------------
1861 //- COMPLEX INPUT PORTS
1862 //-----------------------
1863 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
1865 strcpy(inputs, line.c_str());
1866 result = strtok(inputs, delims);
1867 result = strtok(NULL, delims);
1870 std::istringstream inps(result);
1873 for (int i = 0; i < numInputs; i++) {
1875 getCleanLine(inputStream, line);//COMPLEX_PORT
1876 getCleanLine(inputStream, line);//name
1877 std::string inputPortName(line);
1880 getCleanLine(inputStream, line);//xInic:yInic:zInic
1882 strcpy(coord, line.c_str());
1883 result = strtok(coord, delims);//xInic
1884 std::string xInic(result);
1885 result = strtok(NULL, delims);//yInic
1886 std::string yInic(result);
1887 result = strtok(NULL, delims);//zInic
1888 std::string zInic(result);
1890 double xIn, yIn, zIn;
1891 std::istringstream xSt(xInic);
1893 std::istringstream ySt(yInic);
1895 std::istringstream zSt(zInic);
1900 if (zIn==900) zIn=GPOSITION_Z;
1903 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
1905 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
1907 } // for input complex box
1910 //-----------------------
1911 //- COMPLEX OUTPUT PORTS
1912 //-----------------------
1914 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
1916 strcpy(outputs, line.c_str());
1917 result = strtok(outputs, delims);
1918 result = strtok(NULL, delims);
1921 std::istringstream outps(result);
1922 outps >> numOutputs;
1924 for (int i = 0; i < numOutputs; i++) {
1926 getCleanLine(inputStream, line);//COMPLEX_PORT
1927 getCleanLine(inputStream, line);//name
1928 std::string outputPortName(line);
1931 getCleanLine(inputStream, line);//xInic:yInic:zInic
1933 strcpy(coord, line.c_str());
1934 result = strtok(coord, delims);//xInic
1935 std::string xInic(result);
1936 result = strtok(NULL, delims);//yInic
1937 std::string yInic(result);
1938 result = strtok(NULL, delims);//zInic
1939 std::string zInic(result);
1941 double xIn, yIn, zIn;
1942 std::istringstream xSt(xInic);
1944 std::istringstream ySt(yInic);
1946 std::istringstream zSt(zInic);
1951 if (zIn==900) zIn=GPOSITION_Z;
1954 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
1956 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
1958 } // for output complex box
1963 getCleanLine(inputStream, line);//BOXES:num
1965 strcpy(boxes, line.c_str());
1966 result = strtok(boxes, delims);
1967 result = strtok(NULL, delims);
1970 std::istringstream is(result);
1973 for (int i = 0; i < numBoxes; i++) {
1975 getCleanLine(inputStream, line);//BOX
1976 getCleanLine(inputStream, line);//package:type:name
1978 strcpy(box, line.c_str());
1979 result = strtok(box, delims);//package
1980 std::string package(result);
1981 result = strtok(NULL, delims);//type
1982 std::string type(result);
1983 result = strtok(NULL, delims);//name
1984 std::string name(result);
1986 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
1988 strcpy(exec, line.c_str());
1989 result = strtok(exec, delims);//ISEXEC
1990 result = strtok(NULL, delims);//TRUE|FALSE
1991 std::string isExec(result);
1994 getCleanLine(inputStream, line);//xInic:yInic:zInic
1996 strcpy(coord, line.c_str());
1997 result = strtok(coord, delims);//xInic
1998 std::string xInic(result);
1999 result = strtok(NULL, delims);//yInic
2000 std::string yInic(result);
2001 result = strtok(NULL, delims);//zInic
2002 std::string zInic(result);
2004 double xIn, yIn, zIn;
2005 std::istringstream xSt(xInic);
2007 std::istringstream ySt(yInic);
2009 std::istringstream zSt(zInic);
2015 if (zIn==900) zIn=GPOSITION_Z;
2020 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2021 strcpy(coord, line.c_str());
2022 result = strtok(coord, delims);//xEnd
2023 std::string xEnd(result);
2024 result = strtok(NULL, delims);//yEnd
2025 std::string yEnd(result);
2026 result = strtok(NULL, delims);//zEnd
2027 std::string zEnd(result);
2029 double xEn, yEn, zEn;
2030 std::istringstream xEt(xEnd);
2032 std::istringstream yEt(yEnd);
2034 std::istringstream zEt(zEnd);
2039 if (zEn==900) zEn=GPOSITION_Z;
2043 bool boxExecutable = false;
2044 if (isExec == "TRUE") {
2045 boxExecutable = true;
2048 int idBox = createGBlackBox(xIn, yIn, package, type);
2049 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2051 GObjectController *cont = _controllers[idBox];
2052 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2055 getCleanLine(inputStream, line);//PORT o FIN_BOX
2056 std::string port = line.substr(0, 4);
2057 while (port == "PORT") {
2058 getCleanLine(inputStream, line);//name:value
2060 strcpy(poort, line.c_str());
2061 result = strtok(poort, delims);//name
2062 std::string name(result);
2063 result = strtok(NULL, delims);//value
2064 std::string value(result);
2066 bbmod->setValueToInput(name, value);
2068 getCleanLine(inputStream, line);//PORT o FIN_BOX
2069 port = line.substr(0, 4);
2072 //EED bbmod->notifyObservers(_idManager);
2077 getCleanLine(inputStream, line);//CONNECTIONS:num
2079 strcpy(conns, line.c_str());
2080 result = strtok(conns, delims);
2081 result = strtok(NULL, delims);
2084 std::istringstream isCons(result);
2088 for (int i = 0; i < numConns; i++) {
2090 getCleanLine(inputStream, line);//CONNECTION
2091 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2094 strcpy(connec, line.c_str());
2095 result = strtok(connec, delims);
2096 std::string nameStartBox(result);
2097 result = strtok(NULL, delims);
2098 std::string nameStartPort(result);
2099 result = strtok(NULL, delims);
2100 std::string nameEndBox(result);
2101 result = strtok(NULL, delims);
2102 std::string nameEndPort(result);
2104 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2106 if (version != "1.0") {
2107 //Readding control points of the manualContour
2108 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2109 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2110 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2111 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2112 strcpy(conns, line.c_str());
2113 result = strtok(conns, delims);
2114 result = strtok(NULL, delims);
2116 int numberOfControlPoints;
2117 std::istringstream isCons(result);
2118 isCons >> numberOfControlPoints;
2120 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2121 getCleanLine(inputStream, line); //XX:YY:ZZ
2123 strcpy(connec, line.c_str());
2126 result = strtok(connec, delims);
2127 std::istringstream isPointX(result);
2129 result = strtok(NULL, delims);
2130 std::istringstream isPointY(result);
2132 result = strtok(NULL, delims);
2133 std::istringstream isPointZ(result);
2138 if (pz==900) pz=GPOSITION_Z;
2141 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2142 conView->getManualContourView()->AddPoint();
2150 printf("wxVtkSceneManager::loadDiagram End\n");
2152 //=========================================================================
2155 //=========================================================================
2156 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2157 std::string portName, double xIn, double yIn, double zIn) {
2159 if (inputoutput == true) {
2160 idPort = createGComplexBoxInputPort(portName);
2162 idPort = createGComplexBoxOutputPort(portName);
2164 GObjectController *cont = _controllers[idPort];
2165 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2166 cbmod->setInicPoint(xIn, yIn, zIn);
2167 cbmod->notifyObservers(_idManager);
2169 //=========================================================================
2172 //=========================================================================
2173 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
2177 GBoxModel *boxModel = NULL;
2178 std::vector<int> lstB = getBlackBoxes();
2179 for (j = 0; j < (int) lstB.size(); j++) {
2181 bMod = (GBoxModel*) _controllers[idB]->getModel();
2182 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2187 if ((_isComplexBox) && (boxModel == NULL)) {
2188 std::vector<int> lstInputs = getComplexInputPorts();
2189 for (j = 0; j < (int) lstInputs.size(); j++) {
2191 bMod = (GBoxModel*) _controllers[idB]->getModel();
2192 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2197 std::vector<int> lstOutputs = getComplexOutputPorts();
2198 for (j = 0; j < (int) lstOutputs.size(); j++) {
2199 int idB = lstOutputs[j];
2200 bMod = (GBoxModel*) _controllers[idB]->getModel();
2201 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2211 //=========================================================================
2214 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2215 std::string nameStartPort, std::string nameEndBox,
2216 std::string nameEndPort) {
2218 GBoxModel *boxModel;
2219 GPortModel *startP = NULL;
2220 GPortModel *endP = NULL;
2222 boxModel = findGBox(nameStartBox);
2223 if (boxModel != NULL) {
2224 startP = boxModel->getOutputPort(nameStartPort);
2226 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port %s is null. Port name is probably wrong.\n", nameStartPort.c_str());
2230 boxModel = findGBox(nameEndBox);
2231 if (boxModel != NULL) {
2232 endP = boxModel->getInputPort(nameEndPort);
2234 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port %s is null. Port name is probably wrong\n", nameStartPort.c_str(), nameEndPort.c_str());
2239 int idCon = createGConnector(startP);
2240 _worldState = NOTHING_HAPPENS;
2241 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2243 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2244 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2245 tempp->endContourCreation();
2246 conMod->setEndPort(endP);
2247 conView->updateStartEndPoints();
2251 //=========================================================================
2253 bool wxVtkSceneManager::boxExist(std::string boxname) {
2255 std::map<int, GObjectController*>::iterator it;
2256 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2257 GObjectController *cont = it->second;
2258 if (cont->getModel()->getBBTKName() == boxname) {
2265 //=========================================================================
2267 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2268 std::vector<int> vect;
2269 std::map<int, GObjectController*>::iterator it;
2270 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2271 GObjectController *cont = it->second;
2272 if (cont->getGObjectType() == GBLACKBOX) {
2273 vect.push_back(cont->getId());
2279 //=========================================================================
2281 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2282 std::vector<int> vect;
2283 std::map<int, GObjectController*>::iterator it;
2284 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2285 GObjectController *cont = it->second;
2286 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2287 vect.push_back(cont->getId());
2293 //=========================================================================
2295 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2296 std::vector<int> vect;
2297 std::map<int, GObjectController*>::iterator it;
2298 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2299 GObjectController *cont = it->second;
2300 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2301 vect.push_back(cont->getId());
2307 //=========================================================================
2309 std::vector<int> wxVtkSceneManager::getConnections() {
2310 std::vector<int> vect;
2311 std::map<int, GObjectController*>::iterator it;
2312 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2313 GObjectController *cont = it->second;
2314 if (cont->getGObjectType() == GCONNECTOR) {
2315 vect.push_back(cont->getId());
2321 //=========================================================================
2323 bool wxVtkSceneManager::isComplexBox() {
2324 return _isComplexBox;
2327 //=========================================================================
2329 void wxVtkSceneManager::setComplexBox(bool val) {
2330 _isComplexBox = val;
2333 //=========================================================================
2335 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2336 //Register the controller of the new object
2337 registerController((InteractorStyleMaracas*) objController);
2338 //Add the object to the objects list
2339 int newId = _contLastId;//_controllers.size();
2340 objController->setId(newId);
2341 _controllers[newId] = objController;
2342 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2347 //=========================================================================
2349 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2351 std::map<int, int> oldIdNewIdBoxes;
2352 std::vector<int> connections;
2354 std::vector<int> newBoxesID;
2356 std::map<int, GObjectController*>::iterator it;
2357 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2358 GObjectController *cont = it->second;
2359 int type = cont->getGObjectType();
2361 if (type == GBLACKBOX) {
2363 double xInic, yInic, zInic;
2364 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2365 copyBox->getInicPoint(xInic, yInic, zInic);
2366 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2367 copyBox->getBBTKType());
2369 int idcB = copyBox->getObjectId();
2370 oldIdNewIdBoxes[idcB] = idBox;
2371 cont = _controllers[idBox];
2372 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2373 newbox->setInicPoint(xInic, yInic, zInic);
2374 int num = newbox->getNumInputPorts();
2375 for (int j = 0; j < num; j++) {
2376 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2378 newbox->move(xInic + 20, yInic + 20, zInic);
2379 newbox->notifyObservers(_idManager);
2380 newBoxesID.push_back(newbox->getObjectId());
2382 } else if (type == GCONNECTOR) {
2383 int idCon = cont->getId();
2384 connections.push_back(idCon);
2389 for (int i = 0; i < (int) connections.size(); i++) {
2390 int objId = connections[i];
2391 GObjectController *cont = objectsMap[objId];
2392 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2394 GPortModel* startPort = connectModel->getStartPort();
2395 int startPortIndex = startPort->getPosInBox();
2396 GPortModel* endPort = connectModel->getEndPort();
2397 int endPortIndex = endPort->getPosInBox();
2399 GBlackBoxModel* startPortParentBox =
2400 (GBlackBoxModel*) startPort->getParentBox();
2401 GBlackBoxModel* endPortParentBox =
2402 (GBlackBoxModel*) endPort->getParentBox();
2404 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2405 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2407 GBlackBoxModel* newStartBox =
2408 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2409 GBlackBoxModel* newEndBox =
2410 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2412 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2413 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2415 // Creates connection
2416 int idCon = createGConnector(newStartPort);
2417 GConnectorController *tempp =
2418 (GConnectorController*) _controllers[idCon];
2419 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2420 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2421 tempp->endContourCreation();
2422 conMod->setEndPort(newEndPort);
2423 conView->updateStartEndPoints();
2426 /// the new selected boxes are the duplicate ones
2428 UnSelectBlackBoxes();
2429 for (int i = 0; i < newBoxesID.size(); i++) {
2430 _selectedObjects.push_back(newBoxesID.at(i));
2433 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2434 int id = _selectedObjects[i];
2435 GObjectController* cont = _controllers[id];
2437 cont->getView()->setState(SELECTED);
2438 cont->getModel()->notifyObservers(_idManager);
2444 //=========================================================================
2446 int wxVtkSceneManager::getNumSelectedObjects() {
2447 return _selectedObjects.size();
2450 //=========================================================================
2452 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2453 std::map<int, GObjectController*> mapSelected;
2455 std::map<int, GObjectController*>::iterator it;
2456 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2457 GObjectController *cont = it->second;
2458 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2460 mapSelected[cont->getId()] = cont;
2464 std::map<int, GObjectController*>::iterator it2;
2465 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2466 GObjectController *cont = it2->second;
2467 if (cont->getGObjectType() == GCONNECTOR) {
2468 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2469 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2470 GBoxModel* startPortParentBox =
2471 cmod->getStartPort()->getParentBox();
2473 std::map<int, GObjectController*>::iterator iterOBJ1 =
2474 mapSelected.find(startPortParentBox->getObjectId());
2475 std::map<int, GObjectController*>::iterator iterOBJ2 =
2476 mapSelected.find(endPortParentBox->getObjectId());
2478 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2479 int ID = cont->getId();
2480 mapSelected[ID] = cont;
2487 //=========================================================================
2489 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2491 std::map<int, int> oldIdNewIdBoxes;
2492 std::vector<int> connections;
2494 std::map<int, GObjectController*>::iterator it;
2495 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2496 GObjectController *cont = it->second;
2497 int type = cont->getGObjectType();
2499 if (type == GBLACKBOX) {
2501 double xInic, yInic, zInic;
2502 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2503 copyBox->getInicPoint(xInic, yInic, zInic);
2504 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2505 copyBox->getBBTKType());
2507 int idcB = copyBox->getObjectId();
2508 oldIdNewIdBoxes[idcB] = idBox;
2509 cont = _controllers[idBox];
2510 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2511 newbox->setInicPoint(xInic, yInic, zInic);
2512 int num = newbox->getNumInputPorts();
2513 for (int j = 0; j < num; j++) {
2514 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2516 newbox->notifyObservers(_idManager);
2517 } else if (type == GCONNECTOR) {
2518 int idCon = cont->getId();
2519 connections.push_back(idCon);
2524 for (int i = 0; i < (int) connections.size(); i++) {
2525 int objId = connections[i];
2526 GObjectController *cont = objectsMap[objId];
2527 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2529 GPortModel* startPort = connectModel->getStartPort();
2530 int startPortIndex = startPort->getPosInBox();
2531 GPortModel* endPort = connectModel->getEndPort();
2532 int endPortIndex = endPort->getPosInBox();
2534 GBlackBoxModel* startPortParentBox =
2535 (GBlackBoxModel*) startPort->getParentBox();
2536 GBlackBoxModel* endPortParentBox =
2537 (GBlackBoxModel*) endPort->getParentBox();
2539 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2540 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2542 GBlackBoxModel* newStartBox =
2543 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2544 GBlackBoxModel* newEndBox =
2545 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2547 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2548 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2550 // Creates connection
2551 int idCon = createGConnector(newStartPort);
2552 GConnectorController *tempp =
2553 (GConnectorController*) _controllers[idCon];
2554 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2555 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2556 tempp->endContourCreation();
2557 conMod->setEndPort(newEndPort);
2558 conView->updateStartEndPoints();
2561 std::map<int, int>::iterator itIds;
2562 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2563 int idOld = itIds->first;
2564 int idNew = itIds->second;
2566 GBlackBoxModel* oldBox =
2567 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2568 GBlackBoxModel* newBox =
2569 (GBlackBoxModel*) _controllers[idNew]->getModel();
2571 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2572 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2573 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2574 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2576 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2578 //EED int toCreate=-1;
2579 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2580 if (oldInputConnections[k] == newInputConnections[l]) {
2585 if (exist == false) {
2586 //Create complex input
2587 int posInBox = oldInputConnections[k];
2588 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2589 std::string inputPortName = inputPort->getBBTKName();
2590 int idInputPort = createGComplexBoxInputPort(inputPortName);
2591 GObjectController *cont = _controllers[idInputPort];
2592 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2593 double xIn, yIn, zIn;
2594 inputPort->getInicPoint(xIn, yIn, zIn);
2596 cbmod->setInicPoint(xIn, yIn, zIn);
2597 cbmod->notifyObservers(_idManager);
2599 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2601 // Creates connection
2602 int idCon = createGConnector(cbmod->getOutputPort(0));
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(inputPortEnd);
2610 conView->updateStartEndPoints();
2616 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2618 //EED int toCreate=-1;
2619 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2620 if (oldOutputConnections[k] == newOutputConnections[l]) {
2625 if (exist == false) {
2626 //Create complex output
2627 int posInBox = oldOutputConnections[k];
2628 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2629 std::string outputPortName = outputPort->getBBTKName();
2630 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2631 GObjectController *cont = _controllers[idOutputPort];
2632 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2633 double xIn, yIn, zIn;
2634 outputPort->getInicPoint(xIn, yIn, zIn);
2636 cbmod->setInicPoint(xIn, yIn, zIn);
2637 cbmod->notifyObservers(_idManager);
2639 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2641 // Creates connection
2642 int idCon = createGConnector(outputPortEnd);
2643 GConnectorController *tempp =
2644 (GConnectorController*) _controllers[idCon];
2645 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2646 vtkGConnectorView *conView =
2647 (vtkGConnectorView*) tempp->getView();
2648 tempp->endContourCreation();
2649 conMod->setEndPort(cbmod->getInputPort(0));
2650 conView->updateStartEndPoints();
2660 //=========================================================================
2661 void wxVtkSceneManager::SetCbName(std::string cbName) {
2663 if (_cbName == "") {
2664 _cbName = "<complex box name>";
2668 //=========================================================================
2669 std::string wxVtkSceneManager::GetCbName() {
2673 //=========================================================================
2674 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2675 _cbPackageName = packagename;
2676 if (_cbPackageName == "") {
2677 _cbPackageName = "<package name of the complex box>";
2681 //=========================================================================
2682 std::string wxVtkSceneManager::GetCbPackageName() {
2683 return _cbPackageName;
2686 //=========================================================================
2687 void wxVtkSceneManager::SetAuthor(std::string author) {
2689 if (_Author == "") {
2690 _Author = "<author of the box>";
2694 //=========================================================================
2695 std::string wxVtkSceneManager::GetAuthor() {
2699 //=========================================================================
2700 void wxVtkSceneManager::SetCategory(std::string category) {
2701 _Category = category;
2702 if (_Category == "") {
2703 _Category = "<category of the box>";
2707 //=========================================================================
2708 std::string wxVtkSceneManager::GetCategory() {
2712 //=========================================================================
2713 void wxVtkSceneManager::SetDescription(std::string description) {
2714 _Description = description;
2715 if (_Description == "") {
2716 _Description = "<description of the box>";
2720 //=========================================================================
2721 std::string wxVtkSceneManager::GetDescription() {
2722 return _Description;
2725 //=========================================================================
2728 void wxVtkSceneManager::printAll(int com , int sta ){
2730 int tmpState = sta ;
2731 if ( tmpState == NOTHING_HAPPENS ) {
2732 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2734 if ( tmpState == HIGHLIGHTED ) {
2735 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2737 if ( tmpState == POSSIBLE_CONNECTION ) {
2738 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2740 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2741 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2743 if ( tmpState == CLICKED ) {
2744 std::cout << "CONTROLER STATE---->CLICKED\n" ;
2746 if ( tmpState == DRAG ) {
2747 std::cout << "CONTROLER STATE---->DRAG\n" ;
2749 if ( tmpState == SELECTED ) {
2750 std::cout << "CONTROLER STATE---->SELECTED\n" ;
2752 if ( tmpState == CREATING_CONTOUR ) {
2753 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2759 if ( command == INIT_CREATION_CONTOUR ) {
2760 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2762 if ( command == FIN_CREATION_CONTOUR ) {
2763 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2765 if ( command == ADD_TO_SELECTED ) {
2766 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2768 if ( command == DRAG_OBJECTS ) {
2769 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2771 if ( command == EDIT_BLACKBOX ) {
2772 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
2774 if ( command == REMOVE_FROM_SELECTED ) {
2775 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
2781 } // EO namespace bbtk