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);
285 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
287 k = _bbtkfactory->GetPackage(packageName);
288 mapDesc = k->GetDescriptorMap();
290 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for package %s, NOT EXIST\n", packageName.c_str());
293 BlackBoxDescriptor::Pointer descriptor;
295 descriptor = mapDesc[boxType];
297 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for box %s of package %s, NOT EXIST\n", boxType.c_str(),packageName.c_str());
300 if (descriptor == NULL)
302 printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
305 //Prepares the initial model
306 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
309 double yy = windowHeight - y;
311 //z value is not important yet, because it is only used a parallel projection
312 double zz = GPOSITION_Z;
313 _baseView->TransCoordScreenToWorld(xx, yy, zz);
314 model->setInicPoint(xx, yy, zz);
316 std::stringstream stream;
318 std::string newBoxName;
319 newBoxName = findANewNameForABox();
321 stream << newBoxName;
323 std::string arraystring = stream.str();
325 model->setBBTKName(arraystring);
326 model->setBBTKType(boxType);
327 model->setBBTKPackage(packageName);
329 model->addObserver(view);
330 model->addObserver(this);
332 //Iterate and create the input ports
333 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
334 descriptor->GetInputDescriptorMap();
335 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;
348 for (itOutput = descriptorOutMap.begin(); itOutput
349 != descriptorOutMap.end(); ++itOutput) {
350 BlackBoxOutputDescriptor *desc = itOutput->second;
351 createGOutputPort(GOUTPUTPORT, i, model, desc);
355 //Associates the view with the correspondent renderer and the model.
356 //(NOTE: Refresh is only made by the view)
357 view->setModel(model);
358 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);
530 //EED017 view->initVtkObjects();
531 view->createVtkObjects();
532 // view->addVtkActors();
535 //Associates the controller with the correspondent model and view
536 controller->setModelAndView(model, view);
538 model->notifyObservers(_idManager);
540 addObjectController(controller);
542 return (GPortController*) controller;
546 //=========================================================================
548 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
550 int type = GCONNECTOR;
552 manualConnectorContourController *manContourControl = new manualConnectorContourController();
553 manualConnectorContourView *manContourView = new manualConnectorContourView();
554 manualContourModel *manContourModel = new manualContourModel();
555 GConnectorController *connectorcontroller = new GConnectorController();
556 GConnectorModel *connectorModel = new GConnectorModel();
557 vtkGConnectorView *connectorView = new vtkGConnectorView();
558 connectorModel->setGObjectType(type);
560 manContourModel->SetCloseContour(false);
561 connectorModel->setStartPort(startPort);
563 manContourView->SetModel(manContourModel);
564 manContourView->SetWxVtkBaseView(_baseView);
565 manContourView->SetRange(0.5);
566 manContourView->SetZ(GPOSITION_Z);
568 manContourView->SetColorNormalContour(0, 0, 1);
569 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
570 manContourView->SetColorSelectContour(1, 0.8, 0);
576 * Width increased from 2 to 3, it simplifies line handling and spline control :P
580 manContourView->SetWidthLine( 3 ) ;
581 manContourView->SetShowText(false);
583 manContourControl->SetModelView(manContourModel, manContourView);
585 manContourControl->CreateNewManualContour();
589 connectorModel->getInicPoint(x, y, z);
592 manContourControl->SetState(1);
593 manContourModel->SetCloseContour(false);
595 manContourModel->AddPoint(x, y, z);
596 manContourView->AddPoint();
598 manContourModel->AddPoint(x, y, z);
599 manContourView->AddPoint();
601 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
602 manContourControl->_bakIdPoint = bak;
604 manContourControl->SetMoving(false);
606 connectorcontroller->setModelAndView(connectorModel, connectorView);
608 int newId = addObjectController(connectorcontroller);
610 connectorcontroller->setManualContourController(manContourControl);
611 connectorModel->setManualContourModel(manContourModel);
612 connectorView->setManualContourView(manContourView);
613 connectorView->setModel(connectorModel);
614 connectorView->setBaseView(_baseView);
616 connectorModel->addObserver(connectorView);
617 connectorModel->addObserver(this);
619 // manContourView->Refresh();
624 //=========================================================================
626 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
628 vtkInteractorStyleBaseView * baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
629 baseViewControlManager->AddInteractorStyleMaracas(param);
632 //=========================================================================
634 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
636 vtkInteractorStyleBaseView *baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
637 baseViewControlManager->RemoveInteractorStyleMaracas(param);
640 //=========================================================================
642 vtkRenderer* wxVtkSceneManager::getRenderer()
644 return _baseView->GetRenderer();
647 //=========================================================================
649 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
651 return _baseView->GetRenWin();
653 //=========================================================================
656 //=========================================================================
657 int wxVtkSceneManager::GetIndexInSelected(int idControler)
660 for (int i = 0; i < (int) _selectedObjects.size(); i++)
662 if (_selectedObjects[i] == idControler)
670 //=========================================================================
672 void wxVtkSceneManager::update(int idController, int command) {
674 if (command != NO_COMMAND)
676 if (command == ADD_TO_SELECTED)
678 if (GetIndexInSelected(idController) == -1)
680 _selectedObjects.push_back(idController);
682 } else if (command == REMOVE_FROM_SELECTED) {
683 int index = GetIndexInSelected(idController);
686 _selectedObjects.erase(_selectedObjects.begin() + index);
688 } else if (command == INIT_CREATION_CONTOUR) {
690 typedef std::map<int , GObjectController*>::iterator TIterator ;
693 // Find current item in the controller
694 iter = _controllers.find( idController ) ;
695 iter_end = _controllers.end( ) ;
697 if ( iter != iter_end ) {
698 GObjectController* gobjc = iter->second ;
700 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
701 // And if the item is a port
702 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
703 TIterator c_it = _controllers.begin( ) ;
704 // Go through all componets
705 for ( c_it ; c_it != iter_end ; c_it++ ) {
706 GObjectController* obc = c_it->second ;
707 int obc_type = obc->getModel( )->getGObjectType( ) ;
708 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
709 // if the component is a port and the type is the same of that selected
710 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
712 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
713 //obc->getView( )->setState( HIGHLIGHTED ) ;
721 _worldState = INIT_CREATION_CONTOUR;
722 GObjectController* cont = _controllers[idController];
723 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
725 // The last one is the controller of the connector
726 std::map<int, GObjectController*>::iterator it2;
728 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
730 GObjectController *cont = it2->second;
731 if (cont->getGObjectType() == GPORT)
733 GPortModel* port = (GPortModel*) cont->getModel();
734 if (port->getPortType() == GINPUTPORT)
736 cont->SetActive(true);
738 cont->getView()->setState(NOTHING_HAPPENS);
739 cont->getModel()->notifyObservers(_idManager);
740 cont->SetActive(false);
743 cont->getView()->setState(NOTHING_HAPPENS);
744 cont->getModel()->notifyObservers(_idManager);
745 cont->SetActive(false);
748 _selectedObjects.clear();
749 _idConnectionInCreation = createGConnector(startOutputPort);
750 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
751 _worldState = NOTHING_HAPPENS;
752 //int id = _controllers.size()-1;
753 GObjectController *cont = _controllers[_idConnectionInCreation];
754 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
755 GObjectController *finPort = _controllers[idController];
757 if (finPort->getGObjectType() == GPORT)
759 GPortModel* modelPort = (GPortModel*) finPort->getModel();
760 modelContour->setEndPort(modelPort);
763 typedef std::map<int, GObjectController*>::iterator TIterator;
764 TIterator c_it = _controllers.begin();
765 TIterator iter_end = _controllers.end();
766 // Go through all componets
767 for (c_it; c_it != iter_end; c_it++) {
768 GObjectController* obc = c_it->second;
769 int obc_type = obc->getModel()->getGObjectType();
770 int obc_state = obc->getView()->getState();
771 // if the component is a port and the type is the same of that selected
772 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
773 // Return element to neutral state if not selected
774 obc->getView()->setState(NOTHING_HAPPENS);
776 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
777 // Change element to connected state
778 obc->getView()->setState(HIGHLIGHTED);
785 _parent->saveTempandUpdate("create connection");
788 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
789 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
791 std::map<int, GObjectController*>::iterator it2;
793 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
795 GObjectController *cont = it2->second;
796 if (cont->getView() != NULL) {
797 cont->getView()->setState(NOTHING_HAPPENS);
798 cont->getModel()->notifyObservers(_idManager);
800 cont->SetActive(true);
809 //=========================================================================
811 bool wxVtkSceneManager::OnMouseMove()
814 bool okStatusMessage = false;
815 bool okPortMessage = false;
816 wxVTKRenderWindowInteractor *wxVTKiren;
817 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
818 wxVTKiren->GetEventPosition(X, Y);
820 if (_worldState == DRAG_OBJECTS) {
821 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
822 int id = _selectedObjects[i];
823 GObjectController* cont = _controllers[id];
824 if (_startDragging) {
825 cont->getView()->setStartDragging(true);
827 cont->getView()->moveObject(X, Y);
828 cont->getView()->setState(DRAG);
829 cont->getModel()->notifyObservers(_idManager);
832 std::map<int, GObjectController*>::iterator it;
834 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
835 GObjectController *desc = it->second;
836 if (desc->getGObjectType() == GCONNECTOR) {
837 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
838 vconn->updateStartEndPoints();
842 _startDragging = false;
844 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
845 std::map<int, GObjectController*>::iterator it;
847 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
848 GObjectController *desc = it->second;
849 int type = desc->getGObjectType();
850 int state = desc->getView()->getState();
851 desc->getModel()->getCenter(px, py, pz);
854 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
857 okStatusMessage = true;
858 updateStatusBar(desc->getStatusText());
859 if (type == GBLACKBOX)
861 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
862 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
867 if ( ( _bugTextActor_text==desc->getStatusText() ) || (_bugTextActor_status==0) )
869 _bugTextActor_status = 1;
870 okPortMessage = true;
872 _textActor->SetScale(0.1);
873 std::string tmp = desc->getStatusText()+"\n";
874 _textActor->SetInput( tmp.c_str() );
875 _textActor->SetPosition(px - 25, py + 1, pz + 2);
876 _textActor->Modified();
880 _fillObjectActor->SetScale(1);
881 _fillObjectActor->GetProperty()->SetOpacity(0.50);
882 _fillObjectActor->SetPosition(px, py, 1);
883 _aPolygonMapper->Modified();
885 _bugTextActor_status = 2;
886 } // _bugTextActor_tex
887 _bugTextActor_text = desc->getStatusText();
891 } // for controllers it
893 if (okStatusMessage == false)
898 if ((okPortMessage == false) || (_bugTextActor_status== 2 ) )
900 _bugTextActor_status = 0;
901 _textActor->SetScale(0.0001);
902 _textActor->SetInput("a\n");
903 _textActor->Modified();
904 _fillObjectActor->SetScale(0.0001);
909 //=========================================================================
911 bool wxVtkSceneManager::OnLeftButtonDown()
913 if (_worldState == INIT_CREATION_CONTOUR)
915 bool isOverPort = false;
916 std::map<int, GObjectController*>::iterator it;
917 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
919 GObjectController *desc = it->second;
920 if (desc->getGObjectType() == GPORT)
922 GPortModel *portmod = (GPortModel*) desc->getModel();
923 vtkGObjectView *portView = desc->getView();
924 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
929 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
931 portView->setState( HIGHLIGHTED);
938 if (isOverPort == false)
941 UnSelectBlackBoxes();
945 } else { //_worldState
947 _worldState = DRAG_OBJECTS;
948 _startDragging = true;
950 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
951 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
952 ctrlkey = ctrlkey + shiftkey;
954 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
957 int state = cont->getView()->getState();
958 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
959 UnSelectBlackBoxes();
962 UnSelectBlackBoxes(); // EED 12/07/2012
964 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
965 int id = _selectedObjects[i];
966 GObjectController *cont = _controllers[id];
967 cont->getView()->setState(DRAG);
968 cont->getModel()->notifyObservers(_idManager);
970 } // if _selectedObjects.size
976 //=========================================================================
978 bool wxVtkSceneManager::OnLeftButtonUp()
980 if (_worldState == DRAG_OBJECTS) {
981 _worldState = NOTHING_HAPPENS;
983 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
984 int id = _selectedObjects[i];
985 GObjectController* cont = _controllers[id];
986 cont->getView()->setState(SELECTED);
987 cont->getModel()->notifyObservers(_idManager);
993 //=========================================================================
994 void wxVtkSceneManager::CancelConnection()
996 if (_worldState == INIT_CREATION_CONTOUR)
998 _worldState = NOTHING_HAPPENS;
999 //int lastId = _controllers.size()-1;
1001 GConnectorController *connector =
1002 (GConnectorController*) _controllers[_idConnectionInCreation];
1003 connector->removeFromScene();
1004 unregisterController(connector);
1005 _controllers.erase(_idConnectionInCreation);
1007 std::map<int, GObjectController*>::iterator it;
1008 for (it = _controllers.begin(); it != _controllers.end(); ++it)
1010 GObjectController *desc = it->second;
1011 desc->SetActive(true);
1012 desc->getView()->setState(NOTHING_HAPPENS);
1013 desc->getModel()->notifyObservers(_idManager);
1018 //=========================================================================
1020 bool wxVtkSceneManager::OnRightButtonUp()
1022 if (_worldState == INIT_CREATION_CONTOUR)
1026 UnSelectBlackBoxes();
1032 bool wxVtkSceneManager::OnMiddleButtonDown() {
1035 this->_vtkInteractorStyleBaseView->StartPan();
1040 bool wxVtkSceneManager::OnMiddleButtonUp() {
1043 this->_vtkInteractorStyleBaseView->EndPan();
1050 //=========================================================================
1052 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1053 GObjectController *result = NULL;
1055 wxVTKRenderWindowInteractor *wxVTKiren;
1057 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1058 wxVTKiren->GetEventPosition(X, Y);
1060 std::map<int, GObjectController*>::iterator it;
1062 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1063 GObjectController *cont = it->second;
1064 int type = cont->getGObjectType();
1066 if (cont->getView()->isPointInside(X, Y) == true) {
1067 if (type == GBLACKBOX) {
1070 } // if isPointInside
1075 //=========================================================================
1076 void wxVtkSceneManager::UnSelectBlackBoxes() {
1077 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1078 int id = _selectedObjects[i];
1079 GObjectController* control = _controllers[id];
1080 control->getView()->setState(NOTHING_HAPPENS);
1081 control->getModel()->notifyObservers(_idManager);
1082 }// for _selectedObjects
1083 _selectedObjects.clear();
1086 //=========================================================================
1087 bool wxVtkSceneManager::OnLeftDClick() {
1088 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1090 UnSelectBlackBoxes();
1091 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1097 wxVTKRenderWindowInteractor *wxVTKiren;
1098 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1099 wxVTKiren->GetEventPosition(X,Y);
1101 std::map<int, GObjectController*>::iterator it;
1103 bool clickOnObject = false;
1105 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1107 GObjectController *cont = it->second;
1108 int type = cont->getGObjectType();
1110 if(cont->getView()->isPointInside(X,Y))
1114 for (int i=0; i< (int)_selectedObjects.size(); i++)
1116 int id = _selectedObjects[i];
1117 GObjectController* control = _controllers[id];
1118 control->getView()->setState(NOTHING_HAPPENS);
1120 _selectedObjects.clear();
1122 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1123 _parent->editBlackBox(bbmodel);
1125 clickOnObject = true;
1129 if(clickOnObject==false)
1131 //_parent->editDiagramParameters(this);
1137 //=========================================================================
1139 bool wxVtkSceneManager::OnChar()
1143 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1144 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1146 // KeyCode 127 : Delete Key
1147 // KeyCode 8 : Backspace Key
1150 if (keyCode == 8 || keyCode == 127 || keyCode == 27)
1152 if (_worldState == INIT_CREATION_CONTOUR)
1155 UnSelectBlackBoxes();
1160 if (keyCode == 8 || keyCode == 127)
1163 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1165 int id = _selectedObjects[i];
1166 std::map<int, GObjectController*>::iterator it;
1167 it = _controllers.find(id);
1168 if (it != _controllers.end())
1170 oktmp = deleteObject(id);
1173 }// for selected objects
1174 if (ok) _selectedObjects.clear();
1175 _parent->saveTempandUpdate("delete object");
1180 if((keyCode==0) && (ctrlkey==1)) {
1185 if(_selectedObjects.size()){
1186 std::cout<<"objects to copy :";
1187 for(int i=0;i<_selectedObjects.size();i++)
1189 std::cout<<_selectedObjects.at(i)<<" ";
1191 DuplicateObjects(getSelectedObjects());
1193 std::cout<<"No objects to copy\n";
1194 } // _selectedObjects.size
1200 //=========================================================================
1202 void wxVtkSceneManager::AddControlerToBeRemove(
1203 std::vector<int> *controllersToRemove, int id) {
1207 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1208 if (id == (*controllersToRemove)[i]) {
1214 controllersToRemove->push_back(id);
1219 //=========================================================================
1221 bool wxVtkSceneManager::deleteObject(int id)
1224 GObjectController *control = _controllers[id];
1225 std::vector<int> controllersToRemove;
1226 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1227 == GCOMPLEXINPUTPORT || control->getGObjectType()
1228 == GCOMPLEXOUTPUTPORT) {
1229 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1230 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1232 bool boxConnected = false;
1234 // Add box input controllers to be removed
1235 for (int i = 0; i < (int) inputs.size(); i++) {
1236 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1237 if (inputs[i]->isConnected()) {
1238 boxConnected = true;
1242 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1244 // Add box output controllers to be removed
1245 for (int i = 0; i < (int) outputs.size(); i++) {
1246 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1247 if (outputs[i]->isConnected()) {
1248 boxConnected = true;
1252 // Add connection controllers to be removed
1253 std::map<int, GObjectController*>::iterator it;
1254 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1255 GObjectController *cont = it->second;
1256 int type = cont->getGObjectType();
1257 if (type == GCONNECTOR) {
1258 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1259 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1261 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1263 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1265 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1270 // Add box controller to be removed
1271 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1272 } else if (control->getGObjectType() == GCONNECTOR) {
1273 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1274 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1276 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1277 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1279 gconnectorcontroler->getManualContourController()->OnChar();
1284 std::map<int, GObjectController*>::iterator it;
1286 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1287 int key = controllersToRemove[i];
1288 it = _controllers.find(key);
1289 GObjectController *cont = _controllers[key];
1291 cont->removeFromScene();
1292 unregisterController((InteractorStyleMaracas*) cont);
1293 _controllers.erase(it);
1301 //=========================================================================
1303 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1304 std::string boxName) {
1305 _parent->displayBlackBoxInfo(packageName, boxName);
1308 //=========================================================================
1310 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1311 _parent->updateStatusBar(textStatus);
1314 //=========================================================================
1315 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1316 std::string result = "";
1317 if (withLineNumber == true) {
1319 stringstream StrStream;
1321 std::string strValue = StrStream.str();
1324 } else if (value < 100) {
1328 result += strValue + ": ";
1332 //=========================================================================
1334 bool wxVtkSceneManager::MakeBoxExecutable() {
1335 std::map<int, GObjectController*> selected = getSelectedObjects();
1336 if( selected.empty() )
1339 std::map<int, GObjectController*>::iterator it;
1340 for (it = selected.begin(); it != selected.end(); ++it) {
1341 GObjectController* lastSelected = it->second;
1343 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1344 GBlackBoxModel *bbmodel =
1345 (GBlackBoxModel*) lastSelected->getModel();
1346 view->setState(HIGHLIGHTED);
1347 if (bbmodel->isExecutable()) {
1348 bbmodel->setExecutable(false);
1350 bbmodel->setExecutable(true);
1352 bbmodel->notifyObservers(lastSelected->getId());
1360 //=========================================================================
1362 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1363 std::cout << "wxVtkSceneManager::getDiagramBBS" << std::endl;
1364 bool existsExec = false;
1366 std::vector<std::string> packages;
1367 std::vector<int> boxes;
1368 std::vector<int> connections;
1369 std::vector<int> execBoxes;
1371 std::map<int, GObjectController*>::iterator it;
1373 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1374 GObjectController *desc = it->second;
1375 int type = desc->getGObjectType();
1377 if (type == GBLACKBOX) {
1378 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1380 std::string pkg = mod->getBBTKPackage();
1381 bool existsPkg = false;
1382 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1383 if (packages[t] == pkg) {
1388 packages.push_back(pkg);
1391 boxes.push_back(it->first);
1392 if (mod->isExecutable()) {
1393 execBoxes.push_back(it->first);
1396 } else if (type == GCONNECTOR) {
1397 connections.push_back(it->first);
1402 std::string script = "";
1403 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1404 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1405 script += LineNumber(wln, lnNmbr) + "\n";
1407 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1408 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1410 for (i = 0; i < (int) packages.size(); i++) {
1411 script += LineNumber(wln, lnNmbr);
1412 script += "include ";
1413 script += packages[i];
1417 script += LineNumber(wln, lnNmbr);
1422 script += LineNumber(wln, lnNmbr);
1423 script += "author \"";
1427 script += LineNumber(wln, lnNmbr);
1428 script += "description \"";
1429 script += _Description;
1432 script += LineNumber(wln, lnNmbr);
1433 script += "category \"";
1434 script += _Category;
1437 script += LineNumber(wln, lnNmbr);
1440 // script+="include std\n"; // JPR
1442 for (i = 0; i < (int) boxes.size(); i++) {
1443 script += LineNumber(wln, lnNmbr);
1446 GObjectController *control = _controllers[id];
1447 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1449 script += model->getBBTKPackage()+":";
1450 script += model->getBBTKType();
1452 script += model->getBBTKName();
1455 std::vector<GPortModel*> inputs = model->getInputPorts();
1456 for (int j = 0; j < (int) inputs.size(); j++) {
1457 GPortModel* inputPort = inputs[j];
1458 if (inputPort->isValueSet()) {
1459 script += LineNumber(wln, lnNmbr);
1461 script += model->getBBTKName();
1463 script += inputPort->getBBTKName();
1465 script += inputPort->getValue();
1470 script += LineNumber(wln, lnNmbr);
1475 script += LineNumber(wln, lnNmbr);
1479 std::string complexInputs="";
1481 for (i = 0; i < (int) connections.size(); i++) {
1482 //script += LineNumber(wln, lnNmbr);
1483 //script += "connect ";
1484 int id = connections[i];
1485 GObjectController *control = _controllers[id];
1486 GConnectorModel *model = (GConnectorModel*) control->getModel();
1490 GPortModel *start = model->getStartPort();
1491 GBoxModel *startBox = start->getParentBox();
1493 GPortModel *end = model->getEndPort();
1494 GBoxModel *endBox = end->getParentBox();
1496 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1498 complexInputs += "input ";
1499 complexInputs += startBox->getBBTKName();
1501 complexInputs += " ";
1502 complexInputs += endBox->getBBTKName();
1503 complexInputs += ".";
1504 complexInputs += end->getBBTKName();
1506 complexInputs += " ";
1507 complexInputs += "\" \"";
1509 complexInputs += "\n";
1513 script += LineNumber(wln, lnNmbr);
1514 script += "connect ";
1515 script += startBox->getBBTKName();
1517 script += start->getBBTKName();
1521 //End Connection info
1522 script += endBox->getBBTKName();
1524 script += end->getBBTKName();
1529 script += LineNumber(wln, lnNmbr);
1533 script += LineNumber(wln, lnNmbr);
1536 script += LineNumber(wln, lnNmbr);
1539 script += LineNumber(wln, lnNmbr);
1540 script += "# Complex input ports\n";
1541 script += complexInputs;
1543 if((_MessageKind!=" ")&&(_MessageLevel!=" ")){
1544 script += LineNumber(wln, lnNmbr);
1545 script += "message ";
1546 script += _MessageKind;
1548 script += _MessageLevel;
1552 for (i = 0; i < (int) execBoxes.size(); i++) {
1553 script += LineNumber(wln, lnNmbr);
1555 int id = execBoxes[i];
1556 GObjectController *control = _controllers[id];
1557 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1559 script += model->getBBTKName();
1568 //=========================================================================
1570 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1571 std::cout<<"wxVtkSceneManager::saveComplexBoxBBS"<<std::endl;
1572 std::vector<std::string> packages;
1573 std::vector<int> boxes;
1574 std::vector<int> connections;
1575 std::vector<int> execBoxes;
1577 std::map<int, GObjectController*>::iterator it;
1579 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1580 GObjectController *desc = it->second;
1581 int type = desc->getGObjectType();
1583 if (type == GBLACKBOX) {
1584 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1586 std::string pkg = mod->getBBTKPackage();
1587 bool existsPkg = false;
1588 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1589 if (packages[t] == pkg) {
1594 packages.push_back(pkg);
1597 boxes.push_back(it->first);
1598 if (mod->isExecutable()) {
1599 execBoxes.push_back(it->first);
1601 } else if (type == GCONNECTOR) {
1602 connections.push_back(it->first);
1606 std::string script = "";
1608 script += "include std\n"; // EED
1609 script += "include itkvtk\n"; // EED
1611 for (i = 0; i < (int) packages.size(); i++) {
1612 script += "include ";
1613 script += packages[i];
1618 // Definition of a complex box
1619 script += "define ";
1620 script += _cbName + " " + _cbPackageName;
1624 script += "author \"";
1628 script += "description \"";
1629 script += _Description;
1633 script += "category \"";
1634 script += _Category;
1639 for (i = 0; i < (int) boxes.size(); i++) {
1642 GObjectController *control = _controllers[id];
1643 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1645 script += model->getBBTKPackage()+":";
1646 script += model->getBBTKType();
1648 script += model->getBBTKName();
1651 std::vector<GPortModel*> inputs = model->getInputPorts();
1652 for (int j = 0; j < (int) inputs.size(); j++) {
1653 GPortModel* inputPort = inputs[j];
1654 if (inputPort->isValueSet()) {
1656 script += model->getBBTKName();
1658 script += inputPort->getBBTKName();
1660 script += inputPort->getValue();
1668 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1670 std::string complexInputs = "";
1671 std::string complexOutputs = "";
1674 for (i = 0; i < (int) connections.size(); i++) {
1675 int id = connections[i];
1676 GObjectController *control = _controllers[id];
1677 GConnectorModel *model = (GConnectorModel*) control->getModel();
1680 GPortModel *start = model->getStartPort();
1681 GBoxModel *startBox = start->getParentBox();
1683 GPortModel *end = model->getEndPort();
1684 GBoxModel *endBox = end->getParentBox();
1686 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1687 complexInputs += "input ";
1688 complexInputs += startBox->getBBTKName();
1690 complexInputs += " ";
1691 complexInputs += endBox->getBBTKName();
1692 complexInputs += ".";
1693 complexInputs += end->getBBTKName();
1695 complexInputs += " ";
1696 complexInputs += "\" \"";
1698 complexInputs += "\n";
1699 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1700 complexOutputs += "output ";
1701 complexOutputs += endBox->getBBTKName();
1703 complexOutputs += " ";
1704 complexOutputs += startBox->getBBTKName();
1705 complexOutputs += ".";
1706 complexOutputs += start->getBBTKName();
1708 complexOutputs += " ";
1709 complexOutputs += "\" \"";
1711 complexOutputs += "\n";
1713 script += "connect ";
1714 script += startBox->getBBTKName();
1716 script += start->getBBTKName();
1720 //End Connection info
1721 script += endBox->getBBTKName();
1723 script += end->getBBTKName();
1730 script += "# Complex input ports\n";
1731 script += complexInputs;
1734 script += "# Complex output ports\n";
1735 script += complexOutputs;
1739 script += "message ";
1740 script += _MessageKind;
1742 script += _MessageLevel;
1745 for (i = 0; i < (int) execBoxes.size(); i++) {
1747 int id = execBoxes[i];
1748 GObjectController *control = _controllers[id];
1749 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1751 script += model->getBBTKName();
1756 script += "endefine";
1762 //=========================================================================
1764 void wxVtkSceneManager::deleteAllBoxes() {
1765 std::map<int, GObjectController*>::iterator it;
1766 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1767 GObjectController *cont = it->second;
1768 cont->removeFromScene();
1769 unregisterController((InteractorStyleMaracas*) cont);
1771 _selectedObjects.clear();
1772 _controllers.clear();
1775 //=========================================================================
1778 void wxVtkSceneManager::refresh() {
1779 _baseView->Refresh();
1781 //=========================================================================
1783 void wxVtkSceneManager::refreshScene()
1785 _baseView->RefreshView();
1788 //=========================================================================
1790 void wxVtkSceneManager::centerView()
1793 _baseView->GetRenderer()->ComputeVisiblePropBounds(bb);
1796 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1797 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1798 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1799 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1801 _baseView->GetRenderer()->ResetCamera();
1802 _baseView->GetRenderer()->ResetCameraClippingRange();
1805 double tt=_baseView->GetRenderer()->GetNearClippingPlaneTolerance();
1806 printf("EED wxVtkSceneManager::centerView() tolerance=%f\n",tt);
1808 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1809 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1810 _baseView->GetRenderer()->GetActiveCamera()->SetClippingRange(0.01,100000);
1811 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1812 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1815 _baseView->GetRenderer()->Render();
1818 //=========================================================================
1820 void wxVtkSceneManager::saveDiagram(std::string &content)
1824 content += "CATEGORY:";
1825 content += GetCategory();
1828 content += "DESCRIPTION:";
1829 content += GetDescription();
1832 content += "AUTHOR:";
1833 content += GetAuthor();
1836 //Print info IF COMPLEX BOX
1837 content += "COMPLEXBOX:";
1838 if (_isComplexBox) {
1839 content += "TRUE\n";
1841 content += "COMPLEXBOXNAME:";
1842 content += GetCbName();
1845 content += "PACKAGENAME:";
1846 content += GetCbPackageName();
1849 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1850 * External inputs are possible for applications and complex boxes
1851 //Print info complex input ports
1852 std::vector<int> inputs = getComplexInputPorts();
1853 int insize = inputs.size();
1854 content += "COMPLEXINPUTS:";
1855 sprintf(buffer, "%d", insize);
1859 for (int i = 0; i < insize; i++) {
1861 GObjectController *cont = _controllers[id];
1862 cont->getModel()->save(content);
1866 //Print info complex output ports
1867 std::vector<int> outputs = getComplexOutputPorts();
1868 int outsize = outputs.size();
1869 content += "COMPLEXOUTPUTS:";
1870 sprintf(buffer, "%d", outsize);
1874 for (int i = 0; i < outsize; i++) {
1875 int id = outputs[i];
1876 GObjectController *cont = _controllers[id];
1877 cont->getModel()->save(content);
1881 content += "FALSE\n";
1884 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1885 // External inputs are possible for applications and complex boxes
1886 std::vector<int> inputs = getComplexInputPorts();
1887 int insize = inputs.size();
1888 content += "COMPLEXINPUTS:";
1889 sprintf(buffer, "%d", insize);
1893 for (int i = 0; i < insize; i++) {
1895 GObjectController *cont = _controllers[id];
1896 cont->getModel()->save(content);
1900 std::vector<int> boxes = getBlackBoxes();
1901 int bsize = boxes.size();
1902 content += "BOXES:";
1903 sprintf(buffer, "%d", bsize);
1907 for (int i = 0; i < bsize; i++) {
1909 // std::cout<<"id "<<id<<std::endl;//CFT
1910 GObjectController *cont = _controllers[id];
1911 // std::cout<<"nombre: "<<cont->getStatusText()<<std::endl;//CFT
1912 // std::cout<<"tipo: "<<cont->getModel()->getBBTKType()<<std::endl;//CFT
1913 // //boxesDiagram[i] = cont->getModel()->getBBTKType();//CFT
1914 // std::cout<<"nname: "<<cont->getModel()->getBBTKName()<<std::endl;//CFT
1915 // std::cout<<"categorie: "<<GetCategory()<<std::endl;//CFT
1916 // std::cout<<"type: "<<cont->getModel()->getGObjectType()<<std::endl;//CFT
1917 cont->getModel()->save(content);
1921 std::vector<int> connections = getConnections();
1922 int csize = connections.size();
1923 content += "CONNECTIONS:";
1924 sprintf(buffer, "%d", csize);
1928 for (int i = 0; i < csize; i++) {
1929 int id = connections[i];
1930 GObjectController *cont = _controllers[id];
1931 cont->getModel()->save(content);
1936 //=========================================================================
1937 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1939 getline(inputStream, line,'\n');
1940 int size = line.length();
1943 if ( line[ size-1 ]==13 )
1945 line.erase(size-1,1);
1950 //=========================================================================
1951 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1954 std::string version = "<void>";
1955 std::string line = "";
1956 char delims[] = ":";
1957 char *result = NULL;
1958 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1960 getCleanLine(inputStream, line);
1963 while (!inputStream.eof()) {
1964 if (line == "" || line[0] == '#') {
1966 getCleanLine(inputStream, line);
1968 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1969 version = line.substr(18, 3);
1971 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1972 version = line.substr(18, 3);
1974 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1975 version = line.substr(18, 3);
1977 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1978 version = line.substr(18, 3);
1980 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1981 version = line.substr(18, 3);
1983 } else if (line == "APP_START") {
1992 if ((version != "1.0") && (version != "1.1")) {
1993 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1994 char categoryTmp[30];
1995 strcpy(categoryTmp, line.c_str());
1996 result = strtok(categoryTmp, delims);
1997 result = strtok(NULL, delims);
1998 SetCategory(result);
2000 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
2001 char descriptionTmp[1024];
2002 strcpy(descriptionTmp, line.c_str());
2003 result = strtok(descriptionTmp, delims);
2004 result = strtok(NULL, delims);
2005 SetDescription(result);
2007 getCleanLine(inputStream, line);//AUTHOR:<author>
2008 char authorTmp[255];
2009 strcpy(authorTmp, line.c_str());
2010 result = strtok(authorTmp, delims);
2011 result = strtok(NULL, delims);
2016 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
2017 char complexTmp[30];
2018 strcpy(complexTmp, line.c_str());
2019 result = strtok(complexTmp, delims);
2020 result = strtok(NULL, delims);
2021 std::string isComplexBox(result);
2023 if (isComplexBox == "TRUE") {
2024 _isComplexBox = true;
2026 if ((version != "1.0") && (version != "1.1")) {
2027 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
2028 char complexboxnameTmp[255];
2029 strcpy(complexboxnameTmp, line.c_str());
2030 result = strtok(complexboxnameTmp, delims);
2031 result = strtok(NULL, delims);
2034 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
2035 char packagenameTmp[255];
2036 strcpy(packagenameTmp, line.c_str());
2037 result = strtok(packagenameTmp, delims);
2038 result = strtok(NULL, delims);
2039 SetCbPackageName(result);
2044 //-----------------------
2045 //- COMPLEX INPUT PORTS
2046 //-----------------------
2047 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2049 strcpy(inputs, line.c_str());
2050 result = strtok(inputs, delims);
2051 result = strtok(NULL, delims);
2054 std::istringstream inps(result);
2057 for (int i = 0; i < numInputs; i++) {
2059 getCleanLine(inputStream, line);//COMPLEX_PORT
2060 getCleanLine(inputStream, line);//name
2061 std::string inputPortName(line);
2064 getCleanLine(inputStream, line);//xInic:yInic:zInic
2066 strcpy(coord, line.c_str());
2067 result = strtok(coord, delims);//xInic
2068 std::string xInic(result);
2069 result = strtok(NULL, delims);//yInic
2070 std::string yInic(result);
2071 result = strtok(NULL, delims);//zInic
2072 std::string zInic(result);
2074 double xIn, yIn, zIn;
2075 std::istringstream xSt(xInic);
2077 std::istringstream ySt(yInic);
2079 std::istringstream zSt(zInic);
2084 if (zIn==900) zIn=GPOSITION_Z;
2087 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2089 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2091 } // for input complex box
2096 //-----------------------
2097 //- COMPLEX OUTPUT PORTS
2098 //-----------------------
2100 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2102 strcpy(outputs, line.c_str());
2103 result = strtok(outputs, delims);
2104 result = strtok(NULL, delims);
2107 std::istringstream outps(result);
2108 outps >> numOutputs;
2110 for (int i = 0; i < numOutputs; i++) {
2112 getCleanLine(inputStream, line);//COMPLEX_PORT
2113 getCleanLine(inputStream, line);//name
2114 std::string outputPortName(line);
2117 getCleanLine(inputStream, line);//xInic:yInic:zInic
2119 strcpy(coord, line.c_str());
2120 result = strtok(coord, delims);//xInic
2121 std::string xInic(result);
2122 result = strtok(NULL, delims);//yInic
2123 std::string yInic(result);
2124 result = strtok(NULL, delims);//zInic
2125 std::string zInic(result);
2127 double xIn, yIn, zIn;
2128 std::istringstream xSt(xInic);
2130 std::istringstream ySt(yInic);
2132 std::istringstream zSt(zInic);
2137 if (zIn==900) zIn=GPOSITION_Z;
2140 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2142 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2144 } // for output complex box
2148 // RaC2012 2nd Hackfest
2149 if(version >= "1.4")
2151 //-----------------------
2152 //- EXTERNAL INPUT PORTS
2153 //-----------------------
2154 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2156 strcpy(inputs, line.c_str());
2157 result = strtok(inputs, delims);
2158 result = strtok(NULL, delims);
2161 std::istringstream inps(result);
2164 for (int i = 0; i < numInputs; i++) {
2166 getCleanLine(inputStream, line);//COMPLEX_PORT
2167 getCleanLine(inputStream, line);//name
2168 std::string inputPortName(line);
2171 getCleanLine(inputStream, line);//xInic:yInic:zInic
2173 strcpy(coord, line.c_str());
2174 result = strtok(coord, delims);//xInic
2175 std::string xInic(result);
2176 result = strtok(NULL, delims);//yInic
2177 std::string yInic(result);
2178 result = strtok(NULL, delims);//zInic
2179 std::string zInic(result);
2181 double xIn, yIn, zIn;
2182 std::istringstream xSt(xInic);
2184 std::istringstream ySt(yInic);
2186 std::istringstream zSt(zInic);
2191 if (zIn==900) zIn=GPOSITION_Z;
2194 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2195 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2197 } // for external input
2202 getCleanLine(inputStream, line);//BOXES:num
2204 strcpy(boxes, line.c_str());
2205 result = strtok(boxes, delims);
2206 result = strtok(NULL, delims);
2209 std::istringstream is(result);
2212 for (int i = 0; i < numBoxes; i++)
2215 getCleanLine(inputStream, line);//BOX
2216 getCleanLine(inputStream, line);//package:type:name
2218 strcpy(box, line.c_str());
2219 result = strtok(box, delims);//package
2220 std::string package(result);
2221 result = strtok(NULL, delims);//type
2222 std::string type(result);
2223 result = strtok(NULL, delims);//name
2224 std::string name(result);
2227 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2229 strcpy(exec, line.c_str());
2230 result = strtok(exec, delims);//ISEXEC
2231 result = strtok(NULL, delims);//TRUE|FALSE
2232 std::string isExec(result);
2235 getCleanLine(inputStream, line);//xInic:yInic:zInic
2237 strcpy(coord, line.c_str());
2238 result = strtok(coord, delims);//xInic
2239 std::string xInic(result);
2240 result = strtok(NULL, delims);//yInic
2241 std::string yInic(result);
2242 result = strtok(NULL, delims);//zInic
2243 std::string zInic(result);
2245 double xIn, yIn, zIn;
2246 std::istringstream xSt(xInic);
2248 std::istringstream ySt(yInic);
2250 std::istringstream zSt(zInic);
2256 if (zIn==900) zIn=GPOSITION_Z;
2261 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2262 strcpy(coord, line.c_str());
2263 result = strtok(coord, delims);//xEnd
2264 std::string xEnd(result);
2265 result = strtok(NULL, delims);//yEnd
2266 std::string yEnd(result);
2267 result = strtok(NULL, delims);//zEnd
2268 std::string zEnd(result);
2270 double xEn, yEn, zEn;
2271 std::istringstream xEt(xEnd);
2273 std::istringstream yEt(yEnd);
2275 std::istringstream zEt(zEnd);
2280 if (zEn==900) zEn=GPOSITION_Z;
2284 bool boxExecutable = false;
2285 if (isExec == "TRUE")
2287 boxExecutable = true;
2290 int idBox = createGBlackBox(xIn, yIn, package, type);
2291 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2293 GObjectController *cont = _controllers[idBox];
2294 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2297 getCleanLine(inputStream, line);//PORT o FIN_BOX
2298 std::string port = line.substr(0, 4);
2299 while (port == "PORT")
2301 getCleanLine(inputStream, line);//name:value
2302 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2304 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2307 strcpy(poort, line.c_str());
2308 result = strtok(poort, delims);//name
2309 std::string name(result);
2311 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2312 result = strtok(NULL, delims);//value
2313 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2315 std::string tmpString=" ";
2316 tmpString[0]=34; // character "
2317 strcat(result,tmpString.c_str());
2319 std::string value(result);
2321 bbmod->setValueToInput(name, value);
2323 getCleanLine(inputStream, line);//PORT o FIN_BOX
2324 port = line.substr(0, 4);
2327 //EED bbmod->notifyObservers(_idManager);
2332 getCleanLine(inputStream, line);//CONNECTIONS:num
2334 strcpy(conns, line.c_str());
2335 result = strtok(conns, delims);
2336 result = strtok(NULL, delims);
2339 std::istringstream isCons(result);
2343 for (int i = 0; i < numConns; i++)
2346 getCleanLine(inputStream, line);//CONNECTION
2347 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2350 strcpy(connec, line.c_str());
2351 result = strtok(connec, delims);
2352 std::string nameStartBox(result);
2353 result = strtok(NULL, delims);
2354 std::string nameStartPort(result);
2355 result = strtok(NULL, delims);
2356 std::string nameEndBox(result);
2357 result = strtok(NULL, delims);
2358 std::string nameEndPort(result);
2360 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2362 if (version != "1.0") {
2363 //Readding control points of the manualContour
2364 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2365 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2366 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2367 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2368 strcpy(conns, line.c_str());
2369 result = strtok(conns, delims);
2370 result = strtok(NULL, delims);
2372 int numberOfControlPoints;
2373 std::istringstream isCons(result);
2374 isCons >> numberOfControlPoints;
2376 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2377 getCleanLine(inputStream, line); //XX:YY:ZZ
2379 strcpy(connec, line.c_str());
2382 result = strtok(connec, delims);
2383 std::istringstream isPointX(result);
2385 result = strtok(NULL, delims);
2386 std::istringstream isPointY(result);
2388 result = strtok(NULL, delims);
2389 std::istringstream isPointZ(result);
2394 if (pz==900) pz=GPOSITION_Z;
2397 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2398 conView->getManualContourView()->AddPoint();
2404 //=========================================================================
2407 //=========================================================================
2408 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2409 std::string portName, double xIn, double yIn, double zIn)
2412 if (inputoutput == true) {
2413 idPort = createGComplexBoxInputPort(portName);
2415 idPort = createGComplexBoxOutputPort(portName);
2417 GObjectController *cont = _controllers[idPort];
2418 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2419 cbmod->setInicPoint(xIn, yIn, zIn);
2420 cbmod->notifyObservers(_idManager);
2422 //=========================================================================
2425 //=========================================================================
2426 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2431 GBoxModel *boxModel = NULL;
2432 std::vector<int> lstB = getBlackBoxes();
2433 for (j = 0; j < (int) lstB.size(); j++) {
2435 bMod = (GBoxModel*) _controllers[idB]->getModel();
2436 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2444 if (boxModel == NULL) {
2445 std::vector<int> lstInputs = getComplexInputPorts();
2446 for (j = 0; j < (int) lstInputs.size(); j++) {
2448 bMod = (GBoxModel*) _controllers[idB]->getModel();
2449 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2457 std::vector<int> lstOutputs = getComplexOutputPorts();
2458 for (j = 0; j < (int) lstOutputs.size(); j++) {
2459 int idB = lstOutputs[j];
2460 bMod = (GBoxModel*) _controllers[idB]->getModel();
2461 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2473 //=========================================================================
2476 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2477 std::string nameStartPort, std::string nameEndBox,
2478 std::string nameEndPort) {
2480 GBoxModel *boxModel;
2481 GPortModel *startP = NULL;
2482 GPortModel *endP = NULL;
2484 boxModel = findGBox(nameStartBox);
2485 if(boxModel == NULL)
2487 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2489 if (boxModel != NULL) {
2490 startP = boxModel->getOutputPort(nameStartPort);
2492 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() );
2496 boxModel = findGBox(nameEndBox);
2497 if(boxModel == NULL)
2499 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2501 if (boxModel != NULL) {
2502 endP = boxModel->getInputPort(nameEndPort);
2504 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());
2509 int idCon = createGConnector(startP);
2511 _worldState = NOTHING_HAPPENS;
2512 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2514 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2515 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2516 tempp->endContourCreation();
2517 conMod->setEndPort(endP);
2518 conView->updateStartEndPoints();
2522 //=========================================================================
2524 bool wxVtkSceneManager::boxExist(std::string boxname) {
2526 std::map<int, GObjectController*>::iterator it;
2527 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2528 GObjectController *cont = it->second;
2529 if (cont->getModel()->getBBTKName() == boxname) {
2536 //=========================================================================
2538 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2539 std::vector<int> vect;
2540 std::map<int, GObjectController*>::iterator it;
2541 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2542 GObjectController *cont = it->second;
2543 if (cont->getGObjectType() == GBLACKBOX) {
2544 vect.push_back(cont->getId());
2550 //=========================================================================
2552 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2553 std::vector<int> vect;
2554 std::map<int, GObjectController*>::iterator it;
2555 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2556 GObjectController *cont = it->second;
2557 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2558 vect.push_back(cont->getId());
2564 //=========================================================================
2566 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2567 std::vector<int> vect;
2568 std::map<int, GObjectController*>::iterator it;
2569 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2570 GObjectController *cont = it->second;
2571 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2572 vect.push_back(cont->getId());
2578 //=========================================================================
2580 std::vector<int> wxVtkSceneManager::getConnections() {
2581 std::vector<int> vect;
2582 std::map<int, GObjectController*>::iterator it;
2583 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2584 GObjectController *cont = it->second;
2585 if (cont->getGObjectType() == GCONNECTOR) {
2586 vect.push_back(cont->getId());
2592 //=========================================================================
2594 bool wxVtkSceneManager::isComplexBox() {
2595 return _isComplexBox;
2598 //=========================================================================
2600 void wxVtkSceneManager::setComplexBox(bool val) {
2601 _isComplexBox = val;
2604 //=========================================================================
2606 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2607 //Register the controller of the new object
2608 registerController((InteractorStyleMaracas*) objController);
2609 //Add the object to the objects list
2610 int newId = _contLastId;//_controllers.size();
2611 objController->setId(newId);
2612 _controllers[newId] = objController;
2613 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2618 //=========================================================================
2620 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2622 std::map<int, int> oldIdNewIdBoxes;
2623 std::vector<int> connections;
2625 std::vector<int> newBoxesID;
2627 std::map<int, GObjectController*>::iterator it;
2628 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2629 GObjectController *cont = it->second;
2630 int type = cont->getGObjectType();
2632 if (type == GBLACKBOX) {
2634 double xInic, yInic, zInic;
2635 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2636 copyBox->getInicPoint(xInic, yInic, zInic);
2637 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2638 copyBox->getBBTKType());
2640 int idcB = copyBox->getObjectId();
2641 oldIdNewIdBoxes[idcB] = idBox;
2642 cont = _controllers[idBox];
2643 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2644 newbox->setInicPoint(xInic, yInic, zInic);
2645 int num = newbox->getNumInputPorts();
2646 for (int j = 0; j < num; j++) {
2647 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2649 newbox->move(xInic + 20, yInic + 20, zInic);
2650 newbox->notifyObservers(_idManager);
2651 newBoxesID.push_back(newbox->getObjectId());
2653 } else if (type == GCONNECTOR) {
2654 int idCon = cont->getId();
2655 connections.push_back(idCon);
2660 for (int i = 0; i < (int) connections.size(); i++) {
2661 int objId = connections[i];
2662 GObjectController *cont = objectsMap[objId];
2663 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2665 GPortModel* startPort = connectModel->getStartPort();
2666 int startPortIndex = startPort->getPosInBox();
2667 GPortModel* endPort = connectModel->getEndPort();
2668 int endPortIndex = endPort->getPosInBox();
2670 GBlackBoxModel* startPortParentBox =
2671 (GBlackBoxModel*) startPort->getParentBox();
2672 GBlackBoxModel* endPortParentBox =
2673 (GBlackBoxModel*) endPort->getParentBox();
2675 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2676 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2678 GBlackBoxModel* newStartBox =
2679 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2680 GBlackBoxModel* newEndBox =
2681 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2683 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2684 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2686 // Creates connection
2687 int idCon = createGConnector(newStartPort);
2688 GConnectorController *tempp =
2689 (GConnectorController*) _controllers[idCon];
2690 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2691 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2692 tempp->endContourCreation();
2693 conMod->setEndPort(newEndPort);
2694 conView->updateStartEndPoints();
2697 /// the new selected boxes are the duplicate ones
2699 UnSelectBlackBoxes();
2700 for (int i = 0; i < newBoxesID.size(); i++) {
2701 _selectedObjects.push_back(newBoxesID.at(i));
2704 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2705 int id = _selectedObjects[i];
2706 GObjectController* cont = _controllers[id];
2708 cont->getView()->setState(SELECTED);
2709 cont->getModel()->notifyObservers(_idManager);
2715 //=========================================================================
2717 int wxVtkSceneManager::getNumSelectedObjects() {
2718 return _selectedObjects.size();
2721 //=========================================================================
2723 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2724 std::map<int, GObjectController*> mapSelected;
2726 std::map<int, GObjectController*>::iterator it;
2727 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2728 GObjectController *cont = it->second;
2729 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2731 mapSelected[cont->getId()] = cont;
2735 std::map<int, GObjectController*>::iterator it2;
2736 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2737 GObjectController *cont = it2->second;
2738 if (cont->getGObjectType() == GCONNECTOR) {
2739 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2740 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2741 GBoxModel* startPortParentBox =
2742 cmod->getStartPort()->getParentBox();
2744 std::map<int, GObjectController*>::iterator iterOBJ1 =
2745 mapSelected.find(startPortParentBox->getObjectId());
2746 std::map<int, GObjectController*>::iterator iterOBJ2 =
2747 mapSelected.find(endPortParentBox->getObjectId());
2749 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2750 int ID = cont->getId();
2751 mapSelected[ID] = cont;
2758 //=========================================================================
2760 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2762 std::map<int, int> oldIdNewIdBoxes;
2763 std::vector<int> connections;
2765 std::map<int, GObjectController*>::iterator it;
2766 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2767 GObjectController *cont = it->second;
2768 int type = cont->getGObjectType();
2770 if (type == GBLACKBOX) {
2772 double xInic, yInic, zInic;
2773 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2774 copyBox->getInicPoint(xInic, yInic, zInic);
2775 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2777 int idcB = copyBox->getObjectId();
2778 oldIdNewIdBoxes[idcB] = idBox;
2779 cont = _controllers[idBox];
2780 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2781 newbox->setInicPoint(xInic, yInic, zInic);
2782 int num = newbox->getNumInputPorts();
2783 for (int j = 0; j < num; j++)
2785 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2787 newbox->notifyObservers(_idManager);
2788 } else if (type == GCONNECTOR) {
2789 int idCon = cont->getId();
2790 connections.push_back(idCon);
2795 for (int i = 0; i < (int) connections.size(); i++) {
2796 int objId = connections[i];
2797 GObjectController *cont = objectsMap[objId];
2798 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2800 GPortModel* startPort = connectModel->getStartPort();
2801 int startPortIndex = startPort->getPosInBox();
2802 GPortModel* endPort = connectModel->getEndPort();
2803 int endPortIndex = endPort->getPosInBox();
2805 GBlackBoxModel* startPortParentBox =
2806 (GBlackBoxModel*) startPort->getParentBox();
2807 GBlackBoxModel* endPortParentBox =
2808 (GBlackBoxModel*) endPort->getParentBox();
2810 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2811 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2813 GBlackBoxModel* newStartBox =
2814 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2815 GBlackBoxModel* newEndBox =
2816 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2818 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2819 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2821 // Creates connection
2822 int idCon = createGConnector(newStartPort);
2823 GConnectorController *tempp =
2824 (GConnectorController*) _controllers[idCon];
2825 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2826 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2827 tempp->endContourCreation();
2828 conMod->setEndPort(newEndPort);
2829 conView->updateStartEndPoints();
2832 std::map<int, int>::iterator itIds;
2833 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2834 int idOld = itIds->first;
2835 int idNew = itIds->second;
2837 GBlackBoxModel* oldBox =
2838 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2839 GBlackBoxModel* newBox =
2840 (GBlackBoxModel*) _controllers[idNew]->getModel();
2842 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2843 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2844 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2845 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2847 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2849 //EED int toCreate=-1;
2850 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2851 if (oldInputConnections[k] == newInputConnections[l]) {
2856 if (exist == false) {
2857 //Create complex input
2858 int posInBox = oldInputConnections[k];
2859 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2860 std::string inputPortName = inputPort->getBBTKName();
2861 int idInputPort = createGComplexBoxInputPort(inputPortName);
2862 GObjectController *cont = _controllers[idInputPort];
2863 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2864 double xIn, yIn, zIn;
2865 inputPort->getInicPoint(xIn, yIn, zIn);
2867 cbmod->setInicPoint(xIn, yIn, zIn);
2868 cbmod->notifyObservers(_idManager);
2870 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2872 // Creates connection
2873 int idCon = createGConnector(cbmod->getOutputPort(0));
2874 GConnectorController *tempp =
2875 (GConnectorController*) _controllers[idCon];
2876 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2877 vtkGConnectorView *conView =
2878 (vtkGConnectorView*) tempp->getView();
2879 tempp->endContourCreation();
2880 conMod->setEndPort(inputPortEnd);
2881 conView->updateStartEndPoints();
2887 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2889 //EED int toCreate=-1;
2890 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2891 if (oldOutputConnections[k] == newOutputConnections[l]) {
2896 if (exist == false) {
2897 //Create complex output
2898 int posInBox = oldOutputConnections[k];
2899 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2900 std::string outputPortName = outputPort->getBBTKName();
2901 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2902 GObjectController *cont = _controllers[idOutputPort];
2903 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2904 double xIn, yIn, zIn;
2905 outputPort->getInicPoint(xIn, yIn, zIn);
2907 cbmod->setInicPoint(xIn, yIn, zIn);
2908 cbmod->notifyObservers(_idManager);
2910 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2912 // Creates connection
2913 int idCon = createGConnector(outputPortEnd);
2914 GConnectorController *tempp =
2915 (GConnectorController*) _controllers[idCon];
2916 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2917 vtkGConnectorView *conView =
2918 (vtkGConnectorView*) tempp->getView();
2919 tempp->endContourCreation();
2920 conMod->setEndPort(cbmod->getInputPort(0));
2921 conView->updateStartEndPoints();
2931 //=========================================================================
2932 void wxVtkSceneManager::SetCbName(std::string cbName) {
2934 if (_cbName == "") {
2935 _cbName = "<complex box name>";
2939 //=========================================================================
2940 std::string wxVtkSceneManager::GetCbName() {
2944 //=========================================================================
2945 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2946 _cbPackageName = packagename;
2947 if (_cbPackageName == "") {
2948 _cbPackageName = "<package name of the complex box>";
2952 //=========================================================================
2953 std::string wxVtkSceneManager::GetCbPackageName() {
2954 return _cbPackageName;
2957 //=========================================================================
2958 void wxVtkSceneManager::SetAuthor(std::string author) {
2960 if (_Author == "") {
2961 _Author = "<author of the box>";
2965 //=========================================================================
2966 std::string wxVtkSceneManager::GetAuthor() {
2970 //=========================================================================
2971 void wxVtkSceneManager::SetCategory(std::string category) {
2972 _Category = category;
2973 if (_Category == "") {
2974 _Category = "<category of the box>";
2978 //=========================================================================
2979 std::string wxVtkSceneManager::GetCategory() {
2983 //=========================================================================
2984 void wxVtkSceneManager::SetDescription(std::string description) {
2985 _Description = description;
2986 if (_Description == "") {
2987 _Description = "<description of the box>";
2991 //=========================================================================
2992 std::string wxVtkSceneManager::GetDescription() {
2993 return _Description;
2996 //=========================================================================
2998 void wxVtkSceneManager::SetMessageKind(std::string kind) {
2999 _MessageKind = kind;
3003 //=========================================================================
3005 std::string wxVtkSceneManager::GetMessageKind(){
3006 return _MessageKind;
3009 //=========================================================================
3011 void wxVtkSceneManager::SetMessageLevel(std::string Level){
3012 _MessageLevel = Level;
3015 //=========================================================================
3017 std::string wxVtkSceneManager::GetMessageLevel(){
3018 return _MessageLevel;
3021 //=========================================================================
3023 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
3026 std::vector< std::string> extInputs;
3027 std::map<int, GObjectController*>::iterator it;
3028 for (it = _controllers.begin(); it != _controllers.end(); ++it)
3030 GObjectController *cont = it->second;
3031 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
3033 extInputs.push_back(cont->getModel()->getBBTKName());
3039 //=========================================================================
3043 void wxVtkSceneManager::printAll(int com , int sta ){
3045 int tmpState = sta ;
3046 if ( tmpState == NOTHING_HAPPENS ) {
3047 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
3049 if ( tmpState == HIGHLIGHTED ) {
3050 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
3052 if ( tmpState == POSSIBLE_CONNECTION ) {
3053 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
3055 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
3056 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
3058 if ( tmpState == CLICKED ) {
3059 std::cout << "CONTROLER STATE---->CLICKED\n" ;
3061 if ( tmpState == DRAG ) {
3062 std::cout << "CONTROLER STATE---->DRAG\n" ;
3064 if ( tmpState == SELECTED ) {
3065 std::cout << "CONTROLER STATE---->SELECTED\n" ;
3067 if ( tmpState == CREATING_CONTOUR ) {
3068 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
3074 if ( command == INIT_CREATION_CONTOUR ) {
3075 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
3077 if ( command == FIN_CREATION_CONTOUR ) {
3078 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
3080 if ( command == ADD_TO_SELECTED ) {
3081 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
3083 if ( command == DRAG_OBJECTS ) {
3084 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
3086 if ( command == EDIT_BLACKBOX ) {
3087 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
3089 if ( command == REMOVE_FROM_SELECTED ) {
3090 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
3096 } // EO namespace bbtk