//=========================================================================
- wxVtkSceneManager::wxVtkSceneManager(wxDropTarget *parent, wxVtk3DBaseView *baseView,int id)
+ wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView,int idManager)
{
- _id=id;
+ _parent = parent;
+ _numBoxes=0;
+ _idManager=idManager;
_baseView=baseView;
+ _startDragging=false;
+ _isComplexBox=false;
+
if( _baseView!=NULL )
{
-
- _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(parent);
- registerController(this);
+ _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
configureBaseView();
-
- ///// ******* TO ERASE *******
- //JUST TO TEST
- //
-
-
-
- vtkConeSource *cone = vtkConeSource::New();
-
- cone->SetResolution(10);
-
- vtkPolyDataMapper *map = vtkPolyDataMapper::New();
- map->SetInput(cone->GetOutput());
-
- vtkActor *act = vtkActor::New();
-
- act->SetMapper(map);
-
- vtkPoints *_pts = vtkPoints::New();
- _pts->SetNumberOfPoints(4);
-
- _pts->SetPoint(0, -1 , -1 , 0 );
- _pts->SetPoint(1, 1 , -1 , 0 );
- _pts->SetPoint(2, 1 , 1 , 0 );
- _pts->SetPoint(3, -1 , 1 , 0 );
-
- vtkCellArray *lines = vtkCellArray::New();
- lines->InsertNextCell(5);
- lines->InsertCellPoint(0);
- lines->InsertCellPoint(1);
- lines->InsertCellPoint(2);
- lines->InsertCellPoint(3);
- lines->InsertCellPoint(0);
-
- vtkPolyData *_pd = vtkPolyData::New();
- _pd->SetPoints( _pts );
- _pd->SetLines( lines );
-
- vtkActor *_pointVtkActor = vtkActor::New();
- vtkPolyDataMapper* _bboxMapper = vtkPolyDataMapper::New();
-
- _bboxMapper->SetInput(_pd);
- _pointVtkActor->SetMapper(_bboxMapper);
-
- getRenderer()->AddActor(_pointVtkActor);
-
-
-
- // ******* TO ERASE *******
- /////////////////////
+ _worldState=NOTHING_HAPPENS;
+ registerController(this);
}
+
}
//=========================================================================
+
void wxVtkSceneManager::disconnectDrop()
{
_baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
- }
+ }
+
//=========================================================================
+
wxVtkSceneManager::~wxVtkSceneManager()
{
}
+
//=========================================================================
void wxVtkSceneManager::configureBaseView()
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::createGBlackBox(int x, int y, std::string packageName, std::string boxName)
+ int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
{
-
int windowWidth=_baseView->GetRenWin()->GetSize()[0];
int windowHeight=_baseView->GetRenWin()->GetSize()[1];
vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
- BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
+ 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
double xx = x;
- double yy = windowHeight-y;
+ double yy = windowHeight-y;
//z value is not important yet, because it is only used a parallel projection
- double zz = 0;
+ double zz = 900;
_baseView->TransCoordScreenToWorld(xx,yy,zz);
model->setInicPoint(xx,yy,zz);
+ _numBoxes++;
+ std::stringstream stream;
+
+ if(_numBoxes<10)
+ {
+ stream << "Box0" << _numBoxes;
+ }
+ else
+ {
+ stream << "Box" << _numBoxes;
+ }
+ std::string arraystring = stream.str();
+
+ model->setBBTKName(arraystring);
+ model->setBBTKType(boxType);
+ model->setBBTKPackage(packageName);
+
model->addObserver(view);
model->addObserver(this);
for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
{
BlackBoxInputDescriptor *desc = itInput->second;
- createGInputPort(desc,model,i);
+ createGInputPort(GINPUTPORT,i,model,desc);
i++;
}
for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
{
BlackBoxOutputDescriptor *desc = itOutput->second;
- createGOutputPort(desc,model,i);
+ createGOutputPort(GOUTPUTPORT,i,model,desc);
i++;
}
controller->setModelAndView(model,view);
//Resgiter change to the observers of the actual model
- model->setChanged();
- model->notifyObservers();
+ model->notifyObservers(_idManager);
//Register the controller of the new object
registerController((InteractorStyleMaracas*) controller);
- //Add the object to the objects list (only boxes and connectors)
- _objects.push_back(model);
+ //Add the object to the objects list
+ int newId = _controllers.size();
+ controller->setId(newId);
+ _controllers[newId] = controller;
+ return newId;
}
//=========================================================================
- void wxVtkSceneManager::createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox, int pos)
+ int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
{
- int type = GPORT;
+ int windowWidth=_baseView->GetRenWin()->GetSize()[0];
+ int windowHeight=_baseView->GetRenWin()->GetSize()[1];
+
+ int type = GCOMPLEXINPUTPORT;
//Create the MVC Objects
- GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
+
+ GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
+
+ //Prepares the initial model
- model->registerInBox(blackBox,GOUTPUTPORT, pos);
- blackBox->addOutputPort(model);
+ double xx = 5;
+ double yy = windowHeight-5;
+ //z value is not important yet, because it is only used a parallel projection
+ double zz = 900;
+
+ _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);
+
+ //Resgiter change to the observers of the actual model
+ model->notifyObservers(_idManager);
+
+ //Register the controller of the new object
+ registerController((InteractorStyleMaracas*) controller);
+
+ //Add the object to the objects list
+ int newId = _controllers.size();
+ controller->setId(newId);
+ _controllers[newId] = controller;
+ return newId;
+ }
+ //=========================================================================
+
+ int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
+ {
+ int windowWidth=_baseView->GetRenWin()->GetSize()[0];
+ int windowHeight=_baseView->GetRenWin()->GetSize()[1];
+
+ int type = GCOMPLEXOUTPUTPORT;
+
+ //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
+
+ double xx = 5;
+ double yy = windowHeight-5;
+
+ //z value is not important yet, because it is only used a parallel projection
+ double zz = 900;
+
+ _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);
//Associates the controller with the correspondent model and view
controller->setModelAndView(model,view);
+ //Resgiter change to the observers of the actual model
+ model->notifyObservers(_idManager);
+
//Register the controller of the new object
registerController((InteractorStyleMaracas*) controller);
+
+ //Add the object to the objects list
+ int newId = _controllers.size();
+ controller->setId(newId);
+ _controllers[newId] = 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::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();
}
//=========================================================================
- void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox, int pos)
+ GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
{
int type = GPORT;
vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
- model->registerInBox(blackBox,GINPUTPORT,pos);
- blackBox->addInputPort(model);
+ model->registerInBox(blackBox,portType, posInBox);
+
+ model->setBBTKType(bbtkType);
+ model->setBBTKName(bbtkName);
model->addObserver(view);
model->addObserver(this);
//Associates the controller with the correspondent model and view
controller->setModelAndView(model,view);
+ model->notifyObservers(_idManager);
+
//Register the controller of the new object
registerController((InteractorStyleMaracas*) controller);
+
+ int newId = _controllers.size();
+ controller->setId(newId);
+ _controllers[newId] = controller;
+
+ return (GPortController*)controller;
}
//=========================================================================
- void wxVtkSceneManager::createGConnector(GPortModel* startPort)
+ int wxVtkSceneManager::createGConnector(GPortModel* startPort)
{
- manualContourControler* manContourControl = new manualContourControler();
- manualViewContour* manViewerContour = new manualViewContour();
+ int type = GCONNECTOR;
+
+ manualConnectorContourController* manContourControl = new manualConnectorContourController();
+ manualConnectorContourView* manContourView = new manualConnectorContourView();
manualContourModel* manContourModel = new manualContourModel();
-
- manViewerContour->SetModel( manContourModel );
- manViewerContour->SetWxVtkBaseView( _baseView );
- manViewerContour->SetRange( 0.5 );
- manViewerContour->SetZ( 900 );
+ GConnectorController* connectorcontroller = new GConnectorController();
+ GConnectorModel* connectorModel = new GConnectorModel();
+ vtkGConnectorView* connectorView = new vtkGConnectorView();
+ connectorModel->setGObjectType(type);
- manViewerContour->SetColorNormalContour(0, 0, 1);
- manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
- manViewerContour->SetColorSelectContour(1, 0.8, 0);
- manViewerContour->SetWidthLine(1);
+ manContourModel->SetCloseContour(false);
+ connectorModel->setStartPort(startPort);
- manContourControl->SetModelView( manContourModel , manViewerContour );
- manContourControl->Configure();
- int i,sizeLstPoints = manContourModel->GetSizeLstPoints();
- for ( i=0; i<sizeLstPoints; i++ )
- {
- manViewerContour->AddPoint();
- }
+ manContourView->SetModel( manContourModel );
+ manContourView->SetWxVtkBaseView( _baseView );
+ manContourView->SetRange( 0.5 );
+ manContourView->SetZ( 900 );
+
+ 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);
+ manContourControl->SetModelView( manContourModel , manContourView );
+
manContourControl->CreateNewManualContour();
- manViewerContour->RefreshContour();
- registerController((InteractorStyleMaracas*) manContourControl);
+ manContourView->RefreshContour();
+
+
+ double x,y,z;
+ connectorModel->getInicPoint(x,y,z);
+
+ manContourControl->SetState(1);
+ manContourModel->SetCloseContour(false);
+
+ manContourModel->AddPoint(x,y,z);
+ manContourView->AddPoint();
+
+ manContourModel->AddPoint(x,y,z);
+ manContourView->AddPoint();
+
+ int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
+ manContourControl->_bakIdPoint=bak;
+ manContourView->Refresh();
+
+ manContourControl->SetMoving( false );
+
+ registerController((InteractorStyleMaracas*) connectorcontroller);
+
+ connectorcontroller->setManualContourController(manContourControl);
+ connectorModel->setManualContourModel(manContourModel);
+ connectorView->setManualContourView(manContourView);
+ connectorView->setModel(connectorModel);
+ connectorView->setBaseView(_baseView);
+ connectorcontroller->setModelAndView(connectorModel,connectorView);
+
+ connectorModel->addObserver(connectorView);
+ connectorModel->addObserver(this);
+
+ int newId = _controllers.size();
+ connectorcontroller->setId(newId);
+ _controllers[newId] = connectorcontroller;
+
+ return newId;
}
//=========================================================================
//=========================================================================
+ void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
+ {
+ vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
+ baseViewControlManager->RemoveInteractorStyleMaracas( param );
+ }
+
+ //=========================================================================
+
vtkRenderer* wxVtkSceneManager::getRenderer()
{
return _baseView->GetRenderer();
}
//=========================================================================
+
+ void wxVtkSceneManager::update(int idController,int command)
+ {
+ if(command != NO_COMMAND)
+ {
+ if(command == ADD_TO_SELECTED)
+ {
+ GObjectController* cont = _controllers[idController];
+
+ 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);
+ }
+
+ }
+ else if(command == INIT_CREATION_CONTOUR)
+ {
+ _worldState = INIT_CREATION_CONTOUR;
+ GObjectController* cont = _controllers[idController];
+ GPortModel* startOutputPort = (GPortModel*)cont->getModel();
+
+
+ // The last one is the controller of the connector
+ for(int i=0;i<_controllers.size();i++)
+ {
+ GObjectController* cont = _controllers[i];
+ 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);
+ }
+ }
+
+ _selectedObjects.clear();
+
+ createGConnector(startOutputPort);
+
+ }
+ else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
+ {
+ _worldState = NOTHING_HAPPENS;
+ int id = _controllers.size()-1;
+ GObjectController* cont = _controllers[id];
+ GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
+
+ GObjectController* finPort = _controllers[idController];
+ if(finPort->getGObjectType() == GPORT)
+ {
+ GPortModel* modelPort = (GPortModel*)finPort->getModel();
+ modelContour->setEndPort(modelPort);
+ }
+
+ manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
+ manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
+ connView->Refresh();
+
+ for(int i=0;i<_controllers.size();i++)
+ {
+ GObjectController* cont = _controllers[i];
+ if(cont->getView()!=NULL)
+ {
+ cont->getView()->setState(NOTHING_HAPPENS);
+ cont->getModel()->notifyObservers(_idManager);
+ }
+ cont->SetActive(true);
+ }
+ }
+
+ }
+ }
+
+ //=========================================================================
+
bool wxVtkSceneManager::OnMouseMove()
{
+ int X,Y;
+ wxVTKRenderWindowInteractor *wxVTKiren;
+ wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
+ wxVTKiren->GetEventPosition(X,Y);
+
+
+ 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);
+ }
+
+ 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();
+ }
+ }
+
+ _startDragging=false;
+
+ }
+ else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
+ {
+ std::map<int, GObjectController*>::iterator it;
+
+ for(it = _controllers.begin(); it != _controllers.end(); ++it)
+ {
+ GObjectController *desc = it->second;
+ int type = desc->getGObjectType();
+ int state = desc->getView()->getState();
+
+ if(state == HIGHLIGHTED){
+
+ updateStatusBar(desc->getStatusText());
+ if(type==GBLACKBOX)
+ {
+ GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
+ _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
+ }
+ }
+ }
+ }
+
+
+
+
return true;
}
//=========================================================================
- void wxVtkSceneManager::update(int command)
+ 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)
+ {
+ 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;
+ }
+ }
+ }
+
+ if(isOverPort==false)
+ {
+ _worldState=NOTHING_HAPPENS;
+ int lastId = _controllers.size()-1;
+ GConnectorController *connector = (GConnectorController*)_controllers[lastId];
+ connector->removeFromScene();
+ unregisterController(connector);
+ _controllers.erase(lastId);
+
+ for(it = _controllers.begin(); it != _controllers.end(); ++it)
+ {
+ GObjectController *desc = it->second;
+ desc->SetActive(true);
+ desc->getView()->setState(NOTHING_HAPPENS);
+ desc->getModel()->notifyObservers(_idManager);
+ }
+ }
+ }
+
+ if(_selectedObjects.size()!=0)
+ {
+ _worldState = DRAG_OBJECTS;
+ _startDragging = true;
+
+ for (int i = 0; i < _selectedObjects.size(); i++)
+ {
+ int id = _selectedObjects[i];
+ GObjectController* cont = _controllers[id];
+ cont->getView()->setState(DRAG);
+ cont->getModel()->notifyObservers(_idManager);
+ }
+ }
- if(command==INIT_CREATION_CONTOUR)
+
+
+ return true;
+ }
+
+ //=========================================================================
+
+ bool wxVtkSceneManager::OnLeftButtonUp()
+ {
+ if(_worldState == DRAG_OBJECTS)
+ {
+ _worldState = NOTHING_HAPPENS;
+
+ for (int i = 0; i < _selectedObjects.size(); i++)
+ {
+ int id = _selectedObjects[i];
+ GObjectController* cont = _controllers[id];
+ cont->getView()->setState(SELECTED);
+ cont->getModel()->notifyObservers(_idManager);
+ }
+ }
+ return true;
+ }
+
+ //=========================================================================
+
+ bool wxVtkSceneManager::OnRightButtonUp()
+ {
+ if(_worldState==INIT_CREATION_CONTOUR)
+ {
+ _worldState=NOTHING_HAPPENS;
+ int lastId = _controllers.size()-1;
+ GConnectorController *connector = (GConnectorController*)_controllers[lastId];
+ connector->removeFromScene();
+ unregisterController(connector);
+ _controllers.erase(lastId);
+
+ 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++)
+ {
+ int id = _selectedObjects[i];
+ GObjectController* cont = _controllers[id];
+ cont->SetActive(true);
+ cont->getView()->setState(NOTHING_HAPPENS);
+ cont->getModel()->notifyObservers(_idManager);
+ }
+
+ _selectedObjects.clear();
+
+ return true;
+ }
+
+ //=========================================================================
+
+ bool wxVtkSceneManager::OnLeftDClick()
+ {
+ 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)
{
- std::cout<<"wxVtkSceneManager::update size:"<<_objects.size()<<std::endl;
- for(int i = 0; i<_objects.size();i++)
+ GObjectController *cont = it->second;
+ int type = cont->getGObjectType();
+
+ if(cont->getView()->isPointInside(X,Y))
{
- std::cout<<"wxVtkSceneManager::update type:"<<_objects[i]->getGObjectType()<<std::endl;
- if(_objects[i]->getGObjectType() == GBLACKBOX)
+ if(type==GBLACKBOX)
{
-
- GPortModel* startInputPort=((GBlackBoxModel*)_objects[i])->getStartInputPort();
- std::cout<<"wxVtkSceneManager::update "<<startInputPort<<std::endl;
- createGConnector(startInputPort);
+ for (int i=0; i<_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()
+ {
+ char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
+
+ // KeyCode 127 : Delete Key
+ // KeyCode 8 : Backspace Key
+ if(keyCode == 8 || keyCode == 127)
+ {
+ if(_selectedObjects.size()>0)
+ {
+ for(int i=0;i<_selectedObjects.size();i++)
+ {
+ int id = _selectedObjects[i];
+ deleteObject(id);
+ }
+ _selectedObjects.clear();
+ }
+ }
+
+ return true;
+ }
+
+ //=========================================================================
+
+ void wxVtkSceneManager::deleteObject(int id)
+ {
+ GObjectController *control = _controllers[id];
+ std::vector<int> controllersToRemove;
+
+ if(control->getGObjectType()==GBLACKBOX)
+ {
+ GBlackBoxModel *bbmod = (GBlackBoxModel*)control->getModel();
+ std::vector<GPortModel*> inputs = bbmod->getInputPorts();
+
+ bool boxConnected = false;
+
+ // 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ // 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());
+ }
+
+ for(int i = 0;i<controllersToRemove.size();i++)
+ {
+ int id = controllersToRemove[i];
+ GObjectController *cont = _controllers[id];
+ cont->removeFromScene();
+ unregisterController((InteractorStyleMaracas*)cont);
+ _controllers.erase(id);
+ }
+
+
+ }
+
+ //=========================================================================
+
+ 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::getDiagramBBS()
+ {
+ 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<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);
+ existsExec=true;
+ }
+ }
+ else if(type==GCONNECTOR)
+ {
+ connections.push_back(it->first);
+ }
+ }
+
+ std::string script = "";
+ script+="# BBTK GEditor Script\n";
+ script+="# ----------------------\n";
+ if(existsExec)
+ {
+ int i;
+ for(i = 0; i<packages.size();i++)
+ {
+ script+="include ";
+ script+=packages[i];
+ script+="\n";
+ }
+
+ script+="include std\n";
+
+ for(i = 0; i<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<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";
+ }
+ }
+
+ }
+
+ for(i = 0; i<connections.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";
+ }
+
+ for(i = 0; i<execBoxes.size();i++)
+ {
+ script+="exec ";
+ int id = execBoxes[i];
+ GObjectController *control = _controllers[id];
+ GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
+
+ script+=model->getBBTKName();
+ script+="\n";
+ }
+
+ }
+
+ return script;
+ }
+
+ //=========================================================================
+
+ 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;
+
+ 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<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);
+ }
+ }
+
+ std::string script = "";
+ int i;
+ for(i = 0; i<packages.size();i++)
+ {
+ script+="include ";
+ script+=packages[i];
+ script+="\n";
+ }
+
+ script+="include std\n";
+
+ // Definition of a complex box
+ script+="define ";
+ script+=cbName;
+ script+="\n";
+
+ script+="author \" ";
+ script+=cbAuthor;
+ script+="\"\n";
+
+ script+="description \" ";
+ script+=cbDescription;
+ 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+=model->getBBTKType();
+ script+=" ";
+ script+=model->getBBTKName();
+ 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";
+ }
+ }
+
+ }
+
+ // Create connections in the script. If the connection is made with a complex port, it is created the input or output
+
+ 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();
+
+ //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
{
- // The others must not react to events
+ script+="connect ";
+ script+=startBox->getBBTKName();
+ script+=".";
+ script+=start->getBBTKName();
+
+ script+=" ";
+
+ //End Connection info
+ script+=endBox->getBBTKName();
+ script+=".";
+ script+=end->getBBTKName();
+
+ 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+=model->getBBTKName();
+ script+="\n";
+ }
+
+ script+="\n";
+ script+="# Complex input ports\n";
+ script+=complexInputs;
+
+ script+="\n";
+ script+="# Complex output ports\n";
+ script+=complexOutputs;
+
+ 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();
+ refreshScene();
+ }
+
+ //=========================================================================
+
+ 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]);
+ _baseView->RefreshView();
+
+ }
+
+ //=========================================================================
+
+ void wxVtkSceneManager::saveDiagram(std::string &content)
+ {
+ //Print boxes
+ char buffer [50];
+ std::vector<int> boxes = getBoxes();
+ 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];
+ 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";
+
+ for(int i = 0;i<csize;i++)
+ {
+ int id = connections[i];
+ GObjectController *cont = _controllers[id];
+ cont->getModel()->save(content);
+ }
+
+ }
+
+ //=========================================================================
+
+ void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
+ {
+
+ std::string line="";
+ char delims[] = ":";
+ char *result = NULL;
+ getline(inputStream,line);
+
+ bool start = false;
+ while ( !inputStream.eof() )
+ {
+ if(line=="" || line[0]=='#')
+ {
+ getline(inputStream,line);
+ }
+ else if(line=="APP_START")
+ {
+ start = true;
+ break;
+ }
+ }
+
+ if(start)
+ {
+ //----------
+ getline(inputStream,line);//BOXES:num
+ char boxes[9];
+ strcpy( boxes, line.c_str() );
+ result = strtok( boxes, delims );
+ result = strtok( NULL, delims );
+
+ int numBoxes;
+ std::istringstream is(result);
+ is >> numBoxes;
+
+ for(int i = 0;i<numBoxes;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);
+
+ //----------
+ 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);//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;
+
+ int idBox = createGBlackBox(0,0,package,type);
+ GObjectController *cont = _controllers[idBox];
+ GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
+ bbmod->setBBTKName(name);
+ bbmod->setInicPoint(xIn,yIn,zIn);
+ bbmod->setFinalPoint(xEn,yEn,zEn);
+ if(isExec=="TRUE")
+ {
+ bbmod->setExecutable(true);
+ }
+ else if(isExec=="FALSE")
+ {
+ bbmod->setExecutable(false);
+ }
+
+ //----------
+ getline(inputStream,line);//PORT o FIN_BOX
+ std::string port=line.substr(0,4);
+ while(port=="PORT")
+ {
+ 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);
+
+ bbmod->setValueToInput(name,value);
+
+ getline(inputStream,line);//PORT o FIN_BOX
+ port=line.substr(0,4);
+ }
+
+ bbmod->notifyObservers(_idManager);
+ }
+
+ /// CONNECTIONS
+ //----------
+ getline(inputStream,line);//CONNECTIONS:num
+ char conns[15];
+ strcpy( conns, line.c_str() );
+ result = strtok( conns, delims );
+ result = strtok( NULL, delims );
+
+ int numConns;
+ std::istringstream isCons(result);
+ isCons >> numConns;
+
+ for(int i = 0;i<numConns;i++)
+ {
+ //----------
+ 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 = getBoxes();
+
+ GPortModel *startP=NULL;
+ GPortModel *endP=NULL;
+ for(int j = 0;j<lstB.size();j++)
+ {
+ 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);
+ }
}
+
+ 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();
+
+ }
+ }
+
+ }
+
+ //=========================================================================
+
+ std::vector<int> wxVtkSceneManager::getBoxes()
+ {
+ 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::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;
}
//=========================================================================