private void CheckSelectedSpiceModels() { bool hasErrors = false; int i = 0; foreach (var xpath in selectors.rules.Where(xp => string.IsNullOrWhiteSpace(xp.xpath) == false)) { xpathsPanel.Controls[i].BackColor = xpathsPanel.BackColor; try { root.XPathSelectElements(xpath.xpath).OrderBy(el => (xpath.lowest ? -1 : 1) * el.Ancestors().Count()); } catch { hasErrors = true; xpathsPanel.Controls[i].BackColor = Color.Red; } i++; } if (hasErrors) { okButton.Enabled = false; return; } okButton.Enabled = true; var rootNode = this.selectedTreeView.Nodes[0]; var selected = FidelitySelectionRules.SelectElements(root, selectors); foreach (var node in getNodeAndDescendents(rootNode)) { node.NodeFont = selected.Contains((XElement)node.Tag) ? selectedTreeView.Font : regularFont; } }
public static HashSet <XElement> SelectElements(XElement e, FidelitySelectionRules rules) { HashSet <XElement> results = new HashSet <XElement>(); HashSet <XElement> parentsOfResults = new HashSet <XElement>(); foreach (var xpath in rules.rules.Concat(new FidelitySelectionRules.SelectionRule[] { new FidelitySelectionRules.SelectionRule() { xpath = "//Component/SpiceModel" } }).Where(xp => string.IsNullOrWhiteSpace(xp.xpath) == false)) { foreach (var element in e.XPathSelectElements(xpath.xpath).OrderBy(el => (xpath.lowest ? -1 : 1) * el.Ancestors().Count())) { if (element is XElement && ((XElement)element).Name == "SpiceModel") { // FIXME perf is probably not good here if (element.Ancestors().Any(parentsOfResults.Contains) == false && element.Parent.DescendantNodes().Any(parentsOfResults.Contains) == false) { results.Add(element); parentsOfResults.Add(element.Parent); } } } } return(results); }
public static void SerializeInRegistry(MgaFCO currentobj, FidelitySelectionRules rules) { string savedJson = JsonConvert.SerializeObject(rules, Newtonsoft.Json.Formatting.None, new JsonSerializerSettings() { }); currentobj.RegistryValue["SpiceFidelitySettings"] = savedJson; }
public static FidelitySelectionRules DeserializeSpiceFidelitySelection(IMgaFCO currentobj) { FidelitySelectionRules xpaths = null; var settings = currentobj.RegistryValue["SpiceFidelitySettings"]; if (settings == null) { return(null); } try { xpaths = JsonConvert.DeserializeObject <FidelitySelectionRules>(settings); } catch (JsonException) { } return(xpaths); }
private void DoSpiceFidelitySelection(MgaFCO currentobj) { FidelitySelectionRules xpaths = FidelitySelectionRules.DeserializeSpiceFidelitySelection(currentobj); if (xpaths == null) { xpaths = new FidelitySelectionRules(); } var system = sut.Referred.DesignElement; XElement root = FidelitySelectionRules.CreateForAssembly(system); var sp = new SpiceSelector(root, xpaths); using (sp) { sp.ShowDialog(); if (sp.DialogResult == System.Windows.Forms.DialogResult.OK) { FidelitySelectionRules.SerializeInRegistry(currentobj, xpaths); } return; } }
public SpiceSelector(XElement root, FidelitySelectionRules selectors) { this.root = root; InitializeComponent(); this.selectedTreeView.CheckBoxes = true; this.selectedTreeView.Nodes.Clear(); TreeNode rootNode = null; Queue <Tuple <TreeNode, XElement> > elements = new Queue <Tuple <TreeNode, XElement> >(); elements.Enqueue(new Tuple <TreeNode, XElement>(null, root)); while (elements.Count > 0) { var tuple = elements.Dequeue(); var parentTreeNode = tuple.Item1; var element = tuple.Item2; TreeNode node; if (parentTreeNode == null) { node = rootNode = new TreeNode((string)element.Attribute("Name")); this.selectedTreeView.Nodes.Add(rootNode); } else { node = new TreeNode((string)element.Attribute("Name")); parentTreeNode.Nodes.Add(node); } node.Tag = element; foreach (var child in element.Elements()) { elements.Enqueue(new Tuple <TreeNode, XElement>(node, child)); } node.Expand(); } this.CancelButton = cancelButton; this.AcceptButton = okButton; this.selectors = selectors; this.Load += SpiceSelector_Load; foreach (var selector in selectors.rules) { addXPath(this.xpathsPanel, selector); } selectors.rules.Add(new FidelitySelectionRules.SelectionRule() { }); addXPath(this.xpathsPanel, selectors.rules.Last()); EnableXPathsPanelButtons(); checkSelectedSpiceModelsDebounceTimer = new Timer(); checkSelectedSpiceModelsDebounceTimer.Interval = 100; checkSelectedSpiceModelsDebounceTimer.Tick += (obj, args) => { CheckSelectedSpiceModels(); checkSelectedSpiceModelsDebounceTimer.Stop(); }; this.FormClosing += (sender, e) => { checkSelectedSpiceModelsDebounceTimer.Dispose(); }; // need to bold everything, then switch to regular, or the nodes are too short to display the bold string regularFont = new Font(selectedTreeView.Font, FontStyle.Regular); this.Disposed += (sender, e) => { regularFont.Dispose(); }; selectedTreeView.CheckBoxes = false; }