private void Model_ElementRemoved(object sender, ElementsEventArgs e)
        {
            // Check GeometricNetwork
            if (this._geometricNetwork == null)
            {
                return;
            }

            // Get Element
            Element element = e.Value;

            if (element == null)
            {
                return;
            }
            EsriLine <EdgeConnectivityRule> line = element as EsriLine <EdgeConnectivityRule>;

            if (line == null)
            {
                return;
            }

            // Get Rule
            EdgeConnectivityRule rule = line.Parent;

            // Remove rule from relationship
            this._geometricNetwork.ConnectivityRules.Remove(rule);
        }
        //
        // PRIVATE METHODS
        //
        private void Model_ElementInserted(object sender, ElementsEventArgs e)
        {
            // Check GeometricNetwork
            if (this._geometricNetwork == null)
            {
                return;
            }

            // Get Element
            Element element = e.Value;

            if (element == null)
            {
                return;
            }
            EsriLine <EdgeConnectivityRule> line = element as EsriLine <EdgeConnectivityRule>;

            if (line == null)
            {
                return;
            }

            // Get Rule
            EdgeConnectivityRule rule = line.Parent;

            // Add Rule
            this._geometricNetwork.ConnectivityRules.Add(rule);
        }
Exemple #3
0
        public EdgeConnectivityRule(EdgeConnectivityRule prototype) : base(prototype)
        {
            this._fromClassID                = prototype.FromClassID;
            this._fromEdgeSubtypeCode        = prototype.FromEdgeSubtypeCode;
            this._toClassID                  = prototype.ToClassID;
            this._toEdgeSubtypeCode          = prototype.ToEdgeSubtypeCode;
            this._defaultJunctionID          = prototype.DefaultJunctionID;
            this._defaultJunctionSubtypeCode = prototype.DefaultJunctionSubtypeCode;

            // Clone Junction Subtypes
            this._junctionSubtypes = new List <JunctionSubtype>();
            foreach (JunctionSubtype junctionSubtype in prototype.JunctionSubtypes)
            {
                this._junctionSubtypes.Add((JunctionSubtype)junctionSubtype.Clone());
            }
        }
        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 EdgeConnectivityRule(EdgeConnectivityRule prototype) : base(prototype) {
            this._fromClassID = prototype.FromClassID;
            this._fromEdgeSubtypeCode = prototype.FromEdgeSubtypeCode;
            this._toClassID = prototype.ToClassID;
            this._toEdgeSubtypeCode = prototype.ToEdgeSubtypeCode;
            this._defaultJunctionID = prototype.DefaultJunctionID;
            this._defaultJunctionSubtypeCode = prototype.DefaultJunctionSubtypeCode;
 
            // Clone Junction Subtypes
            this._junctionSubtypes = new List<JunctionSubtype>();
            foreach (JunctionSubtype junctionSubtype in prototype.JunctionSubtypes) {
                this._junctionSubtypes.Add((JunctionSubtype)junctionSubtype.Clone());
            }
        }
        //
        // PUBLIC METHODS
        //
        public override void OpenModel()
        {
            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._geometricNetwork == null)
            {
                return;
            }

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

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

            // Get Parent FeatureDataset
            Dataset parent = this._geometricNetwork.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 allow Simle and Complex Edges
                switch (featureClass.FeatureType)
                {
                case esriFeatureType.esriFTSimpleEdge:
                case esriFeatureType.esriFTComplexEdge:
                    break;

                default:
                    continue;
                }
                //switch (featureClass.CLSID) {
                //    case EsriRegistry.CLASS_SIMPLEEDGE:
                //    case EsriRegistry.CLASS_COMPLEXEDGE:
                //        break;
                //    default:
                //        continue;
                //}

                // Only continue if FeatureClass belongs to the GeometricNetwork
                bool participate = false;
                foreach (ControllerMembership controller in featureClass.ControllerMemberships)
                {
                    if (controller is GeometricNetworkControllerMembership)
                    {
                        GeometricNetworkControllerMembership geometricNetworkControllerMembership = (GeometricNetworkControllerMembership)controller;
                        if (geometricNetworkControllerMembership.GeometricNetworkName == this._geometricNetwork.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 (ConnectivityRule connectivityRule in this._geometricNetwork.ConnectivityRules)
            {
                // Continue only if Edge Connectivity Rule
                if (!(connectivityRule is EdgeConnectivityRule))
                {
                    continue;
                }

                // Get Edge Connectivity Rule
                EdgeConnectivityRule edgeConnectivityRule = (EdgeConnectivityRule)connectivityRule;

                // Origin Table
                EsriTable origin = schemaModel.FindObjectClassOrSubtype(
                    edgeConnectivityRule.FromClassID,
                    edgeConnectivityRule.FromEdgeSubtypeCode);

                // Destination Table
                EsriTable destination = schemaModel.FindObjectClassOrSubtype(
                    edgeConnectivityRule.ToClassID,
                    edgeConnectivityRule.ToEdgeSubtypeCode);

                // 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 <EdgeConnectivityRule> line2 = new EsriLine <EdgeConnectivityRule>(edgeConnectivityRule, 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();
        }
        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 <EdgeConnectivityRule> line = element as EsriLine <EdgeConnectivityRule>;

            if (line == null)
            {
                return;
            }

            // Get EdgeConnectivityRule
            EdgeConnectivityRule 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.FromClassID         = -1;
                rule.FromEdgeSubtypeCode = -1;
            }
            else if (elementStart is EsriShape <FeatureClass> )
            {
                EsriShape <FeatureClass> shape = (EsriShape <FeatureClass>)elementStart;
                ObjectClass objectClass        = shape.Parent;
                rule.FromClassID         = objectClass.DSID;
                rule.FromEdgeSubtypeCode = 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.FromClassID         = -1;
                    rule.FromEdgeSubtypeCode = -1;
                }
                else
                {
                    rule.FromClassID         = objectClass.DSID;
                    rule.FromEdgeSubtypeCode = subtype.SubtypeCode;
                }
            }

            // Update End Class/Subtype
            if (elementEnd == null)
            {
                rule.ToClassID         = -1;
                rule.ToEdgeSubtypeCode = -1;
            }
            else if (elementEnd is EsriShape <FeatureClass> )
            {
                EsriShape <FeatureClass> shape = (EsriShape <FeatureClass>)elementEnd;
                ObjectClass objectClass        = shape.Parent;
                rule.ToClassID         = objectClass.DSID;
                rule.ToEdgeSubtypeCode = 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.ToClassID         = -1;
                    rule.ToEdgeSubtypeCode = -1;
                }
                else
                {
                    rule.ToClassID         = objectClass.DSID;
                    rule.ToEdgeSubtypeCode = subtype.SubtypeCode;
                }
            }

            // Resume Rule Events
            rule.Resume();
        }