Пример #1
0
        /// <summary>
        /// Creates a new renderer.
        /// </summary>
        /// <param name="config">Contains all necessary information.</param>
        public HeatMapRenderer(HeatMapRendererConfiguration config)
        {
            if (config.UseTileCount)
            {
                TileLengthX = config.Tier.GetInfoLength() / config.TilesX;
            }
            else
            {
                TileLengthX = config.Tier.GetInfoLength() / Math.Floor(config.Tier.GetInfoLength() / config.TileLengthX);
            }
            int tilesY = (int)Math.Ceiling(config.Tier.GetInfoWidth() / TileLengthX);

            TileLengthY = config.Tier.GetInfoWidth() / tilesY;
            int xResolution = (int)(Math.Ceiling(config.Tier.GetInfoLength() / TileLengthX));
            int yResolution = (int)(Math.Ceiling(config.Tier.GetInfoWidth() / TileLengthY));

            _heatmap        = new double[xResolution, yResolution];
            _config         = config;
            _dataFile       = config.DataFile;
            Radius          = TileLengthX * config.RadiusRelativeToTileLength;
            _tier           = config.Tier;
            _contentControl = config.ContentControl;
            _transformer    = new Transformation2D(xResolution, yResolution, config.ContentHost.Width, config.ContentHost.Height);
            _finishCallback = config.FinishedCallback;
            _logger         = config.Logger;
        }
Пример #2
0
 public SimulationVisualPod2D(
     IPodInfo pod,
     DetailLevel detailLevel,
     Transformation2D transformer,
     double strokeThickness,
     Func <bool> heatModeEnabled,
     MouseButtonEventHandler elementClickAction,
     SimulationAnimation2D controller)
     : base(pod, detailLevel, transformer, strokeThickness, elementClickAction, controller)
 {
     _pod             = pod;
     _heatModeEnabled = heatModeEnabled;
     // Build geometry
     _geometry =
         new RectangleGeometry(
             new Rect(
                 new Point(-_transformer.ProjectXLength(_pod.GetInfoRadius()), -_transformer.ProjectYLength(_pod.GetInfoRadius())),
                 new Size(_transformer.ProjectXLength(_pod.GetInfoRadius() * 2), _transformer.ProjectYLength(_pod.GetInfoRadius() * 2))));
     // Paint it
     Fill            = VisualizationConstants.BrushPodVisual;
     Cursor          = System.Windows.Input.Cursors.Hand;
     MouseDown      += _elementClickAction;
     Stroke          = VisualizationConstants.BrushOutline;
     StrokeThickness = StrokeThicknessReference;
     // Initialize
     Init();
 }
Пример #3
0
        public static Image GenerateWaypointGraphImage(ITierInfo tier, Transformation2D transformer, double strokeThickness)
        {
            // Init image
            Image image = new Image();

            image.Stretch             = Stretch.Fill;
            image.SnapsToDevicePixels = true;
            RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.NearestNeighbor);
            WriteableBitmap writeableBitmap = BitmapFactory.New((int)transformer.ProjectionXLength, (int)transformer.ProjectionYLength);
            // Create complete waypoint graph
            SymmetricKeyDictionary <IWaypointInfo, bool> connections = new SymmetricKeyDictionary <IWaypointInfo, bool>();

            foreach (var waypoint in tier.GetInfoWaypoints())
            {
                // Create and remember connections (while doing so bidirectional connections are implicitly combined to one)
                foreach (var otherWP in waypoint.GetInfoConnectedWaypoints())
                {
                    connections[waypoint, otherWP] = true;
                }
            }
            // Create connections
            foreach (var connection in connections.KeysCombined)
            {
                writeableBitmap.DrawLineAa(
                    (int)transformer.ProjectX(connection.Item1.GetInfoCenterX()),
                    (int)transformer.ProjectY(connection.Item1.GetInfoCenterY()),
                    (int)transformer.ProjectX(connection.Item2.GetInfoCenterX()),
                    (int)transformer.ProjectY(connection.Item2.GetInfoCenterY()),
                    Colors.Black,
                    (int)Math.Ceiling(strokeThickness * 3));
            }
            // Return it
            image.Source = writeableBitmap;
            return(image);
        }
Пример #4
0
        public SimulationVisualWaypoint2D(
            IWaypointInfo waypoint,
            DetailLevel detailLevel,
            Transformation2D transformer,
            double strokeThickness,
            MouseButtonEventHandler elementClickAction,
            SimulationAnimation2D controller)
            : base(waypoint, detailLevel, transformer, strokeThickness, elementClickAction, controller)
        {
            _waypoint = waypoint;
            // Create waypoint dot
            EllipseGeometry ellipse =
                new EllipseGeometry(
                    new Point(_transformer.ProjectX(waypoint.GetInfoCenterX()), _transformer.ProjectY(waypoint.GetInfoCenterY())),
                    _transformer.ProjectXLength(waypoint.GetInfoLength() / 2.0), _transformer.ProjectYLength(waypoint.GetInfoLength() / 2.0));

            _geometry.Children.Add(ellipse);
            // Add connections
            foreach (var otherWP in waypoint.GetInfoConnectedWaypoints())
            {
                Point  start  = new Point(_transformer.ProjectX(waypoint.GetInfoCenterX()), _transformer.ProjectY(waypoint.GetInfoCenterY()));
                Point  end    = new Point(_transformer.ProjectX(otherWP.GetInfoCenterX()), _transformer.ProjectY(otherWP.GetInfoCenterY()));
                double length = ArrowLineGeometryGenerator.GetDistanceBetweenPoints(start, end);
                var    geom   = ArrowLineGeometryGenerator.GenerateArrowGeometry(ArrowEnds.End, start, end, 45, 0.2 * length);
                _geometry.Children.Add(geom);
            }
            // Paint it
            Fill            = VisualizationConstants.BrushWaypointVisual;
            Cursor          = System.Windows.Input.Cursors.Hand;
            MouseDown      += _elementClickAction;
            Stroke          = VisualizationConstants.BrushOutline;
            StrokeThickness = StrokeThicknessReference;
        }
Пример #5
0
        public SimulationVisualBot2D(
            IBotInfo bot,
            DetailLevel detailLevel,
            Transformation2D transformer,
            double strokeThickness,
            MouseButtonEventHandler elementClickAction,
            SimulationAnimation2D controller)
            : base(bot, detailLevel, transformer, strokeThickness, elementClickAction, controller)
        {
            _bot = bot;
            // Build geometry
            _geometry.Children.Add(new EllipseGeometry(
                                       new Point(0, 0),
                                       _transformer.ProjectXLength(_bot.GetInfoRadius()), _transformer.ProjectYLength(_bot.GetInfoRadius())));
            // Add orientation marker
            double orientationMarkerX = _transformer.ProjectXLength(_bot.GetInfoRadius()) * Math.Cos(0);
            double orientationMarkerY = _transformer.ProjectXLength(_bot.GetInfoRadius()) * Math.Sin(0);

            _geometry.Children.Add(new LineGeometry(
                                       new Point(0, 0),
                                       new Point(orientationMarkerX, orientationMarkerY)));
            // Paint it
            Fill            = VisualizationConstants.BrushBotVisual;
            Cursor          = System.Windows.Input.Cursors.Hand;
            MouseDown      += _elementClickAction;
            Stroke          = VisualizationConstants.BrushOutline;
            StrokeThickness = StrokeThicknessReference;
            // Initialize
            Init();
        }
Пример #6
0
 public SimulationVisual2D(DetailLevel detailLevel, Transformation2D transformer, double strokeThickness, MouseButtonEventHandler elementClickAction, SimulationAnimation2D controller)
 {
     _detailLevel             = detailLevel;
     _transformer             = transformer;
     StrokeThicknessReference = strokeThickness;
     _elementClickAction      = elementClickAction;
     _animationController     = controller;
 }
Пример #7
0
 public SimulationVisualMovable2D(
     IMovableObjectInfo moveableObject,
     DetailLevel detailLevel,
     Transformation2D transformer,
     double strokeThickness,
     MouseButtonEventHandler elementClickAction,
     SimulationAnimation2D controller)
     : base(detailLevel, transformer, strokeThickness, elementClickAction, controller)
 {
     _moveableObject = moveableObject;
 }
Пример #8
0
 public void UpdateTransformation(bool overrideUpdate)
 {
     if (_moveableObject.GetInfoChanged() || overrideUpdate)
     {
         // Set new position
         Canvas.SetLeft(this, _transformer.ProjectX(_moveableObject.GetInfoCenterX()));
         Canvas.SetTop(this, _transformer.ProjectY(_moveableObject.GetInfoCenterY()));
         // Set new orientation
         this.RenderTransform = new RotateTransform(Transformation2D.ProjectOrientation(_moveableObject.GetInfoOrientation()));
     }
     // Update meta info
     UpdateMetaInfo();
 }
Пример #9
0
 public SimulationVisualPathMarker2D(
     IBotInfo bot,
     DetailLevel detailLevel,
     Transformation2D transformer,
     double strokeThickness,
     MouseButtonEventHandler elementClickAction,
     SimulationAnimation2D controller)
     : base(detailLevel, transformer, strokeThickness, elementClickAction, controller)
 {
     _bot = bot;
     // Init geometry
     Stroke          = VisualizationConstants.BrushGoalMarker;
     StrokeThickness = StrokeThicknessReference * VisualizationConstants.PATH_MARKER_STROKE_THICKNESS_FACTOR;
 }
Пример #10
0
 public SimulationVisualDestinationMarker2D(
     IBotInfo bot,
     DetailLevel detailLevel,
     Transformation2D transformer,
     double strokeThickness,
     MouseButtonEventHandler elementClickAction,
     SimulationAnimation2D controller)
     : base(detailLevel, transformer, strokeThickness, elementClickAction, controller)
 {
     _bot = bot;
     // Init geometry
     _geometry       = new LineGeometry(new Point(0, 0), new Point(0, 0));
     Stroke          = VisualizationConstants.BrushDestinationMarker;
     StrokeThickness = StrokeThicknessReference * VisualizationConstants.DESTINATION_MARKER_STROKE_THICKNESS_FACTOR;
 }
Пример #11
0
 public SimulationVisualGuard2D(
     IGuardInfo guard,
     DetailLevel detailLevel,
     Transformation2D transformer,
     double strokeThickness,
     MouseButtonEventHandler elementClickAction,
     SimulationAnimation2D controller)
     : base(detailLevel, transformer, strokeThickness, elementClickAction, controller)
 {
     _guard = guard;
     // Create waypoint dot
     _geometry =
         new EllipseGeometry(
             new Point(_transformer.ProjectX(guard.GetInfoCenterX()), _transformer.ProjectY(guard.GetInfoCenterY())),
             _transformer.ProjectXLength(guard.GetInfoLength() / 2.0), _transformer.ProjectYLength(guard.GetInfoLength() / 2.0));
     // Paint it
     Fill            = _guard.GetInfoIsBarrier() ? VisualizationConstants.BrushSemaphoreEntry : VisualizationConstants.BrushSemaphoreGuard;
     Cursor          = System.Windows.Input.Cursors.Hand;
     MouseDown      += _elementClickAction;
     Stroke          = VisualizationConstants.BrushOutline;
     StrokeThickness = StrokeThicknessReference;
 }
Пример #12
0
 public SimulationVisualOutputStation2D(
     IOutputStationInfo oStation,
     DetailLevel detailLevel,
     Transformation2D transformer,
     double strokeThickness,
     MouseButtonEventHandler elementClickAction,
     SimulationAnimation2D controller)
     : base(oStation, detailLevel, transformer, strokeThickness, elementClickAction, controller)
 {
     _oStation = oStation;
     // Build geometry
     _geometry =
         new RectangleGeometry(
             new Rect(
                 new Point(_transformer.ProjectX(_oStation.GetInfoTLX()), _transformer.ProjectY(_oStation.GetInfoTLY())),
                 new Size(_transformer.ProjectXLength(_oStation.GetInfoLength()), _transformer.ProjectYLength(_oStation.GetInfoWidth()))));
     // Paint it
     Fill            = VisualizationConstants.BrushOutputStationVisual;
     Cursor          = System.Windows.Input.Cursors.Hand;
     MouseDown      += _elementClickAction;
     Stroke          = VisualizationConstants.BrushOutline;
     StrokeThickness = StrokeThicknessReference;
 }
Пример #13
0
        public SimulationVisualElevatorEntrance2D(
            IWaypointInfo waypoint,
            DetailLevel detailLevel,
            Transformation2D transformer,
            double strokeThickness,
            MouseButtonEventHandler elementClickAction,
            SimulationAnimation2D controller)
            : base(waypoint, detailLevel, transformer, strokeThickness, elementClickAction, controller)
        {
            _waypoint = waypoint;
            // Create waypoint dot
            EllipseGeometry ellipse =
                new EllipseGeometry(
                    new Point(_transformer.ProjectX(waypoint.GetInfoCenterX()), _transformer.ProjectY(waypoint.GetInfoCenterY())),
                    _transformer.ProjectXLength(waypoint.GetInfoLength() / 2.0 * SIZE_FACTOR), _transformer.ProjectYLength(waypoint.GetInfoLength() / 2.0 * SIZE_FACTOR));

            _geometry.Children.Add(ellipse);
            // Paint it
            Fill            = VisualizationConstants.BrushElevatorEntranceVisual;
            Cursor          = System.Windows.Input.Cursors.Hand;
            MouseDown      += _elementClickAction;
            Stroke          = VisualizationConstants.BrushOutline;
            StrokeThickness = StrokeThicknessReference;
        }
Пример #14
0
        public override void Init()
        {
            // Canvas size and transformation
            _contentHost.Width  = _currentTier.GetInfoLength() * DEFAULT_TRANSFORMATION_FACTOR;
            _contentHost.Height = _currentTier.GetInfoWidth() * DEFAULT_TRANSFORMATION_FACTOR;
            _transformer        = new Transformation2D(_currentTier.GetInfoLength(), _currentTier.GetInfoWidth(), _contentHost.Width, _contentHost.Height);
            // Remove old visuals (if any)
            foreach (var visual in _contentControl.Children.OfType <SimulationVisual2D>().Cast <UIElement>().ToArray())
            {
                Remove(visual);
            }
            foreach (var visual in _contentControl.Children.OfType <Image>().Cast <UIElement>().ToArray())
            {
                Remove(visual);
            }
            // --> Init visuals
            double waypointRadius  = _instance.GetInfoTiers().First().GetInfoWaypoints().First().GetInfoLength() / 2.0;
            double strokeThickness = 0.2 * Math.Min(_transformer.ProjectXLength(waypointRadius), _transformer.ProjectYLength(waypointRadius));

            // Add bots
            _botVisuals = _currentTier.GetInfoBots().ToDictionary(k => k, v =>
            {
                SimulationVisualBot2D botVisual = new SimulationVisualBot2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this);
                _infoControl.Register(v, botVisual);
                return(botVisual);
            });
            // Add non-visual bots
            _shadowBotVisuals = _instance.GetInfoBots().Except(_botVisuals.Keys).ToDictionary(k => k, v =>
            {
                SimulationVisualBot2D botVisual = new SimulationVisualBot2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this);
                _infoControl.Register(v, botVisual);
                return(botVisual);
            });
            // Add pods
            _podVisuals = _currentTier.GetInfoPods().ToDictionary(k => k, v =>
            {
                SimulationVisualPod2D podVisual = new SimulationVisualPod2D(v, _config.DetailLevel, _transformer, strokeThickness, _heatModeEnabled, _elementClickAction, this);
                _infoControl.Register(v, podVisual);
                return(podVisual);
            });
            // Add non-visual bots
            _shadowPodVisuals = _instance.GetInfoPods().Except(_podVisuals.Keys).ToDictionary(k => k, v =>
            {
                SimulationVisualPod2D podVisual = new SimulationVisualPod2D(v, _config.DetailLevel, _transformer, strokeThickness, _heatModeEnabled, _elementClickAction, this);
                _infoControl.Register(v, podVisual);
                return(podVisual);
            });
            // Add input-stations
            _iStationVisuals = _currentTier.GetInfoInputStations().ToDictionary(k => k, v =>
            {
                SimulationVisualInputStation2D iStationVisual = new SimulationVisualInputStation2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this);
                _infoControl.Register(v, iStationVisual);
                return(iStationVisual);
            });
            // Add output-stations
            _oStationVisuals = _currentTier.GetInfoOutputStations().ToDictionary(k => k, v =>
            {
                SimulationVisualOutputStation2D oStationVisual = new SimulationVisualOutputStation2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this);
                _infoControl.Register(v, oStationVisual);
                return(oStationVisual);
            });
            // Add elevator entrances
            _elevatorEntranceVisuals = _instance.GetInfoElevators().SelectMany(e => e.GetInfoWaypoints()).Where(wp => wp.GetInfoCurrentTier() == _currentTier).ToDictionary(k => k, v =>
            {
                SimulationVisualElevatorEntrance2D elevatorEntranceVisual = new SimulationVisualElevatorEntrance2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this);
                //_infoControl.Register(v, elevatorEntranceVisual); // TODO enable again
                return(elevatorEntranceVisual);
            });
            if (_config.DetailLevel >= DetailLevel.Debug)
            {
                // Refine level of detail
                if (_config.DetailLevel >= DetailLevel.Full)
                {
                    // Add each waypoint
                    _waypointVisuals = _currentTier.GetInfoWaypoints().ToDictionary(k => k, v =>
                    {
                        SimulationVisualWaypoint2D waypointVisual = new SimulationVisualWaypoint2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this);
                        _infoControl.Register(v, waypointVisual);
                        return(waypointVisual);
                    });
                }
                else
                {
                    // Only add the complete waypoint graph without explicit information about each waypoint
                    _waypointGraphVisual = SimulationVisualWaypointGraph2D.GenerateWaypointGraphImage(_currentTier, _transformer, strokeThickness);
                }
                // Add guards
                _guardVisuals = _currentTier.GetInfoGuards().ToDictionary(k => k, v =>
                {
                    SimulationVisualGuard2D guardVisual = new SimulationVisualGuard2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this);
                    _infoControl.Register(v, guardVisual);
                    return(guardVisual);
                });
            }
            // Add if desired
            if (_config.DrawGoal)
            {
                // Add goal markers
                _botGoalMarkerVisuals = _currentTier.GetInfoBots().ToDictionary(k => k, v =>
                {
                    return(new SimulationVisualGoalMarker2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this));
                });
                // Add non-visual goal markers
                _shadowBotGoalMarkerVisuals = _instance.GetInfoBots().Except(_botGoalMarkerVisuals.Keys).ToDictionary(k => k, v =>
                {
                    return(new SimulationVisualGoalMarker2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this));
                });
            }
            // Add if desired
            if (_config.DrawDestination)
            {
                // Add destination markers
                _botDestinationMarkerVisuals = _currentTier.GetInfoBots().ToDictionary(k => k, v =>
                {
                    return(new SimulationVisualDestinationMarker2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this));
                });
                // Add non-visual destination markers
                _shadowBotDestinationMarkerVisuals = _instance.GetInfoBots().Except(_botDestinationMarkerVisuals.Keys).ToDictionary(k => k, v =>
                {
                    return(new SimulationVisualDestinationMarker2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this));
                });
            }
            // Add if desired
            if (_config.DrawPath)
            {
                // Add path markers
                _botPathVisuals = _currentTier.GetInfoBots().ToDictionary(k => k, v =>
                {
                    return(new SimulationVisualPathMarker2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this));
                });
                // Add non-visual path markers
                _shadowBotPathVisuals = _instance.GetInfoBots().Except(_botPathVisuals.Keys).ToDictionary(k => k, v =>
                {
                    return(new SimulationVisualPathMarker2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this));
                });
            }
            // --> Add the generated elements to the GUI
            // Add new waypoint visuals to the view
            if (_config.DetailLevel >= DetailLevel.Debug)
            {
                if (_config.DetailLevel >= DetailLevel.Full)
                {
                    foreach (var waypoint in _currentTier.GetInfoWaypoints())
                    {
                        Add(_waypointVisuals[waypoint]);
                    }
                }
                else
                {
                    Add(_waypointGraphVisual);
                }
            }
            // Add new iStation visuals to the view
            foreach (var iStation in _currentTier.GetInfoInputStations())
            {
                Add(_iStationVisuals[iStation]);
            }
            // Add new oStation visuals to the view
            foreach (var oStation in _currentTier.GetInfoOutputStations())
            {
                Add(_oStationVisuals[oStation]);
            }
            foreach (var elevatorEntrance in _elevatorEntranceVisuals.Keys)
            {
                Add(_elevatorEntranceVisuals[elevatorEntrance]);
            }
            // Add new path marker visuals to the view
            if (_config.DrawPath)
            {
                foreach (var bot in _currentTier.GetInfoBots())
                {
                    Add(_botPathVisuals[bot]);
                }
            }
            // Add new destination marker visuals to the view
            if (_config.DrawDestination)
            {
                foreach (var bot in _currentTier.GetInfoBots())
                {
                    Add(_botDestinationMarkerVisuals[bot]);
                }
            }
            // Add new pod visuals to the view
            foreach (var pod in _currentTier.GetInfoPods())
            {
                Add(_podVisuals[pod]);
            }
            // Add new bot visuals to the view
            foreach (var bot in _currentTier.GetInfoBots())
            {
                Add(_botVisuals[bot]);
            }
            // Add new goal marker visuals to the view
            if (_config.DrawGoal)
            {
                foreach (var bot in _currentTier.GetInfoBots())
                {
                    Add(_botGoalMarkerVisuals[bot]);
                }
            }
            // Add new guard visuals to the view
            if (_config.DetailLevel >= DetailLevel.Debug)
            {
                foreach (var guard in _currentTier.GetInfoGuards())
                {
                    Add(_guardVisuals[guard]);
                }
            }
            // Update the view
            Update(true);
        }