private void Tree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { // Store currently selected attribute, in case we just unselect + select the current item to refresh if (Tree.SelectedItem == null) { // We're unselcting, this is the old data we want to restore in future call of this event GuiTreeAttrib attrib = (TreeDetails.SelectedItem as GuiTreeAttrib); if (attrib == null) { _oldSelectedAttrib = null; _alternativeSelectedAttrib = null; } else { _oldSelectedAttrib = attrib.DataAttrib; int i = TreeDetails.SelectedIndex; if (i < TreeDetails.Items.Count - 1) { _alternativeSelectedAttrib = (TreeDetails.Items[i + 1] as GuiTreeAttrib).DataAttrib; } else if (i > 0) { _alternativeSelectedAttrib = (TreeDetails.Items[i - 1] as GuiTreeAttrib).DataAttrib; } else { _alternativeSelectedAttrib = null; } } } TreeDetails.Items.Clear(); if (Tree.SelectedItem != null) { GuiTreeNode Node = (GuiTreeNode)Tree.SelectedItem; TreeDetails.ContextMenu = Node.ContextMenu; foreach (KmlAttrib attrib in Node.DataNode.Attribs) { TreeDetails.Items.Add(new GuiTreeAttrib(attrib)); } _oldSelectedNode = Node.DataNode; // Restore attrib selection if (Node.DataNode == _oldSelectedNode && _oldSelectedAttrib != null) { if (!Select(_oldSelectedAttrib)) { Select(_alternativeSelectedAttrib); } if (TreeDetails.SelectedItem != null) { (TreeDetails.SelectedItem as ListViewItem).Focus(); } } } else { TreeDetails.ContextMenu = null; } }
/// <summary> /// Adds a child KmlItem to this nodes lists of children, depending of its /// derived class KmlNode or KmlAttrib or further derived from these. /// When an KmlAttrib "Name" is found, its value will be used for the "Name" property /// of this node. /// </summary> /// <param name="item">The KmlItem to add</param> public virtual void Add(KmlItem item) { AllItems.Add(item); if (item is KmlNode) { Children.Add((KmlNode)item); } else if (item is KmlAttrib) { KmlAttrib attrib = (KmlAttrib)item; if (attrib.Name.ToLower() == "name") { Name = attrib.Value; // Get notified when Name changes attrib.AttribValueChanged += Name_Changed; attrib.CanBeDeleted = false; } Attribs.Add(attrib); } else { Unknown.Add(item); Syntax.Warning(this, "Unknown line in persistence file: " + item.ToString()); } }
private void AddAttrib(KmlNode toItem, KmlAttrib beforeItem) { KmlNode node = toItem; string input; string preset = ""; bool loop = true; while (loop && DlgInput.Show("Enter the name for the new attribute:", "NEW attribute", Icons.Add, preset, out input)) { string attrib = input; if (attrib.Length > 0 && attrib.IndexOf('=') < 0) { attrib = attrib + "="; } KmlItem item = KmlItem.CreateItem(attrib); if (item is KmlAttrib && beforeItem != null) { node.InsertBefore(beforeItem, (KmlAttrib)item); loop = false; // View will be refreshed in AttribChanged event } else if (item is KmlAttrib) { node.Add((KmlAttrib)item); loop = false; // View will be refreshed in AttribChanged event } else { DlgMessage.Show("Attribute name is not allowed to be empty or contain following characters: {}", "NEW attribute", Icons.Warning); preset = input; // Input will pop up again while loop == true } } }
private static void RepairGrappleAttachment(KmlPart part, int attachmentIndex) { int lastIndex = -1; // Repair part 'attN = grapple, <attachmentIndex>' for (int i = 0; i < part.Attribs.Count; i++) { KmlAttrib attrib = part.Attribs[i]; if (attrib.Name.ToLower() == "attn") { lastIndex = i; if (attrib.Value.ToLower().StartsWith("grapple,") || attrib.Value.EndsWith(", " + attachmentIndex)) { attrib.Value = "grapple, " + attachmentIndex; return; } } else if (attrib.Name.ToLower() == "srfn") { lastIndex = i; } } // If we got here we didn't find it KmlAttrib newAttrib = new KmlAttrib("attN = grapple, " + attachmentIndex); part.Attribs.Insert(lastIndex + 1, newAttrib); part.AllItems.Insert(lastIndex + 1, newAttrib); }
/// <summary> /// Creates a KmlResource as a copy of a given KmlNode. /// </summary> /// <param name="node">The KmlNode to copy</param> public KmlResource(KmlNode node) : base(node.Line, node.Parent) { Amount = new KmlAttrib("amount ="); MaxAmount = new KmlAttrib("maxAmount ="); AddRange(node.AllItems); }
private void CrewName_Changed(object sender, RoutedEventArgs e) { // Name propert has not changed yet (or maybe), to be sure get the changed attrib KmlAttrib nameAttrib = GetAttribWhereValueChanged(sender); if (AssignedCrewAttrib != null) { AssignedCrewAttrib.Value = nameAttrib.Value; } }
private void AttribDelete_Click(object sender, RoutedEventArgs e) { KmlAttrib attrib = ((sender as MenuItem).DataContext as KmlAttrib); if (DlgConfirmation.Show("Do your really want to delete this attribute?\n" + attrib, "DELETE attribue", Icons.Delete)) { attrib.Delete(); // View will be refreshed in parent's ChildrenChanged event } }
/// <summary> /// Adds a child KmlItem to this nodes lists of children, depending of its /// derived class KmlNode, KmlAttrib or further derived from these. /// When an KmlAttrib "Name", "Type" or "Trait" are found, their value /// will be used for the corresponding property of this node. /// </summary> /// <param name="beforeItem">The KmlItem where the new item should be inserted before</param> /// <param name="newItem">The KmlItem to add</param> protected override void Add(KmlItem beforeItem, KmlItem newItem) { if (newItem is KmlAttrib) { KmlAttrib attrib = (KmlAttrib)newItem; if (attrib.Name.ToLower() == "name" && Name.Length == 0) { // Name property is managed by KmlNode, // but we need another method to be called on name change event // to rename the crew attrib in assigned vessel part also attrib.AttribValueChanged += CrewName_Changed; } else if (attrib.Name.ToLower() == "type" && Type.Length == 0) { Type = attrib.Value; // Get notified when Type changes attrib.AttribValueChanged += Type_Changed; attrib.CanBeDeleted = false; } else if (attrib.Name.ToLower() == "trait" && Trait.Length == 0) { Trait = attrib.Value; // Get notified when Trait changes attrib.AttribValueChanged += Trait_Changed; attrib.CanBeDeleted = false; } else if (attrib.Name.ToLower() == "state" && State.Length == 0) { State = attrib.Value; // Get notified when State changes attrib.AttribValueChanged += State_Changed; attrib.CanBeDeleted = false; } else if (attrib.Name.ToLower() == "brave" && Brave == 0.0) { Brave = GetDoubleValue(attrib.Value, Brave); // Get notified when Trait changes attrib.AttribValueChanged += Brave_Changed; attrib.CanBeDeleted = false; } else if (attrib.Name.ToLower() == "dumb" && Dumb == 0.0) { Dumb = GetDoubleValue(attrib.Value, Dumb); // Get notified when Dumb changes attrib.AttribValueChanged += Dumb_Changed; attrib.CanBeDeleted = false; } } base.Add(beforeItem, newItem); }
private KmlAttrib GetNextSibling(KmlAttrib attrib) { int index = Attribs.IndexOf(attrib); if (index >= 0 && index < Attribs.Count - 1) { return(Attribs[index + 1]); } else { return(null); } }
private void AttribCopy_Click(object sender, RoutedEventArgs e) { KmlAttrib attrib = ((sender as MenuItem).DataContext as KmlAttrib); var sr = new StringWriter(); KmlItem.WriteItem(sr, attrib, 0); sr.Flush(); var textNode = sr.GetStringBuilder().ToString(); Clipboard.SetDataObject(textNode); }
/// <summary> /// After all items are loaded, each items Finalize is called. /// The roots list will contain all loaded items in KML tree structure. /// Each item can then check for other items to get further properties. /// </summary> /// <param name="roots">The loaded root items list</param> protected override void Finalize(List <KmlItem> roots) { base.Finalize(roots); if (Origin == KerbalOrigin.Roster) { string[] tags = { "game", "flightstate" }; KmlNode flightStateNode = GetNodeFromDeep(roots, tags); if (flightStateNode != null) { foreach (KmlNode vesselNode in flightStateNode.Children) { if (vesselNode is KmlVessel) { KmlVessel vessel = (KmlVessel)vesselNode; foreach (KmlPart part in vessel.Parts) { foreach (KmlAttrib attrib in part.Attribs) { if (attrib.Name.ToLower() == "crew" && attrib.Value.ToLower() == Name.ToLower()) { if (AssignedCrewAttrib == null) { AssignedVessel = vessel; AssignedPart = part; AssignedCrewAttrib = attrib; attrib.CanBeDeleted = false; } else { Syntax.Warning(attrib, "Kerbal is listed in multiple vessel part's crew. Kerbal: " + Name + "Assigned vessel: " + AssignedVessel.Name + ", Assigned part: " + AssignedPart + ", Unused Vessel: " + vessel.Name + ", Unused part: " + part); } if (State.ToLower() != "assigned") { Syntax.Warning(this, "Kerbal is listed in a vessels crew list, but state is not 'Assigned'. Vessel: " + vessel.Name + ", Part: " + part); } } } } } } } if (AssignedCrewAttrib == null && State.ToLower() == "assigned" && Type.ToLower() != "unowned") { Syntax.Warning(this, "Kerbal state is 'Assigned' but not listed in any vessels crew list"); } } }
/// <summary> /// Search all KmlAttribs of this node, create one if not found. /// Does not search recursive. Default value will only be used on creation. /// </summary> /// <param name="name">The name of the KmlAttribs to search for</param> /// <param name="defaultValue">The default value for a created attribute</param> /// <returns>The found or created KmlAttrib</returns> public KmlAttrib GetOrCreateAttrib(string name, string defaultValue) { KmlAttrib attrib = GetAttrib(name); if (attrib == null) { string line = name + "="; if (defaultValue != null && defaultValue.Length > 0) { line += defaultValue; } attrib = KmlItem.CreateItem(line) as KmlAttrib; Add(attrib); } return(attrib); }
private void AttribInsertBefore_Click(object sender, RoutedEventArgs e) { // TODO GuiTreeAttrib.AttribInsertBefore_Click(): Almost same code as private GuiTreeNode.AddAttrib() KmlAttrib beforeItem = ((sender as MenuItem).DataContext as KmlAttrib); KmlNode node = beforeItem.Parent; if (node != null) { string input; string preset = ""; bool loop = true; while (loop && DlgInput.Show("Enter the name for the new attribute:", "NEW attribute", Icons.Add, preset, out input)) { string attrib = input; if (attrib.Length > 0 && attrib.IndexOf('=') < 0) { attrib = attrib + "="; } KmlItem item = KmlItem.CreateItem(attrib); if (item is KmlAttrib && beforeItem != null) { node.InsertBefore(beforeItem, (KmlAttrib)item); loop = false; // View will be refreshed in AttribChanged event } else if (item is KmlAttrib) { node.Add((KmlAttrib)item); loop = false; // View will be refreshed in AttribChanged event } else { DlgMessage.Show("Attribute name is not allowed to be empty or contain following characters: {}", "NEW attribute", Icons.Warning); preset = input; // Input will pop up again while loop == true } } } else { DlgMessage.Show("Can not insert, attribute has no parent", "NEW attribute", Icons.Warning); } }
/// <summary> /// Creates a KmlKerbal as a copy of a given KmlNode. /// </summary> /// <param name="node">The KmlNode to copy</param> public KmlKerbal(KmlNode node) : base(node.Line) { // First parent is null, will be set later when added to parent, // then IdentifyParent() will set Origin. Origin = KerbalOrigin.Other; Type = ""; Trait = ""; State = ""; Brave = 0.0; Dumb = 0.0; AssignedVessel = null; AssignedPart = null; AssignedCrewAttrib = null; AddRange(node.AllItems); }
private bool SearchCheckItem(KmlItem item, string text, bool checkNodeTag, bool checkNodeText, bool checkAttribName, bool checkAttribValue) { if (item is KmlNode) { KmlNode node = (KmlNode)item; return((checkNodeTag && node.Tag.ToLower().Contains(text.ToLower())) || (checkNodeText && node.ToString().ToLower().Contains(text.ToLower()))); } else if (item is KmlAttrib) { KmlAttrib attrib = (KmlAttrib)item; return((checkAttribName && attrib.Name.ToLower().Contains(text.ToLower())) || (checkAttribValue && attrib.Value.ToLower().Contains(text.ToLower()))); } else { return(false); } }
/// <summary> /// Creates a GuiVesselsNode containing the given DataVessel. /// To have nice icons in the tree, a GuiIcons can be /// provided. /// </summary> /// <param name="dataVessel">The KmlVessel to contain</param> public GuiVesselsNode(KmlVessel dataVessel) { DataVessel = dataVessel; AssignTemplate(); BuildContextMenu(); // Get notified when KmlNode ToString() changes DataVessel.ToStringChanged += DataVessel_ToStringChanged; // Get notified when flag changes if (DataVessel.RootPart != null) { KmlAttrib flag = DataVessel.RootPart.GetAttrib("flag"); if (flag != null) { flag.AttribValueChanged += DataVessel_FlagChanged; } } }
/// <summary> /// Send the kerbal home to astronaut complex. /// Kerbal will be removed from assigned vessel/part /// and state will be set to 'Available'. /// </summary> public void SendHome() { if (AssignedCrewAttrib != null) { AssignedCrewAttrib.CanBeDeleted = true; AssignedCrewAttrib.Delete(); AssignedCrewAttrib = null; AssignedPart = null; AssignedVessel = null; } foreach (KmlAttrib attrib in Attribs) { if (attrib.Name.ToLower() == "state") { attrib.Value = "Available"; // This will invoke ToStringChanged so State property // and all display items will be updated. // That's why this is the last action in this method } } }
/// <summary> /// Adds a child KmlItem to this nodes lists of children, depending of its /// derived class KmlNode, KmlAttrib or further derived from these. /// When an KmlAttrib "Name", "Type" or "Trait" are found, their value /// will be used for the corresponding property of this node. /// </summary> /// <param name="item">The KmlItem to add</param> public override void Add(KmlItem item) { if (item is KmlAttrib) { KmlAttrib attrib = (KmlAttrib)item; if (attrib.Name.ToLower() == "type") { Type = attrib.Value; // Get notified when Type changes attrib.AttribValueChanged += Type_Changed; attrib.CanBeDeleted = false; } else if (attrib.Name.ToLower() == "trait") { Trait = attrib.Value; // Get notified when Trait changes attrib.AttribValueChanged += Trait_Changed; attrib.CanBeDeleted = false; } else if (attrib.Name.ToLower() == "brave") { Brave = GetDoubleValue(attrib.Value, Brave); // Get notified when Trait changes attrib.AttribValueChanged += Brave_Changed; attrib.CanBeDeleted = false; } else if (attrib.Name.ToLower() == "dumb") { Dumb = GetDoubleValue(attrib.Value, Dumb); // Get notified when Dumb changes attrib.AttribValueChanged += Dumb_Changed; attrib.CanBeDeleted = false; } } base.Add(item); }
private void AttribPasteBefore_Click(object sender, RoutedEventArgs e) { KmlAttrib attrib = ((sender as MenuItem).DataContext as KmlAttrib); if (attrib.Parent != null) { var textNode = Clipboard.GetText(TextDataFormat.UnicodeText); var items = KmlItem.ParseItems(new StringReader(textNode)).Where(i => i is KmlAttrib).ToList(); if (!items.Any()) { DlgMessage.Show("Can not paste attribute from clipboard", "Paste attribute", Icons.Warning); } attrib.Parent.InsertBeforeRange(attrib, items); } else { DlgMessage.Show("Can not insert, attribute has no parent", "Paste attribute", Icons.Warning); } }
private static void RepairGrappleAttachment(KmlPart part, int attachmentIndex) { KmlAttrib lastItem = null; // Repair part 'attN = grapple, <attachmentIndex>' for (int i = 0; i < part.Attribs.Count; i++) { KmlAttrib attrib = part.Attribs[i]; if (attrib.Name.ToLower() == "attn") { lastItem = attrib; if (attrib.Value.ToLower().StartsWith("grapple,") || attrib.Value.EndsWith(", " + attachmentIndex)) { attrib.Value = "grapple, " + attachmentIndex; return; } } else if (attrib.Name.ToLower() == "srfn") { lastItem = attrib; } } // If we got here we didn't find it KmlAttrib newAttrib = new KmlAttrib("attN = grapple, " + attachmentIndex); // InsertAfter will add to the end if lastItem is null part.InsertAfter(lastItem, newAttrib); //if (lastItem != null) //{ // part.Attribs.Insert(part.Attribs.IndexOf(lastItem) + 1, newAttrib); // part.AllItems.Insert(part.AllItems.IndexOf(lastItem) + 1, newAttrib); //} //else //{ // part.Add(newAttrib); //} }
/// <summary> /// Adds a child KmlItem to this nodes lists of children, depending of its /// derived class KmlNode, KmlPart, KmlAttrib or further derived from these. /// When an KmlAttrib "Name", "Amount" or "MaxAmount" are found, they /// will be used for the corresponding property of this node. /// </summary> /// <param name="item">The KmlItem to add</param> public override void Add(KmlItem item) { if (item is KmlAttrib) { KmlAttrib attrib = (KmlAttrib)item; if (attrib.Name.ToLower() == "amount") { Amount = attrib; // Get notified when Amount changes attrib.AttribValueChanged += Amount_Changed; attrib.CanBeDeleted = false; } else if (attrib.Name.ToLower() == "maxamount") { MaxAmount = attrib; // Get notified when MaxAmount changes attrib.AttribValueChanged += MaxAmount_Changed; attrib.CanBeDeleted = false; } } base.Add(item); }
/// <summary> /// Adds (inserts before) a child KmlItem to this nodes lists of children. /// If item to insert before is null or not contained, it will be added at the end. /// This is the basic add method, derived classes can override but should /// always call base.Add(beforeItem, newItem) within. /// Public Add, AddRange, InsertBefore and InsertAfter all use this protected /// method to access the lists. /// <see cref="KML.KmlNode.Add(KML.KmlItem)"/> /// </summary> /// <param name="beforeItem">The KmlItem where the new item should be inserted before</param> /// <param name="newItem">The KmlItem to add</param> protected virtual void Add(KmlItem beforeItem, KmlItem newItem) { // ensure that item.Parent is this node if (newItem.Parent != this) { RemapParent(newItem, this); } // Not add always to end of AllItems, add well ordered: attribs first, then nodes. // Like Add(attrib), Add(Node), Add(attrib) should result in attrib, attrib, node if (newItem is KmlAttrib && !(beforeItem is KmlAttrib) && Children.Count > 0) { Syntax.Warning(newItem, "KML attribute should not come after nodes, will be fixed when saved"); beforeItem = Children[0]; } if (beforeItem != null && AllItems.Contains(beforeItem)) { AllItems.Insert(AllItems.IndexOf(beforeItem), newItem); } else { AllItems.Add(newItem); } if (newItem is KmlNode) { if (beforeItem is KmlNode && Children.Contains((KmlNode)beforeItem)) { Children.Insert(Children.IndexOf((KmlNode)beforeItem), (KmlNode)newItem); } else { Children.Add((KmlNode)newItem); } InvokeChildrenChanged(); } else if (newItem is KmlAttrib) { KmlAttrib attrib = (KmlAttrib)newItem; if (attrib.Name.ToLower() == "name") { if (Name.Length == 0) { Name = attrib.Value; // Get notified when Name changes attrib.AttribValueChanged += Name_Changed; attrib.CanBeDeleted = false; // And notify that the name changed InvokeToStringChanged(); } } if (beforeItem is KmlAttrib && Attribs.Contains((KmlAttrib)beforeItem)) { Attribs.Insert(Attribs.IndexOf((KmlAttrib)beforeItem), attrib); } else { Attribs.Add(attrib); } InvokeAttribChanged(); } else { if (beforeItem != null && Unknown.Contains(newItem)) { Unknown.Insert(Unknown.IndexOf(beforeItem), newItem); } else { Unknown.Add(newItem); } Syntax.Warning(this, "Unknown line in persistence file: " + newItem.ToString()); } }
private static void RepairDockerDockee(KmlPartDock docker, KmlPartDock dockee) { if (docker.ParentPart == dockee || dockee.ParentPart == docker) { bool dockerOk = false; bool dockeeOk = false; try { KmlNode module = docker.GetOrCreateChildNode("MODULE", "ModuleDockingNode"); module.GetOrCreateAttrib("isEnabled", "True"); module.GetOrCreateAttrib("crossfeed", "True"); module.GetOrCreateAttrib("stagingEnabled").Value = "False"; module.GetOrCreateAttrib("state").Value = "Docked (docker)"; module.GetOrCreateAttrib("dockUId").Value = dockee.Uid; KmlNode events = module.GetOrCreateChildNode("EVENTS"); events.GetOrCreateChildNode("Undock").GetOrCreateAttrib("active").Value = "True"; events.GetOrCreateChildNode("UndockSameVessel").GetOrCreateAttrib("active").Value = "False"; events.GetOrCreateChildNode("Decouple").GetOrCreateAttrib("active").Value = "False"; module.GetOrCreateChildNode("ACTIONS"); KmlNode dockedVessel = module.GetOrCreateChildNode("DOCKEDVESSEL"); string defaultName; if (docker.Parent is KmlVessel) { defaultName = (docker.Parent as KmlVessel).Name + " Docker - repaired by KML"; } else { defaultName = "Unknown Docker - repaired by KML"; } if (dockedVessel.GetAttrib("vesselName") == null) { KmlAttrib attrib = dockedVessel.GetOrCreateAttrib("vesselName", defaultName); attrib.AttribValueChanged += docker.DockedVesselName_Changed; docker.DockedVesselName_Changed(attrib, new System.Windows.RoutedEventArgs()); } if (dockedVessel.GetAttrib("vesselType") == null) { KmlAttrib attrib = dockedVessel.GetOrCreateAttrib("vesselType", "6"); attrib.AttribValueChanged += docker.DockedVesselType_Changed; docker.DockedVesselType_Changed(attrib, new System.Windows.RoutedEventArgs()); } dockedVessel.GetOrCreateAttrib("rootUId", docker.Uid); dockerOk = true; } catch (NullReferenceException) { Syntax.Warning(docker, "Couldn't fix docker node, there are sub-nodes missing.\n" + "You should copy a MODULE node from a functional 'Docked (docker)' part.\n" + "Docker should be: " + docker); } try { KmlNode module = dockee.GetOrCreateChildNode("MODULE", "ModuleDockingNode"); module.GetOrCreateAttrib("isEnabled", "True"); module.GetOrCreateAttrib("crossfeed", "True"); module.GetOrCreateAttrib("stagingEnabled").Value = "False"; module.GetOrCreateAttrib("state").Value = "Docked (dockee)"; module.GetOrCreateAttrib("dockUId").Value = docker.Uid; KmlNode events = module.GetOrCreateChildNode("EVENTS"); events.GetOrCreateChildNode("Undock").GetOrCreateAttrib("active").Value = "False"; events.GetOrCreateChildNode("UndockSameVessel").GetOrCreateAttrib("active").Value = "False"; events.GetOrCreateChildNode("Decouple").GetOrCreateAttrib("active").Value = "False"; module.GetOrCreateChildNode("ACTIONS"); KmlNode dockedVessel = module.GetOrCreateChildNode("DOCKEDVESSEL"); string defaultName; string defaultUId; if (dockee.Parent is KmlVessel) { defaultName = (dockee.Parent as KmlVessel).Name; defaultUId = (dockee.Parent as KmlVessel).RootPart.Uid; } else { defaultName = "Unknown Dockee - repaired by KML"; defaultUId = dockee.Uid; } if (dockedVessel.GetAttrib("vesselName") == null) { KmlAttrib attrib = dockedVessel.GetOrCreateAttrib("vesselName", defaultName); attrib.AttribValueChanged += dockee.DockedVesselName_Changed; docker.DockedVesselName_Changed(attrib, new System.Windows.RoutedEventArgs()); } if (dockedVessel.GetAttrib("vesselType") == null) { KmlAttrib attrib = dockedVessel.GetOrCreateAttrib("vesselType", "6"); attrib.AttribValueChanged += dockee.DockedVesselType_Changed; docker.DockedVesselType_Changed(attrib, new System.Windows.RoutedEventArgs()); } dockedVessel.GetOrCreateAttrib("rootUId", defaultUId); dockeeOk = true; } catch (NullReferenceException) { Syntax.Warning(dockee, "Couldn't fix dockee node, there are sub-nodes missing.\n" + "You should copy a MODULE node from a functional 'Docked (dockee)' part.\n" + "Dockee should be: " + dockee); } if (dockerOk && dockeeOk) { Syntax.Info(docker, "Successfully repaired docker-dockee"); if (docker.Parent is KmlVessel) { BuildAttachmentStructure((docker.Parent as KmlVessel).Parts); } } } else { RepairSameVesselChoose(docker, dockee); } }
/// <summary> /// Adds a child KmlItem to this nodes lists of children, depending of its /// derived class KmlNode, KmlPart, KmlAttrib or further derived from these. /// When an KmlAttrib "Name", "Type" or "Root" are found, their value /// will be used for the corresponding property of this node. /// </summary> /// <param name="beforeItem">The KmlItem where the new item should be inserted before</param> /// <param name="newItem">The KmlItem to add</param> protected override void Add(KmlItem beforeItem, KmlItem newItem) { if (newItem is KmlAttrib) { KmlAttrib attrib = (KmlAttrib)newItem; if (attrib.Name.ToLower() == "type" && Type.Length == 0) { Type = attrib.Value; // Get notified when Type changes attrib.AttribValueChanged += Type_Changed; attrib.CanBeDeleted = false; } else if (attrib.Name.ToLower() == "sit" && Situation.Length == 0) { Situation = attrib.Value; // Get notified when Type changes attrib.AttribValueChanged += Situation_Changed; attrib.CanBeDeleted = false; } else if (attrib.Name.ToLower() == "root" && RootPart == null) { SetRootPart(attrib.Value); // Get notified when Type changes attrib.AttribValueChanged += Root_Changed; attrib.CanBeDeleted = false; } } else if (newItem is KmlPart) { KmlPart part = (KmlPart)newItem; if (beforeItem != null) { KmlPart beforePart = null; int allIndex = AllItems.IndexOf(beforeItem); for (int i = allIndex; i < AllItems.Count; i++) { if (AllItems[i] is KmlPart && Parts.Contains((KmlPart)AllItems[i])) { beforePart = (KmlPart)AllItems[i]; break; } } if (beforePart != null) { beforePart.InsertionPreparation(); Parts.Insert(Parts.IndexOf(beforePart), part); beforePart.InsertionFinalization(); } else { Parts.Add(part); } } else { Parts.Add(part); } if (Parts.Count == rootPartIndex + 1) { RootPart = Parts[rootPartIndex]; } if (part.Flag != "" && !Flags.Any(x => x.ToLower() == part.Flag.ToLower())) { Flags.Add(part.Flag); } if (part.HasResources) { foreach (string resType in part.ResourceTypes) { ResourceTypes.Add(resType); } } KmlAttrib flag = part.GetAttrib("flag"); if (flag != null) { flag.AttribValueChanged += Flag_Changed; } } base.Add(beforeItem, newItem); }
/// <summary> /// Creates a GuiTreeNode containing the given dataAttrib. /// </summary> /// <param name="dataAttrib">The KmlAttrib to contain</param> public GuiTreeAttrib(KmlAttrib dataAttrib) { DataAttrib = dataAttrib; BuildContextMenu(); }
private static void RepairGrappling(KmlPartDock grapple, KmlPart part) { int grappleIndex = -1; int partIndex = -1; if (grapple.Parent is KmlVessel) { bool dockedVesselOk = true; KmlVessel vessel = (KmlVessel)grapple.Parent; grappleIndex = vessel.Parts.IndexOf(grapple); partIndex = vessel.Parts.IndexOf(part); try { KmlNode module = grapple.GetOrCreateChildNode("MODULE", "ModuleGrappleNode"); module.GetOrCreateAttrib("isEnabled", "True"); //module.GetOrCreateAttrib("stagingEnabled").Value = "False"; // True?!? module.GetOrCreateAttrib("state").Value = "Grappled"; module.GetOrCreateAttrib("dockUId").Value = part.Uid; KmlNode events = module.GetOrCreateChildNode("EVENTS"); events.GetOrCreateChildNode("Release").GetOrCreateAttrib("active").Value = "True"; events.GetOrCreateChildNode("ReleaseSameVessel").GetOrCreateAttrib("active").Value = "False"; events.GetOrCreateChildNode("Decouple").GetOrCreateAttrib("active").Value = "False"; module.GetOrCreateChildNode("ACTIONS"); KmlNode dockedVessel = module.GetOrCreateChildNode("DOCKEDVESSEL"); KmlNode dockedVesselOther = module.GetOrCreateChildNode("DOCKEDVESSEL_Other"); string vesselName; string vesselRootUId; string defaultName; if (grapple.Parent is KmlVessel) { vesselName = (grapple.Parent as KmlVessel).Name; vesselRootUId = (grapple.Parent as KmlVessel).RootPart.Uid; defaultName = vesselName + " Grappled - repaired by KML"; } else { vesselName = "Unknown Vessel - repaired by KML"; if (part.ParentPart == grapple) { vesselRootUId = grapple.Uid; } else { vesselRootUId = part.Uid; } defaultName = "Unknown Grappled - repaired by KML"; } string thisName; string otherName; string thisUid; string otherUid; if (part.ParentPart == grapple) { thisName = vesselName; thisUid = vesselRootUId; otherName = defaultName; otherUid = part.Uid; } else { thisName = defaultName; thisUid = grapple.Uid; otherName = vesselName; otherUid = vesselRootUId; } if (dockedVessel.GetAttrib("vesselName") == null) { KmlAttrib attrib = dockedVessel.GetOrCreateAttrib("vesselName", thisName); attrib.AttribValueChanged += grapple.DockedVesselName_Changed; grapple.DockedVesselName_Changed(attrib, new System.Windows.RoutedEventArgs()); } if (dockedVessel.GetAttrib("vesselType") == null) { KmlAttrib attrib = dockedVessel.GetOrCreateAttrib("vesselType", "6"); attrib.AttribValueChanged += grapple.DockedVesselType_Changed; grapple.DockedVesselType_Changed(attrib, new System.Windows.RoutedEventArgs()); } dockedVessel.GetOrCreateAttrib("rootUId", thisUid); if (dockedVesselOther.GetAttrib("vesselName") == null) { KmlAttrib attrib = dockedVesselOther.GetOrCreateAttrib("vesselName", otherName); attrib.AttribValueChanged += grapple.DockedVesselOtherName_Changed; grapple.DockedVesselOtherName_Changed(attrib, new System.Windows.RoutedEventArgs()); } if (dockedVesselOther.GetAttrib("vesselType") == null) { KmlAttrib attrib = dockedVesselOther.GetOrCreateAttrib("vesselType", "6"); attrib.AttribValueChanged += grapple.DockedVesselOtherType_Changed; grapple.DockedVesselOtherType_Changed(attrib, new System.Windows.RoutedEventArgs()); } dockedVesselOther.GetOrCreateAttrib("rootUId", otherUid); module = grapple.GetOrCreateChildNode("MODULE", "ModuleAnimateGeneric"); module.GetOrCreateAttrib("animSwitch").Value = "False"; module.GetOrCreateAttrib("animTime").Value = "1"; events = module.GetOrCreateChildNode("EVENTS"); KmlNode toggle = events.GetOrCreateChildNode("Toggle"); toggle.GetOrCreateAttrib("active").Value = "False"; toggle.GetOrCreateAttrib("guiName").Value = "Disarm"; if (part.ParentPart == grapple) { RepairGrappleAttachment(part, grappleIndex); } else if (grapple.ParentPart == part) { RepairGrappleAttachment(grapple, partIndex); } else { // TODO KmlPartDock:RepairGrappling(): Is there a 'Grappled (same vessel)'? } if (dockedVesselOk) { Syntax.Info(grapple, "Successfully repaired grappling"); BuildAttachmentStructure(vessel.Parts); } } catch (NullReferenceException) { Syntax.Warning(grapple, "Couldn't fix grappling node, there are sub-nodes missing.\n" + "You should copy a MODULE node from a functional state 'Grappled' part\n" + "grappled part should be: " + part); } } else { Syntax.Warning(grapple, "Could not search for connected parts, parent vessel is not valid"); } }
/// <summary> /// Adds a child KmlItem to this nodes lists of children, depending of its /// derived class KmlNode, KmlPart, KmlAttrib or further derived from these. /// When an KmlAttrib "Name", "Type" or "Root" are found, their value /// will be used for the corresponding property of this node. /// </summary> /// <param name="item">The KmlItem to add</param> public override void Add(KmlItem item) { KmlItem newItem = item; if (item is KmlAttrib) { KmlAttrib attrib = (KmlAttrib)item; if (attrib.Name.ToLower() == "type") { Type = attrib.Value; // Get notified when Type changes attrib.AttribValueChanged += Type_Changed; attrib.CanBeDeleted = false; } else if (attrib.Name.ToLower() == "sit") { Situation = attrib.Value; // Get notified when Type changes attrib.AttribValueChanged += Situation_Changed; attrib.CanBeDeleted = false; } else if (attrib.Name.ToLower() == "root") { SetRootPart(attrib.Value); // Get notified when Type changes attrib.AttribValueChanged += Root_Changed; attrib.CanBeDeleted = false; } } else if (item is KmlPart) { KmlPart part = (KmlPart)item; Parts.Add(part); if (Parts.Count == rootPartIndex + 1) { RootPart = Parts[rootPartIndex]; } if (part.HasResources) { foreach (string resType in part.ResourceTypes) { ResourceTypes.Add(resType); } } } /*else if (Item is KmlNode) * { * KmlNode node = (KmlNode)Item; * if (node.Tag.ToLower() == "part") * { * newItem = new KmlPart(node); * Parts.Add((KmlPart)newItem); * if (Parts.Count == rootPartNr + 1) * { * RootPart = Parts[rootPartNr]; * } * } * }*/ base.Add(newItem); }
private void DetailsEditBoxGotFocus(ListView Details, object sender, RoutedEventArgs e) { KmlAttrib attrib = (VisualTreeHelper.GetParent(sender as DependencyObject) as ContentPresenter).DataContext as KmlAttrib; Details.SelectedIndex = attrib.Parent.Attribs.IndexOf(attrib); // Wow this seems straight forward! }
/// <summary> /// Adds a child KmlItem to this nodes lists of children, depending of its /// derived class KmlNode, KmlAttrib or further derived from these. /// When an KmlAttrib "Name" is found, its value /// will be used for the corresponding property of this node. /// </summary> /// <param name="item">The KmlItem to add</param> public override void Add(KmlItem item) { KmlItem newItem = item; if (item is KmlAttrib) { KmlAttrib attrib = (KmlAttrib)item; if (attrib.Name.ToLower() == "uid") { Uid = attrib.Value; attrib.AttribValueChanged += Uid_Changed; attrib.CanBeDeleted = false; } else if (attrib.Name.ToLower() == "parent") { int p = ParentPartIndex; if (int.TryParse(attrib.Value, out p)) { ParentPartIndex = p; } else { Syntax.Warning(this, "Unreadable parent part: " + attrib.ToString()); } attrib.AttribValueChanged += ParentPart_Changed; attrib.CanBeDeleted = false; } else if (attrib.Name.ToLower() == "attn") { // Value looks like "top, 12", "bottom, -1", "left, 1", "top2, 3", etc. string[] items = attrib.Value.Split(new char[] { ',' }); int index = -1; if (items.Count() == 2 && int.TryParse(items[1], out index)) { if (index >= 0) { AttachedToNodeIndices.Add(index); attrib.CanBeDeleted = false; } } else { Syntax.Warning(this, "Bad formatted part node attachment: " + attrib.ToString()); } attrib.AttribValueChanged += AttachmentNode_Changed; } else if (attrib.Name.ToLower() == "srfn") { // Value looks like "srfAttach, 12" string[] items = attrib.Value.Split(new char[] { ',' }); int index = -1; if (items.Count() == 2 && int.TryParse(items[1], out index)) { if (index >= 0) { if (AttachedToSurfaceIndex < 0) { AttachedToSurfaceIndex = index; attrib.CanBeDeleted = false; } else { Syntax.Warning(this, "More than one surface attachment is not allowed, already attached to [" + AttachedToSurfaceIndex + "], could not attach to [" + index + "]"); } } } else { Syntax.Warning(this, "Bad formatted part surface attachment: " + attrib.ToString()); } attrib.AttribValueChanged += AttachmentSurface_Changed; } else if (attrib.Name.ToLower() == "position") { // Value looks like "0.1,0,-0.3E-07" string[] items = attrib.Value.Split(new char[] { ',' }); double x = 0; double y = 0; double z = 0; if (items.Count() == 3 && double.TryParse(items[0], NumberStyles.Number | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out x) && double.TryParse(items[1], NumberStyles.Number | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out y) && double.TryParse(items[2], NumberStyles.Number | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out z)) { Position = new Point3D(x, y, z); attrib.CanBeDeleted = false; } else { Syntax.Warning(this, "Bad formatted part position: " + attrib.ToString()); } } } else if (item is KmlResource) { KmlResource res = (KmlResource)item; Resources.Add(res); ResourceTypes.Add(res.Name); // Get notified when Resources change res.MaxAmount.AttribValueChanged += Resources_Changed; res.MaxAmount.CanBeDeleted = false; res.Amount.AttribValueChanged += Resources_Changed; res.Amount.CanBeDeleted = false; } /*if (Item is KmlNode) * { * KmlNode node = (KmlNode)Item; * if (node.Tag.ToLower() == "resource") * { * newItem = new KmlResource(node); * } * }*/ base.Add(newItem); }