From: GERALD NICOLAS Date: Wed, 3 Feb 2021 14:55:16 +0000 (+0100) Subject: Remplacement des taquets de tabulations paor des espaces X-Git-Tag: V9_7_0a1~18^2~25 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=36e723d3d39def077f49db994e6bbe4693ace7f0;p=modules%2Fsmesh.git Remplacement des taquets de tabulations paor des espaces --- diff --git a/src/SMESH/MG_ADAPT.cxx b/src/SMESH/MG_ADAPT.cxx index b59fde866..640305541 100644 --- a/src/SMESH/MG_ADAPT.cxx +++ b/src/SMESH/MG_ADAPT.cxx @@ -17,7 +17,7 @@ // 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/ +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // file : MG_ADAPT.cxx #include "MG_ADAPT.hxx" @@ -41,469 +41,460 @@ using namespace MG_ADAPT; 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 "; + 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; + return errStr; } 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); + size_t lastdot = filename.find_last_of("."); + if (lastdot == std::string::npos) return filename; + return filename.substr(0, lastdot); } namespace { struct GET_DEFAULT // struct used to get default value from GetOptionValue() { - bool isDefault; - operator bool* () { - return &isDefault; - } + 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(); + 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(); + data = new MgAdaptHypothesisData(); + setData(myData); + buildModel(); } MgAdapt::MgAdapt( const MgAdapt& copy) { + data = new MgAdaptHypothesisData(); + MgAdaptHypothesisData *copyData = copy.getData(); + copyMgAdaptHypothesisData(copyData); + setAll(); - 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; - + 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; - + delete data; } void MgAdapt::buildModel() { - const char* boolOptionNames[] = { "compute_ridges", // yes + 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* 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()); + 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() ))); + 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; + return vals; } std::vector MgAdapt::getOptionValuesStrVec() const { - std::vector 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() )); + std::vector 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; + return vals; } std::vector MgAdapt::getCustomOptionValuesStrVec() const { - std::vector 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; + std::vector 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; + return _customOption2value; } void MgAdapt::setData(MgAdaptHypothesisData* myData) { - copyMgAdaptHypothesisData(myData); - setAll(); + copyMgAdaptHypothesisData(myData); + setAll(); } MgAdaptHypothesisData* MgAdapt::getData() const { - return data; + return data; } void MgAdapt::setMedFileIn(std::string fileName) { - medFileIn = fileName; - if (medFileOut == "") // default MED file Out - medFileOut = remove_extension( fileName )+ ".adapt.med"; + medFileIn = fileName; + if (medFileOut == "") // default MED file Out + medFileOut = remove_extension( fileName )+ ".adapt.med"; } std::string MgAdapt::getMedFileIn() { - return medFileIn; + return medFileIn; } void MgAdapt::setMedFileOut(std::string fileOut) { - medFileOut = fileOut; + medFileOut = fileOut; } std::string MgAdapt::getMedFileOut() { - return medFileOut; + return medFileOut; } void MgAdapt::setMeshOutMed(bool mybool) { - meshOutMed = mybool; + meshOutMed = mybool; } bool MgAdapt::getMeshOutMed() { - return meshOutMed; + return meshOutMed; } void MgAdapt::setPublish(bool mybool) { - publish = mybool; + publish = mybool; } bool MgAdapt::getPublish() { - return publish; + return publish; } void MgAdapt::setFieldName(std::string myFieldName) { - fieldName = myFieldName; + fieldName = myFieldName; } std::string MgAdapt::getFieldName() { - return fieldName; + return fieldName; } void MgAdapt::setTimeStep(int time) { - timeStep = time; + timeStep = time; } int MgAdapt::getTimeStep() const { - return timeStep; + return timeStep; } void MgAdapt::setRankTimeStep(int time, int myRank) { - timeStep = time; - rank = myRank; + timeStep = time; + rank = myRank; } int MgAdapt::getRank() { - return rank; + return rank; } void MgAdapt::setTimeStepRankLast() { - myUseLastTimeStep = true; - myUseChosenTimeStep = false; - myUseNoTimeStep = false; - //~med_int aRank, tmst; - //~std::string fieldFile = useBackgroundMap ? sizeMapFile : medFileIn; - //~getTimeStepInfos(fieldFile, tmst, aRank); - //~setRankTimeStep((int) tmst, (int) aRank); + myUseLastTimeStep = true; + myUseChosenTimeStep = false; + myUseNoTimeStep = false; + //~med_int aRank, tmst; + //~std::string fieldFile = useBackgroundMap ? sizeMapFile : medFileIn; + //~getTimeStepInfos(fieldFile, tmst, aRank); + //~setRankTimeStep((int) tmst, (int) aRank); } void MgAdapt::setNoTimeStep() { - myUseLastTimeStep = false; - myUseChosenTimeStep = false; - myUseNoTimeStep = true; - //~int aRank = (int)MED_NO_IT; - //~int tmst = (int)MED_NO_DT ; - //~setRankTimeStep(tmst, aRank); + myUseLastTimeStep = false; + myUseChosenTimeStep = false; + myUseNoTimeStep = true; + //~int aRank = (int)MED_NO_IT; + //~int tmst = (int)MED_NO_DT ; + //~setRankTimeStep(tmst, aRank); } void MgAdapt::setChosenTimeStepRank() { - myUseLastTimeStep = false; - myUseChosenTimeStep = true; - myUseNoTimeStep = false; - //~int aRank = (int)MED_NO_IT; - //~int tmst = (int)MED_NO_DT ; - //~setRankTimeStep(tmst, aRank); + myUseLastTimeStep = false; + myUseChosenTimeStep = true; + myUseNoTimeStep = false; + //~int aRank = (int)MED_NO_IT; + //~int tmst = (int)MED_NO_DT ; + //~setRankTimeStep(tmst, aRank); } void MgAdapt::setUseLocalMap(bool myLocal) { - useLocalMap = myLocal; + useLocalMap = myLocal; } bool MgAdapt::getUseLocalMap() { - return useLocalMap; + return useLocalMap; } void MgAdapt::setUseBackgroundMap(bool bckg) { - useBackgroundMap = bckg; + useBackgroundMap = bckg; } bool MgAdapt::getUseBackgroundMap() { - return useBackgroundMap; + return useBackgroundMap; } void MgAdapt::setUseConstantValue(bool cnst) { - useConstantValue = cnst; + useConstantValue = cnst; } bool MgAdapt::getUseConstantValue() { - return useConstantValue; + return useConstantValue; } void MgAdapt::setLogFile(std::string myLogFile) { - logFile = myLogFile; + logFile = myLogFile; } std::string MgAdapt::getLogFile() { - return logFile; + return logFile; } void MgAdapt::setVerbosityLevel(int verboLevel) { - verbosityLevel = verboLevel; + verbosityLevel = verboLevel; } int MgAdapt::getVerbosityLevel() { - return verbosityLevel; + return verbosityLevel; } void MgAdapt::setRemoveOnSuccess(bool rmons) { - removeOnSuccess = rmons; + removeOnSuccess = rmons; } bool MgAdapt::getRemoveOnSuccess() { - return removeOnSuccess; + return removeOnSuccess; } void MgAdapt::setSizeMapFile(std::string mapFile) { - sizeMapFile = mapFile; + sizeMapFile = mapFile; } std::string MgAdapt::getSizeMapFile() { - return sizeMapFile; + return sizeMapFile; } void MgAdapt::setMeshName(std::string name) { - meshName = name; + meshName = name; } std::string MgAdapt::getMeshName() { - return meshName; + return meshName; } void MgAdapt::setMeshNameOut(std::string name) { - meshNameOut = name; + meshNameOut = name; } std::string MgAdapt::getMeshNameOut() { - return meshNameOut; + return meshNameOut; } void MgAdapt::setFromMedFile(bool mybool) { - fromMedFile = mybool; + fromMedFile = mybool; } bool MgAdapt::isFromMedFile() { - return fromMedFile; + return fromMedFile; } void MgAdapt::setConstantValue(double cnst) { - constantValue = cnst; + constantValue = cnst; } double MgAdapt::getConstantValue() const { - return constantValue; + return constantValue; } void MgAdapt::setWorkingDir(std::string dir) { - workingDir = dir; + workingDir = dir; } std::string MgAdapt::getWorkingDir() const { - return workingDir; + return workingDir; } void MgAdapt::setKeepWorkingFiles(bool mybool) { - toKeepWorkingFiles = mybool; + toKeepWorkingFiles = mybool; } bool MgAdapt::getKeepWorkingFiles() { - return toKeepWorkingFiles; + return toKeepWorkingFiles; } void MgAdapt::setPrintLogInFile(bool print) { - printLogInFile = print; + printLogInFile = print; } bool MgAdapt::getPrintLogInFile() { - return printLogInFile; + 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); - if (data->myUseNoTimeStep) - setNoTimeStep(); - else if (data->myUseLastTimeStep) - setTimeStepRankLast(); - else - { - setChosenTimeStepRank(); - setRankTimeStep(data->myTimeStep, data->myRank); - } - /* 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; + 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); + if (data->myUseNoTimeStep) + setNoTimeStep(); + else if (data->myUseLastTimeStep) + setTimeStepRankLast(); + else + { + setChosenTimeStepRank(); + setRankTimeStep(data->myTimeStep, data->myRank); + } + /* 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(); + const char lastChar = *dirPath.rbegin(); #ifdef WIN32 - if(lastChar != '\\') dirPath+='\\'; + if(lastChar != '\\') dirPath+='\\'; #else - if(lastChar != '/') dirPath+='/'; + if(lastChar != '/') dirPath+='/'; #endif } //============================================================================= @@ -511,61 +502,68 @@ 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()) + 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) { - op_val = _customOption2value.find( optionName ); - _customOption2value[ optionName ] = optionValue; - return; + // empty string } - - if (op_val->second != optionValue) + 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(); - 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; + op_val->second = value; - } + } } //============================================================================= //! Return option value. If isDefault provided, it can be a default value, @@ -574,26 +572,25 @@ throw (std::invalid_argument) 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()) + TOptionValues::const_iterator op_val = _option2value.find(optionName); + if (op_val == _option2value.end()) + { + op_val = _customOption2value.find(optionName); + if (op_val == _customOption2value.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 msg = "Unknown MG-Adapt option: <" + optionName + ">"; + throw std::invalid_argument(msg); } - std::string val = op_val->second; - if ( isDefault ) *isDefault = ( val.empty() ); + } + 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; + if ( val.empty() && isDefault ) + { + op_val = _defaultOptionValues.find( optionName ); + if (op_val != _defaultOptionValues.end()) val = op_val->second; + } + return val; } //================================================================================ /*! @@ -604,20 +601,20 @@ throw (std::invalid_argument) double MgAdapt::toDbl(const std::string& str, bool* isOk ) throw (std::invalid_argument) { - if ( str.empty() ) throw std::invalid_argument("Empty value provided"); + if ( str.empty() ) throw std::invalid_argument("Empty value provided"); - char * endPtr; - double val = strtod(&str[0], &endPtr); - bool ok = (&str[0] != endPtr); + char * endPtr; + double val = strtod(&str[0], &endPtr); + bool ok = (&str[0] != endPtr); - if ( isOk ) *isOk = ok; + if ( isOk ) *isOk = ok; - if ( !ok ) - { - std::string msg = "Not a real value:'" + str + "'"; - throw std::invalid_argument(msg); - } - return val; + if ( !ok ) + { + std::string msg = "Not a real value:'" + str + "'"; + throw std::invalid_argument(msg); + } + return val; } //================================================================================ /*! @@ -626,10 +623,10 @@ throw (std::invalid_argument) //================================================================================ 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; + std::string s = str; + for ( size_t i = 0; i <= s.size(); ++i ) + s[i] = tolower( s[i] ); + return s; } //================================================================================ /*! @@ -640,25 +637,26 @@ std::string MgAdapt::toLowerStr(const std::string& str) bool MgAdapt::toBool(const std::string& str, bool* isOk ) throw (std::invalid_argument) { - std::string s = str; - if ( isOk ) *isOk = true; + std::string s = str; + if ( isOk ) *isOk = true; - for ( size_t i = 0; i <= s.size(); ++i ) - s[i] = tolower( s[i] ); + 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 ( s == "1" || s == "true" || s == "active" || s == "yes" ) + return true; - if ( isOk ) - *isOk = false; - else { - std::string msg = "Not a Boolean value:'" + str + "'"; - throw std::invalid_argument(msg); - } + 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; } //================================================================================ /*! @@ -669,34 +667,34 @@ throw (std::invalid_argument) int MgAdapt::toInt(const std::string& str, bool* isOk ) throw (std::invalid_argument) { - if ( str.empty() ) throw std::invalid_argument("Empty value provided"); + 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); + char * endPtr; + int val = (int)strtol( &str[0], &endPtr, 10); + bool ok = (&str[0] != endPtr); - if ( isOk ) *isOk = ok; + if ( isOk ) *isOk = ok; - if ( !ok ) - { - std::string msg = "Not an integer value:'" + str + "'"; - throw std::invalid_argument(msg); - } - return val; + 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; + bool isDefault = false; + try + { + getOptionValue( optionName, &isDefault ); + } + catch ( std::invalid_argument ) + { + return false; + } + return !isDefault; } //================================================================================ /*! @@ -706,57 +704,56 @@ bool MgAdapt::hasOptionDefined( const std::string& optionName ) const std::string MgAdapt::getCommandToRun(MgAdapt* hyp) { - return hyp ? hyp->getCommandToRun() : ToComment("error with hypothesis!"); + 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 + 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; + 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 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 pipe(popen(cmd, "r"), pclose ); - if(!pipe) - { - throw std::runtime_error("popen() failed!"); - } - while(fgets(buffer.data(), buffer.size(), pipe.get()) !=nullptr ) - { - logStream< 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 pipe(popen(cmd, "r"), pclose ); + if(!pipe) + { + throw std::runtime_error("popen() failed!"); + } + while(fgets(buffer.data(), buffer.size(), pipe.get()) !=nullptr ) + { + logStream<::iterator it = tmpFilesToBeDeleted.begin(); - for (; it!=tmpFilesToBeDeleted.end(); ++it) - { - errStr=removeFile(*it, notOk); - if (notOk) - { - appendMsgToLogFile(errStr); - } + int notOk; + std::string errStr; + if(toKeepWorkingFiles) + return; + if(removeOnSuccess && printLogInFile) + 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(); + std::ofstream logStream; + logStream.open(logFile, std::ofstream::out | std::ofstream::app); + logStream<< msg; + logStream.close(); } //================================================================================ /*! @@ -799,115 +796,109 @@ void MgAdapt::appendMsgToLogFile(std::string& msg) std::string MgAdapt::getCommandToRun() { - /* - || return system command with args and options - || - */ - std::string errStr; - std::string cmd = getExeName(); - std::string meshIn(""), sizeMapIn(""), solFileIn(""); - updateTimeStepRank(); - 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"; - tmpFilesToBeDeleted.push_back(meshFormatOutputMesh); - 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); - tmpFilesToBeDeleted.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 ) + /* + || return system command with args and options + || + */ + std::string errStr; + std::string cmd = getExeName(); + std::string meshIn(""), sizeMapIn(""), solFileIn(""); + updateTimeStepRank(); + 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"; + tmpFilesToBeDeleted.push_back(meshFormatOutputMesh); + 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); + tmpFilesToBeDeleted.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 ) { - 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; - } + 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; + return cmd; } - bool MgAdapt::isFileExist(const std::string& fName) { - if ( fName.empty() ) - return false; + if ( fName.empty() ) return false; - boost::system::error_code err; - bool res = boost::filesystem::exists( fName, err ); + boost::system::error_code err; + bool res = boost::filesystem::exists( fName, err ); - return err ? false : res; + return err ? false : res; } //======================================================================= //function : defaultMaximumMemory @@ -922,46 +913,48 @@ bool MgAdapt::isFileExist(const std::string& fName) 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 ); - } + // 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 ); - } + 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; + return 1024; } - //======================================================================= //function : defaultWorkingDirectory //======================================================================= std::string MgAdapt::defaultWorkingDirectory() { - TCollection_AsciiString aTmpDir; + TCollection_AsciiString aTmpDir; - char *Tmp_dir = getenv("SALOME_TMP_DIR"); - if(Tmp_dir != NULL) { - aTmpDir = Tmp_dir; - } - else { + char *Tmp_dir = getenv("SALOME_TMP_DIR"); + if(Tmp_dir != NULL) + { + aTmpDir = Tmp_dir; + } + else { #ifdef WIN32 - aTmpDir = TCollection_AsciiString("C:\\"); + aTmpDir = TCollection_AsciiString("C:\\"); #else - aTmpDir = TCollection_AsciiString("/tmp/"); + aTmpDir = TCollection_AsciiString("/tmp/"); #endif - } - return aTmpDir.ToCString(); + } + return aTmpDir.ToCString(); } //================================================================================ /*! @@ -971,21 +964,21 @@ std::string MgAdapt::defaultWorkingDirectory() std::string MgAdapt::getFileName() const { - std::string aTmpDir = workingDir; - const char lastChar = *aTmpDir.rbegin(); + std::string aTmpDir = workingDir; + const char lastChar = *aTmpDir.rbegin(); #ifdef WIN32 - if(lastChar != '\\') aTmpDir+='\\'; + if(lastChar != '\\') aTmpDir+='\\'; #else - if(lastChar != '/') aTmpDir+='/'; + if(lastChar != '/') aTmpDir+='/'; #endif - TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str(); - aGenericName += "MgAdapt_"; - aGenericName += getpid(); - aGenericName += "_"; - aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString()); + TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str(); + aGenericName += "MgAdapt_"; + aGenericName += getpid(); + aGenericName += "_"; + aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString()); - return aGenericName.ToCString(); + return aGenericName.ToCString(); } //======================================================================= //function : defaultLogFile @@ -993,104 +986,104 @@ std::string MgAdapt::getFileName() const std::string MgAdapt::defaultLogFile() { - std::string alogFile("MG_ADAPT.log"); - return alogFile; + std::string alogFile("MG_ADAPT.log"); + return alogFile; } //======================================================================= //function : defaultUseConstantValue //======================================================================= -bool MgAdapt::defaultUseConstantValue() +bool MgAdapt::defaultUseConstantValue() { - return false; + return false; } //======================================================================= //function : defaultUseNoTimeStep //======================================================================= -bool MgAdapt::defaultUseNoTimeStep() +bool MgAdapt::defaultUseNoTimeStep() { - return true; + return true; } //======================================================================= //function : defaultRemoveLogOnSuccess //======================================================================= -bool MgAdapt::defaultRemoveLogOnSuccess() +bool MgAdapt::defaultRemoveLogOnSuccess() { - return true; + return true; } //======================================================================= //function : defaultPrintLogInFile //======================================================================= -bool MgAdapt::defaultPrintLogInFile() +bool MgAdapt::defaultPrintLogInFile() { - return false; + return false; } //======================================================================= //function : defaultUseChosenTimeStep //======================================================================= -bool MgAdapt::defaultUseChosenTimeStep() +bool MgAdapt::defaultUseChosenTimeStep() { - return false; + return false; } //======================================================================= //function : UseLastTimeStep //======================================================================= -bool MgAdapt::defaultUseLastTimeStep() +bool MgAdapt::defaultUseLastTimeStep() { - return false; + return false; } //======================================================================= //function : defaultUseBackgroundMap //======================================================================= -bool MgAdapt::defaultUseBackgroundMap() +bool MgAdapt::defaultUseBackgroundMap() { - return false; + return false; } //======================================================================= //function : defaultKeepFiles //======================================================================= -bool MgAdapt::defaultKeepFiles() +bool MgAdapt::defaultKeepFiles() { - return false; + return false; } //======================================================================= //function : defaultUseLocalMap //======================================================================= -bool MgAdapt::defaultUseLocalMap() +bool MgAdapt::defaultUseLocalMap() { - return true; + return true; } //======================================================================= //function : defaultPublish //======================================================================= -bool MgAdapt::defaultPublish() +bool MgAdapt::defaultPublish() { - return false; + return false; } //======================================================================= //function : defaultMeshOutMed //======================================================================= -bool MgAdapt::defaultMeshOutMed() +bool MgAdapt::defaultMeshOutMed() { - return true; + return true; } //======================================================================= //function : defaultFromMedFile //======================================================================= -bool MgAdapt::defaultFromMedFile() +bool MgAdapt::defaultFromMedFile() { - return true; + return true; } //======================================================================= //function : defaultVerboseLevel @@ -1098,355 +1091,337 @@ bool MgAdapt::defaultFromMedFile() int MgAdapt::defaultVerboseLevel() { - return 3; + return 3; } std::string MgAdapt::getExeName() { - return "mg-adapt.exe"; + return "mg-adapt.exe"; } void MgAdapt::copyMgAdaptHypothesisData( const 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; - + 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 fieldFileNames; - MEDCoupling::MeshFormatWriter writer; - MEDCoupling::MCAuto mfd = MEDCoupling::MEDFileData::New(medFileIn); - MEDCoupling::MEDFileMeshes* meshes = mfd->getMeshes(); - MEDCoupling::MEDFileMesh* fileMesh = meshes->getMeshAtPos(0); // ok only one mesh in file! - if (meshNameOut =="") - meshNameOut = fileMesh->getName(); - storeGroupsAndFams(fileMesh); - - MEDCoupling::MCAuto 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 fts = dynamic_cast( mfd->getFields()->getFieldWithName(fieldName) ); - MEDCoupling::MCAuto f = fts->getTimeStep(timeStep, rank); - MEDCoupling::MCAuto tmFts = MEDCoupling::MEDFileFieldMultiTS::New(); - tmFts->pushBackTimeStep(f); - - fields->pushField(tmFts); - - writer.setFieldFileNames( fieldFileNames); - } - - else - { - MEDCoupling::MCAuto mesh = fileMesh->getMeshAtLevel(1); // nodes mesh - MEDCoupling::MCAuto 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(); + std::vector fieldFileNames; + MEDCoupling::MeshFormatWriter writer; + MEDCoupling::MCAuto mfd = MEDCoupling::MEDFileData::New(medFileIn); + MEDCoupling::MEDFileMeshes* meshes = mfd->getMeshes(); + MEDCoupling::MEDFileMesh* fileMesh = meshes->getMeshAtPos(0); // ok only one mesh in file! + if (meshNameOut =="") + meshNameOut = fileMesh->getName(); + storeGroupsAndFams(fileMesh); + + MEDCoupling::MCAuto 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 fts = dynamic_cast( mfd->getFields()->getFieldWithName(fieldName) ); + MEDCoupling::MCAuto f = fts->getTimeStep(timeStep, rank); + MEDCoupling::MCAuto tmFts = MEDCoupling::MEDFileFieldMultiTS::New(); + tmFts->pushBackTimeStep(f); + + fields->pushField(tmFts); + + writer.setFieldFileNames( fieldFileNames); + } + else + { + MEDCoupling::MCAuto mesh = fileMesh->getMeshAtLevel(1); // nodes mesh + MEDCoupling::MCAuto 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::MeshFormatReader reader(meshFormatIn, solFieldFileNames); - MEDCoupling::MCAuto 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); + MEDCoupling::MCAuto 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); + storefams(fileMesh); + storeGroups(fileMesh); } void MgAdapt::restoreGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh) const { - restorefams(fileMesh); - restoreGroups(fileMesh); + restorefams(fileMesh); + restoreGroups(fileMesh); } void MgAdapt::storeGroups(MEDCoupling::MEDFileMesh* fileMesh) { - std::map > grpFams = fileMesh->getGroupInfo(); - std::map >::iterator g2ff = grpFams.begin(); + std::map > grpFams = fileMesh->getGroupInfo(); + std::map >::iterator g2ff = grpFams.begin(); + + for ( ; g2ff != grpFams.end(); ++g2ff ) + { + std::string groupName = g2ff->first; + std::vector famNames = g2ff->second; - for ( ; g2ff != grpFams.end(); ++g2ff ) + if ( famNames.empty() ) continue; + std::size_t k = 0; + std::vector< mcIdType> famListId; + for ( size_t i = 0; i < famNames.size(); ++i ) { - std::string groupName = g2ff->first; - std::vector 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); + 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 grpFams = fileMesh->getFamilyInfo(); - std::map::iterator f = grpFams.begin(); + std::map grpFams = fileMesh->getFamilyInfo(); + std::map::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); - } + 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::const_iterator fIt = famVec.begin(); + std::vector::const_iterator fIt = famVec.begin(); - for (; fIt!=famVec.end(); ++fIt) + for (; fIt!=famVec.end(); ++fIt) + { + try // { - try // - { - 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<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< > info; - std::vector ::const_iterator grpFams = groupVec.begin(); + std::map > info; + std::vector ::const_iterator grpFams = groupVec.begin(); - for (; grpFams!=groupVec.end(); ++grpFams) - { - info.insert(std::pair > (grpFams->_name, grpFams->_famNames) ); - } + for (; grpFams!=groupVec.end(); ++grpFams) + { + info.insert(std::pair > (grpFams->_name, grpFams->_famNames) ); + } - fileMesh->setGroupInfo(info); + 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& fieldFileNames, const std::string& meshFormatsizeMapFile) const { - MEDCoupling::MCAuto tmpMfd = MEDCoupling::MEDFileData::New(sizeMapFile); - MEDCoupling::MEDFileFields* tmpFields = tmpMfd->getFields(); - MEDCoupling::MEDFileAnyTypeFieldMultiTS* fts = tmpFields->getFieldWithName(fieldName); - MEDCoupling::MCAuto fts1 = dynamic_cast(fts); - MEDCoupling::MCAuto f = fts1->getTimeStep(timeStep, rank); - MEDCoupling::MCAuto tmFts = MEDCoupling::MEDFileFieldMultiTS::New(); - tmFts->pushBackTimeStep(f); + MEDCoupling::MCAuto tmpMfd = MEDCoupling::MEDFileData::New(sizeMapFile); + MEDCoupling::MEDFileFields* tmpFields = tmpMfd->getFields(); + MEDCoupling::MEDFileAnyTypeFieldMultiTS* fts = tmpFields->getFieldWithName(fieldName); + MEDCoupling::MCAuto fts1 = dynamic_cast(fts); + MEDCoupling::MCAuto f = fts1->getTimeStep(timeStep, rank); + MEDCoupling::MCAuto tmFts = MEDCoupling::MEDFileFieldMultiTS::New(); + tmFts->pushBackTimeStep(f); - MEDCoupling::MCAuto tmp_fields = MEDCoupling::MEDFileFields::New(); - tmp_fields->pushField(tmFts); + MEDCoupling::MCAuto 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(); + 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; + 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*/) + const bool isFatal/*=false*/) { - if ( isFatal ) - _myErrorMessages.clear(); // warnings are useless if a fatal error encounters + if ( isFatal ) + _myErrorMessages.clear(); // warnings are useless if a fatal error encounters - _myErrorMessages.push_back( msg ); + _myErrorMessages.push_back( msg ); - //~MESSAGE(msg); +//~MESSAGE(msg); #ifdef _DEBUG_ - std::cout << msg << std::endl; + std::cout << msg << std::endl; #endif - return ( _myStatus = isFatal ? MgAdapt::DRS_FAIL : MgAdapt::DRS_WARN_SKIP_ELEM ); + 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()); + 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 ) + 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) { - - //~addMessage( ToComment(" error: error while reading field ") << nomcha << "step (numdt, numit) = " <<"("<< numdt<< ", " \ - numit<< ")" <<" in file " << aFile , /*fatal=*/true ); - return; + 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); - + // Fermeture du fichier + if ( medIdt > 0 ) MEDfileClose(medIdt); } void MgAdapt::updateTimeStepRank() { - med_int arank; - med_int tmst; - if (myUseNoTimeStep) - { - arank = MED_NO_IT; - tmst = MED_NO_DT ; - setRankTimeStep((int)tmst, (int)arank); - } - else if (myUseLastTimeStep) - { - std::string fieldFile = useBackgroundMap ? sizeMapFile : medFileIn; - getTimeStepInfos(fieldFile, tmst, arank); - setRankTimeStep((int)tmst, (int)arank); - } + med_int arank; + med_int tmst; + if (myUseNoTimeStep) + { + arank = MED_NO_IT; + tmst = MED_NO_DT ; + setRankTimeStep((int)tmst, (int)arank); + } + else if (myUseLastTimeStep) + { + std::string fieldFile = useBackgroundMap ? sizeMapFile : medFileIn; + getTimeStepInfos(fieldFile, tmst, arank); + setRankTimeStep((int)tmst, (int)arank); + } } diff --git a/src/SMESH/MG_ADAPT.hxx b/src/SMESH/MG_ADAPT.hxx index c97ad15d3..887d6dc25 100644 --- a/src/SMESH/MG_ADAPT.hxx +++ b/src/SMESH/MG_ADAPT.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2011-2020 CEA/DEN, EDF R&D +// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -14,9 +14,9 @@ // 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/ +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// File : MG_ADAPT.hxx +// File : MG_ADAPT.hxx // #ifndef MG_ADAPT_HXX #define MG_ADAPT_HXX @@ -40,22 +40,21 @@ namespace MG_ADAPT{ class MgAdapt; typedef std::map< std::string, std::string > TOptionValues; -typedef std::set< std::string > TOptionNames; +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; - + 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{ @@ -68,43 +67,43 @@ public: */ class ToComment : public std::string { - std::ostringstream _s ; + 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 - ToComment( const T &anything ) { - _s << anything ; - this->std::string::operator=( _s.str() ); - } - - template - 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; - } + 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 + ToComment( const T &anything ) { + _s << anything ; + this->std::string::operator=( _s.str() ); + } + + template + 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; + } }; @@ -113,227 +112,223 @@ class MgAdapt public: - MgAdapt(); - MgAdapt(MgAdaptHypothesisData*); - MgAdapt(const MgAdapt&); - ~MgAdapt(); - void buildModel(); - void setData( MgAdaptHypothesisData* data); - - void setMedFileIn(std::string fileName); - std::string getMedFileIn(); - - void setMedFileOut(std::string fileOut); - std::string getMedFileOut(); + MgAdapt(); + MgAdapt(MgAdaptHypothesisData*); + MgAdapt(const MgAdapt&); + ~MgAdapt(); + void buildModel(); + void setData( MgAdaptHypothesisData* data); - void setMeshName(std::string name); - std::string getMeshName(); + void setMedFileIn(std::string fileName); + std::string getMedFileIn(); - void setMeshNameOut(std::string name); - std::string getMeshNameOut(); + void setMedFileOut(std::string fileOut); + std::string getMedFileOut(); - void setMeshOutMed(bool mybool); - bool getMeshOutMed(); + void setMeshName(std::string name); + std::string getMeshName(); - void setPublish(bool mybool); - bool getPublish(); + void setMeshNameOut(std::string name); + std::string getMeshNameOut(); - void setFieldName(std::string myFieldName); - std::string getFieldName(); + void setMeshOutMed(bool mybool); + bool getMeshOutMed(); - void setTimeStep(int time); - int getTimeStep() const; + void setPublish(bool mybool); + bool getPublish(); - void setRankTimeStep(int time, int myRank); - int getRank(); - - void setTimeStepRankLast(); - void setNoTimeStep(); - void setChosenTimeStepRank(); - void updateTimeStepRank(); - - void setLogFile(std::string); - std::string getLogFile(); + void setFieldName(std::string myFieldName); + std::string getFieldName(); - void setVerbosityLevel(int verbosity); - int getVerbosityLevel(); + void setTimeStep(int time); + int getTimeStep() const; + + void setRankTimeStep(int time, int myRank); + int getRank(); - 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( const 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 getCustomOptionValuesStrVec() const; - std::vector 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(); - static bool isFileExist(const std::string& fName); - - - - - 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 { + void setTimeStepRankLast(); + void setNoTimeStep(); + void setChosenTimeStepRank(); + void updateTimeStepRank(); + + 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( const 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 getCustomOptionValuesStrVec() const; + std::vector 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(); + static bool isFileExist(const std::string& fName); + + 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 _famListId; + std::vector _famNames; + group(std::string name, std::vector famListId, std::vector famNames):_name(name) + { + std::vector::iterator it = famListId.begin(); + for (; it!=famListId.end(); ++it) + _famListId.push_back(*it); + + std::vector::iterator itt = famNames.begin(); + for (; itt!=famNames.end(); ++itt) + _famNames.push_back(*itt); + } + }; - std::string _name; - std::vector _famListId; - std::vector _famNames; - group(std::string name, std::vector famListId, std::vector famNames):_name(name) - { - std::vector::iterator it = famListId.begin(); - for (; it!=famListId.end(); ++it) - _famListId.push_back(*it); - - std::vector::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) {} - }; + 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; - bool myUseLastTimeStep, myUseNoTimeStep, myUseChosenTimeStep; - 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 _myErrorMessages; - Status _myStatus; - std::string meshFormatOutputMesh; - std::vector< std::string> solFormatOutput; - std::vector groupVec; - std::vector 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& 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) ; - void execCmd( const char* cmd, int& err); - void cleanUp(); - void appendMsgToLogFile(std::string& msg); + bool fromMedFile; + + std::string medFileIn; + std::string medFileOut; + std::string meshName; + std::string meshNameOut; + bool publish, meshOutMed; + bool useLocalMap, useBackgroundMap, useConstantValue; + bool myUseLastTimeStep, myUseNoTimeStep, myUseChosenTimeStep; + 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 _myErrorMessages; + Status _myStatus; + std::string meshFormatOutputMesh; + std::vector< std::string> solFormatOutput; + std::vector groupVec; + std::vector 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& 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) ; + void execCmd( const char* cmd, int& err); + void cleanUp(); + void appendMsgToLogFile(std::string& msg); }; } diff --git a/src/SMESHGUI/MG_ADAPTGUI.cxx b/src/SMESHGUI/MG_ADAPTGUI.cxx index 102e388a6..b2ab3b7d6 100644 --- a/src/SMESHGUI/MG_ADAPTGUI.cxx +++ b/src/SMESHGUI/MG_ADAPTGUI.cxx @@ -95,88 +95,87 @@ const int MARGIN = 9; // layout margin SMESHGUI_MgAdaptDlg::SMESHGUI_MgAdaptDlg( SalomeApp_Module* theModule, SMESH::MG_ADAPT_ptr myModel, QWidget* parent, bool isCreation ) : mySMESHGUI( theModule ), QDialog(parent) { - //~model = new MgAdapt(*myModel); - model = SMESH::MG_ADAPT::_duplicate(myModel); - myData = model->getData(); - buildDlg(); - if (!isCreation) readParamsFromHypo(); + //~model = new MgAdapt(*myModel); + model = SMESH::MG_ADAPT::_duplicate(myModel); + myData = model->getData(); + buildDlg(); + if (!isCreation) readParamsFromHypo(); } -void SMESHGUI_MgAdaptDlg::buildDlg() +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 ); - SMESH::str_array* str = model->getOptionValuesStrVec(); - SMESH::str_array* str2 = model->getCustomOptionValuesStrVec(); - std::vector s; - for (int i = 0; i< str->length(); i++) s.push_back( (*str)[i].in()); - for (int j = str->length(); j< str2->length(); j++) s.push_back((*str2)[ j - str->length() ].in() ); - //~str.insert( str.end(), str2.begin(), str2.end() ); - - myAdvOpt = new MgAdaptAdvWidget(myTabWidget, &s); - - 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)) ); + 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 ); + SMESH::str_array* str = model->getOptionValuesStrVec(); + SMESH::str_array* str2 = model->getCustomOptionValuesStrVec(); + std::vector s; + for (int i = 0; i< str->length(); i++) s.push_back( (*str)[i].in()); + for (int j = str->length(); j< str2->length(); j++) s.push_back((*str2)[ j - str->length() ].in() ); + //~str.insert( str.end(), str2.begin(), str2.end() ); + + myAdvOpt = new MgAdaptAdvWidget(myTabWidget, &s); + + 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)) ); } @@ -195,192 +194,190 @@ SMESHGUI_MgAdaptDlg::~SMESHGUI_MgAdaptDlg() //~} SMESH::MG_ADAPT_ptr SMESHGUI_MgAdaptDlg::getModel() const { - return model; + return model; } /*! - \brief Perform clean-up actions on the dialog box closing. +\brief Perform clean-up actions on the dialog box closing. */ bool SMESHGUI_MgAdaptDlg::clickOnApply() { - readParamsFromWidgets(); - return true; + readParamsFromWidgets(); + return true; } void SMESHGUI_MgAdaptDlg::clickOnOk() { - clickOnApply(); - reject(); + clickOnApply(); + reject(); } void SMESHGUI_MgAdaptDlg::reject() { - QDialog::reject(); + QDialog::reject(); } bool SMESHGUI_MgAdaptDlg::readParamsFromHypo( ) const { - bool ret = true; - myArgs->aMedfile->setChecked(myData->fromMedFile) ; - if (myData->fromMedFile) - { - - *(myArgs->myFileInDir) = QString(myData->myFileInDir) ; - myArgs->selectMedFileLineEdit->setText(QString(myData->myMeshFileIn)) ; - // myData->myInMeshName = // TODO - - } - else - { - myArgs->aBrowserObject->setText(QString(myData->myInMeshName)); - //~ myArgs->myFileInDir =""; // TODO - //~ myArgs->selectMedFileLineEdit->setText(); // TODO - } - myArgs->meshNameLineEdit->setText(QString(myData->myOutMeshName)); - myArgs->medFileCheckBox->setChecked(myData->myMeshOutMed); - - if(myData->myMeshOutMed) - { - *(myArgs->myFileOutDir) = QString(myData->myFileOutDir); - myArgs->selectOutMedFileLineEdit->setText(QString(myData->myMeshFileOut)); - - } - 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) ; - myArgs->selectMedFileBackgroundLineEdit->setText(QString(myData->myMeshFileBackground)); - } - else - { - *(myArgs->myFileSizeMapDir) = QString("") ; //TODO - myArgs->selectMedFileBackgroundLineEdit->setText(""); //TODO - } - - myArgs->fieldNameCmb->setCurrentText(QString(myData->myFieldName)); - 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(QString(myData->myWorkingDir)); - myAdvOpt->logInFileCheck->setChecked(myData->myPrintLogInFile); - - myAdvOpt->verboseLevelSpin->setValue(myData->myVerboseLevel); - myAdvOpt->removeLogOnSuccessCheck->setChecked(myData->myRemoveLogOnSuccess); - myAdvOpt->keepWorkingFilesCheck->setChecked(myData->myKeepFiles); - - return ret; + bool ret = true; + myArgs->aMedfile->setChecked(myData->fromMedFile) ; + if (myData->fromMedFile) + { + + *(myArgs->myFileInDir) = QString(myData->myFileInDir) ; + myArgs->selectMedFileLineEdit->setText(QString(myData->myMeshFileIn)) ; + // myData->myInMeshName = // TODO + + } + else + { + myArgs->aBrowserObject->setText(QString(myData->myInMeshName)); + //~ myArgs->myFileInDir =""; // TODO + //~ myArgs->selectMedFileLineEdit->setText(); // TODO + } + myArgs->meshNameLineEdit->setText(QString(myData->myOutMeshName)); + myArgs->medFileCheckBox->setChecked(myData->myMeshOutMed); + + if(myData->myMeshOutMed) + { + *(myArgs->myFileOutDir) = QString(myData->myFileOutDir); + myArgs->selectOutMedFileLineEdit->setText(QString(myData->myMeshFileOut)); + } + 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) ; + myArgs->selectMedFileBackgroundLineEdit->setText(QString(myData->myMeshFileBackground)); + } + else + { + *(myArgs->myFileSizeMapDir) = QString("") ; //TODO + myArgs->selectMedFileBackgroundLineEdit->setText(""); //TODO + } + + myArgs->fieldNameCmb->setCurrentText(QString(myData->myFieldName)); + 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(QString(myData->myWorkingDir)); + 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; - SMESH::MgAdaptHypothesisData* aData = new SMESH::MgAdaptHypothesisData(); - aData->fromMedFile = myArgs->aMedfile->isChecked(); - if (aData->fromMedFile) - { - - aData->myFileInDir = CORBA::string_dup(myArgs->myFileInDir->toStdString().c_str()); - aData->myMeshFileIn = CORBA::string_dup(myArgs->selectMedFileLineEdit->text().toStdString().c_str()); - // aData->myInMeshName = // TODO - } - else // TODO browser - { - aData->myInMeshName = CORBA::string_dup(myArgs->aBrowserObject->text().toStdString().c_str()); - aData->myFileInDir = CORBA::string_dup(myAdvOpt->workingDirectoryLineEdit->text().toStdString().c_str()); - - TCollection_AsciiString aGenericName = (char*)aData->myFileInDir; - 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 = CORBA::string_dup(myArgs->meshNameLineEdit->text().toStdString().c_str()); - aData->myMeshOutMed = myArgs->medFileCheckBox->isChecked(); - if(aData->myMeshOutMed) - { - aData->myFileOutDir = CORBA::string_dup(myArgs->myFileOutDir->toStdString().c_str()); - aData->myMeshFileOut = CORBA::string_dup(myArgs->selectOutMedFileLineEdit->text().toStdString().c_str()); - - } - 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 = CORBA::string_dup(myArgs->myFileSizeMapDir->toStdString().c_str()); - aData->myMeshFileBackground = CORBA::string_dup(myArgs->selectMedFileBackgroundLineEdit->text().toStdString().c_str()); - } - else - { - aData->myMeshFileBackground = ""; - } - - aData->myFieldName = CORBA::string_dup(myArgs->fieldNameCmb->currentText().toStdString().c_str()); - 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 = CORBA::string_dup(myAdvOpt->workingDirectoryLineEdit->text().toStdString().c_str()); - 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 ret = true; + SMESH::MgAdaptHypothesisData* aData = new SMESH::MgAdaptHypothesisData(); + aData->fromMedFile = myArgs->aMedfile->isChecked(); + if (aData->fromMedFile) + { + + aData->myFileInDir = CORBA::string_dup(myArgs->myFileInDir->toStdString().c_str()); + aData->myMeshFileIn = CORBA::string_dup(myArgs->selectMedFileLineEdit->text().toStdString().c_str()); + // aData->myInMeshName = // TODO + } + else // TODO browser + { + aData->myInMeshName = CORBA::string_dup(myArgs->aBrowserObject->text().toStdString().c_str()); + aData->myFileInDir = CORBA::string_dup(myAdvOpt->workingDirectoryLineEdit->text().toStdString().c_str()); + + TCollection_AsciiString aGenericName = (char*)aData->myFileInDir; + 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 = CORBA::string_dup(myArgs->meshNameLineEdit->text().toStdString().c_str()); + aData->myMeshOutMed = myArgs->medFileCheckBox->isChecked(); + if(aData->myMeshOutMed) + { + aData->myFileOutDir = CORBA::string_dup(myArgs->myFileOutDir->toStdString().c_str()); + aData->myMeshFileOut = CORBA::string_dup(myArgs->selectOutMedFileLineEdit->text().toStdString().c_str()); + + } + 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 = CORBA::string_dup(myArgs->myFileSizeMapDir->toStdString().c_str()); + aData->myMeshFileBackground = CORBA::string_dup(myArgs->selectMedFileBackgroundLineEdit->text().toStdString().c_str()); + } + else + { + aData->myMeshFileBackground = ""; + } + + aData->myFieldName = CORBA::string_dup(myArgs->fieldNameCmb->currentText().toStdString().c_str()); + 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 = CORBA::string_dup(myAdvOpt->workingDirectoryLineEdit->text().toStdString().c_str()); + 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 SMESH::MgAdaptHypothesisData& ) const { @@ -391,59 +388,60 @@ bool SMESHGUI_MgAdaptDlg::storeParamsToHypo( const SMESH::MgAdaptHypothesisData& */ 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 ); + // 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; - } + 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(); + 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 ); + 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 ( name.simplified().isEmpty() ) + continue; // invalid custom option - if ( isDefault ) // not selected option - value.clear(); + 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; - } + 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; + return ok; } //================================================================================= @@ -454,155 +452,153 @@ 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); - visibleTimeStepRankLabel (false); - - // 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(); + 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); + visibleTimeStepRankLabel (false); + + // 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(); } //================================================================================= @@ -615,184 +611,177 @@ SMESHGUI_MgAdaptArguments::~SMESHGUI_MgAdaptArguments() void SMESHGUI_MgAdaptArguments::onNoTimeStep(bool disableOther) { - noTimeStep->setChecked(true); + noTimeStep->setChecked(true); - visibleTimeStepRankLabel (false); - rankSpinBox->setValue(-2); - timeStep->setValue(-2); + visibleTimeStepRankLabel (false); + rankSpinBox->setValue(-2); + timeStep->setValue(-2); - lastTimeStep->setDisabled(disableOther); - chosenTimeStep->setDisabled(disableOther); + lastTimeStep->setDisabled(disableOther); + chosenTimeStep->setDisabled(disableOther); } void SMESHGUI_MgAdaptArguments::onLastTimeStep(bool disableOther) { - lastTimeStep->setChecked(true); + lastTimeStep->setChecked(true); - visibleTimeStepRankLabel (false); - rankSpinBox->setValue(-1); - timeStep->setValue(-1); - noTimeStep->setDisabled(disableOther); + visibleTimeStepRankLabel (false); + rankSpinBox->setValue(-1); + timeStep->setValue(-1); + noTimeStep->setDisabled(disableOther); } void SMESHGUI_MgAdaptArguments::onChosenTimeStep(bool disableOther, int vmax) { - chosenTimeStep->setChecked(true); + chosenTimeStep->setChecked(true); - visibleTimeStepRankLabel (true); - rankSpinBox->setValue(0); - timeStep->setValue(0); - if (vmax) timeStep->setMaximum(vmax); + visibleTimeStepRankLabel (true); + rankSpinBox->setValue(0); + timeStep->setValue(0); + if (vmax) timeStep->setMaximum(vmax); } void SMESHGUI_MgAdaptArguments::visibleTimeStepRankLabel(bool visible) { - rankLabel->setVisible(visible); - rankSpinBox->setVisible(visible); + rankLabel->setVisible(visible); + rankSpinBox->setVisible(visible); - timeStepLabel->setVisible(visible); - timeStep->setVisible(visible); + timeStepLabel->setVisible(visible); + timeStep->setVisible(visible); } 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(); + 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 fileName0 = selectMedFileBackgroundbutton->text().trimmed(); - QString fileName = getMedFileName(false); - if (fileName != QString::null) + QString fileName = getMedFileName(false); + if (fileName != QString::null) + { + myFieldList = GetListeChamps(fileName); + if (myFieldList.empty()) { - myFieldList = GetListeChamps(fileName); - if (myFieldList.empty()) - { - fileName = fileName0; - fieldNameCmb->clear(); - } - else - { - // fill field name Combobox - fieldNameCmb->clear(); - std::map::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, false); - } - - } - + fileName = fileName0; + fieldNameCmb->clear(); } else { - fileName = fileName0; - fieldNameCmb->clear(); + // fill field name Combobox + fieldNameCmb->clear(); + std::map::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, false); + } } + } + else + { + fileName = fileName0; + fieldNameCmb->clear(); + } - QFileInfo myFileInfo(fileName); - *myFileSizeMapDir = myFileInfo.path(); - selectMedFileBackgroundLineEdit->setText(myFileInfo.fileName()); + 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); - } + 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); - } + 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) + // 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 ) { - 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); - } - + QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"), + QObject::tr("MG_ADAPT_MED_FILE_2") ); + fileName = fileName0; } else { - return; + meshNameLineEdit->setText(aMeshName); + ADAPTATION_MODE aMode = meshDim == 3 ? ADAPTATION_MODE::BOTH : ADAPTATION_MODE::SURFACE; // and when dimesh 3 without 2D mesh? + emit meshDimSignal(aMode); } - - - 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()); + } + 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()) + myFieldList = GetListeChamps(filePath, false); + if (myFieldList.empty()) + { + if (localButton->isChecked()) { - if (localButton->isChecked()) - { - fieldNameCmb->clear(); - } - + fieldNameCmb->clear(); } - else + } + else + { + // fill field name Combobox + fieldNameCmb->clear(); + std::map::const_iterator it; + for ( it = myFieldList.begin() ; it != myFieldList.end(); it++) { - // fill field name Combobox - fieldNameCmb->clear(); - std::map::const_iterator it; - for ( it = myFieldList.begin() ; it != myFieldList.end(); it++) - { - fieldNameCmb->insertItem(0,QString(it->first)); - // Je ne comprends pas le rapport entre pas de temps et apparition d'un nouveau champ... GN - int typeStepInField = it->second > 2 ? 2 : it->second ; + fieldNameCmb->insertItem(0,QString(it->first)); + // Je ne comprends pas le rapport entre pas de temps et apparition d'un nouveau champ... GN + int typeStepInField = it->second > 2 ? 2 : it->second ; // std::cout << "SMESHGUI_MgAdaptArguments::onLocalSelected typeStepInField : " << typeStepInField << std::endl; - timeStepGroupChanged(typeStepInField, false); - } - + timeStepGroupChanged(typeStepInField, false); } + } } // ======================================================================= // Gestion les boutons qui permettent de @@ -804,132 +793,128 @@ void SMESHGUI_MgAdaptArguments::onLocalSelected(QString filePath) 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 ); + 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; + return aFile; } void SMESHGUI_MgAdaptArguments::setMode(const Mode theMode, const SIZEMAP theSizeMap ) { - QRadioButton* aButton = qobject_cast( meshInGroup->button( theMode ) ); - QRadioButton* bButton = qobject_cast( sizeMapDefGroup->button( theSizeMap ) ); - if ( aButton ) { - aButton->setChecked( true ); - modeChanged( theMode ); - } - if ( bButton ) { - bButton->setChecked( true ); - sizeMapDefChanged( theSizeMap ); - } + QRadioButton* aButton = qobject_cast( meshInGroup->button( theMode ) ); + QRadioButton* bButton = qobject_cast( 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(); - } - - - + 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 + 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()) { - medFileBackground->hide(); - constantButton->setChecked(true); - selectMedFileBackgroundbutton->hide(); - selectMedFileBackgroundLineEdit->clear(); - selectMedFileBackgroundLineEdit->hide(); - valueLabel->show(); - dvalue->show(); - sizeMapField->setEnabled(false); - + 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 vmax) { - switch (timeStepType) - { - case 0 : - onNoTimeStep(disableOther); - break; - case 1 : - onLastTimeStep(disableOther); - break; - case 2 : - onChosenTimeStep(disableOther, vmax); - default: - break; - } + switch (timeStepType) + { + case 0 : + onNoTimeStep(disableOther); + break; + case 1 : + onLastTimeStep(disableOther); + break; + case 2 : + onChosenTimeStep(disableOther, vmax); + default: + break; + } } void SMESHGUI_MgAdaptArguments::clear() { - selectMedFileLineEdit->clear(); - aBrowserObject->clear(); + selectMedFileLineEdit->clear(); + aBrowserObject->clear(); - meshNameLineEdit->clear(); - selectOutMedFileLineEdit->clear(); + meshNameLineEdit->clear(); + selectOutMedFileLineEdit->clear(); } med_int SMESHGUI_MgAdaptArguments::getMeshDim() const { - return meshDim; + 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; + bool editable = index.data( EDITABLE_ROLE ).toInt(); + return editable ? QItemDelegate::createEditor( parent, o, index ) : 0; } ////////////////////////////////////////// @@ -937,20 +922,20 @@ QWidget* ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem ////////////////////////////////////////// MgAdaptAdvWidget::MgAdaptAdvWidget( QWidget* parent, std::vector * options, Qt::WindowFlags f ) - : QWidget( parent, f ), myOptions(options) + : 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())); + 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() @@ -959,251 +944,241 @@ 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::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 ) + 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::iterator it = optionTreeWidgetItem.find(name); + if(it != optionTreeWidgetItem.end()) return; // option exist + else { - myOptionTable->scrollToItem( row ); - myOptionTable->setCurrentItem( row ); - myOptionTable->editItem( row, NAME_COL ); + 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 (name, row)); + QTreeWidgetItem* row = new QTreeWidgetItem( table ); + row->setData( NAME_COL, EDITABLE_ROLE, int( isCustom && !option )); + row->setFlags( row->flags() | Qt::ItemIsEditable ); + optionTreeWidgetItem.insert(std::pair (name, row)); - return row; + return row; } void MgAdaptAdvWidget::onAddOption() { - AddOption( NULL, true ); + 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 ); + 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 ))); + if ( tblRow ) + { + myOptionTable->blockSignals( true ); - int c = tblRow->checkState( NAME_COL ) ? 0 : 150; - tblRow->setForeground( VALUE_COL, QBrush( QColor( c, c, c ))); + tblRow->setData( VALUE_COL, EDITABLE_ROLE, int( tblRow->checkState( NAME_COL ))); - if ( column == NAME_COL && tblRow->data( NAME_COL, EDITABLE_ROLE ).toInt() ) // custom table - { - tblRow->setData( NAME_COL, PARAM_NAME, tblRow->text( NAME_COL )); - } + int c = tblRow->checkState( NAME_COL ) ? 0 : 150; + tblRow->setForeground( VALUE_COL, QBrush( QColor( c, c, c ))); - myOptionTable->blockSignals( false ); + 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); + 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); - addBtn = new QPushButton(this); - addBtn->setObjectName(QString("addBtn")); + gridLayout_4->addWidget(myOptionTable, 0, 0, 1, 2); - gridLayout_4->addWidget(addBtn, 1, 0, 1, 1); + addBtn = new QPushButton(this); + addBtn->setObjectName(QString("addBtn")); - horizontalSpacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); + gridLayout_4->addWidget(addBtn, 1, 0, 1, 1); - gridLayout_4->addItem(horizontalSpacer, 1, 1, 1, 1); + horizontalSpacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - 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_4->addItem(horizontalSpacer, 1, 1, 1, 1); - gridLayout->addWidget(workingDirectoryLabel, 0, 0, 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")); - workingDirectoryLineEdit = new QLineEdit(logGroupBox); - workingDirectoryLineEdit->setObjectName(QString("workingDirectoryLineEdit")); + gridLayout->addWidget(workingDirectoryLabel, 0, 0, 1, 1); - gridLayout->addWidget(workingDirectoryLineEdit, 0, 1, 1, 1); + workingDirectoryLineEdit = new QLineEdit(logGroupBox); + workingDirectoryLineEdit->setObjectName(QString("workingDirectoryLineEdit")); - workingDirectoryPushButton = new QPushButton(logGroupBox); - workingDirectoryPushButton->setObjectName(QString("workingDirectoryPushButton")); + gridLayout->addWidget(workingDirectoryLineEdit, 0, 1, 1, 1); - gridLayout->addWidget(workingDirectoryPushButton, 0, 2, 1, 1); + workingDirectoryPushButton = new QPushButton(logGroupBox); + workingDirectoryPushButton->setObjectName(QString("workingDirectoryPushButton")); - verboseLevelLabel = new QLabel(logGroupBox); - verboseLevelLabel->setObjectName(QString("verboseLevelLabel")); + gridLayout->addWidget(workingDirectoryPushButton, 0, 2, 1, 1); - gridLayout->addWidget(verboseLevelLabel, 1, 0, 1, 1); + verboseLevelLabel = new QLabel(logGroupBox); + verboseLevelLabel->setObjectName(QString("verboseLevelLabel")); - verboseLevelSpin = new QSpinBox(logGroupBox); - verboseLevelSpin->setObjectName(QString("verboseLevelSpin")); + gridLayout->addWidget(verboseLevelLabel, 1, 0, 1, 1); - gridLayout->addWidget(verboseLevelSpin, 1, 1, 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); + gridLayout_2->addLayout(gridLayout, 0, 0, 1, 1); - horizontalLayout->addWidget(logInFileCheck); + horizontalLayout = new QHBoxLayout(); + horizontalLayout->setObjectName(QString("horizontalLayout")); + logInFileCheck = new QCheckBox(logGroupBox); + logInFileCheck->setObjectName(QString("logInFileCheck")); + logInFileCheck->setChecked(true); - removeLogOnSuccessCheck = new QCheckBox(logGroupBox); - removeLogOnSuccessCheck->setObjectName(QString("removeLogOnSuccessCheck")); - removeLogOnSuccessCheck->setChecked(true); + horizontalLayout->addWidget(logInFileCheck); - horizontalLayout->addWidget(removeLogOnSuccessCheck); + 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->addLayout(horizontalLayout, 1, 0, 1, 1); - gridLayout_2->addWidget(keepWorkingFilesCheck, 2, 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); + gridLayout_4->addWidget(logGroupBox, 3, 0, 1, 2); } void MgAdaptAdvWidget::_onWorkingDirectoryPushButton() { - QString aDirName=QFileDialog::getExistingDirectory (); - if (!(aDirName.isEmpty()))workingDirectoryLineEdit->setText(aDirName); + 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; - } - } +/* 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::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 ); - } + std::map::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 ); + return index.isValid() && + index.flags() & Qt::ItemIsEditable && + index.flags() & Qt::ItemIsEnabled && + ( !index.data( Qt::UserRole + 1 ).isValid() || index.data( Qt::UserRole + 1 ).toInt() != 0 ); } } @@ -1214,56 +1189,56 @@ MgAdaptAdvWidgetTreeWidget::MgAdaptAdvWidgetTreeWidget( QWidget* 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; - } + 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 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; - } + 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; } - return QTreeWidget::moveCursor( action, modifiers ); + 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() ) { + 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(); - } - } + 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 ); + break; + } + QTreeWidget::keyPressEvent( e ); } @@ -1272,175 +1247,173 @@ void MgAdaptAdvWidgetTreeWidget::keyPressEvent( QKeyEvent* e ) // ======================================================================= 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; + 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; - } + 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); + nomMaillage = lireNomMaillage2(medIdt,1, meshdim); + // Fermeture du fichier + if ( medIdt > 0 ) MEDfileClose(medIdt); - return nomMaillage; + 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; + 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 GetListeChamps(QString aFile, bool errorMessage) // ======================================================================= { // Il faut voir si plusieurs maillages - MESSAGE("GetListeChamps"); - std::map ListeChamp ; + MESSAGE("GetListeChamps"); + std::map ListeChamp ; - med_err erreur = 0 ; - med_idt medIdt ; + med_err erreur = 0 ; + med_idt medIdt ; - while ( erreur == 0 ) + 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++) { - // 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); + 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(nomcha), nbofcstp)); - + 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(nomcha), nbofcstp)); + } + break ; + } // Fermeture du fichier - if ( medIdt > 0 ) MEDfileClose(medIdt); + if ( medIdt > 0 ) MEDfileClose(medIdt); - return ListeChamp; + 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); +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); } - diff --git a/src/SMESHGUI/MG_ADAPTGUI.hxx b/src/SMESHGUI/MG_ADAPTGUI.hxx index cd2bf2bbf..853b2683e 100644 --- a/src/SMESHGUI/MG_ADAPTGUI.hxx +++ b/src/SMESHGUI/MG_ADAPTGUI.hxx @@ -1,4 +1,7 @@ -// Copyright (C) 2011-2020 CEA/DEN, EDF R&D +// 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 @@ -16,9 +19,8 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // - // SMESH SMESHGUI : GUI for the adaptation in the SMESH component -// File : MG_ADAPTGUI.hxx +// File : MG_ADAPTGUI.hxx // #ifndef MG_ADAPTGUI_HXX #define MG_ADAPTGUI_HXX @@ -103,9 +105,9 @@ std::string remove_extension(const std::string& filename); enum ADAPTATION_MODE{ - SURFACE, // surface adaption when meshDim == 2 - VOLUME, // - BOTH + SURFACE, // surface adaption when meshDim == 2 + VOLUME, // + BOTH }; //================================================================================= // class : SMESHGUI_MgAdaptDlg @@ -113,148 +115,146 @@ enum ADAPTATION_MODE{ //================================================================================= class SMESHGUI_MgAdaptDlg : public QDialog { - Q_OBJECT; + Q_OBJECT; public: - //! Property type - enum Mode { Arguments, AdvancedOptions}; - SMESHGUI_MgAdaptDlg( SalomeApp_Module*, SMESH::MG_ADAPT_ptr, QWidget* parent= 0,bool isCreation = true ); - ~SMESHGUI_MgAdaptDlg(); + //! Property type + enum Mode { Arguments, AdvancedOptions}; + SMESHGUI_MgAdaptDlg( SalomeApp_Module*, SMESH::MG_ADAPT_ptr, QWidget* parent= 0,bool isCreation = true ); + ~SMESHGUI_MgAdaptDlg(); - void buildDlg(); - void reject(); - bool checkParams(QString& msg) ; - //~void setModel(MgAdapt*); - SMESH::MG_ADAPT_ptr getModel() const; + void buildDlg(); + void reject(); + bool checkParams(QString& msg) ; + //~void setModel(MgAdapt*); + SMESH::MG_ADAPT_ptr getModel() const; public slots: protected slots: - virtual bool clickOnApply(); +virtual bool clickOnApply(); private slots: - virtual void clickOnHelp(); - virtual void clickOnOk(); +virtual void clickOnHelp(); +virtual void clickOnOk(); protected : - SMESHGUI_MgAdaptArguments* myArgs; - MgAdaptAdvWidget* myAdvOpt; - bool readParamsFromHypo( ) const ; - bool readParamsFromWidgets( ) ; - bool storeParamsToHypo( const SMESH::MgAdaptHypothesisData & ) const; + SMESHGUI_MgAdaptArguments* myArgs; + MgAdaptAdvWidget* myAdvOpt; + bool readParamsFromHypo( ) const ; + bool readParamsFromWidgets( ) ; + bool storeParamsToHypo( const SMESH::MgAdaptHypothesisData & ) const; private: - - SalomeApp_Module* mySMESHGUI; /* Current SMESHGUI object */ - QTabWidget* myTabWidget; + SalomeApp_Module* mySMESHGUI; /* Current SMESHGUI object */ + QTabWidget* myTabWidget; - SMESH::MgAdaptHypothesisData* myData; - SMESH::MG_ADAPT_ptr model; + SMESH::MgAdaptHypothesisData* myData; + SMESH::MG_ADAPT_ptr model; }; class SMESHGUI_MgAdaptArguments : public QWidget { - Q_OBJECT; + Q_OBJECT; public: - //! Property type - enum Mode { Mesh, Browser}; - enum SIZEMAP { Local, Background, Constant}; - SMESHGUI_MgAdaptArguments( QWidget* parent); - ~SMESHGUI_MgAdaptArguments(); - void setMode( const Mode, const SIZEMAP ); - med_int getMeshDim() const; - - QString* myFileInDir; - QString* myFileOutDir; - QString* myFileSizeMapDir; - QGroupBox* aMeshIn ; - QRadioButton* aMedfile; - QRadioButton* aBrowser ; - QLineEdit* aBrowserObject; - QPushButton* selectMedFilebutton ; - QSpacerItem* hspacer; - QLineEdit* selectMedFileLineEdit ; - QButtonGroup* meshInGroup ; - QGridLayout* meshIn ; - - QGroupBox* aMeshOut ; - QLabel* meshName; - QLineEdit* meshNameLineEdit; - QSpacerItem* secondHspacer; - QCheckBox* medFileCheckBox; - QPushButton* selectOutMedFilebutton; - QLineEdit* selectOutMedFileLineEdit; - QSpacerItem* thirdHspacer; - QCheckBox* publishOut; - QGridLayout* meshOut ; - - QGroupBox* sizeMapDefinition ; - QRadioButton* localButton; - QRadioButton* backgroundButton ; - QRadioButton* constantButton ; - QLabel* medFileBackground; - QPushButton* selectMedFileBackgroundbutton; - QLineEdit* selectMedFileBackgroundLineEdit; - QLabel* valueLabel; - QDoubleSpinBox* dvalue; - QButtonGroup* sizeMapDefGroup ; - QGridLayout* sizeMapDefGroupLayout; - - - QGroupBox* sizeMapField; - QLabel* fieldName; - QComboBox* fieldNameCmb; - QRadioButton* noTimeStep; - QRadioButton* lastTimeStep ; - QRadioButton* chosenTimeStep; - QLabel* timeStepLabel; - QSpinBox* timeStep; - QLabel* rankLabel; - QSpinBox* rankSpinBox; - QButtonGroup* timeStepGroup; - QGridLayout* sizeMapFieldGroupLayout; + //! Property type + enum Mode { Mesh, Browser}; + enum SIZEMAP { Local, Background, Constant}; + SMESHGUI_MgAdaptArguments( QWidget* parent); + ~SMESHGUI_MgAdaptArguments(); + void setMode( const Mode, const SIZEMAP ); + med_int getMeshDim() const; + + QString* myFileInDir; + QString* myFileOutDir; + QString* myFileSizeMapDir; + QGroupBox* aMeshIn ; + QRadioButton* aMedfile; + QRadioButton* aBrowser ; + QLineEdit* aBrowserObject; + QPushButton* selectMedFilebutton ; + QSpacerItem* hspacer; + QLineEdit* selectMedFileLineEdit ; + QButtonGroup* meshInGroup ; + QGridLayout* meshIn ; + + QGroupBox* aMeshOut ; + QLabel* meshName; + QLineEdit* meshNameLineEdit; + QSpacerItem* secondHspacer; + QCheckBox* medFileCheckBox; + QPushButton* selectOutMedFilebutton; + QLineEdit* selectOutMedFileLineEdit; + QSpacerItem* thirdHspacer; + QCheckBox* publishOut; + QGridLayout* meshOut ; + + QGroupBox* sizeMapDefinition ; + QRadioButton* localButton; + QRadioButton* backgroundButton ; + QRadioButton* constantButton ; + QLabel* medFileBackground; + QPushButton* selectMedFileBackgroundbutton; + QLineEdit* selectMedFileBackgroundLineEdit; + QLabel* valueLabel; + QDoubleSpinBox* dvalue; + QButtonGroup* sizeMapDefGroup ; + QGridLayout* sizeMapDefGroupLayout; + + + QGroupBox* sizeMapField; + QLabel* fieldName; + QComboBox* fieldNameCmb; + QRadioButton* noTimeStep; + QRadioButton* lastTimeStep ; + QRadioButton* chosenTimeStep; + QLabel* timeStepLabel; + QSpinBox* timeStep; + QLabel* rankLabel; + QSpinBox* rankSpinBox; + QButtonGroup* timeStepGroup; + QGridLayout* sizeMapFieldGroupLayout; signals: - void updateSelection(); - void toExportMED(const char *); - void meshDimSignal(ADAPTATION_MODE aMode); + void updateSelection(); + void toExportMED(const char *); + void meshDimSignal(ADAPTATION_MODE aMode); public slots: protected slots: private slots: - void modeChanged( int); - void sizeMapDefChanged(int); - void timeStepGroupChanged(int timeStepType, bool disableOther = false, int vmax = 0); - void onSelectMedFilebuttonClicked(); - void clear(); - void onMedFileCheckBox(int); - void onPublishOut(int); - void onSelectOutMedFilebutton(); - void onSelectMedFileBackgroundbutton(); - void onLocalSelected(QString); - void onNoTimeStep(bool disableOther = false); - void onLastTimeStep(bool disableOther = false); - void onChosenTimeStep(bool disableOther = false, int vmax = 0); - void visibleTimeStepRankLabel(bool visible); + void modeChanged( int); + void sizeMapDefChanged(int); + void timeStepGroupChanged(int timeStepType, bool disableOther = false, int vmax = 0); + void onSelectMedFilebuttonClicked(); + void clear(); + void onMedFileCheckBox(int); + void onPublishOut(int); + void onSelectOutMedFilebutton(); + void onSelectMedFileBackgroundbutton(); + void onLocalSelected(QString); + void onNoTimeStep(bool disableOther = false); + void onLastTimeStep(bool disableOther = false); + void onChosenTimeStep(bool disableOther = false, int vmax = 0); + void visibleTimeStepRankLabel(bool visible); private: - QString getMedFileName(bool avertir); - LightApp_SelectionMgr* selMgr ; - med_int meshDim; - std::map myFieldList; - + QString getMedFileName(bool avertir); + LightApp_SelectionMgr* selMgr ; + med_int meshDim; + std::map myFieldList; }; enum { - OPTION_ID_COLUMN = 0, - OPTION_TYPE_COLUMN, - OPTION_NAME_COLUMN = 0, - OPTION_VALUE_COLUMN, - NB_COLUMNS, + OPTION_ID_COLUMN = 0, + OPTION_TYPE_COLUMN, + OPTION_NAME_COLUMN = 0, + OPTION_VALUE_COLUMN, + NB_COLUMNS, }; ////////////////////////////////////////// @@ -262,44 +262,44 @@ enum { ////////////////////////////////////////// class MgAdaptAdvWidget : public QWidget { - Q_OBJECT + Q_OBJECT public: - MgAdaptAdvWidget( QWidget* = 0, std::vector * = nullptr, Qt::WindowFlags = 0 ); - ~MgAdaptAdvWidget(); - std::vector < std::string > * myOptions; - QGridLayout *gridLayout_4; - MgAdaptAdvWidgetTreeWidget *myOptionTable; - QPushButton *addBtn; - QSpacerItem *horizontalSpacer; - QGroupBox *logGroupBox; - QGridLayout *gridLayout_2; - QGridLayout *gridLayout; - QLabel *workingDirectoryLabel; - QLineEdit *workingDirectoryLineEdit; - QPushButton *workingDirectoryPushButton; - QLabel *verboseLevelLabel; - QSpinBox *verboseLevelSpin; - QHBoxLayout *horizontalLayout; - QCheckBox *logInFileCheck; - QCheckBox *removeLogOnSuccessCheck; - QCheckBox *keepWorkingFilesCheck; - - void AddOption( const char* name_value_type, bool isCustom = false ); - void GetOptionAndValue( QTreeWidgetItem * tblRow, QString& option, QString& value, bool& dflt ); - void setupWidget(); -public slots: + MgAdaptAdvWidget( QWidget* = 0, std::vector * = nullptr, Qt::WindowFlags = 0 ); + ~MgAdaptAdvWidget(); + std::vector < std::string > * myOptions; + QGridLayout *gridLayout_4; + MgAdaptAdvWidgetTreeWidget *myOptionTable; + QPushButton *addBtn; + QSpacerItem *horizontalSpacer; + QGroupBox *logGroupBox; + QGridLayout *gridLayout_2; + QGridLayout *gridLayout; + QLabel *workingDirectoryLabel; + QLineEdit *workingDirectoryLineEdit; + QPushButton *workingDirectoryPushButton; + QLabel *verboseLevelLabel; + QSpinBox *verboseLevelSpin; + QHBoxLayout *horizontalLayout; + QCheckBox *logInFileCheck; + QCheckBox *removeLogOnSuccessCheck; + QCheckBox *keepWorkingFilesCheck; + + void AddOption( const char* name_value_type, bool isCustom = false ); + void GetOptionAndValue( QTreeWidgetItem * tblRow, QString& option, QString& value, bool& dflt ); + void setupWidget(); - void onAddOption(); - void itemChanged(QTreeWidgetItem * tblRow, int column); - void onMeshDimChanged(ADAPTATION_MODE aMode); +public slots: + void onAddOption(); + void itemChanged(QTreeWidgetItem * tblRow, int column); + void onMeshDimChanged(ADAPTATION_MODE aMode); private slots: - void _onWorkingDirectoryPushButton(); + void _onWorkingDirectoryPushButton(); private: - void setOptionValue(QString& option, QString& value); - std::map optionTreeWidgetItem; + void setOptionValue(QString& option, QString& value); + std::map optionTreeWidgetItem; - QTreeWidgetItem* getNewQTreeWidgetItem(QTreeWidget* table, const char* option, QString& name, bool isCustom); + QTreeWidgetItem* getNewQTreeWidgetItem(QTreeWidget* table, const char* option, QString& name, bool isCustom); }; @@ -307,26 +307,23 @@ enum { EDITABLE_ROLE = Qt::UserRole + 1, PARAM_NAME, NAME_COL = 0, VALUE_COL }; - - class ItemDelegate: public QItemDelegate { public: - ItemDelegate(QObject* parent=0): QItemDelegate(parent) {} - QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const; + ItemDelegate(QObject* parent=0): QItemDelegate(parent) {} + QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const; }; class MgAdaptAdvWidgetTreeWidget : public QTreeWidget { - Q_OBJECT + Q_OBJECT public: - MgAdaptAdvWidgetTreeWidget( QWidget* ); + MgAdaptAdvWidgetTreeWidget( QWidget* ); protected: - QModelIndex moveCursor( CursorAction, Qt::KeyboardModifiers ); - void keyPressEvent( QKeyEvent* ); + QModelIndex moveCursor( CursorAction, Qt::KeyboardModifiers ); + void keyPressEvent( QKeyEvent* ); }; - #endif // MG_ADAPTGUI_HXX diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index c66890cf3..a16812234 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -5154,7 +5154,7 @@ bool SMESHGUI::activateModule( SUIT_Study* study ) lab = lab + tr("INFO_COMPUTE") + "
"; lab = lab + tr("INFO_REFINE") + ":"; items << wrap(tr("INFO_REFINE_LOCAL_SIZE"), "li") - << wrap(tr("INFO_REFINE_SUBMESH"), "li"); + << wrap(tr("INFO_REFINE_SUBMESH"), "li"); lab = lab + wrap(items.join(""), "ul"); items.clear(); @@ -5162,11 +5162,11 @@ bool SMESHGUI::activateModule( SUIT_Study* study ) gb = app->infoPanel()->addGroup(tr("INFO_GRP_IMPORT_MESH")); items << wrap("UNV", "li") - << wrap("MED", "li") - << wrap("STL", "li") - << wrap("CGNS", "li") - << wrap("SAUV", "li") - << wrap("GMF", "li"); + << wrap("MED", "li") + << wrap("STL", "li") + << wrap("CGNS", "li") + << wrap("SAUV", "li") + << wrap("GMF", "li"); lab = tr("INFO_AVAILABLE_FORMATS") + ":" + wrap(items.join(""), "ul"); items.clear(); @@ -5175,9 +5175,9 @@ bool SMESHGUI::activateModule( SUIT_Study* study ) gb = app->infoPanel()->addGroup(tr("INFO_GRP_CHECK_MESH")); lab = tr("INFO_DISPLAY") + "
"; items << wrap(tr("INFO_QUALITY_AREA"), "li") - << wrap(tr("INFO_QUALITY_VOLUME"), "li") - << wrap(tr("INFO_QUALITY_ASPECT_RATION"), "li") - << wrap("...", "li"); + << wrap(tr("INFO_QUALITY_VOLUME"), "li") + << wrap(tr("INFO_QUALITY_ASPECT_RATION"), "li") + << wrap("...", "li"); lab = lab + tr("INFO_QUALITY_INFO") + ":" + wrap(items.join(""), "ul"); items.clear(); lab = lab + tr("INFO_CLIPPING"); diff --git a/src/SMESHGUI/SMESHGUI_AdaptDlg.cxx b/src/SMESHGUI/SMESHGUI_AdaptDlg.cxx index 8121932be..a37c196d3 100644 --- a/src/SMESHGUI/SMESHGUI_AdaptDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_AdaptDlg.cxx @@ -146,7 +146,7 @@ bool SMESHGUI_AdaptDlg::OnGUIEvent (int theCommandID) SMESH::MG_ADAPT_ptr model = SMESHGUI::GetSMESHGen()->CreateMG_ADAPT(); bool isCreation = false; - if (mySMESHGUI->isStudyLocked()) break; + if (mySMESHGUI->isStudyLocked()) break; mySMESHGUI->EmitSignalDeactivateDialog(); SMESHGUI_MG_ADAPTDRIVER *mgAdapt = new SMESHGUI_MG_ADAPTDRIVER(mySMESHGUI, model, isCreation); mgAdapt->show(); diff --git a/src/SMESHGUI/SMESHGUI_MG_ADAPTDRIVER.cxx b/src/SMESHGUI/SMESHGUI_MG_ADAPTDRIVER.cxx index 85a719b40..77ccb41d2 100644 --- a/src/SMESHGUI/SMESHGUI_MG_ADAPTDRIVER.cxx +++ b/src/SMESHGUI/SMESHGUI_MG_ADAPTDRIVER.cxx @@ -104,8 +104,8 @@ #include -const int SPACING = 6; // layout spacing -const int MARGIN = 9; // layout margin +const int SPACING = 6; // layout spacing +const int MARGIN = 9; // layout margin SALOME_ListIO mySelected; @@ -116,8 +116,8 @@ SALOME_ListIO mySelected; //================================================================ Handle(SALOME_InteractiveObject) firstIObject() { - const SALOME_ListIO& aList = selectedIO(); - return aList.Extent() > 0 ? aList.First() : Handle(SALOME_InteractiveObject)(); + const SALOME_ListIO& aList = selectedIO(); + return aList.Extent() > 0 ? aList.First() : Handle(SALOME_InteractiveObject)(); } //================================================================ // Function : selectedIO @@ -125,15 +125,15 @@ Handle(SALOME_InteractiveObject) firstIObject() //================================================================ const SALOME_ListIO& selectedIO() { - SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* > ( SUIT_Session::session()->activeApplication() ); - LightApp_SelectionMgr* aSelectionMgr = app->selectionMgr(); - if( aSelectionMgr ) - { - aSelectionMgr->selectedObjects( mySelected ); - for (SALOME_ListIteratorOfListIO it (mySelected); it.More(); it.Next()) - SCRUTE(it.Value()->getEntry()); - }; - return mySelected; + SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* > ( SUIT_Session::session()->activeApplication() ); + LightApp_SelectionMgr* aSelectionMgr = app->selectionMgr(); + if( aSelectionMgr ) + { + aSelectionMgr->selectedObjects( mySelected ); + for (SALOME_ListIteratorOfListIO it (mySelected); it.More(); it.Next()) + SCRUTE(it.Value()->getEntry()); + }; + return mySelected; } //================================================================ // Function : getStudy @@ -141,76 +141,78 @@ const SALOME_ListIO& selectedIO() //================================================================ _PTR(Study) getStudy() { - static _PTR(Study) _study; - if(!_study) - _study = SalomeApp_Application::getStudy(); - return _study; + static _PTR(Study) _study; + if(!_study) + _study = SalomeApp_Application::getStudy(); + return _study; } bool createAndPublishMed(QString fileName) { - SMESH::DriverMED_ReadStatus res; - SMESH::mesh_array_var aMeshes = new SMESH::mesh_array; - // SMESHGUI aGui; - - aMeshes = SMESHGUI::GetSMESHGen()->CreateMeshesFromMED( fileName.toUtf8().constData(), res ); - _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[0] ); - _PTR(Study) aStudy = SMESH::getStudy(); - QStringList anEntryList; - // bool isEmpty; - if ( aMeshSO ) { - _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder(); - _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" ); - aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" ); - anEntryList.append( aMeshSO->GetID().c_str() ); - } - else { - // isEmpty = true; - return false; - } - SMESHGUI::GetSMESHGUI()->updateObjBrowser(); + SMESH::DriverMED_ReadStatus res; + SMESH::mesh_array_var aMeshes = new SMESH::mesh_array; + // SMESHGUI aGui; - // browse to the published meshes - if( LightApp_Application* anApp = - dynamic_cast( SUIT_Session::session()->activeApplication() ) ) - anApp->browseObjects( anEntryList ); - return true; + aMeshes = SMESHGUI::GetSMESHGen()->CreateMeshesFromMED( fileName.toUtf8().constData(), res ); + _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[0] ); + _PTR(Study) aStudy = SMESH::getStudy(); + QStringList anEntryList; + // bool isEmpty; + if ( aMeshSO ) + { + _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder(); + _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" ); + aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" ); + anEntryList.append( aMeshSO->GetID().c_str() ); + } + else + { + // isEmpty = true; + return false; + } + SMESHGUI::GetSMESHGUI()->updateObjBrowser(); + + // browse to the published meshes + if( LightApp_Application* anApp = + dynamic_cast( SUIT_Session::session()->activeApplication() ) ) + anApp->browseObjects( anEntryList ); + return true; } bool createMgAdaptObject(MgAdapt *myMgAdapt ) { - // SMESH::SMESH_Mesh_var newMesh = SMESHGUI::GetSMESHGen()->CreateEmptyMesh(); - - // _PTR(SObject) aHypothesis; - _PTR(Study) aStudy = SMESH::getStudy(); - QStringList anEntryList; - _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder(); - _PTR(SComponent) mgadapt = aStudy->FindComponent("MG-ADAPT"); - _PTR(GenericAttribute) ga; - if (!aBuilder->FindAttribute(mgadapt, ga, "AttributeName") ) - { - mgadapt = aBuilder->NewComponent("MG-ADAPT"); - _PTR(AttributeName) Name = aBuilder->FindOrCreateAttribute(mgadapt, "AttributeName"); - Name->SetValue("MG-ADAPT"); - _PTR(AttributePixMap) myPixmap = aBuilder->FindOrCreateAttribute( mgadapt, "AttributePixMap" ); - myPixmap->SetPixMap( "ICON_MG_ADAPT" ); - anEntryList.append( mgadapt->GetID().c_str() ); - } - - _PTR(SObject) obj = aBuilder->NewObject(mgadapt); - _PTR(AttributeName) myName = aBuilder->FindOrCreateAttribute(obj, "AttributeName"); - myName->SetValue("hypo"); - _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( obj, "AttributePixMap" ); - aPixmap->SetPixMap( "ICON_SMESH_TREE_HYPO" ); - anEntryList.append( obj->GetID().c_str() ); - - SMESHGUI::GetSMESHGUI()->updateObjBrowser(); - - // // browse to the published meshes - if( LightApp_Application* anApp = - dynamic_cast( SUIT_Session::session()->activeApplication() ) ) - anApp->browseObjects( anEntryList ); - return true; + // SMESH::SMESH_Mesh_var newMesh = SMESHGUI::GetSMESHGen()->CreateEmptyMesh(); + + // _PTR(SObject) aHypothesis; + _PTR(Study) aStudy = SMESH::getStudy(); + QStringList anEntryList; + _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder(); + _PTR(SComponent) mgadapt = aStudy->FindComponent("MG-ADAPT"); + _PTR(GenericAttribute) ga; + if (!aBuilder->FindAttribute(mgadapt, ga, "AttributeName") ) + { + mgadapt = aBuilder->NewComponent("MG-ADAPT"); + _PTR(AttributeName) Name = aBuilder->FindOrCreateAttribute(mgadapt, "AttributeName"); + Name->SetValue("MG-ADAPT"); + _PTR(AttributePixMap) myPixmap = aBuilder->FindOrCreateAttribute( mgadapt, "AttributePixMap" ); + myPixmap->SetPixMap( "ICON_MG_ADAPT" ); + anEntryList.append( mgadapt->GetID().c_str() ); + } + + _PTR(SObject) obj = aBuilder->NewObject(mgadapt); + _PTR(AttributeName) myName = aBuilder->FindOrCreateAttribute(obj, "AttributeName"); + myName->SetValue("hypo"); + _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( obj, "AttributePixMap" ); + aPixmap->SetPixMap( "ICON_SMESH_TREE_HYPO" ); + anEntryList.append( obj->GetID().c_str() ); + + SMESHGUI::GetSMESHGUI()->updateObjBrowser(); + + // // browse to the published meshes + if( LightApp_Application* anApp = + dynamic_cast( SUIT_Session::session()->activeApplication() ) ) + anApp->browseObjects( anEntryList ); + return true; } @@ -221,122 +223,121 @@ bool createMgAdaptObject(MgAdapt *myMgAdapt ) //================================================================ int IObjectCount() { - SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); - LightApp_SelectionMgr* aSelectionMgr = app->selectionMgr(); - if( aSelectionMgr ) - { - aSelectionMgr->selectedObjects( mySelected ); - SCRUTE(mySelected.Extent()); - return mySelected.Extent(); - } - return 0; + SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); + LightApp_SelectionMgr* aSelectionMgr = app->selectionMgr(); + if( aSelectionMgr ) + { + aSelectionMgr->selectedObjects( mySelected ); + SCRUTE(mySelected.Extent()); + return mySelected.Extent(); + } + return 0; } SMESHGUI_MG_ADAPTDRIVER::SMESHGUI_MG_ADAPTDRIVER( SMESHGUI* theModule, SMESH::MG_ADAPT_ptr myModel, bool isCreation ) - : mySMESHGUI( theModule ), - myFilterDlg(0), - myIsApplyAndClose( false ), - SMESHGUI_MgAdaptDlg((SalomeApp_Module*)theModule, myModel, SMESHGUI::desktop(), isCreation) + : mySMESHGUI( theModule ), + myFilterDlg(0), + myIsApplyAndClose( false ), + SMESHGUI_MgAdaptDlg((SalomeApp_Module*)theModule, myModel, SMESHGUI::desktop(), isCreation) { - resMgr = resourceMgr(); + resMgr = resourceMgr(); - selMgr = selectionMgr(); + selMgr = selectionMgr(); - // connections - connect(myArgs, SIGNAL(updateSelection()), this, SLOT(updateSelection())); - connect(myArgs, SIGNAL(toExportMED(const char*)), this, SLOT(exportMED(const char*))); + // connections + connect(myArgs, SIGNAL(updateSelection()), this, SLOT(updateSelection())); + connect(myArgs, SIGNAL(toExportMED(const char*)), this, SLOT(exportMED(const char*))); } SUIT_ResourceMgr* SMESHGUI_MG_ADAPTDRIVER::resourceMgr() { - return dynamic_cast( SUIT_Session::session()->resourceMgr() ); + return dynamic_cast( SUIT_Session::session()->resourceMgr() ); } LightApp_SelectionMgr* SMESHGUI_MG_ADAPTDRIVER::selectionMgr() { - SalomeApp_Application* anApp = dynamic_cast( SUIT_Session::session()->activeApplication() ); - if( anApp ) - return dynamic_cast( anApp->selectionMgr() ); - else - return 0; + SalomeApp_Application* anApp = dynamic_cast( SUIT_Session::session()->activeApplication() ); + if( anApp ) + return dynamic_cast( anApp->selectionMgr() ); + else + return 0; } void SMESHGUI_MG_ADAPTDRIVER::updateSelection() { - disconnect( selMgr, 0, this, 0 ); - selMgr->clearFilters(); + disconnect( selMgr, 0, this, 0 ); + selMgr->clearFilters(); - SMESH::SetPointRepresentation( true ); - if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() ) - aViewWindow->SetSelectionMode( ActorSelection ); - if (myArgs->aBrowser->isChecked()) - { - connect( selMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() )); - selectionChanged(); - } + SMESH::SetPointRepresentation( true ); + if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() ) + aViewWindow->SetSelectionMode( ActorSelection ); + if (myArgs->aBrowser->isChecked()) + { + connect( selMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() )); + selectionChanged(); + } } void SMESHGUI_MG_ADAPTDRIVER::selectionChanged() { - //~ get selected mesh - SALOME_ListIO aList; - selMgr->selectedObjects(aList); - QString aString = ""; - int nbSel = aList.Extent(); - if (nbSel != 1) - return; - - Handle(SALOME_InteractiveObject) IO = aList.First(); - SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(IO); - if ( !mesh->_is_nil() ) - { - myMesh = mesh; - - mySelectedObject = SMESH::IObjectToInterface( IO ); - if ( mySelectedObject->_is_nil() ) - return; + //~ get selected mesh + SALOME_ListIO aList; + selMgr->selectedObjects(aList); + QString aString = ""; + int nbSel = aList.Extent(); + if (nbSel != 1) + return; + + Handle(SALOME_InteractiveObject) IO = aList.First(); + SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(IO); + if ( !mesh->_is_nil() ) + { + myMesh = mesh; - } - else + mySelectedObject = SMESH::IObjectToInterface( IO ); + if ( mySelectedObject->_is_nil() ) return; - - SMESH::GetNameOfSelectedIObjects( selMgr, aString ); - if ( aString.isEmpty() ) aString = " "; - else aString = aString.trimmed(); - - - bool ok = !aString.isEmpty(); - if ( !mesh->_is_nil() ) - { - myArgs->aBrowserObject->setText( aString ); - myArgs->meshNameLineEdit->setText( aString ); - myArgs->selectOutMedFileLineEdit->setText(aString+QString(".med")); - ADAPTATION_MODE aMode; - int nbVolumes = myMesh->NbVolumes(); - int nbFaces = myMesh->NbFaces(); - if(nbFaces > 0 && nbVolumes > 0) aMode = ADAPTATION_MODE::BOTH; - else if(nbFaces > 0) aMode = ADAPTATION_MODE::SURFACE; - else aMode = ADAPTATION_MODE::VOLUME; - emit myArgs->meshDimSignal(aMode); - } + } + else + return; + + SMESH::GetNameOfSelectedIObjects( selMgr, aString ); + if ( aString.isEmpty() ) aString = " "; + else aString = aString.trimmed(); + + + bool ok = !aString.isEmpty(); + if ( !mesh->_is_nil() ) + { + myArgs->aBrowserObject->setText( aString ); + myArgs->meshNameLineEdit->setText( aString ); + myArgs->selectOutMedFileLineEdit->setText(aString+QString(".med")); + ADAPTATION_MODE aMode; + int nbVolumes = myMesh->NbVolumes(); + int nbFaces = myMesh->NbFaces(); + if(nbFaces > 0 && nbVolumes > 0) aMode = ADAPTATION_MODE::BOTH; + else if(nbFaces > 0) aMode = ADAPTATION_MODE::SURFACE; + else aMode = ADAPTATION_MODE::VOLUME; + emit myArgs->meshDimSignal(aMode); + } } void SMESHGUI_MG_ADAPTDRIVER::exportMED(const char* tmp_file) { - bool toOverwrite = true; - bool toFindOutDim = true; - myMesh->ExportMED(tmp_file, false, -1, toOverwrite, toFindOutDim); + bool toOverwrite = true; + bool toFindOutDim = true; + myMesh->ExportMED(tmp_file, false, -1, toOverwrite, toFindOutDim); } void SMESHGUI_MG_ADAPTDRIVER::setMyMesh(SMESH::SMESH_Mesh_var mesh) { - myMesh = mesh; + myMesh = mesh; } SMESH::SMESH_Mesh_var SMESHGUI_MG_ADAPTDRIVER::getMyMesh() { - return myMesh; + return myMesh; } //================================================================================= @@ -345,43 +346,42 @@ SMESH::SMESH_Mesh_var SMESHGUI_MG_ADAPTDRIVER::getMyMesh() //================================================================================= void SMESHGUI_MG_ADAPTDRIVER::clickOnOk() { - setIsApplyAndClose( true ); - clickOnApply(); - reject(); + setIsApplyAndClose( true ); + clickOnApply(); + reject(); } bool SMESHGUI_MG_ADAPTDRIVER::clickOnApply() { - if ( SMESHGUI::isStudyLocked() ) - return false; - if( !isValid() ) - return false; + if ( SMESHGUI::isStudyLocked() ) + return false; + if( !isValid() ) + return false; - SMESHGUI_MgAdaptDlg::clickOnApply(); + SMESHGUI_MgAdaptDlg::clickOnApply(); - bool ok = execute(); - if (getModel()->getPublish()) this->createMeshInObjectBrowser(); + bool ok = execute(); + if (getModel()->getPublish()) this->createMeshInObjectBrowser(); - return ok; + return ok; } bool SMESHGUI_MG_ADAPTDRIVER::execute() { - - int err; - //~std::string errStr; - char* errStr; - try - { - err = getModel()->compute(); - errStr = getModel()->getErrMsg(); - std::string msg = err == 0 ? " ok" : std::string("Not ok \n")+CORBA::string_dup(errStr) ; - } - catch (const std::exception& e) - { - std::cerr<compute(); + errStr = getModel()->getErrMsg(); + std::string msg = err == 0 ? " ok" : std::string("Not ok \n")+CORBA::string_dup(errStr) ; + } + catch (const std::exception& e) + { + std::cerr<clear(); - myNbOkElements = 0; + if ( ResetControls ) + { + myLineEditElements->clear(); + myNbOkElements = 0; - buttonOk->setEnabled(false); - buttonApply->setEnabled(false); + buttonOk->setEnabled(false); + buttonApply->setEnabled(false); - //~myActor = 0; - myMesh = SMESH::SMESH_Mesh::_nil(); + //~myActor = 0; + myMesh = SMESH::SMESH_Mesh::_nil(); - myIdSourceCheck->setChecked(true); + myIdSourceCheck->setChecked(true); - onConstructor( 0 ); - } + onConstructor( 0 ); + } } @@ -418,23 +418,21 @@ void SMESHGUI_MG_ADAPTDRIVER::Init (bool ResetControls) void SMESHGUI_MG_ADAPTDRIVER::onConstructor( int withGeom ) { - myGeomLabel ->setVisible( withGeom ); - myGeomNameEdit ->setVisible( withGeom ); - myReuseHypCheck ->setVisible( withGeom ); - myCopyElementsCheck->setVisible( withGeom ); - myFilterBtn ->setVisible( !withGeom ); - myIdSourceCheck ->setVisible( !withGeom ); + myGeomLabel ->setVisible( withGeom ); + myGeomNameEdit ->setVisible( withGeom ); + myReuseHypCheck ->setVisible( withGeom ); + myCopyElementsCheck->setVisible( withGeom ); + myFilterBtn ->setVisible( !withGeom ); + myIdSourceCheck ->setVisible( !withGeom ); - if ( !withGeom ) - myMeshNameEdit->setText( SMESH::UniqueMeshName("Mesh")); + if ( !withGeom ) + myMeshNameEdit->setText( SMESH::UniqueMeshName("Mesh")); } - //~void SMESHGUI_MG_ADAPTDRIVER::onSelectIdSource( bool ) //~{} - //================================================================================= // function : enterEvent() // purpose : @@ -442,13 +440,13 @@ void SMESHGUI_MG_ADAPTDRIVER::onConstructor( int withGeom ) void SMESHGUI_MG_ADAPTDRIVER::enterEvent (QEvent*) { - // if ( !ConstructorsBox->isEnabled() ) { - // SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ); - // if ( aViewWindow && !mySelector ) { - // mySelector = aViewWindow->GetSelector(); - // } - // activateThisDialog(); - // } + // if ( !ConstructorsBox->isEnabled() ) { + // SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ); + // if ( aViewWindow && !mySelector ) { + // mySelector = aViewWindow->GetSelector(); + // } + // activateThisDialog(); + // } } @@ -459,14 +457,15 @@ void SMESHGUI_MG_ADAPTDRIVER::enterEvent (QEvent*) void SMESHGUI_MG_ADAPTDRIVER::keyPressEvent( QKeyEvent* e ) { - QDialog::keyPressEvent( e ); - if ( e->isAccepted() ) - return; + QDialog::keyPressEvent( e ); + if ( e->isAccepted() ) + return; - if ( e->key() == Qt::Key_F1 ) { - e->accept(); - clickOnHelp(); - } + if ( e->key() == Qt::Key_F1 ) + { + e->accept(); + clickOnHelp(); + } } @@ -477,22 +476,21 @@ void SMESHGUI_MG_ADAPTDRIVER::keyPressEvent( QKeyEvent* e ) void SMESHGUI_MG_ADAPTDRIVER::clickOnHelp() { - LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication()); - if (app) - app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName); - else { - QString platform; + LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication()); + if (app) + app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName); + else { + QString platform; #ifdef WIN32 - platform = "winapplication"; + platform = "winapplication"; #else - platform = "application"; + platform = "application"; #endif - SUIT_MessageBox::warning(this, tr("WRN_WARNING"), - tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE"). - arg(app->resourceMgr()->stringValue("ExternalBrowser", - platform)). - arg(myHelpFileName)); - } + SUIT_MessageBox::warning(this, tr("WRN_WARNING"), + tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE"). + arg(app->resourceMgr()->stringValue("ExternalBrowser",platform)). + arg(myHelpFileName)); + } } @@ -502,74 +500,74 @@ void SMESHGUI_MG_ADAPTDRIVER::clickOnHelp() //======================================================================= QString SMESHGUI_MG_ADAPTDRIVER::getErrorMsg( SMESH::string_array_var theInvalidEntries, - QStringList & theEntriesToBrowse ) + QStringList & theEntriesToBrowse ) { - if ( theInvalidEntries->length() == 0 ) - return tr("OPERATION_FAILED"); + if ( theInvalidEntries->length() == 0 ) + return tr("OPERATION_FAILED"); + + // theInvalidEntries - SObject's that hold geometry objects whose + // counterparts are not found in the newGeometry, followed by SObject's + // holding mesh sub-objects that are invalid because they depend on a not found + // preceding sub-shape - // theInvalidEntries - SObject's that hold geometry objects whose - // counterparts are not found in the newGeometry, followed by SObject's - // holding mesh sub-objects that are invalid because they depend on a not found - // preceding sub-shape + QString msg = tr("SUBSHAPES_NOT_FOUND_MSG") + "\n"; - QString msg = tr("SUBSHAPES_NOT_FOUND_MSG") + "\n"; + QString objString; + for ( CORBA::ULong i = 0; i < theInvalidEntries->length(); ++i ) + { + _PTR(SObject) so = SMESH::getStudy()->FindObjectID( theInvalidEntries[i].in() ); - QString objString; - for ( CORBA::ULong i = 0; i < theInvalidEntries->length(); ++i ) + int objType = SMESHGUI_Selection::type( theInvalidEntries[i].in() ); + if ( objType < 0 ) // geom object { - _PTR(SObject) so = SMESH::getStudy()->FindObjectID( theInvalidEntries[i].in() ); - - int objType = SMESHGUI_Selection::type( theInvalidEntries[i].in() ); - if ( objType < 0 ) // geom object - { - objString += "\n"; - if ( so ) - objString += so->GetName().c_str(); - else - objString += theInvalidEntries[i].in(); // it's something like "FACE #2" - } - else // smesh object - { - theEntriesToBrowse.push_back( theInvalidEntries[i].in() ); - - objString += "\n "; - switch ( objType ) { - case SMESH::MESH: - objString += tr("SMESH_MESH"); - break; - case SMESH::HYPOTHESIS: - objString += tr("SMESH_HYPOTHESIS"); - break; - case SMESH::ALGORITHM: - objString += tr("SMESH_ALGORITHM"); - break; - case SMESH::SUBMESH_VERTEX: - case SMESH::SUBMESH_EDGE: - case SMESH::SUBMESH_FACE: - case SMESH::SUBMESH_SOLID: - case SMESH::SUBMESH_COMPOUND: - case SMESH::SUBMESH: - objString += tr("SMESH_SUBMESH"); - break; - case SMESH::GROUP: - objString += tr("SMESH_GROUP"); - break; - default: - ; - } - objString += " \""; - if ( so ) - objString += so->GetName().c_str(); - objString += "\" ("; - objString += theInvalidEntries[i].in(); - objString += ")"; - } + objString += "\n"; + if ( so ) + objString += so->GetName().c_str(); + else + objString += theInvalidEntries[i].in(); // it's something like "FACE #2" } - if ( !objString.isEmpty() ) - msg += objString; + else // smesh object + { + theEntriesToBrowse.push_back( theInvalidEntries[i].in() ); + + objString += "\n "; + switch ( objType ) { + case SMESH::MESH: + objString += tr("SMESH_MESH"); + break; + case SMESH::HYPOTHESIS: + objString += tr("SMESH_HYPOTHESIS"); + break; + case SMESH::ALGORITHM: + objString += tr("SMESH_ALGORITHM"); + break; + case SMESH::SUBMESH_VERTEX: + case SMESH::SUBMESH_EDGE: + case SMESH::SUBMESH_FACE: + case SMESH::SUBMESH_SOLID: + case SMESH::SUBMESH_COMPOUND: + case SMESH::SUBMESH: + objString += tr("SMESH_SUBMESH"); + break; + case SMESH::GROUP: + objString += tr("SMESH_GROUP"); + break; + default: + ; + } + objString += " \""; + if ( so ) + objString += so->GetName().c_str(); + objString += "\" ("; + objString += theInvalidEntries[i].in(); + objString += ")"; + } + } + if ( !objString.isEmpty() ) + msg += objString; - return msg; + return msg; } //================================================================================= @@ -579,64 +577,66 @@ QString SMESHGUI_MG_ADAPTDRIVER::getErrorMsg( SMESH::string_array_var theInvalid bool SMESHGUI_MG_ADAPTDRIVER::isValid() { - bool ok = true; - return ok; + bool ok = true; + return ok; } bool SMESHGUI_MG_ADAPTDRIVER::createMeshInObjectBrowser() { - QString filename(getModel()->getMedFileOut()); - QStringList errors; - QStringList anEntryList; - bool isEmpty = false; - bool ok = false; - SMESH::SMESH_Gen_var SMESH_Gen_ptr = SMESHGUI::GetSMESHGen(); - if (!SMESH_Gen_ptr) { - std::cerr << "Could not retrieve SMESH_Gen_ptr" << std::endl; - throw SALOME_Exception(LOCALIZED("Could not retrieve SMESH::GetSMESHGen()")); - } - SMESH::mesh_array_var aMeshes = new SMESH::mesh_array; - aMeshes->length( 1 ); // one mesh only - SMESH::DriverMED_ReadStatus res; - aMeshes = SMESH_Gen_ptr->CreateMeshesFromMED( filename.toUtf8().constData(), res ); - if ( res != SMESH::DRS_OK ) { - errors.append( QString( "%1 :\n\t%2" ).arg( filename ).arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) ); - } - _PTR(Study) aStudy = SMESH::getStudy(); - for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) + QString filename(getModel()->getMedFileOut()); + QStringList errors; + QStringList anEntryList; + bool isEmpty = false; + bool ok = false; + SMESH::SMESH_Gen_var SMESH_Gen_ptr = SMESHGUI::GetSMESHGen(); + if (!SMESH_Gen_ptr) { + std::cerr << "Could not retrieve SMESH_Gen_ptr" << std::endl; + throw SALOME_Exception(LOCALIZED("Could not retrieve SMESH::GetSMESHGen()")); + } + SMESH::mesh_array_var aMeshes = new SMESH::mesh_array; + aMeshes->length( 1 ); // one mesh only + SMESH::DriverMED_ReadStatus res; + aMeshes = SMESH_Gen_ptr->CreateMeshesFromMED( filename.toUtf8().constData(), res ); + if ( res != SMESH::DRS_OK ) { + errors.append( QString( "%1 :\n\t%2" ).arg( filename ).arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) ); + } + _PTR(Study) aStudy = SMESH::getStudy(); + for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) + { + _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] ); + if ( aMeshSO ) { - _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] ); - if ( aMeshSO ) { - _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder(); - _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" ); - aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" ); // put REFINED mesh ico - anEntryList.append( aMeshSO->GetID().c_str() ); - } - else { - isEmpty = true; - } + _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder(); + _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" ); + aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" ); // put REFINED mesh ico + anEntryList.append( aMeshSO->GetID().c_str() ); } - // update Object browser - SMESHGUI::GetSMESHGUI()->updateObjBrowser(); - // browse to the published meshes - if( LightApp_Application* anApp = - dynamic_cast( SUIT_Session::session()->activeApplication() ) ) - anApp->browseObjects( anEntryList ); - - // show Error message box if there were errors - if ( errors.count() > 0 ) { - SUIT_MessageBox::critical( SMESHGUI::desktop(), - QObject::tr( "SMESH_ERROR" ), - QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) ); - } - - // show warning message box, if some imported mesh is empty - if ( isEmpty ) { - SUIT_MessageBox::warning( SMESHGUI::desktop(), - QObject::tr( "SMESH_WRN_WARNING" ), - QObject::tr( "SMESH_DRS_SOME_EMPTY" ) ); + else + { + isEmpty = true; } - return true; + } + // update Object browser + SMESHGUI::GetSMESHGUI()->updateObjBrowser(); + // browse to the published meshes + if( LightApp_Application* anApp = + dynamic_cast( SUIT_Session::session()->activeApplication() ) ) + anApp->browseObjects( anEntryList ); + + // show Error message box if there were errors + if ( errors.count() > 0 ) { + SUIT_MessageBox::critical( SMESHGUI::desktop(), + QObject::tr( "SMESH_ERROR" ), + QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) ); + } + + // show warning message box, if some imported mesh is empty + if ( isEmpty ) { + SUIT_MessageBox::warning( SMESHGUI::desktop(), + QObject::tr( "SMESH_WRN_WARNING" ), + QObject::tr( "SMESH_DRS_SOME_EMPTY" ) ); + } + return true; } //================================================================ @@ -646,7 +646,7 @@ bool SMESHGUI_MG_ADAPTDRIVER::createMeshInObjectBrowser() //================================================================ void SMESHGUI_MG_ADAPTDRIVER::setIsApplyAndClose( const bool theFlag ) { - myIsApplyAndClose = theFlag; + myIsApplyAndClose = theFlag; }//================================================================ // function : isApplyAndClose // Purpose : Get value of the flag indicating that the dialog is @@ -654,7 +654,7 @@ void SMESHGUI_MG_ADAPTDRIVER::setIsApplyAndClose( const bool theFlag ) //================================================================ bool SMESHGUI_MG_ADAPTDRIVER::isApplyAndClose() const { - return myIsApplyAndClose; + return myIsApplyAndClose; } //================================================================================= @@ -663,16 +663,16 @@ bool SMESHGUI_MG_ADAPTDRIVER::isApplyAndClose() const //================================================================================= void SMESHGUI_MG_ADAPTDRIVER::deactivateActiveDialog() { - - if (ConstructorsBox->isEnabled()) { - ConstructorsBox->setEnabled(false); - GroupArguments->setEnabled(false); - GroupButtons->setEnabled(false); - mySMESHGUI->ResetState(); - mySMESHGUI->SetActiveDialogBox(0); - if ( selMgr ) - selMgr->removeFilter( myIdSourceFilter ); - } + if (ConstructorsBox->isEnabled()) + { + ConstructorsBox->setEnabled(false); + GroupArguments->setEnabled(false); + GroupButtons->setEnabled(false); + mySMESHGUI->ResetState(); + mySMESHGUI->SetActiveDialogBox(0); + if ( selMgr ) + selMgr->removeFilter( myIdSourceFilter ); + } } //================================================================================= @@ -682,17 +682,17 @@ void SMESHGUI_MG_ADAPTDRIVER::deactivateActiveDialog() void SMESHGUI_MG_ADAPTDRIVER::activateThisDialog() { - /* Emit a signal to deactivate the active dialog */ - // mySMESHGUI->EmitSignalDeactivateDialog(); - // ConstructorsBox->setEnabled(true); - // GroupArguments->setEnabled(true); - // GroupButtons->setEnabled(true); + /* Emit a signal to deactivate the active dialog */ + // mySMESHGUI->EmitSignalDeactivateDialog(); + // ConstructorsBox->setEnabled(true); + // GroupArguments->setEnabled(true); + // GroupButtons->setEnabled(true); - // mySMESHGUI->SetActiveDialogBox((QDialog*)this); + // mySMESHGUI->SetActiveDialogBox((QDialog*)this); - // onSelectIdSource( myIdSourceCheck->isChecked() ); + // onSelectIdSource( myIdSourceCheck->isChecked() ); - // SelectionIntoArgument(); + // SelectionIntoArgument(); } //================================================================================= @@ -701,29 +701,30 @@ void SMESHGUI_MG_ADAPTDRIVER::activateThisDialog() //================================================================================= void SMESHGUI_MG_ADAPTDRIVER::setFilters() { - if(myMesh->_is_nil()) { - SUIT_MessageBox::critical(this, - tr("SMESH_ERROR"), - tr("NO_MESH_SELECTED")); - return; - } - if ( !myFilterDlg ) - myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL ); - - QList types; - if ( myMesh->NbEdges() ) types << SMESH::EDGE; - if ( myMesh->NbFaces() ) types << SMESH::FACE; - if ( myMesh->NbVolumes() ) types << SMESH::VOLUME; - if ( myMesh->NbBalls() ) types << SMESH::BALL; - if ( myMesh->Nb0DElements()) types << SMESH::ELEM0D; - if ( types.count() > 1 ) types << SMESH::ALL; - - myFilterDlg->Init( types ); - myFilterDlg->SetSelection(); - myFilterDlg->SetMesh( myMesh ); - myFilterDlg->SetSourceWg( myLineEditElements ); - - myFilterDlg->show(); + if(myMesh->_is_nil()) + { + SUIT_MessageBox::critical(this, + tr("SMESH_ERROR"), + tr("NO_MESH_SELECTED")); + return; + } + if ( !myFilterDlg ) + myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL ); + + QList types; + if ( myMesh->NbEdges() ) types << SMESH::EDGE; + if ( myMesh->NbFaces() ) types << SMESH::FACE; + if ( myMesh->NbVolumes() ) types << SMESH::VOLUME; + if ( myMesh->NbBalls() ) types << SMESH::BALL; + if ( myMesh->Nb0DElements()) types << SMESH::ELEM0D; + if ( types.count() > 1 ) types << SMESH::ALL; + + myFilterDlg->Init( types ); + myFilterDlg->SetSelection(); + myFilterDlg->SetMesh( myMesh ); + myFilterDlg->SetSourceWg( myLineEditElements ); + + myFilterDlg->show(); } //================================================================================= @@ -732,13 +733,13 @@ void SMESHGUI_MG_ADAPTDRIVER::setFilters() //================================================================================= void SMESHGUI_MG_ADAPTDRIVER::onOpenView() { - if ( mySelector ) { - SMESH::SetPointRepresentation(false); - } - else { - mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector(); - activateThisDialog(); - } + if ( mySelector ) { + SMESH::SetPointRepresentation(false); + } + else { + mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector(); + activateThisDialog(); + } } //================================================================================= @@ -747,6 +748,6 @@ void SMESHGUI_MG_ADAPTDRIVER::onOpenView() //================================================================================= void SMESHGUI_MG_ADAPTDRIVER::onCloseView() { - deactivateActiveDialog(); - mySelector = 0; + deactivateActiveDialog(); + mySelector = 0; } diff --git a/src/SMESH_I/MG_ADAPT_i.cxx b/src/SMESH_I/MG_ADAPT_i.cxx index befc5beb8..ec2c9d30d 100644 --- a/src/SMESH_I/MG_ADAPT_i.cxx +++ b/src/SMESH_I/MG_ADAPT_i.cxx @@ -40,61 +40,61 @@ using namespace SMESH; void MG_ADAPT_i::copyHypothesisDataToImpl(const SMESH::MgAdaptHypothesisData& from, ::MG_ADAPT::MgAdaptHypothesisData* to) const { - to->myFileInDir = from.myFileInDir; - to->myMeshFileIn = from.myMeshFileIn; - to->myMeshFileBackground = from.myMeshFileBackground; - to->myOutMeshName = from.myOutMeshName; - to->myMeshFileOut = from.myMeshFileOut; - to->myFileOutDir = from.myFileOutDir; - to->myFileSizeMapDir = from.myFileSizeMapDir; - to->myFieldName = from.myFieldName; - to->fromMedFile = from.fromMedFile; - to->myPublish = from.myPublish; - to->myMeshOutMed = from.myMeshOutMed; - to->myUseLocalMap = from.myUseLocalMap; - to->myUseBackgroundMap = from.myUseBackgroundMap; - to->myUseConstantValue = from.myUseConstantValue; - to->myConstantValue = from.myConstantValue; - to->myTimeStep = from.myTimeStep; - to->myRank = from.myRank; - to->myUseNoTimeStep = from.myUseNoTimeStep; - to->myUseLastTimeStep = from.myUseLastTimeStep; - to->myUseChosenTimeStep = from.myUseChosenTimeStep; - to->myWorkingDir = from.myWorkingDir; - to->myLogFile = from.myLogFile; - to->myPrintLogInFile = from.myPrintLogInFile; - to->myKeepFiles = from.myKeepFiles; - to->myRemoveLogOnSuccess = from.myRemoveLogOnSuccess; - to->myVerboseLevel = from.myVerboseLevel; + to->myFileInDir = from.myFileInDir; + to->myMeshFileIn = from.myMeshFileIn; + to->myMeshFileBackground = from.myMeshFileBackground; + to->myOutMeshName = from.myOutMeshName; + to->myMeshFileOut = from.myMeshFileOut; + to->myFileOutDir = from.myFileOutDir; + to->myFileSizeMapDir = from.myFileSizeMapDir; + to->myFieldName = from.myFieldName; + to->fromMedFile = from.fromMedFile; + to->myPublish = from.myPublish; + to->myMeshOutMed = from.myMeshOutMed; + to->myUseLocalMap = from.myUseLocalMap; + to->myUseBackgroundMap = from.myUseBackgroundMap; + to->myUseConstantValue = from.myUseConstantValue; + to->myConstantValue = from.myConstantValue; + to->myTimeStep = from.myTimeStep; + to->myRank = from.myRank; + to->myUseNoTimeStep = from.myUseNoTimeStep; + to->myUseLastTimeStep = from.myUseLastTimeStep; + to->myUseChosenTimeStep = from.myUseChosenTimeStep; + to->myWorkingDir = from.myWorkingDir; + to->myLogFile = from.myLogFile; + to->myPrintLogInFile = from.myPrintLogInFile; + to->myKeepFiles = from.myKeepFiles; + to->myRemoveLogOnSuccess = from.myRemoveLogOnSuccess; + to->myVerboseLevel = from.myVerboseLevel; } void MG_ADAPT_i::copyHypothesisDataFromImpl(const ::MG_ADAPT::MgAdaptHypothesisData* from, SMESH::MgAdaptHypothesisData* to) const { - to->myFileInDir = CORBA::string_dup(from->myFileInDir.c_str()); - to->myMeshFileIn = CORBA::string_dup(from->myMeshFileIn.c_str()); - to->myMeshFileBackground = CORBA::string_dup(from->myMeshFileBackground.c_str()); - to->myOutMeshName = CORBA::string_dup(from->myOutMeshName.c_str()); - to->myMeshFileOut = CORBA::string_dup(from->myMeshFileOut.c_str()); - to->myFileOutDir = CORBA::string_dup(from->myFileOutDir.c_str()); - to->myFileSizeMapDir = CORBA::string_dup(from->myFileSizeMapDir.c_str()); - to->myFieldName = CORBA::string_dup(from->myFieldName.c_str()); - to->fromMedFile = from->fromMedFile; - to->myPublish = from->myPublish; - to->myMeshOutMed = from->myMeshOutMed; - to->myUseLocalMap = from->myUseLocalMap; - to->myUseBackgroundMap = from->myUseBackgroundMap; - to->myUseConstantValue = from->myUseConstantValue; - to->myConstantValue = from->myConstantValue; - to->myTimeStep = from->myTimeStep; - to->myRank = from->myRank; - to->myUseNoTimeStep = from->myUseNoTimeStep; - to->myUseLastTimeStep = from->myUseLastTimeStep; - to->myUseChosenTimeStep = from->myUseChosenTimeStep; - to->myWorkingDir = CORBA::string_dup(from->myWorkingDir.c_str()); - to->myLogFile = CORBA::string_dup(from->myLogFile.c_str()); - to->myPrintLogInFile = from->myPrintLogInFile; - to->myKeepFiles = from->myKeepFiles; - to->myRemoveLogOnSuccess = from->myRemoveLogOnSuccess; - to->myVerboseLevel = from->myVerboseLevel; + to->myFileInDir = CORBA::string_dup(from->myFileInDir.c_str()); + to->myMeshFileIn = CORBA::string_dup(from->myMeshFileIn.c_str()); + to->myMeshFileBackground = CORBA::string_dup(from->myMeshFileBackground.c_str()); + to->myOutMeshName = CORBA::string_dup(from->myOutMeshName.c_str()); + to->myMeshFileOut = CORBA::string_dup(from->myMeshFileOut.c_str()); + to->myFileOutDir = CORBA::string_dup(from->myFileOutDir.c_str()); + to->myFileSizeMapDir = CORBA::string_dup(from->myFileSizeMapDir.c_str()); + to->myFieldName = CORBA::string_dup(from->myFieldName.c_str()); + to->fromMedFile = from->fromMedFile; + to->myPublish = from->myPublish; + to->myMeshOutMed = from->myMeshOutMed; + to->myUseLocalMap = from->myUseLocalMap; + to->myUseBackgroundMap = from->myUseBackgroundMap; + to->myUseConstantValue = from->myUseConstantValue; + to->myConstantValue = from->myConstantValue; + to->myTimeStep = from->myTimeStep; + to->myRank = from->myRank; + to->myUseNoTimeStep = from->myUseNoTimeStep; + to->myUseLastTimeStep = from->myUseLastTimeStep; + to->myUseChosenTimeStep = from->myUseChosenTimeStep; + to->myWorkingDir = CORBA::string_dup(from->myWorkingDir.c_str()); + to->myLogFile = CORBA::string_dup(from->myLogFile.c_str()); + to->myPrintLogInFile = from->myPrintLogInFile; + to->myKeepFiles = from->myKeepFiles; + to->myRemoveLogOnSuccess = from->myRemoveLogOnSuccess; + to->myVerboseLevel = from->myVerboseLevel; } SMESH::MG_ADAPT_ptr SMESH_Gen_i::CreateMG_ADAPT() { @@ -111,12 +111,12 @@ SMESH::MG_ADAPT_ptr SMESH_Gen_i::CreateAdaptationHypothesis() SMESH::MG_ADAPT_OBJECT_ptr SMESH_Gen_i::Adaptation( const char* adaptationType) { - if (!strcmp(adaptationType, "MG_Adapt")){ - SMESH::MG_ADAPT_OBJECT_i* mg_adapt_object = new SMESH::MG_ADAPT_OBJECT_i(); - SMESH::MG_ADAPT_OBJECT_var anObj = mg_adapt_object->_this(); - return anObj._retn(); - } - + if (!strcmp(adaptationType, "MG_Adapt")) + { + SMESH::MG_ADAPT_OBJECT_i* mg_adapt_object = new SMESH::MG_ADAPT_OBJECT_i(); + SMESH::MG_ADAPT_OBJECT_var anObj = mg_adapt_object->_this(); + return anObj._retn(); + } } //~SMESH::MG_ADAPT_ptr MG_ADAPT_i::CreateMG_ADAPT() @@ -165,181 +165,180 @@ MG_ADAPT_i::~MG_ADAPT_i() } void MG_ADAPT_i::setData( SMESH::MgAdaptHypothesisData& data) { - ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData(); - copyHypothesisDataToImpl(data, baseData); - myMgAdapt->setData(baseData); - delete baseData; + ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData(); + copyHypothesisDataToImpl(data, baseData); + myMgAdapt->setData(baseData); + delete baseData; } void MG_ADAPT_i::setMedFileIn(const char* str) { - myMgAdapt->setMedFileIn(str); + myMgAdapt->setMedFileIn(str); } char* MG_ADAPT_i::getMedFileIn() { - return CORBA::string_dup(myMgAdapt->getMedFileIn().c_str()); + return CORBA::string_dup(myMgAdapt->getMedFileIn().c_str()); } void MG_ADAPT_i::setMedFileOut(const char* str) { - myMgAdapt->setMedFileOut(str); + myMgAdapt->setMedFileOut(str); } char* MG_ADAPT_i::getMedFileOut() { - return CORBA::string_dup(myMgAdapt->getMedFileOut().c_str()); + return CORBA::string_dup(myMgAdapt->getMedFileOut().c_str()); } void MG_ADAPT_i::setMeshName(const char* str) { - myMgAdapt->setMeshName(str); + myMgAdapt->setMeshName(str); } char* MG_ADAPT_i::getMeshName() { - return CORBA::string_dup(myMgAdapt->getMeshName().c_str()); + return CORBA::string_dup(myMgAdapt->getMeshName().c_str()); } void MG_ADAPT_i::setMeshNameOut(const char* str) { - myMgAdapt->setMeshNameOut(str); + myMgAdapt->setMeshNameOut(str); } char* MG_ADAPT_i::getMeshNameOut() { - return CORBA::string_dup(myMgAdapt->getMeshNameOut().c_str()); + return CORBA::string_dup(myMgAdapt->getMeshNameOut().c_str()); } void MG_ADAPT_i::setMeshOutMed(bool mybool) { - myMgAdapt->setMeshOutMed(mybool); + myMgAdapt->setMeshOutMed(mybool); } bool MG_ADAPT_i::getMeshOutMed() { - return myMgAdapt->getMeshOutMed(); + return myMgAdapt->getMeshOutMed(); } void MG_ADAPT_i::setPublish(bool mybool) { - myMgAdapt->setPublish(mybool); + myMgAdapt->setPublish(mybool); } bool MG_ADAPT_i::getPublish() { - return myMgAdapt->getPublish(); + return myMgAdapt->getPublish(); } void MG_ADAPT_i::setSizeMapFieldName(const char* str) { - myMgAdapt->setFieldName(str); + myMgAdapt->setFieldName(str); } char* MG_ADAPT_i::getSizeMapFieldName() { - return CORBA::string_dup(myMgAdapt->getFieldName().c_str()); + return CORBA::string_dup(myMgAdapt->getFieldName().c_str()); } void MG_ADAPT_i::setTimeStep(CORBA::Long t) { - myMgAdapt->setTimeStep(t); + myMgAdapt->setTimeStep(t); } CORBA::Long MG_ADAPT_i::getTimeStep() { - return myMgAdapt->getTimeStep(); + return myMgAdapt->getTimeStep(); } void MG_ADAPT_i::setTimeStepRank(CORBA::Long t, CORBA::Long r) { - myMgAdapt->setChosenTimeStepRank(); - myMgAdapt->setRankTimeStep(t, r); + myMgAdapt->setChosenTimeStepRank(); + myMgAdapt->setRankTimeStep(t, r); } CORBA::Long MG_ADAPT_i::getRank() { - return myMgAdapt->getRank(); + return myMgAdapt->getRank(); } void MG_ADAPT_i::setTimeStepRankLast() { - myMgAdapt->setTimeStepRankLast(); + myMgAdapt->setTimeStepRankLast(); } void MG_ADAPT_i::setNoTimeStep() { - myMgAdapt->setNoTimeStep(); + myMgAdapt->setNoTimeStep(); } void MG_ADAPT_i::setLogFile(const char* str) { - myMgAdapt->setLogFile(str); + myMgAdapt->setLogFile(str); } char* MG_ADAPT_i::getLogFile() { - return CORBA::string_dup(myMgAdapt->getLogFile().c_str()); + return CORBA::string_dup(myMgAdapt->getLogFile().c_str()); } void MG_ADAPT_i::setVerbosityLevel(CORBA::Long v) { - myMgAdapt->setVerbosityLevel(v); + myMgAdapt->setVerbosityLevel(v); } CORBA::Long MG_ADAPT_i::getVerbosityLevel() { - return myMgAdapt->getVerbosityLevel(); + return myMgAdapt->getVerbosityLevel(); } void MG_ADAPT_i::setRemoveOnSuccess(bool mybool) { - myMgAdapt->setRemoveOnSuccess(mybool); + myMgAdapt->setRemoveOnSuccess(mybool); } bool MG_ADAPT_i::getRemoveOnSuccess() { - myMgAdapt->getRemoveOnSuccess(); + myMgAdapt->getRemoveOnSuccess(); } SMESH::MgAdaptHypothesisData* MG_ADAPT_i::getData() { - SMESH::MgAdaptHypothesisData* result = new SMESH::MgAdaptHypothesisData(); - ::MG_ADAPT::MgAdaptHypothesisData* from = myMgAdapt->getData(); - copyHypothesisDataFromImpl(from, result); - return result; + SMESH::MgAdaptHypothesisData* result = new SMESH::MgAdaptHypothesisData(); + ::MG_ADAPT::MgAdaptHypothesisData* from = myMgAdapt->getData(); + copyHypothesisDataFromImpl(from, result); + return result; } void MG_ADAPT_i::setUseLocalMap(bool mybool) { - myMgAdapt->setUseLocalMap(mybool); + myMgAdapt->setUseLocalMap(mybool); } bool MG_ADAPT_i::getUseLocalMap() { - return myMgAdapt->getUseLocalMap(); + return myMgAdapt->getUseLocalMap(); } void MG_ADAPT_i::setUseBackgroundMap(bool mybool) { - myMgAdapt->setUseBackgroundMap(mybool); + myMgAdapt->setUseBackgroundMap(mybool); } bool MG_ADAPT_i::getUseBackgroundMap() { - return myMgAdapt->getUseBackgroundMap(); + return myMgAdapt->getUseBackgroundMap(); } void MG_ADAPT_i::setUseConstantValue(bool mybool) { - myMgAdapt->setUseConstantValue(mybool); + myMgAdapt->setUseConstantValue(mybool); } bool MG_ADAPT_i::getUseConstantValue() { - return myMgAdapt->getUseConstantValue(); + return myMgAdapt->getUseConstantValue(); } - void MG_ADAPT_i::setConstantSize(double value) { - myMgAdapt->setConstantValue(value); + myMgAdapt->setConstantValue(value); } double MG_ADAPT_i::getConstantSize() { - return myMgAdapt->getConstantValue(); + return myMgAdapt->getConstantValue(); } void MG_ADAPT_i::setSizeMapFile(const char* str) { - myMgAdapt->setSizeMapFile(str); + myMgAdapt->setSizeMapFile(str); } char* MG_ADAPT_i::getSizeMapFile() { - return CORBA::string_dup(myMgAdapt->getSizeMapFile().c_str()); + return CORBA::string_dup(myMgAdapt->getSizeMapFile().c_str()); } void MG_ADAPT_i::setFromMedFile(bool mybool) { - myMgAdapt->setFromMedFile(mybool); + myMgAdapt->setFromMedFile(mybool); } bool MG_ADAPT_i::isFromMedFile() { - return myMgAdapt->isFromMedFile(); + return myMgAdapt->isFromMedFile(); } void MG_ADAPT_i::setKeepWorkingFiles(bool mybool) { - myMgAdapt->setKeepWorkingFiles(mybool); + myMgAdapt->setKeepWorkingFiles(mybool); } bool MG_ADAPT_i::getKeepWorkingFiles() { - return myMgAdapt->getKeepWorkingFiles(); + return myMgAdapt->getKeepWorkingFiles(); } //~void MG_ADAPT_i::setPrCORBA::LongLogInFile(bool); @@ -347,193 +346,193 @@ bool MG_ADAPT_i::getKeepWorkingFiles() void MG_ADAPT_i::setSizeMapType(const char* type) { - setUseLocalMap(false); - setUseBackgroundMap(false); - setUseConstantValue(false); + setUseLocalMap(false); + setUseBackgroundMap(false); + setUseConstantValue(false); - if (!strcmp("Local", type)) - setUseLocalMap(true); - else if (!strcmp("Background", type)) - setUseBackgroundMap(true); - else - setUseConstantValue(true); + if (!strcmp("Local", type)) + setUseLocalMap(true); + else if (!strcmp("Background", type)) + setUseBackgroundMap(true); + else + setUseConstantValue(true); } void MG_ADAPT_i::setWorkingDir(const char* dir) { - myMgAdapt->setWorkingDir(dir); + myMgAdapt->setWorkingDir(dir); } char* MG_ADAPT_i::getWorkingDir() { - return CORBA::string_dup(myMgAdapt->getWorkingDir().c_str()); + return CORBA::string_dup(myMgAdapt->getWorkingDir().c_str()); } bool MG_ADAPT_i::setAll() { - return myMgAdapt->setAll(); + return myMgAdapt->setAll(); } char* MG_ADAPT_i::getCommandToRun() { - return CORBA::string_dup(myMgAdapt->getCommandToRun().c_str()); + return CORBA::string_dup(myMgAdapt->getCommandToRun().c_str()); } //~CORBA::Long MG_ADAPT_i::compute(::CORBA::String_out errStr) //~{ - //~std::string err(""); - //~CORBA::Long ret = myMgAdapt->compute(err); - //~errStr = err.c_str(); - //~return ret; + //~std::string err(""); + //~CORBA::Long ret = myMgAdapt->compute(err); + //~errStr = err.c_str(); + //~return ret; //~} CORBA::Long MG_ADAPT_i::compute() { - errStr = ""; - CORBA::Long ret; - try - { - ret = myMgAdapt->compute(errStr); - } - catch (const std::exception& e) - { - std::cerr<getPublish()) - { - SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen(); - SMESH::DriverMED_ReadStatus theStatus; - smeshGen_i->CreateMeshesFromMED(myMgAdapt->getMedFileOut().c_str(), theStatus); - } - //~errStr = err.c_str(); - return ret; + errStr = ""; + CORBA::Long ret; + try + { + ret = myMgAdapt->compute(errStr); + } + catch (const std::exception& e) + { + std::cerr<getPublish()) + { + SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen(); + SMESH::DriverMED_ReadStatus theStatus; + smeshGen_i->CreateMeshesFromMED(myMgAdapt->getMedFileOut().c_str(), theStatus); + } + //~errStr = err.c_str(); + return ret; } char* MG_ADAPT_i::getErrMsg() { - return CORBA::string_dup(errStr.c_str()); + return CORBA::string_dup(errStr.c_str()); } char* MG_ADAPT_i::getFileName() { - return CORBA::string_dup(myMgAdapt->getFileName().c_str()); + return CORBA::string_dup(myMgAdapt->getFileName().c_str()); } char* MG_ADAPT_i::getExeName() { - return CORBA::string_dup(myMgAdapt->getExeName().c_str()); + return CORBA::string_dup(myMgAdapt->getExeName().c_str()); } void MG_ADAPT_i::copyMgAdaptHypothesisData( const SMESH::MgAdaptHypothesisData& data) { - ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData(); - copyHypothesisDataToImpl(data, baseData); - myMgAdapt->copyMgAdaptHypothesisData(baseData); - delete baseData; + ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData(); + copyHypothesisDataToImpl(data, baseData); + myMgAdapt->copyMgAdaptHypothesisData(baseData); + delete baseData; } //~void MG_ADAPT_i::checkDirPath(char*& str) //~{ - //~myMgAdapt->checkDirPath(str); + //~myMgAdapt->checkDirPath(str); //~} bool MG_ADAPT_i::hasOptionDefined( const char* optionName ) { - return myMgAdapt->hasOptionDefined(optionName); + return myMgAdapt->hasOptionDefined(optionName); } void MG_ADAPT_i::setOptionValue(const char* optionName, - const char* optionValue) throw (std::invalid_argument) + const char* optionValue) throw (std::invalid_argument) { - myMgAdapt->setOptionValue(optionName, optionValue); + myMgAdapt->setOptionValue(optionName, optionValue); } char* MG_ADAPT_i::getOptionValue(const char* optionName, - bool& isDefault) throw (std::invalid_argument) + bool& isDefault) throw (std::invalid_argument) { - return CORBA::string_dup(myMgAdapt->getOptionValue(optionName, &isDefault).c_str()); + return CORBA::string_dup(myMgAdapt->getOptionValue(optionName, &isDefault).c_str()); } str_array* MG_ADAPT_i::getCustomOptionValuesStrVec() { - SMESH::str_array_var result = new SMESH::str_array(); - std::vector vals = myMgAdapt->getCustomOptionValuesStrVec(); - result->length(vals.size()); - for (int i = 0; i vals = myMgAdapt->getCustomOptionValuesStrVec(); + result->length(vals.size()); + for (int i = 0; i vals = myMgAdapt->getOptionValuesStrVec(); - result->length(vals.size()); - for (int i = 0; i vals = myMgAdapt->getOptionValuesStrVec(); + result->length(vals.size()); + for (int i = 0; isetPrintLogInFile(mybool); + myMgAdapt->setPrintLogInFile(mybool); } bool MG_ADAPT_i::getPrintLogInFile() { - return myMgAdapt->getPrintLogInFile(); + return myMgAdapt->getPrintLogInFile(); } //~TOptionValues MG_ADAPT_i::getOptionValues() const; //~const TOptionValues& MG_ADAPT_i::getCustomOptionValues() const ; MG_ADAPT_OBJECT_i::MG_ADAPT_OBJECT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() ) { - medFileIn=""; - medFileOut=""; - medFileBackground=""; - publish = false; - //~myMesh = CORBA::nil; + medFileIn=""; + medFileOut=""; + medFileBackground=""; + publish = false; + //~myMesh = CORBA::nil; } void MG_ADAPT_OBJECT_i::setMeshIn(SMESH::SMESH_Mesh_ptr theMesh ) { - myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh); + myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh); } void MG_ADAPT_OBJECT_i::setMEDFileIn(const char* f) { - medFileIn = f; + medFileIn = f; } void MG_ADAPT_OBJECT_i::setMEDFileOut(const char* f) { - medFileOut = f; + medFileOut = f; } void MG_ADAPT_OBJECT_i::setMEDFileBackground(const char* f) { - medFileBackground = f; + medFileBackground = f; } void MG_ADAPT_OBJECT_i::AddHypothesis(SMESH::MG_ADAPT_ptr mg) { - mg->setMedFileIn(medFileIn.c_str()); - mg->setMedFileOut(medFileOut.c_str()); - mg->setSizeMapFile(medFileBackground.c_str()); - hypothesis = SMESH::MG_ADAPT::_duplicate(mg); + mg->setMedFileIn(medFileIn.c_str()); + mg->setMedFileOut(medFileOut.c_str()); + mg->setSizeMapFile(medFileBackground.c_str()); + hypothesis = SMESH::MG_ADAPT::_duplicate(mg); } CORBA::Long MG_ADAPT_OBJECT_i::Compute(bool publish) { - if(!checkMeshFileIn()){ - std::cerr<< "\n Error : Please check the MED file input or mesh input. \n"; - return -1; - } - hypothesis->setPublish(publish); - return hypothesis->compute(); + if(!checkMeshFileIn()){ + std::cerr<< "\n Error : Please check the MED file input or mesh input. \n"; + return -1; + } + hypothesis->setPublish(publish); + return hypothesis->compute(); } bool MG_ADAPT_OBJECT_i::checkMeshFileIn() { - bool ret = false; // 1 ok , 0 nook - if(!::MG_ADAPT::MgAdapt::isFileExist(medFileIn)) + bool ret = false; // 1 ok , 0 nook + if(!::MG_ADAPT::MgAdapt::isFileExist(medFileIn)) + { + if(!myMesh->_is_nil()) { - if(!myMesh->_is_nil()) - { - bool toOverwrite = true; - bool toFindOutDim = true; - medFileIn = hypothesis->getFileName(); - medFileIn+= ".med"; - myMesh->ExportMED(medFileIn.c_str(), false, -1, toOverwrite, toFindOutDim); - hypothesis->setMedFileIn(medFileIn.c_str()); - ret = true; - } - } - else - ret = true; + bool toOverwrite = true; + bool toFindOutDim = true; + medFileIn = hypothesis->getFileName(); + medFileIn+= ".med"; + myMesh->ExportMED(medFileIn.c_str(), false, -1, toOverwrite, toFindOutDim); + hypothesis->setMedFileIn(medFileIn.c_str()); + ret = true; + } + } + else + ret = true; - return ret; + return ret; } diff --git a/src/SMESH_I/MG_ADAPT_i.hxx b/src/SMESH_I/MG_ADAPT_i.hxx index daedce449..b25953175 100644 --- a/src/SMESH_I/MG_ADAPT_i.hxx +++ b/src/SMESH_I/MG_ADAPT_i.hxx @@ -28,129 +28,129 @@ class SMESH_I_EXPORT MG_ADAPT_i : public virtual POA_SMESH::MG_ADAPT { public: - //~MG_ADAPT_i( CORBA::ORB_ptr orb, ADAPT::ADAPT_Gen_var gen_i ); - //~static SMESH::MG_ADAPT_ptr CreateMG_ADAPT(); - //~MG_ADAPT_i(PortableServer::POA_var poa); - MG_ADAPT_i(); - virtual ~MG_ADAPT_i(); - //~void setData( SMESH::MgAdaptHypothesisData* data); - void setData( SMESH::MgAdaptHypothesisData& data); - - void setMedFileIn(const char* str); - char* getMedFileIn(); - - void setMedFileOut(const char* str); - char* getMedFileOut(); - - void setMeshName(const char* str); - char* getMeshName(); - - void setMeshNameOut(const char* str); - char* getMeshNameOut(); - - void setMeshOutMed(bool mybool); - bool getMeshOutMed(); - - void setPublish(bool mybool); - bool getPublish(); - - void setSizeMapFieldName(const char* str); - char* getSizeMapFieldName(); - - void setTimeStep(CORBA::Long t); - CORBA::Long getTimeStep() ; - - void setTimeStepRank(CORBA::Long t, CORBA::Long r ); - CORBA::Long getRank(); - - void setTimeStepRankLast(); - void setNoTimeStep(); - - void setLogFile(const char* str); - char* getLogFile(); - - void setVerbosityLevel(CORBA::Long v); - CORBA::Long getVerbosityLevel(); - - void setRemoveOnSuccess(bool mybool); - bool getRemoveOnSuccess(); - - SMESH::MgAdaptHypothesisData* getData() ; - void setSizeMapType(const char* type); - void setUseLocalMap(bool mybool); - bool getUseLocalMap(); - - void setUseBackgroundMap(bool mybool); - bool getUseBackgroundMap(); - - void setUseConstantValue(bool mybool); - bool getUseConstantValue(); - - void setConstantSize(double value); - double getConstantSize(); - - void setSizeMapFile(const char* str); - char* getSizeMapFile(); - - void setFromMedFile(bool mybool); - bool isFromMedFile(); - - void setKeepWorkingFiles(bool mybool); - bool getKeepWorkingFiles(); - - //~void setPrCORBA::LongLogInFile(bool); - //~bool getPrCORBA::LongLogInFile(); - - void setWorkingDir(const char* str); - char* getWorkingDir() ; - - void setPrintLogInFile(bool mybool); - bool getPrintLogInFile(); - - bool setAll(); - char* getCommandToRun() ; - //~CORBA::Long compute(::CORBA::String_out errStr); - CORBA::Long compute(); - char* getFileName(); - char* getExeName(); - void copyMgAdaptHypothesisData( const SMESH::MgAdaptHypothesisData& data ) ; - //~void copyMgAdaptHypothesisData( const SMESH::MgAdaptHypothesisData& data ) { - //~copyMgAdaptHypothesisData(&data); - //~} - - //~void checkDirPath(char*& str); - - bool hasOptionDefined( const char* optionName ) ; - void setOptionValue(const char* optionName, - const char* optionValue) throw (std::invalid_argument); - char* getOptionValue(const char* optionName, - bool& isDefault) throw (std::invalid_argument); - str_array* getCustomOptionValuesStrVec() ; - str_array* getOptionValuesStrVec() ; - void copyHypothesisDataFromImpl(const ::MG_ADAPT::MgAdaptHypothesisData* from, SMESH::MgAdaptHypothesisData* to) const; - void copyHypothesisDataToImpl(const SMESH::MgAdaptHypothesisData& from, ::MG_ADAPT::MgAdaptHypothesisData* to) const; - //~TOptionValues getOptionValues() const; - //~const TOptionValues& getCustomOptionValues() const ; - char* getErrMsg(); + //~MG_ADAPT_i( CORBA::ORB_ptr orb, ADAPT::ADAPT_Gen_var gen_i ); + //~static SMESH::MG_ADAPT_ptr CreateMG_ADAPT(); + //~MG_ADAPT_i(PortableServer::POA_var poa); + MG_ADAPT_i(); + virtual ~MG_ADAPT_i(); + //~void setData( SMESH::MgAdaptHypothesisData* data); + void setData( SMESH::MgAdaptHypothesisData& data); + + void setMedFileIn(const char* str); + char* getMedFileIn(); + + void setMedFileOut(const char* str); + char* getMedFileOut(); + + void setMeshName(const char* str); + char* getMeshName(); + + void setMeshNameOut(const char* str); + char* getMeshNameOut(); + + void setMeshOutMed(bool mybool); + bool getMeshOutMed(); + + void setPublish(bool mybool); + bool getPublish(); + + void setSizeMapFieldName(const char* str); + char* getSizeMapFieldName(); + + void setTimeStep(CORBA::Long t); + CORBA::Long getTimeStep() ; + + void setTimeStepRank(CORBA::Long t, CORBA::Long r ); + CORBA::Long getRank(); + + void setTimeStepRankLast(); + void setNoTimeStep(); + + void setLogFile(const char* str); + char* getLogFile(); + + void setVerbosityLevel(CORBA::Long v); + CORBA::Long getVerbosityLevel(); + + void setRemoveOnSuccess(bool mybool); + bool getRemoveOnSuccess(); + + SMESH::MgAdaptHypothesisData* getData() ; + void setSizeMapType(const char* type); + void setUseLocalMap(bool mybool); + bool getUseLocalMap(); + + void setUseBackgroundMap(bool mybool); + bool getUseBackgroundMap(); + + void setUseConstantValue(bool mybool); + bool getUseConstantValue(); + + void setConstantSize(double value); + double getConstantSize(); + + void setSizeMapFile(const char* str); + char* getSizeMapFile(); + + void setFromMedFile(bool mybool); + bool isFromMedFile(); + + void setKeepWorkingFiles(bool mybool); + bool getKeepWorkingFiles(); + + //~void setPrCORBA::LongLogInFile(bool); + //~bool getPrCORBA::LongLogInFile(); + + void setWorkingDir(const char* str); + char* getWorkingDir() ; + + void setPrintLogInFile(bool mybool); + bool getPrintLogInFile(); + + bool setAll(); + char* getCommandToRun() ; + //~CORBA::Long compute(::CORBA::String_out errStr); + CORBA::Long compute(); + char* getFileName(); + char* getExeName(); + void copyMgAdaptHypothesisData( const SMESH::MgAdaptHypothesisData& data ) ; + //~void copyMgAdaptHypothesisData( const SMESH::MgAdaptHypothesisData& data ) { + //~copyMgAdaptHypothesisData(&data); + //~} + + //~void checkDirPath(char*& str); + + bool hasOptionDefined( const char* optionName ) ; + void setOptionValue(const char* optionName, + const char* optionValue) throw (std::invalid_argument); + char* getOptionValue(const char* optionName, + bool& isDefault) throw (std::invalid_argument); + str_array* getCustomOptionValuesStrVec() ; + str_array* getOptionValuesStrVec() ; + void copyHypothesisDataFromImpl(const ::MG_ADAPT::MgAdaptHypothesisData* from, SMESH::MgAdaptHypothesisData* to) const; + void copyHypothesisDataToImpl(const SMESH::MgAdaptHypothesisData& from, ::MG_ADAPT::MgAdaptHypothesisData* to) const; + //~TOptionValues getOptionValues() const; + //~const TOptionValues& getCustomOptionValues() const ; + char* getErrMsg(); private: ::MG_ADAPT::MgAdapt* myMgAdapt; std::string errStr; //~CORBA::ORB_ptr _orb; //~ADAPT::ADAPT_Gen_var _gen_i; - + }; class SMESH_I_EXPORT MG_ADAPT_OBJECT_i: - public virtual SALOME::GenericObj_i, - public virtual POA_SMESH::MG_ADAPT_OBJECT { + public virtual SALOME::GenericObj_i, + public virtual POA_SMESH::MG_ADAPT_OBJECT { public : - MG_ADAPT_OBJECT_i(); - void setMeshIn( SMESH::SMESH_Mesh_ptr theMesh ); - void setMEDFileIn(const char* f); - void setMEDFileOut(const char* f); - void setMEDFileBackground(const char* f); - void AddHypothesis(SMESH::MG_ADAPT_ptr); - CORBA::Long Compute(bool Publish); + MG_ADAPT_OBJECT_i(); + void setMeshIn( SMESH::SMESH_Mesh_ptr theMesh ); + void setMEDFileIn(const char* f); + void setMEDFileOut(const char* f); + void setMEDFileBackground(const char* f); + void AddHypothesis(SMESH::MG_ADAPT_ptr); + CORBA::Long Compute(bool Publish); private: std::string medFileIn, medFileOut, medFileBackground; bool checkMeshFileIn();