예제 #1
0
        private void CreateTree()
        {
            // Get width / height of node surface
            int nodeSurfaceWidth, nodeSurfaceHeight;

            NodeSurface.GetDimensions(out nodeSurfaceWidth, out nodeSurfaceHeight);

            // Count the depth of the topology
            int numLevels      = CountLevels(m_baseNode, 1);
            int heightPerLevel = m_usedHeight / numLevels;

            if (heightPerLevel < (nodeSurfaceHeight + k_vertSpacing))
            {
                m_usedHeight   = numLevels * (nodeSurfaceHeight + k_vertSpacing);
                heightPerLevel = m_usedHeight / numLevels;
            }

            int overlap = -1;

            while (overlap != 0)
            {
                ClearVectors();
                overlap      = ParseNode(m_baseNode, m_usedWidth, heightPerLevel, 0, 0);
                m_usedWidth += overlap;
            }
        }
예제 #2
0
 private void SetColors()
 {
     m_legendPCColor.BackColor     = NodeSurface.GetNodeColor(ManagedTopologyNode.NodeType.Computer);
     m_legendBusColor.BackColor    = NodeSurface.GetNodeColor(ManagedTopologyNode.NodeType.Bus);
     m_legendNodeColor.BackColor   = NodeSurface.GetNodeColor(ManagedTopologyNode.NodeType.Node);
     m_legendCameraColor.BackColor = NodeSurface.GetNodeColor(ManagedTopologyNode.NodeType.Camera);
 }
예제 #3
0
        private void InsertNewNodeSurface(ManagedTopologyNode node, int xPos, int yPos)
        {
            NodeSurface nodeSurface = new NodeSurface();
            bool        selected    = false;

            if (m_selectedGuid.Equals(node.GetGuid()) && m_isSelectionValid == true)
            {
                selected = true;
            }

            nodeSurface.Update(node, selected);
            nodeSurface.SetPosition(xPos, yPos);
            m_nodeSurfaces.Add(nodeSurface);
        }
예제 #4
0
        private void DrawTree(Graphics drawingAreaGraphics)
        {
            drawingAreaGraphics.Clear(Color.White);
            drawingAreaGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            // Get width / height of node surface
            int nodeSurfaceWidth, nodeSurfaceHeight;

            NodeSurface.GetDimensions(out nodeSurfaceWidth, out nodeSurfaceHeight);

            // Draw node surfaces
            for (int i = 0; i < m_nodeSurfaces.Count; i++)
            {
                NodeSurface currNodeSurface = m_nodeSurfaces[i];
                int         xPos, yPos;
                currNodeSurface.GetPosition(out xPos, out yPos);
                xPos -= nodeSurfaceWidth / 2;
                yPos -= nodeSurfaceHeight / 2;
                drawingAreaGraphics.DrawImage(currNodeSurface.GetBitmapImage(), xPos, yPos);
            }

            // Draw Draw Node Connector
            for (int i = 0; i < m_lines.Count; i++)
            {
                Line line = m_lines[i];
                Pen  pen = new Pen(Brushes.Black, 4.0f);
                int  portWidth, portHeight;
                NodeSurface.GetPortDimensions(out portWidth, out portHeight);
                Point[] points = new Point[]
                {
                    new Point(line.StartX, line.StartY - (portHeight / 2)),
                    new Point(line.StartX, line.StartY + 5),
                    new Point(line.EndX, line.EndY - 5),
                    new Point(line.EndX, line.EndY + (portHeight / 2))
                };
                drawingAreaGraphics.DrawLines(pen, points);
            }
        }
예제 #5
0
        /** Checks if the position specified is over a camera node surface. */
        private bool IsSelectionValid(MouseEventArgs e, ref ManagedPGRGuid selectedGuid)
        {
            float displayAspectRatio = 1 / (m_currAspectRatio * m_imageZoom);
            float actualX            = (float)e.X * displayAspectRatio;
            float actualY            = (float)e.Y * displayAspectRatio;

            // Get the node surface width
            int surfaceWidth, surfaceHeight;

            NodeSurface.GetDimensions(out surfaceWidth, out surfaceHeight);
            actualX += (surfaceWidth / 2) - (m_offsetX * displayAspectRatio);
            actualY += (surfaceHeight / 2) - (m_offsetY * displayAspectRatio);

            selectedGuid = new ManagedPGRGuid();

            foreach (NodeSurface currentNodeSurface in m_nodeSurfaces)
            {
                int xPos, yPos;
                currentNodeSurface.GetPosition(out xPos, out yPos);
                int            roundedRectangleMargin = currentNodeSurface.GetRoundedRectangleMargin();
                ManagedPGRGuid currGuid = currentNodeSurface.GetGuid();
                if (actualX >= xPos + roundedRectangleMargin &&
                    actualX <= xPos + surfaceWidth - roundedRectangleMargin &&
                    actualY >= yPos + roundedRectangleMargin &&
                    actualY <= yPos + surfaceHeight - roundedRectangleMargin &&
                    IsGuidValid(currGuid) == true)
                {
                    // Store the guid so we can draw something around
                    // the current selection
                    selectedGuid = currGuid;
                    return(true);
                }
            }

            return(false);
        }
예제 #6
0
        private int ParseNode(ManagedTopologyNode node, int width, int height, int horzOffset, int vertOffset)
        {
            // To improve the layout of the tree, the allocation of width is
            // determined by the number of second generation children rather than
            // just immediate children.
            int num2ndGenChildren = CountNum2ndGenChildren(node);
            int widthUnit;

            if (num2ndGenChildren == 0)
            {
                widthUnit = width;
            }
            else
            {
                widthUnit = width / num2ndGenChildren;
            }

            int nextHorzOffset = horzOffset;

            // Calculate the position of the node
            int nodeXPos = horzOffset + (width / 2);
            int nodeYPos = vertOffset + (height / 2);

            // Add this node to the list of surfaces to be drawn
            InsertNewNodeSurface(node, nodeXPos, nodeYPos);

            // Figure out there are any children to be recursively drawn
            int  accumOverlap = 0;
            uint childIndex   = 0;

            for (uint portIndex = 0; portIndex < node.GetNumPorts(); portIndex++)
            {
                ManagedTopologyNode.PortType currPort = node.GetPortType(portIndex);
                if (currPort == ManagedTopologyNode.PortType.ConnectedToChild)
                {
                    ManagedTopologyNode currChild = node.GetChild(childIndex);
                    int thisWidth = widthUnit * ((int)currChild.GetNumChildren());
                    if (thisWidth == 0)
                    {
                        thisWidth = widthUnit;
                    }

                    int thisCenterX = nextHorzOffset + (thisWidth / 2);
                    int thisCenterY = vertOffset + height + (height / 2);

                    int surfaceWidth, surfaceHeight;
                    NodeSurface.GetDimensions(out surfaceWidth, out surfaceHeight);

                    // There might be more than 1 child, so perform some
                    // calculations so that the lines don't start from
                    // the same point
                    int numChildren = (int)node.GetNumChildren();
                    int startX      = unchecked ((int)(nodeXPos + ((surfaceWidth / (numChildren + 1)) * (childIndex + 1)) - (surfaceWidth / 2)));
                    int startY      = nodeYPos + (surfaceHeight / 2);

                    int endX = thisCenterX;
                    int endY = thisCenterY - (surfaceHeight / 2);

                    // Start a line to be drawn later
                    Line newLine = new Line(startX, startY, endX, endY);
                    m_lines.Add(newLine);

                    ManagedTopologyNode nextChild = node.GetChild(childIndex++);
                    accumOverlap += ParseNode(
                        nextChild,
                        thisWidth,
                        height,
                        nextHorzOffset,
                        vertOffset + height);

                    nextHorzOffset += thisWidth;
                }
            }

            int nodeWidth, nodeHeight;

            NodeSurface.GetDimensions(out nodeWidth, out nodeHeight);
            if (width < nodeWidth)
            {
                accumOverlap += nodeWidth - width;
            }

            if (m_usedWidth < (horzOffset + width))
            {
                accumOverlap += (horzOffset + width) - m_usedWidth;
            }

            return(accumOverlap);
        }