public void EndFeedBack()
        {
            m_schematicFeature1 = null;
            m_schematicFeature2 = null;

            if (m_dockableDigit != null)
            {
                m_dockableDigit.SchematicFeature1(m_schematicFeature1);
                m_dockableDigit.SchematicFeature2(m_schematicFeature2);
            }

            if (m_linkFbk != null)
            {
                m_linkFbk.Stop();
                m_linkFbk = null;
            }
        }
 public void SchematicFeature2(ISchematicFeature value)
 {
     m_schematicFeature2 = value;
     return;
 }
		public void SchematicFeature2(ISchematicFeature schematicFeature)
		{
			m_schematicFeature2 = schematicFeature;
			return;
		}
        protected override void OnMouseUp(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            bool abortOperation = false;

            ESRI.ArcGIS.Schematic.ISchematicOperation schematicOperation = null;

            try
            {
                if (m_dockableDigit == null)
                {
                    return;
                }

                if (arg != null)
                {
                    m_x = arg.X;
                    m_y = arg.Y;
                }

                if (m_dockableWindow == null)
                {
                    return;
                }

                if (m_dockableWindow.IsVisible() == false)
                {
                    m_dockableWindow.Show(true);
                }

                ESRI.ArcGIS.SchematicControls.ISchematicTarget target = (ESRI.ArcGIS.SchematicControls.ISchematicTarget)m_schematicExtension;

                if (target != null)
                {
                    m_schematicLayer = target.SchematicTarget;
                }

                if (m_schematicLayer == null)
                {
                    System.Windows.Forms.MessageBox.Show("No target Layer");
                    return;
                }

                ISchematicInMemoryDiagram               inMemoryDiagram;
                ISchematicInMemoryFeatureClass          schematicInMemoryFeatureClass;
                ISchematicInMemoryFeatureClassContainer schematicInMemoryFeatureClassContainer;

                //Get the point
                ESRI.ArcGIS.Geometry.Point point = new ESRI.ArcGIS.Geometry.Point();

                ESRI.ArcGIS.ArcMapUI.IMxApplication mxApp;
                ESRI.ArcGIS.Display.IAppDisplay     appDisplay;
                IScreenDisplay         screenDisplay;
                IDisplay               display;
                IDisplayTransformation transform;
                ISpatialReference      spatialReference;

                inMemoryDiagram = m_schematicLayer.SchematicInMemoryDiagram;
                schematicInMemoryFeatureClassContainer = (ISchematicInMemoryFeatureClassContainer)inMemoryDiagram;

                if (schematicInMemoryFeatureClassContainer == null)
                {
                    return;
                }

                mxApp = (ESRI.ArcGIS.ArcMapUI.IMxApplication)m_app;

                if (mxApp == null)
                {
                    return;
                }

                appDisplay = mxApp.Display;

                if (appDisplay == null)
                {
                    return;
                }

                screenDisplay = appDisplay.FocusScreen;
                display       = screenDisplay;

                if (display == null)
                {
                    return;
                }

                transform = display.DisplayTransformation;

                if (transform == null)
                {
                    return;
                }

                spatialReference = transform.SpatialReference;

                WKSPoint mapPt = new WKSPoint();
                ESRI.ArcGIS.Display.tagPOINT devPoint;
                devPoint.x = m_x;
                devPoint.y = m_y;
                transform.TransformCoords(ref mapPt, ref devPoint, 1, 1); //'esriTransformToMap

                point.SpatialReference = spatialReference;
                point.Project(spatialReference);
                point.X = mapPt.X;
                point.Y = mapPt.Y;

                schematicInMemoryFeatureClass = schematicInMemoryFeatureClassContainer.GetSchematicInMemoryFeatureClass(m_dockableDigit.FeatureClass());

                if (schematicInMemoryFeatureClass == null)
                {
                    System.Windows.Forms.MessageBox.Show("Invalid Type.");
                    return;
                }

                if (m_dockableDigit.CreateNode())
                {
                    //TestMandatoryField
                    m_dockableDigit.btnOKPanel1.Visible = false;

                    if (m_dockableDigit.ValidateFields() == false)
                    {
                        m_dockableDigit.x(m_x);
                        m_dockableDigit.y(m_y);

                        System.Windows.Forms.MessageBox.Show(m_dockableDigit.ErrorProvider1.GetError(m_dockableDigit.btnOKPanel1) + m_messageFromOK);
                        return;
                    }

                    ESRI.ArcGIS.Geometry.IGeometry geometry;

                    ISchematicInMemoryFeature schematicInMemoryFeatureNode;

                    geometry = point;

                    schematicOperation = (ESRI.ArcGIS.Schematic.ISchematicOperation) new ESRI.ArcGIS.SchematicControls.SchematicOperation();

                    //digit operation is undo(redo)able we add it in the stack
                    IMxDocument doc = (IMxDocument)m_app.Document;
                    ESRI.ArcGIS.SystemUI.IOperationStack operationStack;
                    operationStack = doc.OperationStack;
                    operationStack.Do(schematicOperation);
                    schematicOperation.StartOperation("Digit", m_app, m_schematicLayer, true);

                    //do abort operation
                    abortOperation = true;

                    schematicInMemoryFeatureNode = schematicInMemoryFeatureClass.CreateSchematicInMemoryFeatureNode(geometry, "");
                    //schematicInMemoryFeatureNode.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusNew; if we want the node deleted after update
                    schematicInMemoryFeatureNode.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusLocked;

                    abortOperation = false;
                    schematicOperation.StopOperation();

                    ISchematicFeature schematicFeature = schematicInMemoryFeatureNode;
                    m_dockableDigit.FillValue(ref schematicFeature);

                    if (m_dockableDigit.AutoClear())
                    {
                        m_dockableDigit.SelectionChanged();
                    }
                }
                else
                {
                    m_dockableDigit.btnOKPanel2.Visible = false;

                    //Get the Tolerance of ArcMap
                    Double      tolerance;
                    IMxDocument mxDocument = (ESRI.ArcGIS.ArcMapUI.IMxDocument)m_app.Document;
                    ESRI.ArcGIS.esriSystem.WKSPoint point2 = new WKSPoint();
                    ESRI.ArcGIS.Display.tagPOINT    devPt;

                    tolerance = mxDocument.SearchTolerancePixels;
                    devPt.x   = (int)tolerance;
                    devPt.y   = (int)tolerance;

                    transform.TransformCoords(ref point2, ref devPt, 1, 2); //2 <-> esriTransformSize 4 <-> esriTransformToMap

                    tolerance = point2.X * 5;                               //increase the tolerance value

                    IEnumSchematicFeature schematicFeatures = m_schematicLayer.GetSchematicFeaturesAtPoint(point, tolerance, false, true);

                    ISchematicFeature schematicFeatureSelected = null;
                    double            distancetmp;
                    double            distance = 0;
                    schematicFeatures.Reset();

                    if (schematicFeatures.Count <= 0)
                    {
                        return;
                    }

                    //pSchematicFeatures may contain several features, we are choosing the closest node.
                    ISchematicFeature schematicFeature2 = schematicFeatures.Next();

                    double dX;
                    double dY;
                    ISchematicInMemoryFeatureNode schematicInMemoryFeatureNode = null;
                    if (schematicFeature2 != null)
                    {
                        if (schematicFeature2.SchematicElementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType)
                        {
                            schematicInMemoryFeatureNode = (ISchematicInMemoryFeatureNode)schematicFeature2;
                        }
                    }

                    ISchematicInMemoryFeatureNodeGeometry schematicInMemoryFeatureNodeGeometry = (ISchematicInMemoryFeatureNodeGeometry)schematicInMemoryFeatureNode;
                    dX = schematicInMemoryFeatureNodeGeometry.Position.X;
                    dY = schematicInMemoryFeatureNodeGeometry.Position.Y;
                    schematicFeatureSelected = schematicFeature2;
                    distance = SquareDistance(dX - point.X, dY - point.Y);

                    while (schematicFeature2 != null)
                    {
                        //find the closest featureNode...
                        if (schematicInMemoryFeatureNode != null)
                        {
                            schematicInMemoryFeatureNodeGeometry = (ISchematicInMemoryFeatureNodeGeometry)schematicInMemoryFeatureNode;

                            if (schematicInMemoryFeatureNodeGeometry == null)
                            {
                                continue;
                            }

                            dX          = schematicInMemoryFeatureNodeGeometry.Position.X;
                            dY          = schematicInMemoryFeatureNodeGeometry.Position.Y;
                            distancetmp = SquareDistance(dX - point.X, dY - point.Y);

                            if (distancetmp < distance)
                            {
                                distance = distancetmp;
                                schematicFeatureSelected = schematicFeature2;
                            }
                        }

                        schematicFeature2 = schematicFeatures.Next();

                        if (schematicFeature2 != null)
                        {
                            if (schematicFeature2.SchematicElementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType)
                            {
                                schematicInMemoryFeatureNode = (ISchematicInMemoryFeatureNode)schematicFeature2;
                            }
                        }
                    }

                    if (schematicFeatureSelected == null)
                    {
                        return;
                    }

                    if (schematicFeatureSelected.SchematicElementClass.SchematicElementType != esriSchematicElementType.esriSchematicNodeType)
                    {
                        return;
                    }

                    if (m_schematicFeature1 == null)
                    {
                        m_schematicFeature1 = schematicFeatureSelected;
                        m_dockableDigit.SchematicFeature1(m_schematicFeature1);

                        if (!m_dockableDigit.CheckValidFeature(true))
                        {
                            m_schematicFeature1 = null;
                            m_dockableDigit.SchematicFeature1(m_schematicFeature1);
                            throw new Exception("Invalid starting node for this link type");
                        }

                        //Begin Feedback
                        m_linkFbk         = new NewLineFeedback();
                        m_linkFbk.Display = screenDisplay;

                        //symbol
                        ISimpleLineSymbol sLnSym;
                        IRgbColor         rGB = new RgbColor();

                        sLnSym = (ESRI.ArcGIS.Display.ISimpleLineSymbol)m_linkFbk.Symbol;

                        //Make a color
                        rGB.Red   = 255;
                        rGB.Green = 0;
                        rGB.Blue  = 0;

                        // Setup the symbol with color and style
                        sLnSym.Color = rGB;

                        m_linkFbk.Start(point);
                        //End Feedback

                        //To know if we are in the same diagram.
                        m_schematicLayerForLink = m_schematicLayer;
                    }
                    else
                    {
                        if (m_schematicLayerForLink != m_schematicLayer)
                        {
                            System.Windows.Forms.MessageBox.Show("wrong Target layer");
                            m_schematicLayerForLink = null;
                            EndFeedBack();
                            return;
                        }
                        m_schematicFeature2 = schematicFeatureSelected;
                        m_dockableDigit.SchematicFeature2(m_schematicFeature2);

                        //TestMandatoryField
                        if (m_dockableDigit.ValidateFields() == false)
                        {
                            m_dockableDigit.x(m_x);
                            m_dockableDigit.y(m_y);

                            System.Windows.Forms.MessageBox.Show(m_dockableDigit.ErrorProvider1.GetError(m_dockableDigit.btnOKPanel2) + m_messageFromOK);
                            return;
                        }

                        if (!m_dockableDigit.CheckValidFeature(false))
                        {
                            m_schematicFeature2 = null;
                            m_dockableDigit.SchematicFeature2(m_schematicFeature2);
                            throw new Exception("Invalid End node for this link type");
                        }

                        //CreateLink
                        ISchematicInMemoryFeature schematicInMemoryFeatureLink;

                        schematicOperation = (ESRI.ArcGIS.Schematic.ISchematicOperation) new ESRI.ArcGIS.SchematicControls.SchematicOperation();

                        //digit operation is undo(redo)able we add it in the stack
                        IMxDocument doc = (IMxDocument)m_app.Document;
                        ESRI.ArcGIS.SystemUI.IOperationStack operationStack;
                        operationStack = doc.OperationStack;
                        operationStack.Do(schematicOperation);
                        schematicOperation.StartOperation("Digit", m_app, m_schematicLayer, true);

                        //do abort operation
                        abortOperation = true;

                        schematicInMemoryFeatureLink = schematicInMemoryFeatureClass.CreateSchematicInMemoryFeatureLink((ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode)m_schematicFeature1, (ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode)m_schematicFeature2, "");
                        //schematicInMemoryFeatureLink.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusNew; if we want the node deleted after update
                        schematicInMemoryFeatureLink.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusLocked;

                        abortOperation = false;
                        schematicOperation.StopOperation();

                        ISchematicFeature schematicFeature = schematicInMemoryFeatureLink;
                        m_dockableDigit.FillValue(ref schematicFeature);

                        //End Feedback
                        EndFeedBack();

                        m_schematicLayerForLink = null;

                        if (m_dockableDigit.AutoClear())
                        {
                            m_dockableDigit.SelectionChanged();
                        }
                    }
                }

                //Refresh the view and viewer windows
                RefreshView();
            }
            catch (System.Exception e)
            {
                if (abortOperation && (schematicOperation != null))
                {
                    schematicOperation.AbortOperation();
                }

                EndFeedBack();
                System.Windows.Forms.MessageBox.Show(e.Message);
            }

            return;
        }
		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 FillValue(ref ISchematicFeature schFeature)
		{
			try
			{
				if (m_schEltClass == null)
					throw new Exception("Error getting Feature Class");

				int fldIndex;

				foreach (System.Windows.Forms.Control ctrl in m_curPanel.Controls)
				{
					if (!((ctrl.GetType() == typeof(System.Windows.Forms.Label)) || (ctrl.Name == "cboNodeType")))
					{
						if ((ctrl.GetType() == typeof(System.Windows.Forms.TextBox)) || (ctrl.GetType() == typeof(System.Windows.Forms.ComboBox)))
						{
							if (ctrl.Text.Length > 0)
							{
								//insert in DB
								fldIndex = schFeature.Fields.FindField(ctrl.Name);
								if (fldIndex > -1)
								{
									schFeature.set_Value(fldIndex, ctrl.Text);
									schFeature.Store();
								}
							}
						}
						else if (ctrl.GetType() == typeof(System.Windows.Forms.DateTimePicker))
						{
							fldIndex = schFeature.Fields.FindField(ctrl.Name);
							if (fldIndex > -1)
							{
								schFeature.set_Value(fldIndex, ctrl.Text);
								schFeature.Store();
							}
						}
						else if (ctrl.GetType() == typeof(System.Windows.Forms.MaskedTextBox))
						{
							System.Windows.Forms.MaskedTextBox mctrl = (System.Windows.Forms.MaskedTextBox)ctrl;
							if ((mctrl.Text.Length > 0) && (mctrl.Modified) && (mctrl.MaskCompleted))
							{

								fldIndex = schFeature.Fields.FindField(ctrl.Name);
								if (fldIndex > -1)
								{
									schFeature.set_Value(fldIndex, ctrl.Text);
									schFeature.Store();
								}
							}
						}
					}
				}

				return;
			}

			catch (System.Exception e)
			{
				System.Windows.Forms.MessageBox.Show(e.Message);
			}
		}
		private void Splitter_Panel2_Click(object sender, EventArgs e)
		{
			if (m_digitCommand == null)
				m_digitCommand = CurrentDigitTool.CurrentTool.currentDigit;

			if (m_digitCommand == null)
				return;

			m_createNode = false;

			if (m_curPanel != Splitter.Panel2)
			{

				m_curPanel = Splitter.Panel2;
				foreach (System.Windows.Forms.Control ctrl in Splitter.Panel1.Controls)
					ctrl.Enabled = false;

				foreach (System.Windows.Forms.Control ctrl in Splitter.Panel2.Controls)
					ctrl.Enabled = true;

				lblMode.Text = "Create Link";

				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)
				{
					btnOKPanel1.Visible = false;
					ErrorProvider1.SetError(btnOKPanel1, "");
				}
				else
				{
					btnOKPanel2.Visible = false;
					ErrorProvider1.SetError(btnOKPanel2, "");
				}

				System.EventArgs e2 = new System.EventArgs();
				cboLinkType_SelectedIndexChanged(sender, e2);

			}

		}
 public void SchematicFeature2(ISchematicFeature value)
 {
     m_schematicFeature2 = value;
     return;
 }
        public void EndFeedBack()
        {
            m_schematicFeature1 = null;
            m_schematicFeature2 = null;
            
            if (m_dockableDigit != null)
            {
                m_dockableDigit.SchematicFeature1(m_schematicFeature1);
                m_dockableDigit.SchematicFeature2(m_schematicFeature2);
            }

            if (m_linkFbk != null)
            {
                m_linkFbk.Stop();
                m_linkFbk = null;
            }
        }
        protected override void OnMouseUp(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            bool abortOperation = false;
            ESRI.ArcGIS.Schematic.ISchematicOperation schematicOperation = null;

            try
            {
                if (m_dockableDigit == null)
                    return;

                if (arg != null)
                {
                    m_x = arg.X;
                    m_y = arg.Y;
                }

                if (m_dockableWindow == null)
                    return;

                if (m_dockableWindow.IsVisible() == false)
                {
                    m_dockableWindow.Show(true);
                }

                ESRI.ArcGIS.SchematicControls.ISchematicTarget target = (ESRI.ArcGIS.SchematicControls.ISchematicTarget)m_schematicExtension;

                if (target != null)
                    m_schematicLayer = target.SchematicTarget;

                if (m_schematicLayer == null)
                {
                    System.Windows.Forms.MessageBox.Show("No target Layer");
                    return;
                }

                ISchematicInMemoryDiagram inMemoryDiagram;
                ISchematicInMemoryFeatureClass schematicInMemoryFeatureClass;
                ISchematicInMemoryFeatureClassContainer schematicInMemoryFeatureClassContainer;

                //Get the point
                ESRI.ArcGIS.Geometry.Point point = new ESRI.ArcGIS.Geometry.Point();

                ESRI.ArcGIS.ArcMapUI.IMxApplication mxApp;
                ESRI.ArcGIS.Display.IAppDisplay appDisplay;
                IScreenDisplay screenDisplay;
                IDisplay display;
                IDisplayTransformation transform;
                ISpatialReference spatialReference;

                inMemoryDiagram = m_schematicLayer.SchematicInMemoryDiagram;
                schematicInMemoryFeatureClassContainer = (ISchematicInMemoryFeatureClassContainer)inMemoryDiagram;

                if (schematicInMemoryFeatureClassContainer == null)
                    return;

                mxApp = (ESRI.ArcGIS.ArcMapUI.IMxApplication)m_app;

                if (mxApp == null)
                    return;

                appDisplay = mxApp.Display;

                if (appDisplay == null)
                    return;

                screenDisplay = appDisplay.FocusScreen;
                display = screenDisplay;

                if (display == null)
                    return;

                transform = display.DisplayTransformation;

                if (transform == null)
                    return;

                spatialReference = transform.SpatialReference;

                WKSPoint mapPt = new WKSPoint();
                ESRI.ArcGIS.Display.tagPOINT devPoint;
                devPoint.x = m_x;
                devPoint.y = m_y;
                transform.TransformCoords(ref mapPt, ref devPoint, 1, 1); //'esriTransformToMap

                point.SpatialReference = spatialReference;
                point.Project(spatialReference);
                point.X = mapPt.X;
                point.Y = mapPt.Y;

                schematicInMemoryFeatureClass = schematicInMemoryFeatureClassContainer.GetSchematicInMemoryFeatureClass(m_dockableDigit.FeatureClass());

                if (schematicInMemoryFeatureClass == null)
                {
                    System.Windows.Forms.MessageBox.Show("Invalid Type.");
                    return;
                }

                if (m_dockableDigit.CreateNode())
                {
                    //TestMandatoryField
                    m_dockableDigit.btnOKPanel1.Visible = false;

                    if (m_dockableDigit.ValidateFields() == false)
                    {
                        m_dockableDigit.x(m_x);
                        m_dockableDigit.y(m_y);

                        System.Windows.Forms.MessageBox.Show(m_dockableDigit.ErrorProvider1.GetError(m_dockableDigit.btnOKPanel1) + m_messageFromOK);
                        return;
                    }

                    ESRI.ArcGIS.Geometry.IGeometry geometry;

                    ISchematicInMemoryFeature schematicInMemoryFeatureNode;

                    geometry = point;

                    schematicOperation = (ESRI.ArcGIS.Schematic.ISchematicOperation) new ESRI.ArcGIS.SchematicControls.SchematicOperation();

                    //digit operation is undo(redo)able we add it in the stack
                    IMxDocument doc  = (IMxDocument)m_app.Document;
                    ESRI.ArcGIS.SystemUI.IOperationStack operationStack; 
                    operationStack = doc.OperationStack;
                    operationStack.Do(schematicOperation);
                    schematicOperation.StartOperation("Digit", m_app, m_schematicLayer, true);

                    //do abort operation
                    abortOperation = true;

                    schematicInMemoryFeatureNode = schematicInMemoryFeatureClass.CreateSchematicInMemoryFeatureNode(geometry, "");
                    //schematicInMemoryFeatureNode.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusNew; if we want the node deleted after update
                    schematicInMemoryFeatureNode.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusLocked;

                    abortOperation = false;
                    schematicOperation.StopOperation();

                    ISchematicFeature schematicFeature = schematicInMemoryFeatureNode;
                    m_dockableDigit.FillValue(ref schematicFeature);

                    if (m_dockableDigit.AutoClear())
                        m_dockableDigit.SelectionChanged();
                }
                else
                {
                    m_dockableDigit.btnOKPanel2.Visible = false;

                    //Get the Tolerance of ArcMap
                    Double tolerance;
                    IMxDocument mxDocument = (ESRI.ArcGIS.ArcMapUI.IMxDocument)m_app.Document;
                    ESRI.ArcGIS.esriSystem.WKSPoint point2 = new WKSPoint();
                    ESRI.ArcGIS.Display.tagPOINT devPt;

                    tolerance = mxDocument.SearchTolerancePixels;
                    devPt.x = (int)tolerance;
                    devPt.y = (int)tolerance;

                    transform.TransformCoords(ref point2, ref devPt, 1, 2);//2 <-> esriTransformSize 4 <-> esriTransformToMap

                    tolerance = point2.X * 5;//increase the tolerance value

                    IEnumSchematicFeature schematicFeatures = m_schematicLayer.GetSchematicFeaturesAtPoint(point, tolerance, false, true);

                    ISchematicFeature schematicFeatureSelected = null;
                    double distancetmp;
                    double distance = 0;
                    schematicFeatures.Reset();

                    if (schematicFeatures.Count <= 0)
                        return;

                    //pSchematicFeatures may contain several features, we are choosing the closest node.
                    ISchematicFeature schematicFeature2 = schematicFeatures.Next();

                    double dX;
                    double dY;
                    ISchematicInMemoryFeatureNode schematicInMemoryFeatureNode =  null;
                    if (schematicFeature2 != null)
                    {
                        if (schematicFeature2.SchematicElementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType)
                            schematicInMemoryFeatureNode = (ISchematicInMemoryFeatureNode)schematicFeature2;
                    }
                                        
                    ISchematicInMemoryFeatureNodeGeometry schematicInMemoryFeatureNodeGeometry = (ISchematicInMemoryFeatureNodeGeometry)schematicInMemoryFeatureNode;
                    dX = schematicInMemoryFeatureNodeGeometry.Position.X;
                    dY = schematicInMemoryFeatureNodeGeometry.Position.Y;
                    schematicFeatureSelected = schematicFeature2;
                    distance = SquareDistance(dX - point.X, dY - point.Y);

                    while (schematicFeature2 != null)
                    {
                        //find the closest featureNode...
                        if (schematicInMemoryFeatureNode != null)
                        {
                            schematicInMemoryFeatureNodeGeometry = (ISchematicInMemoryFeatureNodeGeometry) schematicInMemoryFeatureNode;

                            if (schematicInMemoryFeatureNodeGeometry == null)
                                continue;

                            dX = schematicInMemoryFeatureNodeGeometry.Position.X;
                            dY = schematicInMemoryFeatureNodeGeometry.Position.Y;
                            distancetmp = SquareDistance(dX - point.X, dY - point.Y);
                            
                            if (distancetmp < distance)
                            {
                                distance = distancetmp;
                                schematicFeatureSelected = schematicFeature2;
                            }
                        }

                        schematicFeature2 = schematicFeatures.Next();
                        
                        if (schematicFeature2 != null)
                        {
                            if (schematicFeature2.SchematicElementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType)
                                schematicInMemoryFeatureNode = (ISchematicInMemoryFeatureNode)schematicFeature2;
                        }
                    }
                    
                    if (schematicFeatureSelected == null)
                        return;

                    if (schematicFeatureSelected.SchematicElementClass.SchematicElementType != esriSchematicElementType.esriSchematicNodeType)
                        return;

                    if (m_schematicFeature1 == null)
                    {
                        m_schematicFeature1 = schematicFeatureSelected;
                        m_dockableDigit.SchematicFeature1(m_schematicFeature1);

                        if (!m_dockableDigit.CheckValidFeature(true))
                        {
                            m_schematicFeature1 = null;
                            m_dockableDigit.SchematicFeature1(m_schematicFeature1);
                            throw new Exception("Invalid starting node for this link type");
                        }

                        //Begin Feedback 
                        m_linkFbk = new NewLineFeedback();
                        m_linkFbk.Display = screenDisplay;

                        //symbol
                        ISimpleLineSymbol sLnSym;
                        IRgbColor rGB = new RgbColor();

                        sLnSym = (ESRI.ArcGIS.Display.ISimpleLineSymbol)m_linkFbk.Symbol;

                        //Make a color
                        rGB.Red = 255;
                        rGB.Green = 0;
                        rGB.Blue = 0;

                        // Setup the symbol with color and style
                        sLnSym.Color = rGB;

                        m_linkFbk.Start(point);
                        //End Feedback

                        //To know if we are in the same diagram.
                        m_schematicLayerForLink = m_schematicLayer;
                    }
                    else
                    {
                        if (m_schematicLayerForLink != m_schematicLayer)
                        {
                            System.Windows.Forms.MessageBox.Show("wrong Target layer");
                            m_schematicLayerForLink = null;
                            EndFeedBack();
                            return;
                        }
                        m_schematicFeature2 = schematicFeatureSelected;
                        m_dockableDigit.SchematicFeature2(m_schematicFeature2);

                        //TestMandatoryField
                        if (m_dockableDigit.ValidateFields() == false)
                        {
                            m_dockableDigit.x(m_x);
                            m_dockableDigit.y(m_y);

                            System.Windows.Forms.MessageBox.Show(m_dockableDigit.ErrorProvider1.GetError(m_dockableDigit.btnOKPanel2) + m_messageFromOK);
                            return;
                        }

                        if (!m_dockableDigit.CheckValidFeature(false))
                        {
                            m_schematicFeature2 = null;
                            m_dockableDigit.SchematicFeature2(m_schematicFeature2);
                            throw new Exception("Invalid End node for this link type");
                        }

                        //CreateLink
                        ISchematicInMemoryFeature schematicInMemoryFeatureLink;

                        schematicOperation = (ESRI.ArcGIS.Schematic.ISchematicOperation) new ESRI.ArcGIS.SchematicControls.SchematicOperation();

                        //digit operation is undo(redo)able we add it in the stack
                        IMxDocument doc  = (IMxDocument)m_app.Document;
                        ESRI.ArcGIS.SystemUI.IOperationStack operationStack; 
                        operationStack = doc.OperationStack;
                        operationStack.Do(schematicOperation);
                        schematicOperation.StartOperation("Digit", m_app, m_schematicLayer, true);

                        //do abort operation
                        abortOperation = true;

                        schematicInMemoryFeatureLink = schematicInMemoryFeatureClass.CreateSchematicInMemoryFeatureLink((ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode)m_schematicFeature1, (ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode)m_schematicFeature2, "");
                        //schematicInMemoryFeatureLink.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusNew; if we want the node deleted after update
                        schematicInMemoryFeatureLink.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusLocked;

                        abortOperation = false;
                        schematicOperation.StopOperation();

                        ISchematicFeature schematicFeature = schematicInMemoryFeatureLink;
                        m_dockableDigit.FillValue(ref schematicFeature);

                        //End Feedback
                        EndFeedBack();

                        m_schematicLayerForLink = null;

                        if (m_dockableDigit.AutoClear())
                            m_dockableDigit.SelectionChanged();

                    }
                }

                //Refresh the view and viewer windows
                RefreshView();
            }
            catch (System.Exception e)
            {
                if (abortOperation && (schematicOperation != null))
                    schematicOperation.AbortOperation();

                EndFeedBack();
                System.Windows.Forms.MessageBox.Show(e.Message);
            }

            return;
        }
Example #11
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();
        }