void OnTriggerStay2D(Collider2D x) { if (x.gameObject.tag != "Enemy" && x.gameObject.tag != "Wreckage") { return; } if (!shield.shutdown) { return; // Shield will protect it from collide. } // Colliding damage is defined here. float dmgps = 3000; float dmg = dmgps * Time.fixedDeltaTime; hp -= dmg; // *Not* RevieveDamage. SpecObject s = x.gameObject.GetComponent <SpecObject>(); if (s != null) { s.RecieveDamage(DamageType.Energy, dmg * 2f); v = (Vector2)(this.gameObject.transform.position - x.gameObject.transform.position).normalized * 2f; } // **No physics effects yet.** }
/// <summary> /// Add ObjSpec childrens to DataTable, recursive with /// </summary> /// <param name="dt"></param> /// <param name="children"></param> /// <param name="level"></param> public void AddRequirements(DataTable dt, List <SpecHierarchy> children, int level) { if (children == null || children.Count == 0) { return; } foreach (SpecHierarchy child in children) { DataRow dataRow = dt.NewRow(); SpecObject specObject = child.Object; dataRow["Id"] = specObject.Identifier; dataRow["Object Level"] = level; List <AttributeValue> columns = specObject.Values; for (int i = 0; i < columns.Count; i++) { try { dataRow[columns[i].AttributeDefinition.LongName] = columns[i].ObjectValue.ToString(); } catch (Exception e) { MessageBox.Show($@"AttrName: '{columns[i].AttributeDefinition.LongName}' {e}", @"Exception add ReqIF Attribute"); continue; } } dt.Rows.Add(dataRow); AddRequirements(dt, child.Children, level + 1); } }
/// <summary> /// This function is for dealing with shield-ship or shield-wreckage collides. /// </summary> /// <param name="x"></param> void OnTriggerStay2D(Collider2D x) { if (x.gameObject.tag != "Enemy" && x.gameObject.tag != "Wreckage") { return; } // Colliding damage is defined here. float dmgps = 3000; float dmg = dmgps * Time.fixedDeltaTime; sp -= dmg; // *Not* RevieveDamage. SpecObject s = x.gameObject.GetComponent <SpecObject>(); if (s != null) { s.RecieveDamage(DamageType.Energy, dmg); Player player = this.transform.parent.gameObject.GetComponent <Player>(); player.v = (Vector2)(this.gameObject.transform.parent.position - x.gameObject.transform.position).normalized; } // **No physics effects yet.** // Shuold have some special FX when colliding. }
/// <summary> /// create a <see cref="SpecObject"/>s with attribute values /// </summary> private void CreateSpecObjects() { var reqIfContent = this.reqIF.CoreContent.SingleOrDefault(); var specObject = new SpecObject(); specObject.LongName = "spec object 1"; specObject.Identifier = this.specobject_1_id; specObject.LastChange = DateTime.Parse("2015-12-01"); var specType = (SpecObjectType)reqIfContent.SpecTypes.SingleOrDefault(x => x.GetType() == typeof(SpecObjectType)); specObject.Type = specType; this.CreateValuesForSpecElementWithAttributes(specObject, specType); reqIfContent.SpecObjects.Add(specObject); var specobject_2 = new SpecObject(); specobject_2.LongName = "spec object 2"; specobject_2.Identifier = this.specobject_2_id; specobject_2.LastChange = DateTime.Parse("2015-12-01"); specobject_2.Type = specType; this.CreateValuesForSpecElementWithAttributes(specobject_2, specType); reqIfContent.SpecObjects.Add(specobject_2); var specobject_3 = new SpecObject(); specobject_3.LongName = "spec object 3"; specobject_3.Identifier = this.specobject_3_id; specobject_3.LastChange = DateTime.Parse("2015-12-01"); specobject_3.Type = specType; this.CreateValuesForSpecElementWithAttributes(specobject_3, specType); reqIfContent.SpecObjects.Add(specobject_3); }
/// <summary> /// Update ReqIF RoundTrip Attributes from EA Tagged value for an Element. /// </summary> /// <param name="el"></param> /// <param name="specObj"></param> /// <returns></returns> private bool ExportUpdateRoundTripAttributes(Element el, SpecObject specObj) { // update values of ReqIF Attributes by TaggedValues foreach (string tvName in _exportFields.GetFields()) { string tvValue = TaggedValue.GetTaggedValue(el, GetPrefixedTagValueName(tvName), caseSensitive: false); // update value string macroValue = _exportFields.GetMacroValue(el, tvName); if (macroValue != "") { tvValue = macroValue; } if (tvValue == "") { continue; } if (!RoundtripChangeValueReqIf(specObj, GetUnPrefixedTagValueName(tvName), tvValue, caseSensitive: false)) { return(false); } } return(true); }
public void VerifyThatExceptionIsThrownWhenInvalidTypeIsSet() { var relationGroupType = new RelationGroupType(); var spectObject = new SpecObject(); var specElementWithAttributes = (SpecElementWithAttributes)spectObject; Assert.Throws <ArgumentException>(() => specElementWithAttributes.SpecType = relationGroupType); }
public void VerifyThatUnkownElementAttributeValueThrowsArgumentException() { var specObject = new SpecObject(); string unknownName = "RHEA"; Assert.Throws <ArgumentException>(() => ReqIfFactory.AttributeValueConstruct(unknownName, specObject)); }
public void Verify_that_constructor_works_as_expected() { var specObject = new SpecObject(); var alternativeId = new AlternativeId(specObject); Assert.That(specObject.AlternativeId, Is.EqualTo(alternativeId)); Assert.That(alternativeId.Ident, Is.EqualTo(specObject)); }
/// <summary> /// Returns a <see cref="RequirementsGroup"/> out of an <see cref="SpecObject"/> /// </summary> /// <param name="specObject">The <see cref="SpecObject"/></param> /// <returns>The <see cref="RequirementsGroup"/></returns> private RequirementsGroup CreateRequirementGroup(SpecObject specObject) { SpecTypeMap specTypeMapping; if (!this.typeMap.TryGetValue(specObject.Type, out specTypeMapping)) { // The instance of this type shall not be generated return(null); } var reqNumber = this.groupMap.Count + 1; var name = grpPrefix + reqNumber.ToString("D4"); var group = new RequirementsGroup { Name = string.IsNullOrWhiteSpace(specObject.LongName) ? name : specObject.LongName, ShortName = name, Owner = this.Owner }; group.Category.AddRange(specTypeMapping.Categories); foreach (var value in specObject.Values) { var attributeMap = specTypeMapping.AttributeDefinitionMap.SingleOrDefault(x => x.AttributeDefinition == value.AttributeDefinition); if (attributeMap == null || attributeMap.MapKind == AttributeDefinitionMapKind.NONE) { continue; } string theValue; switch (attributeMap.MapKind) { case AttributeDefinitionMapKind.FIRST_DEFINITION: this.SetDefinition(group, value); break; case AttributeDefinitionMapKind.NAME: theValue = this.GetAttributeValue(value); group.Name = theValue; break; case AttributeDefinitionMapKind.SHORTNAME: theValue = this.GetAttributeValue(value); group.ShortName = theValue; break; case AttributeDefinitionMapKind.PARAMETER_VALUE: this.SetParameterValue(group, value); break; } } this.groupMap.Add(specObject, group); return(group); }
public void VerifyThatXmlElementNameReturnsAttributeValueBoolean() { var specObject = new SpecObject(); Assert.IsInstanceOf <AttributeValueBoolean>(ReqIfFactory.AttributeValueConstruct("ATTRIBUTE-VALUE-BOOLEAN", specObject)); Assert.IsInstanceOf <AttributeValueDate>(ReqIfFactory.AttributeValueConstruct("ATTRIBUTE-VALUE-DATE", specObject)); Assert.IsInstanceOf <AttributeValueEnumeration>(ReqIfFactory.AttributeValueConstruct("ATTRIBUTE-VALUE-ENUMERATION", specObject)); Assert.IsInstanceOf <AttributeValueInteger>(ReqIfFactory.AttributeValueConstruct("ATTRIBUTE-VALUE-INTEGER", specObject)); Assert.IsInstanceOf <AttributeValueReal>(ReqIfFactory.AttributeValueConstruct("ATTRIBUTE-VALUE-REAL", specObject)); Assert.IsInstanceOf <AttributeValueString>(ReqIfFactory.AttributeValueConstruct("ATTRIBUTE-VALUE-STRING", specObject)); Assert.IsInstanceOf <AttributeValueXHTML>(ReqIfFactory.AttributeValueConstruct("ATTRIBUTE-VALUE-XHTML", specObject)); }
/// <summary> /// Queries all the <see cref="SpecRelation"/>s that the <see cref="SpecObject"/> is either the source or target of /// </summary> /// <param name="specObject"> /// The subject <see cref="SpecObject"/> /// </param> /// <returns> /// An <see cref="IEnumerable{SpecRelation}"/> that the <see cref="SpecObject"/> is either the source or target of /// </returns> public static IEnumerable <SpecRelation> QuerySpecRelations(this SpecObject specObject) { var result = new List <SpecRelation>(); foreach (var specRelation in specObject.ReqIFContent.SpecRelations) { if (specRelation.Source == specObject || specRelation.Target == specObject) { result.Add(specRelation); } } return(result); }
public void Verify_that_When_Type_is_null_WriteXml_throws_exception() { var stream = new MemoryStream(); var writer = XmlWriter.Create(stream, this.settings); var spectObject = new SpecObject { Identifier = "SpectObjectIdentifier", LongName = "SpectObjectLongName" }; Assert.That( () => spectObject.WriteXml(writer), Throws.Exception.TypeOf <SerializationException>() .With.Message.Contains("The Type property of SpecObject SpectObjectIdentifier:SpectObjectLongName may not be null")); }
/// <summary> /// Queries the <see cref="Specification"/> that the <see cref="SpecObject"/> is contained by /// </summary> /// <param name="specObject"> /// The subject <see cref="SpecObject"/> /// </param> /// <returns> /// An <see cref="IEnumerable{Specification}"/> that the <see cref="SpecObject"/> is contained by /// </returns> public static IEnumerable <Specification> QueryContainerSpecifications(this SpecObject specObject) { var result = new List <Specification>(); foreach (var specification in specObject.ReqIFContent.Specifications) { var specobjects = specification.QueryAllContainedSpecObjects(); if (specobjects.Any(x => x.Identifier == specObject.Identifier)) { result.Add(specification); } } return(result); }
/// <summary> /// Returns the <see cref="SpecObject"/> representation of a <see cref="Requirement"/> /// </summary> /// <param name="requirement">The <see cref="Requirement"/></param> /// <param name="specObjectType">The associated <see cref="SpecObjectType"/></param> /// <returns>The associated <see cref="SpecObject"/></returns> public SpecObject ToReqIfSpecObject(Requirement requirement, SpecObjectType specObjectType) { if (requirement == null) { throw new ArgumentNullException("requirement"); } var specObject = new SpecObject(); this.SetIdentifiableProperties(specObject, requirement); specObject.Type = specObjectType; this.SetCommonAttributeValues(specObject, requirement); foreach (var parameterValue in requirement.ParameterValue) { var attributeDef = specObjectType.SpecAttributes.Single(x => x.DatatypeDefinition.Identifier == parameterValue.ParameterType.Iid.ToString()); var value = this.ToReqIfAttributeValue(parameterValue.ParameterType, attributeDef, parameterValue.Value, parameterValue.Scale); specObject.Values.Add(value); } // Add extra AttributeValue corresponding to the requirement text if (requirement.Definition.Any()) { var definition = requirement.Definition.First(); var attributeDefinition = (AttributeDefinitionString)specObjectType.SpecAttributes.Single(def => def.DatatypeDefinition == this.TextDatatypeDefinition && def.LongName == RequirementTextAttributeDefName); var requirementValue = new AttributeValueString { TheValue = definition.Content, Definition = attributeDefinition }; specObject.Values.Add(requirementValue); } // Add extra AttributeValue corresponding to the isDeprecated property var isDeprecatedType = (AttributeDefinitionBoolean)specObjectType.SpecAttributes.Single(def => def.DatatypeDefinition == this.BooleanDatatypeDefinition && def.LongName == IsDeprecatedAttributeDefName); var isDeprecated = new AttributeValueBoolean { TheValue = requirement.IsDeprecated, Definition = isDeprecatedType }; specObject.Values.Add(isDeprecated); return(specObject); }
public void VerifyThatTheSpecTypeCanBeSetOrGet() { var specObjectType = new SpecObjectType(); var spectObject = new SpecObject(); spectObject.Type = specObjectType; var specElementWithAttributes = (SpecElementWithAttributes)spectObject; Assert.AreEqual(specObjectType, specElementWithAttributes.SpecType); var otherSpecObjectType = new SpecObjectType(); specElementWithAttributes.SpecType = otherSpecObjectType; Assert.AreEqual(otherSpecObjectType, spectObject.SpecType); }
public void Verify_that_When_Target_is_null_WriteXml_throws_exception() { var stream = new MemoryStream(); var writer = XmlWriter.Create(stream, this.settings); var specRelationType = new SpecRelationType(); var spectObject = new SpecObject(); var specRelation = new SpecRelation { Identifier = "SpecRelationIdentifier", LongName = "SpecRelationLongName", Type = specRelationType, Source = spectObject }; Assert.That( () => specRelation.WriteXml(writer), Throws.Exception.TypeOf <SerializationException>() .With.Message.Contains("The Target of SpecRelation SpecRelationIdentifier:SpecRelationLongName may not be null")); }
/// <summary> /// Returns the <see cref="SpecObject"/> representation of a <see cref="RequirementsGroup"/> /// </summary> /// <param name="requirementsGroup">The <see cref="RequirementsGroup"/></param> /// <param name="specObjectType">The associated <see cref="SpecObjectType"/></param> /// <returns>The associated <see cref="SpecObject"/></returns> public SpecObject ToReqIfSpecObject(RequirementsGroup requirementsGroup, SpecObjectType specObjectType) { if (requirementsGroup == null) { throw new ArgumentNullException("requirementsGroup"); } var specObject = new SpecObject(); this.SetIdentifiableProperties(specObject, requirementsGroup); specObject.Type = specObjectType; this.SetCommonAttributeValues(specObject, requirementsGroup); foreach (var parameterValue in requirementsGroup.ParameterValue) { var attributeDef = specObjectType.SpecAttributes.Single(x => x.DatatypeDefinition.Identifier == parameterValue.ParameterType.Iid.ToString()); var value = this.ToReqIfAttributeValue(parameterValue.ParameterType, attributeDef, parameterValue.Value, parameterValue.Scale); specObject.Values.Add(value); } return(specObject); }
void DisplayArray() { EditorGUI.indentLevel++; for (int i = 0; i < specStore.storeArray.Count; i++) { SpecObject specObject = specStore.storeArray[i]; System.Type type = specObject.GetType(); string title = System.String.Format("[{0}] {1} ({2})", i.ToString(), specObject.name, type.Name); if (specObjectFoldouts.Count < i + 1) { specObjectFoldouts.Add(false); } if (deleteSelection.Count < i + 1) { deleteSelection.Add(false); } EditorGUILayout.BeginHorizontal(); specObjectFoldouts[i] = EditorGUILayout.Foldout(specObjectFoldouts[i], title); deleteSelection[i] = EditorGUILayout.Toggle(deleteSelection[i]); EditorGUILayout.EndHorizontal(); if (specObjectFoldouts[i]) { var fieldInfos = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance); var MethodInfo = type.GetMethod("DisplayFields", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance); EditorGUI.indentLevel++; if (fieldInfos.Length > 0 && MethodInfo == null) { Debug.LogWarning("Non-inherited fields present but DisplayFields override not implemented"); } specObject.DisplayFields(); EditorGUI.indentLevel--; } } EditorGUI.indentLevel--; }
/// <summary> /// Returns a <see cref="Requirement"/> out of an <see cref="SpecObject"/> /// </summary> /// <param name="specObject">The <see cref="SpecObject"/></param> /// <returns>The <see cref="Requirement"/></returns> private Requirement CreateRequirement(SpecObject specObject) { SpecTypeMap specTypeMapping; if (!this.typeMap.TryGetValue(specObject.Type, out specTypeMapping)) { // The instance of this type shall not be generated return(null); } var specObjectTypeMap = (SpecObjectTypeMap)specTypeMapping; if (!specObjectTypeMap.IsRequirement) { return(null); } var reqNumber = this.specObjectMap.Count + 1; var requirement = new Requirement { Name = specObject.LongName, ShortName = ReqPrefix + reqNumber.ToString("D4"), Owner = this.Owner }; requirement.Category.AddRange(specTypeMapping.Categories); foreach (var value in specObject.Values) { var attributeMap = specTypeMapping.AttributeDefinitionMap.SingleOrDefault(x => x.AttributeDefinition == value.AttributeDefinition); if (attributeMap == null || attributeMap.MapKind == AttributeDefinitionMapKind.NONE) { continue; } string theValue; switch (attributeMap.MapKind) { case AttributeDefinitionMapKind.FIRST_DEFINITION: this.SetDefinition(requirement, value); break; case AttributeDefinitionMapKind.NAME: theValue = this.GetAttributeValue(value); requirement.Name = theValue; break; case AttributeDefinitionMapKind.SHORTNAME: theValue = this.GetAttributeValue(value); requirement.ShortName = theValue; break; case AttributeDefinitionMapKind.PARAMETER_VALUE: this.SetParameterValue(requirement, value); break; } } this.specObjectMap.Add(specObject, requirement); return(requirement); }
public void Edit_SpecObject(SpecobjectViewModel specObject, bool createSpecObject, string position = null) { SpecObjectViewerWindow SpecObjectViewer = new SpecObjectViewerWindow(specObject); SpecObjectViewer.Owner = Window.GetWindow(this); if (SpecObjectViewer.ShowDialog() == true) { if (createSpecObject) { int currentIndex = 0; SpecobjectViewModel currentModelObject = (Application.Current.MainWindow as MainWindow).MainDataGrid.SelectedItem as SpecobjectViewModel; SpecObject currentObject = (Application.Current.MainWindow as MainWindow).content.SpecObjects.Single(x => x.Identifier == currentModelObject.Identifier); var specifications = (Application.Current.MainWindow as MainWindow).content.Specifications; //Create new SpecObject and add Attributes SpecObject newSpecObject = new SpecObject() { Description = specObject.Description, Identifier = specObject.Identifier, LastChange = specObject.LastChange, Type = currentObject.Type }; foreach (var attribute in specObject.Values) { if (attribute.AttributeValue != null) { newSpecObject.Values.Add(attribute.AttributeValue); } } //Add SpecObject to SpecHierarchy and to SpecObjects SpecHierarchy specHierarchy = specifications.First().Children.First().Descendants() .Where(node => node.Object == currentObject).First(); if (position == "after") { SpecHierarchy parentSpecHierarchy = specHierarchy.Container; int specHierarchyIndex = parentSpecHierarchy.Children.IndexOf(specHierarchy); parentSpecHierarchy.Children.Insert(specHierarchyIndex + 1, new SpecHierarchy() { Object = newSpecObject, Identifier = Guid.NewGuid().ToString(), LastChange = DateTime.Now }); var previousObject = specHierarchy.Descendants().Last().Object; currentIndex = (Application.Current.MainWindow as MainWindow).content.SpecObjects.IndexOf(previousObject); } else if (position == "under") { specHierarchy.Children.Insert(0, new SpecHierarchy() { Object = newSpecObject, Identifier = Guid.NewGuid().ToString(), LastChange = DateTime.Now }); currentIndex = (Application.Current.MainWindow as MainWindow).MainDataGrid.SelectedIndex; } this.specObjectsViewModel.SpecObjects.Insert(currentIndex + 1, specObject); this.content.SpecObjects.Insert(currentIndex + 1, newSpecObject); } else { var originalSpecObject = content.SpecObjects.Single(x => x.Identifier == specObject.Identifier); //Update changed AttributeValues foreach (var definition in specObject.Values.Where(x => x.changed == true)) { originalSpecObject.Values.Single(x => x.AttributeDefinition == definition.AttributeDefinition).ObjectValue = specObject.Values.Single(x => x.AttributeDefinition == definition.AttributeDefinition).AttributeValue.ObjectValue; } //Add new AttributeValues to original SpecObject foreach (var definition in specObject.Values.Where(x => x.added == true)) { originalSpecObject.Values.Add(specObject.Values.Single(x => x.AttributeDefinition == definition.AttributeDefinition).AttributeValue); } // Remove AttributeValues from original SpecObject foreach (var definition in specObject.Values.Where(x => x.removed == true)) { originalSpecObject.Values.Remove(originalSpecObject.Values.Single(x => x.AttributeDefinition == definition.AttributeDefinition)); } } } }
/// <summary> /// /// </summary> /// <param name="x"></param> /// <param name="loc">The correct hit location.</param> void Hit(Collider2D x, Vector2 loc) { GameObject t = x.gameObject; // Should do nothing with the friendly. if (this.gameObject.tag == "AllyCannonball") { if (t.tag == "Ally" || t.tag == "AllyCannonball" | t.tag == "Player") { return; } } else if (this.gameObject.tag == "EnemyCannonball") { if (t.tag == "Enemy" || t.tag == "EnemyCannonball") { return; } } /*else if(this.gameObject.tag != "UsedCannonball") * { * Debug.Log("WARNING: Cannonball tag is not set properly : " + this.gameObject.name); * return; * }*/ if (hitted) { return; // This gameobjcet will be destroyed when timeout in FixedUpdate. } // Notice that all *can-be-hit* cannonball & missiles *should* mount a SpecObject. SpecObject s = t.GetComponent <SpecObject>(); if (s == null) { return; } s.RecieveDamage(damageType, damage); this.GetComponent <AudioSource>().Play(); // Not to destroy this object immediatly for playing sounds. //Destroy(this.gameObject); Collider2D cd = this.gameObject.GetComponent <Collider2D>(); if (cd != null) { Destroy(cd); } SpriteRenderer rd = this.gameObject.GetComponent <SpriteRenderer>(); if (rd != null) { Destroy(rd); } this.gameObject.tag = "UsedCannonball"; hitted = true; // FX objects... if (explodeFX != null) { // Maintain direction... Vector3 dir; float a; this.gameObject.transform.rotation.ToAngleAxis(out a, out dir); if (dir.z < 0) { dir = -dir; a = -a; } Vector2 vdir; vdir.y = Mathf.Min(Mathf.Cos(a * Mathf.Deg2Rad) * speed, 0f); vdir.x = -Mathf.Sin(a * Mathf.Deg2Rad) * speed; if (vdir.magnitude > Global.flySpeed * 0.5f) { vdir = vdir.normalized * Global.flySpeed * 0.5f; } // Create and assign fx objects... for (int i = 0; i < explodeFX.Length; i++) { GameObject fx = Instantiate(explodeFX[i]); fx.transform.position = loc; Flasher fl = fx.GetComponent <Flasher>(); if (fl != null) { fl.baseSpeed = vdir; } } } // particle objects... if (explodeParticles != null) { for (int i = 0; i < explodeParticles.Length; i++) { GameObject pc = Instantiate(explodeParticles[i]); pc.transform.position = loc; // Turn the color to red as enemies' ship damaged. SpriteRenderer prd = pc.GetComponent <SpriteRenderer>(); Shield sd = x.gameObject.GetComponent <Shield>(); if (prd != null && sd == null) { SpriteRenderer spr = s.gameObject.GetComponent <SpriteRenderer>(); if (spr != null) { float hrate = 0.5f + 0.5f * s.hp / s.hpMax; prd.color = new Color( spr.color.r, spr.color.g * hrate, spr.color.b * hrate, spr.color.a); } } } } }
/// <summary> /// Create, update, delete requirements in EA Package from Requirement DataTable. /// </summary> /// <param name="eaObjectType"></param> /// <param name="eaStereotype"></param> /// <param name="stateNew"></param> /// <param name="stateChanged"></param> /// <param name="importFile"></param> private void CreateUpdateDeleteEaRequirements(string eaObjectType, string eaStereotype, string stateNew, string stateChanged, string importFile) { Count = 0; CountChanged = 0; CountNew = 0; List <int> parentElementIdsPerLevel = new List <int> { 0 }; int parentElementId = 0; int lastElementId = 0; int oldLevel = 0; string notesColumn = Settings.AttrNotes ?? ""; foreach (DataRow row in DtRequirements.Rows) { Count += 1; string objectId = row["Id"].ToString(); SpecObject specObject = (SpecObject)row["specObject"]; int objectLevel = Int32.Parse(row["Object Level"].ToString()) - 1; // Maintain parent ids of level // get parent id if (objectLevel > oldLevel) { if (parentElementIdsPerLevel.Count <= objectLevel) { parentElementIdsPerLevel.Add(lastElementId); } else { parentElementIdsPerLevel[objectLevel] = lastElementId; } parentElementId = lastElementId; } if (objectLevel < oldLevel) { parentElementId = parentElementIdsPerLevel[objectLevel]; } oldLevel = objectLevel; CombineAttrValues(Settings.AliasList, row, out string alias, ShortNameLength, makeName: true); CombineAttrValues(Settings.AttrNameList, row, out string name, ShortNameLength, makeName: true); string notes = GetStringAttrValue(notesColumn != "" ? row[notesColumn].ToString() : row[1].ToString()); // Check if requirement with Doors ID already exists bool isExistingRequirement = DictPackageRequirements.TryGetValue(objectId, out int elId); EA.Element el; if (isExistingRequirement) { el = Rep.GetElementByID(elId); if (el.Alias != alias || el.Name != name || el.Notes != notes) { if (stateChanged != "") { el.Status = stateChanged; } CountChanged += 1; } } else { el = (EA.Element)Pkg.Elements.AddNew(name, "Requirement"); if (stateNew != "") { el.Status = stateNew; } CountChanged += 1; } try { el.Alias = alias; el.Name = name; el.Multiplicity = objectId; el.Notes = notes; el.TreePos = Count * 10; el.PackageID = Pkg.PackageID; el.ParentID = parentElementId; el.Type = eaObjectType; el.Stereotype = eaStereotype; el.Update(); Pkg.Elements.Refresh(); lastElementId = el.ElementID; } catch (Exception e) { if (MessageBox.Show($@"Name: '{name}' Alias: '{alias} ObjectId/Multiplicity: '{objectId} {e}", @"Error update EA Element, skip!", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { break; } else { continue; } } // handle the remaining columns/ tagged values var cols = from c in DtRequirements.Columns.Cast <DataColumn>() join v in specObject.SpecType.SpecAttributes on c.ColumnName equals v.LongName // specObject.Values on c.ColumnName equals v.AttributeDefinition.LongName where !ColumnNamesNoTaggedValues.Any(n => n == c.ColumnName) select new { Name = c.ColumnName, Value = row[c].ToString(), AttrDef = v } ; // Handle *.rtf/*.docx content string rtfValue = CombineRtfAttrValues(Settings.RtfNameList, row); // Update EA linked documents by graphics and embedded elements UpdateLinkedDocument(el, rtfValue, importFile); // Update/Create Tagged value DeleteWritableTaggedValuesForElement(el); // over all columns foreach (var c in cols) { // suppress column if already schown in notes if (notesColumn != c.Name) { // Enum with multivalue if (c.AttrDef is AttributeDefinitionEnumeration attrDefinitionEnumeration && attrDefinitionEnumeration.IsMultiValued) { // Enum values available var arrayEnumValues = ((DatatypeDefinitionEnumeration)c.AttrDef.DatatypeDefinition) .SpecifiedValues .Select(x => x.LongName).ToArray(); Regex rx = new Regex(@"\r\n| "); var values = rx.Replace(c.Value, ",").Split(','); var found = from all in arrayEnumValues from s1 in values.Where(xxx => all == xxx).DefaultIfEmpty() select new { All = all, Value = s1 }; var value = ""; var del = ""; foreach (var f in found) { if (f.Value == null) { value = $"{value}{del}0"; } else { value = $"{value}{del}1"; } del = ","; } CreateUpdateTaggedValueDuringInput(el, c.Name, c.Value, c.AttrDef); } else { // handle roundtrip attributes CreateUpdateTaggedValueDuringInput(el, c.Name, c.Value, c.AttrDef); } } } }
private void SetupReqIf() { this.reqIf = new ReqIF(); this.reqIf.Lang = "en"; this.corecontent = new ReqIFContent(); this.reqIf.CoreContent = this.corecontent; this.stringDatadef = new DatatypeDefinitionString(); this.specificationtype = new SpecificationType(); this.specobjecttype = new SpecObjectType(); this.specrelationtype = new SpecRelationType(); this.relationgrouptype = new RelationGroupType(); this.specAttribute = new AttributeDefinitionString() { DatatypeDefinition = this.stringDatadef }; this.reqAttribute = new AttributeDefinitionString() { DatatypeDefinition = this.stringDatadef }; this.specRelationAttribute = new AttributeDefinitionString() { DatatypeDefinition = this.stringDatadef }; this.relationgroupAttribute = new AttributeDefinitionString() { DatatypeDefinition = this.stringDatadef }; this.specificationtype.SpecAttributes.Add(this.specAttribute); this.specobjecttype.SpecAttributes.Add(this.reqAttribute); this.specrelationtype.SpecAttributes.Add(this.specRelationAttribute); this.relationgrouptype.SpecAttributes.Add(this.relationgroupAttribute); this.specification1 = new Specification() { Type = this.specificationtype }; this.specification2 = new Specification() { Type = this.specificationtype }; this.specobject1 = new SpecObject() { Type = this.specobjecttype }; this.specobject2 = new SpecObject() { Type = this.specobjecttype }; this.specrelation = new SpecRelation() { Type = this.specrelationtype, Source = this.specobject1, Target = this.specobject2 }; this.relationgroup = new RelationGroup() { Type = this.relationgrouptype, SourceSpecification = this.specification1, TargetSpecification = this.specification2 }; this.specValue1 = new AttributeValueString() { AttributeDefinition = this.specAttribute, TheValue = "spec1" }; this.specValue2 = new AttributeValueString() { AttributeDefinition = this.specAttribute, TheValue = "spec2" }; this.objectValue1 = new AttributeValueString() { AttributeDefinition = this.reqAttribute, TheValue = "req1" }; this.objectValue2 = new AttributeValueString() { AttributeDefinition = this.reqAttribute, TheValue = "req2" }; this.relationgroupValue = new AttributeValueString() { AttributeDefinition = this.relationgroupAttribute, TheValue = "group" }; this.specrelationValue = new AttributeValueString() { AttributeDefinition = this.specRelationAttribute, TheValue = "specrelation" }; this.specification1.Values.Add(this.specValue1); this.specification2.Values.Add(this.specValue2); this.specobject1.Values.Add(this.objectValue1); this.specobject2.Values.Add(this.objectValue2); this.specrelation.Values.Add(this.specrelationValue); this.relationgroup.Values.Add(this.relationgroupValue); this.corecontent.DataTypes.Add(this.stringDatadef); this.corecontent.SpecTypes.AddRange(new SpecType[] { this.specobjecttype, this.specificationtype, this.specrelationtype, this.relationgrouptype }); this.corecontent.SpecObjects.AddRange(new SpecObject[] { this.specobject1, this.specobject2 }); this.corecontent.Specifications.AddRange(new Specification[] { this.specification1, this.specification2 }); this.corecontent.SpecRelations.Add(this.specrelation); this.corecontent.SpecRelationGroups.Add(this.relationgroup); this.specification1.Children.Add(new SpecHierarchy() { Object = this.specobject1 }); this.specification2.Children.Add(new SpecHierarchy() { Object = this.specobject2 }); }
/// <summary> /// Change ReqIF value of the specObject and the attribute value. The Attribute must be part of the ReqIF file. /// </summary> /// <param name="specObject"></param> /// <param name="name"></param> /// <param name="eaValue"></param> /// <param name="caseSensitive"></param> /// <returns></returns> private bool RoundtripChangeValueReqIf(SpecObject specObject, string name, string eaValue, bool caseSensitive = false) { try { AttributeValue attrValueObject = caseSensitive ? specObject.Values.SingleOrDefault(x => x.AttributeDefinition.LongName == name) : specObject.Values.SingleOrDefault(x => x.AttributeDefinition.LongName.ToLower() == name.ToLower()); // Attribute not part of ReqIF, skip if (attrValueObject == null) { // Create AttributValue and assign them to values. AttributeDefinition attributeType = _moduleAttributeDefinitions.SingleOrDefault(x => x.LongName.ToLower() == name.ToLower()); switch (attributeType) { case AttributeDefinitionString _: attrValueObject = new AttributeValueString { AttributeDefinition = attributeType }; break; case AttributeDefinitionXHTML _: attrValueObject = new AttributeValueXHTML { AttributeDefinition = attributeType }; break; case AttributeDefinitionEnumeration moduleAttributDefinitionEnumeration: attrValueObject = new AttributeValueEnumeration { AttributeDefinition = attributeType }; break; } if (attrValueObject == null) { return(true); // not supported datatype } specObject.Values.Add(attrValueObject); } var attrType = attrValueObject.AttributeDefinition; //specObj.Values[0].AttributeDefinition.LongName; switch (attrType) { case AttributeDefinitionXHTML _: // make xhtml and handle new line var xhtmlcontent = MakeXhtmlFromString(eaValue); attrValueObject.ObjectValue = xhtmlcontent; break; case AttributeDefinitionString _: attrValueObject.ObjectValue = eaValue; break; case AttributeDefinitionEnumeration _: try { // take all the valid enums if (!SetReqIfEnumValue((AttributeValueEnumeration)attrValueObject, eaValue)) { return(false); } } catch (Exception e) { MessageBox.Show($@"Name: '{name}' Value: '{eaValue}' {e}", $@"Error enumeration value TV '{name}'."); } break; } return(true); } catch (Exception e) { MessageBox.Show($@"Name: '{name}' Value: '{eaValue}' {e}", $@"Error value TV '{name}'."); return(false); } }
/// <summary> /// Returns the <see cref="SpecRelation"/> representation of a <see cref="BinaryRelationship"/>-<see cref="BinaryRelationshipRule"/> combination /// </summary> /// <param name="relationship"> /// The <see cref="BinaryRelationship"/> /// </param> /// <param name="relationType">The associated <see cref="SpecRelationType"/></param> /// <param name="source">The <see cref="SpecObject"/> source</param> /// <param name="target">The <see cref="SpecObject"/> target</param> /// <returns> /// The <see cref="SpecRelation"/> /// </returns> public SpecRelation ToReqIfSpecRelation(BinaryRelationship relationship, SpecRelationType relationType, SpecObject source, SpecObject target) { if (relationship == null) { throw new ArgumentNullException("relationship"); } var specRelation = new SpecRelation { Identifier = relationship.Iid.ToString(), LastChange = DateTime.UtcNow, LongName = relationship.UserFriendlyName }; specRelation.Type = relationType; this.SetCommonAttributeValues(specRelation, relationship); foreach (var parameterValue in relationship.ParameterValue) { var attributeDef = relationType.SpecAttributes.Single(x => x.DatatypeDefinition.Identifier == parameterValue.ParameterType.Iid.ToString()); var value = this.ToReqIfAttributeValue(parameterValue.ParameterType, attributeDef, parameterValue.Value, parameterValue.Scale); specRelation.Values.Add(value); } specRelation.Source = source; specRelation.Target = target; return(specRelation); }
private void ScrollToRow(SpecObject specObject) { specObject = specObjectsViewModel.SpecObjects.Single(x => x.Identifier == specObject.Identifier); MainDataGrid.SelectedItem = specObject; MainDataGrid.ScrollIntoView(specObject); }
void AddNewElement() { SpecObject element = System.Activator.CreateInstance(specStore.elementBaseType) as SpecObject; specStore.storeArray.Add(element); }