-// Copyright (C) 2016 CEA/DEN, EDF R&D
+// Copyright (C) 2016-2021 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
setIntProperty(MEDPresentationContour::PROP_NB_CONTOUR, params.nbContours);
}
-std::string
-MEDPresentationContour::getContourCommand() const
+void
+MEDPresentationContour::initFieldMeshInfos()
{
- std::ostringstream oss1;
+ MEDPresentation::initFieldMeshInfos();
+ _colorByType = "POINTS";
+}
- oss1 << "min_max = " << _srcObjVar << ".PointData.GetArray('" << _fieldName << "').GetRange();\n";
- oss1 << "delta = (min_max[1]-min_max[0])/float(" << _params.nbContours << ");\n";
- oss1 << _objVar << ".Isosurfaces = [min_max[0]+0.5*delta+i*delta for i in range(" << _params.nbContours << ")];\n";
- return oss1.str();
+void
+MEDPresentationContour::setNumberContours()
+{
+ std::ostringstream oss;
+
+ oss << "min_max = " << _srcObjVar << ".PointData.GetArray('" << _fieldName << "').GetRange();";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << "delta = (min_max[1]-min_max[0])/float(" << _params.nbContours << ");";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << _objVar << ".Isosurfaces = [min_max[0]+0.5*delta+i*delta for i in range(" << _params.nbContours << ")];";
+ pushAndExecPyLine(oss.str()); oss.str("");
}
void
MEDPyLockWrapper lock;
- std::ostringstream oss_o, oss;
- std::string view(getRenderViewVar());
-
- oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');";
- pushAndExecPyLine(oss.str()); oss.str("");
+ createSource();
+ setTimestamp();
// Populate internal array of available components:
fillAvailableFieldComponents();
STDLOG(msg);
throw KERNEL::createSalomeException(msg);
}
-
- pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX
-
- if(_fieldType == "CELLS")
+ if (_params.nbContours < 1)
{
- // In case of a CELLS field need to convert to POINT field, and update source
- STDLOG("Applying CellDatatoPointData filter");
- std::ostringstream oss2, oss4;
- // Apply Cell data to point data:
- oss2 << "__obj" << GeneratePythonId();
- oss << oss2.str() << " = pvs.CellDatatoPointData(Input=" << _srcObjVar << ");";
- pushAndExecPyLine(oss.str()); oss.str("");
- // Now the source becomes the result of the CellDatatoPointData:
- _srcObjVar = oss2.str();
+ const char * mes = "Invalid number of contours!";
+ STDLOG(mes);
+ throw KERNEL::createSalomeException(mes);
}
+
+ setOrCreateRenderView(); // instantiate __viewXXX, needs to be after the exception above otherwise previous elements in the view will be hidden.
+
+ // Contour needs point data:
+ applyCellToPointIfNeeded();
+
+ std::ostringstream oss;
oss << _objVar << " = pvs.Contour(Input=" << _srcObjVar << ");";
pushAndExecPyLine(oss.str()); oss.str("");
+
+ showObject();
+
oss << _objVar << ".ContourBy = ['POINTS', '" << _fieldName << "'];";
pushAndExecPyLine(oss.str()); oss.str("");
+ // Colorize contour
+ oss << _objVar << ".ComputeScalars = 1;";
+ pushAndExecPyLine(oss.str()); oss.str("");
+
// Set number of contours
- pushAndExecPyLine(getContourCommand());
+ setNumberContours();
- oss << _dispVar << " = pvs.Show(" << _objVar << ", " << view << ");";
- pushAndExecPyLine(oss.str()); oss.str("");
- oss << "pvs.ColorBy(" << _dispVar << ", ('POINTS', '" << _fieldName << "'));"; // necessarily POINTS
- pushAndExecPyLine(oss.str()); oss.str("");
- oss << _dispVar << ".SetScalarBarVisibility(" << view << ", True);";
- pushAndExecPyLine(oss.str()); oss.str("");
- oss << getRescaleCommand();
- pushAndExecPyLine(oss.str()); oss.str("");
- oss << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');";
- pushAndExecPyLine(oss.str()); oss.str("");
- pushAndExecPyLine(getColorMapCommand()); oss.str("");
- pushAndExecPyLine(getResetCameraCommand());
- pushAndExecPyLine("pvs.Render();");
+ colorBy(); // see initFieldInfo() - necessarily POINTS because of the conversion above
+ showScalarBar();
+ selectColorMap();
+ rescaleTransferFunction();
+ resetCameraAndRender();
}
void
updateColorMap<MEDPresentationContour, MEDCALC::ContourParameters>(params.colorMap);
if (params.nbContours != _params.nbContours)
- updateNbContours(params.nbContours);
+ {
+ if (params.nbContours < 1)
+ {
+ const char * mes = "Invalid number of contours!";
+ STDLOG(mes);
+ throw KERNEL::createSalomeException(mes);
+ }
+ updateNbContours(params.nbContours);
+ }
}
void
// Update the pipeline:
{
MEDPyLockWrapper lock;
- std::string cmd = getContourCommand();
- pushAndExecPyLine(cmd);
+ setNumberContours();
pushAndExecPyLine("pvs.Render();");
}
}