Beispiel #1
0
        private void DrawPartAndConnected(KmlPart part, IntPair koords, IntPair parentKoords, Brush lineBrush)
        {
            GuiVesselsPartGraphNode partNode = DrawPart(part, koords);
            Line l = DrawConnection(parentKoords, koords, lineBrush);

            partNode.Lines.Add(l);
            GuiVesselsPartGraphNode parentNode = PartGrid[parentKoords.X - PartGridMinX][parentKoords.Y - PartGridMinY];

            parentNode.Lines.Add(l);
            DrawConnectedParts(partNode, koords);
        }
Beispiel #2
0
        private void DrawConnectionAndSeachPart(KmlPart part, IntPair parentKoords, Brush lineBrush)
        {
            // Already drawn sub part with one way arrow.
            // Need to draw the reverse arrow only
            // But where is the node?
            Point parentPos = CalcPosition(parentKoords);
            GuiVesselsPartGraphNode parentNode = PartGrid[parentKoords.X - PartGridMinX][parentKoords.Y - PartGridMinY];

            foreach (UIElement element in VesselsDetails.Children)
            {
                if (element is GuiVesselsPartGraphNode)
                {
                    GuiVesselsPartGraphNode node = (GuiVesselsPartGraphNode)element;
                    if (node.DataPart == part)
                    {
                        Line l = DrawConnection(parentPos.X, parentPos.Y, Canvas.GetLeft(node), Canvas.GetTop(node), lineBrush);
                        node.Lines.Add(l);
                        parentNode.Lines.Add(l);
                        break;
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Draws all parts of the given KmlVessel.
        /// </summary>
        /// <param name="vessel">The KmlVessel to read all parts from</param>
        public void DrawPartStructure(KmlVessel vessel)
        {
            VesselsDetails.Children.Clear();
            InitGrid();
            if (vessel != null)
            {
                foreach (KmlPart part in vessel.Parts)
                {
                    part.Visited = false;
                }

                IntPair rootKoords = CalcKoords(new IntPair(0, 0), 0, 0);
                GuiVesselsPartGraphNode rootNode = DrawPart(vessel.RootPart, rootKoords);
                DrawConnectedParts(rootNode, rootKoords);

                // Draw all parts, that are not drawn yet
                foreach (KmlPart part in vessel.Parts)
                {
                    if (!part.Visited)
                    {
                        IntPair koords = CalcKoords(new IntPair(0, PartGridMaxY), 0, PartGridMaxY + CountTop(part, vessel.RootPart));
                        GuiVesselsPartGraphNode partNode = DrawPart(part, koords);
                        DrawConnectedParts(partNode, koords);
                    }
                }

                double minX = 0;
                double minY = 0;
                double maxX = 0;
                double maxY = 0;
                CalcMinMax(out minX, out minY, out maxX, out maxY);

                VesselsDetails.Width           = maxX - minX + ElementWidth * 2;
                VesselsDetails.Height          = maxY - minY + ElementHeight;
                VesselsDetails.RenderTransform = new TranslateTransform(-minX, -minY);
            }
        }
Beispiel #4
0
        private Line DrawConnection(double x, double y, IntPair parentKoords, Brush lineBrush)
        {
            Point parentPos = CalcPosition(parentKoords);

            return(DrawConnection(x, y, parentPos.X, parentPos.Y, lineBrush));
        }
Beispiel #5
0
        private Line DrawConnection(IntPair koords, double parentX, double parentY, Brush lineBrush)
        {
            Point pos = CalcPosition(koords);

            return(DrawConnection(pos.X, pos.Y, parentX, parentY, lineBrush));
        }
Beispiel #6
0
 private GuiVesselsPartGraphNode DrawPart(KmlPart part, IntPair koords)
 {
     return(DrawPart(part, koords.X, koords.Y));
 }
Beispiel #7
0
        private void DrawConnectedParts(GuiVesselsPartGraphNode parent, IntPair parentKoords)
        {
            KmlPart parentPart = parent.DataPart;
            IntPair newKoords;

            // Top atteched parts
            foreach (KmlPart sub in parentPart.AttachedPartsTop)
            {
                if (!sub.Visited)
                {
                    newKoords = CalcKoords(parentKoords, parentKoords.X, parentKoords.Y - CountBottom(sub, parentPart) - CountTop(parentPart, parentPart) + 1);
                    for (int y = parentKoords.Y - 1; y > newKoords.Y; y--)
                    {
                        // Fill space with dummy nodes
                        InsertGrid(parentKoords.X, y, new GuiVesselsPartGraphNode(parentKoords.X, y));
                    }
                    DrawPartAndConnected(sub, newKoords, parentKoords, ConnectVerticalBrush);
                }
                else
                {
                    DrawConnectionAndSeachPart(sub, parentKoords, ConnectVerticalBrush);
                }
            }

            // Bottom atteched parts
            foreach (KmlPart sub in parentPart.AttachedPartsBottom)
            {
                if (!sub.Visited)
                {
                    newKoords = CalcKoords(parentKoords, parentKoords.X, parentKoords.Y + CountTop(sub, parentPart) + CountBottom(parentPart, parentPart) - 1);
                    for (int y = parentKoords.Y + 1; y < newKoords.Y; y++)
                    {
                        // Fill space with dummy nodes
                        InsertGrid(parentKoords.X, y, new GuiVesselsPartGraphNode(parentKoords.X, y));
                    }
                    DrawPartAndConnected(sub, newKoords, parentKoords, ConnectVerticalBrush);
                }
                else
                {
                    DrawConnectionAndSeachPart(sub, parentKoords, ConnectVerticalBrush);
                }
            }

            // Left atteched parts
            foreach (KmlPart sub in parentPart.AttachedPartsLeft)
            {
                if (!sub.Visited)
                {
                    newKoords = CalcKoords(parentKoords, parentKoords.X - 2, parentKoords.Y);
                    DrawPartAndConnected(sub, newKoords, parentKoords, ConnectSidesBrush);
                }
                else
                {
                    DrawConnectionAndSeachPart(sub, parentKoords, ConnectSidesBrush);
                }
            }

            // Right atteched parts
            foreach (KmlPart sub in parentPart.AttachedPartsRight)
            {
                if (!sub.Visited)
                {
                    newKoords = CalcKoords(parentKoords, parentKoords.X + 2, parentKoords.Y);
                    DrawPartAndConnected(sub, newKoords, parentKoords, ConnectSidesBrush);
                }
                else
                {
                    DrawConnectionAndSeachPart(sub, parentKoords, ConnectSidesBrush);
                }
            }

            // Back atteched parts
            foreach (KmlPart sub in parentPart.AttachedPartsBack)
            {
                if (!sub.Visited)
                {
                    newKoords = CalcKoords(parentKoords, parentKoords.X - 2, parentKoords.Y - 1);
                    DrawPartAndConnected(sub, newKoords, parentKoords, ConnectSidesBrush);
                }
                else
                {
                    DrawConnectionAndSeachPart(sub, parentKoords, ConnectSidesBrush);
                }
            }

            // Front atteched parts
            foreach (KmlPart sub in parentPart.AttachedPartsFront)
            {
                if (!sub.Visited)
                {
                    newKoords = CalcKoords(parentKoords, parentKoords.X + 2, parentKoords.Y + 1);
                    DrawPartAndConnected(sub, newKoords, parentKoords, ConnectSidesBrush);
                }
                else
                {
                    DrawConnectionAndSeachPart(sub, parentKoords, ConnectSidesBrush);
                }
            }

            // Surface atteched parts
            int i = 0;

            foreach (KmlPart sub in parentPart.AttachedPartsSurface)
            {
                if (!sub.Visited)
                {
                    // Arrange alternating left and right
                    do
                    {
                        if (i % 4 == 0)
                        {
                            newKoords = new IntPair(parentKoords.X - (i / 4 + 1), parentKoords.Y - 1);
                        }
                        else if (i % 4 == 1)
                        {
                            newKoords = new IntPair(parentKoords.X + (i / 4 + 1), parentKoords.Y - 1);
                        }
                        else if (i % 4 == 2)
                        {
                            newKoords = new IntPair(parentKoords.X - (i / 4 + 1), parentKoords.Y + 1);
                        }
                        else
                        {
                            newKoords = new IntPair(parentKoords.X + (i / 4 + 1), parentKoords.Y + 1);
                        }
                        i++;
                    }while (!InsertGrid(newKoords.X, newKoords.Y, null));
                    DrawPartAndConnected(sub, newKoords, parentKoords, ConnectSurfaceBrush);
                }
                else
                {
                    DrawConnectionAndSeachPart(sub, parentKoords, ConnectSurfaceBrush);
                    i++;
                }
            }

            // Docked parts
            if (parentPart is KmlPartDock)
            {
                KmlPartDock dock = (KmlPartDock)parentPart;
                KmlPart     sub  = dock.DockedPart;
                if (sub != null)
                {
                    if (!sub.Visited)
                    {
                        newKoords = CalcKoords(parentKoords, parentKoords.X + (sub.Position.X > parentPart.Position.X ? 1 : -1),
                                               parentKoords.Y + (sub.Position.Y > parentPart.Position.Y ? 1 : -1));
                        DrawPartAndConnected(sub, newKoords, parentKoords, ConnectDockBrush);
                    }
                    else
                    {
                        DrawConnectionAndSeachPart(sub, parentKoords, ConnectDockBrush);
                    }
                }
            }
        }
Beispiel #8
0
        private IntPair CalcKoords(IntPair parentKoords, int wantedX, int wantedY)
        {
            int diffX = wantedX - parentKoords.X;
            int diffY = wantedY - parentKoords.Y;

            // Check if it is free
            if (InsertGrid(wantedX, wantedY, null))
            {
                IntPair p = new IntPair(wantedX, wantedY);
                return(p);
            }
            else
            {
                IntPair p;
                int     i = 1;
                while (true)
                {
                    // always move away from root [0, 0]
                    int dx = i;
                    int dy = i;
                    if (wantedX < 0)
                    {
                        dx = -dx;
                    }
                    if (wantedY < 0)
                    {
                        dy = -dy;
                    }

                    if (diffY != 0)
                    {
                        p = new IntPair(wantedX + dx, wantedY);
                        if (InsertGrid(p.X, p.Y, null))
                        {
                            return(p);
                        }
                        //p = new IntPair(wantedX - i, wantedY);
                        //if (InsertGrid(p.X, p.Y, null)) return p;
                    }
                    if (diffX != 0)
                    {
                        p = new IntPair(wantedX, wantedY + dy);
                        if (InsertGrid(p.X, p.Y, null))
                        {
                            return(p);
                        }
                        //p = new IntPair(wantedX, wantedY - i);
                        //if (InsertGrid(p.X, p.Y, null)) return p;
                    }
                    p = new IntPair(wantedX + dx, wantedY + dy);
                    if (InsertGrid(p.X, p.Y, null))
                    {
                        return(p);
                    }
                    //p = new IntPair(wantedX + i, wantedY - i);
                    //if (InsertGrid(p.X, p.Y, null)) return p;
                    //p = new IntPair(wantedX - i, wantedY + i);
                    //if (InsertGrid(p.X, p.Y, null)) return p;
                    //p = new IntPair(wantedX - i, wantedY - i);
                    //if (InsertGrid(p.X, p.Y, null)) return p;
                    i++;
                }
            }
        }
Beispiel #9
0
 private Point CalcPosition(IntPair koords)
 {
     return(CalcPosition(koords.X, koords.Y));
 }