예제 #1
0
        public void PrepareGridDictionary_SingleObject()
        {
            // Arrange
            var placedObjects  = new LayoutLoader().LoadLayout(GetTestDataFile("PrepareGridDictionary_SingleObject"), true);
            var expectedResult = new AnnoObject[][]
            {
                new AnnoObject[5],
                new AnnoObject[]
                {
                    null,
                    placedObjects[0],
                    placedObjects[0],
                    placedObjects[0],
                    null
                },
                new AnnoObject[]
                {
                    null,
                    placedObjects[0],
                    placedObjects[0],
                    placedObjects[0],
                    null
                },
                new AnnoObject[5]
            };

            // Act
            var gridDictionary = RoadSearchHelper.PrepareGridDictionary(placedObjects);

            // Assert
            Assert.Equal(expectedResult, gridDictionary);
        }
예제 #2
0
 /// <summary>
 /// Creates a new instance of a wrapper for <see cref="AnnoObject"/>.
 /// </summary>
 /// <param name="annoObjectToWrap">The <see cref="AnnoObject"/> to wrap. Reference will be kept.</param>
 /// <param name="coordinateHelperToUse">The <see cref="ICoordinateHelper"/> to use in calculations.</param>
 /// <param name="brushCacheToUse">The <see cref="IBrushCache"/> used as a cache.</param>
 public LayoutObject(AnnoObject annoObjectToWrap, ICoordinateHelper coordinateHelperToUse, IBrushCache brushCacheToUse, IPenCache penCacheToUse)
 {
     WrappedAnnoObject = annoObjectToWrap;
     _coordinateHelper = coordinateHelperToUse;
     _brushCache       = brushCacheToUse;
     _penCache         = penCacheToUse;
 }
예제 #3
0
        public Color?GetPredefinedColor(AnnoObject annoObject)
        {
            Color?result = null;

            var templateName = annoObject.Template;

            //template name defined?
            if (string.IsNullOrWhiteSpace(annoObject.Template))
            {
                var foundTemplate = FindTemplateByIdentifier(annoObject.Identifier);
                if (string.IsNullOrWhiteSpace(foundTemplate))
                {
                    return(result);
                }

                templateName = foundTemplate;
                //set template so it is saved when the layout is saved again
                annoObject.Template = templateName;
            }

            //colors for template defined?
            var colorsForTemplate = LoadedDefaultColorScheme.Colors.Where(x => x.TargetTemplate.Equals(templateName, StringComparison.OrdinalIgnoreCase)).ToList();

            if (!colorsForTemplate.Any())
            {
                return(result);
            }

            //specific color for identifier defined?
            var colorForTemplateContainingIdentifier = colorsForTemplate.FirstOrDefault(x => x.TargetIdentifiers.Contains(annoObject.Identifier, StringComparer.OrdinalIgnoreCase));

            if (colorForTemplateContainingIdentifier != null)
            {
                result = colorForTemplateContainingIdentifier.Color;
            }
            //specific color for template but without identifier defined?
            else if (colorsForTemplate.FirstOrDefault(x => x.TargetIdentifiers.Count == 0) != null)
            {
                result = colorsForTemplate.FirstOrDefault(x => x.TargetIdentifiers.Count == 0).Color;
            }
            //use first found defined color
            else
            {
                result = colorsForTemplate.First().Color;
            }

            return(result);
        }
        public void ReturnKeyPressed_CommandParameterHasAnnoObject_ShouldSetSelectedItem()
        {
            // Arrange
            var viewModel       = new PresetsTreeViewModel(_mockedTreeLocalization);
            var annoObjectToSet = new AnnoObject();

            var commandParameter = new GenericTreeItem(null);

            commandParameter.AnnoObject = annoObjectToSet;

            // Act
            viewModel.ReturnKeyPressedCommand.Execute(commandParameter);

            // Assert
            Assert.Equal(commandParameter, viewModel.SelectedItem);
        }
예제 #5
0
        public void GetScreenRadius_SizeWidthIsOdd_ShouldNotAdjustRadius()
        {
            // Arrange
            var annoObject = new AnnoObject
            {
                Size   = new Size(5, 8),
                Radius = 10
            };
            var layoutObject = new LayoutObject(annoObject, coordinateHelper, null, null);

            // Act
            var screenRadius = layoutObject.GetScreenRadius(10);

            // Assert
            Assert.Equal(100, screenRadius);
        }
예제 #6
0
        public void GetScreenRadius_SizeHeightAndWidthAreOdd_ShouldAdjustRadius(double widthToSet, double heightToSet, double expectedRadius)
        {
            // Arrange
            var annoObject = new AnnoObject
            {
                Size   = new Size(widthToSet, heightToSet),
                Radius = 10
            };
            var layoutObject = new LayoutObject(annoObject, coordinateHelper, null, null);

            // Act
            var screenRadius = layoutObject.GetScreenRadius(10);

            // Assert
            Assert.Equal(expectedRadius, screenRadius);
        }
        public void ReturnKeyPressed_CommandParameterHasAnnoObject_ShouldRaiseApplySelectedItemEvent()
        {
            // Arrange
            var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization);

            var annoObjectToSet = new AnnoObject();

            var commandParameter = new GenericTreeItem(null);

            commandParameter.AnnoObject = annoObjectToSet;

            // Act/Assert
            Assert.Raises <EventArgs>(
                x => viewModel.ApplySelectedItem += x,
                x => viewModel.ApplySelectedItem -= x,
                () => viewModel.ReturnKeyPressedCommand.Execute(commandParameter));
        }
예제 #8
0
        public void PrepareGridDictionary_MultipleObjects()
        {
            // Arrange
            var placedObjects  = new LayoutLoader().LoadLayout(GetTestDataFile("PrepareGridDictionary_MultipleObjects"), true).Objects;
            var placedObject1  = placedObjects.FirstOrDefault(o => o.Label == "Object1");
            var placedObject2  = placedObjects.FirstOrDefault(o => o.Label == "Object2");
            var expectedResult = new AnnoObject[][]
            {
                new AnnoObject[5],
                new AnnoObject[]
                {
                    null,
                    placedObject1,
                    placedObject1,
                    placedObject1,
                    null
                },
                new AnnoObject[]
                {
                    null,
                    placedObject1,
                    placedObject1,
                    placedObject1,
                    null
                },
                new AnnoObject[5],
                new AnnoObject[5],
                new AnnoObject[]
                {
                    null,
                    null,
                    placedObject2,
                    placedObject2,
                    null
                },
                new AnnoObject[5]
            };

            // Act
            var gridDictionary = RoadSearchHelper.PrepareGridDictionary(placedObjects);

            // Assert
            Assert.Equal(expectedResult, gridDictionary);
            Assert.Equal(0, gridDictionary.Offset.x);
            Assert.Equal(0, gridDictionary.Offset.y);
        }
예제 #9
0
        public void GridInfluenceRangeRect_InfluenceRangeIsZeroOrNegative_ShouldReturnEmptyRect(double influenceRangeToSet)
        {
            // Arrange
            var annoObject = new AnnoObject
            {
                InfluenceRange = influenceRangeToSet,
                Size           = new Size(10, 10),
                Position       = new Point(42, 42)
            };
            var layoutObject = new LayoutObject(annoObject, null, null, null);

            // Act
            var influenceRangeRect = layoutObject.GridInfluenceRangeRect;

            // Assert
            Assert.Equal(annoObject.Position, influenceRangeRect.Location);
            Assert.Equal(default(Size), influenceRangeRect.Size);
        }
예제 #10
0
 private static void DoNothing(AnnoObject objectInRange)
 {
 }
예제 #11
0
 /// <summary>
 /// Checks if input object should be excluded from certain rendering actions.
 /// </summary>
 /// <remarks>
 /// Currently the logic is based only on a single "Template", but can be extended to other criteria in the future.
 /// </remarks>
 public static bool IsIgnoredObject(this AnnoObject annoObject)
 {
     return(string.Equals(annoObject.Template, "Blocker", StringComparison.OrdinalIgnoreCase));
 }
예제 #12
0
 /// <summary>
 /// Creates a new instance of a wrapper for <see cref="AnnoObject"/>.
 /// </summary>
 /// <param name="annoObjectToWrap">The <see cref="AnnoObject"/> to wrap. Reference will be kept.</param>
 /// <param name="coordinateHelperToUse">The <see cref="ICoordinateHelper"/> to use in calculations.</param>
 public LayoutObject(AnnoObject annoObjectToWrap, ICoordinateHelper coordinateHelperToUse)
 {
     WrappedAnnoObject = annoObjectToWrap;
     _coordinateHelper = coordinateHelperToUse;
 }