#2369 Elm Props: Close selected files

This commit is contained in:
Rebecca Cox
2018-01-12 16:18:54 +01:00
parent 3b46849c79
commit 27901f426c
6 changed files with 94 additions and 8 deletions

View File

@@ -47,6 +47,24 @@ void RifElementPropertyReader::addFile(const std::string& fileName)
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifElementPropertyReader::removeFile(const std::string& fileName)
{
std::map<std::string, RifElementPropertyMetadata> tempMetaData;
for (std::pair<std::string, RifElementPropertyMetadata> metaData : m_fieldsMetaData)
{
if (metaData.second.fileName.toStdString() != fileName)
{
tempMetaData[metaData.first] = metaData.second;
}
}
m_fieldsMetaData.swap(tempMetaData);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -40,6 +40,7 @@ public:
virtual ~RifElementPropertyReader();
void addFile(const std::string& fileName);
void removeFile(const std::string& fileName);
std::map<std::string, std::vector<std::string>> scalarElementFields();

View File

@@ -132,6 +132,17 @@ void RigFemPartResultsCollection::addElementPropertyFiles(const std::vector<QStr
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigFemPartResultsCollection::removeElementPropertyFiles(const std::vector<QString>& filenames)
{
for (const QString filename : filenames)
{
m_elementPropertyReader->removeFile(filename.toStdString());
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -52,7 +52,8 @@ public:
void setActiveFormationNames(RigFormationNames* activeFormationNames);
RigFormationNames* activeFormationNames();
void addElementPropertyFiles(const std::vector<QString>& filename);
void addElementPropertyFiles(const std::vector<QString>& filenames);
void removeElementPropertyFiles(const std::vector<QString>& filenames);
void setCalculationParameters(double cohesion, double frictionAngleRad);
double parameterCohesion() const { return m_cohesion;}

View File

@@ -40,9 +40,11 @@
#include "RimGeoMechResultDefinition.h"
#include "RimGeoMechPropertyFilter.h"
#include "cafPdmUiPushButtonEditor.h"
#include "cafUtils.h"
#include <QFile>
#include <QIcon>
CAF_PDM_SOURCE_INIT(RimGeoMechCase, "ResInsightGeoMechCase");
//--------------------------------------------------------------------------------------------------
@@ -62,8 +64,14 @@ RimGeoMechCase::RimGeoMechCase(void)
CAF_PDM_InitFieldNoDefault(&m_elementPropertyFileNames, "ElementPropertyFileNames", "Element Property Files", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_elementPropertyFileNameUiSelection, "ElementPropertyFileNameSelection", "", "", "", "");
m_elementPropertyFileNameUiSelection.xmlCapability()->disableIO();
CAF_PDM_InitFieldNoDefault(&m_elementPropertyFileNameIndexUiSelection, "ElementPropertyFileNameIndexUiSelection", "", "", "", "");
m_elementPropertyFileNameIndexUiSelection.xmlCapability()->disableIO();
CAF_PDM_InitField(&m_closeElementPropertyFileCommand, "closeElementPropertyFileCommad", false, "", "", "", "");
caf::PdmUiPushButtonEditor::configureEditorForField(&m_closeElementPropertyFileCommand);
CAF_PDM_InitField(&m_reloadElementPropertyFileCommand, "reloadElementPropertyFileCommand", false, "", "", "", "");
caf::PdmUiPushButtonEditor::configureEditorForField(&m_reloadElementPropertyFileCommand);
}
//--------------------------------------------------------------------------------------------------
@@ -422,6 +430,12 @@ void RimGeoMechCase::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c
}
}
}
else if (changedField == &m_closeElementPropertyFileCommand)
{
m_closeElementPropertyFileCommand = false;
closeSelectedElementPropertyFiles();
updateConnectedEditors();
}
}
//--------------------------------------------------------------------------------------------------
@@ -514,6 +528,33 @@ QString RimGeoMechCase::subStringOfDigits(const QString& inputString, int number
return "";
}
struct descendingComparator
{
template<class T>
bool operator()(T const &a, T const &b) const { return a > b; }
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGeoMechCase::closeSelectedElementPropertyFiles()
{
std::sort(m_elementPropertyFileNameIndexUiSelection.v().begin(), m_elementPropertyFileNameIndexUiSelection.v().end(), descendingComparator());
std::vector<QString> filesToClose;
for (size_t idx : m_elementPropertyFileNameIndexUiSelection.v())
{
filesToClose.push_back(m_elementPropertyFileNames.v().at(idx).path());
m_elementPropertyFileNames.v().erase(m_elementPropertyFileNames.v().begin() + idx);
}
m_elementPropertyFileNameIndexUiSelection.v().clear();
if (m_geoMechCaseData.notNull())
{
geoMechData()->femPartResults()->removeElementPropertyFiles(filesToClose);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -529,7 +570,19 @@ void RimGeoMechCase::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering&
caseGroup->add(&m_frictionAngleDeg);
caf::PdmUiGroup* elmPropGroup = uiOrdering.addNewGroup("Element Properties");
elmPropGroup->add(&m_elementPropertyFileNameUiSelection);
elmPropGroup->add(&m_elementPropertyFileNameIndexUiSelection);
elmPropGroup->add(&m_closeElementPropertyFileCommand);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGeoMechCase::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute)
{
if (field == &m_closeElementPropertyFileCommand)
{
dynamic_cast<caf::PdmUiPushButtonEditorAttribute*> (attribute)->m_buttonText = "Close Case(s)";
}
}
//--------------------------------------------------------------------------------------------------
@@ -539,11 +592,11 @@ QList<caf::PdmOptionItemInfo> RimGeoMechCase::calculateValueOptions(const caf::P
{
QList<caf::PdmOptionItemInfo> options;
if (fieldNeedingOptions == &m_elementPropertyFileNameUiSelection)
if (fieldNeedingOptions == &m_elementPropertyFileNameIndexUiSelection)
{
for (const caf::FilePath& fileName : m_elementPropertyFileNames.v())
for (size_t i = 0; i < m_elementPropertyFileNames.v().size(); i++)
{
options.push_back(caf::PdmOptionItemInfo(fileName.path(), fileName.path() , true, QIcon()));
options.push_back(caf::PdmOptionItemInfo(m_elementPropertyFileNames.v().at(i).path(), (int)i, true, QIcon()));
}
}

View File

@@ -81,6 +81,7 @@ private:
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;
virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute) override;
virtual QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) override;
virtual void updateFormationNamesData() override;
@@ -88,13 +89,14 @@ private:
virtual void initAfterRead() override;
static QString subStringOfDigits(const QString& timeStepString, int numberOfDigitsToFind);
void closeSelectedElementPropertyFiles();
private:
cvf::ref<RigGeoMechCaseData> m_geoMechCaseData;
caf::PdmField<QString> m_caseFileName;
caf::PdmField<double> m_cohesion;
caf::PdmField<double> m_frictionAngleDeg;
caf::PdmField<std::vector<caf::FilePath>> m_elementPropertyFileNames;
caf::PdmField<std::vector<QString> > m_elementPropertyFileNameUiSelection;
caf::PdmField<std::vector<int> > m_elementPropertyFileNameIndexUiSelection;
caf::PdmField<bool> m_closeElementPropertyFileCommand;
caf::PdmField<bool> m_reloadElementPropertyFileCommand;
};