mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
* Qt6: Avoid insertWidget, use addWidget In Qt6, the insertWidget function checks if the index parameter is valid based on current widgets present in the layout. This is error prone, and use addWidget to avoid manual counting of index. * Disable use of Qt keyword foreach * Replace use of QRegExp with QRegularExpression Replace use of QRegExp with QRegularExpression Remove dependency on qt5compat module Simplify an expression based on review * Remove Qt5 ifdefs * Guard access out of bounds seen in debug build * Avoid reuse of string variable * Disconnect all signals from the QOpenGLContext The call stack when this assert happens indicates that there are more signals to be disconnected from the object. Crash is fixed by disconnecting all signals. Assert seen in debug build: ASSERT failure in caf::Viewer: "Called object is not of the correct type (class destructor may have already run)", file C:\Qt\6.6.3\msvc2019_64\include\QtCore/qobjectdefs_impl.h, line 130 * Fix issue related to delete of a linked view Guard null pointer use in view linker. Remove complicated cleanup in destructor in Rim3dVew.
234 lines
8.4 KiB
C++
234 lines
8.4 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2018- Equinor ASA
|
|
//
|
|
// 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 "RimPolylinesFromFileAnnotation.h"
|
|
|
|
#include "RiaLogging.h"
|
|
#include "RiaTextStringTools.h"
|
|
#include "RigPolyLinesData.h"
|
|
|
|
#include "RimAnnotationCollection.h"
|
|
#include "RimAnnotationLineAppearance.h"
|
|
|
|
#include "cafPdmUiFilePathEditor.h"
|
|
|
|
#include <QFile>
|
|
#include <QFileInfo>
|
|
|
|
CAF_PDM_SOURCE_INIT( RimPolylinesFromFileAnnotation, "PolylinesFromFileAnnotation" );
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimPolylinesFromFileAnnotation::RimPolylinesFromFileAnnotation()
|
|
{
|
|
CAF_PDM_InitObject( "PolyLines Annotation", ":/PolylinesFromFile16x16.png" );
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_polyLinesFileName, "PolyLineFilePath", "File" );
|
|
CAF_PDM_InitField( &m_userDescription, "PolyLineDescription", QString( "" ), "Name" );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimPolylinesFromFileAnnotation::~RimPolylinesFromFileAnnotation()
|
|
{
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolylinesFromFileAnnotation::setFileName( const QString& fileName )
|
|
{
|
|
m_polyLinesFileName = fileName;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QString RimPolylinesFromFileAnnotation::fileName() const
|
|
{
|
|
return m_polyLinesFileName().path();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolylinesFromFileAnnotation::readPolyLinesFile( QString* errorMessage )
|
|
{
|
|
QFile dataFile( m_polyLinesFileName().path() );
|
|
|
|
if ( !dataFile.open( QFile::ReadOnly ) )
|
|
{
|
|
if ( errorMessage ) ( *errorMessage ) += "Could not open the File: " + ( m_polyLinesFileName().path() ) + "\n";
|
|
return;
|
|
}
|
|
|
|
m_polyLinesData = new RigPolyLinesData;
|
|
|
|
std::vector<std::vector<cvf::Vec3d>> polylines( 1 );
|
|
|
|
QTextStream stream( &dataFile );
|
|
int lineNumber = 1;
|
|
while ( !stream.atEnd() )
|
|
{
|
|
QString line = stream.readLine();
|
|
QStringList commentLineSegs = line.split( "#" );
|
|
if ( commentLineSegs.empty() ) continue; // Empty line
|
|
|
|
QStringList lineSegs = RiaTextStringTools::splitSkipEmptyParts( commentLineSegs[0], QRegularExpression( "\\s+" ) );
|
|
|
|
if ( lineSegs.empty() ) continue; // No data
|
|
|
|
if ( lineSegs.size() != 3 )
|
|
{
|
|
if ( errorMessage ) ( *errorMessage ) += "Unexpected number of words on line: " + QString::number( lineNumber ) + "\n";
|
|
continue;
|
|
}
|
|
|
|
{
|
|
bool isNumberParsingOk = true;
|
|
bool isOk = true;
|
|
double x = lineSegs[0].toDouble( &isOk );
|
|
isNumberParsingOk &= isOk;
|
|
double y = lineSegs[1].toDouble( &isOk );
|
|
isNumberParsingOk &= isOk;
|
|
double z = lineSegs[2].toDouble( &isOk );
|
|
isNumberParsingOk &= isOk;
|
|
|
|
if ( !isNumberParsingOk )
|
|
{
|
|
if ( errorMessage ) ( *errorMessage ) += "Could not read the point at line: " + QString::number( lineNumber ) + "\n";
|
|
continue;
|
|
}
|
|
|
|
if ( x == 999.0 && y == 999.0 && z == 999.0 ) // New PolyLine
|
|
{
|
|
polylines.push_back( std::vector<cvf::Vec3d>() );
|
|
continue;
|
|
}
|
|
|
|
cvf::Vec3d point( x, y, -z );
|
|
polylines.back().push_back( point );
|
|
}
|
|
|
|
++lineNumber;
|
|
}
|
|
|
|
if ( polylines.back().empty() )
|
|
{
|
|
polylines.pop_back();
|
|
}
|
|
|
|
m_polyLinesData->setPolyLines( polylines );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
cvf::ref<RigPolyLinesData> RimPolylinesFromFileAnnotation::polyLinesData()
|
|
{
|
|
auto ap = appearance();
|
|
m_polyLinesData->setVisibility( m_showLines(), m_showSpheres() );
|
|
m_polyLinesData->setSphereAppearance( ap->sphereRadiusFactor(), ap->sphereColor() );
|
|
m_polyLinesData->setLineAppearance( ap->thickness(), ap->color(), m_closePolyline );
|
|
|
|
return m_polyLinesData;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool RimPolylinesFromFileAnnotation::isEmpty()
|
|
{
|
|
if ( m_polyLinesData.isNull() ) return true;
|
|
|
|
for ( const std::vector<cvf::Vec3d>& line : m_polyLinesData->rawPolyLines() )
|
|
{
|
|
if ( !line.empty() ) return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolylinesFromFileAnnotation::setDescriptionFromFileName()
|
|
{
|
|
QFileInfo fileInfo( m_polyLinesFileName().path() );
|
|
m_userDescription = fileInfo.fileName();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolylinesFromFileAnnotation::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
|
{
|
|
appearance()->setLineFieldsHidden( !m_showLines() );
|
|
appearance()->setSphereFieldsHidden( !m_showSpheres() );
|
|
|
|
uiOrdering.add( &m_polyLinesFileName );
|
|
|
|
auto appearanceGroup = uiOrdering.addNewGroup( "Appearance" );
|
|
appearanceGroup->add( &m_closePolyline );
|
|
appearanceGroup->add( &m_showLines );
|
|
appearanceGroup->add( &m_showSpheres );
|
|
|
|
appearance()->uiOrdering( uiConfigName, *appearanceGroup );
|
|
|
|
uiOrdering.skipRemainingFields( true );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolylinesFromFileAnnotation::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
|
|
{
|
|
if ( changedField == &m_polyLinesFileName )
|
|
{
|
|
QString errorMessage;
|
|
readPolyLinesFile( &errorMessage );
|
|
if ( !errorMessage.isEmpty() )
|
|
{
|
|
QString totalError = "\nError in: " + fileName() + "\n\t" + errorMessage;
|
|
RiaLogging::errorInMessageBox( nullptr, "Import Polylines", totalError );
|
|
}
|
|
}
|
|
else if ( changedField == &m_showLines )
|
|
{
|
|
appearance()->setLineFieldsHidden( !m_showLines() );
|
|
}
|
|
else if ( changedField == &m_showSpheres )
|
|
{
|
|
appearance()->setSphereFieldsHidden( !m_showSpheres() );
|
|
}
|
|
|
|
auto annColl = firstAncestorOrThisOfTypeAsserted<RimAnnotationCollection>();
|
|
|
|
annColl->scheduleRedrawOfRelevantViews();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
caf::PdmFieldHandle* RimPolylinesFromFileAnnotation::userDescriptionField()
|
|
{
|
|
return &m_userDescription;
|
|
}
|