X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=lib%2FEditorGraphicBBS%2FbbsKernelEditorGraphic%2FwxVtkSceneManager.cxx;h=cab3936f7976ff5f98d0e03977c28e1a31aa6af1;hb=638f2cd85948ec10d3b30e1f68805ee0153c8813;hp=daa6327c157cceea4e7cd481750fa60fa7654e82;hpb=eaf825847b9ac4bd762deafa59a7df1c2ceba433;p=bbtkGEditor.git diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx index daa6327..cab3936 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx @@ -41,32 +41,31 @@ namespace bbtk //========================================================================= - 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); - } + } //========================================================================= @@ -98,7 +97,7 @@ namespace bbtk //========================================================================= - 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]; @@ -112,13 +111,13 @@ namespace bbtk 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 = 900; @@ -140,7 +139,8 @@ namespace bbtk std::string arraystring = stream.str(); model->setBBTKName(arraystring); - model->setBBTKType(boxName); + model->setBBTKType(boxType); + model->setBBTKPackage(packageName); model->addObserver(view); model->addObserver(this); @@ -196,19 +196,21 @@ namespace bbtk void wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxInputDescriptor *desc) { - createGPort(portType,posinBox,blackBox); + GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox); + blackBox->addInputPort((GPortModel*)portController->getModel()); } //========================================================================= void wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxOutputDescriptor *desc) { - createGPort(portType,posinBox,blackBox); + GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox); + blackBox->addOutputPort((GPortModel*)portController->getModel()); } //========================================================================= - void wxVtkSceneManager::createGPort(int portType, int posInBox,GBlackBoxModel *blackBox) + GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBlackBoxModel *blackBox) { int type = GPORT; @@ -218,8 +220,10 @@ namespace bbtk GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type); model->registerInBox(blackBox,portType, posInBox); - blackBox->addOutputPort(model); + model->setBBTKType(bbtkType); + model->setBBTKName(bbtkName); + model->addObserver(view); model->addObserver(this); @@ -240,6 +244,8 @@ namespace bbtk int newId = _controllers.size(); controller->setId(newId); _controllers[newId] = controller; + + return (GPortController*)controller; } //========================================================================= @@ -300,6 +306,7 @@ namespace bbtk connectorcontroller->setManualContourController(manContourControl); connectorModel->setManualContourModel(manContourModel); connectorView->setManualContourView(manContourView); + connectorView->setModel(connectorModel); connectorcontroller->setModelAndView(connectorModel,connectorView); int newId = _controllers.size(); @@ -318,6 +325,14 @@ namespace bbtk //========================================================================= + void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param) + { + vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView(); + baseViewControlManager->RemoveInteractorStyleMaracas( param ); + } + + //========================================================================= + vtkRenderer* wxVtkSceneManager::getRenderer() { return _baseView->GetRenderer(); @@ -331,76 +346,575 @@ namespace bbtk } //========================================================================= + + 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::iterator it; + + for(it = _controllers.begin(); it != _controllers.end(); ++it) + { + GObjectController *desc = it->second; + if(desc->getGObjectType()==GCONNECTOR) + { + GConnectorView* vconn = (GConnectorView*)desc->getView(); + vconn->updateStartEndPoints(); + } + } + + _startDragging=false; + + } + else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) + { + std::map::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 idController,int command) + bool wxVtkSceneManager::OnLeftButtonDown() { - - if(command == INIT_CREATION_CONTOUR) - { - GObjectController* cont = _controllers[idController]; - GPortModel* startOutputPort = (GPortModel*)cont->getModel(); - createGConnector(startOutputPort); - - // The last one is the controller of the connector - for(int i=0;i<_controllers.size()-1;i++) + if(_worldState==INIT_CREATION_CONTOUR) + { + bool isOverPort=false; + std::map::iterator it; + for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it) { - GObjectController* cont = _controllers[i]; - if(cont->getGObjectType() == GPORT ) + GObjectController *desc = it->second; + if(desc->getGObjectType()==GPORT) { - GPortModel* port = (GPortModel*)cont->getModel(); - if(port->getPortType()==GINPUTPORT) + GPortModel* portmod=(GPortModel*)desc->getModel(); + vtkGObjectView* portView=desc->getView(); + if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED) { - cont->SetActive(true); + isOverPort=true; } - else + } + } + + 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); + } + } + + + + 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::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::iterator it; + + bool clickOnObject = false; + + for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it) + { + GObjectController *cont = it->second; + int type = cont->getGObjectType(); + + if(type==GBLACKBOX) + { + if(cont->getView()->isPointInside(X,Y)) + { + for (int i=0; i<_selectedObjects.size(); i++) { - cont->getView()->setState(NOTHING_HAPPENS); - cont->SetActive(false); + int id = _selectedObjects[i]; + GObjectController* control = _controllers[id]; + control->getView()->setState(NOTHING_HAPPENS); } + _selectedObjects.clear(); + + GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel(); + _parent->editBlackBox(bbmodel); } - else + 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++) { - cont->getView()->setState(NOTHING_HAPPENS); - cont->SetActive(false); - } + int id = _selectedObjects[i]; + removeObject(id); + } + _selectedObjects.clear(); } - _worldState = CREATING_CONTOUR; } - else if(command == FIN_CREATION_CONTOUR && _worldState == CREATING_CONTOUR) + + return true; + } + + //========================================================================= + + void wxVtkSceneManager::removeObject(int id) + { + GObjectController *control = _controllers[id]; + std::vector controllersToRemove; + + if(control->getGObjectType()==GBLACKBOX) { + GBlackBoxModel *bbmod = (GBlackBoxModel*)control->getModel(); + std::vector inputs = bbmod->getInputPorts(); - _worldState = NOTHING_HAPPENS; - int id = _controllers.size()-1; - GObjectController* cont = _controllers[id]; - GConnectorModel* modelContour = (GConnectorModel*)cont->getModel(); + bool boxConnected = false; + + // Add box input controllers to be removed + for(int i = 0;igetObjectId()); + if(inputs[i]->isConnected()) + { + boxConnected = true; + } + } + + std::vector outputs = bbmod->getOutputPorts(); + + // Add box output controllers to be removed + for(int i = 0;igetObjectId()); + if(outputs[i]->isConnected()) + { + boxConnected = true; + } + } + + // Add connection controllers to be removed + std::map::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()); + } + + for(int i = 0;iremoveFromScene(); + 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::getDiagramScript() + { + bool existsExec=false; + + std::vector packages; + std::vector boxes; + std::vector connections; + std::vector execBoxes; + + std::map::iterator it; + + for(it = _controllers.begin(); it != _controllers.end(); ++it) + { + GObjectController *desc = it->second; + int type = desc->getGObjectType(); - GObjectController* finPort = _controllers[idController]; - if(finPort->getGObjectType() == GPORT) + if(type==GBLACKBOX) { - GPortModel* modelPort = (GPortModel*)finPort->getModel(); - modelContour->setEndPort(modelPort); - } + GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel(); + + std::string pkg = mod->getBBTKPackage(); + bool existsPkg = false; + for(int t = 0;tgetManualContourController(); - manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour(); - connView->Refresh(); + boxes.push_back(it->first); + if(mod->isExecutable()) + { + execBoxes.push_back(it->first); + existsExec=true; + } + } + else if(type==GCONNECTOR) + { + connections.push_back(it->first); + } + } - for(int i=0;i<_controllers.size();i++) + std::string script = ""; + script+="# BBTK GEditor Script\n"; + script+="# ----------------------\n"; + if(existsExec) + { + int i; + for(i = 0; igetView()!=NULL) + script+="include "; + script+=packages[i]; + script+="\n"; + } + + script+="include std\n"; + + for(i = 0; igetModel(); + + script+=model->getBBTKType(); + script+=" "; + script+=model->getBBTKName(); + script+="\n"; + + std::vector inputs = model->getInputPorts(); + for(int j = 0; jgetView()->setState(NOTHING_HAPPENS); + GPortModel* inputPort = inputs[j]; + if(inputPort->isValueSet()) + { + script+="set "; + script+=model->getBBTKName(); + script+="."; + script+=inputPort->getBBTKName(); + script+=" "; + script+=inputPort->getValue(); + script+="\n"; + } } - cont->SetActive(true); + } + + for(i = 0; igetModel(); + + //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; igetModel(); + + script+=model->getBBTKName(); + script+="\n"; + } + } + + return script; } //=========================================================================