2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
8 # This software is governed by the CeCILL-B license under French law and
9 # abiding by the rules of distribution of free software. You can use,
10 # modify and/ or redistribute the software under the terms of the CeCILL-B
11 # license as circulated by CEA, CNRS and INRIA at the following URL
12 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
13 # or in the file LICENSE.txt.
15 # As a counterpart to the access to the source code and rights to copy,
16 # modify and redistribute granted by the license, users are provided only
17 # with a limited warranty and the software's author, the holder of the
18 # economic rights, and the successive licensors have only limited
21 # The fact that you are presently reading this means that you have had
22 # knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------
26 /*=========================================================================
32 =========================================================================*/
34 /* ---------------------------------------------------------------------
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
39 * This software is governed by the CeCILL-B license under French law and
40 * abiding by the rules of distribution of free software. You can use,
41 * modify and/ or redistribute the software under the terms of the CeCILL-B
42 * license as circulated by CEA, CNRS and INRIA at the following URL
43 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
44 * or in the file LICENSE.txt.
46 * As a counterpart to the access to the source code and rights to copy,
47 * modify and redistribute granted by the license, users are provided only
48 * with a limited warranty and the software's author, the holder of the
49 * economic rights, and the successive licensors have only limited
52 * The fact that you are presently reading this means that you have had
53 * knowledge of the CeCILL-B license and that you accept its terms.
54 * ------------------------------------------------------------------------ */
58 * \brief Class bbtk::wxVtkSceneManager .
61 #include "wxVtkSceneManager.h"
63 #include <vtkPolygon.h>
64 #include <vtkUnstructuredGrid.h>
68 #define POORT_MAX_LINE_SIZE_INTERPRETER 1500
70 //=========================================================================
72 // EED 15 oct 2012 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
74 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
76 _cbName = "ComplexBoxName";
77 _cbPackageName = "PackageName";
78 _Author = "Author ??";
80 _Description = "Description ??";
84 _bugTextActor_text = "void";
85 _bugTextActor_status = 0;
89 _idManager = idManager;
91 _bbtkfactory = bbtkfactory;
93 _startDragging = false;
94 _isComplexBox = false;
96 if (_baseView != NULL) {
99 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
102 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
106 _worldState = NOTHING_HAPPENS;
107 registerController(this);
110 _idConnectionInCreation = -1;
115 //=========================================================================
117 void wxVtkSceneManager::disconnectDrop()
119 printf("EED %p ~wxVtkSceneManager::disconnectDrop()\n", this);
120 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
121 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
124 //=========================================================================
126 wxVtkSceneManager::~wxVtkSceneManager()
129 printf("EED %p ~wxVtkSceneManager() START\n", this);
132 printf("EED %p ~wxVtkSceneManager() END\n", this);
135 //=========================================================================
137 void wxVtkSceneManager::configureBaseView()
139 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
141 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
143 // Important to activate the 2D interaction system
144 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
145 interactorstylebaseview->SetInteractor(iren);
146 iren->SetInteractorStyle(interactorstylebaseview);
147 interactorstylebaseview->SetwxVtkBaseView(_baseView);
149 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
150 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, -1000, 1000);
151 _baseView->GetRenderer()->GetActiveCamera()->Zoom(10);
154 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
155 _baseView->GetRenderer()->GradientBackgroundOn();
158 _textActor = vtkTextActor3D::New();
159 // _textActor = vtkTextActor::New();
160 _textActor->SetPosition(-9999, -9999, GPOSITION_Z);
161 _textActor->SetInput("<void>");
162 _textActor->GetTextProperty()->SetFontSize(60);
163 _textActor->GetTextProperty()->BoldOn();
164 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,PORTTEXT_NH_B);
166 _baseView->GetRenderer()->AddActor(_textActor);
168 // Actor Fill_Port_Text
173 double zInic = GPOSITION_Z;
175 vtkPolygon *aPolygon = vtkPolygon::New();
176 _fillObjectActor = vtkActor::New();
178 _pts = vtkPoints::New();
180 double w = 100, h = 10, b = h / 15, t = 3;
181 _pts->SetNumberOfPoints(21);
182 _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
183 _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
184 _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
185 _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
186 _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
188 _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
189 _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
190 _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
191 _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
193 _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
194 _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
195 _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
196 _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
198 _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
199 _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
200 _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
201 _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
203 _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
204 _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
205 _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
206 _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
208 aPolygon->GetPointIds()->SetNumberOfIds(21);
209 for (int i = 0; i < 21; i++) {
210 aPolygon->GetPointIds()->SetId(i, i);
213 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
214 aPolygonGrid->Allocate(1, 1);
215 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),
216 aPolygon->GetPointIds());
217 aPolygonGrid->SetPoints(_pts);
218 _aPolygonMapper = vtkDataSetMapper::New();
219 _aPolygonMapper->SetInput(aPolygonGrid);
220 _fillObjectActor->SetMapper(_aPolygonMapper);
221 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
223 _fillObjectActor->GetProperty()->SetOpacity(0);
224 _aPolygonMapper->Modified();
226 _baseView->GetRenderer()->AddActor(_fillObjectActor);
229 //=========================================================================
231 std::string wxVtkSceneManager::generateANewNameForABox() {
232 std::stringstream boxname;
233 if (_numBoxes < 10) {
234 boxname << "Box0" << _numBoxes;
236 boxname << "Box" << _numBoxes;
239 return boxname.str();
242 //=========================================================================
244 std::string wxVtkSceneManager::findANewNameForABox() {
245 std::string boxname = generateANewNameForABox();
247 while (boxExist(boxname) == true) {
248 boxname = generateANewNameForABox();
254 //=========================================================================
255 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
256 double zIn, std::string name, bool boxExecutable, double xEn,
257 double yEn, double zEn) {
258 GObjectController *cont = _controllers[idBox];
259 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
260 bbmod->setBBTKName(name);
261 bbmod->setInicPoint(xIn, yIn, zIn);
262 bbmod->setFinalPoint(xEn, yEn, zEn);
263 bbmod->setExecutable(boxExecutable);
265 bbmod->notifyObservers(_idManager);
269 //=========================================================================
271 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,std::string boxType)
273 _worldState = NOTHING_HAPPENS;
274 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
275 int type = GBLACKBOX;
276 //Create the MVC Objects
277 GBlackBoxModel *model = (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
278 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
279 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
281 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
284 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
286 k = _bbtkfactory->GetPackage(packageName);
287 mapDesc = k->GetDescriptorMap();
289 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for package %s, NOT EXIST\n", packageName.c_str());
292 BlackBoxDescriptor::Pointer descriptor;
294 descriptor = mapDesc[boxType];
296 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for box %s of package %s, NOT EXIST\n", boxType.c_str(),packageName.c_str());
299 if (descriptor == NULL)
301 printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
304 //Prepares the initial model
305 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
308 double yy = windowHeight - y;
310 //z value is not important yet, because it is only used a parallel projection
311 double zz = GPOSITION_Z;
312 _baseView->TransCoordScreenToWorld(xx, yy, zz);
313 model->setInicPoint(xx, yy, zz);
315 std::stringstream stream;
317 std::string newBoxName;
318 newBoxName = findANewNameForABox();
320 stream << newBoxName;
322 std::string arraystring = stream.str();
324 model->setBBTKName(arraystring);
325 model->setBBTKType(boxType);
326 model->setBBTKPackage(packageName);
328 model->addObserver(view);
329 model->addObserver(this);
331 //Iterate and create the input ports
332 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
333 descriptor->GetInputDescriptorMap();
334 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
337 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) {
338 BlackBoxInputDescriptor *desc = itInput->second;
339 createGInputPort(GINPUTPORT, i, model, desc);
343 //Iterate and create the output ports
344 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
345 descriptor->GetOutputDescriptorMap();
346 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
349 for (itOutput = descriptorOutMap.begin(); itOutput
350 != descriptorOutMap.end(); ++itOutput) {
351 BlackBoxOutputDescriptor *desc = itOutput->second;
352 createGOutputPort(GOUTPUTPORT, i, model, desc);
356 //Associates the view with the correspondent renderer and the model.
357 //(NOTE: Refresh is only made by the view)
358 view->setModel(model);
359 view->setBaseView(_baseView);
360 view->initVtkObjects();
362 //Associates the controller with the correspondent model and view
363 controller->setModelAndView(model, view);
365 //Resgiter change to the observers of the actual model
366 model->notifyObservers(_idManager);
368 int newId = addObjectController(controller);
374 //=========================================================================
376 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
377 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
378 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
380 int type = GCOMPLEXINPUTPORT;
382 //Create the MVC Objects
384 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
385 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
386 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
388 //Prepares the initial model
391 double yy = windowHeight - 5;
393 //z value is not important yet, because it is only used a parallel projection
394 double zz = GPOSITION_Z;
396 _baseView->TransCoordScreenToWorld(xx, yy, zz);
397 model->setInicPoint(xx, yy, zz);
399 model->setBBTKName(inputName);
400 model->setBBTKType("ComplexInputPort");
401 model->setComplexPortType(type);
403 model->addObserver(view);
404 model->addObserver(this);
406 //create the output port
407 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
408 "ComplexOutputPortType","ComplexOutputPortDescriopton", 0, model);
409 model->addOutputPort((GPortModel*) portController->getModel());
411 //Associates the view with the correspondent renderer and the model.
412 //(NOTE: Refresh is only made by the view)
413 view->setModel(model);
414 view->setBaseView(_baseView);
415 view->initVtkObjects();
417 //Associates the controller with the correspondent model and view
418 controller->setModelAndView(model, view);
420 //Resgiter change to the observers of the actual model
421 model->notifyObservers(_idManager);
423 int newId = addObjectController(controller);
427 //=========================================================================
429 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
430 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
431 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
433 int type = GCOMPLEXOUTPUTPORT;
435 //Create the MVC Objects
437 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
438 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
439 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
441 //Prepares the initial model
444 double yy = windowHeight - 5;
446 //z value is not important yet, because it is only used a parallel projection
447 double zz = GPOSITION_Z;
449 _baseView->TransCoordScreenToWorld(xx, yy, zz);
450 model->setInicPoint(xx, yy, zz);
452 model->setBBTKName(outputName);
453 model->setBBTKType("ComplexOutputPort");
454 model->setComplexPortType(type);
456 model->addObserver(view);
457 model->addObserver(this);
459 //create the output port
460 GPortController* portController = createGPort(GINPUTPORT, outputName,
461 "ComplexInputPort","ComplexInputPortDescription", 0, model);
462 model->addInputPort((GPortModel*) portController->getModel());
464 //Associates the view with the correspondent renderer and the model.
465 //(NOTE: Refresh is only made by the view)
466 view->setModel(model);
467 view->setBaseView(_baseView);
468 view->initVtkObjects();
470 //Associates the controller with the correspondent model and view
471 controller->setModelAndView(model, view);
473 //Resgiter change to the observers of the actual model
474 model->notifyObservers(_idManager);
476 int newId = addObjectController(controller);
480 //=========================================================================
482 int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
484 GPortController* portController = createGPort(portType, desc->GetName(),
485 desc->GetTypeName(), desc->GetDescription(), posinBox, blackBox);
486 blackBox->addInputPort((GPortModel*) portController->getModel());
487 return portController->getId();
490 //=========================================================================
492 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
494 GPortController* portController = createGPort(portType, desc->GetName(),
495 desc->GetTypeName(),desc->GetDescription(), posinBox, blackBox);
496 blackBox->addOutputPort((GPortModel*) portController->getModel());
497 return portController->getId();
500 //=========================================================================
502 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posInBox,GBoxModel *blackBox)
506 //Create the MVC Objects
509 (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
511 vtkGObjectView *view =
512 GObjectsMVCFactory::getInstance()->createGObjectView(type);
513 GObjectController* controller =
514 GObjectsMVCFactory::getInstance()->createGObjectController(type);
516 model->registerInBox(blackBox, portType, posInBox);
518 model->setBBTKType(bbtkType);
519 model->setBBTKName(bbtkName);
520 model->setBBTKDescription(bbtkDescription);
522 model->addObserver(view);
523 model->addObserver(this);
525 //Associates the view with the correspondent renderer and the model.
526 //(NOTE: Refresh is only made by the view)
527 view->setModel(model);
528 view->setBaseView(_baseView);
529 view->initVtkObjects();
531 //Associates the controller with the correspondent model and view
532 controller->setModelAndView(model, view);
534 model->notifyObservers(_idManager);
536 addObjectController(controller);
538 return (GPortController*) controller;
541 //=========================================================================
543 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
545 int type = GCONNECTOR;
547 manualConnectorContourController *manContourControl = new manualConnectorContourController();
548 manualConnectorContourView *manContourView = new manualConnectorContourView();
549 manualContourModel *manContourModel = new manualContourModel();
550 GConnectorController *connectorcontroller = new GConnectorController();
551 GConnectorModel *connectorModel = new GConnectorModel();
552 vtkGConnectorView *connectorView = new vtkGConnectorView();
553 connectorModel->setGObjectType(type);
555 manContourModel->SetCloseContour(false);
556 connectorModel->setStartPort(startPort);
558 manContourView->SetModel(manContourModel);
559 manContourView->SetWxVtkBaseView(_baseView);
560 manContourView->SetRange(0.5);
561 manContourView->SetZ(GPOSITION_Z);
563 manContourView->SetColorNormalContour(0, 0, 1);
564 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
565 manContourView->SetColorSelectContour(1, 0.8, 0);
571 * Width increased from 2 to 3, it simplifies line handling and spline control :P
574 manContourView->SetWidthLine( 3 ) ;
575 manContourView->SetShowText(false);
577 manContourControl->SetModelView(manContourModel, manContourView);
579 manContourControl->CreateNewManualContour();
583 connectorModel->getInicPoint(x, y, z);
586 manContourControl->SetState(1);
587 manContourModel->SetCloseContour(false);
589 manContourModel->AddPoint(x, y, z);
590 manContourView->AddPoint();
592 manContourModel->AddPoint(x, y, z);
593 manContourView->AddPoint();
595 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
596 manContourControl->_bakIdPoint = bak;
598 manContourControl->SetMoving(false);
600 connectorcontroller->setModelAndView(connectorModel, connectorView);
602 int newId = addObjectController(connectorcontroller);
604 connectorcontroller->setManualContourController(manContourControl);
605 connectorModel->setManualContourModel(manContourModel);
606 connectorView->setManualContourView(manContourView);
607 connectorView->setModel(connectorModel);
608 connectorView->setBaseView(_baseView);
610 connectorModel->addObserver(connectorView);
611 connectorModel->addObserver(this);
613 // manContourView->Refresh();
618 //=========================================================================
620 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
622 vtkInteractorStyleBaseView * baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
623 baseViewControlManager->AddInteractorStyleMaracas(param);
626 //=========================================================================
628 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
630 vtkInteractorStyleBaseView *baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
631 baseViewControlManager->RemoveInteractorStyleMaracas(param);
634 //=========================================================================
636 vtkRenderer* wxVtkSceneManager::getRenderer()
638 return _baseView->GetRenderer();
641 //=========================================================================
643 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
645 return _baseView->GetRenWin();
647 //=========================================================================
650 //=========================================================================
651 int wxVtkSceneManager::GetIndexInSelected(int idControler)
654 for (int i = 0; i < (int) _selectedObjects.size(); i++)
656 if (_selectedObjects[i] == idControler)
664 //=========================================================================
666 void wxVtkSceneManager::update(int idController, int command) {
668 if (command != NO_COMMAND)
670 if (command == ADD_TO_SELECTED)
672 if (GetIndexInSelected(idController) == -1)
674 _selectedObjects.push_back(idController);
676 } else if (command == REMOVE_FROM_SELECTED) {
677 int index = GetIndexInSelected(idController);
680 _selectedObjects.erase(_selectedObjects.begin() + index);
682 } else if (command == INIT_CREATION_CONTOUR) {
684 typedef std::map<int , GObjectController*>::iterator TIterator ;
687 // Find current item in the controller
688 iter = _controllers.find( idController ) ;
689 iter_end = _controllers.end( ) ;
691 if ( iter != iter_end ) {
692 GObjectController* gobjc = iter->second ;
694 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
695 // And if the item is a port
696 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
697 TIterator c_it = _controllers.begin( ) ;
698 // Go through all componets
699 for ( c_it ; c_it != iter_end ; c_it++ ) {
700 GObjectController* obc = c_it->second ;
701 int obc_type = obc->getModel( )->getGObjectType( ) ;
702 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
703 // if the component is a port and the type is the same of that selected
704 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
706 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
707 //obc->getView( )->setState( HIGHLIGHTED ) ;
715 _worldState = INIT_CREATION_CONTOUR;
716 GObjectController* cont = _controllers[idController];
717 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
719 // The last one is the controller of the connector
720 std::map<int, GObjectController*>::iterator it2;
722 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
724 GObjectController *cont = it2->second;
725 if (cont->getGObjectType() == GPORT)
727 GPortModel* port = (GPortModel*) cont->getModel();
728 if (port->getPortType() == GINPUTPORT)
730 cont->SetActive(true);
732 cont->getView()->setState(NOTHING_HAPPENS);
733 cont->getModel()->notifyObservers(_idManager);
734 cont->SetActive(false);
737 cont->getView()->setState(NOTHING_HAPPENS);
738 cont->getModel()->notifyObservers(_idManager);
739 cont->SetActive(false);
742 _selectedObjects.clear();
743 _idConnectionInCreation = createGConnector(startOutputPort);
744 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
745 _worldState = NOTHING_HAPPENS;
746 //int id = _controllers.size()-1;
747 GObjectController *cont = _controllers[_idConnectionInCreation];
748 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
749 GObjectController *finPort = _controllers[idController];
751 if (finPort->getGObjectType() == GPORT)
753 GPortModel* modelPort = (GPortModel*) finPort->getModel();
754 modelContour->setEndPort(modelPort);
757 typedef std::map<int, GObjectController*>::iterator TIterator;
758 TIterator c_it = _controllers.begin();
759 TIterator iter_end = _controllers.end();
760 // Go through all componets
761 for (c_it; c_it != iter_end; c_it++) {
762 GObjectController* obc = c_it->second;
763 int obc_type = obc->getModel()->getGObjectType();
764 int obc_state = obc->getView()->getState();
765 // if the component is a port and the type is the same of that selected
766 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
767 // Return element to neutral state if not selected
768 obc->getView()->setState(NOTHING_HAPPENS);
770 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
771 // Change element to connected state
772 obc->getView()->setState(HIGHLIGHTED);
779 _parent->saveTempandUpdate("create connection");
782 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
783 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
785 std::map<int, GObjectController*>::iterator it2;
787 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
789 GObjectController *cont = it2->second;
790 if (cont->getView() != NULL) {
791 cont->getView()->setState(NOTHING_HAPPENS);
792 cont->getModel()->notifyObservers(_idManager);
794 cont->SetActive(true);
803 //=========================================================================
805 bool wxVtkSceneManager::OnMouseMove()
808 bool okStatusMessage = false;
809 bool okPortMessage = false;
810 wxVTKRenderWindowInteractor *wxVTKiren;
811 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
812 wxVTKiren->GetEventPosition(X, Y);
814 if (_worldState == DRAG_OBJECTS) {
815 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
816 int id = _selectedObjects[i];
817 GObjectController* cont = _controllers[id];
818 if (_startDragging) {
819 cont->getView()->setStartDragging(true);
821 cont->getView()->moveObject(X, Y);
822 cont->getView()->setState(DRAG);
823 cont->getModel()->notifyObservers(_idManager);
826 std::map<int, GObjectController*>::iterator it;
828 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
829 GObjectController *desc = it->second;
830 if (desc->getGObjectType() == GCONNECTOR) {
831 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
832 vconn->updateStartEndPoints();
836 _startDragging = false;
838 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
839 std::map<int, GObjectController*>::iterator it;
841 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
842 GObjectController *desc = it->second;
843 int type = desc->getGObjectType();
844 int state = desc->getView()->getState();
845 desc->getModel()->getCenter(px, py, pz);
848 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
851 okStatusMessage = true;
852 updateStatusBar(desc->getStatusText());
853 if (type == GBLACKBOX)
855 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
856 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
861 if ( ( _bugTextActor_text==desc->getStatusText() ) || (_bugTextActor_status==0) )
863 _bugTextActor_status = 1;
864 okPortMessage = true;
866 _textActor->SetScale(0.1);
867 std::string tmp = desc->getStatusText()+"\n";
868 _textActor->SetInput( tmp.c_str() );
869 _textActor->SetPosition(px - 25, py + 1, pz + 2);
870 _textActor->Modified();
874 _fillObjectActor->SetScale(1);
875 _fillObjectActor->GetProperty()->SetOpacity(0.50);
876 _fillObjectActor->SetPosition(px, py, 1);
877 _aPolygonMapper->Modified();
879 _bugTextActor_status = 2;
880 } // _bugTextActor_tex
881 _bugTextActor_text = desc->getStatusText();
885 } // for controllers it
887 if (okStatusMessage == false)
892 if ((okPortMessage == false) || (_bugTextActor_status== 2 ) )
894 _bugTextActor_status = 0;
895 _textActor->SetScale(0.0001);
896 _textActor->SetInput("a\n");
897 _textActor->Modified();
898 _fillObjectActor->SetScale(0.0001);
903 //=========================================================================
905 bool wxVtkSceneManager::OnLeftButtonDown()
907 if (_worldState == INIT_CREATION_CONTOUR)
909 bool isOverPort = false;
910 std::map<int, GObjectController*>::iterator it;
911 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
913 GObjectController *desc = it->second;
914 if (desc->getGObjectType() == GPORT)
916 GPortModel *portmod = (GPortModel*) desc->getModel();
917 vtkGObjectView *portView = desc->getView();
918 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
923 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
925 portView->setState( HIGHLIGHTED);
932 if (isOverPort == false)
935 UnSelectBlackBoxes();
939 } else { //_worldState
941 _worldState = DRAG_OBJECTS;
942 _startDragging = true;
944 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
945 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
946 ctrlkey = ctrlkey + shiftkey;
948 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
951 int state = cont->getView()->getState();
952 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
953 UnSelectBlackBoxes();
956 UnSelectBlackBoxes(); // EED 12/07/2012
958 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
959 int id = _selectedObjects[i];
960 GObjectController *cont = _controllers[id];
961 cont->getView()->setState(DRAG);
962 cont->getModel()->notifyObservers(_idManager);
964 } // if _selectedObjects.size
970 //=========================================================================
972 bool wxVtkSceneManager::OnLeftButtonUp()
974 if (_worldState == DRAG_OBJECTS) {
975 _worldState = NOTHING_HAPPENS;
977 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
978 int id = _selectedObjects[i];
979 GObjectController* cont = _controllers[id];
980 cont->getView()->setState(SELECTED);
981 cont->getModel()->notifyObservers(_idManager);
987 //=========================================================================
988 void wxVtkSceneManager::CancelConnection()
990 if (_worldState == INIT_CREATION_CONTOUR)
992 _worldState = NOTHING_HAPPENS;
993 //int lastId = _controllers.size()-1;
995 GConnectorController *connector =
996 (GConnectorController*) _controllers[_idConnectionInCreation];
997 connector->removeFromScene();
998 unregisterController(connector);
999 _controllers.erase(_idConnectionInCreation);
1001 std::map<int, GObjectController*>::iterator it;
1002 for (it = _controllers.begin(); it != _controllers.end(); ++it)
1004 GObjectController *desc = it->second;
1005 desc->SetActive(true);
1006 desc->getView()->setState(NOTHING_HAPPENS);
1007 desc->getModel()->notifyObservers(_idManager);
1012 //=========================================================================
1014 bool wxVtkSceneManager::OnRightButtonUp()
1016 if (_worldState == INIT_CREATION_CONTOUR)
1020 UnSelectBlackBoxes();
1026 bool wxVtkSceneManager::OnMiddleButtonDown() {
1029 this->_vtkInteractorStyleBaseView->StartPan();
1034 bool wxVtkSceneManager::OnMiddleButtonUp() {
1037 this->_vtkInteractorStyleBaseView->EndPan();
1044 //=========================================================================
1046 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1047 GObjectController *result = NULL;
1049 wxVTKRenderWindowInteractor *wxVTKiren;
1051 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1052 wxVTKiren->GetEventPosition(X, Y);
1054 std::map<int, GObjectController*>::iterator it;
1056 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1057 GObjectController *cont = it->second;
1058 int type = cont->getGObjectType();
1060 if (cont->getView()->isPointInside(X, Y) == true) {
1061 if (type == GBLACKBOX) {
1064 } // if isPointInside
1069 //=========================================================================
1070 void wxVtkSceneManager::UnSelectBlackBoxes() {
1071 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1072 int id = _selectedObjects[i];
1073 GObjectController* control = _controllers[id];
1074 control->getView()->setState(NOTHING_HAPPENS);
1075 control->getModel()->notifyObservers(_idManager);
1076 }// for _selectedObjects
1077 _selectedObjects.clear();
1080 //=========================================================================
1081 bool wxVtkSceneManager::OnLeftDClick() {
1082 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1084 UnSelectBlackBoxes();
1085 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1091 wxVTKRenderWindowInteractor *wxVTKiren;
1092 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1093 wxVTKiren->GetEventPosition(X,Y);
1095 std::map<int, GObjectController*>::iterator it;
1097 bool clickOnObject = false;
1099 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1101 GObjectController *cont = it->second;
1102 int type = cont->getGObjectType();
1104 if(cont->getView()->isPointInside(X,Y))
1108 for (int i=0; i< (int)_selectedObjects.size(); i++)
1110 int id = _selectedObjects[i];
1111 GObjectController* control = _controllers[id];
1112 control->getView()->setState(NOTHING_HAPPENS);
1114 _selectedObjects.clear();
1116 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1117 _parent->editBlackBox(bbmodel);
1119 clickOnObject = true;
1123 if(clickOnObject==false)
1125 //_parent->editDiagramParameters(this);
1131 //=========================================================================
1133 bool wxVtkSceneManager::OnChar()
1137 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1138 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1140 // KeyCode 127 : Delete Key
1141 // KeyCode 8 : Backspace Key
1144 if (keyCode == 8 || keyCode == 127 || keyCode == 27)
1146 if (_worldState == INIT_CREATION_CONTOUR)
1149 UnSelectBlackBoxes();
1154 if (keyCode == 8 || keyCode == 127)
1157 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1159 int id = _selectedObjects[i];
1160 std::map<int, GObjectController*>::iterator it;
1161 it = _controllers.find(id);
1162 if (it != _controllers.end())
1164 oktmp = deleteObject(id);
1167 }// for selected objects
1168 if (ok) _selectedObjects.clear();
1169 _parent->saveTempandUpdate("delete object");
1174 if((keyCode==0) && (ctrlkey==1)) {
1179 if(_selectedObjects.size()){
1180 std::cout<<"objects to copy :";
1181 for(int i=0;i<_selectedObjects.size();i++)
1183 std::cout<<_selectedObjects.at(i)<<" ";
1185 DuplicateObjects(getSelectedObjects());
1187 std::cout<<"No objects to copy\n";
1188 } // _selectedObjects.size
1194 //=========================================================================
1196 void wxVtkSceneManager::AddControlerToBeRemove(
1197 std::vector<int> *controllersToRemove, int id) {
1201 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1202 if (id == (*controllersToRemove)[i]) {
1208 controllersToRemove->push_back(id);
1213 //=========================================================================
1215 bool wxVtkSceneManager::deleteObject(int id)
1218 GObjectController *control = _controllers[id];
1219 std::vector<int> controllersToRemove;
1220 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1221 == GCOMPLEXINPUTPORT || control->getGObjectType()
1222 == GCOMPLEXOUTPUTPORT) {
1223 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1224 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1226 bool boxConnected = false;
1228 // Add box input controllers to be removed
1229 for (int i = 0; i < (int) inputs.size(); i++) {
1230 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1231 if (inputs[i]->isConnected()) {
1232 boxConnected = true;
1236 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1238 // Add box output controllers to be removed
1239 for (int i = 0; i < (int) outputs.size(); i++) {
1240 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1241 if (outputs[i]->isConnected()) {
1242 boxConnected = true;
1246 // Add connection controllers to be removed
1247 std::map<int, GObjectController*>::iterator it;
1248 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1249 GObjectController *cont = it->second;
1250 int type = cont->getGObjectType();
1251 if (type == GCONNECTOR) {
1252 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1253 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1255 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1257 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1259 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1264 // Add box controller to be removed
1265 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1266 } else if (control->getGObjectType() == GCONNECTOR) {
1267 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1268 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1270 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1271 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1273 gconnectorcontroler->getManualContourController()->OnChar();
1278 std::map<int, GObjectController*>::iterator it;
1280 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1281 int key = controllersToRemove[i];
1282 it = _controllers.find(key);
1283 GObjectController *cont = _controllers[key];
1285 cont->removeFromScene();
1286 unregisterController((InteractorStyleMaracas*) cont);
1287 _controllers.erase(it);
1295 //=========================================================================
1297 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1298 std::string boxName) {
1299 _parent->displayBlackBoxInfo(packageName, boxName);
1302 //=========================================================================
1304 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1305 _parent->updateStatusBar(textStatus);
1308 //=========================================================================
1309 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1310 std::string result = "";
1311 if (withLineNumber == true) {
1313 stringstream StrStream;
1315 std::string strValue = StrStream.str();
1318 } else if (value < 100) {
1322 result += strValue + ": ";
1326 //=========================================================================
1328 bool wxVtkSceneManager::MakeBoxExecutable() {
1329 std::map<int, GObjectController*> selected = getSelectedObjects();
1330 if( selected.empty() )
1333 std::map<int, GObjectController*>::iterator it;
1334 for (it = selected.begin(); it != selected.end(); ++it) {
1335 GObjectController* lastSelected = it->second;
1337 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1338 GBlackBoxModel *bbmodel =
1339 (GBlackBoxModel*) lastSelected->getModel();
1340 view->setState(HIGHLIGHTED);
1341 if (bbmodel->isExecutable()) {
1342 bbmodel->setExecutable(false);
1344 bbmodel->setExecutable(true);
1346 bbmodel->notifyObservers(lastSelected->getId());
1354 //=========================================================================
1356 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1357 std::cout << "wxVtkSceneManager::getDiagramBBS" << std::endl;
1358 bool existsExec = false;
1360 std::vector<std::string> packages;
1361 std::vector<int> boxes;
1362 std::vector<int> connections;
1363 std::vector<int> execBoxes;
1365 std::map<int, GObjectController*>::iterator it;
1367 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1368 GObjectController *desc = it->second;
1369 int type = desc->getGObjectType();
1371 if (type == GBLACKBOX) {
1372 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1374 std::string pkg = mod->getBBTKPackage();
1375 bool existsPkg = false;
1376 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1377 if (packages[t] == pkg) {
1382 packages.push_back(pkg);
1385 boxes.push_back(it->first);
1386 if (mod->isExecutable()) {
1387 execBoxes.push_back(it->first);
1390 } else if (type == GCONNECTOR) {
1391 connections.push_back(it->first);
1396 std::string script = "";
1397 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1398 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1399 script += LineNumber(wln, lnNmbr) + "\n";
1401 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1402 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1404 for (i = 0; i < (int) packages.size(); i++) {
1405 script += LineNumber(wln, lnNmbr);
1406 script += "include ";
1407 script += packages[i];
1411 script += LineNumber(wln, lnNmbr);
1416 script += LineNumber(wln, lnNmbr);
1417 script += "author \"";
1421 script += LineNumber(wln, lnNmbr);
1422 script += "description \"";
1423 script += _Description;
1426 script += LineNumber(wln, lnNmbr);
1427 script += "category \"";
1428 script += _Category;
1431 script += LineNumber(wln, lnNmbr);
1434 // script+="include std\n"; // JPR
1436 for (i = 0; i < (int) boxes.size(); i++) {
1437 script += LineNumber(wln, lnNmbr);
1440 GObjectController *control = _controllers[id];
1441 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1443 script += model->getBBTKPackage()+":";
1444 script += model->getBBTKType();
1446 script += model->getBBTKName();
1449 std::vector<GPortModel*> inputs = model->getInputPorts();
1450 for (int j = 0; j < (int) inputs.size(); j++) {
1451 GPortModel* inputPort = inputs[j];
1452 if (inputPort->isValueSet()) {
1453 script += LineNumber(wln, lnNmbr);
1455 script += model->getBBTKName();
1457 script += inputPort->getBBTKName();
1459 script += inputPort->getValue();
1464 script += LineNumber(wln, lnNmbr);
1469 script += LineNumber(wln, lnNmbr);
1473 std::string complexInputs="";
1475 for (i = 0; i < (int) connections.size(); i++) {
1476 //script += LineNumber(wln, lnNmbr);
1477 //script += "connect ";
1478 int id = connections[i];
1479 GObjectController *control = _controllers[id];
1480 GConnectorModel *model = (GConnectorModel*) control->getModel();
1484 GPortModel *start = model->getStartPort();
1485 GBoxModel *startBox = start->getParentBox();
1487 GPortModel *end = model->getEndPort();
1488 GBoxModel *endBox = end->getParentBox();
1490 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1492 complexInputs += "input ";
1493 complexInputs += startBox->getBBTKName();
1495 complexInputs += " ";
1496 complexInputs += endBox->getBBTKName();
1497 complexInputs += ".";
1498 complexInputs += end->getBBTKName();
1500 complexInputs += " ";
1501 complexInputs += "\" \"";
1503 complexInputs += "\n";
1507 script += LineNumber(wln, lnNmbr);
1508 script += "connect ";
1509 script += startBox->getBBTKName();
1511 script += start->getBBTKName();
1515 //End Connection info
1516 script += endBox->getBBTKName();
1518 script += end->getBBTKName();
1523 script += LineNumber(wln, lnNmbr);
1527 script += LineNumber(wln, lnNmbr);
1530 script += LineNumber(wln, lnNmbr);
1533 script += LineNumber(wln, lnNmbr);
1534 script += "# Complex input ports\n";
1535 script += complexInputs;
1537 if((_MessageKind!=" ")&&(_MessageLevel!=" ")){
1538 script += LineNumber(wln, lnNmbr);
1539 script += "message ";
1540 script += _MessageKind;
1542 script += _MessageLevel;
1546 for (i = 0; i < (int) execBoxes.size(); i++) {
1547 script += LineNumber(wln, lnNmbr);
1549 int id = execBoxes[i];
1550 GObjectController *control = _controllers[id];
1551 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1553 script += model->getBBTKName();
1562 //=========================================================================
1564 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1565 std::cout<<"wxVtkSceneManager::saveComplexBoxBBS"<<std::endl;
1566 std::vector<std::string> packages;
1567 std::vector<int> boxes;
1568 std::vector<int> connections;
1569 std::vector<int> execBoxes;
1571 std::map<int, GObjectController*>::iterator it;
1573 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1574 GObjectController *desc = it->second;
1575 int type = desc->getGObjectType();
1577 if (type == GBLACKBOX) {
1578 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1580 std::string pkg = mod->getBBTKPackage();
1581 bool existsPkg = false;
1582 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1583 if (packages[t] == pkg) {
1588 packages.push_back(pkg);
1591 boxes.push_back(it->first);
1592 if (mod->isExecutable()) {
1593 execBoxes.push_back(it->first);
1595 } else if (type == GCONNECTOR) {
1596 connections.push_back(it->first);
1600 std::string script = "";
1602 script += "include std\n"; // EED
1603 script += "include itkvtk\n"; // EED
1605 for (i = 0; i < (int) packages.size(); i++) {
1606 script += "include ";
1607 script += packages[i];
1612 // Definition of a complex box
1613 script += "define ";
1614 script += _cbName + " " + _cbPackageName;
1618 script += "author \"";
1622 script += "description \"";
1623 script += _Description;
1627 script += "category \"";
1628 script += _Category;
1633 for (i = 0; i < (int) boxes.size(); i++) {
1636 GObjectController *control = _controllers[id];
1637 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1639 script += model->getBBTKPackage()+":";
1640 script += model->getBBTKType();
1642 script += model->getBBTKName();
1645 std::vector<GPortModel*> inputs = model->getInputPorts();
1646 for (int j = 0; j < (int) inputs.size(); j++) {
1647 GPortModel* inputPort = inputs[j];
1648 if (inputPort->isValueSet()) {
1650 script += model->getBBTKName();
1652 script += inputPort->getBBTKName();
1654 script += inputPort->getValue();
1662 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1664 std::string complexInputs = "";
1665 std::string complexOutputs = "";
1668 for (i = 0; i < (int) connections.size(); i++) {
1669 int id = connections[i];
1670 GObjectController *control = _controllers[id];
1671 GConnectorModel *model = (GConnectorModel*) control->getModel();
1674 GPortModel *start = model->getStartPort();
1675 GBoxModel *startBox = start->getParentBox();
1677 GPortModel *end = model->getEndPort();
1678 GBoxModel *endBox = end->getParentBox();
1680 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1681 complexInputs += "input ";
1682 complexInputs += startBox->getBBTKName();
1684 complexInputs += " ";
1685 complexInputs += endBox->getBBTKName();
1686 complexInputs += ".";
1687 complexInputs += end->getBBTKName();
1689 complexInputs += " ";
1690 complexInputs += "\" \"";
1692 complexInputs += "\n";
1693 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1694 complexOutputs += "output ";
1695 complexOutputs += endBox->getBBTKName();
1697 complexOutputs += " ";
1698 complexOutputs += startBox->getBBTKName();
1699 complexOutputs += ".";
1700 complexOutputs += start->getBBTKName();
1702 complexOutputs += " ";
1703 complexOutputs += "\" \"";
1705 complexOutputs += "\n";
1707 script += "connect ";
1708 script += startBox->getBBTKName();
1710 script += start->getBBTKName();
1714 //End Connection info
1715 script += endBox->getBBTKName();
1717 script += end->getBBTKName();
1724 script += "# Complex input ports\n";
1725 script += complexInputs;
1728 script += "# Complex output ports\n";
1729 script += complexOutputs;
1733 script += "message ";
1734 script += _MessageKind;
1736 script += _MessageLevel;
1739 for (i = 0; i < (int) execBoxes.size(); i++) {
1741 int id = execBoxes[i];
1742 GObjectController *control = _controllers[id];
1743 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1745 script += model->getBBTKName();
1750 script += "endefine";
1756 //=========================================================================
1758 void wxVtkSceneManager::deleteAllBoxes() {
1759 std::map<int, GObjectController*>::iterator it;
1760 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1761 GObjectController *cont = it->second;
1762 cont->removeFromScene();
1763 unregisterController((InteractorStyleMaracas*) cont);
1765 _selectedObjects.clear();
1766 _controllers.clear();
1769 //=========================================================================
1772 void wxVtkSceneManager::refresh() {
1773 _baseView->Refresh();
1775 //=========================================================================
1777 void wxVtkSceneManager::refreshScene() {
1778 _baseView->RefreshView();
1781 //=========================================================================
1783 void wxVtkSceneManager::centerView() {
1785 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1786 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1787 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1788 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1791 //=========================================================================
1793 void wxVtkSceneManager::saveDiagram(std::string &content) {
1796 content += "CATEGORY:";
1797 content += GetCategory();
1800 content += "DESCRIPTION:";
1801 content += GetDescription();
1804 content += "AUTHOR:";
1805 content += GetAuthor();
1808 //Print info IF COMPLEX BOX
1809 content += "COMPLEXBOX:";
1810 if (_isComplexBox) {
1811 content += "TRUE\n";
1813 content += "COMPLEXBOXNAME:";
1814 content += GetCbName();
1817 content += "PACKAGENAME:";
1818 content += GetCbPackageName();
1821 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1822 * External inputs are possible for applications and complex boxes
1823 //Print info complex input ports
1824 std::vector<int> inputs = getComplexInputPorts();
1825 int insize = inputs.size();
1826 content += "COMPLEXINPUTS:";
1827 sprintf(buffer, "%d", insize);
1831 for (int i = 0; i < insize; i++) {
1833 GObjectController *cont = _controllers[id];
1834 cont->getModel()->save(content);
1838 //Print info complex output ports
1839 std::vector<int> outputs = getComplexOutputPorts();
1840 int outsize = outputs.size();
1841 content += "COMPLEXOUTPUTS:";
1842 sprintf(buffer, "%d", outsize);
1846 for (int i = 0; i < outsize; i++) {
1847 int id = outputs[i];
1848 GObjectController *cont = _controllers[id];
1849 cont->getModel()->save(content);
1853 content += "FALSE\n";
1856 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1857 // External inputs are possible for applications and complex boxes
1858 std::vector<int> inputs = getComplexInputPorts();
1859 int insize = inputs.size();
1860 content += "COMPLEXINPUTS:";
1861 sprintf(buffer, "%d", insize);
1865 for (int i = 0; i < insize; i++) {
1867 GObjectController *cont = _controllers[id];
1868 cont->getModel()->save(content);
1872 std::vector<int> boxes = getBlackBoxes();
1873 int bsize = boxes.size();
1874 content += "BOXES:";
1875 sprintf(buffer, "%d", bsize);
1879 for (int i = 0; i < bsize; i++) {
1881 // std::cout<<"id "<<id<<std::endl;//CFT
1882 GObjectController *cont = _controllers[id];
1883 // std::cout<<"nombre: "<<cont->getStatusText()<<std::endl;//CFT
1884 // std::cout<<"tipo: "<<cont->getModel()->getBBTKType()<<std::endl;//CFT
1885 // //boxesDiagram[i] = cont->getModel()->getBBTKType();//CFT
1886 // std::cout<<"nname: "<<cont->getModel()->getBBTKName()<<std::endl;//CFT
1887 // std::cout<<"categorie: "<<GetCategory()<<std::endl;//CFT
1888 // std::cout<<"type: "<<cont->getModel()->getGObjectType()<<std::endl;//CFT
1889 cont->getModel()->save(content);
1893 std::vector<int> connections = getConnections();
1894 int csize = connections.size();
1895 content += "CONNECTIONS:";
1896 sprintf(buffer, "%d", csize);
1900 for (int i = 0; i < csize; i++) {
1901 int id = connections[i];
1902 GObjectController *cont = _controllers[id];
1903 cont->getModel()->save(content);
1908 //=========================================================================
1909 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1911 getline(inputStream, line,'\n');
1912 int size = line.length();
1915 if ( line[ size-1 ]==13 )
1917 line.erase(size-1,1);
1922 //=========================================================================
1923 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1927 std::string version = "<void>";
1928 std::string line = "";
1929 char delims[] = ":";
1930 char *result = NULL;
1931 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1933 getCleanLine(inputStream, line);
1936 while (!inputStream.eof()) {
1937 if (line == "" || line[0] == '#') {
1939 getCleanLine(inputStream, line);
1941 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1942 version = line.substr(18, 3);
1944 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1945 version = line.substr(18, 3);
1947 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1948 version = line.substr(18, 3);
1950 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1951 version = line.substr(18, 3);
1953 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1954 version = line.substr(18, 3);
1956 } else if (line == "APP_START") {
1965 if ((version != "1.0") && (version != "1.1")) {
1966 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1967 char categoryTmp[30];
1968 strcpy(categoryTmp, line.c_str());
1969 result = strtok(categoryTmp, delims);
1970 result = strtok(NULL, delims);
1971 SetCategory(result);
1973 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1974 char descriptionTmp[1024];
1975 strcpy(descriptionTmp, line.c_str());
1976 result = strtok(descriptionTmp, delims);
1977 result = strtok(NULL, delims);
1978 SetDescription(result);
1980 getCleanLine(inputStream, line);//AUTHOR:<author>
1981 char authorTmp[255];
1982 strcpy(authorTmp, line.c_str());
1983 result = strtok(authorTmp, delims);
1984 result = strtok(NULL, delims);
1989 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1990 char complexTmp[30];
1991 strcpy(complexTmp, line.c_str());
1992 result = strtok(complexTmp, delims);
1993 result = strtok(NULL, delims);
1994 std::string isComplexBox(result);
1996 if (isComplexBox == "TRUE") {
1997 _isComplexBox = true;
1999 if ((version != "1.0") && (version != "1.1")) {
2000 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
2001 char complexboxnameTmp[255];
2002 strcpy(complexboxnameTmp, line.c_str());
2003 result = strtok(complexboxnameTmp, delims);
2004 result = strtok(NULL, delims);
2007 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
2008 char packagenameTmp[255];
2009 strcpy(packagenameTmp, line.c_str());
2010 result = strtok(packagenameTmp, delims);
2011 result = strtok(NULL, delims);
2012 SetCbPackageName(result);
2017 //-----------------------
2018 //- COMPLEX INPUT PORTS
2019 //-----------------------
2020 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2022 strcpy(inputs, line.c_str());
2023 result = strtok(inputs, delims);
2024 result = strtok(NULL, delims);
2027 std::istringstream inps(result);
2030 for (int i = 0; i < numInputs; i++) {
2032 getCleanLine(inputStream, line);//COMPLEX_PORT
2033 getCleanLine(inputStream, line);//name
2034 std::string inputPortName(line);
2037 getCleanLine(inputStream, line);//xInic:yInic:zInic
2039 strcpy(coord, line.c_str());
2040 result = strtok(coord, delims);//xInic
2041 std::string xInic(result);
2042 result = strtok(NULL, delims);//yInic
2043 std::string yInic(result);
2044 result = strtok(NULL, delims);//zInic
2045 std::string zInic(result);
2047 double xIn, yIn, zIn;
2048 std::istringstream xSt(xInic);
2050 std::istringstream ySt(yInic);
2052 std::istringstream zSt(zInic);
2057 if (zIn==900) zIn=GPOSITION_Z;
2060 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2062 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2064 } // for input complex box
2069 //-----------------------
2070 //- COMPLEX OUTPUT PORTS
2071 //-----------------------
2073 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2075 strcpy(outputs, line.c_str());
2076 result = strtok(outputs, delims);
2077 result = strtok(NULL, delims);
2080 std::istringstream outps(result);
2081 outps >> numOutputs;
2083 for (int i = 0; i < numOutputs; i++) {
2085 getCleanLine(inputStream, line);//COMPLEX_PORT
2086 getCleanLine(inputStream, line);//name
2087 std::string outputPortName(line);
2090 getCleanLine(inputStream, line);//xInic:yInic:zInic
2092 strcpy(coord, line.c_str());
2093 result = strtok(coord, delims);//xInic
2094 std::string xInic(result);
2095 result = strtok(NULL, delims);//yInic
2096 std::string yInic(result);
2097 result = strtok(NULL, delims);//zInic
2098 std::string zInic(result);
2100 double xIn, yIn, zIn;
2101 std::istringstream xSt(xInic);
2103 std::istringstream ySt(yInic);
2105 std::istringstream zSt(zInic);
2110 if (zIn==900) zIn=GPOSITION_Z;
2113 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2115 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2117 } // for output complex box
2121 // RaC2012 2nd Hackfest
2122 if(version >= "1.4")
2124 //-----------------------
2125 //- EXTERNAL INPUT PORTS
2126 //-----------------------
2127 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2129 strcpy(inputs, line.c_str());
2130 result = strtok(inputs, delims);
2131 result = strtok(NULL, delims);
2134 std::istringstream inps(result);
2137 for (int i = 0; i < numInputs; i++) {
2139 getCleanLine(inputStream, line);//COMPLEX_PORT
2140 getCleanLine(inputStream, line);//name
2141 std::string inputPortName(line);
2144 getCleanLine(inputStream, line);//xInic:yInic:zInic
2146 strcpy(coord, line.c_str());
2147 result = strtok(coord, delims);//xInic
2148 std::string xInic(result);
2149 result = strtok(NULL, delims);//yInic
2150 std::string yInic(result);
2151 result = strtok(NULL, delims);//zInic
2152 std::string zInic(result);
2154 double xIn, yIn, zIn;
2155 std::istringstream xSt(xInic);
2157 std::istringstream ySt(yInic);
2159 std::istringstream zSt(zInic);
2164 if (zIn==900) zIn=GPOSITION_Z;
2167 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2168 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2170 } // for external input
2175 getCleanLine(inputStream, line);//BOXES:num
2177 strcpy(boxes, line.c_str());
2178 result = strtok(boxes, delims);
2179 result = strtok(NULL, delims);
2182 std::istringstream is(result);
2185 for (int i = 0; i < numBoxes; i++) {
2187 getCleanLine(inputStream, line);//BOX
2188 getCleanLine(inputStream, line);//package:type:name
2190 strcpy(box, line.c_str());
2191 result = strtok(box, delims);//package
2192 std::string package(result);
2193 result = strtok(NULL, delims);//type
2194 std::string type(result);
2195 result = strtok(NULL, delims);//name
2196 std::string name(result);
2199 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2201 strcpy(exec, line.c_str());
2202 result = strtok(exec, delims);//ISEXEC
2203 result = strtok(NULL, delims);//TRUE|FALSE
2204 std::string isExec(result);
2207 getCleanLine(inputStream, line);//xInic:yInic:zInic
2209 strcpy(coord, line.c_str());
2210 result = strtok(coord, delims);//xInic
2211 std::string xInic(result);
2212 result = strtok(NULL, delims);//yInic
2213 std::string yInic(result);
2214 result = strtok(NULL, delims);//zInic
2215 std::string zInic(result);
2217 double xIn, yIn, zIn;
2218 std::istringstream xSt(xInic);
2220 std::istringstream ySt(yInic);
2222 std::istringstream zSt(zInic);
2228 if (zIn==900) zIn=GPOSITION_Z;
2233 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2234 strcpy(coord, line.c_str());
2235 result = strtok(coord, delims);//xEnd
2236 std::string xEnd(result);
2237 result = strtok(NULL, delims);//yEnd
2238 std::string yEnd(result);
2239 result = strtok(NULL, delims);//zEnd
2240 std::string zEnd(result);
2242 double xEn, yEn, zEn;
2243 std::istringstream xEt(xEnd);
2245 std::istringstream yEt(yEnd);
2247 std::istringstream zEt(zEnd);
2252 if (zEn==900) zEn=GPOSITION_Z;
2256 bool boxExecutable = false;
2257 if (isExec == "TRUE") {
2258 boxExecutable = true;
2261 int idBox = createGBlackBox(xIn, yIn, package, type);
2262 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2264 GObjectController *cont = _controllers[idBox];
2265 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2268 getCleanLine(inputStream, line);//PORT o FIN_BOX
2269 std::string port = line.substr(0, 4);
2270 while (port == "PORT")
2272 getCleanLine(inputStream, line);//name:value
2273 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2275 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2278 strcpy(poort, line.c_str());
2279 result = strtok(poort, delims);//name
2280 std::string name(result);
2282 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2283 result = strtok(NULL, delims);//value
2284 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2286 std::string tmpString=" ";
2287 tmpString[0]=34; // character "
2288 strcat(result,tmpString.c_str());
2290 std::string value(result);
2292 bbmod->setValueToInput(name, value);
2294 getCleanLine(inputStream, line);//PORT o FIN_BOX
2295 port = line.substr(0, 4);
2298 //EED bbmod->notifyObservers(_idManager);
2303 getCleanLine(inputStream, line);//CONNECTIONS:num
2305 strcpy(conns, line.c_str());
2306 result = strtok(conns, delims);
2307 result = strtok(NULL, delims);
2310 std::istringstream isCons(result);
2314 for (int i = 0; i < numConns; i++) {
2316 getCleanLine(inputStream, line);//CONNECTION
2317 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2320 strcpy(connec, line.c_str());
2321 result = strtok(connec, delims);
2322 std::string nameStartBox(result);
2323 result = strtok(NULL, delims);
2324 std::string nameStartPort(result);
2325 result = strtok(NULL, delims);
2326 std::string nameEndBox(result);
2327 result = strtok(NULL, delims);
2328 std::string nameEndPort(result);
2331 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2333 if (version != "1.0") {
2334 //Readding control points of the manualContour
2335 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2336 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2337 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2338 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2339 strcpy(conns, line.c_str());
2340 result = strtok(conns, delims);
2341 result = strtok(NULL, delims);
2343 int numberOfControlPoints;
2344 std::istringstream isCons(result);
2345 isCons >> numberOfControlPoints;
2347 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2348 getCleanLine(inputStream, line); //XX:YY:ZZ
2350 strcpy(connec, line.c_str());
2353 result = strtok(connec, delims);
2354 std::istringstream isPointX(result);
2356 result = strtok(NULL, delims);
2357 std::istringstream isPointY(result);
2359 result = strtok(NULL, delims);
2360 std::istringstream isPointZ(result);
2365 if (pz==900) pz=GPOSITION_Z;
2368 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2369 conView->getManualContourView()->AddPoint();
2375 //=========================================================================
2378 //=========================================================================
2379 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2380 std::string portName, double xIn, double yIn, double zIn)
2383 if (inputoutput == true) {
2384 idPort = createGComplexBoxInputPort(portName);
2386 idPort = createGComplexBoxOutputPort(portName);
2388 GObjectController *cont = _controllers[idPort];
2389 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2390 cbmod->setInicPoint(xIn, yIn, zIn);
2391 cbmod->notifyObservers(_idManager);
2393 //=========================================================================
2396 //=========================================================================
2397 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2402 GBoxModel *boxModel = NULL;
2403 std::vector<int> lstB = getBlackBoxes();
2404 for (j = 0; j < (int) lstB.size(); j++) {
2406 bMod = (GBoxModel*) _controllers[idB]->getModel();
2407 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2415 if (boxModel == NULL) {
2416 std::vector<int> lstInputs = getComplexInputPorts();
2417 for (j = 0; j < (int) lstInputs.size(); j++) {
2419 bMod = (GBoxModel*) _controllers[idB]->getModel();
2420 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2428 std::vector<int> lstOutputs = getComplexOutputPorts();
2429 for (j = 0; j < (int) lstOutputs.size(); j++) {
2430 int idB = lstOutputs[j];
2431 bMod = (GBoxModel*) _controllers[idB]->getModel();
2432 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2444 //=========================================================================
2447 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2448 std::string nameStartPort, std::string nameEndBox,
2449 std::string nameEndPort) {
2451 GBoxModel *boxModel;
2452 GPortModel *startP = NULL;
2453 GPortModel *endP = NULL;
2455 boxModel = findGBox(nameStartBox);
2456 if(boxModel == NULL)
2458 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2460 if (boxModel != NULL) {
2461 startP = boxModel->getOutputPort(nameStartPort);
2463 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port is null. Port name is probably wrong. Start>%s::%s End>%s::%s\n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str() );
2467 boxModel = findGBox(nameEndBox);
2468 if(boxModel == NULL)
2470 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2472 if (boxModel != NULL) {
2473 endP = boxModel->getInputPort(nameEndPort);
2475 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port is null. Port name is probably wrong. Start>%s::%s End>%s::%s \n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str());
2480 int idCon = createGConnector(startP);
2482 _worldState = NOTHING_HAPPENS;
2483 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2485 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2486 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2487 tempp->endContourCreation();
2488 conMod->setEndPort(endP);
2489 conView->updateStartEndPoints();
2493 //=========================================================================
2495 bool wxVtkSceneManager::boxExist(std::string boxname) {
2497 std::map<int, GObjectController*>::iterator it;
2498 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2499 GObjectController *cont = it->second;
2500 if (cont->getModel()->getBBTKName() == boxname) {
2507 //=========================================================================
2509 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2510 std::vector<int> vect;
2511 std::map<int, GObjectController*>::iterator it;
2512 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2513 GObjectController *cont = it->second;
2514 if (cont->getGObjectType() == GBLACKBOX) {
2515 vect.push_back(cont->getId());
2521 //=========================================================================
2523 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2524 std::vector<int> vect;
2525 std::map<int, GObjectController*>::iterator it;
2526 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2527 GObjectController *cont = it->second;
2528 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2529 vect.push_back(cont->getId());
2535 //=========================================================================
2537 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2538 std::vector<int> vect;
2539 std::map<int, GObjectController*>::iterator it;
2540 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2541 GObjectController *cont = it->second;
2542 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2543 vect.push_back(cont->getId());
2549 //=========================================================================
2551 std::vector<int> wxVtkSceneManager::getConnections() {
2552 std::vector<int> vect;
2553 std::map<int, GObjectController*>::iterator it;
2554 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2555 GObjectController *cont = it->second;
2556 if (cont->getGObjectType() == GCONNECTOR) {
2557 vect.push_back(cont->getId());
2563 //=========================================================================
2565 bool wxVtkSceneManager::isComplexBox() {
2566 return _isComplexBox;
2569 //=========================================================================
2571 void wxVtkSceneManager::setComplexBox(bool val) {
2572 _isComplexBox = val;
2575 //=========================================================================
2577 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2578 //Register the controller of the new object
2579 registerController((InteractorStyleMaracas*) objController);
2580 //Add the object to the objects list
2581 int newId = _contLastId;//_controllers.size();
2582 objController->setId(newId);
2583 _controllers[newId] = objController;
2584 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2589 //=========================================================================
2591 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2593 std::map<int, int> oldIdNewIdBoxes;
2594 std::vector<int> connections;
2596 std::vector<int> newBoxesID;
2598 std::map<int, GObjectController*>::iterator it;
2599 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2600 GObjectController *cont = it->second;
2601 int type = cont->getGObjectType();
2603 if (type == GBLACKBOX) {
2605 double xInic, yInic, zInic;
2606 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2607 copyBox->getInicPoint(xInic, yInic, zInic);
2608 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2609 copyBox->getBBTKType());
2611 int idcB = copyBox->getObjectId();
2612 oldIdNewIdBoxes[idcB] = idBox;
2613 cont = _controllers[idBox];
2614 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2615 newbox->setInicPoint(xInic, yInic, zInic);
2616 int num = newbox->getNumInputPorts();
2617 for (int j = 0; j < num; j++) {
2618 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2620 newbox->move(xInic + 20, yInic + 20, zInic);
2621 newbox->notifyObservers(_idManager);
2622 newBoxesID.push_back(newbox->getObjectId());
2624 } else if (type == GCONNECTOR) {
2625 int idCon = cont->getId();
2626 connections.push_back(idCon);
2631 for (int i = 0; i < (int) connections.size(); i++) {
2632 int objId = connections[i];
2633 GObjectController *cont = objectsMap[objId];
2634 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2636 GPortModel* startPort = connectModel->getStartPort();
2637 int startPortIndex = startPort->getPosInBox();
2638 GPortModel* endPort = connectModel->getEndPort();
2639 int endPortIndex = endPort->getPosInBox();
2641 GBlackBoxModel* startPortParentBox =
2642 (GBlackBoxModel*) startPort->getParentBox();
2643 GBlackBoxModel* endPortParentBox =
2644 (GBlackBoxModel*) endPort->getParentBox();
2646 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2647 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2649 GBlackBoxModel* newStartBox =
2650 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2651 GBlackBoxModel* newEndBox =
2652 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2654 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2655 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2657 // Creates connection
2658 int idCon = createGConnector(newStartPort);
2659 GConnectorController *tempp =
2660 (GConnectorController*) _controllers[idCon];
2661 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2662 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2663 tempp->endContourCreation();
2664 conMod->setEndPort(newEndPort);
2665 conView->updateStartEndPoints();
2668 /// the new selected boxes are the duplicate ones
2670 UnSelectBlackBoxes();
2671 for (int i = 0; i < newBoxesID.size(); i++) {
2672 _selectedObjects.push_back(newBoxesID.at(i));
2675 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2676 int id = _selectedObjects[i];
2677 GObjectController* cont = _controllers[id];
2679 cont->getView()->setState(SELECTED);
2680 cont->getModel()->notifyObservers(_idManager);
2686 //=========================================================================
2688 int wxVtkSceneManager::getNumSelectedObjects() {
2689 return _selectedObjects.size();
2692 //=========================================================================
2694 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2695 std::map<int, GObjectController*> mapSelected;
2697 std::map<int, GObjectController*>::iterator it;
2698 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2699 GObjectController *cont = it->second;
2700 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2702 mapSelected[cont->getId()] = cont;
2706 std::map<int, GObjectController*>::iterator it2;
2707 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2708 GObjectController *cont = it2->second;
2709 if (cont->getGObjectType() == GCONNECTOR) {
2710 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2711 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2712 GBoxModel* startPortParentBox =
2713 cmod->getStartPort()->getParentBox();
2715 std::map<int, GObjectController*>::iterator iterOBJ1 =
2716 mapSelected.find(startPortParentBox->getObjectId());
2717 std::map<int, GObjectController*>::iterator iterOBJ2 =
2718 mapSelected.find(endPortParentBox->getObjectId());
2720 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2721 int ID = cont->getId();
2722 mapSelected[ID] = cont;
2729 //=========================================================================
2731 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2733 std::map<int, int> oldIdNewIdBoxes;
2734 std::vector<int> connections;
2736 std::map<int, GObjectController*>::iterator it;
2737 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2738 GObjectController *cont = it->second;
2739 int type = cont->getGObjectType();
2741 if (type == GBLACKBOX) {
2743 double xInic, yInic, zInic;
2744 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2745 copyBox->getInicPoint(xInic, yInic, zInic);
2746 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2748 int idcB = copyBox->getObjectId();
2749 oldIdNewIdBoxes[idcB] = idBox;
2750 cont = _controllers[idBox];
2751 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2752 newbox->setInicPoint(xInic, yInic, zInic);
2753 int num = newbox->getNumInputPorts();
2754 for (int j = 0; j < num; j++)
2756 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2758 newbox->notifyObservers(_idManager);
2759 } else if (type == GCONNECTOR) {
2760 int idCon = cont->getId();
2761 connections.push_back(idCon);
2766 for (int i = 0; i < (int) connections.size(); i++) {
2767 int objId = connections[i];
2768 GObjectController *cont = objectsMap[objId];
2769 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2771 GPortModel* startPort = connectModel->getStartPort();
2772 int startPortIndex = startPort->getPosInBox();
2773 GPortModel* endPort = connectModel->getEndPort();
2774 int endPortIndex = endPort->getPosInBox();
2776 GBlackBoxModel* startPortParentBox =
2777 (GBlackBoxModel*) startPort->getParentBox();
2778 GBlackBoxModel* endPortParentBox =
2779 (GBlackBoxModel*) endPort->getParentBox();
2781 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2782 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2784 GBlackBoxModel* newStartBox =
2785 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2786 GBlackBoxModel* newEndBox =
2787 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2789 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2790 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2792 // Creates connection
2793 int idCon = createGConnector(newStartPort);
2794 GConnectorController *tempp =
2795 (GConnectorController*) _controllers[idCon];
2796 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2797 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2798 tempp->endContourCreation();
2799 conMod->setEndPort(newEndPort);
2800 conView->updateStartEndPoints();
2803 std::map<int, int>::iterator itIds;
2804 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2805 int idOld = itIds->first;
2806 int idNew = itIds->second;
2808 GBlackBoxModel* oldBox =
2809 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2810 GBlackBoxModel* newBox =
2811 (GBlackBoxModel*) _controllers[idNew]->getModel();
2813 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2814 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2815 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2816 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2818 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2820 //EED int toCreate=-1;
2821 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2822 if (oldInputConnections[k] == newInputConnections[l]) {
2827 if (exist == false) {
2828 //Create complex input
2829 int posInBox = oldInputConnections[k];
2830 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2831 std::string inputPortName = inputPort->getBBTKName();
2832 int idInputPort = createGComplexBoxInputPort(inputPortName);
2833 GObjectController *cont = _controllers[idInputPort];
2834 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2835 double xIn, yIn, zIn;
2836 inputPort->getInicPoint(xIn, yIn, zIn);
2838 cbmod->setInicPoint(xIn, yIn, zIn);
2839 cbmod->notifyObservers(_idManager);
2841 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2843 // Creates connection
2844 int idCon = createGConnector(cbmod->getOutputPort(0));
2845 GConnectorController *tempp =
2846 (GConnectorController*) _controllers[idCon];
2847 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2848 vtkGConnectorView *conView =
2849 (vtkGConnectorView*) tempp->getView();
2850 tempp->endContourCreation();
2851 conMod->setEndPort(inputPortEnd);
2852 conView->updateStartEndPoints();
2858 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2860 //EED int toCreate=-1;
2861 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2862 if (oldOutputConnections[k] == newOutputConnections[l]) {
2867 if (exist == false) {
2868 //Create complex output
2869 int posInBox = oldOutputConnections[k];
2870 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2871 std::string outputPortName = outputPort->getBBTKName();
2872 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2873 GObjectController *cont = _controllers[idOutputPort];
2874 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2875 double xIn, yIn, zIn;
2876 outputPort->getInicPoint(xIn, yIn, zIn);
2878 cbmod->setInicPoint(xIn, yIn, zIn);
2879 cbmod->notifyObservers(_idManager);
2881 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2883 // Creates connection
2884 int idCon = createGConnector(outputPortEnd);
2885 GConnectorController *tempp =
2886 (GConnectorController*) _controllers[idCon];
2887 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2888 vtkGConnectorView *conView =
2889 (vtkGConnectorView*) tempp->getView();
2890 tempp->endContourCreation();
2891 conMod->setEndPort(cbmod->getInputPort(0));
2892 conView->updateStartEndPoints();
2902 //=========================================================================
2903 void wxVtkSceneManager::SetCbName(std::string cbName) {
2905 if (_cbName == "") {
2906 _cbName = "<complex box name>";
2910 //=========================================================================
2911 std::string wxVtkSceneManager::GetCbName() {
2915 //=========================================================================
2916 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2917 _cbPackageName = packagename;
2918 if (_cbPackageName == "") {
2919 _cbPackageName = "<package name of the complex box>";
2923 //=========================================================================
2924 std::string wxVtkSceneManager::GetCbPackageName() {
2925 return _cbPackageName;
2928 //=========================================================================
2929 void wxVtkSceneManager::SetAuthor(std::string author) {
2931 if (_Author == "") {
2932 _Author = "<author of the box>";
2936 //=========================================================================
2937 std::string wxVtkSceneManager::GetAuthor() {
2941 //=========================================================================
2942 void wxVtkSceneManager::SetCategory(std::string category) {
2943 _Category = category;
2944 if (_Category == "") {
2945 _Category = "<category of the box>";
2949 //=========================================================================
2950 std::string wxVtkSceneManager::GetCategory() {
2954 //=========================================================================
2955 void wxVtkSceneManager::SetDescription(std::string description) {
2956 _Description = description;
2957 if (_Description == "") {
2958 _Description = "<description of the box>";
2962 //=========================================================================
2963 std::string wxVtkSceneManager::GetDescription() {
2964 return _Description;
2967 //=========================================================================
2969 void wxVtkSceneManager::SetMessageKind(std::string kind) {
2970 _MessageKind = kind;
2974 //=========================================================================
2976 std::string wxVtkSceneManager::GetMessageKind(){
2977 return _MessageKind;
2980 //=========================================================================
2982 void wxVtkSceneManager::SetMessageLevel(std::string Level){
2983 _MessageLevel = Level;
2986 //=========================================================================
2988 std::string wxVtkSceneManager::GetMessageLevel(){
2989 return _MessageLevel;
2992 //=========================================================================
2994 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
2997 std::vector< std::string> extInputs;
2998 std::map<int, GObjectController*>::iterator it;
2999 for (it = _controllers.begin(); it != _controllers.end(); ++it)
3001 GObjectController *cont = it->second;
3002 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
3004 extInputs.push_back(cont->getModel()->getBBTKName());
3010 //=========================================================================
3014 void wxVtkSceneManager::printAll(int com , int sta ){
3016 int tmpState = sta ;
3017 if ( tmpState == NOTHING_HAPPENS ) {
3018 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
3020 if ( tmpState == HIGHLIGHTED ) {
3021 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
3023 if ( tmpState == POSSIBLE_CONNECTION ) {
3024 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
3026 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
3027 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
3029 if ( tmpState == CLICKED ) {
3030 std::cout << "CONTROLER STATE---->CLICKED\n" ;
3032 if ( tmpState == DRAG ) {
3033 std::cout << "CONTROLER STATE---->DRAG\n" ;
3035 if ( tmpState == SELECTED ) {
3036 std::cout << "CONTROLER STATE---->SELECTED\n" ;
3038 if ( tmpState == CREATING_CONTOUR ) {
3039 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
3045 if ( command == INIT_CREATION_CONTOUR ) {
3046 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
3048 if ( command == FIN_CREATION_CONTOUR ) {
3049 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
3051 if ( command == ADD_TO_SELECTED ) {
3052 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
3054 if ( command == DRAG_OBJECTS ) {
3055 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
3057 if ( command == EDIT_BLACKBOX ) {
3058 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
3060 if ( command == REMOVE_FROM_SELECTED ) {
3061 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
3067 } // EO namespace bbtk