//mxd private static bool SetPairedUDMFFieldsLabel(UniFields fields, string paramX, string paramY, double defaultvalue, Label namelabel, Label valuelabel, bool highlight) { double x = UniFields.GetFloat(fields, paramX, defaultvalue); double y = UniFields.GetFloat(fields, paramY, defaultvalue); if (fields.ContainsKey(paramX)) { x = (double)fields[paramX].Value; } if (fields.ContainsKey(paramY)) { y = (double)fields[paramY].Value; } if (x != defaultvalue || y != defaultvalue) { valuelabel.Text = x.ToString(CultureInfo.InvariantCulture) + ", " + y.ToString(CultureInfo.InvariantCulture); valuelabel.Enabled = true; namelabel.Enabled = true; return(true); } else { valuelabel.Text = "--, --"; valuelabel.Enabled = highlight; namelabel.Enabled = highlight; return(false); } }
//comment private void SetComment(string comment) { UniFields fields = GetFields(); if (comment.Length == 0) { if (fields.ContainsKey("comment")) { General.Map.UndoRedo.CreateUndo("Remove comment"); fields.BeforeFieldsChange(); fields.Remove("comment"); } return; } //create undo stuff General.Map.UndoRedo.CreateUndo("Set comment"); fields.BeforeFieldsChange(); if (!fields.ContainsKey("comment")) { fields.Add("comment", new UniValue((int)UniversalType.String, comment)); } else { fields["comment"].Value = comment; } }
protected void Apply(UniFields other, string key) { if (uifields.ContainsKey(key)) { other[key] = new UniValue(uifields[key]); } else if (other.ContainsKey(key)) { other.Remove(key); } }
//mxd public void ApplyUserVars(Dictionary <string, UniversalType> vars, UniFields tofields) { // Apply user variables when target map element contains user var definition and the value is not default foreach (DataGridViewRow row in fieldslist.Rows) { // Row is a field? if (row is FieldsEditorRow) { FieldsEditorRow frow = row as FieldsEditorRow; if (frow.RowType != FieldsEditorRowType.USERVAR || !vars.ContainsKey(frow.Name)) { continue; } object oldvalue = (tofields.ContainsKey(frow.Name) ? tofields[frow.Name].Value : null); object newvalue = frow.GetResult(oldvalue); // Skip field when mixed values if (newvalue == null) { continue; } // Remove field if (newvalue.Equals(frow.TypeHandler.GetDefaultValue())) { if (tofields.ContainsKey(frow.Name)) { tofields.Remove(frow.Name); } } // Add field else if (!newvalue.Equals(oldvalue)) { tofields[frow.Name] = new UniValue(frow.TypeHandler.Index, newvalue); } } } }
private string GetComment() { UniFields fields = GetFields(); if (fields == null) { return(""); } if (!fields.ContainsKey("comment")) { return(""); } return(fields["comment"].Value.ToString()); }
// This applies the current fields to a UniFields object public void Apply(UniFields tofields) { tofields.BeforeFieldsChange(); // Go for all the fields UniFields tempfields = new UniFields(tofields); foreach (KeyValuePair <string, UniValue> f in tempfields) { if (uifields.ContainsKey(f.Key)) { continue; //mxd } // Go for all rows bool foundrow = false; bool skiprow = false; //mxd foreach (DataGridViewRow row in fieldslist.Rows) { // Row is a field and matches field name? if ((row is FieldsEditorRow) && (row.Cells[0].Value.ToString() == f.Key)) { FieldsEditorRow frow = row as FieldsEditorRow; //mxd. User vars are stored separately if (frow.RowType == FieldsEditorRowType.USERVAR) { skiprow = true; break; } // Field is defined? if (frow.IsDefined) { foundrow = true; break; } } } //mxd. User vars are stored separately if (skiprow) { continue; } // No such row? if (!foundrow) { // Remove the definition from the fields tofields.Remove(f.Key); } } // Go for all rows foreach (DataGridViewRow row in fieldslist.Rows) { // Row is a field? if (row is FieldsEditorRow) { FieldsEditorRow frow = row as FieldsEditorRow; // Field is defined and not empty? if (frow.RowType != FieldsEditorRowType.USERVAR && frow.IsDefined && !frow.IsEmpty) { // Apply field object oldvalue = null; if (tofields.ContainsKey(frow.Name)) { oldvalue = tofields[frow.Name].Value; } tofields[frow.Name] = new UniValue(frow.TypeHandler.Index, frow.GetResult(oldvalue)); // Custom row? if (frow.RowType == FieldsEditorRowType.DYNAMIC) { // Write type to map configuration General.Map.Options.SetUniversalFieldType(elementname, frow.Name, frow.TypeHandler.Index); } } } } }
//mxd public void SetUserVars(Dictionary <string, UniversalType> vars, UniFields fromfields, bool first) { foreach (KeyValuePair <string, UniversalType> group in vars) { // Go for all rows bool foundrow = false; TypeHandler vartype = General.Types.GetFieldHandler((int)group.Value, 0); object value = fromfields.ContainsKey(group.Key) ? fromfields[group.Key].Value : vartype.GetDefaultValue(); foreach (DataGridViewRow row in fieldslist.Rows) { // Row is a field? if (row is FieldsEditorRow) { FieldsEditorRow frow = row as FieldsEditorRow; // Row name matches with user var? if (frow.RowType == FieldsEditorRowType.USERVAR && frow.Name == group.Key) { // First time? if (first) { frow.Define(value); } // Check if the value is different else if (!frow.TypeHandler.GetValue().Equals(value)) { // Clear the value in the row frow.Define(value); frow.Clear(); } // Done foundrow = true; break; } } } // Row not found? if (!foundrow) { // Make new row object defaultvalue = vartype.GetDefaultValue(); FieldsEditorRow frow = new FieldsEditorRow(fieldslist, group.Key, (int)group.Value, defaultvalue, true); if (!value.Equals(defaultvalue)) { frow.Define(value); } fieldslist.Rows.Insert(fieldslist.Rows.Count - 1, frow); } } // Now check for rows that the givens fields do NOT have foreach (DataGridViewRow row in fieldslist.Rows) { // Row is a field? if (row is FieldsEditorRow) { FieldsEditorRow frow = row as FieldsEditorRow; // Don't undefine user var rows defined by other actor types if (frow.RowType == FieldsEditorRowType.USERVAR || vars.ContainsKey(frow.Name)) { continue; } // Is this row defined previously? if (frow.IsDefined) { // Check if this row can not be found in the fields at all if (!fromfields.ContainsKey(frow.Name)) { // It is not defined in these fields, undefine the value frow.Undefine(); } } } } // Sort fields Sort(); }
// This sets up the fields and values from a UniFields object // When first is true, the values are applied unconditionally // When first is false, the values in the grid are erased when // they differ from the given values (for multiselection) public void SetValues(UniFields fromfields, bool first) { // Go for all the fields foreach (KeyValuePair <string, UniValue> f in fromfields) { if (uifields.ContainsKey(f.Key)) { continue; //mxd } // Go for all rows bool foundrow = false; bool skiprow = false; //mxd foreach (DataGridViewRow row in fieldslist.Rows) { // Row is a field? if (row is FieldsEditorRow) { FieldsEditorRow frow = row as FieldsEditorRow; // Row name matches with field if (frow.Name == f.Key) { //mxd. User vars are set separately if (frow.RowType == FieldsEditorRowType.USERVAR) { skiprow = true; break; } // First time? if (first) { // Set type when row is not fixed if (frow.RowType == FieldsEditorRowType.DYNAMIC) { frow.ChangeType(f.Value.Type); } // Apply value of field to row frow.Define(f.Value.Value); } else { // Check if the value is different if (!frow.TypeHandler.GetValue().Equals(f.Value.Value)) { // Clear the value in the row frow.Define(f.Value.Value); frow.Clear(); } } // Done foundrow = true; break; } } } //mxd. User vars are set separately if (skiprow) { continue; } // Row not found? if (!foundrow) { // Make new row FieldsEditorRow frow = new FieldsEditorRow(fieldslist, f.Key, f.Value.Type, f.Value.Value, false); fieldslist.Rows.Insert(fieldslist.Rows.Count - 1, frow); // When not the first, clear the field because the others did not define this one if (!first) { frow.Clear(); } } } // Now check for rows that the givens fields do NOT have foreach (DataGridViewRow row in fieldslist.Rows) { // Row is a field? if (row is FieldsEditorRow) { FieldsEditorRow frow = row as FieldsEditorRow; // Is this row defined previously? if (frow.IsDefined) { // Check if this row can not be found in the fields at all if (!fromfields.ContainsKey(frow.Name)) { // It is not defined in these fields, clear the value frow.Clear(); } } } } // Sort fields Sort(); }