private void Model_ElementRemoved(object sender, ElementsEventArgs 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;

            // Remove rule from relationship
            this._relationshipClass.RelationshipRules.Remove(rule);
        }
Esempio n. 2
0
 public RelationshipRule(RelationshipRule prototype) : base(prototype)
 {
     this._destinationClass              = prototype.DestinationClass;
     this._destinationSubtype            = prototype.DestinationSubtype;
     this._originClass                   = prototype.OriginClass;
     this._originSubtype                 = prototype.OriginSubtype;
     this._destinationMinimumCardinality = prototype.DestinationMinimumCardinality;
     this._destinationMaximumCardinality = prototype.DestinationMaximumCardinality;
     this._originMinimumCardinality      = prototype.OriginMinimumCardinality;
     this._originMaximumCardinality      = prototype.OriginMaximumCardinality;
 }
        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();
        }
        //
        // CONSTRUCTOR
        //
        public RelationshipClass(IXPathNavigable path) : base(path)
        {
            // Get Navigator
            XPathNavigator navigator = path.CreateNavigator();

            // Get Model
            SchemaModel model = (SchemaModel)base.Container;

            // <Cardinality></Cardinality>
            XPathNavigator navigatorCardinality = navigator.SelectSingleNode(Xml.CARDINALITY);

            if (navigatorCardinality != null)
            {
                this._cardinality = (esriRelCardinality)Enum.Parse(typeof(esriRelCardinality), navigatorCardinality.Value, true);
            }

            // <Notification></Notification>
            XPathNavigator navigatorNotification = navigator.SelectSingleNode(Xml.NOTIFICATION);

            if (navigatorNotification != null)
            {
                this._notification = (esriRelNotification)Enum.Parse(typeof(esriRelNotification), navigatorNotification.Value, true);
            }

            // <IsComposite>false</IsComposite>
            XPathNavigator navigatorIsComposite = navigator.SelectSingleNode(Xml.ISCOMPOSITE);

            if (navigatorIsComposite != null)
            {
                this._isComposite = navigatorIsComposite.ValueAsBoolean;
            }

            // <OriginClassNames></OriginClassNames>
            XPathNavigator navigatorOriginClassNames = navigator.SelectSingleNode(string.Format("{0}/{1}", Xml.ORIGINCLASSNAMES, Xml.NAME)); //  "OriginClassNames/Name");

            if (navigatorOriginClassNames != null)
            {
                this._originClassNames = navigatorOriginClassNames.Value;
            }

            // <DestinationClassNames></DestinationClassNames>
            XPathNavigator navigatorDestinationClassNames = navigator.SelectSingleNode(string.Format("{0}/{1}", Xml.DESTINATIONCLASSNAMES, Xml.NAME)); //"DestinationClassNames/Name");

            if (navigatorDestinationClassNames != null)
            {
                this._destinationClassNames = navigatorDestinationClassNames.Value;
            }

            // <KeyType></KeyType>
            XPathNavigator navigatorKeyType = navigator.SelectSingleNode(Xml.KEYTYPE);

            if (navigatorKeyType != null)
            {
                this._keyType = (esriRelKeyType)Enum.Parse(typeof(esriRelKeyType), navigatorKeyType.Value, true);
            }

            // <ClassKey></ClassKey>
            XPathNavigator navigatorClassKey = navigator.SelectSingleNode(Xml.CLASSKEY);

            if (navigatorClassKey != null)
            {
                this._classKey = (esriRelClassKey)Enum.Parse(typeof(esriRelClassKey), navigatorClassKey.Value, true);
            }

            // <ForwardPathLabel></ForwardPathLabel>
            XPathNavigator navigatorForwardPathLabel = navigator.SelectSingleNode(Xml.FORWARDPATHLABEL);

            if (navigatorForwardPathLabel != null)
            {
                this._forwardPathLabel = navigatorForwardPathLabel.Value;
            }

            // <BackwardPathLabel></BackwardPathLabel>
            XPathNavigator navigatorBackwardPathLabel = navigator.SelectSingleNode(Xml.BACKWARDPATHLABEL);

            if (navigatorBackwardPathLabel != null)
            {
                this._backwardPathLabel = navigatorBackwardPathLabel.Value;
            }

            // <IsReflexive></IsReflexive>
            XPathNavigator navigatorIsReflexive = navigator.SelectSingleNode(Xml.ISREFLEXIVE);

            if (navigatorIsReflexive != null)
            {
                this._isReflexive = navigatorIsReflexive.ValueAsBoolean;
            }

            // <OriginClassKeys><RelationshipClassKey></RelationshipClassKey></OriginClassKeys>
            // <DestinationClassKeys><RelationshipClassKey></RelationshipClassKey></DestinationClassKeys>
            string            xpath = string.Format("{0}/{2} | {1}/{2}", Xml.ORIGINCLASSKEYS, Xml.DESTINATIONCLASSKEYS, Xml.RELATIONSHIPCLASSKEY);
            XPathNodeIterator interatorClassKeys = navigator.Select(xpath); // "OriginClassKeys/RelationshipClassKey | DestinationClassKeys/RelationshipClassKey");

            while (interatorClassKeys.MoveNext())
            {
                // Get <RelationshipClassKey>
                XPathNavigator navigatorClassKeys = interatorClassKeys.Current;

                // Get <KeyRole>
                XPathNavigator navigatorKeyRole = navigatorClassKeys.SelectSingleNode(Xml.KEYROLE);
                if (navigatorKeyRole == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(navigatorKeyRole.Value))
                {
                    continue;
                }
                string keyRole = navigatorKeyRole.Value;

                // Get <ObjectKeyName>
                XPathNavigator navigatorObjectKeyName = navigatorClassKeys.SelectSingleNode(Xml.OBJECTKEYNAME);
                if (navigatorObjectKeyName == null)
                {
                    continue;
                }

                // Set Relationship Keys
                if (keyRole == esriRelKeyRole.esriRelKeyRoleOriginPrimary.ToString())
                {
                    this._originPrimary = navigatorObjectKeyName.Value;
                }
                else if (keyRole == esriRelKeyRole.esriRelKeyRoleOriginForeign.ToString())
                {
                    this._originForeign = navigatorObjectKeyName.Value;
                }
                else if (keyRole == esriRelKeyRole.esriRelKeyRoleDestinationPrimary.ToString())
                {
                    this._destinationPrimary = navigatorObjectKeyName.Value;
                }
                else if (keyRole == esriRelKeyRole.esriRelKeyRoleDestinationForeign.ToString())
                {
                    this._destinationForeign = navigatorObjectKeyName.Value;
                }
            }

            // <RelationshipRules><RelationshipRule></RelationshipRule></RelationshipRules>
            this._relationshipRules = new List <RelationshipRule>();
            XPathNodeIterator interatorRelationshipRule = navigator.Select(string.Format("{0}/{1}", Xml.RELATIONSHIPRULES, Xml.RELATIONSHIPRULE)); // "RelationshipRules/RelationshipRule");

            while (interatorRelationshipRule.MoveNext())
            {
                // Get <RelationshipRule>
                XPathNavigator navigatorRelationshipRule = interatorRelationshipRule.Current;

                // Create Relationship Rule
                RelationshipRule relationshipRule = new RelationshipRule(navigatorRelationshipRule);

                // Add Rule to Collection
                this._relationshipRules.Add(relationshipRule);
            }
        }
 public RelationshipRule(RelationshipRule prototype): base(prototype) {
     this._destinationClass = prototype.DestinationClass;
     this._destinationSubtype = prototype.DestinationSubtype;
     this._originClass = prototype.OriginClass;
     this._originSubtype = prototype.OriginSubtype;
     this._destinationMinimumCardinality = prototype.DestinationMinimumCardinality;
     this._destinationMaximumCardinality = prototype.DestinationMaximumCardinality;
     this._originMinimumCardinality = prototype.OriginMinimumCardinality;
     this._originMaximumCardinality = prototype.OriginMaximumCardinality;
 }
        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);
        }
        //
        // CONSTRUCTOR
        //
        public RelationshipClass(IXPathNavigable path) : base(path) {
            // Get Navigator
            XPathNavigator navigator = path.CreateNavigator();

            // Get Model
            SchemaModel model = (SchemaModel)base.Container;

            // <Cardinality></Cardinality>
            XPathNavigator navigatorCardinality = navigator.SelectSingleNode(Xml.CARDINALITY);
            if (navigatorCardinality != null) {
                this._cardinality = (esriRelCardinality)Enum.Parse(typeof(esriRelCardinality), navigatorCardinality.Value, true);
            }

            // <Notification></Notification> 
            XPathNavigator navigatorNotification = navigator.SelectSingleNode(Xml.NOTIFICATION);
            if (navigatorNotification != null) {
                this._notification = (esriRelNotification)Enum.Parse(typeof(esriRelNotification), navigatorNotification.Value, true);
            }

            // <IsComposite>false</IsComposite> 
            XPathNavigator navigatorIsComposite = navigator.SelectSingleNode(Xml.ISCOMPOSITE);
            if (navigatorIsComposite != null) {
                this._isComposite = navigatorIsComposite.ValueAsBoolean;
            }

            // <OriginClassNames></OriginClassNames>
            XPathNavigator navigatorOriginClassNames = navigator.SelectSingleNode(string.Format("{0}/{1}", Xml.ORIGINCLASSNAMES, Xml.NAME)); //  "OriginClassNames/Name");
            if (navigatorOriginClassNames != null) {
                this._originClassNames = navigatorOriginClassNames.Value;
            }

            // <DestinationClassNames></DestinationClassNames>
            XPathNavigator navigatorDestinationClassNames = navigator.SelectSingleNode(string.Format("{0}/{1}", Xml.DESTINATIONCLASSNAMES, Xml.NAME)); //"DestinationClassNames/Name");
            if (navigatorDestinationClassNames != null) {
                this._destinationClassNames = navigatorDestinationClassNames.Value;
            }

            // <KeyType></KeyType> 
            XPathNavigator navigatorKeyType = navigator.SelectSingleNode(Xml.KEYTYPE);
            if (navigatorKeyType != null) {
                this._keyType = (esriRelKeyType)Enum.Parse(typeof(esriRelKeyType), navigatorKeyType.Value, true);
            }

            // <ClassKey></ClassKey> 
            XPathNavigator navigatorClassKey = navigator.SelectSingleNode(Xml.CLASSKEY);
            if (navigatorClassKey != null) {
                this._classKey = (esriRelClassKey)Enum.Parse(typeof(esriRelClassKey), navigatorClassKey.Value, true);
            }

            // <ForwardPathLabel></ForwardPathLabel> 
            XPathNavigator navigatorForwardPathLabel = navigator.SelectSingleNode(Xml.FORWARDPATHLABEL);
            if (navigatorForwardPathLabel != null) {
                this._forwardPathLabel = navigatorForwardPathLabel.Value;
            }

            // <BackwardPathLabel></BackwardPathLabel> 
            XPathNavigator navigatorBackwardPathLabel = navigator.SelectSingleNode(Xml.BACKWARDPATHLABEL);
            if (navigatorBackwardPathLabel != null) {
                this._backwardPathLabel = navigatorBackwardPathLabel.Value;
            }

            // <IsReflexive></IsReflexive>
            XPathNavigator navigatorIsReflexive = navigator.SelectSingleNode(Xml.ISREFLEXIVE);
            if (navigatorIsReflexive != null) {
                this._isReflexive = navigatorIsReflexive.ValueAsBoolean;
            }

            // <OriginClassKeys><RelationshipClassKey></RelationshipClassKey></OriginClassKeys>
            // <DestinationClassKeys><RelationshipClassKey></RelationshipClassKey></DestinationClassKeys>
            string xpath = string.Format("{0}/{2} | {1}/{2}", Xml.ORIGINCLASSKEYS, Xml.DESTINATIONCLASSKEYS, Xml.RELATIONSHIPCLASSKEY);
            XPathNodeIterator interatorClassKeys = navigator.Select(xpath); // "OriginClassKeys/RelationshipClassKey | DestinationClassKeys/RelationshipClassKey");
            while (interatorClassKeys.MoveNext()) {
                // Get <RelationshipClassKey>
                XPathNavigator navigatorClassKeys = interatorClassKeys.Current;

                // Get <KeyRole>
                XPathNavigator navigatorKeyRole = navigatorClassKeys.SelectSingleNode(Xml.KEYROLE);
                if (navigatorKeyRole == null){continue;}
                if (string.IsNullOrEmpty(navigatorKeyRole.Value)){continue;}
                string keyRole = navigatorKeyRole.Value;

                // Get <ObjectKeyName>
                XPathNavigator navigatorObjectKeyName = navigatorClassKeys.SelectSingleNode(Xml.OBJECTKEYNAME);
                if (navigatorObjectKeyName == null){continue;}

                // Set Relationship Keys
                if (keyRole == esriRelKeyRole.esriRelKeyRoleOriginPrimary.ToString()){
                    this._originPrimary = navigatorObjectKeyName.Value;
                }
                else if (keyRole == esriRelKeyRole.esriRelKeyRoleOriginForeign.ToString()){
                    this._originForeign = navigatorObjectKeyName.Value;
                }
                else if (keyRole == esriRelKeyRole.esriRelKeyRoleDestinationPrimary.ToString()){
                    this._destinationPrimary = navigatorObjectKeyName.Value;
                }
                else if (keyRole == esriRelKeyRole.esriRelKeyRoleDestinationForeign.ToString()){
                    this._destinationForeign = navigatorObjectKeyName.Value;
                }
            }

            // <RelationshipRules><RelationshipRule></RelationshipRule></RelationshipRules>
            this._relationshipRules = new List<RelationshipRule>();
            XPathNodeIterator interatorRelationshipRule = navigator.Select(string.Format("{0}/{1}", Xml.RELATIONSHIPRULES, Xml.RELATIONSHIPRULE)); // "RelationshipRules/RelationshipRule");
            while (interatorRelationshipRule.MoveNext()) {
                // Get <RelationshipRule>
                XPathNavigator navigatorRelationshipRule = interatorRelationshipRule.Current;

                // Create Relationship Rule
                RelationshipRule relationshipRule = new RelationshipRule(navigatorRelationshipRule);

                // Add Rule to Collection
                this._relationshipRules.Add(relationshipRule);
            }
        }