diff --git a/Post/PView.cpp b/Post/PView.cpp index 81d338f255fd50ed253d4787fc272992bbb0fe20..eed87596aa56e526557465db9512b9c002cca208 100644 --- a/Post/PView.cpp +++ b/Post/PView.cpp @@ -96,7 +96,7 @@ PView::PView(const std::string &xname, const std::string &yname, _options->axesLabel[0] = xname; } -PView::PView(std::string name, std::string type, +PView::PView(const std::string &name, const std::string &type, GModel *model, std::map<int, std::vector<double> > &data, double time, int numComp) { @@ -276,7 +276,7 @@ void PView::combine(bool time, int how, bool remove) delete *it; } -PView *PView::getViewByName(std::string name, int timeStep, int partition) +PView *PView::getViewByName(const std::string &name, int timeStep, int partition) { // search views from most recently to least recently added for(int i = list.size() - 1; i >= 0; i--){ @@ -288,6 +288,13 @@ PView *PView::getViewByName(std::string name, int timeStep, int partition) return 0; } +int PView::getViewIndexByName(const std::string &name, int timeStep, int partition) +{ + PView *view = getViewByName(name, timeStep, partition); + if(view) return view->getIndex(); + return -1; +} + PView *PView::getViewByNum(int num, int timeStep, int partition) { for(unsigned int i = 0; i < list.size(); i++){ diff --git a/Post/PView.h b/Post/PView.h index 9b534733dd5a416789c392022dbe79ff36ed5e92..0c1990bf8ec583282c2f94c2978c6a6f3f494dfb 100644 --- a/Post/PView.h +++ b/Post/PView.h @@ -51,7 +51,7 @@ class PView{ PView(const std::string &xname, const std::string &yname, std::vector<double> &x, std::vector<double> &y); // construct a new mesh-based view from a bunch of data - PView(std::string name, std::string type, GModel *model, + PView(const std::string &name, const std::string &type, GModel *model, std::map<int, std::vector<double> > &data, double time=0., int numComp = -1); // add a new time step to a given mesh-based view @@ -99,18 +99,20 @@ class PView{ // find view by name or by number (if timeStep >= 0, return view // only if it does *not* contain that timestep; if partition >= 0, // return view only if it does *not* contain that partition) - static PView *getViewByName(std::string name, int timeStep=-1, + static PView *getViewByName(const std::string &name, int timeStep=-1, int partition=-1); + static int getViewIndexByName(const std::string &name, int timeStep=-1, + int partition=-1); static PView *getViewByNum(int num, int timeStep=-1, int partition=-1); // IO read routines (these are global: they can create multiple // views) - static bool readPOS(std::string fileName, int fileIndex=-1); - static bool readMSH(std::string fileName, int fileIndex=-1); - static bool readMED(std::string fileName, int fileIndex=-1); + static bool readPOS(const std::string &fileName, int fileIndex=-1); + static bool readMSH(const std::string &fileName, int fileIndex=-1); + static bool readMED(const std::string &fileName, int fileIndex=-1); // IO write routine - bool write(std::string fileName, int format, bool append=false); + bool write(const std::string &fileName, int format, bool append=false); // vertex arrays to draw the elements efficiently VertexArray *va_points, *va_lines, *va_triangles, *va_vectors, *va_ellipses; diff --git a/Post/PViewData.h b/Post/PViewData.h index 997306daa2d93577e95c7669c77c8f33f5d70bb2..4c530490602e3b6f8063939ba919470be83bd8f2 100644 --- a/Post/PViewData.h +++ b/Post/PViewData.h @@ -59,11 +59,11 @@ class PViewData { // get/set name virtual std::string getName(){ return _name; } - virtual void setName(std::string val){ _name = val; } + virtual void setName(const std::string &val){ _name = val; } // get/set (the main) filename containing the data virtual std::string getFileName(int step=-1){ return _fileName; } - virtual void setFileName(std::string val){ _fileName = val; } + virtual void setFileName(const std::string &val){ _fileName = val; } // get/set index of view data in file virtual int getFileIndex(){ return _fileIndex; } @@ -252,12 +252,12 @@ class PViewData { int step=-1, double *size=0); // I/O routines - virtual bool writeSTL(std::string fileName); - virtual bool writeTXT(std::string fileName); - virtual bool writePOS(std::string fileName, bool binary=false, bool parsed=true, + virtual bool writeSTL(const std::string &fileName); + virtual bool writeTXT(const std::string &fileName); + virtual bool writePOS(const std::string &fileName, bool binary=false, bool parsed=true, bool append=false); - virtual bool writeMSH(std::string fileName, bool binary=false, bool savemesh=true); - virtual bool writeMED(std::string fileName); + virtual bool writeMSH(const std::string &fileName, bool binary=false, bool savemesh=true); + virtual bool writeMED(const std::string &fileName); virtual bool toVector(std::vector<std::vector<double> > &vec); virtual bool fromVector(const std::vector<std::vector<double> > &vec); }; diff --git a/Post/PViewDataGModel.h b/Post/PViewDataGModel.h index c0a8391c0d4dcc3c95468f781a9ffd1b837fd556..17fef229f85ea3364214fe1170ca1f0fd2be6745 100644 --- a/Post/PViewDataGModel.h +++ b/Post/PViewDataGModel.h @@ -46,7 +46,7 @@ class stepData{ // a set of all "partitions" encountered in the data std::set<int> _partitions; public: - stepData(GModel *model, int numComp, std::string fileName="", int fileIndex=-1, + stepData(GModel *model, int numComp, const std::string &fileName="", int fileIndex=-1, double time=0., double min=VAL_INF, double max=-VAL_INF) : _model(model), _fileName(fileName), _fileIndex(fileIndex), _time(time), _min(min), _max(max), _numComp(numComp), _data(0) @@ -93,7 +93,7 @@ class stepData{ return _mult[index]; } std::string getFileName(){ return _fileName; } - void setFileName(std::string name){ _fileName = name; } + void setFileName(const std::string &name){ _fileName = name; } int getFileIndex(){ return _fileIndex; } void setFileIndex(int index){ _fileIndex = index; } double getTime(){ return _time; } @@ -235,12 +235,12 @@ class PViewDataGModel : public PViewData { int step, double time, int partition, int numComp); // I/O routines - bool readMSH(std::string fileName, int fileIndex, FILE *fp, bool binary, + bool readMSH(const std::string &fileName, int fileIndex, FILE *fp, bool binary, bool swap, int step, double time, int partition, int numComp, int numNodes, const std::string &interpolationScheme); - bool writeMSH(std::string fileName, bool binary=false, bool savemesh=true); - bool readMED(std::string fileName, int fileIndex); - bool writeMED(std::string fileName); + bool writeMSH(const std::string &fileName, bool binary=false, bool savemesh=true); + bool readMED(const std::string &fileName, int fileIndex); + bool writeMED(const std::string &fileName); }; #endif diff --git a/Post/PViewDataGModelIO.cpp b/Post/PViewDataGModelIO.cpp index 0415ff7442484d35a2fb3bb17f28f629e7470bea..ee96335450ee6499b6186ab5b78d06634df5dd14 100644 --- a/Post/PViewDataGModelIO.cpp +++ b/Post/PViewDataGModelIO.cpp @@ -45,7 +45,7 @@ bool PViewDataGModel::addData(GModel *model, std::map<int, std::vector<double> > return true; } -bool PViewDataGModel::readMSH(std::string fileName, int fileIndex, FILE *fp, +bool PViewDataGModel::readMSH(const std::string &fileName, int fileIndex, FILE *fp, bool binary, bool swap, int step, double time, int partition, int numComp, int numEnt, const std::string &interpolationScheme) @@ -127,7 +127,7 @@ bool PViewDataGModel::readMSH(std::string fileName, int fileIndex, FILE *fp, return true; } -bool PViewDataGModel::writeMSH(std::string fileName, bool binary, bool savemesh) +bool PViewDataGModel::writeMSH(const std::string &fileName, bool binary, bool savemesh) { if(_steps.empty()) return true; @@ -301,7 +301,7 @@ extern "C" { extern int med2mshElementType(med_geometrie_element med); extern int med2mshNodeIndex(med_geometrie_element med, int k); -bool PViewDataGModel::readMED(std::string fileName, int fileIndex) +bool PViewDataGModel::readMED(const std::string &fileName, int fileIndex) { med_idt fid = MEDouvrir((char*)fileName.c_str(), MED_LECTURE); if(fid < 0){ @@ -610,7 +610,7 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex) return true; } -bool PViewDataGModel::writeMED(std::string fileName) +bool PViewDataGModel::writeMED(const std::string &fileName) { if(_steps.empty()) return true; @@ -731,14 +731,14 @@ bool PViewDataGModel::writeMED(std::string fileName) #else -bool PViewDataGModel::readMED(std::string fileName, int fileIndex) +bool PViewDataGModel::readMED(const std::string &fileName, int fileIndex) { Msg::Error("Gmsh must be compiled with MED support to read '%s'", fileName.c_str()); return false; } -bool PViewDataGModel::writeMED(std::string fileName) +bool PViewDataGModel::writeMED(const std::string &fileName) { Msg::Error("Gmsh must be compiled with MED support to write '%s'", fileName.c_str()); diff --git a/Post/PViewDataIO.cpp b/Post/PViewDataIO.cpp index 33d638ef3e04fd2746db7c0bac88f60d63c27601..58f5317b72f3dc0ec4edd85322de667b5dc4fba6 100644 --- a/Post/PViewDataIO.cpp +++ b/Post/PViewDataIO.cpp @@ -11,7 +11,7 @@ #include "PViewData.h" #include "adaptiveData.h" -bool PViewData::writeSTL(std::string fileName) +bool PViewData::writeSTL(const std::string &fileName) { FILE *fp = fopen(fileName.c_str(), "w"); if(!fp){ @@ -70,7 +70,7 @@ bool PViewData::writeSTL(std::string fileName) return true; } -bool PViewData::writeTXT(std::string fileName) +bool PViewData::writeTXT(const std::string &fileName) { FILE *fp = fopen(fileName.c_str(), "w"); if(!fp){ @@ -102,7 +102,8 @@ bool PViewData::writeTXT(std::string fileName) return true; } -bool PViewData::writePOS(std::string fileName, bool binary, bool parsed, bool append) +bool PViewData::writePOS(const std::string &fileName, bool binary, bool parsed, + bool append) { if(_adaptive){ Msg::Warning("Writing adapted dataset (will only export current time step)"); @@ -175,13 +176,13 @@ bool PViewData::writePOS(std::string fileName, bool binary, bool parsed, bool ap return true; } -bool PViewData::writeMSH(std::string fileName, bool binary, bool savemesh) +bool PViewData::writeMSH(const std::string &fileName, bool binary, bool savemesh) { Msg::Error("MSH export not implemented for this view type"); return false; } -bool PViewData::writeMED(std::string fileName) +bool PViewData::writeMED(const std::string &fileName) { Msg::Error("MED export onnly available for mesh-based post-processing views"); return false; diff --git a/Post/PViewDataList.h b/Post/PViewDataList.h index 87f2db440a16592f1b8be4b6eb9baf9d729087ef..774068554c2e96307fd22bdb3341559f16351571 100644 --- a/Post/PViewDataList.h +++ b/Post/PViewDataList.h @@ -123,9 +123,9 @@ class PViewDataList : public PViewData { // I/O routines bool readPOS(FILE *fp, double version, bool binary); - bool writePOS(std::string fileName, bool binary=false, bool parsed=true, + bool writePOS(const std::string &fileName, bool binary=false, bool parsed=true, bool append=false); - virtual bool writeMSH(std::string fileName, bool binary=false, bool savemesh=true); + virtual bool writeMSH(const std::string &fileName, bool binary=false, bool savemesh=true); }; #endif diff --git a/Post/PViewDataListIO.cpp b/Post/PViewDataListIO.cpp index f9c205b494d27d0299719663b4538fd7acd3e660..9716c4e0f9fa5160b93c78cdfe2bfca149c8d720 100644 --- a/Post/PViewDataListIO.cpp +++ b/Post/PViewDataListIO.cpp @@ -341,7 +341,8 @@ static void writeTextPOS(FILE *fp, int nbc, int nb, std::vector<double> &TD, } } -bool PViewDataList::writePOS(std::string fileName, bool binary, bool parsed, bool append) +bool PViewDataList::writePOS(const std::string &fileName, bool binary, bool parsed, + bool append) { if(_adaptive){ Msg::Warning("Writing adapted dataset (will only export current time step)"); @@ -434,7 +435,7 @@ bool PViewDataList::writePOS(std::string fileName, bool binary, bool parsed, boo return true; } -static void createVertices(std::vector<double> &list, int nbelm, int nbnod, +static void createVertices(std::vector<double> &list, int nbelm, int nbnod, std::vector<MVertex*> &nodes) { if(!nbelm) return; @@ -445,10 +446,10 @@ static void createVertices(std::vector<double> &list, int nbelm, int nbnod, double *z = &list[i + 2 * nbnod]; for(int j = 0; j < nbnod; j++) nodes.push_back(new MVertex(x[j], y[j], z[j])); - } + } } -static void createElements(std::vector<double> &list, int nbelm, int nbnod, +static void createElements(std::vector<double> &list, int nbelm, int nbnod, MVertexPositionSet &pos, std::vector<MElement*> &elements, double eps, int type) { @@ -473,7 +474,7 @@ static void createElements(std::vector<double> &list, int nbelm, int nbnod, break; case TYPE_QUA : switch(nbnod){ - case 4: t = MSH_QUA_4; break; + case 4: t = MSH_QUA_4; break; case 8: t = MSH_QUA_8; break; case 9: t = MSH_QUA_9; break; } @@ -524,7 +525,7 @@ static void createElements(std::vector<double> &list, int nbelm, int nbnod, } } -bool PViewDataList::writeMSH(std::string fileName, bool binary, bool savemesh) +bool PViewDataList::writeMSH(const std::string &fileName, bool binary, bool savemesh) { if(_adaptive){ Msg::Warning("Writing adapted dataset (will only export current time step)"); @@ -562,7 +563,7 @@ bool PViewDataList::writeMSH(std::string fileName, bool binary, bool savemesh) int num = 0; for(unsigned int i = 0; i < vertices.size(); i++) - if(vertices[i]->getIndex() < 0) + if(vertices[i]->getIndex() < 0) vertices[i]->setIndex(++num); fprintf(fp, "$MeshFormat\n2.2 0 8\n$EndMeshFormat\n"); diff --git a/Post/PViewIO.cpp b/Post/PViewIO.cpp index 285307b96999700f3d39f0447c8f34c6b847006d..166aa545c7b255f50b7564f9d1823eadd37fcf52 100644 --- a/Post/PViewIO.cpp +++ b/Post/PViewIO.cpp @@ -11,7 +11,7 @@ #include "StringUtils.h" #include "Context.h" -bool PView::readPOS(std::string fileName, int fileIndex) +bool PView::readPOS(const std::string &fileName, int fileIndex) { FILE *fp = fopen(fileName.c_str(), "rb"); if(!fp){ @@ -81,7 +81,7 @@ bool PView::readPOS(std::string fileName, int fileIndex) return true; } -bool PView::readMSH(std::string fileName, int fileIndex) +bool PView::readMSH(const std::string &fileName, int fileIndex) { FILE *fp = fopen(fileName.c_str(), "rb"); if(!fp){ @@ -241,7 +241,7 @@ extern "C" { #include <med.h> } -bool PView::readMED(std::string fileName, int fileIndex) +bool PView::readMED(const std::string &fileName, int fileIndex) { #if (MED_MAJOR_NUM == 3) med_idt fid = MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY); @@ -289,7 +289,7 @@ bool PView::readMED(std::string fileName, int fileIndex) #else -bool PView::readMED(std::string fileName, int fileIndex) +bool PView::readMED(const std::string &fileName, int fileIndex) { Msg::Error("Gmsh must be compiled with MED support to read '%s'", fileName.c_str()); @@ -298,7 +298,7 @@ bool PView::readMED(std::string fileName, int fileIndex) #endif -bool PView::write(std::string fileName, int format, bool append) +bool PView::write(const std::string &fileName, int format, bool append) { Msg::StatusBar(2, true, "Writing '%s'...", fileName.c_str());