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 "ComplexInputPort", 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", 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(), 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(), 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, 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);
488 model->addObserver(view);
489 model->addObserver(this);
491 //Associates the view with the correspondent renderer and the model.
492 //(NOTE: Refresh is only made by the view)
493 view->setModel(model);
494 view->setBaseView(_baseView);
495 view->initVtkObjects();
497 //Associates the controller with the correspondent model and view
498 controller->setModelAndView(model, view);
500 model->notifyObservers(_idManager);
502 addObjectController(controller);
504 return (GPortController*) controller;
507 //=========================================================================
509 int wxVtkSceneManager::createGConnector(GPortModel* startPort) {
510 int type = GCONNECTOR;
512 manualConnectorContourController *manContourControl = new manualConnectorContourController();
513 manualConnectorContourView *manContourView = new manualConnectorContourView();
514 manualContourModel *manContourModel = new manualContourModel();
515 GConnectorController *connectorcontroller = new GConnectorController();
516 GConnectorModel *connectorModel = new GConnectorModel();
517 vtkGConnectorView *connectorView = new vtkGConnectorView();
518 connectorModel->setGObjectType(type);
520 manContourModel->SetCloseContour(false);
521 connectorModel->setStartPort(startPort);
523 manContourView->SetModel(manContourModel);
524 manContourView->SetWxVtkBaseView(_baseView);
525 manContourView->SetRange(0.5);
526 manContourView->SetZ(GPOSITION_Z);
528 manContourView->SetColorNormalContour(0, 0, 1);
529 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
530 manContourView->SetColorSelectContour(1, 0.8, 0);
534 * Width increased from 2 to 3, it simplifies line handling and spline control :P
537 manContourView->SetWidthLine( 3 ) ;
538 manContourView->SetShowText(false);
540 manContourControl->SetModelView(manContourModel, manContourView);
542 manContourControl->CreateNewManualContour();
546 connectorModel->getInicPoint(x, y, z);
549 manContourControl->SetState(1);
550 manContourModel->SetCloseContour(false);
552 manContourModel->AddPoint(x, y, z);
553 manContourView->AddPoint();
555 manContourModel->AddPoint(x, y, z);
556 manContourView->AddPoint();
558 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
559 manContourControl->_bakIdPoint = bak;
561 manContourControl->SetMoving(false);
563 connectorcontroller->setModelAndView(connectorModel, connectorView);
565 int newId = addObjectController(connectorcontroller);
567 connectorcontroller->setManualContourController(manContourControl);
568 connectorModel->setManualContourModel(manContourModel);
569 connectorView->setManualContourView(manContourView);
570 connectorView->setModel(connectorModel);
571 connectorView->setBaseView(_baseView);
573 connectorModel->addObserver(connectorView);
574 connectorModel->addObserver(this);
576 // manContourView->Refresh();
581 //=========================================================================
583 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param) {
584 vtkInteractorStyleBaseView
585 * baseViewControlManager =
586 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
587 baseViewControlManager->AddInteractorStyleMaracas(param);
590 //=========================================================================
592 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param) {
593 vtkInteractorStyleBaseView
594 * baseViewControlManager =
595 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
596 baseViewControlManager->RemoveInteractorStyleMaracas(param);
599 //=========================================================================
601 vtkRenderer* wxVtkSceneManager::getRenderer() {
602 return _baseView->GetRenderer();
605 //=========================================================================
607 vtkRenderWindow* wxVtkSceneManager::getRenderWindow() {
608 return _baseView->GetRenWin();
610 //=========================================================================
613 //=========================================================================
614 int wxVtkSceneManager::GetIndexInSelected(int idControler) {
616 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
617 if (_selectedObjects[i] == idControler) {
624 //=========================================================================
626 void wxVtkSceneManager::update(int idController, int command) {
628 if (command != NO_COMMAND) {
629 if (command == ADD_TO_SELECTED) {
630 if (GetIndexInSelected(idController) == -1) {
631 _selectedObjects.push_back(idController);
633 } else if (command == REMOVE_FROM_SELECTED) {
634 int index = GetIndexInSelected(idController);
636 _selectedObjects.erase(_selectedObjects.begin() + index);
638 } else if (command == INIT_CREATION_CONTOUR) {
641 typedef std::map<int , GObjectController*>::iterator TIterator ;
644 // Find current item in the controller
645 iter = _controllers.find( idController ) ;
646 iter_end = _controllers.end( ) ;
648 if ( iter != iter_end ) {
649 GObjectController* gobjc = iter->second ;
651 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
652 // And if the item is a port
653 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
654 TIterator c_it = _controllers.begin( ) ;
655 // Go through all componets
656 for ( c_it ; c_it != iter_end ; c_it++ ) {
657 GObjectController* obc = c_it->second ;
658 int obc_type = obc->getModel( )->getGObjectType( ) ;
659 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
660 // if the component is a port and the type is the same of that selected
661 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
663 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
664 //obc->getView( )->setState( HIGHLIGHTED ) ;
672 _worldState = INIT_CREATION_CONTOUR;
673 GObjectController* cont = _controllers[idController];
674 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
676 // The last one is the controller of the connector
677 std::map<int, GObjectController*>::iterator it2;
679 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
680 GObjectController *cont = it2->second;
681 if (cont->getGObjectType() == GPORT) {
682 GPortModel* port = (GPortModel*) cont->getModel();
683 if (port->getPortType() == GINPUTPORT) {
684 cont->SetActive(true);
686 cont->getView()->setState(NOTHING_HAPPENS);
687 cont->getModel()->notifyObservers(_idManager);
688 cont->SetActive(false);
691 cont->getView()->setState(NOTHING_HAPPENS);
692 cont->getModel()->notifyObservers(_idManager);
693 cont->SetActive(false);
696 _selectedObjects.clear();
697 _idConnectionInCreation = createGConnector(startOutputPort);
698 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
699 _worldState = NOTHING_HAPPENS;
700 //int id = _controllers.size()-1;
701 GObjectController *cont = _controllers[_idConnectionInCreation];
702 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
703 GObjectController *finPort = _controllers[idController];
705 if (finPort->getGObjectType() == GPORT) {
706 GPortModel* modelPort = (GPortModel*) finPort->getModel();
707 modelContour->setEndPort(modelPort);
710 typedef std::map<int, GObjectController*>::iterator TIterator;
711 TIterator c_it = _controllers.begin();
712 TIterator iter_end = _controllers.end();
713 // Go through all componets
714 for (c_it; c_it != iter_end; c_it++) {
715 GObjectController* obc = c_it->second;
716 int obc_type = obc->getModel()->getGObjectType();
717 int obc_state = obc->getView()->getState();
718 // if the component is a port and the type is the same of that selected
719 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
720 // Return element to neutral state if not selected
721 obc->getView()->setState(NOTHING_HAPPENS);
723 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
724 // Change element to connected state
725 obc->getView()->setState(HIGHLIGHTED);
732 _parent->saveTempandUpdate("create connection");
735 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
736 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
738 std::map<int, GObjectController*>::iterator it2;
740 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
741 GObjectController *cont = it2->second;
742 if (cont->getView() != NULL) {
743 cont->getView()->setState(NOTHING_HAPPENS);
744 cont->getModel()->notifyObservers(_idManager);
746 cont->SetActive(true);
755 //=========================================================================
757 bool wxVtkSceneManager::OnMouseMove() {
759 bool okStatusMessage = false;
760 bool okPortMessage = false;
761 wxVTKRenderWindowInteractor *wxVTKiren;
762 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
763 wxVTKiren->GetEventPosition(X, Y);
765 if (_worldState == DRAG_OBJECTS) {
766 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
767 int id = _selectedObjects[i];
768 GObjectController* cont = _controllers[id];
769 if (_startDragging) {
770 cont->getView()->setStartDragging(true);
772 cont->getView()->moveObject(X, Y);
773 cont->getView()->setState(DRAG);
774 cont->getModel()->notifyObservers(_idManager);
777 std::map<int, GObjectController*>::iterator it;
779 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
780 GObjectController *desc = it->second;
781 if (desc->getGObjectType() == GCONNECTOR) {
782 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
783 vconn->updateStartEndPoints();
787 _startDragging = false;
789 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
790 std::map<int, GObjectController*>::iterator it;
792 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
793 GObjectController *desc = it->second;
794 int type = desc->getGObjectType();
795 int state = desc->getView()->getState();
796 desc->getModel()->getCenter(px, py, pz);
799 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION )) {
801 okStatusMessage = true;
802 updateStatusBar(desc->getStatusText());
803 if (type == GBLACKBOX) {
804 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
805 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),
810 okPortMessage = true;
812 _textActor->SetInput(desc->getStatusText().c_str());
813 _textActor->SetScale(0.1);
814 _textActor->SetPosition(px - 25, py + 1, pz + 2);
819 _fillObjectActor->SetScale(1);
820 _fillObjectActor->GetProperty()->SetOpacity(0.50);
821 _fillObjectActor->SetPosition(px, py, 1);
822 _aPolygonMapper->Modified();
825 } // for controllers it
828 if (okStatusMessage == false) {
832 if (okPortMessage == false) {
833 _textActor->SetScale(0.0001);
834 _fillObjectActor->SetScale(0.0001);
839 //=========================================================================
841 bool wxVtkSceneManager::OnLeftButtonDown() {
843 if (_worldState == INIT_CREATION_CONTOUR) {
844 bool isOverPort = false;
845 std::map<int, GObjectController*>::iterator it;
846 for (it = _controllers.begin(); it != _controllers.end() && isOverPort
848 GObjectController *desc = it->second;
849 if (desc->getGObjectType() == GPORT) {
850 GPortModel *portmod = (GPortModel*) desc->getModel();
851 vtkGObjectView *portView = desc->getView();
852 if (portmod->getPortType() == GINPUTPORT
853 && portView->getState() == HIGHLIGHTED) {
857 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
859 portView->setState( HIGHLIGHTED);
866 if (isOverPort == false) {
868 UnSelectBlackBoxes();
872 } else { //_worldState
874 _worldState = DRAG_OBJECTS;
875 _startDragging = true;
877 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
878 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
879 ctrlkey = ctrlkey + shiftkey;
881 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
883 if (GetGBlackBoxControlerPointedByMouse() != NULL) {
884 int state = cont->getView()->getState();
885 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
886 UnSelectBlackBoxes();
889 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
890 int id = _selectedObjects[i];
891 GObjectController* cont = _controllers[id];
892 cont->getView()->setState(DRAG);
893 cont->getModel()->notifyObservers(_idManager);
896 } // if _selectedObjects.size
902 //=========================================================================
904 bool wxVtkSceneManager::OnLeftButtonUp() {
905 if (_worldState == DRAG_OBJECTS) {
906 _worldState = NOTHING_HAPPENS;
908 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
909 int id = _selectedObjects[i];
910 GObjectController* cont = _controllers[id];
911 cont->getView()->setState(SELECTED);
912 cont->getModel()->notifyObservers(_idManager);
918 //=========================================================================
919 void wxVtkSceneManager::CancelConnection() {
920 if (_worldState == INIT_CREATION_CONTOUR) {
921 _worldState = NOTHING_HAPPENS;
922 //int lastId = _controllers.size()-1;
924 GConnectorController *connector =
925 (GConnectorController*) _controllers[_idConnectionInCreation];
926 connector->removeFromScene();
927 unregisterController(connector);
928 _controllers.erase(_idConnectionInCreation);
930 std::map<int, GObjectController*>::iterator it;
931 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
932 GObjectController *desc = it->second;
933 desc->SetActive(true);
934 desc->getView()->setState(NOTHING_HAPPENS);
935 desc->getModel()->notifyObservers(_idManager);
940 //=========================================================================
942 bool wxVtkSceneManager::OnRightButtonUp() {
943 if (_worldState == INIT_CREATION_CONTOUR) {
946 UnSelectBlackBoxes();
952 bool wxVtkSceneManager::OnMiddleButtonDown() {
955 this->_vtkInteractorStyleBaseView->StartPan();
960 bool wxVtkSceneManager::OnMiddleButtonUp() {
963 this->_vtkInteractorStyleBaseView->EndPan();
970 //=========================================================================
972 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
973 GObjectController *result = NULL;
975 wxVTKRenderWindowInteractor *wxVTKiren;
977 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
978 wxVTKiren->GetEventPosition(X, Y);
980 std::map<int, GObjectController*>::iterator it;
982 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
983 GObjectController *cont = it->second;
984 int type = cont->getGObjectType();
986 if (cont->getView()->isPointInside(X, Y) == true) {
987 if (type == GBLACKBOX) {
990 } // if isPointInside
995 //=========================================================================
996 void wxVtkSceneManager::UnSelectBlackBoxes() {
997 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
998 int id = _selectedObjects[i];
999 GObjectController* control = _controllers[id];
1000 control->getView()->setState(NOTHING_HAPPENS);
1001 control->getModel()->notifyObservers(_idManager);
1002 }// for _selectedObjects
1003 _selectedObjects.clear();
1006 //=========================================================================
1007 bool wxVtkSceneManager::OnLeftDClick() {
1008 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1010 UnSelectBlackBoxes();
1011 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1017 wxVTKRenderWindowInteractor *wxVTKiren;
1018 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1019 wxVTKiren->GetEventPosition(X,Y);
1021 std::map<int, GObjectController*>::iterator it;
1023 bool clickOnObject = false;
1025 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1027 GObjectController *cont = it->second;
1028 int type = cont->getGObjectType();
1030 if(cont->getView()->isPointInside(X,Y))
1034 for (int i=0; i< (int)_selectedObjects.size(); i++)
1036 int id = _selectedObjects[i];
1037 GObjectController* control = _controllers[id];
1038 control->getView()->setState(NOTHING_HAPPENS);
1040 _selectedObjects.clear();
1042 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1043 _parent->editBlackBox(bbmodel);
1045 clickOnObject = true;
1049 if(clickOnObject==false)
1051 //_parent->editDiagramParameters(this);
1057 //=========================================================================
1059 bool wxVtkSceneManager::OnChar()
1062 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1063 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1065 // KeyCode 127 : Delete Key
1066 // KeyCode 8 : Backspace Key
1067 if (keyCode == 8 || keyCode == 127)
1069 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1071 int id = _selectedObjects[i];
1072 printf("EED wxVtkSceneManager::OnChar %d %d\n", i, id);
1073 std::map<int, GObjectController*>::iterator it;
1074 it = _controllers.find(id);
1075 if (it != _controllers.end()) {
1076 ok=ok||deleteObject(id);
1078 }// for selected objects
1079 if (ok) _selectedObjects.clear();
1080 _parent->saveTempandUpdate("delete object");
1085 if((keyCode==0) && (ctrlkey==1)) {
1090 if(_selectedObjects.size()){
1091 std::cout<<"objects to copy :";
1092 for(int i=0;i<_selectedObjects.size();i++){
1093 std::cout<<_selectedObjects.at(i)<<" ";
1095 DuplicateObjects(getSelectedObjects());
1097 std::cout<<"No objects to copy\n";
1098 } // _selectedObjects.size
1104 //=========================================================================
1106 void wxVtkSceneManager::AddControlerToBeRemove(
1107 std::vector<int> *controllersToRemove, int id) {
1111 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1112 if (id == (*controllersToRemove)[i]) {
1118 controllersToRemove->push_back(id);
1123 //=========================================================================
1125 bool wxVtkSceneManager::deleteObject(int id)
1128 GObjectController *control = _controllers[id];
1129 std::vector<int> controllersToRemove;
1131 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1132 == GCOMPLEXINPUTPORT || control->getGObjectType()
1133 == GCOMPLEXOUTPUTPORT) {
1134 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1135 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1137 bool boxConnected = false;
1139 // Add box input controllers to be removed
1140 for (int i = 0; i < (int) inputs.size(); i++) {
1141 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1142 if (inputs[i]->isConnected()) {
1143 boxConnected = true;
1147 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1149 // Add box output controllers to be removed
1150 for (int i = 0; i < (int) outputs.size(); i++) {
1151 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1152 if (outputs[i]->isConnected()) {
1153 boxConnected = true;
1157 // Add connection controllers to be removed
1158 std::map<int, GObjectController*>::iterator it;
1159 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1160 GObjectController *cont = it->second;
1161 int type = cont->getGObjectType();
1162 if (type == GCONNECTOR) {
1163 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1164 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1166 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1168 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1170 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1175 // Add box controller to be removed
1176 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1177 } else if (control->getGObjectType() == GCONNECTOR) {
1178 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1179 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1181 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1182 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1184 gconnectorcontroler->getManualContourController()->OnChar();
1189 std::map<int, GObjectController*>::iterator it;
1191 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1192 int key = controllersToRemove[i];
1193 it = _controllers.find(key);
1194 GObjectController *cont = _controllers[key];
1196 cont->removeFromScene();
1197 unregisterController((InteractorStyleMaracas*) cont);
1198 _controllers.erase(it);
1206 //=========================================================================
1208 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1209 std::string boxName) {
1210 _parent->displayBlackBoxInfo(packageName, boxName);
1213 //=========================================================================
1215 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1216 _parent->updateStatusBar(textStatus);
1219 //=========================================================================
1220 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1221 std::string result = "";
1222 if (withLineNumber == true) {
1224 stringstream StrStream;
1226 std::string strValue = StrStream.str();
1229 } else if (value < 100) {
1233 result += strValue + ": ";
1237 //=========================================================================
1239 bool wxVtkSceneManager::MakeBoxExecutable() {
1240 std::map<int, GObjectController*> selected = getSelectedObjects();
1241 if( selected.empty() )
1244 std::map<int, GObjectController*>::iterator it;
1245 for (it = selected.begin(); it != selected.end(); ++it) {
1246 GObjectController* lastSelected = it->second;
1248 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1249 GBlackBoxModel *bbmodel =
1250 (GBlackBoxModel*) lastSelected->getModel();
1251 view->setState(HIGHLIGHTED);
1252 if (bbmodel->isExecutable()) {
1253 bbmodel->setExecutable(false);
1255 bbmodel->setExecutable(true);
1257 bbmodel->notifyObservers(lastSelected->getId());
1265 //=========================================================================
1267 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1268 bool existsExec = false;
1270 std::vector<std::string> packages;
1271 std::vector<int> boxes;
1272 std::vector<int> connections;
1273 std::vector<int> execBoxes;
1275 std::map<int, GObjectController*>::iterator it;
1277 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1278 GObjectController *desc = it->second;
1279 int type = desc->getGObjectType();
1281 if (type == GBLACKBOX) {
1282 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1284 std::string pkg = mod->getBBTKPackage();
1285 bool existsPkg = false;
1286 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1287 if (packages[t] == pkg) {
1292 packages.push_back(pkg);
1295 boxes.push_back(it->first);
1296 if (mod->isExecutable()) {
1297 execBoxes.push_back(it->first);
1300 } else if (type == GCONNECTOR) {
1301 connections.push_back(it->first);
1306 std::string script = "";
1307 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1308 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1309 script += LineNumber(wln, lnNmbr) + "\n";
1311 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1312 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1314 for (i = 0; i < (int) packages.size(); i++) {
1315 script += LineNumber(wln, lnNmbr);
1316 script += "include ";
1317 script += packages[i];
1321 script += LineNumber(wln, lnNmbr);
1326 script += LineNumber(wln, lnNmbr);
1327 script += "author \"";
1331 script += LineNumber(wln, lnNmbr);
1332 script += "description \"";
1333 script += _Description;
1336 script += LineNumber(wln, lnNmbr);
1337 script += "category \"";
1338 script += _Category;
1341 script += LineNumber(wln, lnNmbr);
1344 // script+="include std\n"; // JPR
1346 for (i = 0; i < (int) boxes.size(); i++) {
1347 script += LineNumber(wln, lnNmbr);
1350 GObjectController *control = _controllers[id];
1351 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1353 script += model->getBBTKType();
1355 script += model->getBBTKName();
1358 std::vector<GPortModel*> inputs = model->getInputPorts();
1359 for (int j = 0; j < (int) inputs.size(); j++) {
1360 GPortModel* inputPort = inputs[j];
1361 if (inputPort->isValueSet()) {
1362 script += LineNumber(wln, lnNmbr);
1364 script += model->getBBTKName();
1366 script += inputPort->getBBTKName();
1368 script += inputPort->getValue();
1373 script += LineNumber(wln, lnNmbr);
1378 script += LineNumber(wln, lnNmbr);
1381 for (i = 0; i < (int) connections.size(); i++) {
1382 script += LineNumber(wln, lnNmbr);
1383 script += "connect ";
1384 int id = connections[i];
1385 GObjectController *control = _controllers[id];
1386 GConnectorModel *model = (GConnectorModel*) control->getModel();
1388 //Start Connection info
1389 GPortModel *start = model->getStartPort();
1390 script += start->getParentBox()->getBBTKName();
1392 script += start->getBBTKName();
1396 //End Connection info
1397 GPortModel *end = model->getEndPort();
1398 script += end->getParentBox()->getBBTKName();
1400 script += end->getBBTKName();
1405 script += LineNumber(wln, lnNmbr);
1407 for (i = 0; i < (int) execBoxes.size(); i++) {
1408 script += LineNumber(wln, lnNmbr);
1410 int id = execBoxes[i];
1411 GObjectController *control = _controllers[id];
1412 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1414 script += model->getBBTKName();
1423 //=========================================================================
1425 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1426 std::vector<std::string> packages;
1427 std::vector<int> boxes;
1428 std::vector<int> connections;
1429 std::vector<int> execBoxes;
1431 std::map<int, GObjectController*>::iterator it;
1433 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1434 GObjectController *desc = it->second;
1435 int type = desc->getGObjectType();
1437 if (type == GBLACKBOX) {
1438 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1440 std::string pkg = mod->getBBTKPackage();
1441 bool existsPkg = false;
1442 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1443 if (packages[t] == pkg) {
1448 packages.push_back(pkg);
1451 boxes.push_back(it->first);
1452 if (mod->isExecutable()) {
1453 execBoxes.push_back(it->first);
1455 } else if (type == GCONNECTOR) {
1456 connections.push_back(it->first);
1460 std::string script = "";
1462 script += "include std\n"; // EED
1463 script += "include itkvtk\n"; // EED
1465 for (i = 0; i < (int) packages.size(); i++) {
1466 script += "include ";
1467 script += packages[i];
1472 // Definition of a complex box
1473 script += "define ";
1474 script += _cbName + " " + _cbPackageName;
1478 script += "author \"";
1482 script += "description \"";
1483 script += _Description;
1487 script += "category \"";
1488 script += _Category;
1493 for (i = 0; i < (int) boxes.size(); i++) {
1496 GObjectController *control = _controllers[id];
1497 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1499 script += model->getBBTKType();
1501 script += model->getBBTKName();
1504 std::vector<GPortModel*> inputs = model->getInputPorts();
1505 for (int j = 0; j < (int) inputs.size(); j++) {
1506 GPortModel* inputPort = inputs[j];
1507 if (inputPort->isValueSet()) {
1509 script += model->getBBTKName();
1511 script += inputPort->getBBTKName();
1513 script += inputPort->getValue();
1521 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1523 std::string complexInputs = "";
1524 std::string complexOutputs = "";
1527 for (i = 0; i < (int) connections.size(); i++) {
1528 int id = connections[i];
1529 GObjectController *control = _controllers[id];
1530 GConnectorModel *model = (GConnectorModel*) control->getModel();
1533 GPortModel *start = model->getStartPort();
1534 GBoxModel *startBox = start->getParentBox();
1536 GPortModel *end = model->getEndPort();
1537 GBoxModel *endBox = end->getParentBox();
1539 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1540 complexInputs += "input ";
1541 complexInputs += startBox->getBBTKName();
1543 complexInputs += " ";
1544 complexInputs += endBox->getBBTKName();
1545 complexInputs += ".";
1546 complexInputs += end->getBBTKName();
1548 complexInputs += " ";
1549 complexInputs += "\" \"";
1551 complexInputs += "\n";
1552 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1553 complexOutputs += "output ";
1554 complexOutputs += endBox->getBBTKName();
1556 complexOutputs += " ";
1557 complexOutputs += startBox->getBBTKName();
1558 complexOutputs += ".";
1559 complexOutputs += start->getBBTKName();
1561 complexOutputs += " ";
1562 complexOutputs += "\" \"";
1564 complexOutputs += "\n";
1566 script += "connect ";
1567 script += startBox->getBBTKName();
1569 script += start->getBBTKName();
1573 //End Connection info
1574 script += endBox->getBBTKName();
1576 script += end->getBBTKName();
1584 for (i = 0; i < (int) execBoxes.size(); i++) {
1586 int id = execBoxes[i];
1587 GObjectController *control = _controllers[id];
1588 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1590 script += model->getBBTKName();
1595 script += "# Complex input ports\n";
1596 script += complexInputs;
1599 script += "# Complex output ports\n";
1600 script += complexOutputs;
1603 script += "endefine";
1609 //=========================================================================
1611 void wxVtkSceneManager::deleteAllBoxes() {
1612 std::map<int, GObjectController*>::iterator it;
1613 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1614 GObjectController *cont = it->second;
1615 cont->removeFromScene();
1616 unregisterController((InteractorStyleMaracas*) cont);
1618 _selectedObjects.clear();
1619 _controllers.clear();
1622 //=========================================================================
1625 void wxVtkSceneManager::refresh() {
1626 _baseView->Refresh();
1628 //=========================================================================
1630 void wxVtkSceneManager::refreshScene() {
1631 _baseView->RefreshView();
1634 //=========================================================================
1636 void wxVtkSceneManager::centerView() {
1638 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1639 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1640 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1641 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1644 //=========================================================================
1646 void wxVtkSceneManager::saveDiagram(std::string &content) {
1649 content += "CATEGORY:";
1650 content += GetCategory();
1653 content += "DESCRIPTION:";
1654 content += GetDescription();
1657 content += "AUTHOR:";
1658 content += GetAuthor();
1661 //Print info IF COMPLEX BOX
1662 content += "COMPLEXBOX:";
1663 if (_isComplexBox) {
1664 content += "TRUE\n";
1666 content += "COMPLEXBOXNAME:";
1667 content += GetCbName();
1670 content += "PACKAGENAME:";
1671 content += GetCbPackageName();
1674 //Print info complex input ports
1675 std::vector<int> inputs = getComplexInputPorts();
1676 int insize = inputs.size();
1677 content += "COMPLEXINPUTS:";
1678 sprintf(buffer, "%d", insize);
1682 for (int i = 0; i < insize; i++) {
1684 GObjectController *cont = _controllers[id];
1685 cont->getModel()->save(content);
1688 //Print info complex output ports
1689 std::vector<int> outputs = getComplexOutputPorts();
1690 int outsize = outputs.size();
1691 content += "COMPLEXOUTPUTS:";
1692 sprintf(buffer, "%d", outsize);
1696 for (int i = 0; i < outsize; i++) {
1697 int id = outputs[i];
1698 GObjectController *cont = _controllers[id];
1699 cont->getModel()->save(content);
1703 content += "FALSE\n";
1707 std::vector<int> boxes = getBlackBoxes();
1708 int bsize = boxes.size();
1709 content += "BOXES:";
1710 sprintf(buffer, "%d", bsize);
1714 for (int i = 0; i < bsize; i++) {
1716 GObjectController *cont = _controllers[id];
1717 cont->getModel()->save(content);
1721 std::vector<int> connections = getConnections();
1722 int csize = connections.size();
1723 content += "CONNECTIONS:";
1724 sprintf(buffer, "%d", csize);
1728 for (int i = 0; i < csize; i++) {
1729 int id = connections[i];
1730 GObjectController *cont = _controllers[id];
1731 cont->getModel()->save(content);
1736 //=========================================================================
1738 void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
1740 std::string version = "<void>";
1741 std::string line = "";
1742 char delims[] = ":";
1743 char *result = NULL;
1745 getline(inputStream, line);
1748 while (!inputStream.eof()) {
1749 if (line == "" || line[0] == '#') {
1750 getline(inputStream, line);
1751 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1752 version = line.substr(18, 3);
1754 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1755 version = line.substr(18, 3);
1757 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1758 version = line.substr(18, 3);
1760 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1761 version = line.substr(18, 3);
1763 } else if (line == "APP_START") {
1769 printf("EED wxVtkSceneManager::loadDiagram version=%s\n", version.c_str());
1773 if ((version != "1.0") && (version != "1.1")) {
1774 getline(inputStream, line);//CATEGORY:<category of the box>
1775 char categoryTmp[30];
1776 strcpy(categoryTmp, line.c_str());
1777 result = strtok(categoryTmp, delims);
1778 result = strtok(NULL, delims);
1779 SetCategory(result);
1781 getline(inputStream, line);//DESCRIPTION:<description of the box>
1782 char descriptionTmp[1024];
1783 strcpy(descriptionTmp, line.c_str());
1784 result = strtok(descriptionTmp, delims);
1785 result = strtok(NULL, delims);
1786 SetDescription(result);
1788 getline(inputStream, line);//AUTHOR:<author>
1789 char authorTmp[255];
1790 strcpy(authorTmp, line.c_str());
1791 result = strtok(authorTmp, delims);
1792 result = strtok(NULL, delims);
1797 getline(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1798 char complexTmp[30];
1799 strcpy(complexTmp, line.c_str());
1800 result = strtok(complexTmp, delims);
1801 result = strtok(NULL, delims);
1802 std::string isComplexBox(result);
1804 if (isComplexBox == "TRUE") {
1805 _isComplexBox = true;
1807 if ((version != "1.0") && (version != "1.1")) {
1808 getline(inputStream, line);//COMPLEXNAME:<name of the complex box>
1809 char complexboxnameTmp[255];
1810 strcpy(complexboxnameTmp, line.c_str());
1811 result = strtok(complexboxnameTmp, delims);
1812 result = strtok(NULL, delims);
1815 getline(inputStream, line);//PACKAGENAME:<name of the package of the box>
1816 char packagenameTmp[255];
1817 strcpy(packagenameTmp, line.c_str());
1818 result = strtok(packagenameTmp, delims);
1819 result = strtok(NULL, delims);
1820 SetCbPackageName(result);
1823 //-----------------------
1824 //- COMPLEX INPUT PORTS
1825 //-----------------------
1826 getline(inputStream, line);//COMPLEXINPUTS:num
1828 strcpy(inputs, line.c_str());
1829 result = strtok(inputs, delims);
1830 result = strtok(NULL, delims);
1833 std::istringstream inps(result);
1836 for (int i = 0; i < numInputs; i++) {
1838 getline(inputStream, line);//COMPLEX_PORT
1839 getline(inputStream, line);//name
1840 std::string inputPortName(line);
1843 getline(inputStream, line);//xInic:yInic:zInic
1845 strcpy(coord, line.c_str());
1846 result = strtok(coord, delims);//xInic
1847 std::string xInic(result);
1848 result = strtok(NULL, delims);//yInic
1849 std::string yInic(result);
1850 result = strtok(NULL, delims);//zInic
1851 std::string zInic(result);
1853 double xIn, yIn, zIn;
1854 std::istringstream xSt(xInic);
1856 std::istringstream ySt(yInic);
1858 std::istringstream zSt(zInic);
1863 if (zIn==900) zIn=GPOSITION_Z;
1866 getline(inputStream, line);//FIN_COMPLEX_PORT
1868 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
1870 } // for input complex box
1873 //-----------------------
1874 //- COMPLEX OUTPUT PORTS
1875 //-----------------------
1877 getline(inputStream, line);//COMPLEXOUTPUTS:num
1879 strcpy(outputs, line.c_str());
1880 result = strtok(outputs, delims);
1881 result = strtok(NULL, delims);
1884 std::istringstream outps(result);
1885 outps >> numOutputs;
1887 for (int i = 0; i < numOutputs; i++) {
1889 getline(inputStream, line);//COMPLEX_PORT
1890 getline(inputStream, line);//name
1891 std::string outputPortName(line);
1894 getline(inputStream, line);//xInic:yInic:zInic
1896 strcpy(coord, line.c_str());
1897 result = strtok(coord, delims);//xInic
1898 std::string xInic(result);
1899 result = strtok(NULL, delims);//yInic
1900 std::string yInic(result);
1901 result = strtok(NULL, delims);//zInic
1902 std::string zInic(result);
1904 double xIn, yIn, zIn;
1905 std::istringstream xSt(xInic);
1907 std::istringstream ySt(yInic);
1909 std::istringstream zSt(zInic);
1914 if (zIn==900) zIn=GPOSITION_Z;
1917 getline(inputStream, line);//FIN_COMPLEX_PORT
1919 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
1921 } // for output complex box
1926 getline(inputStream, line);//BOXES:num
1928 strcpy(boxes, line.c_str());
1929 result = strtok(boxes, delims);
1930 result = strtok(NULL, delims);
1933 std::istringstream is(result);
1936 for (int i = 0; i < numBoxes; i++) {
1938 getline(inputStream, line);//BOX
1939 getline(inputStream, line);//package:type:name
1941 strcpy(box, line.c_str());
1942 result = strtok(box, delims);//package
1943 std::string package(result);
1944 result = strtok(NULL, delims);//type
1945 std::string type(result);
1946 result = strtok(NULL, delims);//name
1947 std::string name(result);
1949 getline(inputStream, line);//ISEXEC:TRUE|FALSE
1951 strcpy(exec, line.c_str());
1952 result = strtok(exec, delims);//ISEXEC
1953 result = strtok(NULL, delims);//TRUE|FALSE
1954 std::string isExec(result);
1957 getline(inputStream, line);//xInic:yInic:zInic
1959 strcpy(coord, line.c_str());
1960 result = strtok(coord, delims);//xInic
1961 std::string xInic(result);
1962 result = strtok(NULL, delims);//yInic
1963 std::string yInic(result);
1964 result = strtok(NULL, delims);//zInic
1965 std::string zInic(result);
1967 double xIn, yIn, zIn;
1968 std::istringstream xSt(xInic);
1970 std::istringstream ySt(yInic);
1972 std::istringstream zSt(zInic);
1978 if (zIn==900) zIn=GPOSITION_Z;
1983 getline(inputStream, line);//xEnd:yEnd:zEnd
1984 strcpy(coord, line.c_str());
1985 result = strtok(coord, delims);//xEnd
1986 std::string xEnd(result);
1987 result = strtok(NULL, delims);//yEnd
1988 std::string yEnd(result);
1989 result = strtok(NULL, delims);//zEnd
1990 std::string zEnd(result);
1992 double xEn, yEn, zEn;
1993 std::istringstream xEt(xEnd);
1995 std::istringstream yEt(yEnd);
1997 std::istringstream zEt(zEnd);
2002 if (zEn==900) zEn=GPOSITION_Z;
2006 bool boxExecutable = false;
2007 if (isExec == "TRUE") {
2008 boxExecutable = true;
2011 int idBox = createGBlackBox(xIn, yIn, package, type);
2012 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2014 GObjectController *cont = _controllers[idBox];
2015 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2018 getline(inputStream, line);//PORT o FIN_BOX
2019 std::string port = line.substr(0, 4);
2020 while (port == "PORT") {
2021 getline(inputStream, line);//name:value
2023 strcpy(poort, line.c_str());
2024 result = strtok(poort, delims);//name
2025 std::string name(result);
2026 result = strtok(NULL, delims);//value
2027 std::string value(result);
2029 bbmod->setValueToInput(name, value);
2031 getline(inputStream, line);//PORT o FIN_BOX
2032 port = line.substr(0, 4);
2035 //EED bbmod->notifyObservers(_idManager);
2040 getline(inputStream, line);//CONNECTIONS:num
2042 strcpy(conns, line.c_str());
2043 result = strtok(conns, delims);
2044 result = strtok(NULL, delims);
2047 std::istringstream isCons(result);
2050 for (int i = 0; i < numConns; i++) {
2052 getline(inputStream, line);//CONNECTION
2053 getline(inputStream, line);//Startbox.PortName:EndBox.PortName
2056 strcpy(connec, line.c_str());
2057 result = strtok(connec, delims);
2058 std::string nameStartBox(result);
2059 result = strtok(NULL, delims);
2060 std::string nameStartPort(result);
2061 result = strtok(NULL, delims);
2062 std::string nameEndBox(result);
2063 result = strtok(NULL, delims);
2064 std::string nameEndPort(result);
2066 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2068 if (version != "1.0") {
2069 //Readding control points of the manualContour
2070 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2071 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2072 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2073 getline(inputStream, line); //NumberOfControlPoints:##
2074 strcpy(conns, line.c_str());
2075 result = strtok(conns, delims);
2076 result = strtok(NULL, delims);
2078 int numberOfControlPoints;
2079 std::istringstream isCons(result);
2080 isCons >> numberOfControlPoints;
2082 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2083 getline(inputStream, line); //XX:YY:ZZ
2085 strcpy(connec, line.c_str());
2088 result = strtok(connec, delims);
2089 std::istringstream isPointX(result);
2091 result = strtok(NULL, delims);
2092 std::istringstream isPointY(result);
2094 result = strtok(NULL, delims);
2095 std::istringstream isPointZ(result);
2100 if (pz==900) pz=GPOSITION_Z;
2103 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2104 conView->getManualContourView()->AddPoint();
2113 //=========================================================================
2116 //=========================================================================
2117 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2118 std::string portName, double xIn, double yIn, double zIn) {
2120 if (inputoutput == true) {
2121 idPort = createGComplexBoxInputPort(portName);
2123 idPort = createGComplexBoxOutputPort(portName);
2125 GObjectController *cont = _controllers[idPort];
2126 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2127 cbmod->setInicPoint(xIn, yIn, zIn);
2128 cbmod->notifyObservers(_idManager);
2130 //=========================================================================
2133 //=========================================================================
2134 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
2138 GBoxModel *boxModel = NULL;
2139 std::vector<int> lstB = getBlackBoxes();
2140 for (j = 0; j < (int) lstB.size(); j++) {
2142 bMod = (GBoxModel*) _controllers[idB]->getModel();
2143 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2148 if ((_isComplexBox) && (boxModel == NULL)) {
2149 std::vector<int> lstInputs = getComplexInputPorts();
2150 for (j = 0; j < (int) lstInputs.size(); j++) {
2152 bMod = (GBoxModel*) _controllers[idB]->getModel();
2153 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2158 std::vector<int> lstOutputs = getComplexOutputPorts();
2159 for (j = 0; j < (int) lstOutputs.size(); j++) {
2160 int idB = lstOutputs[j];
2161 bMod = (GBoxModel*) _controllers[idB]->getModel();
2162 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2172 //=========================================================================
2175 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2176 std::string nameStartPort, std::string nameEndBox,
2177 std::string nameEndPort) {
2179 GBoxModel *boxModel;
2180 GPortModel *startP = NULL;
2181 GPortModel *endP = NULL;
2183 boxModel = findGBox(nameStartBox);
2184 if (boxModel != NULL) {
2185 startP = boxModel->getOutputPort(nameStartPort);
2187 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port %s is null. Port name is probably wrong.\n", nameStartPort.c_str());
2191 boxModel = findGBox(nameEndBox);
2192 if (boxModel != NULL) {
2193 endP = boxModel->getInputPort(nameEndPort);
2195 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port %s is null. Port name is probably wrong\n", nameStartPort.c_str(), nameEndPort.c_str());
2200 int idCon = createGConnector(startP);
2201 _worldState = NOTHING_HAPPENS;
2202 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2204 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2205 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2206 tempp->endContourCreation();
2207 conMod->setEndPort(endP);
2208 conView->updateStartEndPoints();
2212 //=========================================================================
2214 bool wxVtkSceneManager::boxExist(std::string boxname) {
2216 std::map<int, GObjectController*>::iterator it;
2217 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2218 GObjectController *cont = it->second;
2219 if (cont->getModel()->getBBTKName() == boxname) {
2226 //=========================================================================
2228 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2229 std::vector<int> vect;
2230 std::map<int, GObjectController*>::iterator it;
2231 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2232 GObjectController *cont = it->second;
2233 if (cont->getGObjectType() == GBLACKBOX) {
2234 vect.push_back(cont->getId());
2240 //=========================================================================
2242 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2243 std::vector<int> vect;
2244 std::map<int, GObjectController*>::iterator it;
2245 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2246 GObjectController *cont = it->second;
2247 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2248 vect.push_back(cont->getId());
2254 //=========================================================================
2256 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2257 std::vector<int> vect;
2258 std::map<int, GObjectController*>::iterator it;
2259 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2260 GObjectController *cont = it->second;
2261 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2262 vect.push_back(cont->getId());
2268 //=========================================================================
2270 std::vector<int> wxVtkSceneManager::getConnections() {
2271 std::vector<int> vect;
2272 std::map<int, GObjectController*>::iterator it;
2273 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2274 GObjectController *cont = it->second;
2275 if (cont->getGObjectType() == GCONNECTOR) {
2276 vect.push_back(cont->getId());
2282 //=========================================================================
2284 bool wxVtkSceneManager::isComplexBox() {
2285 return _isComplexBox;
2288 //=========================================================================
2290 void wxVtkSceneManager::setComplexBox(bool val) {
2291 _isComplexBox = val;
2294 //=========================================================================
2296 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2297 //Register the controller of the new object
2298 registerController((InteractorStyleMaracas*) objController);
2299 //Add the object to the objects list
2300 int newId = _contLastId;//_controllers.size();
2301 objController->setId(newId);
2302 _controllers[newId] = objController;
2303 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2308 //=========================================================================
2310 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2312 std::map<int, int> oldIdNewIdBoxes;
2313 std::vector<int> connections;
2315 std::vector<int> newBoxesID;
2317 std::map<int, GObjectController*>::iterator it;
2318 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2319 GObjectController *cont = it->second;
2320 int type = cont->getGObjectType();
2322 if (type == GBLACKBOX) {
2324 double xInic, yInic, zInic;
2325 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2326 copyBox->getInicPoint(xInic, yInic, zInic);
2327 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2328 copyBox->getBBTKType());
2330 int idcB = copyBox->getObjectId();
2331 oldIdNewIdBoxes[idcB] = idBox;
2332 cont = _controllers[idBox];
2333 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2334 newbox->setInicPoint(xInic, yInic, zInic);
2335 int num = newbox->getNumInputPorts();
2336 for (int j = 0; j < num; j++) {
2337 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2339 newbox->move(xInic + 20, yInic + 20, zInic);
2340 newbox->notifyObservers(_idManager);
2341 newBoxesID.push_back(newbox->getObjectId());
2343 } else if (type == GCONNECTOR) {
2344 int idCon = cont->getId();
2345 connections.push_back(idCon);
2350 for (int i = 0; i < (int) connections.size(); i++) {
2351 int objId = connections[i];
2352 GObjectController *cont = objectsMap[objId];
2353 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2355 GPortModel* startPort = connectModel->getStartPort();
2356 int startPortIndex = startPort->getPosInBox();
2357 GPortModel* endPort = connectModel->getEndPort();
2358 int endPortIndex = endPort->getPosInBox();
2360 GBlackBoxModel* startPortParentBox =
2361 (GBlackBoxModel*) startPort->getParentBox();
2362 GBlackBoxModel* endPortParentBox =
2363 (GBlackBoxModel*) endPort->getParentBox();
2365 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2366 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2368 GBlackBoxModel* newStartBox =
2369 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2370 GBlackBoxModel* newEndBox =
2371 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2373 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2374 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2376 // Creates connection
2377 int idCon = createGConnector(newStartPort);
2378 GConnectorController *tempp =
2379 (GConnectorController*) _controllers[idCon];
2380 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2381 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2382 tempp->endContourCreation();
2383 conMod->setEndPort(newEndPort);
2384 conView->updateStartEndPoints();
2387 /// the new selected boxes are the duplicate ones
2389 UnSelectBlackBoxes();
2390 for (int i = 0; i < newBoxesID.size(); i++) {
2391 _selectedObjects.push_back(newBoxesID.at(i));
2394 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2395 int id = _selectedObjects[i];
2396 GObjectController* cont = _controllers[id];
2398 cont->getView()->setState(SELECTED);
2399 cont->getModel()->notifyObservers(_idManager);
2405 //=========================================================================
2407 int wxVtkSceneManager::getNumSelectedObjects() {
2408 return _selectedObjects.size();
2411 //=========================================================================
2413 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2414 std::map<int, GObjectController*> mapSelected;
2416 std::map<int, GObjectController*>::iterator it;
2417 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2418 GObjectController *cont = it->second;
2419 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2421 mapSelected[cont->getId()] = cont;
2425 std::map<int, GObjectController*>::iterator it2;
2426 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2427 GObjectController *cont = it2->second;
2428 if (cont->getGObjectType() == GCONNECTOR) {
2429 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2430 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2431 GBoxModel* startPortParentBox =
2432 cmod->getStartPort()->getParentBox();
2434 std::map<int, GObjectController*>::iterator iterOBJ1 =
2435 mapSelected.find(startPortParentBox->getObjectId());
2436 std::map<int, GObjectController*>::iterator iterOBJ2 =
2437 mapSelected.find(endPortParentBox->getObjectId());
2439 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2440 int ID = cont->getId();
2441 mapSelected[ID] = cont;
2448 //=========================================================================
2450 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2452 std::map<int, int> oldIdNewIdBoxes;
2453 std::vector<int> connections;
2455 std::map<int, GObjectController*>::iterator it;
2456 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2457 GObjectController *cont = it->second;
2458 int type = cont->getGObjectType();
2460 if (type == GBLACKBOX) {
2462 double xInic, yInic, zInic;
2463 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2464 copyBox->getInicPoint(xInic, yInic, zInic);
2465 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2466 copyBox->getBBTKType());
2468 int idcB = copyBox->getObjectId();
2469 oldIdNewIdBoxes[idcB] = idBox;
2470 cont = _controllers[idBox];
2471 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2472 newbox->setInicPoint(xInic, yInic, zInic);
2473 int num = newbox->getNumInputPorts();
2474 for (int j = 0; j < num; j++) {
2475 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2477 newbox->notifyObservers(_idManager);
2478 } else if (type == GCONNECTOR) {
2479 int idCon = cont->getId();
2480 connections.push_back(idCon);
2485 for (int i = 0; i < (int) connections.size(); i++) {
2486 int objId = connections[i];
2487 GObjectController *cont = objectsMap[objId];
2488 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2490 GPortModel* startPort = connectModel->getStartPort();
2491 int startPortIndex = startPort->getPosInBox();
2492 GPortModel* endPort = connectModel->getEndPort();
2493 int endPortIndex = endPort->getPosInBox();
2495 GBlackBoxModel* startPortParentBox =
2496 (GBlackBoxModel*) startPort->getParentBox();
2497 GBlackBoxModel* endPortParentBox =
2498 (GBlackBoxModel*) endPort->getParentBox();
2500 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2501 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2503 GBlackBoxModel* newStartBox =
2504 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2505 GBlackBoxModel* newEndBox =
2506 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2508 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2509 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2511 // Creates connection
2512 int idCon = createGConnector(newStartPort);
2513 GConnectorController *tempp =
2514 (GConnectorController*) _controllers[idCon];
2515 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2516 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2517 tempp->endContourCreation();
2518 conMod->setEndPort(newEndPort);
2519 conView->updateStartEndPoints();
2522 std::map<int, int>::iterator itIds;
2523 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2524 int idOld = itIds->first;
2525 int idNew = itIds->second;
2527 GBlackBoxModel* oldBox =
2528 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2529 GBlackBoxModel* newBox =
2530 (GBlackBoxModel*) _controllers[idNew]->getModel();
2532 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2533 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2534 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2535 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2537 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2539 //EED int toCreate=-1;
2540 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2541 if (oldInputConnections[k] == newInputConnections[l]) {
2546 if (exist == false) {
2547 //Create complex input
2548 int posInBox = oldInputConnections[k];
2549 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2550 std::string inputPortName = inputPort->getBBTKName();
2551 int idInputPort = createGComplexBoxInputPort(inputPortName);
2552 GObjectController *cont = _controllers[idInputPort];
2553 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2554 double xIn, yIn, zIn;
2555 inputPort->getInicPoint(xIn, yIn, zIn);
2557 cbmod->setInicPoint(xIn, yIn, zIn);
2558 cbmod->notifyObservers(_idManager);
2560 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2562 // Creates connection
2563 int idCon = createGConnector(cbmod->getOutputPort(0));
2564 GConnectorController *tempp =
2565 (GConnectorController*) _controllers[idCon];
2566 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2567 vtkGConnectorView *conView =
2568 (vtkGConnectorView*) tempp->getView();
2569 tempp->endContourCreation();
2570 conMod->setEndPort(inputPortEnd);
2571 conView->updateStartEndPoints();
2577 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2579 //EED int toCreate=-1;
2580 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2581 if (oldOutputConnections[k] == newOutputConnections[l]) {
2586 if (exist == false) {
2587 //Create complex output
2588 int posInBox = oldOutputConnections[k];
2589 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2590 std::string outputPortName = outputPort->getBBTKName();
2591 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2592 GObjectController *cont = _controllers[idOutputPort];
2593 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2594 double xIn, yIn, zIn;
2595 outputPort->getInicPoint(xIn, yIn, zIn);
2597 cbmod->setInicPoint(xIn, yIn, zIn);
2598 cbmod->notifyObservers(_idManager);
2600 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2602 // Creates connection
2603 int idCon = createGConnector(outputPortEnd);
2604 GConnectorController *tempp =
2605 (GConnectorController*) _controllers[idCon];
2606 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2607 vtkGConnectorView *conView =
2608 (vtkGConnectorView*) tempp->getView();
2609 tempp->endContourCreation();
2610 conMod->setEndPort(cbmod->getInputPort(0));
2611 conView->updateStartEndPoints();
2621 //=========================================================================
2622 void wxVtkSceneManager::SetCbName(std::string cbName) {
2624 if (_cbName == "") {
2625 _cbName = "<complex box name>";
2629 //=========================================================================
2630 std::string wxVtkSceneManager::GetCbName() {
2634 //=========================================================================
2635 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2636 _cbPackageName = packagename;
2637 if (_cbPackageName == "") {
2638 _cbPackageName = "<package name of the complex box>";
2642 //=========================================================================
2643 std::string wxVtkSceneManager::GetCbPackageName() {
2644 return _cbPackageName;
2647 //=========================================================================
2648 void wxVtkSceneManager::SetAuthor(std::string author) {
2650 if (_Author == "") {
2651 _Author = "<author of the box>";
2655 //=========================================================================
2656 std::string wxVtkSceneManager::GetAuthor() {
2660 //=========================================================================
2661 void wxVtkSceneManager::SetCategory(std::string category) {
2662 _Category = category;
2663 if (_Category == "") {
2664 _Category = "<category of the box>";
2668 //=========================================================================
2669 std::string wxVtkSceneManager::GetCategory() {
2673 //=========================================================================
2674 void wxVtkSceneManager::SetDescription(std::string description) {
2675 _Description = description;
2676 if (_Description == "") {
2677 _Description = "<description of the box>";
2681 //=========================================================================
2682 std::string wxVtkSceneManager::GetDescription() {
2683 return _Description;
2686 //=========================================================================
2689 void wxVtkSceneManager::printAll(int com , int sta ){
2691 int tmpState = sta ;
2692 if ( tmpState == NOTHING_HAPPENS ) {
2693 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2695 if ( tmpState == HIGHLIGHTED ) {
2696 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2698 if ( tmpState == POSSIBLE_CONNECTION ) {
2699 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2701 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2702 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2704 if ( tmpState == CLICKED ) {
2705 std::cout << "CONTROLER STATE---->CLICKED\n" ;
2707 if ( tmpState == DRAG ) {
2708 std::cout << "CONTROLER STATE---->DRAG\n" ;
2710 if ( tmpState == SELECTED ) {
2711 std::cout << "CONTROLER STATE---->SELECTED\n" ;
2713 if ( tmpState == CREATING_CONTOUR ) {
2714 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2720 if ( command == INIT_CREATION_CONTOUR ) {
2721 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2723 if ( command == FIN_CREATION_CONTOUR ) {
2724 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2726 if ( command == ADD_TO_SELECTED ) {
2727 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2729 if ( command == DRAG_OBJECTS ) {
2730 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2732 if ( command == EDIT_BLACKBOX ) {
2733 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
2735 if ( command == REMOVE_FROM_SELECTED ) {
2736 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
2742 } // EO namespace bbtk