// Copyright (C) Stichting Deltares 2016. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets 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.
//
// This program 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 for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Core.Common.Base.Data;
using Core.Common.Controls.TreeView;
using Core.Common.Gui;
using Core.Common.Gui.ContextMenu;
using Core.Common.Gui.Forms;
using Core.Common.Gui.Forms.ProgressDialog;
using Core.Common.Gui.Plugin;
using Core.Common.IO.Exceptions;
using log4net;
using Ringtoets.Common.Data;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.Contribution;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Forms.PresentationObjects;
using Ringtoets.Common.Forms.Views;
using Ringtoets.Common.Placeholder;
using Ringtoets.HydraRing.Calculation.Activities;
using Ringtoets.HydraRing.Calculation.Data;
using Ringtoets.HydraRing.Calculation.Data.Input.Hydraulics;
using Ringtoets.HydraRing.Calculation.Data.Output;
using Ringtoets.HydraRing.Data;
using Ringtoets.HydraRing.IO;
using Ringtoets.Integration.Data.Placeholders;
using Ringtoets.Integration.Forms.PresentationObjects;
using Ringtoets.Integration.Forms.PropertyClasses;
using Ringtoets.Integration.Forms.Views;
using Ringtoets.Integration.Plugin.FileImporters;
using Ringtoets.Integration.Plugin.Properties;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.Forms.PresentationObjects;
using RingtoetsDataResources = Ringtoets.Integration.Data.Properties.Resources;
using RingtoetsFormsResources = Ringtoets.Integration.Forms.Properties.Resources;
using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources;
using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
using UtilsResources = Core.Common.Utils.Properties.Resources;
using BaseResources = Core.Common.Base.Properties.Resources;
namespace Ringtoets.Integration.Plugin
{
///
/// The GUI plugin for the Ringtoets application.
///
public class RingtoetsGuiPlugin : GuiPlugin
{
private static readonly ILog log = LogManager.GetLogger(typeof(GuiPlugin));
public override IRibbonCommandHandler RibbonCommandHandler
{
get
{
return new RingtoetsRibbon();
}
}
public override IGui Gui
{
get
{
return base.Gui;
}
set
{
RemoveOnOpenProjectListener(base.Gui);
base.Gui = value;
AddOnOpenProjectListener(value);
}
}
private void RemoveOnOpenProjectListener(IProjectOwner projectOwner)
{
if (projectOwner != null)
{
projectOwner.ProjectOpened -= VerifyHydraulicBoundaryDatabasePath;
}
}
private void AddOnOpenProjectListener(IProjectOwner projectOwner)
{
if (projectOwner != null)
{
projectOwner.ProjectOpened += VerifyHydraulicBoundaryDatabasePath;
}
}
private void VerifyHydraulicBoundaryDatabasePath(Project project)
{
var sectionsWithDatabase = project.Items.OfType().Where(i => i.HydraulicBoundaryDatabase != null);
foreach (IAssessmentSection section in sectionsWithDatabase)
{
string selectedFile = section.HydraulicBoundaryDatabase.FilePath;
var validationProblem = HydraulicDatabaseHelper.ValidatePathForCalculation(selectedFile);
if(validationProblem != null)
{
log.WarnFormat(
Resources.RingtoetsGuiPlugin_VerifyHydraulicBoundaryDatabasePath_Hydraulic_boundary_database_connection_failed_0_,
validationProblem);
}
}
}
///
/// Returns all instances provided for data of .
///
public override IEnumerable GetPropertyInfos()
{
yield return new PropertyInfo();
yield return new PropertyInfo();
}
///
/// Returns all instances provided for data of .
///
public override IEnumerable GetViewInfos()
{
yield return new ViewInfo
{
GetViewName = (v, o) => RingtoetsDataResources.FailureMechanismContribution_DisplayName,
GetViewData = context => context.WrappedData,
Image = RingtoetsCommonFormsResources.GenericInputOutputIcon,
CloseForData = CloseFailureMechanismContributionViewForData,
AfterCreate = (view, context) => view.AssessmentSection = context.Parent
};
yield return new ViewInfo
{
GetViewName = (v, o) => RingtoetsFormsResources.AssessmentSectionMap_DisplayName,
Image = RingtoetsFormsResources.Map
};
yield return new ViewInfo, FailureMechanismResultView>
{
GetViewName = (v, o) => RingtoetsCommonDataResources.FailureMechanism_AssessmentResult_DisplayName,
Image = RingtoetsCommonFormsResources.GenericInputOutputIcon,
CloseForData = CloseFailureMechanismResultViewForData,
GetViewData = context => context.SectionResults,
AfterCreate = (view, context) => view.FailureMechanism = context.FailureMechanism
};
yield return new ViewInfo, IComment, CommentView>
{
GetViewName = (v, o) => Resources.Comment_DisplayName,
GetViewData = context => context.CommentContainer,
Image = RingtoetsCommonFormsResources.EditDocumentIcon,
CloseForData = CloseCommentViewForData,
AfterCreate = (view, context) => view.AssessmentSection = context.AssessmentSection
};
}
///
/// Gets the child data instances that have definitions of some parent data object.
///
/// The parent data object.
/// Sequence of child data.
public override IEnumerable