Commit 1d43fdaf authored by Michel Rasquin's avatar Michel Rasquin

Reads separate views from a requested partition stored under msh2 format for the ParaView plugin

parent 8eb1dc6c
Pipeline #2986 passed with stage
in 14 minutes and 55 seconds
......@@ -296,7 +296,8 @@ static int defineSolver(const std::string &name)
#endif
int MergeFile(const std::string &fileName, bool warnIfMissing,
bool setBoundingBox, bool importPhysicalsInOnelab)
bool setBoundingBox, bool importPhysicalsInOnelab,
int partitionToRead)
{
// added 'b' for pure Windows programs, since some of these files
// contain binary data
......@@ -520,7 +521,7 @@ int MergeFile(const std::string &fileName, bool warnIfMissing,
}
mesh = true;
#if defined(HAVE_POST)
if(status > 1) status = PView::readMSH(fileName);
if(status > 1) status = PView::readMSH(fileName, -1, partitionToRead);
#endif
}
#if defined(HAVE_POST)
......
......@@ -14,7 +14,8 @@ void ParseString(const std::string &str, bool inCurrentModelDir = false);
void OpenProject(const std::string &filename);
void OpenProjectMacFinder(const char *fileName);
int MergeFile(const std::string &fileName, bool warnIfMissing = false,
bool setBoundingBox = true, bool importPhysicalsInOnelab = true);
bool setBoundingBox = true, bool importPhysicalsInOnelab = true,
int partitionToRead = -1);
int MergePostProcessingFile(const std::string &fileName, int showViews = 2,
bool showLastStep = false,
bool warnIfMissing = false);
......
......@@ -128,7 +128,8 @@ public:
// IO read routines (these are global: they can create multiple
// views)
static bool readPOS(const std::string &fileName, int fileIndex = -1);
static bool readMSH(const std::string &fileName, int fileIndex = -1);
static bool readMSH(const std::string &fileName, int fileIndex = -1,
int partitionToRead = -1);
static bool readMED(const std::string &fileName, int fileIndex = -1);
static bool writeX3D(const std::string &fileName);
// IO write routine
......
......@@ -81,7 +81,7 @@ bool PView::readPOS(const std::string &fileName, int fileIndex)
return true;
}
bool PView::readMSH(const std::string &fileName, int fileIndex)
bool PView::readMSH(const std::string &fileName, int fileIndex, int partitionToRead)
{
FILE *fp = Fopen(fileName.c_str(), "rb");
if(!fp) {
......@@ -230,6 +230,7 @@ bool PView::readMSH(const std::string &fileName, int fileIndex)
}
// integer tags
int timeStep = 0, numComp = 0, numEnt = 0, partition = 0;
long int blocksize = 0;
if(!fgets(str, sizeof(str), fp)) {
fclose(fp);
return false;
......@@ -267,29 +268,44 @@ bool PView::readMSH(const std::string &fileName, int fileIndex)
return false;
}
}
}
if(numEnt > 0) {
// either get existing viewData, or create new one
PView *p = getViewByName(viewName, timeStep, partition);
PViewDataGModel *d = 0;
if(p) d = dynamic_cast<PViewDataGModel *>(p->getData());
bool create = d ? false : true;
if(create) d = new PViewDataGModel(type);
if(!d->readMSH(viewName, fileName, fileIndex, fp, binary, swap,
timeStep, time, partition, numComp, numEnt,
interpolationScheme)) {
Msg::Error("Could not read data in msh file");
if(create) delete d;
fclose(fp);
return false;
else if(i == 4) {
if(sscanf(str, "%ld", &blocksize) != 1) {
fclose(fp);
return false;
}
}
else {
d->setName(viewName);
d->setFileName(fileName);
d->setFileIndex(index);
if(create) new PView(d);
}
if(partitionToRead == -1 || partitionToRead == partition) {
// if default (no particular partition requested from MergeFile -> -1) or
// if current partition corresponds to the requested partition, read the data
if(numEnt > 0) {
// either get existing viewData, or create new one
PView *p = getViewByName(viewName, timeStep, partition);
PViewDataGModel *d = 0;
if(p) d = dynamic_cast<PViewDataGModel *>(p->getData());
bool create = d ? false : true;
if(create) d = new PViewDataGModel(type);
if(!d->readMSH(viewName, fileName, fileIndex, fp, binary, swap,
timeStep, time, partition, numComp, numEnt,
interpolationScheme)) {
Msg::Error("Could not read data in msh file");
if(create) delete d;
fclose(fp);
return false;
}
else {
d->setName(viewName);
d->setFileName(fileName);
d->setFileIndex(index);
if(create) new PView(d);
}
}
}
else if(blocksize > 0 && partitionToRead != partition) {
// if current partition does not correspond to the requested partition and
// if its blocksise has been read (5th integer in the header), jump over it
fseek(fp, blocksize, SEEK_CUR);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment