Ejemplo n.º 1
0
        private void showPrintDialog(string sPrinterName)
        {
            //System.Windows.Forms.MessageBox.Show("OOPS!!!! Keith , I found a bug here  at the last minute.Go to File --> Print to print. Sorry.", "OOPS!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            //// create and show...

            IMxDocument pMxDoc = (IMxDocument)this.App.Document;
            IPage       pPage  = (IPage)pMxDoc.PageLayout.Page;

            CSpatialSubs   oSpatialSubs = new CSpatialSubs();
            IMxApplication pMxApp       = (IMxApplication)this.App;

            ESRI.ArcGIS.Output.IPrinter pPrinter = pMxApp.Printer;
            ESRI.ArcGIS.Output.IPaper   pPaper   = pPrinter.Paper;

            int iPageFormID = 0;   // see http://msdn.microsoft.com/en-us/library/ms776398(VS.85).aspx for IPaper::FormID constants

            pMxDoc.PageLayout.Page.Orientation = 2;
            pPaper.Orientation = 2;

            ESRI.ArcGIS.OutputUI.IPrintDialog dialog = new ESRI.ArcGIS.OutputUI.PrintDialogClass();
            dialog.PageLayout = pMxDoc.PageLayout;
            dialog.Printer    = pMxApp.Printer;
            dialog.DoModal(0, pPage);



            //dialog.Printer.Paper.PrinterName = sPrinterName;
            //dialog.Printer.Paper.FormID = (short)iPageFormID;
            //dialog.DoModal(0,pPage);


            //switch (this.cboMapSize.SelectedItem.ToString())
            //{
            //    case "34 x 44": //34 x 44
            //        if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
            //            iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "34 x 44");
            //        else
            //            iPageFormID = 26;
            //        break;
            //    case "17 x 22": // 17 x 22
            //        if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
            //            iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "17 x 22");
            //        else
            //            iPageFormID = 24;
            //        break;
            //    case "11 x 17": // 11 x 22
            //        if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
            //            iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "11 x 17");
            //        else
            //            iPageFormID = 17;
            //        break;
            //    case "8.5 x 11": // 8.5 x 11
            //        if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
            //            iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "8.5 x 11");
            //        else
            //            iPageFormID = 1;
            //        break;
            //}
        }
		public override void OnCreate(object hook)
		{
			if (hook != null)
			{
				if ((hook) is IMxApplication)
					m_application = (IMxApplication)hook;
			}
		}
Ejemplo n.º 3
0
        public VisibilitySessionsController(IMxDocument mapDocument, IMxApplication application)
        {
            VisibilityManager.OnGenerationStarted += UpdateVisibilitySessionsList;
            this.mapDocument = mapDocument;
            this.application = application;

            _calcTypes = LocalizationContext.Instance.CalcTypeLocalisationShort;
            _states    = LocalizationContext.Instance.CalculationStates;
        }
Ejemplo n.º 4
0
        public void Startup(ref object initializationData)
        {
            IApplication pApp2;

            try
            {
                if ((initializationData is IMxApplication) || (initializationData is IMxApplication2))
                {
                    m_pApplication = (IMxApplication)initializationData;
                    try
                    {
                        try
                        {
                            pApp2 = (IApplication)m_pApplication;
                        }
                        catch (Exception EX)
                        {
                            if (!EventLog.SourceExists(m_sEventSource))
                            {
                                EventLog.CreateEventSource(m_sEventSource, m_sEventLog);
                            }
                            EventLog.WriteEntry(m_sEventSource, "Error wirring Events:" + EX.Message);
                        }
                    }
                    catch (Exception EX)
                    {
                        try
                        {
                            if (!EventLog.SourceExists(m_sEventSource))
                            {
                                EventLog.CreateEventSource(m_sEventSource, m_sEventLog);
                            }
                            EventLog.WriteEntry(m_sEventSource, "Error creating Performance Counter Category:" + EX.Message);
                        }
                        catch
                        {
                        }
                    }
                }
            }
            catch (Exception EX)
            {
                try
                {
                    if (!EventLog.SourceExists(m_sEventSource))
                    {
                        EventLog.CreateEventSource(m_sEventSource, m_sEventLog);
                    }
                    EventLog.WriteEntry(m_sEventSource, "Error creating Performance Counter Category:" + EX.Message);
                }
                catch
                {
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the editor
        /// </summary>
        /// <param name="mxApplication"></param>
        /// <returns>the editor</returns>
        public IEditor3 GetEditorFromArcMap(IMxApplication mxApplication)
        {
            if (mxApplication == null)
            {
                return(null);
            }
            ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "{F8842F20-BB23-11D0-802B-0000F8037368}";
            ESRI.ArcGIS.Framework.IApplication application = mxApplication as ESRI.ArcGIS.Framework.IApplication; // Dynamic Cast
            ESRI.ArcGIS.esriSystem.IExtension  extension   = application.FindExtensionByCLSID(uid);
            ESRI.ArcGIS.Editor.IEditor3        editor3     = extension as ESRI.ArcGIS.Editor.IEditor3;            // Dynamic Cast

            return(editor3);
        }
Ejemplo n.º 6
0
        public override void doPrintSetup(IPageLayout2 pPageLayout)
        {
            //IMxApplication pMxApp = (IMxApplication)this.App;
            //IMxDocument pMxDoc = (IMxDocument)this.App.Document;
            //ESRI.ArcGIS.esriSystem.IEnumNamedID pEnumNamedID = (ESRI.ArcGIS.esriSystem.IEnumNamedID)pMxApp.Printer.Paper.Forms;

            //IPrinter pPrinter = null;
            //IPaper pPaper = null;
            //IPage pPage = null;
            //IActiveView pActiveView = null;

            //short shPageForm = 0;  // see ms-help://ESRI.EDNv9.2/esricarto/html/esriPaperFormID.htm for IPrinter::FormID constants

            CSpatialSubs   oSpatialSubs = new CSpatialSubs();
            IMxApplication pMxApp       = (IMxApplication)ArcMap.ThisApplication;
            IMxDocument    pMxDoc       = (IMxDocument)ArcMap.Document;
            esriPageFormID pFormID      = esriPageFormID.esriPageFormLetter;

            IPrinter pPrinter = pMxApp.Printer;
            IPaper   pPaper   = pPrinter.Paper;

            int iPageFormID = 0;   // see http://msdn.microsoft.com/en-us/library/ms776398(VS.85).aspx for IPaper::FormID constants

            try
            {
                pMxDoc.PageLayout.Page.Orientation = 2;
                pPaper.Orientation = 2;

                switch (base.MapSize)
                {
                case "34 x 44":     //34 x 44
                    if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
                    {
                        iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "34 x 44");
                    }
                    else
                    {
                        iPageFormID = 26;
                    }
                    pFormID      = esriPageFormID.esriPageFormE;
                    base.XFactor = 4;
                    base.YFactor = 4;
                    break;

                case "17 x 22":     // 17 x 22
                    if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
                    {
                        iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "17 x 22");
                    }
                    else
                    {
                        iPageFormID = 24;
                    }
                    pFormID      = esriPageFormID.esriPageFormD;
                    base.XFactor = 2;
                    base.YFactor = 2;
                    break;

                case "11 x 17":     // 11 x 22
                    if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
                    {
                        iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "11 x 17");
                    }
                    else
                    {
                        iPageFormID = 17;
                    }
                    pFormID      = esriPageFormID.esriPageFormLegal;
                    base.XFactor = 1.5455;       //1.5455;
                    base.YFactor = 1.2941;       //1.2941;
                    break;

                case "8.5 x 11":     // 8.5 x 11
                    if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
                    {
                        iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "8.5 x 11");
                    }
                    else
                    {
                        iPageFormID = 1;
                    }
                    pFormID      = esriPageFormID.esriPageFormLetter;
                    base.XFactor = 1;
                    base.YFactor = 1;
                    break;
                }

                pPaper.PrinterName = base.PrinterName;
                pPaper.FormID      = (short)iPageFormID;

                double dblWidth  = 0;
                double dblHeight = 0;
                pPaper.QueryPaperSize(out dblWidth, out dblHeight);

                pMxDoc.PageLayout.Page.PutCustomSize(dblWidth, dblHeight);
                //pMxDoc.PageLayout.Page.FormID = (esriPageFormID)Enum.Parse(typeof(esriPageFormID), iPageFormID.ToString());

                pMxDoc.PageLayout.Page.FormID = pFormID;

                IPage pPage = pMxDoc.PageLayout.Page;
                pPage.Orientation = 2;
                pPage.FormID      = esriPageFormID.esriPageFormSameAsPrinter;

                pMxDoc.ActiveView.PrinterChanged(pPrinter);
                pMxDoc.ActiveView.Refresh();


                ////----------------------------------------------------------------------------
                ////Set the printer paper size and orientation.
                ////----------------------------------------------------------------------------
                //pPrinter = pMxApp.Printer;
                //pPrinter.Paper.PrinterName = base.PrinterName;
                //pPrinter.Paper.FormID = shPageForm;
                //pPrinter.Paper.Orientation = 2;

                //pPaper = pMxApp.Paper;
                //pPaper.Orientation = 2;
                //pPaper.FormID = (short)iPaperFormID;

                //pPaper.PrinterName = base.PrinterName;

                //pMxDoc.ActiveView.PrinterChanged(pPrinter);

                ////----------------------------------------------------------------------------
                ////Set the layout page size and orientation.
                ////----------------------------------------------------------------------------
                //pPage = pMxDoc.PageLayout.Page;
                //pPage.Orientation = 1;

                //double dblWidth = 0; double dblHeight = 0;
                //pPaper.QueryPaperSize(out dblWidth, out dblHeight);

                //pPage.PutCustomSize(dblWidth, dblHeight);

                ////pPage.FormID = esriPaperFormID.esriPageFormSameAsPrinter; // (esriPaperFormID)Enum.Parse(typeof(esriPaperFormID), shPageForm.ToString());
                ////pPage.PageToPrinterMapping = esriPageToPrinterMapping.esriPageMappingScale;

                //pPage.PrinterChanged(pPrinter);

                //pMxApp.Printer = pPrinter;
                ////pMxDoc.PageLayout = (IPageLayout)pPage.;

                //pActiveView = (IActiveView)pMxDoc.ActiveView;
                //pActiveView.Refresh();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Errors: CLandscapeLayout:doPrintSetup()\r\n" + ex.Message, "Errors occurred", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
            finally
            {
                pMxDoc   = null;
                pPrinter = null;
                pPaper   = null;
            }
        }
Ejemplo n.º 7
0
        public override void doPrintSetup(IPageLayout2 pPageLayout)
        {
            CSpatialSubs oSpatialSubs = new CSpatialSubs();

            //short shPageForm = 0;  // see ms-help://ESRI.EDNv9.2/esricarto/html/esriPageFormID.htm for IPrinter::FormID constants
            int iPageFormID = 0;   // see http://msdn.microsoft.com/en-us/library/ms776398(VS.85).aspx for IPaper::FormID constants
            //double dblPageWidth = 0;
            //double dblPageHeight = 0;

            IMxApplication pMxApp = (IMxApplication)this.App;
            IMxDocument    pMxDoc = (IMxDocument)this.App.Document;

            IPrinter pPrinter = pMxApp.Printer;
            IPaper   pPaper   = pPrinter.Paper;

            try
            {
                pMxDoc.PageLayout.Page.Orientation = 1;
                pPaper.Orientation = 1;

                switch (this.MapSize)
                {
                case "34 x 44":
                    //shPageForm = 5; // esriPageFormID.esriPageFormE;

                    base.XFactor = 4;
                    base.YFactor = 4;

                    if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
                    {
                        iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "34 x 44");
                    }
                    else
                    {
                        iPageFormID = 26;
                    }

                    break;

                case "17 x 22":
                    //shPageForm = 3; // esriPageFormID.esriPageFormC;

                    base.XFactor = 2;
                    base.YFactor = 2;

                    if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
                    {
                        iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "17 x 22");
                    }
                    else
                    {
                        iPageFormID = 24;
                    }

                    break;

                case "11 x 17":
                    //shPageForm = 2; // esriPageFormID.esriPageFormTabloid;

                    base.XFactor = 1.3;      //1.2941
                    base.YFactor = 1.5455;   //1.5455

                    if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
                    {
                        iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "11 x 17");
                    }
                    else
                    {
                        iPageFormID = 17;
                    }

                    break;

                case "8.5 x 11":
                    //shPageForm = 0; // esriPageFormID.esriPageFormLetter;

                    base.XFactor = 1;
                    base.YFactor = 1;

                    if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
                    {
                        iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "8.5 x 11 ");
                    }
                    else
                    {
                        iPageFormID = 1;
                    }
                    break;
                }

                pPaper.PrinterName = base.PrinterName;
                pPaper.FormID      = (short)iPageFormID;

                double dblWidth  = 0;
                double dblHeight = 0;
                pPaper.QueryPaperSize(out dblWidth, out dblHeight);

                pMxDoc.PageLayout.Page.PutCustomSize(dblWidth, dblHeight);
                pMxDoc.PageLayout.Page.FormID = (esriPageFormID)Enum.Parse(typeof(esriPageFormID), iPageFormID.ToString());


                pMxDoc.ActiveView.PrinterChanged(pPrinter);



                //////----------------------------------------------------------------------------
                //////Set the layout page size and orientation.
                //////----------------------------------------------------------------------------
                //pPage = pMxDoc.PageLayout.Page;
                //pPage.Orientation = 1;
                //pPage.FormID = (esriPageFormID)Enum.Parse(typeof(esriPageFormID), iPageFormID.ToString());

                ////----------------------------------------------------------------------------
                ////Set the printer paper size and orientation.
                ////----------------------------------------------------------------------------
                //pPrinter = pMxApp.Printer;
                //pPrinter.Paper.PrinterName = base.PrinterName;
                //pPrinter.Paper.FormID = shPageForm;
                //pPrinter.Paper.Orientation = 1;

                ////----------------------------------------------------------------------------
                //// deal with the paper
                ////----------------------------------------------------------------------------
                //pPaper = pMxApp.Paper;
                //pPaper.Orientation = 1;
                //pPaper.FormID = (short)iPageFormID;
                //pPaper.PrinterName = base.PrinterName;


                //pMxDoc.ActiveView.PrinterChanged(pPrinter);

                ////////----------------------------------------------------------------------------
                ////////Set the layout page size and orientation.
                ////////----------------------------------------------------------------------------
                ////pPage = pMxDoc.PageLayout.Page;
                ////pPage.Orientation = 1;
                ////pPage.FormID = esriPageFormID.esriPageFormCUSTOM;
                ////pPage.PutCustomSize(dblPageWidth + .1, dblPageHeight + .1);
                ////pPage.PrinterChanged(pPrinter);

                ////double dblWidth = 0; double dblHeight = 0;
                ////pPaper.QueryPaperSize(out dblWidth, out dblHeight);

                ////pPage.PutCustomSize(dblWidth, dblHeight);   //(dblWidth, dblHeight);
                ////pPage.FormID = esriPageFormID.esriPageFormCUSTOM;
                ////pPage.PrinterChanged(pPrinter);

                ////pPage.PutCustomSize(dblWidth, dblHeight);
                ////pPage.PageToPrinterMapping = esriPageToPrinterMapping.esriPageMappingTile;

                //pMxApp.Printer = pPrinter;
                ////pMxDoc.PageLayout = (IPageLayout)pPage;
                //pMxDoc.PageLayout.Page.PutCustomSize(dblPageWidth - 1.8, dblPageHeight - 1.8);
                //pMxDoc.PageLayout.Page.FormID = esriPageFormID.esriPageFormSameAsPrinter;
                //pMxDoc.ActiveView.PrinterChanged(pPrinter);

                //pActiveView = (IActiveView)pMxDoc.ActiveView;
                //pActiveView.Refresh();

                //pMxApp.Printer.Paper.PrinterName = base.PrinterName;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Errors: CPortraitLayout:doPrintSetup()\r\n" + ex.Message, "Errors occurred", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
            finally
            {
                pMxDoc   = null;
                pPrinter = null;
                pPaper   = null;
                oSpatialSubs.Dispose();
            }
        }
        private static string GetFormattedString(string strTextContent, string strFontName, Single sngFontSizeInPoints, double sngMaxWidthInPoints, long hanging)
        {
            System.Array           varWordArray;
            IMxApplication         pMxApp          = ArcMap.Application as IMxApplication;
            IAppDisplay            pAppDisplay     = pMxApp.Display;
            IDisplayTransformation pTransformation = pAppDisplay.DisplayTransformation;
            IFontDisp   pTextFont   = new stdole.StdFontClass() as IFontDisp;
            ITextSymbol pTextSymbol = new TextSymbolClass();
            double      dblXSize;
            double      dblYSize;
            string      strGoodWidth   = "";
            string      strFinalString = "";
            string      strTestString  = "";
            int         i;

            // Split the string into an array of words
            varWordArray = strTextContent.Split(' ') as System.Array;

            // Set up the Font
            pTextFont.Name = strFontName;
            pTextFont.Size = decimal.Parse(sngFontSizeInPoints.ToString());

            // Setup the Text Symbol
            pTextSymbol.Font = pTextFont;

            // Add each word into the test string and test for width
            pAppDisplay.StartDrawing(pAppDisplay.hDC, 0);
            long linesAdded = 0;

            for (i = 0; i <= (int)varWordArray.GetUpperBound(0); i++)
            {
                if (strGoodWidth != "")
                {
                    strTestString = strGoodWidth + " " + varWordArray.GetValue(i);
                }
                else
                {
                    strTestString = varWordArray.GetValue(i).ToString();
                }

                // Get the TextSize
                pTextSymbol.GetTextSize(pAppDisplay.hDC, pTransformation, strTestString, out dblXSize, out dblYSize);

                // If the word added is < max width keep adding to the line, else make a new one
                if (dblXSize < sngMaxWidthInPoints)
                {
                    strGoodWidth = strTestString;
                }
                else
                {
                    if (linesAdded == 0)
                    {
                        strFinalString = strGoodWidth;
                    }
                    else
                    {
                        strFinalString = strFinalString + Environment.NewLine + strGoodWidth;
                    }
                    linesAdded   = linesAdded + 1;
                    strGoodWidth = varWordArray.GetValue(i).ToString();
                }
            }

            strFinalString = strFinalString + Environment.NewLine + strGoodWidth;
            pAppDisplay.FinishDrawing();

            return(strFinalString);
        }
Ejemplo n.º 9
0
        protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            int            X      = arg.X;
            int            Y      = arg.Y;
            IMxApplication pMxApp = null;
            IMxDocument    pMxDoc = null;

            pMxApp = (IMxApplication)ArcMap.Application;
            pMxDoc = (IMxDocument)ArcMap.Application.Document;

            // calculate tolerance rectangle to identify features inside it
            int Tolerance = 0;

            Tolerance = pMxDoc.SearchTolerancePixels;

            IDisplayTransformation pDispTrans = null;

            pDispTrans = pMxApp.Display.DisplayTransformation;
            tagRECT pToleranceRect = new tagRECT();

            pToleranceRect.left   = X - Tolerance;
            pToleranceRect.right  = X + Tolerance;
            pToleranceRect.top    = Y - Tolerance;
            pToleranceRect.bottom = Y + Tolerance;

            IEnvelope pSearchEnvelope = null;

            pSearchEnvelope = new EnvelopeClass();
            pDispTrans.TransformRect(pSearchEnvelope, ref pToleranceRect, (int)(esriDisplayTransformationEnum.esriTransformPosition | esriDisplayTransformationEnum.esriTransformToMap));

            // identify feature points of measurement
            IBasicDocument pBasicDoc = null;

            pBasicDoc = (IBasicDocument)ArcMap.Application.Document;
            pSearchEnvelope.SpatialReference = pMxDoc.ActiveView.FocusMap.SpatialReference;

            IIdentify pIdentify = null;

            pIdentify = (IIdentify)pMxDoc.FocusMap.get_Layer(0);
            if (pIdentify == null)
            {
                MessageBox.Show("No layer");
                return;
            }

            IArray pIDArray = null;

            pIDArray = pIdentify.Identify(pSearchEnvelope);

            // get object from feature point
            IIdentifyObj pIDObj = null;

            if (pIDArray != null)
            {
                pIDObj = (IIdentifyObj)pIDArray.get_Element(0);
            }

            if (pIDObj == null)
            {
                MessageBox.Show("No feature was identified");
                return;
            }

            // get the name of the layer containing feature points
            ILayer pLayer = null;

            pLayer = pMxDoc.FocusMap.get_Layer(0);

            string layerName = null;

            layerName = pLayer.Name;

            // get primary display field for measurement values and set names of a date/time field and gage ID field
            IFeatureLayer pFeatLayer = null;

            pFeatLayer = (IFeatureLayer)pLayer;
            string dataFldName   = null;
            string timefldName   = null;
            string gageIDFldName = null;

            dataFldName   = "TSValue";
            timefldName   = "TSDateTime"; // substitute data/time field name for different dataset
            gageIDFldName = "Name";       // substitute gage ID field name for different dataset

            // get display table from layer
            ITable        pTable        = null;
            IDisplayTable pDisplayTable = null;

            pDisplayTable = (IDisplayTable)pLayer;
            if (pDisplayTable != null)
            {
                pTable = pDisplayTable.DisplayTable;
                if (pTable == null)
                {
                    goto THEEND;
                }
            }

            // get fields from display table
            IFields pFields = null;

            pFields = pTable.Fields;
            long fldCount = 0;

            fldCount = pFields.FieldCount;

            // create WHERE clause from identified objects of measurement points
            int gageIDFldIdx = 0;

            gageIDFldIdx = pFields.FindField(gageIDFldName);

            IRowIdentifyObject pRowIDObj = null;

            pRowIDObj = (IRowIdentifyObject)pIDObj;

            string gageID = null;

            gageID = (string)pRowIDObj.Row.get_Value(gageIDFldIdx);

            IFeatureLayerDefinition pFeatureLayerDef = null;

            pFeatureLayerDef = (IFeatureLayerDefinition)pLayer;
            string definitionExpression = null;

            definitionExpression = pFeatureLayerDef.DefinitionExpression;

            string whereClause = null;

            if (definitionExpression == "")
            {
                whereClause = "[" + gageIDFldName + "] = '" + gageID + "'";
            }
            else
            {
                whereClause = "[" + gageIDFldName + "] = '" + gageID + "' AND " + definitionExpression;
            }

            //find color for the identified object from feature layer's renderer
            IGeoFeatureLayer pGeoFeatureLayer = null;

            pGeoFeatureLayer = (IGeoFeatureLayer)pLayer;

            ILookupSymbol pLookupSymbol = null;

            pLookupSymbol = (ILookupSymbol)pGeoFeatureLayer.Renderer;

            IFeature pFeature = null;

            pFeature = (IFeature)pRowIDObj.Row;

            IMarkerSymbol pSymbol = null;

            pSymbol = (IMarkerSymbol)pLookupSymbol.LookupSymbol(false, pFeature);

            // Find an opened GraphWindow
            IDataGraphBase    pDataGraphBase = null;
            IDataGraphT       pDataGraphT    = null;
            IDataGraphWindow2 pDGWin         = null;

            IDataGraphCollection pDataGraphs = null;

            pDataGraphs = (IDataGraphCollection)pMxDoc;
            int grfCount = 0;

            grfCount = pDataGraphs.DataGraphCount;
            for (int i = 0; i < grfCount; i++)
            {
                pDataGraphBase = pDataGraphs.get_DataGraph(i);
                pDGWin         = FindGraphWindow(ref pDataGraphBase);
                if (pDGWin != null)
                {
                    break;
                }
            }

            // if there is not an opened graph window - create a new graph for
            if (pDGWin == null)
            {
                // create graph
                pDataGraphT    = new DataGraphTClass();
                pDataGraphBase = (IDataGraphBase)pDataGraphT;

                // load template from <ARCGISHOME>\GraphTemplates\
                string strPath = null;
                strPath = Environment.GetEnvironmentVariable("ARCGISHOME");
                try
                {
                    pDataGraphT.LoadTemplate(strPath + @"GraphTemplates\timeseries.tee");
                }
                catch
                { }

                // graph, axis and legend titles. Substitute them for different input layer
                pDataGraphT.GeneralProperties.Title           = "Daily Streamflow for Guadalupe Basin in 1999";
                pDataGraphT.LegendProperties.Title            = "Monitoring Point";
                pDataGraphT.get_AxisProperties(0).Title       = "Streamflow (cfs)";
                pDataGraphT.get_AxisProperties(0).Logarithmic = true;
                pDataGraphT.get_AxisProperties(2).Title       = "Date";
                pDataGraphBase.Name = layerName;
            }
            else // get graph from the opened window
            {
                pDataGraphT = (IDataGraphT)pDataGraphBase;
            }

            // create vertical line series for all measurements for the identified gage
            ISeriesProperties pSP = null;

            pSP             = pDataGraphT.AddSeries("line:vertical");
            pSP.ColorType   = esriGraphColorType.esriGraphColorCustomAll;
            pSP.CustomColor = pSymbol.Color.RGB;
            pSP.WhereClause = whereClause;
            pSP.InLegend    = true;
            pSP.Name        = gageID;

            pSP.SourceData = pLayer;
            pSP.SetField(0, timefldName);
            pSP.SetField(1, dataFldName);
            IDataSortSeriesProperties pSortFlds = null;

            pSortFlds = (IDataSortSeriesProperties)pSP;
            int idx = 0;

            pSortFlds.AddSortingField(timefldName, true, ref idx);


            pDataGraphBase.UseSelectedSet = true;

            ITrackCancel pCancelTracker = null;

            pCancelTracker = new CancelTracker();
            pDataGraphT.Update(pCancelTracker);

            // create data graph window if there is not any opened one
            if (pDGWin == null)
            {
                pDGWin = new DataGraphWindowClass();
                pDGWin.DataGraphBase = pDataGraphBase;
                pDGWin.Application   = ArcMap.Application;
                pDGWin.Show(true);

                pDataGraphs.AddDataGraph(pDataGraphBase);
            }

THEEND:
            return;

            //base.OnMouseDown(arg);
        }
        protected override void OnMouseUp(MouseEventArgs arg)
        {
            // Did they click the left mouse button?
            if (arg.Button == System.Windows.Forms.MouseButtons.Left)
            {
                // Get some application environment variables set
                IMxApplication mxApp = (IMxApplication)ArcMap.Application;

                // Get the clicked location in map units
                IPoint clickedPoint = mxApp.Display.DisplayTransformation.ToMapPoint(arg.Location.X, arg.Location.Y);

                // If this is the first click on the map...
                switch (numberOfClicks)
                {
                case 0:
                    // This is the first click, giving the location of the measurement.
                    measurementLocationX = clickedPoint.X;
                    measurementLocationY = clickedPoint.Y;

                    // Increment the click counter
                    numberOfClicks = 1;

                    // Change the cursor
                    System.Windows.Forms.Cursor firstCursor = new System.Windows.Forms.Cursor(GetType(), "Cursors.firstPointCursor.cur");
                    Cursor = firstCursor;

                    break;

                case 1:
                    // This is the second click, giving the first end of the strike line, according to right-hand rule.
                    firstEndX = clickedPoint.X;
                    firstEndY = clickedPoint.Y;

                    // Increment the click counter
                    numberOfClicks = 2;

                    // Change the cursor
                    System.Windows.Forms.Cursor secondCursor = new System.Windows.Forms.Cursor(GetType(), "Cursors.SecondPointCursor.cur");
                    Cursor = secondCursor;

                    break;

                case 2:
                    // This is the third click, giving the second end of the strike line, according to right-hand rule.
                    secondEndX = clickedPoint.X;
                    secondEndY = clickedPoint.Y;

                    // Increment the click counter
                    numberOfClicks = 3;

                    // Change the cursor
                    //base.m_cursor = Properties.Resources.GetDipCursor;

                    // Calculate the Strike from the two collected points
                    int theStrike = GetStrike(firstEndX, firstEndY, secondEndX, secondEndY);

                    // Get the dip input
                    int    theDip;
                    string inputValue = "";

getDipValue:
                    if (genericForms.InputBox("Digitize Structure Points", "Please enter the dip value", ref inputValue) == DialogResult.OK)
                    {
                        // Make sure they entered a valid dip value
                        int  dipValue;
                        bool result = int.TryParse(inputValue, out dipValue);

                        if (result == true)
                        {
                            // inputValue is an integer
                            if (dipValue >= -90)
                            {
                                if (dipValue <= 90)
                                {
                                    // inputValue is in the appropriate range
                                    theDip = int.Parse(inputValue);
                                }
                                else
                                {
                                    goto getDipValue;
                                }
                            }
                            else
                            {
                                goto getDipValue;
                            }
                        }
                        else
                        {
                            goto getDipValue;
                        }
                    }
                    else
                    {
                        // In this case, the action was canceled during the dip input. Reset the counter, cursor, and exit the routine.
                        numberOfClicks = 0;
                        //base.m_cursor = Properties.Resources.firstPointCursor;
                        return;
                    }

                    // Now we need to create the feature. First we'll find the current FeatureTemplate
                    IEditor3      templateEditor     = (IEditor3)ArcMap.Editor;
                    IEditTemplate theCurrentTemplate = templateEditor.CurrentTemplate;

                    // If they didn't select a template, they'll need to
                    if (theCurrentTemplate == null)
                    {
                        MessageBox.Show("Please select a feature template for the type of measurement that you're digitizing", "NCGMP Tools");
                        numberOfClicks = 0;
                        System.Windows.Forms.Cursor locCursor = new System.Windows.Forms.Cursor(GetType(), "Cursors.StationLocCursor.cur");
                        Cursor = locCursor;
                        return;
                    }

                    // Make sure that the template puts features into the OrientationPoints FeatureClass
                    IFeatureClass templateFC = ((IFeatureLayer)theCurrentTemplate.Layer).FeatureClass;
                    if (templateFC.Equals(commonFunctions.OpenFeatureClass(ArcMap.Editor.EditWorkspace, "OrientationPoints")))
                    {
                        try
                        {
                            // Create a dummy feature and read in values from the feature template
                            IFeature tempFeature = templateFC.CreateFeature();
                            theCurrentTemplate.SetDefaultValues(tempFeature);

                            // Grab values from the dummy feature - the code is actually cleaner than grabbing the values from the FeatureTemplate
                            string StationID = "";
                            string Type      = tempFeature.get_Value(templateFC.FindField("Type")).ToString();
                            string IDConf    = tempFeature.get_Value(templateFC.FindField("IdentityConfidence")).ToString();
                            string Label     = tempFeature.get_Value(templateFC.FindField("Label")).ToString();
                            string Notes     = tempFeature.get_Value(templateFC.FindField("Notes")).ToString();

                            int  Plot;
                            bool result = int.TryParse(tempFeature.get_Value(templateFC.FindField("PlotAtScale")).ToString(), out Plot);

                            double OrientConf;
                            result = double.TryParse(tempFeature.get_Value(templateFC.FindField("OrientationConfidenceDegrees")).ToString(), out OrientConf);

                            int RuleID;
                            result = int.TryParse(tempFeature.get_Value(templateFC.FindField("RuleID")).ToString(), out RuleID);

                            string DataSourceID = commonFunctions.GetCurrentDataSourceID();

                            int SymbolRot = 360 - theStrike;

                            IPoint Shape = new PointClass();
                            Shape.X = measurementLocationX;
                            Shape.Y = measurementLocationY;

                            // Remove the temporary Feature
                            tempFeature.Delete();

                            // Create the new feature
                            OrientationPointsAccess OdpAccess = new OrientationPointsAccess(ArcMap.Editor.EditWorkspace);
                            OdpAccess.NewOrientationPoint(StationID, Type, IDConf, Label, Plot, (double)theStrike, (double)theDip, OrientConf, Notes, DataSourceID, SymbolRot, RuleID, Shape);
                            OdpAccess.SaveOrientationPoints();

                            // Refresh the Active View
                            ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, theCurrentTemplate.Layer, null);
                        }
                        catch
                        {
                            MessageBox.Show("Create feature didn't work.", "NCGMP Tools");
                            numberOfClicks = 0;
                            System.Windows.Forms.Cursor locCursor = new System.Windows.Forms.Cursor(GetType(), "Cursors.StationLocCursor.cur");
                            Cursor = locCursor;
                            return;
                        }
                    }
                    else
                    {
                        // User needs to select a relevant feature template
                        MessageBox.Show("Please select a valid feature template to digitize structural measurements.", "NCGMP Tools");
                    }

                    // Finished successfully, reset the counter and cursor
                    numberOfClicks = 0;
                    System.Windows.Forms.Cursor theLocCursor = new System.Windows.Forms.Cursor(GetType(), "Cursors.StationLocCursor.cur");
                    Cursor = theLocCursor;
                    break;

                default:
                    // Don't do anything here, preventing any more input before the dip is entered and the counter resets
                    break;
                }
            }
        }
Ejemplo n.º 11
0
        public void CalculatePingsNPoints(string sSounderLayer, string sSedCoreLayer, string strDepthValField, long numpoints, double dblIterationRange)
        {
            try
            {
                IMxApplication pMxApp      = ArcMap.Application  as IMxApplication;
                IMxDocument    pmxdoc      = ArcMap.Document as IMxDocument;
                IMap           pmap        = pmxdoc.FocusMap;
                IActiveView    pActiveView = pmap as IActiveView;


                //clear any previous selections so they wont interfere
                pmap.ClearSelection();


                IFeatureLayer     pSounderLayer    = FindLayer(pmap, sSounderLayer) as IFeatureLayer;
                IFeatureSelection pSounderLayerSel = pSounderLayer as IFeatureSelection;



                IFeatureLayer     pSedCoreLayer    = FindLayer(pmap, sSedCoreLayer) as IFeatureLayer;
                IFeatureSelection pSedCoreLayerSel = pSedCoreLayer as IFeatureSelection;

                //Add fields to hold the data if they do not exist already.
                string strAvgfld = "Avg_" + strDepthValField;

                if (strAvgfld.Length > 9)
                {
                    strAvgfld = strAvgfld.Substring(0, 8);
                    strAvgfld = AddField(pSedCoreLayer, strAvgfld);
                }
                else
                {
                    strAvgfld = AddField(pSedCoreLayer, strAvgfld);
                }



                string strStdFld = "Std_" + strDepthValField;

                if (strStdFld.Length > 9)
                {
                    strStdFld = strStdFld.Substring(0, 8);
                    strStdFld = AddField(pSedCoreLayer, strStdFld);
                }
                else
                {
                    strStdFld = AddField(pSedCoreLayer, strStdFld);
                }


                string strSampFld = AddField(pSedCoreLayer, "Samp_Size");


                //Get a cursor from the sample layer
                IFeatureCursor pFCur    = pSedCoreLayer.Search(null, false);
                IFeature       pFeature = pFCur.NextFeature();

                int iPointProgress = 1;
                IProgressDialog2 pProgressDialog = ShowProgressIndicator("Calculating...", pSedCoreLayer.FeatureClass.FeatureCount(null), 1);
                pProgressDialog.Description = "Processing Point: " + iPointProgress + " of " + pSedCoreLayer.FeatureClass.FeatureCount(null).ToString();
                pProgressDialog.ShowDialog();

                //Each point will be buffered at "dblRange" until the desired amount of points are collected.
                double dblRange        = dblIterationRange;
                long   lngFeatureCount = 0;

                while (pFeature != null)
                {
                    //loop thru the featureclass, selecting each feature at a time.
                    SelectFeatures(pSedCoreLayer, pSedCoreLayer.FeatureClass.OIDFieldName + " = " + pFeature.OID);

                    //Select Depth features within the range of the previously selected Sample point features
                    lngFeatureCount = SpatialSelect(sSounderLayer, sSedCoreLayer, dblRange, pmap.MapUnits);

                    //If we reach the user-entered point threshold, stop and calculate.
                    if (lngFeatureCount >= numpoints)
                    {
                        IStatisticsResults pStats = GetDataStatistics(pSounderLayer, strDepthValField);
                        pFeature.set_Value(pFeature.Fields.FindField(strAvgfld), pStats.Mean);
                        pFeature.set_Value(pFeature.Fields.FindField(strStdFld), pStats.StandardDeviation);
                        pFeature.set_Value(pFeature.Fields.FindField(strSampFld), lngFeatureCount);
                        pSounderLayerSel.Clear();
                        pSedCoreLayerSel.Clear();
                        pFeature.Store();

                        dblRange = .1;
                        pFeature = pFCur.NextFeature();
                        pStepProgressor.Step();
                        iPointProgress++;
                        pProgressDialog.Description = "Processing Point: " + iPointProgress + " of " + pSedCoreLayer.FeatureClass.FeatureCount(null).ToString();
                    }
                    else
                    {
                        dblRange = dblRange + dblIterationRange;
                    }
                }


                pProgressDialog.HideDialog();

                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
            }
        }
Ejemplo n.º 12
0
        public void CalculatePingsWithDistance(string sSounderLayer, string sSedCoreLayer, string strDepthField, double dblRange, string strUnits)
        {
            try{
                IMxApplication pMxApp      = ArcMap.Application  as IMxApplication;
                IMxDocument    pmxdoc      = ArcMap.Document as IMxDocument;
                IMap           pmap        = pmxdoc.FocusMap;
                IActiveView    pActiveView = pmap as IActiveView;


                pmap.ClearSelection();

                IFeatureLayer     pSounderLayer    = FindLayer(pmap, sSounderLayer) as IFeatureLayer;
                IFeatureSelection pSounderLayerSel = pSounderLayer as IFeatureSelection;



                IFeatureLayer     pSedCoreLayer    = FindLayer(pmap, sSedCoreLayer) as IFeatureLayer;
                IFeatureSelection pSedCoreLayerSel = pSedCoreLayer as IFeatureSelection;
                //Add fields to hold the data if they do not exist already.
                string strAvgfld = "Avg_" + strDepthField;

                if (strAvgfld.Length > 9)
                {
                    strAvgfld = strAvgfld.Substring(0, 8);
                    strAvgfld = AddField(pSedCoreLayer, strAvgfld);
                }
                else
                {
                    strAvgfld = AddField(pSedCoreLayer, strAvgfld);
                }



                string strStdFld = "Std_" + strDepthField;

                if (strStdFld.Length > 9)
                {
                    strStdFld = strStdFld.Substring(0, 8);
                    strStdFld = AddField(pSedCoreLayer, strStdFld);
                }
                else
                {
                    strStdFld = AddField(pSedCoreLayer, strStdFld);
                }



                string strSampFld = AddField(pSedCoreLayer, "Samp_Size");

                esriUnits eEsriUnitsContant = 0;

                //set the units
                switch (strUnits)
                {
                case "Feet":
                    eEsriUnitsContant = esriUnits.esriFeet;
                    break;

                case "Meters":
                    eEsriUnitsContant = esriUnits.esriMeters;
                    break;

                case "Kilometers":
                    eEsriUnitsContant = esriUnits.esriKilometers;
                    break;
                }


                IFeatureCursor pFCur    = pSedCoreLayer.Search(null, false);
                IFeature       pFeature = pFCur.NextFeature();
                pSedCoreLayerSel.Clear();

                int iPointProgress = 1;
                IProgressDialog2 pProgressDialog = ShowProgressIndicator("Calculating...", pSedCoreLayer.FeatureClass.FeatureCount(null), 1);
                pProgressDialog.Description = "Processing Point: " + iPointProgress + " of " + pSedCoreLayer.FeatureClass.FeatureCount(null).ToString();
                pProgressDialog.ShowDialog();

                long lFeatureCount = 0;
                while (pFeature != null)
                {
                    pStepProgressor.Step();
                    pProgressDialog.Description = "Processing Point: " + iPointProgress + " of " + pSedCoreLayer.FeatureClass.FeatureCount(null).ToString();
                    //loop thru the featureclass, selecting each feature at a time.
                    SelectFeatures(pSedCoreLayer, pSedCoreLayer.FeatureClass.OIDFieldName + " = " + pFeature.OID);

                    //Select Depth features within the range of the previously selected Sample point features
                    lFeatureCount = SpatialSelect(sSounderLayer, sSedCoreLayer, dblRange, eEsriUnitsContant);

                    //Calculate
                    IStatisticsResults pStats = GetDataStatistics(pSounderLayer, strDepthField);
                    pFeature.set_Value(pFeature.Fields.FindField(strAvgfld), pStats.Mean);
                    pFeature.set_Value(pFeature.Fields.FindField(strStdFld), pStats.StandardDeviation);
                    pFeature.set_Value(pFeature.Fields.FindField(strSampFld), lFeatureCount);
                    pSounderLayerSel.Clear();
                    pSedCoreLayerSel.Clear();
                    pFeature.Store();
                    pFeature = pFCur.NextFeature();
                    iPointProgress++;
                }


                pProgressDialog.HideDialog();
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
            }
        }