wxVtkSceneManager.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002  Program:   bbtk
00003  Module:    $RCSfile: wxVtkSceneManager.cxx,v $
00004  Language:  C++
00005  Date:      $Date: 2012/05/29 09:25:15 $
00006  Version:   $Revision: 1.44 $
00007  =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011  * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012  * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013  *
00014  *  This software is governed by the CeCILL-B license under French law and
00015  *  abiding by the rules of distribution of free software. You can  use,
00016  *  modify and/ or redistribute the software under the terms of the CeCILL-B
00017  *  license as circulated by CEA, CNRS and INRIA at the following URL
00018  *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
00019  *  or in the file LICENSE.txt.
00020  *
00021  *  As a counterpart to the access to the source code and  rights to copy,
00022  *  modify and redistribute granted by the license, users are provided only
00023  *  with a limited warranty  and the software's author,  the holder of the
00024  *  economic rights,  and the successive licensors  have only  limited
00025  *  liability.
00026  *
00027  *  The fact that you are presently reading this means that you have had
00028  *  knowledge of the CeCILL-B license and that you accept its terms.
00029  * ------------------------------------------------------------------------ */
00030 
00036 #include "wxVtkSceneManager.h"
00037 
00038 #include <vtkPolygon.h>
00039 #include <vtkUnstructuredGrid.h>
00040 
00041 namespace bbtk {
00042 
00043 //=========================================================================
00044 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent,
00045                 wxVtk3DBaseView *baseView, int idManager) {
00046         _cbName = "ComplexBoxName";
00047         _cbPackageName = "PackageName";
00048         _Author = "Author ??";
00049         _Category = "<VOID>";
00050         _Description = "Description ??";
00051 
00052         _parent = parent;
00053         _numBoxes = 0;
00054         _idManager = idManager;
00055         _baseView = baseView;
00056         _startDragging = false;
00057         _isComplexBox = false;
00058 
00059         if (_baseView != NULL) {
00060                 //EED02JUIN2010
00061                 printf(
00062                                 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
00063                                 this);
00064 //#ifdef __APPLE__
00065                 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
00066 //#endif
00067 
00068                 configureBaseView();
00069                 _worldState = NOTHING_HAPPENS;
00070                 registerController(this);
00071 
00072         }
00073         _idConnectionInCreation = -1;
00074         _contLastId = 0;
00075 
00076 }
00077 
00078 //=========================================================================
00079 
00080 void wxVtkSceneManager::disconnectDrop() {
00081         printf("EED %p ~wxVtkSceneManager::disconnectDrop()\n", this);
00082         //EED02JUIN2010         _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
00083         //      _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
00084 }
00085 
00086 //=========================================================================
00087 
00088 wxVtkSceneManager::~wxVtkSceneManager() {
00089         //FCY memory leaks
00090         printf("EED %p ~wxVtkSceneManager() START\n", this);
00091         disconnectDrop();
00092         delete _baseView;
00093         printf("EED %p ~wxVtkSceneManager() END\n", this);
00094 }
00095 
00096 //=========================================================================
00097 
00098 void wxVtkSceneManager::configureBaseView() {
00099         printf("EED wxVtkSceneManager::configureBaseView 0\n");
00100         vtkInteractorStyleBaseView2D *interactorstylebaseview =
00101                         vtkInteractorStyleBaseView2D::New();
00102 
00103         _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
00104 
00105         // Important to activate the 2D interaction system
00106         wxVTKRenderWindowInteractor *iren =
00107                         _baseView->GetWxVTKRenderWindowInteractor();
00108         interactorstylebaseview->SetInteractor(iren);
00109         iren->SetInteractorStyle(interactorstylebaseview);
00110         interactorstylebaseview->SetwxVtkBaseView(_baseView);
00111 
00112         _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
00113         _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, 800, 1100);
00114 
00115         _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
00116         _baseView->GetRenderer()->GradientBackgroundOn();
00117 
00118         // Actos Port_Text
00119         _textActor = vtkTextActor3D::New();
00120         _textActor->SetPosition(-9999, -9999, 900);
00121         _textActor->SetInput("<void>");
00122         _textActor->GetTextProperty()->SetFontSize(60);
00123         _textActor->GetTextProperty()->BoldOn();
00124         _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,
00125                         PORTTEXT_NH_B);
00126 
00127         _baseView->GetRenderer()->AddActor(_textActor);
00128 
00129         // Actor  Fill_Port_Text
00130 
00131         //------------
00132         double xInic = 0;
00133         double yInic = 0;
00134         double zInic = 900;
00135 
00136         vtkPolygon *aPolygon = vtkPolygon::New();
00137         _fillObjectActor = vtkActor::New();
00138 
00139         _pts = vtkPoints::New();
00140 
00141         double w = 100, h = 10, b = h / 15, t = 3;
00142         _pts->SetNumberOfPoints(21);
00143         _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
00144         _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
00145         _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
00146         _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
00147         _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
00148 
00149         _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
00150         _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
00151         _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
00152         _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
00153 
00154         _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
00155         _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
00156         _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
00157         _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
00158 
00159         _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
00160         _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
00161         _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
00162         _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
00163 
00164         _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
00165         _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
00166         _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
00167         _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
00168 
00169         aPolygon->GetPointIds()->SetNumberOfIds(21);
00170         for (int i = 0; i < 21; i++) {
00171                 aPolygon->GetPointIds()->SetId(i, i);
00172         }
00173 
00174         vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
00175         aPolygonGrid->Allocate(1, 1);
00176         aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),
00177                         aPolygon->GetPointIds());
00178         aPolygonGrid->SetPoints(_pts);
00179         _aPolygonMapper = vtkDataSetMapper::New();
00180         _aPolygonMapper->SetInput(aPolygonGrid);
00181         _fillObjectActor->SetMapper(_aPolygonMapper);
00182         _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
00183                         PORTFILL_NH_B);
00184         _fillObjectActor->GetProperty()->SetOpacity(0);
00185         _aPolygonMapper->Modified();
00186 
00187         _baseView->GetRenderer()->AddActor(_fillObjectActor);
00188         printf("EED wxVtkSceneManager::configureBaseView 1\n");
00189 }
00190 
00191 //=========================================================================
00192 
00193 std::string wxVtkSceneManager::generateANewNameForABox() {
00194         std::stringstream boxname;
00195         if (_numBoxes < 10) {
00196                 boxname << "Box0" << _numBoxes;
00197         } else {
00198                 boxname << "Box" << _numBoxes;
00199         }
00200         _numBoxes++;
00201         return boxname.str();
00202 }
00203 
00204 //=========================================================================
00205 
00206 std::string wxVtkSceneManager::findANewNameForABox() {
00207         std::string boxname = generateANewNameForABox();
00208 
00209         while (boxExist(boxname) == true) {
00210                 boxname = generateANewNameForABox();
00211         } // while
00212 
00213         return boxname;
00214 }
00215 
00216 //=========================================================================
00217 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
00218                 double zIn, std::string name, bool boxExecutable, double xEn,
00219                 double yEn, double zEn) {
00220         GObjectController *cont = _controllers[idBox];
00221         GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
00222         bbmod->setBBTKName(name);
00223         bbmod->setInicPoint(xIn, yIn, zIn);
00224         bbmod->setFinalPoint(xEn, yEn, zEn);
00225         bbmod->setExecutable(boxExecutable);
00226 
00227         bbmod->notifyObservers(_idManager);
00228 
00229 }
00230 
00231 //=========================================================================
00232 
00233 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,
00234                 std::string boxType) {
00235         _worldState = NOTHING_HAPPENS;
00236         //EED           int windowWidth                                                 = _baseView->GetRenWin()->GetSize()[0];
00237         int windowHeight = _baseView->GetRenWin()->GetSize()[1];
00238 
00239         int type = GBLACKBOX;
00240 
00241         //Create the MVC Objects
00242 
00243         GBlackBoxModel
00244                         *model =
00245                                         (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
00246                                                         type);
00247         vtkGObjectView *view =
00248                         GObjectsMVCFactory::getInstance()->createGObjectView(type);
00249         GObjectController* controller =
00250                         GObjectsMVCFactory::getInstance()->createGObjectController(type);
00251 
00252         BlackBoxDescriptor::Pointer descriptor =
00253                         GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
00254                                         packageName, boxType);
00255         if (descriptor == NULL){
00256                         printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n",  boxType.c_str());
00257                 }
00258         //Prepares the initial model
00259         //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
00260 
00261         double xx = x;
00262         double yy = windowHeight - y;
00263 
00264         //z value is not important yet, because it is only used a parallel projection
00265         double zz = 900;
00266         _baseView->TransCoordScreenToWorld(xx, yy, zz);
00267         model->setInicPoint(xx, yy, zz);
00268 
00269         std::stringstream stream;
00270 
00271         std::string newBoxName;
00272         newBoxName = findANewNameForABox();
00273 
00274         stream << newBoxName;
00275 
00276         std::string arraystring = stream.str();
00277 
00278         model->setBBTKName(arraystring);
00279         model->setBBTKType(boxType);
00280         model->setBBTKPackage(packageName);
00281 
00282         model->addObserver(view);
00283         model->addObserver(this);
00284 
00285         //Iterate and create the input ports
00286         std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
00287                         descriptor->GetInputDescriptorMap();
00288         std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
00289 
00290         int i = 0;
00291         for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) {
00292                 BlackBoxInputDescriptor *desc = itInput->second;
00293                 createGInputPort(GINPUTPORT, i, model, desc);
00294                 i++;
00295         }
00296 
00297         //Iterate and create the output ports
00298         std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
00299                         descriptor->GetOutputDescriptorMap();
00300         std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
00301 
00302         i = 0;
00303         for (itOutput = descriptorOutMap.begin(); itOutput
00304                         != descriptorOutMap.end(); ++itOutput) {
00305                 BlackBoxOutputDescriptor *desc = itOutput->second;
00306                 createGOutputPort(GOUTPUTPORT, i, model, desc);
00307                 i++;
00308         }
00309 
00310         //Associates the view with the correspondent renderer and the  model.
00311         //(NOTE: Refresh is only made by the view)
00312         view->setModel(model);
00313         view->setBaseView(_baseView);
00314         view->initVtkObjects();
00315 
00316         //Associates the controller with the correspondent model and view
00317         controller->setModelAndView(model, view);
00318 
00319         //Resgiter change to the observers of the actual model
00320         model->notifyObservers(_idManager);
00321 
00322         int newId = addObjectController(controller);
00323 
00324         return newId;
00325 
00326 }
00327 
00328 //=========================================================================
00329 
00330 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
00331         //EED           int windowWidth=_baseView->GetRenWin()->GetSize()[0];
00332         int windowHeight = _baseView->GetRenWin()->GetSize()[1];
00333 
00334         int type = GCOMPLEXINPUTPORT;
00335 
00336         //Create the MVC Objects
00337 
00338         GComplexBoxPortModel
00339                         *model =
00340                                         (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
00341                                                         type);
00342         vtkGObjectView *view =
00343                         GObjectsMVCFactory::getInstance()->createGObjectView(type);
00344         GObjectController* controller =
00345                         GObjectsMVCFactory::getInstance()->createGObjectController(type);
00346 
00347         //Prepares the initial model
00348 
00349         double xx = 5;
00350         double yy = windowHeight - 5;
00351 
00352         //z value is not important yet, because it is only used a parallel projection
00353         double zz = 900;
00354         printf("EED  wxVtkSceneManager::createGComplexBoxInputPort 900-450\n");
00355 
00356         _baseView->TransCoordScreenToWorld(xx, yy, zz);
00357         model->setInicPoint(xx, yy, zz);
00358 
00359         model->setBBTKName(inputName);
00360         model->setBBTKType("ComplexInputPort");
00361         model->setComplexPortType(type);
00362 
00363         model->addObserver(view);
00364         model->addObserver(this);
00365 
00366         //create the output port
00367         GPortController* portController = createGPort(GOUTPUTPORT, inputName,
00368                         "ComplexInputPort", 0, model);
00369         model->addOutputPort((GPortModel*) portController->getModel());
00370 
00371         //Associates the view with the correspondent renderer and the  model.
00372         //(NOTE: Refresh is only made by the view)
00373         view->setModel(model);
00374         view->setBaseView(_baseView);
00375         view->initVtkObjects();
00376 
00377         //Associates the controller with the correspondent model and view
00378         controller->setModelAndView(model, view);
00379 
00380         //Resgiter change to the observers of the actual model
00381         model->notifyObservers(_idManager);
00382 
00383         int newId = addObjectController(controller);
00384         return newId;
00385 }
00386 
00387 //=========================================================================
00388 
00389 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
00390         //EED           int windowWidth=_baseView->GetRenWin()->GetSize()[0];
00391         int windowHeight = _baseView->GetRenWin()->GetSize()[1];
00392 
00393         int type = GCOMPLEXOUTPUTPORT;
00394 
00395         //Create the MVC Objects
00396 
00397         GComplexBoxPortModel
00398                         *model =
00399                                         (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
00400                                                         type);
00401         vtkGObjectView *view =
00402                         GObjectsMVCFactory::getInstance()->createGObjectView(type);
00403         GObjectController *controller =
00404                         GObjectsMVCFactory::getInstance()->createGObjectController(type);
00405 
00406         //Prepares the initial model
00407 
00408         double xx = 5;
00409         double yy = windowHeight - 5;
00410 
00411         //z value is not important yet, because it is only used a parallel projection
00412         double zz = 900;
00413 
00414         printf("EED  wxVtkSceneManager::createGComplexBoxOutputPort 900-450\n");
00415 
00416         _baseView->TransCoordScreenToWorld(xx, yy, zz);
00417         model->setInicPoint(xx, yy, zz);
00418 
00419         model->setBBTKName(outputName);
00420         model->setBBTKType("ComplexOutputPort");
00421         model->setComplexPortType(type);
00422 
00423         model->addObserver(view);
00424         model->addObserver(this);
00425 
00426         //create the output port
00427         GPortController* portController = createGPort(GINPUTPORT, outputName,
00428                         "ComplexInputPort", 0, model);
00429         model->addInputPort((GPortModel*) portController->getModel());
00430 
00431         //Associates the view with the correspondent renderer and the  model.
00432         //(NOTE: Refresh is only made by the view)
00433         view->setModel(model);
00434         view->setBaseView(_baseView);
00435         view->initVtkObjects();
00436 
00437         //Associates the controller with the correspondent model and view
00438         controller->setModelAndView(model, view);
00439 
00440         //Resgiter change to the observers of the actual model
00441         model->notifyObservers(_idManager);
00442 
00443         int newId = addObjectController(controller);
00444         return newId;
00445 }
00446 
00447 //=========================================================================
00448 
00449 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,
00450                 GBoxModel *blackBox, BlackBoxInputDescriptor *desc) {
00451         GPortController* portController = createGPort(portType, desc->GetName(),
00452                         desc->GetTypeName(), posinBox, blackBox);
00453         blackBox->addInputPort((GPortModel*) portController->getModel());
00454         return portController->getId();
00455 }
00456 
00457 //=========================================================================
00458 
00459 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,
00460                 GBoxModel *blackBox, BlackBoxOutputDescriptor *desc) {
00461         GPortController* portController = createGPort(portType, desc->GetName(),
00462                         desc->GetTypeName(), posinBox, blackBox);
00463         blackBox->addOutputPort((GPortModel*) portController->getModel());
00464         return portController->getId();
00465 }
00466 
00467 //=========================================================================
00468 
00469 GPortController* wxVtkSceneManager::createGPort(int portType,
00470                 std::string bbtkName, std::string bbtkType, int posInBox,
00471                 GBoxModel *blackBox) {
00472         int type = GPORT;
00473 
00474         //Create the MVC Objects
00475         GPortModel
00476                         *model =
00477                                         (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
00478                                                         type);
00479         vtkGObjectView *view =
00480                         GObjectsMVCFactory::getInstance()->createGObjectView(type);
00481         GObjectController* controller =
00482                         GObjectsMVCFactory::getInstance()->createGObjectController(type);
00483 
00484         model->registerInBox(blackBox, portType, posInBox);
00485 
00486         model->setBBTKType(bbtkType);
00487         model->setBBTKName(bbtkName);
00488 
00489         model->addObserver(view);
00490         model->addObserver(this);
00491 
00492         //Associates the view with the correspondent renderer and the  model.
00493         //(NOTE: Refresh is only made by the view)
00494         view->setModel(model);
00495         view->setBaseView(_baseView);
00496         view->initVtkObjects();
00497 
00498         //Associates the controller with the correspondent model and view
00499         controller->setModelAndView(model, view);
00500 
00501         model->notifyObservers(_idManager);
00502 
00503         addObjectController(controller);
00504 
00505         return (GPortController*) controller;
00506 }
00507 
00508 //=========================================================================
00509 
00510 int wxVtkSceneManager::createGConnector(GPortModel* startPort) {
00511         int type = GCONNECTOR;
00512 
00513         manualConnectorContourController* manContourControl =
00514                         new manualConnectorContourController();
00515         manualConnectorContourView* manContourView =
00516                         new manualConnectorContourView();
00517         manualContourModel* manContourModel = new manualContourModel();
00518 
00519         GConnectorController* connectorcontroller = new GConnectorController();
00520         GConnectorModel* connectorModel = new GConnectorModel();
00521         vtkGConnectorView* connectorView = new vtkGConnectorView();
00522         connectorModel->setGObjectType(type);
00523 
00524         manContourModel->SetCloseContour(false);
00525         connectorModel->setStartPort(startPort);
00526 
00527         manContourView->SetModel(manContourModel);
00528         manContourView->SetWxVtkBaseView(_baseView);
00529         manContourView->SetRange(0.5);
00530         manContourView->SetZ(900);
00531 
00532         manContourView->SetColorNormalContour(0, 0, 1);
00533         manContourView->SetColorEditContour(0.5, 0.5, 0.5);
00534         manContourView->SetColorSelectContour(1, 0.8, 0);
00535         
00541         manContourView->SetWidthLine( 3 ) ;
00542         manContourView->SetShowText(false);
00543 
00544         manContourControl->SetModelView(manContourModel, manContourView);
00545 
00546         manContourControl->CreateNewManualContour();
00547 
00548 
00549         double x, y, z;
00550         connectorModel->getInicPoint(x, y, z);
00551 
00552         manContourControl->SetState(1);
00553         manContourModel->SetCloseContour(false);
00554 
00555         manContourModel->AddPoint(x, y, z);
00556         manContourView->AddPoint();
00557 
00558         manContourModel->AddPoint(x, y, z);
00559         manContourView->AddPoint();
00560 
00561         int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
00562         manContourControl->_bakIdPoint = bak;
00563         
00564         manContourControl->SetMoving(false);
00565 
00566         connectorcontroller->setModelAndView(connectorModel, connectorView);
00567 
00568         int newId = addObjectController(connectorcontroller);
00569 
00570         connectorcontroller->setManualContourController(manContourControl);
00571         connectorModel->setManualContourModel(manContourModel);
00572         connectorView->setManualContourView(manContourView);
00573         connectorView->setModel(connectorModel);
00574         connectorView->setBaseView(_baseView);
00575 
00576         connectorModel->addObserver(connectorView);
00577         connectorModel->addObserver(this);
00578 
00579         manContourView->Refresh();
00580         return newId;
00581 }
00582 
00583 //=========================================================================
00584 
00585 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param) {
00586         vtkInteractorStyleBaseView
00587                         * baseViewControlManager =
00588                                         (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
00589         baseViewControlManager->AddInteractorStyleMaracas(param);
00590 }
00591 
00592 //=========================================================================
00593 
00594 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param) {
00595         vtkInteractorStyleBaseView
00596                         * baseViewControlManager =
00597                                         (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
00598         baseViewControlManager->RemoveInteractorStyleMaracas(param);
00599 }
00600 
00601 //=========================================================================
00602 
00603 vtkRenderer* wxVtkSceneManager::getRenderer() {
00604         return _baseView->GetRenderer();
00605 }
00606 
00607 //=========================================================================
00608 
00609 vtkRenderWindow* wxVtkSceneManager::getRenderWindow() {
00610         return _baseView->GetRenWin();
00611 }
00612 //=========================================================================
00613 
00614 
00615 //=========================================================================
00616 int wxVtkSceneManager::GetIndexInSelected(int idControler) {
00617         int index = -1;
00618         for (int i = 0; i < (int) _selectedObjects.size(); i++) {
00619                 if (_selectedObjects[i] == idControler) {
00620                         index = i;
00621                         break;
00622                 }
00623         }
00624         return index;
00625 }
00626 //=========================================================================
00627 
00628 void wxVtkSceneManager::update(int idController, int command) {
00629 
00630         if (command != NO_COMMAND) {
00631                 if (command == ADD_TO_SELECTED) {
00632                         //EEDBorrame                            GObjectController* cont = _controllers[idController];
00633 
00634                         if (GetIndexInSelected(idController) == -1) {
00635                                 _selectedObjects.push_back(idController);
00636                         }
00637 
00638                         //EEDBorrame
00639                         //                              bool foundID=false;
00640                         //                              for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
00641                         //                              {
00642                         //                                      if(_selectedObjects[i]==idController)
00643                         //                                      {
00644                         //                                              foundID = true;
00645                         //                                      }
00646                         //                              }
00647                         //                              if(!foundID)
00648                         //                              {
00649                         //                                      _selectedObjects.push_back(idController);
00650                         //                              }
00651 
00652                 } else if (command == REMOVE_FROM_SELECTED) {
00653                         int index = GetIndexInSelected(idController);
00654                         if (index >= 0) {
00655                                 _selectedObjects.erase(_selectedObjects.begin() + index);
00656                         }
00657                 } else if (command == INIT_CREATION_CONTOUR) {
00658 
00659                 // JGRR & CM WH
00660                 typedef std::map<int , GObjectController*>::iterator TIterator ;
00661                 TIterator iter ;
00662                 TIterator iter_end ;
00663                 // Find current item in the controller
00664                 iter = _controllers.find( idController ) ;
00665                 iter_end = _controllers.end( ) ;
00666                 // If item exist 
00667                 if ( iter != iter_end ) {
00668                     GObjectController* gobjc = iter->second ;
00669 
00670                     std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
00671                     // And if the item is a port
00672                     if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
00673                         TIterator c_it = _controllers.begin( ) ;
00674                         // Go through all componets 
00675                         for ( c_it ; c_it != iter_end ; c_it++ ) {
00676                             GObjectController* obc = c_it->second ;
00677                             int obc_type = obc->getModel( )->getGObjectType( ) ;
00678                             std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
00679                             // if the component is a port and the type is the same of that selected
00680                             if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
00681                                 // Highliht element 
00682                                 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;                             
00683                                 //obc->getView( )->setState( HIGHLIGHTED ) ;
00684                             }
00685                         }
00686                     }
00687                 }
00688 
00689                 // EO JGRR & CM WH  
00690                      
00691                         _worldState = INIT_CREATION_CONTOUR;
00692                         GObjectController* cont = _controllers[idController];
00693                         GPortModel* startOutputPort = (GPortModel*) cont->getModel();
00694 
00695                         // The last one is the controller of the connector
00696                         std::map<int, GObjectController*>::iterator it2;
00697 
00698                         for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
00699                                 GObjectController *cont = it2->second;
00700                                 if (cont->getGObjectType() == GPORT) {
00701                                         GPortModel* port = (GPortModel*) cont->getModel();
00702                                         if (port->getPortType() == GINPUTPORT) {
00703                                                 cont->SetActive(true);
00704                                         } else {
00705                                                 cont->getView()->setState(NOTHING_HAPPENS);
00706                                                 cont->getModel()->notifyObservers(_idManager);
00707                                                 cont->SetActive(false);
00708                                         }
00709                                 } else {
00710                                         cont->getView()->setState(NOTHING_HAPPENS);
00711                                         cont->getModel()->notifyObservers(_idManager);
00712                                         cont->SetActive(false);
00713                                 }
00714                         }
00715                         _selectedObjects.clear();
00716                         _idConnectionInCreation = createGConnector(startOutputPort);
00717                 } else if (command == FIN_CREATION_CONTOUR && _worldState
00718                                 == INIT_CREATION_CONTOUR) {
00719                         _worldState = NOTHING_HAPPENS;
00720                         //int id = _controllers.size()-1;
00721                         GObjectController *cont = _controllers[_idConnectionInCreation];
00722                         GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
00723                         GObjectController *finPort = _controllers[idController];
00724 
00725                         if (finPort->getGObjectType() == GPORT) {
00726                                 GPortModel* modelPort = (GPortModel*) finPort->getModel();
00727                                 modelContour->setEndPort(modelPort);
00728 
00729                                 // JGRR CM                     
00730                                 typedef std::map<int, GObjectController*>::iterator TIterator;
00731                                 TIterator c_it = _controllers.begin();
00732                                 TIterator iter_end = _controllers.end();
00733                                 // Go through all componets 
00734                                 for (c_it; c_it != iter_end; c_it++) {
00735                                     GObjectController* obc = c_it->second;
00736                                     int obc_type = obc->getModel()->getGObjectType();
00737                                     int obc_state = obc->getView()->getState();
00738                                     // if the component is a port and the type is the same of that selected
00739                                     if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
00740                                         // Return element to neutral state if not selected
00741                                         obc->getView()->setState(NOTHING_HAPPENS);
00742                                     }
00743                                     if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
00744                                         // Change element to connected state
00745                                         obc->getView()->setState(HIGHLIGHTED);
00746 
00747                                     }
00748 
00749                                 }
00750                                 // EO JGRR CM                                
00751                     
00752                                                                 _parent->saveTempandUpdate("create connection");
00753                         }
00754 
00755                         manualConnectorContourController
00756                                         * manCont =
00757                                                         ((GConnectorController*) cont)->getManualContourController();
00758                         manualConnectorContourView
00759                                         * connView =
00760                                                         (manualConnectorContourView*) manCont->GetManualViewBaseContour();
00761                                      
00762                         std::map<int, GObjectController*>::iterator it2;
00763 
00764                         for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
00765                                 GObjectController *cont = it2->second;
00766                                 if (cont->getView() != NULL) {
00767                                         cont->getView()->setState(NOTHING_HAPPENS);
00768                                         cont->getModel()->notifyObservers(_idManager);
00769                                 }
00770                                 cont->SetActive(true);
00771                         }
00772                         connView->Refresh();          
00773                 }
00774 
00775         }
00776         
00777 }
00778 
00779 //=========================================================================
00780 
00781 bool wxVtkSceneManager::OnMouseMove() {
00782         int X, Y;
00783         bool okStatusMessage = false;
00784         bool okPortMessage = false;
00785         wxVTKRenderWindowInteractor *wxVTKiren;
00786         wxVTKiren
00787                         = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
00788         wxVTKiren->GetEventPosition(X, Y);
00789 
00790         if (_worldState == DRAG_OBJECTS) {
00791                 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
00792                         int id = _selectedObjects[i];
00793                         GObjectController* cont = _controllers[id];
00794                         if (_startDragging) {
00795                                 cont->getView()->setStartDragging(true);
00796                         }
00797                         cont->getView()->moveObject(X, Y);
00798                         cont->getView()->setState(DRAG);
00799                         cont->getModel()->notifyObservers(_idManager);
00800                 }
00801 
00802                 std::map<int, GObjectController*>::iterator it;
00803 
00804                 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
00805                         GObjectController *desc = it->second;
00806                         if (desc->getGObjectType() == GCONNECTOR) {
00807                                 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
00808                                 vconn->updateStartEndPoints();
00809                         }
00810                 }
00811 
00812                 _startDragging = false;
00813 
00814         } else if (_worldState == NOTHING_HAPPENS || _worldState
00815                         == INIT_CREATION_CONTOUR) {
00816                 std::map<int, GObjectController*>::iterator it;
00817                 double px, py, pz;
00818                 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
00819                         GObjectController *desc = it->second;
00820                         int type = desc->getGObjectType();
00821                         int state = desc->getView()->getState();
00822                         desc->getModel()->getCenter(px, py, pz);
00823 
00824                         // JGRR & CM
00825                         if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION )) {
00826                         // EO JGRR & CM    
00827                                 okStatusMessage = true;
00828                                 updateStatusBar(desc->getStatusText());
00829                                 if (type == GBLACKBOX) {
00830                                         GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
00831                                         _parent->displayBlackBoxInfo(mod->getBBTKPackage(),
00832                                                         mod->getBBTKType());
00833                                 } // if GBLACKBOX
00834                                 if (type == GPORT) {
00835                                         // PortText
00836                                         okPortMessage = true;
00837                                         py = py + 5;
00838                                         _textActor->SetInput(desc->getStatusText().c_str());
00839                                         _textActor->SetScale(0.1);
00840                                         _textActor->SetPosition(px - 25, py + 1, pz + 2);
00841 
00842                                         // FillPortText
00843                                         px = px - 33;
00844                                         py = py;
00845                                         _fillObjectActor->SetScale(1);
00846                                         _fillObjectActor->GetProperty()->SetOpacity(0.50);
00847                                         _fillObjectActor->SetPosition(px, py, 1);
00848                                         _aPolygonMapper->Modified();
00849                                 } // if GPORT
00850 
00851                         } // for controllers it
00852                 }
00853         }
00854         if (okStatusMessage == false) {
00855                 updateStatusBar("");
00856         }
00857 
00858         if (okPortMessage == false) {
00859                 _textActor->SetScale(0.0001);
00860                 _fillObjectActor->SetScale(0.0001);
00861         }
00862         return true;
00863 }
00864 
00865 //=========================================================================
00866 
00867 bool wxVtkSceneManager::OnLeftButtonDown() {
00868 
00869         if (_worldState == INIT_CREATION_CONTOUR) {
00870                 bool isOverPort = false;
00871                 std::map<int, GObjectController*>::iterator it;
00872                 for (it = _controllers.begin(); it != _controllers.end() && isOverPort
00873                                 == false; ++it) {
00874                         GObjectController *desc = it->second;
00875                         if (desc->getGObjectType() == GPORT) {
00876                                 GPortModel *portmod = (GPortModel*) desc->getModel();
00877                                 vtkGObjectView *portView = desc->getView();
00878                                 if (portmod->getPortType() == GINPUTPORT
00879                                                 && portView->getState() == HIGHLIGHTED) {
00880                                         isOverPort = true;
00881                                  } // if
00882                                 // JGRR & CM                    
00883                                 if ( portmod->getPortType( ) == GINPUTPORT &&  portView->getState( ) == SELECTED_POSSIBLE_CONNECTION   ) {
00884                                     isOverPort = true ;
00885                                     portView->setState( HIGHLIGHTED);
00886                                 }                    
00887                                 // EO JGRR & CM 
00888 
00889                         } // if
00890                 } // for
00891 
00892                 if (isOverPort == false) {
00893                         CancelConnection();
00894                         UnSelectBlackBoxes();
00895                 } // isOverPort
00896         
00897 
00898         } else { //_worldState
00899 
00900                 _worldState = DRAG_OBJECTS;
00901                 _startDragging = true;
00902 
00903                 int shiftkey =
00904                                 _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
00905                 int ctrlkey =
00906                                 _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
00907                 ctrlkey = ctrlkey + shiftkey;
00908 
00909                 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
00910 
00911                 if (GetGBlackBoxControlerPointedByMouse() != NULL) {
00912                         int state = cont->getView()->getState();
00913                         if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
00914                                 UnSelectBlackBoxes();
00915                         }
00916                 }
00917                 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
00918                         int id = _selectedObjects[i];
00919                         GObjectController* cont = _controllers[id];
00920                         cont->getView()->setState(DRAG);
00921                         cont->getModel()->notifyObservers(_idManager);
00922                 } // for
00923                 
00924         } // if _selectedObjects.size
00925 
00926 
00927         return true;
00928 }
00929 
00930 //=========================================================================
00931 
00932 bool wxVtkSceneManager::OnLeftButtonUp() {
00933         if (_worldState == DRAG_OBJECTS) {
00934                 _worldState = NOTHING_HAPPENS;
00935 
00936                 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
00937                         int id = _selectedObjects[i];
00938                         GObjectController* cont = _controllers[id];
00939                         cont->getView()->setState(SELECTED);
00940                         cont->getModel()->notifyObservers(_idManager);
00941                 }
00942         }
00943         return true;
00944 }
00945 
00946 //=========================================================================
00947 void wxVtkSceneManager::CancelConnection() {
00948         if (_worldState == INIT_CREATION_CONTOUR) {
00949                 _worldState = NOTHING_HAPPENS;
00950                 //int lastId = _controllers.size()-1;
00951 
00952                 GConnectorController *connector =
00953                                 (GConnectorController*) _controllers[_idConnectionInCreation];
00954                 connector->removeFromScene();
00955                 unregisterController(connector);
00956                 _controllers.erase(_idConnectionInCreation);
00957 
00958                 std::map<int, GObjectController*>::iterator it;
00959                 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
00960                         GObjectController *desc = it->second;
00961                         desc->SetActive(true);
00962                         desc->getView()->setState(NOTHING_HAPPENS);
00963                         desc->getModel()->notifyObservers(_idManager);
00964                 } // for
00965         }// if
00966 }
00967 
00968 //=========================================================================
00969 
00970 bool wxVtkSceneManager::OnRightButtonUp() {
00971         if (_worldState == INIT_CREATION_CONTOUR) {
00972                 CancelConnection();
00973         }
00974         UnSelectBlackBoxes();
00975         return true;
00976 }
00977 
00979 
00980 bool wxVtkSceneManager::OnMiddleButtonDown() {
00981 
00982 
00983         this->_vtkInteractorStyleBaseView->StartPan();
00984 
00985         return true;
00986     }
00987 
00988 bool wxVtkSceneManager::OnMiddleButtonUp() {
00989 
00990 
00991         this->_vtkInteractorStyleBaseView->EndPan();
00992 
00993 
00994         return true;
00995     }
00996 
00997 
00998 //=========================================================================
00999 
01000 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
01001         GObjectController *result = NULL;
01002         int X, Y;
01003         wxVTKRenderWindowInteractor *wxVTKiren;
01004         wxVTKiren
01005                         = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
01006         wxVTKiren->GetEventPosition(X, Y);
01007 
01008         std::map<int, GObjectController*>::iterator it;
01009 
01010         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
01011                 GObjectController *cont = it->second;
01012                 int type = cont->getGObjectType();
01013 
01014                 if (cont->getView()->isPointInside(X, Y) == true) {
01015                         if (type == GBLACKBOX) {
01016                                 result = cont;
01017                         } // if type
01018                 } // if isPointInside
01019         } // for it
01020         return result;
01021 }
01022 
01023 //=========================================================================
01024 void wxVtkSceneManager::UnSelectBlackBoxes() {
01025         for (int i = 0; i < (int) _selectedObjects.size(); i++) {
01026                 int id = _selectedObjects[i];
01027                 GObjectController* control = _controllers[id];
01028                 control->getView()->setState(NOTHING_HAPPENS);
01029                 control->getModel()->notifyObservers(_idManager);
01030         }// for _selectedObjects
01031         _selectedObjects.clear();
01032 }
01033 
01034 //=========================================================================
01035 bool wxVtkSceneManager::OnLeftDClick() {
01036         GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
01037         if (cont != NULL) {
01038                 UnSelectBlackBoxes();
01039                 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
01040         }
01041 
01042         /*EED Borrame
01043 
01044          int X,Y;
01045          wxVTKRenderWindowInteractor *wxVTKiren;
01046          wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
01047          wxVTKiren->GetEventPosition(X,Y);
01048 
01049          std::map<int, GObjectController*>::iterator it;
01050 
01051          bool clickOnObject = false;
01052 
01053          for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
01054          {
01055          GObjectController *cont = it->second;
01056          int type = cont->getGObjectType();
01057 
01058          if(cont->getView()->isPointInside(X,Y))
01059          {
01060          if(type==GBLACKBOX)
01061          {
01062          for (int i=0; i< (int)_selectedObjects.size(); i++)
01063          {
01064          int id = _selectedObjects[i];
01065          GObjectController* control = _controllers[id];
01066          control->getView()->setState(NOTHING_HAPPENS);
01067          }
01068          _selectedObjects.clear();
01069 
01070          GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
01071          _parent->editBlackBox(bbmodel);
01072          }
01073          clickOnObject = true;
01074          }
01075          }
01076 
01077          if(clickOnObject==false)
01078          {
01079          //_parent->editDiagramParameters(this);
01080          }
01081          */
01082         return true;
01083 }
01084 
01085 //=========================================================================
01086 
01087 bool wxVtkSceneManager::OnChar() {
01088         char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
01089         int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
01090         
01091         // KeyCode 127 : Delete Key
01092         // KeyCode 8 : Backspace Key
01093         if (keyCode == 8 || keyCode == 127) {
01094                 if (_selectedObjects.size() > 0) {
01095                         for (int i = 0; i < (int) _selectedObjects.size(); i++) {
01096                                 int id = _selectedObjects[i];
01097                                 std::map<int, GObjectController*>::iterator it;
01098                                 it = _controllers.find(id);
01099                                 if (it != _controllers.end()) {
01100                                         deleteObject(id);
01101                                 }
01102                         }
01103                         _selectedObjects.clear();
01104                 }
01105         }
01106         ctrlkey+=keyCode;
01108              if(ctrlkey==5){                
01109                 if(_selectedObjects.size()){
01110                     std::cout<<"objects to copy :";
01111                     for(int i=0;i<_selectedObjects.size();i++){
01112                        std::cout<<_selectedObjects.at(i)<<" ";
01113                     }
01114                     DuplicateObjects(getSelectedObjects());   
01115                 }else{
01116                     std::cout<<"No objects to copy\n";
01117                 }
01118             }  
01119 
01120         return true;
01121 }
01122 
01123 //=========================================================================
01124 
01125 void wxVtkSceneManager::AddControlerToBeRemove(
01126                 std::vector<int> *controllersToRemove, int id) {
01127 
01128         int i;
01129         bool ok = true;
01130         for (i = 0; i < (int) controllersToRemove->size(); i++) {
01131                 if (id == (*controllersToRemove)[i]) {
01132                         ok = false;
01133                 }
01134         }
01135 
01136         if (ok == true) {
01137                 controllersToRemove->push_back(id);
01138         }
01139 
01140 }
01141 
01142 //=========================================================================
01143 
01144 void wxVtkSceneManager::deleteObject(int id) {
01145         GObjectController *control = _controllers[id];
01146         std::vector<int> controllersToRemove;
01147 
01148         if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
01149                         == GCOMPLEXINPUTPORT || control->getGObjectType()
01150                         == GCOMPLEXOUTPUTPORT) {
01151                 GBoxModel *bbmod = (GBoxModel*) control->getModel();
01152                 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
01153 
01154                 bool boxConnected = false;
01155 
01156                 // Add box input controllers to be removed
01157                 for (int i = 0; i < (int) inputs.size(); i++) {
01158                         AddControlerToBeRemove(&controllersToRemove,
01159                                         inputs[i]->getObjectId());
01160                         if (inputs[i]->isConnected()) {
01161                                 boxConnected = true;
01162                         }
01163                 }
01164 
01165                 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
01166 
01167                 // Add box output controllers to be removed
01168                 for (int i = 0; i < (int) outputs.size(); i++) {
01169                         AddControlerToBeRemove(&controllersToRemove,
01170                                         outputs[i]->getObjectId());
01171                         if (outputs[i]->isConnected()) {
01172                                 boxConnected = true;
01173                         }
01174                 }
01175 
01176                 // Add connection controllers to be removed
01177                 std::map<int, GObjectController*>::iterator it;
01178                 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
01179                         GObjectController *cont = it->second;
01180                         int type = cont->getGObjectType();
01181                         if (type == GCONNECTOR) {
01182                                 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
01183                                 if (conMod->getStartPort() != NULL
01184                                                 && conMod->getStartPort()->getParentBox()->getObjectId()
01185                                                                 == bbmod->getObjectId()) {
01186                                         AddControlerToBeRemove(&controllersToRemove,
01187                                                         conMod->getObjectId());
01188                                 }
01189                                 if (conMod->getEndPort() != NULL
01190                                                 && conMod->getEndPort()->getParentBox()->getObjectId()
01191                                                                 == bbmod->getObjectId()) {
01192                                         AddControlerToBeRemove(&controllersToRemove,
01193                                                         conMod->getObjectId());
01194                                 }
01195                         }
01196                 }
01197 
01198                 // Add box controller to be removed
01199                 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
01200         } else if (control->getGObjectType() == GCONNECTOR) {
01201                 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
01202                 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
01203         }
01204 
01205         std::map<int, GObjectController*>::iterator it;
01206 
01207         for (int i = 0; i < (int) controllersToRemove.size(); i++) {
01208                 int key = controllersToRemove[i];
01209                 it = _controllers.find(key);
01210                 GObjectController *cont = _controllers[key];
01211                 if (cont != NULL) {
01212                         cont->removeFromScene();
01213                         unregisterController((InteractorStyleMaracas*) cont);
01214                         _controllers.erase(it);
01215                 }//if
01216         }// for
01217         _parent->saveTempandUpdate("delete object");
01218 }
01219 
01220 //=========================================================================
01221 
01222 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
01223                 std::string boxName) {
01224         _parent->displayBlackBoxInfo(packageName, boxName);
01225 }
01226 
01227 //=========================================================================
01228 
01229 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
01230         _parent->updateStatusBar(textStatus);
01231 }
01232 
01233 //=========================================================================
01234 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
01235         std::string result = "";
01236         if (withLineNumber == true) {
01237                 value++;
01238                 stringstream StrStream;
01239                 StrStream << value;
01240                 std::string strValue = StrStream.str();
01241                 if (value < 10) {
01242                         result += "  ";
01243                 } else if (value < 100) {
01244                         result += " ";
01245                 }
01246 
01247                 result += strValue + ": ";
01248         }
01249         return result;
01250 }
01251 //=========================================================================
01252 //DFCH
01253 bool wxVtkSceneManager::MakeBoxExecutable() {
01254         std::map<int, GObjectController*> selected = getSelectedObjects();
01255         if( selected.empty() )
01256                 return false;
01257         bool ret = false;
01258         std::map<int, GObjectController*>::iterator it;
01259         for (it = selected.begin(); it != selected.end(); ++it) {
01260                 GObjectController* lastSelected = it->second;
01261                 if (lastSelected) {
01262                         vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
01263                         GBlackBoxModel *bbmodel =
01264                                         (GBlackBoxModel*) lastSelected->getModel();
01265                         view->setState(HIGHLIGHTED);
01266                         if (bbmodel->isExecutable()) {
01267                                 bbmodel->setExecutable(false);
01268                         } else {
01269                                 bbmodel->setExecutable(true);
01270                         }
01271                         bbmodel->notifyObservers(lastSelected->getId());
01272                         ret = true;
01273                 }
01274         }
01275         return ret;
01276 }
01277 //DFCH
01278 
01279 //=========================================================================
01280 
01281 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
01282         bool existsExec = false;
01283 
01284         std::vector<std::string> packages;
01285         std::vector<int> boxes;
01286         std::vector<int> connections;
01287         std::vector<int> execBoxes;
01288 
01289         std::map<int, GObjectController*>::iterator it;
01290 
01291         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
01292                 GObjectController *desc = it->second;
01293                 int type = desc->getGObjectType();
01294 
01295                 if (type == GBLACKBOX) {
01296                         GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
01297 
01298                         std::string pkg = mod->getBBTKPackage();
01299                         bool existsPkg = false;
01300                         for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
01301                                 if (packages[t] == pkg) {
01302                                         existsPkg = true;
01303                                 }
01304                         }
01305                         if (!existsPkg) {
01306                                 packages.push_back(pkg);
01307                         }
01308 
01309                         boxes.push_back(it->first);
01310                         if (mod->isExecutable()) {
01311                                 execBoxes.push_back(it->first);
01312                                 existsExec = true;
01313                         }
01314                 } else if (type == GCONNECTOR) {
01315                         connections.push_back(it->first);
01316                 }
01317         }
01318 
01319         int lnNmbr = 0;
01320         std::string script = "";
01321         script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
01322         script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
01323         script += LineNumber(wln, lnNmbr) + "\n";
01324         if (existsExec) {
01325                 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
01326                 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
01327                 int i;
01328                 for (i = 0; i < (int) packages.size(); i++) {
01329                         script += LineNumber(wln, lnNmbr);
01330                         script += "include ";
01331                         script += packages[i];
01332                         script += "\n";
01333                 }
01334 
01335                 script += LineNumber(wln, lnNmbr);
01336                 script += "\n";
01337 
01338                 //ups2
01339 
01340                 script += LineNumber(wln, lnNmbr);
01341                 script += "author \"";
01342                 script += _Author;
01343                 script += "\"\n";
01344 
01345                 script += LineNumber(wln, lnNmbr);
01346                 script += "description \"";
01347                 script += _Description;
01348                 script += "\"\n";
01349 
01350                 script += LineNumber(wln, lnNmbr);
01351                 script += "category \"";
01352                 script += _Category;
01353                 script += "\"\n";
01354 
01355                 script += LineNumber(wln, lnNmbr);
01356                 script += "\n";
01357 
01358                 // script+="include std\n"; // JPR
01359 
01360                 for (i = 0; i < (int) boxes.size(); i++) {
01361                         script += LineNumber(wln, lnNmbr);
01362                         script += "new ";
01363                         int id = boxes[i];
01364                         GObjectController *control = _controllers[id];
01365                         GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
01366 
01367                         script += model->getBBTKType();
01368                         script += " ";
01369                         script += model->getBBTKName();
01370                         script += "\n";
01371 
01372                         std::vector<GPortModel*> inputs = model->getInputPorts();
01373                         for (int j = 0; j < (int) inputs.size(); j++) {
01374                                 GPortModel* inputPort = inputs[j];
01375                                 if (inputPort->isValueSet()) {
01376                                         script += LineNumber(wln, lnNmbr);
01377                                         script += "  set ";
01378                                         script += model->getBBTKName();
01379                                         script += ".";
01380                                         script += inputPort->getBBTKName();
01381                                         script += " ";
01382                                         script += inputPort->getValue();
01383                                         script += "\n";
01384                                 }
01385                         }
01386 
01387                         script += LineNumber(wln, lnNmbr);
01388                         script += "\n";
01389 
01390                 }
01391 
01392                 script += LineNumber(wln, lnNmbr);
01393                 script += "\n";
01394 
01395                 for (i = 0; i < (int) connections.size(); i++) {
01396                         script += LineNumber(wln, lnNmbr);
01397                         script += "connect ";
01398                         int id = connections[i];
01399                         GObjectController *control = _controllers[id];
01400                         GConnectorModel *model = (GConnectorModel*) control->getModel();
01401 
01402                         //Start Connection info
01403                         GPortModel *start = model->getStartPort();
01404                         script += start->getParentBox()->getBBTKName();
01405                         script += ".";
01406                         script += start->getBBTKName();
01407 
01408                         script += " ";
01409 
01410                         //End Connection info
01411                         GPortModel *end = model->getEndPort();
01412                         script += end->getParentBox()->getBBTKName();
01413                         script += ".";
01414                         script += end->getBBTKName();
01415 
01416                         script += "\n";
01417                 }
01418 
01419                 script += LineNumber(wln, lnNmbr);
01420                 script += "\n";
01421                 for (i = 0; i < (int) execBoxes.size(); i++) {
01422                         script += LineNumber(wln, lnNmbr);
01423                         script += "exec ";
01424                         int id = execBoxes[i];
01425                         GObjectController *control = _controllers[id];
01426                         GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
01427 
01428                         script += model->getBBTKName();
01429                         script += "\n";
01430                 }
01431 
01432         }
01433 
01434         return script;
01435 }
01436 
01437 //=========================================================================
01438 
01439 std::string wxVtkSceneManager::saveComplexBoxBBS() {
01440         std::vector<std::string> packages;
01441         std::vector<int> boxes;
01442         std::vector<int> connections;
01443         std::vector<int> execBoxes;
01444 
01445         std::map<int, GObjectController*>::iterator it;
01446 
01447         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
01448                 GObjectController *desc = it->second;
01449                 int type = desc->getGObjectType();
01450 
01451                 if (type == GBLACKBOX) {
01452                         GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
01453 
01454                         std::string pkg = mod->getBBTKPackage();
01455                         bool existsPkg = false;
01456                         for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
01457                                 if (packages[t] == pkg) {
01458                                         existsPkg = true;
01459                                 }
01460                         }
01461                         if (!existsPkg) {
01462                                 packages.push_back(pkg);
01463                         }
01464 
01465                         boxes.push_back(it->first);
01466                         if (mod->isExecutable()) {
01467                                 execBoxes.push_back(it->first);
01468                         }
01469                 } else if (type == GCONNECTOR) {
01470                         connections.push_back(it->first);
01471                 }
01472         }
01473 
01474         std::string script = "";
01475 
01476         script += "include std\n"; // EED
01477         script += "include itkvtk\n"; // EED
01478         int i;
01479         for (i = 0; i < (int) packages.size(); i++) {
01480                 script += "include ";
01481                 script += packages[i];
01482                 script += "\n";
01483         }
01484         script += "\n";
01485 
01486         // Definition of a complex box
01487         script += "define ";
01488         script += _cbName + " " + _cbPackageName;
01489         script += "\n";
01490         script += "\n";
01491 
01492         script += "author \"";
01493         script += _Author;
01494         script += "\"\n";
01495 
01496         script += "description \"";
01497         script += _Description;
01498         script += "\"\n";
01499         script += "\n";
01500 
01501         script += "category \"";
01502         script += _Category;
01503         script += "\"\n";
01504         script += "\n";
01505 
01506         // Create boxes
01507         for (i = 0; i < (int) boxes.size(); i++) {
01508                 script += "new ";
01509                 int id = boxes[i];
01510                 GObjectController *control = _controllers[id];
01511                 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
01512 
01513                 script += model->getBBTKType();
01514                 script += " ";
01515                 script += model->getBBTKName();
01516                 script += "\n";
01517 
01518                 std::vector<GPortModel*> inputs = model->getInputPorts();
01519                 for (int j = 0; j < (int) inputs.size(); j++) {
01520                         GPortModel* inputPort = inputs[j];
01521                         if (inputPort->isValueSet()) {
01522                                 script += "  set ";
01523                                 script += model->getBBTKName();
01524                                 script += ".";
01525                                 script += inputPort->getBBTKName();
01526                                 script += " ";
01527                                 script += inputPort->getValue();
01528                                 script += "\n";
01529                         }
01530                 }
01531                 script += "\n";
01532 
01533         }
01534 
01535         // Create connections in the script. If the connection is made with a complex port, it is created the input or output
01536 
01537         std::string complexInputs = "";
01538         std::string complexOutputs = "";
01539         script += "\n";
01540 
01541         for (i = 0; i < (int) connections.size(); i++) {
01542                 int id = connections[i];
01543                 GObjectController *control = _controllers[id];
01544                 GConnectorModel *model = (GConnectorModel*) control->getModel();
01545 
01546                 //Connection info
01547                 GPortModel *start = model->getStartPort();
01548                 GBoxModel *startBox = start->getParentBox();
01549 
01550                 GPortModel *end = model->getEndPort();
01551                 GBoxModel *endBox = end->getParentBox();
01552 
01553                 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
01554                         complexInputs += "input ";
01555                         complexInputs += startBox->getBBTKName();
01556 
01557                         complexInputs += " ";
01558                         complexInputs += endBox->getBBTKName();
01559                         complexInputs += ".";
01560                         complexInputs += end->getBBTKName();
01561 
01562                         complexInputs += " ";
01563                         complexInputs += "\" \"";
01564 
01565                         complexInputs += "\n";
01566                 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
01567                         complexOutputs += "output ";
01568                         complexOutputs += endBox->getBBTKName();
01569 
01570                         complexOutputs += " ";
01571                         complexOutputs += startBox->getBBTKName();
01572                         complexOutputs += ".";
01573                         complexOutputs += start->getBBTKName();
01574 
01575                         complexOutputs += " ";
01576                         complexOutputs += "\" \"";
01577 
01578                         complexOutputs += "\n";
01579                 } else {
01580                         script += "connect ";
01581                         script += startBox->getBBTKName();
01582                         script += ".";
01583                         script += start->getBBTKName();
01584 
01585                         script += " ";
01586 
01587                         //End Connection info
01588                         script += endBox->getBBTKName();
01589                         script += ".";
01590                         script += end->getBBTKName();
01591 
01592                         script += "\n";
01593                 }
01594         }
01595 
01596         script += "\n";
01597 
01598         for (i = 0; i < (int) execBoxes.size(); i++) {
01599                 script += "exec ";
01600                 int id = execBoxes[i];
01601                 GObjectController *control = _controllers[id];
01602                 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
01603 
01604                 script += model->getBBTKName();
01605                 script += "\n";
01606         }
01607 
01608         script += "\n";
01609         script += "# Complex input ports\n";
01610         script += complexInputs;
01611 
01612         script += "\n";
01613         script += "# Complex output ports\n";
01614         script += complexOutputs;
01615 
01616         script += "\n";
01617         script += "endefine";
01618         script += "\n";
01619 
01620         return script;
01621 }
01622 
01623 //=========================================================================
01624 
01625 void wxVtkSceneManager::deleteAllBoxes() {
01626         std::map<int, GObjectController*>::iterator it;
01627         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
01628                 GObjectController *cont = it->second;
01629                 cont->removeFromScene();
01630                 unregisterController((InteractorStyleMaracas*) cont);
01631         }
01632         _selectedObjects.clear();
01633         _controllers.clear();
01634 }
01635 
01636 //=========================================================================
01637 
01638 
01639 void wxVtkSceneManager::refresh() {
01640         _baseView->Refresh();
01641 }
01642 //=========================================================================
01643 
01644 void wxVtkSceneManager::refreshScene() {
01645         _baseView->RefreshView();
01646 }
01647 
01648 //=========================================================================
01649 
01650 void wxVtkSceneManager::centerView() {
01651         double temp[3];
01652         _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
01653         _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
01654         _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
01655         _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
01656 }
01657 
01658 //=========================================================================
01659 
01660 void wxVtkSceneManager::saveDiagram(std::string &content) {
01661         char buffer[50];
01662 
01663         content += "CATEGORY:";
01664         content += GetCategory();
01665         content += "\n";
01666 
01667         content += "DESCRIPTION:";
01668         content += GetDescription();
01669         content += "\n";
01670 
01671         content += "AUTHOR:";
01672         content += GetAuthor();
01673         content += "\n";
01674 
01675         //Print info IF COMPLEX BOX
01676         content += "COMPLEXBOX:";
01677         if (_isComplexBox) {
01678                 content += "TRUE\n";
01679                 //ups1
01680                 content += "COMPLEXBOXNAME:";
01681                 content += GetCbName();
01682                 content += "\n";
01683 
01684                 content += "PACKAGENAME:";
01685                 content += GetCbPackageName();
01686                 content += "\n";
01687 
01688                 //Print info complex input ports
01689                 std::vector<int> inputs = getComplexInputPorts();
01690                 int insize = inputs.size();
01691                 content += "COMPLEXINPUTS:";
01692                 sprintf(buffer, "%d", insize);
01693                 content += buffer;
01694                 content += "\n";
01695 
01696                 for (int i = 0; i < insize; i++) {
01697                         int id = inputs[i];
01698                         GObjectController *cont = _controllers[id];
01699                         cont->getModel()->save(content);
01700                 }
01701 
01702                 //Print info complex output ports
01703                 std::vector<int> outputs = getComplexOutputPorts();
01704                 int outsize = outputs.size();
01705                 content += "COMPLEXOUTPUTS:";
01706                 sprintf(buffer, "%d", outsize);
01707                 content += buffer;
01708                 content += "\n";
01709 
01710                 for (int i = 0; i < outsize; i++) {
01711                         int id = outputs[i];
01712                         GObjectController *cont = _controllers[id];
01713                         cont->getModel()->save(content);
01714                 }
01715         } // _isComplexBox
01716         else {
01717                 content += "FALSE\n";
01718         }
01719 
01720         //Print boxes
01721         std::vector<int> boxes = getBlackBoxes();
01722         int bsize = boxes.size();
01723         content += "BOXES:";
01724         sprintf(buffer, "%d", bsize);
01725         content += buffer;
01726         content += "\n";
01727 
01728         for (int i = 0; i < bsize; i++) {
01729                 int id = boxes[i];
01730                 GObjectController *cont = _controllers[id];
01731                 cont->getModel()->save(content);
01732         }
01733 
01734         //Print connections
01735         std::vector<int> connections = getConnections();
01736         int csize = connections.size();
01737         content += "CONNECTIONS:";
01738         sprintf(buffer, "%d", csize);
01739         content += buffer;
01740         content += "\n";
01741 
01742         for (int i = 0; i < csize; i++) {
01743                 int id = connections[i];
01744                 GObjectController *cont = _controllers[id];
01745                 cont->getModel()->save(content);
01746         }
01747 
01748 }
01749 
01750 //=========================================================================
01751 
01752 void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
01753 
01754         std::string version = "<void>";
01755         std::string line = "";
01756         char delims[] = ":";
01757         char *result = NULL;
01758 
01759         getline(inputStream, line);
01760 
01761         bool start = false;
01762         while (!inputStream.eof()) {
01763                 if (line == "" || line[0] == '#') {
01764                         getline(inputStream, line);
01765                         if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
01766                                 version = line.substr(18, 3);
01767                         }
01768                         if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
01769                                 version = line.substr(18, 3);
01770                         }
01771                         if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
01772                                 version = line.substr(18, 3);
01773                         }
01774                 } else if (line == "APP_START") {
01775                         start = true;
01776                         break;
01777                 }
01778         }
01779 
01780         printf("EED wxVtkSceneManager::loadDiagram  version=%s\n", version.c_str());
01781 
01782         if (start) {
01783 
01784                 if ((version != "1.0") && (version != "1.1")) {
01785                         getline(inputStream, line);//CATEGORY:<category of the box>
01786                         char categoryTmp[30];
01787                         strcpy(categoryTmp, line.c_str());
01788                         result = strtok(categoryTmp, delims);
01789                         result = strtok(NULL, delims);
01790                         SetCategory(result);
01791 
01792                         getline(inputStream, line);//DESCRIPTION:<description of the box>
01793                         char descriptionTmp[1024];
01794                         strcpy(descriptionTmp, line.c_str());
01795                         result = strtok(descriptionTmp, delims);
01796                         result = strtok(NULL, delims);
01797                         SetDescription(result);
01798 
01799                         getline(inputStream, line);//AUTHOR:<author>
01800                         char authorTmp[255];
01801                         strcpy(authorTmp, line.c_str());
01802                         result = strtok(authorTmp, delims);
01803                         result = strtok(NULL, delims);
01804                         SetAuthor(result);
01805                 }
01806 
01807                 //----------
01808                 getline(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
01809                 char complexTmp[30];
01810                 strcpy(complexTmp, line.c_str());
01811                 result = strtok(complexTmp, delims);
01812                 result = strtok(NULL, delims);
01813                 std::string isComplexBox(result);
01814 
01815                 if (isComplexBox == "TRUE") {
01816                         _isComplexBox = true;
01817 
01818                         if ((version != "1.0") && (version != "1.1")) {
01819                                 getline(inputStream, line);//COMPLEXNAME:<name of the complex box>
01820                                 char complexboxnameTmp[255];
01821                                 strcpy(complexboxnameTmp, line.c_str());
01822                                 result = strtok(complexboxnameTmp, delims);
01823                                 result = strtok(NULL, delims);
01824                                 SetCbName(result);
01825 
01826                                 getline(inputStream, line);//PACKAGENAME:<name of the package of the box>
01827                                 char packagenameTmp[255];
01828                                 strcpy(packagenameTmp, line.c_str());
01829                                 result = strtok(packagenameTmp, delims);
01830                                 result = strtok(NULL, delims);
01831                                 SetCbPackageName(result);
01832                         }
01833 
01834                         //-----------------------
01835                         //- COMPLEX INPUT PORTS
01836                         //-----------------------
01837                         getline(inputStream, line);//COMPLEXINPUTS:num
01838                         char inputs[30];
01839                         strcpy(inputs, line.c_str());
01840                         result = strtok(inputs, delims);
01841                         result = strtok(NULL, delims);
01842 
01843                         int numInputs;
01844                         std::istringstream inps(result);
01845                         inps >> numInputs;
01846 
01847                         for (int i = 0; i < numInputs; i++) {
01848                                 //----------
01849                                 getline(inputStream, line);//COMPLEX_PORT
01850                                 getline(inputStream, line);//name
01851                                 std::string inputPortName(line);
01852 
01853                                 //----------
01854                                 getline(inputStream, line);//xInic:yInic:zInic
01855                                 char coord[80];
01856                                 strcpy(coord, line.c_str());
01857                                 result = strtok(coord, delims);//xInic
01858                                 std::string xInic(result);
01859                                 result = strtok(NULL, delims);//yInic
01860                                 std::string yInic(result);
01861                                 result = strtok(NULL, delims);//zInic
01862                                 std::string zInic(result);
01863 
01864                                 double xIn, yIn, zIn;
01865                                 std::istringstream xSt(xInic);
01866                                 xSt >> xIn;
01867                                 std::istringstream ySt(yInic);
01868                                 ySt >> yIn;
01869                                 std::istringstream zSt(zInic);
01870                                 zSt >> zIn;
01871 
01872                                 getline(inputStream, line);//FIN_COMPLEX_PORT
01873 
01874                                 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
01875 
01876                         } // for input complex box
01877 
01878 
01879                         //-----------------------
01880                         //- COMPLEX OUTPUT PORTS
01881                         //-----------------------
01882 
01883                         getline(inputStream, line);//COMPLEXOUTPUTS:num
01884                         char outputs[30];
01885                         strcpy(outputs, line.c_str());
01886                         result = strtok(outputs, delims);
01887                         result = strtok(NULL, delims);
01888 
01889                         int numOutputs;
01890                         std::istringstream outps(result);
01891                         outps >> numOutputs;
01892 
01893                         for (int i = 0; i < numOutputs; i++) {
01894                                 //----------
01895                                 getline(inputStream, line);//COMPLEX_PORT
01896                                 getline(inputStream, line);//name
01897                                 std::string outputPortName(line);
01898 
01899                                 //----------
01900                                 getline(inputStream, line);//xInic:yInic:zInic
01901                                 char coord[80];
01902                                 strcpy(coord, line.c_str());
01903                                 result = strtok(coord, delims);//xInic
01904                                 std::string xInic(result);
01905                                 result = strtok(NULL, delims);//yInic
01906                                 std::string yInic(result);
01907                                 result = strtok(NULL, delims);//zInic
01908                                 std::string zInic(result);
01909 
01910                                 double xIn, yIn, zIn;
01911                                 std::istringstream xSt(xInic);
01912                                 xSt >> xIn;
01913                                 std::istringstream ySt(yInic);
01914                                 ySt >> yIn;
01915                                 std::istringstream zSt(zInic);
01916                                 zSt >> zIn;
01917 
01918                                 getline(inputStream, line);//FIN_COMPLEX_PORT
01919 
01920                                 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn,
01921                                                 zIn);
01922 
01923                         } // for output complex box
01924 
01925                 } // complex box
01926 
01927                 //----------
01928                 getline(inputStream, line);//BOXES:num
01929                 char boxes[9];
01930                 strcpy(boxes, line.c_str());
01931                 result = strtok(boxes, delims);
01932                 result = strtok(NULL, delims);
01933 
01934                 int numBoxes;
01935                 std::istringstream is(result);
01936                 is >> numBoxes;
01937 
01938                 for (int i = 0; i < numBoxes; i++) {
01939                         //----------
01940                         getline(inputStream, line);//BOX
01941                         getline(inputStream, line);//package:type:name
01942                         char box[150];
01943                         strcpy(box, line.c_str());
01944                         result = strtok(box, delims);//package
01945                         std::string package(result);
01946                         result = strtok(NULL, delims);//type
01947                         std::string type(result);
01948                         result = strtok(NULL, delims);//name
01949                         std::string name(result);
01950 
01951                         getline(inputStream, line);//ISEXEC:TRUE|FALSE
01952                         char exec[15];
01953                         strcpy(exec, line.c_str());
01954                         result = strtok(exec, delims);//ISEXEC
01955                         result = strtok(NULL, delims);//TRUE|FALSE
01956                         std::string isExec(result);
01957 
01958                         //----------
01959                         getline(inputStream, line);//xInic:yInic:zInic
01960                         char coord[80];
01961                         strcpy(coord, line.c_str());
01962                         result = strtok(coord, delims);//xInic
01963                         std::string xInic(result);
01964                         result = strtok(NULL, delims);//yInic
01965                         std::string yInic(result);
01966                         result = strtok(NULL, delims);//zInic
01967                         std::string zInic(result);
01968 
01969                         double xIn, yIn, zIn;
01970                         std::istringstream xSt(xInic);
01971                         xSt >> xIn;
01972                         std::istringstream ySt(yInic);
01973                         ySt >> yIn;
01974                         std::istringstream zSt(zInic);
01975                         zSt >> zIn;
01976 
01977                         //----------
01978                         getline(inputStream, line);//xEnd:yEnd:zEnd
01979                         strcpy(coord, line.c_str());
01980                         result = strtok(coord, delims);//xEnd
01981                         std::string xEnd(result);
01982                         result = strtok(NULL, delims);//yEnd
01983                         std::string yEnd(result);
01984                         result = strtok(NULL, delims);//zEnd
01985                         std::string zEnd(result);
01986 
01987                         double xEn, yEn, zEn;
01988                         std::istringstream xEt(xEnd);
01989                         xEt >> xEn;
01990                         std::istringstream yEt(yEnd);
01991                         yEt >> yEn;
01992                         std::istringstream zEt(zEnd);
01993                         zEt >> zEn;
01994 
01995                         bool boxExecutable = false;
01996                         if (isExec == "TRUE") {
01997                                 boxExecutable = true;
01998                         }
01999 
02000                         int idBox = createGBlackBox(xIn, yIn, package, type);
02001                         configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn,
02002                                         yEn, zEn);
02003 
02004                         GObjectController *cont = _controllers[idBox];
02005                         GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
02006 
02007                         //----------
02008                         getline(inputStream, line);//PORT o FIN_BOX
02009                         std::string port = line.substr(0, 4);
02010                         while (port == "PORT") {
02011                                 getline(inputStream, line);//name:value
02012                                 char poort[150];
02013                                 strcpy(poort, line.c_str());
02014                                 result = strtok(poort, delims);//name
02015                                 std::string name(result);
02016                                 result = strtok(NULL, delims);//value
02017                                 std::string value(result);
02018 
02019                                 bbmod->setValueToInput(name, value);
02020 
02021                                 getline(inputStream, line);//PORT o FIN_BOX
02022                                 port = line.substr(0, 4);
02023                         } // while
02024 
02025                         //EED                           bbmod->notifyObservers(_idManager);
02026                 } // for boxes
02027 
02029                 //----------
02030                 getline(inputStream, line);//CONNECTIONS:num
02031                 char conns[30];
02032                 strcpy(conns, line.c_str());
02033                 result = strtok(conns, delims);
02034                 result = strtok(NULL, delims);
02035 
02036                 int numConns;
02037                 std::istringstream isCons(result);
02038                 isCons >> numConns;
02039 
02040                 for (int i = 0; i < numConns; i++) {
02041                         //----------
02042                         getline(inputStream, line);//CONNECTION
02043                         getline(inputStream, line);//Startbox.PortName:EndBox.PortName
02044 
02045                         char connec[200];
02046                         strcpy(connec, line.c_str());
02047                         result = strtok(connec, delims);
02048                         std::string nameStartBox(result);
02049                         result = strtok(NULL, delims);
02050                         std::string nameStartPort(result);
02051                         result = strtok(NULL, delims);
02052                         std::string nameEndBox(result);
02053                         result = strtok(NULL, delims);
02054                         std::string nameEndPort(result);
02055 
02056                         int idCon = configGConnetion(nameStartBox, nameStartPort,
02057                                         nameEndBox, nameEndPort);
02058 
02059                         if (version != "1.0") {
02060                                 //Readding control points of the manualContour
02061                                 //ups1
02062                                 GConnectorController *tempp =
02063                                                 (GConnectorController*) _controllers[idCon];
02064                                 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
02065                                 vtkGConnectorView *conView =
02066                                                 (vtkGConnectorView*) tempp->getView();
02067                                 getline(inputStream, line); //NumberOfControlPoints:##
02068                                 strcpy(conns, line.c_str());
02069                                 result = strtok(conns, delims);
02070                                 result = strtok(NULL, delims);
02071 
02072                                 int numberOfControlPoints;
02073                                 std::istringstream isCons(result);
02074                                 isCons >> numberOfControlPoints;
02075 
02076                                 for (int ii = 0; ii < numberOfControlPoints; ii++) {
02077                                         getline(inputStream, line); //XX:YY:ZZ
02078                                         char connec[200];
02079                                         strcpy(connec, line.c_str());
02080 
02081                                         double px, py, pz;
02082                                         result = strtok(connec, delims);
02083                                         std::istringstream isPointX(result);
02084                                         isPointX >> px;
02085                                         result = strtok(NULL, delims);
02086                                         std::istringstream isPointY(result);
02087                                         isPointY >> py;
02088                                         result = strtok(NULL, delims);
02089                                         std::istringstream isPointZ(result);
02090                                         isPointZ >> pz;
02091 
02092                                         conMod->getManualContourModel()->InsertPoint_id(ii + 1, px,
02093                                                         py, pz);
02094                                         conView->getManualContourView()->AddPoint();
02095                                 }
02096                         }// version !=1.0
02097 
02098                 } // for numConns
02099 
02100         } // start
02101 
02102 }
02103 //=========================================================================
02104 
02105 
02106 //=========================================================================
02107 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
02108                 std::string portName, double xIn, double yIn, double zIn) {
02109         int idPort;
02110         if (inputoutput == true) {
02111                 idPort = createGComplexBoxInputPort(portName);
02112         } else {
02113                 idPort = createGComplexBoxOutputPort(portName);
02114         }
02115         GObjectController *cont = _controllers[idPort];
02116         GBoxModel *cbmod = (GBoxModel*) cont->getModel();
02117         cbmod->setInicPoint(xIn, yIn, zIn);
02118         cbmod->notifyObservers(_idManager);
02119 }
02120 //=========================================================================
02121 
02122 
02123 //=========================================================================
02124 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
02125         int j;
02126         int idB;
02127         GBoxModel *bMod;
02128         GBoxModel *boxModel = NULL;
02129         std::vector<int> lstB = getBlackBoxes();
02130         for (j = 0; j < (int) lstB.size(); j++) {
02131                 idB = lstB[j];
02132                 bMod = (GBoxModel*) _controllers[idB]->getModel();
02133                 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
02134                         boxModel = bMod;
02135                 }
02136         } // for
02137 
02138         if ((_isComplexBox) && (boxModel == NULL)) {
02139                 std::vector<int> lstInputs = getComplexInputPorts();
02140                 for (j = 0; j < (int) lstInputs.size(); j++) {
02141                         idB = lstInputs[j];
02142                         bMod = (GBoxModel*) _controllers[idB]->getModel();
02143                         if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
02144                                 boxModel = bMod;
02145                         }
02146                 } // for
02147 
02148                 std::vector<int> lstOutputs = getComplexOutputPorts();
02149                 for (j = 0; j < (int) lstOutputs.size(); j++) {
02150                         int idB = lstOutputs[j];
02151                         bMod = (GBoxModel*) _controllers[idB]->getModel();
02152                         if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
02153                                 boxModel = bMod;
02154                         }
02155                 } // for
02156 
02157         } // complex box
02158 
02159         return boxModel;
02160 }
02161 
02162 //=========================================================================
02163 
02164 
02165 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
02166                 std::string nameStartPort, std::string nameEndBox,
02167                 std::string nameEndPort) {
02168 
02169         GBoxModel *boxModel;
02170         GPortModel *startP = NULL;
02171         GPortModel *endP = NULL;
02172 
02173         boxModel = findGBox(nameStartBox);
02174         if (boxModel != NULL) {
02175                 startP = boxModel->getOutputPort(nameStartPort);
02176                 if(startP == NULL){
02177                         printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port %s is null. Port name is probably wrong.\n", nameStartPort.c_str());
02178                 }
02179         }
02180 
02181         boxModel = findGBox(nameEndBox);
02182         if (boxModel != NULL) {
02183                 endP = boxModel->getInputPort(nameEndPort);
02184                 if(endP == NULL){
02185                         printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port %s is null. Port name is probably wrong\n", nameStartPort.c_str(), nameEndPort.c_str());
02186                 }
02187         }
02188 
02189         //ups2
02190         int idCon = createGConnector(startP);
02191         _worldState = NOTHING_HAPPENS;
02192         GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
02193 
02194         GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
02195         vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
02196         tempp->endContourCreation();
02197         conMod->setEndPort(endP);
02198         conView->updateStartEndPoints();
02199         return idCon;
02200 }
02201 
02202 //=========================================================================
02203 
02204 bool wxVtkSceneManager::boxExist(std::string boxname) {
02205         bool ok = false;
02206         std::map<int, GObjectController*>::iterator it;
02207         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
02208                 GObjectController *cont = it->second;
02209                 if (cont->getModel()->getBBTKName() == boxname) {
02210                         ok = true;
02211                 }
02212         }
02213         return ok;
02214 }
02215 
02216 //=========================================================================
02217 
02218 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
02219         std::vector<int> vect;
02220         std::map<int, GObjectController*>::iterator it;
02221         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
02222                 GObjectController *cont = it->second;
02223                 if (cont->getGObjectType() == GBLACKBOX) {
02224                         vect.push_back(cont->getId());
02225                 }
02226         }
02227         return vect;
02228 }
02229 
02230 //=========================================================================
02231 
02232 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
02233         std::vector<int> vect;
02234         std::map<int, GObjectController*>::iterator it;
02235         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
02236                 GObjectController *cont = it->second;
02237                 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
02238                         vect.push_back(cont->getId());
02239                 }
02240         }
02241         return vect;
02242 }
02243 
02244 //=========================================================================
02245 
02246 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
02247         std::vector<int> vect;
02248         std::map<int, GObjectController*>::iterator it;
02249         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
02250                 GObjectController *cont = it->second;
02251                 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
02252                         vect.push_back(cont->getId());
02253                 }
02254         }
02255         return vect;
02256 }
02257 
02258 //=========================================================================
02259 
02260 std::vector<int> wxVtkSceneManager::getConnections() {
02261         std::vector<int> vect;
02262         std::map<int, GObjectController*>::iterator it;
02263         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
02264                 GObjectController *cont = it->second;
02265                 if (cont->getGObjectType() == GCONNECTOR) {
02266                         vect.push_back(cont->getId());
02267                 }
02268         }
02269         return vect;
02270 }
02271 
02272 //=========================================================================
02273 
02274 bool wxVtkSceneManager::isComplexBox() {
02275         return _isComplexBox;
02276 }
02277 
02278 //=========================================================================
02279 
02280 void wxVtkSceneManager::setComplexBox(bool val) {
02281         _isComplexBox = val;
02282 }
02283 
02284 //=========================================================================
02285 
02286 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
02287         //Register the controller of the new object
02288         registerController((InteractorStyleMaracas*) objController);
02289         //Add the object to the objects list
02290         int newId = _contLastId;//_controllers.size();
02291         objController->setId(newId);
02292         _controllers[newId] = objController;
02293         //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
02294         _contLastId++;
02295         return newId;
02296 }
02297 
02298 //=========================================================================
02299 
02300 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
02301 
02302         std::map<int, int> oldIdNewIdBoxes;
02303         std::vector<int> connections;
02304 
02305         std::vector<int> newBoxesID;
02306 
02307         std::map<int, GObjectController*>::iterator it;
02308         for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
02309             GObjectController *cont = it->second;
02310             int type = cont->getGObjectType();
02311 
02312             if (type == GBLACKBOX) {
02313                 // Copy black box
02314                 double xInic, yInic, zInic;
02315                 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
02316                 copyBox->getInicPoint(xInic, yInic, zInic);
02317                 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
02318                         copyBox->getBBTKType());
02319 
02320                 int idcB = copyBox->getObjectId();
02321                 oldIdNewIdBoxes[idcB] = idBox;
02322                 cont = _controllers[idBox];
02323                 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
02324                 newbox->setInicPoint(xInic, yInic, zInic);
02325                 int num = newbox->getNumInputPorts();
02326                 for (int j = 0; j < num; j++) {
02327                     newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
02328                 }
02329                 newbox->move(xInic + 20, yInic + 20, zInic);
02330                 newbox->notifyObservers(_idManager);
02331                 newBoxesID.push_back(newbox->getObjectId());
02332 
02333             } else if (type == GCONNECTOR) {
02334                 int idCon = cont->getId();
02335                 connections.push_back(idCon);
02336             }
02337 
02338         }
02339 
02340         for (int i = 0; i < (int) connections.size(); i++) {
02341             int objId = connections[i];
02342             GObjectController *cont = objectsMap[objId];
02343             GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
02344 
02345             GPortModel* startPort = connectModel->getStartPort();
02346             int startPortIndex = startPort->getPosInBox();
02347             GPortModel* endPort = connectModel->getEndPort();
02348             int endPortIndex = endPort->getPosInBox();
02349 
02350             GBlackBoxModel* startPortParentBox =
02351                     (GBlackBoxModel*) startPort->getParentBox();
02352             GBlackBoxModel* endPortParentBox =
02353                     (GBlackBoxModel*) endPort->getParentBox();
02354 
02355             int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
02356             int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
02357 
02358             GBlackBoxModel* newStartBox =
02359                     (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
02360             GBlackBoxModel* newEndBox =
02361                     (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
02362 
02363             GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
02364             GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
02365 
02366             // Creates connection
02367             int idCon = createGConnector(newStartPort);
02368             GConnectorController *tempp =
02369                     (GConnectorController*) _controllers[idCon];
02370             GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
02371             vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
02372             tempp->endContourCreation();
02373             conMod->setEndPort(newEndPort);
02374             conView->updateStartEndPoints();
02375         }
02376 
02378 
02379         UnSelectBlackBoxes();
02380         for (int i = 0; i < newBoxesID.size(); i++) {
02381             _selectedObjects.push_back(newBoxesID.at(i));
02382         }
02383 
02384         for (int i = 0; i < (int) _selectedObjects.size(); i++) {
02385             int id = _selectedObjects[i];
02386             GObjectController* cont = _controllers[id];
02387 
02388             cont->getView()->setState(SELECTED);
02389             cont->getModel()->notifyObservers(_idManager);
02390 
02391         }
02392     }
02393 
02394 
02395 //=========================================================================
02396 
02397 int wxVtkSceneManager::getNumSelectedObjects() {
02398         return _selectedObjects.size();
02399 }
02400 
02401 //=========================================================================
02402 
02403 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
02404         std::map<int, GObjectController*> mapSelected;
02405 
02406         std::map<int, GObjectController*>::iterator it;
02407         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
02408                 GObjectController *cont = it->second;
02409                 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
02410                                 == SELECTED) {
02411                         mapSelected[cont->getId()] = cont;
02412                 }
02413         }
02414 
02415         std::map<int, GObjectController*>::iterator it2;
02416         for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
02417                 GObjectController *cont = it2->second;
02418                 if (cont->getGObjectType() == GCONNECTOR) {
02419                         GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
02420                         GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
02421                         GBoxModel* startPortParentBox =
02422                                         cmod->getStartPort()->getParentBox();
02423 
02424                         std::map<int, GObjectController*>::iterator iterOBJ1 =
02425                                         mapSelected.find(startPortParentBox->getObjectId());
02426                         std::map<int, GObjectController*>::iterator iterOBJ2 =
02427                                         mapSelected.find(endPortParentBox->getObjectId());
02428 
02429                         if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
02430                                 int ID = cont->getId();
02431                                 mapSelected[ID] = cont;
02432                         }
02433                 }
02434         }
02435         return mapSelected;
02436 }
02437 
02438 //=========================================================================
02439 
02440 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
02441 
02442         std::map<int, int> oldIdNewIdBoxes;
02443         std::vector<int> connections;
02444 
02445         std::map<int, GObjectController*>::iterator it;
02446         for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
02447                 GObjectController *cont = it->second;
02448                 int type = cont->getGObjectType();
02449 
02450                 if (type == GBLACKBOX) {
02451                         // Copy black box
02452                         double xInic, yInic, zInic;
02453                         GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
02454                         copyBox->getInicPoint(xInic, yInic, zInic);
02455                         int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
02456                                         copyBox->getBBTKType());
02457 
02458                         int idcB = copyBox->getObjectId();
02459                         oldIdNewIdBoxes[idcB] = idBox;
02460                         cont = _controllers[idBox];
02461                         GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
02462                         newbox->setInicPoint(xInic, yInic, zInic);
02463                         int num = newbox->getNumInputPorts();
02464                         for (int j = 0; j < num; j++) {
02465                                 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
02466                         }
02467                         newbox->notifyObservers(_idManager);
02468                 } else if (type == GCONNECTOR) {
02469                         int idCon = cont->getId();
02470                         connections.push_back(idCon);
02471                 }
02472 
02473         }
02474 
02475         for (int i = 0; i < (int) connections.size(); i++) {
02476                 int objId = connections[i];
02477                 GObjectController *cont = objectsMap[objId];
02478                 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
02479 
02480                 GPortModel* startPort = connectModel->getStartPort();
02481                 int startPortIndex = startPort->getPosInBox();
02482                 GPortModel* endPort = connectModel->getEndPort();
02483                 int endPortIndex = endPort->getPosInBox();
02484 
02485                 GBlackBoxModel* startPortParentBox =
02486                                 (GBlackBoxModel*) startPort->getParentBox();
02487                 GBlackBoxModel* endPortParentBox =
02488                                 (GBlackBoxModel*) endPort->getParentBox();
02489 
02490                 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
02491                 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
02492 
02493                 GBlackBoxModel* newStartBox =
02494                                 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
02495                 GBlackBoxModel* newEndBox =
02496                                 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
02497 
02498                 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
02499                 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
02500 
02501                 // Creates connection
02502                 int idCon = createGConnector(newStartPort);
02503                 GConnectorController *tempp =
02504                                 (GConnectorController*) _controllers[idCon];
02505                 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
02506                 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
02507                 tempp->endContourCreation();
02508                 conMod->setEndPort(newEndPort);
02509                 conView->updateStartEndPoints();
02510         }
02511 
02512         std::map<int, int>::iterator itIds;
02513         for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
02514                 int idOld = itIds->first;
02515                 int idNew = itIds->second;
02516 
02517                 GBlackBoxModel* oldBox =
02518                                 (GBlackBoxModel*) objectsMap[idOld]->getModel();
02519                 GBlackBoxModel* newBox =
02520                                 (GBlackBoxModel*) _controllers[idNew]->getModel();
02521 
02522                 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
02523                 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
02524                 std::vector<int> newInputConnections = newBox->getConnectedInputs();
02525                 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
02526 
02527                 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
02528                         bool exist = false;
02529                         //EED                           int toCreate=-1;
02530                         for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
02531                                 if (oldInputConnections[k] == newInputConnections[l]) {
02532                                         exist = true;
02533                                 }
02534                         }
02535 
02536                         if (exist == false) {
02537                                 //Create complex input
02538                                 int posInBox = oldInputConnections[k];
02539                                 GPortModel* inputPort = oldBox->getInputPort(posInBox);
02540                                 std::string inputPortName = inputPort->getBBTKName();
02541                                 int idInputPort = createGComplexBoxInputPort(inputPortName);
02542                                 GObjectController *cont = _controllers[idInputPort];
02543                                 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
02544                                 double xIn, yIn, zIn;
02545                                 inputPort->getInicPoint(xIn, yIn, zIn);
02546                                 yIn += 20;
02547                                 cbmod->setInicPoint(xIn, yIn, zIn);
02548                                 cbmod->notifyObservers(_idManager);
02549 
02550                                 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
02551 
02552                                 // Creates connection
02553                                 int idCon = createGConnector(cbmod->getOutputPort(0));
02554                                 GConnectorController *tempp =
02555                                                 (GConnectorController*) _controllers[idCon];
02556                                 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
02557                                 vtkGConnectorView *conView =
02558                                                 (vtkGConnectorView*) tempp->getView();
02559                                 tempp->endContourCreation();
02560                                 conMod->setEndPort(inputPortEnd);
02561                                 conView->updateStartEndPoints();
02562 
02563                         }
02564 
02565                 }
02566 
02567                 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
02568                         bool exist = false;
02569                         //EED                           int toCreate=-1;
02570                         for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
02571                                 if (oldOutputConnections[k] == newOutputConnections[l]) {
02572                                         exist = true;
02573                                 }
02574                         }
02575 
02576                         if (exist == false) {
02577                                 //Create complex output
02578                                 int posInBox = oldOutputConnections[k];
02579                                 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
02580                                 std::string outputPortName = outputPort->getBBTKName();
02581                                 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
02582                                 GObjectController *cont = _controllers[idOutputPort];
02583                                 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
02584                                 double xIn, yIn, zIn;
02585                                 outputPort->getInicPoint(xIn, yIn, zIn);
02586                                 yIn -= 20;
02587                                 cbmod->setInicPoint(xIn, yIn, zIn);
02588                                 cbmod->notifyObservers(_idManager);
02589 
02590                                 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
02591 
02592                                 // Creates connection
02593                                 int idCon = createGConnector(outputPortEnd);
02594                                 GConnectorController *tempp =
02595                                                 (GConnectorController*) _controllers[idCon];
02596                                 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
02597                                 vtkGConnectorView *conView =
02598                                                 (vtkGConnectorView*) tempp->getView();
02599                                 tempp->endContourCreation();
02600                                 conMod->setEndPort(cbmod->getInputPort(0));
02601                                 conView->updateStartEndPoints();
02602 
02603                         }
02604 
02605                 }
02606 
02607         }
02608 
02609 }
02610 
02611 //=========================================================================
02612 void wxVtkSceneManager::SetCbName(std::string cbName) {
02613         _cbName = cbName;
02614         if (_cbName == "") {
02615                 _cbName = "<complex box name>";
02616         }
02617 }
02618 
02619 //=========================================================================
02620 std::string wxVtkSceneManager::GetCbName() {
02621         return _cbName;
02622 }
02623 
02624 //=========================================================================
02625 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
02626         _cbPackageName = packagename;
02627         if (_cbPackageName == "") {
02628                 _cbPackageName = "<package name of the complex box>";
02629         }
02630 }
02631 
02632 //=========================================================================
02633 std::string wxVtkSceneManager::GetCbPackageName() {
02634         return _cbPackageName;
02635 }
02636 
02637 //=========================================================================
02638 void wxVtkSceneManager::SetAuthor(std::string author) {
02639         _Author = author;
02640         if (_Author == "") {
02641                 _Author = "<author of the box>";
02642         }
02643 }
02644 
02645 //=========================================================================
02646 std::string wxVtkSceneManager::GetAuthor() {
02647         return _Author;
02648 }
02649 
02650 //=========================================================================
02651 void wxVtkSceneManager::SetCategory(std::string category) {
02652         _Category = category;
02653         if (_Category == "") {
02654                 _Category = "<category of the box>";
02655         }
02656 }
02657 
02658 //=========================================================================
02659 std::string wxVtkSceneManager::GetCategory() {
02660         return _Category;
02661 }
02662 
02663 //=========================================================================
02664 void wxVtkSceneManager::SetDescription(std::string description) {
02665         _Description = description;
02666         if (_Description == "") {
02667                 _Description = "<description of the box>";
02668         }
02669 }
02670 
02671 //=========================================================================
02672 std::string wxVtkSceneManager::GetDescription() {
02673         return _Description;
02674 }
02675 
02676 //=========================================================================
02677 
02678 
02679 void wxVtkSceneManager::printAll(int com , int sta ){
02680         
02681          int tmpState = sta ;
02682         if ( tmpState == NOTHING_HAPPENS ) {
02683             std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
02684         }
02685         if ( tmpState == HIGHLIGHTED ) {
02686             std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
02687         }
02688         if ( tmpState == POSSIBLE_CONNECTION ) {
02689             std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
02690         }
02691         if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
02692             std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
02693         }
02694         if ( tmpState == CLICKED ) {
02695             std::cout << "CONTROLER STATE---->CLICKED\n" ;
02696         }
02697         if ( tmpState == DRAG ) {
02698             std::cout << "CONTROLER STATE---->DRAG\n" ;
02699         }
02700         if ( tmpState == SELECTED ) {
02701             std::cout << "CONTROLER STATE---->SELECTED\n" ;
02702         }
02703         if ( tmpState == CREATING_CONTOUR ) {
02704             std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
02705         }   
02706          
02707          // :P 
02708 
02709         int command = com ;
02710         if ( command == INIT_CREATION_CONTOUR ) {
02711             std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
02712         }
02713         if ( command == FIN_CREATION_CONTOUR ) {
02714             std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
02715         }
02716         if ( command == ADD_TO_SELECTED ) {
02717             std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
02718         }
02719         if ( command == DRAG_OBJECTS ) {
02720             std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
02721         }
02722         if ( command == EDIT_BLACKBOX ) {
02723             std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
02724         }
02725         if ( command == REMOVE_FROM_SELECTED ) {
02726             std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
02727         }
02728         
02729     }
02730 
02731 
02732 } // EO namespace bbtk
02733 
02734 // EOF
02735 

Generated on Thu May 31 15:12:20 2012 for bbtkGEditor by  doxygen 1.5.7.1