(#657) Improved 3D view commands and context menu creation

This commit is contained in:
Magne Sjaastad
2015-11-19 18:57:32 +01:00
parent f3a1f21e87
commit 115e0cb660
6 changed files with 51 additions and 72 deletions

View File

@@ -19,9 +19,12 @@
#include "RicNewWellPathCrossSectionFeature.h" #include "RicNewWellPathCrossSectionFeature.h"
#include "RiaApplication.h"
#include "RimCrossSection.h" #include "RimCrossSection.h"
#include "RimCrossSectionCollection.h" #include "RimCrossSectionCollection.h"
#include "RimWellPath.h" #include "RimWellPath.h"
#include "RimView.h"
#include "cafCmdExecCommandManager.h" #include "cafCmdExecCommandManager.h"
#include "cafSelectionManager.h" #include "cafSelectionManager.h"
@@ -36,7 +39,6 @@ CAF_CMD_SOURCE_INIT(RicNewWellPathCrossSectionFeature, "RicNewWellPathCrossSecti
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RicNewWellPathCrossSectionFeature::RicNewWellPathCrossSectionFeature() RicNewWellPathCrossSectionFeature::RicNewWellPathCrossSectionFeature()
: m_view(NULL)
{ {
} }
@@ -54,7 +56,8 @@ bool RicNewWellPathCrossSectionFeature::isCommandEnabled()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicNewWellPathCrossSectionFeature::onActionTriggered(bool isChecked) void RicNewWellPathCrossSectionFeature::onActionTriggered(bool isChecked)
{ {
if (!m_view) return; RimView* activeView = RiaApplication::instance()->activeReservoirView();
if (!activeView) return;
std::vector<RimWellPath*> collection; std::vector<RimWellPath*> collection;
caf::SelectionManager::instance()->objectsByType(&collection); caf::SelectionManager::instance()->objectsByType(&collection);
@@ -62,7 +65,7 @@ void RicNewWellPathCrossSectionFeature::onActionTriggered(bool isChecked)
RimWellPath* wellPath = collection[0]; RimWellPath* wellPath = collection[0];
RicNewWellPathCrossSectionFeatureCmd* cmd = new RicNewWellPathCrossSectionFeatureCmd(m_view->crossSectionCollection, wellPath); RicNewWellPathCrossSectionFeatureCmd* cmd = new RicNewWellPathCrossSectionFeatureCmd(activeView->crossSectionCollection, wellPath);
caf::CmdExecCommandManager::instance()->processExecuteCommand(cmd); caf::CmdExecCommandManager::instance()->processExecuteCommand(cmd);
} }
@@ -75,14 +78,6 @@ void RicNewWellPathCrossSectionFeature::setupActionLook(QAction* actionToSetup)
actionToSetup->setText("New Cross Section"); actionToSetup->setText("New Cross Section");
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewWellPathCrossSectionFeature::setView(RimView* view)
{
m_view = view;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@@ -19,8 +19,6 @@
#pragma once #pragma once
#include "RimView.h"
#include "cafCmdFeature.h" #include "cafCmdFeature.h"
#include "cafCmdExecuteCommand.h" #include "cafCmdExecuteCommand.h"
#include "cafPdmPointer.h" #include "cafPdmPointer.h"
@@ -59,16 +57,11 @@ class RicNewWellPathCrossSectionFeature : public caf::CmdFeature
public: public:
RicNewWellPathCrossSectionFeature(); RicNewWellPathCrossSectionFeature();
void setView(RimView* view);
protected: protected:
// Overrides // Overrides
virtual bool isCommandEnabled(); virtual bool isCommandEnabled();
virtual void onActionTriggered( bool isChecked ); virtual void onActionTriggered( bool isChecked );
virtual void setupActionLook( QAction* actionToSetup ); virtual void setupActionLook( QAction* actionToSetup );
private:
caf::PdmPointer<RimView> m_view;
}; };

View File

@@ -57,8 +57,13 @@
#include "cafSelectionManager.h" #include "cafSelectionManager.h"
#include "cvfAssert.h" #include "cvfAssert.h"
#include "cafCmdFeatureManager.h"
#include "cafCmdFeature.h"
#include <vector> #include <vector>
#include <QMenu>
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -207,6 +212,7 @@ QStringList RimContextCommandBuilder::commandsFromSelection()
{ {
commandIds << "RicNewWellLogFileCurveFeature"; commandIds << "RicNewWellLogFileCurveFeature";
commandIds << "RicNewWellLogCurveExtractionFeature"; commandIds << "RicNewWellLogCurveExtractionFeature";
commandIds << "RicNewWellPathCrossSectionFeature";
commandIds << "RicWellPathDeleteFeature"; commandIds << "RicWellPathDeleteFeature";
} }
else if (dynamic_cast<RimCalcScript*>(uiItem)) else if (dynamic_cast<RimCalcScript*>(uiItem))
@@ -291,3 +297,27 @@ QStringList RimContextCommandBuilder::commandsFromSelection()
return commandIds; return commandIds;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimContextCommandBuilder::appendCommandsToMenu(const QStringList& commandIds, QMenu* menu)
{
CVF_ASSERT(menu);
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
for (int i = 0; i < commandIds.size(); i++)
{
caf::CmdFeature* feature = commandManager->getCommandFeature(commandIds[i].toStdString());
CVF_ASSERT(feature);
if (feature->canFeatureBeExecuted())
{
QAction* act = commandManager->action(commandIds[i]);
CVF_ASSERT(act);
menu->addAction(act);
}
}
}

View File

@@ -21,6 +21,8 @@
#include <QStringList> #include <QStringList>
class QMenu;
//================================================================================================== //==================================================================================================
/// ///
/// ///
@@ -28,5 +30,6 @@
class RimContextCommandBuilder class RimContextCommandBuilder
{ {
public: public:
static QStringList commandsFromSelection(); static QStringList commandsFromSelection();
static void appendCommandsToMenu(const QStringList& commandIds, QMenu* menu);
}; };

View File

@@ -55,8 +55,7 @@ public:
void appendPartsToModel(cvf::ModelBasicList* model, cvf::Transform* scaleTransform); void appendPartsToModel(cvf::ModelBasicList* model, cvf::Transform* scaleTransform);
protected: protected:
//virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue); virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
//virtual void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName);
virtual caf::PdmFieldHandle* objectToggleField(); virtual caf::PdmFieldHandle* objectToggleField();
private: private:

View File

@@ -36,6 +36,7 @@
#include "RimCellRangeFilter.h" #include "RimCellRangeFilter.h"
#include "RimCellRangeFilterCollection.h" #include "RimCellRangeFilterCollection.h"
#include "RimContextCommandBuilder.h"
#include "RimEclipseCase.h" #include "RimEclipseCase.h"
#include "RimEclipseCellColors.h" #include "RimEclipseCellColors.h"
#include "RimEclipsePropertyFilter.h" #include "RimEclipsePropertyFilter.h"
@@ -136,7 +137,6 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event)
if (m_viewer->rayPick(winPosX, winPosY, &hitItems)) if (m_viewer->rayPick(winPosX, winPosY, &hitItems))
{ {
extractIntersectionData(hitItems, &localIntersectionPoint, &firstHitPart, &faceIndex, &nncFirstHitPart, NULL); extractIntersectionData(hitItems, &localIntersectionPoint, &firstHitPart, &faceIndex, &nncFirstHitPart, NULL);
updateSelectionFromPickedPart(firstHitPart);
} }
if (firstHitPart && faceIndex != cvf::UNDEFINED_UINT) if (firstHitPart && faceIndex != cvf::UNDEFINED_UINT)
@@ -222,6 +222,8 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event)
} }
} }
QStringList commandIds;
// Well log curve creation commands // Well log curve creation commands
if (firstHitPart && firstHitPart->sourceInfo()) if (firstHitPart && firstHitPart->sourceInfo())
{ {
@@ -233,26 +235,11 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event)
RimWellPath* wellPath = wellPathSourceInfo->wellPath(); RimWellPath* wellPath = wellPathSourceInfo->wellPath();
if (wellPath) if (wellPath)
{ {
caf::SelectionManager::instance()->setSelectedItem(wellPath);
RicNewWellLogFileCurveFeature* newWellLogFileCurveFeature = dynamic_cast<RicNewWellLogFileCurveFeature*>(commandManager->getCommandFeature("RicNewWellLogFileCurveFeature")); commandIds << "RicNewWellLogFileCurveFeature";
if (newWellLogFileCurveFeature && newWellLogFileCurveFeature->canFeatureBeExecuted()) commandIds << "RicNewWellLogCurveExtractionFeature";
{ commandIds << "RicNewWellPathCrossSectionFeature";
menu.addAction(newWellLogFileCurveFeature->action());
}
RicNewWellLogCurveExtractionFeature* newExtractionCurveFeature = dynamic_cast<RicNewWellLogCurveExtractionFeature*>(commandManager->getCommandFeature("RicNewWellLogCurveExtractionFeature"));
if (newExtractionCurveFeature && newExtractionCurveFeature->canFeatureBeExecuted())
{
menu.addAction(newExtractionCurveFeature->action());
}
RicNewWellPathCrossSectionFeature* newWellPathCrossSectionFeature = dynamic_cast<RicNewWellPathCrossSectionFeature*>(commandManager->getCommandFeature("RicNewWellPathCrossSectionFeature"));
if (newWellPathCrossSectionFeature)
{
newWellPathCrossSectionFeature->setView(m_reservoirView);
menu.addAction(newWellPathCrossSectionFeature->action());
}
} }
} }
@@ -264,11 +251,7 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event)
{ {
caf::SelectionManager::instance()->setSelectedItem(well); caf::SelectionManager::instance()->setSelectedItem(well);
RicNewSimWellCrossSectionFeature* newSimWellCrossSectionFeature = dynamic_cast<RicNewSimWellCrossSectionFeature*>(commandManager->getCommandFeature("RicNewSimWellCrossSectionFeature")); commandIds << "RicNewSimWellCrossSectionFeature";
if (newSimWellCrossSectionFeature && newSimWellCrossSectionFeature->canFeatureBeExecuted())
{
menu.addAction(newSimWellCrossSectionFeature->action());
}
} }
} }
} }
@@ -276,38 +259,14 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event)
// View Link commands // View Link commands
if (!firstHitPart) if (!firstHitPart)
{ {
QStringList commandIds;
commandIds << "RicLinkViewFeature"; commandIds << "RicLinkViewFeature";
commandIds << "RicUnLinkViewFeature"; commandIds << "RicUnLinkViewFeature";
commandIds << "RicShowLinkOptionsFeature"; commandIds << "RicShowLinkOptionsFeature";
commandIds << "RicSetMasterViewFeature"; commandIds << "RicSetMasterViewFeature";
bool firstLinkAction = true;
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
for (int i = 0; i < commandIds.size(); i++)
{
caf::CmdFeature* feature = commandManager->getCommandFeature(commandIds[i].toStdString());
if (feature->canFeatureBeExecuted())
{
QAction* act = commandManager->action(commandIds[i]);
CVF_ASSERT(act);
if (firstLinkAction)
{
if (menu.actions().size() > 0)
{
menu.addSeparator();
}
firstLinkAction = false;
}
menu.addAction(act);
}
}
} }
RimContextCommandBuilder::appendCommandsToMenu(commandIds, &menu);
if (menu.actions().size() > 0) if (menu.actions().size() > 0)
{ {
menu.exec(event->globalPos()); menu.exec(event->globalPos());