/// <summary> /// Method is invoked to complete a drag & drop operation with a (new) docking position /// by docking of the LayoutAnchorable <paramref name="floatingWindow"/> into this drop target. /// </summary> /// <param name="floatingWindow"></param> protected override void Drop(LayoutAnchorableFloatingWindow floatingWindow) { ILayoutPane targetModel = _targetPane.Model as ILayoutPane; switch (Type) { case DropTargetType.DocumentPaneGroupDockInside: #region DropTargetType.DocumentPaneGroupDockInside { var paneGroupModel = targetModel as LayoutDocumentPaneGroup; var paneModel = paneGroupModel.Children[0] as LayoutDocumentPane; var layoutAnchorablePaneGroup = floatingWindow.RootPanel as LayoutAnchorablePaneGroup; int i = 0; foreach (var anchorableToImport in layoutAnchorablePaneGroup.Descendents().OfType <LayoutAnchorable>().ToArray()) { // BD: 18.07.2020 Remove that bodge and handle CanClose=false && CanHide=true in XAML //anchorableToImport.SetCanCloseInternal(true); paneModel.Children.Insert(i, anchorableToImport); i++; } } break; #endregion DropTargetType.DocumentPaneGroupDockInside } base.Drop(floatingWindow); }
protected override void Drop(LayoutAnchorableFloatingWindow floatingWindow) { ILayoutPane targetModel = _targetPane.Model as ILayoutPane; switch (Type) { case DropTargetType.DocumentPaneGroupDockInside: #region DropTargetType.DocumentPaneGroupDockInside { var paneGroupModel = targetModel as LayoutDocumentPaneGroup; var paneModel = paneGroupModel.Children[0] as LayoutDocumentPane; var layoutAnchorablePaneGroup = floatingWindow.RootPanel as LayoutAnchorablePaneGroup; int i = 0; foreach (var anchorableToImport in layoutAnchorablePaneGroup.Descendents().OfType <LayoutAnchorable>().ToArray()) { if (anchorableToImport.CanClose) { anchorableToImport.SetCanCloseInternal(true); } paneModel.Children.Insert(i, anchorableToImport); i++; } } break; #endregion } base.Drop(floatingWindow); }
public void Float() { if (this.PreviousContainer == null || this.PreviousContainer.FindParent <LayoutFloatingWindow>() == null) { base.Root.Manager.StartDraggingFloatingWindowForContent(this, false); this.IsSelected = true; this.IsActive = true; return; } ILayoutPane parent = base.Parent as ILayoutPane; int num = (parent as ILayoutGroup).IndexOfChild(this); ILayoutGroup previousContainer = this.PreviousContainer as ILayoutGroup; if (this.PreviousContainerIndex >= previousContainer.ChildrenCount) { previousContainer.InsertChildAt(previousContainer.ChildrenCount, this); } else { previousContainer.InsertChildAt(this.PreviousContainerIndex, this); } this.PreviousContainer = parent; this.PreviousContainerIndex = num; this.IsSelected = true; this.IsActive = true; base.Root.CollectGarbage(); }
protected override void Drop(LayoutAnchorableFloatingWindow floatingWindow) { ILayoutPane targetModel = _targetPane.Model as ILayoutPane; switch (Type) { case DropTargetType.DocumentPaneGroupDockInside: { var paneGroupModel = targetModel as LayoutDocumentPaneGroup; if (paneGroupModel != null) { var paneModel = paneGroupModel.Children[0] as LayoutDocumentPane; var layoutAnchorablePaneGroup = floatingWindow.RootPanel; int i = 0; foreach ( var anchorableToImport in layoutAnchorablePaneGroup.Descendents().OfType <LayoutAnchorable>().ToArray()) { paneModel?.Children.Insert(i, anchorableToImport); i++; } } } break; } base.Drop(floatingWindow); }
protected override Size ArrangeOverride(Size finalSize) { Size desiredSize; IEnumerable <UIElement> uIElements = base.Children.Cast <UIElement>(); double right = 0; bool flag = false; using (IEnumerator <UIElement> enumerator = ( from ch in uIElements where ch.Visibility != System.Windows.Visibility.Collapsed select ch).GetEnumerator()) { while (enumerator.MoveNext()) { TabItem current = (TabItem)enumerator.Current; LayoutContent content = current.Content as LayoutContent; if (!flag) { desiredSize = current.DesiredSize; if (right + desiredSize.Width <= finalSize.Width) { current.Visibility = System.Windows.Visibility.Visible; Size size = current.DesiredSize; current.Arrange(new Rect(right, 0, size.Width, finalSize.Height)); double actualWidth = current.ActualWidth; Thickness margin = current.Margin; double left = actualWidth + margin.Left; margin = current.Margin; right = right + (left + margin.Right); continue; } } if (content.IsSelected && !current.IsVisible) { ILayoutContainer parent = content.Parent; ILayoutContentSelector layoutContentSelector = content.Parent as ILayoutContentSelector; ILayoutPane layoutPane = content.Parent as ILayoutPane; int num = layoutContentSelector.IndexOf(content); if (num > 0 && parent.ChildrenCount > 1) { layoutPane.MoveChild(num, 0); layoutContentSelector.SelectedContentIndex = 0; desiredSize = this.ArrangeOverride(finalSize); return(desiredSize); } } current.Visibility = System.Windows.Visibility.Hidden; flag = true; } return(finalSize); } return(desiredSize); }
protected override void Drop(LayoutDocumentFloatingWindow floatingWindow) { ILayoutPane model = this._targetPane.Model as ILayoutPane; if (base.Type == DropTargetType.DocumentPaneGroupDockInside) { LayoutDocumentPane item = (model as LayoutDocumentPaneGroup).Children[0] as LayoutDocumentPane; LayoutDocument rootDocument = floatingWindow.RootDocument; item.Children.Insert(0, rootDocument); } base.Drop(floatingWindow); }
public static async Task makeNewLayout() { Layout newLayout = await QueuedTask.Run <Layout>(() => { newLayout = LayoutFactory.Instance.CreateLayout(8.5, 11, LinearUnit.Inches); newLayout.SetName("MY NEW LAYOUT"); return(newLayout); }); await AddMapToNewLayout(newLayout); await addLegendToLayout(newLayout); await AddTtitleToNewLayout(newLayout); ILayoutPane iNewLayoutPane = await ProApp.Panes.CreateLayoutPaneAsync(newLayout); }
protected override void Drop(LayoutAnchorableFloatingWindow floatingWindow) { ILayoutPane model = this._targetPane.Model as ILayoutPane; if (base.Type == DropTargetType.DocumentPaneGroupDockInside) { LayoutDocumentPane item = (model as LayoutDocumentPaneGroup).Children[0] as LayoutDocumentPane; int num = 0; LayoutAnchorable[] array = floatingWindow.RootPanel.Descendents().OfType <LayoutAnchorable>().ToArray <LayoutAnchorable>(); for (int i = 0; i < (int)array.Length; i++) { LayoutAnchorable layoutAnchorable = array[i]; item.Children.Insert(num, layoutAnchorable); num++; } } base.Drop(floatingWindow); }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (this._isMouseDown) { Point position = e.GetPosition(this); if (Math.Abs(position.X - this._mouseDownPoint.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(position.Y - this._mouseDownPoint.Y) > SystemParameters.MinimumVerticalDragDistance) { this.UpdateDragDetails(); base.CaptureMouse(); this._isMouseDown = false; } } if (base.IsMouseCaptured) { Point screenDPI = this.PointToScreenDPI(e.GetPosition(this)); if (!this._parentDocumentTabPanelScreenArea.Contains(screenDPI)) { base.ReleaseMouseCapture(); this.Model.Root.Manager.StartDraggingFloatingWindowForContent(this.Model, true); return; } int num = this._otherTabsScreenArea.FindIndex((Rect r) => r.Contains(screenDPI)); if (num >= 0) { LayoutContent content = this._otherTabs[num].Content as LayoutContent; ILayoutContainer parent = this.Model.Parent; ILayoutPane layoutPane = this.Model.Parent as ILayoutPane; if (layoutPane is LayoutDocumentPane && !((LayoutDocumentPane)layoutPane).CanRepositionItems) { return; } if (layoutPane.Parent != null && layoutPane.Parent is LayoutDocumentPaneGroup && !((LayoutDocumentPaneGroup)layoutPane.Parent).CanRepositionItems) { return; } List <ILayoutElement> list = parent.Children.ToList <ILayoutElement>(); layoutPane.MoveChild(list.IndexOf(this.Model), list.IndexOf(content)); this.Model.IsActive = true; this._parentDocumentTabPanel.UpdateLayout(); this.UpdateDragDetails(); } } }
protected override void OnMouseEnter(MouseEventArgs e) { base.OnMouseEnter(e); if (LayoutAnchorableTabItem._draggingItem != null && LayoutAnchorableTabItem._draggingItem != this && e.LeftButton == MouseButtonState.Pressed) { LayoutContent model = this.Model; ILayoutContainer parent = model.Parent; ILayoutPane layoutPane = model.Parent as ILayoutPane; if (layoutPane is LayoutAnchorablePane && !((LayoutAnchorablePane)layoutPane).CanRepositionItems) { return; } if (layoutPane.Parent != null && layoutPane.Parent is LayoutAnchorablePaneGroup && !((LayoutAnchorablePaneGroup)layoutPane.Parent).CanRepositionItems) { return; } List <ILayoutElement> list = parent.Children.ToList <ILayoutElement>(); layoutPane.MoveChild(list.IndexOf(LayoutAnchorableTabItem._draggingItem.Model), list.IndexOf(model)); } }
protected override void Drop(LayoutDocumentFloatingWindow floatingWindow) { ILayoutPane targetModel = _targetPane.Model as ILayoutPane; switch (Type) { case DropTargetType.DocumentPaneGroupDockInside: #region DropTargetType.DocumentPaneGroupDockInside { var paneGroupModel = targetModel as LayoutDocumentPaneGroup; var paneModel = paneGroupModel.Children[0] as LayoutDocumentPane; var sourceModel = floatingWindow.RootDocument; paneModel.Children.Insert(0, sourceModel); } break; #endregion } base.Drop(floatingWindow); }
protected async override void OnClick() { ReportType rType = ReportType.Watershed; try { string outputDirectory = Module1.Current.Aoi.FilePath + "\\" + Constants.FOLDER_MAP_PACKAGE; if (!System.IO.Directory.Exists(outputDirectory)) { System.IO.Directory.CreateDirectory(outputDirectory); } // Delete any old PDF files //string[] arrFilesToDelete = Constants.FILES_EXPORT_WATERSHED_PDF.Concat(Constants.FILES_EXPORT_SITE_ANALYSIS_PDF).ToArray(); foreach (var item in Constants.FILES_EXPORT_WATERSHED_PDF) { string strPath = GeneralTools.GetFullPdfFileName(item); if (System.IO.File.Exists(strPath)) { try { System.IO.File.Delete(strPath); } catch (Exception) { System.Windows.MessageBoxResult res = MessageBox.Show("Unable to delete file before creating new pdf. Do you want to close the file and try again?", "BAGIS-PRO", System.Windows.MessageBoxButton.YesNo); if (res == System.Windows.MessageBoxResult.Yes) { return; } } } } Layout oLayout = await MapTools.GetDefaultLayoutAsync(Constants.MAPS_DEFAULT_LAYOUT_NAME); // Load the maps if they aren't in the viewer already BA_ReturnCode success = BA_ReturnCode.Success; string strTestState = Constants.STATES_WATERSHED_MAP_BUTTONS[0]; //if (rType.Equals(ReportType.SiteAnalysis)) //{ // strTestState = Constants.STATES_SITE_ANALYSIS_MAP_BUTTONS[0]; //} if (!FrameworkApplication.State.Contains(strTestState)) { success = await MapTools.DisplayMaps(Module1.Current.Aoi.FilePath, oLayout, true); success = await MapTools.DisplayLegendAsync(Constants.MAPS_DEFAULT_MAP_FRAME_NAME, oLayout, "ArcGIS Colors", "1.5 Point", true); } if (success != BA_ReturnCode.Success) { MessageBox.Show("Unable to load maps. The map package cannot be exported!!", "BAGIS-PRO"); return; } if (oLayout != null) { bool bFoundIt = false; //A layout view may exist but it may not be active //Iterate through each pane in the application and check to see if the layout is already open and if so, activate it foreach (var pane in FrameworkApplication.Panes) { if (!(pane is ILayoutPane layoutPane)) //if not a layout view, continue to the next pane { continue; } if (layoutPane.LayoutView != null && layoutPane.LayoutView.Layout == oLayout) //if there is a match, activate the view { (layoutPane as Pane).Activate(); bFoundIt = true; } } if (!bFoundIt) { ILayoutPane iNewLayoutPane = await FrameworkApplication.Panes.CreateLayoutPaneAsync(oLayout); //GUI thread (iNewLayoutPane as Pane).Activate(); } } success = await MapTools.PublishMapsAsync(rType); // export the maps to pdf if (success != BA_ReturnCode.Success) { MessageBox.Show("An error occurred while generating the maps!!", "BAGIS-PRO"); } // Only run critical precip for watershed report if (rType.Equals(ReportType.Watershed)) { success = await GeneralTools.GenerateTablesAsync(false); // export the tables to pdf if (success != BA_ReturnCode.Success) { MessageBox.Show("An error occurred while generating the Excel tables!!", "BAGIS-PRO"); } else { // Generate the crtical precip map; It has to follow the tables Uri uriAnalysis = new Uri(GeodatabaseTools.GetGeodatabasePath(Module1.Current.Aoi.FilePath, GeodatabaseNames.Analysis)); if (await GeodatabaseTools.FeatureClassExistsAsync(uriAnalysis, Constants.FILE_CRITICAL_PRECIP_ZONE)) { success = await MapTools.DisplayCriticalPrecipitationZonesMap(uriAnalysis); string strButtonState = "MapButtonPalette_BtnCriticalPrecipZone_State"; if (success.Equals(BA_ReturnCode.Success)) { Module1.ActivateState(strButtonState); } int foundS1 = strButtonState.IndexOf("_State"); string strMapButton = strButtonState.Remove(foundS1); ICommand cmd = FrameworkApplication.GetPlugInWrapper(strMapButton) as ICommand; Module1.Current.ModuleLogManager.LogDebug(nameof(OnClick), "About to toggle map button " + strMapButton); if ((cmd != null)) { do { await Task.Delay(TimeSpan.FromSeconds(0.4)); // build in delay until the command can execute }while (!cmd.CanExecute(null)); cmd.Execute(null); } do { await Task.Delay(TimeSpan.FromSeconds(0.4)); // build in delay so maps can load }while (Module1.Current.MapFinishedLoading == false); success = await GeneralTools.ExportMapToPdfAsync(150); // export map to pdf if (success == BA_ReturnCode.Success) { // append the map and chart together for posting IList <string> lstToConcat = new List <string>(); lstToConcat.Add(GeneralTools.GetFullPdfFileName(Constants.FILE_EXPORT_MAP_CRITICAL_PRECIPITATION_ZONES_PDF)); lstToConcat.Add(GeneralTools.GetFullPdfFileName(Constants.FILE_EXPORT_TABLE_PRECIP_REPRESENT_PDF)); success = GeneralTools.ConcatenatePagesInPdf(GeneralTools.GetFullPdfFileName(Constants.FILE_EXPORT_CRITICAL_PRECIPITATION_ZONES_PDF), lstToConcat); } else { MessageBox.Show("Unable to generate critical precipitation zones map!!", "BAGIS-PRO"); } } } } success = await GeneralTools.GenerateSitesTableAsync(Module1.Current.Aoi); string strPublisher = (string)Module1.Current.BatchToolSettings.Publisher; success = await GeneralTools.GenerateMapsTitlePageAsync(rType, strPublisher, ""); string outputPath = GeneralTools.GetFullPdfFileName(Constants.FILE_EXPORT_WATERSHED_REPORT_PDF); //if (rType.Equals(ReportType.SiteAnalysis)) //{ // outputPath = GeneralTools.GetFullPdfFileName(Constants.FILE_EXPORT_SITE_ANALYSIS_REPORT_PDF); //} GeneralTools.PublishFullPdfDocument(outputPath, rType); // Put it all together into a single pdf document MessageBox.Show("Map package exported to " + outputPath + "!!", "BAGIS-PRO"); } catch (Exception e) { MessageBox.Show("An error occurred while trying to export the maps!! " + e.Message, "BAGIS PRO"); } }
public static async Task DisplayMaps(string strAoiPath) { BA_Objects.Aoi oAoi = Module1.Current.Aoi; if (String.IsNullOrEmpty(oAoi.Name)) { if (System.IO.Directory.Exists(strAoiPath)) { // Initialize AOI object oAoi = new BA_Objects.Aoi("animas_AOI_prms", strAoiPath); // Store current AOI in Module1 Module1.Current.Aoi = oAoi; } else { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("!!Please set an AOI before testing the maps", "BAGIS Pro"); } } Map oMap = await MapTools.SetDefaultMapNameAsync(Constants.MAPS_DEFAULT_MAP_NAME); if (oMap != null) { if (oMap.Layers.Count() > 0) { string strMessage = "Adding the maps to the display will overwrite the current arrangement of data layers. " + "This action cannot be undone." + System.Environment.NewLine + "Do you wish to continue ?"; MessageBoxResult oRes = ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(strMessage, "BAGIS", MessageBoxButton.YesNo); if (oRes != MessageBoxResult.Yes) { return; } } Layout layout = await MapTools.GetDefaultLayoutAsync(Constants.MAPS_DEFAULT_LAYOUT_NAME); if (layout != null) { bool bFoundIt = false; //A layout view may exist but it may not be active //Iterate through each pane in the application and check to see if the layout is already open and if so, activate it foreach (var pane in ProApp.Panes) { if (!(pane is ILayoutPane layoutPane)) //if not a layout view, continue to the next pane { continue; } if (layoutPane.LayoutView.Layout == layout) //if there is a match, activate the view { (layoutPane as Pane).Activate(); bFoundIt = true; } } if (!bFoundIt) { ILayoutPane iNewLayoutPane = await ProApp.Panes.CreateLayoutPaneAsync(layout); //GUI thread } await MapTools.SetDefaultMapFrameDimensionAsync(Constants.MAPS_DEFAULT_MAP_FRAME_NAME, layout, oMap, 1.0, 2.0, 7.5, 9.0); //remove existing layers from map frame await MapTools.RemoveLayersfromMapFrame(); //add aoi boundary to map and zoom to layer string strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Aoi, true) + Constants.FILE_AOI_VECTOR; Uri aoiUri = new Uri(strPath); await MapTools.AddAoiBoundaryToMapAsync(aoiUri, Constants.MAPS_AOI_BOUNDARY); //add Snotel Represented Area Layer strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Analysis, true) + Constants.FILE_SNOTEL_REPRESENTED; Uri uri = new Uri(strPath); CIMColor fillColor = CIMColor.CreateRGBColor(255, 0, 0, 50); //Red with 30% transparency BA_ReturnCode success = await MapTools.AddPolygonLayerAsync(uri, fillColor, false, Constants.MAPS_SNOTEL_REPRESENTED); if (success.Equals(BA_ReturnCode.Success)) { Module1.ToggleState("MapButtonPalette_BtnSnotel_State"); } // add aoi streams layer strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Layers, true) + Constants.FILE_STREAMS; uri = new Uri(strPath); await MapTools.AddLineLayerAsync(uri, Constants.MAPS_STREAMS, ColorFactory.Instance.BlueRGB); // add Snotel Layer strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Layers, true) + Constants.FILE_SNOTEL; uri = new Uri(strPath); success = await MapTools.AddPointMarkersAsync(uri, Constants.MAPS_SNOTEL, ColorFactory.Instance.BlueRGB, SimpleMarkerStyle.X, 16); if (success == BA_ReturnCode.Success) { Module1.Current.AoiHasSnotel = true; } // add Snow Course Layer strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Layers, true) + Constants.FILE_SNOW_COURSE; uri = new Uri(strPath); success = await MapTools.AddPointMarkersAsync(uri, Constants.MAPS_SNOW_COURSE, CIMColor.CreateRGBColor(0, 255, 255), SimpleMarkerStyle.Star, 16); if (success == BA_ReturnCode.Success) { Module1.Current.AoiHasSnowCourse = true; } // add hillshade layer strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Surfaces, true) + Constants.FILE_HILLSHADE; uri = new Uri(strPath); await MapTools.DisplayRasterAsync(uri, Constants.MAPS_HILLSHADE, 0); // add elev zones layer strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Analysis, true) + Constants.FILE_ELEV_ZONE; uri = new Uri(strPath); await MapTools.DisplayRasterWithSymbolAsync(uri, Constants.MAPS_ELEV_ZONE, "ArcGIS Colors", "Elevation #2", "NAME", 30, true); Module1.ToggleState("MapButtonPalette_BtnElevation_State"); // add slope zones layer strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Analysis, true) + Constants.FILE_SLOPE_ZONE; uri = new Uri(strPath); await MapTools.DisplayRasterWithSymbolAsync(uri, Constants.MAPS_SLOPE_ZONE, "ArcGIS Colors", "Slope", "NAME", 30, false); Module1.ToggleState("MapButtonPalette_BtnSlope_State"); // add aspect zones layer strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Analysis, true) + Constants.FILE_ASPECT_ZONE; uri = new Uri(strPath); await MapTools.DisplayRasterWithSymbolAsync(uri, Constants.MAPS_ASPECT_ZONE, "ArcGIS Colors", "Aspect", "NAME", 30, false); Module1.ToggleState("MapButtonPalette_BtnAspect_State"); // create map elements await MapTools.AddMapElements(Constants.MAPS_DEFAULT_LAYOUT_NAME, "ArcGIS Colors", "1.5 Point"); await MapTools.DisplayNorthArrowAsync(layout, Constants.MAPS_DEFAULT_MAP_FRAME_NAME); await MapTools.DisplayScaleBarAsync(layout, Constants.MAPS_DEFAULT_MAP_FRAME_NAME); // update map elements for default map (elevation) BA_Objects.MapDefinition defaultMap = MapTools.LoadMapDefinition(BagisMapType.ELEVATION); await MapTools.UpdateMapElementsAsync(layout, Module1.Current.Aoi.Name.ToUpper(), defaultMap); await MapTools.UpdateLegendAsync(layout, defaultMap); //zoom to aoi boundary layer double bufferFactor = 1.1; bool bZoomed = await MapTools.ZoomToExtentAsync(aoiUri, bufferFactor); } } }
async public static void MethodSnippets() { LayoutView layoutView = LayoutView.Active; #region LayoutView_ZoomTo_Extent //Set the page extent for a layout view. //Process on worker thread await QueuedTask.Run(() => { var lytExt = layoutView.Extent; layoutView.ZoomTo(lytExt); }); #endregion LayoutView_ZoomTo_Extent #region LayoutView_ZoomTo_Percent //Set the layout view to 100 percent. //Process on worker thread await QueuedTask.Run(() => { layoutView.ZoomTo100Percent(); }); #endregion LayoutView_ZoomTo_Percent #region LayoutView_ZoomTo_Next //Advance the layout view extent to the previous forward extent //Process on worker thread await QueuedTask.Run(() => { layoutView.ZoomToNext(); }); #endregion LayoutView_ZoomTo_Next #region LayoutView_ZoomTo_PageWidth //Set the layout view extent to accomodate the width of the page. //Process on worker thread await QueuedTask.Run(() => { layoutView.ZoomToPageWidth(); }); #endregion LayoutView_ZoomTo_PageWidth #region LayoutView_ZoomTo_Previous //Set the layout view extent to the previous extent. //Process on worker thread await QueuedTask.Run(() => { layoutView.ZoomToPrevious(); }); #endregion LayoutView_ZoomTo_Previous #region LayoutView_ZoomTo_SelectedElements //Set the layout view extent to the selected elements. //Process on worker thread await QueuedTask.Run(() => { layoutView.ZoomToSelectedElements(); }); #endregion LayoutView_ZoomTo_SelectedElements #region LayoutView_ZoomTo_WholePage //Set the layout view extent to fit the entire page. //Process on worker thread await QueuedTask.Run(() => { layoutView.ZoomToWholePage(); }); #endregion LayoutView_ZoomTo_WholePage #region LayoutView_Refresh //Refresh the layout view. //Process on worker thread await QueuedTask.Run(() => layoutView.Refresh()); #endregion #region LayoutView_GetSelection //Get the selected layout elements. var selectedElements = layoutView.GetSelectedElements(); #endregion #region LayoutView_SetSelection //Set the layout's element selection. Element rec = layoutView.Layout.FindElement("Rectangle"); Element rec2 = layoutView.Layout.FindElement("Rectangle 2"); List <Element> elmList = new List <Element>(); elmList.Add(rec); elmList.Add(rec2); layoutView.SelectElements(elmList); #endregion LayoutView_SetSelection #region LayoutView_SelectAll //Select all element on a layout. layoutView.SelectAllElements(); #endregion LayoutView_SelectAll #region LayoutView_ClearSelection //Clear the layout's element selection. layoutView.ClearElementSelection(); #endregion LayoutView_ClearSelection Layout layout = LayoutFactory.Instance.CreateLayout(5, 5, LinearUnit.Inches); #region LayoutView_FindAndCloseLayoutPanes //Find and close all layout panes associated with a specific layout. LayoutProjectItem findLytItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout")); Layout findLyt = await QueuedTask.Run(() => findLytItem.GetLayout()); //Perform on the worker thread var panes = ProApp.Panes.FindLayoutPanes(findLyt); foreach (Pane pane in panes) { ProApp.Panes.CloseLayoutPanes(findLyt.URI); //Close the pane } #endregion LayoutView_FindandCloseLayoutPanes #region LayoutView_LayoutFrameWorkExtender //This sample checks to see if a layout project item already has an open application pane. //If it does, it checks if it is the active layout view, if not, it creates, activates and opens a new pane. //Reference a layoutitem in a project by name LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout View")); //Get the layout associated with the layoutitem Layout lyt = await QueuedTask.Run(() => layoutItem.GetLayout()); //Iterate through each pane in the application and check to see if the layout is already open and if so, activate it foreach (var pane in ProApp.Panes) { var layoutPane = pane as ILayoutPane; if (layoutPane == null) //if not a layout pane, continue to the next pane { continue; } if (layoutPane.LayoutView.Layout == lyt) //if the layout pane does match the layout, activate it. { (layoutPane as Pane).Activate(); layoutPane.Caption = "This is a test"; System.Windows.MessageBox.Show(layoutPane.Caption); return; } } //Otherwise, create, open, and activate the layout if not already open ILayoutPane newPane = await ProApp.Panes.CreateLayoutPaneAsync(lyt); //Zoom to the full extent of the layout await QueuedTask.Run(() => newPane.LayoutView.ZoomTo100Percent()); #endregion LayoutView_LayoutFrameWorkExtender }
protected async override void OnClick() { string tempAoiPath = "C:\\Docs\\animas_AOI_prms"; try { Layout layout = await MapTools.GetDefaultLayoutAsync(Constants.MAPS_DEFAULT_LAYOUT_NAME); BA_ReturnCode success = await MapTools.DisplayMaps(tempAoiPath, layout, true); if (success == BA_ReturnCode.Success && layout != null) { bool bFoundIt = false; //A layout view may exist but it may not be active //Iterate through each pane in the application and check to see if the layout is already open and if so, activate it foreach (var pane in FrameworkApplication.Panes) { if (!(pane is ILayoutPane layoutPane)) //if not a layout view, continue to the next pane { continue; } if (layoutPane.LayoutView != null && layoutPane.LayoutView.Layout == layout) //if there is a match, activate the view { (layoutPane as Pane).Activate(); bFoundIt = true; } else { continue; } } if (!bFoundIt) { ILayoutPane iNewLayoutPane = await FrameworkApplication.Panes.CreateLayoutPaneAsync(layout); //GUI thread } } // Legend success = await MapTools.DisplayLegendAsync(Constants.MAPS_DEFAULT_MAP_FRAME_NAME, layout, "ArcGIS Colors", "1.5 Point", true); // update map elements for default map (elevation) if (FrameworkApplication.State.Contains("MapButtonPalette_BtnElevation_State")) { BA_Objects.MapDefinition defaultMap = MapTools.LoadMapDefinition(BagisMapType.ELEVATION); await MapTools.UpdateMapElementsAsync(Module1.Current.Aoi.NwccName.ToUpper(), defaultMap); success = await MapTools.UpdateLegendAsync(layout, defaultMap.LegendLayerList); } else { MessageBox.Show("The default Elevation Zones map could not be loaded. Use " + "the Display Maps buttons to display other maps!!", "BAGIS-PRO"); } Module1.Current.DisplayedMap = Constants.FILE_EXPORT_MAP_ELEV_PDF; Module1.ActivateState("BtnMapLoad_State"); MessageBox.Show("The maps are loaded. Use the Toggle Maps buttons to view the maps.", "BAGIS-PRO"); } catch (Exception e) { MessageBox.Show("An error occurred while trying to load the maps!! " + e.Message, "BAGIS PRO"); } }
private async void RunImplAsync(object param) { // Create initial log entry string strLogEntry = DateTime.Now.ToString("MM/dd/yy H:mm:ss ") + "Starting batch tool to publish in " + Path.GetDirectoryName(_strLogFile) + "\r\n"; File.WriteAllText(_strLogFile, strLogEntry); // overwrite file if it exists // Check for existing map package files and warn user if (ArchiveChecked) { string[] filePaths = Directory.GetFiles(AoiFolder + "\\" + Constants.FOLDER_MAP_PACKAGE, "*.pdf", SearchOption.TopDirectoryOnly); if (filePaths.Length > 0) { System.Windows.MessageBoxResult res = ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("BAGIS-PRO found at least one .pdf document in the " + "maps\\publish folder. These document(s) may be overwritten during the batch process. Uncheck " + "the 'Copy Reports' checkbox to stop copying documents to the maps\\publish folder. " + "The map packages will still be created in each AOI. Do you wish to continue and overwrite " + "the documents ?", "BAGIS-PRO", System.Windows.MessageBoxButton.YesNo); if (res != System.Windows.MessageBoxResult.Yes) { return; } } } // Save off the publisher name if it is different than previous string strPublisher = (string)Module1.Current.BatchToolSettings.Publisher; if (!Publisher.Trim().Equals(strPublisher)) { Module1.Current.BatchToolSettings.Publisher = Publisher; String json = JsonConvert.SerializeObject(Module1.Current.BatchToolSettings, Formatting.Indented); File.WriteAllText(SettingsFile, json); } // Make directory for required folders if they don't exist // Make sure that maps and maps_publish folders exist for (int idxRow = 0; idxRow < Names.Count; idxRow++) { if (Names[idxRow].AoiBatchIsSelected) { int errorCount = 0; // keep track of any non-fatal errors AoiFolder = Names[idxRow].FilePath; Names[idxRow].AoiBatchStateText = AoiBatchState.Started.ToString(); // update gui string[] arrFolders = { AoiFolder + "\\" + Constants.FOLDER_MAPS, AoiFolder + "\\" + Constants.FOLDER_MAP_PACKAGE, AoiFolder + "\\" + Constants.FOLDER_LOGS }; foreach (var directory in arrFolders) { if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } } // Set logger to AOI directory string logFolderName = AoiFolder + "\\" + Constants.FOLDER_LOGS; Module1.Current.ModuleLogManager.UpdateLogFileLocation(logFolderName); // Set current AOI BA_Objects.Aoi oAoi = await GeneralTools.SetAoiAsync(AoiFolder); if (Module1.Current.CboCurrentAoi != null) { FrameworkApplication.Current.Dispatcher.Invoke(() => { // Do something on the GUI thread Module1.Current.CboCurrentAoi.SetAoiName(oAoi.Name); }); } // Create opening log entry for AOI strLogEntry = DateTime.Now.ToString("MM/dd/yy H:mm:ss ") + "Starting batch PDF export for " + oAoi.Name + "\r\n"; File.AppendAllText(_strLogFile, strLogEntry); // append // Bring GP History tool forward var cmdShowHistory = FrameworkApplication.GetPlugInWrapper("esri_geoprocessing_showToolHistory") as ICommand; if (cmdShowHistory != null) { if (cmdShowHistory.CanExecute(null)) { cmdShowHistory.Execute(null); } } oAoi = Module1.Current.Aoi; // Elevation zones BA_ReturnCode success = await AnalysisTools.CalculateElevationZonesAsync(Module1.Current.Aoi.FilePath); if (success != BA_ReturnCode.Success) { errorCount++; } // Slope zones string strLayer = GeodatabaseTools.GetGeodatabasePath(AoiFolder, GeodatabaseNames.Surfaces, true) + Constants.FILE_SLOPE; string strZonesRaster = GeodatabaseTools.GetGeodatabasePath(AoiFolder, GeodatabaseNames.Analysis, true) + Constants.FILE_SLOPE_ZONE; string strMaskPath = GeodatabaseTools.GetGeodatabasePath(AoiFolder, GeodatabaseNames.Aoi, true) + Constants.FILE_AOI_BUFFERED_VECTOR; IList <BA_Objects.Interval> lstInterval = AnalysisTools.GetSlopeClasses(); success = await AnalysisTools.CalculateZonesAsync(AoiFolder, strLayer, lstInterval, strZonesRaster, strMaskPath, "SLOPE"); if (success != BA_ReturnCode.Success) { errorCount++; } // Check for PRISM buffer units string[] arrPrismBufferInfo = await GeneralTools.QueryBufferDistanceAsync(AoiFolder, GeodatabaseTools.GetGeodatabasePath(AoiFolder, GeodatabaseNames.Aoi), Constants.FILE_AOI_PRISM_VECTOR, false); string pBufferDistance = arrPrismBufferInfo[0]; string pBufferUnits = arrPrismBufferInfo[1]; // Clip PRISM string strDefaultBufferDistance = (string)Module1.Current.BatchToolSettings.PrecipBufferDistance; string strDefaultBufferUnits = (string)Module1.Current.BatchToolSettings.PrecipBufferUnits; success = await AnalysisTools.ClipLayersAsync(AoiFolder, Constants.DATA_TYPE_PRECIPITATION, pBufferDistance, pBufferUnits, strDefaultBufferDistance, strDefaultBufferUnits); if (success == BA_ReturnCode.Success) { success = await AnalysisTools.UpdateSitesPropertiesAsync(Module1.Current.Aoi.FilePath, SiteProperties.Precipitation); } if (success != BA_ReturnCode.Success) { errorCount++; } // PRISM Zones strLayer = GeodatabaseTools.GetGeodatabasePath(Module1.Current.Aoi.FilePath, GeodatabaseNames.Prism, true) + Path.GetFileName((string)Module1.Current.BatchToolSettings.AoiPrecipFile); strZonesRaster = GeodatabaseTools.GetGeodatabasePath(Module1.Current.Aoi.FilePath, GeodatabaseNames.Analysis, true) + Constants.FILE_PRECIP_ZONE; success = await AnalysisTools.CalculatePrecipitationZonesAsync(strLayer, strZonesRaster); if (success != BA_ReturnCode.Success) { errorCount++; } // Winter Precipitation success = await AnalysisTools.GenerateWinterPrecipitationLayerAsync(oAoi); if (success != BA_ReturnCode.Success) { errorCount++; } // Clip SWE success = await AnalysisTools.ClipSweLayersAsync(pBufferDistance, pBufferUnits, strDefaultBufferDistance, strDefaultBufferUnits); if (success != BA_ReturnCode.Success) { errorCount++; } // Generate SWE Delta Layers success = await AnalysisTools.CalculateSWEDeltaAsync(AoiFolder); // Clip Snotel and Snow Course double dblDistance = -1; bool isDouble = Double.TryParse((string)Module1.Current.BatchToolSettings.SnotelBufferDistance, out dblDistance); if (!isDouble) { dblDistance = 0; } Module1.Current.ModuleLogManager.LogDebug(nameof(RunImplAsync), "Buffer distance from settings: " + dblDistance); string snoBufferDistance = dblDistance + " " + (string)Module1.Current.BatchToolSettings.SnotelBufferUnits; Module1.Current.ModuleLogManager.LogDebug(nameof(RunImplAsync), "Sites buffer distance string: " + snoBufferDistance); success = await AnalysisTools.ClipSnoLayersAsync(Module1.Current.Aoi.FilePath, true, snoBufferDistance, true, snoBufferDistance); if (success != BA_ReturnCode.Success) { errorCount++; } // Represented Area if (success == BA_ReturnCode.Success) { double siteBufferDistanceMiles = (double)Module1.Current.BatchToolSettings.SiteBufferDistMiles; double siteElevRangeFeet = (double)Module1.Current.BatchToolSettings.SiteElevRangeFeet; success = await AnalysisTools.GenerateSiteLayersAsync(siteBufferDistanceMiles, siteElevRangeFeet); if (success != BA_ReturnCode.Success) { errorCount++; } // Sites Zones Uri uri = new Uri(GeodatabaseTools.GetGeodatabasePath(Module1.Current.Aoi.FilePath, GeodatabaseNames.Layers)); bool hasSnotel = await GeodatabaseTools.FeatureClassExistsAsync(uri, Constants.FILE_SNOTEL); bool hasSnowCourse = await GeodatabaseTools.FeatureClassExistsAsync(uri, Constants.FILE_SNOW_COURSE); if (hasSnotel || hasSnowCourse) { success = await AnalysisTools.CalculateSitesZonesAsync(Module1.Current.Aoi.FilePath, hasSnotel, hasSnowCourse); if (success != BA_ReturnCode.Success) { errorCount++; } } else { Module1.Current.ModuleLogManager.LogError(nameof(CmdRun), "No sites found to create sites zone layers!!"); } } // Precipitation Contribution; Passing in -1 for threshold so we use STDEV success = await AnalysisTools.CalculatePrecipitationContributionAsync(Module1.Current.Aoi.FilePath, -1); if (success != BA_ReturnCode.Success) { errorCount++; } // Quarterly Precipitation Contribution success = await AnalysisTools.CalculateQuarterlyPrecipitationAsync(Module1.Current.Aoi); if (success != BA_ReturnCode.Success) { errorCount++; } // Aspect zones success = await AnalysisTools.CalculateAspectZonesAsync(); if (success != BA_ReturnCode.Success) { errorCount++; } string[] arrUnmanagedBufferInfo = await GeneralTools.QueryBufferDistanceAsync(AoiFolder, GeodatabaseTools.GetGeodatabasePath(AoiFolder, GeodatabaseNames.Aoi), Constants.FILE_AOI_BUFFERED_VECTOR, false); string unmanagedBufferDistance = arrPrismBufferInfo[0]; string unmanagedBufferUnits = arrPrismBufferInfo[1]; if (SiteAnalysisChecked) { // Clip Roads string strOutputFc = GeodatabaseTools.GetGeodatabasePath(AoiFolder, GeodatabaseNames.Layers, true) + Constants.FILE_ROADS; success = await AnalysisTools.ClipFeatureLayerAsync(AoiFolder, strOutputFc, Constants.DATA_TYPE_ROADS, unmanagedBufferDistance, unmanagedBufferUnits); if (success != BA_ReturnCode.Success) { errorCount++; } if (success == BA_ReturnCode.Success) { // Buffer clipped roads for analysis Uri uri = new Uri(GeodatabaseTools.GetGeodatabasePath(AoiFolder, GeodatabaseNames.Layers)); bool bExists = await GeodatabaseTools.FeatureClassExistsAsync(uri, Constants.FILE_ROADS); if (!bExists) { Module1.Current.ModuleLogManager.LogDebug(nameof(CmdRun), "Unable to buffer roads because fs_roads layer does not exist. Process stopped!!"); } else { string strDistance = Module1.Current.BatchToolSettings.RoadsAnalysisBufferDistance + " " + Module1.Current.BatchToolSettings.RoadsAnalysisBufferUnits; success = await AnalysisTools.GenerateProximityRoadsLayerAsync(uri, strDistance); if (success != BA_ReturnCode.Success) { errorCount++; } } } // Clip public lands strOutputFc = GeodatabaseTools.GetGeodatabasePath(AoiFolder, GeodatabaseNames.Layers, true) + Constants.FILE_PUBLIC_LAND; success = await AnalysisTools.ClipFeatureLayerAsync(AoiFolder, strOutputFc, Constants.DATA_TYPE_PUBLIC_LAND, unmanagedBufferDistance, unmanagedBufferUnits); if (success != BA_ReturnCode.Success) { errorCount++; } if (success == BA_ReturnCode.Success) { // Create public lands layer for potential site analysis success = await AnalysisTools.GetFederalNonWildernessLandsAsync(AoiFolder); if (success != BA_ReturnCode.Success) { errorCount++; } } // Clip Vegetation layer string strOutputRaster = GeodatabaseTools.GetGeodatabasePath(AoiFolder, GeodatabaseNames.Layers, true) + Constants.FILE_VEGETATION_EVT; success = await AnalysisTools.ClipRasterLayerAsync(AoiFolder, strOutputRaster, Constants.DATA_TYPE_VEGETATION, unmanagedBufferDistance, unmanagedBufferUnits); if (success != BA_ReturnCode.Success) { errorCount++; } if (success == BA_ReturnCode.Success) { // Create area below treeline layer for potential site analysis success = await AnalysisTools.ExtractBelowTreelineAsync(AoiFolder); if (success != BA_ReturnCode.Success) { errorCount++; } } // Generate Potential Sites layer success = await AnalysisTools.CalculatePotentialSitesAreaAsync(AoiFolder); if (success != BA_ReturnCode.Success) { errorCount++; } } // Clip Land cover success = await AnalysisTools.ClipLandCoverAsync(AoiFolder, unmanagedBufferDistance, unmanagedBufferUnits); // Generate Elevation Precipitation Correlation layer strLayer = GeodatabaseTools.GetGeodatabasePath(AoiFolder, GeodatabaseNames.Prism, true) + Path.GetFileName((string)Module1.Current.BatchToolSettings.AoiPrecipFile); Uri uriPrism = new Uri(GeodatabaseTools.GetGeodatabasePath(AoiFolder, GeodatabaseNames.Prism)); success = await AnalysisTools.CalculateElevPrecipCorrAsync(AoiFolder, uriPrism, Path.GetFileName((string)Module1.Current.BatchToolSettings.AoiPrecipFile)); if (success != BA_ReturnCode.Success) { errorCount++; } if (success == BA_ReturnCode.Success) { Module1.Current.ModuleLogManager.LogDebug(nameof(CmdRun), "Generated Elevation Precipitation Correlation layer"); } // Generate complete PDF document try { // Delete any old PDF files //string[] arrAllPdfFiles = new string[Constants.FILES_EXPORT_WATERSHED_PDF.Length + FILES_EXPORT_SITE_ANALYSIS_PDF.Length]; //Array.Copy(Constants.FILES_EXPORT_WATERSHED_PDF, arrAllPdfFiles, Constants.FILES_EXPORT_WATERSHED_PDF.Length); //Array.Copy(Constants.FILES_EXPORT_SITE_ANALYSIS_PDF, 0, arrAllPdfFiles, // Constants.FILES_EXPORT_WATERSHED_PDF.Length, Constants.FILES_EXPORT_SITE_ANALYSIS_PDF.Length); foreach (var item in Constants.FILES_EXPORT_WATERSHED_PDF) { string strPath = Module1.Current.Aoi.FilePath + "\\" + Constants.FOLDER_MAP_PACKAGE + "\\" + item; if (System.IO.File.Exists(strPath)) { try { System.IO.File.Delete(strPath); } catch (Exception) { System.Windows.MessageBoxResult res = MessageBox.Show("Unable to delete file before creating new pdf. Do you want to close the file and try again?", "BAGIS-PRO", System.Windows.MessageBoxButton.YesNo); if (res == System.Windows.MessageBoxResult.Yes) { return; } } } } Layout oLayout = await MapTools.GetDefaultLayoutAsync(Constants.MAPS_DEFAULT_LAYOUT_NAME); // Always load the maps in case we are running through multiple Aois success = await MapTools.DisplayMaps(Module1.Current.Aoi.FilePath, oLayout, false); if (success != BA_ReturnCode.Success) { MessageBox.Show("Unable to load maps. The map package cannot be exported!!", "BAGIS-PRO"); Names[idxRow].AoiBatchStateText = AoiBatchState.Failed.ToString(); return; } // Legend success = await MapTools.DisplayLegendAsync(Constants.MAPS_DEFAULT_MAP_FRAME_NAME, oLayout, "ArcGIS Colors", "1.5 Point", true); if (success != BA_ReturnCode.Success) { errorCount++; } if (oLayout != null) { bool bFoundIt = false; //A layout view may exist but it may not be active //Iterate through each pane in the application and check to see if the layout is already open and if so, activate it foreach (var pane in FrameworkApplication.Panes) { if (!(pane is ILayoutPane layoutPane)) //if not a layout view, continue to the next pane { continue; } if (layoutPane.LayoutView != null && layoutPane.LayoutView.Layout == oLayout) //if there is a match, activate the view { (layoutPane as Pane).Activate(); bFoundIt = true; } } if (!bFoundIt) { await FrameworkApplication.Current.Dispatcher.Invoke(async() => { // Do something on the GUI thread ILayoutPane iNewLayoutPane = await FrameworkApplication.Panes.CreateLayoutPaneAsync(oLayout); //GUI thread (iNewLayoutPane as Pane).Activate(); }); } } success = await MapTools.PublishMapsAsync(ReportType.Watershed); // export the watershed maps to pdf if (success != BA_ReturnCode.Success) { MessageBox.Show("An error occurred while generating the watershed characteristics maps!!", "BAGIS-PRO"); errorCount++; } //if (SiteAnalysisChecked) //{ // success = await MapTools.PublishMapsAsync(ReportType.SiteAnalysis); // export the site analysis maps to pdf // if (success != BA_ReturnCode.Success) // { // MessageBox.Show("An error occurred while generating the site analysis maps!!", "BAGIS-PRO"); // errorCount++; // } //} success = await GeneralTools.GenerateTablesAsync(false); // export the tables to pdf if (success != BA_ReturnCode.Success) { MessageBox.Show("An error occurred while generating the Excel tables!!", "BAGIS-PRO"); errorCount++; } else { // Generate the crtical precip map; It has to follow the tables Uri uriAnalysis = new Uri(GeodatabaseTools.GetGeodatabasePath(Module1.Current.Aoi.FilePath, GeodatabaseNames.Analysis)); if (await GeodatabaseTools.FeatureClassExistsAsync(uriAnalysis, Constants.FILE_CRITICAL_PRECIP_ZONE)) { success = await MapTools.DisplayCriticalPrecipitationZonesMap(uriAnalysis); string strButtonState = "MapButtonPalette_BtnCriticalPrecipZone_State"; if (success.Equals(BA_ReturnCode.Success)) { Module1.ActivateState(strButtonState); } int foundS1 = strButtonState.IndexOf("_State"); string strMapButton = strButtonState.Remove(foundS1); ICommand cmd = FrameworkApplication.GetPlugInWrapper(strMapButton) as ICommand; Module1.Current.ModuleLogManager.LogDebug(nameof(RunImplAsync), "About to toggle map button " + strMapButton); if ((cmd != null)) { do { await Task.Delay(TimeSpan.FromSeconds(0.4)); // build in delay until the command can execute }while (!cmd.CanExecute(null)); cmd.Execute(null); } do { await Task.Delay(TimeSpan.FromSeconds(0.4)); // build in delay so maps can load }while (Module1.Current.MapFinishedLoading == false); success = await GeneralTools.ExportMapToPdfAsync(150); // export map to pdf if (success == BA_ReturnCode.Success) { // append the map and chart together for posting IList <string> lstToConcat = new List <string>(); lstToConcat.Add(GeneralTools.GetFullPdfFileName(Constants.FILE_EXPORT_MAP_CRITICAL_PRECIPITATION_ZONES_PDF)); lstToConcat.Add(GeneralTools.GetFullPdfFileName(Constants.FILE_EXPORT_TABLE_PRECIP_REPRESENT_PDF)); success = GeneralTools.ConcatenatePagesInPdf(GeneralTools.GetFullPdfFileName(Constants.FILE_EXPORT_CRITICAL_PRECIPITATION_ZONES_PDF), lstToConcat); } else { Module1.Current.ModuleLogManager.LogError(nameof(RunImplAsync), "Unable to generate critical precipitation zones map!!"); } } } success = await GeneralTools.GenerateSitesTableAsync(Module1.Current.Aoi); success = await GeneralTools.GenerateMapsTitlePageAsync(ReportType.Watershed, strPublisher, Comments); if (success != BA_ReturnCode.Success) { MessageBox.Show("An error occurred while generating the Title page!!", "BAGIS-PRO"); errorCount++; } string outputPath = GeneralTools.GetFullPdfFileName(Constants.FILE_EXPORT_WATERSHED_REPORT_PDF); success = GeneralTools.PublishFullPdfDocument(outputPath, ReportType.Watershed); // Put it all together into a single pdf document if (success != BA_ReturnCode.Success) { errorCount++; } //if (SiteAnalysisChecked) //{ // success = await GeneralTools.GenerateMapsTitlePageAsync(ReportType.SiteAnalysis, strPublisher, Comments); // outputPath = GeneralTools.GetFullPdfFileName(Constants.FILE_EXPORT_SITE_ANALYSIS_REPORT_PDF); // success = GeneralTools.PublishFullPdfDocument(outputPath, ReportType.SiteAnalysis); // Put it all together into a single pdf document //} if (success != BA_ReturnCode.Success) { errorCount++; } else if (ArchiveChecked) { string reportName = Constants.FILE_EXPORT_WATERSHED_REPORT_PDF; // Copy final watershed analysis report to a central location if (File.Exists(outputPath)) { File.Copy(outputPath, GeneralTools.GetFullPdfFileName(reportName), true); } //if (SiteAnalysisChecked) //{ // reportName = Constants.FILE_EXPORT_SITE_ANALYSIS_REPORT_PDF; // File.Copy(outputPath, GeneralTools.GetFullPdfFileName(reportName), true); //} } // Create closing log entry for AOI if (errorCount == 0) { strLogEntry = DateTime.Now.ToString("MM/dd/yy H:mm:ss ") + "Completed batch PDF export for " + oAoi.Name + ". The output is located at " + oAoi.FilePath + "\\" + Constants.FOLDER_MAP_PACKAGE + "\r\n"; Names[idxRow].AoiBatchStateText = AoiBatchState.Completed.ToString(); } else { strLogEntry = DateTime.Now.ToString("MM/dd/yy H:mm:ss ") + "Completed batch PDF export WITH ERRORS for " + oAoi.Name + ". The output is located at " + oAoi.FilePath + "\\" + Constants.FOLDER_MAP_PACKAGE + "\r\n" + "Check for errors in the logs at " + oAoi.FilePath + "\\" + Constants.FOLDER_LOGS + "! \r\n"; Names[idxRow].AoiBatchStateText = AoiBatchState.Errors.ToString(); } File.AppendAllText(_strLogFile, strLogEntry); } catch (Exception e) { MessageBox.Show("An error occurred while running the Batch PDF Tool!! " + e.Message, "BAGIS PRO"); Module1.Current.ModuleLogManager.LogError(nameof(RunImplAsync), e.StackTrace); strLogEntry = DateTime.Now.ToString("MM/dd/yy H:mm:ss ") + "Batch PDF export failed for " + oAoi.Name + ". Check for errors in the logs at " + oAoi.FilePath + "\\" + Constants.FOLDER_LOGS + "!\r\n"; File.AppendAllText(_strLogFile, strLogEntry); Names[idxRow].AoiBatchStateText = AoiBatchState.Failed.ToString(); } } } MessageBox.Show("Done!"); // Concluding log entry strLogEntry = DateTime.Now.ToString("MM/dd/yy H:mm:ss ") + "Batch tool finished!! \r\n"; using (StreamWriter sw = File.AppendText(_strLogFile)) { sw.WriteLine(strLogEntry); } }
async public void snippets_ProjectItems() { #region Reference layout project items //A layout project item is an item that appears in the Layouts folder in the Catalog pane //Reference all the layout project items IEnumerable <LayoutProjectItem> layouts = Project.Current.GetItems <LayoutProjectItem>(); //Or reference a specific layout project item by name LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("MyLayout")); #endregion #region Open a layout project item in a new view //A layout project item may be in a project but it may not be open in a view and/or active //First get the layout associated with the layout project item Layout layout = layoutItem.GetLayout(); //Open a new pane ILayoutPane iNewLayoutPane = await ProApp.Panes.CreateLayoutPaneAsync(layout); #endregion #region Activate an already open layout view //A layout view may exist but it may not be active //Iterate through each pane in the application and check to see if the layout is already open and if so, activate it foreach (var pane in ProApp.Panes) { var layoutPane = pane as ILayoutPane; if (layoutPane == null) //if not a layout view, continue to the next pane { continue; } if (layoutPane.LayoutView.Layout == layout) //if there is a match, activate the view { (layoutPane as Pane).Activate(); return; } } #endregion #region Reference the active layout view //First check to see if the current, active view is a layout view. If it is, use it LayoutView activeLayoutView = LayoutView.Active; if (activeLayoutView != null) { // use activeLayoutView } #endregion #region Create a new, basic layout and open it //Create a new layout project item layout in the project Layout newLayout = await QueuedTask.Run <Layout>(() => { newLayout = LayoutFactory.Instance.CreateLayout(8.5, 11, LinearUnit.Inches); newLayout.SetName("New 8.5x11 Layout"); return(newLayout); }); //Open new layout on the GUI thread await ProApp.Panes.CreateLayoutPaneAsync(newLayout); #endregion #region Create a new layout using a modified CIM and open it //Create a new layout project item layout in the project Layout newCIMLayout = await QueuedTask.Run <Layout>(() => { //Set up a CIM page CIMPage newPage = new CIMPage { //required parameters Width = 8.5, Height = 11, Units = LinearUnit.Inches, //optional rulers ShowRulers = true, SmallestRulerDivision = 0.5, //optional guides ShowGuides = true }; CIMGuide guide1 = new CIMGuide { Position = 1, Orientation = Orientation.Vertical }; CIMGuide guide2 = new CIMGuide { Position = 6.5, Orientation = Orientation.Vertical }; CIMGuide guide3 = new CIMGuide { Position = 1, Orientation = Orientation.Horizontal }; CIMGuide guide4 = new CIMGuide { Position = 10, Orientation = Orientation.Horizontal }; List <CIMGuide> guideList = new List <CIMGuide> { guide1, guide2, guide3, guide4 }; newPage.Guides = guideList.ToArray(); //Create a new page newCIMLayout = LayoutFactory.Instance.CreateLayout(newPage); newCIMLayout.SetName("New 8.5x11 Layout"); return(newCIMLayout); }); //Open new layout on the GUI thread await ProApp.Panes.CreateLayoutPaneAsync(newCIMLayout); #endregion #region Import a pagx into a project //Create a layout project item from importing a pagx file IProjectItem pagx = ItemFactory.Instance.Create(@"C:\Temp\Layout.pagx") as IProjectItem; Project.Current.AddItem(pagx); #endregion #region Remove a layout project item //Remove a layout from the project completely Project.Current.RemoveItem(layoutItem); #endregion }