/// <summary> /// Implementation of depth first search algorithm for experiment tree. /// </summary> /// <param name="targetNode"></param> public ConfigNodeViewModel DepthFirstSearch(string nodeName, string alias = "") { var nodeStack = new Stack <ConfigNodeViewModel>(new[] { children[0] }); while (nodeStack.Any()) { ConfigNodeViewModel node = nodeStack.Pop(); if (node.nodeDefinition != null) { if (node.nodeDefinition.Attributes[XMLTags.nameAttribute].Value.Equals(nodeName)) { if (node.nodeDefinition.Attributes[XMLTags.aliasAttribute] != null) { if (node.nodeDefinition.Attributes[XMLTags.aliasAttribute].Value.Equals(alias)) { return(node); } } if (node.parent is NestedConfigNode) { return(node); } return(null); } } WalkThroughBranch(ref nodeStack, node); } return(null); }
/// <summary> /// Constructor called when loading an experiment config file /// </summary> /// <param name="parentExperiment"></param> /// <param name="parentNode"></param> /// <param name="classDefinition">Class of the node in app definitions</param> /// <param name="parentXPath"></param> /// <param name="configNode">Node in simion.exp file with the configuration for a node class</param> public LinkedNodeViewModel(ExperimentViewModel parentExperiment, ConfigNodeViewModel parentNode, XmlNode classDefinition, XmlNode configNode = null) { m_parentExperiment = parentExperiment; nodeDefinition = classDefinition; m_parent = parentNode; foreach (XmlNode configChildNode in configNode) { if (configChildNode.Name.Equals(XMLTags.linkedNodeTag) && configChildNode.Attributes[XMLTags.nameAttribute].Value .Equals(classDefinition.Attributes[XMLTags.nameAttribute].Value)) { OriginName = configChildNode.Attributes[XMLTags.originNodeAttribute].Value; if (configChildNode.Attributes[XMLTags.aliasAttribute] != null) { OriginAlias = configChildNode.Attributes[XMLTags.aliasAttribute].Value; } } } name = nodeDefinition.Attributes[XMLTags.nameAttribute].Value; LinkedNode = getInstance(parentExperiment, parentNode, classDefinition, parentExperiment.AppName, configNode); }
public MultiValuedConfigViewModel(AppViewModel appDefinition, ConfigNodeViewModel parent , XmlNode definitionNode, string parentXPath, XmlNode configNode = null, bool initChildren = true) { commonInit(appDefinition, parent, definitionNode, parentXPath); m_className = definitionNode.Attributes[XMLConfig.classAttribute].Value; if (definitionNode.Attributes.GetNamedItem(XMLConfig.optionalAttribute) != null) { m_bOptional = definitionNode.Attributes[XMLConfig.optionalAttribute].Value == "true"; } else { m_bOptional = false; } if (configNode != null) { foreach (XmlNode configChild in configNode.ChildNodes) { if (configChild.Name == name) { children.Add(new MultiValuedItemConfigViewModel(appDefinition, this, definitionNode, m_xPath, configChild)); } } } else //default initialization { if (initChildren && !m_bOptional) { children.Add(new MultiValuedItemConfigViewModel(appDefinition, this, definitionNode, m_xPath)); } } }
/// <summary> /// Unlink the node removing it from its origin linked nodes list and restore it to its /// original node class. /// </summary> public void UnlinkNode() { LinkedNodeViewModel linkedNode = (LinkedNodeViewModel)this; linkedNode.Origin.LinkedNodes.Remove(linkedNode); NestedConfigNode parent = (NestedConfigNode)linkedNode.m_parent; ConfigNodeViewModel unlinkedNode = getInstance(m_parentExperiment, parent, linkedNode.nodeDefinition, m_parentExperiment.AppName); // Keep the content of the former ogirin node if (!(linkedNode.Origin is ForkedNodeViewModel)) { unlinkedNode.content = linkedNode.Origin.content; } else { ForkedNodeViewModel forkedNode = (ForkedNodeViewModel)linkedNode.LinkedNode; int valueIndex = int.Parse(forkedNode.currentValueIndex.Substring(0, 1)) - 1; ForkValueViewModel value = (ForkValueViewModel)forkedNode.children[valueIndex]; unlinkedNode.content = value.configNode.content; } // For node substitution We don't need the index in the whole tree just // the index in the parent children list int index = parent.children.IndexOf(linkedNode); parent.children.Remove(linkedNode); parent.children.Insert(index, unlinkedNode); unlinkedNode.CanBeLinked = true; unlinkedNode.IsLinkable = false; }
protected void childrenInit(AppViewModel appViewModel, XmlNode classDefinition , string parentXPath, XmlNode configNode = null) { ConfigNodeViewModel childNode; XmlNode forkNode; if (classDefinition != null) { foreach (XmlNode child in classDefinition.ChildNodes) { forkNode = getForkChild(child.Attributes[XMLConfig.nameAttribute].Value, configNode); if (forkNode != null) { children.Add(new ForkedNodeViewModel(appViewModel, this, child, forkNode)); } else { childNode = ConfigNodeViewModel.getInstance(appViewModel, this, child , parentXPath, configNode); if (childNode != null) { children.Add(childNode); } } } } }
//FACTORY public static ConfigNodeViewModel getInstance(AppViewModel appDefinition, ConfigNodeViewModel parent, XmlNode definitionNode, string parentXPath, XmlNode configNode = null) { switch (definitionNode.Name) { case XMLConfig.integerNodeTag: return(new IntegerValueConfigViewModel(appDefinition, parent, definitionNode, parentXPath, configNode)); case XMLConfig.boolNodeTag: return(new BoolValueConfigViewModel(appDefinition, parent, definitionNode, parentXPath, configNode)); case XMLConfig.doubleNodeTag: return(new DoubleValueConfigViewModel(appDefinition, parent, definitionNode, parentXPath, configNode)); case XMLConfig.stringNodeTag: return(new StringValueConfigViewModel(appDefinition, parent, definitionNode, parentXPath, configNode)); case XMLConfig.filePathNodeTag: return(new FilePathValueConfigViewModel(appDefinition, parent, definitionNode, parentXPath, configNode)); case XMLConfig.dirPathNodeTag: return(new DirPathValueConfigViewModel(appDefinition, parent, definitionNode, parentXPath, configNode)); case XMLConfig.stateVarRefTag: return(new WorldVarRefValueConfigViewModel(appDefinition, WorldVarType.StateVar, parent, definitionNode, parentXPath, configNode)); case XMLConfig.actionVarRefTag: return(new WorldVarRefValueConfigViewModel(appDefinition, WorldVarType.ActionVar, parent, definitionNode, parentXPath, configNode)); case XMLConfig.branchNodeTag: return(new BranchConfigViewModel(appDefinition, parent, definitionNode, parentXPath, configNode)); case XMLConfig.choiceNodeTag: return(new ChoiceConfigViewModel(appDefinition, parent, definitionNode, parentXPath, configNode)); case XMLConfig.choiceElementNodeTag: return(new ChoiceElementConfigViewModel(appDefinition, parent, definitionNode, parentXPath, configNode)); case XMLConfig.enumNodeTag: return(new EnumeratedValueConfigViewModel(appDefinition, parent, definitionNode, parentXPath, configNode)); case XMLConfig.multiValuedNodeTag: return(new MultiValuedConfigViewModel(appDefinition, parent, definitionNode, parentXPath, configNode)); } return(null); }
public ChoiceConfigViewModel(AppViewModel appDefinition, ConfigNodeViewModel parent , XmlNode definitionNode , string parentXPath, XmlNode configNode = null, bool initChildren = true) { string choiceElementName; commonInit(appDefinition, parent, definitionNode, parentXPath); if (configNode != null) { configNode = configNode[name]; } if (initChildren) { foreach (XmlNode choiceElement in definitionNode.ChildNodes) { choiceElementName = choiceElement.Attributes[XMLConfig.nameAttribute].Value; m_choiceNames.Add(choiceElementName); if (configNode != null && choiceElementName == configNode.ChildNodes[0].Name) { loadSelectedChoiceElement(choiceElementName, configNode); } } } }
/// <summary> /// Cancel a linking process between two nodes. /// </summary> public void CancelLinking(ConfigNodeViewModel originNode) { Linking = IsLinkOrigin = false; IsLinkable = true; m_parentExperiment.LinkOriginNode = null; m_parentExperiment.CheckLinkableNodes(originNode, false); }
/// <summary> /// Take the right-clicked node as the origin node to link with all the posible linkable /// nodes (i.e. nodes of the same class). Linkable nodes CanBeLinked property value are set /// to true. /// </summary> /// <param name="originNode">The origin node of the linking process</param> public void LinkThisNode(ConfigNodeViewModel originNode) { Linking = IsLinkOrigin = true; IsLinkable = false; m_parentExperiment.LinkOriginNode = originNode; m_parentExperiment.CheckLinkableNodes(originNode); }
//constructor called from the editor on forking a node public ForkValueViewModel(string valueName, ForkedNodeViewModel parent, ConfigNodeViewModel forkedNode) { name = valueName; m_parent = parent; configNode = forkedNode; //the config node now hangs from this fork value configNode.parent = this; }
//constructor called when loading a fork from a .badger file public ForkValueViewModel(ExperimentViewModel parentExperiment, XmlNode classDefinition, ConfigNodeViewModel parentNode, XmlNode configNode) { name = configNode.Attributes[XMLTags.nameAttribute].Value; //not sure how to do this in a more elegant way this.configNode = getInstance(parentExperiment, parentNode, classDefinition, parentNode.xPath, configNode); this.configNode.bCanBeForked = false; //already belongs to a fork }
public void init(string appDefinitionFileName, XmlNode configRootNode, string experimentName) { XmlDocument appDefinition = new XmlDocument(); appDefinition.Load(appDefinitionFileName); foreach (XmlNode rootChild in appDefinition.ChildNodes) { if (rootChild.Name == XMLConfig.appNodeTag) { //APP node m_preFiles.Clear(); m_appName = rootChild.Attributes[XMLConfig.nameAttribute].Value; name = experimentName; if (rootChild.Attributes.GetNamedItem(XMLConfig.versionAttribute) != null) { m_version = rootChild.Attributes[XMLConfig.versionAttribute].Value; } else { CaliburnUtility.showWarningDialog("Error reading version attribute: " + XMLConfig.experimentConfigVersion , "ERROR"); m_version = "0.0.0.0"; } foreach (XmlNode child in rootChild.ChildNodes) { //Only EXE, PRE, INCLUDE and BRANCH children nodes if (child.Name == XMLConfig.exeNodeTag) { m_exeFile = child.InnerText; } else if (child.Name == XMLConfig.preNodeTag) { m_preFiles.Add(child.InnerText); } else if (child.Name == XMLConfig.includeNodeTag) { loadIncludedDefinitionFile(child.InnerText); } else { children.Add(ConfigNodeViewModel.getInstance(this, null, child, m_appName, configRootNode)); //here we assume definitions are before the children } } } } //deferred load step: enumerated types doDeferredLoadSteps(); }
public void Initialize(string appDefinitionFileName, XmlNode configRootNode, string experimentName) { //Create wires m_wiresViewModel = new WiresViewModel(this); XmlDocument appDefinition = new XmlDocument(); appDefinition.Load(appDefinitionFileName); foreach (XmlNode rootChild in appDefinition.ChildNodes) { if (rootChild.Name == XMLTags.AppNodeTag) { //APP node m_appName = rootChild.Attributes[XMLTags.nameAttribute].Value; Name = experimentName; if (rootChild.Attributes.GetNamedItem(XMLTags.versionAttribute) != null) { m_version = rootChild.Attributes[XMLTags.versionAttribute].Value; } else { CaliburnUtility.ShowWarningDialog("Error reading version attribute: " + XMLTags.ExperimentConfigVersion, "ERROR"); m_version = "0.0.0.0"; } foreach (XmlNode child in rootChild.ChildNodes) { if (child.Name == Herd.Network.XmlTags.Version) { m_appVersions.Add(new AppVersion(child)); } else if (child.Name == Herd.Network.XmlTags.Include) { LoadIncludedDefinitionFile(child.InnerText); } else { // here we expect definitions before any children that uses them children.Add(ConfigNodeViewModel.getInstance(this, null, child, m_appName, configRootNode)); } } } } LinkNodes(); //deferred load step: enumerated types DoDeferredLoadSteps(); }
public void ForkThisNode(ConfigNodeViewModel originNode) { bCanBeForked = false; if (originNode.m_parent != null) { originNode.m_parent.ForkChild(originNode); } else { Console.WriteLine("Can't fork this node because it has no parent: " + name); } }
public override ConfigNodeViewModel clone() { BranchConfigViewModel newBranch = new BranchConfigViewModel(m_parentExperiment, parent, nodeDefinition, parent.xPath, null, false); foreach (ConfigNodeViewModel child in children) { ConfigNodeViewModel clonedChild = child.clone(); clonedChild.parent = newBranch; newBranch.children.Add(clonedChild); } return(newBranch); }
//Constructor used from the experiment editor public ForkedNodeViewModel(AppViewModel appViewModel, ConfigNodeViewModel forkedNode) { m_parent = forkedNode.parent; ForkValueViewModel newForkValue = new ForkValueViewModel("Value-0", this, forkedNode); children.Add(newForkValue); selectedForkValue = newForkValue; m_appViewModel = appViewModel; nodeDefinition = forkedNode.nodeDefinition; name = forkedNode.name; NotifyOfPropertyChange(() => selectedForkValue); }
public override ConfigNodeViewModel clone() { MultiValuedItemConfigViewModel newItem = new MultiValuedItemConfigViewModel(m_parentExperiment , parent as MultiValuedConfigViewModel , nodeDefinition, parent.xPath); foreach (ConfigNodeViewModel child in children) { ConfigNodeViewModel clonedChild = child.clone(); clonedChild.parent = newItem; newItem.children.Add(clonedChild); } return(newItem); }
public override ConfigNodeViewModel clone() { ChoiceConfigViewModel newChoice = new ChoiceConfigViewModel(m_appViewModel, parent , nodeDefinition, parent.xPath, null); foreach (ConfigNodeViewModel child in children) { ConfigNodeViewModel clonedChild = child.clone(); clonedChild.parent = newChoice; newChoice.children.Add(clonedChild); } newChoice.selectedChoiceName = selectedChoiceName; return(newChoice); }
/// <summary> /// Constructor used from the experiment editor /// </summary> /// <param name="parentExperiment"></param> /// <param name="originNode"></param> /// <param name="targetNode"></param> public LinkedNodeViewModel(ExperimentViewModel parentExperiment, ConfigNodeViewModel originNode, ConfigNodeViewModel targetNode) { m_parent = targetNode.parent; m_parentExperiment = parentExperiment; Origin = originNode; nodeDefinition = targetNode.nodeDefinition; name = targetNode.name; comment = nodeDefinition.Attributes[XMLTags.commentAttribute].Value; content = originNode.content; CreateLinkedNode(); }
private void WalkThroughBranch(ref Stack <ConfigNodeViewModel> nodeStack, ConfigNodeViewModel branchRoot) { if (branchRoot is NestedConfigNode) { NestedConfigNode branch = (NestedConfigNode)branchRoot; if (branch.children.Count > 0) { foreach (var node in branch.children) { nodeStack.Push(node); } } } }
/// <summary> /// /// </summary> public void CreateLinkedNode() { // We need the linked node to be shown exactly as the origin node LinkedNode = Origin.clone(); // But we need to protects its identity, so lets put a few things back to normal LinkedNode.nodeDefinition = nodeDefinition; LinkedNode.LinkedNodes = LinkedNodes; LinkedNode.name = name; LinkedNode.comment = nodeDefinition.Attributes[XMLTags.commentAttribute].Value; if (LinkedNode is NestedConfigNode) { NestedConfigNode node = (NestedConfigNode)LinkedNode; } }
public IntegerValueConfigViewModel(AppViewModel appViewModel, ConfigNodeViewModel parent, XmlNode definitionNode, string parentXPath, XmlNode configNode = null) { commonInit(appViewModel, parent, definitionNode, parentXPath); if (configNode == null || configNode[name] == null) { //default init content = definitionNode.Attributes[XMLConfig.defaultAttribute].Value; textColor = XMLConfig.colorDefaultValue; } else { //init from config file content = configNode[name].InnerText; } }
public IntegerValueConfigViewModel(ExperimentViewModel parentExperiment, ConfigNodeViewModel parent, XmlNode definitionNode, string parentXPath, XmlNode configNode = null) { CommonInitialization(parentExperiment, parent, definitionNode, parentXPath); if (configNode == null || configNode[name] == null) { //default init content = definitionNode.Attributes[XMLTags.defaultAttribute].Value; textColor = XMLTags.colorDefaultValue; } else { //init from config file content = configNode[name].InnerText; } }
public override void forkChild(ConfigNodeViewModel forkedChild) { ForkedNodeViewModel newForkNode; if (m_appViewModel != null) { //cross-reference newForkNode = new ForkedNodeViewModel(m_appViewModel, forkedChild); int oldIndex = children.IndexOf(forkedChild); if (oldIndex >= 0) { children.Remove(forkedChild); children.Insert(oldIndex, newForkNode); } } }
/// <summary> /// Implementation of depth first search algorithm for experiment tree. /// </summary> /// <param name="targetNode"></param> public ConfigNodeViewModel DepthFirstSearch(ConfigNodeViewModel targetNode) { var nodeStack = new Stack <ConfigNodeViewModel>(new[] { children[0] }); while (nodeStack.Any()) { ConfigNodeViewModel node = nodeStack.Pop(); if (node.Equals(targetNode)) { return(node); } WalkThroughBranch(ref nodeStack, node); } return(null); }
public WireConnectionViewModel(ExperimentViewModel parentExperiment, ConfigNodeViewModel parent, XmlNode definitionNode, string parentXPath, XmlNode configNode = null) { CommonInitialization(parentExperiment, parent, definitionNode, parentXPath); //the possible values taken by this world variable m_parentExperiment.GetWireNames(ref m_wireNames); NotifyOfPropertyChange(() => WireNames); if (configNode != null) { configNode = configNode[name]; SelectedWire = configNode.InnerText; parentExperiment.AddWire(SelectedWire); } m_parentExperiment.RegisterDeferredLoadStep(Update); m_parentExperiment.RegisterWireConnection(Update); }
public EnumeratedValueConfigViewModel(AppViewModel appDefinition, ConfigNodeViewModel parent, XmlNode definitionNode, string parentXPath, XmlNode configNode = null) { commonInit(appDefinition, parent, definitionNode, parentXPath); m_class = definitionNode.Attributes[XMLConfig.classAttribute].Value; enumeratedNames = m_appViewModel.getEnumeratedType(m_class); if (configNode == null || configNode[name] == null) { content = m_default; textColor = XMLConfig.colorDefaultValue; } else { //init from config file content = configNode[name].InnerText; } }
public EnumeratedValueConfigViewModel(ExperimentViewModel parentExperiment, ConfigNodeViewModel parent, XmlNode definitionNode, string parentXPath, XmlNode configNode = null) { CommonInitialization(parentExperiment, parent, definitionNode, parentXPath); m_class = definitionNode.Attributes[XMLTags.classAttribute].Value; enumeratedNames = m_parentExperiment.GetEnumeratedType(m_class); if (configNode == null || configNode[name] == null) { content = m_default; textColor = XMLTags.colorDefaultValue; } else { //init from config file content = configNode[name].InnerText; } }
public ChoiceElementConfigViewModel(ExperimentViewModel parentExperiment, ConfigNodeViewModel parent, XmlNode definitionNode , string parentXPath, XmlNode configNode = null) { CommonInitialization(parentExperiment, parent, definitionNode, parentXPath); m_className = definitionNode.Attributes[XMLTags.classAttribute].Value; if (definitionNode.Attributes.GetNamedItem(XMLTags.windowAttribute) != null) { m_window = definitionNode.Attributes[XMLTags.windowAttribute].Value; } else { m_window = ""; } if (definitionNode.Attributes.GetNamedItem(XMLTags.optionalAttribute) != null) { m_bOptional = definitionNode.Attributes[XMLTags.optionalAttribute].Value == "true"; } else { m_bOptional = false; } if (definitionNode.Attributes.GetNamedItem(XMLTags.badgerMetadataAttribute) != null) { //BadgerMetadata="World=Wind-turbine" string metadata = definitionNode.Attributes[XMLTags.badgerMetadataAttribute].Value; if (metadata.StartsWith("World=")) { m_selectWorld = metadata.Remove(0, "World=".Length); } m_parentExperiment.SelectWorld(m_selectWorld); } if (configNode != null) { configNode = configNode[name]; } //we allow an undefined class ("", most likely) and we just ignore children childrenInit(parentExperiment, parentExperiment.GetClassDefinition(m_className, true) , m_xPath, configNode); }
//Initialization stuff common to all types of configuration nodes protected void CommonInitialization(ExperimentViewModel parentExperiment, ConfigNodeViewModel parent, XmlNode definitionNode, string parentXPath) { name = definitionNode.Attributes[XMLTags.nameAttribute].Value; m_parent = parent; m_parentExperiment = parentExperiment; nodeDefinition = definitionNode; xPath = parentXPath + "/" + name; if (definitionNode.Attributes.GetNamedItem(XMLTags.defaultAttribute) != null) { m_default = definitionNode.Attributes[XMLTags.defaultAttribute].Value; } if (definitionNode.Attributes.GetNamedItem(XMLTags.commentAttribute) != null) { comment = definitionNode.Attributes[XMLTags.commentAttribute].Value; } }