1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::wxVtkSceneManager .
36 #include "wxVtkSceneManager.h"
38 #include <vtkPolygon.h>
39 #include <vtkUnstructuredGrid.h>
43 //=========================================================================
44 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent,
45 wxVtk3DBaseView *baseView, int idManager) {
46 _cbName = "ComplexBoxName";
47 _cbPackageName = "PackageName";
48 _Author = "Author ??";
50 _Description = "Description ??";
54 _idManager = idManager;
56 _startDragging = false;
57 _isComplexBox = false;
59 if (_baseView != NULL) {
62 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
65 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
69 _worldState = NOTHING_HAPPENS;
70 registerController(this);
73 _idConnectionInCreation = -1;
78 //=========================================================================
80 void wxVtkSceneManager::disconnectDrop() {
81 printf("EED %p ~wxVtkSceneManager::disconnectDrop()\n", this);
82 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
83 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
86 //=========================================================================
88 wxVtkSceneManager::~wxVtkSceneManager() {
90 printf("EED %p ~wxVtkSceneManager() START\n", this);
93 printf("EED %p ~wxVtkSceneManager() END\n", this);
96 //=========================================================================
98 void wxVtkSceneManager::configureBaseView() {
99 printf("EED wxVtkSceneManager::configureBaseView 0\n");
100 vtkInteractorStyleBaseView2D *interactorstylebaseview =
101 vtkInteractorStyleBaseView2D::New();
103 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
105 // Important to activate the 2D interaction system
106 wxVTKRenderWindowInteractor *iren =
107 _baseView->GetWxVTKRenderWindowInteractor();
108 interactorstylebaseview->SetInteractor(iren);
109 iren->SetInteractorStyle(interactorstylebaseview);
110 interactorstylebaseview->SetwxVtkBaseView(_baseView);
112 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
113 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, -1000, 1000);
114 _baseView->GetRenderer()->GetActiveCamera()->Zoom(10);
117 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
118 _baseView->GetRenderer()->GradientBackgroundOn();
121 _textActor = vtkTextActor3D::New();
122 _textActor->SetPosition(-9999, -9999, GPOSITION_Z);
123 _textActor->SetInput("<void>");
124 _textActor->GetTextProperty()->SetFontSize(60);
125 _textActor->GetTextProperty()->BoldOn();
126 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,
129 _baseView->GetRenderer()->AddActor(_textActor);
131 // Actor Fill_Port_Text
136 double zInic = GPOSITION_Z;
138 vtkPolygon *aPolygon = vtkPolygon::New();
139 _fillObjectActor = vtkActor::New();
141 _pts = vtkPoints::New();
143 double w = 100, h = 10, b = h / 15, t = 3;
144 _pts->SetNumberOfPoints(21);
145 _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
146 _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
147 _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
148 _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
149 _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
151 _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
152 _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
153 _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
154 _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
156 _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
157 _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
158 _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
159 _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
161 _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
162 _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
163 _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
164 _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
166 _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
167 _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
168 _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
169 _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
171 aPolygon->GetPointIds()->SetNumberOfIds(21);
172 for (int i = 0; i < 21; i++) {
173 aPolygon->GetPointIds()->SetId(i, i);
176 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
177 aPolygonGrid->Allocate(1, 1);
178 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),
179 aPolygon->GetPointIds());
180 aPolygonGrid->SetPoints(_pts);
181 _aPolygonMapper = vtkDataSetMapper::New();
182 _aPolygonMapper->SetInput(aPolygonGrid);
183 _fillObjectActor->SetMapper(_aPolygonMapper);
184 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
186 _fillObjectActor->GetProperty()->SetOpacity(0);
187 _aPolygonMapper->Modified();
189 _baseView->GetRenderer()->AddActor(_fillObjectActor);
190 printf("EED wxVtkSceneManager::configureBaseView 1\n");
193 //=========================================================================
195 std::string wxVtkSceneManager::generateANewNameForABox() {
196 std::stringstream boxname;
197 if (_numBoxes < 10) {
198 boxname << "Box0" << _numBoxes;
200 boxname << "Box" << _numBoxes;
203 return boxname.str();
206 //=========================================================================
208 std::string wxVtkSceneManager::findANewNameForABox() {
209 std::string boxname = generateANewNameForABox();
211 while (boxExist(boxname) == true) {
212 boxname = generateANewNameForABox();
218 //=========================================================================
219 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
220 double zIn, std::string name, bool boxExecutable, double xEn,
221 double yEn, double zEn) {
222 GObjectController *cont = _controllers[idBox];
223 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
224 bbmod->setBBTKName(name);
225 bbmod->setInicPoint(xIn, yIn, zIn);
226 bbmod->setFinalPoint(xEn, yEn, zEn);
227 bbmod->setExecutable(boxExecutable);
229 bbmod->notifyObservers(_idManager);
233 //=========================================================================
235 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,
236 std::string boxType) {
237 _worldState = NOTHING_HAPPENS;
238 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
239 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
241 int type = GBLACKBOX;
243 //Create the MVC Objects
247 (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
249 vtkGObjectView *view =
250 GObjectsMVCFactory::getInstance()->createGObjectView(type);
251 GObjectController* controller =
252 GObjectsMVCFactory::getInstance()->createGObjectController(type);
254 BlackBoxDescriptor::Pointer descriptor =
255 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
256 packageName, boxType);
257 if (descriptor == NULL){
258 printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
260 //Prepares the initial model
261 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
264 double yy = windowHeight - y;
266 //z value is not important yet, because it is only used a parallel projection
267 double zz = GPOSITION_Z;
268 _baseView->TransCoordScreenToWorld(xx, yy, zz);
269 model->setInicPoint(xx, yy, zz);
271 std::stringstream stream;
273 std::string newBoxName;
274 newBoxName = findANewNameForABox();
276 stream << newBoxName;
278 std::string arraystring = stream.str();
280 model->setBBTKName(arraystring);
281 model->setBBTKType(boxType);
282 model->setBBTKPackage(packageName);
284 model->addObserver(view);
285 model->addObserver(this);
287 //Iterate and create the input ports
288 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
289 descriptor->GetInputDescriptorMap();
290 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
293 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) {
294 BlackBoxInputDescriptor *desc = itInput->second;
295 createGInputPort(GINPUTPORT, i, model, desc);
299 //Iterate and create the output ports
300 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
301 descriptor->GetOutputDescriptorMap();
302 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
305 for (itOutput = descriptorOutMap.begin(); itOutput
306 != descriptorOutMap.end(); ++itOutput) {
307 BlackBoxOutputDescriptor *desc = itOutput->second;
308 createGOutputPort(GOUTPUTPORT, i, model, desc);
312 //Associates the view with the correspondent renderer and the model.
313 //(NOTE: Refresh is only made by the view)
314 view->setModel(model);
315 view->setBaseView(_baseView);
316 view->initVtkObjects();
318 //Associates the controller with the correspondent model and view
319 controller->setModelAndView(model, view);
321 //Resgiter change to the observers of the actual model
322 model->notifyObservers(_idManager);
324 int newId = addObjectController(controller);
330 //=========================================================================
332 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
333 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
334 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
336 int type = GCOMPLEXINPUTPORT;
338 //Create the MVC Objects
342 (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
344 vtkGObjectView *view =
345 GObjectsMVCFactory::getInstance()->createGObjectView(type);
346 GObjectController* controller =
347 GObjectsMVCFactory::getInstance()->createGObjectController(type);
349 //Prepares the initial model
352 double yy = windowHeight - 5;
354 //z value is not important yet, because it is only used a parallel projection
355 double zz = GPOSITION_Z;
357 _baseView->TransCoordScreenToWorld(xx, yy, zz);
358 model->setInicPoint(xx, yy, zz);
360 model->setBBTKName(inputName);
361 model->setBBTKType("ComplexInputPort");
362 model->setComplexPortType(type);
364 model->addObserver(view);
365 model->addObserver(this);
367 //create the output port
368 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
369 "ComplexOutputPortType","ComplexOutputPortDescriopton", 0, model);
370 model->addOutputPort((GPortModel*) portController->getModel());
372 //Associates the view with the correspondent renderer and the model.
373 //(NOTE: Refresh is only made by the view)
374 view->setModel(model);
375 view->setBaseView(_baseView);
376 view->initVtkObjects();
378 //Associates the controller with the correspondent model and view
379 controller->setModelAndView(model, view);
381 //Resgiter change to the observers of the actual model
382 model->notifyObservers(_idManager);
384 int newId = addObjectController(controller);
388 //=========================================================================
390 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
391 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
392 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
394 int type = GCOMPLEXOUTPUTPORT;
396 //Create the MVC Objects
400 (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
402 vtkGObjectView *view =
403 GObjectsMVCFactory::getInstance()->createGObjectView(type);
404 GObjectController *controller =
405 GObjectsMVCFactory::getInstance()->createGObjectController(type);
407 //Prepares the initial model
410 double yy = windowHeight - 5;
412 //z value is not important yet, because it is only used a parallel projection
413 double zz = GPOSITION_Z;
415 _baseView->TransCoordScreenToWorld(xx, yy, zz);
416 model->setInicPoint(xx, yy, zz);
418 model->setBBTKName(outputName);
419 model->setBBTKType("ComplexOutputPort");
420 model->setComplexPortType(type);
422 model->addObserver(view);
423 model->addObserver(this);
425 //create the output port
426 GPortController* portController = createGPort(GINPUTPORT, outputName,
427 "ComplexInputPort","ComplexInputPortDescription", 0, model);
428 model->addInputPort((GPortModel*) portController->getModel());
430 //Associates the view with the correspondent renderer and the model.
431 //(NOTE: Refresh is only made by the view)
432 view->setModel(model);
433 view->setBaseView(_baseView);
434 view->initVtkObjects();
436 //Associates the controller with the correspondent model and view
437 controller->setModelAndView(model, view);
439 //Resgiter change to the observers of the actual model
440 model->notifyObservers(_idManager);
442 int newId = addObjectController(controller);
446 //=========================================================================
448 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,
449 GBoxModel *blackBox, BlackBoxInputDescriptor *desc) {
450 GPortController* portController = createGPort(portType, desc->GetName(),
451 desc->GetTypeName(), desc->GetDescription(), posinBox, blackBox);
452 blackBox->addInputPort((GPortModel*) portController->getModel());
453 return portController->getId();
456 //=========================================================================
458 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,
459 GBoxModel *blackBox, BlackBoxOutputDescriptor *desc) {
460 GPortController* portController = createGPort(portType, desc->GetName(),
461 desc->GetTypeName(),desc->GetDescription(), posinBox, blackBox);
462 blackBox->addOutputPort((GPortModel*) portController->getModel());
463 return portController->getId();
466 //=========================================================================
468 GPortController* wxVtkSceneManager::createGPort(int portType,
469 std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posInBox,
470 GBoxModel *blackBox) {
473 //Create the MVC Objects
476 (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
478 vtkGObjectView *view =
479 GObjectsMVCFactory::getInstance()->createGObjectView(type);
480 GObjectController* controller =
481 GObjectsMVCFactory::getInstance()->createGObjectController(type);
483 model->registerInBox(blackBox, portType, posInBox);
485 model->setBBTKType(bbtkType);
486 model->setBBTKName(bbtkName);
487 model->setBBTKDescription(bbtkDescription);
489 model->addObserver(view);
490 model->addObserver(this);
492 //Associates the view with the correspondent renderer and the model.
493 //(NOTE: Refresh is only made by the view)
494 view->setModel(model);
495 view->setBaseView(_baseView);
496 view->initVtkObjects();
498 //Associates the controller with the correspondent model and view
499 controller->setModelAndView(model, view);
501 model->notifyObservers(_idManager);
503 addObjectController(controller);
505 return (GPortController*) controller;
508 //=========================================================================
510 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
515 int type = GCONNECTOR;
517 manualConnectorContourController *manContourControl = new manualConnectorContourController();
518 manualConnectorContourView *manContourView = new manualConnectorContourView();
519 manualContourModel *manContourModel = new manualContourModel();
520 GConnectorController *connectorcontroller = new GConnectorController();
521 GConnectorModel *connectorModel = new GConnectorModel();
522 vtkGConnectorView *connectorView = new vtkGConnectorView();
523 connectorModel->setGObjectType(type);
525 manContourModel->SetCloseContour(false);
526 connectorModel->setStartPort(startPort);
528 manContourView->SetModel(manContourModel);
529 manContourView->SetWxVtkBaseView(_baseView);
530 manContourView->SetRange(0.5);
531 manContourView->SetZ(GPOSITION_Z);
533 manContourView->SetColorNormalContour(0, 0, 1);
534 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
535 manContourView->SetColorSelectContour(1, 0.8, 0);
541 * Width increased from 2 to 3, it simplifies line handling and spline control :P
544 manContourView->SetWidthLine( 3 ) ;
545 manContourView->SetShowText(false);
547 manContourControl->SetModelView(manContourModel, manContourView);
549 manContourControl->CreateNewManualContour();
553 connectorModel->getInicPoint(x, y, z);
556 manContourControl->SetState(1);
557 manContourModel->SetCloseContour(false);
559 manContourModel->AddPoint(x, y, z);
560 manContourView->AddPoint();
562 manContourModel->AddPoint(x, y, z);
563 manContourView->AddPoint();
565 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
566 manContourControl->_bakIdPoint = bak;
568 manContourControl->SetMoving(false);
570 connectorcontroller->setModelAndView(connectorModel, connectorView);
572 int newId = addObjectController(connectorcontroller);
574 connectorcontroller->setManualContourController(manContourControl);
575 connectorModel->setManualContourModel(manContourModel);
576 connectorView->setManualContourView(manContourView);
577 connectorView->setModel(connectorModel);
578 connectorView->setBaseView(_baseView);
580 connectorModel->addObserver(connectorView);
581 connectorModel->addObserver(this);
583 // manContourView->Refresh();
588 //=========================================================================
590 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param) {
591 vtkInteractorStyleBaseView
592 * baseViewControlManager =
593 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
594 baseViewControlManager->AddInteractorStyleMaracas(param);
597 //=========================================================================
599 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param) {
600 vtkInteractorStyleBaseView
601 * baseViewControlManager =
602 (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
603 baseViewControlManager->RemoveInteractorStyleMaracas(param);
606 //=========================================================================
608 vtkRenderer* wxVtkSceneManager::getRenderer() {
609 return _baseView->GetRenderer();
612 //=========================================================================
614 vtkRenderWindow* wxVtkSceneManager::getRenderWindow() {
615 return _baseView->GetRenWin();
617 //=========================================================================
620 //=========================================================================
621 int wxVtkSceneManager::GetIndexInSelected(int idControler) {
623 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
624 if (_selectedObjects[i] == idControler) {
631 //=========================================================================
633 void wxVtkSceneManager::update(int idController, int command) {
635 if (command != NO_COMMAND) {
636 if (command == ADD_TO_SELECTED) {
637 if (GetIndexInSelected(idController) == -1) {
638 _selectedObjects.push_back(idController);
640 } else if (command == REMOVE_FROM_SELECTED) {
641 int index = GetIndexInSelected(idController);
643 _selectedObjects.erase(_selectedObjects.begin() + index);
645 } else if (command == INIT_CREATION_CONTOUR) {
648 typedef std::map<int , GObjectController*>::iterator TIterator ;
651 // Find current item in the controller
652 iter = _controllers.find( idController ) ;
653 iter_end = _controllers.end( ) ;
655 if ( iter != iter_end ) {
656 GObjectController* gobjc = iter->second ;
658 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
659 // And if the item is a port
660 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
661 TIterator c_it = _controllers.begin( ) ;
662 // Go through all componets
663 for ( c_it ; c_it != iter_end ; c_it++ ) {
664 GObjectController* obc = c_it->second ;
665 int obc_type = obc->getModel( )->getGObjectType( ) ;
666 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
667 // if the component is a port and the type is the same of that selected
668 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
670 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
671 //obc->getView( )->setState( HIGHLIGHTED ) ;
679 _worldState = INIT_CREATION_CONTOUR;
680 GObjectController* cont = _controllers[idController];
681 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
683 // The last one is the controller of the connector
684 std::map<int, GObjectController*>::iterator it2;
687 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
688 GObjectController *cont = it2->second;
689 if (cont->getGObjectType() == GPORT) {
690 GPortModel* port = (GPortModel*) cont->getModel();
691 if (port->getPortType() == GINPUTPORT) {
692 cont->SetActive(true);
694 cont->getView()->setState(NOTHING_HAPPENS);
695 cont->getModel()->notifyObservers(_idManager);
696 cont->SetActive(false);
699 cont->getView()->setState(NOTHING_HAPPENS);
700 cont->getModel()->notifyObservers(_idManager);
701 cont->SetActive(false);
704 _selectedObjects.clear();
705 _idConnectionInCreation = createGConnector(startOutputPort);
706 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
707 _worldState = NOTHING_HAPPENS;
708 //int id = _controllers.size()-1;
709 GObjectController *cont = _controllers[_idConnectionInCreation];
710 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
711 GObjectController *finPort = _controllers[idController];
713 if (finPort->getGObjectType() == GPORT) {
714 GPortModel* modelPort = (GPortModel*) finPort->getModel();
715 modelContour->setEndPort(modelPort);
718 typedef std::map<int, GObjectController*>::iterator TIterator;
719 TIterator c_it = _controllers.begin();
720 TIterator iter_end = _controllers.end();
721 // Go through all componets
722 for (c_it; c_it != iter_end; c_it++) {
723 GObjectController* obc = c_it->second;
724 int obc_type = obc->getModel()->getGObjectType();
725 int obc_state = obc->getView()->getState();
726 // if the component is a port and the type is the same of that selected
727 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
728 // Return element to neutral state if not selected
729 obc->getView()->setState(NOTHING_HAPPENS);
731 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
732 // Change element to connected state
733 obc->getView()->setState(HIGHLIGHTED);
740 _parent->saveTempandUpdate("create connection");
743 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
744 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
746 std::map<int, GObjectController*>::iterator it2;
748 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
749 GObjectController *cont = it2->second;
750 if (cont->getView() != NULL) {
751 cont->getView()->setState(NOTHING_HAPPENS);
752 cont->getModel()->notifyObservers(_idManager);
754 cont->SetActive(true);
763 //=========================================================================
765 bool wxVtkSceneManager::OnMouseMove()
768 bool okStatusMessage = false;
769 bool okPortMessage = false;
770 wxVTKRenderWindowInteractor *wxVTKiren;
771 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
772 wxVTKiren->GetEventPosition(X, Y);
774 if (_worldState == DRAG_OBJECTS) {
775 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
776 int id = _selectedObjects[i];
777 GObjectController* cont = _controllers[id];
778 if (_startDragging) {
779 cont->getView()->setStartDragging(true);
781 cont->getView()->moveObject(X, Y);
782 cont->getView()->setState(DRAG);
783 cont->getModel()->notifyObservers(_idManager);
786 std::map<int, GObjectController*>::iterator it;
788 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
789 GObjectController *desc = it->second;
790 if (desc->getGObjectType() == GCONNECTOR) {
791 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
792 vconn->updateStartEndPoints();
796 _startDragging = false;
798 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
799 std::map<int, GObjectController*>::iterator it;
801 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
802 GObjectController *desc = it->second;
803 int type = desc->getGObjectType();
804 int state = desc->getView()->getState();
805 desc->getModel()->getCenter(px, py, pz);
808 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
811 okStatusMessage = true;
812 updateStatusBar(desc->getStatusText());
813 if (type == GBLACKBOX)
815 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
816 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
821 okPortMessage = true;
823 _textActor->SetInput(desc->getStatusText().c_str());
824 _textActor->SetScale(0.1);
825 _textActor->SetPosition(px - 25, py + 1, pz + 2);
830 _fillObjectActor->SetScale(1);
831 _fillObjectActor->GetProperty()->SetOpacity(0.50);
832 _fillObjectActor->SetPosition(px, py, 1);
833 _aPolygonMapper->Modified();
836 } // for controllers it
839 if (okStatusMessage == false)
844 if (okPortMessage == false)
846 _textActor->SetScale(0.0001);
847 _fillObjectActor->SetScale(0.0001);
852 //=========================================================================
854 bool wxVtkSceneManager::OnLeftButtonDown()
856 if (_worldState == INIT_CREATION_CONTOUR)
858 bool isOverPort = false;
859 std::map<int, GObjectController*>::iterator it;
860 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
862 GObjectController *desc = it->second;
863 if (desc->getGObjectType() == GPORT)
865 GPortModel *portmod = (GPortModel*) desc->getModel();
866 vtkGObjectView *portView = desc->getView();
867 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
872 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
874 portView->setState( HIGHLIGHTED);
881 if (isOverPort == false)
884 UnSelectBlackBoxes();
888 } else { //_worldState
890 _worldState = DRAG_OBJECTS;
891 _startDragging = true;
893 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
894 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
895 ctrlkey = ctrlkey + shiftkey;
897 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
900 int state = cont->getView()->getState();
901 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
902 UnSelectBlackBoxes();
905 UnSelectBlackBoxes(); // EED 12/07/2012
907 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
908 int id = _selectedObjects[i];
909 GObjectController *cont = _controllers[id];
910 cont->getView()->setState(DRAG);
911 cont->getModel()->notifyObservers(_idManager);
913 } // if _selectedObjects.size
919 //=========================================================================
921 bool wxVtkSceneManager::OnLeftButtonUp()
923 if (_worldState == DRAG_OBJECTS) {
924 _worldState = NOTHING_HAPPENS;
926 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
927 int id = _selectedObjects[i];
928 GObjectController* cont = _controllers[id];
929 cont->getView()->setState(SELECTED);
930 cont->getModel()->notifyObservers(_idManager);
936 //=========================================================================
937 void wxVtkSceneManager::CancelConnection()
939 if (_worldState == INIT_CREATION_CONTOUR)
941 _worldState = NOTHING_HAPPENS;
942 //int lastId = _controllers.size()-1;
944 GConnectorController *connector =
945 (GConnectorController*) _controllers[_idConnectionInCreation];
946 connector->removeFromScene();
947 unregisterController(connector);
948 _controllers.erase(_idConnectionInCreation);
950 std::map<int, GObjectController*>::iterator it;
951 for (it = _controllers.begin(); it != _controllers.end(); ++it)
953 GObjectController *desc = it->second;
954 desc->SetActive(true);
955 desc->getView()->setState(NOTHING_HAPPENS);
956 desc->getModel()->notifyObservers(_idManager);
961 //=========================================================================
963 bool wxVtkSceneManager::OnRightButtonUp()
965 if (_worldState == INIT_CREATION_CONTOUR)
969 UnSelectBlackBoxes();
975 bool wxVtkSceneManager::OnMiddleButtonDown() {
978 this->_vtkInteractorStyleBaseView->StartPan();
983 bool wxVtkSceneManager::OnMiddleButtonUp() {
986 this->_vtkInteractorStyleBaseView->EndPan();
993 //=========================================================================
995 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
996 GObjectController *result = NULL;
998 wxVTKRenderWindowInteractor *wxVTKiren;
1000 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1001 wxVTKiren->GetEventPosition(X, Y);
1003 std::map<int, GObjectController*>::iterator it;
1005 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1006 GObjectController *cont = it->second;
1007 int type = cont->getGObjectType();
1009 if (cont->getView()->isPointInside(X, Y) == true) {
1010 if (type == GBLACKBOX) {
1013 } // if isPointInside
1018 //=========================================================================
1019 void wxVtkSceneManager::UnSelectBlackBoxes() {
1020 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1021 int id = _selectedObjects[i];
1022 GObjectController* control = _controllers[id];
1023 control->getView()->setState(NOTHING_HAPPENS);
1024 control->getModel()->notifyObservers(_idManager);
1025 }// for _selectedObjects
1026 _selectedObjects.clear();
1029 //=========================================================================
1030 bool wxVtkSceneManager::OnLeftDClick() {
1031 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1033 UnSelectBlackBoxes();
1034 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1040 wxVTKRenderWindowInteractor *wxVTKiren;
1041 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1042 wxVTKiren->GetEventPosition(X,Y);
1044 std::map<int, GObjectController*>::iterator it;
1046 bool clickOnObject = false;
1048 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1050 GObjectController *cont = it->second;
1051 int type = cont->getGObjectType();
1053 if(cont->getView()->isPointInside(X,Y))
1057 for (int i=0; i< (int)_selectedObjects.size(); i++)
1059 int id = _selectedObjects[i];
1060 GObjectController* control = _controllers[id];
1061 control->getView()->setState(NOTHING_HAPPENS);
1063 _selectedObjects.clear();
1065 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1066 _parent->editBlackBox(bbmodel);
1068 clickOnObject = true;
1072 if(clickOnObject==false)
1074 //_parent->editDiagramParameters(this);
1080 //=========================================================================
1082 bool wxVtkSceneManager::OnChar()
1086 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1087 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1089 // KeyCode 127 : Delete Key
1090 // KeyCode 8 : Backspace Key
1093 if (keyCode == 8 || keyCode == 127 || keyCode == 27)
1095 if (_worldState == INIT_CREATION_CONTOUR)
1098 UnSelectBlackBoxes();
1103 if (keyCode == 8 || keyCode == 127)
1106 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1108 int id = _selectedObjects[i];
1109 std::map<int, GObjectController*>::iterator it;
1110 it = _controllers.find(id);
1111 if (it != _controllers.end())
1113 oktmp = deleteObject(id);
1116 }// for selected objects
1117 if (ok) _selectedObjects.clear();
1118 _parent->saveTempandUpdate("delete object");
1123 if((keyCode==0) && (ctrlkey==1)) {
1128 if(_selectedObjects.size()){
1129 std::cout<<"objects to copy :";
1130 for(int i=0;i<_selectedObjects.size();i++)
1132 std::cout<<_selectedObjects.at(i)<<" ";
1134 DuplicateObjects(getSelectedObjects());
1136 std::cout<<"No objects to copy\n";
1137 } // _selectedObjects.size
1143 //=========================================================================
1145 void wxVtkSceneManager::AddControlerToBeRemove(
1146 std::vector<int> *controllersToRemove, int id) {
1150 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1151 if (id == (*controllersToRemove)[i]) {
1157 controllersToRemove->push_back(id);
1162 //=========================================================================
1164 bool wxVtkSceneManager::deleteObject(int id)
1167 GObjectController *control = _controllers[id];
1168 std::vector<int> controllersToRemove;
1169 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1170 == GCOMPLEXINPUTPORT || control->getGObjectType()
1171 == GCOMPLEXOUTPUTPORT) {
1172 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1173 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1175 bool boxConnected = false;
1177 // Add box input controllers to be removed
1178 for (int i = 0; i < (int) inputs.size(); i++) {
1179 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1180 if (inputs[i]->isConnected()) {
1181 boxConnected = true;
1185 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1187 // Add box output controllers to be removed
1188 for (int i = 0; i < (int) outputs.size(); i++) {
1189 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1190 if (outputs[i]->isConnected()) {
1191 boxConnected = true;
1195 // Add connection controllers to be removed
1196 std::map<int, GObjectController*>::iterator it;
1197 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1198 GObjectController *cont = it->second;
1199 int type = cont->getGObjectType();
1200 if (type == GCONNECTOR) {
1201 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1202 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1204 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1206 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1208 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1213 // Add box controller to be removed
1214 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1215 } else if (control->getGObjectType() == GCONNECTOR) {
1216 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1217 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1219 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1220 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1222 gconnectorcontroler->getManualContourController()->OnChar();
1227 std::map<int, GObjectController*>::iterator it;
1229 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1230 int key = controllersToRemove[i];
1231 it = _controllers.find(key);
1232 GObjectController *cont = _controllers[key];
1234 cont->removeFromScene();
1235 unregisterController((InteractorStyleMaracas*) cont);
1236 _controllers.erase(it);
1244 //=========================================================================
1246 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1247 std::string boxName) {
1248 _parent->displayBlackBoxInfo(packageName, boxName);
1251 //=========================================================================
1253 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1254 _parent->updateStatusBar(textStatus);
1257 //=========================================================================
1258 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1259 std::string result = "";
1260 if (withLineNumber == true) {
1262 stringstream StrStream;
1264 std::string strValue = StrStream.str();
1267 } else if (value < 100) {
1271 result += strValue + ": ";
1275 //=========================================================================
1277 bool wxVtkSceneManager::MakeBoxExecutable() {
1278 std::map<int, GObjectController*> selected = getSelectedObjects();
1279 if( selected.empty() )
1282 std::map<int, GObjectController*>::iterator it;
1283 for (it = selected.begin(); it != selected.end(); ++it) {
1284 GObjectController* lastSelected = it->second;
1286 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1287 GBlackBoxModel *bbmodel =
1288 (GBlackBoxModel*) lastSelected->getModel();
1289 view->setState(HIGHLIGHTED);
1290 if (bbmodel->isExecutable()) {
1291 bbmodel->setExecutable(false);
1293 bbmodel->setExecutable(true);
1295 bbmodel->notifyObservers(lastSelected->getId());
1303 //=========================================================================
1305 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1306 bool existsExec = false;
1308 std::vector<std::string> packages;
1309 std::vector<int> boxes;
1310 std::vector<int> connections;
1311 std::vector<int> execBoxes;
1313 std::map<int, GObjectController*>::iterator it;
1315 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1316 GObjectController *desc = it->second;
1317 int type = desc->getGObjectType();
1319 if (type == GBLACKBOX) {
1320 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1322 std::string pkg = mod->getBBTKPackage();
1323 bool existsPkg = false;
1324 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1325 if (packages[t] == pkg) {
1330 packages.push_back(pkg);
1333 boxes.push_back(it->first);
1334 if (mod->isExecutable()) {
1335 execBoxes.push_back(it->first);
1338 } else if (type == GCONNECTOR) {
1339 connections.push_back(it->first);
1344 std::string script = "";
1345 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1346 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1347 script += LineNumber(wln, lnNmbr) + "\n";
1349 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1350 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1352 for (i = 0; i < (int) packages.size(); i++) {
1353 script += LineNumber(wln, lnNmbr);
1354 script += "include ";
1355 script += packages[i];
1359 script += LineNumber(wln, lnNmbr);
1364 script += LineNumber(wln, lnNmbr);
1365 script += "author \"";
1369 script += LineNumber(wln, lnNmbr);
1370 script += "description \"";
1371 script += _Description;
1374 script += LineNumber(wln, lnNmbr);
1375 script += "category \"";
1376 script += _Category;
1379 script += LineNumber(wln, lnNmbr);
1382 // script+="include std\n"; // JPR
1384 for (i = 0; i < (int) boxes.size(); i++) {
1385 script += LineNumber(wln, lnNmbr);
1388 GObjectController *control = _controllers[id];
1389 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1391 script += model->getBBTKType();
1393 script += model->getBBTKName();
1396 std::vector<GPortModel*> inputs = model->getInputPorts();
1397 for (int j = 0; j < (int) inputs.size(); j++) {
1398 GPortModel* inputPort = inputs[j];
1399 if (inputPort->isValueSet()) {
1400 script += LineNumber(wln, lnNmbr);
1402 script += model->getBBTKName();
1404 script += inputPort->getBBTKName();
1406 script += inputPort->getValue();
1411 script += LineNumber(wln, lnNmbr);
1416 script += LineNumber(wln, lnNmbr);
1420 std::string complexInputs="";
1422 for (i = 0; i < (int) connections.size(); i++) {
1423 //script += LineNumber(wln, lnNmbr);
1424 //script += "connect ";
1425 int id = connections[i];
1426 GObjectController *control = _controllers[id];
1427 GConnectorModel *model = (GConnectorModel*) control->getModel();
1431 GPortModel *start = model->getStartPort();
1432 GBoxModel *startBox = start->getParentBox();
1434 GPortModel *end = model->getEndPort();
1435 GBoxModel *endBox = end->getParentBox();
1437 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1439 complexInputs += "input ";
1440 complexInputs += startBox->getBBTKName();
1442 complexInputs += " ";
1443 complexInputs += endBox->getBBTKName();
1444 complexInputs += ".";
1445 complexInputs += end->getBBTKName();
1447 complexInputs += " ";
1448 complexInputs += "\" \"";
1450 complexInputs += "\n";
1454 script += "connect ";
1455 script += startBox->getBBTKName();
1457 script += start->getBBTKName();
1461 //End Connection info
1462 script += endBox->getBBTKName();
1464 script += end->getBBTKName();
1472 script += LineNumber(wln, lnNmbr);
1476 script += "# Complex input ports\n";
1477 script += complexInputs;
1479 for (i = 0; i < (int) execBoxes.size(); i++) {
1480 script += LineNumber(wln, lnNmbr);
1482 int id = execBoxes[i];
1483 GObjectController *control = _controllers[id];
1484 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1486 script += model->getBBTKName();
1495 //=========================================================================
1497 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1498 std::vector<std::string> packages;
1499 std::vector<int> boxes;
1500 std::vector<int> connections;
1501 std::vector<int> execBoxes;
1503 std::map<int, GObjectController*>::iterator it;
1505 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1506 GObjectController *desc = it->second;
1507 int type = desc->getGObjectType();
1509 if (type == GBLACKBOX) {
1510 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1512 std::string pkg = mod->getBBTKPackage();
1513 bool existsPkg = false;
1514 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1515 if (packages[t] == pkg) {
1520 packages.push_back(pkg);
1523 boxes.push_back(it->first);
1524 if (mod->isExecutable()) {
1525 execBoxes.push_back(it->first);
1527 } else if (type == GCONNECTOR) {
1528 connections.push_back(it->first);
1532 std::string script = "";
1534 script += "include std\n"; // EED
1535 script += "include itkvtk\n"; // EED
1537 for (i = 0; i < (int) packages.size(); i++) {
1538 script += "include ";
1539 script += packages[i];
1544 // Definition of a complex box
1545 script += "define ";
1546 script += _cbName + " " + _cbPackageName;
1550 script += "author \"";
1554 script += "description \"";
1555 script += _Description;
1559 script += "category \"";
1560 script += _Category;
1565 for (i = 0; i < (int) boxes.size(); i++) {
1568 GObjectController *control = _controllers[id];
1569 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1571 script += model->getBBTKType();
1573 script += model->getBBTKName();
1576 std::vector<GPortModel*> inputs = model->getInputPorts();
1577 for (int j = 0; j < (int) inputs.size(); j++) {
1578 GPortModel* inputPort = inputs[j];
1579 if (inputPort->isValueSet()) {
1581 script += model->getBBTKName();
1583 script += inputPort->getBBTKName();
1585 script += inputPort->getValue();
1593 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1595 std::string complexInputs = "";
1596 std::string complexOutputs = "";
1599 for (i = 0; i < (int) connections.size(); i++) {
1600 int id = connections[i];
1601 GObjectController *control = _controllers[id];
1602 GConnectorModel *model = (GConnectorModel*) control->getModel();
1605 GPortModel *start = model->getStartPort();
1606 GBoxModel *startBox = start->getParentBox();
1608 GPortModel *end = model->getEndPort();
1609 GBoxModel *endBox = end->getParentBox();
1611 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1612 complexInputs += "input ";
1613 complexInputs += startBox->getBBTKName();
1615 complexInputs += " ";
1616 complexInputs += endBox->getBBTKName();
1617 complexInputs += ".";
1618 complexInputs += end->getBBTKName();
1620 complexInputs += " ";
1621 complexInputs += "\" \"";
1623 complexInputs += "\n";
1624 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1625 complexOutputs += "output ";
1626 complexOutputs += endBox->getBBTKName();
1628 complexOutputs += " ";
1629 complexOutputs += startBox->getBBTKName();
1630 complexOutputs += ".";
1631 complexOutputs += start->getBBTKName();
1633 complexOutputs += " ";
1634 complexOutputs += "\" \"";
1636 complexOutputs += "\n";
1638 script += "connect ";
1639 script += startBox->getBBTKName();
1641 script += start->getBBTKName();
1645 //End Connection info
1646 script += endBox->getBBTKName();
1648 script += end->getBBTKName();
1655 script += "# Complex input ports\n";
1656 script += complexInputs;
1659 script += "# Complex output ports\n";
1660 script += complexOutputs;
1664 for (i = 0; i < (int) execBoxes.size(); i++) {
1666 int id = execBoxes[i];
1667 GObjectController *control = _controllers[id];
1668 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1670 script += model->getBBTKName();
1675 script += "endefine";
1681 //=========================================================================
1683 void wxVtkSceneManager::deleteAllBoxes() {
1684 std::map<int, GObjectController*>::iterator it;
1685 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1686 GObjectController *cont = it->second;
1687 cont->removeFromScene();
1688 unregisterController((InteractorStyleMaracas*) cont);
1690 _selectedObjects.clear();
1691 _controllers.clear();
1694 //=========================================================================
1697 void wxVtkSceneManager::refresh() {
1698 _baseView->Refresh();
1700 //=========================================================================
1702 void wxVtkSceneManager::refreshScene() {
1703 _baseView->RefreshView();
1706 //=========================================================================
1708 void wxVtkSceneManager::centerView() {
1710 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1711 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1712 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1713 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1716 //=========================================================================
1718 void wxVtkSceneManager::saveDiagram(std::string &content) {
1721 content += "CATEGORY:";
1722 content += GetCategory();
1725 content += "DESCRIPTION:";
1726 content += GetDescription();
1729 content += "AUTHOR:";
1730 content += GetAuthor();
1733 //Print info IF COMPLEX BOX
1734 content += "COMPLEXBOX:";
1735 if (_isComplexBox) {
1736 content += "TRUE\n";
1738 content += "COMPLEXBOXNAME:";
1739 content += GetCbName();
1742 content += "PACKAGENAME:";
1743 content += GetCbPackageName();
1746 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1747 * External inputs are possible for applications and complex boxes
1748 //Print info complex input ports
1749 std::vector<int> inputs = getComplexInputPorts();
1750 int insize = inputs.size();
1751 content += "COMPLEXINPUTS:";
1752 sprintf(buffer, "%d", insize);
1756 for (int i = 0; i < insize; i++) {
1758 GObjectController *cont = _controllers[id];
1759 cont->getModel()->save(content);
1763 //Print info complex output ports
1764 std::vector<int> outputs = getComplexOutputPorts();
1765 int outsize = outputs.size();
1766 content += "COMPLEXOUTPUTS:";
1767 sprintf(buffer, "%d", outsize);
1771 for (int i = 0; i < outsize; i++) {
1772 int id = outputs[i];
1773 GObjectController *cont = _controllers[id];
1774 cont->getModel()->save(content);
1778 content += "FALSE\n";
1781 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1782 // External inputs are possible for applications and complex boxes
1783 std::vector<int> inputs = getComplexInputPorts();
1784 int insize = inputs.size();
1785 content += "COMPLEXINPUTS:";
1786 sprintf(buffer, "%d", insize);
1790 for (int i = 0; i < insize; i++) {
1792 GObjectController *cont = _controllers[id];
1793 cont->getModel()->save(content);
1797 std::vector<int> boxes = getBlackBoxes();
1798 int bsize = boxes.size();
1799 content += "BOXES:";
1800 sprintf(buffer, "%d", bsize);
1804 for (int i = 0; i < bsize; i++) {
1806 GObjectController *cont = _controllers[id];
1807 cont->getModel()->save(content);
1811 std::vector<int> connections = getConnections();
1812 int csize = connections.size();
1813 content += "CONNECTIONS:";
1814 sprintf(buffer, "%d", csize);
1818 for (int i = 0; i < csize; i++) {
1819 int id = connections[i];
1820 GObjectController *cont = _controllers[id];
1821 cont->getModel()->save(content);
1826 //=========================================================================
1827 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1829 getline(inputStream, line,'\n');
1830 int size = line.length();
1833 if ( line[ size-1 ]==13 )
1835 line.erase(size-1,1);
1840 //=========================================================================
1841 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1844 std::string version = "<void>";
1845 std::string line = "";
1846 char delims[] = ":";
1847 char *result = NULL;
1849 getCleanLine(inputStream, line);
1852 while (!inputStream.eof()) {
1853 if (line == "" || line[0] == '#') {
1855 getCleanLine(inputStream, line);
1857 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1858 version = line.substr(18, 3);
1860 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1861 version = line.substr(18, 3);
1863 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1864 version = line.substr(18, 3);
1866 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1867 version = line.substr(18, 3);
1869 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1870 version = line.substr(18, 3);
1872 } else if (line == "APP_START") {
1881 if ((version != "1.0") && (version != "1.1")) {
1882 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1883 char categoryTmp[30];
1884 strcpy(categoryTmp, line.c_str());
1885 result = strtok(categoryTmp, delims);
1886 result = strtok(NULL, delims);
1887 SetCategory(result);
1889 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1890 char descriptionTmp[1024];
1891 strcpy(descriptionTmp, line.c_str());
1892 result = strtok(descriptionTmp, delims);
1893 result = strtok(NULL, delims);
1894 SetDescription(result);
1896 getCleanLine(inputStream, line);//AUTHOR:<author>
1897 char authorTmp[255];
1898 strcpy(authorTmp, line.c_str());
1899 result = strtok(authorTmp, delims);
1900 result = strtok(NULL, delims);
1905 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1906 char complexTmp[30];
1907 strcpy(complexTmp, line.c_str());
1908 result = strtok(complexTmp, delims);
1909 result = strtok(NULL, delims);
1910 std::string isComplexBox(result);
1912 if (isComplexBox == "TRUE") {
1913 _isComplexBox = true;
1915 if ((version != "1.0") && (version != "1.1")) {
1916 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
1917 char complexboxnameTmp[255];
1918 strcpy(complexboxnameTmp, line.c_str());
1919 result = strtok(complexboxnameTmp, delims);
1920 result = strtok(NULL, delims);
1923 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
1924 char packagenameTmp[255];
1925 strcpy(packagenameTmp, line.c_str());
1926 result = strtok(packagenameTmp, delims);
1927 result = strtok(NULL, delims);
1928 SetCbPackageName(result);
1933 //-----------------------
1934 //- COMPLEX INPUT PORTS
1935 //-----------------------
1936 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
1938 strcpy(inputs, line.c_str());
1939 result = strtok(inputs, delims);
1940 result = strtok(NULL, delims);
1943 std::istringstream inps(result);
1946 for (int i = 0; i < numInputs; i++) {
1948 getCleanLine(inputStream, line);//COMPLEX_PORT
1949 getCleanLine(inputStream, line);//name
1950 std::string inputPortName(line);
1953 getCleanLine(inputStream, line);//xInic:yInic:zInic
1955 strcpy(coord, line.c_str());
1956 result = strtok(coord, delims);//xInic
1957 std::string xInic(result);
1958 result = strtok(NULL, delims);//yInic
1959 std::string yInic(result);
1960 result = strtok(NULL, delims);//zInic
1961 std::string zInic(result);
1963 double xIn, yIn, zIn;
1964 std::istringstream xSt(xInic);
1966 std::istringstream ySt(yInic);
1968 std::istringstream zSt(zInic);
1973 if (zIn==900) zIn=GPOSITION_Z;
1976 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
1978 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
1980 } // for input complex box
1984 //-----------------------
1985 //- COMPLEX OUTPUT PORTS
1986 //-----------------------
1988 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
1990 strcpy(outputs, line.c_str());
1991 result = strtok(outputs, delims);
1992 result = strtok(NULL, delims);
1995 std::istringstream outps(result);
1996 outps >> numOutputs;
1998 for (int i = 0; i < numOutputs; i++) {
2000 getCleanLine(inputStream, line);//COMPLEX_PORT
2001 getCleanLine(inputStream, line);//name
2002 std::string outputPortName(line);
2005 getCleanLine(inputStream, line);//xInic:yInic:zInic
2007 strcpy(coord, line.c_str());
2008 result = strtok(coord, delims);//xInic
2009 std::string xInic(result);
2010 result = strtok(NULL, delims);//yInic
2011 std::string yInic(result);
2012 result = strtok(NULL, delims);//zInic
2013 std::string zInic(result);
2015 double xIn, yIn, zIn;
2016 std::istringstream xSt(xInic);
2018 std::istringstream ySt(yInic);
2020 std::istringstream zSt(zInic);
2025 if (zIn==900) zIn=GPOSITION_Z;
2028 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2030 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2032 } // for output complex box
2036 // RaC2012 2nd Hackfest
2037 if(version >= "1.4")
2039 //-----------------------
2040 //- EXTERNAL INPUT PORTS
2041 //-----------------------
2042 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2044 strcpy(inputs, line.c_str());
2045 result = strtok(inputs, delims);
2046 result = strtok(NULL, delims);
2049 std::istringstream inps(result);
2052 for (int i = 0; i < numInputs; i++) {
2054 getCleanLine(inputStream, line);//COMPLEX_PORT
2055 getCleanLine(inputStream, line);//name
2056 std::string inputPortName(line);
2059 getCleanLine(inputStream, line);//xInic:yInic:zInic
2061 strcpy(coord, line.c_str());
2062 result = strtok(coord, delims);//xInic
2063 std::string xInic(result);
2064 result = strtok(NULL, delims);//yInic
2065 std::string yInic(result);
2066 result = strtok(NULL, delims);//zInic
2067 std::string zInic(result);
2069 double xIn, yIn, zIn;
2070 std::istringstream xSt(xInic);
2072 std::istringstream ySt(yInic);
2074 std::istringstream zSt(zInic);
2079 if (zIn==900) zIn=GPOSITION_Z;
2082 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2083 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2085 } // for external input
2090 getCleanLine(inputStream, line);//BOXES:num
2092 strcpy(boxes, line.c_str());
2093 result = strtok(boxes, delims);
2094 result = strtok(NULL, delims);
2097 std::istringstream is(result);
2100 for (int i = 0; i < numBoxes; i++) {
2102 getCleanLine(inputStream, line);//BOX
2103 getCleanLine(inputStream, line);//package:type:name
2105 strcpy(box, line.c_str());
2106 result = strtok(box, delims);//package
2107 std::string package(result);
2108 result = strtok(NULL, delims);//type
2109 std::string type(result);
2110 result = strtok(NULL, delims);//name
2111 std::string name(result);
2113 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2115 strcpy(exec, line.c_str());
2116 result = strtok(exec, delims);//ISEXEC
2117 result = strtok(NULL, delims);//TRUE|FALSE
2118 std::string isExec(result);
2121 getCleanLine(inputStream, line);//xInic:yInic:zInic
2123 strcpy(coord, line.c_str());
2124 result = strtok(coord, delims);//xInic
2125 std::string xInic(result);
2126 result = strtok(NULL, delims);//yInic
2127 std::string yInic(result);
2128 result = strtok(NULL, delims);//zInic
2129 std::string zInic(result);
2131 double xIn, yIn, zIn;
2132 std::istringstream xSt(xInic);
2134 std::istringstream ySt(yInic);
2136 std::istringstream zSt(zInic);
2142 if (zIn==900) zIn=GPOSITION_Z;
2147 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2148 strcpy(coord, line.c_str());
2149 result = strtok(coord, delims);//xEnd
2150 std::string xEnd(result);
2151 result = strtok(NULL, delims);//yEnd
2152 std::string yEnd(result);
2153 result = strtok(NULL, delims);//zEnd
2154 std::string zEnd(result);
2156 double xEn, yEn, zEn;
2157 std::istringstream xEt(xEnd);
2159 std::istringstream yEt(yEnd);
2161 std::istringstream zEt(zEnd);
2166 if (zEn==900) zEn=GPOSITION_Z;
2170 bool boxExecutable = false;
2171 if (isExec == "TRUE") {
2172 boxExecutable = true;
2175 int idBox = createGBlackBox(xIn, yIn, package, type);
2176 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2178 GObjectController *cont = _controllers[idBox];
2179 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2182 getCleanLine(inputStream, line);//PORT o FIN_BOX
2183 std::string port = line.substr(0, 4);
2184 while (port == "PORT") {
2185 getCleanLine(inputStream, line);//name:value
2187 strcpy(poort, line.c_str());
2188 result = strtok(poort, delims);//name
2189 std::string name(result);
2190 result = strtok(NULL, delims);//value
2191 std::string value(result);
2193 bbmod->setValueToInput(name, value);
2195 getCleanLine(inputStream, line);//PORT o FIN_BOX
2196 port = line.substr(0, 4);
2199 //EED bbmod->notifyObservers(_idManager);
2204 getCleanLine(inputStream, line);//CONNECTIONS:num
2206 strcpy(conns, line.c_str());
2207 result = strtok(conns, delims);
2208 result = strtok(NULL, delims);
2211 std::istringstream isCons(result);
2215 for (int i = 0; i < numConns; i++) {
2217 getCleanLine(inputStream, line);//CONNECTION
2218 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2221 strcpy(connec, line.c_str());
2222 result = strtok(connec, delims);
2223 std::string nameStartBox(result);
2224 result = strtok(NULL, delims);
2225 std::string nameStartPort(result);
2226 result = strtok(NULL, delims);
2227 std::string nameEndBox(result);
2228 result = strtok(NULL, delims);
2229 std::string nameEndPort(result);
2231 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2233 if (version != "1.0") {
2234 //Readding control points of the manualContour
2235 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2236 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2237 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2238 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2239 strcpy(conns, line.c_str());
2240 result = strtok(conns, delims);
2241 result = strtok(NULL, delims);
2243 int numberOfControlPoints;
2244 std::istringstream isCons(result);
2245 isCons >> numberOfControlPoints;
2247 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2248 getCleanLine(inputStream, line); //XX:YY:ZZ
2250 strcpy(connec, line.c_str());
2253 result = strtok(connec, delims);
2254 std::istringstream isPointX(result);
2256 result = strtok(NULL, delims);
2257 std::istringstream isPointY(result);
2259 result = strtok(NULL, delims);
2260 std::istringstream isPointZ(result);
2265 if (pz==900) pz=GPOSITION_Z;
2268 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2269 conView->getManualContourView()->AddPoint();
2278 //=========================================================================
2281 //=========================================================================
2282 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2283 std::string portName, double xIn, double yIn, double zIn) {
2285 if (inputoutput == true) {
2286 idPort = createGComplexBoxInputPort(portName);
2288 idPort = createGComplexBoxOutputPort(portName);
2290 GObjectController *cont = _controllers[idPort];
2291 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2292 cbmod->setInicPoint(xIn, yIn, zIn);
2293 cbmod->notifyObservers(_idManager);
2295 //=========================================================================
2298 //=========================================================================
2299 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
2303 GBoxModel *boxModel = NULL;
2304 std::vector<int> lstB = getBlackBoxes();
2305 for (j = 0; j < (int) lstB.size(); j++) {
2307 bMod = (GBoxModel*) _controllers[idB]->getModel();
2308 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2315 if (boxModel == NULL) {
2316 std::vector<int> lstInputs = getComplexInputPorts();
2317 for (j = 0; j < (int) lstInputs.size(); j++) {
2319 bMod = (GBoxModel*) _controllers[idB]->getModel();
2320 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2327 std::vector<int> lstOutputs = getComplexOutputPorts();
2328 for (j = 0; j < (int) lstOutputs.size(); j++) {
2329 int idB = lstOutputs[j];
2330 bMod = (GBoxModel*) _controllers[idB]->getModel();
2331 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2342 //=========================================================================
2345 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2346 std::string nameStartPort, std::string nameEndBox,
2347 std::string nameEndPort) {
2349 GBoxModel *boxModel;
2350 GPortModel *startP = NULL;
2351 GPortModel *endP = NULL;
2353 boxModel = findGBox(nameStartBox);
2354 if(boxModel == NULL)
2356 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2358 if (boxModel != NULL) {
2359 startP = boxModel->getOutputPort(nameStartPort);
2361 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port %s is null. Port name is probably wrong.\n", nameStartPort.c_str());
2365 boxModel = findGBox(nameEndBox);
2366 if(boxModel == NULL)
2368 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2370 if (boxModel != NULL) {
2371 endP = boxModel->getInputPort(nameEndPort);
2373 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port %s is null. Port name is probably wrong\n", nameStartPort.c_str(), nameEndPort.c_str());
2378 int idCon = createGConnector(startP);
2380 _worldState = NOTHING_HAPPENS;
2381 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2383 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2384 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2385 tempp->endContourCreation();
2386 conMod->setEndPort(endP);
2387 conView->updateStartEndPoints();
2391 //=========================================================================
2393 bool wxVtkSceneManager::boxExist(std::string boxname) {
2395 std::map<int, GObjectController*>::iterator it;
2396 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2397 GObjectController *cont = it->second;
2398 if (cont->getModel()->getBBTKName() == boxname) {
2405 //=========================================================================
2407 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2408 std::vector<int> vect;
2409 std::map<int, GObjectController*>::iterator it;
2410 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2411 GObjectController *cont = it->second;
2412 if (cont->getGObjectType() == GBLACKBOX) {
2413 vect.push_back(cont->getId());
2419 //=========================================================================
2421 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2422 std::vector<int> vect;
2423 std::map<int, GObjectController*>::iterator it;
2424 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2425 GObjectController *cont = it->second;
2426 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2427 vect.push_back(cont->getId());
2433 //=========================================================================
2435 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2436 std::vector<int> vect;
2437 std::map<int, GObjectController*>::iterator it;
2438 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2439 GObjectController *cont = it->second;
2440 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2441 vect.push_back(cont->getId());
2447 //=========================================================================
2449 std::vector<int> wxVtkSceneManager::getConnections() {
2450 std::vector<int> vect;
2451 std::map<int, GObjectController*>::iterator it;
2452 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2453 GObjectController *cont = it->second;
2454 if (cont->getGObjectType() == GCONNECTOR) {
2455 vect.push_back(cont->getId());
2461 //=========================================================================
2463 bool wxVtkSceneManager::isComplexBox() {
2464 return _isComplexBox;
2467 //=========================================================================
2469 void wxVtkSceneManager::setComplexBox(bool val) {
2470 _isComplexBox = val;
2473 //=========================================================================
2475 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2476 //Register the controller of the new object
2477 registerController((InteractorStyleMaracas*) objController);
2478 //Add the object to the objects list
2479 int newId = _contLastId;//_controllers.size();
2480 objController->setId(newId);
2481 _controllers[newId] = objController;
2482 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2487 //=========================================================================
2489 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2491 std::map<int, int> oldIdNewIdBoxes;
2492 std::vector<int> connections;
2494 std::vector<int> newBoxesID;
2496 std::map<int, GObjectController*>::iterator it;
2497 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2498 GObjectController *cont = it->second;
2499 int type = cont->getGObjectType();
2501 if (type == GBLACKBOX) {
2503 double xInic, yInic, zInic;
2504 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2505 copyBox->getInicPoint(xInic, yInic, zInic);
2506 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2507 copyBox->getBBTKType());
2509 int idcB = copyBox->getObjectId();
2510 oldIdNewIdBoxes[idcB] = idBox;
2511 cont = _controllers[idBox];
2512 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2513 newbox->setInicPoint(xInic, yInic, zInic);
2514 int num = newbox->getNumInputPorts();
2515 for (int j = 0; j < num; j++) {
2516 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2518 newbox->move(xInic + 20, yInic + 20, zInic);
2519 newbox->notifyObservers(_idManager);
2520 newBoxesID.push_back(newbox->getObjectId());
2522 } else if (type == GCONNECTOR) {
2523 int idCon = cont->getId();
2524 connections.push_back(idCon);
2529 for (int i = 0; i < (int) connections.size(); i++) {
2530 int objId = connections[i];
2531 GObjectController *cont = objectsMap[objId];
2532 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2534 GPortModel* startPort = connectModel->getStartPort();
2535 int startPortIndex = startPort->getPosInBox();
2536 GPortModel* endPort = connectModel->getEndPort();
2537 int endPortIndex = endPort->getPosInBox();
2539 GBlackBoxModel* startPortParentBox =
2540 (GBlackBoxModel*) startPort->getParentBox();
2541 GBlackBoxModel* endPortParentBox =
2542 (GBlackBoxModel*) endPort->getParentBox();
2544 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2545 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2547 GBlackBoxModel* newStartBox =
2548 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2549 GBlackBoxModel* newEndBox =
2550 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2552 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2553 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2555 // Creates connection
2556 int idCon = createGConnector(newStartPort);
2557 GConnectorController *tempp =
2558 (GConnectorController*) _controllers[idCon];
2559 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2560 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2561 tempp->endContourCreation();
2562 conMod->setEndPort(newEndPort);
2563 conView->updateStartEndPoints();
2566 /// the new selected boxes are the duplicate ones
2568 UnSelectBlackBoxes();
2569 for (int i = 0; i < newBoxesID.size(); i++) {
2570 _selectedObjects.push_back(newBoxesID.at(i));
2573 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2574 int id = _selectedObjects[i];
2575 GObjectController* cont = _controllers[id];
2577 cont->getView()->setState(SELECTED);
2578 cont->getModel()->notifyObservers(_idManager);
2584 //=========================================================================
2586 int wxVtkSceneManager::getNumSelectedObjects() {
2587 return _selectedObjects.size();
2590 //=========================================================================
2592 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2593 std::map<int, GObjectController*> mapSelected;
2595 std::map<int, GObjectController*>::iterator it;
2596 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2597 GObjectController *cont = it->second;
2598 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2600 mapSelected[cont->getId()] = cont;
2604 std::map<int, GObjectController*>::iterator it2;
2605 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2606 GObjectController *cont = it2->second;
2607 if (cont->getGObjectType() == GCONNECTOR) {
2608 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2609 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2610 GBoxModel* startPortParentBox =
2611 cmod->getStartPort()->getParentBox();
2613 std::map<int, GObjectController*>::iterator iterOBJ1 =
2614 mapSelected.find(startPortParentBox->getObjectId());
2615 std::map<int, GObjectController*>::iterator iterOBJ2 =
2616 mapSelected.find(endPortParentBox->getObjectId());
2618 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2619 int ID = cont->getId();
2620 mapSelected[ID] = cont;
2627 //=========================================================================
2629 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2631 std::map<int, int> oldIdNewIdBoxes;
2632 std::vector<int> connections;
2634 std::map<int, GObjectController*>::iterator it;
2635 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2636 GObjectController *cont = it->second;
2637 int type = cont->getGObjectType();
2639 if (type == GBLACKBOX) {
2641 double xInic, yInic, zInic;
2642 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2643 copyBox->getInicPoint(xInic, yInic, zInic);
2644 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2645 copyBox->getBBTKType());
2647 int idcB = copyBox->getObjectId();
2648 oldIdNewIdBoxes[idcB] = idBox;
2649 cont = _controllers[idBox];
2650 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2651 newbox->setInicPoint(xInic, yInic, zInic);
2652 int num = newbox->getNumInputPorts();
2653 for (int j = 0; j < num; j++) {
2654 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2656 newbox->notifyObservers(_idManager);
2657 } else if (type == GCONNECTOR) {
2658 int idCon = cont->getId();
2659 connections.push_back(idCon);
2664 for (int i = 0; i < (int) connections.size(); i++) {
2665 int objId = connections[i];
2666 GObjectController *cont = objectsMap[objId];
2667 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2669 GPortModel* startPort = connectModel->getStartPort();
2670 int startPortIndex = startPort->getPosInBox();
2671 GPortModel* endPort = connectModel->getEndPort();
2672 int endPortIndex = endPort->getPosInBox();
2674 GBlackBoxModel* startPortParentBox =
2675 (GBlackBoxModel*) startPort->getParentBox();
2676 GBlackBoxModel* endPortParentBox =
2677 (GBlackBoxModel*) endPort->getParentBox();
2679 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2680 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2682 GBlackBoxModel* newStartBox =
2683 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2684 GBlackBoxModel* newEndBox =
2685 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2687 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2688 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2690 // Creates connection
2691 int idCon = createGConnector(newStartPort);
2692 GConnectorController *tempp =
2693 (GConnectorController*) _controllers[idCon];
2694 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2695 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2696 tempp->endContourCreation();
2697 conMod->setEndPort(newEndPort);
2698 conView->updateStartEndPoints();
2701 std::map<int, int>::iterator itIds;
2702 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2703 int idOld = itIds->first;
2704 int idNew = itIds->second;
2706 GBlackBoxModel* oldBox =
2707 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2708 GBlackBoxModel* newBox =
2709 (GBlackBoxModel*) _controllers[idNew]->getModel();
2711 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2712 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2713 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2714 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2716 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2718 //EED int toCreate=-1;
2719 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2720 if (oldInputConnections[k] == newInputConnections[l]) {
2725 if (exist == false) {
2726 //Create complex input
2727 int posInBox = oldInputConnections[k];
2728 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2729 std::string inputPortName = inputPort->getBBTKName();
2730 int idInputPort = createGComplexBoxInputPort(inputPortName);
2731 GObjectController *cont = _controllers[idInputPort];
2732 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2733 double xIn, yIn, zIn;
2734 inputPort->getInicPoint(xIn, yIn, zIn);
2736 cbmod->setInicPoint(xIn, yIn, zIn);
2737 cbmod->notifyObservers(_idManager);
2739 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2741 // Creates connection
2742 int idCon = createGConnector(cbmod->getOutputPort(0));
2743 GConnectorController *tempp =
2744 (GConnectorController*) _controllers[idCon];
2745 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2746 vtkGConnectorView *conView =
2747 (vtkGConnectorView*) tempp->getView();
2748 tempp->endContourCreation();
2749 conMod->setEndPort(inputPortEnd);
2750 conView->updateStartEndPoints();
2756 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2758 //EED int toCreate=-1;
2759 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2760 if (oldOutputConnections[k] == newOutputConnections[l]) {
2765 if (exist == false) {
2766 //Create complex output
2767 int posInBox = oldOutputConnections[k];
2768 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2769 std::string outputPortName = outputPort->getBBTKName();
2770 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2771 GObjectController *cont = _controllers[idOutputPort];
2772 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2773 double xIn, yIn, zIn;
2774 outputPort->getInicPoint(xIn, yIn, zIn);
2776 cbmod->setInicPoint(xIn, yIn, zIn);
2777 cbmod->notifyObservers(_idManager);
2779 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2781 // Creates connection
2782 int idCon = createGConnector(outputPortEnd);
2783 GConnectorController *tempp =
2784 (GConnectorController*) _controllers[idCon];
2785 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2786 vtkGConnectorView *conView =
2787 (vtkGConnectorView*) tempp->getView();
2788 tempp->endContourCreation();
2789 conMod->setEndPort(cbmod->getInputPort(0));
2790 conView->updateStartEndPoints();
2800 //=========================================================================
2801 void wxVtkSceneManager::SetCbName(std::string cbName) {
2803 if (_cbName == "") {
2804 _cbName = "<complex box name>";
2808 //=========================================================================
2809 std::string wxVtkSceneManager::GetCbName() {
2813 //=========================================================================
2814 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2815 _cbPackageName = packagename;
2816 if (_cbPackageName == "") {
2817 _cbPackageName = "<package name of the complex box>";
2821 //=========================================================================
2822 std::string wxVtkSceneManager::GetCbPackageName() {
2823 return _cbPackageName;
2826 //=========================================================================
2827 void wxVtkSceneManager::SetAuthor(std::string author) {
2829 if (_Author == "") {
2830 _Author = "<author of the box>";
2834 //=========================================================================
2835 std::string wxVtkSceneManager::GetAuthor() {
2839 //=========================================================================
2840 void wxVtkSceneManager::SetCategory(std::string category) {
2841 _Category = category;
2842 if (_Category == "") {
2843 _Category = "<category of the box>";
2847 //=========================================================================
2848 std::string wxVtkSceneManager::GetCategory() {
2852 //=========================================================================
2853 void wxVtkSceneManager::SetDescription(std::string description) {
2854 _Description = description;
2855 if (_Description == "") {
2856 _Description = "<description of the box>";
2860 //=========================================================================
2861 std::string wxVtkSceneManager::GetDescription() {
2862 return _Description;
2865 //=========================================================================
2867 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
2870 std::vector< std::string> extInputs;
2871 std::map<int, GObjectController*>::iterator it;
2872 for (it = _controllers.begin(); it != _controllers.end(); ++it)
2874 GObjectController *cont = it->second;
2875 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
2877 extInputs.push_back(cont->getModel()->getBBTKName());
2883 //=========================================================================
2887 void wxVtkSceneManager::printAll(int com , int sta ){
2889 int tmpState = sta ;
2890 if ( tmpState == NOTHING_HAPPENS ) {
2891 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2893 if ( tmpState == HIGHLIGHTED ) {
2894 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2896 if ( tmpState == POSSIBLE_CONNECTION ) {
2897 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2899 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2900 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2902 if ( tmpState == CLICKED ) {
2903 std::cout << "CONTROLER STATE---->CLICKED\n" ;
2905 if ( tmpState == DRAG ) {
2906 std::cout << "CONTROLER STATE---->DRAG\n" ;
2908 if ( tmpState == SELECTED ) {
2909 std::cout << "CONTROLER STATE---->SELECTED\n" ;
2911 if ( tmpState == CREATING_CONTOUR ) {
2912 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2918 if ( command == INIT_CREATION_CONTOUR ) {
2919 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2921 if ( command == FIN_CREATION_CONTOUR ) {
2922 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2924 if ( command == ADD_TO_SELECTED ) {
2925 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2927 if ( command == DRAG_OBJECTS ) {
2928 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2930 if ( command == EDIT_BLACKBOX ) {
2931 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
2933 if ( command == REMOVE_FROM_SELECTED ) {
2934 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
2940 } // EO namespace bbtk