# additional include directories
INCLUDE_DIRECTORIES(
${KERNEL_INCLUDE_DIRS}
+ ${MEDCOUPLING_INCLUDE_DIRS}
)
# additional preprocessor / compiler flags
# libraries to link to
SET(_link_LIBRARIES
${KERNEL_SALOMELocalTrace}
+ ${MEDCoupling_medloader}
)
# --- headers ---
HOMARD_YACS.hxx
HomardDriver.hxx
YACSDriver.hxx
+ MG_ADAPT.hxx
)
# --- sources ---
HOMARD_YACS.cxx
HomardDriver.cxx
YACSDriver.cxx
+ MG_ADAPT.cxx
)
# --- rules ---
--- /dev/null
+// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/
+// file : MG_ADAPT.cxx
+
+#include "MG_ADAPT.hxx"
+
+#include "MeshFormatReader.hxx"
+#include "MeshFormatWriter.hxx"
+#include "MEDFileMesh.hxx"
+#include "MCAuto.hxx"
+#include "MEDFileData.hxx"
+#include "MEDFileField.hxx"
+#include "MEDCouplingFieldDouble.hxx"
+
+#include <utilities.h>
+#include <iostream>
+#include <unistd.h>
+#include <TCollection_AsciiString.hxx>
+#include <cstring>
+#include <cstdlib>
+#include <boost/filesystem.hpp>
+
+static std::string removeFile(std::string fileName, int& notOk)
+{
+ std::string errStr;
+ notOk = std::remove(fileName.c_str());
+ if (notOk) errStr = ToComment(" \n error while removing file : ")
+ << fileName;
+ else errStr= ToComment("\n file : ")<< fileName << " succesfully deleted! \n ";
+
+ return errStr;
+}
+namespace
+{
+struct GET_DEFAULT // struct used to get default value from GetOptionValue()
+{
+ bool isDefault;
+ operator bool* () {
+ return &isDefault;
+ }
+};
+}
+
+//----------------------------------------------------------------------------------------
+MgAdapt::MgAdapt()
+{
+ data = new MgAdaptHypothesisData();
+ data->myInMeshName = "";
+ data->fromMedFile = defaultFromMedFile();
+ data->myFileInDir = defaultWorkingDirectory();
+ data->myMeshFileIn = "";
+ data->myFileOutDir = defaultWorkingDirectory();
+ data->myOutMeshName = "";
+ data->myMeshFileOut = "";
+ data->myMeshOutMed = defaultMeshOutMed();
+ data->myPublish = defaultPublish();
+ data->myUseLocalMap = defaultUseLocalMap();
+ data->myUseBackgroundMap = defaultUseBackgroundMap();
+ data->myFileSizeMapDir = defaultWorkingDirectory();
+ data->myMeshFileBackground = "";
+ data->myUseConstantValue = defaultUseConstantValue();
+ data->myConstantValue = 0.0;
+ data->myFieldName = "";
+ data->myUseNoTimeStep = defaultUseNoTimeStep();
+ data->myUseLastTimeStep = defaultUseLastTimeStep();
+ data->myUseChosenTimeStep = defaultUseChosenTimeStep();
+ data->myTimeStep = -2;
+ data->myRank = -2;
+ data->myWorkingDir = defaultWorkingDirectory();
+ data->myLogFile = defaultLogFile();
+ data->myVerboseLevel = defaultVerboseLevel();
+ data->myPrintLogInFile = defaultPrintLogInFile();
+ data->myKeepFiles = defaultKeepFiles();
+ data->myRemoveLogOnSuccess = defaultRemoveLogOnSuccess();
+
+ buildModel();
+ setAll();
+}
+MgAdapt::MgAdapt(MgAdaptHypothesisData* myData)
+{
+ data = new MgAdaptHypothesisData();
+ setData(myData);
+ buildModel();
+}
+
+MgAdapt::MgAdapt( const MgAdapt& copy)
+{
+
+ data = new MgAdaptHypothesisData();
+ MgAdaptHypothesisData *copyData = copy.getData();
+ copyMgAdaptHypothesisData(copyData);
+ setAll();
+
+ this->_option2value = copy._option2value;
+ this->_customOption2value = copy._customOption2value;
+ this->_defaultOptionValues = copy._defaultOptionValues;
+ this->_doubleOptions = copy._doubleOptions;
+ this->_charOptions = copy._charOptions;
+ this->_boolOptions = copy._boolOptions;
+
+}
+
+
+
+//-----------------------------------------------------------------------------------------
+MgAdapt::~MgAdapt()
+{
+
+ delete data;
+
+}
+void MgAdapt::buildModel()
+{
+
+ const char* boolOptionNames[] = { "compute_ridges", // yes
+ "" // mark of end
+ };
+ // const char* intOptionNames[] = { "max_number_of_errors_printed", // 1
+ // "max_number_of_threads", // 4
+ // "" // mark of end
+ // };
+ const char* doubleOptionNames[] = { "max_memory", // 0
+ "" // mark of end
+ };
+ const char* charOptionNames[] = { "components", // "yes"
+ "adaptation", // both
+ "" // mark of end
+ };
+
+ int i = 0;
+ while (boolOptionNames[i][0])
+ {
+ _boolOptions.insert( boolOptionNames[i] );
+ _option2value[boolOptionNames[i++]].clear();
+ }
+ // i = 0;
+ // while (intOptionNames[i][0])
+ // _option2value[intOptionNames[i++]].clear();
+
+ i = 0;
+ while (doubleOptionNames[i][0]) {
+ _doubleOptions.insert(doubleOptionNames[i]);
+ _option2value[doubleOptionNames[i++]].clear();
+ }
+ i = 0;
+ while (charOptionNames[i][0]) {
+ _charOptions.insert(charOptionNames[i]);
+ _option2value[charOptionNames[i++]].clear();
+ }
+
+ // default values to be used while MG-Adapt
+
+ _defaultOptionValues["adaptation" ] = "both";
+ _defaultOptionValues["components" ] = "outside components";
+ _defaultOptionValues["compute_ridges" ] = "yes";
+ _defaultOptionValues["max_memory" ] = ToComment(defaultMaximumMemory());
+}
+
+//=============================================================================
+TOptionValues MgAdapt::getOptionValues() const
+{
+ TOptionValues vals;
+ TOptionValues::const_iterator op_val = _option2value.begin();
+ for ( ; op_val != _option2value.end(); ++op_val )
+ vals.insert( make_pair( op_val->first, getOptionValue( op_val->first, GET_DEFAULT() )));
+
+ return vals;
+}
+
+std::vector <std::string> MgAdapt::getOptionValuesStrVec() const
+{
+ std::vector <std::string> vals;
+ TOptionValues::const_iterator op_val = _option2value.begin();
+ for ( ; op_val != _option2value.end(); ++op_val )
+ vals.push_back(op_val->first+":"+getOptionValue( op_val->first, GET_DEFAULT() ));
+
+ return vals;
+}
+
+std::vector <std::string> MgAdapt::getCustomOptionValuesStrVec() const
+{
+ std::vector <std::string> vals;
+ TOptionValues::const_iterator op_val;
+ for ( op_val = _customOption2value.begin(); op_val != _customOption2value.end(); ++op_val )
+ {
+ vals.push_back(op_val->first+":"+getOptionValue( op_val->first, GET_DEFAULT() ));
+ }
+ return vals;
+}
+const TOptionValues& MgAdapt::getCustomOptionValues() const
+{
+ return _customOption2value;
+}
+void MgAdapt::setData(MgAdaptHypothesisData* myData)
+{
+ copyMgAdaptHypothesisData(myData);
+ setAll();
+}
+MgAdaptHypothesisData* MgAdapt::getData() const
+{
+ return data;
+}
+void MgAdapt::setMedFileIn(std::string fileName)
+{
+ medFileIn = fileName;
+}
+
+std::string MgAdapt::getMedFileIn()
+{
+ return medFileIn;
+}
+
+void MgAdapt::setMedFileOut(std::string fileOut)
+{
+ medFileOut = fileOut;
+}
+
+std::string MgAdapt::getMedFileOut()
+{
+ return medFileOut;
+}
+void MgAdapt::setMeshOutMed(bool mybool)
+{
+ meshOutMed = mybool;
+}
+bool MgAdapt::getMeshOutMed()
+{
+ return meshOutMed;
+}
+void MgAdapt::setPublish(bool mybool)
+{
+ publish = mybool;
+}
+bool MgAdapt::getPublish()
+{
+ return publish;
+}
+void MgAdapt::setFieldName(std::string myFieldName)
+{
+ fieldName = myFieldName;
+}
+std::string MgAdapt::getFieldName()
+{
+ return fieldName;
+}
+void MgAdapt::setTimeStep(int time)
+{
+ timeStep = time;
+}
+int MgAdapt::getTimeStep() const
+{
+ return timeStep;
+}
+
+void MgAdapt::setRankTimeStep(int time, int myRank)
+{
+ timeStep = time;
+ rank = myRank;
+}
+
+int MgAdapt::getRank()
+{
+ return rank;
+}
+void MgAdapt::setUseLocalMap(bool myLocal)
+{
+ useLocalMap = myLocal;
+
+}
+bool MgAdapt::getUseLocalMap()
+{
+ return useLocalMap;
+}
+
+void MgAdapt::setUseBackgroundMap(bool bckg)
+{
+ useBackgroundMap = bckg;
+
+}
+bool MgAdapt::getUseBackgroundMap()
+{
+ return useBackgroundMap;
+}
+
+void MgAdapt::setUseConstantValue(bool cnst)
+{
+ useConstantValue = cnst;
+
+}
+bool MgAdapt::getUseConstantValue()
+{
+ return useConstantValue;
+}
+void MgAdapt::setLogFile(std::string myLogFile)
+{
+ logFile = myLogFile;
+}
+std::string MgAdapt::getLogFile()
+{
+ return logFile;
+}
+void MgAdapt::setVerbosityLevel(int verboLevel)
+{
+ verbosityLevel = verboLevel;
+}
+int MgAdapt::getVerbosityLevel()
+{
+ return verbosityLevel;
+}
+void MgAdapt::setRemoveOnSuccess(bool rmons)
+{
+ removeOnSuccess = rmons;
+}
+bool MgAdapt::getRemoveOnSuccess()
+{
+ return removeOnSuccess;
+}
+void MgAdapt::setSizeMapFile(std::string mapFile)
+{
+ sizeMapFile = mapFile;
+}
+std::string MgAdapt::getSizeMapFile()
+{
+ return sizeMapFile;
+}
+
+void MgAdapt::setMeshName(std::string name)
+{
+ meshName = name;
+}
+std::string MgAdapt::getMeshName()
+{
+ return meshName;
+}
+void MgAdapt::setMeshNameOut(std::string name)
+{
+ meshNameOut = name;
+}
+std::string MgAdapt::getMeshNameOut()
+{
+ return meshNameOut;
+}
+void MgAdapt::setFromMedFile(bool mybool)
+{
+ fromMedFile = mybool;
+}
+bool MgAdapt::isFromMedFile()
+{
+ return fromMedFile;
+}
+void MgAdapt::setConstantValue(double cnst)
+{
+ constantValue = cnst;
+}
+double MgAdapt::getConstantValue() const
+{
+ return constantValue;
+}
+
+void MgAdapt::setWorkingDir(std::string dir)
+{
+ workingDir = dir;
+}
+std::string MgAdapt::getWorkingDir() const
+{
+ return workingDir;
+}
+void MgAdapt::setKeepWorkingFiles(bool mybool)
+{
+ toKeepWorkingFiles = mybool;
+}
+bool MgAdapt::getKeepWorkingFiles()
+{
+ return toKeepWorkingFiles;
+}
+void MgAdapt::setPrintLogInFile(bool print)
+{
+ printLogInFile = print;
+}
+bool MgAdapt::getPrintLogInFile()
+{
+ return printLogInFile;
+}
+
+bool MgAdapt::setAll()
+{
+
+ setFromMedFile(data->fromMedFile);
+ std::string file;
+ checkDirPath(data->myFileInDir);
+ file = data->myFileInDir+data->myMeshFileIn;
+ setMedFileIn(file);
+ setMeshName(data->myInMeshName);
+ setMeshNameOut(data->myOutMeshName);
+ checkDirPath(data->myFileOutDir);
+ std::string out = data->myFileOutDir+data->myMeshFileOut;
+ setMedFileOut(out);
+ setPublish(data->myPublish);
+ setMeshOutMed(data->myMeshOutMed);
+ setUseLocalMap(data->myUseLocalMap);
+ setUseBackgroundMap(data->myUseBackgroundMap);
+ setUseConstantValue(data->myUseConstantValue);
+
+ std::string mapfile;
+ if (useBackgroundMap)
+ {
+
+ checkDirPath(data->myFileSizeMapDir);
+ mapfile = data->myFileSizeMapDir+data->myMeshFileBackground;
+ setFieldName(data->myFieldName);
+ }
+ else if (useConstantValue)
+ {
+ setConstantValue(data->myConstantValue);
+ }
+ else
+ {
+ mapfile ="";
+ setConstantValue(0.0);
+ setFieldName(data->myFieldName);
+
+ }
+
+ setSizeMapFile(mapfile);
+ med_int rank;
+ med_int tmst;
+ if (data->myUseNoTimeStep)
+ {
+ rank = MED_NO_IT;
+ tmst = MED_NO_DT ;
+ }
+ else if (data->myUseLastTimeStep)
+ {
+ std::string fieldFile = useBackgroundMap ? sizeMapFile : medFileIn;
+ getTimeStepInfos(fieldFile, tmst, rank);
+ }
+ else
+ {
+ rank = data->myRank;
+ tmst = data->myTimeStep;
+ }
+ setRankTimeStep((int)tmst, (int)rank);
+
+ /* Advanced options */
+ setWorkingDir(data->myWorkingDir);
+ checkDirPath(data->myWorkingDir);
+ setLogFile(data->myWorkingDir+defaultLogFile());
+ setVerbosityLevel(data->myVerboseLevel);
+ setRemoveOnSuccess(data->myRemoveLogOnSuccess);
+ setPrintLogInFile(data->myPrintLogInFile);
+ setKeepWorkingFiles(data->myKeepFiles);
+
+ return true;
+}
+
+void MgAdapt::checkDirPath(std::string& dirPath)
+{
+ const char lastChar = *dirPath.rbegin();
+#ifdef WIN32
+ if(lastChar != '\\') dirPath+='\\';
+#else
+ if(lastChar != '/') dirPath+='/';
+#endif
+}
+//=============================================================================
+void MgAdapt::setOptionValue(const std::string& optionName,
+ const std::string& optionValue)
+throw (std::invalid_argument)
+{
+ TOptionValues::iterator op_val = _option2value.find(optionName);
+ if (op_val == _option2value.end())
+ {
+ op_val = _customOption2value.find( optionName );
+ _customOption2value[ optionName ] = optionValue;
+ return;
+ }
+
+ if (op_val->second != optionValue)
+ {
+
+ std::string lowerOptionValue = toLowerStr(optionValue);
+ const char* ptr = lowerOptionValue.c_str();
+ // strip white spaces
+ while (ptr[0] == ' ')
+ ptr++;
+ int i = strlen(ptr);
+ while (i != 0 && ptr[i - 1] == ' ')
+ i--;
+ // check value type
+ bool typeOk = true;
+ std::string typeName;
+ if (i == 0) {
+ // empty string
+ } else if (_charOptions.count(optionName)) {
+ // do not check strings
+ } else if (_doubleOptions.count(optionName)) {
+ // check if value is double
+ toDbl(ptr, &typeOk);
+ typeName = "real";
+ } else if (_boolOptions.count(optionName)) {
+ // check if value is bool
+ toBool(ptr, &typeOk);
+ typeName = "bool";
+ } else {
+ // check if value is int
+ toInt(ptr, &typeOk);
+ typeName = "integer";
+ }
+ if ( typeOk ) // check some specific values ?
+ {
+ }
+ if ( !typeOk )
+ {
+ std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
+ throw std::invalid_argument(msg);
+ }
+ std::string value( ptr, i );
+ if ( _defaultOptionValues[ optionName ] == value )
+ value.clear();
+
+
+ op_val->second = value;
+
+ }
+}
+//=============================================================================
+//! Return option value. If isDefault provided, it can be a default value,
+// then *isDefault == true. If isDefault is not provided, the value will be
+// empty if it equals a default one.
+std::string MgAdapt::getOptionValue(const std::string& optionName, bool* isDefault) const
+throw (std::invalid_argument)
+{
+ TOptionValues::const_iterator op_val = _option2value.find(optionName);
+ if (op_val == _option2value.end())
+ {
+ op_val = _customOption2value.find(optionName);
+ if (op_val == _customOption2value.end())
+ {
+ std::string msg = "Unknown MG-Adapt option: <" + optionName + ">";
+ throw std::invalid_argument(msg);
+ }
+ }
+ std::string val = op_val->second;
+ if ( isDefault ) *isDefault = ( val.empty() );
+
+ if ( val.empty() && isDefault )
+ {
+ op_val = _defaultOptionValues.find( optionName );
+ if (op_val != _defaultOptionValues.end())
+ val = op_val->second;
+ }
+ return val;
+}
+//================================================================================
+/*!
+ * \brief Converts a string to a real value
+ */
+//================================================================================
+
+double MgAdapt::toDbl(const std::string& str, bool* isOk )
+throw (std::invalid_argument)
+{
+ if ( str.empty() ) throw std::invalid_argument("Empty value provided");
+
+ char * endPtr;
+ double val = strtod(&str[0], &endPtr);
+ bool ok = (&str[0] != endPtr);
+
+ if ( isOk ) *isOk = ok;
+
+ if ( !ok )
+ {
+ std::string msg = "Not a real value:'" + str + "'";
+ throw std::invalid_argument(msg);
+ }
+ return val;
+}
+//================================================================================
+/*!
+ * \brief Converts a string to a lower
+ */
+//================================================================================
+std::string MgAdapt::toLowerStr(const std::string& str)
+{
+ std::string s = str;
+ for ( size_t i = 0; i <= s.size(); ++i )
+ s[i] = tolower( s[i] );
+ return s;
+}
+//================================================================================
+/*!
+ * \brief Converts a string to a bool
+ */
+//================================================================================
+
+bool MgAdapt::toBool(const std::string& str, bool* isOk )
+throw (std::invalid_argument)
+{
+ std::string s = str;
+ if ( isOk ) *isOk = true;
+
+ for ( size_t i = 0; i <= s.size(); ++i )
+ s[i] = tolower( s[i] );
+
+ if ( s == "1" || s == "true" || s == "active" || s == "yes" )
+ return true;
+
+ if ( s == "0" || s == "false" || s == "inactive" || s == "no" )
+ return false;
+
+ if ( isOk )
+ *isOk = false;
+ else {
+ std::string msg = "Not a Boolean value:'" + str + "'";
+ throw std::invalid_argument(msg);
+ }
+ return false;
+}
+//================================================================================
+/*!
+ * \brief Converts a string to a integer value
+ */
+//================================================================================
+
+int MgAdapt::toInt(const std::string& str, bool* isOk )
+throw (std::invalid_argument)
+{
+ if ( str.empty() ) throw std::invalid_argument("Empty value provided");
+
+ char * endPtr;
+ int val = (int)strtol( &str[0], &endPtr, 10);
+ bool ok = (&str[0] != endPtr);
+
+ if ( isOk ) *isOk = ok;
+
+ if ( !ok )
+ {
+ std::string msg = "Not an integer value:'" + str + "'";
+ throw std::invalid_argument(msg);
+ }
+ return val;
+}
+//=============================================================================
+bool MgAdapt::hasOptionDefined( const std::string& optionName ) const
+{
+ bool isDefault = false;
+ try
+ {
+ getOptionValue( optionName, &isDefault );
+ }
+ catch ( std::invalid_argument )
+ {
+ return false;
+ }
+ return !isDefault;
+}
+//================================================================================
+/*!
+ * \brief Return command to run MG-Tetra mesher excluding file prefix (-f)
+ */
+//================================================================================
+
+std::string MgAdapt::getCommandToRun(MgAdapt* hyp)
+{
+ return hyp ? hyp->getCommandToRun() : ToComment("error with hypothesis!");
+}
+
+
+
+int MgAdapt::compute(std::string& errStr)
+{
+ std::string cmd = getCommandToRun();
+ int err = 0;
+ execCmd( cmd.c_str(), err ); // run
+
+ if ( err )
+ {
+ errStr = ToComment("system(mg-adapt.exe ...) command failed with error: ")
+ << strerror( errno );
+ }
+ else
+ {
+ convertMeshFile(meshFormatOutputMesh, solFormatOutput);
+ }
+ //~if (!err) cleanUp();
+ return err;
+}
+
+void MgAdapt::execCmd( const char* cmd, int& err)
+{
+ err = 1;
+ std::array <char, 128> buffer;
+ std::streambuf* buf;
+ outFileStream fileStream;
+ if (printLogInFile)
+ {
+ fileStream.open(logFile);
+ buf = fileStream.rdbuf();
+ }
+ else
+ {
+ buf = std::cout.rdbuf();
+ }
+ std::ostream logStream(buf);
+
+ std::unique_ptr <FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose );
+ if(!pipe)
+ {
+ throw std::runtime_error("popen() failed!");
+ }
+ while(fgets(buffer.data(), buffer.size(), pipe.get()) !=nullptr )
+ {
+ logStream<<buffer.data() ;
+ }
+ err = 0;
+}
+
+void MgAdapt::cleanUp()
+{
+ int notOk;
+ std::string errStr;
+ if(removeOnSuccess) tmpFilesToBeDeleted.push_back(logFile);
+
+ std::vector< std::string>::iterator it = tmpFilesToBeDeleted.begin();
+ for (; it!=tmpFilesToBeDeleted.end(); ++it)
+ {
+ errStr=removeFile(*it, notOk);
+ if (notOk)
+ {
+ appendMsgToLogFile(errStr);
+ }
+
+ }
+}
+
+void MgAdapt::appendMsgToLogFile(std::string& msg)
+{
+ std::ofstream logStream;
+ logStream.open(logFile, std::ofstream::out | std::ofstream::app);
+ logStream<< msg;
+ logStream.close();
+}
+//================================================================================
+/*!
+ * \brief Return command to run MG-Tetra mesher excluding file prefix (-f)
+ */
+//================================================================================
+
+std::string MgAdapt::getCommandToRun()
+{
+ /*
+ || return system command with args and options
+ ||
+ */
+ std::string errStr;
+ std::string cmd = getExeName();
+ std::string meshIn(""), sizeMapIn(""), solFileIn("");
+ convertMedFile(meshIn, solFileIn, sizeMapIn);
+ if (!isFileExist(meshIn) || !isFileExist(solFileIn))
+ {
+ errStr = ToComment(" failed to find .mesh or .sol file from converter ")<< strerror( errno );
+ return errStr;
+ }
+ tmpFilesToBeDeleted.push_back(meshIn);
+ tmpFilesToBeDeleted.push_back(solFileIn);
+ if(useBackgroundMap && !isFileExist(sizeMapIn))
+ {
+
+ errStr = ToComment(" failed to find .mesh size map file from converter ")<< strerror( errno );
+ return errStr;
+
+ }
+
+
+ cmd+= " --in "+ meshIn;
+ meshFormatOutputMesh = getFileName()+".mesh";
+ cmd+= " --out "+ meshFormatOutputMesh;
+ if (useLocalMap || useConstantValue) cmd+= " --sizemap "+ solFileIn;
+ else // (useBackgroundMap)
+ {
+ cmd+= " --background_mesh "+ sizeMapIn ;
+ cmd+= " --background_sizemap "+ solFileIn;
+ tmpFilesToBeDeleted.push_back(sizeMapIn);
+ }
+ //~else
+ //~{
+ //~// constant value TODO
+ //~}
+ /* sizemap file is not adapted in case of only surface adaptation see MeshGems docs */
+ std::string adapOp = "adaptation";
+ std::string adpOpVal = getOptionValue(adapOp);
+ std::string surfaceAdapt = "surface";
+ if(surfaceAdapt != adpOpVal )
+ {
+ std::string solFileOut = getFileName()+".sol";
+ cmd+= " --write_sizemap "+ solFileOut;
+ solFormatOutput.push_back(solFileOut);
+ }
+ if (verbosityLevel != defaultVerboseLevel())
+ {
+
+ cmd+= " --verbose "+ ToComment(verbosityLevel);
+ }
+
+ std::string option, value;
+ bool isDefault;
+ const TOptionValues* options[] = { &_option2value, &_customOption2value };
+ for ( int iOp = 0; iOp < 2; ++iOp )
+ {
+ TOptionValues::const_iterator o2v = options[iOp]->begin();
+ for ( ; o2v != options[iOp]->end(); ++o2v )
+ {
+ option = o2v->first;
+ value = getOptionValue( option, &isDefault );
+
+ if ( isDefault )
+ continue;
+ if ( value.empty() )//value == NoValue() )
+ {
+ if ( _defaultOptionValues.count( option ))
+ continue; // non-custom option with no value
+ //value.clear();
+ }
+ if ( strncmp( "no", option.c_str(), 2 ) == 0 ) // options w/o values: --no_*
+ {
+ if ( !value.empty() && toBool( value ) == false )
+ continue;
+ value.clear();
+ }
+ if ( option[0] != '-' )
+ cmd += " --";
+ else
+ cmd += " ";
+ cmd += option + " " + value;
+ }
+ }
+ //~}
+//~cmd+= " >"
+#ifdef WIN32
+ cmd += " < NUL";
+#endif
+
+ return cmd;
+}
+
+
+bool MgAdapt::isFileExist(std::string& fName) const
+{
+
+ if ( fName.empty() )
+ return false;
+
+ boost::system::error_code err;
+ bool res = boost::filesystem::exists( fName, err );
+
+ return err ? false : res;
+}
+//=======================================================================
+//function : defaultMaximumMemory
+//=======================================================================
+
+#if defined(WIN32)
+#include <windows.h>
+#elif !defined(__APPLE__)
+#include <sys/sysinfo.h>
+#endif
+
+double MgAdapt::defaultMaximumMemory()
+{
+#if defined(WIN32)
+ // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
+ MEMORYSTATUSEX statex;
+ statex.dwLength = sizeof (statex);
+ long err = GlobalMemoryStatusEx (&statex);
+ if (err != 0) {
+ double totMB = (double)statex.ullAvailPhys / 1024. / 1024.;
+ return (double)( 0.7 * totMB );
+ }
+#elif !defined(__APPLE__)
+ struct sysinfo si;
+ long err = sysinfo( &si );
+ if ( err == 0 ) {
+ long ramMB = si.totalram * si.mem_unit / 1024 / 1024;
+ return ( 0.7 * ramMB );
+ }
+#endif
+ return 1024;
+}
+
+
+//=======================================================================
+//function : defaultWorkingDirectory
+//=======================================================================
+
+std::string MgAdapt::defaultWorkingDirectory()
+{
+ TCollection_AsciiString aTmpDir;
+
+ char *Tmp_dir = getenv("SALOME_TMP_DIR");
+ if(Tmp_dir != NULL) {
+ aTmpDir = Tmp_dir;
+ }
+ else {
+#ifdef WIN32
+ aTmpDir = TCollection_AsciiString("C:\\");
+#else
+ aTmpDir = TCollection_AsciiString("/tmp/");
+#endif
+ }
+ return aTmpDir.ToCString();
+}
+//================================================================================
+/*!
+ * \brief Return a unique file name
+ */
+//================================================================================
+
+std::string MgAdapt::getFileName() const
+{
+ std::string aTmpDir = workingDir;
+ const char lastChar = *aTmpDir.rbegin();
+#ifdef WIN32
+ if(lastChar != '\\') aTmpDir+='\\';
+#else
+ if(lastChar != '/') aTmpDir+='/';
+#endif
+
+ TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str();
+ aGenericName += "MgAdapt_";
+ aGenericName += getpid();
+ aGenericName += "_";
+ aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString());
+
+ return aGenericName.ToCString();
+}
+//=======================================================================
+//function : defaultLogFile
+//=======================================================================
+
+std::string MgAdapt::defaultLogFile()
+{
+ std::string alogFile("MG_ADAPT.log");
+ return alogFile;
+}
+//=======================================================================
+//function : defaultUseConstantValue
+//=======================================================================
+
+bool MgAdapt::defaultUseConstantValue()
+{
+ return false;
+}
+//=======================================================================
+//function : defaultUseNoTimeStep
+//=======================================================================
+
+bool MgAdapt::defaultUseNoTimeStep()
+{
+ return true;
+}
+//=======================================================================
+//function : defaultRemoveLogOnSuccess
+//=======================================================================
+
+bool MgAdapt::defaultRemoveLogOnSuccess()
+{
+ return true;
+}
+//=======================================================================
+//function : defaultPrintLogInFile
+//=======================================================================
+
+bool MgAdapt::defaultPrintLogInFile()
+{
+ return false;
+}
+//=======================================================================
+//function : defaultUseChosenTimeStep
+//=======================================================================
+
+bool MgAdapt::defaultUseChosenTimeStep()
+{
+ return false;
+}
+//=======================================================================
+//function : UseLastTimeStep
+//=======================================================================
+
+bool MgAdapt::defaultUseLastTimeStep()
+{
+ return false;
+}
+//=======================================================================
+//function : defaultUseBackgroundMap
+//=======================================================================
+
+bool MgAdapt::defaultUseBackgroundMap()
+{
+ return false;
+}
+//=======================================================================
+//function : defaultKeepFiles
+//=======================================================================
+
+bool MgAdapt::defaultKeepFiles()
+{
+ return false;
+}
+//=======================================================================
+//function : defaultUseLocalMap
+//=======================================================================
+
+bool MgAdapt::defaultUseLocalMap()
+{
+ return true;
+}
+//=======================================================================
+//function : defaultPublish
+//=======================================================================
+
+bool MgAdapt::defaultPublish()
+{
+ return false;
+}
+//=======================================================================
+//function : defaultMeshOutMed
+//=======================================================================
+
+bool MgAdapt::defaultMeshOutMed()
+{
+ return true;
+}
+//=======================================================================
+//function : defaultFromMedFile
+//=======================================================================
+
+bool MgAdapt::defaultFromMedFile()
+{
+ return true;
+}
+//=======================================================================
+//function : defaultVerboseLevel
+//=======================================================================
+
+int MgAdapt::defaultVerboseLevel()
+{
+ return 3;
+}
+std::string MgAdapt::getExeName()
+{
+ return "mg-adapt.exe";
+}
+void MgAdapt::copyMgAdaptHypothesisData( MgAdaptHypothesisData* from)
+{
+
+ data->myFileInDir = from->myFileInDir;
+ data->myMeshFileIn = from->myMeshFileIn;
+ data->myMeshFileBackground = from->myMeshFileBackground;
+ data->myOutMeshName = from->myOutMeshName;
+ data->myMeshFileOut = from->myMeshFileOut;
+ data->myFileOutDir = from->myFileOutDir;
+ data->myFileSizeMapDir = from->myFileSizeMapDir;
+ data->myFieldName = from->myFieldName;
+ data->fromMedFile = from->fromMedFile;
+ data->myPublish = from->myPublish;
+ data->myMeshOutMed = from->myMeshOutMed;
+ data->myUseLocalMap = from->myUseLocalMap;
+ data->myUseBackgroundMap = from->myUseBackgroundMap;
+ data->myUseConstantValue = from->myUseConstantValue;
+ data->myConstantValue = from->myConstantValue;
+ data->myTimeStep = from->myTimeStep;
+ data->myRank = from->myRank;
+ data->myUseNoTimeStep = from->myUseNoTimeStep;
+ data->myUseLastTimeStep = from->myUseLastTimeStep;
+ data->myUseChosenTimeStep = from->myUseChosenTimeStep;
+ data->myWorkingDir = from->myWorkingDir;
+ data->myLogFile = from->myLogFile;
+ data->myPrintLogInFile = from->myPrintLogInFile;
+ data->myKeepFiles = from->myKeepFiles;
+ data->myRemoveLogOnSuccess = from->myRemoveLogOnSuccess;
+ data->myVerboseLevel = from->myVerboseLevel;
+
+}
+
+
+void MgAdapt::convertMedFile(std::string& meshFormatMeshFileName, std::string& solFormatFieldFileName, std::string& meshFormatsizeMapFile)
+{
+
+ std::vector<std::string> fieldFileNames;
+ MEDCoupling::MeshFormatWriter writer;
+ MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = MEDCoupling::MEDFileData::New(medFileIn);
+ MEDCoupling::MEDFileMeshes* meshes = mfd->getMeshes();
+ MEDCoupling::MEDFileMesh* fileMesh = meshes->getMeshAtPos(0); // ok only one mesh in file!
+ storeGroupsAndFams(fileMesh);
+
+ MEDCoupling::MCAuto<MEDCoupling::MEDFileFields> fields = MEDCoupling::MEDFileFields::New();
+ solFormatFieldFileName = getFileName();
+ solFormatFieldFileName+=".sol";
+ fieldFileNames.push_back(solFormatFieldFileName);
+
+ if (useBackgroundMap)
+ {
+
+ meshFormatsizeMapFile = getFileName();
+ meshFormatsizeMapFile += ".mesh";
+ buildBackGroundMeshAndSolFiles(fieldFileNames, meshFormatsizeMapFile);
+
+ }
+ else if(useLocalMap)
+ {
+
+ MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS> fts = dynamic_cast<MEDCoupling::MEDFileFieldMultiTS *>( mfd->getFields()->getFieldWithName(fieldName) );
+ MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeField1TS> f = fts->getTimeStep(timeStep, rank);
+ MEDCoupling::MCAuto<MEDCoupling::MEDFileFieldMultiTS> tmFts = MEDCoupling::MEDFileFieldMultiTS::New();
+ tmFts->pushBackTimeStep(f);
+
+ fields->pushField(tmFts);
+
+ writer.setFieldFileNames( fieldFileNames);
+ }
+
+ else
+ {
+ MEDCoupling::MCAuto<MEDCoupling::MEDCouplingMesh> mesh = fileMesh->getMeshAtLevel(1); // nodes mesh
+ MEDCoupling::MCAuto<MEDCoupling::MEDCouplingUMesh> umesh = mesh->buildUnstructured(); // nodes mesh
+ int dim = umesh->getSpaceDimension();
+ int version = sizeof(double) < 8 ? 1 : 2;
+ mcIdType nbNodes = umesh->getNumberOfNodes();
+ buildConstantSizeMapSolFile(solFormatFieldFileName, dim, version, nbNodes);
+
+ }
+
+ mfd->setFields( fields );
+ meshFormatMeshFileName = getFileName();
+ meshFormatMeshFileName+=".mesh";
+ writer.setMeshFileName(meshFormatMeshFileName);
+ writer.setMEDFileDS( mfd);
+ writer.write();
+
+}
+
+void MgAdapt::convertMeshFile(std::string& meshFormatIn, std::vector< std::string>& solFieldFileNames) const
+{
+ MEDCoupling::MeshFormatReader reader(meshFormatIn, solFieldFileNames);
+
+ MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = reader.loadInMedFileDS();
+ // write MED
+ MEDCoupling::MEDFileMeshes* meshes = mfd->getMeshes();
+ MEDCoupling::MEDFileMesh* fileMesh = meshes->getMeshAtPos(0); // ok only one mesh in file!
+ fileMesh->setName(meshNameOut);
+ restoreGroupsAndFams(fileMesh);
+ mfd->write(medFileOut, 2);
+}
+
+
+void MgAdapt::storeGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh)
+{
+ storefams(fileMesh);
+ storeGroups(fileMesh);
+}
+
+void MgAdapt::restoreGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh) const
+{
+ restorefams(fileMesh);
+ restoreGroups(fileMesh);
+}
+void MgAdapt::storeGroups(MEDCoupling::MEDFileMesh* fileMesh)
+{
+ std::map<std::string, std::vector<std::string> > grpFams = fileMesh->getGroupInfo();
+ std::map<std::string, std::vector<std::string> >::iterator g2ff = grpFams.begin();
+
+ for ( ; g2ff != grpFams.end(); ++g2ff )
+ {
+ std::string groupName = g2ff->first;
+ std::vector<std::string> famNames = g2ff->second;
+
+ if ( famNames.empty() ) continue;
+ std::size_t k = 0;
+ std::vector< mcIdType> famListId;
+ for ( size_t i = 0; i < famNames.size(); ++i )
+ {
+ famListId.push_back( fileMesh->getFamilyId( famNames[i].c_str() ) );
+ }
+ group grp(groupName, famListId, famNames);
+ groupVec.push_back(grp);
+ }
+}
+
+void MgAdapt::storefams(MEDCoupling::MEDFileMesh* fileMesh)
+{
+ std::map<std::string, mcIdType> grpFams = fileMesh->getFamilyInfo();
+ std::map<std::string, mcIdType >::iterator f = grpFams.begin();
+
+ for ( ; f != grpFams.end(); ++f )
+ {
+ if(!f->second) continue; // FAMILLE_ZERO
+ family fs(f->first, f->second);
+ famVec.push_back(fs);
+ }
+
+}
+
+void MgAdapt::restorefams(MEDCoupling::MEDFileMesh* fileMesh) const
+{
+ std::vector<family>::const_iterator fIt = famVec.begin();
+
+ for (; fIt!=famVec.end(); ++fIt)
+ {
+ try // safety : FAMILY could be lost P2-->P1
+ {
+ std::string givenFamNameFromMeshGemConverter = fileMesh->getFamilyNameGivenId( std::abs(fIt->_famId) );
+ fileMesh->changeFamilyId(std::abs(fIt->_famId), fIt->_famId);
+ fileMesh->changeFamilyName(givenFamNameFromMeshGemConverter, fIt->_famName);
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr<<e.what();
+ }
+ }
+}
+
+void MgAdapt::restoreGroups(MEDCoupling::MEDFileMesh* fileMesh) const
+{
+ std::map<std::string, std::vector<std::string> > info;
+ std::vector <group>::const_iterator grpFams = groupVec.begin();
+
+ for (; grpFams!=groupVec.end(); ++grpFams)
+ {
+ info.insert(std::pair <std::string, std::vector<std::string> > (grpFams->_name, grpFams->_famNames) );
+ }
+
+ fileMesh->setGroupInfo(info);
+}
+
+void MgAdapt::buildConstantSizeMapSolFile(const std::string& solFormatFieldFileName, const int dim, const int version, const mcIdType nbNodes) const
+{
+ MeshFormat::Localizer loc;
+ MeshFormat::MeshFormatParser writer;
+ int fileId = writer.GmfOpenMesh( solFormatFieldFileName.c_str(), GmfWrite, version, dim);
+ int typTab[] = {GmfSca};
+ writer.GmfSetKwd(fileId, MeshFormat::GmfSolAtVertices, (int)nbNodes, 1, typTab);
+ for (mcIdType i = 0; i<nbNodes; i++)
+ {
+ double valTab[1] = {constantValue};
+ writer.GmfSetLin( fileId, MeshFormat::GmfSolAtVertices, valTab);
+ }
+ writer.GmfCloseMesh(fileId);
+}
+
+void MgAdapt::buildBackGroundMeshAndSolFiles(const std::vector<std::string>& fieldFileNames, const std::string& meshFormatsizeMapFile) const
+{
+ MEDCoupling::MCAuto<MEDCoupling::MEDFileData> tmpMfd = MEDCoupling::MEDFileData::New(sizeMapFile);
+ MEDCoupling::MEDFileFields* tmpFields = tmpMfd->getFields();
+ MEDCoupling::MEDFileAnyTypeFieldMultiTS* fts = tmpFields->getFieldWithName(fieldName);
+ MEDCoupling::MCAuto<MEDCoupling::MEDFileFieldMultiTS> fts1 = dynamic_cast<MEDCoupling::MEDFileFieldMultiTS *>(fts);
+ MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeField1TS> f = fts1->getTimeStep(timeStep, rank);
+ MEDCoupling::MCAuto<MEDCoupling::MEDFileFieldMultiTS> tmFts = MEDCoupling::MEDFileFieldMultiTS::New();
+ tmFts->pushBackTimeStep(f);
+
+ MEDCoupling::MCAuto<MEDCoupling::MEDFileFields> tmp_fields = MEDCoupling::MEDFileFields::New();
+ tmp_fields->pushField(tmFts);
+
+
+ tmpMfd->setFields( tmp_fields );
+ MEDCoupling::MeshFormatWriter tmpWriter;
+ tmpWriter.setMeshFileName(meshFormatsizeMapFile);
+ tmpWriter.setFieldFileNames( fieldFileNames);
+ tmpWriter.setMEDFileDS(tmpMfd);
+ tmpWriter.write();
+}
+// =======================================================================
+med_idt MgAdapt::openMedFile(const std::string aFile)
+// =======================================================================
+// renvoie le medId associe au fichier Med apres ouverture
+{
+ med_idt medIdt = MEDfileOpen(aFile.c_str(),MED_ACC_RDONLY);
+ if (medIdt <0)
+ {
+ //~addMessage( ToComment(" error: Can't open ") << aFile, /*fatal=*/true );
+ ;
+ }
+ return medIdt;
+}
+
+MgAdapt::Status MgAdapt::addMessage(const std::string& msg,
+ const bool isFatal/*=false*/)
+{
+ if ( isFatal )
+ _myErrorMessages.clear(); // warnings are useless if a fatal error encounters
+
+ _myErrorMessages.push_back( msg );
+
+ //~MESSAGE(msg);
+#ifdef _DEBUG_
+ std::cout << msg << std::endl;
+#endif
+ return ( _myStatus = isFatal ? MgAdapt::DRS_FAIL : MgAdapt::DRS_WARN_SKIP_ELEM );
+}
+
+
+
+
+// =======================================================================
+void MgAdapt::getTimeStepInfos(std::string aFile, med_int& numdt, med_int& numit)
+// =======================================================================
+{
+// Il faut voir si plusieurs maillages
+
+
+ herr_t erreur = 0 ;
+ med_idt medIdt ;
+
+
+ // Ouverture du fichier
+ //~SCRUTE(aFile.toStdString());
+ medIdt = openMedFile(aFile);
+ if ( medIdt < 0 ) return ;
+ // Lecture du nombre de champs
+ med_int ncha = MEDnField(medIdt) ;
+ if (ncha < 1 )
+ {
+ //~addMessage( ToComment(" error: there is no field in ") << aFile, /*fatal=*/true );
+ return;
+ }
+ // Lecture des caracteristiques du champs
+
+ // Lecture du type du champ, des noms des composantes et du nom de l'unite
+ char nomcha [MED_NAME_SIZE+1];
+ strcpy(nomcha, fieldName.c_str());
+// Lecture du nombre de composantes
+ med_int ncomp = MEDfieldnComponentByName(medIdt, nomcha);
+ char meshname[MED_NAME_SIZE+1];
+ char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
+ char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
+ char dtunit[MED_SNAME_SIZE+1];
+ med_bool local;
+ med_field_type typcha;
+ med_int nbofcstp;
+ erreur = MEDfieldInfoByName (medIdt, nomcha, meshname,&local,&typcha,comp,unit,dtunit, &nbofcstp);
+ free(comp);
+ free(unit);
+ if ( erreur < 0 )
+ {
+ //~addMessage( ToComment(" error: error while reading field ") << nomcha << " in file " << aFile , /*fatal=*/true );
+ return;
+ }
+
+ med_float dt;
+ med_int tmp_numdt, tmp_numit;
+
+ //~med_int step = data->myUseLastTimeStep ? nbofcstp : data->myTimeStep+1;
+ //~myPrint("step ", step);
+ erreur = MEDfieldComputingStepInfo ( medIdt, nomcha, 1, &numdt, &numit, &dt );
+ for(med_int step = 1; step <= nbofcstp; step++ )
+ {
+ erreur = MEDfieldComputingStepInfo ( medIdt, nomcha, step, &tmp_numdt, &tmp_numit, &dt );
+ if(tmp_numdt > numdt)
+ {
+ numdt = tmp_numdt;
+ numit = tmp_numit;
+ }
+ }
+ if ( erreur < 0 )
+ {
+
+ //~addMessage( ToComment(" error: error while reading field ") << nomcha << "step (numdt, numit) = " <<"("<< numdt<< ", " \
+ numit<< ")" <<" in file " << aFile , /*fatal=*/true );
+ return;
+ }
+
+
+
+ // Fermeture du fichier
+ if ( medIdt > 0 ) MEDfileClose(medIdt);
+
+
+}
+
+
+
--- /dev/null
+// Copyright (C) 2011-2020 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/
+//
+// File : MG_ADAPT.hxx
+//
+#ifndef MG_ADAPT_HXX
+#define MG_ADAPT_HXX
+#include <string>
+# include <sstream>
+#include <map>
+#include <vector>
+#include <set>
+#include <fstream>
+
+#include "MCAuto.hxx"
+#include "MCType.hxx"
+#include "MEDFileMesh.hxx"
+
+#include <med.h>
+// SMESH includes
+
+//~#include <med.h>
+
+
+class MgAdapt;
+
+typedef std::map< std::string, std::string > TOptionValues;
+typedef std::set< std::string > TOptionNames;
+
+struct MgAdaptHypothesisData
+{
+ std::string myFileInDir, myMeshFileIn, myInMeshName, myMeshFileBackground, myOutMeshName,
+ myMeshFileOut, myFileOutDir, myFileSizeMapDir, myFieldName;
+ bool fromMedFile;
+ bool myPublish, myMeshOutMed;
+ bool myUseLocalMap, myUseBackgroundMap, myUseConstantValue;
+ double myConstantValue;
+ int myRank, myTimeStep;
+ bool myUseNoTimeStep, myUseLastTimeStep, myUseChosenTimeStep;
+ std::string myWorkingDir, myLogFile;
+ bool myPrintLogInFile, myKeepFiles, myRemoveLogOnSuccess;
+ int myVerboseLevel;
+
+};
+
+class outFileStream : public std::ofstream{
+public:
+ ~outFileStream(){close();} //to close file at dtor
+};
+
+/*!
+ * \brief Class to generate string from any type
+ */
+class ToComment : public std::string
+{
+ std::ostringstream _s ;
+
+public :
+
+ ToComment():std::string("") {}
+
+ ToComment(const ToComment& c):std::string() {
+ _s << c.c_str() ;
+ this->std::string::operator=( _s.str() );
+ }
+
+ ToComment & operator=(const ToComment& c) {
+ _s << c.c_str() ;
+ this->std::string::operator=( _s.str() );
+ return *this;
+ }
+
+ template <class T>
+ ToComment( const T &anything ) {
+ _s << anything ;
+ this->std::string::operator=( _s.str() );
+ }
+
+ template <class T>
+ ToComment & operator<<( const T &anything ) {
+ _s << anything ;
+ this->std::string::operator=( _s.str() );
+ return *this ;
+ }
+
+ operator char*() const {
+ return (char*)c_str();
+ }
+
+ std::ostream& Stream() {
+ return _s;
+ }
+};
+
+
+class MgAdapt
+{
+
+public:
+
+ MgAdapt();
+ MgAdapt(MgAdaptHypothesisData*);
+ MgAdapt(const MgAdapt&);
+ ~MgAdapt();
+ void buildModel();
+ void setData( MgAdaptHypothesisData*);
+
+ void setMedFileIn(std::string fileName);
+ std::string getMedFileIn();
+
+ void setMedFileOut(std::string fileOut);
+ std::string getMedFileOut();
+
+ void setMeshName(std::string name);
+ std::string getMeshName();
+
+ void setMeshNameOut(std::string name);
+ std::string getMeshNameOut();
+
+ void setMeshOutMed(bool mybool);
+ bool getMeshOutMed();
+
+ void setPublish(bool mybool);
+ bool getPublish();
+
+ void setFieldName(std::string myFieldName);
+ std::string getFieldName();
+
+ void setTimeStep(int time);
+ int getTimeStep() const;
+
+ void setRankTimeStep(int time, int myRank);
+ int getRank();
+
+ void setLogFile(std::string);
+ std::string getLogFile();
+
+ void setVerbosityLevel(int verbosity);
+ int getVerbosityLevel();
+
+ void setRemoveOnSuccess(bool mybool);
+ bool getRemoveOnSuccess();
+
+ MgAdaptHypothesisData* getData() const;
+
+ void setUseLocalMap(bool mybool);
+ bool getUseLocalMap();
+
+ void setUseBackgroundMap(bool mybool);
+ bool getUseBackgroundMap();
+
+ void setUseConstantValue(bool mybool);
+ bool getUseConstantValue();
+
+ void setConstantValue(double cnst);
+ double getConstantValue() const;
+
+ void setSizeMapFile(std::string mapFile);
+ std::string getSizeMapFile();
+
+ void setFromMedFile(bool mybool);
+ bool isFromMedFile();
+
+ void setKeepWorkingFiles(bool mybool);
+ bool getKeepWorkingFiles();
+
+ void setPrintLogInFile(bool mybool);
+ bool getPrintLogInFile();
+
+ void setWorkingDir(std::string dir);
+ std::string getWorkingDir() const;
+
+
+ bool setAll();
+ static std::string getCommandToRun(MgAdapt* );
+ std::string getCommandToRun() ;
+ int compute(std::string& errStr);
+ std::string getFileName() const;
+ static std::string getExeName();
+ void copyMgAdaptHypothesisData( MgAdaptHypothesisData* from) ;
+
+ void checkDirPath(std::string& dirPath);
+
+
+
+ bool hasOptionDefined( const std::string& optionName ) const;
+ void setOptionValue(const std::string& optionName,
+ const std::string& optionValue) throw (std::invalid_argument);
+ std::string getOptionValue(const std::string& optionName,
+ bool* isDefault=0) const throw (std::invalid_argument);
+ std::vector <std::string> getCustomOptionValuesStrVec() const;
+ std::vector <std::string> getOptionValuesStrVec() const;
+
+
+ TOptionValues getOptionValues() const;
+ const TOptionValues& getCustomOptionValues() const ;
+ static double toDbl(const std::string&, bool* isOk = 0) throw (std::invalid_argument);
+ static bool toBool(const std::string&, bool* isOk = 0) throw (std::invalid_argument);
+ static int toInt(const std::string&, bool* isOk = 0 ) throw (std::invalid_argument);
+ static std::string toLowerStr(const std::string& str);
+
+
+ /* default values */
+ static std::string defaultWorkingDirectory();
+ static std::string defaultLogFile();
+ static bool defaultKeepFiles();
+ static bool defaultRemoveLogOnSuccess();
+ static int defaultVerboseLevel();
+ static bool defaultPrintLogInFile();
+ static bool defaultFromMedFile();
+ static bool defaultMeshOutMed();
+ static bool defaultPublish();
+ static bool defaultUseLocalMap();
+ static bool defaultUseBackgroundMap();
+ static bool defaultUseConstantValue();
+ static bool defaultUseNoTimeStep();
+ static bool defaultUseLastTimeStep();
+ static bool defaultUseChosenTimeStep();
+ static double defaultMaximumMemory();
+
+
+
+
+ enum Status {
+ DRS_OK,
+ DRS_EMPTY, // a file contains no mesh with the given name
+ DRS_WARN_RENUMBER, // a file has overlapped ranges of element numbers,
+ // so the numbers from the file are ignored
+ DRS_WARN_SKIP_ELEM, // some elements were skipped due to incorrect file data
+ DRS_WARN_DESCENDING, // some elements were skipped due to descending connectivity
+ DRS_FAIL, // general failure (exception etc.)
+ DRS_NO_TIME_STEP // general failure (exception etc.)
+ };
+
+ struct group {
+
+ std::string _name;
+ std::vector<MEDCoupling::mcIdType> _famListId;
+ std::vector<std::string> _famNames;
+ group(std::string name, std::vector<MEDCoupling::mcIdType> famListId, std::vector<std::string> famNames):_name(name)
+ {
+ std::vector<MEDCoupling::mcIdType>::iterator it = famListId.begin();
+ for (; it!=famListId.end(); ++it)
+ _famListId.push_back(*it);
+
+ std::vector<std::string>::iterator itt = famNames.begin();
+ for (; itt!=famNames.end(); ++itt)
+ _famNames.push_back(*itt);
+ }
+ };
+
+ struct family {
+ std::string _famName;
+ mcIdType _famId;
+ family(std::string famName, MEDCoupling::mcIdType famId):_famName(famName), _famId(famId) {}
+ };
+
+
+private :
+ bool fromMedFile;
+
+ std::string medFileIn;
+ std::string medFileOut;
+ std::string meshName;
+ std::string meshNameOut;
+ bool publish, meshOutMed;
+ bool useLocalMap, useBackgroundMap, useConstantValue;
+ std::string sizeMapFile;
+ std::string fieldName;
+ double constantValue;
+ int rank, timeStep;
+
+ /* advanced options */
+
+
+ std::string logFile;
+ std::string workingDir;
+ int verbosityLevel;
+ bool removeOnSuccess;
+ bool toKeepWorkingFiles;
+ bool printLogInFile;
+
+ /* Model DATA */
+ MgAdaptHypothesisData* data;
+
+ /* */
+
+ TOptionValues _option2value, _customOption2value; // user defined values
+ TOptionValues _defaultOptionValues; // default values
+ TOptionNames _doubleOptions, _charOptions, _boolOptions; // to find a type of option
+
+ std::vector <std::string> _myErrorMessages;
+ Status _myStatus;
+ std::string meshFormatOutputMesh;
+ std::vector< std::string> solFormatOutput;
+ std::vector <group> groupVec;
+ std::vector <family> famVec;
+ std::vector< std::string> tmpFilesToBeDeleted;
+
+ /* convert MED-->.mesh format */
+ void convertMedFile(std::string& meshIn,std::string& solFileIn, std::string& sizeMapIn) ;
+ void storeGroups(MEDCoupling::MEDFileMesh* fileMesh);
+ void restoreGroups(MEDCoupling::MEDFileMesh* fileMesh) const;
+ void storefams(MEDCoupling::MEDFileMesh* fileMesh);
+ void restorefams(MEDCoupling::MEDFileMesh* fileMesh) const;
+ void storeGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh);
+ void restoreGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh) const;
+ void convertMeshFile(std::string& meshFormatIn, std::vector< std::string>& solFieldFileNames) const ;
+ void buildConstantSizeMapSolFile(const std::string& solFormatFieldFileName, const int dim, const int version, const mcIdType nbNodes) const;
+ void buildBackGroundMeshAndSolFiles(const std::vector<std::string>& fieldFileNames, const std::string& meshFormatsizeMapFile) const;
+ void getTimeStepInfos(std::string aFile, med_int& numdt, med_int& numit);
+ Status addMessage(const std::string& msg, const bool isFatal = false);
+ med_idt openMedFile(const std::string aFile) ;
+ bool isFileExist(std::string& fName) const;
+ void execCmd( const char* cmd, int& err);
+ void cleanUp();
+ void appendMsgToLogFile(std::string& msg);
+};
+
+
+
+#endif // MG_ADAPT_HXX
${PROJECT_BINARY_DIR}/adm_local/unix
${PROJECT_SOURCE_DIR}/src/ADAPT
${PROJECT_SOURCE_DIR}/src/ADAPT_I
+ ${MEDCOUPLING_INCLUDE_DIRS}
)
# additional preprocessor / compiler flags
${GUI_SalomeApp}
${SMESH_SalomeIDLSMESH}
ADAPTEngine
+ ${MEDCoupling_medloader}
)
# --- resources ---
MonCreateYACS.h
MonEditYACS.h
MonEditFile.h
+ MG_ADAPTGUI.hxx
)
# header files / uic wrappings
MonEditYACS.cxx
MonEditFile.cxx
HomardQtCommun.cxx
+ MG_ADAPTGUI.cxx
)
# sources / to compile
--- /dev/null
+// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// file : MG_ADAPTGUI.cxx
+
+#include "MG_ADAPTGUI.hxx"
+
+#include "SUIT_Desktop.h"
+#include "SUIT_Application.h"
+#include "SUIT_Session.h"
+
+#include "SalomeApp_Application.h"
+#include "SalomeApp_Module.h"
+#include "SalomeApp_Study.h"
+//~#include "SMESH_Actor.h"
+#include <SUIT_MessageBox.h>
+//~#include <SMESH_TypeFilter.hxx>
+//~#include <SMESH_MeshAlgos.hxx>
+//~#include <SMESH_LogicalFilter.hxx>
+//~#include <SMDS_Mesh.hxx>
+//~#include <SMDS_MeshNode.hxx>
+#include <LightApp_SelectionMgr.h>
+#include <SUIT_OverrideCursor.h>
+#include <SUIT_ResourceMgr.h>
+#include <SVTK_ViewWindow.h>
+#include <SALOME_ListIO.hxx>
+#include <SUIT_FileDlg.h>
+#include <QApplication>
+#include <QButtonGroup>
+#include <QGridLayout>
+#include <QGroupBox>
+#include <QHBoxLayout>
+#include <QKeyEvent>
+#include <QLabel>
+#include <QLineEdit>
+#include <QCheckBox>
+#include <QPushButton>
+#include <QRadioButton>
+#include <QTabWidget>
+#include <QVBoxLayout>
+#include <QDoubleSpinBox>
+#include <QSpinBox>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+#include <QSpacerItem>
+#include <QString>
+#include <QHeaderView>
+#include <QItemDelegate>
+#include <QFileDialog>
+#include <QMessageBox>
+#include <QComboBox>
+
+#include <vtkPoints.h>
+#include <vtkUnstructuredGrid.h>
+#include <vtkIdList.h>
+#include <vtkCellArray.h>
+#include <vtkUnsignedCharArray.h>
+#include <vtkDataSetMapper.h>
+#include <VTKViewer_CellLocationsArray.h>
+#include <vtkProperty.h>
+
+#include <ElCLib.hxx>
+// SALOME KERNEL includes
+#include <SALOMEDS_SComponent.hxx>
+#include <SALOMEDS_SObject.hxx>
+#include <SALOMEDS_Study.hxx>
+#include <SALOMEDS_wrap.hxx>
+#include "SalomeApp_Tools.h"
+#include <SALOMEconfig.h>
+#include <med.h>
+#include <utilities.h>
+
+#include <TCollection_AsciiString.hxx>
+
+
+const int SPACING = 6; // layout spacing
+const int MARGIN = 9; // layout margin
+
+//=================================================================================
+// function : SMESHGUI_MgAdaptDlg()
+// purpose :
+//=================================================================================
+SMESHGUI_MgAdaptDlg::SMESHGUI_MgAdaptDlg( SalomeApp_Module* theModule, MgAdapt* myModel, QWidget* parent, bool isCreation )
+ : mySMESHGUI( theModule ), QDialog(parent)
+{
+ model = new MgAdapt(*myModel);
+ myData = model->getData();
+ buildDlg();
+ if (!isCreation) readParamsFromHypo();
+}
+
+void SMESHGUI_MgAdaptDlg::buildDlg()
+{
+ setModal( false );
+ setAttribute( Qt::WA_DeleteOnClose, true );
+ setWindowTitle( tr( "ADAPT_PREF_MG_ADAPT" ) );
+ setSizeGripEnabled( true );
+
+
+ myTabWidget = new QTabWidget( this );
+
+ // Arguments
+
+ myArgs = new SMESHGUI_MgAdaptArguments( myTabWidget );
+ std::vector <std::string> str = model->getOptionValuesStrVec();
+ std::vector <std::string> str2 = model->getCustomOptionValuesStrVec();
+ str.insert( str.end(), str2.begin(), str2.end() );
+
+ myAdvOpt = new MgAdaptAdvWidget(myTabWidget, &str);
+ int argsTab = myTabWidget->addTab( myArgs, tr( "Args" ) );
+ int advTab = myTabWidget->addTab( myAdvOpt, tr( "ADVOP" ) );
+
+ myAdvOpt->workingDirectoryLabel ->setText (tr( "WORKING_DIR" ));
+ myAdvOpt->workingDirectoryPushButton ->setText (tr( "SELECT_DIR" ));
+ myAdvOpt->keepWorkingFilesCheck ->setText (tr( "KEEP_WORKING_FILES" ));
+ myAdvOpt->verboseLevelLabel ->setText (tr( "VERBOSE_LEVEL" ));
+ myAdvOpt->removeLogOnSuccessCheck ->setText (tr( "REMOVE_LOG_ON_SUCCESS" ));
+ myAdvOpt->logInFileCheck ->setText (tr( "LOG_IN_FILE" ));
+ myAdvOpt->logGroupBox ->setTitle(tr( "LOG_GROUP_TITLE" ));
+
+ // buttons
+ QPushButton* okBtn = new QPushButton( tr( "SMESH_BUT_OK" ), this );
+ okBtn->setAutoDefault( true );
+ okBtn->setDefault( true );
+ okBtn->setFocus();
+ QPushButton* buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), this);
+ buttonApply->setAutoDefault(true);
+ QPushButton* buttonApplyAndClose = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), this);
+ buttonApplyAndClose->setAutoDefault(true);
+ QPushButton* cancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), this );
+ cancelBtn->setAutoDefault( true );
+ QPushButton* helpBtn = new QPushButton( tr( "SMESH_BUT_HELP" ), this );
+ helpBtn->setAutoDefault( true );
+
+ QHBoxLayout* btnLayout = new QHBoxLayout;
+ btnLayout->setSpacing( SPACING );
+ btnLayout->setMargin( 0 );
+ btnLayout->addWidget( buttonApplyAndClose );
+ btnLayout->addStretch( 10 );
+ btnLayout->addWidget( buttonApply );
+ btnLayout->addStretch( 10 );
+ btnLayout->addWidget( okBtn );
+ btnLayout->addStretch( 10 );
+ btnLayout->addWidget( cancelBtn );
+ btnLayout->addStretch( 10 );
+ btnLayout->addWidget( helpBtn );
+ okBtn->hide(); // tab 1
+
+ QVBoxLayout* l = new QVBoxLayout ( this );
+ l->setMargin( MARGIN );
+ l->setSpacing( SPACING );
+ l->addWidget( myTabWidget );
+ l->addStretch();
+ l->addLayout( btnLayout );
+
+
+ connect( okBtn, SIGNAL( clicked() ), this, SLOT( clickOnOk() ) );
+ connect( helpBtn, SIGNAL( clicked() ), this, SLOT( clickOnHelp() ) );
+ connect(cancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
+ connect(buttonApply, SIGNAL(clicked()), this,SLOT(clickOnApply()));
+ connect(buttonApplyAndClose, SIGNAL(clicked()), this,SLOT(clickOnOk()));
+ connect(myArgs, SIGNAL(meshDimSignal(ADAPTATION_MODE)), myAdvOpt, SLOT( onMeshDimChanged(ADAPTATION_MODE)) );
+}
+
+
+//=================================================================================
+// function : ~SMESHGUI_MgAdaptDlg()
+// purpose : Destroys the object and frees any allocated resources
+//=================================================================================
+SMESHGUI_MgAdaptDlg::~SMESHGUI_MgAdaptDlg()
+{
+ delete model;
+}
+
+void SMESHGUI_MgAdaptDlg::setModel(MgAdapt* mg)
+{
+ model = mg;
+}
+MgAdapt* SMESHGUI_MgAdaptDlg::getModel() const
+{
+ return model;
+}
+/*!
+ \brief Perform clean-up actions on the dialog box closing.
+*/
+bool SMESHGUI_MgAdaptDlg::clickOnApply()
+{
+ readParamsFromWidgets();
+ return true;
+}
+void SMESHGUI_MgAdaptDlg::clickOnOk()
+{
+ clickOnApply();
+ reject();
+}
+void SMESHGUI_MgAdaptDlg::reject()
+{
+ QDialog::reject();
+}
+bool SMESHGUI_MgAdaptDlg::readParamsFromHypo( ) const
+{
+ bool ret = true;
+ myArgs->aMedfile->setChecked(myData->fromMedFile) ;
+ if (myData->fromMedFile)
+ {
+
+ *(myArgs->myFileInDir) = QString(myData->myFileInDir.c_str()) ;
+ myArgs->selectMedFileLineEdit->setText(myData->myMeshFileIn.c_str()) ;
+ // myData->myInMeshName = // TODO
+
+ }
+ else
+ {
+ myArgs->aBrowserObject->setText(myData->myInMeshName.c_str());
+ //~ myArgs->myFileInDir =""; // TODO
+ //~ myArgs->selectMedFileLineEdit->setText(); // TODO
+ }
+ myArgs->meshNameLineEdit->setText(myData->myOutMeshName.c_str());
+ myArgs->medFileCheckBox->setChecked(myData->myMeshOutMed);
+
+ if(myData->myMeshOutMed)
+ {
+ *(myArgs->myFileOutDir) = QString(myData->myFileOutDir.c_str());
+ myArgs->selectOutMedFileLineEdit->setText(myData->myMeshFileOut.c_str());
+
+ }
+ else
+ {
+ *(myArgs->myFileOutDir) = QString(""); //TODO
+ }
+
+ myArgs->publishOut->setChecked(myData->myPublish);
+
+ myArgs->localButton->setChecked(myData->myUseLocalMap);
+ myArgs->backgroundButton->setChecked(myData->myUseBackgroundMap);
+ myArgs->constantButton->setChecked(myData->myUseConstantValue);
+
+ if (myData->myUseConstantValue)
+ {
+ myArgs->dvalue->setValue(myData->myConstantValue);
+ }
+ else
+ {
+ myArgs->dvalue->setValue(0.0);
+ }
+
+ if (myData->myUseBackgroundMap)
+ {
+
+ *(myArgs->myFileSizeMapDir) = QString(myData->myFileSizeMapDir.c_str()) ;
+ myArgs->selectMedFileBackgroundLineEdit->setText(myData->myMeshFileBackground.c_str());
+ }
+ else
+ {
+ *(myArgs->myFileSizeMapDir) = QString("") ; //TODO
+ myArgs->selectMedFileBackgroundLineEdit->setText(""); //TODO
+ }
+
+ myArgs->fieldNameCmb->setCurrentText(myData->myFieldName.c_str());
+ myArgs->noTimeStep->setChecked(myData->myUseNoTimeStep);
+ myArgs->lastTimeStep->setChecked( myData->myUseLastTimeStep);
+ myArgs->chosenTimeStep->setChecked(myData->myUseChosenTimeStep);
+ if (myData->myUseChosenTimeStep)
+ {
+ myArgs->rankSpinBox->setValue(myData->myRank);
+ myArgs->timeStep->setValue(myData->myTimeStep);
+ }
+
+ myAdvOpt->workingDirectoryLineEdit->setText(myData->myWorkingDir.c_str());
+ myAdvOpt->logInFileCheck->setChecked(myData->myPrintLogInFile);
+
+ myAdvOpt->verboseLevelSpin->setValue(myData->myVerboseLevel);
+ myAdvOpt->removeLogOnSuccessCheck->setChecked(myData->myRemoveLogOnSuccess);
+ myAdvOpt->keepWorkingFilesCheck->setChecked(myData->myKeepFiles);
+
+ return ret;
+
+}
+
+
+bool SMESHGUI_MgAdaptDlg::readParamsFromWidgets()
+{
+ bool ret = true;
+ MgAdaptHypothesisData* aData = new MgAdaptHypothesisData();
+ aData->fromMedFile = myArgs->aMedfile->isChecked();
+ if (aData->fromMedFile)
+ {
+
+ aData->myFileInDir = myArgs->myFileInDir->toStdString();
+ aData->myMeshFileIn = myArgs->selectMedFileLineEdit->text().toStdString();
+ // aData->myInMeshName = // TODO
+ }
+ else // TODO browser
+ {
+ aData->myInMeshName = myArgs->aBrowserObject->text().toStdString();
+ aData->myFileInDir = myAdvOpt->workingDirectoryLineEdit->text().toStdString();
+
+ TCollection_AsciiString aGenericName = (char*)aData->myFileInDir.c_str();
+ TCollection_AsciiString aGenericName2 = "MgAdapt_";
+ aGenericName2 += getpid();
+ aGenericName2 += "_";
+ aGenericName2 += Abs((Standard_Integer)(long) aGenericName.ToCString());
+ aGenericName2 += ".med";
+ aGenericName+=aGenericName2;
+ emit myArgs->toExportMED(aGenericName.ToCString());
+ aData->myMeshFileIn = aGenericName2.ToCString();
+ }
+ aData->myOutMeshName = myArgs->meshNameLineEdit->text().toStdString();
+ aData->myMeshOutMed = myArgs->medFileCheckBox->isChecked();
+ if(aData->myMeshOutMed)
+ {
+ aData->myFileOutDir = myArgs->myFileOutDir->toStdString();
+ aData->myMeshFileOut = myArgs->selectOutMedFileLineEdit->text().toStdString();
+
+ }
+ else
+ {
+ aData->myMeshFileOut = "";
+ }
+
+ aData->myPublish = myArgs->publishOut->isChecked();
+
+
+ aData->myUseLocalMap = myArgs->localButton->isChecked();
+ aData->myUseBackgroundMap = myArgs->backgroundButton->isChecked();
+ aData->myUseConstantValue = myArgs->constantButton->isChecked();
+ if (aData->myUseConstantValue)
+ {
+ aData->myConstantValue = myArgs->dvalue->value();
+ }
+ else
+ {
+ aData->myConstantValue = 0.0;
+ }
+ if (aData->myUseBackgroundMap)
+ {
+ aData->myFileSizeMapDir = myArgs->myFileSizeMapDir->toStdString();
+ aData->myMeshFileBackground = myArgs->selectMedFileBackgroundLineEdit->text().toStdString();
+ }
+ else
+ {
+ aData->myMeshFileBackground = "";
+ }
+
+ aData->myFieldName = myArgs->fieldNameCmb->currentText().toStdString();
+ aData->myUseNoTimeStep = myArgs->noTimeStep->isChecked();
+ aData->myUseLastTimeStep = myArgs->lastTimeStep->isChecked();
+ aData->myUseChosenTimeStep = myArgs->chosenTimeStep->isChecked();
+ if (aData->myUseChosenTimeStep)
+ {
+ aData->myRank = myArgs->rankSpinBox->value();
+ aData->myTimeStep = myArgs->timeStep->value();
+
+ }
+
+
+ aData->myWorkingDir = myAdvOpt->workingDirectoryLineEdit->text().toStdString();
+ aData->myPrintLogInFile = myAdvOpt->logInFileCheck->isChecked();
+ aData->myVerboseLevel = myAdvOpt->verboseLevelSpin->value();
+ aData->myRemoveLogOnSuccess = myAdvOpt->removeLogOnSuccessCheck->isChecked();
+ aData->myKeepFiles = myAdvOpt->keepWorkingFilesCheck->isChecked();
+ model->setData(aData);
+ QString msg;
+ checkParams(msg);
+ delete aData;
+ return ret;
+}
+bool SMESHGUI_MgAdaptDlg::storeParamsToHypo( const MgAdaptHypothesisData& ) const
+{
+
+}
+/*!
+ \brief Show help page
+*/
+void SMESHGUI_MgAdaptDlg::clickOnHelp()
+{
+ // QString aHelpFile;
+ // if ( myTabWidget->currentIndex() == MinDistance ) {
+ // aHelpFile = "measurements.html#min-distance-anchor";
+ // } else if ( myTabWidget->currentIndex() == BoundingBox ) {
+ // aHelpFile = "measurements.html#bounding-box-anchor";
+ // } else if ( myTabWidget->currentWidget() == myAngle ) {
+ // aHelpFile = "measurements.html#angle-anchor";
+ // } else {
+ // aHelpFile = "measurements.html#basic-properties-anchor";
+ // }
+
+ // SMESH::ShowHelpFile( aHelpFile );
+}
+bool SMESHGUI_MgAdaptDlg::checkParams(QString& msg)
+{
+ if ( !QFileInfo( myAdvOpt->workingDirectoryLineEdit->text().trimmed() ).isWritable() ) {
+ SUIT_MessageBox::warning( this,
+ tr( "SMESH_WRN_WARNING" ),
+ tr( "GHS3D_PERMISSION_DENIED" ) );
+ return false;
+ }
+
+
+ myAdvOpt->myOptionTable->setFocus();
+ QApplication::instance()->processEvents();
+
+ QString name, value;
+ bool isDefault, ok = true;
+ int iRow = 0, nbRows = myAdvOpt->myOptionTable->topLevelItemCount();
+ for ( ; iRow < nbRows; ++iRow )
+ {
+ QTreeWidgetItem* row = myAdvOpt->myOptionTable->topLevelItem( iRow );
+ myAdvOpt->GetOptionAndValue( row, name, value, isDefault );
+
+ if ( name.simplified().isEmpty() )
+ continue; // invalid custom option
+
+ if ( isDefault ) // not selected option
+ value.clear();
+
+ try {
+ model->setOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
+ }
+ catch ( const SALOME::SALOME_Exception& ex )
+ {
+ msg = ex.details.text.in();
+ ok = false;
+ break;
+ }
+ }
+
+
+ return ok;
+}
+
+//=================================================================================
+// function : SMESHGUI_MgAdaptArguments()
+// purpose :
+//=================================================================================
+SMESHGUI_MgAdaptArguments::SMESHGUI_MgAdaptArguments( QWidget* parent )
+ :QWidget(parent)
+{
+
+
+ myFileInDir = new QString("");
+ myFileOutDir = new QString("");
+ myFileSizeMapDir = new QString("");
+ if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
+ {
+ *myFileInDir = QDir::currentPath();
+ *myFileOutDir = QDir::currentPath();
+ *myFileSizeMapDir = QDir::currentPath();
+ }
+ else
+ {
+ *myFileInDir = SUIT_FileDlg::getLastVisitedPath();
+ *myFileOutDir = SUIT_FileDlg::getLastVisitedPath();
+ *myFileSizeMapDir = SUIT_FileDlg::getLastVisitedPath();
+ }
+
+ meshDim = 0;
+ // Mesh in
+ aMeshIn = new QGroupBox( tr( "MeshIn" ), this );
+ aMedfile = new QRadioButton( tr( "MEDFile" ), aMeshIn );
+ aBrowser = new QRadioButton( tr( "Browser" ), aMeshIn );
+ aBrowserObject = new QLineEdit( aMeshIn );
+ selectMedFilebutton = new QPushButton("", aMeshIn);
+ selectMedFileLineEdit = new QLineEdit( aMeshIn );
+
+ meshIn = new QGridLayout( aMeshIn );
+
+ meshIn->setMargin( MARGIN );
+ meshIn->setSpacing( SPACING );
+ meshIn->addWidget( aMedfile, 0, 0, 1,1 );
+ meshIn->addWidget( aBrowser, 0, 1,1,1);
+ meshIn->addWidget( aBrowserObject, 0, 2, 1, 1 );
+ meshIn->addWidget( selectMedFilebutton, 1, 0,1, 1);
+ meshIn->addWidget( selectMedFileLineEdit, 1, 1, 1, 1 );
+ hspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
+
+ meshInGroup = new QButtonGroup( this );
+ meshInGroup->addButton( aMedfile, 0 );
+ meshInGroup->addButton( aBrowser, 1 );
+
+ //Mesh out
+
+ aMeshOut = new QGroupBox( tr( "MeshOut" ), this );
+ meshName = new QLabel(tr("MeshName"), aMeshOut);
+ secondHspacer = new QSpacerItem(100, 30);
+ meshNameLineEdit = new QLineEdit(aMeshOut) ;
+ medFileCheckBox = new QCheckBox(tr("MEDFile"), aMeshOut);
+ selectOutMedFilebutton = new QPushButton("", aMeshOut);
+ thirdHspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
+ selectOutMedFileLineEdit = new QLineEdit(aMeshOut) ;
+ publishOut = new QCheckBox(tr("Publish_MG_ADAPT"), aMeshOut);
+
+ meshOut = new QGridLayout( aMeshOut );
+
+ meshOut->setMargin( MARGIN );
+ meshOut->setSpacing( SPACING );
+ meshOut->addWidget( meshName, 0, 0, 1,1 );
+ meshOut->addItem( secondHspacer, 0, 1, 1, 1 );
+ meshOut->addWidget( meshNameLineEdit, 0, 2,1,1);
+ meshOut->addWidget( medFileCheckBox, 1, 0,1,1 );
+ meshOut->addWidget( selectOutMedFilebutton, 1, 1,1,1 );
+ meshOut->addWidget( selectOutMedFileLineEdit, 1, 2,1,1);
+ meshOut->addWidget( publishOut, 2, 0,1,1 );
+
+ //size map definition
+
+ sizeMapDefinition = new QGroupBox(tr("SIZE_MAP_DEF"), this);
+ localButton = new QRadioButton(tr("LOCAL_MG_ADAPT"), sizeMapDefinition);
+ backgroundButton = new QRadioButton(tr("BACKGRND_MG_ADAPT"), sizeMapDefinition);
+ constantButton = new QRadioButton(tr("CNST_MG_ADAPT"), sizeMapDefinition);
+ medFileBackground = new QLabel(tr("MED_FILE_BCKG"), sizeMapDefinition);
+ selectMedFileBackgroundbutton = new QPushButton(tr(""), sizeMapDefinition);
+ selectMedFileBackgroundLineEdit = new QLineEdit(sizeMapDefinition);
+ valueLabel = new QLabel(tr("VALUE_MG_ADAPT"), sizeMapDefinition);
+ dvalue = new QDoubleSpinBox(sizeMapDefinition);
+ sizeMapDefGroup = new QButtonGroup( this );
+ sizeMapDefGroup->addButton( localButton, 0 );
+ sizeMapDefGroup->addButton( backgroundButton, 1 );
+ sizeMapDefGroup->addButton( constantButton, 2 );
+
+ sizeMapDefGroupLayout = new QGridLayout(sizeMapDefinition);
+ sizeMapDefGroupLayout->addWidget(localButton, 0,0);
+ sizeMapDefGroupLayout->addWidget(backgroundButton, 0,1);
+ sizeMapDefGroupLayout->addWidget(constantButton, 0,2);
+ sizeMapDefGroupLayout->addWidget(medFileBackground, 1,0);
+ sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundbutton, 1,1);
+ sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundLineEdit, 1,2);
+ sizeMapDefGroupLayout->addWidget(valueLabel, 2,0);
+ sizeMapDefGroupLayout->addWidget(dvalue, 2,1);
+
+ // size Map field
+ sizeMapField = new QGroupBox(tr("SIZE_MAP_FIELD"), this);
+ fieldName = new QLabel(tr("MG_ADAPT_FIELD_NAME"), sizeMapField);
+ fieldNameCmb = new QComboBox(sizeMapField);
+ noTimeStep = new QRadioButton(tr("MG_ADAPT_NO_T_ST"), sizeMapField);
+ lastTimeStep = new QRadioButton(tr("MG_ADAPT_L_ST"), sizeMapField);
+ chosenTimeStep = new QRadioButton(tr("MG_ADAPT_CH_ST"), sizeMapField);
+ timeStepLabel = new QLabel(tr("MG_ADAPT_TSTP"), sizeMapField);
+ timeStep = new QSpinBox(sizeMapField);
+ //~timeStep->setMinimum(-1);
+ rankLabel = new QLabel(tr("MG_ADAPT_RANK"), sizeMapField);
+ rankSpinBox = new QSpinBox(sizeMapField);
+ rankSpinBox->setMinimum(-1);
+
+ timeStepGroup = new QButtonGroup(this);
+ timeStepGroup->addButton(noTimeStep, 0);
+ timeStepGroup->addButton(lastTimeStep, 1);
+ timeStepGroup->addButton(chosenTimeStep, 2);
+
+ sizeMapFieldGroupLayout = new QGridLayout(sizeMapField);
+
+ sizeMapFieldGroupLayout->addWidget(fieldName, 0,0);
+ sizeMapFieldGroupLayout->addWidget(fieldNameCmb, 0,1);
+ sizeMapFieldGroupLayout->addWidget(noTimeStep, 1,0);
+ sizeMapFieldGroupLayout->addWidget(lastTimeStep, 1,1);
+ sizeMapFieldGroupLayout->addWidget(chosenTimeStep, 1,2);
+ sizeMapFieldGroupLayout->addWidget(timeStepLabel, 2,0);
+ sizeMapFieldGroupLayout->addWidget(timeStep, 2,1);
+ sizeMapFieldGroupLayout->addWidget(rankLabel, 2,2);
+ sizeMapFieldGroupLayout->addWidget(rankSpinBox, 2,3);
+
+
+ QGridLayout* argumentsLayout = new QGridLayout( this );
+ argumentsLayout->setMargin( MARGIN );
+ argumentsLayout->setSpacing( SPACING );
+
+ argumentsLayout->addWidget( aMeshIn, 0, 0, 1, 3 );
+ argumentsLayout->addWidget( aMeshOut, 1, 0, 1, 3 );
+ argumentsLayout->addWidget( sizeMapDefinition, 2, 0, 1, 3 );
+ argumentsLayout->addWidget( sizeMapField, 3, 0, 1, 3 );
+ argumentsLayout->setColumnStretch( 1, 5 );
+ argumentsLayout->setRowStretch( 4, 5 );
+
+ // Initial state
+ setMode( Mesh, Local);
+ medFileCheckBox->setChecked(true);
+
+ // Connections
+ connect( meshInGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( modeChanged( int ) ) );
+ connect( sizeMapDefGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( sizeMapDefChanged( int ) ) );
+ connect( selectMedFilebutton, SIGNAL( pressed( ) ), this, SLOT( onSelectMedFilebuttonClicked( ) ) );
+ connect(medFileCheckBox, SIGNAL (stateChanged(int)), this, SLOT(onMedFileCheckBox(int) ) );
+ connect(publishOut, SIGNAL (stateChanged(int)), this, SLOT(onPublishOut(int) ) );
+ connect(selectOutMedFilebutton, SIGNAL( pressed()), this, SLOT(onSelectOutMedFilebutton()));
+ connect(selectMedFileBackgroundbutton, SIGNAL(pressed()), this, SLOT(onSelectMedFileBackgroundbutton()) );
+ connect( timeStepGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( timeStepGroupChanged( int ) ) );
+ emit updateSelection();
+}
+
+//=================================================================================
+// function : ~SMESHGUI_MgAdaptArguments()
+// purpose : Destroys the object and frees any allocated resources
+//=================================================================================
+SMESHGUI_MgAdaptArguments::~SMESHGUI_MgAdaptArguments()
+{
+}
+
+void SMESHGUI_MgAdaptArguments::onNoTimeStep(bool disableOther)
+{
+ noTimeStep->setChecked(true);
+
+ rankLabel->setVisible(0);
+ rankSpinBox->setVisible(0);
+ rankSpinBox->setValue(-2);
+
+ timeStepLabel->setVisible(0);
+ timeStep->setVisible(0);
+ timeStep->setValue(-2);
+
+ lastTimeStep->setDisabled(disableOther);
+ chosenTimeStep->setDisabled(disableOther);
+
+
+}
+void SMESHGUI_MgAdaptArguments::onLastTimeStep(bool disableOther)
+{
+ lastTimeStep->setChecked(true);
+
+ rankLabel->setVisible(0);
+ rankSpinBox->setVisible(0);
+ rankSpinBox->setValue(-1);
+
+ timeStepLabel->setVisible(0);
+ timeStep->setVisible(0);
+ timeStep->setValue(-1);
+ noTimeStep->setDisabled(disableOther);
+}
+
+void SMESHGUI_MgAdaptArguments::onChosenTimeStep(bool disableOther, int max)
+{
+ chosenTimeStep->setChecked(true);
+
+ rankLabel->setVisible(1);
+ rankSpinBox->setVisible(1);
+ rankSpinBox->setValue(0);
+
+ timeStepLabel->setVisible(1);
+ timeStep->setVisible(1);
+ timeStep->setValue(0);
+ if (max) timeStep->setMaximum(max);
+
+}
+
+void SMESHGUI_MgAdaptArguments::onSelectOutMedFilebutton()
+{
+
+ QString filtre = QString("Med") ;
+ filtre += QString(" files (*.") + QString("med") + QString(");;");
+ QString fileName = QFileDialog::getSaveFileName(this, tr("SAVE_MED"),
+ QString(""), filtre);
+ QFileInfo myFileInfo(fileName);
+ selectOutMedFileLineEdit->setText(myFileInfo.fileName());
+ *myFileOutDir = myFileInfo.path();
+
+}
+void SMESHGUI_MgAdaptArguments::onSelectMedFileBackgroundbutton()
+{
+ QString fileName0 = selectMedFileBackgroundbutton->text().trimmed();
+
+ QString fileName = getMedFileName(false);
+ if (fileName != QString::null)
+ {
+ myFieldList = GetListeChamps(fileName);
+ if (myFieldList.empty())
+ {
+ fileName = fileName0;
+ fieldNameCmb->clear();
+ }
+ else
+ {
+ // fill field name Combobox
+ fieldNameCmb->clear();
+ std::map<QString, int>::const_iterator it;
+ for ( it=myFieldList.begin() ; it != myFieldList.end(); it++)
+ {
+ fieldNameCmb->insertItem(0,QString(it->first));
+ int typeStepInField = it->second > 2 ? 2 : it->second ;
+ timeStepGroupChanged(typeStepInField, true);
+ }
+
+ }
+
+ }
+ else
+ {
+ fileName = fileName0;
+ fieldNameCmb->clear();
+ }
+
+ QFileInfo myFileInfo(fileName);
+ *myFileSizeMapDir = myFileInfo.path();
+ selectMedFileBackgroundLineEdit->setText(myFileInfo.fileName());
+
+}
+void SMESHGUI_MgAdaptArguments::onMedFileCheckBox(int state)
+{
+ if (state == Qt::Checked)
+ {
+ selectOutMedFilebutton->show();
+ selectOutMedFileLineEdit->show();
+ selectOutMedFilebutton->setEnabled(true);
+ selectOutMedFileLineEdit->setEnabled(true);
+ }
+ else
+ {
+ selectOutMedFilebutton->setEnabled(false);
+ selectOutMedFileLineEdit->setEnabled(false);
+ publishOut->setChecked(true);
+ }
+}
+void SMESHGUI_MgAdaptArguments::onPublishOut(int state)
+{
+ if (state == Qt::Unchecked)
+ {
+ medFileCheckBox->setChecked(true);
+ }
+}
+
+void SMESHGUI_MgAdaptArguments::onSelectMedFilebuttonClicked()
+{
+ // bool keep = false;
+ QString fileName0 = selectMedFileLineEdit->text().trimmed();
+
+ QString fileName = getMedFileName(false);
+ if(fileName != QString::null)
+ {
+ QString aMeshName = lireNomMaillage(fileName.trimmed(), meshDim);
+ if (aMeshName == QString::null )
+ {
+ QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
+ QObject::tr("MG_ADAPT_MED_FILE_2") );
+ fileName = fileName0;
+ }
+ else
+ {
+ meshNameLineEdit->setText(aMeshName);
+ ADAPTATION_MODE aMode = meshDim == 3 ? ADAPTATION_MODE::BOTH : ADAPTATION_MODE::SURFACE; // and when dimesh 3 without 2D mesh?
+ emit meshDimSignal(aMode);
+ }
+
+ }
+ else
+ {
+ return;
+ }
+
+
+ QFileInfo myFileInfo(fileName);
+ *myFileInDir = myFileInfo.path();
+ *myFileOutDir = myFileInfo.path();
+ selectMedFileLineEdit->setText(myFileInfo.fileName());
+ QString outF = fileName == QString::null ? myFileInfo.fileName() :
+ QString( remove_extension(myFileInfo.fileName().toStdString() ).c_str() )+ QString(".adapt.med");
+ selectOutMedFileLineEdit->setText(outF);
+ onLocalSelected(myFileInfo.filePath());
+
+}
+
+void SMESHGUI_MgAdaptArguments::onLocalSelected(QString filePath)
+{
+ myFieldList = GetListeChamps(filePath, false);
+ if (myFieldList.empty())
+ {
+ if (localButton->isChecked())
+ {
+ fieldNameCmb->clear();
+ }
+
+ }
+ else
+ {
+ // fill field name Combobox
+ fieldNameCmb->clear();
+ std::map<QString, int>::const_iterator it;
+ for ( it = myFieldList.begin() ; it != myFieldList.end(); it++)
+ {
+ fieldNameCmb->insertItem(0,QString(it->first));
+ int typeStepInField = it->second > 2 ? 2 : it->second ;
+ timeStepGroupChanged(typeStepInField, true);
+ }
+
+ }
+}
+// =======================================================================
+// Gestion les boutons qui permettent de
+// 1) retourne le nom d'un fichier par une fenetre de dialogue si aucun
+// objet est selectionne dans l arbre d etude
+// 2) retourne le nom du fichier asocie a l objet
+// selectionne dans l arbre d etude
+// =======================================================================
+QString SMESHGUI_MgAdaptArguments::getMedFileName(bool avertir)
+{
+
+ QString aFile = QString::null;
+ QString filtre = QString("Med") ;
+ filtre += QString(" files (*.") + QString("med") + QString(");;");
+ aFile = SUIT_FileDlg::getOpenFileName(0, QObject::tr("MG_ADAPT_SELECT_FILE_0"), QString(""), filtre );
+
+ return aFile;
+
+}
+void SMESHGUI_MgAdaptArguments::setMode(const Mode theMode, const SIZEMAP theSizeMap )
+{
+ QRadioButton* aButton = qobject_cast<QRadioButton*>( meshInGroup->button( theMode ) );
+ QRadioButton* bButton = qobject_cast<QRadioButton*>( sizeMapDefGroup->button( theSizeMap ) );
+ if ( aButton ) {
+ aButton->setChecked( true );
+ modeChanged( theMode );
+ }
+ if ( bButton ) {
+ bButton->setChecked( true );
+ sizeMapDefChanged( theSizeMap );
+ }
+}
+
+void SMESHGUI_MgAdaptArguments::modeChanged( int theMode )
+{
+ clear();
+ if(theMode == Mesh)
+ {
+ aBrowserObject->hide();
+ selectMedFileLineEdit->show();
+ selectMedFilebutton->show();
+ localButton->setEnabled(true);
+ }
+ else
+ {
+ selectMedFileLineEdit->hide();
+ selectMedFilebutton->hide();
+ localButton->setEnabled(false);
+ aBrowserObject->show();
+ sizeMapDefChanged(Background);
+ emit updateSelection();
+ }
+
+
+
+}
+
+void SMESHGUI_MgAdaptArguments::sizeMapDefChanged( int theSizeMap )
+{
+ fieldNameCmb->clear();
+ if(theSizeMap == Local)
+ {
+ localButton->setEnabled(true);
+ localButton->setChecked(true);
+ medFileBackground->hide();
+ selectMedFileBackgroundbutton->hide();
+ selectMedFileBackgroundLineEdit->hide();
+ selectMedFileBackgroundLineEdit->clear();
+ valueLabel->hide();
+ dvalue->hide();
+
+ sizeMapField->setEnabled(true);
+ if (!selectMedFileLineEdit->text().isEmpty())
+ {
+ QFileInfo myFileInfo(QDir(*myFileInDir), selectMedFileLineEdit->text());
+ onLocalSelected(myFileInfo.filePath());
+ }
+ }
+ else if (theSizeMap == Background)
+ {
+ medFileBackground->show();
+ backgroundButton->setChecked(true);
+ selectMedFileBackgroundbutton->show();
+ selectMedFileBackgroundLineEdit->show();
+ valueLabel->hide();
+ dvalue->hide();
+ sizeMapField->setEnabled(true);
+
+ }
+ else
+ {
+ medFileBackground->hide();
+ constantButton->setChecked(true);
+ selectMedFileBackgroundbutton->hide();
+ selectMedFileBackgroundLineEdit->clear();
+ selectMedFileBackgroundLineEdit->hide();
+ valueLabel->show();
+ dvalue->show();
+ sizeMapField->setEnabled(false);
+
+ }
+
+
+}
+void SMESHGUI_MgAdaptArguments::timeStepGroupChanged(int timeStepType, bool disableOther, int max)
+{
+ switch (timeStepType)
+ {
+ case 0 :
+ onNoTimeStep(disableOther);
+ break;
+ case 1 :
+ onLastTimeStep(disableOther);
+ break;
+ case 2 :
+ onChosenTimeStep(disableOther, max);
+ default:
+ break;
+ }
+}
+
+void SMESHGUI_MgAdaptArguments::clear()
+{
+ selectMedFileLineEdit->clear();
+ aBrowserObject->clear();
+
+ meshNameLineEdit->clear();
+ selectOutMedFileLineEdit->clear();
+}
+med_int SMESHGUI_MgAdaptArguments::getMeshDim() const
+{
+ return meshDim;
+}
+QWidget* ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const
+{
+ bool editable = index.data( EDITABLE_ROLE ).toInt();
+ return editable ? QItemDelegate::createEditor( parent, o, index ) : 0;
+}
+
+//////////////////////////////////////////
+// MgAdaptAdvWidget
+//////////////////////////////////////////
+
+MgAdaptAdvWidget::MgAdaptAdvWidget( QWidget* parent, std::vector <std::string>* options, Qt::WindowFlags f )
+ : QWidget( parent, f ), myOptions(options)
+{
+ setupWidget();
+ myOptionTable->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
+ myOptionTable->setItemDelegate( new ItemDelegate( myOptionTable ) );
+
+ for ( int i = 0, nb = myOptions->size(); i < nb; ++i )
+ {
+ AddOption( (*myOptions)[i].c_str() );
+ }
+
+ connect( myOptionTable, SIGNAL( itemChanged(QTreeWidgetItem *, int)), SLOT( itemChanged(QTreeWidgetItem *, int )));
+ connect( addBtn, SIGNAL( clicked() ), this, SLOT( onAddOption() ) );
+ connect(workingDirectoryPushButton, SIGNAL(pressed()), this, SLOT(_onWorkingDirectoryPushButton()));
+}
+
+MgAdaptAdvWidget::~MgAdaptAdvWidget()
+{
+}
+
+void MgAdaptAdvWidget::AddOption( const char* option, bool isCustom )
+{
+
+
+ QString name, value;
+ bool isDefault = false;
+ if ( option )
+ {
+ QStringList name_value_type = QString(option).split( ":", QString::KeepEmptyParts );
+ if ( name_value_type.size() > 0 )
+ name = name_value_type[0];
+ if ( name_value_type.size() > 1 )
+ value = name_value_type[1];
+ if ( name_value_type.size() > 2 )
+ isDefault = !name_value_type[2].toInt();
+
+ }
+ QTreeWidget* table = myOptionTable;
+ //table->setExpanded( true );
+
+ QTreeWidgetItem* row;
+ if (optionTreeWidgetItem.size())
+ {
+ std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(name);
+ if(it != optionTreeWidgetItem.end()) return; // option exist
+ else
+ {
+ row = getNewQTreeWidgetItem(table, option, name, isCustom);
+ }
+ }
+ else
+ {
+ row = getNewQTreeWidgetItem(table, option, name, isCustom);
+ }
+ row->setText( 0, tr( name.toLatin1().constData() ));
+ row->setText( 1, tr( value.toLatin1().constData() ));
+ row->setCheckState( 0, isDefault ? Qt::Unchecked : Qt::Checked);
+ row->setData( NAME_COL, PARAM_NAME, name );
+
+ if ( isCustom )
+ {
+ myOptionTable->scrollToItem( row );
+ myOptionTable->setCurrentItem( row );
+ myOptionTable->editItem( row, NAME_COL );
+ }
+}
+
+QTreeWidgetItem* MgAdaptAdvWidget::getNewQTreeWidgetItem(QTreeWidget* table, const char* option, QString& name, bool isCustom)
+{
+ QTreeWidgetItem* row = new QTreeWidgetItem( table );
+ row->setData( NAME_COL, EDITABLE_ROLE, int( isCustom && !option ));
+ row->setFlags( row->flags() | Qt::ItemIsEditable );
+ optionTreeWidgetItem.insert(std::pair <QString, QTreeWidgetItem*> (name, row));
+
+ return row;
+}
+
+void MgAdaptAdvWidget::onAddOption()
+{
+ AddOption( NULL, true );
+}
+void MgAdaptAdvWidget::GetOptionAndValue( QTreeWidgetItem * tblRow,
+ QString& option,
+ QString& value,
+ bool& isDefault)
+{
+ option = tblRow->data( NAME_COL, PARAM_NAME ).toString();
+ value = tblRow->text( VALUE_COL );
+ isDefault = ! tblRow->checkState( NAME_COL );
+
+}
+
+
+void MgAdaptAdvWidget::itemChanged(QTreeWidgetItem* tblRow, int column)
+{
+ if ( tblRow )
+ {
+ myOptionTable->blockSignals( true );
+
+ tblRow->setData( VALUE_COL, EDITABLE_ROLE, int( tblRow->checkState( NAME_COL )));
+
+ int c = tblRow->checkState( NAME_COL ) ? 0 : 150;
+ tblRow->setForeground( VALUE_COL, QBrush( QColor( c, c, c )));
+
+ if ( column == NAME_COL && tblRow->data( NAME_COL, EDITABLE_ROLE ).toInt() ) // custom table
+ {
+ tblRow->setData( NAME_COL, PARAM_NAME, tblRow->text( NAME_COL ));
+ }
+
+ myOptionTable->blockSignals( false );
+ }
+}
+void MgAdaptAdvWidget::setupWidget()
+{
+ if (this->objectName().isEmpty())
+ this->setObjectName(QString(tr("MG-ADAPT-ADV")));
+ this->resize(337, 369);
+ gridLayout_4 = new QGridLayout(this);
+ gridLayout_4->setObjectName(QString("gridLayout_4"));
+ myOptionTable = new MgAdaptAdvWidgetTreeWidget(this);
+ QFont font;
+ font.setBold(false);
+ font.setWeight(50);
+ QTreeWidgetItem *__qtreewidgetitem = new QTreeWidgetItem();
+ __qtreewidgetitem->setFont(1, font);
+ __qtreewidgetitem->setFont(0, font);
+ __qtreewidgetitem->setText(1, tr("OPTION_VALUE_COLUMN"));
+ __qtreewidgetitem->setText(0, tr("OPTION_NAME_COLUMN"));
+ myOptionTable->setHeaderItem(__qtreewidgetitem);
+ myOptionTable->setObjectName(QString("myOptionTable"));
+ myOptionTable->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
+ myOptionTable->setTabKeyNavigation(true);
+
+ gridLayout_4->addWidget(myOptionTable, 0, 0, 1, 2);
+
+ addBtn = new QPushButton(this);
+ addBtn->setObjectName(QString("addBtn"));
+
+ gridLayout_4->addWidget(addBtn, 1, 0, 1, 1);
+
+ horizontalSpacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
+
+ gridLayout_4->addItem(horizontalSpacer, 1, 1, 1, 1);
+
+ logGroupBox = new QGroupBox(this);
+ logGroupBox->setObjectName(QString("logGroupBox"));
+ gridLayout_2 = new QGridLayout(logGroupBox);
+ gridLayout_2->setObjectName(QString("gridLayout_2"));
+ gridLayout = new QGridLayout();
+ gridLayout->setObjectName(QString("gridLayout"));
+ workingDirectoryLabel = new QLabel(logGroupBox);
+ workingDirectoryLabel->setObjectName(QString("workingDirectoryLabel"));
+
+ gridLayout->addWidget(workingDirectoryLabel, 0, 0, 1, 1);
+
+ workingDirectoryLineEdit = new QLineEdit(logGroupBox);
+ workingDirectoryLineEdit->setObjectName(QString("workingDirectoryLineEdit"));
+
+ gridLayout->addWidget(workingDirectoryLineEdit, 0, 1, 1, 1);
+
+ workingDirectoryPushButton = new QPushButton(logGroupBox);
+ workingDirectoryPushButton->setObjectName(QString("workingDirectoryPushButton"));
+
+ gridLayout->addWidget(workingDirectoryPushButton, 0, 2, 1, 1);
+
+ verboseLevelLabel = new QLabel(logGroupBox);
+ verboseLevelLabel->setObjectName(QString("verboseLevelLabel"));
+
+ gridLayout->addWidget(verboseLevelLabel, 1, 0, 1, 1);
+
+ verboseLevelSpin = new QSpinBox(logGroupBox);
+ verboseLevelSpin->setObjectName(QString("verboseLevelSpin"));
+
+ gridLayout->addWidget(verboseLevelSpin, 1, 1, 1, 1);
+
+
+ gridLayout_2->addLayout(gridLayout, 0, 0, 1, 1);
+
+ horizontalLayout = new QHBoxLayout();
+ horizontalLayout->setObjectName(QString("horizontalLayout"));
+ logInFileCheck = new QCheckBox(logGroupBox);
+ logInFileCheck->setObjectName(QString("logInFileCheck"));
+ logInFileCheck->setChecked(true);
+
+ horizontalLayout->addWidget(logInFileCheck);
+
+ removeLogOnSuccessCheck = new QCheckBox(logGroupBox);
+ removeLogOnSuccessCheck->setObjectName(QString("removeLogOnSuccessCheck"));
+ removeLogOnSuccessCheck->setChecked(true);
+
+ horizontalLayout->addWidget(removeLogOnSuccessCheck);
+
+
+ gridLayout_2->addLayout(horizontalLayout, 1, 0, 1, 1);
+
+ keepWorkingFilesCheck = new QCheckBox(logGroupBox);
+ keepWorkingFilesCheck->setObjectName(QString("keepWorkingFilesCheck"));
+ keepWorkingFilesCheck->setAutoExclusive(false);
+
+ gridLayout_2->addWidget(keepWorkingFilesCheck, 2, 0, 1, 1);
+
+
+ gridLayout_4->addWidget(logGroupBox, 3, 0, 1, 2);
+
+
+ // retranslateUi(this);
+
+ // QMetaObject::connectSlotsByName(this);
+
+}
+void MgAdaptAdvWidget::_onWorkingDirectoryPushButton()
+{
+ QString aDirName=QFileDialog::getExistingDirectory ();
+ if (!(aDirName.isEmpty()))workingDirectoryLineEdit->setText(aDirName);
+}
+void MgAdaptAdvWidget::onMeshDimChanged(ADAPTATION_MODE aMode)
+{
+ /* default adaptation mode
+ * assume that if meshDim == 2 -->adaptation surface
+ * if meshDim == 3 and if there is not 2D mesh -->VOLUME
+ * else BOTH
+ */
+
+ QString adaptation("adaptation"), value;
+ switch(aMode)
+ {
+ case ADAPTATION_MODE::SURFACE:
+ {
+ value ="surface";
+ setOptionValue(adaptation, value);
+ break;
+ }
+ case ADAPTATION_MODE::BOTH :
+ {
+ value = "both";
+ setOptionValue(adaptation, value);
+ break;
+ }
+ case ADAPTATION_MODE::VOLUME :
+ {
+ value = "volume";
+ setOptionValue(adaptation, value);
+ break;
+ }
+ }
+}
+void MgAdaptAdvWidget::setOptionValue(QString& option, QString& value)
+{
+
+ std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(option);
+ if (it != optionTreeWidgetItem.end())
+ {
+ it->second->setText( 0, tr( option.toLatin1().constData() ));
+ it->second->setText( 1, tr( value.toLatin1().constData() ));
+ it->second->setCheckState( 0, Qt::Checked );
+ it->second->setData( NAME_COL, PARAM_NAME, option );
+ myOptionTable->editItem( it->second, NAME_COL );
+ }
+}
+namespace
+{
+bool isEditable( const QModelIndex& index )
+{
+ return index.isValid() &&
+ index.flags() & Qt::ItemIsEditable &&
+ index.flags() & Qt::ItemIsEnabled &&
+ ( !index.data( Qt::UserRole + 1 ).isValid() || index.data( Qt::UserRole + 1 ).toInt() != 0 );
+}
+}
+
+MgAdaptAdvWidgetTreeWidget::MgAdaptAdvWidgetTreeWidget( QWidget* parent )
+ : QTreeWidget( parent )
+{
+}
+
+QModelIndex MgAdaptAdvWidgetTreeWidget::moveCursor( CursorAction action, Qt::KeyboardModifiers modifiers )
+{
+ QModelIndex current = currentIndex();
+ int column = current.column();
+ if ( action == MoveNext ) {
+ if ( column < columnCount()-1 ) {
+ QModelIndex next = current.sibling( current.row(), column+1 );
+ if ( isEditable( next ) )
+ return next;
+ }
+ else {
+ QModelIndex next = current.sibling( current.row()+1, 0 );
+ if ( isEditable( next ) )
+ return next;
+ }
+ }
+ else if ( action == MovePrevious ) {
+ if ( column == 0 ) {
+ QModelIndex next = current.sibling( current.row()-1, columnCount()-1 );
+ if ( isEditable( next ) )
+ return next;
+ }
+ else {
+ QModelIndex next = current.sibling( current.row(), column-1 );
+ if ( isEditable( next ) )
+ return next;
+ }
+ }
+ return QTreeWidget::moveCursor( action, modifiers );
+}
+
+void MgAdaptAdvWidgetTreeWidget::keyPressEvent( QKeyEvent* e )
+{
+ switch ( e->key() ) {
+ case Qt::Key_F2:
+ {
+ QModelIndex index = currentIndex();
+ if ( !isEditable( index ) ) {
+ for ( int i = 0; i < columnCount(); i++ ) {
+ QModelIndex sibling = index.sibling( index.row(), i );
+ if ( isEditable( sibling ) ) {
+ if ( !edit( sibling, EditKeyPressed, e ) )
+ e->ignore();
+ }
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ QTreeWidget::keyPressEvent( e );
+}
+
+
+// =======================================================================
+// renvoie le medId associe au fichier Med apres ouverture
+// =======================================================================
+med_idt OuvrirFichier(QString aFile)
+{
+ med_idt medIdt = MEDfileOpen(aFile.toStdString().c_str(),MED_ACC_RDONLY);
+ if (medIdt <0)
+ {
+ QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
+ QObject::tr("MG_ADAPT_MED_FILE_1") );
+ }
+ return medIdt;
+}
+
+// ======================================================
+// ========================================================
+QString lireNomMaillage(QString aFile, med_int& meshdim)
+{
+ QString nomMaillage = QString::null ;
+ int erreur = 0 ;
+ med_idt medIdt ;
+
+ // Ouverture du fichier
+ medIdt = OuvrirFichier(aFile);
+ if ( medIdt < 0 )
+ {
+ erreur = 1 ;
+ return nomMaillage;
+ }
+ med_int numberOfMeshes = MEDnMesh(medIdt) ;
+ if (numberOfMeshes == 0 )
+ {
+ QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
+ QObject::tr("MG_ADAPT_MED_FILE_2") );
+ erreur = 2 ;
+ return nomMaillage;
+ }
+ if (numberOfMeshes > 1 )
+ {
+ QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
+ QObject::tr("MG_ADAPT_MED_FILE_3") );
+ erreur = 3 ;
+ return nomMaillage;
+ }
+
+ nomMaillage = lireNomMaillage2(medIdt,1, meshdim);
+ // Fermeture du fichier
+ if ( medIdt > 0 ) MEDfileClose(medIdt);
+
+ return nomMaillage;
+}
+
+// =======================================================================
+// =======================================================================
+QString lireNomMaillage2(med_idt medIdt,int meshId, med_int& meshdim )
+{
+ QString NomMaillage=QString::null;
+ char meshname[MED_NAME_SIZE+1];
+ med_int spacedim;
+ med_mesh_type meshtype;
+ char descriptionription[MED_COMMENT_SIZE+1];
+ char dtunit[MED_SNAME_SIZE+1];
+ med_sorting_type sortingtype;
+ med_int nstep;
+ med_axis_type axistype;
+ int naxis = MEDmeshnAxis(medIdt,1);
+ char *axisname=new char[naxis*MED_SNAME_SIZE+1];
+ char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
+ med_err aRet = MEDmeshInfo(medIdt,
+ meshId,
+ meshname,
+ &spacedim,
+ &meshdim,
+ &meshtype,
+ descriptionription,
+ dtunit,
+ &sortingtype,
+ &nstep,
+ &axistype,
+ axisname,
+ axisunit);
+
+ if ( aRet < 0 ) {
+ QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"), \
+ QObject::tr("MG_ADAPT_MED_FILE_4") );
+ }
+ else {
+ NomMaillage=QString(meshname);
+ }
+
+ delete[] axisname ;
+ delete[] axisunit ;
+
+ return NomMaillage;
+}
+
+
+
+// =======================================================================
+std::map<QString, int> GetListeChamps(QString aFile, bool errorMessage)
+// =======================================================================
+{
+// Il faut voir si plusieurs maillages
+
+ MESSAGE("GetListeChamps");
+ std::map<QString, int> ListeChamp ;
+
+ med_err erreur = 0 ;
+ med_idt medIdt ;
+
+ while ( erreur == 0 )
+ {
+ // Ouverture du fichier
+ SCRUTE(aFile.toStdString());
+ medIdt = OuvrirFichier(aFile);
+ if ( medIdt < 0 )
+ {
+ erreur = 1 ;
+ break ;
+ }
+ // Lecture du nombre de champs
+ med_int ncha = MEDnField(medIdt) ;
+ if (ncha < 1 )
+ {
+ if(errorMessage)
+ {
+ QMessageBox::critical( 0, QObject::tr("_ERROR"),
+ QObject::tr("HOM_MED_FILE_5") );
+ }
+ erreur = 2 ;
+ break ;
+ }
+ // Lecture des caracteristiques des champs
+ for (int i=0; i< ncha; i++)
+ {
+// Lecture du nombre de composantes
+ med_int ncomp = MEDfieldnComponent(medIdt,i+1);
+// Lecture du type du champ, des noms des composantes et du nom de l'unite
+ char nomcha [MED_NAME_SIZE+1];
+ char meshname[MED_NAME_SIZE+1];
+ char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
+ char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
+ char dtunit[MED_SNAME_SIZE+1];
+ med_bool local;
+ med_field_type typcha;
+ med_int nbofcstp;
+ erreur = MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) ;
+ free(comp);
+ free(unit);
+ if ( erreur < 0 )
+ {
+ if(errorMessage)
+ {
+ QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
+ QObject::tr("MG_ADAPT_MED_FILE_6") );
+ }
+ break ;
+ }
+
+ ListeChamp.insert(std::pair<QString, int> (QString(nomcha), nbofcstp));
+
+ }
+ break ;
+ }
+ // Fermeture du fichier
+ if ( medIdt > 0 ) MEDfileClose(medIdt);
+
+ return ListeChamp;
+}
+
+std::string remove_extension(const std::string& filename) {
+ size_t lastdot = filename.find_last_of(".");
+ if (lastdot == std::string::npos) return filename;
+ return filename.substr(0, lastdot);
+}
+
+
--- /dev/null
+// Copyright (C) 2011-2020 CEA/DEN, EDF R&D\r
+//\r
+// This library is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU Lesser General Public\r
+// License as published by the Free Software Foundation; either\r
+// version 2.1 of the License, or (at your option) any later version.\r
+//\r
+// This library is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+// Lesser General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU Lesser General Public\r
+// License along with this library; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+//\r
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com\r
+//\r
+\r
+// SMESH SMESHGUI : GUI for the adaptation in the SMESH component\r
+// File : MG_ADAPTGUI.hxx\r
+//\r
+#ifndef MG_ADAPTGUI_HXX\r
+#define MG_ADAPTGUI_HXX\r
+\r
+#include <set>\r
+// SMESH includes\r
+\r
+// Qt includes\r
+#include <QDialog>\r
+#include <QTreeWidget>\r
+#include<QItemDelegate>\r
+\r
+#include "LightApp_DataOwner.h"\r
+#include "SalomeApp_Application.h"\r
+#include <SALOMEconfig.h>\r
+#include <SALOME_ListIO.hxx>\r
+#include "SalomeApp_Module.h"\r
+#include "SalomeApp_Study.h"\r
+#include <med.h>\r
+#include <map>\r
+\r
+\r
+// model\r
+\r
+\r
+#include "MG_ADAPT.hxx"\r
+\r
+class SUIT_ViewWindow;\r
+class SUIT_Desktop;\r
+class SUIT_Study;\r
+class SUIT_ResourceMgr;\r
+\r
+class CAM_Module;\r
+\r
+class SALOMEDSClient_Study;\r
+class SALOMEDSClient_SObject;\r
+\r
+class SalomeApp_Study;\r
+class SalomeApp_Module;\r
+class LightApp_SelectionMgr;\r
+\r
+\r
+class QButtonGroup;\r
+class QLineEdit;\r
+class QGroupBox;\r
+class QRadioButton;\r
+class QLabel;\r
+class QCheckBox;\r
+class QGridLayout;\r
+class QTabWidget;\r
+class QDoubleSpinBox;\r
+class QSpinBox;\r
+class QTreeWidget;\r
+class QTreeWidgetItem;\r
+class QSpacerItem;\r
+class QHBoxLayout;\r
+class QItemDelegate;\r
+class QComboBox;\r
+\r
+// IDL includes\r
+#include <SALOMEconfig.h>\r
+\r
+class SVTK_ViewWindow;\r
+class SVTK_Selector;\r
+class SMESHGUI_MgAdaptDlg;\r
+class SMESHGUI_MgAdaptArguments;\r
+class SMESHGUI_SpinBox;\r
+class MgAdaptAdvWidgetTreeWidget;\r
+class MgAdaptAdvWidget;\r
+class MgAdapt;\r
+class QHeaderView;\r
+class QFileDialog;\r
+\r
+\r
+std::map<QString, int> GetListeChamps(QString aFile, bool errorMessage = true);\r
+QString lireNomMaillage(QString aFile, med_int& meshDim);\r
+QString lireNomMaillage2(med_idt medIdt,int meshId, med_int& meshDim);\r
+med_idt OuvrirFichier(QString aFile);\r
+std::string remove_extension(const std::string& filename);\r
+\r
+\r
+enum ADAPTATION_MODE{
+ SURFACE, // surface adaption when meshDim == 2\r
+ VOLUME, // \r
+ BOTH
+};\r
+//=================================================================================\r
+// class : SMESHGUI_MgAdaptDlg\r
+// purpose :\r
+//=================================================================================\r
+class SMESHGUI_MgAdaptDlg : public QDialog\r
+{\r
+ Q_OBJECT;\r
+public:\r
+ //! Property type\r
+ enum Mode { Arguments, AdvancedOptions};\r
+ SMESHGUI_MgAdaptDlg( SalomeApp_Module*, MgAdapt*, QWidget* parent= 0,bool isCreation = true );\r
+ ~SMESHGUI_MgAdaptDlg();\r
+\r
+ void buildDlg();\r
+ void reject();\r
+ bool checkParams(QString& msg) ;\r
+ void setModel(MgAdapt*);\r
+ MgAdapt* getModel() const;\r
+\r
+public slots:\r
+\r
+protected slots:\r
+\r
+ virtual bool clickOnApply();\r
+private slots:\r
+ virtual void clickOnHelp();\r
+ virtual void clickOnOk();\r
+protected :\r
+\r
+ SMESHGUI_MgAdaptArguments* myArgs;\r
+ MgAdaptAdvWidget* myAdvOpt;\r
+ bool readParamsFromHypo( ) const ;\r
+ bool readParamsFromWidgets( ) ;\r
+ bool storeParamsToHypo( const MgAdaptHypothesisData& ) const;\r
+\r
+private:\r
+\r
+\r
+ SalomeApp_Module* mySMESHGUI; /* Current SMESHGUI object */\r
+ QTabWidget* myTabWidget;\r
+\r
+\r
+ MgAdaptHypothesisData* myData;\r
+ MgAdapt* model;\r
+\r
+};\r
+\r
+class SMESHGUI_MgAdaptArguments : public QWidget\r
+{\r
+ Q_OBJECT;\r
+public:\r
+ //! Property type\r
+ enum Mode { Mesh, Browser};\r
+ enum SIZEMAP { Local, Background, Constant};\r
+ SMESHGUI_MgAdaptArguments( QWidget* parent);\r
+ ~SMESHGUI_MgAdaptArguments();\r
+ void setMode( const Mode, const SIZEMAP );\r
+ med_int getMeshDim() const;\r
+\r
+ QString* myFileInDir;\r
+ QString* myFileOutDir;\r
+ QString* myFileSizeMapDir;\r
+ QGroupBox* aMeshIn ;\r
+ QRadioButton* aMedfile;\r
+ QRadioButton* aBrowser ;\r
+ QLineEdit* aBrowserObject;\r
+ QPushButton* selectMedFilebutton ;\r
+ QSpacerItem* hspacer;\r
+ QLineEdit* selectMedFileLineEdit ;\r
+ QButtonGroup* meshInGroup ;\r
+ QGridLayout* meshIn ;\r
+\r
+ QGroupBox* aMeshOut ;\r
+ QLabel* meshName;\r
+ QLineEdit* meshNameLineEdit;\r
+ QSpacerItem* secondHspacer;\r
+ QCheckBox* medFileCheckBox;\r
+ QPushButton* selectOutMedFilebutton;\r
+ QLineEdit* selectOutMedFileLineEdit;\r
+ QSpacerItem* thirdHspacer;\r
+ QCheckBox* publishOut;\r
+ QGridLayout* meshOut ;\r
+\r
+ QGroupBox* sizeMapDefinition ;\r
+ QRadioButton* localButton;\r
+ QRadioButton* backgroundButton ;\r
+ QRadioButton* constantButton ;\r
+ QLabel* medFileBackground;\r
+ QPushButton* selectMedFileBackgroundbutton;\r
+ QLineEdit* selectMedFileBackgroundLineEdit;\r
+ QLabel* valueLabel;\r
+ QDoubleSpinBox* dvalue;\r
+ QButtonGroup* sizeMapDefGroup ;\r
+ QGridLayout* sizeMapDefGroupLayout;\r
+\r
+\r
+ QGroupBox* sizeMapField;\r
+ QLabel* fieldName;\r
+ QComboBox* fieldNameCmb;\r
+ QRadioButton* noTimeStep;\r
+ QRadioButton* lastTimeStep ;\r
+ QRadioButton* chosenTimeStep;\r
+ QLabel* timeStepLabel;\r
+ QSpinBox* timeStep;\r
+ QLabel* rankLabel;\r
+ QSpinBox* rankSpinBox;\r
+ QButtonGroup* timeStepGroup;\r
+ QGridLayout* sizeMapFieldGroupLayout;\r
+\r
+signals:\r
+ void updateSelection();\r
+ void toExportMED(const char *);\r
+ void meshDimSignal(ADAPTATION_MODE aMode);\r
+public slots:\r
+\r
+protected slots:\r
+\r
+private slots:\r
+ void modeChanged( int);\r
+ void sizeMapDefChanged(int);\r
+ void timeStepGroupChanged(int timeStepType, bool disableOther = false, int max = 0);\r
+ void onSelectMedFilebuttonClicked();\r
+ void clear();\r
+ void onMedFileCheckBox(int);\r
+ void onPublishOut(int);\r
+ void onSelectOutMedFilebutton();\r
+ void onSelectMedFileBackgroundbutton();\r
+ void onLocalSelected(QString);\r
+ void onNoTimeStep(bool disableOther = false);\r
+ void onLastTimeStep(bool disableOther = false);\r
+ void onChosenTimeStep(bool disableOther = false, int max = 0);\r
+\r
+private:\r
+\r
+ QString getMedFileName(bool avertir);\r
+ LightApp_SelectionMgr* selMgr ;\r
+ med_int meshDim;\r
+ std::map<QString, int> myFieldList;\r
+\r
+\r
+};\r
+enum {\r
+ OPTION_ID_COLUMN = 0,\r
+ OPTION_TYPE_COLUMN,\r
+ OPTION_NAME_COLUMN = 0,\r
+ OPTION_VALUE_COLUMN,\r
+ NB_COLUMNS,\r
+};\r
+\r
+//////////////////////////////////////////\r
+// MgAdaptAdvWidget\r
+//////////////////////////////////////////\r
+class MgAdaptAdvWidget : public QWidget\r
+{\r
+ Q_OBJECT\r
+\r
+public:\r
+ MgAdaptAdvWidget( QWidget* = 0, std::vector <std::string> * = nullptr, Qt::WindowFlags = 0 );\r
+ ~MgAdaptAdvWidget();\r
+ std::vector < std::string > * myOptions;\r
+ QGridLayout *gridLayout_4;\r
+ MgAdaptAdvWidgetTreeWidget *myOptionTable;\r
+ QPushButton *addBtn;\r
+ QSpacerItem *horizontalSpacer;\r
+ QGroupBox *logGroupBox;\r
+ QGridLayout *gridLayout_2;\r
+ QGridLayout *gridLayout;\r
+ QLabel *workingDirectoryLabel;\r
+ QLineEdit *workingDirectoryLineEdit;\r
+ QPushButton *workingDirectoryPushButton;\r
+ QLabel *verboseLevelLabel;\r
+ QSpinBox *verboseLevelSpin;\r
+ QHBoxLayout *horizontalLayout;\r
+ QCheckBox *logInFileCheck;\r
+ QCheckBox *removeLogOnSuccessCheck;\r
+ QCheckBox *keepWorkingFilesCheck;\r
+\r
+ void AddOption( const char* name_value_type, bool isCustom = false );\r
+ void GetOptionAndValue( QTreeWidgetItem * tblRow, QString& option, QString& value, bool& dflt );\r
+ void setupWidget();\r
+public slots:\r
+\r
+ void onAddOption();\r
+ void itemChanged(QTreeWidgetItem * tblRow, int column);\r
+ void onMeshDimChanged(ADAPTATION_MODE aMode);\r
+private slots:\r
+ void _onWorkingDirectoryPushButton();\r
+private:\r
+ void setOptionValue(QString& option, QString& value);\r
+ std::map<QString, QTreeWidgetItem *> optionTreeWidgetItem;\r
+ \r
+ QTreeWidgetItem* getNewQTreeWidgetItem(QTreeWidget* table, const char* option, QString& name, bool isCustom);\r
+\r
+};\r
+\r
+enum { EDITABLE_ROLE = Qt::UserRole + 1, PARAM_NAME,\r
+ NAME_COL = 0, VALUE_COL\r
+ };\r
+\r
+\r
+\r
+class ItemDelegate: public QItemDelegate\r
+{\r
+public:\r
+\r
+ ItemDelegate(QObject* parent=0): QItemDelegate(parent) {}\r
+ QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const;\r
+};\r
+\r
+class MgAdaptAdvWidgetTreeWidget : public QTreeWidget\r
+{\r
+ Q_OBJECT\r
+public:\r
+ MgAdaptAdvWidgetTreeWidget( QWidget* );\r
+\r
+protected:\r
+ QModelIndex moveCursor( CursorAction, Qt::KeyboardModifiers );\r
+ void keyPressEvent( QKeyEvent* );\r
+};\r
+\r
+\r
+#endif // MG_ADAPTGUI_HXX\r
${PROJECT_SOURCE_DIR}/src/Controls
${PROJECT_SOURCE_DIR}/src/SMESHClient
${PROJECT_SOURCE_DIR}/src/MEDWrapper
+ ${PROJECT_SOURCE_DIR}/src/ADAPT
${PROJECT_SOURCE_DIR}/src/ADAPTGUI
${PROJECT_BINARY_DIR}
${PROJECT_BINARY_DIR}/idl
${PROJECT_BINARY_DIR}/src/ADAPTGUI
+ ${PROJECT_BINARY_DIR}/src/ADAPT
${MEDCOUPLING_INCLUDE_DIRS}
)
SMESHGUI_PreVisualObj.h
SMESHGUI_AdaptDlg.h
SMESHGUI_MG_ADAPTDRIVER.h
- MG_ADAPTGUI.hxx # to replace in ../ADAPTGUI/
+ #~MG_ADAPTGUI.hxx # to replace in ../ADAPTGUI/
)
# header files / no moc processing
SMESHGUI_FileValidator.h
SMESHGUI_SelectionProxy.h
SMESH_SMESHGUI.hxx
- MG_ADAPT.hxx # to replace in ../ADAPT/
+ #~MG_ADAPT.hxx # to replace in ../ADAPT/
)
# header files / to install
SMESHGUI_IdPreview.cxx
SMESHGUI_AdaptDlg.cxx
SMESHGUI_MG_ADAPTDRIVER.cxx
- MG_ADAPTGUI.cxx # to replace in ../ADAPTGUI/
- MG_ADAPT.cxx # to replace in ../ADAPT/
+ #~MG_ADAPTGUI.cxx # to replace in ../ADAPTGUI/
+ #MG_ADAPT.cxx
)
# sources / to compile
+++ /dev/null
-// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/
-// file : MG_ADAPT.cxx
-
-#include "MG_ADAPT.hxx"
-
-#include "MeshFormatReader.hxx"
-#include "MeshFormatWriter.hxx"
-#include "MEDFileMesh.hxx"
-#include "MCAuto.hxx"
-#include "MEDFileData.hxx"
-#include "MEDFileField.hxx"
-#include "MEDCouplingFieldDouble.hxx"
-
-#include <utilities.h>
-#include <iostream>
-#include <unistd.h>
-#include <TCollection_AsciiString.hxx>
-#include <cstring>
-#include <cstdlib>
-#include <boost/filesystem.hpp>
-
-static std::string removeFile(std::string fileName, int& notOk)
-{
- std::string errStr;
- notOk = std::remove(fileName.c_str());
- if (notOk) errStr = ToComment(" \n error while removing file : ")
- << fileName;
- else errStr= ToComment("\n file : ")<< fileName << " succesfully deleted! \n ";
-
- return errStr;
-}
-namespace
-{
-struct GET_DEFAULT // struct used to get default value from GetOptionValue()
-{
- bool isDefault;
- operator bool* () {
- return &isDefault;
- }
-};
-}
-
-//----------------------------------------------------------------------------------------
-MgAdapt::MgAdapt()
-{
- data = new MgAdaptHypothesisData();
- data->myInMeshName = "";
- data->fromMedFile = defaultFromMedFile();
- data->myFileInDir = defaultWorkingDirectory();
- data->myMeshFileIn = "";
- data->myFileOutDir = defaultWorkingDirectory();
- data->myOutMeshName = "";
- data->myMeshFileOut = "";
- data->myMeshOutMed = defaultMeshOutMed();
- data->myPublish = defaultPublish();
- data->myUseLocalMap = defaultUseLocalMap();
- data->myUseBackgroundMap = defaultUseBackgroundMap();
- data->myFileSizeMapDir = defaultWorkingDirectory();
- data->myMeshFileBackground = "";
- data->myUseConstantValue = defaultUseConstantValue();
- data->myConstantValue = 0.0;
- data->myFieldName = "";
- data->myUseNoTimeStep = defaultUseNoTimeStep();
- data->myUseLastTimeStep = defaultUseLastTimeStep();
- data->myUseChosenTimeStep = defaultUseChosenTimeStep();
- data->myTimeStep = -2;
- data->myRank = -2;
- data->myWorkingDir = defaultWorkingDirectory();
- data->myLogFile = defaultLogFile();
- data->myVerboseLevel = defaultVerboseLevel();
- data->myPrintLogInFile = defaultPrintLogInFile();
- data->myKeepFiles = defaultKeepFiles();
- data->myRemoveLogOnSuccess = defaultRemoveLogOnSuccess();
-
- buildModel();
- setAll();
-}
-MgAdapt::MgAdapt(MgAdaptHypothesisData* myData)
-{
- data = new MgAdaptHypothesisData();
- setData(myData);
- buildModel();
-}
-
-MgAdapt::MgAdapt( const MgAdapt& copy)
-{
-
- data = new MgAdaptHypothesisData();
- MgAdaptHypothesisData *copyData = copy.getData();
- copyMgAdaptHypothesisData(copyData);
- setAll();
-
- this->_option2value = copy._option2value;
- this->_customOption2value = copy._customOption2value;
- this->_defaultOptionValues = copy._defaultOptionValues;
- this->_doubleOptions = copy._doubleOptions;
- this->_charOptions = copy._charOptions;
- this->_boolOptions = copy._boolOptions;
-
-}
-
-
-
-//-----------------------------------------------------------------------------------------
-MgAdapt::~MgAdapt()
-{
-
- delete data;
-
-}
-void MgAdapt::buildModel()
-{
-
- const char* boolOptionNames[] = { "compute_ridges", // yes
- "" // mark of end
- };
- // const char* intOptionNames[] = { "max_number_of_errors_printed", // 1
- // "max_number_of_threads", // 4
- // "" // mark of end
- // };
- const char* doubleOptionNames[] = { "max_memory", // 0
- "" // mark of end
- };
- const char* charOptionNames[] = { "components", // "yes"
- "adaptation", // both
- "" // mark of end
- };
-
- int i = 0;
- while (boolOptionNames[i][0])
- {
- _boolOptions.insert( boolOptionNames[i] );
- _option2value[boolOptionNames[i++]].clear();
- }
- // i = 0;
- // while (intOptionNames[i][0])
- // _option2value[intOptionNames[i++]].clear();
-
- i = 0;
- while (doubleOptionNames[i][0]) {
- _doubleOptions.insert(doubleOptionNames[i]);
- _option2value[doubleOptionNames[i++]].clear();
- }
- i = 0;
- while (charOptionNames[i][0]) {
- _charOptions.insert(charOptionNames[i]);
- _option2value[charOptionNames[i++]].clear();
- }
-
- // default values to be used while MG-Adapt
-
- _defaultOptionValues["adaptation" ] = "both";
- _defaultOptionValues["components" ] = "outside components";
- _defaultOptionValues["compute_ridges" ] = "yes";
- _defaultOptionValues["max_memory" ] = ToComment(defaultMaximumMemory());
-}
-
-//=============================================================================
-TOptionValues MgAdapt::getOptionValues() const
-{
- TOptionValues vals;
- TOptionValues::const_iterator op_val = _option2value.begin();
- for ( ; op_val != _option2value.end(); ++op_val )
- vals.insert( make_pair( op_val->first, getOptionValue( op_val->first, GET_DEFAULT() )));
-
- return vals;
-}
-
-std::vector <std::string> MgAdapt::getOptionValuesStrVec() const
-{
- std::vector <std::string> vals;
- TOptionValues::const_iterator op_val = _option2value.begin();
- for ( ; op_val != _option2value.end(); ++op_val )
- vals.push_back(op_val->first+":"+getOptionValue( op_val->first, GET_DEFAULT() ));
-
- return vals;
-}
-
-std::vector <std::string> MgAdapt::getCustomOptionValuesStrVec() const
-{
- std::vector <std::string> vals;
- TOptionValues::const_iterator op_val;
- for ( op_val = _customOption2value.begin(); op_val != _customOption2value.end(); ++op_val )
- {
- vals.push_back(op_val->first+":"+getOptionValue( op_val->first, GET_DEFAULT() ));
- }
- return vals;
-}
-const TOptionValues& MgAdapt::getCustomOptionValues() const
-{
- return _customOption2value;
-}
-void MgAdapt::setData(MgAdaptHypothesisData* myData)
-{
- copyMgAdaptHypothesisData(myData);
- setAll();
-}
-MgAdaptHypothesisData* MgAdapt::getData() const
-{
- return data;
-}
-void MgAdapt::setMedFileIn(std::string fileName)
-{
- medFileIn = fileName;
-}
-
-std::string MgAdapt::getMedFileIn()
-{
- return medFileIn;
-}
-
-void MgAdapt::setMedFileOut(std::string fileOut)
-{
- medFileOut = fileOut;
-}
-
-std::string MgAdapt::getMedFileOut()
-{
- return medFileOut;
-}
-void MgAdapt::setMeshOutMed(bool mybool)
-{
- meshOutMed = mybool;
-}
-bool MgAdapt::getMeshOutMed()
-{
- return meshOutMed;
-}
-void MgAdapt::setPublish(bool mybool)
-{
- publish = mybool;
-}
-bool MgAdapt::getPublish()
-{
- return publish;
-}
-void MgAdapt::setFieldName(std::string myFieldName)
-{
- fieldName = myFieldName;
-}
-std::string MgAdapt::getFieldName()
-{
- return fieldName;
-}
-void MgAdapt::setTimeStep(int time)
-{
- timeStep = time;
-}
-int MgAdapt::getTimeStep() const
-{
- return timeStep;
-}
-
-void MgAdapt::setRankTimeStep(int time, int myRank)
-{
- timeStep = time;
- rank = myRank;
-}
-
-int MgAdapt::getRank()
-{
- return rank;
-}
-void MgAdapt::setUseLocalMap(bool myLocal)
-{
- useLocalMap = myLocal;
-
-}
-bool MgAdapt::getUseLocalMap()
-{
- return useLocalMap;
-}
-
-void MgAdapt::setUseBackgroundMap(bool bckg)
-{
- useBackgroundMap = bckg;
-
-}
-bool MgAdapt::getUseBackgroundMap()
-{
- return useBackgroundMap;
-}
-
-void MgAdapt::setUseConstantValue(bool cnst)
-{
- useConstantValue = cnst;
-
-}
-bool MgAdapt::getUseConstantValue()
-{
- return useConstantValue;
-}
-void MgAdapt::setLogFile(std::string myLogFile)
-{
- logFile = myLogFile;
-}
-std::string MgAdapt::getLogFile()
-{
- return logFile;
-}
-void MgAdapt::setVerbosityLevel(int verboLevel)
-{
- verbosityLevel = verboLevel;
-}
-int MgAdapt::getVerbosityLevel()
-{
- return verbosityLevel;
-}
-void MgAdapt::setRemoveOnSuccess(bool rmons)
-{
- removeOnSuccess = rmons;
-}
-bool MgAdapt::getRemoveOnSuccess()
-{
- return removeOnSuccess;
-}
-void MgAdapt::setSizeMapFile(std::string mapFile)
-{
- sizeMapFile = mapFile;
-}
-std::string MgAdapt::getSizeMapFile()
-{
- return sizeMapFile;
-}
-
-void MgAdapt::setMeshName(std::string name)
-{
- meshName = name;
-}
-std::string MgAdapt::getMeshName()
-{
- return meshName;
-}
-void MgAdapt::setMeshNameOut(std::string name)
-{
- meshNameOut = name;
-}
-std::string MgAdapt::getMeshNameOut()
-{
- return meshNameOut;
-}
-void MgAdapt::setFromMedFile(bool mybool)
-{
- fromMedFile = mybool;
-}
-bool MgAdapt::isFromMedFile()
-{
- return fromMedFile;
-}
-void MgAdapt::setConstantValue(double cnst)
-{
- constantValue = cnst;
-}
-double MgAdapt::getConstantValue() const
-{
- return constantValue;
-}
-
-void MgAdapt::setWorkingDir(std::string dir)
-{
- workingDir = dir;
-}
-std::string MgAdapt::getWorkingDir() const
-{
- return workingDir;
-}
-void MgAdapt::setKeepWorkingFiles(bool mybool)
-{
- toKeepWorkingFiles = mybool;
-}
-bool MgAdapt::getKeepWorkingFiles()
-{
- return toKeepWorkingFiles;
-}
-void MgAdapt::setPrintLogInFile(bool print)
-{
- printLogInFile = print;
-}
-bool MgAdapt::getPrintLogInFile()
-{
- return printLogInFile;
-}
-
-bool MgAdapt::setAll()
-{
-
- setFromMedFile(data->fromMedFile);
- std::string file;
- checkDirPath(data->myFileInDir);
- file = data->myFileInDir+data->myMeshFileIn;
- setMedFileIn(file);
- setMeshName(data->myInMeshName);
- setMeshNameOut(data->myOutMeshName);
- checkDirPath(data->myFileOutDir);
- std::string out = data->myFileOutDir+data->myMeshFileOut;
- setMedFileOut(out);
- setPublish(data->myPublish);
- setMeshOutMed(data->myMeshOutMed);
- setUseLocalMap(data->myUseLocalMap);
- setUseBackgroundMap(data->myUseBackgroundMap);
- setUseConstantValue(data->myUseConstantValue);
-
- std::string mapfile;
- if (useBackgroundMap)
- {
-
- checkDirPath(data->myFileSizeMapDir);
- mapfile = data->myFileSizeMapDir+data->myMeshFileBackground;
- setFieldName(data->myFieldName);
- }
- else if (useConstantValue)
- {
- setConstantValue(data->myConstantValue);
- }
- else
- {
- mapfile ="";
- setConstantValue(0.0);
- setFieldName(data->myFieldName);
-
- }
-
- setSizeMapFile(mapfile);
- med_int rank;
- med_int tmst;
- if (data->myUseNoTimeStep)
- {
- rank = MED_NO_IT;
- tmst = MED_NO_DT ;
- }
- else if (data->myUseLastTimeStep)
- {
- std::string fieldFile = useBackgroundMap ? sizeMapFile : medFileIn;
- getTimeStepInfos(fieldFile, tmst, rank);
- }
- else
- {
- rank = data->myRank;
- tmst = data->myTimeStep;
- }
- setRankTimeStep((int)tmst, (int)rank);
-
- /* Advanced options */
- setWorkingDir(data->myWorkingDir);
- checkDirPath(data->myWorkingDir);
- setLogFile(data->myWorkingDir+defaultLogFile());
- setVerbosityLevel(data->myVerboseLevel);
- setRemoveOnSuccess(data->myRemoveLogOnSuccess);
- setPrintLogInFile(data->myPrintLogInFile);
- setKeepWorkingFiles(data->myKeepFiles);
-
- return true;
-}
-
-void MgAdapt::checkDirPath(std::string& dirPath)
-{
- const char lastChar = *dirPath.rbegin();
-#ifdef WIN32
- if(lastChar != '\\') dirPath+='\\';
-#else
- if(lastChar != '/') dirPath+='/';
-#endif
-}
-//=============================================================================
-void MgAdapt::setOptionValue(const std::string& optionName,
- const std::string& optionValue)
-throw (std::invalid_argument)
-{
- TOptionValues::iterator op_val = _option2value.find(optionName);
- if (op_val == _option2value.end())
- {
- op_val = _customOption2value.find( optionName );
- _customOption2value[ optionName ] = optionValue;
- return;
- }
-
- if (op_val->second != optionValue)
- {
-
- std::string lowerOptionValue = toLowerStr(optionValue);
- const char* ptr = lowerOptionValue.c_str();
- // strip white spaces
- while (ptr[0] == ' ')
- ptr++;
- int i = strlen(ptr);
- while (i != 0 && ptr[i - 1] == ' ')
- i--;
- // check value type
- bool typeOk = true;
- std::string typeName;
- if (i == 0) {
- // empty string
- } else if (_charOptions.count(optionName)) {
- // do not check strings
- } else if (_doubleOptions.count(optionName)) {
- // check if value is double
- toDbl(ptr, &typeOk);
- typeName = "real";
- } else if (_boolOptions.count(optionName)) {
- // check if value is bool
- toBool(ptr, &typeOk);
- typeName = "bool";
- } else {
- // check if value is int
- toInt(ptr, &typeOk);
- typeName = "integer";
- }
- if ( typeOk ) // check some specific values ?
- {
- }
- if ( !typeOk )
- {
- std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
- throw std::invalid_argument(msg);
- }
- std::string value( ptr, i );
- if ( _defaultOptionValues[ optionName ] == value )
- value.clear();
-
-
- op_val->second = value;
-
- }
-}
-//=============================================================================
-//! Return option value. If isDefault provided, it can be a default value,
-// then *isDefault == true. If isDefault is not provided, the value will be
-// empty if it equals a default one.
-std::string MgAdapt::getOptionValue(const std::string& optionName, bool* isDefault) const
-throw (std::invalid_argument)
-{
- TOptionValues::const_iterator op_val = _option2value.find(optionName);
- if (op_val == _option2value.end())
- {
- op_val = _customOption2value.find(optionName);
- if (op_val == _customOption2value.end())
- {
- std::string msg = "Unknown MG-Adapt option: <" + optionName + ">";
- throw std::invalid_argument(msg);
- }
- }
- std::string val = op_val->second;
- if ( isDefault ) *isDefault = ( val.empty() );
-
- if ( val.empty() && isDefault )
- {
- op_val = _defaultOptionValues.find( optionName );
- if (op_val != _defaultOptionValues.end())
- val = op_val->second;
- }
- return val;
-}
-//================================================================================
-/*!
- * \brief Converts a string to a real value
- */
-//================================================================================
-
-double MgAdapt::toDbl(const std::string& str, bool* isOk )
-throw (std::invalid_argument)
-{
- if ( str.empty() ) throw std::invalid_argument("Empty value provided");
-
- char * endPtr;
- double val = strtod(&str[0], &endPtr);
- bool ok = (&str[0] != endPtr);
-
- if ( isOk ) *isOk = ok;
-
- if ( !ok )
- {
- std::string msg = "Not a real value:'" + str + "'";
- throw std::invalid_argument(msg);
- }
- return val;
-}
-//================================================================================
-/*!
- * \brief Converts a string to a lower
- */
-//================================================================================
-std::string MgAdapt::toLowerStr(const std::string& str)
-{
- std::string s = str;
- for ( size_t i = 0; i <= s.size(); ++i )
- s[i] = tolower( s[i] );
- return s;
-}
-//================================================================================
-/*!
- * \brief Converts a string to a bool
- */
-//================================================================================
-
-bool MgAdapt::toBool(const std::string& str, bool* isOk )
-throw (std::invalid_argument)
-{
- std::string s = str;
- if ( isOk ) *isOk = true;
-
- for ( size_t i = 0; i <= s.size(); ++i )
- s[i] = tolower( s[i] );
-
- if ( s == "1" || s == "true" || s == "active" || s == "yes" )
- return true;
-
- if ( s == "0" || s == "false" || s == "inactive" || s == "no" )
- return false;
-
- if ( isOk )
- *isOk = false;
- else {
- std::string msg = "Not a Boolean value:'" + str + "'";
- throw std::invalid_argument(msg);
- }
- return false;
-}
-//================================================================================
-/*!
- * \brief Converts a string to a integer value
- */
-//================================================================================
-
-int MgAdapt::toInt(const std::string& str, bool* isOk )
-throw (std::invalid_argument)
-{
- if ( str.empty() ) throw std::invalid_argument("Empty value provided");
-
- char * endPtr;
- int val = (int)strtol( &str[0], &endPtr, 10);
- bool ok = (&str[0] != endPtr);
-
- if ( isOk ) *isOk = ok;
-
- if ( !ok )
- {
- std::string msg = "Not an integer value:'" + str + "'";
- throw std::invalid_argument(msg);
- }
- return val;
-}
-//=============================================================================
-bool MgAdapt::hasOptionDefined( const std::string& optionName ) const
-{
- bool isDefault = false;
- try
- {
- getOptionValue( optionName, &isDefault );
- }
- catch ( std::invalid_argument )
- {
- return false;
- }
- return !isDefault;
-}
-//================================================================================
-/*!
- * \brief Return command to run MG-Tetra mesher excluding file prefix (-f)
- */
-//================================================================================
-
-std::string MgAdapt::getCommandToRun(MgAdapt* hyp)
-{
- return hyp ? hyp->getCommandToRun() : ToComment("error with hypothesis!");
-}
-
-
-
-int MgAdapt::compute(std::string& errStr)
-{
- std::string cmd = getCommandToRun();
- int err = 0;
- execCmd( cmd.c_str(), err ); // run
-
- if ( err )
- {
- errStr = ToComment("system(mg-adapt.exe ...) command failed with error: ")
- << strerror( errno );
- }
- else
- {
- convertMeshFile(meshFormatOutputMesh, solFormatOutput);
- }
- //~if (!err) cleanUp();
- return err;
-}
-
-void MgAdapt::execCmd( const char* cmd, int& err)
-{
- err = 1;
- std::array <char, 128> buffer;
- std::streambuf* buf;
- outFileStream fileStream;
- if (printLogInFile)
- {
- fileStream.open(logFile);
- buf = fileStream.rdbuf();
- }
- else
- {
- buf = std::cout.rdbuf();
- }
- std::ostream logStream(buf);
-
- std::unique_ptr <FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose );
- if(!pipe)
- {
- throw std::runtime_error("popen() failed!");
- }
- while(fgets(buffer.data(), buffer.size(), pipe.get()) !=nullptr )
- {
- logStream<<buffer.data() ;
- }
- err = 0;
-}
-
-void MgAdapt::cleanUp()
-{
- int notOk;
- std::string errStr;
- if(removeOnSuccess) tmpFilesToBeDeleted.push_back(logFile);
-
- std::vector< std::string>::iterator it = tmpFilesToBeDeleted.begin();
- for (; it!=tmpFilesToBeDeleted.end(); ++it)
- {
- errStr=removeFile(*it, notOk);
- if (notOk)
- {
- appendMsgToLogFile(errStr);
- }
-
- }
-}
-
-void MgAdapt::appendMsgToLogFile(std::string& msg)
-{
- std::ofstream logStream;
- logStream.open(logFile, std::ofstream::out | std::ofstream::app);
- logStream<< msg;
- logStream.close();
-}
-//================================================================================
-/*!
- * \brief Return command to run MG-Tetra mesher excluding file prefix (-f)
- */
-//================================================================================
-
-std::string MgAdapt::getCommandToRun()
-{
- /*
- || return system command with args and options
- ||
- */
- std::string errStr;
- std::string cmd = getExeName();
- std::string meshIn(""), sizeMapIn(""), solFileIn("");
- convertMedFile(meshIn, solFileIn, sizeMapIn);
- if (!isFileExist(meshIn) || !isFileExist(solFileIn))
- {
- errStr = ToComment(" failed to find .mesh or .sol file from converter ")<< strerror( errno );
- return errStr;
- }
- tmpFilesToBeDeleted.push_back(meshIn);
- tmpFilesToBeDeleted.push_back(solFileIn);
- if(useBackgroundMap && !isFileExist(sizeMapIn))
- {
-
- errStr = ToComment(" failed to find .mesh size map file from converter ")<< strerror( errno );
- return errStr;
-
- }
-
-
- cmd+= " --in "+ meshIn;
- meshFormatOutputMesh = getFileName()+".mesh";
- cmd+= " --out "+ meshFormatOutputMesh;
- if (useLocalMap || useConstantValue) cmd+= " --sizemap "+ solFileIn;
- else // (useBackgroundMap)
- {
- cmd+= " --background_mesh "+ sizeMapIn ;
- cmd+= " --background_sizemap "+ solFileIn;
- tmpFilesToBeDeleted.push_back(sizeMapIn);
- }
- //~else
- //~{
- //~// constant value TODO
- //~}
- /* sizemap file is not adapted in case of only surface adaptation see MeshGems docs */
- std::string adapOp = "adaptation";
- std::string adpOpVal = getOptionValue(adapOp);
- std::string surfaceAdapt = "surface";
- if(surfaceAdapt != adpOpVal )
- {
- std::string solFileOut = getFileName()+".sol";
- cmd+= " --write_sizemap "+ solFileOut;
- solFormatOutput.push_back(solFileOut);
- }
- if (verbosityLevel != defaultVerboseLevel())
- {
-
- cmd+= " --verbose "+ ToComment(verbosityLevel);
- }
-
- std::string option, value;
- bool isDefault;
- const TOptionValues* options[] = { &_option2value, &_customOption2value };
- for ( int iOp = 0; iOp < 2; ++iOp )
- {
- TOptionValues::const_iterator o2v = options[iOp]->begin();
- for ( ; o2v != options[iOp]->end(); ++o2v )
- {
- option = o2v->first;
- value = getOptionValue( option, &isDefault );
-
- if ( isDefault )
- continue;
- if ( value.empty() )//value == NoValue() )
- {
- if ( _defaultOptionValues.count( option ))
- continue; // non-custom option with no value
- //value.clear();
- }
- if ( strncmp( "no", option.c_str(), 2 ) == 0 ) // options w/o values: --no_*
- {
- if ( !value.empty() && toBool( value ) == false )
- continue;
- value.clear();
- }
- if ( option[0] != '-' )
- cmd += " --";
- else
- cmd += " ";
- cmd += option + " " + value;
- }
- }
- //~}
-//~cmd+= " >"
-#ifdef WIN32
- cmd += " < NUL";
-#endif
-
- return cmd;
-}
-
-
-bool MgAdapt::isFileExist(std::string& fName) const
-{
-
- if ( fName.empty() )
- return false;
-
- boost::system::error_code err;
- bool res = boost::filesystem::exists( fName, err );
-
- return err ? false : res;
-}
-//=======================================================================
-//function : defaultMaximumMemory
-//=======================================================================
-
-#if defined(WIN32)
-#include <windows.h>
-#elif !defined(__APPLE__)
-#include <sys/sysinfo.h>
-#endif
-
-double MgAdapt::defaultMaximumMemory()
-{
-#if defined(WIN32)
- // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
- MEMORYSTATUSEX statex;
- statex.dwLength = sizeof (statex);
- long err = GlobalMemoryStatusEx (&statex);
- if (err != 0) {
- double totMB = (double)statex.ullAvailPhys / 1024. / 1024.;
- return (double)( 0.7 * totMB );
- }
-#elif !defined(__APPLE__)
- struct sysinfo si;
- long err = sysinfo( &si );
- if ( err == 0 ) {
- long ramMB = si.totalram * si.mem_unit / 1024 / 1024;
- return ( 0.7 * ramMB );
- }
-#endif
- return 1024;
-}
-
-
-//=======================================================================
-//function : defaultWorkingDirectory
-//=======================================================================
-
-std::string MgAdapt::defaultWorkingDirectory()
-{
- TCollection_AsciiString aTmpDir;
-
- char *Tmp_dir = getenv("SALOME_TMP_DIR");
- if(Tmp_dir != NULL) {
- aTmpDir = Tmp_dir;
- }
- else {
-#ifdef WIN32
- aTmpDir = TCollection_AsciiString("C:\\");
-#else
- aTmpDir = TCollection_AsciiString("/tmp/");
-#endif
- }
- return aTmpDir.ToCString();
-}
-//================================================================================
-/*!
- * \brief Return a unique file name
- */
-//================================================================================
-
-std::string MgAdapt::getFileName() const
-{
- std::string aTmpDir = workingDir;
- const char lastChar = *aTmpDir.rbegin();
-#ifdef WIN32
- if(lastChar != '\\') aTmpDir+='\\';
-#else
- if(lastChar != '/') aTmpDir+='/';
-#endif
-
- TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str();
- aGenericName += "MgAdapt_";
- aGenericName += getpid();
- aGenericName += "_";
- aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString());
-
- return aGenericName.ToCString();
-}
-//=======================================================================
-//function : defaultLogFile
-//=======================================================================
-
-std::string MgAdapt::defaultLogFile()
-{
- std::string alogFile("MG_ADAPT.log");
- return alogFile;
-}
-//=======================================================================
-//function : defaultUseConstantValue
-//=======================================================================
-
-bool MgAdapt::defaultUseConstantValue()
-{
- return false;
-}
-//=======================================================================
-//function : defaultUseNoTimeStep
-//=======================================================================
-
-bool MgAdapt::defaultUseNoTimeStep()
-{
- return true;
-}
-//=======================================================================
-//function : defaultRemoveLogOnSuccess
-//=======================================================================
-
-bool MgAdapt::defaultRemoveLogOnSuccess()
-{
- return true;
-}
-//=======================================================================
-//function : defaultPrintLogInFile
-//=======================================================================
-
-bool MgAdapt::defaultPrintLogInFile()
-{
- return false;
-}
-//=======================================================================
-//function : defaultUseChosenTimeStep
-//=======================================================================
-
-bool MgAdapt::defaultUseChosenTimeStep()
-{
- return false;
-}
-//=======================================================================
-//function : UseLastTimeStep
-//=======================================================================
-
-bool MgAdapt::defaultUseLastTimeStep()
-{
- return false;
-}
-//=======================================================================
-//function : defaultUseBackgroundMap
-//=======================================================================
-
-bool MgAdapt::defaultUseBackgroundMap()
-{
- return false;
-}
-//=======================================================================
-//function : defaultKeepFiles
-//=======================================================================
-
-bool MgAdapt::defaultKeepFiles()
-{
- return false;
-}
-//=======================================================================
-//function : defaultUseLocalMap
-//=======================================================================
-
-bool MgAdapt::defaultUseLocalMap()
-{
- return true;
-}
-//=======================================================================
-//function : defaultPublish
-//=======================================================================
-
-bool MgAdapt::defaultPublish()
-{
- return false;
-}
-//=======================================================================
-//function : defaultMeshOutMed
-//=======================================================================
-
-bool MgAdapt::defaultMeshOutMed()
-{
- return true;
-}
-//=======================================================================
-//function : defaultFromMedFile
-//=======================================================================
-
-bool MgAdapt::defaultFromMedFile()
-{
- return true;
-}
-//=======================================================================
-//function : defaultVerboseLevel
-//=======================================================================
-
-int MgAdapt::defaultVerboseLevel()
-{
- return 3;
-}
-std::string MgAdapt::getExeName()
-{
- return "mg-adapt.exe";
-}
-void MgAdapt::copyMgAdaptHypothesisData( MgAdaptHypothesisData* from)
-{
-
- data->myFileInDir = from->myFileInDir;
- data->myMeshFileIn = from->myMeshFileIn;
- data->myMeshFileBackground = from->myMeshFileBackground;
- data->myOutMeshName = from->myOutMeshName;
- data->myMeshFileOut = from->myMeshFileOut;
- data->myFileOutDir = from->myFileOutDir;
- data->myFileSizeMapDir = from->myFileSizeMapDir;
- data->myFieldName = from->myFieldName;
- data->fromMedFile = from->fromMedFile;
- data->myPublish = from->myPublish;
- data->myMeshOutMed = from->myMeshOutMed;
- data->myUseLocalMap = from->myUseLocalMap;
- data->myUseBackgroundMap = from->myUseBackgroundMap;
- data->myUseConstantValue = from->myUseConstantValue;
- data->myConstantValue = from->myConstantValue;
- data->myTimeStep = from->myTimeStep;
- data->myRank = from->myRank;
- data->myUseNoTimeStep = from->myUseNoTimeStep;
- data->myUseLastTimeStep = from->myUseLastTimeStep;
- data->myUseChosenTimeStep = from->myUseChosenTimeStep;
- data->myWorkingDir = from->myWorkingDir;
- data->myLogFile = from->myLogFile;
- data->myPrintLogInFile = from->myPrintLogInFile;
- data->myKeepFiles = from->myKeepFiles;
- data->myRemoveLogOnSuccess = from->myRemoveLogOnSuccess;
- data->myVerboseLevel = from->myVerboseLevel;
-
-}
-
-
-void MgAdapt::convertMedFile(std::string& meshFormatMeshFileName, std::string& solFormatFieldFileName, std::string& meshFormatsizeMapFile)
-{
-
- std::vector<std::string> fieldFileNames;
- MEDCoupling::MeshFormatWriter writer;
- MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = MEDCoupling::MEDFileData::New(medFileIn);
- MEDCoupling::MEDFileMeshes* meshes = mfd->getMeshes();
- MEDCoupling::MEDFileMesh* fileMesh = meshes->getMeshAtPos(0); // ok only one mesh in file!
- storeGroupsAndFams(fileMesh);
-
- MEDCoupling::MCAuto<MEDCoupling::MEDFileFields> fields = MEDCoupling::MEDFileFields::New();
- solFormatFieldFileName = getFileName();
- solFormatFieldFileName+=".sol";
- fieldFileNames.push_back(solFormatFieldFileName);
-
- if (useBackgroundMap)
- {
-
- meshFormatsizeMapFile = getFileName();
- meshFormatsizeMapFile += ".mesh";
- buildBackGroundMeshAndSolFiles(fieldFileNames, meshFormatsizeMapFile);
-
- }
- else if(useLocalMap)
- {
-
- MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS> fts = dynamic_cast<MEDCoupling::MEDFileFieldMultiTS *>( mfd->getFields()->getFieldWithName(fieldName) );
- MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeField1TS> f = fts->getTimeStep(timeStep, rank);
- MEDCoupling::MCAuto<MEDCoupling::MEDFileFieldMultiTS> tmFts = MEDCoupling::MEDFileFieldMultiTS::New();
- tmFts->pushBackTimeStep(f);
-
- fields->pushField(tmFts);
-
- writer.setFieldFileNames( fieldFileNames);
- }
-
- else
- {
- MEDCoupling::MCAuto<MEDCoupling::MEDCouplingMesh> mesh = fileMesh->getMeshAtLevel(1); // nodes mesh
- MEDCoupling::MCAuto<MEDCoupling::MEDCouplingUMesh> umesh = mesh->buildUnstructured(); // nodes mesh
- int dim = umesh->getSpaceDimension();
- int version = sizeof(double) < 8 ? 1 : 2;
- mcIdType nbNodes = umesh->getNumberOfNodes();
- buildConstantSizeMapSolFile(solFormatFieldFileName, dim, version, nbNodes);
-
- }
-
- mfd->setFields( fields );
- meshFormatMeshFileName = getFileName();
- meshFormatMeshFileName+=".mesh";
- writer.setMeshFileName(meshFormatMeshFileName);
- writer.setMEDFileDS( mfd);
- writer.write();
-
-}
-
-void MgAdapt::convertMeshFile(std::string& meshFormatIn, std::vector< std::string>& solFieldFileNames) const
-{
- MEDCoupling::MeshFormatReader reader(meshFormatIn, solFieldFileNames);
-
- MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = reader.loadInMedFileDS();
- // write MED
- MEDCoupling::MEDFileMeshes* meshes = mfd->getMeshes();
- MEDCoupling::MEDFileMesh* fileMesh = meshes->getMeshAtPos(0); // ok only one mesh in file!
- fileMesh->setName(meshNameOut);
- restoreGroupsAndFams(fileMesh);
- mfd->write(medFileOut, 2);
-}
-
-
-void MgAdapt::storeGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh)
-{
- storefams(fileMesh);
- storeGroups(fileMesh);
-}
-
-void MgAdapt::restoreGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh) const
-{
- restorefams(fileMesh);
- restoreGroups(fileMesh);
-}
-void MgAdapt::storeGroups(MEDCoupling::MEDFileMesh* fileMesh)
-{
- std::map<std::string, std::vector<std::string> > grpFams = fileMesh->getGroupInfo();
- std::map<std::string, std::vector<std::string> >::iterator g2ff = grpFams.begin();
-
- for ( ; g2ff != grpFams.end(); ++g2ff )
- {
- std::string groupName = g2ff->first;
- std::vector<std::string> famNames = g2ff->second;
-
- if ( famNames.empty() ) continue;
- std::size_t k = 0;
- std::vector< mcIdType> famListId;
- for ( size_t i = 0; i < famNames.size(); ++i )
- {
- famListId.push_back( fileMesh->getFamilyId( famNames[i].c_str() ) );
- }
- group grp(groupName, famListId, famNames);
- groupVec.push_back(grp);
- }
-}
-
-void MgAdapt::storefams(MEDCoupling::MEDFileMesh* fileMesh)
-{
- std::map<std::string, mcIdType> grpFams = fileMesh->getFamilyInfo();
- std::map<std::string, mcIdType >::iterator f = grpFams.begin();
-
- for ( ; f != grpFams.end(); ++f )
- {
- if(!f->second) continue; // FAMILLE_ZERO
- family fs(f->first, f->second);
- famVec.push_back(fs);
- }
-
-}
-
-void MgAdapt::restorefams(MEDCoupling::MEDFileMesh* fileMesh) const
-{
- std::vector<family>::const_iterator fIt = famVec.begin();
-
- for (; fIt!=famVec.end(); ++fIt)
- {
- try // safety : FAMILY could be lost P2-->P1
- {
- std::string givenFamNameFromMeshGemConverter = fileMesh->getFamilyNameGivenId( std::abs(fIt->_famId) );
- fileMesh->changeFamilyId(std::abs(fIt->_famId), fIt->_famId);
- fileMesh->changeFamilyName(givenFamNameFromMeshGemConverter, fIt->_famName);
- }
- catch (const std::exception& e)
- {
- std::cerr<<e.what();
- }
- }
-}
-
-void MgAdapt::restoreGroups(MEDCoupling::MEDFileMesh* fileMesh) const
-{
- std::map<std::string, std::vector<std::string> > info;
- std::vector <group>::const_iterator grpFams = groupVec.begin();
-
- for (; grpFams!=groupVec.end(); ++grpFams)
- {
- info.insert(std::pair <std::string, std::vector<std::string> > (grpFams->_name, grpFams->_famNames) );
- }
-
- fileMesh->setGroupInfo(info);
-}
-
-void MgAdapt::buildConstantSizeMapSolFile(const std::string& solFormatFieldFileName, const int dim, const int version, const mcIdType nbNodes) const
-{
- MeshFormat::Localizer loc;
- MeshFormat::MeshFormatParser writer;
- int fileId = writer.GmfOpenMesh( solFormatFieldFileName.c_str(), GmfWrite, version, dim);
- int typTab[] = {GmfSca};
- writer.GmfSetKwd(fileId, MeshFormat::GmfSolAtVertices, (int)nbNodes, 1, typTab);
- for (mcIdType i = 0; i<nbNodes; i++)
- {
- double valTab[1] = {constantValue};
- writer.GmfSetLin( fileId, MeshFormat::GmfSolAtVertices, valTab);
- }
- writer.GmfCloseMesh(fileId);
-}
-
-void MgAdapt::buildBackGroundMeshAndSolFiles(const std::vector<std::string>& fieldFileNames, const std::string& meshFormatsizeMapFile) const
-{
- MEDCoupling::MCAuto<MEDCoupling::MEDFileData> tmpMfd = MEDCoupling::MEDFileData::New(sizeMapFile);
- MEDCoupling::MEDFileFields* tmpFields = tmpMfd->getFields();
- MEDCoupling::MEDFileAnyTypeFieldMultiTS* fts = tmpFields->getFieldWithName(fieldName);
- MEDCoupling::MCAuto<MEDCoupling::MEDFileFieldMultiTS> fts1 = dynamic_cast<MEDCoupling::MEDFileFieldMultiTS *>(fts);
- MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeField1TS> f = fts1->getTimeStep(timeStep, rank);
- MEDCoupling::MCAuto<MEDCoupling::MEDFileFieldMultiTS> tmFts = MEDCoupling::MEDFileFieldMultiTS::New();
- tmFts->pushBackTimeStep(f);
-
- MEDCoupling::MCAuto<MEDCoupling::MEDFileFields> tmp_fields = MEDCoupling::MEDFileFields::New();
- tmp_fields->pushField(tmFts);
-
-
- tmpMfd->setFields( tmp_fields );
- MEDCoupling::MeshFormatWriter tmpWriter;
- tmpWriter.setMeshFileName(meshFormatsizeMapFile);
- tmpWriter.setFieldFileNames( fieldFileNames);
- tmpWriter.setMEDFileDS(tmpMfd);
- tmpWriter.write();
-}
-// =======================================================================
-med_idt MgAdapt::openMedFile(const std::string aFile)
-// =======================================================================
-// renvoie le medId associe au fichier Med apres ouverture
-{
- med_idt medIdt = MEDfileOpen(aFile.c_str(),MED_ACC_RDONLY);
- if (medIdt <0)
- {
- //~addMessage( ToComment(" error: Can't open ") << aFile, /*fatal=*/true );
- ;
- }
- return medIdt;
-}
-
-MgAdapt::Status MgAdapt::addMessage(const std::string& msg,
- const bool isFatal/*=false*/)
-{
- if ( isFatal )
- _myErrorMessages.clear(); // warnings are useless if a fatal error encounters
-
- _myErrorMessages.push_back( msg );
-
- //~MESSAGE(msg);
-#ifdef _DEBUG_
- std::cout << msg << std::endl;
-#endif
- return ( _myStatus = isFatal ? MgAdapt::DRS_FAIL : MgAdapt::DRS_WARN_SKIP_ELEM );
-}
-
-
-
-
-// =======================================================================
-void MgAdapt::getTimeStepInfos(std::string aFile, med_int& numdt, med_int& numit)
-// =======================================================================
-{
-// Il faut voir si plusieurs maillages
-
-
- herr_t erreur = 0 ;
- med_idt medIdt ;
-
-
- // Ouverture du fichier
- //~SCRUTE(aFile.toStdString());
- medIdt = openMedFile(aFile);
- if ( medIdt < 0 ) return ;
- // Lecture du nombre de champs
- med_int ncha = MEDnField(medIdt) ;
- if (ncha < 1 )
- {
- //~addMessage( ToComment(" error: there is no field in ") << aFile, /*fatal=*/true );
- return;
- }
- // Lecture des caracteristiques du champs
-
- // Lecture du type du champ, des noms des composantes et du nom de l'unite
- char nomcha [MED_NAME_SIZE+1];
- strcpy(nomcha, fieldName.c_str());
-// Lecture du nombre de composantes
- med_int ncomp = MEDfieldnComponentByName(medIdt, nomcha);
- char meshname[MED_NAME_SIZE+1];
- char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
- char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
- char dtunit[MED_SNAME_SIZE+1];
- med_bool local;
- med_field_type typcha;
- med_int nbofcstp;
- erreur = MEDfieldInfoByName (medIdt, nomcha, meshname,&local,&typcha,comp,unit,dtunit, &nbofcstp);
- free(comp);
- free(unit);
- if ( erreur < 0 )
- {
- //~addMessage( ToComment(" error: error while reading field ") << nomcha << " in file " << aFile , /*fatal=*/true );
- return;
- }
-
- med_float dt;
- med_int tmp_numdt, tmp_numit;
-
- //~med_int step = data->myUseLastTimeStep ? nbofcstp : data->myTimeStep+1;
- //~myPrint("step ", step);
- erreur = MEDfieldComputingStepInfo ( medIdt, nomcha, 1, &numdt, &numit, &dt );
- for(med_int step = 1; step <= nbofcstp; step++ )
- {
- erreur = MEDfieldComputingStepInfo ( medIdt, nomcha, step, &tmp_numdt, &tmp_numit, &dt );
- if(tmp_numdt > numdt)
- {
- numdt = tmp_numdt;
- numit = tmp_numit;
- }
- }
- if ( erreur < 0 )
- {
-
- //~addMessage( ToComment(" error: error while reading field ") << nomcha << "step (numdt, numit) = " <<"("<< numdt<< ", " \
- numit<< ")" <<" in file " << aFile , /*fatal=*/true );
- return;
- }
-
-
-
- // Fermeture du fichier
- if ( medIdt > 0 ) MEDfileClose(medIdt);
-
-
-}
-
-
-
+++ /dev/null
-// Copyright (C) 2011-2020 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
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/
-//
-// File : MG_ADAPT.hxx
-//
-#ifndef MG_ADAPT_HXX
-#define MG_ADAPT_HXX
-#include <string>
-# include <sstream>
-#include <map>
-#include <vector>
-#include <set>
-#include <fstream>
-
-#include "MCAuto.hxx"
-#include "MCType.hxx"
-#include "MEDFileMesh.hxx"
-
-#include <med.h>
-// SMESH includes
-
-//~#include <med.h>
-
-
-class MgAdapt;
-
-typedef std::map< std::string, std::string > TOptionValues;
-typedef std::set< std::string > TOptionNames;
-
-struct MgAdaptHypothesisData
-{
- std::string myFileInDir, myMeshFileIn, myInMeshName, myMeshFileBackground, myOutMeshName,
- myMeshFileOut, myFileOutDir, myFileSizeMapDir, myFieldName;
- bool fromMedFile;
- bool myPublish, myMeshOutMed;
- bool myUseLocalMap, myUseBackgroundMap, myUseConstantValue;
- double myConstantValue;
- int myRank, myTimeStep;
- bool myUseNoTimeStep, myUseLastTimeStep, myUseChosenTimeStep;
- std::string myWorkingDir, myLogFile;
- bool myPrintLogInFile, myKeepFiles, myRemoveLogOnSuccess;
- int myVerboseLevel;
-
-};
-
-class outFileStream : public std::ofstream{
-public:
- ~outFileStream(){close();} //to close file at dtor
-};
-
-/*!
- * \brief Class to generate string from any type
- */
-class ToComment : public std::string
-{
- std::ostringstream _s ;
-
-public :
-
- ToComment():std::string("") {}
-
- ToComment(const ToComment& c):std::string() {
- _s << c.c_str() ;
- this->std::string::operator=( _s.str() );
- }
-
- ToComment & operator=(const ToComment& c) {
- _s << c.c_str() ;
- this->std::string::operator=( _s.str() );
- return *this;
- }
-
- template <class T>
- ToComment( const T &anything ) {
- _s << anything ;
- this->std::string::operator=( _s.str() );
- }
-
- template <class T>
- ToComment & operator<<( const T &anything ) {
- _s << anything ;
- this->std::string::operator=( _s.str() );
- return *this ;
- }
-
- operator char*() const {
- return (char*)c_str();
- }
-
- std::ostream& Stream() {
- return _s;
- }
-};
-
-
-class MgAdapt
-{
-
-public:
-
- MgAdapt();
- MgAdapt(MgAdaptHypothesisData*);
- MgAdapt(const MgAdapt&);
- ~MgAdapt();
- void buildModel();
- void setData( MgAdaptHypothesisData*);
-
- void setMedFileIn(std::string fileName);
- std::string getMedFileIn();
-
- void setMedFileOut(std::string fileOut);
- std::string getMedFileOut();
-
- void setMeshName(std::string name);
- std::string getMeshName();
-
- void setMeshNameOut(std::string name);
- std::string getMeshNameOut();
-
- void setMeshOutMed(bool mybool);
- bool getMeshOutMed();
-
- void setPublish(bool mybool);
- bool getPublish();
-
- void setFieldName(std::string myFieldName);
- std::string getFieldName();
-
- void setTimeStep(int time);
- int getTimeStep() const;
-
- void setRankTimeStep(int time, int myRank);
- int getRank();
-
- void setLogFile(std::string);
- std::string getLogFile();
-
- void setVerbosityLevel(int verbosity);
- int getVerbosityLevel();
-
- void setRemoveOnSuccess(bool mybool);
- bool getRemoveOnSuccess();
-
- MgAdaptHypothesisData* getData() const;
-
- void setUseLocalMap(bool mybool);
- bool getUseLocalMap();
-
- void setUseBackgroundMap(bool);
- bool getUseBackgroundMap();
-
- void setUseConstantValue(bool);
- bool getUseConstantValue();
-
- void setConstantValue(double);
- double getConstantValue() const;
-
- void setSizeMapFile(std::string);
- std::string getSizeMapFile();
-
- void setFromMedFile(bool);
- bool isFromMedFile();
-
- void setKeepWorkingFiles(bool);
- bool getKeepWorkingFiles();
-
- void setPrintLogInFile(bool);
- bool getPrintLogInFile();
-
- void setWorkingDir(std::string);
- std::string getWorkingDir() const;
-
-
- bool setAll();
- static std::string getCommandToRun(MgAdapt* );
- std::string getCommandToRun() ;
- int compute(std::string& errStr);
- std::string getFileName() const;
- static std::string getExeName();
- void copyMgAdaptHypothesisData( MgAdaptHypothesisData* ) ;
-
- void checkDirPath(std::string& );
-
-
-
- bool hasOptionDefined( const std::string& optionName ) const;
- void setOptionValue(const std::string& optionName,
- const std::string& optionValue) throw (std::invalid_argument);
- std::string getOptionValue(const std::string& optionName,
- bool* isDefault=0) const throw (std::invalid_argument);
- std::vector <std::string> getCustomOptionValuesStrVec() const;
- std::vector <std::string> getOptionValuesStrVec() const;
-
-
- TOptionValues getOptionValues() const;
- const TOptionValues& getCustomOptionValues() const ;
- static double toDbl(const std::string&, bool* isOk = 0) throw (std::invalid_argument);
- static bool toBool(const std::string&, bool* isOk = 0) throw (std::invalid_argument);
- static int toInt(const std::string&, bool* isOk = 0 ) throw (std::invalid_argument);
- static std::string toLowerStr(const std::string& str);
-
-
- /* default values */
- static std::string defaultWorkingDirectory();
- static std::string defaultLogFile();
- static bool defaultKeepFiles();
- static bool defaultRemoveLogOnSuccess();
- static int defaultVerboseLevel();
- static bool defaultPrintLogInFile();
- static bool defaultFromMedFile();
- static bool defaultMeshOutMed();
- static bool defaultPublish();
- static bool defaultUseLocalMap();
- static bool defaultUseBackgroundMap();
- static bool defaultUseConstantValue();
- static bool defaultUseNoTimeStep();
- static bool defaultUseLastTimeStep();
- static bool defaultUseChosenTimeStep();
- static double defaultMaximumMemory();
-
-
-
-
- enum Status {
- DRS_OK,
- DRS_EMPTY, // a file contains no mesh with the given name
- DRS_WARN_RENUMBER, // a file has overlapped ranges of element numbers,
- // so the numbers from the file are ignored
- DRS_WARN_SKIP_ELEM, // some elements were skipped due to incorrect file data
- DRS_WARN_DESCENDING, // some elements were skipped due to descending connectivity
- DRS_FAIL, // general failure (exception etc.)
- DRS_NO_TIME_STEP // general failure (exception etc.)
- };
-
- struct group {
-
- std::string _name;
- std::vector<MEDCoupling::mcIdType> _famListId;
- std::vector<std::string> _famNames;
- group(std::string name, std::vector<MEDCoupling::mcIdType> famListId, std::vector<std::string> famNames):_name(name)
- {
- std::vector<MEDCoupling::mcIdType>::iterator it = famListId.begin();
- for (; it!=famListId.end(); ++it)
- _famListId.push_back(*it);
-
- std::vector<std::string>::iterator itt = famNames.begin();
- for (; itt!=famNames.end(); ++itt)
- _famNames.push_back(*itt);
- }
- };
-
- struct family {
- std::string _famName;
- mcIdType _famId;
- family(std::string famName, MEDCoupling::mcIdType famId):_famName(famName), _famId(famId) {}
- };
-
-
-private :
- bool fromMedFile;
-
- std::string medFileIn;
- std::string medFileOut;
- std::string meshName;
- std::string meshNameOut;
- bool publish, meshOutMed;
- bool useLocalMap, useBackgroundMap, useConstantValue;
- std::string sizeMapFile;
- std::string fieldName;
- double constantValue;
- int rank, timeStep;
-
- /* advanced options */
-
-
- std::string logFile;
- std::string workingDir;
- int verbosityLevel;
- bool removeOnSuccess;
- bool toKeepWorkingFiles;
- bool printLogInFile;
-
- /* Model DATA */
- MgAdaptHypothesisData* data;
-
- /* */
-
- TOptionValues _option2value, _customOption2value; // user defined values
- TOptionValues _defaultOptionValues; // default values
- TOptionNames _doubleOptions, _charOptions, _boolOptions; // to find a type of option
-
- std::vector <std::string> _myErrorMessages;
- Status _myStatus;
- std::string meshFormatOutputMesh;
- std::vector< std::string> solFormatOutput;
- std::vector <group> groupVec;
- std::vector <family> famVec;
- std::vector< std::string> tmpFilesToBeDeleted;
-
- /* convert MED-->.mesh format */
- void convertMedFile(std::string& meshIn,std::string& solFileIn, std::string& sizeMapIn) ;
- void storeGroups(MEDCoupling::MEDFileMesh* fileMesh);
- void restoreGroups(MEDCoupling::MEDFileMesh* fileMesh) const;
- void storefams(MEDCoupling::MEDFileMesh* fileMesh);
- void restorefams(MEDCoupling::MEDFileMesh* fileMesh) const;
- void storeGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh);
- void restoreGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh) const;
- void convertMeshFile(std::string& meshFormatIn, std::vector< std::string>& solFieldFileNames) const ;
- void buildConstantSizeMapSolFile(const std::string& solFormatFieldFileName, const int dim, const int version, const mcIdType nbNodes) const;
- void buildBackGroundMeshAndSolFiles(const std::vector<std::string>& fieldFileNames, const std::string& meshFormatsizeMapFile) const;
- void getTimeStepInfos(std::string aFile, med_int& numdt, med_int& numit);
- Status addMessage(const std::string& msg, const bool isFatal = false);
- med_idt openMedFile(const std::string aFile) ;
- bool isFileExist(std::string& fName) const;
- void execCmd( const char* cmd, int& err);
- void cleanUp();
- void appendMsgToLogFile(std::string& msg);
-};
-
-
-
-#endif // MG_ADAPT_HXX
+++ /dev/null
-// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// file : MG_ADAPTGUI.cxx
-
-#include "MG_ADAPTGUI.hxx"
-
-#include "SUIT_Desktop.h"
-#include "SUIT_Application.h"
-#include "SUIT_Session.h"
-
-#include "SalomeApp_Application.h"
-#include "SalomeApp_Module.h"
-#include "SalomeApp_Study.h"
-#include "SMESH_Actor.h"
-#include <SUIT_MessageBox.h>
-#include <SMESH_TypeFilter.hxx>
-#include <SMESH_MeshAlgos.hxx>
-#include <SMESH_LogicalFilter.hxx>
-#include <SMDS_Mesh.hxx>
-#include <SMDS_MeshNode.hxx>
-#include <LightApp_SelectionMgr.h>
-#include <SUIT_OverrideCursor.h>
-#include <SUIT_ResourceMgr.h>
-#include <SVTK_ViewWindow.h>
-#include <SALOME_ListIO.hxx>
-#include <SUIT_FileDlg.h>
-#include <QApplication>
-#include <QButtonGroup>
-#include <QGridLayout>
-#include <QGroupBox>
-#include <QHBoxLayout>
-#include <QKeyEvent>
-#include <QLabel>
-#include <QLineEdit>
-#include <QCheckBox>
-#include <QPushButton>
-#include <QRadioButton>
-#include <QTabWidget>
-#include <QVBoxLayout>
-#include <QDoubleSpinBox>
-#include <QSpinBox>
-#include <QTreeWidget>
-#include <QTreeWidgetItem>
-#include <QSpacerItem>
-#include <QString>
-#include <QHeaderView>
-#include <QItemDelegate>
-#include <QFileDialog>
-#include <QMessageBox>
-#include <QComboBox>
-
-#include <vtkPoints.h>
-#include <vtkUnstructuredGrid.h>
-#include <vtkIdList.h>
-#include <vtkCellArray.h>
-#include <vtkUnsignedCharArray.h>
-#include <vtkDataSetMapper.h>
-#include <VTKViewer_CellLocationsArray.h>
-#include <vtkProperty.h>
-
-#include <ElCLib.hxx>
-// SALOME KERNEL includes
-#include <SALOMEDS_SComponent.hxx>
-#include <SALOMEDS_SObject.hxx>
-#include <SALOMEDS_Study.hxx>
-#include <SALOMEDS_wrap.hxx>
-#include "SalomeApp_Tools.h"
-#include <SALOMEconfig.h>
-#include <med.h>
-#include <utilities.h>
-
-#include <TCollection_AsciiString.hxx>
-
-
-const int SPACING = 6; // layout spacing
-const int MARGIN = 9; // layout margin
-
-//=================================================================================
-// function : SMESHGUI_MgAdaptDlg()
-// purpose :
-//=================================================================================
-SMESHGUI_MgAdaptDlg::SMESHGUI_MgAdaptDlg( SalomeApp_Module* theModule, MgAdapt* myModel, QWidget* parent, bool isCreation )
- : mySMESHGUI( theModule ), QDialog(parent)
-{
- model = new MgAdapt(*myModel);
- myData = model->getData();
- buildDlg();
- if (!isCreation) readParamsFromHypo();
-}
-
-void SMESHGUI_MgAdaptDlg::buildDlg()
-{
- setModal( false );
- setAttribute( Qt::WA_DeleteOnClose, true );
- setWindowTitle( tr( "ADAPT_PREF_MG_ADAPT" ) );
- setSizeGripEnabled( true );
-
-
- myTabWidget = new QTabWidget( this );
-
- // Arguments
-
- myArgs = new SMESHGUI_MgAdaptArguments( myTabWidget );
- std::vector <std::string> str = model->getOptionValuesStrVec();
- std::vector <std::string> str2 = model->getCustomOptionValuesStrVec();
- str.insert( str.end(), str2.begin(), str2.end() );
-
- myAdvOpt = new MgAdaptAdvWidget(myTabWidget, &str);
- int argsTab = myTabWidget->addTab( myArgs, tr( "Args" ) );
- int advTab = myTabWidget->addTab( myAdvOpt, tr( "ADVOP" ) );
-
- myAdvOpt->workingDirectoryLabel ->setText (tr( "WORKING_DIR" ));
- myAdvOpt->workingDirectoryPushButton ->setText (tr( "SELECT_DIR" ));
- myAdvOpt->keepWorkingFilesCheck ->setText (tr( "KEEP_WORKING_FILES" ));
- myAdvOpt->verboseLevelLabel ->setText (tr( "VERBOSE_LEVEL" ));
- myAdvOpt->removeLogOnSuccessCheck ->setText (tr( "REMOVE_LOG_ON_SUCCESS" ));
- myAdvOpt->logInFileCheck ->setText (tr( "LOG_IN_FILE" ));
- myAdvOpt->logGroupBox ->setTitle(tr( "LOG_GROUP_TITLE" ));
-
- // buttons
- QPushButton* okBtn = new QPushButton( tr( "SMESH_BUT_OK" ), this );
- okBtn->setAutoDefault( true );
- okBtn->setDefault( true );
- okBtn->setFocus();
- QPushButton* buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), this);
- buttonApply->setAutoDefault(true);
- QPushButton* buttonApplyAndClose = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), this);
- buttonApplyAndClose->setAutoDefault(true);
- QPushButton* cancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), this );
- cancelBtn->setAutoDefault( true );
- QPushButton* helpBtn = new QPushButton( tr( "SMESH_BUT_HELP" ), this );
- helpBtn->setAutoDefault( true );
-
- QHBoxLayout* btnLayout = new QHBoxLayout;
- btnLayout->setSpacing( SPACING );
- btnLayout->setMargin( 0 );
- btnLayout->addWidget( buttonApplyAndClose );
- btnLayout->addStretch( 10 );
- btnLayout->addWidget( buttonApply );
- btnLayout->addStretch( 10 );
- btnLayout->addWidget( okBtn );
- btnLayout->addStretch( 10 );
- btnLayout->addWidget( cancelBtn );
- btnLayout->addStretch( 10 );
- btnLayout->addWidget( helpBtn );
- okBtn->hide(); // tab 1
-
- QVBoxLayout* l = new QVBoxLayout ( this );
- l->setMargin( MARGIN );
- l->setSpacing( SPACING );
- l->addWidget( myTabWidget );
- l->addStretch();
- l->addLayout( btnLayout );
-
-
- connect( okBtn, SIGNAL( clicked() ), this, SLOT( clickOnOk() ) );
- connect( helpBtn, SIGNAL( clicked() ), this, SLOT( clickOnHelp() ) );
- connect(cancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
- connect(buttonApply, SIGNAL(clicked()), this,SLOT(clickOnApply()));
- connect(buttonApplyAndClose, SIGNAL(clicked()), this,SLOT(clickOnOk()));
- connect(myArgs, SIGNAL(meshDimSignal(ADAPTATION_MODE)), myAdvOpt, SLOT( onMeshDimChanged(ADAPTATION_MODE)) );
-}
-
-
-//=================================================================================
-// function : ~SMESHGUI_MgAdaptDlg()
-// purpose : Destroys the object and frees any allocated resources
-//=================================================================================
-SMESHGUI_MgAdaptDlg::~SMESHGUI_MgAdaptDlg()
-{
- delete model;
-}
-
-void SMESHGUI_MgAdaptDlg::setModel(MgAdapt* mg)
-{
- model = mg;
-}
-MgAdapt* SMESHGUI_MgAdaptDlg::getModel() const
-{
- return model;
-}
-/*!
- \brief Perform clean-up actions on the dialog box closing.
-*/
-bool SMESHGUI_MgAdaptDlg::clickOnApply()
-{
- readParamsFromWidgets();
- return true;
-}
-void SMESHGUI_MgAdaptDlg::clickOnOk()
-{
- clickOnApply();
- reject();
-}
-void SMESHGUI_MgAdaptDlg::reject()
-{
- QDialog::reject();
-}
-bool SMESHGUI_MgAdaptDlg::readParamsFromHypo( ) const
-{
- bool ret = true;
- myArgs->aMedfile->setChecked(myData->fromMedFile) ;
- if (myData->fromMedFile)
- {
-
- *(myArgs->myFileInDir) = QString(myData->myFileInDir.c_str()) ;
- myArgs->selectMedFileLineEdit->setText(myData->myMeshFileIn.c_str()) ;
- // myData->myInMeshName = // TODO
-
- }
- else
- {
- myArgs->aBrowserObject->setText(myData->myInMeshName.c_str());
- //~ myArgs->myFileInDir =""; // TODO
- //~ myArgs->selectMedFileLineEdit->setText(); // TODO
- }
- myArgs->meshNameLineEdit->setText(myData->myOutMeshName.c_str());
- myArgs->medFileCheckBox->setChecked(myData->myMeshOutMed);
-
- if(myData->myMeshOutMed)
- {
- *(myArgs->myFileOutDir) = QString(myData->myFileOutDir.c_str());
- myArgs->selectOutMedFileLineEdit->setText(myData->myMeshFileOut.c_str());
-
- }
- else
- {
- *(myArgs->myFileOutDir) = QString(""); //TODO
- }
-
- myArgs->publishOut->setChecked(myData->myPublish);
-
- myArgs->localButton->setChecked(myData->myUseLocalMap);
- myArgs->backgroundButton->setChecked(myData->myUseBackgroundMap);
- myArgs->constantButton->setChecked(myData->myUseConstantValue);
-
- if (myData->myUseConstantValue)
- {
- myArgs->dvalue->setValue(myData->myConstantValue);
- }
- else
- {
- myArgs->dvalue->setValue(0.0);
- }
-
- if (myData->myUseBackgroundMap)
- {
-
- *(myArgs->myFileSizeMapDir) = QString(myData->myFileSizeMapDir.c_str()) ;
- myArgs->selectMedFileBackgroundLineEdit->setText(myData->myMeshFileBackground.c_str());
- }
- else
- {
- *(myArgs->myFileSizeMapDir) = QString("") ; //TODO
- myArgs->selectMedFileBackgroundLineEdit->setText(""); //TODO
- }
-
- myArgs->fieldNameCmb->setCurrentText(myData->myFieldName.c_str());
- myArgs->noTimeStep->setChecked(myData->myUseNoTimeStep);
- myArgs->lastTimeStep->setChecked( myData->myUseLastTimeStep);
- myArgs->chosenTimeStep->setChecked(myData->myUseChosenTimeStep);
- if (myData->myUseChosenTimeStep)
- {
- myArgs->rankSpinBox->setValue(myData->myRank);
- myArgs->timeStep->setValue(myData->myTimeStep);
- }
-
- myAdvOpt->workingDirectoryLineEdit->setText(myData->myWorkingDir.c_str());
- myAdvOpt->logInFileCheck->setChecked(myData->myPrintLogInFile);
-
- myAdvOpt->verboseLevelSpin->setValue(myData->myVerboseLevel);
- myAdvOpt->removeLogOnSuccessCheck->setChecked(myData->myRemoveLogOnSuccess);
- myAdvOpt->keepWorkingFilesCheck->setChecked(myData->myKeepFiles);
-
- return ret;
-
-}
-
-
-bool SMESHGUI_MgAdaptDlg::readParamsFromWidgets()
-{
- bool ret = true;
- MgAdaptHypothesisData* aData = new MgAdaptHypothesisData();
- aData->fromMedFile = myArgs->aMedfile->isChecked();
- if (aData->fromMedFile)
- {
-
- aData->myFileInDir = myArgs->myFileInDir->toStdString();
- aData->myMeshFileIn = myArgs->selectMedFileLineEdit->text().toStdString();
- // aData->myInMeshName = // TODO
- }
- else // TODO browser
- {
- aData->myInMeshName = myArgs->aBrowserObject->text().toStdString();
- aData->myFileInDir = myAdvOpt->workingDirectoryLineEdit->text().toStdString();
-
- TCollection_AsciiString aGenericName = (char*)aData->myFileInDir.c_str();
- TCollection_AsciiString aGenericName2 = "MgAdapt_";
- aGenericName2 += getpid();
- aGenericName2 += "_";
- aGenericName2 += Abs((Standard_Integer)(long) aGenericName.ToCString());
- aGenericName2 += ".med";
- aGenericName+=aGenericName2;
- emit myArgs->toExportMED(aGenericName.ToCString());
- aData->myMeshFileIn = aGenericName2.ToCString();
- }
- aData->myOutMeshName = myArgs->meshNameLineEdit->text().toStdString();
- aData->myMeshOutMed = myArgs->medFileCheckBox->isChecked();
- if(aData->myMeshOutMed)
- {
- aData->myFileOutDir = myArgs->myFileOutDir->toStdString();
- aData->myMeshFileOut = myArgs->selectOutMedFileLineEdit->text().toStdString();
-
- }
- else
- {
- aData->myMeshFileOut = "";
- }
-
- aData->myPublish = myArgs->publishOut->isChecked();
-
-
- aData->myUseLocalMap = myArgs->localButton->isChecked();
- aData->myUseBackgroundMap = myArgs->backgroundButton->isChecked();
- aData->myUseConstantValue = myArgs->constantButton->isChecked();
- if (aData->myUseConstantValue)
- {
- aData->myConstantValue = myArgs->dvalue->value();
- }
- else
- {
- aData->myConstantValue = 0.0;
- }
- if (aData->myUseBackgroundMap)
- {
- aData->myFileSizeMapDir = myArgs->myFileSizeMapDir->toStdString();
- aData->myMeshFileBackground = myArgs->selectMedFileBackgroundLineEdit->text().toStdString();
- }
- else
- {
- aData->myMeshFileBackground = "";
- }
-
- aData->myFieldName = myArgs->fieldNameCmb->currentText().toStdString();
- aData->myUseNoTimeStep = myArgs->noTimeStep->isChecked();
- aData->myUseLastTimeStep = myArgs->lastTimeStep->isChecked();
- aData->myUseChosenTimeStep = myArgs->chosenTimeStep->isChecked();
- if (aData->myUseChosenTimeStep)
- {
- aData->myRank = myArgs->rankSpinBox->value();
- aData->myTimeStep = myArgs->timeStep->value();
-
- }
-
-
- aData->myWorkingDir = myAdvOpt->workingDirectoryLineEdit->text().toStdString();
- aData->myPrintLogInFile = myAdvOpt->logInFileCheck->isChecked();
- aData->myVerboseLevel = myAdvOpt->verboseLevelSpin->value();
- aData->myRemoveLogOnSuccess = myAdvOpt->removeLogOnSuccessCheck->isChecked();
- aData->myKeepFiles = myAdvOpt->keepWorkingFilesCheck->isChecked();
- model->setData(aData);
- QString msg;
- checkParams(msg);
- delete aData;
- return ret;
-}
-bool SMESHGUI_MgAdaptDlg::storeParamsToHypo( const MgAdaptHypothesisData& ) const
-{
-
-}
-/*!
- \brief Show help page
-*/
-void SMESHGUI_MgAdaptDlg::clickOnHelp()
-{
- // QString aHelpFile;
- // if ( myTabWidget->currentIndex() == MinDistance ) {
- // aHelpFile = "measurements.html#min-distance-anchor";
- // } else if ( myTabWidget->currentIndex() == BoundingBox ) {
- // aHelpFile = "measurements.html#bounding-box-anchor";
- // } else if ( myTabWidget->currentWidget() == myAngle ) {
- // aHelpFile = "measurements.html#angle-anchor";
- // } else {
- // aHelpFile = "measurements.html#basic-properties-anchor";
- // }
-
- // SMESH::ShowHelpFile( aHelpFile );
-}
-bool SMESHGUI_MgAdaptDlg::checkParams(QString& msg)
-{
- if ( !QFileInfo( myAdvOpt->workingDirectoryLineEdit->text().trimmed() ).isWritable() ) {
- SUIT_MessageBox::warning( this,
- tr( "SMESH_WRN_WARNING" ),
- tr( "GHS3D_PERMISSION_DENIED" ) );
- return false;
- }
-
-
- myAdvOpt->myOptionTable->setFocus();
- QApplication::instance()->processEvents();
-
- QString name, value;
- bool isDefault, ok = true;
- int iRow = 0, nbRows = myAdvOpt->myOptionTable->topLevelItemCount();
- for ( ; iRow < nbRows; ++iRow )
- {
- QTreeWidgetItem* row = myAdvOpt->myOptionTable->topLevelItem( iRow );
- myAdvOpt->GetOptionAndValue( row, name, value, isDefault );
-
- if ( name.simplified().isEmpty() )
- continue; // invalid custom option
-
- if ( isDefault ) // not selected option
- value.clear();
-
- try {
- model->setOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
- }
- catch ( const SALOME::SALOME_Exception& ex )
- {
- msg = ex.details.text.in();
- ok = false;
- break;
- }
- }
-
-
- return ok;
-}
-
-//=================================================================================
-// function : SMESHGUI_MgAdaptArguments()
-// purpose :
-//=================================================================================
-SMESHGUI_MgAdaptArguments::SMESHGUI_MgAdaptArguments( QWidget* parent )
- :QWidget(parent)
-{
-
-
- myFileInDir = new QString("");
- myFileOutDir = new QString("");
- myFileSizeMapDir = new QString("");
- if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
- {
- *myFileInDir = QDir::currentPath();
- *myFileOutDir = QDir::currentPath();
- *myFileSizeMapDir = QDir::currentPath();
- }
- else
- {
- *myFileInDir = SUIT_FileDlg::getLastVisitedPath();
- *myFileOutDir = SUIT_FileDlg::getLastVisitedPath();
- *myFileSizeMapDir = SUIT_FileDlg::getLastVisitedPath();
- }
-
- meshDim = 0;
- // Mesh in
- aMeshIn = new QGroupBox( tr( "MeshIn" ), this );
- aMedfile = new QRadioButton( tr( "MEDFile" ), aMeshIn );
- aBrowser = new QRadioButton( tr( "Browser" ), aMeshIn );
- aBrowserObject = new QLineEdit( aMeshIn );
- selectMedFilebutton = new QPushButton("", aMeshIn);
- selectMedFileLineEdit = new QLineEdit( aMeshIn );
-
- meshIn = new QGridLayout( aMeshIn );
-
- meshIn->setMargin( MARGIN );
- meshIn->setSpacing( SPACING );
- meshIn->addWidget( aMedfile, 0, 0, 1,1 );
- meshIn->addWidget( aBrowser, 0, 1,1,1);
- meshIn->addWidget( aBrowserObject, 0, 2, 1, 1 );
- meshIn->addWidget( selectMedFilebutton, 1, 0,1, 1);
- meshIn->addWidget( selectMedFileLineEdit, 1, 1, 1, 1 );
- hspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
-
- meshInGroup = new QButtonGroup( this );
- meshInGroup->addButton( aMedfile, 0 );
- meshInGroup->addButton( aBrowser, 1 );
-
- //Mesh out
-
- aMeshOut = new QGroupBox( tr( "MeshOut" ), this );
- meshName = new QLabel(tr("MeshName"), aMeshOut);
- secondHspacer = new QSpacerItem(100, 30);
- meshNameLineEdit = new QLineEdit(aMeshOut) ;
- medFileCheckBox = new QCheckBox(tr("MEDFile"), aMeshOut);
- selectOutMedFilebutton = new QPushButton("", aMeshOut);
- thirdHspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
- selectOutMedFileLineEdit = new QLineEdit(aMeshOut) ;
- publishOut = new QCheckBox(tr("Publish_MG_ADAPT"), aMeshOut);
-
- meshOut = new QGridLayout( aMeshOut );
-
- meshOut->setMargin( MARGIN );
- meshOut->setSpacing( SPACING );
- meshOut->addWidget( meshName, 0, 0, 1,1 );
- meshOut->addItem( secondHspacer, 0, 1, 1, 1 );
- meshOut->addWidget( meshNameLineEdit, 0, 2,1,1);
- meshOut->addWidget( medFileCheckBox, 1, 0,1,1 );
- meshOut->addWidget( selectOutMedFilebutton, 1, 1,1,1 );
- meshOut->addWidget( selectOutMedFileLineEdit, 1, 2,1,1);
- meshOut->addWidget( publishOut, 2, 0,1,1 );
-
- //size map definition
-
- sizeMapDefinition = new QGroupBox(tr("SIZE_MAP_DEF"), this);
- localButton = new QRadioButton(tr("LOCAL_MG_ADAPT"), sizeMapDefinition);
- backgroundButton = new QRadioButton(tr("BACKGRND_MG_ADAPT"), sizeMapDefinition);
- constantButton = new QRadioButton(tr("CNST_MG_ADAPT"), sizeMapDefinition);
- medFileBackground = new QLabel(tr("MED_FILE_BCKG"), sizeMapDefinition);
- selectMedFileBackgroundbutton = new QPushButton(tr(""), sizeMapDefinition);
- selectMedFileBackgroundLineEdit = new QLineEdit(sizeMapDefinition);
- valueLabel = new QLabel(tr("VALUE_MG_ADAPT"), sizeMapDefinition);
- dvalue = new QDoubleSpinBox(sizeMapDefinition);
- sizeMapDefGroup = new QButtonGroup( this );
- sizeMapDefGroup->addButton( localButton, 0 );
- sizeMapDefGroup->addButton( backgroundButton, 1 );
- sizeMapDefGroup->addButton( constantButton, 2 );
-
- sizeMapDefGroupLayout = new QGridLayout(sizeMapDefinition);
- sizeMapDefGroupLayout->addWidget(localButton, 0,0);
- sizeMapDefGroupLayout->addWidget(backgroundButton, 0,1);
- sizeMapDefGroupLayout->addWidget(constantButton, 0,2);
- sizeMapDefGroupLayout->addWidget(medFileBackground, 1,0);
- sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundbutton, 1,1);
- sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundLineEdit, 1,2);
- sizeMapDefGroupLayout->addWidget(valueLabel, 2,0);
- sizeMapDefGroupLayout->addWidget(dvalue, 2,1);
-
- // size Map field
- sizeMapField = new QGroupBox(tr("SIZE_MAP_FIELD"), this);
- fieldName = new QLabel(tr("MG_ADAPT_FIELD_NAME"), sizeMapField);
- fieldNameCmb = new QComboBox(sizeMapField);
- noTimeStep = new QRadioButton(tr("MG_ADAPT_NO_T_ST"), sizeMapField);
- lastTimeStep = new QRadioButton(tr("MG_ADAPT_L_ST"), sizeMapField);
- chosenTimeStep = new QRadioButton(tr("MG_ADAPT_CH_ST"), sizeMapField);
- timeStepLabel = new QLabel(tr("MG_ADAPT_TSTP"), sizeMapField);
- timeStep = new QSpinBox(sizeMapField);
- //~timeStep->setMinimum(-1);
- rankLabel = new QLabel(tr("MG_ADAPT_RANK"), sizeMapField);
- rankSpinBox = new QSpinBox(sizeMapField);
- rankSpinBox->setMinimum(-1);
-
- timeStepGroup = new QButtonGroup(this);
- timeStepGroup->addButton(noTimeStep, 0);
- timeStepGroup->addButton(lastTimeStep, 1);
- timeStepGroup->addButton(chosenTimeStep, 2);
-
- sizeMapFieldGroupLayout = new QGridLayout(sizeMapField);
-
- sizeMapFieldGroupLayout->addWidget(fieldName, 0,0);
- sizeMapFieldGroupLayout->addWidget(fieldNameCmb, 0,1);
- sizeMapFieldGroupLayout->addWidget(noTimeStep, 1,0);
- sizeMapFieldGroupLayout->addWidget(lastTimeStep, 1,1);
- sizeMapFieldGroupLayout->addWidget(chosenTimeStep, 1,2);
- sizeMapFieldGroupLayout->addWidget(timeStepLabel, 2,0);
- sizeMapFieldGroupLayout->addWidget(timeStep, 2,1);
- sizeMapFieldGroupLayout->addWidget(rankLabel, 2,2);
- sizeMapFieldGroupLayout->addWidget(rankSpinBox, 2,3);
-
-
- QGridLayout* argumentsLayout = new QGridLayout( this );
- argumentsLayout->setMargin( MARGIN );
- argumentsLayout->setSpacing( SPACING );
-
- argumentsLayout->addWidget( aMeshIn, 0, 0, 1, 3 );
- argumentsLayout->addWidget( aMeshOut, 1, 0, 1, 3 );
- argumentsLayout->addWidget( sizeMapDefinition, 2, 0, 1, 3 );
- argumentsLayout->addWidget( sizeMapField, 3, 0, 1, 3 );
- argumentsLayout->setColumnStretch( 1, 5 );
- argumentsLayout->setRowStretch( 4, 5 );
-
- // Initial state
- setMode( Mesh, Local);
- medFileCheckBox->setChecked(true);
-
- // Connections
- connect( meshInGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( modeChanged( int ) ) );
- connect( sizeMapDefGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( sizeMapDefChanged( int ) ) );
- connect( selectMedFilebutton, SIGNAL( pressed( ) ), this, SLOT( onSelectMedFilebuttonClicked( ) ) );
- connect(medFileCheckBox, SIGNAL (stateChanged(int)), this, SLOT(onMedFileCheckBox(int) ) );
- connect(publishOut, SIGNAL (stateChanged(int)), this, SLOT(onPublishOut(int) ) );
- connect(selectOutMedFilebutton, SIGNAL( pressed()), this, SLOT(onSelectOutMedFilebutton()));
- connect(selectMedFileBackgroundbutton, SIGNAL(pressed()), this, SLOT(onSelectMedFileBackgroundbutton()) );
- connect( timeStepGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( timeStepGroupChanged( int ) ) );
- emit updateSelection();
-}
-
-//=================================================================================
-// function : ~SMESHGUI_MgAdaptArguments()
-// purpose : Destroys the object and frees any allocated resources
-//=================================================================================
-SMESHGUI_MgAdaptArguments::~SMESHGUI_MgAdaptArguments()
-{
-}
-
-void SMESHGUI_MgAdaptArguments::onNoTimeStep(bool disableOther)
-{
- noTimeStep->setChecked(true);
-
- rankLabel->setVisible(0);
- rankSpinBox->setVisible(0);
- rankSpinBox->setValue(-2);
-
- timeStepLabel->setVisible(0);
- timeStep->setVisible(0);
- timeStep->setValue(-2);
-
- lastTimeStep->setDisabled(disableOther);
- chosenTimeStep->setDisabled(disableOther);
-
-
-}
-void SMESHGUI_MgAdaptArguments::onLastTimeStep(bool disableOther)
-{
- lastTimeStep->setChecked(true);
-
- rankLabel->setVisible(0);
- rankSpinBox->setVisible(0);
- rankSpinBox->setValue(-1);
-
- timeStepLabel->setVisible(0);
- timeStep->setVisible(0);
- timeStep->setValue(-1);
- noTimeStep->setDisabled(disableOther);
-}
-
-void SMESHGUI_MgAdaptArguments::onChosenTimeStep(bool disableOther, int max)
-{
- chosenTimeStep->setChecked(true);
-
- rankLabel->setVisible(1);
- rankSpinBox->setVisible(1);
- rankSpinBox->setValue(0);
-
- timeStepLabel->setVisible(1);
- timeStep->setVisible(1);
- timeStep->setValue(0);
- if (max) timeStep->setMaximum(max);
-
-}
-
-void SMESHGUI_MgAdaptArguments::onSelectOutMedFilebutton()
-{
-
- QString filtre = QString("Med") ;
- filtre += QString(" files (*.") + QString("med") + QString(");;");
- QString fileName = QFileDialog::getSaveFileName(this, tr("SAVE_MED"),
- QString(""), filtre);
- QFileInfo myFileInfo(fileName);
- selectOutMedFileLineEdit->setText(myFileInfo.fileName());
- *myFileOutDir = myFileInfo.path();
-
-}
-void SMESHGUI_MgAdaptArguments::onSelectMedFileBackgroundbutton()
-{
- QString fileName0 = selectMedFileBackgroundbutton->text().trimmed();
-
- QString fileName = getMedFileName(false);
- if (fileName != QString::null)
- {
- myFieldList = GetListeChamps(fileName);
- if (myFieldList.empty())
- {
- fileName = fileName0;
- fieldNameCmb->clear();
- }
- else
- {
- // fill field name Combobox
- fieldNameCmb->clear();
- std::map<QString, int>::const_iterator it;
- for ( it=myFieldList.begin() ; it != myFieldList.end(); it++)
- {
- fieldNameCmb->insertItem(0,QString(it->first));
- int typeStepInField = it->second > 2 ? 2 : it->second ;
- timeStepGroupChanged(typeStepInField, true);
- }
-
- }
-
- }
- else
- {
- fileName = fileName0;
- fieldNameCmb->clear();
- }
-
- QFileInfo myFileInfo(fileName);
- *myFileSizeMapDir = myFileInfo.path();
- selectMedFileBackgroundLineEdit->setText(myFileInfo.fileName());
-
-}
-void SMESHGUI_MgAdaptArguments::onMedFileCheckBox(int state)
-{
- if (state == Qt::Checked)
- {
- selectOutMedFilebutton->show();
- selectOutMedFileLineEdit->show();
- selectOutMedFilebutton->setEnabled(true);
- selectOutMedFileLineEdit->setEnabled(true);
- }
- else
- {
- selectOutMedFilebutton->setEnabled(false);
- selectOutMedFileLineEdit->setEnabled(false);
- publishOut->setChecked(true);
- }
-}
-void SMESHGUI_MgAdaptArguments::onPublishOut(int state)
-{
- if (state == Qt::Unchecked)
- {
- medFileCheckBox->setChecked(true);
- }
-}
-
-void SMESHGUI_MgAdaptArguments::onSelectMedFilebuttonClicked()
-{
- // bool keep = false;
- QString fileName0 = selectMedFileLineEdit->text().trimmed();
-
- QString fileName = getMedFileName(false);
- if(fileName != QString::null)
- {
- QString aMeshName = lireNomMaillage(fileName.trimmed(), meshDim);
- if (aMeshName == QString::null )
- {
- QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
- QObject::tr("MG_ADAPT_MED_FILE_2") );
- fileName = fileName0;
- }
- else
- {
- meshNameLineEdit->setText(aMeshName);
- ADAPTATION_MODE aMode = meshDim == 3 ? ADAPTATION_MODE::BOTH : ADAPTATION_MODE::SURFACE; // and when dimesh 3 without 2D mesh?
- emit meshDimSignal(aMode);
- }
-
- }
- else
- {
- return;
- }
-
-
- QFileInfo myFileInfo(fileName);
- *myFileInDir = myFileInfo.path();
- *myFileOutDir = myFileInfo.path();
- selectMedFileLineEdit->setText(myFileInfo.fileName());
- QString outF = fileName == QString::null ? myFileInfo.fileName() :
- QString( remove_extension(myFileInfo.fileName().toStdString() ).c_str() )+ QString(".adapt.med");
- selectOutMedFileLineEdit->setText(outF);
- onLocalSelected(myFileInfo.filePath());
-
-}
-
-void SMESHGUI_MgAdaptArguments::onLocalSelected(QString filePath)
-{
- myFieldList = GetListeChamps(filePath, false);
- if (myFieldList.empty())
- {
- if (localButton->isChecked())
- {
- fieldNameCmb->clear();
- }
-
- }
- else
- {
- // fill field name Combobox
- fieldNameCmb->clear();
- std::map<QString, int>::const_iterator it;
- for ( it = myFieldList.begin() ; it != myFieldList.end(); it++)
- {
- fieldNameCmb->insertItem(0,QString(it->first));
- int typeStepInField = it->second > 2 ? 2 : it->second ;
- timeStepGroupChanged(typeStepInField, true);
- }
-
- }
-}
-// =======================================================================
-// Gestion les boutons qui permettent de
-// 1) retourne le nom d'un fichier par une fenetre de dialogue si aucun
-// objet est selectionne dans l arbre d etude
-// 2) retourne le nom du fichier asocie a l objet
-// selectionne dans l arbre d etude
-// =======================================================================
-QString SMESHGUI_MgAdaptArguments::getMedFileName(bool avertir)
-{
-
- QString aFile = QString::null;
- QString filtre = QString("Med") ;
- filtre += QString(" files (*.") + QString("med") + QString(");;");
- aFile = SUIT_FileDlg::getOpenFileName(0, QObject::tr("MG_ADAPT_SELECT_FILE_0"), QString(""), filtre );
-
- return aFile;
-
-}
-void SMESHGUI_MgAdaptArguments::setMode(const Mode theMode, const SIZEMAP theSizeMap )
-{
- QRadioButton* aButton = qobject_cast<QRadioButton*>( meshInGroup->button( theMode ) );
- QRadioButton* bButton = qobject_cast<QRadioButton*>( sizeMapDefGroup->button( theSizeMap ) );
- if ( aButton ) {
- aButton->setChecked( true );
- modeChanged( theMode );
- }
- if ( bButton ) {
- bButton->setChecked( true );
- sizeMapDefChanged( theSizeMap );
- }
-}
-
-void SMESHGUI_MgAdaptArguments::modeChanged( int theMode )
-{
- clear();
- if(theMode == Mesh)
- {
- aBrowserObject->hide();
- selectMedFileLineEdit->show();
- selectMedFilebutton->show();
- localButton->setEnabled(true);
- }
- else
- {
- selectMedFileLineEdit->hide();
- selectMedFilebutton->hide();
- localButton->setEnabled(false);
- aBrowserObject->show();
- sizeMapDefChanged(Background);
- emit updateSelection();
- }
-
-
-
-}
-
-void SMESHGUI_MgAdaptArguments::sizeMapDefChanged( int theSizeMap )
-{
- fieldNameCmb->clear();
- if(theSizeMap == Local)
- {
- localButton->setEnabled(true);
- localButton->setChecked(true);
- medFileBackground->hide();
- selectMedFileBackgroundbutton->hide();
- selectMedFileBackgroundLineEdit->hide();
- selectMedFileBackgroundLineEdit->clear();
- valueLabel->hide();
- dvalue->hide();
-
- sizeMapField->setEnabled(true);
- if (!selectMedFileLineEdit->text().isEmpty())
- {
- QFileInfo myFileInfo(QDir(*myFileInDir), selectMedFileLineEdit->text());
- onLocalSelected(myFileInfo.filePath());
- }
- }
- else if (theSizeMap == Background)
- {
- medFileBackground->show();
- backgroundButton->setChecked(true);
- selectMedFileBackgroundbutton->show();
- selectMedFileBackgroundLineEdit->show();
- valueLabel->hide();
- dvalue->hide();
- sizeMapField->setEnabled(true);
-
- }
- else
- {
- medFileBackground->hide();
- constantButton->setChecked(true);
- selectMedFileBackgroundbutton->hide();
- selectMedFileBackgroundLineEdit->clear();
- selectMedFileBackgroundLineEdit->hide();
- valueLabel->show();
- dvalue->show();
- sizeMapField->setEnabled(false);
-
- }
-
-
-}
-void SMESHGUI_MgAdaptArguments::timeStepGroupChanged(int timeStepType, bool disableOther, int max)
-{
- switch (timeStepType)
- {
- case 0 :
- onNoTimeStep(disableOther);
- break;
- case 1 :
- onLastTimeStep(disableOther);
- break;
- case 2 :
- onChosenTimeStep(disableOther, max);
- default:
- break;
- }
-}
-
-void SMESHGUI_MgAdaptArguments::clear()
-{
- selectMedFileLineEdit->clear();
- aBrowserObject->clear();
-
- meshNameLineEdit->clear();
- selectOutMedFileLineEdit->clear();
-}
-med_int SMESHGUI_MgAdaptArguments::getMeshDim() const
-{
- return meshDim;
-}
-QWidget* ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const
-{
- bool editable = index.data( EDITABLE_ROLE ).toInt();
- return editable ? QItemDelegate::createEditor( parent, o, index ) : 0;
-}
-
-//////////////////////////////////////////
-// MgAdaptAdvWidget
-//////////////////////////////////////////
-
-MgAdaptAdvWidget::MgAdaptAdvWidget( QWidget* parent, std::vector <std::string>* options, Qt::WindowFlags f )
- : QWidget( parent, f ), myOptions(options)
-{
- setupWidget();
- myOptionTable->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
- myOptionTable->setItemDelegate( new ItemDelegate( myOptionTable ) );
-
- for ( int i = 0, nb = myOptions->size(); i < nb; ++i )
- {
- AddOption( (*myOptions)[i].c_str() );
- }
-
- connect( myOptionTable, SIGNAL( itemChanged(QTreeWidgetItem *, int)), SLOT( itemChanged(QTreeWidgetItem *, int )));
- connect( addBtn, SIGNAL( clicked() ), this, SLOT( onAddOption() ) );
- connect(workingDirectoryPushButton, SIGNAL(pressed()), this, SLOT(_onWorkingDirectoryPushButton()));
-}
-
-MgAdaptAdvWidget::~MgAdaptAdvWidget()
-{
-}
-
-void MgAdaptAdvWidget::AddOption( const char* option, bool isCustom )
-{
-
-
- QString name, value;
- bool isDefault = false;
- if ( option )
- {
- QStringList name_value_type = QString(option).split( ":", QString::KeepEmptyParts );
- if ( name_value_type.size() > 0 )
- name = name_value_type[0];
- if ( name_value_type.size() > 1 )
- value = name_value_type[1];
- if ( name_value_type.size() > 2 )
- isDefault = !name_value_type[2].toInt();
-
- }
- QTreeWidget* table = myOptionTable;
- //table->setExpanded( true );
-
- QTreeWidgetItem* row;
- if (optionTreeWidgetItem.size())
- {
- std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(name);
- if(it != optionTreeWidgetItem.end()) return; // option exist
- else
- {
- row = getNewQTreeWidgetItem(table, option, name, isCustom);
- }
- }
- else
- {
- row = getNewQTreeWidgetItem(table, option, name, isCustom);
- }
- row->setText( 0, tr( name.toLatin1().constData() ));
- row->setText( 1, tr( value.toLatin1().constData() ));
- row->setCheckState( 0, isDefault ? Qt::Unchecked : Qt::Checked);
- row->setData( NAME_COL, PARAM_NAME, name );
-
- if ( isCustom )
- {
- myOptionTable->scrollToItem( row );
- myOptionTable->setCurrentItem( row );
- myOptionTable->editItem( row, NAME_COL );
- }
-}
-
-QTreeWidgetItem* MgAdaptAdvWidget::getNewQTreeWidgetItem(QTreeWidget* table, const char* option, QString& name, bool isCustom)
-{
- QTreeWidgetItem* row = new QTreeWidgetItem( table );
- row->setData( NAME_COL, EDITABLE_ROLE, int( isCustom && !option ));
- row->setFlags( row->flags() | Qt::ItemIsEditable );
- optionTreeWidgetItem.insert(std::pair <QString, QTreeWidgetItem*> (name, row));
-
- return row;
-}
-
-void MgAdaptAdvWidget::onAddOption()
-{
- AddOption( NULL, true );
-}
-void MgAdaptAdvWidget::GetOptionAndValue( QTreeWidgetItem * tblRow,
- QString& option,
- QString& value,
- bool& isDefault)
-{
- option = tblRow->data( NAME_COL, PARAM_NAME ).toString();
- value = tblRow->text( VALUE_COL );
- isDefault = ! tblRow->checkState( NAME_COL );
-
-}
-
-
-void MgAdaptAdvWidget::itemChanged(QTreeWidgetItem* tblRow, int column)
-{
- if ( tblRow )
- {
- myOptionTable->blockSignals( true );
-
- tblRow->setData( VALUE_COL, EDITABLE_ROLE, int( tblRow->checkState( NAME_COL )));
-
- int c = tblRow->checkState( NAME_COL ) ? 0 : 150;
- tblRow->setForeground( VALUE_COL, QBrush( QColor( c, c, c )));
-
- if ( column == NAME_COL && tblRow->data( NAME_COL, EDITABLE_ROLE ).toInt() ) // custom table
- {
- tblRow->setData( NAME_COL, PARAM_NAME, tblRow->text( NAME_COL ));
- }
-
- myOptionTable->blockSignals( false );
- }
-}
-void MgAdaptAdvWidget::setupWidget()
-{
- if (this->objectName().isEmpty())
- this->setObjectName(QString(tr("MG-ADAPT-ADV")));
- this->resize(337, 369);
- gridLayout_4 = new QGridLayout(this);
- gridLayout_4->setObjectName(QString("gridLayout_4"));
- myOptionTable = new MgAdaptAdvWidgetTreeWidget(this);
- QFont font;
- font.setBold(false);
- font.setWeight(50);
- QTreeWidgetItem *__qtreewidgetitem = new QTreeWidgetItem();
- __qtreewidgetitem->setFont(1, font);
- __qtreewidgetitem->setFont(0, font);
- __qtreewidgetitem->setText(1, tr("OPTION_VALUE_COLUMN"));
- __qtreewidgetitem->setText(0, tr("OPTION_NAME_COLUMN"));
- myOptionTable->setHeaderItem(__qtreewidgetitem);
- myOptionTable->setObjectName(QString("myOptionTable"));
- myOptionTable->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
- myOptionTable->setTabKeyNavigation(true);
-
- gridLayout_4->addWidget(myOptionTable, 0, 0, 1, 2);
-
- addBtn = new QPushButton(this);
- addBtn->setObjectName(QString("addBtn"));
-
- gridLayout_4->addWidget(addBtn, 1, 0, 1, 1);
-
- horizontalSpacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
-
- gridLayout_4->addItem(horizontalSpacer, 1, 1, 1, 1);
-
- logGroupBox = new QGroupBox(this);
- logGroupBox->setObjectName(QString("logGroupBox"));
- gridLayout_2 = new QGridLayout(logGroupBox);
- gridLayout_2->setObjectName(QString("gridLayout_2"));
- gridLayout = new QGridLayout();
- gridLayout->setObjectName(QString("gridLayout"));
- workingDirectoryLabel = new QLabel(logGroupBox);
- workingDirectoryLabel->setObjectName(QString("workingDirectoryLabel"));
-
- gridLayout->addWidget(workingDirectoryLabel, 0, 0, 1, 1);
-
- workingDirectoryLineEdit = new QLineEdit(logGroupBox);
- workingDirectoryLineEdit->setObjectName(QString("workingDirectoryLineEdit"));
-
- gridLayout->addWidget(workingDirectoryLineEdit, 0, 1, 1, 1);
-
- workingDirectoryPushButton = new QPushButton(logGroupBox);
- workingDirectoryPushButton->setObjectName(QString("workingDirectoryPushButton"));
-
- gridLayout->addWidget(workingDirectoryPushButton, 0, 2, 1, 1);
-
- verboseLevelLabel = new QLabel(logGroupBox);
- verboseLevelLabel->setObjectName(QString("verboseLevelLabel"));
-
- gridLayout->addWidget(verboseLevelLabel, 1, 0, 1, 1);
-
- verboseLevelSpin = new QSpinBox(logGroupBox);
- verboseLevelSpin->setObjectName(QString("verboseLevelSpin"));
-
- gridLayout->addWidget(verboseLevelSpin, 1, 1, 1, 1);
-
-
- gridLayout_2->addLayout(gridLayout, 0, 0, 1, 1);
-
- horizontalLayout = new QHBoxLayout();
- horizontalLayout->setObjectName(QString("horizontalLayout"));
- logInFileCheck = new QCheckBox(logGroupBox);
- logInFileCheck->setObjectName(QString("logInFileCheck"));
- logInFileCheck->setChecked(true);
-
- horizontalLayout->addWidget(logInFileCheck);
-
- removeLogOnSuccessCheck = new QCheckBox(logGroupBox);
- removeLogOnSuccessCheck->setObjectName(QString("removeLogOnSuccessCheck"));
- removeLogOnSuccessCheck->setChecked(true);
-
- horizontalLayout->addWidget(removeLogOnSuccessCheck);
-
-
- gridLayout_2->addLayout(horizontalLayout, 1, 0, 1, 1);
-
- keepWorkingFilesCheck = new QCheckBox(logGroupBox);
- keepWorkingFilesCheck->setObjectName(QString("keepWorkingFilesCheck"));
- keepWorkingFilesCheck->setAutoExclusive(false);
-
- gridLayout_2->addWidget(keepWorkingFilesCheck, 2, 0, 1, 1);
-
-
- gridLayout_4->addWidget(logGroupBox, 3, 0, 1, 2);
-
-
- // retranslateUi(this);
-
- // QMetaObject::connectSlotsByName(this);
-
-}
-void MgAdaptAdvWidget::_onWorkingDirectoryPushButton()
-{
- QString aDirName=QFileDialog::getExistingDirectory ();
- if (!(aDirName.isEmpty()))workingDirectoryLineEdit->setText(aDirName);
-}
-void MgAdaptAdvWidget::onMeshDimChanged(ADAPTATION_MODE aMode)
-{
- /* default adaptation mode
- * assume that if meshDim == 2 -->adaptation surface
- * if meshDim == 3 and if there is not 2D mesh -->VOLUME
- * else BOTH
- */
-
- QString adaptation("adaptation"), value;
- switch(aMode)
- {
- case ADAPTATION_MODE::SURFACE:
- {
- value ="surface";
- setOptionValue(adaptation, value);
- break;
- }
- case ADAPTATION_MODE::BOTH :
- {
- value = "both";
- setOptionValue(adaptation, value);
- break;
- }
- case ADAPTATION_MODE::VOLUME :
- {
- value = "volume";
- setOptionValue(adaptation, value);
- break;
- }
- }
-}
-void MgAdaptAdvWidget::setOptionValue(QString& option, QString& value)
-{
-
- std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(option);
- if (it != optionTreeWidgetItem.end())
- {
- it->second->setText( 0, tr( option.toLatin1().constData() ));
- it->second->setText( 1, tr( value.toLatin1().constData() ));
- it->second->setCheckState( 0, Qt::Checked );
- it->second->setData( NAME_COL, PARAM_NAME, option );
- myOptionTable->editItem( it->second, NAME_COL );
- }
-}
-namespace
-{
-bool isEditable( const QModelIndex& index )
-{
- return index.isValid() &&
- index.flags() & Qt::ItemIsEditable &&
- index.flags() & Qt::ItemIsEnabled &&
- ( !index.data( Qt::UserRole + 1 ).isValid() || index.data( Qt::UserRole + 1 ).toInt() != 0 );
-}
-}
-
-MgAdaptAdvWidgetTreeWidget::MgAdaptAdvWidgetTreeWidget( QWidget* parent )
- : QTreeWidget( parent )
-{
-}
-
-QModelIndex MgAdaptAdvWidgetTreeWidget::moveCursor( CursorAction action, Qt::KeyboardModifiers modifiers )
-{
- QModelIndex current = currentIndex();
- int column = current.column();
- if ( action == MoveNext ) {
- if ( column < columnCount()-1 ) {
- QModelIndex next = current.sibling( current.row(), column+1 );
- if ( isEditable( next ) )
- return next;
- }
- else {
- QModelIndex next = current.sibling( current.row()+1, 0 );
- if ( isEditable( next ) )
- return next;
- }
- }
- else if ( action == MovePrevious ) {
- if ( column == 0 ) {
- QModelIndex next = current.sibling( current.row()-1, columnCount()-1 );
- if ( isEditable( next ) )
- return next;
- }
- else {
- QModelIndex next = current.sibling( current.row(), column-1 );
- if ( isEditable( next ) )
- return next;
- }
- }
- return QTreeWidget::moveCursor( action, modifiers );
-}
-
-void MgAdaptAdvWidgetTreeWidget::keyPressEvent( QKeyEvent* e )
-{
- switch ( e->key() ) {
- case Qt::Key_F2:
- {
- QModelIndex index = currentIndex();
- if ( !isEditable( index ) ) {
- for ( int i = 0; i < columnCount(); i++ ) {
- QModelIndex sibling = index.sibling( index.row(), i );
- if ( isEditable( sibling ) ) {
- if ( !edit( sibling, EditKeyPressed, e ) )
- e->ignore();
- }
- }
- }
- }
- break;
- default:
- break;
- }
- QTreeWidget::keyPressEvent( e );
-}
-
-
-// =======================================================================
-// renvoie le medId associe au fichier Med apres ouverture
-// =======================================================================
-med_idt OuvrirFichier(QString aFile)
-{
- med_idt medIdt = MEDfileOpen(aFile.toStdString().c_str(),MED_ACC_RDONLY);
- if (medIdt <0)
- {
- QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
- QObject::tr("MG_ADAPT_MED_FILE_1") );
- }
- return medIdt;
-}
-
-// ======================================================
-// ========================================================
-QString lireNomMaillage(QString aFile, med_int& meshdim)
-{
- QString nomMaillage = QString::null ;
- int erreur = 0 ;
- med_idt medIdt ;
-
- // Ouverture du fichier
- medIdt = OuvrirFichier(aFile);
- if ( medIdt < 0 )
- {
- erreur = 1 ;
- return nomMaillage;
- }
- med_int numberOfMeshes = MEDnMesh(medIdt) ;
- if (numberOfMeshes == 0 )
- {
- QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
- QObject::tr("MG_ADAPT_MED_FILE_2") );
- erreur = 2 ;
- return nomMaillage;
- }
- if (numberOfMeshes > 1 )
- {
- QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
- QObject::tr("MG_ADAPT_MED_FILE_3") );
- erreur = 3 ;
- return nomMaillage;
- }
-
- nomMaillage = lireNomMaillage2(medIdt,1, meshdim);
- // Fermeture du fichier
- if ( medIdt > 0 ) MEDfileClose(medIdt);
-
- return nomMaillage;
-}
-
-// =======================================================================
-// =======================================================================
-QString lireNomMaillage2(med_idt medIdt,int meshId, med_int& meshdim )
-{
- QString NomMaillage=QString::null;
- char meshname[MED_NAME_SIZE+1];
- med_int spacedim;
- med_mesh_type meshtype;
- char descriptionription[MED_COMMENT_SIZE+1];
- char dtunit[MED_SNAME_SIZE+1];
- med_sorting_type sortingtype;
- med_int nstep;
- med_axis_type axistype;
- int naxis = MEDmeshnAxis(medIdt,1);
- char *axisname=new char[naxis*MED_SNAME_SIZE+1];
- char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
- med_err aRet = MEDmeshInfo(medIdt,
- meshId,
- meshname,
- &spacedim,
- &meshdim,
- &meshtype,
- descriptionription,
- dtunit,
- &sortingtype,
- &nstep,
- &axistype,
- axisname,
- axisunit);
-
- if ( aRet < 0 ) {
- QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"), \
- QObject::tr("MG_ADAPT_MED_FILE_4") );
- }
- else {
- NomMaillage=QString(meshname);
- }
-
- delete[] axisname ;
- delete[] axisunit ;
-
- return NomMaillage;
-}
-
-
-
-// =======================================================================
-std::map<QString, int> GetListeChamps(QString aFile, bool errorMessage)
-// =======================================================================
-{
-// Il faut voir si plusieurs maillages
-
- MESSAGE("GetListeChamps");
- std::map<QString, int> ListeChamp ;
-
- med_err erreur = 0 ;
- med_idt medIdt ;
-
- while ( erreur == 0 )
- {
- // Ouverture du fichier
- SCRUTE(aFile.toStdString());
- medIdt = OuvrirFichier(aFile);
- if ( medIdt < 0 )
- {
- erreur = 1 ;
- break ;
- }
- // Lecture du nombre de champs
- med_int ncha = MEDnField(medIdt) ;
- if (ncha < 1 )
- {
- if(errorMessage)
- {
- QMessageBox::critical( 0, QObject::tr("_ERROR"),
- QObject::tr("HOM_MED_FILE_5") );
- }
- erreur = 2 ;
- break ;
- }
- // Lecture des caracteristiques des champs
- for (int i=0; i< ncha; i++)
- {
-// Lecture du nombre de composantes
- med_int ncomp = MEDfieldnComponent(medIdt,i+1);
-// Lecture du type du champ, des noms des composantes et du nom de l'unite
- char nomcha [MED_NAME_SIZE+1];
- char meshname[MED_NAME_SIZE+1];
- char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
- char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
- char dtunit[MED_SNAME_SIZE+1];
- med_bool local;
- med_field_type typcha;
- med_int nbofcstp;
- erreur = MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) ;
- free(comp);
- free(unit);
- if ( erreur < 0 )
- {
- if(errorMessage)
- {
- QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
- QObject::tr("MG_ADAPT_MED_FILE_6") );
- }
- break ;
- }
-
- ListeChamp.insert(std::pair<QString, int> (QString(nomcha), nbofcstp));
-
- }
- break ;
- }
- // Fermeture du fichier
- if ( medIdt > 0 ) MEDfileClose(medIdt);
-
- return ListeChamp;
-}
-
-std::string remove_extension(const std::string& filename) {
- size_t lastdot = filename.find_last_of(".");
- if (lastdot == std::string::npos) return filename;
- return filename.substr(0, lastdot);
-}
-
-
+++ /dev/null
-// Copyright (C) 2011-2020 CEA/DEN, EDF R&D\r
-//\r
-// This library is free software; you can redistribute it and/or\r
-// modify it under the terms of the GNU Lesser General Public\r
-// License as published by the Free Software Foundation; either\r
-// version 2.1 of the License, or (at your option) any later version.\r
-//\r
-// This library is distributed in the hope that it will be useful,\r
-// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
-// Lesser General Public License for more details.\r
-//\r
-// You should have received a copy of the GNU Lesser General Public\r
-// License along with this library; if not, write to the Free Software\r
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
-//\r
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com\r
-//\r
-\r
-// SMESH SMESHGUI : GUI for the adaptation in the SMESH component\r
-// File : MG_ADAPTGUI.hxx\r
-//\r
-#ifndef MG_ADAPTGUI_HXX\r
-#define MG_ADAPTGUI_HXX\r
-\r
-#include <set>\r
-// SMESH includes\r
-\r
-// Qt includes\r
-#include <QDialog>\r
-#include <QTreeWidget>\r
-#include<QItemDelegate>\r
-\r
-#include "LightApp_DataOwner.h"\r
-#include "SalomeApp_Application.h"\r
-#include <SALOMEconfig.h>\r
-#include <SALOME_ListIO.hxx>\r
-#include "SalomeApp_Module.h"\r
-#include "SalomeApp_Study.h"\r
-#include <med.h>\r
-#include <map>\r
-\r
-\r
-// model\r
-\r
-\r
-#include "MG_ADAPT.hxx"\r
-\r
-class SUIT_ViewWindow;\r
-class SUIT_Desktop;\r
-class SUIT_Study;\r
-class SUIT_ResourceMgr;\r
-\r
-class CAM_Module;\r
-\r
-class SALOMEDSClient_Study;\r
-class SALOMEDSClient_SObject;\r
-\r
-class SalomeApp_Study;\r
-class SalomeApp_Module;\r
-class LightApp_SelectionMgr;\r
-\r
-\r
-class QButtonGroup;\r
-class QLineEdit;\r
-class QGroupBox;\r
-class QRadioButton;\r
-class QLabel;\r
-class QCheckBox;\r
-class QGridLayout;\r
-class QTabWidget;\r
-class QDoubleSpinBox;\r
-class QSpinBox;\r
-class QTreeWidget;\r
-class QTreeWidgetItem;\r
-class QSpacerItem;\r
-class QHBoxLayout;\r
-class QItemDelegate;\r
-class QComboBox;\r
-\r
-// IDL includes\r
-#include <SALOMEconfig.h>\r
-\r
-class SVTK_ViewWindow;\r
-class SVTK_Selector;\r
-class SMESHGUI_MgAdaptDlg;\r
-class SMESHGUI_MgAdaptArguments;\r
-class SMESHGUI_SpinBox;\r
-class MgAdaptAdvWidgetTreeWidget;\r
-class MgAdaptAdvWidget;\r
-class MgAdapt;\r
-class QHeaderView;\r
-class QFileDialog;\r
-\r
-\r
-std::map<QString, int> GetListeChamps(QString aFile, bool errorMessage = true);\r
-QString lireNomMaillage(QString aFile, med_int& meshDim);\r
-QString lireNomMaillage2(med_idt medIdt,int meshId, med_int& meshDim);\r
-med_idt OuvrirFichier(QString aFile);\r
-std::string remove_extension(const std::string& filename);\r
-\r
-\r
-enum ADAPTATION_MODE{
- SURFACE, // surface adaption when meshDim == 2\r
- VOLUME, // \r
- BOTH
-};\r
-//=================================================================================\r
-// class : SMESHGUI_MgAdaptDlg\r
-// purpose :\r
-//=================================================================================\r
-class SMESHGUI_MgAdaptDlg : public QDialog\r
-{\r
- Q_OBJECT;\r
-public:\r
- //! Property type\r
- enum Mode { Arguments, AdvancedOptions};\r
- SMESHGUI_MgAdaptDlg( SalomeApp_Module*, MgAdapt*, QWidget* parent= 0,bool isCreation = true );\r
- ~SMESHGUI_MgAdaptDlg();\r
-\r
- void buildDlg();\r
- void reject();\r
- bool checkParams(QString& msg) ;\r
- void setModel(MgAdapt*);\r
- MgAdapt* getModel() const;\r
-\r
-public slots:\r
-\r
-protected slots:\r
-\r
- virtual bool clickOnApply();\r
-private slots:\r
- virtual void clickOnHelp();\r
- virtual void clickOnOk();\r
-protected :\r
-\r
- SMESHGUI_MgAdaptArguments* myArgs;\r
- MgAdaptAdvWidget* myAdvOpt;\r
- bool readParamsFromHypo( ) const ;\r
- bool readParamsFromWidgets( ) ;\r
- bool storeParamsToHypo( const MgAdaptHypothesisData& ) const;\r
-\r
-private:\r
-\r
-\r
- SalomeApp_Module* mySMESHGUI; /* Current SMESHGUI object */\r
- QTabWidget* myTabWidget;\r
-\r
-\r
- MgAdaptHypothesisData* myData;\r
- MgAdapt* model;\r
-\r
-};\r
-\r
-class SMESHGUI_MgAdaptArguments : public QWidget\r
-{\r
- Q_OBJECT;\r
-public:\r
- //! Property type\r
- enum Mode { Mesh, Browser};\r
- enum SIZEMAP { Local, Background, Constant};\r
- SMESHGUI_MgAdaptArguments( QWidget* parent);\r
- ~SMESHGUI_MgAdaptArguments();\r
- void setMode( const Mode, const SIZEMAP );\r
- med_int getMeshDim() const;\r
-\r
- QString* myFileInDir;\r
- QString* myFileOutDir;\r
- QString* myFileSizeMapDir;\r
- QGroupBox* aMeshIn ;\r
- QRadioButton* aMedfile;\r
- QRadioButton* aBrowser ;\r
- QLineEdit* aBrowserObject;\r
- QPushButton* selectMedFilebutton ;\r
- QSpacerItem* hspacer;\r
- QLineEdit* selectMedFileLineEdit ;\r
- QButtonGroup* meshInGroup ;\r
- QGridLayout* meshIn ;\r
-\r
- QGroupBox* aMeshOut ;\r
- QLabel* meshName;\r
- QLineEdit* meshNameLineEdit;\r
- QSpacerItem* secondHspacer;\r
- QCheckBox* medFileCheckBox;\r
- QPushButton* selectOutMedFilebutton;\r
- QLineEdit* selectOutMedFileLineEdit;\r
- QSpacerItem* thirdHspacer;\r
- QCheckBox* publishOut;\r
- QGridLayout* meshOut ;\r
-\r
- QGroupBox* sizeMapDefinition ;\r
- QRadioButton* localButton;\r
- QRadioButton* backgroundButton ;\r
- QRadioButton* constantButton ;\r
- QLabel* medFileBackground;\r
- QPushButton* selectMedFileBackgroundbutton;\r
- QLineEdit* selectMedFileBackgroundLineEdit;\r
- QLabel* valueLabel;\r
- QDoubleSpinBox* dvalue;\r
- QButtonGroup* sizeMapDefGroup ;\r
- QGridLayout* sizeMapDefGroupLayout;\r
-\r
-\r
- QGroupBox* sizeMapField;\r
- QLabel* fieldName;\r
- QComboBox* fieldNameCmb;\r
- QRadioButton* noTimeStep;\r
- QRadioButton* lastTimeStep ;\r
- QRadioButton* chosenTimeStep;\r
- QLabel* timeStepLabel;\r
- QSpinBox* timeStep;\r
- QLabel* rankLabel;\r
- QSpinBox* rankSpinBox;\r
- QButtonGroup* timeStepGroup;\r
- QGridLayout* sizeMapFieldGroupLayout;\r
-\r
-signals:\r
- void updateSelection();\r
- void toExportMED(const char *);\r
- void meshDimSignal(ADAPTATION_MODE aMode);\r
-public slots:\r
-\r
-protected slots:\r
-\r
-private slots:\r
- void modeChanged( int);\r
- void sizeMapDefChanged(int);\r
- void timeStepGroupChanged(int timeStepType, bool disableOther = false, int max = 0);\r
- void onSelectMedFilebuttonClicked();\r
- void clear();\r
- void onMedFileCheckBox(int);\r
- void onPublishOut(int);\r
- void onSelectOutMedFilebutton();\r
- void onSelectMedFileBackgroundbutton();\r
- void onLocalSelected(QString);\r
- void onNoTimeStep(bool disableOther = false);\r
- void onLastTimeStep(bool disableOther = false);\r
- void onChosenTimeStep(bool disableOther = false, int max = 0);\r
-\r
-private:\r
-\r
- QString getMedFileName(bool avertir);\r
- LightApp_SelectionMgr* selMgr ;\r
- med_int meshDim;\r
- std::map<QString, int> myFieldList;\r
-\r
-\r
-};\r
-enum {\r
- OPTION_ID_COLUMN = 0,\r
- OPTION_TYPE_COLUMN,\r
- OPTION_NAME_COLUMN = 0,\r
- OPTION_VALUE_COLUMN,\r
- NB_COLUMNS,\r
-};\r
-\r
-//////////////////////////////////////////\r
-// MgAdaptAdvWidget\r
-//////////////////////////////////////////\r
-class MgAdaptAdvWidget : public QWidget\r
-{\r
- Q_OBJECT\r
-\r
-public:\r
- MgAdaptAdvWidget( QWidget* = 0, std::vector <std::string> * = nullptr, Qt::WindowFlags = 0 );\r
- ~MgAdaptAdvWidget();\r
- std::vector < std::string > * myOptions;\r
- QGridLayout *gridLayout_4;\r
- MgAdaptAdvWidgetTreeWidget *myOptionTable;\r
- QPushButton *addBtn;\r
- QSpacerItem *horizontalSpacer;\r
- QGroupBox *logGroupBox;\r
- QGridLayout *gridLayout_2;\r
- QGridLayout *gridLayout;\r
- QLabel *workingDirectoryLabel;\r
- QLineEdit *workingDirectoryLineEdit;\r
- QPushButton *workingDirectoryPushButton;\r
- QLabel *verboseLevelLabel;\r
- QSpinBox *verboseLevelSpin;\r
- QHBoxLayout *horizontalLayout;\r
- QCheckBox *logInFileCheck;\r
- QCheckBox *removeLogOnSuccessCheck;\r
- QCheckBox *keepWorkingFilesCheck;\r
-\r
- void AddOption( const char* name_value_type, bool isCustom = false );\r
- void GetOptionAndValue( QTreeWidgetItem * tblRow, QString& option, QString& value, bool& dflt );\r
- void setupWidget();\r
-public slots:\r
-\r
- void onAddOption();\r
- void itemChanged(QTreeWidgetItem * tblRow, int column);\r
- void onMeshDimChanged(ADAPTATION_MODE aMode);\r
-private slots:\r
- void _onWorkingDirectoryPushButton();\r
-private:\r
- void setOptionValue(QString& option, QString& value);\r
- std::map<QString, QTreeWidgetItem *> optionTreeWidgetItem;\r
- \r
- QTreeWidgetItem* getNewQTreeWidgetItem(QTreeWidget* table, const char* option, QString& name, bool isCustom);\r
-\r
-};\r
-\r
-enum { EDITABLE_ROLE = Qt::UserRole + 1, PARAM_NAME,\r
- NAME_COL = 0, VALUE_COL\r
- };\r
-\r
-\r
-\r
-class ItemDelegate: public QItemDelegate\r
-{\r
-public:\r
-\r
- ItemDelegate(QObject* parent=0): QItemDelegate(parent) {}\r
- QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const;\r
-};\r
-\r
-class MgAdaptAdvWidgetTreeWidget : public QTreeWidget\r
-{\r
- Q_OBJECT\r
-public:\r
- MgAdaptAdvWidgetTreeWidget( QWidget* );\r
-\r
-protected:\r
- QModelIndex moveCursor( CursorAction, Qt::KeyboardModifiers );\r
- void keyPressEvent( QKeyEvent* );\r
-};\r
-\r
-\r
-#endif // MG_ADAPTGUI_HXX\r