Beispiel #1
0
 internal static bool ExtractThePort(TopologyVisualizer.TopologyNode node, string dbElemName, out TopologyVisualizer.TopologyPort thePort)
 {
     if (dbElemName.StartsWith("rx_") || dbElemName.StartsWith("status_") || dbElemName.StartsWith("port_"))
     {
         return(node.GetPortByDbName(dbElemName, out thePort));
     }
     thePort = null;
     return(false);
 }
Beispiel #2
0
        private void ConfigCreator_Load(object sender, EventArgs e)
        {
            bool editMode      = this.vis != null;
            int  numOfNodes    = -1;
            int  numOfSwitches = -1;

            if (editMode)
            {
                numOfNodes = vis.NumOfNodes;
            }
            else
            {
                string numOfNodesStr    = Interaction.InputBox(Prompt: "Please enter the number of nodes", DefaultResponse: null);
                string numOfSwitchesStr = Interaction.InputBox(Prompt: "Please enter the number of switches", DefaultResponse: null);
                if (!int.TryParse(numOfNodesStr, out numOfNodes) || !int.TryParse(numOfSwitchesStr, out numOfSwitches))
                {
                    forceCloseForm = true;
                    Close();
                    return;
                }
                if (numOfNodes <= 0 || numOfSwitches < 0)
                {
                    MessageBox.Show(this, "Number of nodes must be greater than zero and number of switches must be greater than or equal to zero!", "Wrong input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    forceCloseForm = true;
                    Close();
                    return;
                }

                vis = new TopologyVisualizer(topologyPictureBox, logTextBox);
            }

            const short MARGIN    = 20;
            int         numOfCols = (topologyPictureBox.Width - 2 * MARGIN) / (TopologyVisualizer.NODE_WIDTH + 2 * MARGIN);

            TopologyVisualizer.TopologyNode         lastNode        = null;
            TopologyVisualizer.TopologyNode[]       exisNodes       = editMode ? vis.Nodes : null;
            TopologyVisualizer.TopologySwitchNode   lastSwitchNode  = null;
            TopologyVisualizer.TopologySwitchNode[] exisSwitchNodes = editMode ? vis.SwitchNodes : null;
            short switchDeltaY = (short)(numOfSwitches == 0 ? 0 : TopologyVisualizer.SWITCH_HEIGHT + MARGIN);

            for (int n = 0, r = 0, c = 0; n < numOfSwitches; n++)
            {
                lastSwitchNode = editMode ? exisSwitchNodes[n] : vis.AddSwitchNode(
                    posX: (short)((TopologyVisualizer.SWITCH_WIDTH + 2 * MARGIN) * c + MARGIN),
                    posY: (short)((TopologyVisualizer.SWITCH_HEIGHT + 2 * MARGIN) * r + MARGIN)
                    );

                if (c == numOfCols)
                {
                    r++;
                    c             = 0;
                    switchDeltaY += TopologyVisualizer.SWITCH_HEIGHT + MARGIN;
                }
                else
                {
                    c++;
                }
            }
            for (int n = 0, r = 0, c = 0; n < numOfNodes; n++)
            {
                lastNode = editMode ? exisNodes[n] : vis.AddNode(
                    posX: (short)((TopologyVisualizer.NODE_WIDTH + 2 * MARGIN) * c + MARGIN),
                    posY: (short)((TopologyVisualizer.NODE_HEIGHT + 2 * MARGIN) * r + MARGIN + switchDeltaY)
                    );

                if (c == numOfCols)
                {
                    r++;
                    c = 0;
                }
                else
                {
                    c++;
                }
            }

            if (topologyPictureBox.Height < lastNode.endLoc.y + MARGIN)
            {
                topologyPictureBox.Height = lastNode.endLoc.y + MARGIN;
            }

            vis.clickAction = TopologyVisualizer.TpClickAction.MOVE_LOCATION;
            Log(key: "action", value: "altering node locations");
        }