X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FEditorGraphicBBS%2FbbsKernelEditorGraphic%2FwxVtkSceneManager.cxx;h=784c3f667f9fd4aa1d301e716449145e37ead717;hb=b07121ce96dd600b41cb6b9588d117ec72969317;hp=2227c9003b5245407b07340d5be07c8808aaadb7;hpb=eb765b17b9d4f6952a565569f89e3bc9204f9c6e;p=bbtkGEditor.git diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx index 2227c90..784c3f6 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx @@ -48,6 +48,7 @@ namespace bbtk _idManager=idManager; _baseView=baseView; _startDragging=false; + _isComplexBox=false; if( _baseView!=NULL ) { @@ -65,14 +66,14 @@ namespace bbtk void wxVtkSceneManager::disconnectDrop() { _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL); - } + } //========================================================================= wxVtkSceneManager::~wxVtkSceneManager() { } - + //========================================================================= void wxVtkSceneManager::configureBaseView() @@ -97,9 +98,8 @@ namespace bbtk //========================================================================= - void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType) + 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]; @@ -189,28 +189,149 @@ namespace bbtk int newId = _controllers.size(); controller->setId(newId); _controllers[newId] = controller; + return newId; } //========================================================================= - void wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxInputDescriptor *desc) + int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) + { + int windowWidth=_baseView->GetRenWin()->GetSize()[0]; + int windowHeight=_baseView->GetRenWin()->GetSize()[1]; + + int type = GCOMPLEXINPUTPORT; + + //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(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); + 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::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(); } //========================================================================= - void wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxOutputDescriptor *desc) + 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(); } //========================================================================= - GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBlackBoxModel *blackBox) + GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox) { int type = GPORT; @@ -250,7 +371,7 @@ namespace bbtk //========================================================================= - void wxVtkSceneManager::createGConnector(GPortModel* startPort) + int wxVtkSceneManager::createGConnector(GPortModel* startPort) { int type = GCONNECTOR; @@ -260,7 +381,7 @@ namespace bbtk GConnectorController* connectorcontroller = new GConnectorController(); GConnectorModel* connectorModel = new GConnectorModel(); - GConnectorView* connectorView = new GConnectorView(); + vtkGConnectorView* connectorView = new vtkGConnectorView(); connectorModel->setGObjectType(type); manContourModel->SetCloseContour(false); @@ -318,6 +439,7 @@ namespace bbtk connectorcontroller->setId(newId); _controllers[newId] = connectorcontroller; + return newId; } //========================================================================= @@ -373,7 +495,6 @@ namespace bbtk { int id = idController; _selectedObjects.push_back(id); - cout<<"RaC wxVtkSceneManager::update _selectedObjects.push_back id:"<second; if(desc->getGObjectType()==GCONNECTOR) { - GConnectorView* vconn = (GConnectorView*)desc->getView(); + vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView(); vconn->updateStartEndPoints(); } } @@ -764,7 +885,6 @@ namespace bbtk else if(control->getGObjectType()==GCONNECTOR) { GConnectorModel *conMod = (GConnectorModel*)control->getModel(); - cout<<"RaC wxVtkSceneManager::deleteObject id:"<getObjectId()<getObjectId()); } @@ -796,7 +916,7 @@ namespace bbtk //========================================================================= - std::string wxVtkSceneManager::getDiagramScript() + std::string wxVtkSceneManager::getDiagramBBS() { bool existsExec=false; @@ -931,6 +1051,201 @@ namespace bbtk //========================================================================= + std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription) + { + + 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); + } + } + else if(type==GCONNECTOR) + { + connections.push_back(it->first); + } + } + + std::string script = ""; + int i; + for(i = 0; igetModel(); + + script+=model->getBBTKType(); + script+=" "; + script+=model->getBBTKName(); + script+="\n"; + + std::vector inputs = model->getInputPorts(); + for(int j = 0; jisValueSet()) + { + 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; igetModel(); + + //Connection info + GPortModel *start = model->getStartPort(); + GBoxModel *startBox =start->getParentBox(); + + GPortModel *end = model->getEndPort(); + GBoxModel *endBox =end->getParentBox(); + + if(startBox->getGObjectType()==GCOMPLEXINPUTPORT) + { + complexInputs+="input "; + complexInputs+=startBox->getBBTKName(); + + complexInputs+=" "; + complexInputs+=endBox->getBBTKName(); + complexInputs+="."; + complexInputs+=end->getBBTKName(); + + complexInputs+=" "; + complexInputs+="\" \""; + + complexInputs+="\n"; + } + else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT) + { + complexOutputs+="output "; + complexOutputs+=endBox->getBBTKName(); + + complexOutputs+=" "; + complexOutputs+=startBox->getBBTKName(); + complexOutputs+="."; + complexOutputs+=start->getBBTKName(); + + complexOutputs+=" "; + complexOutputs+="\" \""; + + complexOutputs+="\n"; + } + else + { + script+="connect "; + script+=startBox->getBBTKName(); + script+="."; + script+=start->getBBTKName(); + + script+=" "; + + //End Connection info + script+=endBox->getBBTKName(); + script+="."; + script+=end->getBBTKName(); + + script+="\n"; + } + } + + for(i = 0; igetModel(); + + 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::iterator it; @@ -973,7 +1288,7 @@ namespace bbtk char buffer [50]; std::vector boxes = getBoxes(); int bsize = boxes.size(); - content+="BOXES "; + content+="BOXES:"; sprintf (buffer, "%d", bsize); content+=buffer; content+="\n"; @@ -985,12 +1300,10 @@ namespace bbtk cont->getModel()->save(content); } - content+="\n"; - //Print connections std::vector connections = getConnections(); int csize = connections.size(); - content+="CONNECTIONS "; + content+="CONNECTIONS:"; sprintf (buffer, "%d", csize); content+=buffer; content+="\n"; @@ -1006,6 +1319,200 @@ namespace bbtk //========================================================================= + 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> 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 lstB = getBoxes(); + + GPortModel *startP=NULL; + GPortModel *endP=NULL; + for(int j = 0;jgetModel(); + 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 wxVtkSceneManager::getBoxes() { std::vector vect; @@ -1039,6 +1546,20 @@ namespace bbtk } //========================================================================= + + bool wxVtkSceneManager::isComplexBox() + { + return _isComplexBox; + } + + //========================================================================= + + void wxVtkSceneManager::setComplexBox(bool val) + { + _isComplexBox=val; + } + + //========================================================================= } // EO namespace bbtk