X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FEditorGraphicBBS%2FbbsKernelEditorGraphic%2FwxVtkSceneManager.cxx;h=c4efe5605d986f87da642f9bbcd499ea122c47e3;hb=a6d479881eeb637cd06afa3b2177e430fa05571e;hp=23ea678c0a0d21ca6bfe58265e8a10e5256724d4;hpb=878ac6ad472bc459f4e364c16890e5026c401944;p=bbtkGEditor.git diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx index 23ea678..c4efe56 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx @@ -41,105 +41,32 @@ namespace bbtk //========================================================================= - 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; + _idLastController=0; + _startDragging=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, -100 , -100 , 900 ); - _pts->SetPoint(1, 100 , -100 , 900 ); - _pts->SetPoint(2, 100 , 100 , 900 ); - _pts->SetPoint(3, -100 , 100 , 900 ); - - 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); - - - - - vtkPoints *_pts2 = vtkPoints::New(); - _pts2->SetNumberOfPoints(4); - - _pts2->SetPoint(0, -105 , -100 , -50 ); - _pts2->SetPoint(1, 100 , -100 , -50 ); - _pts2->SetPoint(2, 100 , 100 , -50 ); - _pts2->SetPoint(3, -105 , 100 , -50 ); - - vtkCellArray *lines2 = vtkCellArray::New(); - lines2->InsertNextCell(5); - lines2->InsertCellPoint(0); - lines2->InsertCellPoint(1); - lines2->InsertCellPoint(2); - lines2->InsertCellPoint(3); - lines2->InsertCellPoint(0); - - vtkPolyData *_pd2 = vtkPolyData::New(); - _pd2->SetPoints( _pts2 ); - _pd2->SetLines( lines2 ); - - vtkActor *_pointVtkActor2 = vtkActor::New(); - vtkPolyDataMapper* _bboxMapper2 = vtkPolyDataMapper::New(); - - _bboxMapper2->SetInput(_pd2); - _pointVtkActor2->SetMapper(_bboxMapper2); - - getRenderer()->AddActor(_pointVtkActor2); - - */ - // ******* TO ERASE ******* - ///////////////////// + _worldState=NOTHING_HAPPENS; + registerController(this); } - } + } //========================================================================= void wxVtkSceneManager::disconnectDrop() { _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL); - } + } //========================================================================= @@ -171,7 +98,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]; @@ -185,13 +112,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; @@ -199,22 +126,22 @@ namespace bbtk _baseView->TransCoordScreenToWorld(xx,yy,zz); model->setInicPoint(xx,yy,zz); - int cantObjects = _objects.size(); - cantObjects++; + _numBoxes++; std::stringstream stream; - if(cantObjects<10) + if(_numBoxes<10) { - stream << "Box0" << cantObjects; + stream << "Box0" << _numBoxes; } else { - stream << "Box" << cantObjects; + stream << "Box" << _numBoxes; } std::string arraystring = stream.str(); model->setBBTKName(arraystring); - model->setBBTKType(boxName); + model->setBBTKType(boxType); + model->setBBTKPackage(packageName); model->addObserver(view); model->addObserver(this); @@ -254,15 +181,12 @@ namespace bbtk 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 - _objects.push_back(controller); - int newId = _controllers.size(); controller->setId(newId); _controllers[newId] = controller; @@ -273,19 +197,19 @@ namespace bbtk 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; @@ -297,6 +221,9 @@ namespace bbtk model->registerInBox(blackBox,portType, posInBox); blackBox->addOutputPort(model); + model->setBBTKType(bbtkType); + model->setBBTKName(bbtkName); + model->addObserver(view); model->addObserver(this); @@ -309,7 +236,7 @@ namespace bbtk //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); @@ -323,35 +250,66 @@ namespace bbtk void wxVtkSceneManager::createGConnector(GPortModel* startPort) { - manualContourControler* manContourControl = new manualContourControler(); - GConnectorView* manViewerContour = new GConnectorView(); + int type = GCONNECTOR; + + manualConnectorContourController* manContourControl = new manualConnectorContourController(); + manualConnectorContourView* manContourView = new manualConnectorContourView(); manualContourModel* manContourModel = new manualContourModel(); - manContourModel->SetCloseContour(false); - manViewerContour->SetModel( manContourModel ); - manViewerContour->SetWxVtkBaseView( _baseView ); - manViewerContour->SetRange( 0.5 ); - manViewerContour->SetZ( 900 ); + GConnectorController* connectorcontroller = new GConnectorController(); + GConnectorModel* connectorModel = new GConnectorModel(); + GConnectorView* connectorView = new GConnectorView(); + 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(); + manContourView->SetModel( manContourModel ); + manContourView->SetWxVtkBaseView( _baseView ); + manContourView->SetRange( 0.5 ); + manContourView->SetZ( 900 ); - for ( i=0; iAddPoint(); - } + 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 , manContourView ); + manContourControl->CreateNewManualContour(); - manViewerContour->RefreshContour(); + 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(); - registerController((InteractorStyleMaracas*) manContourControl); + 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); + connectorcontroller->setModelAndView(connectorModel,connectorView); + + int newId = _controllers.size(); + connectorcontroller->setId(newId); + _controllers[newId] = connectorcontroller; } @@ -365,6 +323,14 @@ namespace bbtk //========================================================================= + void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param) + { + vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView(); + baseViewControlManager->RemoveInteractorStyleMaracas( param ); + } + + //========================================================================= + vtkRenderer* wxVtkSceneManager::getRenderer() { return _baseView->GetRenderer(); @@ -378,33 +344,421 @@ 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 idObservable,int command) + bool wxVtkSceneManager::OnLeftButtonDown() { - if(command==INIT_CREATION_CONTOUR) - { - GObjectController* cont = _controllers[idObservable]; - if(cont->getGObjectType() == GPORT) + if(_selectedObjects.size()!=0) + { + _worldState = DRAG_OBJECTS; + _startDragging = true; + + for (int i = 0; i < _selectedObjects.size(); i++) { - GPortController* controller = (GPortController*)cont; - vtkGPortView* view = (vtkGPortView*)controller->getView(); + 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(); - if(view->getState() == CREATING_CONTOUR) + 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++) { - //pre: The port in this state is an output port - GPortModel* startOutputPort = (GPortModel*)controller->getModel(); - createGConnector(startOutputPort); + int id = _selectedObjects[i]; + removeObject(id); } + _selectedObjects.clear(); } + } + + return true; + } + + //========================================================================= + + void wxVtkSceneManager::removeObject(int id) + { + GObjectController *control = _controllers[id]; + std::vector controllersToRemove; + + if(control->getGObjectType()==GBLACKBOX) + { + GBlackBoxModel *bbmod = (GBlackBoxModel*)control->getModel(); + std::vectorinputs = bbmod->getInputPorts(); + for(int i = 0;igetObjectId()); + } + + std::vectoroutputs = bbmod->getOutputPorts(); + + for(int i = 0;igetObjectId()); + } + + controllersToRemove.push_back(control->getId()); + } + + 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(); + + if(type==GBLACKBOX) + { + GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel(); + + std::string pkg = mod->getBBTKPackage(); + bool existsPkg = false; + for(int t = 0;tfirst); + 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; igetModel(); + + script+=model->getBBTKType(); + script+=" "; + script+=model->getBBTKName(); + script+="\n"; + } + + 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; } //=========================================================================