예제 #1
0
        private void createSpecies(XPathNavigator navLocal, XmlDocument document, XPathNavigator navGlobal)
        {
            // Set up component values
            String cType = "Species";
            String cName = navLocal.SelectSingleNode("Name").Value;
            String cDescription = String.Empty;
            // Create component
            createComponent(VSGConfiguration, document, cType, cName, cDescription);

            // Create links
            #region links

            // Scenario
            createLink(VSGConfiguration, document, navGlobal.SelectSingleNode("/Scenario").GetAttribute("name", navGlobal.NamespaceURI), navGlobal.SelectSingleNode("/Scenario").GetAttribute("name", navGlobal.NamespaceURI), cName, "Scenario", String.Empty);
            
            // SpeciesType
            createLink(VSGConfiguration, document, navGlobal.SelectSingleNode("/Scenario").GetAttribute("name", navGlobal.NamespaceURI), navGlobal.SelectSingleNode("/Scenario").GetAttribute("name", navGlobal.NamespaceURI), cName, "SpeciesType", String.Empty);
            String speciesBase = (navLocal.SelectSingleNode("Base") == null) ? String.Empty : navLocal.SelectSingleNode("Base").Value;
            if (navGlobal.SelectSingleNode(String.Format("/Scenario/Species[Name='{0}']", speciesBase)) != null)
            {
                createLink(VSGConfiguration, document, navGlobal.SelectSingleNode("/Scenario").GetAttribute("name", navGlobal.NamespaceURI), cName, speciesBase, "SpeciesType", String.Empty);
                speciesBase = "ExistingSpecies";
            }

            // SpeciesDMCanOwn
            String canDMOwn = (navLocal.SelectSingleNode("CanOwn") == null) ? String.Empty : navLocal.SelectSingleNode("CanOwn").Value;
            if (canDMOwn != String.Empty)
            {
                String[] dms = canDMOwn.Split(',');
                foreach (String dm in dms)
                {
                    String dmName = dm.Trim();
                    if (navGlobal.SelectSingleNode(String.Format("/Scenario/DecisionMaker[Identifier='{0}']", dmName)) != null)
                    {
                        createLink(VSGConfiguration, document, cName, cName, dmName, "SpeciesDMCanOwn", String.Empty);
                    }
                }
            }

            XPathNodeIterator itCapacities = navLocal.Select("SubplatformCapacity");
            while (itCapacities.MoveNext())
            {
                String subplatformSpeciesName = itCapacities.Current.SelectSingleNode("SpeciesName").Value;
                int subplatformSpeciesCount = Int32.Parse(itCapacities.Current.SelectSingleNode("Count").Value);
                String dynamicLinkName = GetDynamicLinkType("SpeciesSubplatformCapacity", cName);
                createLink(VSGConfiguration, document, cName, cName, subplatformSpeciesName, dynamicLinkName, String.Empty);
                String linkID = GetLinkID(cName, subplatformSpeciesName, dynamicLinkName);
                createParameter(VSGConfiguration, document, linkID, eParamParentType.Link.ToString(), "Capacity.Count", subplatformSpeciesCount.ToString(), "");
            }

            #endregion

            // Create parameters
            #region parameters

            createParameter(VSGConfiguration, document, cName, "Component", "Species.IsWeapon", (navLocal.SelectSingleNode("IsWeapon") == null) ? String.Empty : navLocal.SelectSingleNode("IsWeapon").Value, String.Empty);
            createParameter(VSGConfiguration, document, cName, "Component", "Species.RemoveOnDestruction", (navLocal.SelectSingleNode("RemoveOnDestruction") == null) ? String.Empty : navLocal.SelectSingleNode("RemoveOnDestruction").Value, String.Empty);
            createParameter(VSGConfiguration, document, cName, "Component", "Species.DefaultClassification", (navLocal.SelectSingleNode("DefaultClassification") == null) ? String.Empty : navLocal.SelectSingleNode("DefaultClassification").Value, String.Empty);

            if (navLocal.SelectSingleNode("ClassificationDisplayRules") != null)
            {
                String rules = navLocal.SelectSingleNode("ClassificationDisplayRules").OuterXml;
                ClassificationDisplayRules CDRs = new ClassificationDisplayRules();
                int i = rules.IndexOf("\r\n");
                int start = rules.IndexOf(">",i-1);
                int end = rules.IndexOf("<", i);
                
                while (i >= 0)
                {
                    start = rules.IndexOf(">", i-1);
                    end = rules.IndexOf("<", start);
                    if (end - start > 1)
                    {
                        rules = rules.Remove(start + 1, end - start-1);
                    }
                    i = rules.IndexOf("\r\n");                    
                }

                CDRs.Rules = ClassificationDisplayRules.FromXML(rules);
                createParameter(VSGConfiguration, document, cName, "Component", "Species.ClassificationDisplayRules", CDRs.ToXML(), String.Empty);
            }

            createParameter(VSGConfiguration, document, cName, "Component", "Species.CollisionRadius", (navLocal.SelectSingleNode("Size") == null) ? String.Empty : navLocal.SelectSingleNode("Size").Value, String.Empty);
            createParameter(VSGConfiguration, document, cName, "Component", "Species.LaunchedByOwner", (navLocal.SelectSingleNode("LaunchedByOwner") == null) ? String.Empty : navLocal.SelectSingleNode("LaunchedByOwner").Value, String.Empty);
            switch (speciesBase)
            {
                case "LandObject":
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.LandObject", "true", String.Empty);
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.AirObject", "false", String.Empty);
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.SeaObject", "false", String.Empty);
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.ExistingSpecies", "false", String.Empty); 
                    break;

                case "AirObject":
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.LandObject", "false", String.Empty);
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.AirObject", "true", String.Empty);
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.SeaObject", "false", String.Empty);
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.ExistingSpecies", "false", String.Empty); 
                    break;

                case "SeaObject":
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.LandObject", "false", String.Empty);
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.AirObject", "false", String.Empty);
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.SeaObject", "true", String.Empty);
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.ExistingSpecies", "false", String.Empty); 
                    break;

                case "ExistingSpecies":
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.LandObject", "false", String.Empty);
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.AirObject", "false", String.Empty);
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.SeaObject", "false", String.Empty);
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.ExistingSpecies", "true", String.Empty);
                    break;

                default:
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.LandObject", "false", String.Empty);
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.AirObject", "false", String.Empty);
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.SeaObject", "false", String.Empty);
                    createParameter(VSGConfiguration, document, cName, "Component", "Species.ExistingSpecies", "false", String.Empty); 
                    break;
            }

            // Name States
            // Because of the State to State links we need to create the names first. Then create them. 
            XPathNodeIterator itStates = navLocal.Select("FullyFunctional | DefineState");
            while (itStates.MoveNext())
            {
                if (itStates.Current.SelectSingleNode("State") != null)
                {
                    String stateName = itStates.Current.SelectSingleNode("State").Value;
                    //itStates.Current.SelectSingleNode("State").SetValue(cName + AME.Tools.ImportTool.Delimitter + stateName);
                    itStates.Current.CreateAttribute(String.Empty, "name", itStates.Current.NamespaceURI, cName + AME.Tools.ImportTool.Delimitter + stateName);
                }
                else
                    //itStates.Current.AppendChildElement(String.Empty, "State", String.Empty, cName + AME.Tools.ImportTool.Delimitter + "FullyFunctional");
                    itStates.Current.CreateAttribute(String.Empty, "name", String.Empty, cName + AME.Tools.ImportTool.Delimitter + "FullyFunctional");
            }


            // Create States
            itStates = navLocal.Select("FullyFunctional | DefineState");
            Boolean isDeadState = false;
            while (itStates.MoveNext())
            {
                String stateName = itStates.Current.GetAttribute("name", itStates.Current.NamespaceURI);
                if (stateName.ToLower().Equals(cName.ToLower() + AME.Tools.ImportTool.Delimitter + "Dead".ToLower()))
                    isDeadState = true;
            }
            if (!isDeadState)
            {
                String name = cName + AME.Tools.ImportTool.Delimitter + "Dead";

                XmlElement deadState = document.CreateElement("DefineState");
                XmlAttribute deadStateName = document.CreateAttribute("name");
                deadStateName.InnerXml = name;
                deadState.Attributes.Append(deadStateName);
                XmlElement state = document.CreateElement("State");
                state.InnerXml = name;
                deadState.AppendChild(state);
                navLocal.AppendChild(deadState.CreateNavigator());
            }
            itStates = navLocal.Select("FullyFunctional | DefineState");
            while (itStates.MoveNext())
            {
                createState(itStates.Current, document, navGlobal);
            }

            #endregion
        }
예제 #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (controller == null)
         return;
     String state = ""; 
     String classification = "";
     String icon = "";
     EditClassificationDialog dlg = new EditClassificationDialog();
     dlg.controller = this.controller;
     dlg.StateEnum.AddRange(GetStatesListBySpecies(controller, rootId, link, componentId));
     dlg.ClassificationEnum.AddRange(GetClassificationList(controller, rootId));
     dlg.IconEnum.AddRange(controller.CurrentIconLibraryIconNames());
     if (dlg.StateEnum.Count == 0)
     {
         MessageBox.Show(this, "In order to create Classification Display Rules, you'll need to define States for this Species first.");
         return;
     }
     if (dlg.ClassificationEnum.Count == 0)
     {
         MessageBox.Show(this, "In order to create Classification Display Rules, you'll need to define Classifications first.  You can do this on the Scenario Elements window, under the Players tab.");
         return;
     }
     if (dlg.IconEnum.Count == 0)
     {
         MessageBox.Show(this, "In order to create Classification Display Rules, you'll need to choose an Icon library first");
         return;
     }
     //dlg.StateName = state;
     //dlg.ClassificationName = classification;
     //dlg.IconName = icon;
     dlg.Initialize();
     if (dlg.ShowDialog(this) == DialogResult.OK)
     {
         state = dlg.StateName;
         classification = dlg.ClassificationName;
         icon = dlg.IconName;
         if (currentRules == null)
             currentRules = new ClassificationDisplayRules();
         currentRules.Rules.Add(new ClassificationDisplayRule(state, classification, icon));
         UpdateRuleInAME(currentRules);
         UpdateViewComponent();
         //DataGridViewRow row = new DataGridViewRow();
         //row.CreateCells(dataGridView1, state, classification, icon, GetImage(icon), "Edit...", "Delete");
         //dataGridView1.Rows.Add(row);
     }
     //ClassificationDisplayRule r = new ClassificationDisplayRule(state, classification, icon);
     //dataGridView1.Rows.Add(CreateRow(r));
 }
예제 #3
0
        public void UpdateViewComponent()
        {
            if (controller == null)
                return;
            if (componentId < 0)
            {
                this.SuspendLayout();
                dataGridView1.Rows.Clear();
                this.ResumeLayout();
                return;
            }

            this.SuspendLayout();
            controller.TurnViewUpdateOff();

            dataGridView1.Rows.Clear();
            String serializedString = String.Empty;
            if (!parameterCategory.Equals(String.Empty) && !parameterName.Equals(String.Empty))
            {
                IXPathNavigable inav = controller.GetParametersForComponent(componentId);
                XPathNavigator navigator = inav.CreateNavigator();

                XPathNavigator node = navigator.SelectSingleNode(String.Format("ComponentParameters/Parameter[@category='{0}']/Parameter[@displayedName='{1}']", parameterCategory, parameterName));
                if (node != null)
                {
                    serializedString = node.GetAttribute("value", String.Empty);
                }
                ClassificationDisplayRules cdr = new ClassificationDisplayRules();
                currentRules.Rules = ClassificationDisplayRules.FromXML(serializedString);
                foreach (ClassificationDisplayRule r in currentRules.Rules)
                {
                    dataGridView1.Rows.Add(CreateRow(r));
                }
            }

            controller.TurnViewUpdateOn(false, false);
            this.ResumeLayout();
        }
예제 #4
0
 private void UpdateRuleInAME(ClassificationDisplayRules rules)
 {
     if (controller == null || componentId < 0)
         return;
     try
     {
         controller.UpdateParameters(componentId, parameterCategory + "." + parameterName, rules.ToXML(), eParamParentType.Component);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error updating parameter. Check the format of the parameter and any other constraints");
     }
 }
예제 #5
0
 private void UpdateClassificationRule(String oldClassification, String oldState, String oldIconName, String classification, String state, String iconName)
 {
     if (currentRules == null)
         currentRules = new ClassificationDisplayRules();
     foreach (ClassificationDisplayRule rule in currentRules.Rules)
     {
         if (rule.Classification == oldClassification && rule.IconName == oldIconName && rule.StateName == oldState)
         {
             rule.Classification = classification;
             rule.IconName = iconName;
             rule.StateName = state;
             break;
         }
     }
     UpdateRuleInAME(currentRules);
 }
예제 #6
0
 public ClassificationRule(IContainer container)
 {
     container.Add(this);
     currentRules = new ClassificationDisplayRules();
     viewComponentHelper = new ViewComponentHelper(this);
     InitializeComponent();
     dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick);
 }