(#339) Added RicCloseCaseFeature

This commit is contained in:
Pål Hagen 2015-08-18 13:40:57 +02:00
parent 5defe45209
commit 9c4766a262
6 changed files with 188 additions and 70 deletions

View File

@ -5,7 +5,7 @@ if (${CMAKE_VERSION} VERSION_GREATER "2.8.2")
endif()
set (SOURCE_GROUP_HEADER_FILES
${CEE_CURRENT_LIST_DIR}RicEclipseCaseCloseFeature.h
${CEE_CURRENT_LIST_DIR}RicCloseCaseFeature.h
${CEE_CURRENT_LIST_DIR}RicEclipseCaseExecuteScriptFeature.h
${CEE_CURRENT_LIST_DIR}RicEclipseCaseNewGroupFeature.h
${CEE_CURRENT_LIST_DIR}RicEclipseCaseNewGroupExec.h
@ -47,7 +47,7 @@ ${CEE_CURRENT_LIST_DIR}RicDeleteItemFeature.h
)
set (SOURCE_GROUP_SOURCE_FILES
${CEE_CURRENT_LIST_DIR}RicEclipseCaseCloseFeature.cpp
${CEE_CURRENT_LIST_DIR}RicCloseCaseFeature.cpp
${CEE_CURRENT_LIST_DIR}RicEclipseCaseExecuteScriptFeature.cpp
${CEE_CURRENT_LIST_DIR}RicEclipseCaseNewGroupFeature.cpp
${CEE_CURRENT_LIST_DIR}RicEclipseCaseNewGroupExec.cpp

View File

@ -0,0 +1,171 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicCloseCaseFeature.h"
#include "RimEclipseCase.h"
#include "RimGeoMechCase.h"
#include "RimIdenticalGridCaseGroup.h"
#include "RimEclipseCaseCollection.h"
#include "RimCaseCollection.h"
#include "RimProject.h"
#include "RimOilField.h"
#include "RimGeoMechModels.h"
#include "RiaApplication.h"
#include "cafSelectionManager.h"
#include "cafPdmFieldHandle.h"
#include <QAction>
CAF_CMD_SOURCE_INIT(RicCloseCaseFeature, "RicCloseCaseFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicCloseCaseFeature::isCommandEnabled()
{
return selectedEclipseCase() != NULL || selectedGeoMechCase() != NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCloseCaseFeature::onActionTriggered(bool isChecked)
{
RimEclipseCase* eclipseCase = selectedEclipseCase();
RimGeoMechCase* geoMechCase = selectedGeoMechCase();
if (eclipseCase)
{
deleteEclipseCase(eclipseCase);
}
else if (geoMechCase)
{
deleteGeoMechCase(geoMechCase);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCloseCaseFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setText("Close");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEclipseCase* RicCloseCaseFeature::selectedEclipseCase() const
{
std::vector<RimEclipseCase*> selection;
caf::SelectionManager::instance()->objectsByType(&selection);
if (selection.size() > 0)
{
return selection[0];
}
return NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGeoMechCase* RicCloseCaseFeature::selectedGeoMechCase() const
{
std::vector<RimGeoMechCase*> selection;
caf::SelectionManager::instance()->objectsByType(&selection);
if (selection.size() > 0)
{
return selection[0];
}
return NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCloseCaseFeature::removeCaseFromAllGroups(RimEclipseCase* eclipseCase)
{
CVF_ASSERT(eclipseCase);
RimProject* proj = RiaApplication::instance()->project();
RimOilField* activeOilField = proj ? proj->activeOilField() : NULL;
RimEclipseCaseCollection* analysisModels = (activeOilField) ? activeOilField->analysisModels() : NULL;
if (analysisModels)
{
analysisModels->removeCaseFromAllGroups(eclipseCase);
analysisModels->updateConnectedEditors();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCloseCaseFeature::deleteEclipseCase(RimEclipseCase* eclipseCase)
{
CVF_ASSERT(eclipseCase);
RimCaseCollection* caseCollection = eclipseCase->parentCaseCollection();
if (caseCollection)
{
if (RimIdenticalGridCaseGroup::isStatisticsCaseCollection(caseCollection))
{
RimIdenticalGridCaseGroup* caseGroup = caseCollection->parentCaseGroup();
CVF_ASSERT(caseGroup);
caseGroup->statisticsCaseCollection()->reservoirs.removeChildObject(eclipseCase);
caseGroup->updateConnectedEditors();
}
else
{
removeCaseFromAllGroups(eclipseCase);
}
}
else
{
removeCaseFromAllGroups(eclipseCase);
}
delete eclipseCase;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCloseCaseFeature::deleteGeoMechCase(RimGeoMechCase* geoMechCase)
{
CVF_ASSERT(geoMechCase);
RimProject* proj = RiaApplication::instance()->project();
RimOilField* activeOilField = proj ? proj->activeOilField() : NULL;
RimGeoMechModels* models = (activeOilField) ? activeOilField->geoMechModels() : NULL;
if (models)
{
models->cases.removeChildObject(geoMechCase);
models->updateConnectedEditors();
}
delete geoMechCase;
}

View File

@ -21,11 +21,13 @@
#include "cafCmdFeature.h"
class RimEclipseCase;
class RimGeoMechCase;
//==================================================================================================
///
//==================================================================================================
class RicEclipseCaseCloseFeature : public caf::CmdFeature
class RicCloseCaseFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
@ -34,6 +36,14 @@ protected:
virtual bool isCommandEnabled();
virtual void onActionTriggered( bool isChecked );
virtual void setupActionLook( QAction* actionToSetup );
private:
RimEclipseCase* selectedEclipseCase() const;
RimGeoMechCase* selectedGeoMechCase() const;
void removeCaseFromAllGroups(RimEclipseCase* eclipseCase);
void deleteEclipseCase(RimEclipseCase* eclipseCase);
void deleteGeoMechCase(RimGeoMechCase* geoMechCase);
};

View File

@ -1,65 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicEclipseCaseCloseFeature.h"
#include "RimCase.h"
#include "cafSelectionManager.h"
#include <QAction>
CAF_CMD_SOURCE_INIT(RicEclipseCaseCloseFeature, "RicEclipseCaseCloseFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicEclipseCaseCloseFeature::isCommandEnabled()
{
std::vector<RimCase*> selection;
caf::SelectionManager::instance()->objectsByType(&selection);
if (selection.size() > 0)
{
return true;
}
else
{
return false;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicEclipseCaseCloseFeature::onActionTriggered(bool isChecked)
{
// TODO
assert(false);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicEclipseCaseCloseFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setText("Close");
}

View File

@ -575,7 +575,7 @@ void RimProject::actionsBasedOnSelection(QMenu& contextMenu)
commandIds << "RicPasteEclipseCasesFeature";
commandIds << "RicPasteEclipseViewsFeature";
//commandIds << "RicEclipseCaseClose";
commandIds << "RicCloseCaseFeature";
commandIds << "RicNewViewFeature";
commandIds << "RicEclipseCaseNewGroupFeature";
//commandIds << "RicEclipseCaseExecuteScript";
@ -583,8 +583,8 @@ void RimProject::actionsBasedOnSelection(QMenu& contextMenu)
else if (dynamic_cast<RimGeoMechCase*>(uiItem))
{
commandIds << "RicPasteGeoMechViewsFeature";
//commandIds << "RicEclipseCaseClose";
commandIds << "RicNewViewFeature";
commandIds << "RicCloseCaseFeature";
}
else if (dynamic_cast<RimIdenticalGridCaseGroup*>(uiItem))
{

View File

@ -937,6 +937,7 @@ void RimUiTreeView::slotWriteBinaryResultAsInputProperty()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
// OBSOLETE - See RicCloseCaseFeature
void RimUiTreeView::slotCloseCase()
{
QModelIndexList miList;
@ -1546,6 +1547,7 @@ void RimUiTreeView::selectedUiItems(std::vector<caf::PdmUiItem*>& objects)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
// OBSOLETE - See RicCloseCaseFeature
void RimUiTreeView::slotCloseGeomechCase()
{
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());