// Copyright (C) Stichting Deltares 2024. All rights reserved.
//
// This file is part of the application DAM - UI.
//
// DAM - UI 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.Windows.Forms;
using Deltares.Dam.Data;
using Deltares.Geometry;
using Deltares.Geotechnics.SurfaceLines;
using Deltares.Standard.EventPublisher.Enum;
using Deltares.Standard.Forms;
using Deltares.Standard.Forms.DExpress;
using DevExpress.Utils;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
namespace Deltares.Dam.Forms
{
///
/// This is the property control for the surface lines as used in Dam.
///
///
///
public partial class DamSurfaceLineControl : UserControl, IPropertyControl
{
///
/// Initializes a new instance of the class.
///
public DamSurfaceLineControl()
{
InitializeComponent();
SurfaceLinePointsGridControl.PropertyEditorReactionType = PropertyEditorReactionType.Ignore;
((IPropertyControl) this).Name = "SurfaceLine";
BindSupport.Bind(this, SurfaceLinePointsGridControl, sl => sl.CharacteristicPoints);
LocalizationSupport.RegisterAndTranslate(typeof(SurfaceLine2), PointsGroup);
FormsSupport.RepairRightAnchoredControls(this);
SurfaceLinePointsGridControl.CreateNew = CreateNewCharacteristicPointListItem;
// Disable sorting for this table!
GridView gridView = SurfaceLinePointsGridControl.gridView1;
foreach (GridColumn column in gridView.Columns)
{
column.OptionsColumn.AllowSort = DefaultBoolean.False;
}
}
///
/// Gets a value indicating whether this instance is visible.
///
///
/// true if this instance is visible; otherwise, false.
///
public bool IsVisible
{
get
{
return true;
}
}
///
/// Gets or sets the selected object.
///
///
/// The selected object.
///
public object SelectedObject
{
get
{
return CharacteristicPoints;
}
set
{
CharacteristicPointSet pointSet = GetCharacteristicPointSetFromSelectedObject(value);
if (pointSet != null)
{
CharacteristicPoints = pointSet;
BindSupport.Assign(this, this);
}
else
{
var locJob = value as LocationJob;
if (locJob != null)
{
CharacteristicPoints = locJob.Location.LocalXZSurfaceLine2.CharacteristicPoints;
BindSupport.Assign(this, this);
}
}
}
}
private CharacteristicPointSet CharacteristicPoints { get; set; }
private CharacteristicPoint CreateNewCharacteristicPointListItem()
{
return new CharacteristicPoint(CharacteristicPoints, new GeometryPoint());
}
private static CharacteristicPointSet GetCharacteristicPointSetFromSelectedObject(object value)
{
var line = value as SurfaceLine2;
if (line != null)
{
return line.CharacteristicPoints;
}
var characteristicPoint = value as CharacteristicPoint;
if (characteristicPoint != null)
{
return characteristicPoint.PointSet;
}
return null;
}
}
}