(#605) Fixed delete of well path to avoid reuse of old data

This commit is contained in:
Magne Sjaastad
2015-10-29 13:12:55 +01:00
parent f004752aea
commit 1156da7f03
9 changed files with 202 additions and 19 deletions

View File

@@ -5,12 +5,14 @@ if (${CMAKE_VERSION} VERSION_GREATER "2.8.2")
endif()
set (SOURCE_GROUP_HEADER_FILES
${CEE_CURRENT_LIST_DIR}RicWellPathDeleteFeature.h
${CEE_CURRENT_LIST_DIR}RicWellPathsDeleteAllFeature.h
${CEE_CURRENT_LIST_DIR}RicWellPathsImportFileFeature.h
${CEE_CURRENT_LIST_DIR}RicWellPathsImportSsihubFeature.h
)
set (SOURCE_GROUP_SOURCE_FILES
${CEE_CURRENT_LIST_DIR}RicWellPathDeleteFeature.cpp
${CEE_CURRENT_LIST_DIR}RicWellPathsDeleteAllFeature.cpp
${CEE_CURRENT_LIST_DIR}RicWellPathsImportFileFeature.cpp
${CEE_CURRENT_LIST_DIR}RicWellPathsImportSsihubFeature.cpp

View File

@@ -0,0 +1,81 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicWellPathDeleteFeature.h"
#include "RimWellPathCollection.h"
#include "cafSelectionManager.h"
#include <QAction>
#include "RimWellPath.h"
namespace caf
{
CAF_CMD_SOURCE_INIT(RicWellPathDeleteFeature, "RicWellPathDeleteFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicWellPathDeleteFeature::isCommandEnabled()
{
std::vector<RimWellPath*> objects;
caf::SelectionManager::instance()->objectsByType(&objects);
if (objects.size() == 1)
{
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicWellPathDeleteFeature::onActionTriggered(bool isChecked)
{
std::vector<RimWellPath*> objects;
caf::SelectionManager::instance()->objectsByType(&objects);
if (objects.size() == 0) return;
RimWellPath* wellPath = objects[0];
RimWellPathCollection* wellPathCollection = NULL;
wellPath->firstAnchestorOrThisOfType(wellPathCollection);
wellPathCollection->removeWellPath(wellPath);;
delete wellPath;
wellPathCollection->uiCapability()->updateConnectedEditors();
wellPathCollection->scheduleGeometryRegenAndRedrawViews();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicWellPathDeleteFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setText("Delete Well Path");
}
} // end namespace caf

View File

@@ -0,0 +1,43 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
namespace caf
{
//==================================================================================================
///
//==================================================================================================
class RicWellPathDeleteFeature : public CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
virtual bool isCommandEnabled();
virtual void onActionTriggered( bool isChecked );
virtual void setupActionLook( QAction* actionToSetup );
};
} // end namespace caf

View File

@@ -57,7 +57,7 @@ void RicWellPathsDeleteAllFeature::onActionTriggered(bool isChecked)
RimWellPathCollection* wellPathCollection = objects[0];
wellPathCollection->wellPaths.deleteAllChildObjects();
wellPathCollection->deleteAllWellPaths();
wellPathCollection->uiCapability()->updateConnectedEditors();
wellPathCollection->scheduleGeometryRegenAndRedrawViews();

View File

@@ -21,8 +21,8 @@ TEST(RimWellPathAsciiFileReaderTest, TestWellNameNoColon)
out << "1 2 3";
}
RimWellPathAsciiFileReader reader;
RimWellPathAsciiFileReader::WellData wpData = reader.readWellData(file.fileName(), 0);
RifWellPathAsciiFileReader reader;
RifWellPathAsciiFileReader::WellData wpData = reader.readWellData(file.fileName(), 0);
EXPECT_TRUE(wpData.m_name == wellName);
}
}
@@ -42,8 +42,8 @@ TEST(RimWellPathAsciiFileReaderTest, TestWellNameWithColon)
out << "1 2 3";
}
RimWellPathAsciiFileReader reader;
RimWellPathAsciiFileReader::WellData wpData = reader.readWellData(file.fileName(), 0);
RifWellPathAsciiFileReader reader;
RifWellPathAsciiFileReader::WellData wpData = reader.readWellData(file.fileName(), 0);
EXPECT_TRUE(wpData.m_name == wellName);
}
}
@@ -63,8 +63,8 @@ TEST(RimWellPathAsciiFileReaderTest, TestWellNameWithColonAndSpace)
out << "1 2 3";
}
RimWellPathAsciiFileReader reader;
RimWellPathAsciiFileReader::WellData wpData = reader.readWellData(file.fileName(), 0);
RifWellPathAsciiFileReader reader;
RifWellPathAsciiFileReader::WellData wpData = reader.readWellData(file.fileName(), 0);
EXPECT_TRUE(wpData.m_name == wellName);
}
}

View File

@@ -779,7 +779,7 @@ void RimProject::actionsBasedOnSelection(QMenu& contextMenu)
{
commandIds << "RicNewWellLogFileCurveFeature";
commandIds << "RicNewWellLogCurveExtractionFeature";
commandIds << "RicDeleteItemFeature";
commandIds << "RicWellPathDeleteFeature";
}
else if (dynamic_cast<RimCalcScript*>(uiItem))
{

View File

@@ -257,7 +257,7 @@ void RimWellPath::readJsonWellPathFile()
//--------------------------------------------------------------------------------------------------
void RimWellPath::readAsciiWellPathFile()
{
RimWellPathAsciiFileReader::WellData wpData = m_wellPathCollection->asciiFileReader()->readWellData(filepath(), wellPathIndexInFile());
RifWellPathAsciiFileReader::WellData wpData = m_wellPathCollection->asciiFileReader()->readWellData(filepath(), wellPathIndexInFile());
this->name = wpData.m_name;
setWellPathGeometry(wpData.m_wellPathGeometry.p());

View File

@@ -84,7 +84,7 @@ RimWellPathCollection::RimWellPathCollection()
m_wellPathCollectionPartManager = new RivWellPathCollectionPartMgr(this);
m_project = NULL;
m_asciiFileReader = new RimWellPathAsciiFileReader;
m_asciiFileReader = new RifWellPathAsciiFileReader;
}
@@ -349,7 +349,42 @@ RimWellPath* RimWellPathCollection::wellPathByName(const QString& wellPathName)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellPathAsciiFileReader::readAllWellData(QString filePath)
void RimWellPathCollection::deleteAllWellPaths()
{
wellPaths.deleteAllChildObjects();
m_asciiFileReader->clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellPathCollection::removeWellPath(RimWellPath* wellPath)
{
wellPaths.removeChildObject(wellPath);
bool isFilePathUsed = false;
for (size_t i = 0; i < wellPaths.size(); i++)
{
if (wellPaths[i]->filepath == wellPath->filepath)
{
isFilePathUsed = true;
break;
}
}
if (!isFilePathUsed)
{
// One file can have multiple well paths
// If no other well paths are referencing the filepath, remove cached data from the file reader
m_asciiFileReader->removeFilePath(wellPath->filepath);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifWellPathAsciiFileReader::readAllWellData(QString filePath)
{
std::map<QString, std::vector<WellData> >::iterator it = m_fileNameToWellDataGroupMap.find(filePath);
@@ -459,7 +494,7 @@ void RimWellPathAsciiFileReader::readAllWellData(QString filePath)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellPathAsciiFileReader::WellData RimWellPathAsciiFileReader::readWellData(QString filePath, int indexInFile)
RifWellPathAsciiFileReader::WellData RifWellPathAsciiFileReader::readWellData(QString filePath, int indexInFile)
{
this->readAllWellData(filePath);
@@ -473,7 +508,7 @@ RimWellPathAsciiFileReader::WellData RimWellPathAsciiFileReader::readWellData(QS
}
else
{
// Error : The ascii well path file does not contain that many wellpaths
// Error : The ascii well path file does not contain that many well paths
return WellData();
}
}
@@ -481,7 +516,7 @@ RimWellPathAsciiFileReader::WellData RimWellPathAsciiFileReader::readWellData(QS
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t RimWellPathAsciiFileReader::wellDataCount(QString filePath)
size_t RifWellPathAsciiFileReader::wellDataCount(QString filePath)
{
std::map<QString, std::vector<WellData> >::iterator it = m_fileNameToWellDataGroupMap.find(filePath);
@@ -497,3 +532,19 @@ size_t RimWellPathAsciiFileReader::wellDataCount(QString filePath)
return it->second.size();;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifWellPathAsciiFileReader::clear()
{
m_fileNameToWellDataGroupMap.clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifWellPathAsciiFileReader::removeFilePath(const QString& filePath)
{
m_fileNameToWellDataGroupMap.erase(filePath);
}

View File

@@ -34,7 +34,7 @@
#include <QString>
class RivWellPathCollectionPartMgr;
class RimWellPathAsciiFileReader;
class RifWellPathAsciiFileReader;
class RimWellPath;
class RimProject;
class RigWellPath;
@@ -80,7 +80,11 @@ public:
void readWellPathFiles();
void addWellPaths(QStringList filePaths);
RimWellPathAsciiFileReader* asciiFileReader() {return m_asciiFileReader;}
void removeWellPath(RimWellPath* wellPath);
void deleteAllWellPaths();
RifWellPathAsciiFileReader* asciiFileReader() {return m_asciiFileReader;}
RimWellPath* wellPathByName(const QString& wellPathName) const;
void addWellLogs(const QStringList& filePaths);
@@ -99,7 +103,7 @@ private:
caf::PdmPointer<RimProject> m_project;
cvf::ref<RivWellPathCollectionPartMgr> m_wellPathCollectionPartManager;
RimWellPathAsciiFileReader* m_asciiFileReader;
RifWellPathAsciiFileReader* m_asciiFileReader;
};
@@ -107,7 +111,7 @@ private:
///
///
//==================================================================================================
class RimWellPathAsciiFileReader
class RifWellPathAsciiFileReader
{
public:
struct WellData
@@ -119,8 +123,10 @@ public:
WellData readWellData(QString filePath, int indexInFile);
size_t wellDataCount(QString filePath);
private:
void clear();
void removeFilePath(const QString& filePath);
private:
void readAllWellData(QString filePath);
std::map<QString, std::vector<WellData> > m_fileNameToWellDataGroupMap;