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); }
public void UpdateCurrentTier(ITierInfo newTier) { // Set new current tier _currentTier = newTier; // Reinitialize the visualization Init(); }
public SimulationVisualTier3D(ITierInfo tier, DetailLevel detailLevel) : base(tier) { _tier = tier; var visual = new BoxVisual3D { Fill = VisualizationConstants.BrushTierVisual, Center = new Point3D( (_tier.GetInfoTLX() + _tier.GetInfoLength()) / 2.0, (_tier.GetInfoTLY() + _tier.GetInfoWidth()) / 2.0, _tier.GetInfoZ() - TIER_HEIGHT / 2.0), Length = _tier.GetInfoLength(), Width = _tier.GetInfoWidth(), Height = TIER_HEIGHT }; Children.Add(visual); }
public void UpdateTransformation(bool overrideUpdate) { if (_moveableObject.GetInfoChanged() || overrideUpdate) { // Fetch necessary information ITierInfo tier = _moveableObject.GetInfoCurrentTier(); if (tier != null) { // Get position double xOffset = tier.GetInfoTLX() + _moveableObject.GetInfoCenterX(); double yOffset = tier.GetInfoTLY() + _moveableObject.GetInfoCenterY(); double zOffset = tier.GetInfoZ() + GetZ(); double orientationInDegrees = _moveableObject.GetInfoOrientation() / (2 * Math.PI) * 360; //// Fetch transformers // TODO is it really necessary to "new" the transformer objects? //Transform3DGroup tg = (Transform3DGroup)Transform; //TranslateTransform3D positionTransform = (TranslateTransform3D)tg.Children.First(); //RotateTransform3D rotationTransform = (RotateTransform3D)tg.Children.Last(); //// Set new information //positionTransform.OffsetX = xOffset; //positionTransform.OffsetY = yOffset; //positionTransform.OffsetZ = zOffset; // Update visual object itself Transform3DGroup tg = new Transform3DGroup(); tg.Children.Add(new TranslateTransform3D(xOffset, yOffset, zOffset)); tg.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), _moveableObject.GetInfoOrientation() / (2 * Math.PI) * 360), new Point3D(xOffset, yOffset, zOffset))); Transform = tg; // Update onboard camera, if attached if (_onboardCameraAttached) { double angle = _moveableObject.GetInfoOrientation() + 0.5 * Math.PI; CameraHelper.AnimateTo( _camera, // The camera to adjust new Point3D(xOffset, yOffset, tier.GetInfoZ() + _height + 0.05), // The position of the camera new Vector3D(Math.Sin(angle), -Math.Cos(angle), 0), // The direction the camera is facing new Vector3D(0, 0, 1), // The roll of the camera - just keep it upright 0); // The animation time } } } // Update meta info UpdateMetaInfo(); }
public SimulationAnimation2D( IInstanceInfo instance, Dispatcher uiDispatcher, SimulationAnimationConfig config, Func <bool> heatModeEnabled, Func <BotColorMode> botColorModeGetter, Canvas contentControl, Grid contentHost, MouseButtonEventHandler elementClickAction, SimulationInfoManager infoControl, ITierInfo currentTier) : base(instance, uiDispatcher, config, botColorModeGetter, heatModeEnabled) { _contentControl = contentControl; _contentHost = contentHost; _currentTier = instance.GetInfoTiers().First(); _elementClickAction = elementClickAction; _infoControl = infoControl; _currentTier = currentTier; }
/// <summary> /// Removes all elements in scope from the instance. /// </summary> /// <param name="theTier">The tier to remove the elements from.</param> /// <param name="xMin">The min x-value of the scope.</param> /// <param name="xMax">The max x-value of the scope.</param> /// <param name="yMin">The min y-value of the scope.</param> /// <param name="yMax">The max y-value of the scope.</param> public void ModRemoveWaypoints(ITierInfo theTier, double xMin, double yMin, double xMax, double yMax) { Tier tier = theTier as Tier; // Remove waypoints List <Waypoint> remWaypoints = Waypoints.Where(w => w.Tier == tier && xMin <= w.X && w.X <= xMax && yMin <= w.Y && w.Y <= yMax).ToList(); // Remove all of them foreach (var waypoint in remWaypoints) { // Remove the waypoint - the waypoint graph handles all cascading path removals waypoint.Tier.RemoveWaypoint(waypoint); // Remove all elements that were connected to the waypoint foreach (var guard in Semaphores.SelectMany(s => s.Guards).Where(guard => guard.From == waypoint || guard.To == waypoint).ToArray()) { guard.Semaphore.UnregisterGuard(guard); if (guard.Semaphore.Guards.Count() == 0) { Semaphores.Remove(guard.Semaphore); } } foreach (var station in InputStations.Where(s => s.Waypoint == waypoint).ToArray()) { station.Tier.RemoveInputStation(station); InputStations.Remove(station); } foreach (var station in OutputStations.Where(s => s.Waypoint == waypoint).ToArray()) { station.Tier.RemoveOutputStation(station); OutputStations.Remove(station); } foreach (var pod in Pods.Where(p => p.Waypoint == waypoint).ToArray()) { pod.Tier.RemovePod(pod); Pods.Remove(pod); } foreach (var elevator in Elevators.Where(e => e.ConnectedPoints.Contains(waypoint))) { elevator.UnregisterPoint(waypoint); if (elevator.ConnectedPoints.Count == 0) { Elevators.Remove(elevator); } } // Make sure it is not on the list of storage locations anymore if (waypoint.PodStorageLocation) { ResourceManager.RemovePodStorageLocation(waypoint); } // Finally remove from the overall waypoint list Waypoints.Remove(waypoint); } // Also remove movables in scope List <Bot> remBots = Bots.Where(b => b.Tier == tier && xMin <= b.X && b.X <= xMax && yMin <= b.Y && b.Y <= yMax).ToList(); foreach (var bot in remBots) { Bots.Remove(bot); bot.Tier.RemoveBot(bot); } List <Pod> remPods = Pods.Where(p => p.Tier == tier && xMin <= p.X && p.X <= xMax && yMin <= p.Y && p.Y <= yMax).ToList(); foreach (var pod in remPods) { Pods.Remove(pod); pod.Tier.RemovePod(pod); } }