//=========================================================================
- wxVtkSceneManager::wxVtkSceneManager(wxDropTarget *parent, wxVtk3DBaseView *baseView,int idManager)
+ wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView,int idManager)
{
+ _parent = parent;
_numBoxes=0;
_idManager=idManager;
_baseView=baseView;
_idLastController=0;
+ _startDragging=false;
if( _baseView!=NULL )
{
- _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(parent);
- registerController(this);
+ _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
configureBaseView();
_worldState=NOTHING_HAPPENS;
+ registerController(this);
}
-
}
-
//=========================================================================
void wxVtkSceneManager::disconnectDrop()
{
_baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
- }
+ }
//=========================================================================
//=========================================================================
- void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxName)
+ void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
{
int windowWidth=_baseView->GetRenWin()->GetSize()[0];
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
std::string arraystring = stream.str();
model->setBBTKName(arraystring);
- model->setBBTKType(boxName);
+ model->setBBTKType(boxType);
+ model->setBBTKPackage(packageName);
model->addObserver(view);
model->addObserver(this);
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);
void wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxInputDescriptor *desc)
{
- createGPort(portType,posinBox,blackBox);
+ createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
}
//=========================================================================
void wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
{
- createGPort(portType,posinBox,blackBox);
+ createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
}
//=========================================================================
- void wxVtkSceneManager::createGPort(int portType, int posInBox,GBlackBoxModel *blackBox)
+ void wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBlackBoxModel *blackBox)
{
int type = GPORT;
model->registerInBox(blackBox,portType, posInBox);
blackBox->addOutputPort(model);
+ 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();
+ model->notifyObservers(_idManager);
//Register the controller of the new object
registerController((InteractorStyleMaracas*) controller);
int type = GCONNECTOR;
manualConnectorContourController* manContourControl = new manualConnectorContourController();
- manualConnectorContourView* manViewerContour = new manualConnectorContourView();
+ manualConnectorContourView* manContourView = new manualConnectorContourView();
manualContourModel* manContourModel = new manualContourModel();
GConnectorController* connectorcontroller = new GConnectorController();
manContourModel->SetCloseContour(false);
connectorModel->setStartPort(startPort);
- manViewerContour->SetModel( manContourModel );
- manViewerContour->SetWxVtkBaseView( _baseView );
- manViewerContour->SetRange( 0.5 );
- manViewerContour->SetZ( 900 );
+ manContourView->SetModel( manContourModel );
+ manContourView->SetWxVtkBaseView( _baseView );
+ manContourView->SetRange( 0.5 );
+ manContourView->SetZ( 900 );
- manViewerContour->SetColorNormalContour(0, 0, 1);
- manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
- manViewerContour->SetColorSelectContour(1, 0.8, 0);
- manViewerContour->SetWidthLine(1);
+ manContourView->SetColorNormalContour(0, 0, 1);
+ manContourView->SetColorEditContour(0.5, 0.5, 0.5);
+ manContourView->SetColorSelectContour(1, 0.8, 0);
+ manContourView->SetWidthLine(1);
- manContourControl->SetModelView( manContourModel , manViewerContour );
+ manContourControl->SetModelView( manContourModel , manContourView );
manContourControl->CreateNewManualContour();
- manViewerContour->RefreshContour();
+ manContourView->RefreshContour();
double x,y,z;
manContourModel->SetCloseContour(false);
manContourModel->AddPoint(x,y,z);
- manViewerContour->AddPoint();
+ manContourView->AddPoint();
manContourModel->AddPoint(x,y,z);
- manViewerContour->AddPoint();
+ manContourView->AddPoint();
int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
manContourControl->_bakIdPoint=bak;
- manViewerContour->Refresh();
+ manContourView->Refresh();
manContourControl->SetMoving( false );
connectorcontroller->setManualContourController(manContourControl);
connectorModel->setManualContourModel(manContourModel);
- connectorcontroller->setModelAndView(connectorModel,NULL);
+ connectorView->setManualContourView(manContourView);
+ connectorView->setModel(connectorModel);
+ connectorcontroller->setModelAndView(connectorModel,connectorView);
int newId = _controllers.size();
connectorcontroller->setId(newId);
}
//=========================================================================
- bool wxVtkSceneManager::OnMouseMove()
- {
- return true;
- }
-
- //=========================================================================
-
+
void wxVtkSceneManager::update(int idController,int command)
{
-
- if(command == INIT_CREATION_CONTOUR)
- {
- GObjectController* cont = _controllers[idController];
- if(cont->getGObjectType() == GPORT)
+ if(command != NO_COMMAND)
+ {
+ if(command == ADD_TO_SELECTED)
{
- GPortModel* startOutputPort = (GPortModel*)cont->getModel();
- createGConnector(startOutputPort);
+ 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);
+ }
+
}
- // The last one is the controller of the connector
- for(int i=0;i<_controllers.size()-1;i++)
- {
- GObjectController* cont = _controllers[i];
- if(cont->getGObjectType() == GPORT )
+ 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++)
{
- GPortModel* port = (GPortModel*)cont->getModel();
- if(port->getPortType()==GINPUTPORT)
+ GObjectController* cont = _controllers[i];
+ if(cont->getGObjectType() == GPORT )
{
- cont->SetActive(true);
+ 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);
- }
+ }
}
- else
+
+ _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++)
{
- cont->getView()->setState(NOTHING_HAPPENS);
- cont->SetActive(false);
- }
+ GObjectController* cont = _controllers[i];
+ if(cont->getView()!=NULL)
+ {
+ cont->getView()->setState(NOTHING_HAPPENS);
+ cont->getModel()->notifyObservers(_idManager);
+ }
+ cont->SetActive(true);
+ }
}
- _worldState = CREATING_CONTOUR;
}
- else if(command == FIN_CREATION_CONTOUR && _worldState == CREATING_CONTOUR)
- {
- _worldState = NOTHING_HAPPENS;
- int id = _controllers.size()-1;
- GObjectController* cont = _controllers[id];
- GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
+ }
- GObjectController* finPort = _controllers[idController];
- if(cont->getGObjectType() == GPORT)
+ //=========================================================================
+
+ 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++)
{
- GPortModel* modelPort = (GPortModel*)finPort->getModel();
- modelContour->setEndPort(modelPort);
- }
+ 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);
+ }
- manualContourControler* manCont = ((GConnectorController*)cont)->getManualContourController();
-
- //manCont->SetCompleteCreation( true );
- //manCont->SetKeyBoardMoving( false );
- //manCont->GetManualContourModel()->SetCloseContour(false);
- //manCont->SetEditable( false );
- //manCont->SetPosibleToMove( false );
- //manCont->SetState(0);
-
- for(int i=0;i<_controllers.size();i++)
+ std::map<int, GObjectController*>::iterator it;
+
+ for(it = _controllers.begin(); it != _controllers.end(); ++it)
{
- GObjectController* cont = _controllers[i];
- if(cont->getView()!=NULL)
+ GObjectController *desc = it->second;
+ if(desc->getGObjectType()==GCONNECTOR)
{
- cont->getView()->setState(NOTHING_HAPPENS);
+ GConnectorView* vconn = (GConnectorView*)desc->getView();
+ vconn->updateStartEndPoints();
}
- cont->SetActive(true);
}
+
+ _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;
+ }
+
+ //=========================================================================
+
+ bool wxVtkSceneManager::OnLeftButtonDown()
+ {
+
+ 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);
+ }
+ }
+
+
+
+ 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()
+ {
+ 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;
+ }
+
+ //=========================================================================
+
+ void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
+ {
+ _parent->displayBlackBoxInfo(packageName,boxName);
+ }
+
+ //=========================================================================
+
+ void wxVtkSceneManager::updateStatusBar(std::string textStatus)
+ {
+ _parent->updateStatusBar(textStatus);
}
//=========================================================================