Skip to content

Commit 78a4327

Browse files
committed
Bugfixes related to MW5CORE-260
1 parent c89c7ac commit 78a4327

4 files changed

Lines changed: 220 additions & 117 deletions

File tree

src/Plugins/MW5.Symbology/Services/LabelMoveData.cs

Lines changed: 62 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ namespace MW5.Plugins.Symbology.Services
1717
/// <summary>
1818
/// Holds information about the currently selected label
1919
/// </summary>
20-
internal abstract class ObjectMoveData
20+
public abstract class ObjectMoveData
2121
{
22-
internal int LayerHandle;
23-
internal int ObjectIndex;
24-
internal int PartIndex;
25-
internal Rectangle Rect;
22+
public int LayerHandle;
23+
public int ObjectIndex;
24+
public int PartIndex;
25+
public Rectangle Rect;
2626

27-
internal virtual bool IsChart { get; }
28-
internal virtual bool IsLabel { get; }
29-
internal virtual bool IsSymbol { get; }
27+
public virtual bool IsChart { get; }
28+
public virtual bool IsLabel { get; }
29+
public virtual bool IsSymbol { get; }
3030

31-
internal int X; // original location in screen coordinates
32-
internal int Y; // original location in screen coordinates
31+
public virtual double X { get; set; } // original location
32+
public virtual double Y { get; set; } // original location
3333

34-
internal virtual void Clear()
34+
public virtual void Clear()
3535
{
3636
LayerHandle = -1;
3737
ObjectIndex = -1;
@@ -40,17 +40,17 @@ internal virtual void Clear()
4040
Y = 0;
4141
}
4242

43-
internal ObjectMoveData()
43+
public ObjectMoveData()
4444
{
4545
Clear();
4646
}
47-
internal void GetEventDelta(MouseEventArgs e, out int dx, out int dy)
47+
public void GetEventDelta(MouseEventArgs e, out double dx, out double dy)
4848
{
4949
dx = -X + e.X;
5050
dy = -Y + e.Y;
5151
}
5252

53-
internal void GetProjectedEventDelta(IMuteMap map, MouseEventArgs e, out double dx, out double dy)
53+
public void GetProjectedEventDelta(IMuteMap map, MouseEventArgs e, out double dx, out double dy)
5454
{
5555
map.PixelToProj(X, Y, out double x1, out double y1);
5656
map.PixelToProj(e.X, e.Y, out double x2, out double y2);
@@ -59,13 +59,13 @@ internal void GetProjectedEventDelta(IMuteMap map, MouseEventArgs e, out double
5959
dy = -y1 + y2;
6060
}
6161
}
62-
internal abstract class ObjectTranslateData : ObjectMoveData
62+
public abstract class ObjectTranslateData : ObjectMoveData
6363
{
64-
internal bool HasBackingOffsetFields;
65-
internal int OffsetXField;
66-
internal int OffsetYField;
64+
public bool HasBackingOffsetFields;
65+
public int OffsetXField;
66+
public int OffsetYField;
6767

68-
internal override void Clear()
68+
public override void Clear()
6969
{
7070
base.Clear();
7171
OffsetXField = -1;
@@ -88,31 +88,38 @@ public void UpdateOffsetFields(ILayer layer, double dx, double dy)
8888
}
8989
}
9090

91-
internal abstract class ObjectRotateData : ObjectMoveData
91+
public abstract class ObjectRotateData : ObjectMoveData
9292
{
9393

94-
internal bool HasBackingRotationField;
95-
internal int RotationField;
94+
public Action RotationCancelledCallback;
9695

97-
internal double OriginalRotation;
96+
public bool HasBackingRotationField;
97+
public int RotationField;
9898

99-
internal override void Clear()
99+
public double OriginalRotation;
100+
101+
public IEnumerable<double> SegmentAngles { get; protected set; }
102+
public IEnumerable<double> CartesianAngles { get; } =
103+
new double[] { 0, 45, 90, 135, 180, 225, 270, 315 };
104+
105+
106+
public override void Clear()
100107
{
101108
base.Clear();
102109
RotationField = -1;
103110
OriginalRotation = 0;
104111
HasBackingRotationField = false;
105112
}
106113

107-
internal double GetAngle(double newX, double newY, bool azimuth = false)
114+
public double GetAngle(double newX, double newY, bool azimuth = false)
108115
{
109-
var angle = Math.Atan2(Y - newY, newX - X);
116+
var angle = Math.Atan2(newY - Y, newX - X);
110117
if (azimuth)
111118
angle = (Math.PI * 0.5) - angle;
112119
return NormalizeAngle(angle);
113120
}
114121

115-
internal double GetAngleInDegrees(double newX, double newY, bool geographicAngles = false)
122+
public double GetAngleInDegrees(double newX, double newY, bool geographicAngles = false)
116123
{
117124
return GetAngle(newX, newY, geographicAngles) * (180 / Math.PI);
118125
}
@@ -127,36 +134,39 @@ protected double NormalizeAngle(double angle, double minAngle = 0, double maxAng
127134
public abstract void UpdateRotationField(
128135
ILayer layer, double dx, double dy,
129136
bool snapToFeatures = false, bool snapToAxes = false);
137+
138+
public abstract void SaveRotationField(ILayer layer);
130139
}
131140

132-
internal class ChartMoveData : ObjectTranslateData
141+
public class ChartMoveData : ObjectTranslateData
133142
{
134-
override internal bool IsChart => true;
143+
override public bool IsChart => true;
135144
}
136145

137-
internal class EmptyMoveData : ObjectTranslateData
146+
public class EmptyMoveData : ObjectTranslateData
138147
{
139148
}
140149

141-
internal class LabelMoveData : ObjectTranslateData
150+
public class LabelMoveData : ObjectTranslateData
142151
{
143-
override internal bool IsLabel => true;
152+
override public bool IsLabel => true;
144153
}
145154

146-
internal class SymbolRotateData : ObjectRotateData
155+
public class SymbolRotateData : ObjectRotateData
147156
{
148-
override internal bool IsSymbol => true;
157+
override public bool IsSymbol => true;
149158

150-
protected IMuteMap Map { get; }
159+
private readonly ICoordinate originalPoint;
151160

152-
private IEnumerable<double> SegmentAngles;
153-
private IEnumerable<double> CartesianAngles = new double[] { 0, 45, 90, 135, 180, 225, 270, 315 };
161+
protected IMuteMap Map { get; }
154162

155-
public SymbolRotateData(IMuteMap map, int layerHandle, int objectIndex)
163+
public SymbolRotateData(IMuteMap map, int layerHandle, int objectIndex, double x, double y)
156164
{
157165
Map = map;
158166
LayerHandle = layerHandle;
159167
ObjectIndex = objectIndex;
168+
X = x;
169+
Y = y;
160170

161171
CalculateSnapAngles();
162172
}
@@ -184,7 +194,7 @@ private void CalculateSnapAngles()
184194
continue;
185195
var segments = snapCandidate.Points
186196
.Pairwise((p1, p2) => new Tuple<ICoordinate, ICoordinate>(p1, p2))
187-
.Where(pair => IsBetween(pair.Item1, pair.Item2, center));
197+
.Where(pair => IsBetween(pair.Item1, pair.Item2, center, tolerance));
188198
foreach (var segment in segments)
189199
{
190200
var angle = (Math.PI * 0.5) - Math.Atan2(segment.Item2.Y - segment.Item1.Y, segment.Item2.X - segment.Item1.X);
@@ -199,25 +209,25 @@ private void CalculateSnapAngles()
199209
SegmentAngles = angles.Distinct().ToList();
200210
}
201211

202-
public bool IsBetween(ICoordinate segment1, ICoordinate segment2, ICoordinate point)
212+
public bool IsBetween(ICoordinate segment1, ICoordinate segment2, ICoordinate point, double tolerance)
203213
{
204214
var crossproduct =
205215
(point.Y - segment1.Y) * (segment2.X - segment1.X) -
206216
(point.X - segment1.X) * (segment2.Y - segment1.Y);
207217

208-
if (Math.Abs(crossproduct) > float.Epsilon)
218+
if (Math.Abs(crossproduct) > tolerance)
209219
return false;
210220

211221
var dotproduct =
212222
(point.X - segment1.X) * (segment2.X - segment1.X) +
213223
(point.Y - segment1.Y) * (segment2.Y - segment1.Y);
214-
if (dotproduct < 0)
224+
if (dotproduct < -tolerance)
215225
return false;
216226

217227
var squaredlengthba =
218228
(segment2.X - segment1.X) * (segment2.X - segment1.X) +
219229
(segment2.Y - segment1.Y) * (segment2.Y - segment1.Y);
220-
if (dotproduct > squaredlengthba)
230+
if (dotproduct > squaredlengthba + tolerance)
221231
return false;
222232

223233
return true;
@@ -259,6 +269,8 @@ public double GetSnappedAngleInDegress(
259269
return snappedAngle;
260270
}
261271

272+
private bool needToCloseTable = false;
273+
262274
public override void UpdateRotationField(
263275
ILayer layer, double dx, double dy,
264276
bool snapToFeatures = false, bool snapToAxes = false)
@@ -269,8 +281,15 @@ public override void UpdateRotationField(
269281
var feature = fs.Features[ObjectIndex];
270282
bool needToCloseTable = !fs.EditingTable;
271283
if (needToCloseTable) fs.StartEditingTable();
284+
feature.Rotation = angle;
272285
if (RotationField != -1)
273286
feature.SetDouble(RotationField, angle);
287+
}
288+
289+
public override void SaveRotationField(ILayer layer)
290+
{
291+
var fs = layer.FeatureSet;
292+
var feature = fs.Features[ObjectIndex];
274293
layer.VectorSource?.SaveChanges(out int count, SaveType.AttributesOnly, false);
275294
if (needToCloseTable) fs.StopEditingTable();
276295
}

src/Plugins/MW5.Symbology/Services/LabelMover.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ private void MapMouseMove(IMuteMap map, MouseEventArgs e)
102102

103103
if (e.X != _currentObject.X || e.Y != _currentObject.Y)
104104
{
105-
int dx, dy;
106-
_currentObject.GetEventDelta(e, out dx, out dy);
107-
var r = _currentObject.Rect.CloneWithOffset(dx, dy);
105+
_currentObject.GetEventDelta(e, out double dx, out double dy);
106+
var r = _currentObject.Rect.CloneWithOffset((int) dx, (int) dy);
108107
DrawLabelRectangle(r);
109108
}
110109
}

0 commit comments

Comments
 (0)