示例#1
0
        private void ShowOptions(DatasourceDriver driver, GdalDriverMetadata metadata,
                                 StronglyTypedGrid <DriverOption> grid, TabPageAdv tabPage)
        {
            string options    = driver.get_Metadata(metadata);
            bool   hasOptions = !string.IsNullOrWhiteSpace(options);

            if (hasOptions)
            {
                var list = DriverMetadata.ParseOptionList(options).OrderBy(o => o.Name).ToList();
                hasOptions      = list.Any();
                grid.DataSource = list;

                var cmn = grid.Adapter.GetColumn(item => item.UserDescription);
                if (cmn != null)
                {
                    cmn.Width = 0;      // to make it shrink
                }

                grid.AdjustColumnWidths();

                if (cmn != null && cmn.Width > DescriptionColumnWidth)
                {
                    cmn.Width = DescriptionColumnWidth;
                }

                grid.AdjustRowHeights();
            }

            tabPage.TabVisible = hasOptions;
        }
        /// <summary>
        /// Generates controls for driver options.
        /// </summary>
        private void GenerateDriverControls(Panel panel, DatasourceDriver driver)
        {
            var options = driver.GetMainOptions().ToList();

            if (options.Any())
            {
                // options in 2 different section for drivers like GTiff
                var parameters = _driverOptions.Where(o => !options.Contains(o.Name));
                _generator.GenerateIntoPanel(panel, driver.Name + " Other Options", parameters);

                parameters = _driverOptions.Where(o => options.Contains(o.Name));
                _generator.GenerateIntoPanel(panel, driver.Name + " Main Options", parameters);
            }
            else
            {
                // one section for all the others
                _generator.GenerateIntoPanel(panel, driver.Name + " Options", _driverOptions);
            }

            _driverOptions.SetControlDefaults();

            panel.AddVerticalPadding();

            _styleService.ApplyStyle(panel);
        }
示例#3
0
        /// <summary>
        /// Restores last used parameters of the tool from the disk based config file.
        /// </summary>
        public static void RestoreConfig(this DatasourceDriver driver, IEnumerable <BaseParameter> parameters)
        {
            string filename = driver.GetConfigPath();

            if (!File.Exists(filename))
            {
                return;
            }

            try
            {
                using (var reader = new StreamReader(filename))
                {
                    using (var xmlReader = new XmlTextReader(reader))
                    {
                        xmlReader.ReadStartElement();

                        xmlReader.ReadParameters(parameters);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Current.Warn("Failed to deserialize tool settings.", ex);
            }
        }
示例#4
0
        /// <summary>
        /// Updates output extension when active driver changes.
        /// </summary>
        private void UpdateOutputFilename(IParametrizedTool tool, DatasourceDriver driver)
        {
            var input = tool.GetSingleInputParameter() as FilenameParameter;

            if (input == null)
            {
                return;
            }

            foreach (var p in tool.Parameters.OfType <OutputLayerParameter>())
            {
                var ctrl = p.Control as IOuputputParameterControl;
                if (ctrl != null)
                {
                    string ext = driver.Extension;
                    if (string.IsNullOrWhiteSpace(ext))
                    {
                        // sometimes there is no extension in the driver metadata
                        ext = "???";
                    }

                    ctrl.SetExtension(ext);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Generates the parameters for particular driver.
        /// </summary>
        public static IEnumerable<BaseParameter> GenerateCreationOptions(this DatasourceDriver driver)
        {
            string options = driver.get_Metadata(GdalDriverMetadata.CreationOptionList);
            if (string.IsNullOrWhiteSpace(options))
            {
                return new List<BaseParameter>();
            }

            var list = DriverMetadata.ParseOptionList(options).ToList();

            var result = new List<BaseParameter>();

            var exclude = new[] { "boolean", "string-select" };

            result.AddRange(Generate(list.Where(o => o.Type.ToLower() == "boolean")));

            result.AddRange(Generate(list.Where(o => !exclude.Contains(o.Type.ToLower()))));

            result.AddRange(Generate(list.Where(o => o.Type.ToLower() == "string-select")));

            foreach (var p in result)
            {
                p.Name = p.DisplayName;
            }

            return result;
        }
示例#6
0
        private TreeNodeAdv CreateDriverNode(DatasourceDriver driver, bool vector)
        {
            var node = new TreeNodeAdv {
                Text = driver.Name, Tag = driver
            };

            node.LeftImageIndices = new[] { vector ? 0 : 1 };
            return(node);
        }
示例#7
0
        private void ShowDriverMetadata(DatasourceDriver driver)
        {
            var items = driver.Where(item => item.Type != GdalDriverMetadata.LayerCreationOptionList &&
                                     item.Type != GdalDriverMetadata.CreationOptionList &&
                                     item.Type != GdalDriverMetadata.OpenOptionList).ToList();

            _driverMetadataGrid1.DataSource = items;
            _driverMetadataGrid1.AdjustRowHeights();
        }
        protected override void OnDriverChanged(DatasourceDriver driver)
        {
            base.OnDriverChanged(driver);

            if (GdalTool.SupportDriverCreationOptions)
            {
                GenerateDriverOptions(driver, _tabDriver);
            }
        }
示例#9
0
 /// <summary>
 /// Gets list of options to be displayed in a separate main section.
 /// </summary>
 public static IEnumerable<string> GetMainOptions(this DatasourceDriver driver)
 {
     switch (driver.Name.ToLower())
     {
         case GdalFormats.GTiff:
             // can be specified in app config if needed
             return new[] { "COMPRESS", "JPEG_QUALITY", "ZLEVEL" };
         default:
             return new List<string>();
     }
 }
示例#10
0
        protected override void OnDriverChanged(DatasourceDriver driver)
        {
            base.OnDriverChanged(driver);

            var tool = Model.Tool as IParametrizedTool;

            if (tool == null)
            {
                return;
            }

            UpdateOutputFilename(tool, driver);

            UpdateDataTypes(driver);
        }
示例#11
0
        /// <summary>
        /// Generates control for creation options exposed by selected GDAL driver.
        /// </summary>
        private void GenerateDriverOptions(DatasourceDriver driver, TabPageAdv tab)
        {
            var panel = tab.GetPanel();

            panel.Controls.Clear();

            _driverOptions = driver.GenerateCreationOptions().ToList();

            driver.RestoreConfig(DriverParameters);

            GenerateDriverControls(panel, driver);

            tab.TabVisible = panel.Controls.Count > 0;

            superToolTip1.AddTooltips(_driverOptions);
        }
示例#12
0
        /// <summary>
        /// Saves configuration of the tool.
        /// </summary>
        public static void SaveConfig(this DatasourceDriver driver, IEnumerable <BaseParameter> parameters)
        {
            try
            {
                string xml = parameters.Serialize("Driver");

                string filename = GetConfigPath(driver);

                PathHelper.CreateFolder(filename);

                File.WriteAllText(filename, xml);
            }
            catch (Exception ex)
            {
                Logger.Current.Warn("Failed to serialize tool settings.", ex);
            }
        }
示例#13
0
        /// <summary>
        /// Gets list of data types supported by driver according to metadata.
        /// </summary>
        public static IEnumerable<string> GetCreationDataTypes(this DatasourceDriver driver)
        {
            string s = driver.get_Metadata(GdalDriverMetadata.CreationDataTypes);

            IList<string> result;

            if (string.IsNullOrWhiteSpace(s))
            {
                result = GdalHelper.GetRasterDataTypes();
            }
            else
            {
                result = s.Split(new[] { ' ' }).ToList();
            }

            result.Insert(0, SameAsInputDataType);

            return result;
        }
示例#14
0
        /// <summary>
        /// Updates list of supported data type for the current driver.
        /// </summary>
        /// <param name="driver">The driver.</param>
        private void UpdateDataTypes(DatasourceDriver driver)
        {
            var tool = Model.Tool as GisTool;

            if (tool == null)
            {
                return;
            }

            var p = tool.FindParameter <GdalRasterTool, string>(t => t.OutputType) as OptionsParameter;

            if (p == null)
            {
                return;
            }

            var ctrl = p.Control as IOptionsParameterControl;

            if (ctrl != null)
            {
                var types = driver.GetCreationDataTypes();
                ctrl.SetOptions(types);
            }
        }
示例#15
0
 /// <summary>
 /// Gets path of the file with configuration info for the driver.
 /// </summary>
 private static string GetConfigPath(this DatasourceDriver driver)
 {
     return(ConfigPathHelper.GetDriversConfigPath() + driver.Name + ".xml");
 }
示例#16
0
 /// <summary>
 /// Updates other controls after driver is changed.
 /// </summary>
 protected virtual void OnDriverChanged(DatasourceDriver driver)
 {
     // overriden in derived classes
 }
示例#17
0
 /// <summary>
 /// Gets the list of drivers that support the creation of new datasources.
 /// </summary>
 protected abstract bool DriverFilter(DatasourceDriver driver);
示例#18
0
 /// <summary>
 /// Gets the list of drivers that support the creation of new datasources.
 /// </summary>
 protected override bool DriverFilter(DatasourceDriver driver)
 {
     return(driver.IsVector);
 }
示例#19
0
 /// <summary>
 /// Gets the list of drivers that support the creation of new datasources.
 /// </summary>
 protected override bool DriverFilter(DatasourceDriver driver)
 {
     return(driver.IsRaster && driver.MatchesFilter(Api.Enums.DriverFilter.Create));
 }