コード例 #1
0
        ///////////////////////////////////////////////////////////////////////////////////////
        //
        // ISchematicAlgorithm interface : Defines its properties and methods (mandatory)
        //
        #region Implements ISchematicAlgorithm


        public bool get_Enabled(ISchematicLayer schematicLayer)
        {
            if (schematicLayer == null)
            {
                return(false);
            }

            // an algorithm needs the diagram to be in editing mode in order to run
            if (!schematicLayer.IsEditingSchematicDiagram())
            {
                return(false);
            }

            IEnumSchematicFeature enumFeatures = schematicLayer.GetSchematicSelectedFeatures(true);

            if (enumFeatures == null)
            {
                return(false);
            }

            // Count the selected nodes
            int iCount = 0;
            ISchematicFeature feature;

            enumFeatures.Reset();
            feature = enumFeatures.Next();
            while (feature != null && iCount < 2)
            {
                ISchematicInMemoryFeatureClass inMemoryFeatureClass;

                // just want SchematicFeatureNode
                inMemoryFeatureClass = (ISchematicInMemoryFeatureClass)feature.Class;

                if (inMemoryFeatureClass.SchematicElementClass.SchematicElementType == esriSchematicElementType.esriSchematicNodeType)
                {
                    iCount++;
                }
                feature = enumFeatures.Next();
            }

            if (iCount == 1)
            {
                return(true); // just want one selected node
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        // The execute part of the algorithm
        private void InternalExecute(ISchematicLayer schematicLayer, ISchematicInMemoryDiagram inMemoryDiagram, ITrackCancel CancelTracker)
        {
            if (schematicLayer == null || inMemoryDiagram == null)
                return;

            // get the diagram spatial reference for geometry transformation
            IGeoDataset geoDataset = (IGeoDataset)inMemoryDiagram;
            if (geoDataset == null)
                return;

            ISpatialReference spatialReference = geoDataset.SpatialReference;

            ISchematicDiagramClass diagramClass;
            diagramClass = inMemoryDiagram.SchematicDiagramClass;
            if (diagramClass == null)
                return;

            ISchematicDataset schemDataset;
            schemDataset = diagramClass.SchematicDataset;
            if (schemDataset == null)
                return;

            ISchematicAlgorithmEventsTrigger algorithmEventsTrigger;
            algorithmEventsTrigger = (ISchematicAlgorithmEventsTrigger)schemDataset;
            if (algorithmEventsTrigger == null)
                return;

            ESRI.ArcGIS.Carto.ILayer layer = (ESRI.ArcGIS.Carto.ILayer)schematicLayer;
            ISchematicAlgorithm algorithm = (ISchematicAlgorithm)this;

            bool canExecute = true;
            algorithmEventsTrigger.FireBeforeExecuteAlgorithm(layer, algorithm, ref canExecute);
            if (!canExecute)
                return; // cannot execute

            // Get the selected Features
            IEnumSchematicFeature enumFeatures = schematicLayer.GetSchematicSelectedFeatures(true);
            if (enumFeatures == null)
                return;

            // Count the selected nodes
            ISchematicInMemoryFeatureClass inMemoryFeatureClass;
            ISchematicFeature selectedFeature = null;
            int iCount = 0;
            ISchematicFeature schemFeature;
            enumFeatures.Reset();
            schemFeature = enumFeatures.Next();
            while (schemFeature != null && iCount < 2)
            {
                // just want SchematicFeatureNode
                inMemoryFeatureClass = (ISchematicInMemoryFeatureClass)schemFeature.Class;

                if (inMemoryFeatureClass.SchematicElementClass.SchematicElementType == esriSchematicElementType.esriSchematicNodeType)
                {
                    selectedFeature = schemFeature;
                    iCount++;
                }
                schemFeature = enumFeatures.Next();
            }

            if (iCount != 1 || selectedFeature == null)
                return; // must be only one

            // Create a new SchematicAnalystFindConnected algorithm
            ISchematicAnalystFindConnected analystFindConnected = null;

            analystFindConnected = (ISchematicAnalystFindConnected)new SchematicAnalystFindConnected();
            if (analystFindConnected == null)
                return;

            // Modifying parameters value for this SchematicAnalystFindConnected algorithm so that when it is launched the trace result appears a selection set{
            analystFindConnected.SelectLink = true;
            analystFindConnected.SelectNode = true;
            analystFindConnected.UseFlow = false;
            //pAnalystFindConnected.FlowDirection = 1;
            // Execute the algorithm
            analystFindConnected.Execute(schematicLayer, CancelTracker);

            // Retrieving the trace result (if any)
            IEnumSchematicFeature resultFeatures;
            resultFeatures = analystFindConnected.TraceResult;

            // free the schematic analyst COM object
            while (System.Runtime.InteropServices.Marshal.ReleaseComObject(analystFindConnected) > 0) { }

            if (resultFeatures == null || resultFeatures.Count < 1)
                return;

            // Apply the translation to the result
            //ISchematicInMemoryDiagram inMemoryDiagram;
            //inMemoryDiagram = schematicLayer.SchematicInMemoryDiagram;

            // Translating each traced elements according to the TranslationFactorX and TranslationFactorY parameters current values
            ISchematicInMemoryFeature inMemoryFeature;
            resultFeatures.Reset();
            while ((inMemoryFeature = (ISchematicInMemoryFeature)resultFeatures.Next()) != null)
            {
                IGeometry geometry;
                ITransform2D transform;
                esriSchematicElementType elemType;

                inMemoryFeatureClass = (ISchematicInMemoryFeatureClass)inMemoryFeature.Class;
                elemType = inMemoryFeatureClass.SchematicElementClass.SchematicElementType;
                if (elemType == esriSchematicElementType.esriSchematicLinkType || elemType == esriSchematicElementType.esriSchematicNodeType)
                {
                    // get a copy of the feature geometry
                    // then process the cloned geometry rather than the feature geometry directly
                    // Thus the modifications are stored in the heap of the current operation
                    // meaning it can be undone then redo (undo/redo)
                    geometry = inMemoryFeature.ShapeCopy;
                    // Convert the geometry into the SpatialReference of diagram class
                    geometry.Project(spatialReference);
                    // Move the geometry
                    transform = (ITransform2D)geometry;
                    if (transform != null)
                    {
                        transform.Move(m_paramX, m_paramY);

                        // Convert the moved geometry into the spatial reference of storage
                        // and feed it back to the feature
                        IObjectClass table = inMemoryFeature.Class;
                        if (table == null)
                            continue;

                        IGeoDataset featureGeoDataset = (IGeoDataset)table;
                        if (featureGeoDataset == null)
                            continue;

                        ISpatialReference featureSpatialRef = featureGeoDataset.SpatialReference;
                        if (featureSpatialRef == null)
                            continue;

                        IGeometry movedGeometry = (IGeometry)transform;
                        movedGeometry.Project(featureSpatialRef);


                        inMemoryFeature.Shape = movedGeometry;
                    }
                }
            }

            // After Execute part
            algorithmEventsTrigger.FireAfterExecuteAlgorithm(layer, algorithm);

            // update the diagram extent
            schematicLayer.UpdateExtent();
        }
コード例 #3
0
        ///////////////////////////////////////////////////////////////////////////////////////
        //
        // ISchematicAlgorithm interface : Defines its properties and methods (mandatory)
        //
        #region Implements ISchematicAlgorithm


        public bool get_Enabled(ISchematicLayer schematicLayer)
        {
            if (schematicLayer == null)
                return false;

            // an algorithm needs the diagram to be in editing mode in order to run
            if (!schematicLayer.IsEditingSchematicDiagram())
                return false;

            IEnumSchematicFeature enumFeatures = schematicLayer.GetSchematicSelectedFeatures(true);
            if (enumFeatures == null)
                return false;

            // Count the selected nodes
            int iCount = 0;
            ISchematicFeature feature;
            enumFeatures.Reset();
            feature = enumFeatures.Next();
            while (feature != null && iCount < 2)
            {
                ISchematicInMemoryFeatureClass inMemoryFeatureClass;

                // just want SchematicFeatureNode
                inMemoryFeatureClass = (ISchematicInMemoryFeatureClass)feature.Class;

                if (inMemoryFeatureClass.SchematicElementClass.SchematicElementType == esriSchematicElementType.esriSchematicNodeType)
                    iCount++;
                feature = enumFeatures.Next();
            }

            if (iCount == 1)
                return true; // just want one selected node
            else
                return false;
        }
コード例 #4
0
        // The execute part of the algorithm
        private void InternalExecute(ISchematicLayer schematicLayer, ISchematicInMemoryDiagram inMemoryDiagram, ITrackCancel CancelTracker)
        {
            if (schematicLayer == null || inMemoryDiagram == null)
            {
                return;
            }

            // get the diagram spatial reference for geometry transformation
            IGeoDataset geoDataset = (IGeoDataset)inMemoryDiagram;

            if (geoDataset == null)
            {
                return;
            }

            ISpatialReference spatialReference = geoDataset.SpatialReference;

            ISchematicDiagramClass diagramClass;

            diagramClass = inMemoryDiagram.SchematicDiagramClass;
            if (diagramClass == null)
            {
                return;
            }

            ISchematicDataset schemDataset;

            schemDataset = diagramClass.SchematicDataset;
            if (schemDataset == null)
            {
                return;
            }

            ISchematicAlgorithmEventsTrigger algorithmEventsTrigger;

            algorithmEventsTrigger = (ISchematicAlgorithmEventsTrigger)schemDataset;
            if (algorithmEventsTrigger == null)
            {
                return;
            }

            ESRI.ArcGIS.Carto.ILayer layer     = (ESRI.ArcGIS.Carto.ILayer)schematicLayer;
            ISchematicAlgorithm      algorithm = (ISchematicAlgorithm)this;

            bool canExecute = true;

            algorithmEventsTrigger.FireBeforeExecuteAlgorithm(layer, algorithm, ref canExecute);
            if (!canExecute)
            {
                return; // cannot execute
            }
            // Get the selected Features
            IEnumSchematicFeature enumFeatures = schematicLayer.GetSchematicSelectedFeatures(true);

            if (enumFeatures == null)
            {
                return;
            }

            // Count the selected nodes
            ISchematicInMemoryFeatureClass inMemoryFeatureClass;
            ISchematicFeature selectedFeature = null;
            int iCount = 0;
            ISchematicFeature schemFeature;

            enumFeatures.Reset();
            schemFeature = enumFeatures.Next();
            while (schemFeature != null && iCount < 2)
            {
                // just want SchematicFeatureNode
                inMemoryFeatureClass = (ISchematicInMemoryFeatureClass)schemFeature.Class;

                if (inMemoryFeatureClass.SchematicElementClass.SchematicElementType == esriSchematicElementType.esriSchematicNodeType)
                {
                    selectedFeature = schemFeature;
                    iCount++;
                }
                schemFeature = enumFeatures.Next();
            }

            if (iCount != 1 || selectedFeature == null)
            {
                return; // must be only one
            }
            // Create a new SchematicAnalystFindConnected algorithm
            ISchematicAnalystFindConnected analystFindConnected = null;

            analystFindConnected = (ISchematicAnalystFindConnected) new SchematicAnalystFindConnected();
            if (analystFindConnected == null)
            {
                return;
            }

            // Modifying parameters value for this SchematicAnalystFindConnected algorithm so that when it is launched the trace result appears a selection set{
            analystFindConnected.SelectLink = true;
            analystFindConnected.SelectNode = true;
            analystFindConnected.UseFlow    = false;
            //pAnalystFindConnected.FlowDirection = 1;
            // Execute the algorithm
            analystFindConnected.Execute(schematicLayer, CancelTracker);

            // Retrieving the trace result (if any)
            IEnumSchematicFeature resultFeatures;

            resultFeatures = analystFindConnected.TraceResult;

            // free the schematic analyst COM object
            while (System.Runtime.InteropServices.Marshal.ReleaseComObject(analystFindConnected) > 0)
            {
            }

            if (resultFeatures == null || resultFeatures.Count < 1)
            {
                return;
            }

            // Apply the translation to the result
            //ISchematicInMemoryDiagram inMemoryDiagram;
            //inMemoryDiagram = schematicLayer.SchematicInMemoryDiagram;

            // Translating each traced elements according to the TranslationFactorX and TranslationFactorY parameters current values
            ISchematicInMemoryFeature inMemoryFeature;

            resultFeatures.Reset();
            while ((inMemoryFeature = (ISchematicInMemoryFeature)resultFeatures.Next()) != null)
            {
                IGeometry                geometry;
                ITransform2D             transform;
                esriSchematicElementType elemType;

                inMemoryFeatureClass = (ISchematicInMemoryFeatureClass)inMemoryFeature.Class;
                elemType             = inMemoryFeatureClass.SchematicElementClass.SchematicElementType;
                if (elemType == esriSchematicElementType.esriSchematicLinkType || elemType == esriSchematicElementType.esriSchematicNodeType)
                {
                    // get a copy of the feature geometry
                    // then process the cloned geometry rather than the feature geometry directly
                    // Thus the modifications are stored in the heap of the current operation
                    // meaning it can be undone then redo (undo/redo)
                    geometry = inMemoryFeature.ShapeCopy;
                    // Convert the geometry into the SpatialReference of diagram class
                    geometry.Project(spatialReference);
                    // Move the geometry
                    transform = (ITransform2D)geometry;
                    if (transform != null)
                    {
                        transform.Move(m_paramX, m_paramY);

                        // Convert the moved geometry into the spatial reference of storage
                        // and feed it back to the feature
                        IObjectClass table = inMemoryFeature.Class;
                        if (table == null)
                        {
                            continue;
                        }

                        IGeoDataset featureGeoDataset = (IGeoDataset)table;
                        if (featureGeoDataset == null)
                        {
                            continue;
                        }

                        ISpatialReference featureSpatialRef = featureGeoDataset.SpatialReference;
                        if (featureSpatialRef == null)
                        {
                            continue;
                        }

                        IGeometry movedGeometry = (IGeometry)transform;
                        movedGeometry.Project(featureSpatialRef);


                        inMemoryFeature.Shape = movedGeometry;
                    }
                }
            }

            // After Execute part
            algorithmEventsTrigger.FireAfterExecuteAlgorithm(layer, algorithm);

            // update the diagram extent
            schematicLayer.UpdateExtent();
        }