private static XElement GenerateHardwareXML(HardwareNode hardwareNode) { HardwareType type = hardwareNode.Hardware.HardwareType; XElement hardwareXML = new XElement(ConvertHardwareTypeToString(type)); hardwareXML.Add(new XElement("name", hardwareNode.Text)); foreach (Node node in hardwareNode.Nodes) { TypeNode typeNode = node as TypeNode; if (typeNode != null) { hardwareXML.Add(GenerateTypeXML(typeNode)); } else { HardwareNode subHardwareNode = node as HardwareNode; if (subHardwareNode != null) { hardwareXML.Add(GenerateHardwareXML(subHardwareNode)); } } } return(hardwareXML); }
private static string GetHardwareImageFile(HardwareNode hn) { switch (hn.Hardware.HardwareType) { case HardwareType.CPU: return("cpu.png"); case HardwareType.GpuNvidia: return("nvidia.png"); case HardwareType.GpuAti: return("ati.png"); case HardwareType.HDD: return("hdd.png"); case HardwareType.Heatmaster: return("bigng.png"); case HardwareType.Mainboard: return("mainboard.png"); case HardwareType.SuperIO: return("chip.png"); case HardwareType.TBalancer: return("bigng.png"); case HardwareType.RAM: return("ram.png"); default: return("cpu.png"); } }
private static string GetHardwareImageFile(HardwareNode hn) { switch (hn.Hardware.HardwareType) { case HardwareType.Cpu: return("cpu.png"); case HardwareType.GpuNvidia: return("nvidia.png"); case HardwareType.GpuAmd: return("ati.png"); case HardwareType.Storage: return("hdd.png"); case HardwareType.Motherboard: return("mainboard.png"); case HardwareType.SuperIO: return("chip.png"); case HardwareType.Memory: return("ram.png"); case HardwareType.Cooler: return("fan.png"); case HardwareType.Network: return("nic.png"); default: return("cpu.png"); } }
private void SubHardwareAdded(IHardware hardware, Node node) { HardwareNode hardwareNode = new HardwareNode(hardware, settings, unitManager); InsertSorted(node.Nodes, hardwareNode); foreach (IHardware subHardware in hardware.SubHardware) { SubHardwareAdded(subHardware, hardwareNode); } }
private void InsertSorted(Collection <Node> nodes, HardwareNode node) { int i = 0; while (i < nodes.Count && nodes[i] is HardwareNode && ((HardwareNode)nodes[i]).Hardware.HardwareType < node.Hardware.HardwareType) { i++; } nodes.Insert(i, node); }
private static XElement GenerateXML(Node root) { XElement rootElement = new XElement("info"); foreach (Node node in root.Nodes) { HardwareNode hardwareNode = node as HardwareNode; if (hardwareNode != null) { rootElement.Add(GenerateHardwareXML(hardwareNode)); } } return(rootElement); }
private void HardwareRemoved(IHardware hardware) { List <HardwareNode> nodesToRemove = new List <HardwareNode>(); foreach (Node node in root.Nodes) { HardwareNode hardwareNode = node as HardwareNode; if (hardwareNode != null && hardwareNode.Hardware == hardware) { nodesToRemove.Add(hardwareNode); } } foreach (HardwareNode hardwareNode in nodesToRemove) { root.Nodes.Remove(hardwareNode); } }
private void FindMonitorTarget(HardwareNode node) { switch (node.Hardware.HardwareType) { case HardwareType.CPU: cpus.Add(node); break; case HardwareType.HDD: hdds.Add(node); break; case HardwareType.Mainboard: mainboards.Add(node); break; default: break; } }
private static string GetHardwareImageFile(HardwareNode hn) { switch (hn.Hardware.HardwareType) { case HardwareType.Cpu: return("cpu.png"); case HardwareType.GpuNvidia: return("nvidia.png"); case HardwareType.GpuAmd: return("ati.png"); case HardwareType.Storage: return("hdd.png"); case HardwareType.Heatmaster: return("bigng.png"); case HardwareType.Motherboard: return("mainboard.png"); case HardwareType.SuperIO: return("chip.png"); case HardwareType.TBalancer: return("bigng.png"); case HardwareType.Memory: return("ram.png"); case HardwareType.AquaComputer: return("acicon.png"); case HardwareType.AeroCool: return("chip.png"); case HardwareType.Network: return("nic.png"); default: return("cpu.png"); } }
private void HardwareRemoved(IHardware hardware) { List <HardwareNode> nodesToRemove = new List <HardwareNode>(); foreach (Node node in root.Nodes) { HardwareNode hardwareNode = node as HardwareNode; if (hardwareNode != null && hardwareNode.Hardware == hardware) { nodesToRemove.Add(hardwareNode); } } foreach (HardwareNode hardwareNode in nodesToRemove) { root.Nodes.Remove(hardwareNode); hardwareNode.PlotSelectionChanged -= PlotSelectionChanged; } PlotSelectionChanged(this, null); }
private float?GetCurrentValueOfSensor(HardwareNode hardware, SensorType type) { float?maxValue = null; foreach (Node node in hardware.Nodes) { TypeNode typeNode = node as TypeNode; if (typeNode != null && typeNode.SensorType == type) { foreach (Node sensor in typeNode.Nodes) { SensorNode sensorNode = sensor as SensorNode; float? value = sensorNode.Sensor.Value; if (value.HasValue && (!maxValue.HasValue || maxValue.Value < value.Value)) { maxValue = value; } } } else { // subhardware HardwareNode hardwareNode = node as HardwareNode; if (hardwareNode != null) { float?value = GetCurrentValueOfSensor(hardwareNode, type); if (value.HasValue && (!maxValue.HasValue || maxValue.Value < value.Value)) { maxValue = value; } } } } return(maxValue); }
private void treeView_Click(object sender, EventArgs e) { MouseEventArgs m = e as MouseEventArgs; if (m == null || m.Button != MouseButtons.Right) { return; } NodeControlInfo info = treeView.GetNodeControlInfoAt( new Point(m.X, m.Y) ); treeView.SelectedNode = info.Node; if (info.Node != null) { SensorNode node = info.Node.Tag as SensorNode; if (node != null && node.Sensor != null) { treeContextMenu.MenuItems.Clear(); if (node.Sensor.Parameters.Length > 0) { MenuItem item = new MenuItem("Parameters..."); item.Click += delegate(object obj, EventArgs args) { ShowParameterForm(node.Sensor); }; treeContextMenu.MenuItems.Add(item); } if (nodeTextBoxText.EditEnabled) { MenuItem item = new MenuItem("Rename"); item.Click += delegate(object obj, EventArgs args) { nodeTextBoxText.BeginEdit(); }; treeContextMenu.MenuItems.Add(item); } if (node.IsVisible) { MenuItem item = new MenuItem("Hide"); item.Click += delegate(object obj, EventArgs args) { node.IsVisible = false; }; treeContextMenu.MenuItems.Add(item); } else { MenuItem item = new MenuItem("Unhide"); item.Click += delegate(object obj, EventArgs args) { node.IsVisible = true; }; treeContextMenu.MenuItems.Add(item); } treeContextMenu.MenuItems.Add(new MenuItem("-")); { MenuItem item = new MenuItem("Pen Color..."); item.Click += delegate(object obj, EventArgs args) { ColorDialog dialog = new ColorDialog(); dialog.Color = node.PenColor.GetValueOrDefault(); if (dialog.ShowDialog() == DialogResult.OK) { node.PenColor = dialog.Color; } }; treeContextMenu.MenuItems.Add(item); } { MenuItem item = new MenuItem("Reset Pen Color"); item.Click += delegate(object obj, EventArgs args) { node.PenColor = null; }; treeContextMenu.MenuItems.Add(item); } treeContextMenu.MenuItems.Add(new MenuItem("-")); { MenuItem item = new MenuItem("Show in Tray"); item.Checked = systemTray.Contains(node.Sensor); item.Click += delegate(object obj, EventArgs args) { if (item.Checked) { systemTray.Remove(node.Sensor); } else { systemTray.Add(node.Sensor, true); } }; treeContextMenu.MenuItems.Add(item); } if (gadget != null) { MenuItem item = new MenuItem("Show in Gadget"); item.Checked = gadget.Contains(node.Sensor); item.Click += delegate(object obj, EventArgs args) { if (item.Checked) { gadget.Remove(node.Sensor); } else { gadget.Add(node.Sensor); } }; treeContextMenu.MenuItems.Add(item); } if (node.Sensor.Control != null) { treeContextMenu.MenuItems.Add(new MenuItem("-")); IControl control = node.Sensor.Control; MenuItem controlItem = new MenuItem("Control"); MenuItem defaultItem = new MenuItem("Default"); defaultItem.Checked = control.ControlMode == ControlMode.Default; controlItem.MenuItems.Add(defaultItem); defaultItem.Click += delegate(object obj, EventArgs args) { control.SetDefault(); }; MenuItem manualItem = new MenuItem("Manual"); controlItem.MenuItems.Add(manualItem); manualItem.Checked = control.ControlMode == ControlMode.Software; for (int i = 0; i <= 100; i += 5) { if (i <= control.MaxSoftwareValue && i >= control.MinSoftwareValue) { MenuItem item = new MenuItem(i + " %"); item.RadioCheck = true; manualItem.MenuItems.Add(item); item.Checked = control.ControlMode == ControlMode.Software && Math.Round(control.SoftwareValue) == i; int softwareValue = i; item.Click += delegate(object obj, EventArgs args) { control.SetSoftware(softwareValue); }; } } treeContextMenu.MenuItems.Add(controlItem); } treeContextMenu.Show(treeView, new Point(m.X, m.Y)); } HardwareNode hardwareNode = info.Node.Tag as HardwareNode; if (hardwareNode != null && hardwareNode.Hardware != null) { treeContextMenu.MenuItems.Clear(); if (nodeTextBoxText.EditEnabled) { MenuItem item = new MenuItem("Rename"); item.Click += delegate(object obj, EventArgs args) { nodeTextBoxText.BeginEdit(); }; treeContextMenu.MenuItems.Add(item); } treeContextMenu.Show(treeView, new Point(m.X, m.Y)); } } }
//public static Transform Reference; public ForceDirectedPetri(Dictionary <PetrinetCondition, Valuation> conds, Dictionary <HardwareRequirements, Valuation> hard, ForceLayoutSettings settings, Vector3 bottomLeft, Vector3 topRight, Transform reference) { bottomLeft = reference.InverseTransformPoint(bottomLeft); topRight = reference.InverseTransformPoint(topRight); _bottomLeft = new Vector2(Mathf.Min(bottomLeft.x, topRight.x), Mathf.Min(bottomLeft.z, topRight.z)); _topRight = new Vector2(Mathf.Max(bottomLeft.x, topRight.x), Mathf.Max(bottomLeft.z, topRight.z)); _bottomLeft *= .8f; _topRight *= .8f; _layoutSettings = settings; _graph = new Graph(); _physics = new ForceDirected2D(_graph, _layoutSettings.Stiffness, _layoutSettings.Repulsion, _layoutSettings.Damping); _condToNodes = new Dictionary <PetrinetCondition, CondNode>(); _hardwareNodes = new Dictionary <HardwareRequirements, HardwareNode>(); _petriNodes = new List <PetriNode>(); PetriNode.Reference = reference; //Reference = reference; Func <Vector3, bool> withinBoundaries = delegate(Vector3 pos) { return(_bottomLeft.x <= pos.x && pos.x <= _topRight.x && _bottomLeft.y <= pos.z && pos.z <= _topRight.y); }; foreach (var condRadius in conds) { var condNode = new CondNode(condRadius.Key, condRadius.Value.Radius, condRadius.Value.Weight); if (!withinBoundaries(condNode.Visual.position)) { Debug.LogWarning(condNode.Visual.name + " not within boundaries"); } _petriNodes.Add(condNode); _graph.AddNode(condNode); _condToNodes[condRadius.Key] = condNode; } foreach (var hardwareRadius in hard) { var hardwareNode = new HardwareNode(hardwareRadius.Key, hardwareRadius.Value.Radius, hardwareRadius.Value.Weight); if (!withinBoundaries(hardwareNode.Visual.position)) { Debug.LogWarning(hardwareNode.Visual.name + " not within boundaries"); } _petriNodes.Add(hardwareNode); _graph.AddNode(hardwareNode); _hardwareNodes[hardwareRadius.Key] = hardwareNode; foreach (var transition in hardwareRadius.Key.gameObject.GetComponents <PetrinetTransition>()) { transition.In.ForEach(cond => AddEdge(_condToNodes[cond], hardwareNode)); transition.Out.ForEach(cond => AddEdge(hardwareNode, _condToNodes[cond])); } } foreach (var condNode in _condToNodes) { if (condNode.Key.Type == PetrinetCondition.ConditionType.Place) { condNode.Value.Kids = condNode.Key.GetComponentsInChildren <HardwareRequirements>() .Select(kid => _hardwareNodes[kid])//kid => kid.HardwareRequirements.transform) //.Distinct()/ .ToList(); condNode.Value.Kids.ForEach(kid => AddEdge(condNode.Value, kid)); } } }