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)
515 int type = GCONNECTOR;
517 manualConnectorContourController *manContourControl = new manualConnectorContourController();
518 manualConnectorContourView *manContourView = new manualConnectorContourView();
519 manualContourModel *manContourModel = new manualContourModel();
520 GConnectorController *connectorcontroller = new GConnectorController();
521 GConnectorModel *connectorModel = new GConnectorModel();
522 vtkGConnectorView *connectorView = new vtkGConnectorView();
523 connectorModel->setGObjectType(type);
525 manContourModel->SetCloseContour(false);
526 connectorModel->setStartPort(startPort);
528 manContourView->SetModel(manContourModel);
529 manContourView->SetWxVtkBaseView(_baseView);
530 manContourView->SetRange(0.5);
531 manContourView->SetZ(GPOSITION_Z);
533 manContourView->SetColorNormalContour(0, 0, 1);
534 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
535 manContourView->SetColorSelectContour(1, 0.8, 0);
541 * Width increased from 2 to 3, it simplifies line handling and spline control :P
544 manContourView->SetWidthLine( 3 ) ;
545 manContourView->SetShowText(false);
547 manContourControl->SetModelView(manContourModel, manContourView);
549 manContourControl->CreateNewManualContour();
553 connectorModel->getInicPoint(x, y, z);
556 manContourControl->SetState(1);
557 manContourModel->SetCloseContour(false);
559 manContourModel->AddPoint(x, y, z);
560 manContourView->AddPoint();
562 manContourModel->AddPoint(x, y, z);
563 manContourView->AddPoint();
565 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
566 manContourControl->_bakIdPoint = bak;
568 manContourControl->SetMoving(false);
570 connectorcontroller->setModelAndView(connectorModel, connectorView);
572 int newId = addObjectController(connectorcontroller);
574 connectorcontroller->setManualContourController(manContourControl);
575 connectorModel->setManualContourModel(manContourModel);
576 connectorView->setManualContourView(manContourView);
577 connectorView->setModel(connectorModel);
578 connectorView->setBaseView(_baseView);
580 connectorModel->addObserver(connectorView);
581 connectorModel->addObserver(this);
583 // manContourView->Refresh();
588 //=========================================================================
590 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param) {
591 vtkInteractorStyleBaseView
592 * baseViewControlManager =
593 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
594 baseViewControlManager->AddInteractorStyleMaracas(param);
597 //=========================================================================
599 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param) {
600 vtkInteractorStyleBaseView
601 * baseViewControlManager =
602 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
603 baseViewControlManager->RemoveInteractorStyleMaracas(param);
606 //=========================================================================
608 vtkRenderer* wxVtkSceneManager::getRenderer() {
609 return _baseView->GetRenderer();
612 //=========================================================================
614 vtkRenderWindow* wxVtkSceneManager::getRenderWindow() {
615 return _baseView->GetRenWin();
617 //=========================================================================
620 //=========================================================================
621 int wxVtkSceneManager::GetIndexInSelected(int idControler) {
623 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
624 if (_selectedObjects[i] == idControler) {
631 //=========================================================================
633 void wxVtkSceneManager::update(int idController, int command) {
635 if (command != NO_COMMAND) {
636 if (command == ADD_TO_SELECTED) {
637 if (GetIndexInSelected(idController) == -1) {
638 _selectedObjects.push_back(idController);
640 } else if (command == REMOVE_FROM_SELECTED) {
641 int index = GetIndexInSelected(idController);
643 _selectedObjects.erase(_selectedObjects.begin() + index);
645 } else if (command == INIT_CREATION_CONTOUR) {
648 typedef std::map<int , GObjectController*>::iterator TIterator ;
651 // Find current item in the controller
652 iter = _controllers.find( idController ) ;
653 iter_end = _controllers.end( ) ;
655 if ( iter != iter_end ) {
656 GObjectController* gobjc = iter->second ;
658 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
659 // And if the item is a port
660 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
661 TIterator c_it = _controllers.begin( ) ;
662 // Go through all componets
663 for ( c_it ; c_it != iter_end ; c_it++ ) {
664 GObjectController* obc = c_it->second ;
665 int obc_type = obc->getModel( )->getGObjectType( ) ;
666 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
667 // if the component is a port and the type is the same of that selected
668 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
670 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
671 //obc->getView( )->setState( HIGHLIGHTED ) ;
679 _worldState = INIT_CREATION_CONTOUR;
680 GObjectController* cont = _controllers[idController];
681 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
683 // The last one is the controller of the connector
684 std::map<int, GObjectController*>::iterator it2;
687 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
688 GObjectController *cont = it2->second;
689 if (cont->getGObjectType() == GPORT) {
690 GPortModel* port = (GPortModel*) cont->getModel();
691 if (port->getPortType() == GINPUTPORT) {
692 cont->SetActive(true);
694 cont->getView()->setState(NOTHING_HAPPENS);
695 cont->getModel()->notifyObservers(_idManager);
696 cont->SetActive(false);
699 cont->getView()->setState(NOTHING_HAPPENS);
700 cont->getModel()->notifyObservers(_idManager);
701 cont->SetActive(false);
704 _selectedObjects.clear();
705 _idConnectionInCreation = createGConnector(startOutputPort);
706 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
707 _worldState = NOTHING_HAPPENS;
708 //int id = _controllers.size()-1;
709 GObjectController *cont = _controllers[_idConnectionInCreation];
710 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
711 GObjectController *finPort = _controllers[idController];
713 if (finPort->getGObjectType() == GPORT) {
714 GPortModel* modelPort = (GPortModel*) finPort->getModel();
715 modelContour->setEndPort(modelPort);
718 typedef std::map<int, GObjectController*>::iterator TIterator;
719 TIterator c_it = _controllers.begin();
720 TIterator iter_end = _controllers.end();
721 // Go through all componets
722 for (c_it; c_it != iter_end; c_it++) {
723 GObjectController* obc = c_it->second;
724 int obc_type = obc->getModel()->getGObjectType();
725 int obc_state = obc->getView()->getState();
726 // if the component is a port and the type is the same of that selected
727 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
728 // Return element to neutral state if not selected
729 obc->getView()->setState(NOTHING_HAPPENS);
731 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
732 // Change element to connected state
733 obc->getView()->setState(HIGHLIGHTED);
740 _parent->saveTempandUpdate("create connection");
743 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
744 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
746 std::map<int, GObjectController*>::iterator it2;
748 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
749 GObjectController *cont = it2->second;
750 if (cont->getView() != NULL) {
751 cont->getView()->setState(NOTHING_HAPPENS);
752 cont->getModel()->notifyObservers(_idManager);
754 cont->SetActive(true);
763 //=========================================================================
765 bool wxVtkSceneManager::OnMouseMove()
768 bool okStatusMessage = false;
769 bool okPortMessage = false;
770 wxVTKRenderWindowInteractor *wxVTKiren;
771 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
772 wxVTKiren->GetEventPosition(X, Y);
774 if (_worldState == DRAG_OBJECTS) {
775 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
776 int id = _selectedObjects[i];
777 GObjectController* cont = _controllers[id];
778 if (_startDragging) {
779 cont->getView()->setStartDragging(true);
781 cont->getView()->moveObject(X, Y);
782 cont->getView()->setState(DRAG);
783 cont->getModel()->notifyObservers(_idManager);
786 std::map<int, GObjectController*>::iterator it;
788 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
789 GObjectController *desc = it->second;
790 if (desc->getGObjectType() == GCONNECTOR) {
791 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
792 vconn->updateStartEndPoints();
796 _startDragging = false;
798 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
799 std::map<int, GObjectController*>::iterator it;
801 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
802 GObjectController *desc = it->second;
803 int type = desc->getGObjectType();
804 int state = desc->getView()->getState();
805 desc->getModel()->getCenter(px, py, pz);
808 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
811 okStatusMessage = true;
812 updateStatusBar(desc->getStatusText());
813 if (type == GBLACKBOX)
815 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
816 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
821 okPortMessage = true;
823 _textActor->SetInput(desc->getStatusText().c_str());
824 _textActor->SetScale(0.1);
825 _textActor->SetPosition(px - 25, py + 1, pz + 2);
830 _fillObjectActor->SetScale(1);
831 _fillObjectActor->GetProperty()->SetOpacity(0.50);
832 _fillObjectActor->SetPosition(px, py, 1);
833 _aPolygonMapper->Modified();
836 } // for controllers it
839 if (okStatusMessage == false)
844 if (okPortMessage == false)
846 _textActor->SetScale(0.0001);
847 _fillObjectActor->SetScale(0.0001);
852 //=========================================================================
854 bool wxVtkSceneManager::OnLeftButtonDown()
856 if (_worldState == INIT_CREATION_CONTOUR)
858 bool isOverPort = false;
859 std::map<int, GObjectController*>::iterator it;
860 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
862 GObjectController *desc = it->second;
863 if (desc->getGObjectType() == GPORT)
865 GPortModel *portmod = (GPortModel*) desc->getModel();
866 vtkGObjectView *portView = desc->getView();
867 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
872 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
874 portView->setState( HIGHLIGHTED);
881 if (isOverPort == false)
884 UnSelectBlackBoxes();
888 } else { //_worldState
890 _worldState = DRAG_OBJECTS;
891 _startDragging = true;
893 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
894 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
895 ctrlkey = ctrlkey + shiftkey;
897 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
900 int state = cont->getView()->getState();
901 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
902 UnSelectBlackBoxes();
905 UnSelectBlackBoxes(); // EED 12/07/2012
907 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
908 int id = _selectedObjects[i];
909 GObjectController *cont = _controllers[id];
910 cont->getView()->setState(DRAG);
911 cont->getModel()->notifyObservers(_idManager);
913 } // if _selectedObjects.size
919 //=========================================================================
921 bool wxVtkSceneManager::OnLeftButtonUp()
923 if (_worldState == DRAG_OBJECTS) {
924 _worldState = NOTHING_HAPPENS;
926 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
927 int id = _selectedObjects[i];
928 GObjectController* cont = _controllers[id];
929 cont->getView()->setState(SELECTED);
930 cont->getModel()->notifyObservers(_idManager);
936 //=========================================================================
937 void wxVtkSceneManager::CancelConnection()
939 if (_worldState == INIT_CREATION_CONTOUR)
941 _worldState = NOTHING_HAPPENS;
942 //int lastId = _controllers.size()-1;
944 GConnectorController *connector =
945 (GConnectorController*) _controllers[_idConnectionInCreation];
946 connector->removeFromScene();
947 unregisterController(connector);
948 _controllers.erase(_idConnectionInCreation);
950 std::map<int, GObjectController*>::iterator it;
951 for (it = _controllers.begin(); it != _controllers.end(); ++it)
953 GObjectController *desc = it->second;
954 desc->SetActive(true);
955 desc->getView()->setState(NOTHING_HAPPENS);
956 desc->getModel()->notifyObservers(_idManager);
961 //=========================================================================
963 bool wxVtkSceneManager::OnRightButtonUp()
965 if (_worldState == INIT_CREATION_CONTOUR)
969 UnSelectBlackBoxes();
975 bool wxVtkSceneManager::OnMiddleButtonDown() {
978 this->_vtkInteractorStyleBaseView->StartPan();
983 bool wxVtkSceneManager::OnMiddleButtonUp() {
986 this->_vtkInteractorStyleBaseView->EndPan();
993 //=========================================================================
995 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
996 GObjectController *result = NULL;
998 wxVTKRenderWindowInteractor *wxVTKiren;
1000 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1001 wxVTKiren->GetEventPosition(X, Y);
1003 std::map<int, GObjectController*>::iterator it;
1005 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1006 GObjectController *cont = it->second;
1007 int type = cont->getGObjectType();
1009 if (cont->getView()->isPointInside(X, Y) == true) {
1010 if (type == GBLACKBOX) {
1013 } // if isPointInside
1018 //=========================================================================
1019 void wxVtkSceneManager::UnSelectBlackBoxes() {
1020 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1021 int id = _selectedObjects[i];
1022 GObjectController* control = _controllers[id];
1023 control->getView()->setState(NOTHING_HAPPENS);
1024 control->getModel()->notifyObservers(_idManager);
1025 }// for _selectedObjects
1026 _selectedObjects.clear();
1029 //=========================================================================
1030 bool wxVtkSceneManager::OnLeftDClick() {
1031 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1033 UnSelectBlackBoxes();
1034 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1040 wxVTKRenderWindowInteractor *wxVTKiren;
1041 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1042 wxVTKiren->GetEventPosition(X,Y);
1044 std::map<int, GObjectController*>::iterator it;
1046 bool clickOnObject = false;
1048 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1050 GObjectController *cont = it->second;
1051 int type = cont->getGObjectType();
1053 if(cont->getView()->isPointInside(X,Y))
1057 for (int i=0; i< (int)_selectedObjects.size(); i++)
1059 int id = _selectedObjects[i];
1060 GObjectController* control = _controllers[id];
1061 control->getView()->setState(NOTHING_HAPPENS);
1063 _selectedObjects.clear();
1065 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1066 _parent->editBlackBox(bbmodel);
1068 clickOnObject = true;
1072 if(clickOnObject==false)
1074 //_parent->editDiagramParameters(this);
1080 //=========================================================================
1082 bool wxVtkSceneManager::OnChar()
1086 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1087 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1089 // KeyCode 127 : Delete Key
1090 // KeyCode 8 : Backspace Key
1093 if (keyCode == 8 || keyCode == 127 || keyCode == 27)
1095 if (_worldState == INIT_CREATION_CONTOUR)
1098 UnSelectBlackBoxes();
1103 if (keyCode == 8 || keyCode == 127)
1106 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1108 int id = _selectedObjects[i];
1109 std::map<int, GObjectController*>::iterator it;
1110 it = _controllers.find(id);
1111 if (it != _controllers.end())
1113 oktmp = deleteObject(id);
1116 }// for selected objects
1117 if (ok) _selectedObjects.clear();
1118 _parent->saveTempandUpdate("delete object");
1123 if((keyCode==0) && (ctrlkey==1)) {
1128 if(_selectedObjects.size()){
1129 std::cout<<"objects to copy :";
1130 for(int i=0;i<_selectedObjects.size();i++)
1132 std::cout<<_selectedObjects.at(i)<<" ";
1134 DuplicateObjects(getSelectedObjects());
1136 std::cout<<"No objects to copy\n";
1137 } // _selectedObjects.size
1143 //=========================================================================
1145 void wxVtkSceneManager::AddControlerToBeRemove(
1146 std::vector<int> *controllersToRemove, int id) {
1150 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1151 if (id == (*controllersToRemove)[i]) {
1157 controllersToRemove->push_back(id);
1162 //=========================================================================
1164 bool wxVtkSceneManager::deleteObject(int id)
1167 GObjectController *control = _controllers[id];
1168 std::vector<int> controllersToRemove;
1169 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1170 == GCOMPLEXINPUTPORT || control->getGObjectType()
1171 == GCOMPLEXOUTPUTPORT) {
1172 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1173 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1175 bool boxConnected = false;
1177 // Add box input controllers to be removed
1178 for (int i = 0; i < (int) inputs.size(); i++) {
1179 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1180 if (inputs[i]->isConnected()) {
1181 boxConnected = true;
1185 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1187 // Add box output controllers to be removed
1188 for (int i = 0; i < (int) outputs.size(); i++) {
1189 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1190 if (outputs[i]->isConnected()) {
1191 boxConnected = true;
1195 // Add connection controllers to be removed
1196 std::map<int, GObjectController*>::iterator it;
1197 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1198 GObjectController *cont = it->second;
1199 int type = cont->getGObjectType();
1200 if (type == GCONNECTOR) {
1201 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1202 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1204 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1206 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1208 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1213 // Add box controller to be removed
1214 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1215 } else if (control->getGObjectType() == GCONNECTOR) {
1216 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1217 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1219 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1220 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1222 gconnectorcontroler->getManualContourController()->OnChar();
1227 std::map<int, GObjectController*>::iterator it;
1229 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1230 int key = controllersToRemove[i];
1231 it = _controllers.find(key);
1232 GObjectController *cont = _controllers[key];
1234 cont->removeFromScene();
1235 unregisterController((InteractorStyleMaracas*) cont);
1236 _controllers.erase(it);
1244 //=========================================================================
1246 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1247 std::string boxName) {
1248 _parent->displayBlackBoxInfo(packageName, boxName);
1251 //=========================================================================
1253 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1254 _parent->updateStatusBar(textStatus);
1257 //=========================================================================
1258 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1259 std::string result = "";
1260 if (withLineNumber == true) {
1262 stringstream StrStream;
1264 std::string strValue = StrStream.str();
1267 } else if (value < 100) {
1271 result += strValue + ": ";
1275 //=========================================================================
1277 bool wxVtkSceneManager::MakeBoxExecutable() {
1278 std::map<int, GObjectController*> selected = getSelectedObjects();
1279 if( selected.empty() )
1282 std::map<int, GObjectController*>::iterator it;
1283 for (it = selected.begin(); it != selected.end(); ++it) {
1284 GObjectController* lastSelected = it->second;
1286 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1287 GBlackBoxModel *bbmodel =
1288 (GBlackBoxModel*) lastSelected->getModel();
1289 view->setState(HIGHLIGHTED);
1290 if (bbmodel->isExecutable()) {
1291 bbmodel->setExecutable(false);
1293 bbmodel->setExecutable(true);
1295 bbmodel->notifyObservers(lastSelected->getId());
1303 //=========================================================================
1305 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1306 bool existsExec = false;
1308 std::vector<std::string> packages;
1309 std::vector<int> boxes;
1310 std::vector<int> connections;
1311 std::vector<int> execBoxes;
1313 std::map<int, GObjectController*>::iterator it;
1315 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1316 GObjectController *desc = it->second;
1317 int type = desc->getGObjectType();
1319 if (type == GBLACKBOX) {
1320 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1322 std::string pkg = mod->getBBTKPackage();
1323 bool existsPkg = false;
1324 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1325 if (packages[t] == pkg) {
1330 packages.push_back(pkg);
1333 boxes.push_back(it->first);
1334 if (mod->isExecutable()) {
1335 execBoxes.push_back(it->first);
1338 } else if (type == GCONNECTOR) {
1339 connections.push_back(it->first);
1344 std::string script = "";
1345 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1346 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1347 script += LineNumber(wln, lnNmbr) + "\n";
1349 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1350 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1352 for (i = 0; i < (int) packages.size(); i++) {
1353 script += LineNumber(wln, lnNmbr);
1354 script += "include ";
1355 script += packages[i];
1359 script += LineNumber(wln, lnNmbr);
1364 script += LineNumber(wln, lnNmbr);
1365 script += "author \"";
1369 script += LineNumber(wln, lnNmbr);
1370 script += "description \"";
1371 script += _Description;
1374 script += LineNumber(wln, lnNmbr);
1375 script += "category \"";
1376 script += _Category;
1379 script += LineNumber(wln, lnNmbr);
1382 // script+="include std\n"; // JPR
1384 for (i = 0; i < (int) boxes.size(); i++) {
1385 script += LineNumber(wln, lnNmbr);
1388 GObjectController *control = _controllers[id];
1389 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1391 script += model->getBBTKType();
1393 script += model->getBBTKName();
1396 std::vector<GPortModel*> inputs = model->getInputPorts();
1397 for (int j = 0; j < (int) inputs.size(); j++) {
1398 GPortModel* inputPort = inputs[j];
1399 if (inputPort->isValueSet()) {
1400 script += LineNumber(wln, lnNmbr);
1402 script += model->getBBTKName();
1404 script += inputPort->getBBTKName();
1406 script += inputPort->getValue();
1411 script += LineNumber(wln, lnNmbr);
1416 script += LineNumber(wln, lnNmbr);
1419 for (i = 0; i < (int) connections.size(); i++) {
1420 script += LineNumber(wln, lnNmbr);
1421 script += "connect ";
1422 int id = connections[i];
1423 GObjectController *control = _controllers[id];
1424 GConnectorModel *model = (GConnectorModel*) control->getModel();
1426 //Start Connection info
1427 GPortModel *start = model->getStartPort();
1428 script += start->getParentBox()->getBBTKName();
1430 script += start->getBBTKName();
1434 //End Connection info
1435 GPortModel *end = model->getEndPort();
1436 script += end->getParentBox()->getBBTKName();
1438 script += end->getBBTKName();
1443 script += LineNumber(wln, lnNmbr);
1445 for (i = 0; i < (int) execBoxes.size(); i++) {
1446 script += LineNumber(wln, lnNmbr);
1448 int id = execBoxes[i];
1449 GObjectController *control = _controllers[id];
1450 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1452 script += model->getBBTKName();
1461 //=========================================================================
1463 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1464 std::vector<std::string> packages;
1465 std::vector<int> boxes;
1466 std::vector<int> connections;
1467 std::vector<int> execBoxes;
1469 std::map<int, GObjectController*>::iterator it;
1471 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1472 GObjectController *desc = it->second;
1473 int type = desc->getGObjectType();
1475 if (type == GBLACKBOX) {
1476 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1478 std::string pkg = mod->getBBTKPackage();
1479 bool existsPkg = false;
1480 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1481 if (packages[t] == pkg) {
1486 packages.push_back(pkg);
1489 boxes.push_back(it->first);
1490 if (mod->isExecutable()) {
1491 execBoxes.push_back(it->first);
1493 } else if (type == GCONNECTOR) {
1494 connections.push_back(it->first);
1498 std::string script = "";
1500 script += "include std\n"; // EED
1501 script += "include itkvtk\n"; // EED
1503 for (i = 0; i < (int) packages.size(); i++) {
1504 script += "include ";
1505 script += packages[i];
1510 // Definition of a complex box
1511 script += "define ";
1512 script += _cbName + " " + _cbPackageName;
1516 script += "author \"";
1520 script += "description \"";
1521 script += _Description;
1525 script += "category \"";
1526 script += _Category;
1531 for (i = 0; i < (int) boxes.size(); i++) {
1534 GObjectController *control = _controllers[id];
1535 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1537 script += model->getBBTKType();
1539 script += model->getBBTKName();
1542 std::vector<GPortModel*> inputs = model->getInputPorts();
1543 for (int j = 0; j < (int) inputs.size(); j++) {
1544 GPortModel* inputPort = inputs[j];
1545 if (inputPort->isValueSet()) {
1547 script += model->getBBTKName();
1549 script += inputPort->getBBTKName();
1551 script += inputPort->getValue();
1559 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1561 std::string complexInputs = "";
1562 std::string complexOutputs = "";
1565 for (i = 0; i < (int) connections.size(); i++) {
1566 int id = connections[i];
1567 GObjectController *control = _controllers[id];
1568 GConnectorModel *model = (GConnectorModel*) control->getModel();
1571 GPortModel *start = model->getStartPort();
1572 GBoxModel *startBox = start->getParentBox();
1574 GPortModel *end = model->getEndPort();
1575 GBoxModel *endBox = end->getParentBox();
1577 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1578 complexInputs += "input ";
1579 complexInputs += startBox->getBBTKName();
1581 complexInputs += " ";
1582 complexInputs += endBox->getBBTKName();
1583 complexInputs += ".";
1584 complexInputs += end->getBBTKName();
1586 complexInputs += " ";
1587 complexInputs += "\" \"";
1589 complexInputs += "\n";
1590 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1591 complexOutputs += "output ";
1592 complexOutputs += endBox->getBBTKName();
1594 complexOutputs += " ";
1595 complexOutputs += startBox->getBBTKName();
1596 complexOutputs += ".";
1597 complexOutputs += start->getBBTKName();
1599 complexOutputs += " ";
1600 complexOutputs += "\" \"";
1602 complexOutputs += "\n";
1604 script += "connect ";
1605 script += startBox->getBBTKName();
1607 script += start->getBBTKName();
1611 //End Connection info
1612 script += endBox->getBBTKName();
1614 script += end->getBBTKName();
1622 for (i = 0; i < (int) execBoxes.size(); i++) {
1624 int id = execBoxes[i];
1625 GObjectController *control = _controllers[id];
1626 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1628 script += model->getBBTKName();
1633 script += "# Complex input ports\n";
1634 script += complexInputs;
1637 script += "# Complex output ports\n";
1638 script += complexOutputs;
1641 script += "endefine";
1647 //=========================================================================
1649 void wxVtkSceneManager::deleteAllBoxes() {
1650 std::map<int, GObjectController*>::iterator it;
1651 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1652 GObjectController *cont = it->second;
1653 cont->removeFromScene();
1654 unregisterController((InteractorStyleMaracas*) cont);
1656 _selectedObjects.clear();
1657 _controllers.clear();
1660 //=========================================================================
1663 void wxVtkSceneManager::refresh() {
1664 _baseView->Refresh();
1666 //=========================================================================
1668 void wxVtkSceneManager::refreshScene() {
1669 _baseView->RefreshView();
1672 //=========================================================================
1674 void wxVtkSceneManager::centerView() {
1676 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1677 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1678 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1679 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1682 //=========================================================================
1684 void wxVtkSceneManager::saveDiagram(std::string &content) {
1687 content += "CATEGORY:";
1688 content += GetCategory();
1691 content += "DESCRIPTION:";
1692 content += GetDescription();
1695 content += "AUTHOR:";
1696 content += GetAuthor();
1699 //Print info IF COMPLEX BOX
1700 content += "COMPLEXBOX:";
1701 if (_isComplexBox) {
1702 content += "TRUE\n";
1704 content += "COMPLEXBOXNAME:";
1705 content += GetCbName();
1708 content += "PACKAGENAME:";
1709 content += GetCbPackageName();
1712 //Print info complex input ports
1713 std::vector<int> inputs = getComplexInputPorts();
1714 int insize = inputs.size();
1715 content += "COMPLEXINPUTS:";
1716 sprintf(buffer, "%d", insize);
1720 for (int i = 0; i < insize; i++) {
1722 GObjectController *cont = _controllers[id];
1723 cont->getModel()->save(content);
1726 //Print info complex output ports
1727 std::vector<int> outputs = getComplexOutputPorts();
1728 int outsize = outputs.size();
1729 content += "COMPLEXOUTPUTS:";
1730 sprintf(buffer, "%d", outsize);
1734 for (int i = 0; i < outsize; i++) {
1735 int id = outputs[i];
1736 GObjectController *cont = _controllers[id];
1737 cont->getModel()->save(content);
1741 content += "FALSE\n";
1745 std::vector<int> boxes = getBlackBoxes();
1746 int bsize = boxes.size();
1747 content += "BOXES:";
1748 sprintf(buffer, "%d", bsize);
1752 for (int i = 0; i < bsize; i++) {
1754 GObjectController *cont = _controllers[id];
1755 cont->getModel()->save(content);
1759 std::vector<int> connections = getConnections();
1760 int csize = connections.size();
1761 content += "CONNECTIONS:";
1762 sprintf(buffer, "%d", csize);
1766 for (int i = 0; i < csize; i++) {
1767 int id = connections[i];
1768 GObjectController *cont = _controllers[id];
1769 cont->getModel()->save(content);
1774 //=========================================================================
1775 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1777 getline(inputStream, line,'\n');
1778 int size = line.length();
1781 if ( line[ size-1 ]==13 )
1783 line.erase(size-1,1);
1788 //=========================================================================
1789 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1792 std::string version = "<void>";
1793 std::string line = "";
1794 char delims[] = ":";
1795 char *result = NULL;
1797 getCleanLine(inputStream, line);
1800 while (!inputStream.eof()) {
1801 if (line == "" || line[0] == '#') {
1803 getCleanLine(inputStream, line);
1805 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1806 version = line.substr(18, 3);
1808 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1809 version = line.substr(18, 3);
1811 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1812 version = line.substr(18, 3);
1814 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1815 version = line.substr(18, 3);
1817 } else if (line == "APP_START") {
1826 if ((version != "1.0") && (version != "1.1")) {
1827 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1828 char categoryTmp[30];
1829 strcpy(categoryTmp, line.c_str());
1830 result = strtok(categoryTmp, delims);
1831 result = strtok(NULL, delims);
1832 SetCategory(result);
1834 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1835 char descriptionTmp[1024];
1836 strcpy(descriptionTmp, line.c_str());
1837 result = strtok(descriptionTmp, delims);
1838 result = strtok(NULL, delims);
1839 SetDescription(result);
1841 getCleanLine(inputStream, line);//AUTHOR:<author>
1842 char authorTmp[255];
1843 strcpy(authorTmp, line.c_str());
1844 result = strtok(authorTmp, delims);
1845 result = strtok(NULL, delims);
1850 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1851 char complexTmp[30];
1852 strcpy(complexTmp, line.c_str());
1853 result = strtok(complexTmp, delims);
1854 result = strtok(NULL, delims);
1855 std::string isComplexBox(result);
1857 if (isComplexBox == "TRUE") {
1858 _isComplexBox = true;
1860 if ((version != "1.0") && (version != "1.1")) {
1861 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
1862 char complexboxnameTmp[255];
1863 strcpy(complexboxnameTmp, line.c_str());
1864 result = strtok(complexboxnameTmp, delims);
1865 result = strtok(NULL, delims);
1868 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
1869 char packagenameTmp[255];
1870 strcpy(packagenameTmp, line.c_str());
1871 result = strtok(packagenameTmp, delims);
1872 result = strtok(NULL, delims);
1873 SetCbPackageName(result);
1876 //-----------------------
1877 //- COMPLEX INPUT PORTS
1878 //-----------------------
1879 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
1881 strcpy(inputs, line.c_str());
1882 result = strtok(inputs, delims);
1883 result = strtok(NULL, delims);
1886 std::istringstream inps(result);
1889 for (int i = 0; i < numInputs; i++) {
1891 getCleanLine(inputStream, line);//COMPLEX_PORT
1892 getCleanLine(inputStream, line);//name
1893 std::string inputPortName(line);
1896 getCleanLine(inputStream, line);//xInic:yInic:zInic
1898 strcpy(coord, line.c_str());
1899 result = strtok(coord, delims);//xInic
1900 std::string xInic(result);
1901 result = strtok(NULL, delims);//yInic
1902 std::string yInic(result);
1903 result = strtok(NULL, delims);//zInic
1904 std::string zInic(result);
1906 double xIn, yIn, zIn;
1907 std::istringstream xSt(xInic);
1909 std::istringstream ySt(yInic);
1911 std::istringstream zSt(zInic);
1916 if (zIn==900) zIn=GPOSITION_Z;
1919 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
1921 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
1923 } // for input complex box
1926 //-----------------------
1927 //- COMPLEX OUTPUT PORTS
1928 //-----------------------
1930 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
1932 strcpy(outputs, line.c_str());
1933 result = strtok(outputs, delims);
1934 result = strtok(NULL, delims);
1937 std::istringstream outps(result);
1938 outps >> numOutputs;
1940 for (int i = 0; i < numOutputs; i++) {
1942 getCleanLine(inputStream, line);//COMPLEX_PORT
1943 getCleanLine(inputStream, line);//name
1944 std::string outputPortName(line);
1947 getCleanLine(inputStream, line);//xInic:yInic:zInic
1949 strcpy(coord, line.c_str());
1950 result = strtok(coord, delims);//xInic
1951 std::string xInic(result);
1952 result = strtok(NULL, delims);//yInic
1953 std::string yInic(result);
1954 result = strtok(NULL, delims);//zInic
1955 std::string zInic(result);
1957 double xIn, yIn, zIn;
1958 std::istringstream xSt(xInic);
1960 std::istringstream ySt(yInic);
1962 std::istringstream zSt(zInic);
1967 if (zIn==900) zIn=GPOSITION_Z;
1970 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
1972 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
1974 } // for output complex box
1979 getCleanLine(inputStream, line);//BOXES:num
1981 strcpy(boxes, line.c_str());
1982 result = strtok(boxes, delims);
1983 result = strtok(NULL, delims);
1986 std::istringstream is(result);
1989 for (int i = 0; i < numBoxes; i++) {
1991 getCleanLine(inputStream, line);//BOX
1992 getCleanLine(inputStream, line);//package:type:name
1994 strcpy(box, line.c_str());
1995 result = strtok(box, delims);//package
1996 std::string package(result);
1997 result = strtok(NULL, delims);//type
1998 std::string type(result);
1999 result = strtok(NULL, delims);//name
2000 std::string name(result);
2002 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2004 strcpy(exec, line.c_str());
2005 result = strtok(exec, delims);//ISEXEC
2006 result = strtok(NULL, delims);//TRUE|FALSE
2007 std::string isExec(result);
2010 getCleanLine(inputStream, line);//xInic:yInic:zInic
2012 strcpy(coord, line.c_str());
2013 result = strtok(coord, delims);//xInic
2014 std::string xInic(result);
2015 result = strtok(NULL, delims);//yInic
2016 std::string yInic(result);
2017 result = strtok(NULL, delims);//zInic
2018 std::string zInic(result);
2020 double xIn, yIn, zIn;
2021 std::istringstream xSt(xInic);
2023 std::istringstream ySt(yInic);
2025 std::istringstream zSt(zInic);
2031 if (zIn==900) zIn=GPOSITION_Z;
2036 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2037 strcpy(coord, line.c_str());
2038 result = strtok(coord, delims);//xEnd
2039 std::string xEnd(result);
2040 result = strtok(NULL, delims);//yEnd
2041 std::string yEnd(result);
2042 result = strtok(NULL, delims);//zEnd
2043 std::string zEnd(result);
2045 double xEn, yEn, zEn;
2046 std::istringstream xEt(xEnd);
2048 std::istringstream yEt(yEnd);
2050 std::istringstream zEt(zEnd);
2055 if (zEn==900) zEn=GPOSITION_Z;
2059 bool boxExecutable = false;
2060 if (isExec == "TRUE") {
2061 boxExecutable = true;
2064 int idBox = createGBlackBox(xIn, yIn, package, type);
2065 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2067 GObjectController *cont = _controllers[idBox];
2068 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2071 getCleanLine(inputStream, line);//PORT o FIN_BOX
2072 std::string port = line.substr(0, 4);
2073 while (port == "PORT") {
2074 getCleanLine(inputStream, line);//name:value
2076 strcpy(poort, line.c_str());
2077 result = strtok(poort, delims);//name
2078 std::string name(result);
2079 result = strtok(NULL, delims);//value
2080 std::string value(result);
2082 bbmod->setValueToInput(name, value);
2084 getCleanLine(inputStream, line);//PORT o FIN_BOX
2085 port = line.substr(0, 4);
2088 //EED bbmod->notifyObservers(_idManager);
2093 getCleanLine(inputStream, line);//CONNECTIONS:num
2095 strcpy(conns, line.c_str());
2096 result = strtok(conns, delims);
2097 result = strtok(NULL, delims);
2100 std::istringstream isCons(result);
2104 for (int i = 0; i < numConns; i++) {
2106 getCleanLine(inputStream, line);//CONNECTION
2107 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2110 strcpy(connec, line.c_str());
2111 result = strtok(connec, delims);
2112 std::string nameStartBox(result);
2113 result = strtok(NULL, delims);
2114 std::string nameStartPort(result);
2115 result = strtok(NULL, delims);
2116 std::string nameEndBox(result);
2117 result = strtok(NULL, delims);
2118 std::string nameEndPort(result);
2120 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2122 if (version != "1.0") {
2123 //Readding control points of the manualContour
2124 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2125 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2126 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2127 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2128 strcpy(conns, line.c_str());
2129 result = strtok(conns, delims);
2130 result = strtok(NULL, delims);
2132 int numberOfControlPoints;
2133 std::istringstream isCons(result);
2134 isCons >> numberOfControlPoints;
2136 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2137 getCleanLine(inputStream, line); //XX:YY:ZZ
2139 strcpy(connec, line.c_str());
2142 result = strtok(connec, delims);
2143 std::istringstream isPointX(result);
2145 result = strtok(NULL, delims);
2146 std::istringstream isPointY(result);
2148 result = strtok(NULL, delims);
2149 std::istringstream isPointZ(result);
2154 if (pz==900) pz=GPOSITION_Z;
2157 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2158 conView->getManualContourView()->AddPoint();
2167 //=========================================================================
2170 //=========================================================================
2171 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2172 std::string portName, double xIn, double yIn, double zIn) {
2174 if (inputoutput == true) {
2175 idPort = createGComplexBoxInputPort(portName);
2177 idPort = createGComplexBoxOutputPort(portName);
2179 GObjectController *cont = _controllers[idPort];
2180 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2181 cbmod->setInicPoint(xIn, yIn, zIn);
2182 cbmod->notifyObservers(_idManager);
2184 //=========================================================================
2187 //=========================================================================
2188 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
2192 GBoxModel *boxModel = NULL;
2193 std::vector<int> lstB = getBlackBoxes();
2194 for (j = 0; j < (int) lstB.size(); j++) {
2196 bMod = (GBoxModel*) _controllers[idB]->getModel();
2197 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2202 if ((_isComplexBox) && (boxModel == NULL)) {
2203 std::vector<int> lstInputs = getComplexInputPorts();
2204 for (j = 0; j < (int) lstInputs.size(); j++) {
2206 bMod = (GBoxModel*) _controllers[idB]->getModel();
2207 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2212 std::vector<int> lstOutputs = getComplexOutputPorts();
2213 for (j = 0; j < (int) lstOutputs.size(); j++) {
2214 int idB = lstOutputs[j];
2215 bMod = (GBoxModel*) _controllers[idB]->getModel();
2216 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2226 //=========================================================================
2229 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2230 std::string nameStartPort, std::string nameEndBox,
2231 std::string nameEndPort) {
2233 GBoxModel *boxModel;
2234 GPortModel *startP = NULL;
2235 GPortModel *endP = NULL;
2237 boxModel = findGBox(nameStartBox);
2238 if (boxModel != NULL) {
2239 startP = boxModel->getOutputPort(nameStartPort);
2241 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port %s is null. Port name is probably wrong.\n", nameStartPort.c_str());
2245 boxModel = findGBox(nameEndBox);
2246 if (boxModel != NULL) {
2247 endP = boxModel->getInputPort(nameEndPort);
2249 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port %s is null. Port name is probably wrong\n", nameStartPort.c_str(), nameEndPort.c_str());
2254 int idCon = createGConnector(startP);
2255 _worldState = NOTHING_HAPPENS;
2256 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2258 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2259 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2260 tempp->endContourCreation();
2261 conMod->setEndPort(endP);
2262 conView->updateStartEndPoints();
2266 //=========================================================================
2268 bool wxVtkSceneManager::boxExist(std::string boxname) {
2270 std::map<int, GObjectController*>::iterator it;
2271 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2272 GObjectController *cont = it->second;
2273 if (cont->getModel()->getBBTKName() == boxname) {
2280 //=========================================================================
2282 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2283 std::vector<int> vect;
2284 std::map<int, GObjectController*>::iterator it;
2285 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2286 GObjectController *cont = it->second;
2287 if (cont->getGObjectType() == GBLACKBOX) {
2288 vect.push_back(cont->getId());
2294 //=========================================================================
2296 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2297 std::vector<int> vect;
2298 std::map<int, GObjectController*>::iterator it;
2299 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2300 GObjectController *cont = it->second;
2301 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2302 vect.push_back(cont->getId());
2308 //=========================================================================
2310 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2311 std::vector<int> vect;
2312 std::map<int, GObjectController*>::iterator it;
2313 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2314 GObjectController *cont = it->second;
2315 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2316 vect.push_back(cont->getId());
2322 //=========================================================================
2324 std::vector<int> wxVtkSceneManager::getConnections() {
2325 std::vector<int> vect;
2326 std::map<int, GObjectController*>::iterator it;
2327 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2328 GObjectController *cont = it->second;
2329 if (cont->getGObjectType() == GCONNECTOR) {
2330 vect.push_back(cont->getId());
2336 //=========================================================================
2338 bool wxVtkSceneManager::isComplexBox() {
2339 return _isComplexBox;
2342 //=========================================================================
2344 void wxVtkSceneManager::setComplexBox(bool val) {
2345 _isComplexBox = val;
2348 //=========================================================================
2350 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2351 //Register the controller of the new object
2352 registerController((InteractorStyleMaracas*) objController);
2353 //Add the object to the objects list
2354 int newId = _contLastId;//_controllers.size();
2355 objController->setId(newId);
2356 _controllers[newId] = objController;
2357 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2362 //=========================================================================
2364 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2366 std::map<int, int> oldIdNewIdBoxes;
2367 std::vector<int> connections;
2369 std::vector<int> newBoxesID;
2371 std::map<int, GObjectController*>::iterator it;
2372 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2373 GObjectController *cont = it->second;
2374 int type = cont->getGObjectType();
2376 if (type == GBLACKBOX) {
2378 double xInic, yInic, zInic;
2379 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2380 copyBox->getInicPoint(xInic, yInic, zInic);
2381 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2382 copyBox->getBBTKType());
2384 int idcB = copyBox->getObjectId();
2385 oldIdNewIdBoxes[idcB] = idBox;
2386 cont = _controllers[idBox];
2387 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2388 newbox->setInicPoint(xInic, yInic, zInic);
2389 int num = newbox->getNumInputPorts();
2390 for (int j = 0; j < num; j++) {
2391 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2393 newbox->move(xInic + 20, yInic + 20, zInic);
2394 newbox->notifyObservers(_idManager);
2395 newBoxesID.push_back(newbox->getObjectId());
2397 } else if (type == GCONNECTOR) {
2398 int idCon = cont->getId();
2399 connections.push_back(idCon);
2404 for (int i = 0; i < (int) connections.size(); i++) {
2405 int objId = connections[i];
2406 GObjectController *cont = objectsMap[objId];
2407 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2409 GPortModel* startPort = connectModel->getStartPort();
2410 int startPortIndex = startPort->getPosInBox();
2411 GPortModel* endPort = connectModel->getEndPort();
2412 int endPortIndex = endPort->getPosInBox();
2414 GBlackBoxModel* startPortParentBox =
2415 (GBlackBoxModel*) startPort->getParentBox();
2416 GBlackBoxModel* endPortParentBox =
2417 (GBlackBoxModel*) endPort->getParentBox();
2419 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2420 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2422 GBlackBoxModel* newStartBox =
2423 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2424 GBlackBoxModel* newEndBox =
2425 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2427 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2428 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2430 // Creates connection
2431 int idCon = createGConnector(newStartPort);
2432 GConnectorController *tempp =
2433 (GConnectorController*) _controllers[idCon];
2434 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2435 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2436 tempp->endContourCreation();
2437 conMod->setEndPort(newEndPort);
2438 conView->updateStartEndPoints();
2441 /// the new selected boxes are the duplicate ones
2443 UnSelectBlackBoxes();
2444 for (int i = 0; i < newBoxesID.size(); i++) {
2445 _selectedObjects.push_back(newBoxesID.at(i));
2448 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2449 int id = _selectedObjects[i];
2450 GObjectController* cont = _controllers[id];
2452 cont->getView()->setState(SELECTED);
2453 cont->getModel()->notifyObservers(_idManager);
2459 //=========================================================================
2461 int wxVtkSceneManager::getNumSelectedObjects() {
2462 return _selectedObjects.size();
2465 //=========================================================================
2467 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2468 std::map<int, GObjectController*> mapSelected;
2470 std::map<int, GObjectController*>::iterator it;
2471 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2472 GObjectController *cont = it->second;
2473 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2475 mapSelected[cont->getId()] = cont;
2479 std::map<int, GObjectController*>::iterator it2;
2480 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2481 GObjectController *cont = it2->second;
2482 if (cont->getGObjectType() == GCONNECTOR) {
2483 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2484 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2485 GBoxModel* startPortParentBox =
2486 cmod->getStartPort()->getParentBox();
2488 std::map<int, GObjectController*>::iterator iterOBJ1 =
2489 mapSelected.find(startPortParentBox->getObjectId());
2490 std::map<int, GObjectController*>::iterator iterOBJ2 =
2491 mapSelected.find(endPortParentBox->getObjectId());
2493 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2494 int ID = cont->getId();
2495 mapSelected[ID] = cont;
2502 //=========================================================================
2504 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2506 std::map<int, int> oldIdNewIdBoxes;
2507 std::vector<int> connections;
2509 std::map<int, GObjectController*>::iterator it;
2510 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2511 GObjectController *cont = it->second;
2512 int type = cont->getGObjectType();
2514 if (type == GBLACKBOX) {
2516 double xInic, yInic, zInic;
2517 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2518 copyBox->getInicPoint(xInic, yInic, zInic);
2519 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2520 copyBox->getBBTKType());
2522 int idcB = copyBox->getObjectId();
2523 oldIdNewIdBoxes[idcB] = idBox;
2524 cont = _controllers[idBox];
2525 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2526 newbox->setInicPoint(xInic, yInic, zInic);
2527 int num = newbox->getNumInputPorts();
2528 for (int j = 0; j < num; j++) {
2529 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2531 newbox->notifyObservers(_idManager);
2532 } else if (type == GCONNECTOR) {
2533 int idCon = cont->getId();
2534 connections.push_back(idCon);
2539 for (int i = 0; i < (int) connections.size(); i++) {
2540 int objId = connections[i];
2541 GObjectController *cont = objectsMap[objId];
2542 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2544 GPortModel* startPort = connectModel->getStartPort();
2545 int startPortIndex = startPort->getPosInBox();
2546 GPortModel* endPort = connectModel->getEndPort();
2547 int endPortIndex = endPort->getPosInBox();
2549 GBlackBoxModel* startPortParentBox =
2550 (GBlackBoxModel*) startPort->getParentBox();
2551 GBlackBoxModel* endPortParentBox =
2552 (GBlackBoxModel*) endPort->getParentBox();
2554 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2555 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2557 GBlackBoxModel* newStartBox =
2558 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2559 GBlackBoxModel* newEndBox =
2560 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2562 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2563 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2565 // Creates connection
2566 int idCon = createGConnector(newStartPort);
2567 GConnectorController *tempp =
2568 (GConnectorController*) _controllers[idCon];
2569 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2570 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2571 tempp->endContourCreation();
2572 conMod->setEndPort(newEndPort);
2573 conView->updateStartEndPoints();
2576 std::map<int, int>::iterator itIds;
2577 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2578 int idOld = itIds->first;
2579 int idNew = itIds->second;
2581 GBlackBoxModel* oldBox =
2582 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2583 GBlackBoxModel* newBox =
2584 (GBlackBoxModel*) _controllers[idNew]->getModel();
2586 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2587 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2588 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2589 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2591 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2593 //EED int toCreate=-1;
2594 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2595 if (oldInputConnections[k] == newInputConnections[l]) {
2600 if (exist == false) {
2601 //Create complex input
2602 int posInBox = oldInputConnections[k];
2603 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2604 std::string inputPortName = inputPort->getBBTKName();
2605 int idInputPort = createGComplexBoxInputPort(inputPortName);
2606 GObjectController *cont = _controllers[idInputPort];
2607 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2608 double xIn, yIn, zIn;
2609 inputPort->getInicPoint(xIn, yIn, zIn);
2611 cbmod->setInicPoint(xIn, yIn, zIn);
2612 cbmod->notifyObservers(_idManager);
2614 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2616 // Creates connection
2617 int idCon = createGConnector(cbmod->getOutputPort(0));
2618 GConnectorController *tempp =
2619 (GConnectorController*) _controllers[idCon];
2620 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2621 vtkGConnectorView *conView =
2622 (vtkGConnectorView*) tempp->getView();
2623 tempp->endContourCreation();
2624 conMod->setEndPort(inputPortEnd);
2625 conView->updateStartEndPoints();
2631 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2633 //EED int toCreate=-1;
2634 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2635 if (oldOutputConnections[k] == newOutputConnections[l]) {
2640 if (exist == false) {
2641 //Create complex output
2642 int posInBox = oldOutputConnections[k];
2643 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2644 std::string outputPortName = outputPort->getBBTKName();
2645 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2646 GObjectController *cont = _controllers[idOutputPort];
2647 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2648 double xIn, yIn, zIn;
2649 outputPort->getInicPoint(xIn, yIn, zIn);
2651 cbmod->setInicPoint(xIn, yIn, zIn);
2652 cbmod->notifyObservers(_idManager);
2654 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2656 // Creates connection
2657 int idCon = createGConnector(outputPortEnd);
2658 GConnectorController *tempp =
2659 (GConnectorController*) _controllers[idCon];
2660 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2661 vtkGConnectorView *conView =
2662 (vtkGConnectorView*) tempp->getView();
2663 tempp->endContourCreation();
2664 conMod->setEndPort(cbmod->getInputPort(0));
2665 conView->updateStartEndPoints();
2675 //=========================================================================
2676 void wxVtkSceneManager::SetCbName(std::string cbName) {
2678 if (_cbName == "") {
2679 _cbName = "<complex box name>";
2683 //=========================================================================
2684 std::string wxVtkSceneManager::GetCbName() {
2688 //=========================================================================
2689 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2690 _cbPackageName = packagename;
2691 if (_cbPackageName == "") {
2692 _cbPackageName = "<package name of the complex box>";
2696 //=========================================================================
2697 std::string wxVtkSceneManager::GetCbPackageName() {
2698 return _cbPackageName;
2701 //=========================================================================
2702 void wxVtkSceneManager::SetAuthor(std::string author) {
2704 if (_Author == "") {
2705 _Author = "<author of the box>";
2709 //=========================================================================
2710 std::string wxVtkSceneManager::GetAuthor() {
2714 //=========================================================================
2715 void wxVtkSceneManager::SetCategory(std::string category) {
2716 _Category = category;
2717 if (_Category == "") {
2718 _Category = "<category of the box>";
2722 //=========================================================================
2723 std::string wxVtkSceneManager::GetCategory() {
2727 //=========================================================================
2728 void wxVtkSceneManager::SetDescription(std::string description) {
2729 _Description = description;
2730 std::cout<<"Description:"<<_Description<<std::endl;
2731 if (_Description == "") {
2732 _Description = "<description of the box>";
2736 //=========================================================================
2737 std::string wxVtkSceneManager::GetDescription() {
2738 return _Description;
2741 //=========================================================================
2744 void wxVtkSceneManager::printAll(int com , int sta ){
2746 int tmpState = sta ;
2747 if ( tmpState == NOTHING_HAPPENS ) {
2748 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2750 if ( tmpState == HIGHLIGHTED ) {
2751 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2753 if ( tmpState == POSSIBLE_CONNECTION ) {
2754 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2756 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2757 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2759 if ( tmpState == CLICKED ) {
2760 std::cout << "CONTROLER STATE---->CLICKED\n" ;
2762 if ( tmpState == DRAG ) {
2763 std::cout << "CONTROLER STATE---->DRAG\n" ;
2765 if ( tmpState == SELECTED ) {
2766 std::cout << "CONTROLER STATE---->SELECTED\n" ;
2768 if ( tmpState == CREATING_CONTOUR ) {
2769 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2775 if ( command == INIT_CREATION_CONTOUR ) {
2776 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2778 if ( command == FIN_CREATION_CONTOUR ) {
2779 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2781 if ( command == ADD_TO_SELECTED ) {
2782 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2784 if ( command == DRAG_OBJECTS ) {
2785 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2787 if ( command == EDIT_BLACKBOX ) {
2788 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
2790 if ( command == REMOVE_FROM_SELECTED ) {
2791 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
2797 } // EO namespace bbtk