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();
1759 if ( line[ size-1 ]==13 )
1761 line.erase(size-1,1);
1766 //=========================================================================
1767 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1770 std::string version = "<void>";
1771 std::string line = "";
1772 char delims[] = ":";
1773 char *result = NULL;
1775 getCleanLine(inputStream, line);
1778 while (!inputStream.eof()) {
1779 if (line == "" || line[0] == '#') {
1781 getCleanLine(inputStream, line);
1783 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1784 version = line.substr(18, 3);
1786 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1787 version = line.substr(18, 3);
1789 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1790 version = line.substr(18, 3);
1792 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1793 version = line.substr(18, 3);
1795 } else if (line == "APP_START") {
1804 if ((version != "1.0") && (version != "1.1")) {
1805 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1806 char categoryTmp[30];
1807 strcpy(categoryTmp, line.c_str());
1808 result = strtok(categoryTmp, delims);
1809 result = strtok(NULL, delims);
1810 SetCategory(result);
1812 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1813 char descriptionTmp[1024];
1814 strcpy(descriptionTmp, line.c_str());
1815 result = strtok(descriptionTmp, delims);
1816 result = strtok(NULL, delims);
1817 SetDescription(result);
1819 getCleanLine(inputStream, line);//AUTHOR:<author>
1820 char authorTmp[255];
1821 strcpy(authorTmp, line.c_str());
1822 result = strtok(authorTmp, delims);
1823 result = strtok(NULL, delims);
1828 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1829 char complexTmp[30];
1830 strcpy(complexTmp, line.c_str());
1831 result = strtok(complexTmp, delims);
1832 result = strtok(NULL, delims);
1833 std::string isComplexBox(result);
1835 if (isComplexBox == "TRUE") {
1836 _isComplexBox = true;
1838 if ((version != "1.0") && (version != "1.1")) {
1839 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
1840 char complexboxnameTmp[255];
1841 strcpy(complexboxnameTmp, line.c_str());
1842 result = strtok(complexboxnameTmp, delims);
1843 result = strtok(NULL, delims);
1846 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
1847 char packagenameTmp[255];
1848 strcpy(packagenameTmp, line.c_str());
1849 result = strtok(packagenameTmp, delims);
1850 result = strtok(NULL, delims);
1851 SetCbPackageName(result);
1854 //-----------------------
1855 //- COMPLEX INPUT PORTS
1856 //-----------------------
1857 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
1859 strcpy(inputs, line.c_str());
1860 result = strtok(inputs, delims);
1861 result = strtok(NULL, delims);
1864 std::istringstream inps(result);
1867 for (int i = 0; i < numInputs; i++) {
1869 getCleanLine(inputStream, line);//COMPLEX_PORT
1870 getCleanLine(inputStream, line);//name
1871 std::string inputPortName(line);
1874 getCleanLine(inputStream, line);//xInic:yInic:zInic
1876 strcpy(coord, line.c_str());
1877 result = strtok(coord, delims);//xInic
1878 std::string xInic(result);
1879 result = strtok(NULL, delims);//yInic
1880 std::string yInic(result);
1881 result = strtok(NULL, delims);//zInic
1882 std::string zInic(result);
1884 double xIn, yIn, zIn;
1885 std::istringstream xSt(xInic);
1887 std::istringstream ySt(yInic);
1889 std::istringstream zSt(zInic);
1894 if (zIn==900) zIn=GPOSITION_Z;
1897 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
1899 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
1901 } // for input complex box
1904 //-----------------------
1905 //- COMPLEX OUTPUT PORTS
1906 //-----------------------
1908 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
1910 strcpy(outputs, line.c_str());
1911 result = strtok(outputs, delims);
1912 result = strtok(NULL, delims);
1915 std::istringstream outps(result);
1916 outps >> numOutputs;
1918 for (int i = 0; i < numOutputs; i++) {
1920 getCleanLine(inputStream, line);//COMPLEX_PORT
1921 getCleanLine(inputStream, line);//name
1922 std::string outputPortName(line);
1925 getCleanLine(inputStream, line);//xInic:yInic:zInic
1927 strcpy(coord, line.c_str());
1928 result = strtok(coord, delims);//xInic
1929 std::string xInic(result);
1930 result = strtok(NULL, delims);//yInic
1931 std::string yInic(result);
1932 result = strtok(NULL, delims);//zInic
1933 std::string zInic(result);
1935 double xIn, yIn, zIn;
1936 std::istringstream xSt(xInic);
1938 std::istringstream ySt(yInic);
1940 std::istringstream zSt(zInic);
1945 if (zIn==900) zIn=GPOSITION_Z;
1948 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
1950 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
1952 } // for output complex box
1957 getCleanLine(inputStream, line);//BOXES:num
1959 strcpy(boxes, line.c_str());
1960 result = strtok(boxes, delims);
1961 result = strtok(NULL, delims);
1964 std::istringstream is(result);
1967 for (int i = 0; i < numBoxes; i++) {
1969 getCleanLine(inputStream, line);//BOX
1970 getCleanLine(inputStream, line);//package:type:name
1972 strcpy(box, line.c_str());
1973 result = strtok(box, delims);//package
1974 std::string package(result);
1975 result = strtok(NULL, delims);//type
1976 std::string type(result);
1977 result = strtok(NULL, delims);//name
1978 std::string name(result);
1980 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
1982 strcpy(exec, line.c_str());
1983 result = strtok(exec, delims);//ISEXEC
1984 result = strtok(NULL, delims);//TRUE|FALSE
1985 std::string isExec(result);
1988 getCleanLine(inputStream, line);//xInic:yInic:zInic
1990 strcpy(coord, line.c_str());
1991 result = strtok(coord, delims);//xInic
1992 std::string xInic(result);
1993 result = strtok(NULL, delims);//yInic
1994 std::string yInic(result);
1995 result = strtok(NULL, delims);//zInic
1996 std::string zInic(result);
1998 double xIn, yIn, zIn;
1999 std::istringstream xSt(xInic);
2001 std::istringstream ySt(yInic);
2003 std::istringstream zSt(zInic);
2009 if (zIn==900) zIn=GPOSITION_Z;
2014 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2015 strcpy(coord, line.c_str());
2016 result = strtok(coord, delims);//xEnd
2017 std::string xEnd(result);
2018 result = strtok(NULL, delims);//yEnd
2019 std::string yEnd(result);
2020 result = strtok(NULL, delims);//zEnd
2021 std::string zEnd(result);
2023 double xEn, yEn, zEn;
2024 std::istringstream xEt(xEnd);
2026 std::istringstream yEt(yEnd);
2028 std::istringstream zEt(zEnd);
2033 if (zEn==900) zEn=GPOSITION_Z;
2037 bool boxExecutable = false;
2038 if (isExec == "TRUE") {
2039 boxExecutable = true;
2042 int idBox = createGBlackBox(xIn, yIn, package, type);
2043 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2045 GObjectController *cont = _controllers[idBox];
2046 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2049 getCleanLine(inputStream, line);//PORT o FIN_BOX
2050 std::string port = line.substr(0, 4);
2051 while (port == "PORT") {
2052 getCleanLine(inputStream, line);//name:value
2054 strcpy(poort, line.c_str());
2055 result = strtok(poort, delims);//name
2056 std::string name(result);
2057 result = strtok(NULL, delims);//value
2058 std::string value(result);
2060 bbmod->setValueToInput(name, value);
2062 getCleanLine(inputStream, line);//PORT o FIN_BOX
2063 port = line.substr(0, 4);
2066 //EED bbmod->notifyObservers(_idManager);
2071 getCleanLine(inputStream, line);//CONNECTIONS:num
2073 strcpy(conns, line.c_str());
2074 result = strtok(conns, delims);
2075 result = strtok(NULL, delims);
2078 std::istringstream isCons(result);
2082 for (int i = 0; i < numConns; i++) {
2084 getCleanLine(inputStream, line);//CONNECTION
2085 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2088 strcpy(connec, line.c_str());
2089 result = strtok(connec, delims);
2090 std::string nameStartBox(result);
2091 result = strtok(NULL, delims);
2092 std::string nameStartPort(result);
2093 result = strtok(NULL, delims);
2094 std::string nameEndBox(result);
2095 result = strtok(NULL, delims);
2096 std::string nameEndPort(result);
2098 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2100 if (version != "1.0") {
2101 //Readding control points of the manualContour
2102 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2103 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2104 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2105 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2106 strcpy(conns, line.c_str());
2107 result = strtok(conns, delims);
2108 result = strtok(NULL, delims);
2110 int numberOfControlPoints;
2111 std::istringstream isCons(result);
2112 isCons >> numberOfControlPoints;
2114 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2115 getCleanLine(inputStream, line); //XX:YY:ZZ
2117 strcpy(connec, line.c_str());
2120 result = strtok(connec, delims);
2121 std::istringstream isPointX(result);
2123 result = strtok(NULL, delims);
2124 std::istringstream isPointY(result);
2126 result = strtok(NULL, delims);
2127 std::istringstream isPointZ(result);
2132 if (pz==900) pz=GPOSITION_Z;
2135 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2136 conView->getManualContourView()->AddPoint();
2145 //=========================================================================
2148 //=========================================================================
2149 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2150 std::string portName, double xIn, double yIn, double zIn) {
2152 if (inputoutput == true) {
2153 idPort = createGComplexBoxInputPort(portName);
2155 idPort = createGComplexBoxOutputPort(portName);
2157 GObjectController *cont = _controllers[idPort];
2158 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2159 cbmod->setInicPoint(xIn, yIn, zIn);
2160 cbmod->notifyObservers(_idManager);
2162 //=========================================================================
2165 //=========================================================================
2166 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
2170 GBoxModel *boxModel = NULL;
2171 std::vector<int> lstB = getBlackBoxes();
2172 for (j = 0; j < (int) lstB.size(); j++) {
2174 bMod = (GBoxModel*) _controllers[idB]->getModel();
2175 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2180 if ((_isComplexBox) && (boxModel == NULL)) {
2181 std::vector<int> lstInputs = getComplexInputPorts();
2182 for (j = 0; j < (int) lstInputs.size(); j++) {
2184 bMod = (GBoxModel*) _controllers[idB]->getModel();
2185 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2190 std::vector<int> lstOutputs = getComplexOutputPorts();
2191 for (j = 0; j < (int) lstOutputs.size(); j++) {
2192 int idB = lstOutputs[j];
2193 bMod = (GBoxModel*) _controllers[idB]->getModel();
2194 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2204 //=========================================================================
2207 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2208 std::string nameStartPort, std::string nameEndBox,
2209 std::string nameEndPort) {
2211 GBoxModel *boxModel;
2212 GPortModel *startP = NULL;
2213 GPortModel *endP = NULL;
2215 boxModel = findGBox(nameStartBox);
2216 if (boxModel != NULL) {
2217 startP = boxModel->getOutputPort(nameStartPort);
2219 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port %s is null. Port name is probably wrong.\n", nameStartPort.c_str());
2223 boxModel = findGBox(nameEndBox);
2224 if (boxModel != NULL) {
2225 endP = boxModel->getInputPort(nameEndPort);
2227 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port %s is null. Port name is probably wrong\n", nameStartPort.c_str(), nameEndPort.c_str());
2232 int idCon = createGConnector(startP);
2233 _worldState = NOTHING_HAPPENS;
2234 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2236 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2237 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2238 tempp->endContourCreation();
2239 conMod->setEndPort(endP);
2240 conView->updateStartEndPoints();
2244 //=========================================================================
2246 bool wxVtkSceneManager::boxExist(std::string boxname) {
2248 std::map<int, GObjectController*>::iterator it;
2249 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2250 GObjectController *cont = it->second;
2251 if (cont->getModel()->getBBTKName() == boxname) {
2258 //=========================================================================
2260 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2261 std::vector<int> vect;
2262 std::map<int, GObjectController*>::iterator it;
2263 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2264 GObjectController *cont = it->second;
2265 if (cont->getGObjectType() == GBLACKBOX) {
2266 vect.push_back(cont->getId());
2272 //=========================================================================
2274 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2275 std::vector<int> vect;
2276 std::map<int, GObjectController*>::iterator it;
2277 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2278 GObjectController *cont = it->second;
2279 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2280 vect.push_back(cont->getId());
2286 //=========================================================================
2288 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2289 std::vector<int> vect;
2290 std::map<int, GObjectController*>::iterator it;
2291 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2292 GObjectController *cont = it->second;
2293 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2294 vect.push_back(cont->getId());
2300 //=========================================================================
2302 std::vector<int> wxVtkSceneManager::getConnections() {
2303 std::vector<int> vect;
2304 std::map<int, GObjectController*>::iterator it;
2305 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2306 GObjectController *cont = it->second;
2307 if (cont->getGObjectType() == GCONNECTOR) {
2308 vect.push_back(cont->getId());
2314 //=========================================================================
2316 bool wxVtkSceneManager::isComplexBox() {
2317 return _isComplexBox;
2320 //=========================================================================
2322 void wxVtkSceneManager::setComplexBox(bool val) {
2323 _isComplexBox = val;
2326 //=========================================================================
2328 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2329 //Register the controller of the new object
2330 registerController((InteractorStyleMaracas*) objController);
2331 //Add the object to the objects list
2332 int newId = _contLastId;//_controllers.size();
2333 objController->setId(newId);
2334 _controllers[newId] = objController;
2335 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2340 //=========================================================================
2342 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2344 std::map<int, int> oldIdNewIdBoxes;
2345 std::vector<int> connections;
2347 std::vector<int> newBoxesID;
2349 std::map<int, GObjectController*>::iterator it;
2350 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2351 GObjectController *cont = it->second;
2352 int type = cont->getGObjectType();
2354 if (type == GBLACKBOX) {
2356 double xInic, yInic, zInic;
2357 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2358 copyBox->getInicPoint(xInic, yInic, zInic);
2359 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2360 copyBox->getBBTKType());
2362 int idcB = copyBox->getObjectId();
2363 oldIdNewIdBoxes[idcB] = idBox;
2364 cont = _controllers[idBox];
2365 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2366 newbox->setInicPoint(xInic, yInic, zInic);
2367 int num = newbox->getNumInputPorts();
2368 for (int j = 0; j < num; j++) {
2369 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2371 newbox->move(xInic + 20, yInic + 20, zInic);
2372 newbox->notifyObservers(_idManager);
2373 newBoxesID.push_back(newbox->getObjectId());
2375 } else if (type == GCONNECTOR) {
2376 int idCon = cont->getId();
2377 connections.push_back(idCon);
2382 for (int i = 0; i < (int) connections.size(); i++) {
2383 int objId = connections[i];
2384 GObjectController *cont = objectsMap[objId];
2385 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2387 GPortModel* startPort = connectModel->getStartPort();
2388 int startPortIndex = startPort->getPosInBox();
2389 GPortModel* endPort = connectModel->getEndPort();
2390 int endPortIndex = endPort->getPosInBox();
2392 GBlackBoxModel* startPortParentBox =
2393 (GBlackBoxModel*) startPort->getParentBox();
2394 GBlackBoxModel* endPortParentBox =
2395 (GBlackBoxModel*) endPort->getParentBox();
2397 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2398 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2400 GBlackBoxModel* newStartBox =
2401 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2402 GBlackBoxModel* newEndBox =
2403 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2405 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2406 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2408 // Creates connection
2409 int idCon = createGConnector(newStartPort);
2410 GConnectorController *tempp =
2411 (GConnectorController*) _controllers[idCon];
2412 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2413 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2414 tempp->endContourCreation();
2415 conMod->setEndPort(newEndPort);
2416 conView->updateStartEndPoints();
2419 /// the new selected boxes are the duplicate ones
2421 UnSelectBlackBoxes();
2422 for (int i = 0; i < newBoxesID.size(); i++) {
2423 _selectedObjects.push_back(newBoxesID.at(i));
2426 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2427 int id = _selectedObjects[i];
2428 GObjectController* cont = _controllers[id];
2430 cont->getView()->setState(SELECTED);
2431 cont->getModel()->notifyObservers(_idManager);
2437 //=========================================================================
2439 int wxVtkSceneManager::getNumSelectedObjects() {
2440 return _selectedObjects.size();
2443 //=========================================================================
2445 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2446 std::map<int, GObjectController*> mapSelected;
2448 std::map<int, GObjectController*>::iterator it;
2449 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2450 GObjectController *cont = it->second;
2451 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2453 mapSelected[cont->getId()] = cont;
2457 std::map<int, GObjectController*>::iterator it2;
2458 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2459 GObjectController *cont = it2->second;
2460 if (cont->getGObjectType() == GCONNECTOR) {
2461 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2462 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2463 GBoxModel* startPortParentBox =
2464 cmod->getStartPort()->getParentBox();
2466 std::map<int, GObjectController*>::iterator iterOBJ1 =
2467 mapSelected.find(startPortParentBox->getObjectId());
2468 std::map<int, GObjectController*>::iterator iterOBJ2 =
2469 mapSelected.find(endPortParentBox->getObjectId());
2471 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2472 int ID = cont->getId();
2473 mapSelected[ID] = cont;
2480 //=========================================================================
2482 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2484 std::map<int, int> oldIdNewIdBoxes;
2485 std::vector<int> connections;
2487 std::map<int, GObjectController*>::iterator it;
2488 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2489 GObjectController *cont = it->second;
2490 int type = cont->getGObjectType();
2492 if (type == GBLACKBOX) {
2494 double xInic, yInic, zInic;
2495 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2496 copyBox->getInicPoint(xInic, yInic, zInic);
2497 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2498 copyBox->getBBTKType());
2500 int idcB = copyBox->getObjectId();
2501 oldIdNewIdBoxes[idcB] = idBox;
2502 cont = _controllers[idBox];
2503 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2504 newbox->setInicPoint(xInic, yInic, zInic);
2505 int num = newbox->getNumInputPorts();
2506 for (int j = 0; j < num; j++) {
2507 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2509 newbox->notifyObservers(_idManager);
2510 } else if (type == GCONNECTOR) {
2511 int idCon = cont->getId();
2512 connections.push_back(idCon);
2517 for (int i = 0; i < (int) connections.size(); i++) {
2518 int objId = connections[i];
2519 GObjectController *cont = objectsMap[objId];
2520 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2522 GPortModel* startPort = connectModel->getStartPort();
2523 int startPortIndex = startPort->getPosInBox();
2524 GPortModel* endPort = connectModel->getEndPort();
2525 int endPortIndex = endPort->getPosInBox();
2527 GBlackBoxModel* startPortParentBox =
2528 (GBlackBoxModel*) startPort->getParentBox();
2529 GBlackBoxModel* endPortParentBox =
2530 (GBlackBoxModel*) endPort->getParentBox();
2532 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2533 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2535 GBlackBoxModel* newStartBox =
2536 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2537 GBlackBoxModel* newEndBox =
2538 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2540 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2541 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2543 // Creates connection
2544 int idCon = createGConnector(newStartPort);
2545 GConnectorController *tempp =
2546 (GConnectorController*) _controllers[idCon];
2547 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2548 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2549 tempp->endContourCreation();
2550 conMod->setEndPort(newEndPort);
2551 conView->updateStartEndPoints();
2554 std::map<int, int>::iterator itIds;
2555 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2556 int idOld = itIds->first;
2557 int idNew = itIds->second;
2559 GBlackBoxModel* oldBox =
2560 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2561 GBlackBoxModel* newBox =
2562 (GBlackBoxModel*) _controllers[idNew]->getModel();
2564 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2565 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2566 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2567 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2569 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2571 //EED int toCreate=-1;
2572 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2573 if (oldInputConnections[k] == newInputConnections[l]) {
2578 if (exist == false) {
2579 //Create complex input
2580 int posInBox = oldInputConnections[k];
2581 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2582 std::string inputPortName = inputPort->getBBTKName();
2583 int idInputPort = createGComplexBoxInputPort(inputPortName);
2584 GObjectController *cont = _controllers[idInputPort];
2585 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2586 double xIn, yIn, zIn;
2587 inputPort->getInicPoint(xIn, yIn, zIn);
2589 cbmod->setInicPoint(xIn, yIn, zIn);
2590 cbmod->notifyObservers(_idManager);
2592 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2594 // Creates connection
2595 int idCon = createGConnector(cbmod->getOutputPort(0));
2596 GConnectorController *tempp =
2597 (GConnectorController*) _controllers[idCon];
2598 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2599 vtkGConnectorView *conView =
2600 (vtkGConnectorView*) tempp->getView();
2601 tempp->endContourCreation();
2602 conMod->setEndPort(inputPortEnd);
2603 conView->updateStartEndPoints();
2609 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2611 //EED int toCreate=-1;
2612 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2613 if (oldOutputConnections[k] == newOutputConnections[l]) {
2618 if (exist == false) {
2619 //Create complex output
2620 int posInBox = oldOutputConnections[k];
2621 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2622 std::string outputPortName = outputPort->getBBTKName();
2623 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2624 GObjectController *cont = _controllers[idOutputPort];
2625 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2626 double xIn, yIn, zIn;
2627 outputPort->getInicPoint(xIn, yIn, zIn);
2629 cbmod->setInicPoint(xIn, yIn, zIn);
2630 cbmod->notifyObservers(_idManager);
2632 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2634 // Creates connection
2635 int idCon = createGConnector(outputPortEnd);
2636 GConnectorController *tempp =
2637 (GConnectorController*) _controllers[idCon];
2638 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2639 vtkGConnectorView *conView =
2640 (vtkGConnectorView*) tempp->getView();
2641 tempp->endContourCreation();
2642 conMod->setEndPort(cbmod->getInputPort(0));
2643 conView->updateStartEndPoints();
2653 //=========================================================================
2654 void wxVtkSceneManager::SetCbName(std::string cbName) {
2656 if (_cbName == "") {
2657 _cbName = "<complex box name>";
2661 //=========================================================================
2662 std::string wxVtkSceneManager::GetCbName() {
2666 //=========================================================================
2667 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2668 _cbPackageName = packagename;
2669 if (_cbPackageName == "") {
2670 _cbPackageName = "<package name of the complex box>";
2674 //=========================================================================
2675 std::string wxVtkSceneManager::GetCbPackageName() {
2676 return _cbPackageName;
2679 //=========================================================================
2680 void wxVtkSceneManager::SetAuthor(std::string author) {
2682 if (_Author == "") {
2683 _Author = "<author of the box>";
2687 //=========================================================================
2688 std::string wxVtkSceneManager::GetAuthor() {
2692 //=========================================================================
2693 void wxVtkSceneManager::SetCategory(std::string category) {
2694 _Category = category;
2695 if (_Category == "") {
2696 _Category = "<category of the box>";
2700 //=========================================================================
2701 std::string wxVtkSceneManager::GetCategory() {
2705 //=========================================================================
2706 void wxVtkSceneManager::SetDescription(std::string description) {
2707 _Description = description;
2708 if (_Description == "") {
2709 _Description = "<description of the box>";
2713 //=========================================================================
2714 std::string wxVtkSceneManager::GetDescription() {
2715 return _Description;
2718 //=========================================================================
2721 void wxVtkSceneManager::printAll(int com , int sta ){
2723 int tmpState = sta ;
2724 if ( tmpState == NOTHING_HAPPENS ) {
2725 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2727 if ( tmpState == HIGHLIGHTED ) {
2728 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2730 if ( tmpState == POSSIBLE_CONNECTION ) {
2731 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2733 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2734 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2736 if ( tmpState == CLICKED ) {
2737 std::cout << "CONTROLER STATE---->CLICKED\n" ;
2739 if ( tmpState == DRAG ) {
2740 std::cout << "CONTROLER STATE---->DRAG\n" ;
2742 if ( tmpState == SELECTED ) {
2743 std::cout << "CONTROLER STATE---->SELECTED\n" ;
2745 if ( tmpState == CREATING_CONTOUR ) {
2746 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2752 if ( command == INIT_CREATION_CONTOUR ) {
2753 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2755 if ( command == FIN_CREATION_CONTOUR ) {
2756 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2758 if ( command == ADD_TO_SELECTED ) {
2759 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2761 if ( command == DRAG_OBJECTS ) {
2762 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2764 if ( command == EDIT_BLACKBOX ) {
2765 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
2767 if ( command == REMOVE_FROM_SELECTED ) {
2768 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
2774 } // EO namespace bbtk