2018-12-07 02:11:03 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2018- Equinor ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2018-12-07 02:11:03 -06:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2018-12-07 02:11:03 -06:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2018-12-07 02:11:03 -06:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "RicNewPolylineTargetFeature.h"
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_CMD_SOURCE_INIT( RicNewPolylineTargetFeature, "RicNewPolylineTargetFeature" );
|
2018-12-07 02:11:03 -06:00
|
|
|
|
2018-12-11 04:50:52 -06:00
|
|
|
#include "RimCase.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "RimGridView.h"
|
2018-12-07 02:11:03 -06:00
|
|
|
#include "RimPolylineTarget.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "RimProject.h"
|
|
|
|
#include "RimUserDefinedPolylinesAnnotation.h"
|
2018-12-07 02:11:03 -06:00
|
|
|
#include "cafSelectionManager.h"
|
|
|
|
#include <QAction>
|
|
|
|
|
2018-12-11 04:50:52 -06:00
|
|
|
#include "cvfBoundingBox.h"
|
|
|
|
|
2018-12-07 02:11:03 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-12-07 02:11:03 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicNewPolylineTargetFeature::isCommandEnabled()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::vector<RimUserDefinedPolylinesAnnotation*> objects;
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::SelectionManager::instance()->objectsByType( &objects );
|
2018-12-07 02:11:03 -06:00
|
|
|
|
|
|
|
if ( !objects.empty() )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::vector<RimPolylineTarget*> objects;
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::SelectionManager::instance()->objectsByType( &objects, caf::SelectionManager::FIRST_LEVEL );
|
2018-12-07 02:11:03 -06:00
|
|
|
|
|
|
|
if ( !objects.empty() )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-12-07 02:11:03 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicNewPolylineTargetFeature::onActionTriggered( bool isChecked )
|
2018-12-07 02:11:03 -06:00
|
|
|
{
|
|
|
|
std::vector<RimPolylineTarget*> selectedTargets;
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::SelectionManager::instance()->objectsByType( &selectedTargets, caf::SelectionManager::FIRST_LEVEL );
|
|
|
|
if ( !selectedTargets.empty() )
|
2018-12-07 02:11:03 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
auto firstTarget = selectedTargets.front();
|
2018-12-07 02:11:03 -06:00
|
|
|
RimUserDefinedPolylinesAnnotation* polylineDef = nullptr;
|
2019-09-06 03:40:57 -05:00
|
|
|
firstTarget->firstAncestorOrThisOfTypeAsserted( polylineDef );
|
|
|
|
|
|
|
|
auto afterBeforePair = polylineDef->findActiveTargetsAroundInsertionPoint( firstTarget );
|
|
|
|
|
2018-12-07 02:11:03 -06:00
|
|
|
cvf::Vec3d newPos = cvf::Vec3d::ZERO;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !afterBeforePair.first && afterBeforePair.second )
|
2018-12-07 02:11:03 -06:00
|
|
|
{
|
|
|
|
newPos = afterBeforePair.second->targetPointXYZ();
|
2018-12-11 04:50:52 -06:00
|
|
|
|
|
|
|
// Small displacement to separate the targets
|
|
|
|
newPos.x() -= 50;
|
|
|
|
newPos.y() -= 50;
|
2019-09-06 03:40:57 -05:00
|
|
|
}
|
|
|
|
else if ( afterBeforePair.first && afterBeforePair.second )
|
2018-12-07 02:11:03 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
newPos = 0.5 * ( afterBeforePair.first->targetPointXYZ() + afterBeforePair.second->targetPointXYZ() );
|
2018-12-07 02:11:03 -06:00
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
else if ( afterBeforePair.first && !afterBeforePair.second )
|
2018-12-07 02:11:03 -06:00
|
|
|
{
|
|
|
|
std::vector<RimPolylineTarget*> activeTargets = polylineDef->activeTargets();
|
2019-09-06 03:40:57 -05:00
|
|
|
size_t targetCount = activeTargets.size();
|
|
|
|
if ( targetCount > 1 )
|
2018-12-07 02:11:03 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
newPos = activeTargets[targetCount - 1]->targetPointXYZ();
|
|
|
|
cvf::Vec3d nextLastToLast = newPos - activeTargets[targetCount - 2]->targetPointXYZ();
|
|
|
|
newPos += 0.5 * nextLastToLast;
|
2018-12-07 02:11:03 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
newPos = afterBeforePair.first->targetPointXYZ() + cvf::Vec3d( 0, 0, 200 );
|
2018-12-07 02:11:03 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* newTarget = new RimPolylineTarget;
|
2020-11-06 03:46:38 -06:00
|
|
|
newTarget->setAsPointTargetXYD( { newPos[0], newPos[1], -newPos[2] } );
|
2018-12-07 02:11:03 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
polylineDef->insertTarget( firstTarget, newTarget );
|
2018-12-07 02:11:03 -06:00
|
|
|
polylineDef->updateConnectedEditors();
|
|
|
|
polylineDef->updateVisualization();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<RimUserDefinedPolylinesAnnotation*> polylineDefs;
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::SelectionManager::instance()->objectsByType( &polylineDefs );
|
|
|
|
if ( !polylineDefs.empty() )
|
2018-12-07 02:11:03 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
auto* polylineDef = polylineDefs[0];
|
|
|
|
std::vector<RimPolylineTarget*> activeTargets = polylineDef->activeTargets();
|
|
|
|
|
2018-12-07 02:11:03 -06:00
|
|
|
size_t targetCount = activeTargets.size();
|
|
|
|
|
|
|
|
if ( targetCount == 0 )
|
|
|
|
{
|
2018-12-11 04:50:52 -06:00
|
|
|
auto defaultPos = cvf::Vec3d::ZERO;
|
|
|
|
|
|
|
|
// Set decent position
|
|
|
|
std::vector<RimGridView*> gridViews;
|
2020-05-12 02:50:38 -05:00
|
|
|
RimProject::current()->allVisibleGridViews( gridViews );
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !gridViews.empty() )
|
2018-12-11 04:50:52 -06:00
|
|
|
{
|
|
|
|
auto minPos = gridViews.front()->ownerCase()->allCellsBoundingBox().min();
|
2019-09-06 03:40:57 -05:00
|
|
|
defaultPos = minPos;
|
2018-12-11 04:50:52 -06:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
polylineDef->appendTarget( defaultPos );
|
2018-12-07 02:11:03 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cvf::Vec3d newPos = cvf::Vec3d::ZERO;
|
|
|
|
|
|
|
|
if ( targetCount > 1 )
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
newPos = activeTargets[targetCount - 1]->targetPointXYZ();
|
|
|
|
cvf::Vec3d nextLastToLast = newPos - activeTargets[targetCount - 2]->targetPointXYZ();
|
|
|
|
newPos += 0.5 * nextLastToLast;
|
2018-12-07 02:11:03 -06:00
|
|
|
}
|
|
|
|
else if ( targetCount > 0 )
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
newPos = activeTargets[targetCount - 1]->targetPointXYZ() + cvf::Vec3d( 0, 0, 200 );
|
2018-12-07 02:11:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
auto* newTarget = new RimPolylineTarget;
|
2020-11-06 03:46:38 -06:00
|
|
|
newTarget->setAsPointTargetXYD( { newPos[0], newPos[1], -newPos[2] } );
|
2019-09-06 03:40:57 -05:00
|
|
|
polylineDef->insertTarget( nullptr, newTarget );
|
2018-12-07 02:11:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
polylineDef->updateConnectedEditors();
|
|
|
|
polylineDef->updateVisualization();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-12-07 02:11:03 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicNewPolylineTargetFeature::setupActionLook( QAction* actionToSetup )
|
2018-12-07 02:11:03 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
actionToSetup->setText( "New Target" );
|
2020-10-20 06:01:46 -05:00
|
|
|
actionToSetup->setIcon( QIcon( ":/Well.svg" ) );
|
2018-12-07 02:11:03 -06:00
|
|
|
}
|