init
This commit is contained in:
@@ -0,0 +1,581 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public class Region
|
||||
{
|
||||
private TestObjectTemplate _template;
|
||||
public TestObjectTemplate Template
|
||||
{
|
||||
get => _template;
|
||||
set
|
||||
{
|
||||
_template = value;
|
||||
DetermineAvailableISOSettings();
|
||||
}
|
||||
}
|
||||
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(); }
|
||||
}
|
||||
|
||||
public Point RegionUpperLeft { get; set; }
|
||||
|
||||
public Point RegionBottomRight { get; set; }
|
||||
|
||||
private MMEDirections _direction;
|
||||
public MMEDirections RegionDirection
|
||||
{
|
||||
get => _direction;
|
||||
set
|
||||
{
|
||||
_direction = value;
|
||||
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;
|
||||
SetISOCode();
|
||||
}
|
||||
}
|
||||
|
||||
private MMEFineLocations2 _fineLocation2;
|
||||
public MMEFineLocations2 RegionFineLocation2
|
||||
{
|
||||
get => _fineLocation2;
|
||||
set
|
||||
{
|
||||
_fineLocation2 = value;
|
||||
SetISOCode();
|
||||
}
|
||||
}
|
||||
|
||||
private MMEFineLocations3 _fineLocation3;
|
||||
public MMEFineLocations3 RegionFineLocation3
|
||||
{
|
||||
get => _fineLocation3;
|
||||
set
|
||||
{
|
||||
_fineLocation3 = value;
|
||||
SetISOCode();
|
||||
}
|
||||
}
|
||||
|
||||
private MMETransducerMainLocation _mainLocation;
|
||||
public MMETransducerMainLocation RegionMainLocation
|
||||
{
|
||||
get => _mainLocation;
|
||||
set
|
||||
{
|
||||
if (_mainLocation != value)
|
||||
{
|
||||
_mainLocation = value;
|
||||
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;
|
||||
SetISOCode();
|
||||
}
|
||||
}
|
||||
|
||||
private MMEPositions _position;
|
||||
public MMEPositions RegionPosition
|
||||
{
|
||||
get => _position;
|
||||
set
|
||||
{
|
||||
_position = value;
|
||||
SetISOCode();
|
||||
}
|
||||
}
|
||||
|
||||
public MMETestObjects RegionTestObject { get; set; }
|
||||
|
||||
|
||||
private readonly 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 = ISO13499FileDb.IsoDb.GetTestObjectByIso(r.TestObject);
|
||||
RegionBottomRight = new Point(r.LowerRight.X, r.LowerRight.Y);
|
||||
RegionUpperLeft = new Point(r.UpperLeft.X, r.UpperLeft.Y);
|
||||
RegionDirection = ISO13499FileDb.IsoDb.GetDirectionByIso(r.Direction);
|
||||
RegionFilterClass = ISO13499FileDb.IsoDb.GetFilterClassByIso(r.FilterClass);
|
||||
RegionFineLocation1 = ISO13499FileDb.IsoDb.GetFineLocation1ByIso(r.FineLocation1);
|
||||
RegionFineLocation2 = ISO13499FileDb.IsoDb.GetFineLocation2ByIso(r.FineLocation2);
|
||||
RegionFineLocation3 = ISO13499FileDb.IsoDb.GetFineLocation3ByIso(r.FineLocation3);
|
||||
RegionMainLocation = ISO13499FileDb.IsoDb.GetMainLocationByIso(r.MainLocation);
|
||||
RegionPhysicalDimension = ISO13499FileDb.IsoDb.GetPhysicalDimensionByIso(r.PhysicalDimension);
|
||||
RegionPosition = ISO13499FileDb.IsoDb.GetPosition(r.Position);
|
||||
FilterRegionChannels();
|
||||
SetISOCode();
|
||||
}
|
||||
|
||||
public Visibility RegionAddVisibility { get; set; } = Visibility.Visible;
|
||||
|
||||
public Visibility RegionDeleteVisibility { get; set; } = Visibility.Hidden;
|
||||
|
||||
private List<MMEDirections> _allDirections = new List<MMEDirections>();
|
||||
public MMEDirections[] AllDirections
|
||||
{
|
||||
get => _allDirections.ToArray();
|
||||
set
|
||||
{
|
||||
_allDirections = new List<MMEDirections>(value);
|
||||
var directions = new List<string>();
|
||||
foreach (var dir in _allDirections)
|
||||
{
|
||||
if (null == dir) { directions.Add("?"); }
|
||||
else { directions.Add(dir.Text_L1); }
|
||||
}
|
||||
AllDirectionsStrings = directions.ToArray();
|
||||
}
|
||||
}
|
||||
private List<string> _allDirectionsStrings = new List<string>();
|
||||
public string[] AllDirectionsStrings
|
||||
{
|
||||
get => _allDirectionsStrings.ToArray();
|
||||
set => _allDirectionsStrings = new List<String>(value);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
fineLocations1.Add(null == loc ? "??" : 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 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 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);
|
||||
var locations = new List<string>();
|
||||
foreach (var loc in _mainLocations)
|
||||
{
|
||||
if (null == loc)
|
||||
{
|
||||
locations.Add("????");
|
||||
}
|
||||
else { locations.Add(loc.Text_L1); }
|
||||
}
|
||||
AllMainLocationsStrings = locations.ToArray();
|
||||
}
|
||||
}
|
||||
private List<String> _allMainLocationsStrings = new List<string>();
|
||||
public string[] AllMainLocationsStrings
|
||||
{
|
||||
get => _allMainLocationsStrings.ToArray();
|
||||
set => _allMainLocationsStrings = new List<string>(value);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (null == dim) { dimensions.Add("??"); }
|
||||
else { dimensions.Add(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 List<MMEPositions> _positions = new List<MMEPositions>();
|
||||
public MMEPositions[] AllPositions
|
||||
{
|
||||
get => _positions.ToArray();
|
||||
set
|
||||
{
|
||||
_positions = new List<MMEPositions>(value);
|
||||
var positions = new List<string>();
|
||||
foreach (var pos in _positions) { positions.Add(pos.Text_L1); }
|
||||
AllPositionStrings = positions.ToArray();
|
||||
}
|
||||
}
|
||||
private List<string> _allPositionsStrings = new List<string>();
|
||||
public string[] AllPositionStrings
|
||||
{
|
||||
get => _allPositionsStrings.ToArray();
|
||||
set => _allPositionsStrings = new List<string>(value);
|
||||
}
|
||||
|
||||
public string ISOCode { get; set; } = "????????????????";
|
||||
|
||||
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 = ISO13499FileDb.IsoDb.GetTestObjectByIso(testObjects[0]);
|
||||
|
||||
|
||||
var dirs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Direction).Distinct().ToArray());
|
||||
dirs.Sort();
|
||||
var directions = new List<MMEDirections>();
|
||||
foreach (var dir in dirs) { directions.Add(ISO13499FileDb.IsoDb.GetDirectionByIso(dir)); }
|
||||
var d = ISO13499FileDb.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 (1 == dirs.Count) { RegionDirection = (ISO13499FileDb.IsoDb.GetDirectionByIso(dirs[0])); }
|
||||
else if (0 == dirs.Count) { RegionDirection = null; }
|
||||
|
||||
var fcs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Default_Filter_Class).Distinct().ToArray());
|
||||
fcs.Sort();
|
||||
var filterclasses = new List<MMEFilterClasses>();
|
||||
foreach (var fc in fcs) { filterclasses.Add(ISO13499FileDb.IsoDb.GetFilterClassByIso(fc)); }
|
||||
var fc2 = ISO13499FileDb.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 = (ISO13499FileDb.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(ISO13499FileDb.IsoDb.GetFineLocation1ByIso(loc)); }
|
||||
var f = ISO13499FileDb.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 = (ISO13499FileDb.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 = new List<MMEFineLocations2>();
|
||||
foreach (var loc in locs) { finelocations2.Add(ISO13499FileDb.IsoDb.GetFineLocation2ByIso(loc)); }
|
||||
AllFineLocations2 = finelocations2.ToArray();
|
||||
var f2 = ISO13499FileDb.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 = (ISO13499FileDb.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 = new List<MMEFineLocations3>();
|
||||
foreach (var loc in locs) { finelocations3.Add(ISO13499FileDb.IsoDb.GetFineLocation3ByIso(loc)); }
|
||||
var f3 = ISO13499FileDb.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 = (ISO13499FileDb.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 = new List<MMETransducerMainLocation>();
|
||||
foreach (var loc in locs) { mains.Add(ISO13499FileDb.IsoDb.GetMainLocationByIso(loc)); }
|
||||
var m = ISO13499FileDb.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 = (ISO13499FileDb.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 = new List<MMEPhysicalDimensions>();
|
||||
foreach (var dim in dims) { dimensions.Add(ISO13499FileDb.IsoDb.GetPhysicalDimensionByIso(dim)); }
|
||||
var pd = ISO13499FileDb.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 = (ISO13499FileDb.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 = new List<MMEPositions>();
|
||||
foreach (var pos in poss) { positions.Add(ISO13499FileDb.IsoDb.GetPositionByISO(pos)); }
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
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;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public class RegionAdorner : Adorner
|
||||
{
|
||||
public Point GetUpperLeft()
|
||||
{
|
||||
var p = SelectRect.TopLeft;
|
||||
|
||||
var i = AdornedElement as Image;
|
||||
|
||||
var s = new Size(i.Source.Width, i.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;
|
||||
|
||||
var i = AdornedElement as Image;
|
||||
if (null == i.Source) { return new Point(0, 0); }
|
||||
var s = new Size(i.Source.Width, i.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
|
||||
{
|
||||
_bNew = value;
|
||||
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 => __anchorPoint = value;
|
||||
}
|
||||
private UIElement _adornedElement;
|
||||
private Path _path;
|
||||
private Rect __selectRect;
|
||||
public Rect SelectRect
|
||||
{
|
||||
get => __selectRect;
|
||||
set
|
||||
{
|
||||
__selectRect = value;
|
||||
MyRegion.RegionUpperLeft = GetUpperLeft();
|
||||
MyRegion.RegionBottomRight = GetLowerRight();
|
||||
}
|
||||
}
|
||||
private RectangleGeometry _geometry;
|
||||
|
||||
private Region _region;
|
||||
public Region MyRegion
|
||||
{
|
||||
get => _region;
|
||||
set => _region = value;
|
||||
}
|
||||
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 += new MouseButtonEventHandler(Region_MouseLeftButtonUp);
|
||||
MouseMove += new MouseEventHandler(Region_MouseMove);
|
||||
MouseLeftButtonDown += new MouseButtonEventHandler(Region_MouseLeftButtonDown);
|
||||
_MeasuredSize = adornedElement.RenderSize;
|
||||
//_region.PropertyChanged += new PropertyChangedEventHandler(_region_PropertyChanged);
|
||||
Context = context;
|
||||
}
|
||||
void Region_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
EndSelection(sender, e);
|
||||
}
|
||||
public enum Contexts { EditTestObject, EditTestObjectTemplate };
|
||||
private Contexts _context;
|
||||
public Contexts Context
|
||||
{
|
||||
get => _context;
|
||||
set => _context = value;
|
||||
}
|
||||
void Region_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (null != OnRegionSelected) { OnRegionSelected(this, e); }
|
||||
}
|
||||
private Size __MeasuredSize;
|
||||
private Size _MeasuredSize
|
||||
{
|
||||
get => __MeasuredSize;
|
||||
set => __MeasuredSize = value;
|
||||
}
|
||||
private Point p1;
|
||||
public void Region_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
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)
|
||||
{
|
||||
var mousePosition = e.GetPosition(adornedElement);
|
||||
var r = SelectRect;
|
||||
if (mousePosition.X < AnchorPoint.X) { r.X = mousePosition.X; }
|
||||
else { r.X = AnchorPoint.X; }
|
||||
if (mousePosition.Y < AnchorPoint.Y) { r.Y = mousePosition.Y; }
|
||||
else { r.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)
|
||||
{
|
||||
var mousePosition = e.GetPosition(adornedElement);
|
||||
var r = SelectRect;
|
||||
r.X -= /*p1.X -*/ (p1.X - mousePosition.X);
|
||||
r.Y -= /*p1.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();
|
||||
if (null != OnEndSelection) { OnEndSelection(this); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public class Zone //: Common.BindableBase
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public string Image { get; set; }
|
||||
|
||||
public TemplateZone ISODllZone { get; }
|
||||
|
||||
public Zone(TemplateZone z, TestObjectTemplate template)
|
||||
{
|
||||
ISODllZone = z;
|
||||
|
||||
if (null == z || null == z.Description)
|
||||
{
|
||||
Description = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
Description = z.Description;
|
||||
}
|
||||
Image = z.Picture;
|
||||
var path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZonePictures");
|
||||
|
||||
//if (string.IsNullOrEmpty(Image)) { Image = "H3_2_11.png"; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (right == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return left.FullName.CompareTo(right.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
private List<System.IO.FileInfo> _fileNames = null;
|
||||
|
||||
public string[] AllPictures
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == _fileNames)
|
||||
{
|
||||
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());
|
||||
}
|
||||
var l = new List<string>();
|
||||
foreach (var fi in _fileNames)
|
||||
{
|
||||
l.Add(fi.Name);
|
||||
}
|
||||
return l.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
private int _pictureIndex = -1;
|
||||
|
||||
public int PictureIndex
|
||||
{
|
||||
get => _pictureIndex;
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
PictureSource = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var src = new System.Windows.Media.Imaging.BitmapImage();
|
||||
src.BeginInit();
|
||||
src.UriSource = new Uri(_fileNames[value].FullName, UriKind.Absolute);
|
||||
src.EndInit();
|
||||
PictureSource = src;
|
||||
}
|
||||
_pictureIndex = value;
|
||||
//if (null != _template) { _template.MarkChanged(Tags.PictureIndex.ToString()); }
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user