mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 22:50:25 -05:00
#13355 Use validation framework for RimCustomSegmentInterval
This commit is contained in:
1 parent
60081466a7
commit
b8575e6b5e
4 files changed
+63
-39
No files matched your search
@@ -18,8 +18,8 @@
|
||||
|
||||
#include "RimCustomSegmentInterval.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "RimCustomSegmentIntervalCollection.h"
|
||||
|
||||
#include "cafPdmFieldScriptingCapability.h"
|
||||
@@ -78,6 +78,23 @@ void RimCustomSegmentInterval::setEndMD( double endMD )
|
||||
m_endMD = endMD;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<QString, QString> RimCustomSegmentInterval::validate( const QString& configName ) const
|
||||
{
|
||||
// First validate all fields using base implementation
|
||||
auto errors = PdmObject::validate( configName );
|
||||
|
||||
// Validate that end MD is greater than start MD
|
||||
if ( m_endMD <= m_startMD )
|
||||
{
|
||||
errors["EndMd"] = "End MD must be greater than Start MD";
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -49,9 +49,10 @@ public:
|
||||
void setEndMD( double endMD );
|
||||
|
||||
// Validation
|
||||
bool isValidInterval() const;
|
||||
bool overlaps( const RimCustomSegmentInterval* other ) const;
|
||||
bool containsMD( double md ) const;
|
||||
std::map<QString, QString> validate( const QString& configName = "" ) const override;
|
||||
bool isValidInterval() const;
|
||||
bool overlaps( const RimCustomSegmentInterval* other ) const;
|
||||
bool containsMD( double md ) const;
|
||||
|
||||
// Comparison for sorting
|
||||
bool operator<( const RimCustomSegmentInterval& rhs ) const;
|
||||
@@ -67,13 +68,14 @@ public:
|
||||
// Visual feedback for overlapping intervals
|
||||
void updateOverlapVisualFeedback( bool hasOverlap );
|
||||
|
||||
QString generateDisplayLabel() const;
|
||||
|
||||
protected:
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
|
||||
|
||||
private:
|
||||
void updateConnectedEditors();
|
||||
QString generateDisplayLabel() const;
|
||||
void updateConnectedEditors();
|
||||
|
||||
private:
|
||||
caf::PdmField<double> m_startMD;
|
||||
|
||||
+35
-30
@@ -167,45 +167,50 @@ bool RimCustomSegmentIntervalCollection::hasOverlappingIntervals() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<QString> RimCustomSegmentIntervalCollection::validateIntervals() const
|
||||
std::map<QString, QString> RimCustomSegmentIntervalCollection::validate( const QString& configName ) const
|
||||
{
|
||||
std::vector<QString> issues;
|
||||
// First validate all fields using base implementation
|
||||
auto errors = PdmObject::validate( configName );
|
||||
|
||||
if ( isEmpty() )
|
||||
QStringList validationIssues;
|
||||
|
||||
// Validate each child interval
|
||||
for ( const auto* interval : intervals() )
|
||||
{
|
||||
issues.push_back( "No intervals defined" );
|
||||
return issues;
|
||||
}
|
||||
|
||||
auto intervalList = intervals();
|
||||
|
||||
// Check for invalid intervals
|
||||
for ( auto* interval : intervalList )
|
||||
{
|
||||
if ( !interval->isValidInterval() )
|
||||
if ( interval )
|
||||
{
|
||||
issues.push_back(
|
||||
QString( "Invalid interval: MD %.1f-%.1f (Start MD must be less than End MD)" ).arg( interval->startMD() ).arg( interval->endMD() ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Check for overlaps
|
||||
for ( size_t i = 0; i < intervalList.size(); ++i )
|
||||
{
|
||||
for ( size_t j = i + 1; j < intervalList.size(); ++j )
|
||||
{
|
||||
if ( intervalList[i]->overlaps( intervalList[j] ) )
|
||||
// Get validation errors from the interval itself
|
||||
auto intervalErrors = interval->validate( configName );
|
||||
for ( const auto& [field, errorMsg] : intervalErrors )
|
||||
{
|
||||
issues.push_back( QString( "Overlapping intervals: MD %.1f-%.1f and MD %.1f-%.1f" )
|
||||
.arg( intervalList[i]->startMD() )
|
||||
.arg( intervalList[i]->endMD() )
|
||||
.arg( intervalList[j]->startMD() )
|
||||
.arg( intervalList[j]->endMD() ) );
|
||||
validationIssues.append( QString( "Interval (%1): %2." ).arg( interval->generateDisplayLabel() ).arg( errorMsg ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return issues;
|
||||
// Check for overlaps between intervals
|
||||
for ( size_t i = 0; i < intervals().size(); ++i )
|
||||
{
|
||||
for ( size_t j = i + 1; j < intervals().size(); ++j )
|
||||
{
|
||||
RimCustomSegmentInterval* intervalI = intervals()[i];
|
||||
RimCustomSegmentInterval* intervalJ = intervals()[j];
|
||||
if ( intervalI && intervalJ && intervalI->overlaps( intervalJ ) )
|
||||
{
|
||||
validationIssues.append( QString( "Interval (%1) overlaps with another interval (%2)." )
|
||||
.arg( intervalI->generateDisplayLabel() )
|
||||
.arg( intervalJ->generateDisplayLabel() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there are any validation issues, combine them into a single error message
|
||||
if ( !validationIssues.isEmpty() )
|
||||
{
|
||||
errors["Intervals"] = validationIssues.join( "\n" );
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
+3
-3
@@ -54,9 +54,9 @@ public:
|
||||
RimCustomSegmentInterval* findIntervalAtMD( double md ) const;
|
||||
|
||||
// Validation
|
||||
bool hasValidIntervals() const;
|
||||
bool hasOverlappingIntervals() const;
|
||||
std::vector<QString> validateIntervals() const;
|
||||
std::map<QString, QString> validate( const QString& configName = "" ) const override;
|
||||
bool hasValidIntervals() const;
|
||||
bool hasOverlappingIntervals() const;
|
||||
|
||||
// Sorting and organization
|
||||
void sortIntervalsByMD();
|
||||
|
||||
Reference in new issue
Block a user