//
        // PUBLIC METHODS
        //
        public override void OpenModel()
        {
            EsriShape <ObjectClass>     orig                = null;
            EsriShape <ObjectClass>     dest                = null;
            List <EsriShape <Subtype> > originSubtypes      = new List <EsriShape <Subtype> >();
            List <EsriShape <Subtype> > destinationSubtypes = new List <EsriShape <Subtype> >();

            // Exit if invalid
            if (this._relationshipClass == null)
            {
                return;
            }

            // Suspend Model
            if (ModelSettings.Default.EnableUndoRedo)
            {
                this.UndoList.Suspend();
            }
            this.Suspend();
            this.SuspendEvents = true;

            // Get Schema Model
            SchemaModel schemaModel = (SchemaModel)this._relationshipClass.Container;

            // Get Origin and Destination ObjectClasses
            ObjectClass objectClassOrig = schemaModel.FindObjectClass(this._relationshipClass.OriginClassName);
            ObjectClass objectClassDest = schemaModel.FindObjectClass(this._relationshipClass.DestinationClassName);

            // Add ObjectClasses
            orig = new EsriShape <ObjectClass>(objectClassOrig);
            dest = new EsriShape <ObjectClass>(objectClassDest);
            this.Shapes.Add(this.Shapes.CreateKey(), orig);
            this.Shapes.Add(this.Shapes.CreateKey(), dest);

            // Get Subtypes
            List <Subtype> subtypesOrig = objectClassOrig.GetSubtypes();
            List <Subtype> subtypesDest = objectClassDest.GetSubtypes();

            // Add Subtypes
            foreach (Subtype subtype in subtypesOrig)
            {
                EsriShape <Subtype> sub = new EsriShape <Subtype>(subtype);
                this.Shapes.Add(this.Shapes.CreateKey(), sub);

                Arrow arrow = new Arrow();
                arrow.BorderColor    = ModelSettings.Default.DisabledLined;
                arrow.DrawBackground = false;

                Line line = new Line(orig, sub);
                line.BorderColor     = ModelSettings.Default.DisabledLined;
                line.End.AllowMove   = false;
                line.End.Marker      = arrow;
                line.Start.AllowMove = false;
                this.Lines.Add(this.Lines.CreateKey(), line);

                originSubtypes.Add(sub);
            }
            foreach (Subtype subtype in subtypesDest)
            {
                EsriShape <Subtype> sub = new EsriShape <Subtype>(subtype);
                this.Shapes.Add(this.Shapes.CreateKey(), sub);

                Arrow arrow = new Arrow();
                arrow.BorderColor    = ModelSettings.Default.DisabledLined;
                arrow.DrawBackground = false;

                Line line = new Line(sub, dest);
                line.BorderColor     = ModelSettings.Default.DisabledLined;
                line.End.AllowMove   = false;
                line.Start.AllowMove = false;
                line.Start.Marker    = arrow;
                this.Lines.Add(this.Lines.CreateKey(), line);

                destinationSubtypes.Add(sub);
            }

            // Get Rules
            List <RelationshipRule> rules = this._relationshipClass.RelationshipRules;

            foreach (RelationshipRule rule in rules)
            {
                Shape shapeOrign = null;
                if (subtypesOrig.Count == 0)
                {
                    shapeOrign = orig;
                }
                else
                {
                    foreach (EsriShape <Subtype> subtype in originSubtypes)
                    {
                        if (subtype.Parent.SubtypeCode == rule.OriginSubtype)
                        {
                            shapeOrign = subtype;
                            break;
                        }
                    }
                }

                Shape shapeDestination = null;
                if (subtypesDest.Count == 0)
                {
                    shapeDestination = dest;
                }
                else
                {
                    foreach (EsriShape <Subtype> subtype in destinationSubtypes)
                    {
                        if (subtype.Parent.SubtypeCode == rule.DestinationSubtype)
                        {
                            shapeDestination = subtype;
                            break;
                        }
                    }
                }
                if (shapeOrign == null || shapeDestination == null)
                {
                    continue;
                }
                //
                EsriLine <RelationshipRule> line = new EsriLine <RelationshipRule>(rule, shapeOrign, shapeDestination);
                this.Lines.Add(this.Lines.CreateKey(), line);
            }

            // Perform Layout
            this.ExecuteLayout(typeof(HierarchicalLayout), true);

            // Resume and Refresh Model
            this.SuspendEvents = false;
            this.Resume();
            if (ModelSettings.Default.EnableUndoRedo)
            {
                this.UndoList.Resume();
            }
            this.Refresh();
        }
예제 #2
0
        public override void Errors(List <Error> list, EsriTable table)
        {
            // Write Base Errors
            base.Errors(list, table);

            // Get Topology
            Topology topology = (Topology)table;

            // Check for duplicate rules
            bool duplicate = false;

            foreach (TopologyRule topologyRule in topology.TopologyRules)
            {
                if (topologyRule == this)
                {
                    continue;
                }
                if (this._allOriginSubtypes == topologyRule.AllOriginSubtypes &&
                    this._originClassId == topologyRule.OriginClassId &&
                    this._originSubtype == topologyRule.OriginSubtype &&
                    this._allDestinationSubtypes == topologyRule.AllDestinationSubtypes &&
                    this._destinationClassId == topologyRule.DestinationClassId &&
                    this._destinationSubtype == topologyRule.DestinationSubtype &&
                    this._topologyRuleType == topologyRule.TopologyRuleType)
                {
                    duplicate = true;
                    break;
                }
            }
            if (duplicate)
            {
                string message = string.Format("Duplicate topology rules found");
                list.Add(new ErrorObject(this, table, message, ErrorType.Error));
            }

            // Duplicate Guids
            bool duplicateGuid = false;

            foreach (TopologyRule topologyRule in topology.TopologyRules)
            {
                if (topologyRule == this)
                {
                    continue;
                }
                if (this._guid == topologyRule.Guid)
                {
                    duplicateGuid = true;
                    break;
                }
            }
            if (duplicateGuid)
            {
                string message = string.Format("Topology Rule Guid [{0}] is not unique", this._guid);
                list.Add(new ErrorObject(this, table, message, ErrorType.Error));
            }

            // Check if rule conflict with rules using "All Subtypes" - Origin
            if (this._allOriginSubtypes)
            {
                bool originSubtypeConflict = false;
                foreach (TopologyRule topologyRule in topology.TopologyRules)
                {
                    if (topologyRule == this)
                    {
                        continue;
                    }
                    if (topologyRule.AllOriginSubtypes == false &&
                        this._originClassId == topologyRule.OriginClassId &&
                        this._allDestinationSubtypes == topologyRule.AllDestinationSubtypes &&
                        this._destinationClassId == topologyRule.DestinationClassId &&
                        this._destinationSubtype == topologyRule.DestinationSubtype &&
                        this._topologyRuleType == topologyRule.TopologyRuleType)
                    {
                        originSubtypeConflict = true;
                        break;
                    }
                }
                if (originSubtypeConflict)
                {
                    string message = string.Format("The Topology Rule [{0}] with an Origin 'AllSubtypes' setting conflicts another rule", this._guid);
                    list.Add(new ErrorObject(this, table, message, ErrorType.Error));
                }
            }

            // Check if rule conflict with rules using "All Subtypes" - Destination
            if (this._allDestinationSubtypes)
            {
                bool destinationSubtypeConflict = false;
                foreach (TopologyRule topologyRule in topology.TopologyRules)
                {
                    if (topologyRule == this)
                    {
                        continue;
                    }
                    if (topologyRule.AllDestinationSubtypes == false &&
                        this._destinationClassId == topologyRule.DestinationClassId &&
                        this._allOriginSubtypes == topologyRule.AllOriginSubtypes &&
                        this._originClassId == topologyRule.OriginClassId &&
                        this._originSubtype == topologyRule.OriginSubtype &&
                        this._topologyRuleType == topologyRule.TopologyRuleType)
                    {
                        destinationSubtypeConflict = true;
                        break;
                    }
                }
                if (destinationSubtypeConflict)
                {
                    string message = string.Format("The Topology Rule [{0}] with an Destination 'AllSubtypes' setting conflicts another rule", this._guid);
                    list.Add(new ErrorObject(this, table, message, ErrorType.Error));
                }
            }

            // Valid rules for Origin/Destination Shape Types
            DiagrammerEnvironment diagrammerEnvironment = DiagrammerEnvironment.Default;
            SchemaModel           schemaModel           = diagrammerEnvironment.SchemaModel;

            // Get Origin and Destination FeatureClasses
            ObjectClass objectClassOrig = schemaModel.FindObjectClass(this._originClassId);
            ObjectClass objectClassDest = schemaModel.FindObjectClass(this._destinationClassId);

            // Check if Origin and Destination ObjectClasses Exist
            if (objectClassOrig == null)
            {
                list.Add(new ErrorObject(this, table, "Origin FeatureClass Does Not Exist", ErrorType.Error));
            }
            if (objectClassDest == null)
            {
                list.Add(new ErrorObject(this, table, "Destination FeatureClass Does Not Exist", ErrorType.Error));
            }

            // Check if Origin and Destination Subypes Exist
            EsriTable tableOrig = schemaModel.FindObjectClassOrSubtype(this._originClassId, this._originSubtype);
            EsriTable tableDest = schemaModel.FindObjectClassOrSubtype(this._destinationClassId, this._destinationSubtype);

            if (tableOrig == null)
            {
                list.Add(new ErrorObject(this, table, "Origin FeatureClass and/or Subtype Does Not Exist", ErrorType.Error));
            }
            if (tableDest == null)
            {
                list.Add(new ErrorObject(this, table, "Destination FeatureClass and/or Subtype Does Not Exist", ErrorType.Error));
            }

            // Get Origin and Destination FeatureClasses
            FeatureClass featureClassOrig = objectClassOrig as FeatureClass;
            FeatureClass featureClassDest = objectClassDest as FeatureClass;

            // These rules MUST have the same origin and destination class/subtype
            if (featureClassOrig != null && featureClassDest != null && tableOrig != null && tableDest != null)
            {
                switch (this._topologyRuleType)
                {
                case esriTopologyRuleType.esriTRTLineNoOverlap:
                case esriTopologyRuleType.esriTRTLineNoIntersection:
                case esriTopologyRuleType.esriTRTLineNoDangles:
                case esriTopologyRuleType.esriTRTLineNoPseudos:
                case esriTopologyRuleType.esriTRTLineNoSelfOverlap:
                case esriTopologyRuleType.esriTRTLineNoSelfIntersect:
                case esriTopologyRuleType.esriTRTLineNoIntersectOrInteriorTouch:
                case esriTopologyRuleType.esriTRTLineNoMultipart:
                case esriTopologyRuleType.esriTRTAreaNoGaps:
                case esriTopologyRuleType.esriTRTAreaNoOverlap:
                    if (this._originClassId != this._destinationClassId ||
                        this._originSubtype != this._destinationSubtype)
                    {
                        list.Add(new ErrorObject(this, table, "This rule must have the same origin and destination FeatureClass and Subtype", ErrorType.Error));
                    }
                    break;

                default:
                    break;
                }
            }

            // Examine Rule Based on Origin and Destination GeometryType
            bool ok = false;

            if (featureClassOrig != null && featureClassDest != null)
            {
                switch (featureClassOrig.ShapeType)
                {
                case esriGeometryType.esriGeometryPoint:
                    switch (featureClassDest.ShapeType)
                    {
                    case esriGeometryType.esriGeometryPoint:
                        // POINT > POINT
                        switch (this._topologyRuleType)
                        {
                        default:
                            ok = false;
                            break;
                        }
                        break;

                    case esriGeometryType.esriGeometryPolyline:
                        // POINT > POLYLINE
                        switch (this._topologyRuleType)
                        {
                        case esriTopologyRuleType.esriTRTPointCoveredByLine:
                        case esriTopologyRuleType.esriTRTPointCoveredByLineEndpoint:
                            ok = true;
                            break;

                        default:
                            ok = false;
                            break;
                        }
                        break;

                    case esriGeometryType.esriGeometryPolygon:
                        // POINT > POLYGON
                        switch (this._topologyRuleType)
                        {
                        case esriTopologyRuleType.esriTRTPointCoveredByAreaBoundary:
                        case esriTopologyRuleType.esriTRTPointProperlyInsideArea:
                            ok = true;
                            break;

                        default:
                            ok = false;
                            break;
                        }
                        break;
                    }
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    switch (featureClassDest.ShapeType)
                    {
                    case esriGeometryType.esriGeometryPoint:
                        // POLYLINE > POINT
                        switch (this._topologyRuleType)
                        {
                        case esriTopologyRuleType.esriTRTLineEndpointCoveredByPoint:
                            ok = true;
                            break;

                        default:
                            ok = false;
                            break;
                        }
                        break;

                    case esriGeometryType.esriGeometryPolyline:
                        // POLYLINE > POLYLINE
                        switch (this._topologyRuleType)
                        {
                        case esriTopologyRuleType.esriTRTLineNoOverlap:
                        case esriTopologyRuleType.esriTRTLineNoIntersection:
                        case esriTopologyRuleType.esriTRTLineNoDangles:
                        case esriTopologyRuleType.esriTRTLineNoPseudos:
                        case esriTopologyRuleType.esriTRTLineCoveredByLineClass:
                        case esriTopologyRuleType.esriTRTLineNoOverlapLine:
                        case esriTopologyRuleType.esriTRTLineNoSelfOverlap:
                        case esriTopologyRuleType.esriTRTLineNoSelfIntersect:
                        case esriTopologyRuleType.esriTRTLineNoIntersectOrInteriorTouch:
                        case esriTopologyRuleType.esriTRTLineNoMultipart:
                            ok = true;
                            break;

                        default:
                            ok = false;
                            break;
                        }
                        break;

                    case esriGeometryType.esriGeometryPolygon:
                        // POLYLINE > POLYGON
                        switch (this._topologyRuleType)
                        {
                        case esriTopologyRuleType.esriTRTLineCoveredByAreaBoundary:
                            ok = true;
                            break;

                        default:
                            ok = false;
                            break;
                        }
                        break;
                    }
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    switch (featureClassDest.ShapeType)
                    {
                    case esriGeometryType.esriGeometryPoint:
                        // POLYGON > POINT
                        switch (this._topologyRuleType)
                        {
                        case esriTopologyRuleType.esriTRTAreaContainPoint:
                            ok = true;
                            break;

                        default:
                            ok = false;
                            break;
                        }
                        break;

                    case esriGeometryType.esriGeometryPolyline:
                        // POLYGON > POLYLINE
                        switch (this._topologyRuleType)
                        {
                        case esriTopologyRuleType.esriTRTAreaBoundaryCoveredByLine:
                            ok = true;
                            break;

                        default:
                            ok = false;
                            break;
                        }
                        break;

                    case esriGeometryType.esriGeometryPolygon:
                        // POLYGON > POLYGON
                        switch (this._topologyRuleType)
                        {
                        case esriTopologyRuleType.esriTRTAreaNoGaps:
                        case esriTopologyRuleType.esriTRTAreaNoOverlap:
                        case esriTopologyRuleType.esriTRTAreaCoveredByAreaClass:
                        case esriTopologyRuleType.esriTRTAreaAreaCoverEachOther:
                        case esriTopologyRuleType.esriTRTAreaCoveredByArea:
                        case esriTopologyRuleType.esriTRTAreaNoOverlapArea:
                        case esriTopologyRuleType.esriTRTAreaBoundaryCoveredByAreaBoundary:
                            ok = true;
                            break;

                        default:
                            ok = false;
                            break;
                        }
                        break;
                    }
                    break;
                }
            }
            if (!ok)
            {
                list.Add(new ErrorObject(this, table, "This rule cannot be added between these FeatureClass geometric types", ErrorType.Error));
            }
        }
        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);
        }
        private ObjectClass GetObjectClass(ITypeDescriptorContext context)
        {
            DiagrammerEnvironment de          = DiagrammerEnvironment.Default;
            SchemaModel           model       = de.SchemaModel;
            ObjectClass           objectClass = null;

            if (context.PropertyDescriptor.ComponentType == typeof(EdgeConnectivityRule))
            {
                EdgeConnectivityRule edgeConnectivityRule = (EdgeConnectivityRule)context.Instance;
                switch (context.PropertyDescriptor.Name)
                {
                case "FromEdgeSubtypeCode":
                    objectClass = model.FindObjectClass(edgeConnectivityRule.FromClassID);
                    break;

                case "ToEdgeSubtypeCode":
                    objectClass = model.FindObjectClass(edgeConnectivityRule.ToClassID);
                    break;

                case "DefaultJunctionSubtypeCode":
                    objectClass = model.FindObjectClass(edgeConnectivityRule.DefaultJunctionID);
                    break;
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(JunctionSubtype))
            {
                JunctionSubtype junctionSubtype = (JunctionSubtype)context.Instance;
                switch (context.PropertyDescriptor.Name)
                {
                case "SubtypeCode":
                    objectClass = model.FindObjectClass(junctionSubtype.ClassID);
                    break;
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(RelationshipRule))
            {
                RelationshipRule relationshipRule = (RelationshipRule)context.Instance;
                switch (context.PropertyDescriptor.Name)
                {
                case "OriginSubtype":
                    objectClass = model.FindObjectClass(relationshipRule.OriginClass);
                    break;

                case "DestinationSubtype":
                    objectClass = model.FindObjectClass(relationshipRule.DestinationClass);
                    break;
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(JunctionConnectivityRule))
            {
                JunctionConnectivityRule junctionConnectivityRule = (JunctionConnectivityRule)context.Instance;
                switch (context.PropertyDescriptor.Name)
                {
                case "EdgeSubtypeCode":
                    objectClass = model.FindObjectClass(junctionConnectivityRule.EdgeClassID);
                    break;

                case "SubtypeCode":
                    objectClass = model.FindObjectClass(junctionConnectivityRule.JunctionClassID);
                    break;
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(TopologyRule))
            {
                TopologyRule topologyRule = (TopologyRule)context.Instance;
                switch (context.PropertyDescriptor.Name)
                {
                case "OriginSubtype":
                    objectClass = model.FindObjectClass(topologyRule.OriginClassId);
                    break;

                case "DestinationSubtype":
                    objectClass = model.FindObjectClass(topologyRule.DestinationClassId);
                    break;
                }
            }
            return(objectClass);
        }
        //
        // PUBLIC METHODS
        //
        public override void OpenModel()
        {
            // Create Origin and Destination Lists
            List <EsriShape <FeatureClass> > listFeatureClassFrom = new List <EsriShape <FeatureClass> >();
            List <EsriShape <FeatureClass> > listFeatureClassTo   = new List <EsriShape <FeatureClass> >();
            List <EsriShape <Subtype> >      listSubtypeFrom      = new List <EsriShape <Subtype> >();
            List <EsriShape <Subtype> >      listSubtypeTo        = new List <EsriShape <Subtype> >();

            // Exit if invalid
            if (this._topology == null)
            {
                return;
            }

            // Suspend Model
            if (ModelSettings.Default.EnableUndoRedo)
            {
                this.UndoList.Suspend();
            }
            this.Suspend();
            this.SuspendEvents = true;

            // Get SchemaModel
            SchemaModel schemaModel = (SchemaModel)this._topology.Container;

            // Get Parent FeatureDataset
            Dataset parent = this._topology.GetParent();

            if (parent == null)
            {
                return;
            }
            FeatureDataset featureDataset = parent as FeatureDataset;

            if (featureDataset == null)
            {
                return;
            }

            // Add From and To FeatureDatasets
            EsriShape <FeatureDataset> featureDataset1 = new EsriShape <FeatureDataset>(featureDataset);
            EsriShape <FeatureDataset> featureDataset2 = new EsriShape <FeatureDataset>(featureDataset);

            this.Shapes.Add(this.Shapes.CreateKey(), featureDataset1);
            this.Shapes.Add(this.Shapes.CreateKey(), featureDataset2);

            // Add all Child FeatureClasses
            foreach (Dataset dataset in featureDataset.GetChildren())
            {
                if (dataset.GetType() != typeof(FeatureClass))
                {
                    continue;
                }

                // Get FeatureClass
                FeatureClass featureClass = (FeatureClass)dataset;

                // Only continue if FeatureClass belongs to the Topology
                bool participate = false;
                foreach (ControllerMembership controller in featureClass.ControllerMemberships)
                {
                    if (controller is TopologyControllerMembership)
                    {
                        TopologyControllerMembership topologyControllerMembership = (TopologyControllerMembership)controller;
                        if (topologyControllerMembership.TopologyName == this._topology.Name)
                        {
                            participate = true;
                            break;
                        }
                    }
                }
                if (!participate)
                {
                    continue;
                }

                // Get Subtypes
                List <Subtype> subtypes = featureClass.GetSubtypes();

                // Add From FetaureClasses and Subtypes
                EsriShape <FeatureClass> featureClass1 = new EsriShape <FeatureClass>(featureClass);
                this.Shapes.Add(this.Shapes.CreateKey(), featureClass1);
                listFeatureClassFrom.Add(featureClass1);

                // Add Line from FeatureDataset to FeatureClass
                Arrow arrow1 = new Arrow();
                arrow1.BorderColor    = ModelSettings.Default.DisabledLined;
                arrow1.DrawBackground = false;
                Line line1 = new Line(featureDataset1, featureClass1);
                line1.End.AllowMove   = false;
                line1.End.Marker      = arrow1;
                line1.Start.AllowMove = false;
                line1.BorderColor     = ModelSettings.Default.DisabledLined;
                this.Lines.Add(this.Lines.CreateKey(), line1);

                // Add Subtypes and Link to FeatureClass
                foreach (Subtype subtype in subtypes)
                {
                    EsriShape <Subtype> sub = new EsriShape <Subtype>(subtype);
                    this.Shapes.Add(this.Shapes.CreateKey(), sub);
                    listSubtypeFrom.Add(sub);
                    Arrow arrow3 = new Arrow();
                    arrow3.BorderColor    = ModelSettings.Default.DisabledLined;
                    arrow3.DrawBackground = false;
                    Line line = new Line(featureClass1, sub);
                    line.End.AllowMove   = false;
                    line.End.Marker      = arrow3;
                    line.Start.AllowMove = false;
                    line.BorderColor     = ModelSettings.Default.DisabledLined;
                    this.Lines.Add(this.Lines.CreateKey(), line);
                }

                // Add To FetaureClasses and Subtypes
                EsriShape <FeatureClass> featureClass2 = new EsriShape <FeatureClass>(featureClass);
                this.Shapes.Add(this.Shapes.CreateKey(), featureClass2);
                listFeatureClassTo.Add(featureClass2);

                // Add Line from FeatureDataset to FeatureClass
                Arrow arrow2 = new Arrow();
                arrow2.BorderColor    = ModelSettings.Default.DisabledLined;
                arrow2.DrawBackground = false;
                Line line2 = new Line(featureClass2, featureDataset2);
                line2.End.AllowMove   = false;
                line2.Start.AllowMove = false;
                line2.Start.Marker    = arrow2;
                line2.BorderColor     = ModelSettings.Default.DisabledLined;
                this.Lines.Add(this.Lines.CreateKey(), line2);

                // Add Subtyes and Link to FeatureClasses
                foreach (Subtype subtype in subtypes)
                {
                    EsriShape <Subtype> sub = new EsriShape <Subtype>(subtype);
                    this.Shapes.Add(this.Shapes.CreateKey(), sub);
                    listSubtypeTo.Add(sub);
                    Arrow arrow4 = new Arrow();
                    arrow4.BorderColor    = ModelSettings.Default.DisabledLined;
                    arrow4.DrawBackground = false;
                    Line line = new Line(sub, featureClass2);
                    line.End.AllowMove   = false;
                    line.Start.Marker    = arrow4;
                    line.Start.AllowMove = false;
                    line.BorderColor     = ModelSettings.Default.DisabledLined;
                    this.Lines.Add(this.Lines.CreateKey(), line);
                }
            }

            // Loop Through All Connectivity Rules
            foreach (TopologyRule topologyRule in this._topology.TopologyRules)
            {
                // Origin Table
                EsriTable origin = null;
                if (topologyRule.AllOriginSubtypes)
                {
                    origin = schemaModel.FindObjectClass(topologyRule.OriginClassId);
                }
                else
                {
                    origin = schemaModel.FindObjectClassOrSubtype(
                        topologyRule.OriginClassId,
                        topologyRule.OriginSubtype);
                }

                // Destination Table
                EsriTable destination = null;
                if (topologyRule.AllDestinationSubtypes)
                {
                    destination = schemaModel.FindObjectClass(topologyRule.DestinationClassId);
                }
                else
                {
                    destination = schemaModel.FindObjectClassOrSubtype(
                        topologyRule.DestinationClassId,
                        topologyRule.DestinationSubtype);
                }

                // Origin and Destination Shapes
                Shape shapeOrigin      = null;
                Shape shapeDestiantion = null;

                // Find Origin Shape in Diagram
                foreach (EsriShape <FeatureClass> f in listFeatureClassFrom)
                {
                    if (f.Parent == origin)
                    {
                        shapeOrigin = f;
                        break;
                    }
                }
                if (shapeOrigin == null)
                {
                    foreach (EsriShape <Subtype> s in listSubtypeFrom)
                    {
                        if (s.Parent == origin)
                        {
                            shapeOrigin = s;
                            break;
                        }
                    }
                }

                // Find Destination Shape in Diagram
                foreach (EsriShape <FeatureClass> f in listFeatureClassTo)
                {
                    if (f.Parent == destination)
                    {
                        shapeDestiantion = f;
                        break;
                    }
                }
                if (shapeDestiantion == null)
                {
                    foreach (EsriShape <Subtype> s in listSubtypeTo)
                    {
                        if (s.Parent == destination)
                        {
                            shapeDestiantion = s;
                            break;
                        }
                    }
                }

                // Skip if Origin and Destination Shapes not found
                if (shapeOrigin == null || shapeDestiantion == null)
                {
                    continue;
                }

                EsriLine <TopologyRule> line2 = new EsriLine <TopologyRule>(topologyRule, shapeOrigin, shapeDestiantion);
                this.Lines.Add(this.Lines.CreateKey(), line2);
            }

            // Perform Layout
            this.ExecuteLayout(typeof(HierarchicalLayout), true);

            // Resume and Refresh Model
            this.SuspendEvents = false;
            this.Resume();
            if (ModelSettings.Default.EnableUndoRedo)
            {
                this.UndoList.Resume();
            }
            this.Refresh();
        }
        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);

                if (context.PropertyDescriptor.ComponentType == typeof(RelationshipClass))
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "OriginClassName":
                    case "DestinationClassName":
                        if (text == string.Empty ||
                            text == Resources.TEXT_NONE_BR)
                        {
                            return(string.Empty);
                        }
                        return(text);
                    }
                }
                else if (context.PropertyDescriptor.ComponentType == typeof(EdgeConnectivityRule))
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "DefaultJunctionID":
                    case "FromClassID":
                    case "ToClassID":
                        if (text == string.Empty ||
                            text == Resources.TEXT_NONE_BR)
                        {
                            return(-1);
                        }
                        DiagrammerEnvironment de          = DiagrammerEnvironment.Default;
                        SchemaModel           model       = de.SchemaModel;
                        ObjectClass           objectClass = model.FindObjectClass(text);
                        if (objectClass == null)
                        {
                            return(-1);
                        }
                        return(objectClass.DSID);
                    }
                }
                else if (context.PropertyDescriptor.ComponentType == typeof(JunctionSubtype))
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "ClassID":
                        if (text == string.Empty ||
                            text == Resources.TEXT_NONE_BR)
                        {
                            return(-1);
                        }
                        DiagrammerEnvironment de          = DiagrammerEnvironment.Default;
                        SchemaModel           model       = de.SchemaModel;
                        ObjectClass           objectClass = model.FindObjectClass(text);
                        if (objectClass == null)
                        {
                            return(-1);
                        }
                        return(objectClass.DSID);
                    }
                }
                else if (context.PropertyDescriptor.ComponentType == typeof(RelationshipRule))
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "OriginClass":
                    case "DestinationClass":
                        if (text == string.Empty ||
                            text == Resources.TEXT_NONE_BR)
                        {
                            return(-1);
                        }
                        DiagrammerEnvironment de          = DiagrammerEnvironment.Default;
                        SchemaModel           model       = de.SchemaModel;
                        ObjectClass           objectClass = model.FindObjectClass(text);
                        if (objectClass == null)
                        {
                            return(-1);
                        }
                        return(objectClass.DSID);
                    }
                }
                else if (context.PropertyDescriptor.ComponentType == typeof(JunctionConnectivityRule))
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "EdgeClassID":
                    case "JunctionClassID":
                        if (text == string.Empty ||
                            text == Resources.TEXT_NONE_BR)
                        {
                            return(-1);
                        }
                        DiagrammerEnvironment de          = DiagrammerEnvironment.Default;
                        SchemaModel           model       = de.SchemaModel;
                        ObjectClass           objectClass = model.FindObjectClass(text);
                        if (objectClass == null)
                        {
                            return(-1);
                        }
                        return(objectClass.DSID);
                    }
                }
                else if (context.PropertyDescriptor.ComponentType == typeof(TopologyRule))
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "OriginClassId":
                    case "DestinationClassId":
                        if (text == string.Empty ||
                            text == Resources.TEXT_NONE_BR)
                        {
                            return(-1);
                        }
                        DiagrammerEnvironment de          = DiagrammerEnvironment.Default;
                        SchemaModel           model       = de.SchemaModel;
                        ObjectClass           objectClass = model.FindObjectClass(text);
                        if (objectClass == null)
                        {
                            return(-1);
                        }
                        return(objectClass.DSID);
                    }
                }
                else if (context.PropertyDescriptor.ComponentType == typeof(NetWeightAssociation))
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "TableName":
                        if (text == string.Empty ||
                            text == Resources.TEXT_NONE_BR)
                        {
                            return(string.Empty);
                        }
                        return(text);
                    }
                }
                else if (context.PropertyDescriptor.ComponentType == typeof(TerrainDataSource))
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "FeatureClassName":
                        if (text == string.Empty ||
                            text == Resources.TEXT_NONE_BR)
                        {
                            return(string.Empty);
                        }
                        return(text);
                    }
                }
            }

            return(base.ConvertFrom(context, culture, value));
        }