private void Updatecontainers(ESRI.ArcGIS.Schematic.ISchematicLayer schLayer)
        {
            if (schLayer == null)
            {
                return;
            }

            // get the inMemorydiagram if any
            ISchematicInMemoryDiagram inMemoryDiagram;

            inMemoryDiagram = schLayer.SchematicInMemoryDiagram;
            if (inMemoryDiagram == null)
            {
                return;
            }

            bool bCreate = false;

            // create or remove relations between containers and their contents
            if (this.State == ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled)
            {
                bCreate = true;
            }

            ISchematicElementClass        schemContainerClass = null;
            ISchematicElementClass        schemElementClass;
            ISchematicElementClass        schemStationClass = null;
            IEnumSchematicInMemoryFeature enumElementsInContainer;
            IEnumSchematicInMemoryFeature enumContainerElements;
            ISchematicInMemoryFeature     schemFeature          = null;
            ISchematicInMemoryFeature     schemContainerFeature = null;
            object feederOID;
            string containerNameID;
            IEnumSchematicElementClass   enumElementClass;
            ISchematicAttributeContainer schemAttributeContainer;
            ISchematicAttribute          schemAttributeRelatedFeeder;
            //ISchematicElement schemElement ;
            ISchematicRelationController     schemRelationController     = null;
            ISchematicRelationControllerEdit schemRelationControllerEdit = null;
            Collection colContElem = new Collection();

            // Getting SchematicFeature Class Stations and Containers
            enumElementClass = inMemoryDiagram.SchematicDiagramClass.AssociatedSchematicElementClasses;
            enumElementClass.Reset();
            schemElementClass = enumElementClass.Next();

            while (schemElementClass != null)
            {
                if (schemElementClass.Name == "Stations")
                {
                    schemStationClass = schemElementClass;
                }
                if (schemElementClass.Name == "Containers")
                {
                    schemContainerClass = schemElementClass;
                }
                if (schemStationClass != null && schemContainerClass != null)
                {
                    break;
                }

                schemElementClass = enumElementClass.Next();
            }
            // go out if schemStationClass or schemContainerClass are null
            if (schemStationClass == null || schemContainerClass == null)
            {
                return;
            }

            // Getting the Stations elements that will be displayed in the containers
            enumElementsInContainer = inMemoryDiagram.GetSchematicInMemoryFeaturesByClass(schemStationClass);
            if (enumElementsInContainer == null)
            {
                return;
            }

            // Creating the Schematic Container Manager
            schemRelationController = new SchematicRelationController();

            // Creating the Schematic Container Editor that will be used to define the relation between the stations and their container
            schemRelationControllerEdit = (ISchematicRelationControllerEdit)schemRelationController;

            // Defining each Container element as a schematic container
            enumContainerElements = inMemoryDiagram.GetSchematicInMemoryFeaturesByClass(schemContainerClass);

            // Add Container Element to a collection
            enumContainerElements.Reset();
            schemContainerFeature = enumContainerElements.Next();
            while (schemContainerFeature != null)
            {
                colContElem.Add(schemContainerFeature, schemContainerFeature.Name, null, null);
                schemContainerFeature = enumContainerElements.Next();
            }

            // Setting the relation between each station and its related container
            enumElementsInContainer.Reset();
            schemFeature = enumElementsInContainer.Next();

            while (schemFeature != null)
            {
                // The relation is specified by the RelatedFeeder attribute value defined for each station
                schemAttributeContainer     = (ISchematicAttributeContainer)schemFeature.SchematicElementClass;
                schemAttributeRelatedFeeder = schemAttributeContainer.GetSchematicAttribute("RelatedFeeder", false);

                feederOID = schemAttributeRelatedFeeder.GetValue((ISchematicObject)schemFeature);

                if (feederOID != null)
                {
                    containerNameID = "Container-" + feederOID.ToString();

                    try
                    {
                        // Retrieve Container Element in the collection
                        schemContainerFeature = (ISchematicInMemoryFeature)colContElem[containerNameID];

                        if (bCreate)
                        {
                            schemRelationControllerEdit.CreateRelation(schemFeature, schemContainerFeature); // Create relation
                        }
                        else
                        {
                            schemRelationControllerEdit.DeleteRelation(schemFeature); // delete child relation
                        }
                    }
                    catch { }
                }

                schemContainerFeature = null;
                schemFeature          = enumElementsInContainer.Next();
            }

            if (!bCreate)
            {
                // Force container geometry
                enumContainerElements.Reset();
                while ((schemContainerFeature = enumContainerElements.Next()) != null)
                {
                    try
                    {
                        // set an empty geometry
                        // container does not have content at this stage
                        Polygon   emptyRectangle    = new Polygon();
                        IGeometry ContainerGeometry = (IGeometry)emptyRectangle;
                        schemContainerFeature.Shape = ContainerGeometry;
                    }
                    catch { }
                }
            }

            IActiveView activeView = (IActiveView)ArcMap.Document.FocusMap;

            if (activeView != null)
            {
                activeView.ContentsChanged();
                activeView.Refresh();
            }
        }
 private ISchematicInMemoryFeatureClass GetSchematicInMemoryFeatureClass(ISchematicInMemoryDiagram inMemoryDiagram, ISchematicElementClass eltClass)
 {
     ISchematicInMemoryFeatureClassContainer SchInMemoryFeatureClassContainer = (ISchematicInMemoryFeatureClassContainer)inMemoryDiagram;
     return SchInMemoryFeatureClassContainer.GetSchematicInMemoryFeatureClass(eltClass);
 }
Exemple #3
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 Apply(ISchematicInMemoryDiagram inMemoryDiagram, ESRI.ArcGIS.esriSystem.ITrackCancel cancelTracker)
        {
            ISchematicRulesHelper rulesHelper = new SchematicRulesHelperClass();

            System.Collections.Generic.Dictionary <string, ISchematicInMemoryFeature> colSchfeatureNode = new Dictionary <string, ISchematicInMemoryFeature>();
            rulesHelper.InitHelper(inMemoryDiagram);
            rulesHelper.KeepVertices = true;

            ISchematicDiagramClass     diagramClass = null;
            ISchematicElementClass     elementClass;
            ISchematicElementClass     elementClassParentNode = null;
            IEnumSchematicElementClass enumSchEltCls;

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

            if (diagramClass == null)
            {
                return;
            }

            enumSchEltCls = diagramClass.AssociatedSchematicElementClasses;

            if (enumSchEltCls.Count == 0)
            {
                return;
            }

            enumSchEltCls.Reset();
            elementClass = enumSchEltCls.Next();

            while (elementClass != null)
            {
                if (elementClass.Name == m_parentNodeClassName)
                {
                    elementClassParentNode = elementClass;
                    m_parentNodeClass      = GetSchematicInMemoryFeatureClass(inMemoryDiagram, elementClass);
                }

                if (elementClass.Name == m_targetNodeClassName)
                {
                    m_targetNodeClass = GetSchematicInMemoryFeatureClass(inMemoryDiagram, elementClass);
                }

                if (elementClass.Name == m_targetLinkClassName)
                {
                    m_targetLinkClass = GetSchematicInMemoryFeatureClass(inMemoryDiagram, elementClass);
                }

                elementClass = enumSchEltCls.Next();
            }

            if (m_parentNodeClass == null || m_targetNodeClass == null || m_targetLinkClass == null)
            {
                return;
            }

            IEnumSchematicInMemoryFeature enumSchematicInMemoryFeature;

            // list nodes degree two
            // get all feature of parent node class
            enumSchematicInMemoryFeature = inMemoryDiagram.GetSchematicInMemoryFeaturesByClass(elementClassParentNode);
            enumSchematicInMemoryFeature.Reset();

            // add the node into collection if it contains only 2 links displayed.
            AddNodesDegreeTwo(enumSchematicInMemoryFeature, colSchfeatureNode, rulesHelper);
            ISchematicInMemoryFeature schFeatureParent;

            foreach (KeyValuePair <string, ISchematicInMemoryFeature> kvp in colSchfeatureNode)
            {
                schFeatureParent = colSchfeatureNode[kvp.Key];

                if (schFeatureParent == null)
                {
                    continue;
                }

                // get 2 links connected of eache feature node
                IEnumSchematicInMemoryFeature enumLinks = rulesHelper.GetDisplayedIncidentLinks((ISchematicInMemoryFeatureNode)schFeatureParent, esriSchematicEndPointType.esriSchematicOriginOrExtremityNode);
                // enumLinks surely not null    and it contain 2 links displayed

                double angle1, angle2, angleBisector;
                bool   first = true;

                angle1 = angle2 = angleBisector = 0;
                IPoint pointParent = null;
                ISchematicInMemoryFeatureNodeGeometry geoParent;
                geoParent = (ISchematicInMemoryFeatureNodeGeometry)schFeatureParent;

                pointParent = geoParent.InitialPosition;
                IPoint pointSon        = null;
                bool   enableCalculate = true;

                ISchematicInMemoryFeature schInMemoryFeature = enumLinks.Next();

                ISchematicInMemoryFeatureLink schInMemoryLink = (ISchematicInMemoryFeatureLink)schInMemoryFeature;
                while (schInMemoryLink != null)
                {
                    ISchematicInMemoryFeatureNodeGeometry nodeGeo;
                    // get angle of 2 links connected
                    if (schInMemoryLink.FromNode.Name == schFeatureParent.Name)
                    {
                        nodeGeo = (ISchematicInMemoryFeatureNodeGeometry)schInMemoryLink.ToNode;
                    }
                    else
                    {
                        nodeGeo = (ISchematicInMemoryFeatureNodeGeometry)schInMemoryLink.FromNode;
                    }

                    if (nodeGeo == null)
                    {
                        enableCalculate = false;
                        break;
                    }

                    pointSon = nodeGeo.InitialPosition;
                    if (first)
                    {
                        angle1 = CalculateAngle(pointParent, pointSon);
                        first  = false;
                    }
                    else
                    {
                        angle2 = CalculateAngle(pointParent, pointSon);
                    }

                    schInMemoryFeature = enumLinks.Next();
                    schInMemoryLink    = (ISchematicInMemoryFeatureLink)schInMemoryFeature;
                }

                // caculate angle bisector
                if (enableCalculate)
                {
                    angleBisector = CalculateAngleBisector(angle1, angle2);
                }
                else
                {
                    continue;
                }

                // construct a geometry for the new node node
                // now call alterNode to create a new schematic feature
                // construct a correct name
                string uniqueNodeName, featureCreateName;
                featureCreateName = schFeatureParent.Name + Separator + extensionName;
                esriSchematicElementType elementType = esriSchematicElementType.esriSchematicNodeType;
                uniqueNodeName = GetUniqueName(inMemoryDiagram, elementType, featureCreateName);
                IWorkspace workspace = null;

                try
                {
                    workspace = inMemoryDiagram.SchematicDiagramClass.SchematicDataset.SchematicWorkspace.Workspace;
                }
                catch { }

                int datasourceID = -1;

                if (workspace != null)
                {
                    datasourceID = rulesHelper.FindDataSourceID(workspace, false);
                }

                if (datasourceID == -1)
                {
                    datasourceID = m_diagramClass.SchematicDataset.DefaultSchematicDataSource.ID;
                }

                ISchematicInMemoryFeature schFeatureNodeCreate = null;
                IPoint pointBisector = null;
                pointBisector = GetCoordPointBisector(pointParent, angleBisector, m_distance);
                try
                {
                    schFeatureNodeCreate = rulesHelper.AlterNode(m_targetNodeClass, uniqueNodeName, null, (IGeometry)pointBisector, datasourceID, 0);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine(ex.Message, "Impossible to create a feature Node");
                }

                // now construct a unique link name
                string linkName = schFeatureParent.Name + Separator + uniqueNodeName;
                string uniqueLinkName;

                elementType    = esriSchematicElementType.esriSchematicLinkType;
                uniqueLinkName = GetUniqueName(inMemoryDiagram, elementType, linkName);
                // construct a link
                ISchematicInMemoryFeature schFeatureLinkCreate = null;
                try
                {
                    schFeatureLinkCreate = rulesHelper.AlterLink(m_targetLinkClass, uniqueLinkName, null, null, datasourceID, 0, schFeatureParent.Name, uniqueNodeName, esriFlowDirection.esriFDWithFlow, 0, 0);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine(ex.Message, "Impossible to create a feature link");
                }
            }

            if (colSchfeatureNode.Count > 0)
            {
                colSchfeatureNode.Clear();
            }

            colSchfeatureNode = null;
            rulesHelper       = null;
        }
        private ISchematicInMemoryFeatureClass GetSchematicInMemoryFeatureClass(ISchematicInMemoryDiagram inMemoryDiagram, ISchematicElementClass eltClass)
        {
            ISchematicInMemoryFeatureClassContainer SchInMemoryFeatureClassContainer = (ISchematicInMemoryFeatureClassContainer)inMemoryDiagram;

            return(SchInMemoryFeatureClassContainer.GetSchematicInMemoryFeatureClass(eltClass));
        }
		public void SelectionChanged()
		{

			try
			{
				System.Windows.Forms.Control ctrl = null;
				System.Windows.Forms.Control ctrl2 = null;
				Control[] ctrls = null;
				System.Collections.ArrayList ctrlstoremove = new System.Collections.ArrayList();
				string labelName = "";
				string featureClass = "";
				System.Windows.Forms.ComboBox cbo = null;
				System.Windows.Forms.Label lblMain = null;

				if (m_digitCommand == null)
					return;

				//clear any current elements
				if (m_schematicFeature1 != null)
				{
					m_schematicFeature1 = null;
					m_digitCommand.SchematicFeature1(m_schematicFeature1);
				}

				if (m_schematicFeature2 != null)
				{
					m_schematicFeature2 = null;
					m_digitCommand.SchematicFeature2(m_schematicFeature2);
				}

				if (m_curPanel == Splitter.Panel1)
				{
					labelName = "lblNodeLabel";
					featureClass = "descendant::NodeFeature";
					cbo = cboNodeType;
					lblMain = lblNodeLabel;
				}
				else
				{
					labelName = "lblLinkLabel";
					featureClass = "descendant::LinkFeature";
					cbo = cboLinkType;
					lblMain = lblLinkLabel;
				}

				foreach (System.Windows.Forms.Control ctrlfor in m_curPanel.Controls)
				{
					if (ctrlfor.Name.StartsWith("lbl") && (ctrlfor.Name.ToString() != labelName))
					{
						ctrls = m_curPanel.Controls.Find(ctrlfor.Name.Substring(3), true);
						ctrl2 = ctrls[0];
						ctrlstoremove.Add(ctrlfor);
						ctrlstoremove.Add(ctrl2);
					}
				}

				if (ctrlstoremove.Count > 0)
				{
					foreach (System.Windows.Forms.Control ctrol in ctrlstoremove)
					{
						m_curPanel.Controls.Remove(ctrol);
					}
				}

				XmlNodeList elems = null;
				m_curfrmWidth = m_curPanel.Width;
				elems = m_dom.SelectNodes(featureClass);

				bool blnFound = false;
				XmlElement elem = null;
				foreach (XmlElement elem0 in elems)
				{
					if (elem0.GetAttribute("FeatureClassName").ToString() == cbo.Text.ToString())
					{
						elem = elem0;
						blnFound = true;
						break;
					}
				}

				if (blnFound == false)
				{
					// CR229717: If this is deactivate, lost the Schematic ElementClass and can not retrieve it
					//m_schEltClass = null;
					return;
				}

				if (m_curPanel == Splitter.Panel1)
					m_curNode = elem;
				else
					m_curLink = elem;

				//set grid
				elems = elem.SelectNodes("descendant::Field");
				int x = Splitter.Location.X;
				int y = lblMain.Location.Y + lblMain.Height + 5;

				System.Drawing.Point p = new System.Drawing.Point();

				foreach (XmlElement f in elems)
				{
					System.Windows.Forms.Label lbl = new System.Windows.Forms.Label();
					lbl.Name = "lbl" + f.GetAttribute("DBColumnName").ToString();
					lbl.Text = f.GetAttribute("DisplayName").ToString();
					lbl.AutoSize = true;
					m_curPanel.Controls.Add(lbl);
					p.X = 3;
					p.Y = y;
					lbl.Location = p;
					y = y + lbl.Height + 10;

					switch (f.GetAttribute("Type").ToString())
					{
						case "Text":
							System.Windows.Forms.TextBox tx = new System.Windows.Forms.TextBox();
							ctrl = tx;
							tx.Name = f.GetAttribute("DBColumnName").ToString();
							if (f.GetAttribute("Length").Length > 0)
								tx.MaxLength = System.Convert.ToInt32(f.GetAttribute("Length"));

							if (f.GetAttribute("Default").Length > 0)
								tx.Text = f.GetAttribute("Default");

							m_curPanel.Controls.Add(tx);
							break;

						case "Combo":

							System.Windows.Forms.ComboBox cb = new System.Windows.Forms.ComboBox();
							string defaulttext = "";
							ctrl = cb;
							cb.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
							cb.Name = f.GetAttribute("DBColumnName").ToString();
							XmlNodeList vlist = f.SelectNodes("descendant::Value");

							foreach (XmlElement v in vlist)
							{
								cb.Items.Add(v.InnerText.ToString());
								if (v.GetAttribute("Default").Length > 0)
									defaulttext = v.InnerText;
							}

							if (defaulttext.Length > 0)
								cb.Text = defaulttext;

							m_curPanel.Controls.Add(cb);
							break;

						case "MaskText":
							System.Windows.Forms.MaskedTextBox MaskControl = new System.Windows.Forms.MaskedTextBox();
							ctrl = MaskControl;
							string mask = "";
							MaskControl.Name = f.GetAttribute("DBColumnName").ToString();
							if (f.GetAttribute("Mask").Length > 0)
								mask = f.GetAttribute("Mask");
							else
								mask = "";

							MaskControl.Mask = mask;

							if (f.GetAttribute("Default").Length > 0)
								MaskControl.Text = f.GetAttribute("Default");

							MaskControl.Modified = false;
							m_curPanel.Controls.Add(MaskControl);
							MaskControl.TextChanged += new System.EventHandler(MaskedTextBox);

							break;

						case "Number":
							System.Windows.Forms.MaskedTextBox MaskControl2 = new System.Windows.Forms.MaskedTextBox();
							ctrl = MaskControl2;
							string mask2 = "";
							MaskControl2.Name = f.GetAttribute("DBColumnName").ToString();
							int i = 1;
							if (f.GetAttribute("Length").Length > 0)
							{
								for (i = 1; i <= System.Convert.ToInt32(f.GetAttribute("Length")); i++)
									mask = mask2 + "9";
							}
							else
							{
								if (f.GetAttribute("Mask").Length > 0)
									mask2 = f.GetAttribute("Mask");
								else
									mask2 = "";
							}

							MaskControl2.Mask = mask2;
							if (f.GetAttribute("Default").Length > 0)
								MaskControl2.Text = f.GetAttribute("Default");

							MaskControl2.Modified = false;
							m_curPanel.Controls.Add(MaskControl2);
							MaskControl2.TextChanged += new System.EventHandler(MaskedTextBox);
							break;

						case "Date":
							System.Windows.Forms.DateTimePicker dt = new System.Windows.Forms.DateTimePicker();
							ctrl = dt;
							dt.Name = f.GetAttribute("DBColumnName").ToString();
							dt.Value = DateTime.Now;
							dt.Format = System.Windows.Forms.DateTimePickerFormat.Short;
							m_curPanel.Controls.Add(dt);
							break;

						case "Relation":
							System.Windows.Forms.ComboBox cb2 = new System.Windows.Forms.ComboBox();
							ctrl = cb2;
							cb2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
							cb2.Name = f.GetAttribute("DBColumnName").ToString();
							XmlNodeList vlist2 = m_dom.SelectNodes("descendant::Relation");
							XmlNodeList rellist = null;
							string str = null;
							foreach (XmlElement v in vlist2)
							{
								if (v.GetAttribute("LinkType").ToString() == elem.GetAttribute("FeatureClassName").ToString())
								{
									rellist = v.SelectNodes("descendant::Value");
									if (rellist.Count > 0)
										foreach (XmlElement r in rellist)
										{
											str = v.GetAttribute("FromType").ToString() + "-" + v.GetAttribute("ToType").ToString() + "-" + r.InnerText.ToString();
											cb2.Items.Add(str);
										}
									else //assume they are not using subtypes
										cb2.Items.Add(v.GetAttribute("FromType").ToString() + "-" + v.GetAttribute("ToType").ToString());
								}
							}
							//relations are always mandatory
							ctrl.BackColor = m_MandatoryColor;
							ctrl.Tag = "Mandatory";
							m_curPanel.Controls.Add(cb2);
							break;
					}

					if (f.GetAttribute("Mandatory").ToString() == "True")
					{
						ctrl.BackColor = m_MandatoryColor;
						ctrl.Tag = "Mandatory";
					}
				}
				ResizeForm();

				// set m_schEltClass
				XmlElement curElement = null;

				if (m_curPanel == Splitter.Panel1)
					curElement = m_curNode;
				else
					curElement = m_curLink;

				if (m_schEltClass == null)
					m_schEltClass = m_schEltClassCont.GetSchematicElementClass(curElement.GetAttribute("FeatureClassName"));
				else
					if (m_schEltClass.Name != curElement.GetAttribute("FeatureClassName"))
						m_schEltClass = m_schEltClassCont.GetSchematicElementClass(curElement.GetAttribute("FeatureClassName"));
			}

			catch (System.Exception e)
			{
				System.Windows.Forms.MessageBox.Show(e.Message);
			}
		}
		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;

		}
        void formAdvanced_doneFormEvent(object sender, AdvancedEvents e)
        {
            m_pSDS.DesignMode   = true;
            formAdvanced.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            //process the algorithm if there is one
            if (e.AlgorithmName != "")
            {
                ISchematicAlgoSmartTree a = new SchematicAlgoSmartTreeClass();
                if (e.AlgorithmParams.Count > 0)
                {
                    Dictionary <string, string> .KeyCollection keys = e.AlgorithmParams.Keys;
                    string strValue = "";
                    foreach (string s in keys)
                    {
                        if (s == "Direction")
                        {
                            e.AlgorithmParams.TryGetValue(s, out strValue);

                            if (strValue == "Top to Bottom")
                            {
                                a.Direction = esriSchematicAlgoDirection.esriSchematicAlgoTopDown;
                            }
                            else if (strValue == "Bottom to Top")
                            {
                                a.Direction = esriSchematicAlgoDirection.esriSchematicAlgoBottomUp;
                            }
                            else if (strValue == "Left to Right")
                            {
                                a.Direction = esriSchematicAlgoDirection.esriSchematicAlgoLeftRight;
                            }
                            else
                            {
                                a.Direction = esriSchematicAlgoDirection.esriSchematicAlgoRightLeft;
                            }
                        }
                    }
                    if (e.RootClass != "")
                    {
                        ISchematicElementClassContainer pECC = (ISchematicElementClassContainer)m_pSDS;
                        ISchematicElementClass          pEC  = pECC.GetSchematicElementClass(e.RootClass);
                        ESRI.ArcGIS.esriSystem.UID      u    = new ESRI.ArcGIS.esriSystem.UID();
                        u.Value = "{3AD9D8B8-0A1D-4F32-ABB5-54B848A46F85}";

                        ISchematicAttributeConstant   pAttrConst = (ISchematicAttributeConstant)pEC.CreateSchematicAttribute("RootFlag", u);
                        ISchematicAttributeManagement pAttrMgmt  = (ISchematicAttributeManagement)pAttrConst;
                        pAttrMgmt.StorageMode    = esriSchematicAttributeStorageMode.esriSchematicAttributeFieldStorage;
                        pAttrConst.ConstantValue = "-1";
                    }
                }

                m_pSDT.SchematicAlgorithm = (ISchematicAlgorithm)a;
            }

            //check to see if we need to add associated fields
            if (e.FieldsToCreate != null)
            {
                if (e.FieldsToCreate.Count > 0)
                {
                    ISchematicElementClassContainer pECC = (ISchematicElementClassContainer)m_pSDS;

                    //create the associated field attributes
                    string[] keys = e.FieldsToCreate.AllKeys;
                    foreach (string s in keys)
                    {
                        //get the feature class
                        ISchematicElementClass pEC = pECC.GetSchematicElementClass(s);
                        if (pEC != null)
                        {
                            string   strName = "";
                            string[] values  = e.FieldsToCreate.GetValues(s);
                            foreach (string v in values)
                            {
                                //create the field
                                ESRI.ArcGIS.esriSystem.UID u = new ESRI.ArcGIS.esriSystem.UID();
                                u.Value = "{7DE3A19D-32D0-41CD-B896-37CA3AFBD88A}";

                                IClass pClass = (IClass)pEC;
                                //only handle names that don't already exist in the schematic tables
                                if (pClass.FindField(v) == -1)
                                {
                                    strName = v.ToString();

                                    ISchematicAttributeAssociatedField pFieldAttr = (ISchematicAttributeAssociatedField)pEC.CreateSchematicAttribute(strName, u);
                                    pFieldAttr.AssociatedFieldName = v;
                                    ISchematicAttributeManagement pAttrMgmt = (ISchematicAttributeManagement)pFieldAttr;
                                    pAttrMgmt.StorageMode = esriSchematicAttributeStorageMode.esriSchematicAttributeFieldStorage;
                                }
                            }
                        }
                    }
                }
            }

            m_pSDS.Save(ESRI.ArcGIS.esriSystem.esriArcGISVersion.esriArcGISVersionCurrent, true);
            m_pSDS.DesignMode   = false;
            formAdvanced.Cursor = System.Windows.Forms.Cursors.Default;
            formAdvanced.Close();
        }