//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RicPasteWellLogCurveFeature::onActionTriggered(bool isChecked)
{
    caf::PdmObjectHandle* destinationObject = dynamic_cast<caf::PdmObjectHandle*>(caf::SelectionManager::instance()->selectedItem());

    RimWellLogTrack* wellLogTrack = nullptr;
    destinationObject->firstAncestorOrThisOfType(wellLogTrack);
    if (!wellLogTrack)
    {
        return;
    }

    std::vector<caf::PdmPointer<RimWellLogCurve> > sourceObjects = RicPasteWellLogCurveFeature::curves();

    for (size_t i = 0; i < sourceObjects.size(); i++)
    {
        RimWellLogFileCurve* fileCurve = dynamic_cast<RimWellLogFileCurve*>(sourceObjects[i].p());
        if (fileCurve)
        {
            RimWellLogFileCurve* newObject = dynamic_cast<RimWellLogFileCurve*>(sourceObjects[i]->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance()));
            CVF_ASSERT(newObject);

            wellLogTrack->addCurve(newObject);

            // Resolve references after object has been inserted into the project data model
            newObject->resolveReferencesRecursively();
            newObject->initAfterReadRecursively();

            newObject->loadDataAndUpdate();

            wellLogTrack->updateConnectedEditors();
        }

        RimWellLogExtractionCurve* extractionCurve = dynamic_cast<RimWellLogExtractionCurve*>(sourceObjects[i].p());
        if (extractionCurve)
        {
            RimWellLogExtractionCurve* newObject = dynamic_cast<RimWellLogExtractionCurve*>(sourceObjects[i]->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance()));
            CVF_ASSERT(newObject);

            wellLogTrack->addCurve(newObject);

            // Resolve references after object has been inserted into the project data model
            newObject->resolveReferencesRecursively();
            newObject->initAfterReadRecursively();

            newObject->loadDataAndUpdate();

            wellLogTrack->updateConnectedEditors();
        }
    }
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RicNewWellLogFileCurveFeature::addWellLogChannelsToPlotTrack(RimWellLogTrack* plotTrack, const std::vector<RimWellLogFileChannel*>& wellLogFileChannels)
{
    for (size_t cIdx = 0; cIdx < wellLogFileChannels.size(); cIdx++)
    {
        RimWellLogFileCurve* plotCurve = addCurve(plotTrack);
    
        RimWellPath* wellPath;
        wellLogFileChannels[cIdx]->firstAncestorOrThisOfType(wellPath);
        if (wellPath)
        {
            plotCurve->setWellPath(wellPath);
            plotCurve->setWellLogChannelName(wellLogFileChannels[cIdx]->name());
            plotCurve->loadDataAndUpdate();
            plotCurve->updateConnectedEditors();
        }
    }
}