From: corredor <> Date: Thu, 6 May 2010 15:14:46 +0000 (+0000) Subject: It saves the diagram and it was added the icon to open a file ..... Now it is necessa... X-Git-Tag: v1_0_0~78 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=eb765b17b9d4f6952a565569f89e3bc9204f9c6e;p=bbtkGEditor.git It saves the diagram and it was added the icon to open a file ..... Now it is necessary to implement the Open Diagram functionality --- diff --git a/data/icons/wxart_open.xpm b/data/icons/wxart_open.xpm new file mode 100644 index 0000000..e2bd507 --- /dev/null +++ b/data/icons/wxart_open.xpm @@ -0,0 +1,57 @@ +/* XPM */ +static const char *open_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 15 36 1", +"6 c #9BACC2", +"< c #9AEA53", +"9 c #94A5BD", +"5 c #839CB5", +"; c #4D7492", +". c #376485", +"$ c #7F99B4", +"r c #D1D9E5", +"7 c #EAEDF3", +"@ c #CAD2DC", +"% c #718BA7", +"t c #BECAD9", +"& c #65839D", +"0 c #DCE2EA", +"4 c #F5F6F7", +"w c #597B9A", +"O c #8DA0B9", +" c None", +"+ c #467291", +"u c #305F81", +"= c #B4C4D3", +"# c #CAE2AA", +"1 c #FAFCFE", +"3 c #A8B6CA", +"q c #E4E9ED", +"8 c #EEF1F3", +"X c #215579", +"2 c #7F97B0", +": c #B3BFD1", +"y c #7A90AC", +", c #C2CBDB", +"- c #ADD668", +"* c #B6D791", +"e c #CAD6E1", +"o c #DFF0D0", +"> c #BBC4D6", +/* pixels */ +" ", +" .... ", +"XXXXX .oo. ", +"XOOOO+@.#o. ", +"XOOOO$%&.*oXXX ", +"XOOOOOOO.*oX=X ", +"XOXXXX...-oXXXX;", +"XOX:>,.<<<<,.<<>.>.X0q7; ", +"Xw2O963:>>er0t; ", +"X&y2O963:>,er; ", +"uXXXXXXXXXXXX; ", +" " +}; diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.cxx b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.cxx index c7778f3..7c7bebb 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.cxx +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.cxx @@ -38,18 +38,19 @@ Version: $Revision$ namespace bbtk { - - //========================================================================= + GBlackBoxModel::GBlackBoxModel() { _isExecutable = false; } //========================================================================= + GBlackBoxModel::~GBlackBoxModel() { } + //========================================================================= void GBlackBoxModel::setInicPoint(double& x, double& y, double& z) @@ -174,6 +175,52 @@ namespace bbtk //========================================================================= + void GBlackBoxModel::save(std::string &content) + { + content+="BOX\n"; + // Box info + content+=_bbtkPackage; + content+=":"; + content+=_bbtkType; + content+=":"; + content+=_bbtkName; + content+="\n"; + + //Box Position + char buffer [50]; + sprintf (buffer, "%f", _xInic); + content+=buffer; + content+=":"; + sprintf (buffer, "%f", _yInic); + content+=buffer; + content+=":"; + sprintf (buffer, "%f", _zInic); + content+=buffer; + content+="\n"; + + sprintf (buffer, "%f", _xFin); + content+=buffer; + content+=":"; + sprintf (buffer, "%f", _yFin); + content+=buffer; + content+=":"; + sprintf (buffer, "%f", _zFin); + content+=buffer; + content+="\n"; + + //Ports with a value + for(int i = 0; i<_inputs.size();i++) + { + if(_inputs[i]->isValueSet()) + { + _inputs[i]->save(content); + } + } + + } + + //========================================================================= + } // EO namespace bbtk diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.h b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.h index c766dba..de8b708 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.h +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.h @@ -81,6 +81,7 @@ namespace bbtk void setBBTKPackage(std::string obpackage); virtual std::string getStatusText(); + virtual void save(std::string &content); bool isExecutable(); void setExecutable(bool executable); diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GConnectorModel.cxx b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GConnectorModel.cxx index bd4ecf3..28df0dd 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GConnectorModel.cxx +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GConnectorModel.cxx @@ -157,6 +157,25 @@ namespace bbtk return false; } + //========================================================================= + + void GConnectorModel::save(std::string &content) + { + content+="CONNECTION\n"; + + // Connection info + content+=_startPort->getParentBox()->getBBTKName(); + content+="."; + content+=_startPort->getBBTKName(); + content+=":"; + content+=_endPort->getParentBox()->getBBTKName(); + content+="."; + content+=_endPort->getBBTKName(); + content+="\n"; + } + + //========================================================================= + } // EO namespace bbtk // EOF diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GConnectorModel.h b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GConnectorModel.h index 9e7d7f7..d590b84 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GConnectorModel.h +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GConnectorModel.h @@ -78,6 +78,7 @@ namespace bbtk void updateStartEndPoints(); void disconnectConnection(); virtual bool isPointInside(double x,double y, double z); + virtual void save(std::string &content); private: diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GObjectModel.cxx b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GObjectModel.cxx index e4710a2..1255128 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GObjectModel.cxx +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GObjectModel.cxx @@ -188,6 +188,14 @@ namespace bbtk _objectId=id; } + //========================================================================= + + void GObjectModel::save(std::string &content) + { + //virtual + } + + //========================================================================= } // EO namespace bbtk diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GObjectModel.h b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GObjectModel.h index a630038..d13b459 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GObjectModel.h +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GObjectModel.h @@ -93,6 +93,7 @@ namespace bbtk void setObjectId(int id); virtual std::string getStatusText(); + virtual void save(std::string &content); private: diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.cxx b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.cxx index 326cbe2..200a5f4 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.cxx +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.cxx @@ -86,7 +86,7 @@ namespace bbtk } //Attribute '_posInBox' starts with value 0 and it represents the position of the port in the box from left to right - posX = xInic + PORT_WIDTH + _posInBox*2*PORT_WIDTH; + posX = xInic + (PORT_WIDTH/2) + _posInBox*1.6*PORT_WIDTH; setInicPoint(posX,posY,posZ); @@ -177,6 +177,19 @@ namespace bbtk //========================================================================= + void GPortModel::save(std::string &content) + { + content+="PORT\n"; + + // Port value info + content+=_bbtkName; + content+=":"; + content+=_value; + content+="\n"; + } + + //========================================================================= + } // EO namespace bbtk // EOF diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.h b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.h index 3d6c497..6b5d772 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.h +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.h @@ -79,6 +79,7 @@ namespace bbtk bool isValueSet(); void setValue(std::string value); std::string getValue(); + virtual void save(std::string &content); private: diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GlobalConstants.h b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GlobalConstants.h index f9319af..7949d5b 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GlobalConstants.h +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GlobalConstants.h @@ -132,6 +132,12 @@ namespace bbtk const double BOXTEXT_SELECTED_B=0.05; // Id's + const int ID_NEW = 1000; + const int ID_SAVE = 1001; + const int ID_OPEN = 1002; + const int ID_RUN = 1003; + const int ID_DELETEALL = 1004; + const int ID_CENTERVIEW = 1005; } // namespace bbtk #endif diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx index 41f2fd5..2227c90 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx @@ -967,6 +967,79 @@ namespace bbtk //========================================================================= + void wxVtkSceneManager::saveDiagram(std::string &content) + { + //Print boxes + char buffer [50]; + std::vector boxes = getBoxes(); + int bsize = boxes.size(); + content+="BOXES "; + sprintf (buffer, "%d", bsize); + content+=buffer; + content+="\n"; + + for(int i = 0;igetModel()->save(content); + } + + content+="\n"; + + //Print connections + std::vector connections = getConnections(); + int csize = connections.size(); + content+="CONNECTIONS "; + sprintf (buffer, "%d", csize); + content+=buffer; + content+="\n"; + + for(int i = 0;igetModel()->save(content); + } + + } + + //========================================================================= + + std::vector wxVtkSceneManager::getBoxes() + { + std::vector vect; + std::map::iterator it; + for(it = _controllers.begin(); it != _controllers.end(); ++it) + { + GObjectController *cont = it->second; + if(cont->getGObjectType()==GBLACKBOX) + { + vect.push_back(cont->getId()); + } + } + return vect; + } + + //========================================================================= + + std::vector wxVtkSceneManager::getConnections() + { + std::vector vect; + std::map::iterator it; + for(it = _controllers.begin(); it != _controllers.end(); ++it) + { + GObjectController *cont = it->second; + if(cont->getGObjectType()==GCONNECTOR) + { + vect.push_back(cont->getId()); + } + } + return vect; + } + + //========================================================================= + } // EO namespace bbtk // EOF diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.h b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.h index d789c7a..1cee565 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.h +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.h @@ -117,10 +117,12 @@ namespace bbtk std::string getDiagramScript(); void deleteObject(int id); void deleteAllBoxes(); - + void saveDiagram(std::string &content); void centerView(); void refreshScene(); + std::vector getBoxes(); + std::vector getConnections(); private: diff --git a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx index abda879..069b66d 100644 --- a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx +++ b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx @@ -86,6 +86,7 @@ namespace bbtk void wxGUIEditorGraphicBBS::initToolbar() { wxBitmap bmp_new(new_xpm); + wxBitmap bmp_open(open_xpm); wxBitmap bmp_save(save_xpm); wxBitmap bmp_run(run_xpm); wxBitmap bmp_delete(delete_xpm); @@ -94,11 +95,12 @@ namespace bbtk wxToolBar *_toolbar = new wxToolBar(this, wxID_ANY); //Adds a tool btn to the toolbar - _toolbar->AddTool(1000,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab")); - _toolbar->AddTool(1001,_T("Save diagram"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves actual diagram"), _T("Saves actual diagram")); - _toolbar->AddTool(1002,_T("Execute"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram")); - _toolbar->AddTool(1003,_T("Delete all"),bmp_delete, wxNullBitmap, wxITEM_NORMAL,_T("Delete all boxes"), _T("Delete all boxes")); - _toolbar->AddTool(1004,_T("Center view"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Center view"), _T("Center view")); + _toolbar->AddTool(ID_NEW,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab")); + _toolbar->AddTool(ID_OPEN,_T("Open diagram"),bmp_open, wxNullBitmap, wxITEM_NORMAL,_T("Open a diagram"), _T("Open a diagram")); + _toolbar->AddTool(ID_SAVE,_T("Save diagram"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves actual diagram"), _T("Saves actual diagram")); + _toolbar->AddTool(ID_RUN,_T("Run"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram")); + _toolbar->AddTool(ID_DELETEALL,_T("Delete all"),bmp_delete, wxNullBitmap, wxITEM_NORMAL,_T("Delete all boxes"), _T("Delete all boxes")); + _toolbar->AddTool(ID_CENTERVIEW,_T("Center view"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Center view"), _T("Center view")); _toolbar->SetMargins( 2, 2 ); @@ -106,11 +108,12 @@ namespace bbtk SetToolBar(_toolbar); // connect command event handlers - Connect(1000,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab)); - Connect(1001,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); - Connect(1002,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram)); - Connect(1003,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram)); - Connect(1004,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram)); + Connect(ID_NEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab)); + Connect(ID_OPEN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram)); + Connect(ID_SAVE,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); + Connect(ID_RUN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram)); + Connect(ID_DELETEALL,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram)); + Connect(ID_CENTERVIEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram)); } //========================================================================= @@ -367,7 +370,34 @@ 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) + { + wxString fileName = openFileDialog->GetPath(); + + ofstream file; + file.open(fileName.c_str()); + + std::string content=""; + + // writing file header + content += "# ----------------------------------\n"; + content += "# - BBTKGEditor v 1.0 Diagram file\n"; + content += "# - "; + content += fileName; + content += "\n"; + content += "# ----------------------------------\n"; + content += "\n"; + + _tabsMgr->saveActualDiagram(content); + file << content; + file.close(); + wxMessageDialog *dial = new wxMessageDialog(NULL, wxT(" Diagram successfully saved!! "), wxT("Saved!!"), wxOK); + dial->ShowModal(); + + } + } //========================================================================= @@ -390,12 +420,20 @@ namespace bbtk //========================================================================= + + void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) + { + cout<<"RaC wxGUIEditorGraphicBBS::OnOpenDiagram "<saveDiagram(content); + } + + //========================================================================= } // EO namespace bbtk diff --git a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxGEditorTabPanel.h b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxGEditorTabPanel.h index 3f6e699..8ac5648 100644 --- a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxGEditorTabPanel.h +++ b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxGEditorTabPanel.h @@ -86,6 +86,7 @@ namespace bbtk void editDiagramParameters(wxVtkSceneManager* scene); void deleteAllBoxes(); void centerView(); + void saveDiagram(std::string &content); //========================================================================= diff --git a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.cxx b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.cxx index e6c91c1..b626f4b 100644 --- a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.cxx +++ b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.cxx @@ -131,6 +131,13 @@ namespace bbtk //========================================================================= + void wxTabPanelsManager::saveActualDiagram(std::string &content) + { + _actual->saveDiagram(content); + } + + //========================================================================= + } // EO namespace bbtk // EOF diff --git a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.h b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.h index 05b8b7c..ce207f4 100644 --- a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.h +++ b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.h @@ -79,6 +79,7 @@ namespace bbtk void editDiagramParameters(wxVtkSceneManager* scene); void deleteAllBoxesActualDiagram(); void centerViewActualDiagram(); + void saveActualDiagram(std::string &content); private: