Esempio n. 1
0
        private void BuildDisplacementLinks()
        {
            try
            {

                if (_App == null)
                {
                    // Get the actual underlying COM type
                    Type t = Type.GetTypeFromCLSID(typeof(AppRefClass).GUID);
                    System.Object obj = Activator.CreateInstance(t);
                    _App = obj as IApplication;

                }

                string masterText = this._form.cbMaster.SelectedItem.ToString();
                string secondaryText = this._form.cbSecondLayer.SelectedItem.ToString();

                DataTable mainTbl = MainErrorTable("MainTable", "");
                string filter = "fClass = '" + masterText + "'";
                DataRow[] foundRowsTo;
                foundRowsTo = mainTbl.Select(filter);

                int rowsCount = foundRowsTo.Length;

                string msg = "You have selected to process '" + rowsCount.ToString() + "' coordinates.  Depending on your hardware configuration this process may take several minutes.\n Click on the 'OK' button to continue or the 'Cancel' button to terminate the process.";

                if (MessageBox.Show(msg, "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    IsdutHourGlass theHourGlass = new IsdutHourGlass(this._App);

                    theHourGlass.start("Processing " + rowsCount.ToString() + " Coordinates...");

                    double _fromX = 0;
                    double _fromY = 0;
                    double _toX = 0;
                    double _toY = 0;
                    string _toFClass = "";
                    int _objId = 0;

                    IMxDocument mxDocument = _App.Document as IMxDocument;
                    IMap map = mxDocument.FocusMap;
                    IGraphicsContainer graphicsContainer = util.GraphicsHelper.get_GraphicsContainer(map);

                    graphicsContainer.Reset();

                    graphicsContainer.DeleteAllElements();

                    //Get the link symbol from the adjustment extension
                    IAdjustment adjustment = _App.FindExtensionByName("ESRI Adjustment Tools") as IAdjustment;
                    IAdjustProperties adjustmentProperties = adjustment as IAdjustProperties;
                    ILineSymbol linkSymbol = adjustmentProperties.DisplacementLinkSymbol;
                    IElementCollection elements = new ElementCollectionClass();

                    for (int i = 0; i < adjustment.TransformationMethodCount; i++)
                    {
                        if (adjustment.get_TransformationMethod(i).Name == "Edge Snap")
                        {
                            adjustment.CurrentTransformationMethod = adjustment.get_TransformationMethod(i);
                            break;
                        }
                    }

                    foreach (DataRow dRowTo in foundRowsTo)
                    {

                        _objId = Convert.ToInt32(dRowTo[mainTbl.Columns.IndexOf("objId")]);
                        _f1_id = Convert.ToInt32(dRowTo[mainTbl.Columns.IndexOf("fId")]);
                        _toFClass = Convert.ToString(dRowTo[mainTbl.Columns.IndexOf("fClass")]);
                        _toX = Convert.ToDouble(dRowTo[mainTbl.Columns.IndexOf("x")]);
                        _toY = Convert.ToDouble(dRowTo[mainTbl.Columns.IndexOf("y")]);

                        filter = "objId = " + _objId;
                        filter = filter + " AND fClass = '" + secondaryText + "'";
                        DataRow[] foundRowsFrom;

                        foundRowsFrom = mainTbl.Select(filter);

                        foreach (DataRow dRowFrom in foundRowsFrom)
                        {

                            _fromX = Convert.ToDouble(dRowFrom[mainTbl.Columns.IndexOf("x")]);
                            _fromY = Convert.ToDouble(dRowFrom[mainTbl.Columns.IndexOf("y")]);

                        }

                        //Create the polyline from two points
                        IPoint fromPoint = new PointClass();
                        IPoint toPoint = new PointClass();
                        IPolyline polyLine = new PolylineClass();
                        IDisplacementLinkElement link = new DisplacementLinkElementClass();

                        fromPoint.ID = toPoint.ID = _objId;

                        fromPoint.PutCoords(_fromX, _fromY);
                        polyLine.FromPoint = fromPoint;

                        toPoint.PutCoords(_toX, _toY);
                        polyLine.ToPoint = toPoint;

                        //Instantiate a new displacement link and set symbology

                        link.Symbol = linkSymbol;

                        IElement element = link as IElement;

                        //Set the geometry and add to the elements collections
                        element.Geometry = polyLine;
                        elements.Add(element, 0);

                        /*
                        #region DELETE this - for testing only

                        string line = "";
                        line = _objId.ToString()
                            + "\t" + secondaryText
                            + "\t" + _fromX.ToString()
                            + "\t" + _fromY.ToString()
                            + "\t" + this.cbMaster.SelectedItem.ToString()
                            + "\t" + _toX.ToString()
                            + "\t" + _toY.ToString();

                        tw.WriteLine(line);

                        #endregion
                        */

                    }

                    this.CreateErrorLayer(masterText, secondaryText);
                    graphicsContainer.AddElements(elements, 0);
                    mxDocument.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                    theHourGlass.end();
                    this._form.Close();

                }
            }
            catch (Exception ex)
            {
                if (this._form != null)
                {
                    this._form.Dispose();
                    this._form = null;
                }
                string msg = "Exception caught building the spacial adjustment links layer: " + Environment.NewLine
                    + ex.Message + Environment.NewLine + ex.StackTrace;
                MessageBox.Show(msg,"Build Links Error", MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                                );
                util.Logger.Write(msg);
            }
        }
Esempio n. 2
0
        private void _form_Closed(object sender, EventArgs e)
        {
            // Decouple event handlers
            this._form.Closed -= new EventHandler(_form_Closed);
            this._form.cbMaster.SelectedIndexChanged -= new System.EventHandler(_form_cbMaster_SelectedIndexChanged);
            this._form.cbSecondLayer.SelectedIndexChanged -= new System.EventHandler(_form_cbSecondLayer_SelectedIndexChanged);
            this._form.btnBuildLink.Click -= new System.EventHandler(_form_btnBuildLink_Click);
            this._form.btnCancel.Click -= new System.EventHandler(_form_btnCancel_Click);

            IMap theMap = this.Extension.FocusMap;
            try
            {
                // Clean up the error layer in the map

                /*   IFeatureLayer theErrorLayer = this.ErrorLayer;
                   if (theErrorLayer != null)
                   theMap.DeleteLayer((ILayer)theErrorLayer);
               */

                // Remove any extra feedback
                /// if (this._extraFeedback != null)
                ///  {
                ///      IGraphicsContainer theGCont = util.GraphicsHelper.get_GraphicsContainer(theMap);
                ///      theGCont.DeleteElement(this._extraFeedback);
                ///       this._extraFeedback = null;
                ///   }

                this._form.Dispose();
                /*
                // Stop listening to map selection events
                if (this._selectionEventHandler != null)
                {
                    try
                    {
                        ((IActiveViewEvents_Event)theMap).SelectionChanged -= this._selectionEventHandler;
                    }
                    catch (Exception ex)
                    {
                        util.Logger.Write("Exception caught disposing selection evt handler in ErrorManagerCmd::_form_Closed(): " + Environment.NewLine
                            + ex.Message + Environment.NewLine + ex.StackTrace);
                    }
                    this._selectionEventHandler = null;
                }*/

            }
            catch (Exception ex)
            {
                util.Logger.Write("Exception caught disposing of the Error Management form:" + Environment.NewLine
                    + ex.Message + ex.StackTrace);
            }
            finally
            {
                this._form = null;
                ((IActiveView)theMap).Refresh();
                Marshal.ReleaseComObject(theMap);
            }
        }
Esempio n. 3
0
        public void Open()
        {
            if (this._form != null)
            {
                this._form.Activate();
                return;
            }

            IMap theMap = this.Extension.FocusMap;
            try
            {

                if (Enabled == true)
                {
                    // Create error management dialog
                    this._form = new AdjustmentLinkTool();
                    // Establish event handlers
                    this._form.Closed += new EventHandler(_form_Closed);
                    this._form.cbMaster.SelectedIndexChanged += new System.EventHandler(_form_cbMaster_SelectedIndexChanged);
                    this._form.cbSecondLayer.SelectedIndexChanged += new System.EventHandler(_form_cbSecondLayer_SelectedIndexChanged);
                    this._form.btnBuildLink.Click += new System.EventHandler(_form_btnBuildLink_Click);
                    this._form.btnCancel.Click += new System.EventHandler(_form_btnCancel_Click);

                    this.FillMasterList();
                    this._form.Show();
                }
            }
            catch (Exception ex)
            {
                if (this._form != null)
                {
                    this._form.Dispose();
                    this._form = null;
                }

                util.Logger.Write("Exception caught opening the Adjustment Link Tool: " + Environment.NewLine
                    + ex.Message + Environment.NewLine + ex.StackTrace);
            }
            finally
            {
                Marshal.ReleaseComObject(theMap);
            }
        }