示例#1
0
        private void ReportCumulativeValues(ISchematicInMemoryFeature schFeat1, ISchematicInMemoryFeature schFeat2, ISchematicInMemoryFeature schTargetFeat)
        {
            if (schFeat1 == null || schFeat2 == null || schTargetFeat == null)
            {
                return;
            }

            // assume the attribute field name is the same on every schematic feature link classes
            IFields linkFields = schFeat1.Fields;
            int     iIndex     = linkFields.FindField(m_lengthAttributeName);

            if (iIndex < 0)
            {
                return;             // attribute field does not exist
            }
            object value1 = schFeat1.get_Value(iIndex);

            linkFields = schFeat2.Fields;
            iIndex     = linkFields.FindField(m_lengthAttributeName);
            if (iIndex < 0)
            {
                return;             // attribute field does not exist
            }
            object value2 = schFeat2.get_Value(iIndex);

            double dValue1 = 0;
            double dValue2 = 0;

            if (!DBNull.Value.Equals(value1))
            {
                try
                {
                    dValue1 = Convert.ToDouble(value1);
                }
                catch { }
            }


            if (!DBNull.Value.Equals(value2))
            {
                try
                {
                    dValue2 = Convert.ToDouble(value2);
                }
                catch { }
            }


            // assume the values to be numeric
            double dlength = dValue1 + dValue2;

            linkFields = schTargetFeat.Fields;
            iIndex     = linkFields.FindField(m_lengthAttributeName);
            if (iIndex < 0)
            {
                return;             // attribute field does not exist
            }
            schTargetFeat.set_Value(iIndex, dlength);
        }
示例#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;
                }
            }
        }
		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;
				}
			}
		}
        private void ReportCumulativeValues(ISchematicInMemoryFeature schFeat1, ISchematicInMemoryFeature schFeat2, ISchematicInMemoryFeature schTargetFeat)
        {

            if (schFeat1 == null || schFeat2 == null || schTargetFeat == null)
                return;

            // assume the attribute field name is the same on every schematic feature link classes
            IFields linkFields = schFeat1.Fields;
            int iIndex = linkFields.FindField(m_lengthAttributeName);
            if (iIndex < 0) return; // attribute field does not exist
            object value1 = schFeat1.get_Value(iIndex);

            linkFields = schFeat2.Fields;
            iIndex = linkFields.FindField(m_lengthAttributeName);
            if (iIndex < 0) return; // attribute field does not exist
            object value2 = schFeat2.get_Value(iIndex);

            double dValue1 = 0;
            double dValue2 = 0;

            if (!DBNull.Value.Equals(value1))
            {
                try
                {
                    dValue1 = Convert.ToDouble(value1);
                }
                catch { }
            }


            if (!DBNull.Value.Equals(value2))
            {
                try
                {
                    dValue2 = Convert.ToDouble(value2);
                }
                catch{ }
            }


            // assume the values to be numeric
            double dlength    = dValue1 + dValue2;

            linkFields = schTargetFeat.Fields;
            iIndex = linkFields.FindField(m_lengthAttributeName);
            if (iIndex < 0) return; // attribute field does not exist
            schTargetFeat.set_Value(iIndex, dlength);
        }