public List <Subtype> GetSubtypes() { // Create Subtype List List <Subtype> subtypes = new List <Subtype>(); // Get Model if (base.Container == null) { return(subtypes); } EsriModel model = (EsriModel)base.Container; // Get Navigator Navigate navigate = model.Navigate; navigate.Start = this; // Get Child Subtypes Elements elements = navigate.Children(1); foreach (Element element in elements.Values) { if (element is Subtype) { Subtype subtype = (Subtype)element; subtypes.Add(subtype); } } // Return Subtypes return(subtypes); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (context == null) { return(null); } if (context.Instance == null) { return(null); } if (value.GetType() == typeof(string)) { string text = Convert.ToString(value); // "" or "(None)" if (text == string.Empty || text == Resources.TEXT_NONE_BR) { if (context.PropertyDescriptor.ComponentType == typeof(TopologyRule)) { TopologyRule topologyRule = (TopologyRule)context.Instance; switch (context.PropertyDescriptor.Name) { case "OriginSubtype": return(topologyRule.AllOriginSubtypes ? 0 : -1); case "DestinationSubtype": return(topologyRule.AllDestinationSubtypes ? 0 : -1); default: return(-1); } } return(-1); } // "(Class)" if (text == Resources.TEXT_CLASS_BR) { return(0); } // Subtype Name ObjectClass objectClass = this.GetObjectClass(context); if (objectClass == null) { return(-1); } Subtype subtype = objectClass.FindSubtype(text); if (subtype == null) { return(-1); } return(subtype.SubtypeCode); } return(base.ConvertFrom(context, culture, value)); }
public Subtype(Subtype prototype) : base(prototype) { this._subtypeName = prototype.SubtypeName; this._subtypeCode = prototype.SubtypeCode; this._default = prototype.Default; // Refresh this.Refresh(); }
public int CompareTo(object obj) { if (!(obj is Subtype)) { throw new ArgumentException("object is not a Domain"); } Subtype subtype = (Subtype)obj; return(this._subtypeName.CompareTo(subtype.SubtypeName)); }
public Subtype FindSubtype(string name) { Subtype subtype = null; List <Subtype> subtypes = this.GetSubtypes(); foreach (Subtype subtypeTest in subtypes) { if (subtypeTest.SubtypeName == name) { subtype = subtypeTest; break; } } return(subtype); }
public Subtype FindSubtype(int code) { Subtype subtype = null; List <Subtype> subtypes = this.GetSubtypes(); foreach (Subtype subtypeTest in subtypes) { if (subtypeTest.SubtypeCode == code) { subtype = subtypeTest; break; } } return(subtype); }
private void AddSubtypes(ObjectClass objectClass, IXPathNavigable path) { // Get Navigator XPathNavigator navigator = path.CreateNavigator(); // Check if Subtypes Exist XPathNavigator navigatorSubtypeField = navigator.SelectSingleNode("SubtypeFieldName"); if (navigatorSubtypeField != null) { // Get Default Subtype XPathNavigator navigatorDefaultSubtypeCode = navigator.SelectSingleNode("DefaultSubtypeCode"); // Get Subtypes XPathNodeIterator iteratorSubtype = navigator.Select("Subtypes/Subtype"); // Loop for each Subtype while (iteratorSubtype.MoveNext()) { // Create Subtype XPathNavigator navigatorSubtype = iteratorSubtype.Current; Subtype subtype = new Subtype(navigatorSubtype); // Update Default Subtype Property subtype.Default = (subtype.SubtypeCode == navigatorDefaultSubtypeCode.ValueAsInt); // Add Subtype to Model this.Shapes.Add(this.Shapes.CreateKey(), subtype); // Add Link From ObjectClass to Subtype Link link = new Link(objectClass, subtype); link.BorderColor = ModelSettings.Default.EnabledLines; link.BorderStyle = DashStyle.Solid; link.BorderWidth = 1f; link.End.Marker.BorderColor = ModelSettings.Default.EnabledLines; this.Lines.Add(this.Lines.CreateKey(), link); } } }
private void Model_ElementInvalid(object sender, ElementEventArgs e) { // Check Relationship if (this._relationshipClass == null) { return; } // Get Element Element element = e.Value; if (element == null) { return; } EsriLine <RelationshipRule> line = element as EsriLine <RelationshipRule>; if (line == null) { return; } // Get Rule RelationshipRule rule = line.Parent; // Suspend Rule Events rule.Suspend(); // Element elementStart = line.Start.Shape; Element elementEnd = line.End.Shape; // Update Origin Class/Subtype if (elementStart == null) { rule.OriginClass = -1; rule.OriginSubtype = -1; } else if (elementStart is EsriShape <ObjectClass> ) { EsriShape <ObjectClass> shape = (EsriShape <ObjectClass>)elementStart; ObjectClass objectClass = shape.Parent; rule.OriginClass = objectClass.DSID; rule.OriginSubtype = 0; } else if (elementStart is EsriShape <FeatureClass> ) { EsriShape <FeatureClass> shape = (EsriShape <FeatureClass>)elementStart; FeatureClass featureClass = shape.Parent; rule.OriginClass = featureClass.DSID; rule.OriginSubtype = 0; } else if (elementStart is EsriShape <Subtype> ) { EsriShape <Subtype> shape = (EsriShape <Subtype>)elementStart; Subtype subtype = shape.Parent; ObjectClass objectClass = subtype.GetParent(); if (objectClass != null) { rule.OriginClass = objectClass.DSID; rule.OriginSubtype = subtype.SubtypeCode; } } // Update Destination Class/Subtype if (elementEnd == null) { rule.DestinationClass = -1; rule.DestinationSubtype = -1; } else if (elementEnd is EsriShape <ObjectClass> ) { EsriShape <ObjectClass> shape = (EsriShape <ObjectClass>)elementEnd; ObjectClass objectClass = shape.Parent; rule.DestinationClass = objectClass.DSID; rule.DestinationSubtype = 0; } else if (elementEnd is EsriShape <FeatureClass> ) { EsriShape <FeatureClass> shape = (EsriShape <FeatureClass>)elementEnd; FeatureClass featureClass = shape.Parent; rule.DestinationClass = featureClass.DSID; rule.DestinationSubtype = 0; } else if (elementEnd is EsriShape <Subtype> ) { EsriShape <Subtype> shape = (EsriShape <Subtype>)elementEnd; Subtype subtype = shape.Parent; ObjectClass objectClass = subtype.GetParent(); if (objectClass != null) { rule.DestinationClass = objectClass.DSID; rule.DestinationSubtype = subtype.SubtypeCode; } } // Resume Rule Events rule.Resume(); }
public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { if (context == null) { return(null); } if (context.Instance == null) { return(null); } // FeatureClass::ShapeFieldName, AreaFieldName, LengthFieldName, ShapeFieldName // GeometricNetworkControllerMembership::EnabledFieldName, AncillaryRoleFieldName // IndexField::Name // ObjectClass::OIDFieldName, GlobalIDFieldName, RasterFieldName, SubtypeFieldName, OIDFieldName, GlobalIDFieldName // RelationshipClass::OriginPrimary, OriginForeign, DestinationPrimary, DestinationForeign // SubtypeField::FieldName // NetWeightAssociation::FieldName // TerrainDataSource::HeightField, TagValueField // Create List List <string> list = new List <string>(); DiagrammerEnvironment diagrammerEnvironment = DiagrammerEnvironment.Default; SchemaModel schemaModel = diagrammerEnvironment.SchemaModel; if (context.PropertyDescriptor.ComponentType == typeof(IndexField)) { IndexField indexField = (IndexField)context.Instance; ObjectClass objectClass = (ObjectClass)indexField.Table; foreach (Field field in objectClass.GetFields()) { list.Add(field.Name); } } else if (context.PropertyDescriptor.ComponentType == typeof(GeometricNetworkControllerMembership)) { GeometricNetworkControllerMembership geometricNetworkControllerMembership = (GeometricNetworkControllerMembership)context.Instance; ObjectClass objectClass = schemaModel.FindParent(geometricNetworkControllerMembership); foreach (Field field in objectClass.GetFields()) { list.Add(field.Name); } } else if (context.PropertyDescriptor.ComponentType == typeof(SubtypeField)) { SubtypeField subtypeField = (SubtypeField)context.Instance; Subtype subtype = (Subtype)subtypeField.Table; ObjectClass objectClass = subtype.GetParent(); foreach (Field field in objectClass.GetFields()) { list.Add(field.Name); } } else if (context.PropertyDescriptor.ComponentType == typeof(ObjectClass)) { ObjectClass objectClass = (ObjectClass)context.Instance; foreach (Field field in objectClass.GetFields()) { list.Add(field.Name); } } else if (context.PropertyDescriptor.ComponentType == typeof(RelationshipClass)) { RelationshipClass relationshipClass = (RelationshipClass)context.Instance; if (relationshipClass.IsAttributed) { switch (context.PropertyDescriptor.Name) { case "OIDFieldName": case "GlobalIDFieldName": case "RasterFieldName": case "SubtypeFieldName": foreach (Field field in relationshipClass.GetFields()) { list.Add(field.Name); } break; case "OriginPrimary": ObjectClass objectClass1 = schemaModel.FindObjectClass(relationshipClass.OriginClassName); foreach (Field field in objectClass1.GetFields()) { list.Add(field.Name); } break; case "OriginForeign": case "DestinationForeign": foreach (Field field in relationshipClass.GetFields()) { list.Add(field.Name); } break; case "DestinationPrimary": ObjectClass objectClass2 = schemaModel.FindObjectClass(relationshipClass.DestinationClassName); foreach (Field field in objectClass2.GetFields()) { list.Add(field.Name); } break; } } else { switch (context.PropertyDescriptor.Name) { case "OIDFieldName": case "GlobalIDFieldName": case "RasterFieldName": case "SubtypeFieldName": foreach (Field field in relationshipClass.GetFields()) { list.Add(field.Name); } break; case "OriginPrimary": ObjectClass objectClass1 = schemaModel.FindObjectClass(relationshipClass.OriginClassName); foreach (Field field in objectClass1.GetFields()) { list.Add(field.Name); } break; case "OriginForeign": ObjectClass objectClass2 = schemaModel.FindObjectClass(relationshipClass.DestinationClassName); foreach (Field field in objectClass2.GetFields()) { list.Add(field.Name); } break; case "DestinationPrimary": case "DestinationForeign": break; } } } else if ( context.PropertyDescriptor.ComponentType == typeof(FeatureClass) || context.PropertyDescriptor.ComponentType == typeof(RasterCatalog)) { FeatureClass featureClass = (FeatureClass)context.Instance; foreach (Field field in featureClass.GetFields()) { list.Add(field.Name); } } else if (context.PropertyDescriptor.ComponentType == typeof(NetWeightAssociation)) { NetWeightAssociation netWeightAssociation = (NetWeightAssociation)context.Instance; if (netWeightAssociation != null) { if (!string.IsNullOrEmpty(netWeightAssociation.TableName)) { ObjectClass objectClass = schemaModel.FindObjectClass(netWeightAssociation.TableName); if (objectClass != null) { foreach (Field field in objectClass.GetFields()) { list.Add(field.Name); } } } } } else if (context.PropertyDescriptor.ComponentType == typeof(TerrainDataSource)) { TerrainDataSource terrainDataSource = (TerrainDataSource)context.Instance; if (terrainDataSource != null) { if (!string.IsNullOrEmpty(terrainDataSource.FeatureClassName)) { ObjectClass objectClass = schemaModel.FindObjectClass(terrainDataSource.FeatureClassName); if (objectClass != null) { foreach (Field field in objectClass.GetFields()) { list.Add(field.Name); } } } } } // Sort field name list and insert "None" item list.Sort(); list.Insert(0, Resources.TEXT_NONE_BR); // Return sort field name list StandardValuesCollection svc = new StandardValuesCollection(list); return(svc); }
public override void Errors(List <Error> list) { // Field Name Null or Empty if (string.IsNullOrEmpty(this._fieldName)) { list.Add(new ErrorTableRow(this, "Subtype Field names cannot be empty", ErrorType.Error)); } // Get DiagrammerEnvironment Singleton DiagrammerEnvironment diagrammerEnvironment = DiagrammerEnvironment.Default; SchemaModel schemaModel = diagrammerEnvironment.SchemaModel; // Get Subtype Subtype subtype = (Subtype)this.Table; // Get ObjectClass ObjectClass objectClass = subtype.GetParent(); if (objectClass == null) { // This error is handled by the Subtype class return; } // Get Field Field field = objectClass.FindField(this._fieldName); if (field == null) { // Field is missing in parent ObjectClass string message = string.Format("The subtype field [{0}] does not exist in the parent objectclass", this._fieldName); list.Add(new ErrorTableRow(this, message, ErrorType.Error)); return; } // Warning if parent default value and domain are identical if (this._defaultValue == field.DefaultValue && this._domainName == field.Domain) { string message = string.Format("The default values and domain for the subtype field [{0}] are identical to those in the parent objectclass", this._fieldName); list.Add(new ErrorTableRow(this, message, ErrorType.Warning)); } // Field can only be small int, long in, single, double, text, date, guid switch (field.FieldType) { case esriFieldType.esriFieldTypeDate: case esriFieldType.esriFieldTypeDouble: case esriFieldType.esriFieldTypeGUID: case esriFieldType.esriFieldTypeInteger: case esriFieldType.esriFieldTypeSingle: case esriFieldType.esriFieldTypeSmallInteger: case esriFieldType.esriFieldTypeString: // OK break; case esriFieldType.esriFieldTypeRaster: case esriFieldType.esriFieldTypeBlob: case esriFieldType.esriFieldTypeGeometry: case esriFieldType.esriFieldTypeOID: case esriFieldType.esriFieldTypeGlobalID: case esriFieldType.esriFieldTypeXML: string message = string.Format("The subtype field [{0}] must use a field of type Date, Double, Guid, Integer, Single, SmallInteger or String", this._fieldName); list.Add(new ErrorTableRow(this, message, ErrorType.Error)); break; } // Find Domain if (!string.IsNullOrEmpty(this._domainName)) { // Get Domain Domain domain = schemaModel.FindDomain(this._domainName); if (domain == null) { // Domain does not exit string message = string.Format("The domain [{0}] for field [{1}] does not exist", this._domainName, field.Name); list.Add(new ErrorTableRow(this, message, ErrorType.Error)); } else { // Compare domain and field types if (field.FieldType != domain.FieldType) { string message = string.Format("The field [{0}] and assigned domain [{1}] do not have matching field types.", field.Name, this._domainName); list.Add(new ErrorTableRow(this, message, ErrorType.Error)); } // Check Default Value ( if (!string.IsNullOrEmpty(this._defaultValue)) { string message = null; if (!domain.IsValid(this._defaultValue, out message)) { list.Add(new ErrorTableRow(this, message, ErrorType.Warning)); } } // Check if a domain value is too long for the text field if (field.FieldType == esriFieldType.esriFieldTypeString && domain.FieldType == esriFieldType.esriFieldTypeString && domain.GetType() == typeof(DomainCodedValue)) { DomainCodedValue domain2 = (DomainCodedValue)domain; foreach (DomainCodedValueRow x in domain2.CodedValues) { if (string.IsNullOrEmpty(x.Code)) { continue; } if (x.Code.Length > field.Length) { string message = string.Format("The domain [{0}] has a value [{1}] that is too long for the field [{2}]", this._domainName, x, this._fieldName); list.Add(new ErrorTableRow(this, message, ErrorType.Error)); } } } } } // Check validity of default value against field type if (!string.IsNullOrEmpty(this._defaultValue)) { string message; if (!GeodatabaseUtility.IsValidateValue(field.FieldType, this._defaultValue, out message)) { string message2 = string.Format("Default value [{0}] {1}", this._defaultValue, message); list.Add(new ErrorTableRow(this, message2, ErrorType.Error)); } } // if (!string.IsNullOrEmpty(this._defaultValue)) { if (!string.IsNullOrEmpty(this._domainName)) { if (!string.IsNullOrEmpty(field.Domain)) { if (this._domainName != field.Domain) { Domain domain2 = schemaModel.FindDomain(field.Domain); string message = null; if (!domain2.IsValid(this._defaultValue, out message)) { string message2 = string.Format("NIM013605: Field [{0}] - {1}", this._fieldName, message); list.Add(new ErrorTableRow(this, message2, ErrorType.Error)); } } } } } }
protected override void WriteInnerXml(XmlWriter writer) { base.WriteInnerXml(writer); // Get Model Subtype subtype = (Subtype)this.Table; ObjectClass objectClass = subtype.GetParent(); // <FieldName></FieldName> writer.WriteStartElement("FieldName"); writer.WriteValue(this._fieldName); writer.WriteEndElement(); if (!string.IsNullOrEmpty(this._domainName)) { // <DomainName></DomainName> writer.WriteStartElement("DomainName"); writer.WriteValue(this._domainName); writer.WriteEndElement(); } // Get Field Field field = objectClass.FindField(this._fieldName); // if (!string.IsNullOrEmpty(this._defaultValue)) { // Get correct data type value string dataType = string.Empty; switch (field.FieldType) { case esriFieldType.esriFieldTypeSmallInteger: dataType = "xs:short"; break; case esriFieldType.esriFieldTypeInteger: dataType = "xs:int"; break; case esriFieldType.esriFieldTypeSingle: dataType = "xs:float"; break; case esriFieldType.esriFieldTypeDouble: dataType = "xs:double"; break; case esriFieldType.esriFieldTypeString: dataType = "xs:string"; break; case esriFieldType.esriFieldTypeDate: dataType = "xs:dateTime"; break; } // <DefaultValue></DefaultValue> writer.WriteStartElement("DefaultValue"); writer.WriteAttributeString(Xml._XSI, Xml._TYPE, null, dataType); writer.WriteValue(this._defaultValue); writer.WriteEndElement(); } }
// // CONSTRUCTOR // public EsriShape(T parent) : base() { this._parent = parent; // this.SuspendEvents = true; // Get a stencil containing some basic shapes BasicStencil stencil = (BasicStencil)Crainiate.ERM4.Component.Instance.GetStencil(typeof(BasicStencil)); this.BorderWidth = 2f; this.Size = new Size(100, 40); this.SmoothingMode = SmoothingMode.HighQuality; this.StencilItem = stencil[BasicStencilType.RoundedRectangle]; this.Label = new TextLabel(); this.Label.Color = ModelSettings.Default.TextColor; if (typeof(T) == typeof(DomainCodedValue)) { DomainCodedValue domainCodedValue = this._parent as DomainCodedValue; this.BorderColor = ColorSettings.Default.CodedValueDomainColor; this.GradientColor = ColorSettings.Default.CodedValueDomainColor; this.Label.Text = domainCodedValue.Name; this.Tooltip = domainCodedValue.Name; } else if (typeof(T) == typeof(DomainRange)) { DomainRange domainRange = this._parent as DomainRange; this.BorderColor = ColorSettings.Default.RangeDomainColor; this.GradientColor = ColorSettings.Default.RangeDomainColor; this.Label.Text = domainRange.Name; this.Tooltip = domainRange.Name; } else if (typeof(T) == typeof(FeatureClass)) { FeatureClass featureClass = this._parent as FeatureClass; this.BorderColor = ColorSettings.Default.FeatureClassColor; this.GradientColor = ColorSettings.Default.FeatureClassColor; this.Label.Text = featureClass.Name; this.Tooltip = featureClass.Name; } else if (typeof(T) == typeof(ObjectClass)) { ObjectClass objectClass = this._parent as ObjectClass; this.BorderColor = ColorSettings.Default.ObjectClassColor; this.GradientColor = ColorSettings.Default.ObjectClassColor; this.Label.Text = objectClass.Name; this.Tooltip = objectClass.Name; } else if (typeof(T) == typeof(RelationshipClass)) { RelationshipClass relationship = this._parent as RelationshipClass; this.BorderColor = ColorSettings.Default.RelationshipColor; this.GradientColor = ColorSettings.Default.RelationshipColor; this.Label.Text = relationship.Name; this.Tooltip = relationship.Name; } else if (typeof(T) == typeof(Subtype)) { Subtype subtype = this._parent as Subtype; this.BorderColor = ColorSettings.Default.SubtypeColor; this.GradientColor = ColorSettings.Default.SubtypeColor; this.Label.Text = subtype.SubtypeName; this.Tooltip = subtype.SubtypeName; } else if (typeof(T) == typeof(Field)) { Field field = this._parent as Field; this.BorderColor = ColorSettings.Default.FieldColor; this.GradientColor = ColorSettings.Default.FieldColor; this.Label.Text = field.Name; this.Tooltip = field.Name; } else if (typeof(T) == typeof(SubtypeField)) { SubtypeField subtypeField = this._parent as SubtypeField; this.BorderColor = ColorSettings.Default.SubtypeFieldColor; this.GradientColor = ColorSettings.Default.SubtypeFieldColor; this.Label.Text = subtypeField.FieldName; this.Tooltip = subtypeField.FieldName; } else if (typeof(T) == typeof(FeatureDataset)) { FeatureDataset featureDataset = this._parent as FeatureDataset; this.BorderColor = ColorSettings.Default.FeatureDatasetColor; this.GradientColor = ColorSettings.Default.FeatureDatasetColor; this.Label.Text = featureDataset.Name; this.Tooltip = featureDataset.Name; } else if (typeof(T) == typeof(GeometricNetwork)) { GeometricNetwork geometricNetwork = this._parent as GeometricNetwork; this.BorderColor = ColorSettings.Default.GeometricNetworkColor; this.GradientColor = ColorSettings.Default.GeometricNetworkColor; this.Label.Text = geometricNetwork.Name; this.Tooltip = geometricNetwork.Name; } else if (typeof(T) == typeof(Network)) { Network network = this._parent as Network; this.BorderColor = ColorSettings.Default.NetworkColor; this.GradientColor = ColorSettings.Default.NetworkColor; this.Label.Text = network.Name; this.Tooltip = network.Name; } else if (typeof(T) == typeof(Topology)) { Topology topology = this._parent as Topology; this.BorderColor = ColorSettings.Default.TopologyColor; this.GradientColor = ColorSettings.Default.TopologyColor; this.Label.Text = topology.Name; this.Tooltip = topology.Name; } else if (typeof(T) == typeof(Terrain)) { Terrain terrain = this._parent as Terrain; this.BorderColor = ColorSettings.Default.TerrainColor; this.GradientColor = ColorSettings.Default.TerrainColor; this.Label.Text = terrain.Name; this.Tooltip = terrain.Name; } // this.SuspendEvents = false; }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (context == null) { return(null); } if (context.Instance == null) { return(null); } if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if (destinationType == typeof(string)) { if (value.GetType() == typeof(int)) { int id = Convert.ToInt32(value); ObjectClass objectClass = this.GetObjectClass(context); if (objectClass == null) { return(Resources.TEXT_NONE_BR); } List <Subtype> subtypes = objectClass.GetSubtypes(); if (subtypes.Count == 0) { if (id == -1) { return(Resources.TEXT_NONE_BR); } return(Resources.TEXT_CLASS_BR); } if (context.PropertyDescriptor.ComponentType == typeof(TopologyRule)) { TopologyRule topologyRule = (TopologyRule)context.Instance; switch (context.PropertyDescriptor.Name) { case "OriginSubtype": if (topologyRule.OriginSubtype == 0 && topologyRule.AllOriginSubtypes) { return(Resources.TEXT_NONE_BR); } break; case "DestinationSubtype": if (topologyRule.DestinationSubtype == 0 && topologyRule.AllDestinationSubtypes) { return(Resources.TEXT_NONE_BR); } break; } } Subtype subtype = objectClass.FindSubtype(id); if (subtype == null) { return(Resources.TEXT_NONE_BR); } return(subtype.SubtypeName); } } return(base.ConvertTo(context, culture, value, destinationType)); }
public override void Errors(List <Error> list) { // Get Base List of Errors base.Errors(list); // Add Field Errors List <Field> fields = this.GetFields(); foreach (Field field in fields) { field.Errors(list); } // Check if Field names duplicated. Domain names are not case sensitive. Dictionary <string, Field> dictionary = new Dictionary <string, Field>(); foreach (Field field in fields) { if (string.IsNullOrEmpty(field.Name)) { continue; } Field f = null; if (dictionary.TryGetValue(field.Name.ToUpper(), out f)) { string message1 = string.Format("Field name '{0}' is duplicated", field.Name); string message2 = string.Format("Field name '{0}' is duplicated", f.Name); list.Add(new ErrorTableRow(field, message1, ErrorType.Error)); list.Add(new ErrorTableRow(f, message2, ErrorType.Error)); } else { dictionary.Add(field.Name.ToUpper(), field); } } // Get Indexes List <Index> indexes = this.GetIndexes(); // Add Index Errors foreach (Index index in indexes) { index.Errors(list); } // Check for duplicate Index Names Dictionary <string, Index> dictionary4 = new Dictionary <string, Index>(); foreach (Index index in indexes) { if (string.IsNullOrEmpty(index.Name)) { continue; } Index i = null; if (dictionary4.TryGetValue(index.Name.ToUpper(), out i)) { string message1 = string.Format("Subtype name '{0}' is duplicated", index.Name); string message2 = string.Format("Subtype name '{0}' is duplicated", i.Name); list.Add(new ErrorTable(this, message1, ErrorType.Error)); list.Add(new ErrorTable(this, message2, ErrorType.Error)); } else { dictionary4.Add(index.Name.ToUpper(), index); } } // Add Subtype Errors List <Subtype> subtypes = this.GetSubtypes(); // Check if Subtype names duplicated. Subtype names are not case sensitive. Dictionary <string, Subtype> dictionary2 = new Dictionary <string, Subtype>(); foreach (Subtype subtype in subtypes) { if (string.IsNullOrEmpty(subtype.SubtypeName)) { continue; } Subtype s = null; if (dictionary2.TryGetValue(subtype.SubtypeName.ToUpper(), out s)) { string message1 = string.Format("Subtype name '{0}' is duplicated", subtype.SubtypeName); string message2 = string.Format("Subtype name '{0}' is duplicated", s.SubtypeName); list.Add(new ErrorTable(subtype, message1, ErrorType.Error)); list.Add(new ErrorTable(s, message2, ErrorType.Error)); } else { dictionary2.Add(subtype.SubtypeName.ToUpper(), subtype); } } // Check if Subtype codes duplicated Dictionary <int, Subtype> dictionary3 = new Dictionary <int, Subtype>(); foreach (Subtype subtype in subtypes) { Subtype s = null; if (dictionary3.TryGetValue(subtype.SubtypeCode, out s)) { string message1 = string.Format("Subtype code '{0}' is duplicated", subtype.SubtypeCode.ToString()); string message2 = string.Format("Subtype code '{0}' is duplicated", s.SubtypeCode.ToString()); list.Add(new ErrorTable(subtype, message1, ErrorType.Error)); list.Add(new ErrorTable(s, message2, ErrorType.Error)); } else { dictionary3.Add(subtype.SubtypeCode, subtype); } } // AliasName if (!string.IsNullOrEmpty(this._aliasName)) { if (this._aliasName.Length > 255) { // Cannot be longer than 255 characters list.Add(new ErrorTable(this, "Alias name cannot be longer than 255 characters", ErrorType.Error)); } } // CLSID if (this.GetType() == typeof(ObjectClass)) { if (string.IsNullOrEmpty(this._clsid)) { // Cannot be empty list.Add(new ErrorTable(this, "CLSID cannot be emtpy", ErrorType.Error)); } else { Guid guid = Guid.Empty; try { guid = new Guid(this._clsid); } catch (FormatException) { } catch (OverflowException) { } if (guid == Guid.Empty) { list.Add(new ErrorTable(this, "CLSID is not a valid guid {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}", ErrorType.Error)); } else { if (guid.ToString("B").ToUpper() != EsriRegistry.CLASS_TABLE) { string x = string.Format("CLSID is valid but normally set to '{0}'", Resources.TEXT_TABLE); list.Add(new ErrorTable(this, x, ErrorType.Warning)); } } } } // EXTCLSID if (this.GetType() == typeof(ObjectClass)) { if (!string.IsNullOrEmpty(this._extClsid)) { // Must be a valid GUID format "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" Guid guid = Guid.Empty; try { guid = new Guid(this._extClsid); } catch (FormatException) { } catch (OverflowException) { } if (guid == Guid.Empty) { list.Add(new ErrorTable(this, "EXTCLSID is not a valid guid {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}", ErrorType.Error)); } } } // GlobalIDFieldName if (!string.IsNullOrEmpty(this._globalIDFieldName)) { Field field = this.FindField(this._globalIDFieldName); if (field == null) { // GlobalIDFieldName does not exist string message = string.Format("Global ID Field '{0}' does not exist", this._globalIDFieldName); list.Add(new ErrorTable(this, message, ErrorType.Error)); } else { if (field.FieldType != esriFieldType.esriFieldTypeGlobalID) { // Field is not of type "GlobalID" string message = string.Format("Global ID Field '{0}' must be of type '{1}'", this._globalIDFieldName, esriFieldType.esriFieldTypeGlobalID.ToString()); list.Add(new ErrorTable(this, message, ErrorType.Error)); } } } // ModelName if (this._modelName.Length > 255) { // ModelName must be less than 255 characters long list.Add(new ErrorTable(this, "Model name exceeds maximum length of 255 characters", ErrorType.Error)); } // OIDFieldName if (string.IsNullOrEmpty(this._oidFieldName)) { // OID Field is Empty if (this.GetType() == typeof(RelationshipClass)) { // RelationshipClasses can have an empty OIDFieldName } else { list.Add(new ErrorTable(this, "OIDFieldName cannot be empty", ErrorType.Error)); } } else { Field field = this.FindField(this._oidFieldName); if (field == null) { // OID Field does not exist string message = string.Format("OIDFieldName '{0}' does not exist", this._oidFieldName); list.Add(new ErrorTable(this, message, ErrorType.Error)); } else { if (field.FieldType != esriFieldType.esriFieldTypeOID) { // OID Field is the correct field type string message = string.Format("OIDFieldName '{0}' is not of type '{1}'", this._oidFieldName, esriFieldType.esriFieldTypeOID.ToString()); list.Add(new ErrorTable(this, message, ErrorType.Error)); } } } // Can only have one OID in ObjectClass int oidFieldCount = 0; foreach (Field field in fields) { if (field.FieldType == esriFieldType.esriFieldTypeOID) { oidFieldCount++; } } switch (oidFieldCount) { case 0: // ObjectClass does not contain any ObjectID Fields if (this.GetType() == typeof(RelationshipClass)) { // RelationshipClasses do not have to specify a OID Field } else { list.Add(new ErrorTable(this, "Tables and FeatureClasses must have one OID Field", ErrorType.Error)); } break; case 1: // OK break; default: // Mulitple ObjectID Fields found list.Add(new ErrorTable(this, "Only one ObjectID Fields is permitted per Table/FeatureClass", ErrorType.Error)); break; } // RasterFieldName if (!(string.IsNullOrEmpty(this._rasterFieldName))) { Field field = this.FindField(this._rasterFieldName); if (field == null) { // Raster Field does not exist string message = string.Format("Raster Field '{0}' does not exist", this._rasterFieldName); list.Add(new ErrorTable(this, message, ErrorType.Error)); } else { if (field.FieldType != esriFieldType.esriFieldTypeRaster) { // Raster Field is the correct field type string message = string.Format("Raster Field '{0}' is not of type '{1}'", this._rasterFieldName, esriFieldType.esriFieldTypeRaster.ToString()); list.Add(new ErrorTable(this, message, ErrorType.Error)); } } } // ObjectClass can only participate in one Controller (eg GeometricNetwork, Topology, Network and Terrain?) switch (this._controllerMemberships.Count) { case 0: // OK break; case 1: // OK. But must validate. this._controllerMemberships[0].Errors(list, this); break; default: list.Add(new ErrorTable(this, "A table or feature class must only have one controller", ErrorType.Error)); break; } // SubtypeFieldName if (string.IsNullOrEmpty(this._subtypeFieldName)) { if (subtypes.Count > 0) { // Empty subtype field name but has one or more linked subtypes string message = string.Format("Table/FeatureClass has no subtype field but has '{0}' subtypes linked", subtypes.Count.ToString()); list.Add(new ErrorTable(this, message, ErrorType.Error)); } } else { Field field = this.FindField(this._subtypeFieldName); if (field == null) { // Subtype Field does not exist string message = string.Format("Subtype Field '{0}' does not exist", this._subtypeFieldName); list.Add(new ErrorTable(this, message, ErrorType.Error)); } else { switch (field.FieldType) { case esriFieldType.esriFieldTypeSmallInteger: case esriFieldType.esriFieldTypeInteger: // OK break; default: // Invalid Subtype Field Type string message = string.Format( "Subtype Field '{0}' is not of type '{1}' or '{2}'", this._subtypeFieldName, esriFieldType.esriFieldTypeSmallInteger.ToString(), esriFieldType.esriFieldTypeInteger.ToString()); list.Add(new ErrorTable(this, message, ErrorType.Error)); break; } if (subtypes.Count == 0) { // Must have at least one Subtype string message = string.Format("Table/FeatureClass has a subtype field but no linked subtypes"); list.Add(new ErrorTable(this, message, ErrorType.Error)); } else { // Check that only one subtype is the default int defaultSubtypes = 0; foreach (Subtype subtype in subtypes) { if (subtype.Default) { defaultSubtypes++; } } switch (defaultSubtypes) { case 0: string message1 = string.Format("Table/FeatureClass must have a default subtype"); list.Add(new ErrorTable(this, message1, ErrorType.Error)); break; case 1: // OK break; default: string message2 = string.Format("Table/FeatureClass cannot have more than one default subtype"); list.Add(new ErrorTable(this, message2, ErrorType.Error)); break; } } } } }
private TreeNode CreateCatalogNode(TreeNode node, EsriTable table) { if (table.GetType() == typeof(DomainCodedValue)) { // Get Coded Value Domain DomainCodedValue domainCodedValue = (DomainCodedValue)table; // Add Coded Value Domain TreeNodeTable treeNode = new TreeNodeTable(domainCodedValue); treeNode.ImageKey = Catalog.CODED_VALUE_DOMAIN; treeNode.SelectedImageKey = Catalog.CODED_VALUE_DOMAIN; treeNode.Text = domainCodedValue.Name; node.Nodes.Add(treeNode); return(treeNode); } if (table.GetType() == typeof(DomainRange)) { // Get Range Domain DomainRange domainRange = (DomainRange)table; // Add Range Domain TreeNodeTable treeNode = new TreeNodeTable(domainRange); treeNode.ImageKey = Catalog.RANGE_DOMAIN; treeNode.SelectedImageKey = Catalog.RANGE_DOMAIN; treeNode.Text = domainRange.Name; node.Nodes.Add(treeNode); return(treeNode); } if (table.GetType() == typeof(FeatureClass)) { // Get FeatureClass FeatureClass featureClass = (FeatureClass)table; // Add FeatureClass Node string imageKey = null; switch (featureClass.FeatureType) { case ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTAnnotation: imageKey = Catalog.ANNOTATION_FEATURE_CLASS; break; case ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTDimension: imageKey = Catalog.DIMENSION_FEATURE_CLASS; break; case ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple: switch (featureClass.ShapeType) { case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultipoint: case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint: imageKey = Catalog.POINT_FEATURE_CLASS; break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon: imageKey = Catalog.POLYGON_FEATURE_CLASS; break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline: imageKey = Catalog.POLYLINE_FEATURE_CLASS; break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultiPatch: imageKey = Catalog.MULTIPATCH_FEATURE_CLASS; break; default: imageKey = Catalog.POINT_FEATURE_CLASS; break; } break; default: imageKey = POINT_FEATURE_CLASS; break; } TreeNodeTable treeNode = new TreeNodeTable(featureClass); treeNode.ImageKey = imageKey; treeNode.SelectedImageKey = imageKey; treeNode.Text = featureClass.Name; node.Nodes.Add(treeNode); return(treeNode); } if (table.GetType() == typeof(FeatureDataset)) { // Get FeatureDataset FeatureDataset featureDataset = (FeatureDataset)table; // Add FeatureDataset Node TreeNodeTable treeNode = new TreeNodeTable(featureDataset); treeNode.ImageKey = Catalog.FEATURE_DATASET; treeNode.SelectedImageKey = Catalog.FEATURE_DATASET; treeNode.Text = featureDataset.Name; node.Nodes.Add(treeNode); return(treeNode); } if (table.GetType() == typeof(GeometricNetwork)) { // Get GeometricNetwork GeometricNetwork geometricNetwork = (GeometricNetwork)table; // Add GeometricNetwork Node TreeNodeTable treeNode = new TreeNodeTable(geometricNetwork); treeNode.ImageKey = Catalog.GEOMETRIC_NETWORK; treeNode.SelectedImageKey = Catalog.GEOMETRIC_NETWORK; treeNode.Text = geometricNetwork.Name; node.Nodes.Add(treeNode); return(treeNode); } if (table.GetType() == typeof(Network)) { // Get Network Network network = (Network)table; // Add Network TreeNode TreeNodeTable treeNode = new TreeNodeTable(network); treeNode.ImageKey = Catalog.NETWORK_DATASET; treeNode.SelectedImageKey = Catalog.NETWORK_DATASET; treeNode.Text = network.Name; node.Nodes.Add(treeNode); return(treeNode); } if (table.GetType() == typeof(ObjectClass)) { // Get ObjectClass ObjectClass objectClass = (ObjectClass)table; // Add ObjectClass TreeNode TreeNodeTable treeNode = new TreeNodeTable(objectClass); treeNode.ImageKey = Catalog.TABLE; treeNode.SelectedImageKey = Catalog.TABLE; treeNode.Text = objectClass.Name; node.Nodes.Add(treeNode); return(treeNode); } if (table.GetType() == typeof(RasterBand)) { // Get RasterBand RasterBand rasterBand = (RasterBand)table; // Add RasterBand TreeNode TreeNodeTable treeNode = new TreeNodeTable(rasterBand); treeNode.ImageKey = Catalog.RASTER_BAND; treeNode.SelectedImageKey = Catalog.RASTER_BAND; treeNode.Text = rasterBand.Name; node.Nodes.Add(treeNode); return(treeNode); } if (table.GetType() == typeof(RasterCatalog)) { // Get RasterCatalog RasterCatalog rasterCatalog = (RasterCatalog)table; // Add RasterCatalog TreeNode TreeNodeTable treeNode = new TreeNodeTable(rasterCatalog); treeNode.ImageKey = Catalog.RASTER_CATALOG; treeNode.SelectedImageKey = Catalog.RASTER_CATALOG; treeNode.Text = rasterCatalog.Name; node.Nodes.Add(treeNode); return(treeNode); } if (table.GetType() == typeof(RasterDataset)) { // Get RasterDataset RasterDataset rasterDataset = (RasterDataset)table; // Add RasterDataset TreeNode TreeNodeTable treeNode = new TreeNodeTable(rasterDataset); treeNode.ImageKey = Catalog.RASTER_DATASET; treeNode.SelectedImageKey = Catalog.RASTER_DATASET; treeNode.Text = rasterDataset.Name; node.Nodes.Add(treeNode); return(treeNode); } if (table.GetType() == typeof(RelationshipClass)) { // Get RelationshipClass RelationshipClass relationshipClass = (RelationshipClass)table; // Add RelationshipClass TreeNode TreeNodeTable treeNode = new TreeNodeTable(relationshipClass); treeNode.ImageKey = Catalog.RELATIONSHIP_CLASS; treeNode.SelectedImageKey = Catalog.RELATIONSHIP_CLASS; treeNode.Text = relationshipClass.Name; node.Nodes.Add(treeNode); return(treeNode); } if (table.GetType() == typeof(Subtype)) { // Get Subtype Subtype subtype = (Subtype)table; // Add Subtype TreeNode TreeNodeTable treeNode = new TreeNodeTable(subtype); treeNode.ImageKey = Catalog.SUBTYPE; treeNode.SelectedImageKey = Catalog.SUBTYPE; treeNode.Text = subtype.SubtypeName; node.Nodes.Add(treeNode); return(treeNode); } if (table.GetType() == typeof(Terrain)) { // Get Terrain Terrain terrain = (Terrain)table; // Add Terrain TreeNode TreeNodeTable treeNode = new TreeNodeTable(terrain); treeNode.ImageKey = Catalog.TERRAIN; treeNode.SelectedImageKey = Catalog.TERRAIN; treeNode.Text = terrain.Name; node.Nodes.Add(treeNode); return(treeNode); } if (table.GetType() == typeof(Topology)) { // Get Topology Topology topology = (Topology)table; // Add Topology TreeNode TreeNodeTable treeNode = new TreeNodeTable(topology); treeNode.ImageKey = Catalog.TOPOLOGY; treeNode.SelectedImageKey = Catalog.TOPOLOGY; treeNode.Text = topology.Name; node.Nodes.Add(treeNode); return(treeNode); } return(null); }
private void Model_ElementInvalid(object sender, ElementEventArgs e) { // Exit if Topology Does not Exist if (this._topology == null) { return; } // Get Element Element element = e.Value; if (element == null) { return; } EsriLine <TopologyRule> line = element as EsriLine <TopologyRule>; if (line == null) { return; } // Get TopologyRule TopologyRule rule = line.Parent; // Suspend Rule Events rule.Suspend(); // Get Start and End Elements Element elementStart = line.Start.Shape; Element elementEnd = line.End.Shape; // Update Start Class/Subtype if (elementStart == null) { rule.AllOriginSubtypes = false; rule.OriginClassId = -1; rule.OriginSubtype = -1; } else if (elementStart is EsriShape <FeatureClass> ) { EsriShape <FeatureClass> shape = (EsriShape <FeatureClass>)elementStart; ObjectClass objectClass = shape.Parent; rule.AllOriginSubtypes = true; rule.OriginClassId = objectClass.DSID; rule.OriginSubtype = 0; } else if (elementStart is EsriShape <Subtype> ) { EsriShape <Subtype> shape = (EsriShape <Subtype>)elementStart; Subtype subtype = shape.Parent; ObjectClass objectClass = subtype.GetParent(); rule.AllOriginSubtypes = false; if (objectClass == null) { rule.OriginClassId = -1; rule.OriginSubtype = -1; } else { rule.OriginClassId = objectClass.DSID; rule.OriginSubtype = subtype.SubtypeCode; } } // Update End Class/Subtype if (elementEnd == null) { rule.AllDestinationSubtypes = false; rule.DestinationClassId = -1; rule.DestinationSubtype = -1; } else if (elementEnd is EsriShape <FeatureClass> ) { EsriShape <FeatureClass> shape = (EsriShape <FeatureClass>)elementEnd; ObjectClass objectClass = shape.Parent; rule.AllDestinationSubtypes = true; rule.DestinationClassId = objectClass.DSID; rule.DestinationSubtype = 0; } else if (elementEnd is EsriShape <Subtype> ) { EsriShape <Subtype> shape = (EsriShape <Subtype>)elementEnd; Subtype subtype = shape.Parent; ObjectClass objectClass = subtype.GetParent(); rule.AllDestinationSubtypes = false; if (objectClass == null) { rule.DestinationClassId = -1; rule.DestinationSubtype = -1; } else { rule.DestinationClassId = objectClass.DSID; rule.DestinationSubtype = subtype.SubtypeCode; } } // Resume Rule Events rule.Resume(); }
private void Model_ElementInvalid(object sender, ElementEventArgs e) { // Exit if GeometricNetwork Does not Exist if (this._geometricNetwork == null) { return; } // Get Element Element element = e.Value; if (element == null) { return; } EsriLine <JunctionConnectivityRule> line = element as EsriLine <JunctionConnectivityRule>; if (line == null) { return; } // Get EdgeConnectivityRule JunctionConnectivityRule rule = line.Parent; // Suspend Rule Events rule.Suspend(); // Get Start and End Elements Element elementStart = line.Start.Shape; Element elementEnd = line.End.Shape; // Update Start Class/Subtype if (elementStart == null) { rule.EdgeClassID = -1; rule.EdgeSubtypeCode = -1; } else if (elementStart is EsriShape <FeatureClass> ) { EsriShape <FeatureClass> shape = (EsriShape <FeatureClass>)elementStart; ObjectClass objectClass = shape.Parent; rule.EdgeClassID = objectClass.DSID; rule.EdgeSubtypeCode = 0; } else if (elementStart is EsriShape <Subtype> ) { EsriShape <Subtype> shape = (EsriShape <Subtype>)elementStart; Subtype subtype = shape.Parent; ObjectClass objectClass = subtype.GetParent(); if (objectClass == null) { rule.EdgeClassID = -1; rule.EdgeSubtypeCode = -1; } else { rule.EdgeClassID = objectClass.DSID; rule.EdgeSubtypeCode = subtype.SubtypeCode; } } // Update End Class/Subtype if (elementEnd == null) { rule.JunctionClassID = -1; rule.SubtypeCode = -1; } else if (elementEnd is EsriShape <FeatureClass> ) { EsriShape <FeatureClass> shape = (EsriShape <FeatureClass>)elementEnd; ObjectClass objectClass = shape.Parent; rule.JunctionClassID = objectClass.DSID; rule.SubtypeCode = 0; } else if (elementEnd is EsriShape <Subtype> ) { EsriShape <Subtype> shape = (EsriShape <Subtype>)elementEnd; Subtype subtype = shape.Parent; ObjectClass objectClass = subtype.GetParent(); if (objectClass == null) { rule.JunctionClassID = -1; rule.SubtypeCode = -1; } else { rule.JunctionClassID = objectClass.DSID; rule.SubtypeCode = subtype.SubtypeCode; } } // Resume Rule Events rule.Resume(); }