private void UpdateButtonsEnabledStatus() { UIOutputItem source = SelectedSource; UIInputItem target = SelectedTarget; List <UIExchangeItem> sources = _treeSource.GetCheckedExchangeItems(); bool checkedSourceAndTarget = source != null && target != null; // Make it look as if inactive rather than do it as // tooltips will not work on inactive buttons btnLinkAdd.ForeColor = checkedSourceAndTarget ? SystemColors.ActiveCaptionText : SystemColors.InactiveCaptionText; btnLinkRemove.ForeColor = listLinks.SelectedItem != null ? SystemColors.ActiveCaptionText : SystemColors.InactiveCaptionText; btnViewer.ForeColor = checkedSourceAndTarget ? SystemColors.ActiveCaptionText : SystemColors.InactiveCaptionText; btnAddSources.ForeColor = checkedSourceAndTarget ? SystemColors.ActiveCaptionText : SystemColors.InactiveCaptionText; btnArgEdit.ForeColor = source != null && source.IExchangeItem is IAdaptedOutput ? SystemColors.ActiveCaptionText : SystemColors.InactiveCaptionText; }
void expandOutputItem(TreeNode node, UIOutputItem item) { List <UIOutputItem> children = currentLink.FindNextChildrenInChain(item); for (int i = 0; i < children.Count; i++) { UIOutputItem child = children[0]; TreeNode n1 = null; if (!TreeNodeContains(child, node, out n1)) { n1 = new TreeNode(child.Caption); n1.Tag = child; n1.ImageKey = "RESOURCE.BMP"; n1.SelectedImageKey = "RESOURCE.BMP"; node.Nodes.Add(n1); if (!fastLookUpOutputs.ContainsKey(child)) { fastLookUpOutputs.Add(child, n1); } } if (n1 != null) { expandOutputItem(n1, child); } } foreach (Link link in connection.Links) { children = link.FindNextChildrenInChain(item); for (int i = 0; i < children.Count; i++) { UIOutputItem child = children[0]; TreeNode n1 = null; if (!TreeNodeContains(child, node, out n1)) { n1 = new TreeNode(child.Caption); n1.Tag = child; n1.ImageKey = "RESOURCE.BMP"; n1.SelectedImageKey = "RESOURCE.BMP"; node.Nodes.Add(n1); if (!fastLookUpOutputs.ContainsKey(child)) { fastLookUpOutputs.Add(child, n1); } } if (n1 != null) { expandOutputItem(n1, child); } } } }
public FactoriesDialog(List <UIModel> models, UIOutputItem itemOut, UIInputItem itemIn) { _itemOut = itemOut; _itemIn = itemIn; UIAdaptedFactory factory; string firstSourceFactory = null; foreach (UIModel model in models) { foreach (IAdaptedOutputFactory iFactory in model.LinkableComponent.AdaptedOutputFactories) { factory = new UIAdaptedFactory(); if (_itemOut.Component == model.LinkableComponent) { factory.InitialiseAsNative(iFactory.Id, model.LinkableComponent); if (firstSourceFactory == null) { firstSourceFactory = factory.ToString(); } } else { factory.InitialiseAs3rdParty(iFactory.GetType(), model.LinkableComponent); } AddFactory(factory); } } InitializeComponent(); groupBox2.Text = string.Format( "Factory sources that adapt \"{0}\" -> \"{1}\"", itemOut.Caption, itemIn.Caption); UpdateUIFactories(); if (firstSourceFactory != null) { cbFactories.SelectedIndex = cbFactories.FindStringExact(firstSourceFactory); } UpdateControlEnabling(); }
private void OnAddSources(object sender, System.EventArgs e) { UIOutputItem source = SelectedSource; UIInputItem target = SelectedTarget; if (source == null || target == null) { return; } FactoriesDialog dlg = new FactoriesDialog(_models, source, target); if (dlg.ShowDialog(this) == DialogResult.Cancel) { return; } _treeSource.TreeAdd(dlg.Adapters); UpdateButtonsEnabledStatus(); }
private void OnEditArgs(object sender, System.EventArgs e) { UIOutputItem source = SelectedSource; if (source == null) { return; } IAdaptedOutput adapted = source.IExchangeItem as IAdaptedOutput; if (adapted == null) { return; } AdaptedArguments dlg = new AdaptedArguments(); dlg.Initialise(adapted.Arguments); dlg.ShowDialog(this); }
private void OnViewElementSet(object sender, System.EventArgs e) { UIOutputItem source = SelectedSource; UIInputItem target = SelectedTarget; ArrayList elementSets = new ArrayList(); if (source != null) { elementSets.Add(source.ElementSet); } if (target != null) { elementSets.Add(target.ElementSet); } if (elementSets.Count > 0) { _elementSetViewer.PopulateDialog(elementSets); _elementSetViewer.ShowDialog(); } }
private void buttonAddAdaptedOutput_Click(object sender, EventArgs e) { UIOutputItem output = null; if (treeViewSources.SelectedNode != null && treeViewSources.SelectedNode.Checked && treeViewSources.SelectedNode.Tag is UIOutputItem) { output = (UIOutputItem)treeViewSources.SelectedNode.Tag; if (listBoxAdaptedOutputs.SelectedItem is UIAdaptedOutputItem) { UIAdaptedOutputItem adaptedOutput = (UIAdaptedOutputItem)listBoxAdaptedOutputs.SelectedItem; if (adaptedOutput.Adaptee == output) { if (fastLookUpOutputs.ContainsKey(output)) { TreeNode parent = fastLookUpOutputs[output]; TreeNode child = new TreeNode(adaptedOutput.Caption); child.Tag = adaptedOutput; child.ImageKey = "RESOURCE.BMP"; child.SelectedImageKey = "RESOURCE.BMP"; child.Checked = true; parent.Nodes.Add(child); fastLookUpOutputs.Add(adaptedOutput, child); parent.ExpandAll(); UpdateCurrentLink(); } } else { SetErrorText("Selected adaptor is not valid for selected output"); } } } }
void SetValidAdatedOutputs(TreeNode outputSender = null) { UIInputItem input = null; UIOutputItem output = null; if (outputSender != null && outputSender.Tag is UIOutputItem) { output = outputSender.Tag as UIOutputItem; } else { SetErrorText("No output item has been selected"); } List <UIInputItem> checkedInputs = GetDownStreamCheckedItems <UIInputItem>(treeViewTargets.Nodes); if (checkedInputs.Count != 1) { SetErrorText("More than one input item has been selected"); } else { input = checkedInputs[0]; } if (input == null) { listBoxAdaptedOutputs.DataSource = null; return; } if (output == null) { listBoxAdaptedOutputs.DataSource = null; return; } List <UIAdaptedOutputItem> ids = new List <UIAdaptedOutputItem>(); foreach (UIAdaptedFactory factory in externalFactories) { IIdentifiable[] idf = factory.GetAvailableAdaptedOutputIds(output, input); foreach (IIdentifiable f in idf) { ITimeSpaceAdaptedOutput adpout = (ITimeSpaceAdaptedOutput)factory.CreateAdaptedOutput(f, output, input); UIAdaptedOutputItem uiadpout = new UIAdaptedOutputItem(factory, f, adpout, output); ids.Add(uiadpout); } } foreach (IAdaptedOutputFactory factory in connection.SourceModel.LinkableComponent.AdaptedOutputFactories) { UIAdaptedFactory fac = new UIAdaptedFactory(); fac.InitialiseAsNative(factory.Id, connection.SourceModel.LinkableComponent); IIdentifiable[] idf = factory.GetAvailableAdaptedOutputIds(output, input); foreach (IIdentifiable f in idf) { UIAdaptedFactory tempFac = new UIAdaptedFactory(); tempFac.InitialiseAsNative(factory.Id, connection.SourceModel.LinkableComponent); ITimeSpaceAdaptedOutput adpout = (ITimeSpaceAdaptedOutput)factory.CreateAdaptedOutput(f, output, input); UIAdaptedOutputItem uiadpout = new UIAdaptedOutputItem(tempFac, f, adpout, output); ids.Add(uiadpout); } } foreach (TreeNode node in outputSender.Nodes) { if (node.Tag != null && node.Tag is UIAdaptedOutputItem) { UIAdaptedOutputItem item = (UIAdaptedOutputItem)node.Tag; for (int i = 0; i < ids.Count; i++) { if (item.Id == ids[i].Id) { ids.RemoveAt(i); break; } } } } listBoxAdaptedOutputs.DataSource = ids; listBoxAdaptedOutputs.DisplayMember = "Caption"; }
void updateSourcesTreeView() { treeViewSources.SuspendLayout(); treeViewSources.Nodes.Clear(); fastLookUpOutputs = new Dictionary <UIOutputItem, TreeNode>(); UIModel sourceModel = connection.SourceModel; Dictionary <string, TreeNode> quantities = new Dictionary <string, TreeNode>(); foreach (IBaseOutput output in sourceModel.LinkableComponent.Outputs) { IValueDefinition value = output.ValueDefinition; TreeNode node = null; if (!quantities.ContainsKey(value.Caption)) { node = new TreeNode(value.Caption); node.ImageKey = "valueDef"; quantities.Add(value.Caption, node); treeViewSources.Nodes.Add(node); } else { node = quantities[value.Caption]; } TreeNode item = new TreeNode(output.Id); item.ImageKey = "id"; item.Tag = output; node.Nodes.Add(item); if (output is ITimeSpaceOutput) { ITimeSpaceOutput tspaceOutput = (ITimeSpaceOutput)output; UIOutputItem uitem = (from n in connection.Links where n.FindInChain(tspaceOutput) != null select n.FindInChain(tspaceOutput)).FirstOrDefault(); if (uitem != null) { item.Tag = uitem; fastLookUpOutputs.Add(uitem, item); expandOutputItem(item, uitem); } else { uitem = new UIOutputItem(tspaceOutput); item.Tag = uitem; fastLookUpOutputs.Add(uitem, item); } if (tspaceOutput.SpatialDefinition is IElementSet) { IElementSet eSet = (IElementSet)tspaceOutput.SpatialDefinition; switch (eSet.ElementType) { case ElementType.IdBased: item.ImageKey = "id"; break; case ElementType.Point: if (!eSet.HasZ) { item.ImageKey = "point2d"; item.SelectedImageKey = "point2d"; } else { item.ImageKey = "point3d"; item.SelectedImageKey = "point3d"; } break; case ElementType.Polygon: if (!eSet.HasZ) { item.ImageKey = "polygon2d"; item.SelectedImageKey = "polygon2d"; } else { item.ImageKey = "polygon3d"; item.SelectedImageKey = "polygon3d"; } break; case ElementType.Polyhedron: item.ImageKey = "polyhedra"; item.SelectedImageKey = "polyhedra"; break; case ElementType.PolyLine: if (!eSet.HasZ) { item.ImageKey = "mline2d"; item.SelectedImageKey = "mline2d"; } else { item.ImageKey = "mline3d"; item.SelectedImageKey = "mline3d"; } break; } } } } treeViewSources.ExpandAll(); treeViewSources.ResumeLayout(); }