mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Add copyObject to PdmObjectHandle
New syntax to copy an object auto curveCopy = curve->copyObject<RimSummaryCurve>(); Previous deprecated syntax RimColorLegend* customLegend = dynamic_cast<RimColorLegend*>( standardLegend->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
This commit is contained in:
@@ -103,9 +103,7 @@ void RicEditPreferencesFeature::setupActionLook( QAction* actionToSetup )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::unique_ptr<RiaPreferences> RicEditPreferencesFeature::clonePreferences( const RiaPreferences* preferences )
|
||||
{
|
||||
caf::PdmObjectHandle* pdmClone = preferences->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() );
|
||||
|
||||
return std::unique_ptr<RiaPreferences>( dynamic_cast<RiaPreferences*>( pdmClone ) );
|
||||
return std::unique_ptr<RiaPreferences>( preferences->copyObject<RiaPreferences>() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@@ -49,9 +49,7 @@ void RicCopyStandardLegendFeature::onActionTriggered( bool isChecked )
|
||||
if ( standardLegend )
|
||||
{
|
||||
// perform deep copy of standard legend object via XML
|
||||
RimColorLegend* customLegend = dynamic_cast<RimColorLegend*>(
|
||||
standardLegend->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
auto customLegend = standardLegend->copyObject<RimColorLegend>();
|
||||
customLegend->setColorLegendName( "Copy of " + standardLegend->colorLegendName() );
|
||||
|
||||
RimColorLegendCollection* colorLegendCollection = RimProject::current()->colorLegendCollection;
|
||||
|
@@ -119,8 +119,7 @@ void RicCopyIntersectionsToAllViewsInCaseFeature::copyIntersectionsToOtherViews(
|
||||
{
|
||||
RimIntersectionCollection* destCollection = currGridView->intersectionCollection();
|
||||
|
||||
RimExtrudedCurveIntersection* copy = dynamic_cast<RimExtrudedCurveIntersection*>(
|
||||
intersection->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto copy = intersection->copyObject<RimExtrudedCurveIntersection>();
|
||||
CVF_ASSERT( copy );
|
||||
|
||||
destCollection->appendIntersectionAndUpdate( copy, false );
|
||||
@@ -150,8 +149,7 @@ void RicCopyIntersectionsToAllViewsInCaseFeature::copyIntersectionBoxesToOtherVi
|
||||
{
|
||||
RimIntersectionCollection* destCollection = currGridView->intersectionCollection();
|
||||
|
||||
RimBoxIntersection* copy = dynamic_cast<RimBoxIntersection*>(
|
||||
intersectionBox->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto copy = intersectionBox->copyObject<RimBoxIntersection>();
|
||||
CVF_ASSERT( copy );
|
||||
|
||||
destCollection->appendIntersectionBoxAndUpdate( copy );
|
||||
|
@@ -157,8 +157,7 @@ void RicAdvancedSnapshotExportFeature::exportMultipleSnapshots( const QString& f
|
||||
RimGeoMechView* sourceGeoMechView = dynamic_cast<RimGeoMechView*>( sourceView );
|
||||
if ( geomCase && sourceGeoMechView )
|
||||
{
|
||||
RimGeoMechView* copyOfGeoMechView = dynamic_cast<RimGeoMechView*>(
|
||||
sourceGeoMechView->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto copyOfGeoMechView = sourceGeoMechView->copyObject<RimGeoMechView>();
|
||||
CVF_ASSERT( copyOfGeoMechView );
|
||||
|
||||
geomCase->geoMechViews().push_back( copyOfGeoMechView );
|
||||
|
@@ -63,8 +63,7 @@ void RicAddStoredFlowCharacteristicsPlotFeature::onActionTriggered( bool isCheck
|
||||
RimFlowCharacteristicsPlot* sourceObject =
|
||||
dynamic_cast<RimFlowCharacteristicsPlot*>( caf::SelectionManager::instance()->selectedItem() );
|
||||
|
||||
RimFlowCharacteristicsPlot* flowCharacteristicsPlot =
|
||||
dynamic_cast<RimFlowCharacteristicsPlot*>( sourceObject->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto flowCharacteristicsPlot = sourceObject->copyObject<RimFlowCharacteristicsPlot>();
|
||||
CVF_ASSERT( flowCharacteristicsPlot );
|
||||
|
||||
flowPlotColl->addFlowCharacteristicsPlotToStoredPlots( flowCharacteristicsPlot );
|
||||
|
@@ -62,9 +62,7 @@ void RicAddStoredWellAllocationPlotFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
RimWellAllocationPlot* sourceObject = dynamic_cast<RimWellAllocationPlot*>( caf::SelectionManager::instance()->selectedItem() );
|
||||
|
||||
RimWellAllocationPlot* wellAllocationPlot =
|
||||
dynamic_cast<RimWellAllocationPlot*>( sourceObject->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
auto wellAllocationPlot = sourceObject->copyObject<RimWellAllocationPlot>();
|
||||
CVF_ASSERT( wellAllocationPlot );
|
||||
|
||||
flowPlotColl->addWellAllocPlotToStoredPlots( wellAllocationPlot );
|
||||
|
@@ -54,8 +54,7 @@ void RicCreateDuplicateTemplateInOtherUnitSystemFeature::onActionTriggered( bool
|
||||
RimFractureTemplate* fractureTemplate = caf::firstAncestorOfTypeFromSelectedObject<RimFractureTemplate>();
|
||||
if ( !fractureTemplate ) return;
|
||||
|
||||
auto copyOfTemplate = dynamic_cast<RimFractureTemplate*>(
|
||||
fractureTemplate->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto copyOfTemplate = fractureTemplate->copyObject<RimFractureTemplate>();
|
||||
|
||||
RimFractureTemplateCollection* fractureTemplateCollection = caf::firstAncestorOfTypeFromSelectedObject<RimFractureTemplateCollection>();
|
||||
fractureTemplateCollection->addFractureTemplate( copyOfTemplate );
|
||||
|
@@ -74,9 +74,7 @@ void RicPasteEllipseFractureFeature::onActionTriggered( bool isChecked )
|
||||
|
||||
for ( const auto& source : typedObjects )
|
||||
{
|
||||
auto templ = dynamic_cast<RimEllipseFractureTemplate*>(
|
||||
source->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
auto templ = source->copyObject<RimEllipseFractureTemplate>();
|
||||
fractureTemplateColl->addFractureTemplate( templ );
|
||||
|
||||
RicNewEllipseFractureTemplateFeature::selectFractureTemplateAndUpdate( templ );
|
||||
|
@@ -74,9 +74,7 @@ void RicPasteStimPlanFractureFeature::onActionTriggered( bool isChecked )
|
||||
|
||||
for ( const auto& source : typedObjects )
|
||||
{
|
||||
auto copyOfStimPlanTemplate = dynamic_cast<RimStimPlanFractureTemplate*>(
|
||||
source->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
auto copyOfStimPlanTemplate = source->copyObject<RimStimPlanFractureTemplate>();
|
||||
fractureTemplateColl->addFractureTemplate( copyOfStimPlanTemplate );
|
||||
|
||||
RicNewEllipseFractureTemplateFeature::selectFractureTemplateAndUpdate( copyOfStimPlanTemplate );
|
||||
|
@@ -59,9 +59,7 @@ void RicPasteGridCrossPlotDataSetFeature::onActionTriggered( bool isChecked )
|
||||
|
||||
for ( RimGridCrossPlotDataSet* dataSet : gridCrossPlotDataSetsOnClipboard() )
|
||||
{
|
||||
RimGridCrossPlotDataSet* newDataSet = dynamic_cast<RimGridCrossPlotDataSet*>(
|
||||
dataSet->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
auto newDataSet = dataSet->copyObject<RimGridCrossPlotDataSet>();
|
||||
crossPlot->addDataSet( newDataSet );
|
||||
newDataSet->resolveReferencesRecursively();
|
||||
newDataSet->initAfterReadRecursively();
|
||||
|
@@ -67,9 +67,7 @@ void RicPasteCellFiltersFeature::onActionTriggered( bool isChecked )
|
||||
|
||||
for ( auto obj : objectGroup.objects )
|
||||
{
|
||||
auto duplicatedObject =
|
||||
dynamic_cast<RimCellFilter*>( obj->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
auto duplicatedObject = obj->copyObject<RimCellFilter>();
|
||||
if ( duplicatedObject )
|
||||
{
|
||||
cellFilterCollection->addFilterAndNotifyChanges( duplicatedObject, eclipseCase );
|
||||
|
@@ -86,8 +86,7 @@ void RicPasteEclipseViewsFeature::onActionTriggered( bool isChecked )
|
||||
// Add cases to case group
|
||||
for ( const auto& eclipseView : eclipseViews )
|
||||
{
|
||||
auto* rimReservoirView =
|
||||
dynamic_cast<RimEclipseView*>( eclipseView->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto* rimReservoirView = eclipseView->copyObject<RimEclipseView>();
|
||||
CVF_ASSERT( rimReservoirView );
|
||||
|
||||
QString nameOfCopy = QString( "Copy of " ) + rimReservoirView->name();
|
||||
|
@@ -80,9 +80,8 @@ void RicPasteGeoMechViewsFeature::onActionTriggered( bool isChecked )
|
||||
// Add cases to case group
|
||||
for ( size_t i = 0; i < geomViews.size(); i++ )
|
||||
{
|
||||
RimGeoMechView* rimReservoirView =
|
||||
dynamic_cast<RimGeoMechView*>( geomViews[i]->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
QString nameOfCopy = QString( "Copy of " ) + rimReservoirView->name();
|
||||
auto rimReservoirView = geomViews[i]->copyObject<RimGeoMechView>();
|
||||
QString nameOfCopy = QString( "Copy of " ) + rimReservoirView->name();
|
||||
rimReservoirView->setName( nameOfCopy );
|
||||
geomCase->geoMechViews().push_back( rimReservoirView );
|
||||
|
||||
|
@@ -78,10 +78,8 @@ void RicPasteIntersectionsFeature::onActionTriggered( bool isChecked )
|
||||
|
||||
for ( size_t i = 0; i < intersectionObjects.size(); i++ )
|
||||
{
|
||||
RimExtrudedCurveIntersection* intersection = dynamic_cast<RimExtrudedCurveIntersection*>(
|
||||
intersectionObjects[i]->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
QString nameOfCopy = QString( "Copy of " ) + intersection->name();
|
||||
auto intersection = intersectionObjects[i]->copyObject<RimExtrudedCurveIntersection>();
|
||||
QString nameOfCopy = QString( "Copy of " ) + intersection->name();
|
||||
intersection->setName( nameOfCopy );
|
||||
|
||||
if ( i == intersectionObjects.size() - 1 )
|
||||
@@ -99,10 +97,8 @@ void RicPasteIntersectionsFeature::onActionTriggered( bool isChecked )
|
||||
|
||||
for ( size_t i = 0; i < intersectionBoxObjects.size(); i++ )
|
||||
{
|
||||
RimBoxIntersection* intersectionBox = dynamic_cast<RimBoxIntersection*>(
|
||||
intersectionBoxObjects[i]->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
QString nameOfCopy = QString( "Copy of " ) + intersectionBox->name();
|
||||
RimBoxIntersection* intersectionBox = intersectionBoxObjects[i]->copyObject<RimBoxIntersection>();
|
||||
QString nameOfCopy = QString( "Copy of " ) + intersectionBox->name();
|
||||
intersectionBox->setName( nameOfCopy );
|
||||
|
||||
if ( i == intersectionBoxObjects.size() - 1 )
|
||||
|
@@ -38,8 +38,7 @@ void RicNewSummaryPlotFromCurveFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
RimSummaryCurve* curve = static_cast<RimSummaryCurve*>( userData.value<void*>() );
|
||||
|
||||
auto curveCopy = dynamic_cast<RimSummaryCurve*>( curve->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
auto curveCopy = curve->copyObject<RimSummaryCurve>();
|
||||
curveCopy->setShowInLegend( true );
|
||||
|
||||
RimSummaryPlot* plot = RicSummaryPlotBuilder::createPlot( { curveCopy } );
|
||||
|
@@ -278,8 +278,7 @@ std::vector<RimPlot*> RicSummaryPlotBuilder::duplicatePlots( const std::vector<R
|
||||
|
||||
for ( auto plot : sourcePlots )
|
||||
{
|
||||
auto copy = dynamic_cast<RimPlot*>( plot->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
auto copy = plot->copyObject<RimPlot>();
|
||||
{
|
||||
// TODO: Workaround for fixing the PdmPointer in RimEclipseResultDefinition
|
||||
// caf::PdmPointer<RimEclipseCase> m_eclipseCase;
|
||||
@@ -308,8 +307,7 @@ std::vector<RimSummaryPlot*> RicSummaryPlotBuilder::duplicateSummaryPlots( const
|
||||
|
||||
for ( auto plot : sourcePlots )
|
||||
{
|
||||
auto copy = dynamic_cast<RimSummaryPlot*>( plot->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
auto copy = plot->copyObject<RimSummaryPlot>();
|
||||
if ( copy )
|
||||
{
|
||||
plots.push_back( copy );
|
||||
|
@@ -87,8 +87,7 @@ void RicCreateSummaryCaseCollectionFeature::onActionTriggered( bool isChecked )
|
||||
|
||||
for ( const auto sumCase : selection )
|
||||
{
|
||||
auto copy = dynamic_cast<RimSummaryCase*>( sumCase->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
auto copy = sumCase->copyObject<RimSummaryCase>();
|
||||
duplicates.push_back( copy );
|
||||
}
|
||||
|
||||
|
@@ -210,10 +210,8 @@ RimEclipseContourMapView*
|
||||
RicNewContourMapViewFeature::createEclipseContourMapFromExistingContourMap( RimEclipseCase* eclipseCase,
|
||||
RimEclipseContourMapView* existingContourMap )
|
||||
{
|
||||
RimEclipseContourMapView* contourMap = dynamic_cast<RimEclipseContourMapView*>(
|
||||
existingContourMap->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto contourMap = existingContourMap->copyObject<RimEclipseContourMapView>();
|
||||
CVF_ASSERT( contourMap );
|
||||
|
||||
contourMap->setEclipseCase( eclipseCase );
|
||||
|
||||
auto col = RiuGuiTheme::getColorByVariableName( "backgroundColor2" );
|
||||
@@ -358,10 +356,8 @@ RimGeoMechContourMapView*
|
||||
RicNewContourMapViewFeature::createGeoMechContourMapFromExistingContourMap( RimGeoMechCase* geoMechCase,
|
||||
RimGeoMechContourMapView* existingContourMap )
|
||||
{
|
||||
RimGeoMechContourMapView* contourMap = dynamic_cast<RimGeoMechContourMapView*>(
|
||||
existingContourMap->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto contourMap = existingContourMap->copyObject<RimGeoMechContourMapView>();
|
||||
CVF_ASSERT( contourMap );
|
||||
|
||||
contourMap->setGeoMechCase( geoMechCase );
|
||||
|
||||
auto col = RiuGuiTheme::getColorByVariableName( "backgroundColor2" );
|
||||
|
@@ -63,8 +63,7 @@ void RicDuplicateSummaryTableFeature::copyTableAndAddToCollection( RimSummaryTab
|
||||
RimSummaryTableCollection* summaryTableColl = RimMainPlotCollection::current()->summaryTableCollection();
|
||||
if ( !summaryTableColl ) return;
|
||||
|
||||
RimSummaryTable* newSummaryTable =
|
||||
dynamic_cast<RimSummaryTable*>( sourceTable->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto newSummaryTable = sourceTable->copyObject<RimSummaryTable>();
|
||||
CVF_ASSERT( newSummaryTable );
|
||||
|
||||
// Add table to collection
|
||||
|
@@ -64,8 +64,7 @@ void RicPasteAsciiDataCurveFeature::onActionTriggered( bool isChecked )
|
||||
|
||||
for ( size_t i = 0; i < sourceObjects.size(); i++ )
|
||||
{
|
||||
RimAsciiDataCurve* newObject = dynamic_cast<RimAsciiDataCurve*>(
|
||||
sourceObjects[i]->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto newObject = sourceObjects[i]->copyObject<RimAsciiDataCurve>();
|
||||
CVF_ASSERT( newObject );
|
||||
|
||||
summaryPlot->addAsciiDataCruve( newObject );
|
||||
|
@@ -45,8 +45,7 @@ RimEnsembleCurveSet* RicPasteEnsembleCurveSetFeature::copyCurveSetAndAddToCollec
|
||||
{
|
||||
CVF_ASSERT( curveSetCollection );
|
||||
|
||||
RimEnsembleCurveSet* newCurveSet = dynamic_cast<RimEnsembleCurveSet*>(
|
||||
sourceCurveSet->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto newCurveSet = sourceCurveSet->copyObject<RimEnsembleCurveSet>();
|
||||
CVF_ASSERT( newCurveSet );
|
||||
|
||||
curveSetCollection->addCurveSet( newCurveSet );
|
||||
|
@@ -45,10 +45,7 @@ RimSummaryCurve* RicPasteSummaryCurveFeature::copyCurveAndAddToPlot( RimSummaryC
|
||||
{
|
||||
RimSummaryPlot* summaryPlot = caf::firstAncestorOfTypeFromSelectedObject<RimSummaryPlot>();
|
||||
|
||||
RimSummaryCurve* newCurve =
|
||||
dynamic_cast<RimSummaryCurve*>( sourceCurve->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
CVF_ASSERT( newCurve );
|
||||
|
||||
auto newCurve = sourceCurve->copyObject<RimSummaryCurve>();
|
||||
summaryPlot->addCurveAndUpdate( newCurve );
|
||||
|
||||
// Resolve references after object has been inserted into the project data model
|
||||
|
@@ -72,8 +72,7 @@ void RicPasteTimeHistoryCurveFeature::onActionTriggered( bool isChecked )
|
||||
|
||||
for ( size_t i = 0; i < sourceObjects.size(); i++ )
|
||||
{
|
||||
RimGridTimeHistoryCurve* newObject = dynamic_cast<RimGridTimeHistoryCurve*>(
|
||||
sourceObjects[i]->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto newObject = sourceObjects[i]->copyObject<RimGridTimeHistoryCurve>();
|
||||
CVF_ASSERT( newObject );
|
||||
|
||||
summaryPlot->addGridTimeHistoryCurve( newObject );
|
||||
|
@@ -705,8 +705,7 @@ void RicSummaryPlotEditorUi::updateTargetPlot()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicSummaryPlotEditorUi::copyCurveAndAddToPlot( const RimSummaryCurve* curve, RimSummaryPlot* plot, bool forceVisible )
|
||||
{
|
||||
auto curveCopy =
|
||||
dynamic_cast<RimSummaryCurve*>( curve->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto curveCopy = curve->copyObject<RimSummaryCurve>();
|
||||
CVF_ASSERT( curveCopy );
|
||||
|
||||
if ( forceVisible )
|
||||
@@ -728,8 +727,7 @@ void RicSummaryPlotEditorUi::copyCurveAndAddToPlot( const RimSummaryCurve* curve
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicSummaryPlotEditorUi::copyEnsembleCurveAndAddToCurveSet( const RimSummaryCurve* curve, RimEnsembleCurveSet* curveSet, bool forceVisible )
|
||||
{
|
||||
RimSummaryCurve* curveCopy =
|
||||
dynamic_cast<RimSummaryCurve*>( curve->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto curveCopy = curve->copyObject<RimSummaryCurve>();
|
||||
CVF_ASSERT( curveCopy );
|
||||
|
||||
if ( forceVisible )
|
||||
|
@@ -102,8 +102,7 @@ void RicCreateRftPlotsFeature::appendRftPlotForWell( const QString& wellName, Ri
|
||||
|
||||
// Create a RFT plot based on wellName, and reuse the data source selection in sourcePlot
|
||||
|
||||
auto rftPlot =
|
||||
dynamic_cast<RimWellRftPlot*>( sourcePlot->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto rftPlot = sourcePlot->copyObject<RimWellRftPlot>();
|
||||
if ( !rftPlot ) return;
|
||||
|
||||
rftPlot->setSimWellOrWellPathName( wellName );
|
||||
|
@@ -105,8 +105,7 @@ void RicPasteWellLogCurveFeature::onActionTriggered( bool isChecked )
|
||||
auto* rftCurve = dynamic_cast<RimWellLogRftCurve*>( sourceObject.p() );
|
||||
if ( fileCurve || measurementCurve || extractionCurve || rftCurve )
|
||||
{
|
||||
auto* newObject = dynamic_cast<RimWellLogCurve*>(
|
||||
sourceObject->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto* newObject = sourceObject->copyObject<RimWellLogCurve>();
|
||||
CVF_ASSERT( newObject );
|
||||
|
||||
wellLogTrack->addCurve( newObject );
|
||||
|
@@ -72,8 +72,7 @@ void RicPasteWellLogPlotFeature::onActionTriggered( bool isChecked )
|
||||
RimWellLogPlot* fileCurve = sourceObjects[i];
|
||||
if ( fileCurve )
|
||||
{
|
||||
RimWellLogPlot* newObject = dynamic_cast<RimWellLogPlot*>(
|
||||
fileCurve->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto newObject = fileCurve->copyObject<RimWellLogPlot>();
|
||||
CVF_ASSERT( newObject );
|
||||
|
||||
wellLogPlotCollection->addWellLogPlot( newObject );
|
||||
|
@@ -73,8 +73,7 @@ void RicPasteWellLogTrackFeature::onActionTriggered( bool isChecked )
|
||||
RimWellLogTrack* fileCurve = sourceObjects[i];
|
||||
if ( fileCurve )
|
||||
{
|
||||
RimWellLogTrack* newObject = dynamic_cast<RimWellLogTrack*>(
|
||||
fileCurve->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto newObject = fileCurve->copyObject<RimWellLogTrack>();
|
||||
CVF_ASSERT( newObject );
|
||||
|
||||
wellLogPlot->addPlot( newObject );
|
||||
|
@@ -146,10 +146,8 @@ void RicCreateMultipleWellPathLaterals::slotAppendFractures()
|
||||
{
|
||||
for ( auto measuredDepth : m_ui->locationConfig()->locations() )
|
||||
{
|
||||
RimModeledWellPath* newModeledWellPath = dynamic_cast<RimModeledWellPath*>(
|
||||
sourceLateral->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
auto nameOfNewWell = RicNewWellPathLateralAtDepthFeature::updateNameOfParentAndFindNameOfSideStep( parentWellPath );
|
||||
auto newModeledWellPath = sourceLateral->copyObject<RimModeledWellPath>();
|
||||
auto nameOfNewWell = RicNewWellPathLateralAtDepthFeature::updateNameOfParentAndFindNameOfSideStep( parentWellPath );
|
||||
newModeledWellPath->setName( nameOfNewWell );
|
||||
|
||||
newModeledWellPath->wellPathTieIn()->setTieInMeasuredDepth( measuredDepth );
|
||||
|
@@ -148,10 +148,8 @@ RimModeledWellPath* RicPasteModeledWellPathFeature::duplicateAndInitializeWellPa
|
||||
|
||||
auto wpc = RimTools::wellPathCollection();
|
||||
|
||||
auto* destinationWellPath = dynamic_cast<RimModeledWellPath*>(
|
||||
sourceWellPath->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
QString name = sourceWellPath->name() + "(copy)";
|
||||
auto* destinationWellPath = sourceWellPath->copyObject<RimModeledWellPath>();
|
||||
QString name = sourceWellPath->name() + "(copy)";
|
||||
destinationWellPath->setName( name );
|
||||
|
||||
wpc->addWellPath( destinationWellPath );
|
||||
|
@@ -121,8 +121,7 @@ void RimUserDefinedPolylinesAnnotation::appendTarget( const cvf::Vec3d& defaultP
|
||||
}
|
||||
else
|
||||
{
|
||||
target = dynamic_cast<RimPolylineTarget*>(
|
||||
targets.back()->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
target = targets.back()->copyObject<RimPolylineTarget>();
|
||||
}
|
||||
|
||||
if ( target )
|
||||
|
@@ -221,11 +221,9 @@ void RimFractureTemplateCollection::createAndAssignTemplateCopyForNonMatchingUni
|
||||
{
|
||||
if ( !templateWithMatchingUnit )
|
||||
{
|
||||
templateWithMatchingUnit = dynamic_cast<RimFractureTemplate*>(
|
||||
fractureTemplate->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
auto currentUnit = fractureTemplate->fractureTemplateUnit();
|
||||
auto neededUnit = RiaDefines::EclipseUnitSystem::UNITS_UNKNOWN;
|
||||
templateWithMatchingUnit = fractureTemplate->copyObject<RimFractureTemplate>();
|
||||
auto currentUnit = fractureTemplate->fractureTemplateUnit();
|
||||
auto neededUnit = RiaDefines::EclipseUnitSystem::UNITS_UNKNOWN;
|
||||
if ( currentUnit == RiaDefines::EclipseUnitSystem::UNITS_METRIC )
|
||||
{
|
||||
neededUnit = RiaDefines::EclipseUnitSystem::UNITS_FIELD;
|
||||
|
@@ -247,8 +247,7 @@ RimGeoMechView* RimGeoMechCase::createAndAddReservoirView()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimGeoMechView* RimGeoMechCase::createCopyAndAddView( const RimGeoMechView* sourceView )
|
||||
{
|
||||
RimGeoMechView* rimGeoMechView =
|
||||
dynamic_cast<RimGeoMechView*>( sourceView->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto rimGeoMechView = sourceView->copyObject<RimGeoMechView>();
|
||||
CVF_ASSERT( rimGeoMechView );
|
||||
|
||||
rimGeoMechView->setGeoMechCase( this );
|
||||
@@ -268,8 +267,7 @@ RimGeoMechCase* RimGeoMechCase::createCopy( const QString& newInputFileName )
|
||||
{
|
||||
RimProject* project = RimProject::current();
|
||||
|
||||
RimGeoMechCase* copycase =
|
||||
dynamic_cast<RimGeoMechCase*>( xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto copycase = copyObject<RimGeoMechCase>();
|
||||
CVF_ASSERT( copycase );
|
||||
|
||||
QFileInfo filenameInfo( newInputFileName );
|
||||
|
@@ -329,8 +329,7 @@ RimEclipseView* RimEclipseCase::createCopyAndAddView( const RimEclipseView* sour
|
||||
{
|
||||
CVF_ASSERT( sourceView );
|
||||
|
||||
RimEclipseView* rimEclipseView =
|
||||
dynamic_cast<RimEclipseView*>( sourceView->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto rimEclipseView = sourceView->copyObject<RimEclipseView>();
|
||||
CVF_ASSERT( rimEclipseView );
|
||||
rimEclipseView->setEclipseCase( this );
|
||||
|
||||
|
@@ -65,8 +65,7 @@ RimUserDefinedCalculation* RimUserDefinedCalculationCollection::addCalculation(
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimUserDefinedCalculation* RimUserDefinedCalculationCollection::addCalculationCopy( const RimUserDefinedCalculation* sourceCalculation )
|
||||
{
|
||||
RimUserDefinedCalculation* calcCopy = dynamic_cast<RimUserDefinedCalculation*>(
|
||||
sourceCalculation->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto calcCopy = sourceCalculation->copyObject<RimUserDefinedCalculation>();
|
||||
CVF_ASSERT( calcCopy );
|
||||
|
||||
std::set<QString> calcNames;
|
||||
|
@@ -2282,8 +2282,7 @@ void RimEnsembleCurveSet::updateStatisticsCurves()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimEnsembleCurveSet* RimEnsembleCurveSet::clone() const
|
||||
{
|
||||
RimEnsembleCurveSet* copy =
|
||||
dynamic_cast<RimEnsembleCurveSet*>( xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto copy = copyObject<RimEnsembleCurveSet>();
|
||||
copy->setSummaryCaseCollection( m_yValuesSummaryCaseCollection() );
|
||||
|
||||
// Update summary case references
|
||||
|
@@ -159,8 +159,7 @@ void RimSummaryMultiPlotCollection::duplicatePlot( RimSummaryMultiPlot* plotToDu
|
||||
{
|
||||
if ( !plotToDuplicate ) return;
|
||||
|
||||
auto plotCopy = dynamic_cast<RimSummaryMultiPlot*>( plotToDuplicate->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
auto plotCopy = plotToDuplicate->copyObject<RimSummaryMultiPlot>();
|
||||
addSummaryMultiPlot( plotCopy );
|
||||
|
||||
plotCopy->resolveReferencesRecursively();
|
||||
|
@@ -86,9 +86,7 @@ bool RimEnsembleStatisticsSurface::onLoadData()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSurface* RimEnsembleStatisticsSurface::createCopy()
|
||||
{
|
||||
auto* newSurface =
|
||||
dynamic_cast<RimEnsembleStatisticsSurface*>( xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
auto newSurface = copyObject<RimEnsembleStatisticsSurface>();
|
||||
if ( !newSurface->onLoadData() )
|
||||
{
|
||||
delete newSurface;
|
||||
|
@@ -81,9 +81,7 @@ bool RimFileSurface::onLoadData()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSurface* RimFileSurface::createCopy()
|
||||
{
|
||||
RimFileSurface* newSurface =
|
||||
dynamic_cast<RimFileSurface*>( xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
|
||||
auto newSurface = copyObject<RimFileSurface>();
|
||||
if ( !newSurface->onLoadData() )
|
||||
{
|
||||
delete newSurface;
|
||||
|
@@ -89,7 +89,7 @@ bool RimGridCaseSurface::onLoadData()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSurface* RimGridCaseSurface::createCopy()
|
||||
{
|
||||
auto* newSurface = dynamic_cast<RimGridCaseSurface*>( xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
auto* newSurface = copyObject<RimGridCaseSurface>();
|
||||
newSurface->setCase( m_case.value() ); // TODO: case seems to get lost in the xml copy, investigate later
|
||||
|
||||
if ( !newSurface->onLoadData() )
|
||||
|
@@ -427,8 +427,7 @@ RimWellPathTarget* RimWellPathGeometryDef::appendTarget()
|
||||
}
|
||||
else
|
||||
{
|
||||
wellPathTarget = dynamic_cast<RimWellPathTarget*>(
|
||||
targets.back()->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
wellPathTarget = targets.back()->copyObject<RimWellPathTarget>();
|
||||
}
|
||||
|
||||
if ( wellPathTarget )
|
||||
|
@@ -167,6 +167,14 @@ void PdmObjectHandle::prepareForDelete()
|
||||
m_pointersReferencingMe.clear();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmObjectHandle::addCapability( PdmObjectCapability* capability, bool takeOwnership )
|
||||
{
|
||||
m_capabilities.push_back( std::make_pair( capability, takeOwnership ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -181,6 +189,14 @@ void PdmObjectHandle::addField( PdmFieldHandle* field, const QString& keyword )
|
||||
m_fields.push_back( field );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmObjectHandle* PdmObjectHandle::doCopyObject() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@@ -31,6 +31,10 @@ public:
|
||||
static QString classKeywordStatic(); // For PdmXmlFieldCap to be able to handle fields of PdmObjectHandle directly
|
||||
static std::vector<QString> classKeywordAliases();
|
||||
|
||||
// Function template to call the virtual copy function
|
||||
template <typename T>
|
||||
[[nodiscard]] T* copyObject() const;
|
||||
|
||||
/// The registered fields contained in this PdmObject.
|
||||
[[nodiscard]] std::vector<PdmFieldHandle*> fields() const;
|
||||
[[nodiscard]] PdmFieldHandle* findField( const QString& keyword ) const;
|
||||
@@ -84,21 +88,10 @@ public:
|
||||
void prepareForDelete();
|
||||
|
||||
// Object capabilities
|
||||
void addCapability( PdmObjectCapability* capability, bool takeOwnership )
|
||||
{
|
||||
m_capabilities.push_back( std::make_pair( capability, takeOwnership ) );
|
||||
}
|
||||
void addCapability( PdmObjectCapability* capability, bool takeOwnership );
|
||||
|
||||
template <typename CapabilityType>
|
||||
CapabilityType* capability() const
|
||||
{
|
||||
for ( size_t i = 0; i < m_capabilities.size(); ++i )
|
||||
{
|
||||
CapabilityType* capability = dynamic_cast<CapabilityType*>( m_capabilities[i].first );
|
||||
if ( capability ) return capability;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
CapabilityType* capability() const;
|
||||
|
||||
PdmUiObjectHandle* uiCapability() const; // Implementation is in cafPdmUiObjectHandle.cpp
|
||||
PdmXmlObjectHandle* xmlCapability() const; // Implementation is in cafPdmXmlObjectHandle.cpp
|
||||
@@ -118,6 +111,9 @@ public:
|
||||
protected:
|
||||
void addField( PdmFieldHandle* field, const QString& keyword );
|
||||
|
||||
// Virtual method used to copy objects. The implementation is in PdmObject
|
||||
[[nodiscard]] virtual PdmObjectHandle* doCopyObject() const;
|
||||
|
||||
private:
|
||||
PDM_DISABLE_COPY_AND_ASSIGN( PdmObjectHandle );
|
||||
|
||||
@@ -173,6 +169,16 @@ private:
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
[[nodiscard]] T* PdmObjectHandle::copyObject() const
|
||||
{
|
||||
return dynamic_cast<T*>( doCopyObject() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -338,4 +344,17 @@ template <typename T>
|
||||
return objectsOfType;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename CapabilityType>
|
||||
CapabilityType* PdmObjectHandle::capability() const
|
||||
{
|
||||
for ( auto capability : m_capabilities )
|
||||
{
|
||||
if ( auto capabilityType = dynamic_cast<CapabilityType*>( capability.first ) ) return capabilityType;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // End of namespace caf
|
||||
|
@@ -17,6 +17,16 @@ caf::PdmObject::PdmObject()
|
||||
CAF_PDM_InitObject( "Base PDM Object", "", "", "The Abstract Base Class for the Project Data Model" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmObjectHandle* PdmObject::doCopyObject() const
|
||||
{
|
||||
if ( !xmlCapability() ) return nullptr;
|
||||
|
||||
return xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@@ -186,6 +186,9 @@ public:
|
||||
|
||||
/// Gets all children matching class keyword. Not recursive.
|
||||
void childrenFromClassKeyword( const QString& classKeyword, std::vector<PdmObject*>& children ) const;
|
||||
|
||||
protected:
|
||||
PdmObjectHandle* doCopyObject() const override;
|
||||
};
|
||||
|
||||
} // End of namespace caf
|
||||
|
@@ -991,3 +991,14 @@ TEST( BaseTest, PdmReferenceHelper )
|
||||
EXPECT_TRUE( fromRef == &( ihd1->m_simpleObjectsField ) );
|
||||
}
|
||||
}
|
||||
|
||||
TEST( BaseTest, CopyObject )
|
||||
{
|
||||
const double testValue = 123.345;
|
||||
|
||||
auto ihd1 = std::make_unique<SimpleObj>();
|
||||
ihd1->m_doubleMember = testValue;
|
||||
|
||||
auto objectCopy = std::unique_ptr<SimpleObj>( ihd1->copyObject<SimpleObj>() );
|
||||
EXPECT_EQ( testValue, objectCopy->m_doubleMember );
|
||||
}
|
||||
|
Reference in New Issue
Block a user