예제 #1
0
        private bool SameIncidentLinkAttributeValue(IEnumSchematicInMemoryFeature enumInMemoryLinks, string attributeName, ISchematicRulesHelper ruleHelper)
        {
            ISchematicInMemoryFeature inMemoryFeature = null;

            enumInMemoryLinks.Reset();

            bool   bFirstVariant  = true;
            object vPreviousValue = null;
            object vCurrentValue  = null;

            inMemoryFeature = enumInMemoryLinks.Next();

            while (inMemoryFeature != null)
            {
                // Do not take account the link if the link is not displayed
                //
                // Search for an attribute with the given name
                //
                ISchematicElementClass schematicElementClass;
                schematicElementClass = inMemoryFeature.SchematicElementClass;
                ISchematicAttributeContainer attributeContainer = (ISchematicAttributeContainer)schematicElementClass;
                ISchematicAttribute          schematicAttribute = null;
                if (attributeContainer != null)
                {
                    schematicAttribute = attributeContainer.GetSchematicAttribute(attributeName, true);
                }

                if (schematicAttribute != null)
                {
                    ISchematicObject schematicObject = (ISchematicObject)inMemoryFeature;
                    vCurrentValue = schematicAttribute.GetValue(schematicObject);
                }
                else
                {
                    // If schematic attribute not existing ==> find a field in the associated feature
                    IObject iObject = null;

                    ISchematicInMemoryFeaturePrimaryAssociation primaryAssociation = (ISchematicInMemoryFeaturePrimaryAssociation)inMemoryFeature;
                    if (primaryAssociation != null)
                    {
                        iObject = primaryAssociation.AssociatedObject;
                    }

                    IRow row = (IRow)iObject;

                    int fieldIndex = 0;
                    if (row != null)
                    {
                        IFields fields = row.Fields;

                        if (fields != null)
                        {
                            fieldIndex = fields.FindField(attributeName);
                        }
                    }

                    if (fieldIndex > 0)
                    {
                        vCurrentValue = row.get_Value(fieldIndex);
                        if (DBNull.Value.Equals(vCurrentValue))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (bFirstVariant)
                {
                    vPreviousValue = vCurrentValue;
                    bFirstVariant  = false;
                }
                else
                {
                    // Compare PreviousValue and CurrentValue
                    if (vPreviousValue.GetType() != vCurrentValue.GetType())
                    {
                        return(false);
                    }

                    if (DBNull.Value.Equals(vPreviousValue) || DBNull.Value.Equals(vCurrentValue))
                    {
                        return(false);
                    }

                    if (vPreviousValue.GetType().FullName is System.String)//Speciale Case for string.
                    {
                        string str1 = (string)vPreviousValue;
                        string str2 = (string)vCurrentValue;
                        if (string.Compare(str1, str2, true) != 0)
                        {
                            return(false);
                        }
                    }
                    else if (vPreviousValue != vCurrentValue)// == or != operator compare for Variant match the right type.
                    {
                        return(false);
                    }
                }

                inMemoryFeature = enumInMemoryLinks.Next();
            }

            return(true);
        }
예제 #2
0
        void OnBeforeRemoveFeature(ISchematicInMemoryFeature inMemoryFeature, ref bool canRemove)
        {
            if (State != ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled)
            {
                return;
            }

            ESRI.ArcGIS.Geodatabase.IDataset esriData = (ESRI.ArcGIS.Geodatabase.IDataset)inMemoryFeature.SchematicDiagram.SchematicDiagramClass.SchematicDataset;

            //  Remove only elements contained in a specific Schematic dataset
            if (esriData.Name != SampleDatasetName)
            {
                return;
            }
            //  Remove only elements contained in a specific type of diagram
            if (inMemoryFeature.SchematicDiagram.SchematicDiagramClass.Name != DiagramClassName)
            {
                return;
            }

            canRemove = false;
            // can't remove SubStation
            if (inMemoryFeature.SchematicElementClass.Name == "InsidePlant_SubStation")
            {
                return;
            }

            ISchematicDiagramClass schemDiagramClass;

            schemDiagramClass = (ISchematicDiagramClass)inMemoryFeature.SchematicDiagram.SchematicDiagramClass;

            //  For this specific diagram type, we retrieve the datasource
            //  and the tables where the elements are stored
            ISchematicDataSource schemDataSource = schemDiagramClass.SchematicDataSource;

            string tableName = "";

            switch (inMemoryFeature.SchematicElementClass.SchematicElementType)
            {
            case esriSchematicElementType.esriSchematicNodeType:
                tableName = TableNameNodes;
                break;

            case esriSchematicElementType.esriSchematicLinkType:
                tableName = TableNameLinks;
                break;

            case esriSchematicElementType.esriSchematicDrawingType:
                return;

                break;
            }

            // Retrieve Feature Workspace
            ESRI.ArcGIS.Geodatabase.IWorkspace        esriWorkspace        = (ESRI.ArcGIS.Geodatabase.IWorkspace)schemDataSource.Object;
            ESRI.ArcGIS.Geodatabase.IFeatureWorkspace esriFeatureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)esriWorkspace;

            // Get Attributes values
            ISchematicAttributeContainer schemAttribCont       = (ISchematicAttributeContainer)inMemoryFeature.SchematicElementClass;
            ISchematicAttributeContainer schemFatherAttribCont = (ISchematicAttributeContainer)inMemoryFeature.SchematicElementClass.Parent;

            if ((!(schemAttribCont.GetSchematicAttribute(AttributeNameObjectID, false) == null) ||
                 !(schemFatherAttribCont.GetSchematicAttribute(AttributeNameObjectID, false) == null)))
            {
                int indField = inMemoryFeature.Fields.FindFieldByAliasName(AttributeNameObjectID);
                int OID      = int.Parse(inMemoryFeature.get_Value(indField).ToString(), System.Globalization.NumberStyles.Integer);
                //Get table and row
                ESRI.ArcGIS.Geodatabase.ITable esriTable = esriFeatureWorkspace.OpenTable(tableName);
                ESRI.ArcGIS.Geodatabase.IRow   esriRow   = esriTable.GetRow(OID);

                //  When the row is identified in the table, it is deleted and
                //  the CanRemove returns True so that the associated
                //  schematic element is graphically removed from the active diagram
                if (!(esriRow == null))
                {
                    esriRow.Delete();
                    canRemove = true;
                }
            }
        }