public LambdaPsiHost(Lifetime lifetime, ISolution solution, ISymbolCache symbolCache, PsiIconManager psiIconManager, IconHost iconHost,
                             ProjectModelViewHost projectModelViewHost, IShellLocks locks, ILogger logger)
        {
            _symbolCache          = symbolCache;
            _psiIconManager       = psiIconManager;
            _iconHost             = iconHost;
            _projectModelViewHost = projectModelViewHost;
            _locks  = locks;
            _logger = logger;

            var model = solution.GetProtocolSolution().GetLambdaPsiModel();

            model.DetermineHandlersRequest.Advise(lifetime, request =>
            {
                var handlers = DetermineHandlers(solution);
                model.DetermineHandlersResponse(new DetermineHandlersResponse(request.RequestId, handlers));
            });

            model.IsHandlerExistRequest.Advise(lifetime, request =>
            {
                var className  = request.ClassName;
                var methodName = request.MethodName;
                var projectId  = request.ProjectId;

                var handlerExists = IsHandlerExists(lifetime, projectId, className, methodName);
                model.IsHandlerExistResponse(new HandlerExistResponse(request.RequestId, handlerExists));
            });
        }
Example #2
0
        public UnityNUnitServiceProvider(ISolution solution,
                                         IPsiModules psiModules,
                                         ISymbolCache symbolCache,
                                         IUnitTestElementIdFactory idFactory,
                                         IUnitTestElementManager elementManager,
                                         NUnitTestProvider provider,
                                         IUnitTestingSettings settings,
                                         ISettingsStore settingsStore,
                                         ISettingsOptimization settingsOptimization,
                                         ISettingsCache settingsCache,
                                         UnitTestingCachingService cachingService,
                                         INUnitTestParametersProvider testParametersProvider,
                                         UnityEditorProtocol editorProtocol,
                                         RunViaUnityEditorStrategy runViaUnityEditorStrategy,
                                         UnitySolutionTracker unitySolutionTracker)
            : base(solution, psiModules, symbolCache, idFactory, elementManager, provider, settings, settingsStore,
                   settingsOptimization, settingsCache, cachingService, testParametersProvider)
        {
            if (solution.GetData(ProjectModelExtensions.ProtocolSolutionKey) == null)
            {
                return;
            }

            myRdUnityModel         = solution.GetProtocolSolution().GetRdUnityModel();
            myEditorProtocol       = editorProtocol;
            myUnityEditorStrategy  = runViaUnityEditorStrategy;
            myUnitySolutionTracker = unitySolutionTracker;
        }
Example #3
0
        public void InvokeHover(Point screenPosition, float scale, ISymbolCache symbolCache)
        {
            if (Hover == null)
            {
                return;
            }
            if (HoverLayers.Count == 0)
            {
                return;
            }
            var mapInfo = InfoHelper.GetMapInfo(Viewport, screenPosition, scale, HoverLayers, symbolCache);

            if (mapInfo?.Feature != _previousHoverEventArgs?.MapInfo.Feature) // only notify when the feature changes
            {
                var mapInfoEventArgs = new MapInfoEventArgs
                {
                    MapInfo = mapInfo,
                    NumTaps = 0,
                    Handled = false
                };

                _previousHoverEventArgs = mapInfoEventArgs;
                Hover?.Invoke(this, mapInfoEventArgs);
            }
        }
Example #4
0
        public UnityNUnitServiceProvider(ISolution solution,
                                         IPsiModules psiModules,
                                         ISymbolCache symbolCache,
                                         IUnitTestElementIdFactory idFactory,
                                         IUnitTestElementManager elementManager,
                                         NUnitTestProvider provider,
                                         IUnitTestingSettings settings,
                                         ISettingsStore settingsStore,
                                         ISettingsOptimization settingsOptimization,
                                         ISettingsCache settingsCache,
                                         UnitTestingCachingService cachingService,
                                         INUnitTestParametersProvider testParametersProvider,
                                         FrontendBackendHost frontendBackendHost,
                                         BackendUnityHost backendUnityHost,
                                         RunViaUnityEditorStrategy runViaUnityEditorStrategy,
                                         UnitySolutionTracker unitySolutionTracker)
            : base(solution, psiModules, symbolCache, idFactory, elementManager, provider, settings, settingsStore,
                   settingsOptimization, settingsCache, cachingService, testParametersProvider)
        {
            // Only in tests
            if (!frontendBackendHost.IsAvailable)
            {
                return;
            }

            myFrontendBackendModel = frontendBackendHost.Model.NotNull("frontendBackendHost.Model != null");
            myBackendUnityHost     = backendUnityHost;
            myUnityEditorStrategy  = runViaUnityEditorStrategy;
            myUnitySolutionTracker = unitySolutionTracker;
        }
Example #5
0
        public bool Draw(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IFeature feature, IStyle istyle,
                         ISymbolCache symbolCache)
        {
            var style = ((PolylineMarkerStyle)istyle);

            var zoom = 1 / (float)viewport.Resolution;
            //
            var dest = viewport.WorldToScreen(style.start.X, style.start.Y);

            canvas.Translate((float)dest.X, (float)dest.Y);
            canvas.Scale(zoom, zoom);

            canvas.RotateDegrees((float)viewport.Rotation, 0.0f, 0.0f);

            //#TODO store paint with shader in the style
            using (SKPaint paint = new SKPaint())
            {
                paint.Color       = style.color.WithAlpha((byte)(style.Opacity * 255));
                paint.StrokeWidth = 3f * (float)viewport.Resolution;
                paint.Style       = SKPaintStyle.Stroke;
                paint.IsAntialias = true;

                canvas.DrawPath(style.path, paint);
            }

            return(true);
        }
Example #6
0
        public LambdaPsiHost(ISolution solution, ISymbolCache symbolCache, PsiIconManager psiIconManager, IconHost iconHost,
                             ProjectModelViewHost projectModelViewHost, IShellLocks locks, ILogger logger)
        {
            _symbolCache          = symbolCache;
            _psiIconManager       = psiIconManager;
            _iconHost             = iconHost;
            _projectModelViewHost = projectModelViewHost;
            _locks  = locks;
            _logger = logger;

            var model = solution.GetProtocolSolution().GetLambdaPsiModel();

            model.DetermineHandlers.Set((lifetime, unit) =>
            {
                var task = new RdTask <List <HandlerCompletionItem> >();
                task.Set(DetermineHandlers(solution));
                return(task);
            });

            model.IsHandlerExists.Set((lifetime, request) =>
            {
                var task       = new RdTask <bool>();
                var className  = request.ClassName;
                var methodName = request.MethodName;
                var projectId  = request.ProjectId;

                var handlerExists = IsHandlerExists(lifetime, projectId, className, methodName);
                task.Set(handlerExists);
                return(task);
            });
        }
Example #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="layers">The layers to query for MapInfo</param>
        /// <param name="viewport">The current Viewport</param>
        /// <param name="screenPosition">The screenposition to query</param>
        /// <param name="symbolCache">The </param>
        /// <param name="margin">Margin of error in pixels. If the distance between screen position and geometry
        /// is smaller than the margin it is seen as a hit.</param>
        /// <returns></returns>
        public static MapInfo GetMapInfo(IEnumerable <ILayer> layers, IReadOnlyViewport viewport, Point screenPosition,
                                         ISymbolCache symbolCache, int margin = 0)
        {
            var worldPosition = viewport.ScreenToWorld(screenPosition);

            return(GetMapInfo(layers, worldPosition, screenPosition, viewport.Resolution, symbolCache, margin));
        }
Example #8
0
        public static InfoEventArgs GetInfoEventArgs(IViewport viewport, Point screenPosition, IEnumerable <ILayer> layers,
                                                     ISymbolCache symbolCache)
        {
            var worldPosition = viewport.ScreenToWorld(new Point(screenPosition.X, screenPosition.Y));

            return(GetInfoEventArgs(layers, worldPosition, screenPosition, viewport.Resolution, symbolCache));
        }
Example #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="viewport"></param>
        /// <param name="screenPosition"></param>
        /// <param name="scale"></param>
        /// <param name="layers"></param>
        /// <param name="symbolCache"></param>
        /// <param name="margin">Margin of error in pixels. If the distance between screen position and geometry
        /// is smaller than the margin it is seen as a hit.</param>
        /// <returns></returns>
        public static MapInfo GetMapInfo(IViewport viewport, Point screenPosition,
                                         float scale, IEnumerable <ILayer> layers, ISymbolCache symbolCache, int margin = 0)
        {
            var worldPosition = viewport.ScreenToWorld(
                new Point(screenPosition.X / scale, screenPosition.Y / scale));

            return(GetMapInfo(layers, worldPosition, screenPosition, viewport.Resolution, symbolCache, margin));
        }
Example #10
0
 public PositionCache(ISymbolCache symbolCache)
 {
     _positions = new List<Position>();
     var random = new Random();
     for(int i = 0; i < 100; i++)
     {
         _positions.Add(new Position(){Id = i + 1, Amount = random.Next(1, 100), Symbol = symbolCache.GetNext()});
     }
 }
 public UnityObjectTypeOrNamespaceReference(ICSharpLiteralExpression owner, [CanBeNull] IQualifier qualifier,
                                            ITokenNode token, TextRange rangeWithin,
                                            ExpectedObjectTypeReferenceKind kind, ISymbolCache symbolCache,
                                            bool isFinalPart)
     : base(owner, qualifier, token, rangeWithin.ToTreeTextRange())
 {
     mySymbolCache              = symbolCache;
     myIsFinalPart              = isFinalPart;
     myForwardedTypesFilter     = new ForwardedTypesFilter(symbolCache);
     myExpectedObjectTypeFilter = new ExpectedObjectTypeFilter(kind, mustBeClass: isFinalPart);
 }
Example #12
0
        public bool Draw(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IFeature feature, IStyle style,
                         ISymbolCache symbolCache)
        {
            var image = ((SvgStyle)style).GetImage();

            if (image == null)
            {
                return(true);
            }
            var center = viewport.Center;

            //SvgRenderer.Draw(canvas, image, -(float)viewport.Center.X, (float)viewport.Center.Y, (float)viewport.Rotation, 0,0,default, default, default, (float)viewport.Resolution);

            canvas.Save();


            var zoom = 1 / (float)viewport.Resolution;

            var canvasSize = canvas.LocalClipBounds;

            var canvasCenterX = canvasSize.Width / 2;
            var canvasCenterY = canvasSize.Height / 2;


            //float width = (float)MapPage.currentBounds.Width;
            //float height = (float)MapPage.currentBounds.Height;


            float width  = image.Picture.CullRect.Width;
            float height = image.Picture.CullRect.Height;

            float num1 = (width / 2) * zoom;
            float num2 = (-height) * zoom;

            canvas.Translate(canvasCenterX, num2 + canvasCenterY);

            canvas.Translate(-(float)viewport.Center.X * zoom, (float)viewport.Center.Y * zoom);

            canvas.Scale(zoom, zoom);


            canvas.RotateDegrees((float)viewport.Rotation, 0.0f, 0.0f);


            canvas.DrawPicture(image.Picture, new SKPaint()
            {
                IsAntialias = true
            });
            canvas.Restore();



            return(true);
        }
Example #13
0
        public void InvokeInfo(Point screenPosition, ISymbolCache symbolCache)
        {
            if (Info == null)
            {
                return;
            }
            var eventArgs = InfoHelper.GetInfoEventArgs(Viewport, screenPosition, InfoLayers, symbolCache);

            if (eventArgs != null)
            {
                Info?.Invoke(this, eventArgs);
            }
        }
 public UnityNUnitServiceProvider(ISolution solution, IPsiModules psiModules, ISymbolCache symbolCache,
                                  IUnitTestElementIdFactory idFactory, IUnitTestElementManager elementManager, NUnitTestProvider provider,
                                  ISettingsStore settingsStore, ISettingsOptimization settingsOptimization, ISettingsCache settingsCache,
                                  UnitTestingCachingService cachingService, IDotNetCoreSdkResolver dotNetCoreSdkResolver,
                                  UnityEditorProtocol unityEditorProtocol,
                                  RunViaUnityEditorStrategy runViaUnityEditorStrategy,
                                  NUnitOutOfProcessUnitTestRunStrategy nUnitOutOfProcessUnitTestRunStrategy)
     : base(solution, psiModules, symbolCache, idFactory, elementManager, provider, settingsStore,
            settingsOptimization, settingsCache, cachingService, dotNetCoreSdkResolver, nUnitOutOfProcessUnitTestRunStrategy)
 {
     myUnityEditorProtocol = unityEditorProtocol;
     myUnityEditorStrategy = runViaUnityEditorStrategy;
 }
Example #15
0
        private static bool IsTouchingTakingIntoAccountSymbolStyles(
            Point point, IFeature feature, IStyle layerStyle, double resolution, ISymbolCache symbolCache)
        {
            if (feature.Geometry is Point)
            {
                var styles = new List <IStyle>();
                if (layerStyle != null)
                {
                    styles.Add(layerStyle);
                }
                styles.AddRange(feature.Styles);

                foreach (var style in styles)
                {
                    var symbolStyle = style as SymbolStyle;

                    if (symbolStyle == null)
                    {
                        Logger.Log(LogLevel.Warning, $"Feature info not supported for {style.GetType()}");
                        continue; //todo: add support for other types
                    }

                    var scale = symbolStyle.SymbolScale;

                    var size = symbolStyle.BitmapId >= 0
                        ? symbolCache.GetSize(symbolStyle.BitmapId)
                        : new Size(SymbolStyle.DefaultWidth, SymbolStyle.DefaultHeight);

                    // Symbols allways drawn around the center (* 0.5 instead of / 2)
                    var factor  = resolution * scale;
                    var marginX = size.Width * 0.5 * factor;
                    var marginY = size.Height * 0.5 * factor;

                    var box = feature.Geometry.GetBoundingBox();
                    box = box.Grow(marginX, marginY);
                    if (symbolStyle.SymbolOffset.IsRelative)
                    {
                        box.Offset(size.Width * symbolStyle.SymbolOffset.X * factor, size.Height * symbolStyle.SymbolOffset.Y * factor);
                    }
                    else
                    {
                        box.Offset(symbolStyle.SymbolOffset.X * factor, symbolStyle.SymbolOffset.Y * factor);
                    }
                    if (box.Contains(point))
                    {
                        return(true);
                    }
                }
            }
            return(feature.Geometry.Contains(point));
        }
Example #16
0
        public static IEnumerable <ITypeElement> GetTypeElementsByClrName(ISolution solution, string clrName)
        {
            IPsiServices psiServices = solution.GetComponent <IPsiServices>();

            psiServices.Files.CommitAllDocuments();

            ISymbolCache symbolCache = psiServices.Symbols;
            ISymbolScope symbolScope = symbolCache.GetSymbolScope(LibrarySymbolScope.FULL, true);

            IEnumerable <ITypeElement> validTypeElements = symbolScope.GetTypeElementsByCLRName(clrName)
                                                           .Where(element => element.IsValid());

            return(SkipDefaultProfileIfRuntimeExist(validTypeElements));
        }
        public LambdaHost(ISolution solution, ISymbolCache symbolCache, PsiIconManager psiIconManager, IconHost iconHost)
        {
            _model          = solution.GetProtocolSolution().GetLambdaModel();
            _symbolCache    = symbolCache;
            _psiIconManager = psiIconManager;
            _iconHost       = iconHost;

            _model.DetermineHandlers.Set((lifetime, unit) =>
            {
                var task = new RdTask <List <HandlerCompletionItem> >();
                task.Set(DetermineHandlers(solution));
                return(task);
            });
        }
Example #18
0
        private static MapInfo GetMapInfo(IEnumerable <ILayer> layers, Point worldPosition,
                                          Point screenPosition, double resolution, ISymbolCache symbolCache, int margin = 0)
        {
            var reversedLayer = layers.Reverse();

            foreach (var layer in reversedLayer)
            {
                if (!layer.Enabled)
                {
                    continue;
                }
                if (layer.MinVisible > resolution)
                {
                    continue;
                }
                if (layer.MaxVisible < resolution)
                {
                    continue;
                }

                var maxSymbolSize = 128; // This sucks. There should be a better way to determine max symbol size.
                var box           = new BoundingBox(worldPosition, worldPosition);
                var grownBox      = box.Grow(resolution * maxSymbolSize * 0.5);
                var features      = layer.GetFeaturesInView(grownBox, resolution);

                var feature = features.LastOrDefault(f =>
                                                     IsTouchingTakingIntoAccountSymbolStyles(worldPosition, f, layer.Style, resolution, symbolCache, margin));

                if (feature != null)
                {
                    return(new MapInfo
                    {
                        Feature = feature,
                        Layer = layer,
                        WorldPosition = worldPosition,
                        ScreenPosition = screenPosition,
                        Resolution = resolution
                    });
                }
            }

            // return MapInfoEventArgs without feature if none was found. Can be usefull to create features
            return(new MapInfo
            {
                WorldPosition = worldPosition,
                ScreenPosition = screenPosition
            });
        }
Example #19
0
        private static MapInfo GetMapInfo(IEnumerable <ILayer> layers, Point worldPosition,
                                          Point screenPosition, double resolution, ISymbolCache symbolCache, int margin = 0)
        {
            var reversedLayer = layers.Reverse();

            foreach (var layer in reversedLayer)
            {
                if (layer.Enabled == false)
                {
                    continue;
                }
                if (layer.MinVisible > resolution)
                {
                    continue;
                }
                if (layer.MaxVisible < resolution)
                {
                    continue;
                }

                var features = layer.GetFeaturesInView(layer.Envelope, resolution);

                var feature = features.LastOrDefault(f =>
                                                     IsTouchingTakingIntoAccountSymbolStyles(worldPosition, f, layer.Style, resolution, symbolCache, margin));

                if (feature != null)
                {
                    return(new MapInfo
                    {
                        Feature = feature,
                        Layer = layer,
                        WorldPosition = worldPosition,
                        ScreenPosition = screenPosition,
                        Resolution = resolution
                    });
                }
            }

            // return MapInfoEventArgs without feature if none was found. Can be usefull to create features
            return(new MapInfo
            {
                WorldPosition = worldPosition,
                ScreenPosition = screenPosition
            });
        }
Example #20
0
        public void InvokeHover(Point screenPosition, ISymbolCache symbolCache)
        {
            if (Hover == null)
            {
                return;
            }
            if (HoverLayers.Count == 0)
            {
                return;
            }
            var hoverEventArgs = InfoHelper.GetInfoEventArgs(Viewport, screenPosition, HoverLayers, symbolCache);

            if (hoverEventArgs?.Feature != _previousHoverEventArgs?.Feature) // only notify when the feature changes
            {
                _previousHoverEventArgs = hoverEventArgs;
                Hover?.Invoke(this, hoverEventArgs);
            }
        }
Example #21
0
        public UnityNUnitServiceProvider(ISolution solution, IPsiModules psiModules, ISymbolCache symbolCache,
                                         IUnitTestElementIdFactory idFactory, IUnitTestElementManager elementManager, NUnitTestProvider provider,
                                         ISettingsStore settingsStore, ISettingsOptimization settingsOptimization, ISettingsCache settingsCache,
                                         UnitTestingCachingService cachingService, IDotNetCoreSdkResolver dotNetCoreSdkResolver,
                                         UnityEditorProtocol editorProtocol,
                                         RunViaUnityEditorStrategy runViaUnityEditorStrategy,
                                         NUnitOutOfProcessUnitTestRunStrategy nUnitOutOfProcessUnitTestRunStrategy)
            : base(solution, psiModules, symbolCache, idFactory, elementManager, provider, settingsStore,
                   settingsOptimization, settingsCache, cachingService, dotNetCoreSdkResolver, nUnitOutOfProcessUnitTestRunStrategy)
        {
            if (solution.GetData(ProjectModelExtensions.ProtocolSolutionKey) == null)
            {
                return;
            }

            myRdUnityModel = solution.GetProtocolSolution().GetRdUnityModel();

            myEditorModel         = editorProtocol.UnityModel;
            myUnityEditorStrategy = runViaUnityEditorStrategy;
        }
Example #22
0
        public bool Draw(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IFeature feature, IStyle istyle,
                         ISymbolCache symbolCache)
        {
            var style = ((VelocityIndicatorStyle)istyle);

            var position = feature.Geometry as Point;
            var dest     = viewport.WorldToScreen(position);

            var zoom = 1 / (float)viewport.Resolution;

            canvas.Translate((float)dest.X, (float)dest.Y);
            //canvas.Scale(zoom, zoom);

            canvas.RotateDegrees((float)viewport.Rotation, 0.0f, 0.0f);

            //#TODO store paint with shader as static
            using (SKPaint paint = new SKPaint
            {
                Style = SKPaintStyle.StrokeAndFill,
                Color = SKColors.Red,
                StrokeWidth = 4
            })
            {
                //if (style.rotation == 0) //Weird artifacting on 0 rotation, no idea why. Seems Skia bug.
                //    style.rotation = 180;
                //
                //SKMatrix shaderTransform =
                //    SKMatrix.CreateScale((float)viewport.Resolution, (float)viewport.Resolution);
                //if (style.rotation != 0)
                //    shaderTransform = SKMatrix.Concat(shaderTransform, SKMatrix.CreateRotationDegrees(-style.rotation));


                canvas.DrawLine(new SKPoint(0, 0), new SKPoint(-style.velocity.X, style.velocity.Y), paint);
            }



            return(true);
        }
Example #23
0
        public bool Draw(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IFeature feature, IStyle style, ISymbolCache symbolCache)
        {
            MultiWeightedVectorStyle multiVectorStyle      = (MultiWeightedVectorStyle)style;
            MultiWeightedLineString  multiWeigthLineString = (MultiWeightedLineString)feature.Geometry;


            var paints = multiVectorStyle.OrderByDescending(o => o.Weight).Select(o => (o.Weight, paint: new SKPaint
            {
                IsAntialias = true,
                IsStroke = true,
                StrokeWidth = (float)(o.Style).Line.Width,
                Color = o.Style.Line.Color.ToSkia((float)layer.Opacity * o.Style.Opacity),
                StrokeCap = o.Style.Line.PenStrokeCap.ToSkia(),
                StrokeJoin = o.Style.Line.StrokeJoin.ToSkia(),
                StrokeMiter = o.Style.Line.StrokeMiterLimit,
                PathEffect = o.Style.Line.PenStyle.ToSkia((float)o.Style.Line.Width, o.Style.Line.DashArray)
            })).ToDictionary(o => o.Weight, o => o.paint);



            foreach (var weigthlineString in multiWeigthLineString)
            {
                using (var path = weigthlineString.LineString.Vertices.ToSkiaPath(viewport, canvas.LocalClipBounds))
                {
                    canvas.DrawPath(path, paints[weigthlineString.Weight]);
                }
            }
            return(true);
        }
Example #24
0
        public void InvokeInfo(Point screenPosition, Point startScreenPosition, float scale, ISymbolCache symbolCache,
                               Action <IWidget> widgetCallback)
        {
            var allWidgets = Layers.Select(l => l.Attribution).Where(a => a != null).Concat(Widgets).ToList();

            // First check if a Widget is clicked. In the current design they are always on top of the map.
            var widget = WidgetTouch.GetWidget(screenPosition, startScreenPosition, scale, allWidgets);

            if (widget != null)
            {
                widgetCallback(widget);
                return;
            }

            if (Info == null)
            {
                return;
            }
            var eventArgs = InfoHelper.GetInfoEventArgs(Viewport, screenPosition, scale, InfoLayers, symbolCache);

            if (eventArgs != null)
            {
                Info?.Invoke(this, eventArgs);
            }
        }
 public XunitServiceProvider(XunitTestProvider provider, IPsiModules psiModuleManager, ISymbolCache cacheManager)
 {
     this.provider = provider;
     this.psiModuleManager = psiModuleManager;
     this.cacheManager = cacheManager;
 }
Example #26
0
        public bool Draw(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IFeature feature, IStyle style, ISymbolCache symbolCache, long iteration)
        {
            try
            {
                var vectorStyle = (VectorStyle)style;
                var opacity = (float)(layer.Opacity * style.Opacity);

                switch (feature)
                {
                    case RectFeature rectFeature:
                        PolygonRenderer.Draw(canvas, viewport, vectorStyle, rectFeature, rectFeature.Rect.ToPolygon(), opacity);
                        break;
                    case PointFeature pointFeature:
                        SymbolStyleRenderer.DrawSymbol(canvas, viewport, layer, pointFeature.Point.X, pointFeature.Point.Y, new SymbolStyle { Outline = vectorStyle.Outline, Fill = vectorStyle.Fill, Line = vectorStyle.Line });
                        break;
                    case GeometryFeature geometryFeature:
                        switch (geometryFeature.Geometry)
                        {
                            case GeometryCollection collection:
                                for (var i = 0; i < collection.NumGeometries; i++)
                                    Draw(canvas, viewport, layer, new GeometryFeature(collection.GetGeometryN(i)), style, symbolCache, iteration);
                                break;
                            case Point point:
                                Draw(canvas, viewport, layer, new PointFeature(point.X, point.Y), style, symbolCache, iteration);
                                break;
                            case Polygon polygon:
                                PolygonRenderer.Draw(canvas, viewport, vectorStyle, feature, polygon, opacity, symbolCache);
                                break;
                            case LineString lineString:
                                LineStringRenderer.Draw(canvas, viewport, vectorStyle, lineString, opacity);
                                break;
                            default:
                                throw new ArgumentException("Unknown geometry of Feature");
                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Error, ex.Message, ex);
            }

            return true;
        }
Example #27
0
        private static bool IsTouchingTakingIntoAccountSymbolStyles(Point point, IFeature feature, IStyle layerStyle,
                                                                    double resolution, ISymbolCache symbolCache, int margin = 0)
        {
            var styles = new List <IStyle>();

            styles.AddRange(ToCollection(layerStyle));
            styles.AddRange(feature.Styles);

            var marginInWorldUnits = margin * resolution;

            if (feature.Geometry is Point)
            {
                foreach (var style in styles)
                {
                    var localStyle = HandleThemeStyle(feature, style);

                    if (localStyle is SymbolStyle symbolStyle)
                    {
                        var scale = symbolStyle.SymbolScale;

                        var size = symbolStyle.BitmapId >= 0
                            ? symbolCache.GetSize(symbolStyle.BitmapId)
                            : new Size(SymbolStyle.DefaultWidth, SymbolStyle.DefaultHeight);

                        // Symbols allways drawn around the center (* 0.5 instead of / 2)
                        var factor  = resolution * scale;
                        var marginX = size.Width * 0.5 * factor;
                        var marginY = size.Height * 0.5 * factor;

                        var box = feature.Geometry.BoundingBox;
                        box = box.Grow(marginX, marginY);
                        if (symbolStyle.SymbolOffset.IsRelative)
                        {
                            box.Offset(
                                size.Width * symbolStyle.SymbolOffset.X * factor,
                                size.Height * symbolStyle.SymbolOffset.Y * factor);
                        }
                        else
                        {
                            box.Offset(symbolStyle.SymbolOffset.X * factor, symbolStyle.SymbolOffset.Y * factor);
                        }
                        if (box.Distance(point) <= marginInWorldUnits)
                        {
                            return(true);
                        }
                    }
                    else if (localStyle is VectorStyle)
                    {
                        var marginX = SymbolStyle.DefaultWidth * 0.5 * resolution;
                        var marginY = SymbolStyle.DefaultHeight * 0.5 * resolution;

                        var box = feature.Geometry.BoundingBox;
                        box = box.Grow(marginX, marginY);
                        if (box.Distance(point) <= marginInWorldUnits)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        if (!(localStyle is LabelStyle)) // I don't intend to support label click, so don't warn
                        {
                            Logger.Log(LogLevel.Warning, $"Feature info not supported for points with {localStyle.GetType()}");
                        }
                    }
                }
            }
            else if (feature.Geometry is LineString || feature.Geometry is MultiLineString)
            {
                foreach (var style in styles)
                {
                    var localStyle = HandleThemeStyle(feature, style);

                    if (localStyle is VectorStyle symbolStyle)
                    {
                        var lineWidthInWorldUnits = symbolStyle.Line.Width * resolution * 0.5;

                        if (feature.Geometry.Distance(point) <= lineWidthInWorldUnits + marginInWorldUnits)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        Logger.Log(LogLevel.Warning, $"Feature info not supported for lines with {localStyle.GetType()}");
                    }
                }
            }
            else
            {
                return(feature.Geometry.Distance(point) <= marginInWorldUnits);
            }
            return(false);
        }
        public bool Draw(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IFeature feature, IStyle istyle,
                         ISymbolCache symbolCache)
        {
            var style = ((MarkerIconStyle)istyle);

            if (style.markerIcon == null)
            {
                return(false);
            }

            var position = feature.Geometry as Point;
            var dest     = viewport.WorldToScreen(position);


            var zoom = 1 / (float)viewport.Resolution;

            canvas.Translate((float)dest.X, (float)dest.Y);
            canvas.Scale(0.7f, 0.7f);

            canvas.RotateDegrees((float)viewport.Rotation, 0.0f, 0.0f);

            SKPoint textOffset = new SKPoint(style.finalSize.Width, style.finalSize.Height / 2);

            if (!string.IsNullOrEmpty(style.text))
            {
                if (zoom > 1.5f)
                {
                    zoom = 1.5f;
                }
                if (zoom < 0.5f)
                {
                    zoom = 0.5f;
                }


                renderPaint.TextSize = 32 * zoom;
                SKRect bounds = new SKRect();
                //renderPaint.GetFontMetrics(out var fontMet);
                //renderPaint.MeasureText(style.text, ref bounds);
                var textHeight = (style.finalSize.Height / 2);
                //if (zoom < 1.5f)
                //{
                //    textHeight += bounds.Height/2;
                //}

                textOffset = new SKPoint(style.finalSize.Width, textHeight);
            }


            if (style.shadow)
            {
                var targetRect   = style.finalRect;
                var shadowOffset = style.ShadowOffset;

                targetRect.Offset(shadowOffset);
                renderPaint.Color       = new SKColor(0, 0, 0, (byte)(style.Opacity * 0.8f * 255));
                renderPaint.ColorFilter = SkiaSharp.SKColorFilter.CreateLighting(renderPaint.Color, new SKColor(0, 0, 0));

                if (style.SymbolRotation != 0)
                {
                    canvas.RotateDegrees(style.SymbolRotation, 0.0f, 0.0f);
                }
                canvas.DrawImage(style.markerIcon, targetRect, renderPaint);
                if (style.SymbolRotation != 0)
                {
                    canvas.RotateDegrees(-style.SymbolRotation, 0.0f, 0.0f);                            //No rotation for text
                }
                //canvas.DrawRect(targetRect, renderPaint);

                if (!string.IsNullOrEmpty(style.text) && zoom > 1)
                {
                    canvas.DrawText(style.text, textOffset + style.ShadowOffset, renderPaint);
                }
            }



            renderPaint.Color       = SKColor.Empty.WithAlpha((byte)(style.Opacity * 255));
            renderPaint.ColorFilter = style.colorFilter;
            if (style.SymbolRotation != 0)
            {
                canvas.RotateDegrees(style.SymbolRotation, 0.0f, 0.0f);
            }
            canvas.DrawImage(style.markerIcon, style.finalRect, renderPaint);
            if (!string.IsNullOrEmpty(style.text))
            {
                if (style.SymbolRotation != 0)
                {
                    canvas.RotateDegrees(-style.SymbolRotation, 0.0f, 0.0f);                            //No rotation for text
                }
                renderPaint.Color       = style.color.WithAlpha((byte)(style.Opacity * 255));
                renderPaint.ColorFilter = null;
                canvas.DrawText(style.text, textOffset, renderPaint);
            }


            return(true);
        }
Example #29
0
 public PriceCache(ISymbolCache symbolCache)
 {
     _symbolCache = symbolCache;
 }
Example #30
0
        public bool Draw(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IFeature feature, Styles.IStyle style, ISymbolCache symbolCache, long iteration)
        {
            var centroid = feature.Extent?.Centroid;

            if (centroid is null)
            {
                return(false);
            }

            var calloutStyle = (CalloutStyle)style;

            // Todo: Use opacity
            var opacity = (float)(layer.Opacity * style.Opacity);

            var(x, y) = viewport.WorldToScreenXY(centroid.X, centroid.Y);

            if (calloutStyle.BitmapId < 0 || calloutStyle.Invalidated)
            {
                if (calloutStyle.Content < 0 && calloutStyle.Type == CalloutType.Custom)
                {
                    return(false);
                }

                if (calloutStyle.Invalidated)
                {
                    UpdateContent(calloutStyle);
                }

                RenderCallout(calloutStyle);
            }

            // Now we have the complete callout rendered, so we could draw it
            if (calloutStyle.BitmapId < 0)
            {
                return(false);
            }

            var picture = (SKPicture)BitmapRegistry.Instance.Get(calloutStyle.BitmapId);

            // Calc offset (relative or absolute)
            MPoint symbolOffset = calloutStyle.SymbolOffset.ToPoint();

            if (calloutStyle.SymbolOffset.IsRelative)
            {
                symbolOffset.X *= picture.CullRect.Width;
                symbolOffset.Y *= picture.CullRect.Height;
            }

            var rotation = (float)calloutStyle.SymbolRotation;

            if (viewport.Rotation != 0)
            {
                if (calloutStyle.RotateWithMap)
                {
                    rotation += (float)viewport.Rotation;
                }
                if (calloutStyle.SymbolOffsetRotatesWithMap)
                {
                    symbolOffset = symbolOffset.Rotate(-viewport.Rotation);
                }
            }

            // Save state of the canvas, so we could move and rotate the canvas
            canvas.Save();

            // Move 0/0 to the Anchor point of Callout
            canvas.Translate((float)(x - symbolOffset.X), (float)(y - symbolOffset.Y));
            canvas.Scale((float)calloutStyle.SymbolScale, (float)calloutStyle.SymbolScale);

            // 0/0 are assumed at center of image, but Picture has 0/0 at left top position
            canvas.RotateDegrees(rotation);
            canvas.Translate((float)calloutStyle.Offset.X, (float)calloutStyle.Offset.Y);

            using var skPaint = new SKPaint()
                  {
                      IsAntialias = true
                  };
            canvas.DrawPicture(picture, skPaint);

            canvas.Restore();

            return(true);
        }
Example #31
0
 public Cache(ISymbolCache cache)
 {
   _cache = cache;
 }
 public Cache(ISymbolCache cache)
 {
     this._cache = cache;
 }
Example #33
0
 public ForwardedTypesFilter(ISymbolCache symbolCache)
 {
     mySymbolCache = symbolCache;
 }
        public bool Draw(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IFeature feature, IStyle istyle,
                         ISymbolCache symbolCache)
        {
            var style = ((TiledBitmapStyle)istyle);

            if (style.image == null)
            {
                return(false);
            }

            var position = feature.Geometry.BoundingBox.Centroid;
            var dest     = viewport.WorldToScreen(position);


            var zoom = 1 / (float)viewport.Resolution;

            canvas.Translate((float)dest.X, (float)dest.Y);
            canvas.Scale(zoom, zoom);

            canvas.RotateDegrees((float)viewport.Rotation, 0.0f, 0.0f);
            if (style.rotation != 0)
            {
                canvas.RotateDegrees(style.rotation, 0.0f, 0.0f);
            }

            //#TODO store paint with shader in the style
            using (SKPaint paint = new SKPaint())
            {
                if (style.rotation == 0) //Weird artifacting on 0 rotation, no idea why. Seems Skia bug.
                {
                    style.rotation = 180;
                }

                SKMatrix shaderTransform =
                    SKMatrix.CreateScale((float)viewport.Resolution, (float)viewport.Resolution);
                if (style.rotation != 0)
                {
                    shaderTransform = SKMatrix.Concat(shaderTransform, SKMatrix.CreateRotationDegrees(-style.rotation));
                }



                paint.Shader      = SKShader.CreateImage(style.image, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat, shaderTransform);
                paint.ColorFilter = style.colorFilter;

                //style.image.Encode().SaveTo(File.Create($"P:/{style.image.UniqueId}.png"));

                if (style.ellipse)
                {
                    canvas.DrawOval(0, 0, style.rect.Right, style.rect.Bottom, paint);
                }
                else
                {
                    canvas.DrawRect(style.rect, paint);
                }

                if (style.border)
                {
                    var borderPaint = new SKPaint
                    {
                        Style = SKPaintStyle.Stroke,
                        Color = style.color
                    };


                    if (style.ellipse)
                    {
                        canvas.DrawOval(0, 0, style.rect.Right, style.rect.Bottom, borderPaint);
                    }
                    else
                    {
                        canvas.DrawRect(style.rect, borderPaint);
                    }
                }
            }



            return(true);
        }
Example #35
0
        public bool Draw(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IFeature feature, IStyle style, ISymbolCache symbolCache)
        {
            if (!(feature.Geometry is global::Mapsui.Geometries.Point worldPoint))
            {
                return(false);
            }

            var screenPoint = viewport.WorldToScreen(worldPoint);
            var color       = new SKColor((byte)rnd.Next(0, 256), (byte)rnd.Next(0, 256), (byte)rnd.Next(0, 256), (byte)(256.0 * layer.Opacity * style.Opacity));
            var colored     = new SKPaint()
            {
                Color = color, IsAntialias = true
            };
            var black = new SKPaint()
            {
                Color = SKColors.Black, IsAntialias = true
            };

            canvas.Translate((float)screenPoint.X, (float)screenPoint.Y);
            canvas.DrawCircle(0, 0, 15, colored);
            canvas.DrawCircle(-8, -12, 8, colored);
            canvas.DrawCircle(8, -12, 8, colored);
            canvas.DrawCircle(8, -8, 2, black);
            canvas.DrawCircle(-8, -8, 2, black);
            using (var path = new SKPath())
            {
                path.ArcTo(new SKRect(-8, 2, 8, 10), 25, 135, true);
                canvas.DrawPath(path, new SKPaint()
                {
                    Style = SKPaintStyle.Stroke, Color = SKColors.Black, IsAntialias = true
                });
            }

            return(true);
        }