protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     System.Windows.Media.Media3D.Size3D size = (agentBase as BusAgent).Size;
     drawingContext.PushTransform(new TranslateTransform(Location.X - size.X / 4 , Location.Y));
     drawingContext.PushTransform(new RotateTransform((agentBase as BusAgent).Angle));
     drawingContext.DrawRectangle(GetGroupColor(agentBase.Group), null, new Rect(-size.X / 4, -size.Y / 2, size.X, size.Y));
     drawingContext.DrawRectangle(Brushes.LightBlue, null, new Rect(size.X / 4 * 3 - 2, -size.Y / 2, 2, size.Y));
     drawingContext.Pop();
     drawingContext.Pop();
 }
 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     System.Windows.Media.Media3D.Size3D size = (agentBase as TrainAgent).Size;
     for (int i = 0; i < (agentBase as TrainAgent).Positions.Length; i++)
     {
         if ((agentBase as TrainAgent).NeedDraw[i] == true)
         {
             Point position = (agentBase as TrainAgent).Positions[i];
             drawingContext.PushTransform(new TranslateTransform(position.X, position.Y));
             drawingContext.PushTransform(new RotateTransform((agentBase as TrainAgent).Angles[i]));
             drawingContext.DrawRectangle(GetGroupColor(agentBase.Group), null, new Rect(-size.X / 2, -size.Y / 2, size.X, size.Y));
             drawingContext.Pop();
             drawingContext.Pop();
         }
     }
 }
Exemple #3
0
 public static void reverseStack(System.Collections.Generic.Stack<int> s)
 {
     if (s.Count != 0)
     {
         int data = s.Pop();
         reverseStack(s);
         addStackToBack(s, data);
     }
 }
Exemple #4
0
 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     Rotary rotary = Visual as Rotary;
     if (rotary != null)
     {
         drawingContext.PushTransform(new RotateTransform(rotary.KnobRotation, _center.X, _center.Y));
         drawingContext.DrawImage(_image, _imageRect);
         drawingContext.Pop();
     }
 }
Exemple #5
0
 private static void addStackToBack(System.Collections.Generic.Stack<int> s, int m)
 {
     if (s.Count == 0)
     {
         s.Push(m);
     }
     else
     {
         int data = s.Pop();
         addStackToBack(s, m);
         s.Push(data);
     }
 }
Exemple #6
0
        public void Draw(System.Windows.Media.DrawingContext context, DrawingArgs args)
        {
            double lineWidth = 1;
            context.PushClip(new RectangleGeometry(args.RenderBounds));

            var transformdPos = args.Transform.Transform(new Point(0, Position)).X;

            Point start = new Point(transformdPos, args.RenderBounds.Top);
            Point end = new Point(transformdPos, args.RenderBounds.Bottom);

            var offset = lineWidth / 2;
            context.PushGuidelineSet(new GuidelineSet(
                new[] { start.X + offset, end.X + offset },
                new[] { start.Y + offset, end.Y + offset }));

            context.DrawLine(new Pen(new SolidColorBrush(Color), lineWidth), start, end);

            context.Pop();
        }
        public async Task<Errorable<TreeNode>> PersistTree(TreeID rootid, ImmutableContainer<TreeID, TreeNode> trees)
        {
            if (trees == null) throw new ArgumentNullException("trees");
            // TODO: better return value than `null`
            if (trees.Count == 0) return (TreeNode)null;

            // Start a query to check what Trees exist already:
            var existTrees = await db.ExecuteListQueryAsync(new QueryTreesExist(trees.Keys), expectedCapacity: trees.Count);

            // This code scans the tree breadth-first and builds a reversed depth-ordered stack:

            var reverseDepthOrder = new { id = rootid, depth = 0 }.StackOf(trees.Count);
            reverseDepthOrder.Pop();

            var breadthFirstQueue = new { id = rootid, depth = 0 }.QueueOf(trees.Count);
            while (breadthFirstQueue.Count > 0)
            {
                var curr = breadthFirstQueue.Dequeue();
                // Add it to the reverse stack:
                reverseDepthOrder.Push(curr);

                TreeNode node;
                if (!trees.TryGetValue(curr.id, out node))
                {
                    // TODO: didn't find the TreeID in the given collection, assume already persisted?
                    continue;
                }

                // Queue up the child TreeIDs:
                foreach (var trtr in node.Trees)
                    breadthFirstQueue.Enqueue(new { id = trtr.TreeID, depth = curr.depth + 1 });
            }

            // This code takes the reverse depth-ordered stack and persists the tree nodes in groups per depth level.
            // This ensures that all child nodes across the breadth of the tree at each depth level are persisted
            // before moving up to their parents.

            List<Task<Errorable<TreeNode>>> persistTasks = new List<Task<Errorable<TreeNode>>>();
            // Initialize the `isPersisting` set with the set of TreeIDs that already exist.
            HashSet<TreeID> isPersisting = new HashSet<TreeID>(existTrees);

            int lastDepth = reverseDepthOrder.Peek().depth;
            foreach (var curr in reverseDepthOrder)
            {
                Debug.WriteLine(String.Format("{0}: {1}", curr.depth, curr.id.ToString(firstLength: 7)));
                // An invariant of the algorithm, enforced via assert:
                Debug.Assert(curr.depth <= lastDepth);

                // Did we move to the next depth group:
                if ((persistTasks.Count > 0) && (curr.depth != lastDepth))
                {
                    Debug.WriteLine(String.Format("Awaiting depth group {0}...", lastDepth));
                    // Wait for the last depth group to finish persisting:
                    await Task.WhenAll(persistTasks);

                    // Start a new depth group:
                    persistTasks = new List<Task<Errorable<TreeNode>>>();
                }

                // Don't re-persist the same TreeID (this is a legit case - the same TreeID may be seen in different nodes of the tree):
                if (isPersisting.Contains(curr.id))
                {
                    Debug.WriteLine(String.Format("Already persisting {0}", curr.id.ToString(firstLength: 7)));

                    // Keep track of the last depth level:
                    lastDepth = curr.depth;
                    continue;
                }

                // Get the TreeNode and persist it:
                TreeNode node = trees[curr.id];
                isPersisting.Add(curr.id);

                // Fire up a task to persist this tree node:
                var tsk = db.ExecuteNonQueryAsync(new PersistTree(node));

                // Add the task to the depth group to await:
                Debug.WriteLine(String.Format("Adding to depth group {0}...", curr.depth));
                persistTasks.Add(tsk);

                // Keep track of the last depth level:
                lastDepth = curr.depth;
            }

            Debug.Assert(lastDepth == 0);
            if (persistTasks.Count > 0)
            {
                // Await the last group (the root node):
                Debug.WriteLine(String.Format("Awaiting depth group {0}...", lastDepth));
                await Task.WhenAll(persistTasks);
            }

            // Return the root TreeNode:
            return trees[rootid];
        }
 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     if (_bitmap != null)
     {
         drawingContext.PushClip(new RectangleGeometry(new Rect(RenderSize)));
         drawingContext.DrawImage(_bitmap, new Rect(new Size(_bitmap.Width, _bitmap.Height)));
         drawingContext.Pop();
     }
 }
Exemple #9
0
        private static void SnipVoidRound(DirectoryInfo dTarget, System.Collections.Stack stackDirs)
        {
            DirectoryInfo currentDir = null;
            try
            {
                foreach (DirectoryInfo diNext in dTarget.GetDirectories())
                    stackDirs.Push(diNext);

                while (stackDirs.Count > 0)
                {
                    currentDir = (DirectoryInfo)stackDirs.Pop();

                    //Process dir
                    if (currentDir.GetFiles().Length == 0)
                    {
                        if (currentDir.GetDirectories().Length == 0)
                            currentDir.Delete();
                        else
                            //Process Subdirectories
                            foreach (DirectoryInfo diNext in currentDir.GetDirectories())
                                stackDirs.Push(diNext);
                    }
                }
            }
            catch (Exception e)
            {
                if (currentDir != null)
                    throw new Exception(String.Format(Resources.errorNoDelete, currentDir.FullName, e.ToString()));
                else
                    throw;
            }
        }
Exemple #10
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            TransformGroup transform = new TransformGroup();
            transform.Children.Add(new TranslateTransform((-_center.X + HorizontalOffset) * _xScale, (-_center.Y + VerticalOffset) * _yScale));
            transform.Children.Add(new RotateTransform(_rotation + _baseRotation));
            transform.Children.Add(new TranslateTransform(_location.X * _xScale, _location.Y * _yScale));

            drawingContext.PushTransform(transform);
            drawingContext.DrawImage(_image, _rectangle);
            drawingContext.Pop();
        }
        public override void Draw(System.Windows.Media.DrawingContext dc)
        {
            var formattedText = GetFormattedText(Text, Thickness);

            if (Orientation == Orientation.Hor)
            {
                dc.DrawText(formattedText, new System.Windows.Point(StartPoint.X - formattedText.Width/2, StartPoint.Y));
            }
            else
            {
                var rotate = new RotateTransform();
                rotate.Angle = 90;
                dc.PushTransform(rotate);
                dc.DrawText(formattedText, new System.Windows.Point(StartPoint.Y, -StartPoint.X));
                dc.Pop();
            }
        }
		private static Object pop(System.Collections.Stack stack)
		{
			return (stack.Count != 0) ? stack.Pop() : null;
		}
Exemple #13
0
 private static void evaluate_stack_tops(Stack numStack, System.Collections.Generic.Stack<char> opStack, System.Collections.Generic.Stack<string> funcStack, bool safetyKill)
 {
     if (((numStack.Count != 0) || (funcStack.Count != 0)) && (opStack.Count != 0) && (!opStack.Peek().Equals(","))) {
         char Operation = opStack.Pop();
         if (Operation == '@') { // @ is the placeholder for a function. The function itself is in funcStack.
             evaluate_stack_tops_function(numStack, funcStack);
         }
         else if (Operation == '~') {
             object obj = numStack.Pop();
             if (obj is bool) numStack.Push(!(bool)obj);
             else if (obj is int) numStack.Push(~(int)obj);
             else numStack.Push(obj);
         }
         else if (Operation == '!') {
             int fact = Convert.ToInt32(numStack.Pop(), Util.cfi);
             numStack.Push(Convert.ToDouble(Factorial(fact), Util.nfi));
         }
         else if (numStack.Count >= 2) {
             object objOne, objTwo;
             objTwo = numStack.Pop();
             objOne = numStack.Pop();
             try {
                 switch (Operation) {
                     case 'c': // concatenation
                         numStack.Push((string)objOne + objTwo.ToString());
                         break;
                     case '^': // power
                         numStack.Push(Math.Pow((double)objOne, (double)objTwo));
                         break;
                     case '*': // multiplication
                         numStack.Push((double)objOne * (double)objTwo);
                         break;
                     case '/': // division
                         numStack.Push((double)objOne / (double)objTwo);
                         break;
                     case '%': // modulus
                         //numStack.Push((int)(double)objOne%(int)(double)objTwo);
                         numStack.Push(Math.IEEERemainder((double)objOne, (double)objTwo));
                         break;
                     case '+': // addition
                         numStack.Push((double)objOne + (double)objTwo);
                         break;
                     case '-': // subtraction
                         numStack.Push((double)objOne - (double)objTwo);
                         break;
                     case '>': // greater than
                         numStack.Push(doCompare(objOne, objTwo, false) >= 0);
                         break;
                     case 'G': // greater than or equal to
                         numStack.Push(doCompare(objOne, objTwo, false) == 1);
                         break;
                     case '<': // less than
                         numStack.Push(doCompare(objOne, objTwo, false) == -1);
                         break;
                     case 'L': // less than or equal to
                         numStack.Push(doCompare(objOne, objTwo, false) <= 0);
                         break;
                     case '=': // case-sensitive equal
                         numStack.Push(doCompare(objOne, objTwo, false) == 0);
                         break;
                     case 'i': // case-insensitive equal
                         numStack.Push(doCompare(objOne, objTwo, true) == 0);
                         break;
                     case 'N': // case-sensitive not equal
                         numStack.Push(doCompare(objOne, objTwo, false) != 0);
                         break;
                     case 'I': // case-insensitive not equal
                         numStack.Push(doCompare(objOne, objTwo, true) != 0);
                         break;
                     case '&': // bitwise-and
                         numStack.Push((int)objOne & (int)objTwo);
                         break;
                     case 'X': // bitwise-xor
                         numStack.Push((int)objOne ^ (int)objTwo);
                         break;
                     case '|': // bitwise-or
                         numStack.Push((int)objOne | (int)objTwo);
                         break;
                     case 'A': // boolean and
                         numStack.Push((bool)objOne && (bool)objTwo);
                         break;
                     case 'O': // boolean or
                         numStack.Push((bool)objOne || (bool)objTwo);
                         break;
                     case 'r': // shift right
                         numStack.Push((int)objOne >> (int)objTwo);
                         break;
                     case 'l': // shift left
                         numStack.Push((int)objOne << (int)objTwo);
                         break;
                 }
             } catch { throw new FormatException(); }
         }
         // Can't make sense of the stacks, so just clear them...
         else if (safetyKill) {
             funcStack.Clear();
             opStack.Clear();
             numStack.Clear();
         }
     }
 }
Exemple #14
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            if (_editor.SelectedItems.Count > 0)
            {
                Pen rectPen = _drawFocus ? SelectionRectPen : SelectionRectPenNoFocus;
                Brush circleBrush = _drawFocus ? SelectionResizeBrush : SelectionResizeBrushNoFocus;

                if (_isline)
                {                    
                    Point start;
                    Point end;

                    drawingContext.PushTransform(new ScaleTransform(_editor.ZoomFactor, _editor.ZoomFactor));
                    if (_editor.SnapManager.Action == SnapAction.LineStart || _editor.SnapManager.Action == SnapAction.LineEnd)
                    {
                        drawingContext.PushTransform(new TranslateTransform(_tempLine.Left, _tempLine.Top));
                        _tempLine.Renderer.Render(drawingContext);
                        drawingContext.Pop();

                        start = _tempLine.Start;
                        end = _tempLine.End;
                    }
                    else
                    {
                        Helios.Controls.LineDecoration line = _editor.SelectedItems[0] as Helios.Controls.LineDecoration;

                        start = line.Start;
                        end = line.End;
                        if (_editor.SnapManager.Action == SnapAction.Move)
                        {
                            start += _editor.SnapManager.LocationOffset;
                            end += _editor.SnapManager.LocationOffset;
                            _tempLine.Clone(line);
                            
                            drawingContext.PushTransform(new TranslateTransform(_tempLine.Left + _editor.SnapManager.LocationOffset.X, _tempLine.Top + _editor.SnapManager.LocationOffset.Y));
                            _tempLine.Renderer.Render(drawingContext);
                            drawingContext.Pop();
                        }
                    }
                    drawingContext.Pop();

                    start.X *= _editor.ZoomFactor;
                    start.Y *= _editor.ZoomFactor;
                    end.X *= _editor.ZoomFactor;
                    end.Y *= _editor.ZoomFactor;

                    drawingContext.DrawEllipse(circleBrush, rectPen, start, ResizeRadius, ResizeRadius);
                    drawingContext.DrawEllipse(circleBrush, rectPen, end, ResizeRadius, ResizeRadius);
                }
                else
                {
                    foreach (HeliosVisual visual in _editor.SelectedItems)
                    {
                        Rect visualRect = visual.DisplayRectangle;
                        visualRect.Scale(_editor.ZoomFactor, _editor.ZoomFactor);
                        drawingContext.DrawRectangle(null, SelectionBorderPen, visualRect);
                    }

                    Rect selectionRect = (_editor.SnapManager.Action != SnapAction.None && _editor.SnapManager.Action != SnapAction.Drop && _editor.SnapManager.IsValidDrag) ? _editor.SnapManager.NewRectangle : _editor.SelectedItems.Rectangle;
                    selectionRect.Scale(_editor.ZoomFactor, _editor.ZoomFactor);

                    drawingContext.DrawRectangle(null, rectPen, selectionRect);

                    drawingContext.DrawEllipse(circleBrush, rectPen, selectionRect.TopLeft, ResizeRadius, ResizeRadius);
                    drawingContext.DrawEllipse(circleBrush, rectPen, selectionRect.TopRight, ResizeRadius, ResizeRadius);
                    drawingContext.DrawEllipse(circleBrush, rectPen, selectionRect.BottomLeft, ResizeRadius, ResizeRadius);
                    drawingContext.DrawEllipse(circleBrush, rectPen, selectionRect.BottomRight, ResizeRadius, ResizeRadius);
                }
            }
        }
Exemple #15
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            drawingContext.PushTransform(new ScaleTransform(_scaleX, _scaleY));

            drawingContext.DrawEllipse(Brushes.Black, null, _center, 187d, 187d);

            if (_rwr != null && _rwr.IsOn)
            {
                bool primary = DateTime.Now.Millisecond < 500;

                // Draw heart beat lines
                drawingContext.DrawLine(_scopePen, new Point(160d, 193.5), new Point(180d, 193.5d));
                drawingContext.DrawLine(_scopePen, new Point(220d, 193.5), new Point(240d, 193.5d));
                drawingContext.DrawLine(_scopePen, new Point(200d, 153.5), new Point(200d, 173.5));
                drawingContext.DrawLine(_scopePen, new Point(200d, 213.5), new Point(200d, 233.5));
                if (primary)
                {
                    drawingContext.DrawLine(_scopePen, new Point(220d, 193.5d), new Point(220d, 203.5d));
                }
                else
                {
                    drawingContext.DrawLine(_scopePen, new Point(220d, 183.5d), new Point(220d, 193.5d));
                }

                if (_rwr.Contacts != null)
                {
                    foreach (RadarContact contact in _rwr.Contacts)
                    {
                        if (contact.Visible)
                        {
                            double y = 0.0f;
                            if (contact.Lethality > 1f)
                            {
                                y = -((2.0f - contact.Lethality) * 178.0d);
                            }
                            else
                            {
                                y = -((1.0f - contact.Lethality) * 178.0d);
                            }

                            drawingContext.PushTransform(new RotateTransform(contact.RelativeBearing));
                            drawingContext.PushTransform(new TranslateTransform(0d, y));
                            drawingContext.PushTransform(new RotateTransform(-contact.RelativeBearing));

                            if (contact.NewDetection && !primary)
                            {
                                _format.FontSize = 24;
                            }
                            else
                            {
                                _format.FontSize = 22;
                            }

                            DrawContactSymbol(drawingContext, contact, primary);

                            if (contact.Selected)
                            {
                                drawingContext.DrawLine(_scopePen, new Point(200d, 168.5d), new Point(225d, 193.5d));
                                drawingContext.DrawLine(_scopePen, new Point(225d, 193.5d), new Point(200d, 218.5d));
                                drawingContext.DrawLine(_scopePen, new Point(200d, 218.5d), new Point(175d, 193.5d));
                                drawingContext.DrawLine(_scopePen, new Point(175d, 193.5d), new Point(200d, 168.5d));
                            }

                            if ((contact.MissileActivity && !contact.MissileLaunch) ||
                                (contact.MissileActivity && contact.MissileLaunch && _rwr.Flash4Hz))
                            {
                                drawingContext.DrawEllipse(null, _scopePen, _center, 25, 25);
                            }

                            drawingContext.Pop();
                            drawingContext.Pop();
                            drawingContext.Pop();
                        }
                    }
                }
            }

            if (_bezelBrush != null)
            {
                drawingContext.DrawRectangle(_bezelBrush, null, _bezelRect);
            }

            drawingContext.Pop();
        }
Exemple #16
0
        public void PopOne()
        {
            const int x = 123, y = 456, z = 789;
            var array = new[] { x, y, z };

            var pop1 = array.Pop((t, h) => new { Popped = t, Rest = h });
            Assert.AreEqual(z, pop1.Popped);
            Assert.AreEqual(new[] { x, y }, pop1.Rest);

            var pop2 = pop1.Rest.Pop((t, h) => new { Popped = t, Rest = h });
            Assert.AreEqual(y, pop2.Popped);
            Assert.AreEqual(new[] { x }, pop2.Rest);

            var pop3 = pop2.Rest.Pop((t, h) => new { Popped = t, Rest = h });
            Assert.AreEqual(x, pop3.Popped);
            Assert.AreEqual(0, pop3.Rest.Length);
        }
 protected override void OnDrawn(System.Windows.Media.DrawingContext g)
 {
     if (Rotation != 0)
     {
         g.Pop();
     }
 }
 internal void SetPositions(System.Collections.Generic.Stack<int> stack)
 {
     this.endChar = stack.Pop();
     this.startChar = stack.Pop();
 }
        private IEnumerable<TagName> getAllTagNames()
        {
            // Create a new stack of an anonymous type:
            var s = new { di = system.getTagsDirectory(), parts = new string[0] }.StackOf();
            while (s.Count > 0)
            {
                var curr = s.Pop();

                // Yield all files as TagNames in this directory:
                FileInfo[] files = curr.di.GetFiles();
                for (int i = 0; i < files.Length; ++i)
                    yield return (TagName)curr.parts.AppendAsArray(files[i].Name);

                // Push all the subdirectories to the stack:
                DirectoryInfo[] dirs = curr.di.GetDirectories();
                for (int i = 0; i < dirs.Length; ++i)
                    s.Push(new { di = dirs[i], parts = curr.parts.AppendAsArray(dirs[i].Name) });
            }
        }