Skip to content

Commit c794a40

Browse files
committed
Merge branch 'release/v5.6.3' into master
2 parents 77e87a2 + 47d67a0 commit c794a40

25 files changed

+447
-401
lines changed

src/MW5.AdvancedSnapping/MW5.AdvancedSnapping.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
6868
</PropertyGroup>
6969
<ItemGroup>
70-
<Reference Include="Microsoft.Expression.Interactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
7170
<Reference Include="PresentationCore" />
7271
<Reference Include="PresentationFramework" />
7372
<Reference Include="System" />

src/MW5.AdvancedSnapping/Services/AnchorService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ namespace MW5.Plugins.AdvancedSnapping.Services
1616
public class AnchorService : IAnchorService
1717
{
1818
private const string drawingContextName = "anchorService";
19-
private IAppContext _context;
19+
private readonly IAppContext _context;
2020
private readonly IDrawingService _drawingService;
21-
private int highlightLayerHandle;
21+
//private int highlightLayerHandle;
2222
private readonly Dispatcher dispatcher;
2323
private IList<CancellationTokenSource> taskTokens;
2424

@@ -94,8 +94,8 @@ public ICoordinate PrimaryAnchor
9494

9595
public AnchorService(IAppContext context, IDrawingService drawingService)
9696
{
97-
_context = context ?? throw new ArgumentNullException("context");
98-
_drawingService = drawingService ?? throw new ArgumentNullException("drawingService");
97+
_context = context ?? throw new ArgumentNullException(nameof(context));
98+
_drawingService = drawingService ?? throw new ArgumentNullException(nameof(drawingService));
9999
dispatcher = Dispatcher.CurrentDispatcher;
100100
taskTokens = new List<CancellationTokenSource>();
101101
}

src/MW5.Api/Concrete/FeatureCategoryList.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ public void ApplyColorScheme(SchemeType type, ColorRamp colorRamp, StyleElement
159159
categoryStartIndex, categoryEndIndex);
160160
}
161161

162-
public void ApplyExpression(int categoryIndex)
162+
public void ApplyExpression(int categoryIndex, int startRowIndex = -1, int endRowIndex = -1)
163163
{
164-
_categories.ApplyExpression(categoryIndex);
164+
_categories.ApplyExpression(categoryIndex, startRowIndex, endRowIndex);
165165
}
166166

167167
public void ApplyExpressions()

src/MW5.Api/Interfaces/IFeatureCategoryList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public interface IFeatureCategoryList : IEnumerable<IFeatureCategory>, ISerializ
2121
void ApplyColorScheme(SchemeType type, ColorRamp colorScheme, StyleElement shapeElement,
2222
int categoryStartIndex, int categoryEndIndex);
2323

24-
void ApplyExpression(int categoryIndex);
24+
void ApplyExpression(int categoryIndex, int startRowIndex = -1, int endRowIndex = -1);
2525

2626
void ApplyExpressions();
2727

src/MW5.Api/Legend/Constants.cs

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,73 @@
1-
namespace MW5.Api.Legend
1+
using System.Drawing;
2+
using System.Windows.Forms;
3+
namespace MW5.Api.Legend
24
{
3-
internal class Constants
5+
// TODO turn this in to service?
6+
public class Constants
47
{
5-
public const int ItemHeight = 19;
8+
9+
public Constants(Control control)
10+
{
11+
Control = control;
12+
}
13+
14+
public int _itemHeight => (int)(19.0 * GetScalingFactor());
15+
16+
public int ItemHeight => TextHeight + 4;
617
public const int ItemPad = 4;
718
public const int ItemRightPad = 5;
819
// TEXT
9-
public const int TextHeight = 14;
20+
21+
public static Font DefaultLegendFont = new Font("Arial", 8, GraphicsUnit.Pixel);
22+
23+
public int _textHeight = -1;
24+
public int TextHeight
25+
{
26+
get
27+
{
28+
var scale = GetScalingFactor();
29+
return (int) (14.0 * scale);/*
30+
if (_textHeight < 0)
31+
{
32+
33+
_textHeight = TextRenderer
34+
.MeasureText("HçjÊ{}g", DefaultLegendFont)
35+
.Height + (int) (4 * scale);
36+
}
37+
38+
return _textHeight;*/
39+
}
40+
}
41+
42+
public Control Control { get; }
43+
44+
private double GetScalingFactor()
45+
{
46+
var graphics = Control.CreateGraphics();
47+
return graphics.DpiX / 96.0;
48+
}
49+
1050
public const int TextTopPad = 3;
1151
public const int TextLeftPad = 30;
1252
public const int TextRightPad = 25;
1353
public const int TextRightPadNoIcon = 8;
1454
public const int TextEditingRightPad = 10;
1555
// CHECK BOX
16-
public const int CheckTopPad = 4;
17-
public const int CheckBoxSize = 12;
56+
public int CheckTopPad => (ItemHeight - CheckBoxSize) / 2;
57+
public int CheckBoxSize => 12;
1858
// EXPANSION BOX
1959
public const int ExpandBoxTopPad = 5;
2060
public const int ExpandBoxLeftPad = 3;
2161
public const int ExpandBoxSize = 8;
2262
// LIST ITEMS
2363
public const int ListItemIndent = 18;
2464
public const int IconRightPad = 25;
25-
public const int IconTopPad = 3;
65+
public int IconTopPad => (ItemHeight - IconSize) / 2;
2666
public const int IconSize = 13;
2767
public const int VertLineGrpTopOffset = 14;
2868
// COLOR SCHEME CONSTANTS
29-
public const int CsItemHeight = 14;
30-
public const int CsTopPad = 1;
69+
public int CsItemHeight => (int) (14 * GetScalingFactor());
3170
public const int CsPatchHeight = 12;
32-
public const int CsTextTopPad = 3;
3371
// SCROLLBAR
3472
public const int ScrollWidth = 15;
3573
// MISC
@@ -53,24 +91,13 @@ internal class Constants
5391

5492
public const int VerticalPad = 2;
5593

56-
public static int ItemHeightAndPad()
57-
{
58-
return ItemHeight + VerticalPad;
59-
}
94+
public int ItemHeightAndPad => ItemHeight + VerticalPad;
6095

61-
public static int CsItemHeightAndPad()
62-
{
63-
return CsItemHeight + VerticalPad;
64-
}
96+
public int CsItemHeightAndPad => CsItemHeight + VerticalPad;
6597

66-
public static int CategoryCheckboxWidthWithPadding()
67-
{
68-
return CheckBoxSize + 5;
69-
}
98+
public int CategoryCheckboxWidthWithPadding
99+
=> CheckBoxSize + 5;
70100

71-
public static int CheckboxTopOffset()
72-
{
73-
return (TextHeight - CheckBoxSize) / 2;
74-
}
101+
public int CheckboxTopOffset => (TextHeight - CheckBoxSize) / 2;
75102
}
76103
}

src/MW5.Api/Legend/LegendControlBase.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public partial class LegendControlBase : UserControl
4242
protected Graphics GraphicsBackBuffer;
4343
protected Image BackBuffer;
4444

45+
protected Constants Constants;
46+
4547
/// <summary>
4648
/// Initializes a new instance of the <see cref="LegendControlBase"/> class.
4749
/// </summary>
@@ -60,12 +62,12 @@ private void Init()
6062
_selectedGroupHandle = -1;
6163

6264
HitTest = new LegendHitTest(this);
63-
Font = new Font("Arial", 8);
65+
Font = new Font("Arial", 8, GraphicsUnit.Pixel);
6466
SelectionColor = Color.FromArgb(255, 240, 240, 240);
6567
ShowGroupIcons = true;
6668
ShowLabels = false;
6769
DrawLines = true;
68-
70+
Constants = new Constants(this);
6971
MouseWheel += (s, e) => OnMouseWheel(e);
7072
}
7173

src/MW5.Api/Legend/LegendGroup.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@ public class LegendGroup : ILegendGroup
2121
private int _height;
2222
private object _icon;
2323
private bool _recalcHeight;
24+
private Constants Constants { get; }
2425

2526
/// <summary>
2627
/// Initializes a new instance of the <see cref="LegendGroup"/> class.
2728
/// </summary>
28-
internal LegendGroup(LegendControl leg, int handle)
29+
internal LegendGroup(LegendControl legend, int handle)
2930
{
30-
_legend = leg;
31+
_legend = legend;
3132
_layers = new List<LegendLayer>();
3233
_icon = null;
3334
_recalcHeight = true;
3435

36+
Constants = new Constants(legend);
3537
Handle = handle;
3638
Visible = Visibility.AllVisible;
3739
Expanded = true;

src/MW5.Api/Legend/LegendHitTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ public class LegendHitTest
1313
{
1414
private readonly LegendControlBase _legend;
1515

16+
private Constants Constants { get; }
17+
1618
public LegendHitTest(LegendControlBase legend)
1719
{
1820
if (legend == null) throw new ArgumentNullException("legend");
1921
_legend = legend;
22+
Constants = new Constants(legend);
2023
}
2124

2225
private LegendGroup GetGroup(int index)

src/MW5.Api/Legend/LegendLayer.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class LegendLayer : Layer, ILegendLayer
2222
private readonly LayerElementsCollection _elements; // size and positions of elements
2323
private readonly Dictionary<Guid, ILayerMetadataBase> _customObjects;
2424
private readonly Dictionary<Guid, XmlElement> _rawObjects;
25+
private Constants Constants { get; }
2526

2627
private bool _expanded;
2728
private object _icon;
@@ -49,6 +50,7 @@ internal LegendLayer(MapControl map, LegendControlBase legend, int layerHandle )
4950
Expanded = true;
5051
SmallIconWasDrawn = false;
5152
SymbologyCaption = "";
53+
Constants = new Constants(legend);
5254
}
5355

5456
/// <summary>
@@ -408,24 +410,24 @@ private int CalcHeight(bool useExpandedHeight)
408410
}
409411

410412
// layer name
411-
int ret = Constants.ItemHeightAndPad();
413+
int ret = Constants.ItemHeightAndPad;
412414

413415
bool expanded = _expanded || useExpandedHeight;
414416

415417
if (LegendLayerType == LegendLayerType.Grid || LegendLayerType == LegendLayerType.Image)
416418
{
417419
if (expanded)
418420
{
419-
ret += Constants.CsItemHeightAndPad(); //!string.IsNullOrWhiteSpace(SymbologyCaption) ? Constants.CsItemHeightAndPad() : 0;
421+
ret += Constants.CsItemHeightAndPad;
420422

421-
ret += RasterSymbologyCount * Constants.CsItemHeightAndPad();
423+
ret += RasterSymbologyCount * Constants.CsItemHeightAndPad;
422424
}
423425
}
424426
else if (LegendLayerType == LegendLayerType.WmsLayer)
425427
{
426428
if (expanded)
427429
{
428-
ret += Constants.CsItemHeightAndPad();
430+
ret += Constants.CsItemHeightAndPad;
429431
}
430432
}
431433
else
@@ -438,12 +440,12 @@ private int CalcHeight(bool useExpandedHeight)
438440

439441
if (sf.Categories.Count > 0)
440442
{
441-
ret += Constants.CsItemHeight + Constants.VerticalPad; // caption
443+
ret += Constants.CsItemHeightAndPad; // caption
442444

443445
var categories = sf.Categories;
444446
if (LegendLayerType == LegendLayerType.LineShapefile || LegendLayerType == LegendLayerType.PolygonShapefile)
445447
{
446-
ret += sf.Categories.Count * (Constants.CsItemHeight + Constants.VerticalPad);
448+
ret += sf.Categories.Count * (Constants.CsItemHeightAndPad);
447449
}
448450
else
449451
{
@@ -458,11 +460,11 @@ private int CalcHeight(bool useExpandedHeight)
458460

459461
if (sf.Charts.Count > 0 && sf.Charts.NumFields > 0 && sf.Charts.Visible)
460462
{
461-
ret += Constants.CsItemHeightAndPad(); // caption
463+
ret += Constants.CsItemHeightAndPad; // caption
462464
ret += sf.Charts.IconHeight;
463465
ret += Constants.VerticalPad;
464466

465-
ret += sf.Charts.NumFields * Constants.CsItemHeightAndPad();
467+
ret += sf.Charts.NumFields * Constants.CsItemHeightAndPad;
466468
}
467469
}
468470
}
@@ -476,7 +478,7 @@ protected internal int GetCategoryHeight(ShapeDrawingOptions options)
476478
{
477479
if (LegendLayerType == LegendLayerType.PolygonShapefile || LegendLayerType == LegendLayerType.LineShapefile)
478480
{
479-
return Constants.CsItemHeight + 2;
481+
return Constants.CsItemHeightAndPad;
480482
}
481483

482484
if (LegendLayerType == LegendLayerType.PointShapefile)
@@ -489,7 +491,7 @@ protected internal int GetCategoryHeight(ShapeDrawingOptions options)
489491
((options.Picture.Height * options.PictureScaleY) + 2 <= Constants.CsItemHeight);
490492

491493
return defaultHeight
492-
? Constants.CsItemHeight + 2
494+
? Constants.CsItemHeightAndPad
493495
: (int) ((options.Picture.Height*options.PictureScaleY) + 2);
494496
}
495497

src/MW5.Api/Legend/Renderer/GroupRenderer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public class GroupRenderer: LayerRenderer
1010
{
1111
public GroupRenderer(LegendControlBase legend) : base(legend)
1212
{
13-
1413
}
1514

1615
/// <summary>

src/MW5.Api/Legend/Renderer/LayerRenderer.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,17 @@ public LayerRenderer(LegendControlBase legend)
2424
{
2525
}
2626

27+
private Font _boldFont;
2728
public Font BoldFont
2829
{
29-
get { return new Font(Legend.Font, FontStyle.Bold); }
30+
get {
31+
if (_boldFont == null)
32+
{
33+
_boldFont = new Font(Legend.Font, FontStyle.Bold);
34+
}
35+
36+
return _boldFont;
37+
}
3038
}
3139

3240
/// <summary>
@@ -95,7 +103,7 @@ private void DrawLayerCaptionBackground(Graphics g, LegendLayer lyr, Rectangle b
95103
if (!isSnapshot)
96104
{
97105
var curWidth = bounds.Width - Constants.ItemRightPad;
98-
const int curHeight = Constants.ItemHeight;
106+
int curHeight = Constants.ItemHeight;
99107
var rect = new Rectangle(curLeft, curTop, curWidth, curHeight);
100108

101109
if (lyr.Handle == Legend.SelectedLayerHandle && bounds.Width > 25

src/MW5.Api/Legend/Renderer/RasterSymbologyRenderer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ internal class RasterSymbologyRenderer : SymbologyRendererBase
1414
public RasterSymbologyRenderer(LegendControlBase legend)
1515
: base(legend)
1616
{
17-
1817
}
1918

2019
/// <summary>
@@ -110,8 +109,8 @@ private void RenderColorScheme(Graphics g, LegendLayer layer, Rectangle bounds,
110109

111110
DrawText(g, item.ToString(), textRect, Font, Color.Black);
112111

113-
r.Y += Constants.CsItemHeightAndPad();
114-
textRect.Y += Constants.CsItemHeightAndPad();
112+
r.Y += Constants.CsItemHeightAndPad;
113+
textRect.Y += Constants.CsItemHeightAndPad;
115114
// count++;
116115
}
117116
}

0 commit comments

Comments
 (0)