This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,683 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
namespace DatabaseImport
{
public class Region //: BasePropertyChanged
{
private TestObjectTemplate _template;
public TestObjectTemplate Template
{
get => _template;
set
{
//if (null != _template && _template != value) { _template.PropertyChanged -= Template_PropertyChanged; }
_template = value;
//Template.PropertyChanged += Template_PropertyChanged;
DetermineAvailableISOSettings();
}
}
private void Template_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (Enum.TryParse(e.PropertyName, out TestObjectTemplate.Tags tag))
{
switch (tag)
{
case TestObjectTemplate.Tags.TemplateAllChannels:
RegionChannels = Template.TemplateAllChannels;
RegionUIChannels = Template.TemplateAllUIChannels;
DetermineAvailableISOSettings();
break;
}
}
else
{
switch (e.PropertyName)
{
case "TestObjectType":
RegionChannels = Template.TemplateAllChannels;
RegionUIChannels = Template.TemplateAllUIChannels;
DetermineAvailableISOSettings();
break;
}
}
}
private void InvalidateVisual()
{
_adorner?.InvalidateVisual();
}
private string _name;
public string RegionName
{
get => _name;
set { _name = value; InvalidateVisual(); }
}
private string _regionDescription;
public string RegionDescription
{
get => _regionDescription;
set { _regionDescription = value; InvalidateVisual(); }
}
private Point _upperLeft;
public Point RegionUpperLeft
{
get => _upperLeft;
set => _upperLeft = value;
}
private Point _bottomRight;
public Point RegionBottomRight
{
get => _bottomRight;
set => _bottomRight = value;
}
private MMEDirections _direction;
public MMEDirections RegionDirection
{
get => _direction;
set
{
_direction = value;
if (null != value)
{
_directionIndex = _allDirections.IndexOf(value);
}
else
{
_directionIndex = -1;
}
SetISOCode();
}
}
private MMEFilterClasses _filterClass;
public MMEFilterClasses RegionFilterClass
{
get => _filterClass;
set
{
_filterClass = value;
if (null != value)
{
_filterClassIndex = _filterClasses.IndexOf(value);
}
else
{
_filterClassIndex = -1;
}
SetISOCode();
}
}
private MMEFineLocations1 _fineLocation1;
public MMEFineLocations1 RegionFineLocation1
{
get => _fineLocation1;
set
{
_fineLocation1 = value;
if (null != value)
{
_fineLocation1Index = _fineLocations1.IndexOf(value);
}
else
{
_fineLocation1Index = -1;
}
SetISOCode();
}
}
private MMEFineLocations2 _fineLocation2;
public MMEFineLocations2 RegionFineLocation2
{
get => _fineLocation2;
set
{
_fineLocation2 = value;
if (null != value)
{
_fineLocation2Index = _fineLocations2.IndexOf(value);
}
else
{
_fineLocation2Index = -1;
}
SetISOCode();
}
}
private MMEFineLocations3 _fineLocation3;
public MMEFineLocations3 RegionFineLocation3
{
get => _fineLocation3;
set
{
_fineLocation3 = value;
if (null != value)
{
}
else
{
}
SetISOCode();
}
}
private MMETransducerMainLocation _mainLocation;
public MMETransducerMainLocation RegionMainLocation
{
get => _mainLocation;
set
{
if (_mainLocation != value)
{
_mainLocation = value;
if (null != value)
{
_mainLocationIndex = _mainLocations.IndexOf(value);
}
else
{
_mainLocationIndex = _mainLocations.Count - 1;
}
SetISOCode();
}
}
}
private void FilterRegionChannels()
{
_regionChannels = new List<TestObjectTemplateChannel>(Template.TemplateAllChannels);
_regionUIChannels = new List<TemplateChannelUI>(Template.TemplateAllUIChannels);
for (var i = _regionChannels.Count - 1; i >= 0; i--)
{
var channel = _regionChannels[i];
var mmeChannel = channel.Channel;
if (RegionMainLocation != null && RegionMainLocation.Trans_Main_Loc != mmeChannel.Trans_Main_Loc)
{
_regionChannels.RemoveAt(i);
_regionUIChannels.RemoveAt(i);
continue;
}
if (RegionDirection != null && RegionDirection.Direction != mmeChannel.Direction && RegionDirection.Direction != "?")
{
_regionChannels.RemoveAt(i);
_regionUIChannels.RemoveAt(i);
continue;
}
if (RegionFilterClass != null && RegionFilterClass.Filter_Class != mmeChannel.Default_Filter_Class && RegionFilterClass.Filter_Class != "?")
{
_regionChannels.RemoveAt(i);
_regionUIChannels.RemoveAt(i);
continue;
}
if (RegionFineLocation1 != null && RegionFineLocation1.Fine_Loc_1 != mmeChannel.Fine_Loc_1 && RegionFineLocation1.Fine_Loc_1 != "??")
{
_regionChannels.RemoveAt(i);
_regionUIChannels.RemoveAt(i);
continue;
}
if (RegionFineLocation2 != null && RegionFineLocation2.FINE_LOC_2 != mmeChannel.Fine_Loc_2 && RegionFineLocation2.FINE_LOC_2 != "??")
{
_regionChannels.RemoveAt(i);
_regionUIChannels.RemoveAt(i);
continue;
}
if (RegionFineLocation3 != null && RegionFineLocation3.FINE_LOC_3 != mmeChannel.Fine_Loc_3 && RegionFineLocation3.FINE_LOC_3 != "??")
{
_regionChannels.RemoveAt(i);
_regionUIChannels.RemoveAt(i);
continue;
}
if (RegionPhysicalDimension != null && RegionPhysicalDimension.Physical_Dimension != mmeChannel.Physical_Dimension && RegionPhysicalDimension.Physical_Dimension != "??")
{
_regionChannels.RemoveAt(i);
_regionUIChannels.RemoveAt(i);
continue;
}
if (RegionPosition != null && RegionPosition.Position != mmeChannel.Position && RegionPosition.Position != "?")
{
_regionChannels.RemoveAt(i);
_regionUIChannels.RemoveAt(i);
continue;
}
}
RegionChannels = _regionChannels.ToArray();
RegionUIChannels = _regionUIChannels.ToArray();
SetISOCode();
}
private MMEPhysicalDimensions _physicalDimension;
public MMEPhysicalDimensions RegionPhysicalDimension
{
get => _physicalDimension;
set
{
_physicalDimension = value;
if (null != value)
{
_physicalDimensionIndex = _physicalDimensions.IndexOf(value);
}
else
{
_physicalDimensionIndex = -1;
}
SetISOCode();
}
}
private MMEPositions _position;
public MMEPositions RegionPosition
{
get => _position;
set
{
_position = value;
if (null != value)
{
_positionIndex = _positions.IndexOf(value);
}
else
{
_positionIndex = -1;
}
SetISOCode();
}
}
private MMETestObjects _testObject;
public MMETestObjects RegionTestObject
{
get => _testObject;
set => _testObject = value;
}
private RegionAdorner _adorner;
public Region(RegionAdorner adorner, TestObjectTemplate template)
{
_adorner = adorner;
RegionName = "New region";
RegionDescription = "Describe region";
Template = template;
RegionTestObject = template.TestObject;
RegionChannels = template.TemplateAllChannels;
RegionUIChannels = template.TemplateAllUIChannels;
DetermineAvailableISOSettings();
}
public Region(TestObjectTemplate template, TemplateRegion r)
{
RegionName = r.RegionName;
RegionDescription = r.RegionDescription;
Template = template;
RegionChannels = template.TemplateAllChannels;
RegionUIChannels = template.TemplateAllUIChannels;
RegionTestObject = ((App)Application.Current).IsoDb.GetTestObjectByIso(r.TestObject);
RegionBottomRight = new Point(r.LowerRight.X, r.LowerRight.Y);
RegionUpperLeft = new Point(r.UpperLeft.X, r.UpperLeft.Y);
RegionDirection = ((App)Application.Current).IsoDb.GetDirectionByIso(r.Direction);
RegionFilterClass = ((App)Application.Current).IsoDb.GetFilterClassByIso(r.FilterClass);
RegionFineLocation1 = ((App)Application.Current).IsoDb.GetFineLocation1ByIso(r.FineLocation1);
RegionFineLocation2 = ((App)Application.Current).IsoDb.GetFineLocation2ByIso(r.FineLocation2);
RegionFineLocation3 = ((App)Application.Current).IsoDb.GetFineLocation3ByIso(r.FineLocation3);
RegionMainLocation = ((App)Application.Current).IsoDb.GetMainLocationByIso(r.MainLocation);
RegionPhysicalDimension = ((App)Application.Current).IsoDb.GetPhysicalDimensionByIso(r.PhysicalDimension);
RegionPosition = ((App)Application.Current).IsoDb.GetPosition(r.Position);
FilterRegionChannels();
SetISOCode();
}
private Visibility _regionAddVisibility = Visibility.Visible;
public Visibility RegionAddVisibility
{
get => _regionAddVisibility;
set => _regionAddVisibility = value;
}
private Visibility _regionDeleteVisibility = Visibility.Hidden;
public Visibility RegionDeleteVisibility
{
get => _regionDeleteVisibility;
set => _regionDeleteVisibility = value;
}
private List<MMEDirections> _allDirections = new List<MMEDirections>();
public MMEDirections[] AllDirections
{
get => _allDirections.ToArray();
set
{
_allDirections = new List<MMEDirections>(value);
AllDirectionsStrings = _allDirections.Select(dir => null == dir ? "?" : dir.Text_L1).ToArray();
}
}
private List<string> _allDirectionsStrings = new List<string>();
public string[] AllDirectionsStrings
{
get => _allDirectionsStrings.ToArray();
set => _allDirectionsStrings = new List<string>(value);
}
private int _directionIndex = -1;
private List<MMEFilterClasses> _filterClasses = new List<MMEFilterClasses>();
public MMEFilterClasses[] AllFilterClasses
{
get => _filterClasses.ToArray();
set
{
_filterClasses = new List<MMEFilterClasses>(value);
var filterclasses = new List<string>();
foreach (var fc in _filterClasses) { filterclasses.Add(fc.Text_L1); }
AllFilterClassStrings = filterclasses.ToArray();
}
}
private List<string> _allFilterClassStrings = new List<string>();
public string[] AllFilterClassStrings
{
get => _allFilterClassStrings.ToArray();
set => _allFilterClassStrings = new List<string>(value);
}
public int _filterClassIndex = -1;
private List<MMEFineLocations1> _fineLocations1 = new List<MMEFineLocations1>();
public MMEFineLocations1[] AllFineLocations1
{
get => _fineLocations1.ToArray();
set
{
_fineLocations1 = new List<MMEFineLocations1>(value);
var fineLocations1 = new List<string>();
foreach (var loc in _fineLocations1)
{
if (null == loc) { fineLocations1.Add("??"); }
else { fineLocations1.Add(loc.Text_L1); }
}
AllFineLocations1Strings = fineLocations1.ToArray();
}
}
private List<string> _allFineLocations1Strings = new List<string>();
public string[] AllFineLocations1Strings
{
get => _allFineLocations1Strings.ToArray();
set => _allFineLocations1Strings = new List<string>(value);
}
private int _fineLocation1Index = -1;
private List<MMEFineLocations2> _fineLocations2 = new List<MMEFineLocations2>();
public MMEFineLocations2[] AllFineLocations2
{
get => _fineLocations2.ToArray();
set
{
_fineLocations2 = new List<MMEFineLocations2>(value);
var locations = new List<string>();
foreach (var loc in _fineLocations2) { locations.Add(loc.Text_L1); }
AllFineLocations2Strings = locations.ToArray();
}
}
private List<string> _allFineLocations2Strings = new List<string>();
public string[] AllFineLocations2Strings
{
get => _allFineLocations2Strings.ToArray();
set => _allFineLocations2Strings = new List<string>(value);
}
private int _fineLocation2Index = -1;
public int FineLocation2Index
{
get => _fineLocation2Index;
set
{
if (value == _fineLocation2Index) { return; }
if (value < 0) { RegionFineLocation2 = null; }
else { RegionFineLocation2 = _fineLocations2[value]; }
FilterRegionChannels();
}
}
private List<MMEFineLocations3> _fineLocations3 = new List<MMEFineLocations3>();
public MMEFineLocations3[] AllFineLocations3
{
get => _fineLocations3.ToArray();
set
{
_fineLocations3 = new List<MMEFineLocations3>(value);
var locations = new List<string>();
foreach (var l in _fineLocations3) { locations.Add(l.Text_L1); }
AllFineLocations3Strings = locations.ToArray();
}
}
private List<string> _allFineLocations3Strings = new List<string>();
public string[] AllFineLocations3Strings
{
get => _allFineLocations3Strings.ToArray();
set => _allFineLocations3Strings = new List<string>(value);
}
private List<MMETransducerMainLocation> _mainLocations = new List<MMETransducerMainLocation>();
public MMETransducerMainLocation[] AllMainLocations
{
get => _mainLocations.ToArray();
set
{
_mainLocations = new List<MMETransducerMainLocation>(value);
AllMainLocationsStrings = _mainLocations.Select(loc => null == loc ? "????" : loc.Text_L1).ToArray();
}
}
private List<string> _allMainLocationsStrings = new List<string>();
public string[] AllMainLocationsStrings
{
get => _allMainLocationsStrings.ToArray();
set => _allMainLocationsStrings = new List<string>(value);
}
private int _mainLocationIndex = -1;
private List<MMEPhysicalDimensions> _physicalDimensions = new List<MMEPhysicalDimensions>();
public MMEPhysicalDimensions[] AllPhysicalDimensions
{
get => _physicalDimensions.ToArray();
set
{
_physicalDimensions = new List<MMEPhysicalDimensions>(value);
var dimensions = new List<string>();
foreach (var dim in _physicalDimensions)
{
dimensions.Add(null == dim ? "??" : dim.Text_L1);
}
AllPhysicalDimensionStrings = dimensions.ToArray();
}
}
private List<string> _allPhysicalDimensionStrings = new List<string>();
public string[] AllPhysicalDimensionStrings
{
get => _allPhysicalDimensionStrings.ToArray();
set => _allPhysicalDimensionStrings = new List<string>(value);
}
private int _physicalDimensionIndex = -1;
private List<MMEPositions> _positions = new List<MMEPositions>();
public MMEPositions[] AllPositions
{
get => _positions.ToArray();
set
{
_positions = new List<MMEPositions>(value);
AllPositionStrings = _positions.Select(pos => pos.Text_L1).ToArray();
}
}
private List<string> _allPositionsStrings = new List<string>();
public string[] AllPositionStrings
{
get => _allPositionsStrings.ToArray();
set => _allPositionsStrings = new List<string>(value);
}
private int _positionIndex = -1;
private string _isoCode = "????????????????";
public string ISOCode
{
get => _isoCode;
set => _isoCode = value;
}
private void SetISOCode()
{
var testObject = "?";
if (null != RegionTestObject) { testObject = RegionTestObject.Test_Object; }
var position = "?";
if (null != RegionPosition) { position = RegionPosition.Position; }
var main = "????";
if (null != RegionMainLocation) { main = RegionMainLocation.Trans_Main_Loc; }
var floc1 = "??";
if (null != RegionFineLocation1) { floc1 = RegionFineLocation1.Fine_Loc_1; }
var floc2 = "??";
if (null != RegionFineLocation2) { floc2 = RegionFineLocation2.FINE_LOC_2; }
var floc3 = "??";
if (null != RegionFineLocation3) { floc3 = RegionFineLocation3.FINE_LOC_3; }
var physdim = "??";
if (null != RegionPhysicalDimension) { physdim = RegionPhysicalDimension.Physical_Dimension; }
var dir = "?";
if (null != RegionDirection) { dir = RegionDirection.Direction; }
var fc = "?";
if (null != RegionFilterClass) { fc = RegionFilterClass.Filter_Class; }
ISOCode = ISO.IsoCode.GetString(testObject, position, main, floc1, floc2, floc3, physdim, dir, fc);
}
private List<TestObjectTemplateChannel> _regionChannels = new List<TestObjectTemplateChannel>();
public TestObjectTemplateChannel[] RegionChannels
{
get => _regionChannels.ToArray();
set
{
_regionChannels = new List<TestObjectTemplateChannel>(value);
DetermineAvailableISOSettings();
}
}
private void DetermineAvailableISOSettings()
{
var regionChannels = RegionChannels;
var templateChannels = Template.TemplateAllChannels;
var testObjects = (from pc in regionChannels.AsParallel() select pc.Channel.Test_Object).Distinct().ToArray();
if (testObjects.Length < 1) { return; }
RegionTestObject = ((App)Application.Current).IsoDb.GetTestObjectByIso(testObjects[0]);
var dirs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Direction).Distinct().ToArray());
dirs.Sort();
var directions = dirs.Select(dir => ((App)Application.Current).IsoDb.GetDirectionByIso(dir)).ToList();
var d = ((App)Application.Current).IsoDb.GetDirectionByIso("?");
if (!directions.Contains(d)) { directions.Add(d); }
AllDirections = directions.ToArray();
dirs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Direction).Distinct().ToArray());
if (dirs.Count == 1) { RegionDirection = ((App)Application.Current).IsoDb.GetDirectionByIso(dirs[0]); }
else if (dirs.Count == 0) { RegionDirection = null; }
var fcs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Default_Filter_Class).Distinct().ToArray());
fcs.Sort();
var filterclasses = fcs.Select(fc => ((App)Application.Current).IsoDb.GetFilterClassByIso(fc)).ToList();
var fc2 = ((App)Application.Current).IsoDb.GetFilterClassByIso("?");
if (!filterclasses.Contains(fc2)) { filterclasses.Add(fc2); }
AllFilterClasses = filterclasses.ToArray();
fcs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Default_Filter_Class).Distinct().ToArray());
if (1 == fcs.Count) { RegionFilterClass = ((App)Application.Current).IsoDb.GetFilterClassByIso(fcs[0]); }
else if (0 == fcs.Count) { RegionFilterClass = null; }
var locs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Fine_Loc_1).Distinct().ToArray());
locs.Sort();
var finelocations1 = new List<MMEFineLocations1>();
foreach (var loc in locs) { finelocations1.Add(((App)Application.Current).IsoDb.GetFineLocation1ByIso(loc)); }
var f = ((App)Application.Current).IsoDb.GetFineLocation1ByIso("??");
if (!finelocations1.Contains(f)) { finelocations1.Add(f); }
AllFineLocations1 = finelocations1.ToArray();
locs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Fine_Loc_1).Distinct().ToArray());
if (1 == locs.Count) { RegionFineLocation1 = ((App)Application.Current).IsoDb.GetFineLocation1ByIso(locs[0]); }
else if (0 == locs.Count) { RegionFineLocation1 = null; }
locs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Fine_Loc_2).Distinct().ToArray());
locs.Sort();
var finelocations2 = locs.Select(loc => ((App)Application.Current).IsoDb.GetFineLocation2ByIso(loc)).ToList();
AllFineLocations2 = finelocations2.ToArray();
var f2 = ((App)Application.Current).IsoDb.GetFineLocation2ByIso("??");
if (!finelocations2.Contains(f2)) { finelocations2.Add(f2); }
locs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Fine_Loc_2).Distinct().ToArray());
if (1 == locs.Count) { RegionFineLocation2 = ((App)Application.Current).IsoDb.GetFineLocation2ByIso(locs[0]); }
else if (0 == locs.Count) { RegionFineLocation2 = null; }
locs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Fine_Loc_3).Distinct().ToArray());
locs.Sort();
var finelocations3 = locs.Select(loc => ((App)Application.Current).IsoDb.GetFineLocation3ByIso(loc)).ToList();
var f3 = ((App)Application.Current).IsoDb.GetFineLocation3ByIso("??");
if (!finelocations3.Contains(f3)) { finelocations3.Add(f3); }
AllFineLocations3 = finelocations3.ToArray();
locs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Fine_Loc_3).Distinct().ToArray());
if (1 == locs.Count) { RegionFineLocation3 = ((App)Application.Current).IsoDb.GetFineLocation3ByIso(locs[0]); }
else if (0 == locs.Count) { RegionFineLocation3 = null; }
locs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Trans_Main_Loc).Distinct().ToArray());
locs.Sort();
var mains = locs.Select(loc => ((App)Application.Current).IsoDb.GetMainLocationByIso(loc)).ToList();
var m = ((App)Application.Current).IsoDb.GetMainLocationByIso("????");
if (!mains.Contains(m)) { mains.Add(m); }
AllMainLocations = mains.ToArray();
locs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Trans_Main_Loc).Distinct().ToArray());
if (1 == locs.Count) { RegionMainLocation = ((App)Application.Current).IsoDb.GetMainLocationByIso(locs[0]); }
else if (0 == locs.Count) { RegionMainLocation = null; }
var dims = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Physical_Dimension).Distinct().ToArray());
dims.Sort();
var dimensions = dims.Select(dim => ((App)Application.Current).IsoDb.GetPhysicalDimensionByIso(dim)).ToList();
var pd = ((App)Application.Current).IsoDb.GetPhysicalDimensionByIso("??");
if (!dimensions.Contains(pd)) { dimensions.Add(pd); }
AllPhysicalDimensions = dimensions.ToArray();
dims = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Physical_Dimension).Distinct().ToArray());
if (1 == dims.Count) { RegionPhysicalDimension = ((App)Application.Current).IsoDb.GetPhysicalDimensionByIso(dims[0]); }
else if (0 == dims.Count) { RegionPhysicalDimension = null; }
var poss = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Position).Distinct().ToArray());
poss.Sort();
var positions = poss.Select(pos => (Application.Current as App).IsoDb.GetPositionByISO(pos)).ToList();
AllPositions = positions.ToArray();
poss = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Position).Distinct().ToArray());
if (1 == poss.Count) { RegionPosition = positions[0]; }
else if (0 == poss.Count) { RegionPosition = null; }
}
public TemplateRegion ToISORegion(TestObjectTemplate template, Zone zone, int number)
{
var region = new TemplateRegion(template.TemplateName, zone.Name, template.IsLocalOnly);
region.Direction = null == RegionDirection ? "?" : RegionDirection.Direction;
region.FilterClass = null == RegionFilterClass ? "?" : RegionFilterClass.Filter_Class;
region.FineLocation1 = null == RegionFineLocation1 ? "??" : RegionFineLocation1.Fine_Loc_1;
region.FineLocation2 = null == RegionFineLocation2 ? "??" : RegionFineLocation2.FINE_LOC_2;
region.FineLocation3 = null == RegionFineLocation3 ? "??" : RegionFineLocation3.FINE_LOC_3;
region.LowerRight = new System.Drawing.Point(Convert.ToInt32(RegionBottomRight.X), Convert.ToInt32(RegionBottomRight.Y));
region.MainLocation = null == RegionMainLocation ? "????" : RegionMainLocation.Trans_Main_Loc;
region.PhysicalDimension = null == RegionPhysicalDimension ? "??" : RegionPhysicalDimension.Physical_Dimension;
region.Position = null == RegionPosition ? "?" : RegionPosition.Position;
region.RegionDescription = RegionDescription;
region.RegionName = RegionName;
region.RegionNumber = number;
region.TestObject = null == RegionTestObject ? "?" : RegionTestObject.Test_Object;
region.UpperLeft = new System.Drawing.Point(Convert.ToInt32(RegionUpperLeft.X), Convert.ToInt32(RegionUpperLeft.Y));
return region;
}
private List<TemplateChannelUI> _regionUIChannels = new List<TemplateChannelUI>();
public TemplateChannelUI[] RegionUIChannels
{
get => _regionUIChannels.ToArray();
set => _regionUIChannels = new List<TemplateChannelUI>(value);
}
}
}

View File

@@ -0,0 +1,193 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using System.ComponentModel;
namespace DatabaseImport
{
public class RegionAdorner : Adorner, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected bool SetProperty<T>(ref T storage, T value, string propertyName = null)
{
if (Equals(storage, value)) return false;
storage = value;
OnPropertyChanged(propertyName);
return true;
}
protected void OnPropertyChanged(string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public Point GetUpperLeft()
{
var p = SelectRect.TopLeft;
var image = AdornedElement as Image;
if (null == image) { return p; }
var s = new Size(image.Source.Width, image.Source.Height);
var difX = s.Width - _MeasuredSize.Width;
var difY = s.Height - _MeasuredSize.Height;
var scaleX = difX / _MeasuredSize.Width;
var scaleY = difY / _MeasuredSize.Height;
p = new Point(p.X + p.X * scaleX, p.Y + p.Y * scaleY);
return p;
}
public Point GetLowerRight()
{
var p = SelectRect.BottomRight;
if (!(AdornedElement is Image image)) { return p; }
if (null == image.Source) { return new Point(0, 0); }
var s = new Size(image.Source.Width, image.Source.Height);
var difX = (s.Width - _MeasuredSize.Width);
var difY = s.Height - _MeasuredSize.Height;
var scaleX = difX / _MeasuredSize.Width;
var scaleY = difY / _MeasuredSize.Height;
p = new Point(p.X + p.X * scaleX, p.Y + p.Y * scaleY);
return p;
}
public delegate void RegionSelectedHandler(RegionAdorner r, MouseButtonEventArgs e);
public event RegionSelectedHandler OnRegionSelected;
private bool _bNew = true;
public bool IsNew
{
get => _bNew;
set
{
SetProperty(ref _bNew, value, "IsNew");
if (_bNew)
{
MyRegion.RegionAddVisibility = Visibility.Visible;
MyRegion.RegionDeleteVisibility = Visibility.Hidden;
}
else
{
MyRegion.RegionDeleteVisibility = Visibility.Visible;
MyRegion.RegionAddVisibility = Visibility.Hidden;
}
}
}
private Point _anchorPoint;
public Point AnchorPoint
{
get => _anchorPoint;
set => SetProperty(ref _anchorPoint, value, "AnchorPoint");
}
private readonly UIElement _adornedElement;
private readonly Path _path;
private Rect _selectRect;
public Rect SelectRect
{
get => _selectRect;
set
{
SetProperty(ref _selectRect, value, "SelectRect");
MyRegion.RegionUpperLeft = GetUpperLeft();
MyRegion.RegionBottomRight = GetLowerRight();
}
}
private readonly RectangleGeometry _geometry;
private Region _region;
public Region MyRegion
{
get => _region;
set => SetProperty(ref _region, value, "MyRegion");
}
public RegionAdorner(UIElement adornedElement, TestObjectTemplate template, Contexts context)
: base(adornedElement)
{
_region = new Region(this, template);
_adornedElement = adornedElement;
SelectRect = new Rect();
_geometry = new RectangleGeometry();
_path = new Path();
_path.Data = _geometry;
_path.StrokeThickness = 5;
_path.Stroke = Brushes.AliceBlue;
_path.Opacity = .6;
_path.Visibility = Visibility.Hidden;
MouseLeftButtonUp += Region_MouseLeftButtonUp;
MouseMove += Region_MouseMove;
MouseLeftButtonDown += Region_MouseLeftButtonDown;
_MeasuredSize = adornedElement.RenderSize;
//_region.PropertyChanged += _region_PropertyChanged;
Context = context;
}
private void Region_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
EndSelection(sender, e);
}
public enum Contexts { EditTestObject, EditTestObjectTemplate };
private Contexts _context;
public Contexts Context
{
get => _context;
set => SetProperty(ref _context, value, "Context");
}
void Region_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
OnRegionSelected?.Invoke(this, e);
}
private Size _MeasuredSize { get; set; }
private Point p1;
public void Region_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton != MouseButtonState.Pressed) return;
if (IsNew) { DrawSelection(sender, e, _adornedElement); }
else { MoveSelection(sender, e, _adornedElement); }
var layer = AdornerLayer.GetAdornerLayer(_adornedElement);
InvalidateVisual();
layer.InvalidateVisual();
}
public void DrawSelection(object sender, MouseEventArgs e, UIElement adornedElement)
{
if (e.LeftButton != MouseButtonState.Pressed) return;
var mousePosition = e.GetPosition(adornedElement);
var r = SelectRect;
r.X = mousePosition.X < AnchorPoint.X ? mousePosition.X : AnchorPoint.X;
r.Y = mousePosition.Y < AnchorPoint.Y ? mousePosition.Y : AnchorPoint.Y;
r.Width = Math.Abs(mousePosition.X - AnchorPoint.X);
r.Height = Math.Abs(mousePosition.Y - AnchorPoint.Y);
SelectRect = r;
_geometry.Rect = SelectRect;
}
public void MoveSelection(object sender, MouseEventArgs e, UIElement adornedElement)
{
if (e.LeftButton != MouseButtonState.Pressed) return;
var mousePosition = e.GetPosition(adornedElement);
var r = SelectRect;
r.X -= p1.X - mousePosition.X;
r.Y -= p1.Y - mousePosition.Y;
SelectRect = r;
p1 = mousePosition;
_geometry.Rect = SelectRect;
}
public delegate void EndSelectionHandler(RegionAdorner r);
public event EndSelectionHandler OnEndSelection;
public void EndSelection(object sender, MouseButtonEventArgs e)
{
ReleaseMouseCapture();
OnEndSelection?.Invoke(this);
}
}
}

View File

@@ -0,0 +1,156 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace DatabaseImport
{
public class Zone //: BasePropertyChanged
{
public string Name { get; set; }
public string Description { get; set; }
public string Image { get; set; }
private readonly TestObjectTemplate _template;
public TemplateZone ISODllZone { get; }
public Zone(Zone copy, TestObjectTemplate template)
{
ISODllZone = copy.ISODllZone;
_template = template;
Description = ISODllZone?.Description ?? "";
Image = ISODllZone?.Picture;
_fileNames = new List<System.IO.FileInfo>();
PopulateFilenamesIfNeeded();
PictureIndex = copy.PictureIndex;
PictureSource = copy.PictureSource;
Name = ISODllZone.ZoneName;
_regions = new List<Region>(copy.Regions);
}
public Zone(TemplateZone z, TestObjectTemplate template)
{
ISODllZone = z;
_template = template;
Description = z?.Description ?? "";
Image = z?.Picture;
var path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZonePictures");
if (!string.IsNullOrEmpty(Image))
{
path = System.IO.Path.Combine(path, Image);
if (!System.IO.File.Exists(path)) { PictureIndex = -1; }
else
{
var src = new System.Windows.Media.Imaging.BitmapImage();
src.BeginInit();
src.UriSource = new Uri(path, UriKind.Absolute);
try
{
src.EndInit();
PictureSource = src;
_pictureIndex = AllPictures.ToList().IndexOf(Image);
}
catch
{
PictureIndex = -1;
}
}
}
if (z != null)
{
Name = z.ZoneName;
_regions = new List<Region>();
foreach (var r in z.TemplateRegions)
{
var region = new Region(template, r);
_regions.Add(region);
}
}
}
public class FileInfoComparer : IComparer<System.IO.FileInfo>
{
int IComparer<System.IO.FileInfo>.Compare(System.IO.FileInfo left, System.IO.FileInfo right)
{
if (left == right) { return 0; }
if (left == null) { return -1; }
return right == null ? 1 : string.Compare(left.FullName, right.FullName, StringComparison.Ordinal);
}
}
private List<System.IO.FileInfo> _fileNames;
private static object MyLock = new object();
public string[] AllPictures
{
get
{
lock (MyLock)
{
PopulateFilenamesIfNeeded();
return _fileNames.Select(fi => fi.Name).ToArray();
}
}
}
public void PopulateFilenamesIfNeeded()
{
lock (MyLock)
{
if (null == _fileNames || _fileNames.Count == 0)
{
PopulateFilenames();
}
}
}
private void PopulateFilenames()
{
lock (MyLock)
{
var files = new List<string>();
files.AddRange(System.IO.Directory.EnumerateFiles(
System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZonePictures")));
_fileNames = new List<System.IO.FileInfo>();
foreach (var file in files)
{
_fileNames.Add(new System.IO.FileInfo(file));
}
_fileNames.Sort(new FileInfoComparer());
}
}
private int _pictureIndex = -1;
public int PictureIndex
{
get => _pictureIndex;
set
{
if (value < 0) { PictureSource = null; }
else
{
var src = new System.Windows.Media.Imaging.BitmapImage();
lock (MyLock)
{
PopulateFilenamesIfNeeded();
src.BeginInit();
src.UriSource = new Uri(_fileNames[value].FullName, UriKind.Absolute);
src.EndInit();
}
PictureSource = src;
}
_pictureIndex = value;
}
}
public string GetPictureName()
{
return _pictureIndex < 0 ? "" : _fileNames[_pictureIndex].Name;
}
public System.Windows.Media.ImageSource PictureSource { get; set; } = null;
private List<Region> _regions = new List<Region>();
public Region[] Regions
{
get => _regions.ToArray();
set => _regions = new List<Region>(value);
}
}
}