-/*=========================================================================
-Program: bbtk
-Module: $RCSfile$
-Language: C++
-Date: $Date$
-Version: $Revision$
-=========================================================================*/
+/*
+# ---------------------------------------------------------------------
+#
+# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+# pour la Santé)
+# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+#
+# This software is governed by the CeCILL-B license under French law and
+# abiding by the rules of distribution of free software. You can use,
+# modify and/ or redistribute the software under the terms of the CeCILL-B
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+# or in the file LICENSE.txt.
+#
+# As a counterpart to the access to the source code and rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty and the software's author, the holder of the
+# economic rights, and the successive licensors have only limited
+# liability.
+#
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL-B license and that you accept its terms.
+# ------------------------------------------------------------------------
+*/
+
+/*=========================================================================
+ Program: bbtk
+ Module: $RCSfile$
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+ =========================================================================*/
/* ---------------------------------------------------------------------
-* Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
-* Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
-*
-* This software is governed by the CeCILL-B license under French law and
-* abiding by the rules of distribution of free software. You can use,
-* modify and/ or redistribute the software under the terms of the CeCILL-B
-* license as circulated by CEA, CNRS and INRIA at the following URL
-* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-* or in the file LICENSE.txt.
-*
-* As a counterpart to the access to the source code and rights to copy,
-* modify and redistribute granted by the license, users are provided only
-* with a limited warranty and the software's author, the holder of the
-* economic rights, and the successive licensors have only limited
-* liability.
-*
-* The fact that you are presently reading this means that you have had
-* knowledge of the CeCILL-B license and that you accept its terms.
-* ------------------------------------------------------------------------ */
+ * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
+ * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
+ *
+ * This software is governed by the CeCILL-B license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/ or redistribute the software under the terms of the CeCILL-B
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+ * or in the file LICENSE.txt.
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL-B license and that you accept its terms.
+ * ------------------------------------------------------------------------ */
/**
-* \file
-* \brief Class bbtk::wxVtkSceneManager .
-*/
-
+ * \file
+ * \brief Class bbtk::wxVtkSceneManager .
+ */
#include "wxVtkSceneManager.h"
-namespace bbtk
-{
+#include <vtkPolygon.h>
+#include <vtkUnstructuredGrid.h>
+namespace bbtk {
- //=========================================================================
- wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView,int idManager)
- {
- printf ("EED %p wxVtkSceneManager()\n" , this );
- _parent = parent;
- _numBoxes=0;
- _idManager=idManager;
- _baseView=baseView;
- _startDragging=false;
- _isComplexBox=false;
-
- if( _baseView!=NULL )
- {
-//EED02JUIN2010
- printf ("RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n" , this );
- _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
+#define POORT_MAX_LINE_SIZE_INTERPRETER 1500
- configureBaseView();
- _worldState=NOTHING_HAPPENS;
- registerController(this);
-
- }
- _idConnectionInCreation=-1;
- _contLastId=0;
+//=========================================================================
+
+// EED 15 oct 2012 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
+
+wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
+{
+ _cbName = "ComplexBoxName";
+ _cbPackageName = "PackageName";
+ _Author = "Author ??";
+ _Category = "<VOID>";
+ _Description = "Description ??";
+ _MessageKind = " ";
+ _MessageLevel = " ";
+
+ _bugTextActor_text = "void";
+ _bugTextActor_status = 0;
+
+ _parent = parent;
+ _numBoxes = 0;
+ _idManager = idManager;
+ _baseView = baseView;
+ _bbtkfactory = bbtkfactory;
+
+ _startDragging = false;
+ _isComplexBox = false;
+
+ if (_baseView != NULL) {
+ //EED02JUIN2010
+ printf(
+ "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
+ this);
+//#ifdef __APPLE__
+ _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
+//#endif
+
+ configureBaseView();
+ _worldState = NOTHING_HAPPENS;
+ registerController(this);
}
+ _idConnectionInCreation = -1;
+ _contLastId = 0;
- //=========================================================================
+}
- void wxVtkSceneManager::disconnectDrop()
- {
- printf ("EED %p ~wxVtkSceneManager::disconnectDrop()\n" , this );
-//EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
-// _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
- }
+//=========================================================================
- //=========================================================================
+void wxVtkSceneManager::disconnectDrop()
+{
+ printf("EED %p ~wxVtkSceneManager::disconnectDrop()\n", this);
+ //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
+ // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
+}
- wxVtkSceneManager::~wxVtkSceneManager()
- {
- printf ("EED %p ~wxVtkSceneManager()\n" , this );
- disconnectDrop();
- }
-
- //=========================================================================
+//=========================================================================
- void wxVtkSceneManager::configureBaseView()
- {
- vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
+wxVtkSceneManager::~wxVtkSceneManager()
+{
+ //FCY memory leaks
+ printf("EED %p ~wxVtkSceneManager() START\n", this);
+ disconnectDrop();
+ delete _baseView;
+ printf("EED %p ~wxVtkSceneManager() END\n", this);
+}
- _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
+//=========================================================================
- // Important to activate the 2D interaction system
- wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
- interactorstylebaseview->SetInteractor ( iren );
- iren->SetInteractorStyle(interactorstylebaseview);
- interactorstylebaseview->SetwxVtkBaseView(_baseView);
-
- _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
- _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,900,1000);
-
- _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
- _baseView->GetRenderer()->GradientBackgroundOff();
- _baseView->Refresh();
+void wxVtkSceneManager::configureBaseView()
+{
+ vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
+
+ _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
+
+ // Important to activate the 2D interaction system
+ wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
+ interactorstylebaseview->SetInteractor(iren);
+ iren->SetInteractorStyle(interactorstylebaseview);
+ interactorstylebaseview->SetwxVtkBaseView(_baseView);
+
+ _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
+ _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, -1000, 1000);
+ _baseView->GetRenderer()->GetActiveCamera()->Zoom(10);
+
+
+ _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
+ _baseView->GetRenderer()->GradientBackgroundOn();
+
+ // Actos Port_Text
+ _textActor = vtkTextActor3D::New();
+// _textActor = vtkTextActor::New();
+ _textActor->SetPosition(-9999, -9999, GPOSITION_Z);
+ _textActor->SetInput("<void>");
+ _textActor->GetTextProperty()->SetFontSize(60);
+ _textActor->GetTextProperty()->BoldOn();
+ _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,PORTTEXT_NH_B);
+
+ _baseView->GetRenderer()->AddActor(_textActor);
+
+ // Actor Fill_Port_Text
+
+ //------------
+ double xInic = 0;
+ double yInic = 0;
+ double zInic = GPOSITION_Z;
+
+ vtkPolygon *aPolygon = vtkPolygon::New();
+ _fillObjectActor = vtkActor::New();
+
+ _pts = vtkPoints::New();
+
+ double w = 100, h = 10, b = h / 15, t = 3;
+ _pts->SetNumberOfPoints(21);
+ _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
+ _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
+ _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
+ _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
+ _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
+
+ _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
+ _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
+ _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
+ _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
+
+ _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
+ _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
+ _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
+ _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
+
+ _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
+ _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
+ _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
+ _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
+
+ _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
+ _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
+ _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
+ _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
+
+ aPolygon->GetPointIds()->SetNumberOfIds(21);
+ for (int i = 0; i < 21; i++) {
+ aPolygon->GetPointIds()->SetId(i, i);
}
- //=========================================================================
+ vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
+ aPolygonGrid->Allocate(1, 1);
+ aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),
+ aPolygon->GetPointIds());
+ aPolygonGrid->SetPoints(_pts);
+ _aPolygonMapper = vtkDataSetMapper::New();
+ _aPolygonMapper->SetInput(aPolygonGrid);
+ _fillObjectActor->SetMapper(_aPolygonMapper);
+ _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
+ PORTFILL_NH_B);
+ _fillObjectActor->GetProperty()->SetOpacity(0);
+ _aPolygonMapper->Modified();
+
+ _baseView->GetRenderer()->AddActor(_fillObjectActor);
+}
+
+//=========================================================================
+
+std::string wxVtkSceneManager::generateANewNameForABox() {
+ std::stringstream boxname;
+ if (_numBoxes < 10) {
+ boxname << "Box0" << _numBoxes;
+ } else {
+ boxname << "Box" << _numBoxes;
+ }
+ _numBoxes++;
+ return boxname.str();
+}
- int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
- {
-printf("EED %p wxVtkSceneManager::createGBlackBox 1\n",this);
+//=========================================================================
- _worldState = NOTHING_HAPPENS;
-printf("EED %p wxVtkSceneManager::createGBlackBox 1.1\n",this);
- int windowWidth=_baseView->GetRenWin()->GetSize()[0];
-printf("EED %p wxVtkSceneManager::createGBlackBox 1.2\n",this);
- int windowHeight=_baseView->GetRenWin()->GetSize()[1];
-printf("EED %p wxVtkSceneManager::createGBlackBox 1.3\n",this);
+std::string wxVtkSceneManager::findANewNameForABox() {
+ std::string boxname = generateANewNameForABox();
- int type = GBLACKBOX;
+ while (boxExist(boxname) == true) {
+ boxname = generateANewNameForABox();
+ } // while
- //Create the MVC Objects
-
- GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
-printf("EED %p wxVtkSceneManager::createGBlackBox 1.4\n",this);
- vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
-printf("EED %p wxVtkSceneManager::createGBlackBox 1.5\n",this);
- GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
-printf("EED %p wxVtkSceneManager::createGBlackBox 1.6 >%s< >%s<\n",this, packageName.c_str(), boxType.c_str() );
-
- BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
-
- //Prepares the initial model
- //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
+ return boxname;
+}
-printf("EED %p wxVtkSceneManager::createGBlackBox 2\n",this);
- double xx = x;
- double yy = windowHeight-y;
-
- //z value is not important yet, because it is only used a parallel projection
- double zz = 900;
+//=========================================================================
+void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
+ double zIn, std::string name, bool boxExecutable, double xEn,
+ double yEn, double zEn) {
+ GObjectController *cont = _controllers[idBox];
+ GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
+ bbmod->setBBTKName(name);
+ bbmod->setInicPoint(xIn, yIn, zIn);
+ bbmod->setFinalPoint(xEn, yEn, zEn);
+ bbmod->setExecutable(boxExecutable);
- _baseView->TransCoordScreenToWorld(xx,yy,zz);
- model->setInicPoint(xx,yy,zz);
-
- _numBoxes++;
- std::stringstream stream;
-
-printf("EED %p wxVtkSceneManager::createGBlackBox 3\n",this);
- if(_numBoxes<10)
- {
- stream << "Box0" << _numBoxes;
- }
- else
- {
- stream << "Box" << _numBoxes;
- }
- std::string arraystring = stream.str();
+ bbmod->notifyObservers(_idManager);
- model->setBBTKName(arraystring);
- model->setBBTKType(boxType);
- model->setBBTKPackage(packageName);
-
- model->addObserver(view);
- model->addObserver(this);
+}
- //Iterate and create the input ports
- std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
- std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
+//=========================================================================
- int i=0;
- for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
- {
- BlackBoxInputDescriptor *desc = itInput->second;
- createGInputPort(GINPUTPORT,i,model,desc);
- i++;
- }
+int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,std::string boxType)
+{
+ _worldState = NOTHING_HAPPENS;
+ int windowHeight = _baseView->GetRenWin()->GetSize()[1];
+ int type = GBLACKBOX;
+ //Create the MVC Objects
+ GBlackBoxModel *model = (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
+ vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
+ GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
+
+//EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
+
+ Package::Pointer k;
+ std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
+ try{
+ k = _bbtkfactory->GetPackage(packageName);
+ mapDesc = k->GetDescriptorMap();
+ }catch(Exception e){
+ printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for package %s, NOT EXIST\n", packageName.c_str());
+ }
-printf("EED %p wxVtkSceneManager::createGBlackBox 4\n",this);
- //Iterate and create the output ports
- std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
- std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
+ BlackBoxDescriptor::Pointer descriptor;
+ try{
+ descriptor = mapDesc[boxType];
+ }catch(Exception e){
+ printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for box %s of package %s, NOT EXIST\n", boxType.c_str(),packageName.c_str());
+ }
+
+ if (descriptor == NULL)
+ {
+ printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
+ }
+
+ //Prepares the initial model
+ //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
- i=0;
- for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
- {
- BlackBoxOutputDescriptor *desc = itOutput->second;
- createGOutputPort(GOUTPUTPORT,i,model,desc);
- i++;
- }
+ double xx = x;
+ double yy = windowHeight - y;
+ //z value is not important yet, because it is only used a parallel projection
+ double zz = GPOSITION_Z;
+ _baseView->TransCoordScreenToWorld(xx, yy, zz);
+ model->setInicPoint(xx, yy, zz);
- //Associates the view with the correspondent renderer and the model.
- //(NOTE: Refresh is only made by the view)
- view->setModel(model);
- view->setBaseView(_baseView);
- view->initVtkObjects();
-printf("EED %p wxVtkSceneManager::createGBlackBox 5\n",this);
-
- //Associates the controller with the correspondent model and view
- controller->setModelAndView(model,view);
+ std::stringstream stream;
- //Resgiter change to the observers of the actual model
- model->notifyObservers(_idManager);
-
- int newId = addObjectController(controller);
-printf("EED %p wxVtkSceneManager::createGBlackBox 6\n",this);
- return newId;
+ std::string newBoxName;
+ newBoxName = findANewNameForABox();
- }
+ stream << newBoxName;
- //=========================================================================
+ std::string arraystring = stream.str();
- int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
- {
- int windowWidth=_baseView->GetRenWin()->GetSize()[0];
- int windowHeight=_baseView->GetRenWin()->GetSize()[1];
-
- int type = GCOMPLEXINPUTPORT;
+ model->setBBTKName(arraystring);
+ model->setBBTKType(boxType);
+ model->setBBTKPackage(packageName);
- //Create the MVC Objects
-
- GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
- vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
- GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
-
- //Prepares the initial model
+ model->addObserver(view);
+ model->addObserver(this);
- double xx = 5;
- double yy = windowHeight-5;
-
- //z value is not important yet, because it is only used a parallel projection
- double zz = 900;
+ //Iterate and create the input ports
+ std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
+ descriptor->GetInputDescriptorMap();
+ std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
- _baseView->TransCoordScreenToWorld(xx,yy,zz);
- model->setInicPoint(xx,yy,zz);
-
- model->setBBTKName(inputName);
- model->setBBTKType("ComplexInputPort");
- model->setComplexPortType(type);
-
- model->addObserver(view);
- model->addObserver(this);
-
- //create the output port
- GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
- model->addOutputPort((GPortModel*)portController->getModel());
-
- //Associates the view with the correspondent renderer and the model.
- //(NOTE: Refresh is only made by the view)
- view->setModel(model);
- view->setBaseView(_baseView);
- view->initVtkObjects();
-
- //Associates the controller with the correspondent model and view
- controller->setModelAndView(model,view);
+ int i = 0;
+ for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) {
+ BlackBoxInputDescriptor *desc = itInput->second;
+ createGInputPort(GINPUTPORT, i, model, desc);
+ i++;
+ }
- //Resgiter change to the observers of the actual model
- model->notifyObservers(_idManager);
-
- int newId = addObjectController(controller);
- return newId;
+ //Iterate and create the output ports
+ std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
+ descriptor->GetOutputDescriptorMap();
+ std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
+
+ i = 0;
+ for (itOutput = descriptorOutMap.begin(); itOutput
+ != descriptorOutMap.end(); ++itOutput) {
+ BlackBoxOutputDescriptor *desc = itOutput->second;
+ createGOutputPort(GOUTPUTPORT, i, model, desc);
+ i++;
}
- //=========================================================================
-
- int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
- {
- int windowWidth=_baseView->GetRenWin()->GetSize()[0];
- int windowHeight=_baseView->GetRenWin()->GetSize()[1];
+ //Associates the view with the correspondent renderer and the model.
+ //(NOTE: Refresh is only made by the view)
+ view->setModel(model);
+ view->setBaseView(_baseView);
+ view->initVtkObjects();
- int type = GCOMPLEXOUTPUTPORT;
+ //Associates the controller with the correspondent model and view
+ controller->setModelAndView(model, view);
- //Create the MVC Objects
-
- GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
- vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
- GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
-
- //Prepares the initial model
+ //Resgiter change to the observers of the actual model
+ model->notifyObservers(_idManager);
- double xx = 5;
- double yy = windowHeight-5;
-
- //z value is not important yet, because it is only used a parallel projection
- double zz = 900;
+ int newId = addObjectController(controller);
- _baseView->TransCoordScreenToWorld(xx,yy,zz);
- model->setInicPoint(xx,yy,zz);
-
- model->setBBTKName(outputName);
- model->setBBTKType("ComplexOutputPort");
- model->setComplexPortType(type);
-
- model->addObserver(view);
- model->addObserver(this);
-
- //create the output port
- GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
- model->addInputPort((GPortModel*)portController->getModel());
-
- //Associates the view with the correspondent renderer and the model.
- //(NOTE: Refresh is only made by the view)
- view->setModel(model);
- view->setBaseView(_baseView);
- view->initVtkObjects();
-
- //Associates the controller with the correspondent model and view
- controller->setModelAndView(model,view);
+ return newId;
- //Resgiter change to the observers of the actual model
- model->notifyObservers(_idManager);
-
- int newId = addObjectController(controller);
- return newId;
- }
+}
- //=========================================================================
+//=========================================================================
- int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
- {
- GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
- blackBox->addInputPort((GPortModel*)portController->getModel());
- return portController->getId();
- }
+int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
+ //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
+ int windowHeight = _baseView->GetRenWin()->GetSize()[1];
- //=========================================================================
+ int type = GCOMPLEXINPUTPORT;
- int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
- {
- GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
- blackBox->addOutputPort((GPortModel*)portController->getModel());
- return portController->getId();
- }
+ //Create the MVC Objects
- //=========================================================================
+ GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
+ vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
+ GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
- GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
- {
- int type = GPORT;
+ //Prepares the initial model
- //Create the MVC Objects
- GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
- vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
- GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
+ double xx = 5;
+ double yy = windowHeight - 5;
- model->registerInBox(blackBox,portType, posInBox);
-
- model->setBBTKType(bbtkType);
- model->setBBTKName(bbtkName);
+ //z value is not important yet, because it is only used a parallel projection
+ double zz = GPOSITION_Z;
- model->addObserver(view);
- model->addObserver(this);
+ _baseView->TransCoordScreenToWorld(xx, yy, zz);
+ model->setInicPoint(xx, yy, zz);
- //Associates the view with the correspondent renderer and the model.
- //(NOTE: Refresh is only made by the view)
- view->setModel(model);
- view->setBaseView(_baseView);
- view->initVtkObjects();
-
- //Associates the controller with the correspondent model and view
- controller->setModelAndView(model,view);
+ model->setBBTKName(inputName);
+ model->setBBTKType("ComplexInputPort");
+ model->setComplexPortType(type);
- model->notifyObservers(_idManager);
+ model->addObserver(view);
+ model->addObserver(this);
- int newId = addObjectController(controller);
+ //create the output port
+ GPortController* portController = createGPort(GOUTPUTPORT, inputName,
+ "ComplexOutputPortType","ComplexOutputPortDescriopton", 0, model);
+ model->addOutputPort((GPortModel*) portController->getModel());
- return (GPortController*)controller;
- }
+ //Associates the view with the correspondent renderer and the model.
+ //(NOTE: Refresh is only made by the view)
+ view->setModel(model);
+ view->setBaseView(_baseView);
+ view->initVtkObjects();
- //=========================================================================
+ //Associates the controller with the correspondent model and view
+ controller->setModelAndView(model, view);
- int wxVtkSceneManager::createGConnector(GPortModel* startPort)
- {
- int type = GCONNECTOR;
+ //Resgiter change to the observers of the actual model
+ model->notifyObservers(_idManager);
- manualConnectorContourController* manContourControl = new manualConnectorContourController();
- manualConnectorContourView* manContourView = new manualConnectorContourView();
- manualContourModel* manContourModel = new manualContourModel();
+ int newId = addObjectController(controller);
+ return newId;
+}
- GConnectorController* connectorcontroller = new GConnectorController();
- GConnectorModel* connectorModel = new GConnectorModel();
- vtkGConnectorView* connectorView = new vtkGConnectorView();
- connectorModel->setGObjectType(type);
+//=========================================================================
- manContourModel->SetCloseContour(false);
- connectorModel->setStartPort(startPort);
+int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
+ //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
+ int windowHeight = _baseView->GetRenWin()->GetSize()[1];
- manContourView->SetModel( manContourModel );
- manContourView->SetWxVtkBaseView( _baseView );
- manContourView->SetRange( 0.5 );
- manContourView->SetZ( 900 );
+ int type = GCOMPLEXOUTPUTPORT;
- manContourView->SetColorNormalContour(0, 0, 1);
- manContourView->SetColorEditContour(0.5, 0.5, 0.5);
- manContourView->SetColorSelectContour(1, 0.8, 0);
- manContourView->SetWidthLine(1);
- manContourView->SetShowText(false);
+ //Create the MVC Objects
- manContourControl->SetModelView( manContourModel , manContourView );
-
- manContourControl->CreateNewManualContour();
+ GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
+ vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
+ GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
- manContourView->RefreshContour();
+ //Prepares the initial model
+ double xx = 5;
+ double yy = windowHeight - 5;
- double x,y,z;
- connectorModel->getInicPoint(x,y,z);
+ //z value is not important yet, because it is only used a parallel projection
+ double zz = GPOSITION_Z;
- manContourControl->SetState(1);
- manContourModel->SetCloseContour(false);
-
- manContourModel->AddPoint(x,y,z);
- manContourView->AddPoint();
+ _baseView->TransCoordScreenToWorld(xx, yy, zz);
+ model->setInicPoint(xx, yy, zz);
- manContourModel->AddPoint(x,y,z);
- manContourView->AddPoint();
+ model->setBBTKName(outputName);
+ model->setBBTKType("ComplexOutputPort");
+ model->setComplexPortType(type);
- int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
- manContourControl->_bakIdPoint=bak;
- manContourView->Refresh();
+ model->addObserver(view);
+ model->addObserver(this);
- manContourControl->SetMoving( false );
+ //create the output port
+ GPortController* portController = createGPort(GINPUTPORT, outputName,
+ "ComplexInputPort","ComplexInputPortDescription", 0, model);
+ model->addInputPort((GPortModel*) portController->getModel());
- connectorcontroller->setModelAndView(connectorModel,connectorView);
+ //Associates the view with the correspondent renderer and the model.
+ //(NOTE: Refresh is only made by the view)
+ view->setModel(model);
+ view->setBaseView(_baseView);
+ view->initVtkObjects();
- int newId = addObjectController(connectorcontroller);
+ //Associates the controller with the correspondent model and view
+ controller->setModelAndView(model, view);
- connectorcontroller->setManualContourController(manContourControl);
- connectorModel->setManualContourModel(manContourModel);
- connectorView->setManualContourView(manContourView);
- connectorView->setModel(connectorModel);
- connectorView->setBaseView(_baseView);
-
+ //Resgiter change to the observers of the actual model
+ model->notifyObservers(_idManager);
- connectorModel->addObserver(connectorView);
- connectorModel->addObserver(this);
+ int newId = addObjectController(controller);
+ return newId;
+}
- return newId;
- }
+//=========================================================================
+
+int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
+{
+ GPortController* portController = createGPort(portType, desc->GetName(),
+ desc->GetTypeName(), desc->GetDescription(), posinBox, blackBox);
+ blackBox->addInputPort((GPortModel*) portController->getModel());
+ return portController->getId();
+}
- //=========================================================================
+//=========================================================================
- void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
+int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
{
- vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
- baseViewControlManager->AddInteractorStyleMaracas( param );
- }
+ GPortController* portController = createGPort(portType, desc->GetName(),
+ desc->GetTypeName(),desc->GetDescription(), posinBox, blackBox);
+ blackBox->addOutputPort((GPortModel*) portController->getModel());
+ return portController->getId();
+}
- //=========================================================================
+//=========================================================================
- void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
- {
- vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
- baseViewControlManager->RemoveInteractorStyleMaracas( param );
- }
+GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posInBox,GBoxModel *blackBox)
+{
+ int type = GPORT;
- //=========================================================================
+ //Create the MVC Objects
+ GPortModel
+ *model =
+ (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
+ type);
+ vtkGObjectView *view =
+ GObjectsMVCFactory::getInstance()->createGObjectView(type);
+ GObjectController* controller =
+ GObjectsMVCFactory::getInstance()->createGObjectController(type);
- vtkRenderer* wxVtkSceneManager::getRenderer()
- {
- return _baseView->GetRenderer();
- }
+ model->registerInBox(blackBox, portType, posInBox);
- //=========================================================================
+ model->setBBTKType(bbtkType);
+ model->setBBTKName(bbtkName);
+ model->setBBTKDescription(bbtkDescription);
- vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
- {
- return _baseView->GetRenWin();
- }
- //=========================================================================
+ model->addObserver(view);
+ model->addObserver(this);
-
- void wxVtkSceneManager::update(int idController,int command)
- {
- if(command != NO_COMMAND)
- {
- if(command == ADD_TO_SELECTED)
- {
- GObjectController* cont = _controllers[idController];
+ //Associates the view with the correspondent renderer and the model.
+ //(NOTE: Refresh is only made by the view)
+ view->setModel(model);
+ view->setBaseView(_baseView);
+ view->initVtkObjects();
- bool foundID=false;
- for (int i=0; i<_selectedObjects.size() && foundID==false; i++)
- {
- int id = _selectedObjects[i];
- if(id==idController)
- {
- foundID = true;
- }
- }
- if(!foundID)
- {
- int id = idController;
- _selectedObjects.push_back(id);
- }
+ //Associates the controller with the correspondent model and view
+ controller->setModelAndView(model, view);
- }
- else if(command == INIT_CREATION_CONTOUR)
- {
- _worldState = INIT_CREATION_CONTOUR;
- GObjectController* cont = _controllers[idController];
- GPortModel* startOutputPort = (GPortModel*)cont->getModel();
-
+ model->notifyObservers(_idManager);
- // The last one is the controller of the connector
- std::map<int, GObjectController*>::iterator it2;
+ addObjectController(controller);
- for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
- {
- GObjectController *cont = it2->second;
- if(cont->getGObjectType() == GPORT )
- {
- GPortModel* port = (GPortModel*)cont->getModel();
- if(port->getPortType()==GINPUTPORT)
- {
- cont->SetActive(true);
- }
- else
- {
- cont->getView()->setState(NOTHING_HAPPENS);
- cont->getModel()->notifyObservers(_idManager);
- cont->SetActive(false);
- }
- }
- else
- {
- cont->getView()->setState(NOTHING_HAPPENS);
- cont->getModel()->notifyObservers(_idManager);
- cont->SetActive(false);
- }
- }
+ return (GPortController*) controller;
+}
- _selectedObjects.clear();
+//=========================================================================
- _idConnectionInCreation=createGConnector(startOutputPort);
+int wxVtkSceneManager::createGConnector(GPortModel* startPort)
+{
+ int type = GCONNECTOR;
+
+ manualConnectorContourController *manContourControl = new manualConnectorContourController();
+ manualConnectorContourView *manContourView = new manualConnectorContourView();
+ manualContourModel *manContourModel = new manualContourModel();
+ GConnectorController *connectorcontroller = new GConnectorController();
+ GConnectorModel *connectorModel = new GConnectorModel();
+ vtkGConnectorView *connectorView = new vtkGConnectorView();
+ connectorModel->setGObjectType(type);
+
+ manContourModel->SetCloseContour(false);
+ connectorModel->setStartPort(startPort);
+
+ manContourView->SetModel(manContourModel);
+ manContourView->SetWxVtkBaseView(_baseView);
+ manContourView->SetRange(0.5);
+ manContourView->SetZ(GPOSITION_Z);
+
+ manContourView->SetColorNormalContour(0, 0, 1);
+ manContourView->SetColorEditContour(0.5, 0.5, 0.5);
+ manContourView->SetColorSelectContour(1, 0.8, 0);
+
+
- }
- else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
- {
- _worldState = NOTHING_HAPPENS;
- //int id = _controllers.size()-1;
- GObjectController* cont = _controllers[_idConnectionInCreation];
- GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
-
- GObjectController* finPort = _controllers[idController];
- if(finPort->getGObjectType() == GPORT)
- {
- GPortModel* modelPort = (GPortModel*)finPort->getModel();
- modelContour->setEndPort(modelPort);
- }
+ /**
+ * JGRR AND CM
+ * Width increased from 2 to 3, it simplifies line handling and spline control :P
+ * @param WidthLine
+ */
+ manContourView->SetWidthLine( 3 ) ;
+ manContourView->SetShowText(false);
- manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
- manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
- connView->Refresh();
+ manContourControl->SetModelView(manContourModel, manContourView);
- std::map<int, GObjectController*>::iterator it2;
+ manContourControl->CreateNewManualContour();
- for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
- {
- GObjectController *cont = it2->second;
- if(cont->getView()!=NULL)
- {
- cont->getView()->setState(NOTHING_HAPPENS);
- cont->getModel()->notifyObservers(_idManager);
- }
- cont->SetActive(true);
- }
- }
-
- }
- }
- //=========================================================================
+ double x, y, z;
+ connectorModel->getInicPoint(x, y, z);
+
+
+ manContourControl->SetState(1);
+ manContourModel->SetCloseContour(false);
- bool wxVtkSceneManager::OnMouseMove()
- {
- int X,Y;
- wxVTKRenderWindowInteractor *wxVTKiren;
- wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
- wxVTKiren->GetEventPosition(X,Y);
+ manContourModel->AddPoint(x, y, z);
+ manContourView->AddPoint();
+
+ manContourModel->AddPoint(x, y, z);
+ manContourView->AddPoint();
+
+ int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
+ manContourControl->_bakIdPoint = bak;
-
- if(_worldState == DRAG_OBJECTS)
- {
- for (int i=0; i<_selectedObjects.size(); i++)
- {
- int id = _selectedObjects[i];
- GObjectController* cont = _controllers[id];
- if(_startDragging)
- {
- cont->getView()->setStartDragging(true);
- }
- cont->getView()->moveObject(X,Y);
- cont->getView()->setState(DRAG);
- cont->getModel()->notifyObservers(_idManager);
- }
+ manContourControl->SetMoving(false);
- std::map<int, GObjectController*>::iterator it;
+ connectorcontroller->setModelAndView(connectorModel, connectorView);
- for(it = _controllers.begin(); it != _controllers.end(); ++it)
- {
- GObjectController *desc = it->second;
- if(desc->getGObjectType()==GCONNECTOR)
- {
- vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
- vconn->updateStartEndPoints();
- }
- }
-
- _startDragging=false;
+ int newId = addObjectController(connectorcontroller);
- }
- else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
- {
- std::map<int, GObjectController*>::iterator it;
+ connectorcontroller->setManualContourController(manContourControl);
+ connectorModel->setManualContourModel(manContourModel);
+ connectorView->setManualContourView(manContourView);
+ connectorView->setModel(connectorModel);
+ connectorView->setBaseView(_baseView);
- for(it = _controllers.begin(); it != _controllers.end(); ++it)
- {
- GObjectController *desc = it->second;
- int type = desc->getGObjectType();
- int state = desc->getView()->getState();
-
- if(state == HIGHLIGHTED){
+ connectorModel->addObserver(connectorView);
+ connectorModel->addObserver(this);
- updateStatusBar(desc->getStatusText());
- if(type==GBLACKBOX)
- {
- GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
- _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
- }
- }
- }
+// manContourView->Refresh();
+
+ return newId;
+}
+
+//=========================================================================
+
+void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
+{
+ vtkInteractorStyleBaseView * baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
+ baseViewControlManager->AddInteractorStyleMaracas(param);
+}
+
+//=========================================================================
+
+void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
+{
+ vtkInteractorStyleBaseView *baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
+ baseViewControlManager->RemoveInteractorStyleMaracas(param);
+}
+
+//=========================================================================
+
+vtkRenderer* wxVtkSceneManager::getRenderer()
+{
+ return _baseView->GetRenderer();
+}
+
+//=========================================================================
+
+vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
+{
+ return _baseView->GetRenWin();
+}
+//=========================================================================
+
+
+//=========================================================================
+int wxVtkSceneManager::GetIndexInSelected(int idControler)
+{
+ int index = -1;
+ for (int i = 0; i < (int) _selectedObjects.size(); i++)
+ {
+ if (_selectedObjects[i] == idControler)
+ {
+ index = i;
+ break;
}
-
- return true;
}
+ return index;
+}
+//=========================================================================
- //=========================================================================
-
- bool wxVtkSceneManager::OnLeftButtonDown()
+void wxVtkSceneManager::update(int idController, int command) {
+
+ if (command != NO_COMMAND)
{
- if(_worldState==INIT_CREATION_CONTOUR)
+ if (command == ADD_TO_SELECTED)
{
- bool isOverPort=false;
- std::map<int, GObjectController*>::iterator it;
- for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
+ if (GetIndexInSelected(idController) == -1)
{
- GObjectController *desc = it->second;
- if(desc->getGObjectType()==GPORT)
- {
- GPortModel* portmod=(GPortModel*)desc->getModel();
- vtkGObjectView* portView=desc->getView();
- if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
- {
- isOverPort=true;
- }
- }
+ _selectedObjects.push_back(idController);
}
-
- if(isOverPort==false)
+ } else if (command == REMOVE_FROM_SELECTED) {
+ int index = GetIndexInSelected(idController);
+ if (index >= 0)
+ {
+ _selectedObjects.erase(_selectedObjects.begin() + index);
+ }
+ } else if (command == INIT_CREATION_CONTOUR) {
+ // JGRR & CM WH
+ typedef std::map<int , GObjectController*>::iterator TIterator ;
+ TIterator iter ;
+ TIterator iter_end ;
+ // Find current item in the controller
+ iter = _controllers.find( idController ) ;
+ iter_end = _controllers.end( ) ;
+ // If item exist
+ if ( iter != iter_end ) {
+ GObjectController* gobjc = iter->second ;
+
+ std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
+ // And if the item is a port
+ if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
+ TIterator c_it = _controllers.begin( ) ;
+ // Go through all componets
+ for ( c_it ; c_it != iter_end ; c_it++ ) {
+ GObjectController* obc = c_it->second ;
+ int obc_type = obc->getModel( )->getGObjectType( ) ;
+ std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
+ // if the component is a port and the type is the same of that selected
+ if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
+ // Highliht element
+ obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
+ //obc->getView( )->setState( HIGHLIGHTED ) ;
+ }
+ }
+ }
+ }
+
+ // EO JGRR & CM WH
+
+ _worldState = INIT_CREATION_CONTOUR;
+ GObjectController* cont = _controllers[idController];
+ GPortModel* startOutputPort = (GPortModel*) cont->getModel();
+
+ // The last one is the controller of the connector
+ std::map<int, GObjectController*>::iterator it2;
+
+ for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
{
- _worldState=NOTHING_HAPPENS;
- //int lastId = _controllers.size()-1;
- GConnectorController *connector = (GConnectorController*)_controllers[_controllers.size()-1];
- connector->removeFromScene();
- unregisterController(connector);
- _controllers.erase(_controllers.size()-1);
-
- for(it = _controllers.begin(); it != _controllers.end(); ++it)
+ GObjectController *cont = it2->second;
+ if (cont->getGObjectType() == GPORT)
{
- GObjectController *desc = it->second;
- desc->SetActive(true);
- desc->getView()->setState(NOTHING_HAPPENS);
- desc->getModel()->notifyObservers(_idManager);
+ GPortModel* port = (GPortModel*) cont->getModel();
+ if (port->getPortType() == GINPUTPORT)
+ {
+ cont->SetActive(true);
+ } else {
+ cont->getView()->setState(NOTHING_HAPPENS);
+ cont->getModel()->notifyObservers(_idManager);
+ cont->SetActive(false);
+ }
+ } else {
+ cont->getView()->setState(NOTHING_HAPPENS);
+ cont->getModel()->notifyObservers(_idManager);
+ cont->SetActive(false);
}
}
- }
-
- if(_selectedObjects.size()!=0)
- {
- _worldState = DRAG_OBJECTS;
- _startDragging = true;
+ _selectedObjects.clear();
+ _idConnectionInCreation = createGConnector(startOutputPort);
+ } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
+ _worldState = NOTHING_HAPPENS;
+ //int id = _controllers.size()-1;
+ GObjectController *cont = _controllers[_idConnectionInCreation];
+ GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
+ GObjectController *finPort = _controllers[idController];
- for (int i = 0; i < _selectedObjects.size(); i++)
+ if (finPort->getGObjectType() == GPORT)
{
- int id = _selectedObjects[i];
- GObjectController* cont = _controllers[id];
- cont->getView()->setState(DRAG);
- cont->getModel()->notifyObservers(_idManager);
+ GPortModel* modelPort = (GPortModel*) finPort->getModel();
+ modelContour->setEndPort(modelPort);
+
+ // JGRR CM
+ typedef std::map<int, GObjectController*>::iterator TIterator;
+ TIterator c_it = _controllers.begin();
+ TIterator iter_end = _controllers.end();
+ // Go through all componets
+ for (c_it; c_it != iter_end; c_it++) {
+ GObjectController* obc = c_it->second;
+ int obc_type = obc->getModel()->getGObjectType();
+ int obc_state = obc->getView()->getState();
+ // if the component is a port and the type is the same of that selected
+ if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
+ // Return element to neutral state if not selected
+ obc->getView()->setState(NOTHING_HAPPENS);
+ }
+ if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
+ // Change element to connected state
+ obc->getView()->setState(HIGHLIGHTED);
+
+ }
+
+ }
+ // EO JGRR CM
+
+ _parent->saveTempandUpdate("create connection");
}
- }
-
-
-
- return true;
- }
- //=========================================================================
-
- bool wxVtkSceneManager::OnLeftButtonUp()
- {
- if(_worldState == DRAG_OBJECTS)
- {
- _worldState = NOTHING_HAPPENS;
+ manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
+ manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
+
+ std::map<int, GObjectController*>::iterator it2;
- for (int i = 0; i < _selectedObjects.size(); i++)
+ for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
{
- int id = _selectedObjects[i];
- GObjectController* cont = _controllers[id];
- cont->getView()->setState(SELECTED);
- cont->getModel()->notifyObservers(_idManager);
+ GObjectController *cont = it2->second;
+ if (cont->getView() != NULL) {
+ cont->getView()->setState(NOTHING_HAPPENS);
+ cont->getModel()->notifyObservers(_idManager);
+ }
+ cont->SetActive(true);
}
+ connView->Refresh();
}
- return true;
- }
- //=========================================================================
+ }
+
+}
- bool wxVtkSceneManager::OnRightButtonUp()
- {
- if(_worldState==INIT_CREATION_CONTOUR)
- {
- _worldState=NOTHING_HAPPENS;
- //int lastId = _controllers.size()-1;
- GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
- connector->removeFromScene();
- unregisterController(connector);
- _controllers.erase(_idConnectionInCreation);
-
- std::map<int, GObjectController*>::iterator it;
- for(it = _controllers.begin(); it != _controllers.end(); ++it)
- {
- GObjectController *desc = it->second;
- desc->SetActive(true);
- desc->getView()->setState(NOTHING_HAPPENS);
- desc->getModel()->notifyObservers(_idManager);
- }
- }
+//=========================================================================
-
- for (int i = 0; i < _selectedObjects.size(); i++)
- {
+bool wxVtkSceneManager::OnMouseMove()
+{
+ int X, Y;
+ bool okStatusMessage = false;
+ bool okPortMessage = false;
+ wxVTKRenderWindowInteractor *wxVTKiren;
+ wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
+ wxVTKiren->GetEventPosition(X, Y);
+
+ if (_worldState == DRAG_OBJECTS) {
+ for (int i = 0; i < (int) _selectedObjects.size(); i++) {
int id = _selectedObjects[i];
GObjectController* cont = _controllers[id];
- cont->SetActive(true);
- cont->getView()->setState(NOTHING_HAPPENS);
+ if (_startDragging) {
+ cont->getView()->setStartDragging(true);
+ }
+ cont->getView()->moveObject(X, Y);
+ cont->getView()->setState(DRAG);
cont->getModel()->notifyObservers(_idManager);
}
- _selectedObjects.clear();
-
- return true;
- }
+ std::map<int, GObjectController*>::iterator it;
- //=========================================================================
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *desc = it->second;
+ if (desc->getGObjectType() == GCONNECTOR) {
+ vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
+ vconn->updateStartEndPoints();
+ }
+ }
- bool wxVtkSceneManager::OnLeftDClick()
- {
- int X,Y;
- wxVTKRenderWindowInteractor *wxVTKiren;
- wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
- wxVTKiren->GetEventPosition(X,Y);
+ _startDragging = false;
+ } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
std::map<int, GObjectController*>::iterator it;
+ double px, py, pz;
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *desc = it->second;
+ int type = desc->getGObjectType();
+ int state = desc->getView()->getState();
+ desc->getModel()->getCenter(px, py, pz);
- bool clickOnObject = false;
-
- for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
- {
- GObjectController *cont = it->second;
- int type = cont->getGObjectType();
-
- if(cont->getView()->isPointInside(X,Y))
+ // JGRR & CM
+ if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
{
- if(type==GBLACKBOX)
+ // EO JGRR & CM
+ okStatusMessage = true;
+ updateStatusBar(desc->getStatusText());
+ if (type == GBLACKBOX)
{
- for (int i=0; i<_selectedObjects.size(); i++)
+ GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
+ _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
+ } // if GBLACKBOX
+ if (type == GPORT)
+ {
+ // PortText
+ if ( ( _bugTextActor_text==desc->getStatusText() ) || (_bugTextActor_status==0) )
{
- int id = _selectedObjects[i];
- GObjectController* control = _controllers[id];
- control->getView()->setState(NOTHING_HAPPENS);
- }
- _selectedObjects.clear();
-
- GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
- _parent->editBlackBox(bbmodel);
- }
- clickOnObject = true;
- }
- }
-
- if(clickOnObject==false)
- {
- //_parent->editDiagramParameters(this);
- }
+ _bugTextActor_status = 1;
+ okPortMessage = true;
+ py = py + 5;
+ _textActor->SetScale(0.1);
+ std::string tmp = desc->getStatusText()+"\n";
+ _textActor->SetInput( tmp.c_str() );
+ _textActor->SetPosition(px - 25, py + 1, pz + 2);
+ _textActor->Modified();
+ // FillPortText
+ px = px - 33;
+ //py = py;
+ _fillObjectActor->SetScale(1);
+ _fillObjectActor->GetProperty()->SetOpacity(0.50);
+ _fillObjectActor->SetPosition(px, py, 1);
+ _aPolygonMapper->Modified();
+ } else {
+ _bugTextActor_status = 2;
+ } // _bugTextActor_tex
+ _bugTextActor_text = desc->getStatusText();
+
+ } // if GPORT
+ } //if state
+ } // for controllers it
+ }
+ if (okStatusMessage == false)
+ {
+ updateStatusBar("");
+ }
- return true;
+ if ((okPortMessage == false) || (_bugTextActor_status== 2 ) )
+ {
+ _bugTextActor_status = 0;
+ _textActor->SetScale(0.0001);
+ _textActor->SetInput("a\n");
+ _textActor->Modified();
+ _fillObjectActor->SetScale(0.0001);
}
-
- //=========================================================================
+ return true;
+}
- bool wxVtkSceneManager::OnChar()
- {
- char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
-
- // KeyCode 127 : Delete Key
- // KeyCode 8 : Backspace Key
- if(keyCode == 8 || keyCode == 127)
+//=========================================================================
+
+bool wxVtkSceneManager::OnLeftButtonDown()
+{
+ if (_worldState == INIT_CREATION_CONTOUR)
+ {
+ bool isOverPort = false;
+ std::map<int, GObjectController*>::iterator it;
+ for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
{
- if(_selectedObjects.size()>0)
+ GObjectController *desc = it->second;
+ if (desc->getGObjectType() == GPORT)
{
- for(int i=0;i<_selectedObjects.size();i++)
+ GPortModel *portmod = (GPortModel*) desc->getModel();
+ vtkGObjectView *portView = desc->getView();
+ if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
{
- int id = _selectedObjects[i];
- deleteObject(id);
- }
- _selectedObjects.clear();
- }
- }
+ isOverPort = true;
+ } // if
+ // JGRR & CM
+ if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
+ isOverPort = true ;
+ portView->setState( HIGHLIGHTED);
+ }
+ // EO JGRR & CM
+
+ } // if
+ } // for
+
+ if (isOverPort == false)
+ {
+ CancelConnection();
+ UnSelectBlackBoxes();
+ } // isOverPort
+
- return true;
- }
+ } else { //_worldState
- //=========================================================================
+ _worldState = DRAG_OBJECTS;
+ _startDragging = true;
- void wxVtkSceneManager::deleteObject(int id)
- {
- GObjectController *control = _controllers[id];
- std::vector<int> controllersToRemove;
+ int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
+ int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
+ ctrlkey = ctrlkey + shiftkey;
- if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
- {
- GBoxModel *bbmod = (GBoxModel*)control->getModel();
- std::vector<GPortModel*> inputs = bbmod->getInputPorts();
-
- bool boxConnected = false;
+ GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
- // Add box input controllers to be removed
- for(int i = 0;i<inputs.size();i++)
- {
- controllersToRemove.push_back(inputs[i]->getObjectId());
- if(inputs[i]->isConnected())
- {
- boxConnected = true;
- }
+ if (cont != NULL) {
+ int state = cont->getView()->getState();
+ if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
+ UnSelectBlackBoxes();
}
+ } else {
+ UnSelectBlackBoxes(); // EED 12/07/2012
+ }
+ for (int i = 0; i < (int) _selectedObjects.size(); i++) {
+ int id = _selectedObjects[i];
+ GObjectController *cont = _controllers[id];
+ cont->getView()->setState(DRAG);
+ cont->getModel()->notifyObservers(_idManager);
+ } // for
+ } // if _selectedObjects.size
- std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
- // Add box output controllers to be removed
- for(int i = 0;i<outputs.size();i++)
- {
- controllersToRemove.push_back(outputs[i]->getObjectId());
- if(outputs[i]->isConnected())
- {
- boxConnected = true;
- }
- }
+ return true;
+}
- // Add connection controllers to be removed
- std::map<int, GObjectController*>::iterator it;
- for(it = _controllers.begin(); it != _controllers.end(); ++it)
- {
- GObjectController *cont = it->second;
- int type = cont->getGObjectType();
- if(type==GCONNECTOR)
- {
- GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
- if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
- {
- controllersToRemove.push_back(conMod->getObjectId());
- }
- if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
- {
- controllersToRemove.push_back(conMod->getObjectId());
- }
- }
- }
+//=========================================================================
- // Add box controller to be removed
- controllersToRemove.push_back(bbmod->getObjectId());
- }
- else if(control->getGObjectType()==GCONNECTOR)
- {
- GConnectorModel *conMod = (GConnectorModel*)control->getModel();
- controllersToRemove.push_back(conMod->getObjectId());
- }
+bool wxVtkSceneManager::OnLeftButtonUp()
+{
+ if (_worldState == DRAG_OBJECTS) {
+ _worldState = NOTHING_HAPPENS;
- for(int i = 0;i<controllersToRemove.size();i++)
- {
- int id = controllersToRemove[i];
- GObjectController *cont = _controllers[id];
- if(cont!=NULL)
- {
- cont->removeFromScene();
- unregisterController((InteractorStyleMaracas*)cont);
- _controllers.erase(id);
- }
+ for (int i = 0; i < (int) _selectedObjects.size(); i++) {
+ int id = _selectedObjects[i];
+ GObjectController* cont = _controllers[id];
+ cont->getView()->setState(SELECTED);
+ cont->getModel()->notifyObservers(_idManager);
}
+ }
+ return true;
+}
+//=========================================================================
+void wxVtkSceneManager::CancelConnection()
+{
+ if (_worldState == INIT_CREATION_CONTOUR)
+ {
+ _worldState = NOTHING_HAPPENS;
+ //int lastId = _controllers.size()-1;
- }
+ GConnectorController *connector =
+ (GConnectorController*) _controllers[_idConnectionInCreation];
+ connector->removeFromScene();
+ unregisterController(connector);
+ _controllers.erase(_idConnectionInCreation);
- //=========================================================================
+ std::map<int, GObjectController*>::iterator it;
+ for (it = _controllers.begin(); it != _controllers.end(); ++it)
+ {
+ GObjectController *desc = it->second;
+ desc->SetActive(true);
+ desc->getView()->setState(NOTHING_HAPPENS);
+ desc->getModel()->notifyObservers(_idManager);
+ } // for
+ }// if
+}
+
+//=========================================================================
- void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
+bool wxVtkSceneManager::OnRightButtonUp()
+{
+ if (_worldState == INIT_CREATION_CONTOUR)
{
- _parent->displayBlackBoxInfo(packageName,boxName);
+ CancelConnection();
}
+ UnSelectBlackBoxes();
+ return true;
+}
- //=========================================================================
+ ///JLGR 21-05-2012
- void wxVtkSceneManager::updateStatusBar(std::string textStatus)
- {
- _parent->updateStatusBar(textStatus);
- }
+bool wxVtkSceneManager::OnMiddleButtonDown() {
- //=========================================================================
- std::string wxVtkSceneManager::getDiagramBBS()
- {
- bool existsExec=false;
+ this->_vtkInteractorStyleBaseView->StartPan();
- std::vector<std::string> packages;
- std::vector<int> boxes;
- std::vector<int> connections;
- std::vector<int> execBoxes;
+ return true;
+ }
- std::map<int, GObjectController*>::iterator it;
+bool wxVtkSceneManager::OnMiddleButtonUp() {
- for(it = _controllers.begin(); it != _controllers.end(); ++it)
- {
- GObjectController *desc = it->second;
- int type = desc->getGObjectType();
- if(type==GBLACKBOX)
- {
- GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
-
- std::string pkg = mod->getBBTKPackage();
- bool existsPkg = false;
- for(int t = 0;t<packages.size() && existsPkg == false;t++)
- {
- if(packages[t]==pkg)
- {
- existsPkg=true;
- }
- }
- if(!existsPkg)
- {
- packages.push_back(pkg);
- }
+ this->_vtkInteractorStyleBaseView->EndPan();
- boxes.push_back(it->first);
- if(mod->isExecutable())
- {
- execBoxes.push_back(it->first);
- existsExec=true;
- }
- }
- else if(type==GCONNECTOR)
- {
- connections.push_back(it->first);
- }
- }
+ return true;
+ }
+
+
+//=========================================================================
+
+GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
+ GObjectController *result = NULL;
+ int X, Y;
+ wxVTKRenderWindowInteractor *wxVTKiren;
+ wxVTKiren
+ = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
+ wxVTKiren->GetEventPosition(X, Y);
+
+ std::map<int, GObjectController*>::iterator it;
+
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *cont = it->second;
+ int type = cont->getGObjectType();
+
+ if (cont->getView()->isPointInside(X, Y) == true) {
+ if (type == GBLACKBOX) {
+ result = cont;
+ } // if type
+ } // if isPointInside
+ } // for it
+ return result;
+}
- std::string script = "";
- script+="# BBTK GEditor Script\n";
- script+="# ----------------------\n";
- if(existsExec)
+//=========================================================================
+void wxVtkSceneManager::UnSelectBlackBoxes() {
+ for (int i = 0; i < (int) _selectedObjects.size(); i++) {
+ int id = _selectedObjects[i];
+ GObjectController* control = _controllers[id];
+ control->getView()->setState(NOTHING_HAPPENS);
+ control->getModel()->notifyObservers(_idManager);
+ }// for _selectedObjects
+ _selectedObjects.clear();
+}
+
+//=========================================================================
+bool wxVtkSceneManager::OnLeftDClick() {
+ GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
+ if (cont != NULL) {
+ UnSelectBlackBoxes();
+ _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
+ }
+
+ /*EED Borrame
+
+ int X,Y;
+ wxVTKRenderWindowInteractor *wxVTKiren;
+ wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
+ wxVTKiren->GetEventPosition(X,Y);
+
+ std::map<int, GObjectController*>::iterator it;
+
+ bool clickOnObject = false;
+
+ for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
+ {
+ GObjectController *cont = it->second;
+ int type = cont->getGObjectType();
+
+ if(cont->getView()->isPointInside(X,Y))
+ {
+ if(type==GBLACKBOX)
+ {
+ for (int i=0; i< (int)_selectedObjects.size(); i++)
+ {
+ int id = _selectedObjects[i];
+ GObjectController* control = _controllers[id];
+ control->getView()->setState(NOTHING_HAPPENS);
+ }
+ _selectedObjects.clear();
+
+ GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
+ _parent->editBlackBox(bbmodel);
+ }
+ clickOnObject = true;
+ }
+ }
+
+ if(clickOnObject==false)
+ {
+ //_parent->editDiagramParameters(this);
+ }
+ */
+ return true;
+}
+
+//=========================================================================
+
+bool wxVtkSceneManager::OnChar()
+{
+ bool ok=false;
+ bool oktmp;
+ char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
+ int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
+
+ // KeyCode 127 : Delete Key
+ // KeyCode 8 : Backspace Key
+
+
+ if (keyCode == 8 || keyCode == 127 || keyCode == 27)
+ {
+ if (_worldState == INIT_CREATION_CONTOUR)
{
- script+="include std\n"; // EED
- script+="include itkvtk\n"; // EED
- int i;
- for(i = 0; i<packages.size();i++)
- {
- script+="include ";
- script+=packages[i];
- script+="\n";
- }
+ CancelConnection();
+ UnSelectBlackBoxes();
+ }
+ }
+
- // script+="include std\n"; // JPR
+ if (keyCode == 8 || keyCode == 127)
+ {
- for(i = 0; i<boxes.size();i++)
+ for (int i = 0; i < (int) _selectedObjects.size(); i++)
{
- script+="new ";
- int id = boxes[i];
- GObjectController *control = _controllers[id];
- GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
-
- script+=model->getBBTKType();
- script+=" ";
- script+=model->getBBTKName();
- script+="\n";
-
- std::vector<GPortModel*> inputs = model->getInputPorts();
- for(int j = 0; j<inputs.size();j++)
+ int id = _selectedObjects[i];
+ std::map<int, GObjectController*>::iterator it;
+ it = _controllers.find(id);
+ if (it != _controllers.end())
{
- GPortModel* inputPort = inputs[j];
- if(inputPort->isValueSet())
- {
- script+="set ";
- script+=model->getBBTKName();
- script+=".";
- script+=inputPort->getBBTKName();
- script+=" ";
- script+=inputPort->getValue();
- script+="\n";
- }
- }
-
- }
-
- for(i = 0; i<connections.size();i++)
+ oktmp = deleteObject(id);
+ ok = ok||oktmp;
+ } // if
+ }// for selected objects
+ if (ok) _selectedObjects.clear();
+ _parent->saveTempandUpdate("delete object");
+ }// if keyCode
+
+ /// Duplicate
+#ifdef MACOSX
+ if((keyCode==0) && (ctrlkey==1)) {
+#else
+ ctrlkey+=keyCode;
+ if(ctrlkey==5){
+#endif
+ if(_selectedObjects.size()){
+ std::cout<<"objects to copy :";
+ for(int i=0;i<_selectedObjects.size();i++)
{
- script+="connect ";
- int id = connections[i];
- GObjectController *control = _controllers[id];
- GConnectorModel *model = (GConnectorModel*)control->getModel();
-
- //Start Connection info
- GPortModel *start = model->getStartPort();
- script+=start->getParentBox()->getBBTKName();
- script+=".";
- script+=start->getBBTKName();
-
- script+=" ";
-
- //End Connection info
- GPortModel *end = model->getEndPort();
- script+=end->getParentBox()->getBBTKName();
- script+=".";
- script+=end->getBBTKName();
-
- script+="\n";
+ std::cout<<_selectedObjects.at(i)<<" ";
}
+ DuplicateObjects(getSelectedObjects());
+ }else{
+ std::cout<<"No objects to copy\n";
+ } // _selectedObjects.size
+ } // ctrlkey 5
- for(i = 0; i<execBoxes.size();i++)
- {
- script+="exec ";
- int id = execBoxes[i];
- GObjectController *control = _controllers[id];
- GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
+ return true;
+}
- script+=model->getBBTKName();
- script+="\n";
- }
+//=========================================================================
+void wxVtkSceneManager::AddControlerToBeRemove(
+ std::vector<int> *controllersToRemove, int id) {
+
+ int i;
+ bool ok = true;
+ for (i = 0; i < (int) controllersToRemove->size(); i++) {
+ if (id == (*controllersToRemove)[i]) {
+ ok = false;
}
+ }
- return script;
+ if (ok == true) {
+ controllersToRemove->push_back(id);
}
- //=========================================================================
+}
- std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
- {
+//=========================================================================
- std::vector<std::string> packages;
- std::vector<int> boxes;
- std::vector<int> connections;
- std::vector<int> execBoxes;
+bool wxVtkSceneManager::deleteObject(int id)
+{
+ bool result=true;
+ GObjectController *control = _controllers[id];
+ std::vector<int> controllersToRemove;
+ if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
+ == GCOMPLEXINPUTPORT || control->getGObjectType()
+ == GCOMPLEXOUTPUTPORT) {
+ GBoxModel *bbmod = (GBoxModel*) control->getModel();
+ std::vector<GPortModel*> inputs = bbmod->getInputPorts();
+
+ bool boxConnected = false;
+
+ // Add box input controllers to be removed
+ for (int i = 0; i < (int) inputs.size(); i++) {
+ AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
+ if (inputs[i]->isConnected()) {
+ boxConnected = true;
+ }
+ }
- std::map<int, GObjectController*>::iterator it;
+ std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
- for(it = _controllers.begin(); it != _controllers.end(); ++it)
- {
- GObjectController *desc = it->second;
- int type = desc->getGObjectType();
+ // Add box output controllers to be removed
+ for (int i = 0; i < (int) outputs.size(); i++) {
+ AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
+ if (outputs[i]->isConnected()) {
+ boxConnected = true;
+ }
+ }
- if(type==GBLACKBOX)
- {
- GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
-
- std::string pkg = mod->getBBTKPackage();
- bool existsPkg = false;
- for(int t = 0;t<packages.size() && existsPkg == false;t++)
+ // Add connection controllers to be removed
+ std::map<int, GObjectController*>::iterator it;
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *cont = it->second;
+ int type = cont->getGObjectType();
+ if (type == GCONNECTOR) {
+ GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
+ if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
{
- if(packages[t]==pkg)
- {
- existsPkg=true;
- }
+ AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
}
- if(!existsPkg)
+ if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
{
- packages.push_back(pkg);
+ AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
}
+ }
+ }
+ // Add box controller to be removed
+ AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
+ } else if (control->getGObjectType() == GCONNECTOR) {
+ GConnectorController *gconnectorcontroler = (GConnectorController*)control;
+ if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
+ {
+ GConnectorModel *conMod = (GConnectorModel*) control->getModel();
+ AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
+ } else{
+ gconnectorcontroler->getManualContourController()->OnChar();
+ result = false;
+ }
+ }
- boxes.push_back(it->first);
- if(mod->isExecutable())
- {
- execBoxes.push_back(it->first);
+ std::map<int, GObjectController*>::iterator it;
+
+ for (int i = 0; i < (int) controllersToRemove.size(); i++) {
+ int key = controllersToRemove[i];
+ it = _controllers.find(key);
+ GObjectController *cont = _controllers[key];
+ if (cont != NULL) {
+ cont->removeFromScene();
+ unregisterController((InteractorStyleMaracas*) cont);
+ _controllers.erase(it);
+ }//if
+ }// for
+
+
+ return result;
+}
+
+//=========================================================================
+
+void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
+ std::string boxName) {
+ _parent->displayBlackBoxInfo(packageName, boxName);
+}
+
+//=========================================================================
+
+void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
+ _parent->updateStatusBar(textStatus);
+}
+
+//=========================================================================
+std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
+ std::string result = "";
+ if (withLineNumber == true) {
+ value++;
+ stringstream StrStream;
+ StrStream << value;
+ std::string strValue = StrStream.str();
+ if (value < 10) {
+ result += " ";
+ } else if (value < 100) {
+ result += " ";
+ }
+
+ result += strValue + ": ";
+ }
+ return result;
+}
+//=========================================================================
+//DFCH
+bool wxVtkSceneManager::MakeBoxExecutable() {
+ std::map<int, GObjectController*> selected = getSelectedObjects();
+ if( selected.empty() )
+ return false;
+ bool ret = false;
+ std::map<int, GObjectController*>::iterator it;
+ for (it = selected.begin(); it != selected.end(); ++it) {
+ GObjectController* lastSelected = it->second;
+ if (lastSelected) {
+ vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
+ GBlackBoxModel *bbmodel =
+ (GBlackBoxModel*) lastSelected->getModel();
+ view->setState(HIGHLIGHTED);
+ if (bbmodel->isExecutable()) {
+ bbmodel->setExecutable(false);
+ } else {
+ bbmodel->setExecutable(true);
+ }
+ bbmodel->notifyObservers(lastSelected->getId());
+ ret = true;
+ }
+ }
+ return ret;
+}
+//DFCH
+
+//=========================================================================
+
+std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
+ std::cout << "wxVtkSceneManager::getDiagramBBS" << std::endl;
+ bool existsExec = false;
+
+ std::vector<std::string> packages;
+ std::vector<int> boxes;
+ std::vector<int> connections;
+ std::vector<int> execBoxes;
+
+ std::map<int, GObjectController*>::iterator it;
+
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *desc = it->second;
+ int type = desc->getGObjectType();
+
+ if (type == GBLACKBOX) {
+ GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
+
+ std::string pkg = mod->getBBTKPackage();
+ bool existsPkg = false;
+ for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
+ if (packages[t] == pkg) {
+ existsPkg = true;
}
}
- else if(type==GCONNECTOR)
- {
- connections.push_back(it->first);
+ if (!existsPkg) {
+ packages.push_back(pkg);
}
- }
- std::string script = "";
+ boxes.push_back(it->first);
+ if (mod->isExecutable()) {
+ execBoxes.push_back(it->first);
+ existsExec = true;
+ }
+ } else if (type == GCONNECTOR) {
+ connections.push_back(it->first);
+ }
+ }
- script+="include std\n"; // EED
- script+="include itkvtk\n"; // EED
+ int lnNmbr = 0;
+ std::string script = "";
+ script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
+ script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
+ script += LineNumber(wln, lnNmbr) + "\n";
+ if (existsExec) {
+ script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
+ script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
int i;
- for(i = 0; i<packages.size();i++)
- {
- script+="include ";
- script+=packages[i];
- script+="\n";
+ for (i = 0; i < (int) packages.size(); i++) {
+ script += LineNumber(wln, lnNmbr);
+ script += "include ";
+ script += packages[i];
+ script += "\n";
}
- // Definition of a complex box
- script+="define ";
- script+=cbName;
- script+="\n";
+ script += LineNumber(wln, lnNmbr);
+ script += "\n";
- script+="author \" ";
- script+=cbAuthor;
- script+="\"\n";
+ //ups2
+
+ script += LineNumber(wln, lnNmbr);
+ script += "author \"";
+ script += _Author;
+ script += "\"\n";
- script+="description \" ";
- script+=cbDescription;
- script+="\"\n";
+ script += LineNumber(wln, lnNmbr);
+ script += "description \"";
+ script += _Description;
+ script += "\"\n";
- // Create boxes
- for(i = 0; i<boxes.size();i++)
- {
- script+="new ";
- int id = boxes[i];
- GObjectController *control = _controllers[id];
- GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
+ script += LineNumber(wln, lnNmbr);
+ script += "category \"";
+ script += _Category;
+ script += "\"\n";
- script+=model->getBBTKType();
- script+=" ";
- script+=model->getBBTKName();
- script+="\n";
+ script += LineNumber(wln, lnNmbr);
+ script += "\n";
- std::vector<GPortModel*> inputs = model->getInputPorts();
- for(int j = 0; j<inputs.size();j++)
- {
- GPortModel* inputPort = inputs[j];
- if(inputPort->isValueSet())
- {
- script+="set ";
- script+=model->getBBTKName();
- script+=".";
- script+=inputPort->getBBTKName();
- script+=" ";
- script+=inputPort->getValue();
- script+="\n";
- }
- }
+ // script+="include std\n"; // JPR
+ for (i = 0; i < (int) boxes.size(); i++) {
+ script += LineNumber(wln, lnNmbr);
+ script += "new ";
+ int id = boxes[i];
+ GObjectController *control = _controllers[id];
+ GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
+
+ script += model->getBBTKType();
+ script += " ";
+ script += model->getBBTKName();
+ script += "\n";
+
+ std::vector<GPortModel*> inputs = model->getInputPorts();
+ for (int j = 0; j < (int) inputs.size(); j++) {
+ GPortModel* inputPort = inputs[j];
+ if (inputPort->isValueSet()) {
+ script += LineNumber(wln, lnNmbr);
+ script += " set ";
+ script += model->getBBTKName();
+ script += ".";
+ script += inputPort->getBBTKName();
+ script += " ";
+ script += inputPort->getValue();
+ script += "\n";
+ }
}
- // Create connections in the script. If the connection is made with a complex port, it is created the input or output
+ script += LineNumber(wln, lnNmbr);
+ script += "\n";
- std::string complexInputs="";
- std::string complexOutputs="";
+ }
- for(i = 0; i<connections.size();i++)
- {
- int id = connections[i];
- GObjectController *control = _controllers[id];
- GConnectorModel *model = (GConnectorModel*)control->getModel();
+ script += LineNumber(wln, lnNmbr);
+ script += "\n";
- //Connection info
- GPortModel *start = model->getStartPort();
- GBoxModel *startBox =start->getParentBox();
- GPortModel *end = model->getEndPort();
- GBoxModel *endBox =end->getParentBox();
+ std::string complexInputs="";
- if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
- {
- complexInputs+="input ";
- complexInputs+=startBox->getBBTKName();
+ for (i = 0; i < (int) connections.size(); i++) {
+ //script += LineNumber(wln, lnNmbr);
+ //script += "connect ";
+ int id = connections[i];
+ GObjectController *control = _controllers[id];
+ GConnectorModel *model = (GConnectorModel*) control->getModel();
- complexInputs+=" ";
- complexInputs+=endBox->getBBTKName();
- complexInputs+=".";
- complexInputs+=end->getBBTKName();
- complexInputs+=" ";
- complexInputs+="\" \"";
+ //Connection info
+ GPortModel *start = model->getStartPort();
+ GBoxModel *startBox = start->getParentBox();
- complexInputs+="\n";
- }
- else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
- {
- complexOutputs+="output ";
- complexOutputs+=endBox->getBBTKName();
+ GPortModel *end = model->getEndPort();
+ GBoxModel *endBox = end->getParentBox();
- complexOutputs+=" ";
- complexOutputs+=startBox->getBBTKName();
- complexOutputs+=".";
- complexOutputs+=start->getBBTKName();
+ if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
+ {
+ complexInputs += "input ";
+ complexInputs += startBox->getBBTKName();
- complexOutputs+=" ";
- complexOutputs+="\" \"";
+ complexInputs += " ";
+ complexInputs += endBox->getBBTKName();
+ complexInputs += ".";
+ complexInputs += end->getBBTKName();
- complexOutputs+="\n";
- }
- else
- {
- script+="connect ";
- script+=startBox->getBBTKName();
- script+=".";
- script+=start->getBBTKName();
+ complexInputs += " ";
+ complexInputs += "\" \"";
- script+=" ";
+ complexInputs += "\n";
+ }
+ else
+ {
+ script += "connect ";
+ script += startBox->getBBTKName();
+ script += ".";
+ script += start->getBBTKName();
+
+ script += " ";
//End Connection info
- script+=endBox->getBBTKName();
- script+=".";
- script+=end->getBBTKName();
+ script += endBox->getBBTKName();
+ script += ".";
+ script += end->getBBTKName();
- script+="\n";
- }
+ script += "\n";
}
- for(i = 0; i<execBoxes.size();i++)
- {
- script+="exec ";
- int id = execBoxes[i];
- GObjectController *control = _controllers[id];
- GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
+ script += "\n";
+ }
- script+=model->getBBTKName();
- script+="\n";
- }
+ script += LineNumber(wln, lnNmbr);
+ script += "\n";
+
+ script += "\n";
+ script += "# Complex input ports\n";
+ script += complexInputs;
- script+="\n";
- script+="# Complex input ports\n";
- script+=complexInputs;
+ script += LineNumber(wln, lnNmbr);
+ script += "message ";
+ script += _MessageKind;
+ script += " ";
+ script += _MessageLevel;
+ script += "\n";
- script+="\n";
- script+="# Complex output ports\n";
- script+=complexOutputs;
+ for (i = 0; i < (int) execBoxes.size(); i++) {
+ script += LineNumber(wln, lnNmbr);
+ script += "exec ";
+ int id = execBoxes[i];
+ GObjectController *control = _controllers[id];
+ GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
- script+="\n";
- script+="endefine";
- script+="\n";
+ script += model->getBBTKName();
+ script += "\n";
+ }
- return script;
}
- //=========================================================================
+ return script;
+}
- void wxVtkSceneManager::deleteAllBoxes()
- {
- std::map<int, GObjectController*>::iterator it;
- for(it = _controllers.begin(); it != _controllers.end(); ++it)
- {
- GObjectController *cont = it->second;
- cont->removeFromScene();
- unregisterController((InteractorStyleMaracas*)cont);
+//=========================================================================
+
+std::string wxVtkSceneManager::saveComplexBoxBBS() {
+ std::cout<<"wxVtkSceneManager::saveComplexBoxBBS"<<std::endl;
+ std::vector<std::string> packages;
+ std::vector<int> boxes;
+ std::vector<int> connections;
+ std::vector<int> execBoxes;
+
+ std::map<int, GObjectController*>::iterator it;
+
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *desc = it->second;
+ int type = desc->getGObjectType();
+
+ if (type == GBLACKBOX) {
+ GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
+
+ std::string pkg = mod->getBBTKPackage();
+ bool existsPkg = false;
+ for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
+ if (packages[t] == pkg) {
+ existsPkg = true;
+ }
+ }
+ if (!existsPkg) {
+ packages.push_back(pkg);
+ }
+
+ boxes.push_back(it->first);
+ if (mod->isExecutable()) {
+ execBoxes.push_back(it->first);
+ }
+ } else if (type == GCONNECTOR) {
+ connections.push_back(it->first);
}
- _selectedObjects.clear();
- _controllers.clear();
- refreshScene();
}
- //=========================================================================
+ std::string script = "";
- void wxVtkSceneManager::refreshScene()
- {
- _baseView->RefreshView();
+ script += "include std\n"; // EED
+ script += "include itkvtk\n"; // EED
+ int i;
+ for (i = 0; i < (int) packages.size(); i++) {
+ script += "include ";
+ script += packages[i];
+ script += "\n";
}
-
- //=========================================================================
-
- void wxVtkSceneManager::centerView()
- {
- double temp[3];
- _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
- _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
- _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
- _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
- _baseView->RefreshView();
+ script += "\n";
+
+ // Definition of a complex box
+ script += "define ";
+ script += _cbName + " " + _cbPackageName;
+ script += "\n";
+ script += "\n";
+
+ script += "author \"";
+ script += _Author;
+ script += "\"\n";
+
+ script += "description \"";
+ script += _Description;
+ script += "\"\n";
+ script += "\n";
+
+ script += "category \"";
+ script += _Category;
+ script += "\"\n";
+ script += "\n";
+
+ // Create boxes
+ for (i = 0; i < (int) boxes.size(); i++) {
+ script += "new ";
+ int id = boxes[i];
+ GObjectController *control = _controllers[id];
+ GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
+
+ script += model->getBBTKType();
+ script += " ";
+ script += model->getBBTKName();
+ script += "\n";
+
+ std::vector<GPortModel*> inputs = model->getInputPorts();
+ for (int j = 0; j < (int) inputs.size(); j++) {
+ GPortModel* inputPort = inputs[j];
+ if (inputPort->isValueSet()) {
+ script += " set ";
+ script += model->getBBTKName();
+ script += ".";
+ script += inputPort->getBBTKName();
+ script += " ";
+ script += inputPort->getValue();
+ script += "\n";
+ }
+ }
+ script += "\n";
}
- //=========================================================================
+ // Create connections in the script. If the connection is made with a complex port, it is created the input or output
- void wxVtkSceneManager::saveDiagram(std::string &content)
- {
-printf("EED %p wxVtkSceneManager::saveDiagram 1\n",this);
- char buffer [50];
+ std::string complexInputs = "";
+ std::string complexOutputs = "";
+ script += "\n";
- //Print info IF COMPLEX BOX
- content+="COMPLEXBOX:";
- if(_isComplexBox)
- {
-printf("EED %p wxVtkSceneManager::saveDiagram 2\n",this);
- content+="TRUE\n";
-
- //Print info complex input ports
- std::vector<int> inputs = getComplexInputPorts();
- int insize = inputs.size();
- content+="COMPLEXINPUTS:";
- sprintf (buffer, "%d", insize);
- content+=buffer;
- content+="\n";
-
- for(int i = 0;i<insize;i++)
- {
- int id = inputs[i];
- GObjectController *cont = _controllers[id];
- cont->getModel()->save(content);
- }
+ for (i = 0; i < (int) connections.size(); i++) {
+ int id = connections[i];
+ GObjectController *control = _controllers[id];
+ GConnectorModel *model = (GConnectorModel*) control->getModel();
- //Print info complex output ports
- std::vector<int> outputs = getComplexOutputPorts();
- int outsize = outputs.size();
- content+="COMPLEXOUTPUTS:";
- sprintf (buffer, "%d", outsize);
- content+=buffer;
- content+="\n";
-
- for(int i = 0;i<outsize;i++)
- {
- int id = outputs[i];
- GObjectController *cont = _controllers[id];
- cont->getModel()->save(content);
- }
- } // _isComplexBox
- else
- {
- content+="FALSE\n";
+ //Connection info
+ GPortModel *start = model->getStartPort();
+ GBoxModel *startBox = start->getParentBox();
+
+ GPortModel *end = model->getEndPort();
+ GBoxModel *endBox = end->getParentBox();
+
+ if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
+ complexInputs += "input ";
+ complexInputs += startBox->getBBTKName();
+
+ complexInputs += " ";
+ complexInputs += endBox->getBBTKName();
+ complexInputs += ".";
+ complexInputs += end->getBBTKName();
+
+ complexInputs += " ";
+ complexInputs += "\" \"";
+
+ complexInputs += "\n";
+ } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
+ complexOutputs += "output ";
+ complexOutputs += endBox->getBBTKName();
+
+ complexOutputs += " ";
+ complexOutputs += startBox->getBBTKName();
+ complexOutputs += ".";
+ complexOutputs += start->getBBTKName();
+
+ complexOutputs += " ";
+ complexOutputs += "\" \"";
+
+ complexOutputs += "\n";
+ } else {
+ script += "connect ";
+ script += startBox->getBBTKName();
+ script += ".";
+ script += start->getBBTKName();
+
+ script += " ";
+
+ //End Connection info
+ script += endBox->getBBTKName();
+ script += ".";
+ script += end->getBBTKName();
+
+ script += "\n";
}
+ }
- //Print boxes
- std::vector<int> boxes = getBlackBoxes();
- int bsize = boxes.size();
- content+="BOXES:";
- sprintf (buffer, "%d", bsize);
- content+=buffer;
- content+="\n";
-
-printf("EED %p wxVtkSceneManager::saveDiagram 3\n",this);
- for(int i = 0;i<bsize;i++)
- {
- int id = boxes[i];
+ script += "\n";
+ script += "# Complex input ports\n";
+ script += complexInputs;
+
+ script += "\n";
+ script += "# Complex output ports\n";
+ script += complexOutputs;
+
+ script += "\n";
+
+ script += "message ";
+ script += _MessageKind;
+ script += " ";
+ script += _MessageLevel;
+ script += "\n";
+
+ for (i = 0; i < (int) execBoxes.size(); i++) {
+ script += "exec ";
+ int id = execBoxes[i];
+ GObjectController *control = _controllers[id];
+ GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
+
+ script += model->getBBTKName();
+ script += "\n";
+ }
+
+ script += "\n";
+ script += "endefine";
+ script += "\n";
+
+ return script;
+}
+
+//=========================================================================
+
+void wxVtkSceneManager::deleteAllBoxes() {
+ std::map<int, GObjectController*>::iterator it;
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *cont = it->second;
+ cont->removeFromScene();
+ unregisterController((InteractorStyleMaracas*) cont);
+ }
+ _selectedObjects.clear();
+ _controllers.clear();
+}
+
+//=========================================================================
+
+
+void wxVtkSceneManager::refresh() {
+ _baseView->Refresh();
+}
+//=========================================================================
+
+void wxVtkSceneManager::refreshScene() {
+ _baseView->RefreshView();
+}
+
+//=========================================================================
+
+void wxVtkSceneManager::centerView() {
+ double temp[3];
+ _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
+ _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
+ _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
+ _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
+}
+
+//=========================================================================
+
+void wxVtkSceneManager::saveDiagram(std::string &content) {
+ char buffer[50];
+
+ content += "CATEGORY:";
+ content += GetCategory();
+ content += "\n";
+
+ content += "DESCRIPTION:";
+ content += GetDescription();
+ content += "\n";
+
+ content += "AUTHOR:";
+ content += GetAuthor();
+ content += "\n";
+
+ //Print info IF COMPLEX BOX
+ content += "COMPLEXBOX:";
+ if (_isComplexBox) {
+ content += "TRUE\n";
+ //ups1
+ content += "COMPLEXBOXNAME:";
+ content += GetCbName();
+ content += "\n";
+
+ content += "PACKAGENAME:";
+ content += GetCbPackageName();
+ content += "\n";
+
+ /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
+ * External inputs are possible for applications and complex boxes
+ //Print info complex input ports
+ std::vector<int> inputs = getComplexInputPorts();
+ int insize = inputs.size();
+ content += "COMPLEXINPUTS:";
+ sprintf(buffer, "%d", insize);
+ content += buffer;
+ content += "\n";
+
+ for (int i = 0; i < insize; i++) {
+ int id = inputs[i];
GObjectController *cont = _controllers[id];
cont->getModel()->save(content);
}
-
- //Print connections
- std::vector<int> connections = getConnections();
- int csize = connections.size();
- content+="CONNECTIONS:";
- sprintf (buffer, "%d", csize);
- content+=buffer;
- content+="\n";
-
-printf("EED %p wxVtkSceneManager::saveDiagram 4\n",this);
- for(int i = 0;i<csize;i++)
- {
- int id = connections[i];
+ */
+
+ //Print info complex output ports
+ std::vector<int> outputs = getComplexOutputPorts();
+ int outsize = outputs.size();
+ content += "COMPLEXOUTPUTS:";
+ sprintf(buffer, "%d", outsize);
+ content += buffer;
+ content += "\n";
+
+ for (int i = 0; i < outsize; i++) {
+ int id = outputs[i];
GObjectController *cont = _controllers[id];
cont->getModel()->save(content);
}
+ } // _isComplexBox
+ else {
+ content += "FALSE\n";
+ }
+ // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
+ // External inputs are possible for applications and complex boxes
+ std::vector<int> inputs = getComplexInputPorts();
+ int insize = inputs.size();
+ content += "COMPLEXINPUTS:";
+ sprintf(buffer, "%d", insize);
+ content += buffer;
+ content += "\n";
+
+ for (int i = 0; i < insize; i++) {
+ int id = inputs[i];
+ GObjectController *cont = _controllers[id];
+ cont->getModel()->save(content);
}
- //=========================================================================
+ //Print boxes
+ std::vector<int> boxes = getBlackBoxes();
+ int bsize = boxes.size();
+ content += "BOXES:";
+ sprintf(buffer, "%d", bsize);
+ content += buffer;
+ content += "\n";
+
+ for (int i = 0; i < bsize; i++) {
+ int id = boxes[i];
+ std::cout<<"id "<<id<<std::endl;//CFT
+ GObjectController *cont = _controllers[id];
+ std::cout<<"nombre: "<<cont->getStatusText()<<std::endl;//CFT
+ std::cout<<"tipo: "<<cont->getModel()->getBBTKType()<<std::endl;//CFT
+ //boxesDiagram[i] = cont->getModel()->getBBTKType();//CFT
+ std::cout<<"nname: "<<cont->getModel()->getBBTKName()<<std::endl;//CFT
+ std::cout<<"categorie: "<<GetCategory()<<std::endl;//CFT
+ std::cout<<"type: "<<cont->getModel()->getGObjectType()<<std::endl;//CFT
+ cont->getModel()->save(content);
+ }
- void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
- {
-printf("EED %p wxVtkSceneManager::loadDiagram 1\n",this);
+ //Print connections
+ std::vector<int> connections = getConnections();
+ int csize = connections.size();
+ content += "CONNECTIONS:";
+ sprintf(buffer, "%d", csize);
+ content += buffer;
+ content += "\n";
+
+ for (int i = 0; i < csize; i++) {
+ int id = connections[i];
+ GObjectController *cont = _controllers[id];
+ cont->getModel()->save(content);
+ }
- std::string line="";
- char delims[] = ":";
- char *result = NULL;
- getline(inputStream,line);
+}
- bool start = false;
- while ( !inputStream.eof() )
+//=========================================================================
+void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
+{
+ getline(inputStream, line,'\n');
+ int size = line.length();
+ if (size>0)
+ {
+ if ( line[ size-1 ]==13 )
{
- if(line=="" || line[0]=='#')
- {
- getline(inputStream,line);
+ line.erase(size-1,1);
+ } // if line
+ } // if size
+}
+
+//=========================================================================
+void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
+{
+
+ int size;
+ std::string version = "<void>";
+ std::string line = "";
+ char delims[] = ":";
+ char *result = NULL;
+ char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
+
+ getCleanLine(inputStream, line);
+
+ bool start = false;
+ while (!inputStream.eof()) {
+ if (line == "" || line[0] == '#') {
+ line="";
+ getCleanLine(inputStream, line);
+
+ if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
+ version = line.substr(18, 3);
}
- else if(line=="APP_START")
- {
-printf("EED %p wxVtkSceneManager::loadDiagram 2\n",this);
- start = true;
- break;
+ if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
+ version = line.substr(18, 3);
+ }
+ if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
+ version = line.substr(18, 3);
}
+ if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
+ version = line.substr(18, 3);
+ }
+ if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
+ version = line.substr(18, 3);
+ }
+ } else if (line == "APP_START") {
+ start = true;
+ break;
}
+ }
- if(start)
- {
-printf("EED %p wxVtkSceneManager::loadDiagram 3\n",this);
- //----------
- getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
- char complex[20];
- strcpy( complex, line.c_str() );
- result = strtok( complex, delims );
- result = strtok( NULL, delims );
- std::string isComplexBox(result);
-
- if(isComplexBox=="TRUE")
- {
-printf("EED %p wxVtkSceneManager::loadDiagram 4\n",this);
- _isComplexBox=true;
+ if (start) {
+
+ if ((version != "1.0") && (version != "1.1")) {
+ getCleanLine(inputStream, line);//CATEGORY:<category of the box>
+ char categoryTmp[30];
+ strcpy(categoryTmp, line.c_str());
+ result = strtok(categoryTmp, delims);
+ result = strtok(NULL, delims);
+ SetCategory(result);
+
+ getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
+ char descriptionTmp[1024];
+ strcpy(descriptionTmp, line.c_str());
+ result = strtok(descriptionTmp, delims);
+ result = strtok(NULL, delims);
+ SetDescription(result);
+
+ getCleanLine(inputStream, line);//AUTHOR:<author>
+ char authorTmp[255];
+ strcpy(authorTmp, line.c_str());
+ result = strtok(authorTmp, delims);
+ result = strtok(NULL, delims);
+ SetAuthor(result);
+ }
+
+ //----------
+ getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
+ char complexTmp[30];
+ strcpy(complexTmp, line.c_str());
+ result = strtok(complexTmp, delims);
+ result = strtok(NULL, delims);
+ std::string isComplexBox(result);
+
+ if (isComplexBox == "TRUE") {
+ _isComplexBox = true;
+
+ if ((version != "1.0") && (version != "1.1")) {
+ getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
+ char complexboxnameTmp[255];
+ strcpy(complexboxnameTmp, line.c_str());
+ result = strtok(complexboxnameTmp, delims);
+ result = strtok(NULL, delims);
+ SetCbName(result);
+
+ getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
+ char packagenameTmp[255];
+ strcpy(packagenameTmp, line.c_str());
+ result = strtok(packagenameTmp, delims);
+ result = strtok(NULL, delims);
+ SetCbPackageName(result);
+ }
+ if(version < "1.4")
+ {
//-----------------------
//- COMPLEX INPUT PORTS
//-----------------------
- getline(inputStream,line);//COMPLEXINPUTS:num
- char inputs[18];
- strcpy( inputs, line.c_str() );
- result = strtok( inputs, delims );
- result = strtok( NULL, delims );
-
+ getCleanLine(inputStream, line);//COMPLEXINPUTS:num
+ char inputs[30];
+ strcpy(inputs, line.c_str());
+ result = strtok(inputs, delims);
+ result = strtok(NULL, delims);
+
int numInputs;
std::istringstream inps(result);
inps >> numInputs;
-
- for(int i = 0;i<numInputs;i++)
- {
+
+ for (int i = 0; i < numInputs; i++) {
//----------
- getline(inputStream,line);//COMPLEX_PORT
- getline(inputStream,line);//name
+ getCleanLine(inputStream, line);//COMPLEX_PORT
+ getCleanLine(inputStream, line);//name
std::string inputPortName(line);
//----------
- getline(inputStream,line);//xInic:yInic:zInic
+ getCleanLine(inputStream, line);//xInic:yInic:zInic
char coord[80];
- strcpy( coord, line.c_str() );
- result = strtok( coord, delims );//xInic
+ strcpy(coord, line.c_str());
+ result = strtok(coord, delims);//xInic
std::string xInic(result);
- result = strtok( NULL, delims );//yInic
+ result = strtok(NULL, delims);//yInic
std::string yInic(result);
- result = strtok( NULL, delims );//zInic
+ result = strtok(NULL, delims);//zInic
std::string zInic(result);
double xIn, yIn, zIn;
std::istringstream zSt(zInic);
zSt >> zIn;
- getline(inputStream,line);//FIN_COMPLEX_PORT
+ if (version<="1.2")
+ {
+ if (zIn==900) zIn=GPOSITION_Z;
+ }
- int idInputPort = createGComplexBoxInputPort(inputPortName);
- GObjectController *cont = _controllers[idInputPort];
- GBoxModel *cbmod = (GBoxModel*)cont->getModel();
- cbmod->setInicPoint(xIn,yIn,zIn);
- cbmod->notifyObservers(_idManager);
- } // for input complex box
+ getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
+ configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
- //-----------------------
- //- COMPLEX OUTPUT PORTS
- //-----------------------
+ } // for input complex box
+ }
- getline(inputStream,line);//COMPLEXOUTPUTS:num
- char outputs[18];
- strcpy( outputs, line.c_str() );
- result = strtok( outputs, delims );
- result = strtok( NULL, delims );
-
- int numOutputs;
- std::istringstream outps(result);
- outps >> numOutputs;
-
- for(int i = 0;i<numOutputs;i++)
- {
- //----------
- getline(inputStream,line);//COMPLEX_PORT
- getline(inputStream,line);//name
- std::string outputPortName(line);
- //----------
- getline(inputStream,line);//xInic:yInic:zInic
- char coord[80];
- strcpy( coord, line.c_str() );
- result = strtok( coord, delims );//xInic
- std::string xInic(result);
- result = strtok( NULL, delims );//yInic
- std::string yInic(result);
- result = strtok( NULL, delims );//zInic
- std::string zInic(result);
- double xIn, yIn, zIn;
- std::istringstream xSt(xInic);
- xSt >> xIn;
- std::istringstream ySt(yInic);
- ySt >> yIn;
- std::istringstream zSt(zInic);
- zSt >> zIn;
-
- getline(inputStream,line);//FIN_COMPLEX_PORT
+ //-----------------------
+ //- COMPLEX OUTPUT PORTS
+ //-----------------------
- int idOutputPort = createGComplexBoxOutputPort(outputPortName);
- GObjectController *cont = _controllers[idOutputPort];
- GBoxModel *cbmod = (GBoxModel*)cont->getModel();
- cbmod->setInicPoint(xIn,yIn,zIn);
- cbmod->notifyObservers(_idManager);
- } // for output complex box
+ getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
+ char outputs[30];
+ strcpy(outputs, line.c_str());
+ result = strtok(outputs, delims);
+ result = strtok(NULL, delims);
- } // complex box
+ int numOutputs;
+ std::istringstream outps(result);
+ outps >> numOutputs;
- //----------
-printf("EED %p wxVtkSceneManager::loadDiagram 4.1\n",this);
- getline(inputStream,line);//BOXES:num
-printf("EED %p wxVtkSceneManager::loadDiagram 4.2\n",this);
- char boxes[9];
-printf("EED %p wxVtkSceneManager::loadDiagram 4.3\n",this);
- strcpy( boxes, line.c_str() );
-printf("EED %p wxVtkSceneManager::loadDiagram 4.4\n",this);
- result = strtok( boxes, delims );
-printf("EED %p wxVtkSceneManager::loadDiagram 4.5\n",this);
- result = strtok( NULL, delims );
-printf("EED %p wxVtkSceneManager::loadDiagram 4.6\n",this);
-
- int numBoxes;
-printf("EED %p wxVtkSceneManager::loadDiagram 4.7\n",this);
- std::istringstream is(result);
-printf("EED %p wxVtkSceneManager::loadDiagram 4.8\n",this);
- is >> numBoxes;
-
-printf("EED %p wxVtkSceneManager::loadDiagram 5\n",this);
- for(int i = 0;i<numBoxes;i++)
- {
+ for (int i = 0; i < numOutputs; i++) {
//----------
- getline(inputStream,line);//BOX
- getline(inputStream,line);//package:type:name
- char box[100];
- strcpy( box, line.c_str() );
- result = strtok( box, delims );//package
- std::string package(result);
- result = strtok( NULL, delims );//type
- std::string type(result);
- result = strtok( NULL, delims );//name
- std::string name(result);
-
- getline(inputStream,line);//ISEXEC:TRUE|FALSE
- char exec[15];
- strcpy( exec, line.c_str() );
- result = strtok( exec, delims );//ISEXEC
- result = strtok( NULL, delims );//TRUE|FALSE
- std::string isExec(result);
+ getCleanLine(inputStream, line);//COMPLEX_PORT
+ getCleanLine(inputStream, line);//name
+ std::string outputPortName(line);
//----------
- getline(inputStream,line);//xInic:yInic:zInic
+ getCleanLine(inputStream, line);//xInic:yInic:zInic
char coord[80];
- strcpy( coord, line.c_str() );
- result = strtok( coord, delims );//xInic
+ strcpy(coord, line.c_str());
+ result = strtok(coord, delims);//xInic
std::string xInic(result);
- result = strtok( NULL, delims );//yInic
+ result = strtok(NULL, delims);//yInic
std::string yInic(result);
- result = strtok( NULL, delims );//zInic
+ result = strtok(NULL, delims);//zInic
std::string zInic(result);
double xIn, yIn, zIn;
ySt >> yIn;
std::istringstream zSt(zInic);
zSt >> zIn;
-printf("EED %p wxVtkSceneManager::loadDiagram 6\n",this);
-
- //----------
- getline(inputStream,line);//xEnd:yEnd:zEnd
- strcpy( coord, line.c_str() );
- result = strtok( coord, delims );//xEnd
- std::string xEnd(result);
- result = strtok( NULL, delims );//yEnd
- std::string yEnd(result);
- result = strtok( NULL, delims );//zEnd
- std::string zEnd(result);
-printf("EED %p wxVtkSceneManager::loadDiagram 6.1\n",this);
-
- double xEn, yEn, zEn;
- std::istringstream xEt(xEnd);
- xEt >> xEn;
- std::istringstream yEt(yEnd);
- yEt >> yEn;
- std::istringstream zEt(zEnd);
- zEt >> zEn;
-
-printf("EED %p wxVtkSceneManager::loadDiagram 6.2\n",this);
- int idBox = createGBlackBox(0,0,package,type);
-printf("EED %p wxVtkSceneManager::loadDiagram 6.2\n",this);
- GObjectController *cont = _controllers[idBox];
-printf("EED %p wxVtkSceneManager::loadDiagram 6.2\n",this);
- GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
-printf("EED %p wxVtkSceneManager::loadDiagram 6.2\n",this);
- bbmod->setBBTKName(name);
-printf("EED %p wxVtkSceneManager::loadDiagram 6.2\n",this);
- bbmod->setInicPoint(xIn,yIn,zIn);
-printf("EED %p wxVtkSceneManager::loadDiagram 6.2\n",this);
- bbmod->setFinalPoint(xEn,yEn,zEn);
-printf("EED %p wxVtkSceneManager::loadDiagram 6.2\n",this);
- if(isExec=="TRUE")
- {
- bbmod->setExecutable(true);
- }
- else if(isExec=="FALSE")
+
+ if (version<="1.2")
{
- bbmod->setExecutable(false);
+ if (zIn==900) zIn=GPOSITION_Z;
}
-
+
+ getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
+
+ configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
+
+ } // for output complex box
+
+ } // complex box
+
+ // RaC2012 2nd Hackfest
+ if(version >= "1.4")
+ {
+ //-----------------------
+ //- EXTERNAL INPUT PORTS
+ //-----------------------
+ getCleanLine(inputStream, line);//COMPLEXINPUTS:num
+ char inputs[30];
+ strcpy(inputs, line.c_str());
+ result = strtok(inputs, delims);
+ result = strtok(NULL, delims);
+
+ int numInputs;
+ std::istringstream inps(result);
+ inps >> numInputs;
+
+ for (int i = 0; i < numInputs; i++) {
//----------
- getline(inputStream,line);//PORT o FIN_BOX
- std::string port=line.substr(0,4);
- while(port=="PORT")
+ getCleanLine(inputStream, line);//COMPLEX_PORT
+ getCleanLine(inputStream, line);//name
+ std::string inputPortName(line);
+
+ //----------
+ getCleanLine(inputStream, line);//xInic:yInic:zInic
+ char coord[80];
+ strcpy(coord, line.c_str());
+ result = strtok(coord, delims);//xInic
+ std::string xInic(result);
+ result = strtok(NULL, delims);//yInic
+ std::string yInic(result);
+ result = strtok(NULL, delims);//zInic
+ std::string zInic(result);
+
+ double xIn, yIn, zIn;
+ std::istringstream xSt(xInic);
+ xSt >> xIn;
+ std::istringstream ySt(yInic);
+ ySt >> yIn;
+ std::istringstream zSt(zInic);
+ zSt >> zIn;
+
+ if (version<="1.2")
{
-printf("EED %p wxVtkSceneManager::loadDiagram 7\n",this);
- getline(inputStream,line);//name:value
- char poort[20];
- strcpy( poort, line.c_str() );
- result = strtok( poort, delims );//name
- std::string name(result);
- result = strtok( NULL, delims );//value
- std::string value(result);
+ if (zIn==900) zIn=GPOSITION_Z;
+ }
+
+ getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
+ configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
+
+ } // for external input
+ }
- bbmod->setValueToInput(name,value);
- getline(inputStream,line);//PORT o FIN_BOX
- port=line.substr(0,4);
- } // while
+ //----------
+ getCleanLine(inputStream, line);//BOXES:num
+ char boxes[9];
+ strcpy(boxes, line.c_str());
+ result = strtok(boxes, delims);
+ result = strtok(NULL, delims);
- bbmod->notifyObservers(_idManager);
- } // boxes
+ int numBoxes;
+ std::istringstream is(result);
+ is >> numBoxes;
- /// CONNECTIONS
+ for (int i = 0; i < numBoxes; i++) {
//----------
- getline(inputStream,line);//CONNECTIONS:num
- char conns[20];
- strcpy( conns, line.c_str() );
- result = strtok( conns, delims );
- result = strtok( NULL, delims );
-
- int numConns;
- std::istringstream isCons(result);
- isCons >> numConns;
-
-printf("EED %p wxVtkSceneManager::loadDiagram 8\n",this);
- for(int i = 0;i<numConns;i++)
+ getCleanLine(inputStream, line);//BOX
+ getCleanLine(inputStream, line);//package:type:name
+ char box[150];
+ strcpy(box, line.c_str());
+ result = strtok(box, delims);//package
+ std::string package(result);
+ result = strtok(NULL, delims);//type
+ std::string type(result);
+ result = strtok(NULL, delims);//name
+ std::string name(result);
+
+
+ getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
+ char exec[15];
+ strcpy(exec, line.c_str());
+ result = strtok(exec, delims);//ISEXEC
+ result = strtok(NULL, delims);//TRUE|FALSE
+ std::string isExec(result);
+
+ //----------
+ getCleanLine(inputStream, line);//xInic:yInic:zInic
+ char coord[80];
+ strcpy(coord, line.c_str());
+ result = strtok(coord, delims);//xInic
+ std::string xInic(result);
+ result = strtok(NULL, delims);//yInic
+ std::string yInic(result);
+ result = strtok(NULL, delims);//zInic
+ std::string zInic(result);
+
+ double xIn, yIn, zIn;
+ std::istringstream xSt(xInic);
+ xSt >> xIn;
+ std::istringstream ySt(yInic);
+ ySt >> yIn;
+ std::istringstream zSt(zInic);
+ zSt >> zIn;
+
+
+ if (version<="1.2")
{
-printf("EED %p wxVtkSceneManager::loadDiagram 9\n",this);
- //----------
- getline(inputStream,line);//CONNECTION
- getline(inputStream,line);//Startbox.PortName:EndBox.PortName
-
- char connec[100];
- strcpy( connec, line.c_str() );
- result = strtok( connec, delims );
- std::string nameStartBox(result);
- result = strtok( NULL, delims );
- std::string nameStartPort(result);
- result = strtok( NULL, delims );
- std::string nameEndBox(result);
- result = strtok( NULL, delims );
- std::string nameEndPort(result);
-
- std::vector<int> lstB = getBlackBoxes();
+ if (zIn==900) zIn=GPOSITION_Z;
+ }
+
+
+ //----------
+ getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
+ strcpy(coord, line.c_str());
+ result = strtok(coord, delims);//xEnd
+ std::string xEnd(result);
+ result = strtok(NULL, delims);//yEnd
+ std::string yEnd(result);
+ result = strtok(NULL, delims);//zEnd
+ std::string zEnd(result);
+
+ double xEn, yEn, zEn;
+ std::istringstream xEt(xEnd);
+ xEt >> xEn;
+ std::istringstream yEt(yEnd);
+ yEt >> yEn;
+ std::istringstream zEt(zEnd);
+ zEt >> zEn;
+
+ if (version<="1.2")
+ {
+ if (zEn==900) zEn=GPOSITION_Z;
+ }
+
+
+ bool boxExecutable = false;
+ if (isExec == "TRUE") {
+ boxExecutable = true;
+ }
+
+ int idBox = createGBlackBox(xIn, yIn, package, type);
+ configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
+
+ GObjectController *cont = _controllers[idBox];
+ GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
+
+ //----------
+ getCleanLine(inputStream, line);//PORT o FIN_BOX
+ std::string port = line.substr(0, 4);
+ while (port == "PORT")
+ {
+ getCleanLine(inputStream, line);//name:value
+ if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
+ {
+ line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
+ }
- GPortModel *startP=NULL;
- GPortModel *endP=NULL;
- for(int j = 0;j<lstB.size();j++)
+ strcpy(poort, line.c_str());
+ result = strtok(poort, delims);//name
+ std::string name(result);
+
+ //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
+ result = strtok(NULL, delims);//value
+ if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
{
- int idB = lstB[j];
- GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
- if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
- {
- startP = bbMod->getOutputPort(nameStartPort);
- }
- else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
- {
- endP = bbMod->getInputPort(nameEndPort);
- }
- } // for
+ std::string tmpString=" ";
+ tmpString[0]=34; // character "
+ strcat(result,tmpString.c_str());
+ }
+ std::string value(result);
- if(_isComplexBox)
- {
- if(startP==NULL)
- {
- std::vector<int> lstInputs = getComplexInputPorts();
- for(int j = 0;j<lstInputs.size();j++)
- {
- int idB = lstInputs[j];
- GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
- if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
- {
- startP = cbMod->getOutputPort(nameStartPort);
- }
- }
- }
+ bbmod->setValueToInput(name, value);
+
+ getCleanLine(inputStream, line);//PORT o FIN_BOX
+ port = line.substr(0, 4);
+ } // while
+
+ //EED bbmod->notifyObservers(_idManager);
+ } // for boxes
+
+ /// CONNECTIONS
+ //----------
+ getCleanLine(inputStream, line);//CONNECTIONS:num
+ char conns[30];
+ strcpy(conns, line.c_str());
+ result = strtok(conns, delims);
+ result = strtok(NULL, delims);
- if(endP==NULL)
+ int numConns;
+ std::istringstream isCons(result);
+ isCons >> numConns;
+
+
+ for (int i = 0; i < numConns; i++) {
+ //----------
+ getCleanLine(inputStream, line);//CONNECTION
+ getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
+
+ char connec[200];
+ strcpy(connec, line.c_str());
+ result = strtok(connec, delims);
+ std::string nameStartBox(result);
+ result = strtok(NULL, delims);
+ std::string nameStartPort(result);
+ result = strtok(NULL, delims);
+ std::string nameEndBox(result);
+ result = strtok(NULL, delims);
+ std::string nameEndPort(result);
+
+
+ int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
+
+ if (version != "1.0") {
+ //Readding control points of the manualContour
+ GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
+ GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
+ vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
+ getCleanLine(inputStream, line); //NumberOfControlPoints:##
+ strcpy(conns, line.c_str());
+ result = strtok(conns, delims);
+ result = strtok(NULL, delims);
+
+ int numberOfControlPoints;
+ std::istringstream isCons(result);
+ isCons >> numberOfControlPoints;
+
+ for (int ii = 0; ii < numberOfControlPoints; ii++) {
+ getCleanLine(inputStream, line); //XX:YY:ZZ
+ char connec[200];
+ strcpy(connec, line.c_str());
+
+ double px, py, pz;
+ result = strtok(connec, delims);
+ std::istringstream isPointX(result);
+ isPointX >> px;
+ result = strtok(NULL, delims);
+ std::istringstream isPointY(result);
+ isPointY >> py;
+ result = strtok(NULL, delims);
+ std::istringstream isPointZ(result);
+ isPointZ >> pz;
+
+ if (version<="1.2")
{
- std::vector<int> lstOutputs = getComplexOutputPorts();
- for(int j = 0;j<lstOutputs.size();j++)
- {
- int idB = lstOutputs[j];
- GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
- if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
- {
- endP = cbMod->getInputPort(nameEndPort);
- }
- }
+ if (pz==900) pz=GPOSITION_Z;
}
- } // complex box
-
- int idCon = createGConnector(startP);
- _worldState = NOTHING_HAPPENS;
- GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
-
- GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
- vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
- tempp->endContourCreation();
- conMod->setEndPort(endP);
- conView->updateStartEndPoints();
+
+ conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
+ conView->getManualContourView()->AddPoint();
+ }
+ }// version !=1.0
+ } // for numConns
+ } // start
+}
+//=========================================================================
- } // for numConns
- } // start
-printf("EED %p wxVtkSceneManager::loadDiagram 10\n",this);
+//=========================================================================
+void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
+ std::string portName, double xIn, double yIn, double zIn)
+{
+ int idPort;
+ if (inputoutput == true) {
+ idPort = createGComplexBoxInputPort(portName);
+ } else {
+ idPort = createGComplexBoxOutputPort(portName);
}
+ GObjectController *cont = _controllers[idPort];
+ GBoxModel *cbmod = (GBoxModel*) cont->getModel();
+ cbmod->setInicPoint(xIn, yIn, zIn);
+ cbmod->notifyObservers(_idManager);
+}
+//=========================================================================
- //=========================================================================
- std::vector<int> wxVtkSceneManager::getBlackBoxes()
- {
- std::vector<int> vect;
- std::map<int, GObjectController*>::iterator it;
- for(it = _controllers.begin(); it != _controllers.end(); ++it)
- {
- GObjectController *cont = it->second;
- if(cont->getGObjectType()==GBLACKBOX)
- {
- vect.push_back(cont->getId());
- }
+//=========================================================================
+GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
+{
+ int j;
+ int idB;
+ GBoxModel *bMod;
+ GBoxModel *boxModel = NULL;
+ std::vector<int> lstB = getBlackBoxes();
+ for (j = 0; j < (int) lstB.size(); j++) {
+ idB = lstB[j];
+ bMod = (GBoxModel*) _controllers[idB]->getModel();
+ if (_controllers[idB]->getModel()->getBBTKName() == boxname)
+ {
+ boxModel = bMod;
}
- return vect;
- }
+ } // for
- //=========================================================================
- std::vector<int> wxVtkSceneManager::getComplexInputPorts()
- {
- std::vector<int> vect;
- std::map<int, GObjectController*>::iterator it;
- for(it = _controllers.begin(); it != _controllers.end(); ++it)
- {
- GObjectController *cont = it->second;
- if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
- {
- vect.push_back(cont->getId());
- }
- }
- return vect;
- }
- //=========================================================================
+ if (boxModel == NULL) {
+ std::vector<int> lstInputs = getComplexInputPorts();
+ for (j = 0; j < (int) lstInputs.size(); j++) {
+ idB = lstInputs[j];
+ bMod = (GBoxModel*) _controllers[idB]->getModel();
+ if (_controllers[idB]->getModel()->getBBTKName() == boxname)
+ {
+ boxModel = bMod;
+ }
+ } // for
- std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
- {
- std::vector<int> vect;
- std::map<int, GObjectController*>::iterator it;
- for(it = _controllers.begin(); it != _controllers.end(); ++it)
+ if(_isComplexBox)
{
- GObjectController *cont = it->second;
- if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
- {
- vect.push_back(cont->getId());
+ std::vector<int> lstOutputs = getComplexOutputPorts();
+ for (j = 0; j < (int) lstOutputs.size(); j++) {
+ int idB = lstOutputs[j];
+ bMod = (GBoxModel*) _controllers[idB]->getModel();
+ if (_controllers[idB]->getModel()->getBBTKName() == boxname)
+ {
+ boxModel = bMod;
}
+ } // for
}
- return vect;
- }
- //=========================================================================
+ } // inputs/outputs
- std::vector<int> wxVtkSceneManager::getConnections()
- {
- std::vector<int> vect;
- std::map<int, GObjectController*>::iterator it;
- for(it = _controllers.begin(); it != _controllers.end(); ++it)
- {
- GObjectController *cont = it->second;
- if(cont->getGObjectType()==GCONNECTOR)
- {
- vect.push_back(cont->getId());
- }
- }
- return vect;
- }
+ return boxModel;
+}
- //=========================================================================
-
- bool wxVtkSceneManager::isComplexBox()
- {
- return _isComplexBox;
- }
+//=========================================================================
- //=========================================================================
- void wxVtkSceneManager::setComplexBox(bool val)
- {
- _isComplexBox=val;
- }
-
- //=========================================================================
+int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
+ std::string nameStartPort, std::string nameEndBox,
+ std::string nameEndPort) {
+
+ GBoxModel *boxModel;
+ GPortModel *startP = NULL;
+ GPortModel *endP = NULL;
- int wxVtkSceneManager::addObjectController(GObjectController* objController)
+ boxModel = findGBox(nameStartBox);
+ if(boxModel == NULL)
{
- //Register the controller of the new object
- registerController((InteractorStyleMaracas*) objController);
-
- //Add the object to the objects list
- int newId = _contLastId;//_controllers.size();
- objController->setId(newId);
- _controllers[newId] = objController;
- _contLastId++;
- return newId;
+ printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
+ }
+ if (boxModel != NULL) {
+ startP = boxModel->getOutputPort(nameStartPort);
+ if(startP == NULL){
+ printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port is null. Port name is probably wrong. Start>%s::%s End>%s::%s\n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str() );
+ }
}
- //=========================================================================
-
- int wxVtkSceneManager::getNumSelectedObjects()
+ boxModel = findGBox(nameEndBox);
+ if(boxModel == NULL)
{
- return _selectedObjects.size();
+ printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
+ }
+ if (boxModel != NULL) {
+ endP = boxModel->getInputPort(nameEndPort);
+ if(endP == NULL){
+ printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port is null. Port name is probably wrong. Start>%s::%s End>%s::%s \n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str());
+ }
}
- //=========================================================================
-
- std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
- {
- std::map<int,GObjectController*> mapSelected;
+ //ups2
+ int idCon = createGConnector(startP);
+
+ _worldState = NOTHING_HAPPENS;
+ GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
+
+ GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
+ vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
+ tempp->endContourCreation();
+ conMod->setEndPort(endP);
+ conView->updateStartEndPoints();
+ return idCon;
+}
+
+//=========================================================================
+
+bool wxVtkSceneManager::boxExist(std::string boxname) {
+ bool ok = false;
+ std::map<int, GObjectController*>::iterator it;
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *cont = it->second;
+ if (cont->getModel()->getBBTKName() == boxname) {
+ ok = true;
+ }
+ }
+ return ok;
+}
+
+//=========================================================================
+
+std::vector<int> wxVtkSceneManager::getBlackBoxes() {
+ std::vector<int> vect;
+ std::map<int, GObjectController*>::iterator it;
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *cont = it->second;
+ if (cont->getGObjectType() == GBLACKBOX) {
+ vect.push_back(cont->getId());
+ }
+ }
+ return vect;
+}
+
+//=========================================================================
+
+std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
+ std::vector<int> vect;
+ std::map<int, GObjectController*>::iterator it;
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *cont = it->second;
+ if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
+ vect.push_back(cont->getId());
+ }
+ }
+ return vect;
+}
+
+//=========================================================================
+
+std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
+ std::vector<int> vect;
+ std::map<int, GObjectController*>::iterator it;
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *cont = it->second;
+ if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
+ vect.push_back(cont->getId());
+ }
+ }
+ return vect;
+}
+
+//=========================================================================
+
+std::vector<int> wxVtkSceneManager::getConnections() {
+ std::vector<int> vect;
+ std::map<int, GObjectController*>::iterator it;
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *cont = it->second;
+ if (cont->getGObjectType() == GCONNECTOR) {
+ vect.push_back(cont->getId());
+ }
+ }
+ return vect;
+}
+
+//=========================================================================
+
+bool wxVtkSceneManager::isComplexBox() {
+ return _isComplexBox;
+}
+
+//=========================================================================
+
+void wxVtkSceneManager::setComplexBox(bool val) {
+ _isComplexBox = val;
+}
+
+//=========================================================================
+
+int wxVtkSceneManager::addObjectController(GObjectController* objController) {
+ //Register the controller of the new object
+ registerController((InteractorStyleMaracas*) objController);
+ //Add the object to the objects list
+ int newId = _contLastId;//_controllers.size();
+ objController->setId(newId);
+ _controllers[newId] = objController;
+ //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
+ _contLastId++;
+ return newId;
+}
+
+//=========================================================================
+
+void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
+
+ std::map<int, int> oldIdNewIdBoxes;
+ std::vector<int> connections;
+
+ std::vector<int> newBoxesID;
+
+ std::map<int, GObjectController*>::iterator it;
+ for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
+ GObjectController *cont = it->second;
+ int type = cont->getGObjectType();
+
+ if (type == GBLACKBOX) {
+ // Copy black box
+ double xInic, yInic, zInic;
+ GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
+ copyBox->getInicPoint(xInic, yInic, zInic);
+ int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
+ copyBox->getBBTKType());
+
+ int idcB = copyBox->getObjectId();
+ oldIdNewIdBoxes[idcB] = idBox;
+ cont = _controllers[idBox];
+ GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
+ newbox->setInicPoint(xInic, yInic, zInic);
+ int num = newbox->getNumInputPorts();
+ for (int j = 0; j < num; j++) {
+ newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
+ }
+ newbox->move(xInic + 20, yInic + 20, zInic);
+ newbox->notifyObservers(_idManager);
+ newBoxesID.push_back(newbox->getObjectId());
+
+ } else if (type == GCONNECTOR) {
+ int idCon = cont->getId();
+ connections.push_back(idCon);
+ }
+
+ }
+
+ for (int i = 0; i < (int) connections.size(); i++) {
+ int objId = connections[i];
+ GObjectController *cont = objectsMap[objId];
+ GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
+
+ GPortModel* startPort = connectModel->getStartPort();
+ int startPortIndex = startPort->getPosInBox();
+ GPortModel* endPort = connectModel->getEndPort();
+ int endPortIndex = endPort->getPosInBox();
+
+ GBlackBoxModel* startPortParentBox =
+ (GBlackBoxModel*) startPort->getParentBox();
+ GBlackBoxModel* endPortParentBox =
+ (GBlackBoxModel*) endPort->getParentBox();
+
+ int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
+ int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
+
+ GBlackBoxModel* newStartBox =
+ (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
+ GBlackBoxModel* newEndBox =
+ (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
+
+ GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
+ GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
+
+ // Creates connection
+ int idCon = createGConnector(newStartPort);
+ GConnectorController *tempp =
+ (GConnectorController*) _controllers[idCon];
+ GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
+ vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
+ tempp->endContourCreation();
+ conMod->setEndPort(newEndPort);
+ conView->updateStartEndPoints();
+ }
+
+ /// the new selected boxes are the duplicate ones
+
+ UnSelectBlackBoxes();
+ for (int i = 0; i < newBoxesID.size(); i++) {
+ _selectedObjects.push_back(newBoxesID.at(i));
+ }
+
+ for (int i = 0; i < (int) _selectedObjects.size(); i++) {
+ int id = _selectedObjects[i];
+ GObjectController* cont = _controllers[id];
+
+ cont->getView()->setState(SELECTED);
+ cont->getModel()->notifyObservers(_idManager);
+
+ }
+ }
+
+
+//=========================================================================
+
+int wxVtkSceneManager::getNumSelectedObjects() {
+ return _selectedObjects.size();
+}
+
+//=========================================================================
+
+std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
+ std::map<int, GObjectController*> mapSelected;
+
+ std::map<int, GObjectController*>::iterator it;
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *cont = it->second;
+ if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
+ == SELECTED) {
+ mapSelected[cont->getId()] = cont;
+ }
+ }
- std::map<int, GObjectController*>::iterator it;
- for(it = _controllers.begin(); it != _controllers.end(); ++it)
- {
- GObjectController *cont = it->second;
- if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
- {
- mapSelected[cont->getId()]=cont;
+ std::map<int, GObjectController*>::iterator it2;
+ for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
+ GObjectController *cont = it2->second;
+ if (cont->getGObjectType() == GCONNECTOR) {
+ GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
+ GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
+ GBoxModel* startPortParentBox =
+ cmod->getStartPort()->getParentBox();
+
+ std::map<int, GObjectController*>::iterator iterOBJ1 =
+ mapSelected.find(startPortParentBox->getObjectId());
+ std::map<int, GObjectController*>::iterator iterOBJ2 =
+ mapSelected.find(endPortParentBox->getObjectId());
+
+ if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
+ int ID = cont->getId();
+ mapSelected[ID] = cont;
}
}
-
- std::map<int, GObjectController*>::iterator it2;
- for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
- {
- GObjectController *cont = it2->second;
- if(cont->getGObjectType()==GCONNECTOR)
+ }
+ return mapSelected;
+}
+
+//=========================================================================
+
+void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
+
+ std::map<int, int> oldIdNewIdBoxes;
+ std::vector<int> connections;
+
+ std::map<int, GObjectController*>::iterator it;
+ for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
+ GObjectController *cont = it->second;
+ int type = cont->getGObjectType();
+
+ if (type == GBLACKBOX) {
+ // Copy black box
+ double xInic, yInic, zInic;
+ GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
+ copyBox->getInicPoint(xInic, yInic, zInic);
+ int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
+
+ int idcB = copyBox->getObjectId();
+ oldIdNewIdBoxes[idcB] = idBox;
+ cont = _controllers[idBox];
+ GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
+ newbox->setInicPoint(xInic, yInic, zInic);
+ int num = newbox->getNumInputPorts();
+ for (int j = 0; j < num; j++)
{
- GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
- GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
- GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
+ newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
+ }// for j
+ newbox->notifyObservers(_idManager);
+ } else if (type == GCONNECTOR) {
+ int idCon = cont->getId();
+ connections.push_back(idCon);
+ }
- std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
- std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
-
- if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
- {
- int ID = cont->getId();
- mapSelected[ID]=cont;
+ }
+
+ for (int i = 0; i < (int) connections.size(); i++) {
+ int objId = connections[i];
+ GObjectController *cont = objectsMap[objId];
+ GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
+
+ GPortModel* startPort = connectModel->getStartPort();
+ int startPortIndex = startPort->getPosInBox();
+ GPortModel* endPort = connectModel->getEndPort();
+ int endPortIndex = endPort->getPosInBox();
+
+ GBlackBoxModel* startPortParentBox =
+ (GBlackBoxModel*) startPort->getParentBox();
+ GBlackBoxModel* endPortParentBox =
+ (GBlackBoxModel*) endPort->getParentBox();
+
+ int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
+ int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
+
+ GBlackBoxModel* newStartBox =
+ (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
+ GBlackBoxModel* newEndBox =
+ (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
+
+ GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
+ GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
+
+ // Creates connection
+ int idCon = createGConnector(newStartPort);
+ GConnectorController *tempp =
+ (GConnectorController*) _controllers[idCon];
+ GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
+ vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
+ tempp->endContourCreation();
+ conMod->setEndPort(newEndPort);
+ conView->updateStartEndPoints();
+ }
+
+ std::map<int, int>::iterator itIds;
+ for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
+ int idOld = itIds->first;
+ int idNew = itIds->second;
+
+ GBlackBoxModel* oldBox =
+ (GBlackBoxModel*) objectsMap[idOld]->getModel();
+ GBlackBoxModel* newBox =
+ (GBlackBoxModel*) _controllers[idNew]->getModel();
+
+ std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
+ std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
+ std::vector<int> newInputConnections = newBox->getConnectedInputs();
+ std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
+
+ for (int k = 0; k < (int) oldInputConnections.size(); k++) {
+ bool exist = false;
+ //EED int toCreate=-1;
+ for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
+ if (oldInputConnections[k] == newInputConnections[l]) {
+ exist = true;
}
-
}
- }
- return mapSelected;
- }
- //=========================================================================
+ if (exist == false) {
+ //Create complex input
+ int posInBox = oldInputConnections[k];
+ GPortModel* inputPort = oldBox->getInputPort(posInBox);
+ std::string inputPortName = inputPort->getBBTKName();
+ int idInputPort = createGComplexBoxInputPort(inputPortName);
+ GObjectController *cont = _controllers[idInputPort];
+ GBoxModel *cbmod = (GBoxModel*) cont->getModel();
+ double xIn, yIn, zIn;
+ inputPort->getInicPoint(xIn, yIn, zIn);
+ yIn += 20;
+ cbmod->setInicPoint(xIn, yIn, zIn);
+ cbmod->notifyObservers(_idManager);
+
+ GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
+
+ // Creates connection
+ int idCon = createGConnector(cbmod->getOutputPort(0));
+ GConnectorController *tempp =
+ (GConnectorController*) _controllers[idCon];
+ GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
+ vtkGConnectorView *conView =
+ (vtkGConnectorView*) tempp->getView();
+ tempp->endContourCreation();
+ conMod->setEndPort(inputPortEnd);
+ conView->updateStartEndPoints();
- void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
- {
-
- std::map<int,int> oldIdNewIdBoxes;
- std::vector<int> connections;
+ }
- std::map<int, GObjectController*>::iterator it;
- for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
- {
- GObjectController *cont = it->second;
- int type = cont->getGObjectType();
+ }
- if(type==GBLACKBOX)
- {
- // Copy black box
- double xInic, yInic,zInic;
- GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
- copyBox->getInicPoint(xInic,yInic,zInic);
- int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
-
- int idcB = copyBox->getObjectId();
- oldIdNewIdBoxes[idcB]=idBox;
- cont = _controllers[idBox];
- GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
- newbox->setInicPoint(xInic,yInic,zInic);
- int num = newbox->getNumInputPorts();
- for(int j=0;j<num;j++)
- {
- newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
+ for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
+ bool exist = false;
+ //EED int toCreate=-1;
+ for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
+ if (oldOutputConnections[k] == newOutputConnections[l]) {
+ exist = true;
}
- newbox->notifyObservers(_idManager);
}
- else if(type==GCONNECTOR)
- {
- int idCon = cont->getId();
- connections.push_back(idCon);
+
+ if (exist == false) {
+ //Create complex output
+ int posInBox = oldOutputConnections[k];
+ GPortModel* outputPort = oldBox->getOutputPort(posInBox);
+ std::string outputPortName = outputPort->getBBTKName();
+ int idOutputPort = createGComplexBoxOutputPort(outputPortName);
+ GObjectController *cont = _controllers[idOutputPort];
+ GBoxModel *cbmod = (GBoxModel*) cont->getModel();
+ double xIn, yIn, zIn;
+ outputPort->getInicPoint(xIn, yIn, zIn);
+ yIn -= 20;
+ cbmod->setInicPoint(xIn, yIn, zIn);
+ cbmod->notifyObservers(_idManager);
+
+ GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
+
+ // Creates connection
+ int idCon = createGConnector(outputPortEnd);
+ GConnectorController *tempp =
+ (GConnectorController*) _controllers[idCon];
+ GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
+ vtkGConnectorView *conView =
+ (vtkGConnectorView*) tempp->getView();
+ tempp->endContourCreation();
+ conMod->setEndPort(cbmod->getInputPort(0));
+ conView->updateStartEndPoints();
+
}
-
- }
-
- for(int i = 0 ;i<connections.size();i++)
- {
- int objId = connections[i];
- GObjectController *cont = objectsMap[objId];
- GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
-
- GPortModel* startPort = connectModel->getStartPort();
- int startPortIndex = startPort->getPosInBox();
- GPortModel* endPort = connectModel->getEndPort();
- int endPortIndex = endPort->getPosInBox();
- GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
- GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
-
- int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
- int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
-
- GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
- GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
-
- GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
- GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
-
- // Creates connection
- int idCon = createGConnector(newStartPort);
- GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
- GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
- vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
- tempp->endContourCreation();
- conMod->setEndPort(newEndPort);
- conView->updateStartEndPoints();
}
- std::map<int, int>::iterator itIds;
- for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
- {
- int idOld = itIds->first;
- int idNew = itIds->second;
+ }
- GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
- GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
+}
- std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
- std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
- std::vector<int> newInputConnections = newBox->getConnectedInputs();
- std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
+//=========================================================================
+void wxVtkSceneManager::SetCbName(std::string cbName) {
+ _cbName = cbName;
+ if (_cbName == "") {
+ _cbName = "<complex box name>";
+ }
+}
+
+//=========================================================================
+std::string wxVtkSceneManager::GetCbName() {
+ return _cbName;
+}
+
+//=========================================================================
+void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
+ _cbPackageName = packagename;
+ if (_cbPackageName == "") {
+ _cbPackageName = "<package name of the complex box>";
+ }
+}
+
+//=========================================================================
+std::string wxVtkSceneManager::GetCbPackageName() {
+ return _cbPackageName;
+}
+
+//=========================================================================
+void wxVtkSceneManager::SetAuthor(std::string author) {
+ _Author = author;
+ if (_Author == "") {
+ _Author = "<author of the box>";
+ }
+}
+
+//=========================================================================
+std::string wxVtkSceneManager::GetAuthor() {
+ return _Author;
+}
+
+//=========================================================================
+void wxVtkSceneManager::SetCategory(std::string category) {
+ _Category = category;
+ if (_Category == "") {
+ _Category = "<category of the box>";
+ }
+}
+
+//=========================================================================
+std::string wxVtkSceneManager::GetCategory() {
+ return _Category;
+}
+
+//=========================================================================
+void wxVtkSceneManager::SetDescription(std::string description) {
+ _Description = description;
+ if (_Description == "") {
+ _Description = "<description of the box>";
+ }
+}
- for(int k = 0; k<oldInputConnections.size();k++)
- {
- bool exist=false;
- int toCreate=-1;
- for(int l = 0; l<newInputConnections.size() && !exist;l++)
- {
- if(oldInputConnections[k]==newInputConnections[l])
- {
- exist=true;
- }
- }
+//=========================================================================
+std::string wxVtkSceneManager::GetDescription() {
+ return _Description;
+}
- if(exist==false)
- {
- //Create complex input
- int posInBox = oldInputConnections[k];
- GPortModel* inputPort = oldBox->getInputPort(posInBox);
- std::string inputPortName = inputPort->getBBTKName();
- int idInputPort = createGComplexBoxInputPort(inputPortName);
- GObjectController *cont = _controllers[idInputPort];
- GBoxModel *cbmod = (GBoxModel*)cont->getModel();
- double xIn,yIn,zIn;
- inputPort->getInicPoint(xIn,yIn,zIn);
- yIn+=20;
- cbmod->setInicPoint(xIn,yIn,zIn);
- cbmod->notifyObservers(_idManager);
-
- GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
-
- // Creates connection
- int idCon = createGConnector(cbmod->getOutputPort(0));
- GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
- GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
- vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
- tempp->endContourCreation();
- conMod->setEndPort(inputPortEnd);
- conView->updateStartEndPoints();
+//=========================================================================
- }
-
- }
-
+void wxVtkSceneManager::SetMessageKind(std::string kind) {
+ _MessageKind = kind;
+
+}
+
+//=========================================================================
- for(int k = 0; k<oldOutputConnections.size();k++)
- {
- bool exist=false;
- int toCreate=-1;
- for(int l = 0; l<newOutputConnections.size() && !exist;l++)
- {
- if(oldOutputConnections[k]==newOutputConnections[l])
- {
- exist=true;
- }
- }
+std::string wxVtkSceneManager::GetMessageKind(){
+ return _MessageKind;
+}
- if(exist==false)
- {
- //Create complex output
- int posInBox = oldOutputConnections[k];
- GPortModel* outputPort = oldBox->getOutputPort(posInBox);
- std::string outputPortName = outputPort->getBBTKName();
- int idOutputPort = createGComplexBoxOutputPort(outputPortName);
- GObjectController *cont = _controllers[idOutputPort];
- GBoxModel *cbmod = (GBoxModel*)cont->getModel();
- double xIn,yIn,zIn;
- outputPort->getInicPoint(xIn,yIn,zIn);
- yIn-=20;
- cbmod->setInicPoint(xIn,yIn,zIn);
- cbmod->notifyObservers(_idManager);
-
- GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
-
- // Creates connection
- int idCon = createGConnector(outputPortEnd);
- GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
- GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
- vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
- tempp->endContourCreation();
- conMod->setEndPort(cbmod->getInputPort(0));
- conView->updateStartEndPoints();
+//=========================================================================
- }
-
- }
+void wxVtkSceneManager::SetMessageLevel(std::string Level){
+ _MessageLevel = Level;
+}
- }
+//=========================================================================
+std::string wxVtkSceneManager::GetMessageLevel(){
+ return _MessageLevel;
+}
- }
+//=========================================================================
- //=========================================================================
+std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
+{
-} // EO namespace bbtk
+ std::vector< std::string> extInputs;
+ std::map<int, GObjectController*>::iterator it;
+ for (it = _controllers.begin(); it != _controllers.end(); ++it)
+ {
+ GObjectController *cont = it->second;
+ if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
+ {
+ extInputs.push_back(cont->getModel()->getBBTKName());
+ }
+ }
+ return extInputs;
+}
+
+//=========================================================================
+
+
+
+void wxVtkSceneManager::printAll(int com , int sta ){
+
+ int tmpState = sta ;
+ if ( tmpState == NOTHING_HAPPENS ) {
+ std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
+ }
+ if ( tmpState == HIGHLIGHTED ) {
+ std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
+ }
+ if ( tmpState == POSSIBLE_CONNECTION ) {
+ std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
+ }
+ if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
+ std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
+ }
+ if ( tmpState == CLICKED ) {
+ std::cout << "CONTROLER STATE---->CLICKED\n" ;
+ }
+ if ( tmpState == DRAG ) {
+ std::cout << "CONTROLER STATE---->DRAG\n" ;
+ }
+ if ( tmpState == SELECTED ) {
+ std::cout << "CONTROLER STATE---->SELECTED\n" ;
+ }
+ if ( tmpState == CREATING_CONTOUR ) {
+ std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
+ }
+
+ // :P
+
+ int command = com ;
+ if ( command == INIT_CREATION_CONTOUR ) {
+ std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
+ }
+ if ( command == FIN_CREATION_CONTOUR ) {
+ std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
+ }
+ if ( command == ADD_TO_SELECTED ) {
+ std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
+ }
+ if ( command == DRAG_OBJECTS ) {
+ std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
+ }
+ if ( command == EDIT_BLACKBOX ) {
+ std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
+ }
+ if ( command == REMOVE_FROM_SELECTED ) {
+ std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
+ }
+
+ }
+
+
+} // EO namespace bbtk
// EOF