//--------------------------------------------------------------------- // FIX: 059 Do not display map window number with layer name // if there is only one map window. // public ViewModelWindowSwitchGISLayer(List<GISLayer> ValidHluLayers, GISLayer SelectedHLULayer, int MapWindowsCount) { if (ValidHluLayers != null) { _availableHLULayers = ValidHluLayers; _selectedHLULayer = SelectedHLULayer; _mapWindowsCount = MapWindowsCount; // Set the static variable for the total number of // map windows. GISLayer.MapWindowsCount = _mapWindowsCount; } }
public bool AddLayer(string tabName) { try { string path = null; if (String.IsNullOrEmpty(tabName)) { tabName = OpenTable(out path); if (!IsHluLayer(tabName)) { if (String.IsNullOrEmpty(tabName)) { throw new Exception("No HLU table."); } else { _mapInfoApp.Do(String.Format("Close Table {0}", tabName)); throw new Exception(String.Format("Table {0} is not a valid HLU table.", tabName)); } } } _hluMapWindowID = Int32.Parse(_mapInfoApp.Eval("FrontWindow()")); if ((_hluMapWindowID <= 0) || Int32.Parse(_mapInfoApp.Eval(String.Format( "WindowInfo({0}, {1})", _hluMapWindowID, (int)MapInfoConstants.WindowInfo.WIN_INFO_TYPE))) != (int)MapInfoConstants.WindowInfoWindowTypes.WIN_MAPPER) _hluMapWindowID = -1; //--------------------------------------------------------------------- // CHANGED: CR19 (Feature layer position in GIS) // Loop through all windows to find the window number (order) of // the current window. int numWindows = Int32.Parse(_mapInfoApp.Eval("NumWindows()")); int windowID; int windowNum = 0; for (int i = 1; i <= numWindows; i++) { windowID = Int32.Parse(_mapInfoApp.Eval(String.Format("WindowID({0})", i))); // If this is a mapper window if (Int32.Parse(_mapInfoApp.Eval(String.Format("WindowInfo({0}, {1})", i, (int)MapInfoConstants.WindowInfo.WIN_INFO_TYPE))) == (int)MapInfoConstants.WindowInfoWindowTypes.WIN_MAPPER) { // Increment the window number windowNum += 1; // If this window is the current window then use this window number (order) if (windowID == _hluMapWindowID) break; } } //--------------------------------------------------------------------- if (_hluMapWindowID != -1) { _mapInfoApp.Do(String.Format("Add Map Layer {0}", tabName)); } else { _mapInfoApp.Do(String.Format("Map From {0}", tabName)); _hluMapWindowID = Convert.ToInt32(_mapInfoApp.Eval("FrontWindow()")); SizeWindow(_hluMapWindowID, true); } //--------------------------------------------------------------------- // CHANGED: CR19 (Feature layer position in GIS) // Set the current HLU layer to the new layer. _hluCurrentLayer = new GISLayer(windowNum, 0, tabName); //--------------------------------------------------------------------- _mapInfoApp.Do(String.Format("Set Window {0} SysMenuClose Off", _hluMapWindowID)); if (!String.IsNullOrEmpty(path)) return SaveWorkspace(); return true; } catch (Exception ex) { _hluMapWindowID = -1; MessageBox.Show(ex.Message, "Error Opening Table", MessageBoxButton.OK, MessageBoxImage.Error); return false; } }
/// <summary> /// Checks whether the current workspace contains an HLU layer. Also initializes the fields /// _hluMapWindowID and, indirectly (by calling IsHluLayer()), _hluFieldNames and _hluFieldMap. /// </summary> /// <returns>True if the current workspace contains a valid HLU layer, otherwise false.</returns> protected override bool IsHluWorkspace() { if (_mapInfoApp == null) return false; try { // check if the workspace contains a mapper window with a valid HLU layer int numWindows = Int32.Parse(_mapInfoApp.Eval("NumWindows()")); int windowID; int windowNum = 0; string layer; // Loop through all windows for (int i = 1; i <= numWindows; i++) { windowID = Int32.Parse(_mapInfoApp.Eval(String.Format("WindowID({0})", i))); // If this is a mapper window if (Int32.Parse(_mapInfoApp.Eval(String.Format("WindowInfo({0}, {1})", i, (int)MapInfoConstants.WindowInfo.WIN_INFO_TYPE))) == (int)MapInfoConstants.WindowInfoWindowTypes.WIN_MAPPER) { // Increment the window number counter windowNum += 1; // Store the number of layers in the window int numLayers = Int32.Parse(_mapInfoApp.Eval(String.Format("MapperInfo({0}, {1})", windowID, (int)MapInfoConstants.MapperInfo.MAPPER_INFO_LAYERS))); // Loop through all the layers in the current window for (int j = 1; j <= numLayers; j++) { // If this is not a cosmetic layer if (_mapInfoApp.Eval(String.Format("LayerInfo({0}, {1}, {2})", windowID, j, (int)MapInfoConstants.LayerInfo.LAYER_INFO_COSMETIC)) == "F") { // Store the name of the layer layer = _mapInfoApp.Eval(String.Format("LayerInfo({0}, {1}, {2})", windowID, j, (int)MapInfoConstants.LayerInfo.LAYER_INFO_NAME)); // Check to see if this layer is a HLU layer if (IsHluLayer(layer)) { _hluMapWindowID = windowID; _hluCurrentLayer = new GISLayer(windowNum, 0, layer); // Disable the Close command in the window's system menu. _mapInfoApp.Do(String.Format("Set Window {0} SysMenuClose Off", _hluMapWindowID)); // Note: Before version 10.5, you could enable or disable the Close // button regardless of the toolbar’s floating or docking state. // As of version 10.5, you cannot enable or disable the Close // button when the toolbar is docked. You can only change the // state when it is floating or floating and hidden. return true; } } } } } // no mapper window open, but there may still be an HLU table int numTables = Int32.Parse(_mapInfoApp.Eval("NumTables()")); string tabName; layer = null; for (int i = 1; i <= numTables; i++) { tabName = _mapInfoApp.Eval(String.Format("TableInfo({0}, {1})", i, (int)MapInfoConstants.TableInfo.TAB_INFO_NAME)); if (IsHluLayer(tabName)) { layer = tabName; break; } } // make a map from the open HLU table or browse for a table return AddLayer(layer); } catch { } return false; }
//--------------------------------------------------------------------- // CHANGED: CR31 (Switching between GIS layers) // Enable the user to switch between different HLU layers, where // there is more than one valid layer in the current document. // /// <summary> /// Determines which of the layers in all the windows are valid HLU layers /// and stores these in a list so the user can switch between them. /// Called before displaying the list of layers for the user to switch /// between. /// </summary> /// <returns>The number of valid HLU layers in the list</returns> public override int ListHluLayers() { if (_mapInfoApp == null) return 0; try { // check if the workspace contains a mapper window with a valid HLU layer int numWindows = Int32.Parse(_mapInfoApp.Eval("NumWindows()")); int windowID; _mapWindowsCount = 0; // Initialise the list of valid layers if (_hluLayerList == null) _hluLayerList = new List<GISLayer>(); // Clear the valid HLU layer list _hluLayerList.Clear(); // Loop through all windows for (int i = 1; i <= numWindows; i++) { windowID = Int32.Parse(_mapInfoApp.Eval(String.Format("WindowID({0})", i))); // If this is a mapper window if (Int32.Parse(_mapInfoApp.Eval(String.Format("WindowInfo({0}, {1})", i, (int)MapInfoConstants.WindowInfo.WIN_INFO_TYPE))) == (int)MapInfoConstants.WindowInfoWindowTypes.WIN_MAPPER) { //--------------------------------------------------------------------- // FIX: 059 Do not display map window number with layer name // if there is only one map window. // // Increment the map window counter _mapWindowsCount += 1; //--------------------------------------------------------------------- // Store the number of layers in the window int numLayers = Int32.Parse(_mapInfoApp.Eval(String.Format("MapperInfo({0}, {1})", windowID, (int)MapInfoConstants.MapperInfo.MAPPER_INFO_LAYERS))); // Loop through all the layers in the current window for (int j = 1; j <= numLayers; j++) { // If this is not a cosmetic layer if (_mapInfoApp.Eval(String.Format("LayerInfo({0}, {1}, {2})", windowID, j, (int)MapInfoConstants.LayerInfo.LAYER_INFO_COSMETIC)) == "F") { // Store the name of the layer string layer = _mapInfoApp.Eval(String.Format("LayerInfo({0}, {1}, {2})", windowID, j, (int)MapInfoConstants.LayerInfo.LAYER_INFO_NAME)); // Check to see if this layer is a HLU layer if (IsHluLayer(layer)) { // Add the name of layer to the valid list _hluLayerList.Add(new GISLayer(_mapWindowsCount, 0, layer)); } } } } } //// no mapper window open, but there may still be an HLU table //int numTables = Int32.Parse(_mapInfoApp.Eval("NumTables()")); //for (int i = 1; i <= numTables; i++) //{ // _hluLayer = _mapInfoApp.Eval(String.Format("TableInfo({0}, {1})", i, // (int)MapInfoConstants.TableInfo.TAB_INFO_NAME)); // if (IsHluLayer()) break; //} //// make a map from the open HLU table or browse for a table //return AddLayer(); } catch { } if (_hluCurrentLayer == null) _hluCurrentLayer = _hluLayerList[0]; return _hluLayerList.Count(); }
//--------------------------------------------------------------------- //--------------------------------------------------------------------- // CHANGED: CR31 (Switching between GIS layers) // Enable the user to switch between different HLU layers, where // there is more than one valid layer in the current document. // /// <summary> /// Checks whether the layer/table that is passed to the method is an HLU layer, /// as determined by its data structure. The data structure must follow the template of the /// HLU.Data.Model.HluGISLayer.incid_mm_polygonsDataTable (same column names and data types, /// as per type maps _typeMapSystemToSQL and _typeMapSQLToSystem). /// If _hluLayer points to a proper HLU layer _hluLayer, _hluFieldNames and _hluFieldMap /// are initialized to their correct values; otherwise they are left as their old values. /// </summary> /// <returns>True if the new GIS is a valid HLU layer, otherwise False</returns> public override bool IsHluLayer(GISLayer newGISLayer) { int hluMapWindowIDBak = _hluMapWindowID; int[] hluFieldMapBak = _hluFieldMap; string[] hluFieldNamesBak = _hluFieldNames; string hluLayerBak = _hluLayer; string hluColumnListBak = _hluColumnList; try { // Store the previous HLU layer so that the user can remove it // if they wish. _hluLayerOld = _hluLayer; // Initialise the current HLU layer so that it will be set when // if the passed layer is a valid HLU layer. _hluLayer = null; string hluLayer = newGISLayer.LayerName; int windowID = Int32.Parse(_mapInfoApp.Eval(String.Format("WindowID({0})", newGISLayer.MapNum))); if (IsHluLayer(hluLayer)) { // If this layer is in a different window to the current HLU layer if (_hluMapWindowID != windowID) { // Enable the Close command in the previous window's system menu. _mapInfoApp.Do(String.Format("Set Window {0} SysMenuClose On", _hluMapWindowID)); } _hluMapWindowID = windowID; _hluCurrentLayer = newGISLayer; // Disable the Close command in the new window's system menu. _mapInfoApp.Do(String.Format("Set Window {0} SysMenuClose Off", _hluMapWindowID)); } } catch { } // Reset the class properties if the layer is not valid. if (_hluLayer == null) { _hluMapWindowID = hluMapWindowIDBak; _hluFieldNames = hluFieldNamesBak; _hluFieldMap = hluFieldMapBak; _hluLayer = hluLayerBak; _hluColumnList = hluColumnListBak; return false; } else return true; }
public abstract bool IsHluLayer(GISLayer newGISLayer);
public virtual bool Equals(GISLayer other) { if (other == null) return false; return ((this._mapNum == other._mapNum) && (this._mapName == other._mapName) && (this._layerNum == other._layerNum) && (this._layerName == other._layerName)); }