Esempio n. 1
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);
        }
Esempio n. 2
0
        private static int CountNum2ndGenChildren(ManagedTopologyNode node)
        {
            int num2ndGenChildren = 0;

            for (uint i = 0; i < node.GetNumChildren(); i++)
            {
                num2ndGenChildren += (int)node.GetChild(i).GetNumChildren();
                if (node.GetChild(i).GetNumChildren() == 0)
                {
                    num2ndGenChildren++;
                }
            }

            return(num2ndGenChildren);
        }
Esempio n. 3
0
        public void Update(ManagedTopologyNode node, bool selected)
        {
            Debug.Assert(node != null, "node paramter is null");
            if (node == null)
            {
                return;
            }

            // Store the PGRGuid so we can handle device information on clicks
            m_guid     = node.GetGuid();
            m_deviceId = node.GetDeviceId();

            // Create a context for the surface
            Graphics surfaceGraphics = Graphics.FromImage(m_surface);

            surfaceGraphics.Clear(Color.White);

            Pen pen;

            if (selected == true)
            {
                pen = new Pen(Color.Red, 3);
            }
            else
            {
                pen = new Pen(Color.Black, 1);
            }

            using (pen)
            {
                int width  = m_surface.Width;
                int height = m_surface.Height;

                Rectangle surfaceRectangle = new Rectangle(
                    0 + RoundedRectangleMargin,
                    0 + RoundedRectangleMargin,
                    width - (2 * RoundedRectangleMargin),
                    height - (2 * RoundedRectangleMargin));

                const int Radius = 20;
                DrawRoundedRectangle(surfaceGraphics, surfaceRectangle, Radius, pen, GetNodeColor(node.GetNodeType()));

                DrawTextToGraphics(GetNodeText(node), surfaceGraphics, width, height);

                DrawPorts(node, surfaceGraphics);
            }
        }
Esempio n. 4
0
        private static void DrawPorts(ManagedTopologyNode node, Graphics graphics)
        {
            int numChildren = 0;

            for (uint i = 0; i < node.GetNumPorts(); i++)
            {
                if (node.GetPortType(i) == ManagedTopologyNode.PortType.ConnectedToChild)
                {
                    numChildren++;
                }
            }

            int childIndex = 0;

            for (uint i = 0; i < node.GetNumPorts(); i++)
            {
                ManagedTopologyNode.PortType currPort = node.GetPortType(i);
                switch (currPort)
                {
                case ManagedTopologyNode.PortType.NotConnected:
                    break;

                case ManagedTopologyNode.PortType.ConnectedToParent:
                    graphics.FillRectangle(
                        Brushes.Black,
                        (NodeWidth / 2) - (PortWidth / 2),
                        0,
                        PortWidth,
                        PortHeight);
                    break;

                case ManagedTopologyNode.PortType.ConnectedToChild:
                    int startX = (NodeWidth / (numChildren + 1)) * (childIndex + 1);
                    graphics.FillRectangle(
                        Brushes.Black,
                        startX - (PortWidth / 2),
                        NodeHeight - PortHeight,
                        PortWidth,
                        PortHeight);
                    childIndex++;
                    break;

                default:
                    break;
                }
            }
        }
Esempio n. 5
0
        private static int CountLevels(ManagedTopologyNode node, int seed)
        {
            if (node == null)
            {
                return(-1);
            }

            int result = seed;

            for (uint i = 0; i < node.GetNumChildren(); i++)
            {
                ManagedTopologyNode childNode = node.GetChild(i);
                int newSeed = CountLevels(childNode, seed + 1);
                if (newSeed > result)
                {
                    result = newSeed;
                }
            }

            return(result);
        }
Esempio n. 6
0
        private void OnRefreshTopology()
        {
            try
            {
                m_baseNode   = m_busMgr.GetTopology();
                m_redrawTree = true;
            }
            catch (FC2Exception ex)
            {
                // Error
                Debug.WriteLine("Error getting topology." + ex.Message);
            }

            m_drawingArea.Refresh();

            if (m_selectedGuid.Equals(new ManagedPGRGuid()) == false)
            {
                // If current selected node is not a null node,
                // We need to update node information as well
                UpdateNodeInformation(m_selectedGuid);
            }
        }
Esempio n. 7
0
        private static string GetNodeText(ManagedTopologyNode node)
        {
            string result;

            ManagedTopologyNode.NodeType nodeType = node.GetNodeType();
            switch (nodeType)
            {
            case ManagedTopologyNode.NodeType.Computer:
                result = "PC";
                break;

            case ManagedTopologyNode.NodeType.Bus:
                InterfaceType ifType = node.GetInterfaceType();
                switch (ifType)
                {
                case InterfaceType.Ieee1394:
                    result = "1394 Bus";
                    break;

                case InterfaceType.Usb2:
                    result = "USB 2.0 Bus";
                    break;

                case InterfaceType.Usb3:
                    result = "USB 3.0 Bus";
                    break;

                case InterfaceType.GigE:
                    result = "GigE Bus";
                    break;

                default:
                    result = "Bus";
                    break;
                }

                break;

            case ManagedTopologyNode.NodeType.Camera:
                result = string.Format("ID: {0}", node.GetDeviceId());
                break;

            case ManagedTopologyNode.NodeType.Node:
                if (node.GetGuid().Equals(new ManagedPGRGuid()))
                {
                    result = "Node";
                }
                else
                {
                    result = "Node*";
                }

                break;

            default:
                result = "Unknown";
                break;
            }

            return(result);
        }
Esempio n. 8
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);
        }