From: corredor <> Date: Fri, 7 May 2010 14:30:39 +0000 (+0000) Subject: The app saves and opens diagrams !!!! Allll fiiiinnn se logro !! X-Git-Tag: v1_0_0~77 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=e36858ea5937bb1699bc437136718007df27be7b;p=bbtkGEditor.git The app saves and opens diagrams !!!! Allll fiiiinnn se logro !! --- diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.cxx b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.cxx index 7c7bebb..f7fe2e1 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.cxx +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.cxx @@ -216,11 +216,70 @@ namespace bbtk _inputs[i]->save(content); } } + content+="FIN_BOX\n"; } //========================================================================= + void GBlackBoxModel::setValueToInput(std::string name,std::string value) + { + for(int i = 0; i<_inputs.size();i++) + { + if(_inputs[i]->getBBTKName()==name) + { + _inputs[i]->setValue(value); + } + } + } + + //========================================================================= + + GPortModel* GBlackBoxModel::getInputPort(std::string name) + { + for(int i = 0; i<_inputs.size();i++) + { + if(_inputs[i]->getBBTKName()==name) + { + return _inputs[i]; + } + } + return NULL; + } + + //========================================================================= + + GPortModel* GBlackBoxModel::getOutputPort(std::string name) + { + for(int i = 0; i<_outputs.size();i++) + { + if(_outputs[i]->getBBTKName()==name) + { + return _outputs[i]; + } + } + return NULL; + } + + //========================================================================= + + void GBlackBoxModel::updatePorts() + { + for(int i = 0; i<_inputs.size();i++) + { + _inputs[i]->updatePortPosition(); + _inputs[i]->notifyObservers(_objectId); + } + + for(int i = 0; i<_outputs.size();i++) + { + _outputs[i]->updatePortPosition(); + _outputs[i]->notifyObservers(_objectId); + } + } + + //========================================================================= + } // EO namespace bbtk diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.h b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.h index de8b708..04ae668 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.h +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.h @@ -90,6 +90,12 @@ namespace bbtk std::vector getOutputPorts(); void setValueToInputPort(int pos,std::string value); + void setValueToInput(std::string name,std::string value); + + GPortModel* getInputPort(std::string name); + GPortModel* getOutputPort(std::string name); + + void updatePorts(); private: diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GConnectorModel.cxx b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GConnectorModel.cxx index 28df0dd..84cc58d 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GConnectorModel.cxx +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GConnectorModel.cxx @@ -165,11 +165,11 @@ namespace bbtk // Connection info content+=_startPort->getParentBox()->getBBTKName(); - content+="."; + content+=":"; content+=_startPort->getBBTKName(); content+=":"; content+=_endPort->getParentBox()->getBBTKName(); - content+="."; + content+=":"; content+=_endPort->getBBTKName(); content+="\n"; } diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx index 2227c90..4fcb043 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx @@ -97,7 +97,7 @@ 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]; @@ -189,23 +189,26 @@ 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::createGInputPort(int portType, int posinBox,GBlackBoxModel *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,GBlackBoxModel *blackBox, BlackBoxOutputDescriptor *desc) { GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox); blackBox->addOutputPort((GPortModel*)portController->getModel()); + return portController->getId(); } //========================================================================= @@ -250,7 +253,7 @@ namespace bbtk //========================================================================= - void wxVtkSceneManager::createGConnector(GPortModel* startPort) + int wxVtkSceneManager::createGConnector(GPortModel* startPort) { int type = GCONNECTOR; @@ -318,6 +321,7 @@ namespace bbtk connectorcontroller->setId(newId); _controllers[newId] = connectorcontroller; + return newId; } //========================================================================= @@ -373,7 +377,6 @@ namespace bbtk { int id = idController; _selectedObjects.push_back(id); - cout<<"RaC wxVtkSceneManager::update _selectedObjects.push_back id:"< boxes = getBoxes(); int bsize = boxes.size(); - content+="BOXES "; + content+="BOXES:"; sprintf (buffer, "%d", bsize); content+=buffer; content+="\n"; @@ -985,12 +988,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 +1007,185 @@ 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); + + //---------- + 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(); + GConnectorView *conView = (GConnectorView*)tempp->getView(); + tempp->endContourCreation(); + conMod->setEndPort(endP); + conView->updateStartEndPoints(); + + } + } + + } + + //========================================================================= + std::vector wxVtkSceneManager::getBoxes() { std::vector vect; diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.h b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.h index 1cee565..5fb1a86 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.h +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.h @@ -89,11 +89,11 @@ namespace bbtk ~wxVtkSceneManager(); void configureBaseView(); - void createGBlackBox(int x, int y,std::string packageName, std::string boxType); + int createGBlackBox(int x, int y,std::string packageName, std::string boxType); GPortController* createGPort(int portType, std::string bbtkName, std::string bbtkType, int posinBox,GBlackBoxModel *blackBox); - void createGInputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxInputDescriptor *desc); - void createGOutputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxOutputDescriptor *desc); - void createGConnector(GPortModel* startPort); + int createGInputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxInputDescriptor *desc); + int createGOutputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxOutputDescriptor *desc); + int createGConnector(GPortModel* startPort); void registerController(InteractorStyleMaracas *param); void unregisterController(InteractorStyleMaracas *param); @@ -118,6 +118,7 @@ namespace bbtk void deleteObject(int id); void deleteAllBoxes(); void saveDiagram(std::string &content); + void loadDiagram(ifstream &inputStream); void centerView(); void refreshScene(); diff --git a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GConnectorController.cxx b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GConnectorController.cxx index b2ff896..c9d8f74 100644 --- a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GConnectorController.cxx +++ b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GConnectorController.cxx @@ -106,7 +106,6 @@ namespace bbtk _controller->MouseReleaseLeft(X,Y); if(_controller->GetManualViewBaseContour()->GetSelected()==true) { - cout<<"RaC GConnectorController::OnLeftButtonUp GetSelected():"<<_controller->GetManualViewBaseContour()->GetSelected() <setState(SELECTED); _model->notifyObservers(getId(),ADD_TO_SELECTED); } @@ -206,6 +205,13 @@ namespace bbtk //========================================================================= + void GConnectorController::endContourCreation() + { + _controller->endContourCreation(); + } + + //========================================================================= + } // EO namespace bbtk // EOF diff --git a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GConnectorController.h b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GConnectorController.h index 0d72239..00aeb03 100644 --- a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GConnectorController.h +++ b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GConnectorController.h @@ -81,6 +81,7 @@ namespace bbtk void setManualContourController(manualConnectorContourController* controller); virtual void removeFromScene(); + void endContourCreation(); private: diff --git a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/manualConnectorContourController.cxx b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/manualConnectorContourController.cxx index 415c64d..a1c234a 100644 --- a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/manualConnectorContourController.cxx +++ b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/manualConnectorContourController.cxx @@ -92,7 +92,9 @@ namespace bbtk } //========================================================================= - void manualConnectorContourController::MouseClickLeft(int x, int y){ + + void manualConnectorContourController::MouseClickLeft(int x, int y) + { bool ok = false; int z = GetZ(); @@ -121,14 +123,7 @@ namespace bbtk if ((GetState()==1) && (_easyCreation==true) && GetNumberOfPointsManualContour()==2) { ok=true; - - SetCompleteCreation( true ); - SetKeyBoardMoving( false ); - GetManualContourModel()->SetCloseContour(false); - - SetEditable( false ); - SetPosibleToMove( false ); - SetState(0); + endContourCreation(); } // Continue to Insert Control Points with ClickLeft (After being empty the contour) @@ -181,6 +176,21 @@ namespace bbtk GetManualViewBaseContour()->Refresh(); } } + + //========================================================================= + + void manualConnectorContourController::endContourCreation() + { + SetCompleteCreation( true ); + SetKeyBoardMoving( false ); + GetManualContourModel()->SetCloseContour(false); + + SetEditable( false ); + SetPosibleToMove( false ); + SetState(0); + } + + //========================================================================= } // EO namespace bbtk diff --git a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/manualConnectorContourController.h b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/manualConnectorContourController.h index a987842..f7919a4 100644 --- a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/manualConnectorContourController.h +++ b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/manualConnectorContourController.h @@ -70,6 +70,7 @@ namespace bbtk virtual void MouseClickRight(int x, int y); virtual void MouseClickLeft(int x, int y); virtual void MouseMove(int x, int y); + void endContourCreation(); private: diff --git a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.cxx b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.cxx index 9d24f21..2d9f0c1 100644 --- a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.cxx +++ b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.cxx @@ -66,6 +66,7 @@ namespace bbtk _pts->SetPoint(2, xFin, yFin, zFin ); _pts->SetPoint(3, xFin, yInic, zFin ); + updatePorts(); _borderPolyMapper->Modified(); _fillPolyMapper->Modified(); @@ -230,6 +231,14 @@ namespace bbtk //========================================================================= + void vtkGBlackBoxView::updatePorts() + { + GBlackBoxModel* bmod =(GBlackBoxModel*)_model; + bmod->updatePorts(); + } + + //========================================================================= + } // EO namespace bbtk // EOF diff --git a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.h b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.h index 5eee4e1..4391d61 100644 --- a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.h +++ b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.h @@ -100,6 +100,7 @@ namespace bbtk virtual void createVtkObjects(); virtual void update(int idController,int command); virtual void updateColors(); + void updatePorts(); }; diff --git a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGPortView.cxx b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGPortView.cxx index a56cd3b..321a858 100644 --- a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGPortView.cxx +++ b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGPortView.cxx @@ -70,6 +70,7 @@ namespace bbtk _fillPolyMapper->Modified(); + //----------- setRefreshWaiting(); } diff --git a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx index 069b66d..06b7ed0 100644 --- a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx +++ b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx @@ -370,10 +370,10 @@ namespace bbtk /*****************************************************/ void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) { - wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Save actual diagram"),wxEmptyString,"NewDiagram","*.bbd",wxSAVE|wxOVERWRITE_PROMPT); - if (openFileDialog->ShowModal() == wxID_OK) + wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save actual diagram"),wxEmptyString,"NewDiagram","*.bbd",wxSAVE|wxOVERWRITE_PROMPT); + if (saveFileDialog->ShowModal() == wxID_OK) { - wxString fileName = openFileDialog->GetPath(); + wxString fileName = saveFileDialog->GetPath(); ofstream file; file.open(fileName.c_str()); @@ -388,13 +388,12 @@ namespace bbtk content += "\n"; content += "# ----------------------------------\n"; content += "\n"; - - _tabsMgr->saveActualDiagram(content); + content += "APP_START\n"; + _tabsMgr->saveActualDiagram(content); + content += "APP_END\n"; file << content; file.close(); - wxMessageDialog *dial = new wxMessageDialog(NULL, wxT(" Diagram successfully saved!! "), wxT("Saved!!"), wxOK); - dial->ShowModal(); } @@ -423,7 +422,21 @@ namespace bbtk void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) { - cout<<"RaC wxGUIEditorGraphicBBS::OnOpenDiagram "<ShowModal() == wxID_OK) + { + wxString fileName = openFileDialog->GetPath(); + + ifstream inputStream; + inputStream.open(fileName.c_str()); + + _tabsMgr->addNewTab(); + _tabsMgr->loadDiagram(inputStream); + + inputStream.close(); + + + } } //========================================================================= diff --git a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxGEditorTabPanel.cxx b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxGEditorTabPanel.cxx index a82b584..0fba895 100644 --- a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxGEditorTabPanel.cxx +++ b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxGEditorTabPanel.cxx @@ -161,6 +161,13 @@ namespace bbtk //========================================================================= + void wxGEditorTabPanel::loadDiagram(ifstream &inputStream) + { + _sceneManager->loadDiagram(inputStream); + } + + //========================================================================= + } // EO namespace bbtk // EOF diff --git a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxGEditorTabPanel.h b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxGEditorTabPanel.h index 8ac5648..ea7c426 100644 --- a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxGEditorTabPanel.h +++ b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxGEditorTabPanel.h @@ -87,6 +87,7 @@ namespace bbtk void deleteAllBoxes(); void centerView(); void saveDiagram(std::string &content); + void loadDiagram(ifstream &inputStream); //========================================================================= diff --git a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.cxx b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.cxx index b626f4b..7998bc4 100644 --- a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.cxx +++ b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.cxx @@ -138,6 +138,13 @@ namespace bbtk //========================================================================= + void wxTabPanelsManager::loadDiagram(ifstream &inputStream) + { + _actual->loadDiagram(inputStream); + } + + //========================================================================= + } // EO namespace bbtk // EOF diff --git a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.h b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.h index ce207f4..42681b7 100644 --- a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.h +++ b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.h @@ -80,6 +80,7 @@ namespace bbtk void deleteAllBoxesActualDiagram(); void centerViewActualDiagram(); void saveActualDiagram(std::string &content); + void loadDiagram(ifstream &inputStream); private: