Ejemplo n.º 1
0
        public void Apply(ISchematicInMemoryDiagram inMemoryDiagram, ESRI.ArcGIS.esriSystem.ITrackCancel cancelTracker)
        {
            if (m_reducedNodeClassName == "" || inMemoryDiagram == null)
            {
                return;
            }

            // initialize the schematic rules helper
            ISchematicRulesHelper rulesHelper = new SchematicRulesHelperClass();

            rulesHelper.InitHelper(inMemoryDiagram);
            rulesHelper.KeepVertices = m_keepVertices;

            ////////////////////////
            // get the feature classes processed by the rule
            ISchematicDiagramClass diagramClass = null;

            try
            {
                diagramClass = inMemoryDiagram.SchematicDiagramClass;
            }
            catch { }

            if (diagramClass == null)
            {
                return;
            }
            ISchematicDataset schematicDataset = null;

            try
            {
                schematicDataset = diagramClass.SchematicDataset;
            }
            catch { }

            ISchematicElementClassContainer elementclassContainer = (ISchematicElementClassContainer)schematicDataset;

            if (elementclassContainer == null)
            {
                return;
            }

            ISchematicElementClass elementClassReducedNode = null;

            elementClassReducedNode = elementclassContainer.GetSchematicElementClass(m_reducedNodeClassName);

            ISchematicElementClass elementClassSuperspan = null;

            elementClassSuperspan = elementclassContainer.GetSchematicElementClass(m_superspanLinkClassName);

            if (elementClassSuperspan == null || elementClassReducedNode == null)
            {
                return;
            }

            ISchematicInMemoryFeatureClassContainer featureClassContainer = (ISchematicInMemoryFeatureClassContainer)inMemoryDiagram;

            if (featureClassContainer == null)
            {
                return;
            }

            ISchematicInMemoryFeatureClass superspanLinkClass = featureClassContainer.GetSchematicInMemoryFeatureClass(elementClassSuperspan);
            //
            /////////////////////////

            // fetch the superspan spatial reference
            IGeoDataset geoDataset = (IGeoDataset)superspanLinkClass;

            ISpatialReference spatialRef = null;

            if (geoDataset != null)
            {
                spatialRef = geoDataset.SpatialReference;
            }
            if (spatialRef == null)
            {
                return;
            }

            // Retrieve the schematic in memory feature nodes to reduce


            System.Collections.Generic.Dictionary <string, ISchematicInMemoryFeature> colSchfeatureNode = new Dictionary <string, ISchematicInMemoryFeature>();

            // get all feature of parent node class
            IEnumSchematicInMemoryFeature enumSchematicInMemoryFeature = inMemoryDiagram.GetSchematicInMemoryFeaturesByClass(elementClassReducedNode);

            // retain only the nodes of degree two
            RetainNodesDegreeTwo(enumSchematicInMemoryFeature, colSchfeatureNode, rulesHelper);    // there would be inserted a SQL query to also filter by attributes

            IProgressor msgProgressor = null;

            if (cancelTracker != null)
            {
                msgProgressor = cancelTracker.Progressor;
                IStepProgressor stepProgressor = (IStepProgressor)msgProgressor;
                if (stepProgressor != null)
                {
                    stepProgressor.MinRange  = 0;
                    stepProgressor.MaxRange  = colSchfeatureNode.Count;
                    stepProgressor.StepValue = 1;
                    stepProgressor.Position  = 0;
                    stepProgressor.Message   = m_description;
                    cancelTracker.Reset();
                    cancelTracker.Progressor = msgProgressor;
                    stepProgressor.Show();
                }
            }

            ISchematicInMemoryFeature schFeatureToReduce;

            foreach (KeyValuePair <string, ISchematicInMemoryFeature> kvp in colSchfeatureNode)
            {
                if (cancelTracker != null)
                {
                    if (cancelTracker.Continue() == false)
                    {
                        break;
                    }
                }

                schFeatureToReduce = colSchfeatureNode[kvp.Key];
                if (schFeatureToReduce != null)
                {
                    ReduceNode(rulesHelper, superspanLinkClass, spatialRef, schFeatureToReduce);
                }
            }


            // release memory
            colSchfeatureNode.Clear();
            colSchfeatureNode = null;
            rulesHelper       = null;
        }
		public void Init(ISchematicLayer schematicLayer)
		{
			// CR229717: Lost the ElementClass if the dockable window is deactivate
			if (schematicLayer == m_schematicLayer)
				if (m_schEltClass != null)
					return;

			try
			{
				if (schematicLayer == null)
					return;

				m_schematicLayer = schematicLayer;
				XmlNode col = null;
				String myString = "";

				m_schDataset = schematicLayer.SchematicDiagram.SchematicDiagramClass.SchematicDataset;

				m_schEltClassCont = (ISchematicElementClassContainer)m_schDataset;
				m_SchematicInMemoryDiagram = schematicLayer.SchematicInMemoryDiagram;

				m_dom = new XmlDocument();

				ISchematicDiagram schematicDiagram;
				schematicDiagram = m_SchematicInMemoryDiagram.SchematicDiagram;

				// get the path of the xml file that contains the definitions of the digitize dockable window
				String path;

				ISchematicDiagramClass schematicDiagramClass = schematicDiagram.SchematicDiagramClass;
				ISchematicAttributeContainer schematicAttributeContainer = (ISchematicAttributeContainer)schematicDiagramClass;

				ISchematicAttribute schematicAttribute = schematicAttributeContainer.GetSchematicAttribute("DigitizePropertiesLocation", true);

				if (schematicAttribute == null)
				{
					System.Windows.Forms.MessageBox.Show("Need an attribute named DigitizePropertiesLocation in the corresponding DiagramTemplate attributes");
					return;
				}

				path = (string)schematicAttribute.GetValue((ISchematicObject)schematicDiagram);

				if (IsRelative(path)) //Concat the workspace's path with this path
				{
					//current workspace path
					ISchematicDataset myDataset = schematicDiagramClass.SchematicDataset;
					if (myDataset != null)
					{
						ISchematicWorkspace mySchematicWorkspace = myDataset.SchematicWorkspace;
						if (mySchematicWorkspace != null)
						{
							ESRI.ArcGIS.Geodatabase.IWorkspace myWorkspace = mySchematicWorkspace.Workspace;
							if (myWorkspace != null)
							{
								string workspacePath = myWorkspace.PathName;
								//add "..\" to path to step back one level...
								string stepBack = "..\\";
								path = stepBack + path;

								path = System.IO.Path.Combine(workspacePath, path);
							}
						}
					}
				}
				//else keep the original hard path

				XmlReader reader = XmlReader.Create(path);

				m_dom.Load(reader);

				//Load Nodes
				XmlNodeList nodes = m_dom.SelectNodes("descendant::NodeFeature");

				//Clear combo box after each call
				cboNodeType.Items.Clear();
				foreach (XmlElement node in nodes)
				{
					cboNodeType.Items.Add(node.GetAttribute("FeatureClassName").ToString());
				}


				//Load Links
				XmlNodeList links = m_dom.SelectNodes("descendant::LinkFeature");

				//Clear combo box after each call
				cboLinkType.Items.Clear();
				foreach (XmlElement link in links)
				{
					cboLinkType.Items.Add(link.GetAttribute("FeatureClassName").ToString());
				}

				col = m_dom.SelectSingleNode("descendant::MandatoryColor");
				if (col != null)
				{
					myString = "System.Drawing.";
					myString = col.InnerText.ToString();
					m_MandatoryColor = System.Drawing.Color.FromName(myString);
				}

				col = m_dom.SelectSingleNode("descendant::FormName");
				if (col != null)
				{
					myString = col.InnerText.ToString();
					Text = myString;
				}


				XmlNodeList rels = m_dom.SelectNodes("descendant::Relation");
				if (rels.Count > 0)
					m_relations = rels;

				col = m_dom.SelectSingleNode("descendant::AutoClearAfterCreate");
				if ((col != null) && col.InnerText.ToString() == "True")
					m_autoClear = true;

			}
			catch (System.Exception e)
			{
				System.Windows.Forms.MessageBox.Show(e.Message);
			}

			m_Panel1 = Splitter.Panel1;
			m_Panel2 = Splitter.Panel2;
			m_curPanel = Splitter.Panel1;
			lblMode.Text = "Create Node";
			m_loading = false;
			m_clickPanel = false;
			m_schEltClass = null;

		}