internal Activity(ItemObjectInitializer initializer) : base(initializer) { DescriptionProperty = new AttributeProperty <string>(this, "Description", "Description", false, false, (x) => { OnDescriptionChanged(ref x); return(x); }, (x) => { OnDescriptionWriting(ref x); return(x); }); FromProperty = new AttributeProperty <System.DateTime>(this, "From", "From", false, false, (x) => { OnFromChanged(ref x); return(x); }, (x) => { OnFromWriting(ref x); return(x); }); ToProperty = new AttributeProperty <System.DateTime>(this, "To", "To", false, false, (x) => { OnToChanged(ref x); return(x); }, (x) => { OnToWriting(ref x); return(x); }); Incurred = new Association <Expense>(this, "Incurred", "Incurred", "IncurredOn"); OnInitialize(); }
private void ProcessAttributeProperty(XmlElement parent, AttributeProperty prop) { XmlElement tmpElement = document.CreateElement("Property"); tmpElement.SetAttribute("Name", prop.Name); tmpElement.SetAttribute("Value", prop.Value.ToString()); parent.AppendChild(tmpElement); }
private bool CheckPropertyIsDefault(AttributeProperty <WMIPropertyAttribute> attributeProperty, T instance) { var value = attributeProperty.Property.GetValue(instance); return((value == null || (attributeProperty.Attribute.Type == typeof(int) && (int)value == default)) || (attributeProperty.Attribute.Type == typeof(string) && string.IsNullOrWhiteSpace((string)value)) || (attributeProperty.Attribute.Type == typeof(bool) && (bool)value == default) || (attributeProperty.Attribute.Type == typeof(DateTime) && (DateTime)value == default)); }
public void Start() { if (this.panelPrefab == null) { Debug.LogError("Panels prefab has not been set."); return; } if (this.equationInputField == null) { Debug.LogError("Input field has not been set."); return; } if (this.toggleGroup == null) { Debug.LogError("Toggle group has not been set."); return; } if (this.healthToggle == null || this.attackToggle == null || this.speedToggle == null || this.mergeToggle == null || this.attackCooldownToggle == null || this.splitToggle == null) { Debug.LogError("Toggle has not been set. Please check."); return; } this.oldProperty = this.newProperty = AttributeProperty.Health; this.inputLag = 0f; this.prefabList = new List <GameObject>(); //For each level, instantiate a prefab and place it in the Content of the ScrollView. //This allows the Attributes to show consistently the progression of the attributes for each level. for (int i = 0; i < MAX_NUM_OF_LEVELS; i++) { GameObject obj = MonoBehaviour.Instantiate <GameObject>(this.panelPrefab); obj.transform.SetParent(this.transform); RectTransform rectTransform = obj.GetComponent <RectTransform>(); if (rectTransform != null) { rectTransform.localScale = Vector3.one; } this.prefabList.Add(obj); Title title = obj.GetComponentInChildren <Title>(); if (title != null) { title.titleText.text = "Level " + (i + 1).ToString(); } Number number = obj.GetComponentInChildren <Number>(); if (number != null) { number.numberText.text = (0f).ToString(); } } }
private void setNameToolStripMenuItem_Click(object sender, EventArgs e) { string productSKU = dgvItems.Rows[selectedRowIndex].Cells["code"].Value.ToString(); //is this the child or the parent? if (productSKU == selectedAttributeSet.stockCode) { selectedAttributeSet.propertyName = InputBox.ShowDialog("Parent Property Name", "Parent Property Name", selectedAttributeSet.propertyName); } else { AttributeProperty prop = findChildAttribute(productSKU); prop.propertyName = InputBox.ShowDialog("Property Name", "Property Name", prop.propertyName); } }
//public ArrayList getAttributeSetProperties(string attributeSetID) //{ // DataTable dt = new DataTable(); // query = "SELECT propertyID, stockCode, skuCode, position, propertyName FROM attribute_properties WHERE attributeSetID = " + attributeSetID; // dt = db.read(query); // ArrayList properties = new ArrayList(); // for (int i = 0; i < dt.Rows.Count; i++) // { // properties.Add(bindAttributeSetProperties(dt.Rows[i])); // } // return properties; //} public AttributeProperty bindAttributeSetProperties(DataRow dr) { AttributeProperty prop = new AttributeProperty(); prop.propertyID = dr["propertyID"].ToString(); prop.stockCode = dr["stockCode"].ToString(); prop.skuCode = dr["skuCode"].ToString(); if (!string.IsNullOrWhiteSpace(dr["position"].ToString())) { prop.position = int.Parse(dr["position"].ToString()); } else { prop.position = 0; } prop.propertyName = dr["propertyName"].ToString(); return(prop); }
private void setPositionToolStripMenuItem_Click(object sender, EventArgs e) { string childSKU = dgvItems.Rows[selectedRowIndex].Cells["code"].Value.ToString(); AttributeProperty prop = findChildAttribute(childSKU); if (childSKU == selectedAttributeSet.stockCode) { MessageBox.Show("You cannot give positions to parent items"); return; } string val = InputBox.ShowDialog("Property Position", "Property Position", prop.position.ToString()); if (!string.IsNullOrWhiteSpace(val)) { prop.position = int.Parse(val); } }
private void createChildToolStripMenuItem1_Click(object sender, EventArgs e) { string childSKU = dgvItems.Rows[selectedRowIndex].Cells["code"].Value.ToString(); selectedAttributeSet = findParentAttribute(lblParentStockCode.Text); if (childSKU == selectedAttributeSet.stockCode) { MessageBox.Show("Invalid link: Child and Parent cannot be the same"); return; } AttributeProperty prop = new AttributeProperty(); prop.stockCode = childSKU; prop.skuCode = dgvItems.Rows[selectedRowIndex].Cells["SKUCode"].Value.ToString(); dgvItems.Rows[selectedRowIndex].DefaultCellStyle.BackColor = Color.Aquamarine; prop.propertyName = InputBox.ShowDialog("Property Name", "Property Name", prop.propertyName); if (prop.position == 0) { prop.position = childPositionCounter; } string positionTemp = InputBox.ShowDialog("Property Position", "Property Position", prop.position.ToString()); if (positionTemp == null) { positionTemp = (childPositionCounter + 1).ToString(); } prop.position = int.Parse(positionTemp); if (selectedAttributeSet.childrenProperties == null) { selectedAttributeSet.childrenProperties = new List <AttributeProperty>(); } selectedAttributeSet.childrenProperties.Add(prop); childPositionCounter++; }
public void Update() { if (!this.equationInputField.text.Equals("") && Input.GetKey(KeyCode.Return) && this.inputLag < 0.01f) { InputText inputText = this.equationInputField.GetComponentInChildren<InputText>(); if (inputText != null) { this.equationInputField.text = inputText.inputText.text; AttributeProperty property = ProcessToggle(); if (property == AttributeProperty.Invalid) { Debug.LogError("Toggle setup is incorrect. Please check."); } try { UpdateAttributes(property); } catch (Exception e) { Debug.LogError(e.Message.ToString()); this.equationInputField.text = this.equationInputField.text + " [" + e.Message.ToString() + "]"; for (int i = 0; i < MAX_NUM_OF_LEVELS; i++) { GameObject obj = this.prefabList[i]; Title title = obj.GetComponentInChildren<Title>(); if (title != null) { title.titleText.text = "Level " + (i + 1).ToString(); } Number number = obj.GetComponentInChildren<Number>(); if (number != null) { number.numberText.text = (0f).ToString(); } } } this.inputLag = 1.0f; } else { Debug.LogError("This is null."); } } if (this.inputLag > 0f) { this.inputLag -= Time.deltaTime; } if (this.oldProperty != this.newProperty) { for (int i = 0; i < MAX_NUM_OF_LEVELS; i++) { Number number = this.prefabList[i].GetComponentInChildren<Number>(); if (number != null) { switch (this.newProperty) { default: case AttributeProperty.Health: number.numberText.text = this.unitAttributes.healthPrefabList[i].ToString(); break; case AttributeProperty.Attack: number.numberText.text = this.unitAttributes.attackPrefabList[i].ToString(); break; case AttributeProperty.Speed: number.numberText.text = this.unitAttributes.speedPrefabList[i].ToString(); break; case AttributeProperty.Merge: number.numberText.text = this.unitAttributes.mergePrefabList[i].ToString(); break; case AttributeProperty.AttackCooldown: number.numberText.text = this.unitAttributes.attackCooldownPrefabList[i].ToString(); break; case AttributeProperty.Split: if (i <= 0) { number.numberText.text = this.unitAttributes.splitPrefabFactor.ToString(); } else { number.numberText.text = "N/A"; } break; } } } //this.unitAttributes.UpdateValues(); this.oldProperty = this.newProperty; } }
public void Update() { if (!this.equationInputField.text.Equals("") && Input.GetKey(KeyCode.Return) && this.inputLag < 0.01f) { InputText inputText = this.equationInputField.GetComponentInChildren <InputText>(); if (inputText != null) { this.equationInputField.text = inputText.inputText.text; AttributeProperty property = ProcessToggle(); if (property == AttributeProperty.Invalid) { Debug.LogError("Toggle setup is incorrect. Please check."); } try { UpdateAttributes(property); } catch (Exception e) { Debug.LogError(e.Message.ToString()); this.equationInputField.text = this.equationInputField.text + " [" + e.Message.ToString() + "]"; for (int i = 0; i < MAX_NUM_OF_LEVELS; i++) { GameObject obj = this.prefabList[i]; Title title = obj.GetComponentInChildren <Title>(); if (title != null) { title.titleText.text = "Level " + (i + 1).ToString(); } Number number = obj.GetComponentInChildren <Number>(); if (number != null) { number.numberText.text = (0f).ToString(); } } } this.inputLag = 1.0f; } else { Debug.LogError("This is null."); } } if (this.inputLag > 0f) { this.inputLag -= Time.deltaTime; } if (this.oldProperty != this.newProperty) { for (int i = 0; i < MAX_NUM_OF_LEVELS; i++) { Number number = this.prefabList[i].GetComponentInChildren <Number>(); if (number != null) { switch (this.newProperty) { default: case AttributeProperty.Health: number.numberText.text = this.unitAttributes.healthPrefabList[i].ToString(); break; case AttributeProperty.Attack: number.numberText.text = this.unitAttributes.attackPrefabList[i].ToString(); break; case AttributeProperty.Speed: number.numberText.text = this.unitAttributes.speedPrefabList[i].ToString(); break; case AttributeProperty.Merge: number.numberText.text = this.unitAttributes.mergePrefabList[i].ToString(); break; case AttributeProperty.AttackCooldown: number.numberText.text = this.unitAttributes.attackCooldownPrefabList[i].ToString(); break; case AttributeProperty.Split: if (i <= 0) { number.numberText.text = this.unitAttributes.splitPrefabFactor.ToString(); } else { number.numberText.text = "N/A"; } break; } } } //this.unitAttributes.UpdateValues(); this.oldProperty = this.newProperty; } }
public void UpdateAttributes(AttributeProperty property) { float previousAnswer = 0f; for (int level = 0; level < MAX_NUM_OF_LEVELS; level++) { float answer = (float)MathParser.ProcessEquation(this.equationInputField.text, property, level + 1, level, previousAnswer); previousAnswer = answer; if (this.debugFlag) { Debug.Log("DEBUG 8"); } GameObject panel = this.prefabList[level]; Title titlePanel = panel.GetComponentInChildren <Title>(); if (this.debugFlag) { Debug.Log("DEBUG 9"); } if (titlePanel != null) { titlePanel.titleText.text = "Level " + (level + 1).ToString(); } if (this.debugFlag) { Debug.Log("DEBUG 10"); } Number numberPanel = panel.GetComponentInChildren <Number>(); if (numberPanel != null) { if (this.unitAttributes != null) { switch (property) { case AttributeProperty.Health: this.unitAttributes.healthPrefabList[level] = answer; numberPanel.numberText.text = answer.ToString(); break; case AttributeProperty.Attack: this.unitAttributes.attackPrefabList[level] = answer; numberPanel.numberText.text = answer.ToString(); break; case AttributeProperty.Speed: this.unitAttributes.speedPrefabList[level] = answer; numberPanel.numberText.text = answer.ToString(); break; case AttributeProperty.Merge: this.unitAttributes.mergePrefabList[level] = answer; numberPanel.numberText.text = answer.ToString(); break; case AttributeProperty.AttackCooldown: this.unitAttributes.attackCooldownPrefabList[level] = answer; numberPanel.numberText.text = answer.ToString(); break; case AttributeProperty.Split: if (level <= 0) { this.unitAttributes.splitPrefabFactor = answer; numberPanel.numberText.text = answer.ToString(); } else { numberPanel.numberText.text = "N/A"; } level = 10; break; default: case AttributeProperty.Invalid: throw new ArgumentException("Attribute property is invalid."); } } } if (this.debugFlag) { Debug.Log("DEBUG 11"); } if (this.debugFlag) { Debug.Log("DEBUG 12"); } } }
public void UpdateOnlineAttributes(UnitAttributes unitAttributes, AttributeProperty property) { float previousAnswer = 0f; for (int level = 0; level < MAX_NUM_OF_LEVELS; level++) { float answer = (float)MathParser.ProcessEquation(this.equationInputField.text, property, level + 1, level, previousAnswer); previousAnswer = answer; if (this.debugFlag) { Debug.Log("DEBUG 8"); } GameObject panel = this.prefabList[level]; Title titlePanel = panel.GetComponentInChildren<Title>(); if (this.debugFlag) { Debug.Log("DEBUG 9"); } if (titlePanel != null) { titlePanel.titleText.text = "Level " + (level + 1).ToString(); } if (this.debugFlag) { Debug.Log("DEBUG 10"); } int propertyValue = 0; Number numberPanel = panel.GetComponentInChildren<Number>(); if (numberPanel != null) { if (this.unitAttributes != null) { switch (property) { case AttributeProperty.Health: unitAttributes.healthPrefabList[level] = answer; numberPanel.numberText.text = answer.ToString(); propertyValue = 0; break; case AttributeProperty.Attack: unitAttributes.attackPrefabList[level] = answer; numberPanel.numberText.text = answer.ToString(); propertyValue = 1; break; case AttributeProperty.Speed: unitAttributes.speedPrefabList[level] = answer; numberPanel.numberText.text = answer.ToString(); propertyValue = 2; break; case AttributeProperty.Merge: unitAttributes.mergePrefabList[level] = answer; numberPanel.numberText.text = answer.ToString(); propertyValue = 3; break; case AttributeProperty.AttackCooldown: unitAttributes.attackCooldownPrefabList[level] = answer; numberPanel.numberText.text = answer.ToString(); propertyValue = 4; break; case AttributeProperty.Split: if (level <= 0) { unitAttributes.splitPrefabFactor = answer; numberPanel.numberText.text = answer.ToString(); } else { numberPanel.numberText.text = "N/A"; } level = 10; propertyValue = 5; break; default: case AttributeProperty.Invalid: throw new ArgumentException("Attribute property is invalid."); } } } if (this.debugFlag) { Debug.Log("DEBUG 11"); } unitAttributes.CmdUpdateAnswer(answer, level, propertyValue); if (this.debugFlag) { Debug.Log("DEBUG 12"); } } }
public void deleteChildProperties(AttributeProperty property) { query = "DELETE FROM attribute_properties WHERE propertyID = " + property.propertyID; db.write(query); }
//Shunting yard algorithm public static double ProcessEquation(string equation, AttributeProperty property, int level, int previousLevel, float previousAnswer) { if (equation.Equals("")) { throw new ArgumentException("Equation is empty."); } List<string> result = new List<string>(Regex.Split(equation.ToLower().Trim())); for (int i = result.Count - 1; i >= 0; i--) { if (result[i].Equals("") || result[i].Equals(" ")) { result.RemoveAt(i); } } Queue<string> queue = new Queue<string>(); Stack<string> stack = new Stack<string>(); for (int i = 0; i < result.Count; i++) { if (result[i].Equals("x") || result[i].Equals("X")) { result[i] = level.ToString(); } else if (result[i].Equals("k") || result[i].Equals("K")) { if (previousLevel > 0) { result[i] = previousLevel.ToString(); } else { result[i] = "0"; } } else if (result[i].Equals("p") || result[i].Equals("P")) { result[i] = previousAnswer.ToString(); } else if (result[i].Equals("r") || result[i].Equals("R")) { float value = UnityEngine.Random.Range(1f, 1000f); value /= 1000f; result[i] = value.ToString(); } } TokenClass previousTokenClass = TokenClass.Value; for (int i = 0; i < result.Count; i++) { string element = result[i]; if (element.Equals("y") || element.Equals("=")) { continue; } TokenClass tokenClass = GetTokenClass(element); switch (tokenClass) { case TokenClass.Value: queue.Enqueue(element); break; case TokenClass.LeftParentheses: stack.Push(element); break; case TokenClass.RightParentheses: while (!stack.Peek().Equals("(")) { queue.Enqueue(stack.Pop()); } stack.Pop(); break; case TokenClass.Operator: if (element.Equals("-") && (previousTokenClass == TokenClass.Operator || previousTokenClass == TokenClass.LeftParentheses) && (stack.Count == 0 || result[i - 1].Equals("("))) { //Push unary operator "Negative" to stack. stack.Push("NEG"); break; } if (element.Equals("-") && (i + 1 < result.Count) && GetTokenClass(result[i + 1]) == TokenClass.Value) { if (previousTokenClass == TokenClass.Value) { stack.Push(element); } else { stack.Push("NEG"); } break; } if (stack.Count > 0) { string stackTopToken = stack.Peek(); if (GetTokenClass(stackTopToken) == TokenClass.Operator) { Associativity tokenAssociativity = GetAssociativity(stackTopToken); int tokenPrecedence = GetPrecedence(element); int stackTopPrecedence = GetPrecedence(stackTopToken); if ((tokenAssociativity == Associativity.Left && tokenPrecedence <= stackTopPrecedence) || (tokenAssociativity == Associativity.Right && tokenPrecedence < stackTopPrecedence)) { queue.Enqueue(stack.Pop()); } } } stack.Push(element); break; } if (tokenClass == TokenClass.Value || tokenClass == TokenClass.RightParentheses) { if (i < result.Count - 1) { string nextToken = result[i + 1]; TokenClass nextTokenClass = GetTokenClass(nextToken); if (nextTokenClass != TokenClass.Operator && nextTokenClass != TokenClass.RightParentheses) { result.Insert(i + 1, "*"); } } } previousTokenClass = tokenClass; } while (stack.Count > 0) { string operand = stack.Pop(); if (operand.Equals("(") || operand.Equals(")")) { throw new ArgumentException("Mismatched parentheses."); } queue.Enqueue(operand); } Stack<string> expressionStack = new Stack<string>(); while (queue.Count > 0) { string token = queue.Dequeue(); TokenClass tokenClass = GetTokenClass(token); if (tokenClass == TokenClass.Value) { expressionStack.Push(token); } else { double answer = 0f; if (tokenClass == TokenClass.Operator) { string rightOperand = expressionStack.Pop(); string leftOperand = expressionStack.Pop(); if (token.Equals("+")) { answer = double.Parse(leftOperand); answer += double.Parse(rightOperand); } else if (token.Equals("-")) { answer = double.Parse(leftOperand); answer -= double.Parse(rightOperand); } else if (token.Equals("*")) { answer = double.Parse(leftOperand); answer *= double.Parse(rightOperand); } else if (token.Equals("/")) { answer = double.Parse(leftOperand); answer /= double.Parse(rightOperand); } else if (token.Equals("^")) { double baseValue = double.Parse(leftOperand); double exponent = double.Parse(rightOperand); answer = Math.Pow(baseValue, exponent); } } else if (tokenClass == TokenClass.Negative) { string operand = expressionStack.Pop(); answer = double.Parse(operand) * -1f; } expressionStack.Push(answer.ToString()); } } if (expressionStack.Count != 1) { throw new ArgumentException("Invalid equation."); } double finalAnswer = double.Parse(expressionStack.Pop()); return finalAnswer; }
/// <summary> /// Recursive function for handling Seq attributes /// </summary> /// <param name="attribute"></param> void GetSeqAttributesValues(HLI.Attribute attribute) { int itemCount = attribute.ItemCount; int sqVm = 1; string displayTagString = ""; for(int i=0; i < levelOfSeq; i++) displayTagString += ">"; displayTagString += TagString(attribute.GroupNumber,attribute.ElementNumber); // Attribute name string attributeName = attribute.Name; if(attributeName == "") attributeName = "Undefined"; // Add the sequence attribute to the DataGrid AttributeProperty theSeqAttributeInfo = new AttributeProperty(displayTagString, attributeName, "SQ", sqVm.ToString(), "", attribute); _AttributesInfoForDataGrid.Add(theSeqAttributeInfo); for( int i=0; i < itemCount; i++ ) { string itemString = ""; for(int j=0; j < levelOfSeq; j++) itemString += ">"; itemString += string.Format(">BEGIN ITEM {0}", i+1); AttributeProperty theDataGridItemInfo = new AttributeProperty(itemString, "", "", "", "", attribute); _AttributesInfoForDataGrid.Add(theDataGridItemInfo); HLI.SequenceItem item = attribute.GetItem(i+1); for( int k=0; k < item.Count; k++ ) { HLI.Attribute seqAttribute = item[k]; string attributesValues = ""; string seqTagString = ""; string seqAttributeName = seqAttribute.Name; if(seqAttributeName == "") seqAttributeName = "Undefined"; if (seqAttribute.VR != VR.SQ) { for(int m=0; m <= levelOfSeq; m++) seqTagString += ">"; seqTagString += TagString(seqAttribute.GroupNumber,seqAttribute.ElementNumber); if (seqAttribute.Values.Count != 0) { for( int l=0; l < seqAttribute.Values.Count; l++ ) { attributesValues += seqAttribute.Values[l] + "\\"; } if (attributesValues.Trim().EndsWith("\\")) { // now search for the last "\"... int lastLocation = attributesValues.LastIndexOf( "\\" ); // remove the identified section, if it is a valid region if ( lastLocation >= 0 ) attributesValues = attributesValues.Substring( 0, lastLocation ); } } else { attributesValues = ""; } } else { sequenceInSq = true; levelOfSeq++; GetSeqAttributesValues(seqAttribute); sequenceInSq = false; --levelOfSeq; continue; } AttributeProperty theDataGridSeqAttributeInfo = new AttributeProperty(seqTagString, seqAttributeName, seqAttribute.VR.ToString(), seqAttribute.VM.ToString(), attributesValues, seqAttribute); _AttributesInfoForDataGrid.Add(theDataGridSeqAttributeInfo); } itemString = ""; for(int m=0; m < levelOfSeq; m++) itemString += ">"; itemString += string.Format(">END ITEM {0}", i+1); AttributeProperty theDataGridEndItemInfo = new AttributeProperty(itemString, "", "", "", "", null); _AttributesInfoForDataGrid.Add(theDataGridEndItemInfo); } }
/// <summary> /// Helper function for adding dataset to the datagrid /// </summary> void AddDatasetInfoToDataGrid() { for( int i=0; i < _DCMdataset.Count; i++ ) { HLI.Attribute attribute = _DCMdataset[i]; string attributesValues = ""; string attributeName = attribute.Name; if(attributeName == "") attributeName = "Undefined"; //Check for group length attributes if(attribute.ElementNumber == 0x0000) _IsAttributeGroupLengthDefined = true; if (attribute.VR != VR.SQ) { if (attribute.Values.Count != 0) { for( int j=0; j < attribute.Values.Count; j++ ) { attributesValues += attribute.Values[j] + "\\"; } if (attributesValues.EndsWith("\\")) { // now search for the last "\"... int lastLocation = attributesValues.LastIndexOf( "\\" ); // remove the identified section, if it is a valid region if ( lastLocation >= 0 ) attributesValues = attributesValues.Substring( 0, lastLocation ); } } else { attributesValues = ""; } } else { try { GetSeqAttributesValues(attribute); } catch(Exception exception) { string theErrorText; theErrorText = string.Format("Media file {0} could not be read:\n{1}\n\n", DCMFile, exception.Message); richTextBoxLog.AppendText(theErrorText); richTextBoxLog.ScrollToCaret(); richTextBoxLog.Focus(); } if(sequenceInSq) { --levelOfSeq; sequenceInSq = false; } continue; } AttributeProperty theDataGridAttributeInfo = new AttributeProperty(TagString(attribute.GroupNumber,attribute.ElementNumber), attributeName, attribute.VR.ToString(), attribute.VM.ToString(), attributesValues, attribute); _AttributesInfoForDataGrid.Add(theDataGridAttributeInfo); } }
public void ChangeProperty() { this.newProperty = ProcessToggle(); }
public void Start() { if (this.panelPrefab == null) { Debug.LogError("Panels prefab has not been set."); return; } if (this.equationInputField == null) { Debug.LogError("Input field has not been set."); return; } if (this.toggleGroup == null) { Debug.LogError("Toggle group has not been set."); return; } if (this.healthToggle == null || this.attackToggle == null || this.speedToggle == null || this.mergeToggle == null || this.attackCooldownToggle == null || this.splitToggle == null) { Debug.LogError("Toggle has not been set. Please check."); return; } this.oldProperty = this.newProperty = AttributeProperty.Health; this.inputLag = 0f; this.prefabList = new List<GameObject>(); //For each level, instantiate a prefab and place it in the Content of the ScrollView. //This allows the Attributes to show consistently the progression of the attributes for each level. for (int i = 0; i < MAX_NUM_OF_LEVELS; i++) { GameObject obj = MonoBehaviour.Instantiate<GameObject>(this.panelPrefab); obj.transform.SetParent(this.transform); RectTransform rectTransform = obj.GetComponent<RectTransform>(); if (rectTransform != null) { rectTransform.localScale = Vector3.one; } this.prefabList.Add(obj); Title title = obj.GetComponentInChildren<Title>(); if (title != null) { title.titleText.text = "Level " + (i + 1).ToString(); } Number number = obj.GetComponentInChildren<Number>(); if (number != null) { number.numberText.text = (0f).ToString(); } } }
/// <summary> /// Helper function for adding FMI to the datagrid /// </summary> void AddFMIToDataGrid() { for( int i=0; i < _FileMetaInfo.Count; i++ ) { HLI.Attribute attribute = _FileMetaInfo[i]; string attributesValues = ""; string attributeName = attribute.Name; if(attributeName == "") attributeName = "Undefined"; if (attribute.Values.Count != 0) { for( int j=0; j < attribute.Values.Count; j++ ) { attributesValues += attribute.Values[j] + "\\"; } if (attributesValues.EndsWith("\\")) { // now search for the last "\"... int lastLocation = attributesValues.LastIndexOf( "\\" ); // remove the identified section, if it is a valid region if ( lastLocation >= 0 ) attributesValues = attributesValues.Substring( 0, lastLocation ); } } else { attributesValues = ""; } AttributeProperty theDataGridAttributeInfo = new AttributeProperty(TagString(attribute.GroupNumber,attribute.ElementNumber), attributeName, attribute.VR.ToString(), attribute.VM.ToString(), attributesValues, attribute); _FMIForDataGrid.Add(theDataGridAttributeInfo); } //Pass the DICOM Editor object for updating FMI grid AttributeProperty attrProperty = new AttributeProperty(this); }
private void removeChildToolStripMenuItem1_Click(object sender, EventArgs e) { selectedAttributeSet = findParentAttribute(lblParentStockCode.Text); if (selectedAttributeSet == null) { MessageBox.Show("Please select a parent first"); return; } string sku = dgvItems.Rows[selectedRowIndex].Cells["code"].Value.ToString(); if (sku == selectedAttributeSet.stockCode) { //this is a parent - get confirmation as this action is destructive if (MessageBox.Show("Are you sure you wish to delete this parent and all child properties? This action cannot be undone", "Confirmation", MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes) { return; } try { attrMethods.deleteFullAttributeSet(selectedAttributeSet); } catch (Exception ee) { MessageBox.Show(ee.Message); return; } //clears the currently highlighted children foreach (AttributeProperty props in selectedAttributeSet.childrenProperties) { foreach (DataGridViewRow row in dgvItems.Rows) { if ((row.Cells["code"].Value.ToString() == props.stockCode && row.DefaultCellStyle.BackColor == Color.Aquamarine) || row.Cells["code"].Value.ToString() == selectedAttributeSet.stockCode) { row.DefaultCellStyle.BackColor = Color.White; } } } //remove the parent out of the collection fullAttributeSets.Remove(selectedAttributeSet); selectedAttributeSet = new AttributePropertyParent(); } else { //this is a parent - get confirmation as this action is destructive if (MessageBox.Show("Are you sure you wish to delete this child properties? This action cannot be undone", "Confirmation", MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes) { return; } AttributeProperty childProperty = findChildAttribute(sku); selectedAttributeSet.childrenProperties.Remove(childProperty); if (childProperty.propertyID != null) { attrMethods.deleteChildProperties(childProperty); } dgvItems.Rows[selectedRowIndex].DefaultCellStyle.BackColor = Color.White; } }
private void dataGridAttributes_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { DataGridView.HitTestInfo theHitTestInfo; // Find out what part of the data grid is below the mouse pointer. theHitTestInfo = dataGridAttributes.HitTest(e.X, e.Y); switch (theHitTestInfo.Type) { case DataGridViewHitTestType.Cell: { menuItem_CopyItem.Visible = false; menuItem_CopyAttribute.Visible = false; menuItem_DeleteAttribute.Visible = false; menuItem_AddNewAttribute.Visible = false; menuItem_PasteItem.Visible = false; menuItem_PasteAttributes.Visible = false; menuItem_InsertAbove.Visible = false; menuItem_InsertBelow.Visible = false; menuItem_AddNewAttribute.Text = "Add New Attribute"; menuItem_DeleteAttribute.Text = "Delete Attribute"; selectedRow = theHitTestInfo.RowIndex; if (_AttributesInfoForDataGrid.Count != 0) { theSelectedAttributeProperty = (AttributeProperty)_AttributesInfoForDataGrid[theHitTestInfo.RowIndex]; string tagString = GetHLITagString(theSelectedAttributeProperty.AttributeTag); if (theHitTestInfo.ColumnIndex == 4) { if ((tagString == "0x00041200") || (tagString == "0x00041202") || (tagString == "0x00041400") || (tagString == "0x00041410") || (tagString == "0x00041420") || (tagString == "0x00041430")) { dataGridAttributes.CurrentCell.ReadOnly = true; dataGridAttributes.CurrentCell.ToolTipText = "This attribute value can't be modified."; menuItem_CopyItem.Visible = false; menuItem_CopyAttribute.Visible = false; menuItem_InsertAbove.Visible = false; menuItem_InsertBelow.Visible = false; menuItem_DeleteAttribute.Visible = false; menuItem_AddNewAttribute.Visible = true; menuItem_PasteAttributes.Visible = false; string msg = "This attribute value can't be modified.\n"; richTextBoxLog.AppendText(msg); } else { if (_IsDICOMDIR) { if (backgroundWorkerEditor.IsBusy) richTextBoxLog.AppendText("Reading of reference files dataset is in progress in background...\n"); } } } //dataGridAttributes.CurrentRow.Selected = true; if (!_IsDICOMDIR) { // Check for BEGIN ITEM & END ITEM rows if ((theSelectedAttributeProperty.AttributeTag.IndexOf("BEGIN") == -1) && (theSelectedAttributeProperty.AttributeTag.IndexOf("END") == -1)) { menuItem_AddNewAttribute.Visible = true; menuItem_DeleteAttribute.Visible = true; menuItem_CopyAttribute.Visible = true; if (copyAttributes != null) menuItem_PasteAttributes.Visible = true; else menuItem_PasteAttributes.Visible = false; menuItem_CopyItem.Visible = false; menuItem_InsertAbove.Visible = false; menuItem_InsertBelow.Visible = false; } else { menuItem_AddNewAttribute.Visible = true; menuItem_CopyItem.Visible = true; menuItem_CopyAttribute.Visible = false; menuItem_PasteAttributes.Visible = false; if (copySequenceItemBuffer != null) { menuItem_InsertAbove.Visible = true; menuItem_InsertBelow.Visible = true; } menuItem_DeleteAttribute.Visible = true; menuItem_DeleteAttribute.Text = "Delete Sequence Item"; } //Check for Sequence attribute if (theSelectedAttributeProperty.AttributeVR == "SQ") { menuItem_AddNewAttribute.Visible = true; menuItem_AddNewAttribute.Text = "Add Sequence Item"; if (copySequenceItemBuffer != null) menuItem_PasteItem.Visible = true; else menuItem_PasteItem.Visible = false; } //Check for attributes in a sequence item if (theSelectedAttributeProperty.AttributeTag.StartsWith(">") && (theSelectedAttributeProperty.AttributeTag.IndexOf("BEGIN") == -1)) { menuItem_AddNewAttribute.Visible = false; } } if (dataGridAttributes.SelectedRows.Count > 1) { menuItem_AddNewAttribute.Visible = false; menuItem_DeleteAttribute.Visible = true; menuItem_CopyItem.Visible = false; menuItem_CopyAttribute.Visible = true; if (copyAttributes != null) menuItem_PasteAttributes.Visible = true; else menuItem_PasteAttributes.Visible = false; menuItem_DeleteAttribute.Text = "Delete Selected Attributes"; } } break; } } }
//Shunting yard algorithm public static double ProcessEquation(string equation, AttributeProperty property, int level, int previousLevel, float previousAnswer) { if (equation.Equals("")) { throw new ArgumentException("Equation is empty."); } List <string> result = new List <string>(Regex.Split(equation.ToLower().Trim())); for (int i = result.Count - 1; i >= 0; i--) { if (result[i].Equals("") || result[i].Equals(" ")) { result.RemoveAt(i); } } Queue <string> queue = new Queue <string>(); Stack <string> stack = new Stack <string>(); for (int i = 0; i < result.Count; i++) { if (result[i].Equals("x") || result[i].Equals("X")) { result[i] = level.ToString(); } else if (result[i].Equals("k") || result[i].Equals("K")) { if (previousLevel > 0) { result[i] = previousLevel.ToString(); } else { result[i] = "0"; } } else if (result[i].Equals("p") || result[i].Equals("P")) { result[i] = previousAnswer.ToString(); } else if (result[i].Equals("r") || result[i].Equals("R")) { float value = UnityEngine.Random.Range(1f, 1000f); value /= 1000f; result[i] = value.ToString(); } } TokenClass previousTokenClass = TokenClass.Value; for (int i = 0; i < result.Count; i++) { string element = result[i]; if (element.Equals("y") || element.Equals("=")) { continue; } TokenClass tokenClass = GetTokenClass(element); switch (tokenClass) { case TokenClass.Value: queue.Enqueue(element); break; case TokenClass.LeftParentheses: stack.Push(element); break; case TokenClass.RightParentheses: while (!stack.Peek().Equals("(")) { queue.Enqueue(stack.Pop()); } stack.Pop(); break; case TokenClass.Operator: if (element.Equals("-") && (previousTokenClass == TokenClass.Operator || previousTokenClass == TokenClass.LeftParentheses) && (stack.Count == 0 || result[i - 1].Equals("("))) { //Push unary operator "Negative" to stack. stack.Push("NEG"); break; } if (element.Equals("-") && (i + 1 < result.Count) && GetTokenClass(result[i + 1]) == TokenClass.Value) { if (previousTokenClass == TokenClass.Value) { stack.Push(element); } else { stack.Push("NEG"); } break; } if (stack.Count > 0) { string stackTopToken = stack.Peek(); if (GetTokenClass(stackTopToken) == TokenClass.Operator) { Associativity tokenAssociativity = GetAssociativity(stackTopToken); int tokenPrecedence = GetPrecedence(element); int stackTopPrecedence = GetPrecedence(stackTopToken); if ((tokenAssociativity == Associativity.Left && tokenPrecedence <= stackTopPrecedence) || (tokenAssociativity == Associativity.Right && tokenPrecedence < stackTopPrecedence)) { queue.Enqueue(stack.Pop()); } } } stack.Push(element); break; } if (tokenClass == TokenClass.Value || tokenClass == TokenClass.RightParentheses) { if (i < result.Count - 1) { string nextToken = result[i + 1]; TokenClass nextTokenClass = GetTokenClass(nextToken); if (nextTokenClass != TokenClass.Operator && nextTokenClass != TokenClass.RightParentheses) { result.Insert(i + 1, "*"); } } } previousTokenClass = tokenClass; } while (stack.Count > 0) { string operand = stack.Pop(); if (operand.Equals("(") || operand.Equals(")")) { throw new ArgumentException("Mismatched parentheses."); } queue.Enqueue(operand); } Stack <string> expressionStack = new Stack <string>(); while (queue.Count > 0) { string token = queue.Dequeue(); TokenClass tokenClass = GetTokenClass(token); if (tokenClass == TokenClass.Value) { expressionStack.Push(token); } else { double answer = 0f; if (tokenClass == TokenClass.Operator) { string rightOperand = expressionStack.Pop(); string leftOperand = expressionStack.Pop(); if (token.Equals("+")) { answer = double.Parse(leftOperand); answer += double.Parse(rightOperand); } else if (token.Equals("-")) { answer = double.Parse(leftOperand); answer -= double.Parse(rightOperand); } else if (token.Equals("*")) { answer = double.Parse(leftOperand); answer *= double.Parse(rightOperand); } else if (token.Equals("/")) { answer = double.Parse(leftOperand); answer /= double.Parse(rightOperand); } else if (token.Equals("^")) { double baseValue = double.Parse(leftOperand); double exponent = double.Parse(rightOperand); answer = Math.Pow(baseValue, exponent); } } else if (tokenClass == TokenClass.Negative) { string operand = expressionStack.Pop(); answer = double.Parse(operand) * -1f; } expressionStack.Push(answer.ToString()); } } if (expressionStack.Count != 1) { throw new ArgumentException("Invalid equation."); } double finalAnswer = double.Parse(expressionStack.Pop()); return(finalAnswer); }
private void DumpAttributeProperty(AttributeProperty attributeProperty) { textWriter.Write("{0} = ", SafeName(attributeProperty.Name)); DumpDynamic(attributeProperty.Value); }
public void ChangeProperty() { this.newProperty = ProcessToggle(); }