# sec_interp.core.validation package

## Submodules

- sec_interp.core.validation.field_validator module
  - `validate_numeric_input()`
  - `validate_integer_input()`
  - `validate_angle_range()`
  - `validate_field_exists()`
  - `validate_field_type()`
- sec_interp.core.validation.layer_validator module
  - `validate_layer_exists()`
  - `validate_layer_has_features()`
  - `validate_layer_geometry()`
  - `validate_raster_band()`
  - `validate_structural_requirements()`
  - `validate_layer_configuration()`
  - `validate_crs_compatibility()`
- sec_interp.core.validation.path_validator module
  - `validate_safe_output_path()`
  - `validate_output_path()`
- sec_interp.core.validation.project_validator module
  - `validate_reasonable_ranges()`
  - `ValidationParams`
    - `ValidationParams.raster_layer`
    - `ValidationParams.band_number`
    - `ValidationParams.line_layer`
    - `ValidationParams.output_path`
    - `ValidationParams.scale`
    - `ValidationParams.vert_exag`
    - `ValidationParams.buffer_dist`
    - `ValidationParams.outcrop_layer`
    - `ValidationParams.outcrop_field`
    - `ValidationParams.struct_layer`
    - `ValidationParams.struct_dip_field`
    - `ValidationParams.struct_strike_field`
    - `ValidationParams.dip_scale_factor`
  - `ProjectValidator`
    - `ProjectValidator.validate_all()`
    - `ProjectValidator.validate_preview_requirements()`

## Module contents

Validation package for SecInterp plugin.

sec_interp.core.validation.validate_numeric_input(value: str, min_val: float | None = None, max_val: float | None = None, field_name: str = 'Value', allow_empty: bool = False) → Tuple[bool, str, float | None]

  Validate a numeric input string from a text field.

  Parameters:

    - value – The string value to validate.

    - min_val – Optional minimum value allowed.

    - max_val – Optional maximum value allowed.

    - field_name – Name of the field for error messages.

    - allow_empty – Whether to allow an empty string.

  Returns:

    (is_valid, error_message, float_value)

      - is_valid (bool): True if validation passed.

      - error_message (str): Error details if validation failed.

      - float_value (float | None): The parsed numeric value if valid.

  Return type:

    tuple

sec_interp.core.validation.validate_integer_input(value: str, min_val: int | None = None, max_val: int | None = None, field_name: str = 'Value', allow_empty: bool = False) → Tuple[bool, str, int | None]

  Validate an integer input string from a text field.

  Parameters:

    - value – The string value to validate.

    - min_val – Optional minimum value allowed.

    - max_val – Optional maximum value allowed.

    - field_name – Name of the field for error messages.

    - allow_empty – Whether to allow an empty string.

  Returns:

    (is_valid, error_message, int_value)

      - is_valid (bool): True if validation passed.

      - error_message (str): Error details if validation failed.

      - int_value (int | None): The parsed integer value if valid.

  Return type:

    tuple

sec_interp.core.validation.validate_angle_range(value: float, field_name: str, min_angle: float = 0.0, max_angle: float = 360.0) → Tuple[bool, str]

  Validate that an angle value is within the expected range.

  Parameters:

    - value – The angle value to validate.

    - field_name – Name of the field for error messages.

    - min_angle – Minimum allowed angle (default 0.0).

    - max_angle – Maximum allowed angle (default 360.0).

  Returns:

    (is_valid, error_message)

      - is_valid (bool): True if validation passed.

      - error_message (str): Error details if validation failed.

  Return type:

    tuple

sec_interp.core.validation.validate_field_exists(layer: qgis.core.QgsVectorLayer, field_name: str | None) → Tuple[bool, str]

  Validate that a specific field exists in a vector layer.

  Parameters:

    - layer – The QGIS vector layer to check.

    - field_name – The name of the field to search for.

  Returns:

    (is_valid, error_message)

      - is_valid (bool): True if validation passed.

      - error_message (str): Error details if validation failed.

  Return type:

    tuple

sec_interp.core.validation.validate_field_type(layer: qgis.core.QgsVectorLayer, field_name: str, expected_types: List[qgis.PyQt.QtCore.QVariant.Type]) → Tuple[bool, str]

  Validate that a field in a layer has one of the expected data types.

  Parameters:

    - layer – The QGIS vector layer containing the field.

    - field_name – The name of the field to check.

    - expected_types – List of allowed QVariant.Type values.

  Returns:

    (is_valid, error_message)

      - is_valid (bool): True if validation passed.

      - error_message (str): Error details if validation failed.

  Return type:

    tuple

sec_interp.core.validation.validate_layer_exists(layer_name: str | None) → Tuple[bool, str, qgis.core.QgsMapLayer | None]

  Validate that a layer with the given name exists in the current QGIS project.

  Parameters:

    layer_name – The name of the layer to search for.

  Returns:

    (is_valid, error_message, layer)

      - is_valid (bool): True if at least one matching layer was found.

      - error_message (str): Error details if no layer was found.

      - layer (QgsMapLayer | None): The first matching layer instance if valid.

  Return type:

    tuple

sec_interp.core.validation.validate_layer_has_features(layer: qgis.core.QgsVectorLayer) → tuple[bool, str]

  Validate that a vector layer contains at least one feature.

  Parameters:

    layer – The QGIS vector layer to check.

  Returns:

    (is_valid, error_message)

      - is_valid (bool): True if the layer has features.

      - error_message (str): Error details if the layer is empty.

  Return type:

    tuple

sec_interp.core.validation.validate_layer_geometry(layer: qgis.core.QgsVectorLayer, expected_type: qgis.core.QgsWkbTypes.GeometryType) → tuple[bool, str]

  Validate that a vector layer matches the expected QGIS geometry type.

  Parameters:

    - layer – The QGIS vector layer to check.

    - expected_type – The required QgsWkbTypes.GeometryType.

  Returns:

    (is_valid, error_message)

      - is_valid (bool): True if the geometry type matches.

      - error_message (str): Detailed error if types mismatch.

  Return type:

    tuple

sec_interp.core.validation.validate_raster_band(layer: qgis.core.QgsRasterLayer, band_number: int) → tuple[bool, str]

  Validate that a specified band number exists in the given raster layer.

  Parameters:

    - layer – The QGIS raster layer to check.

    - band_number – The 1-based index of the raster band.

  Returns:

    (is_valid, error_message)

      - is_valid (bool): True if the band exists.

      - error_message (str): Error message if the band is out of range.

  Return type:

    tuple

sec_interp.core.validation.validate_structural_requirements(layer: qgis.core.QgsVectorLayer, layer_name: str, dip_field: str | None, strike_field: str | None) → Tuple[bool, str]

  Validate structural layer requirements (geometry and attribute fields).

  Parameters:

    - layer – The QGIS point layer containing structural data.

    - layer_name – Human-readable name of the layer.

    - dip_field – Name of the attribute field containing dip values.

    - strike_field – Name of the attribute field containing strike values.

  Returns:

    (is_valid, error_message)

      - is_valid (bool): True if both geometry and fields are valid.

      - error_message (str): Detailed error if validation fails.

  Return type:

    tuple

sec_interp.core.validation.validate_layer_configuration(raster_layer: qgis.core.QgsMapLayer | None, line_layer: qgis.core.QgsVectorLayer | None, outcrop_layer: qgis.core.QgsVectorLayer | None = None, structural_layer: qgis.core.QgsVectorLayer | None = None, outcrop_field: str | None = None, struct_dip_field: str | None = None, struct_strike_field: str | None = None) → Tuple[bool, str]

  Validate a complete set of layer inputs for the plugin.

  Parameters:

    - raster_layer – The primary DEM layer.

    - line_layer – The section line layer.

    - outcrop_layer – Optional geological outcrop layer.

    - structural_layer – Optional structural measurement layer.

    - outcrop_field – Attribute field for geology units.

    - struct_dip_field – Attribute field for dip values.

    - struct_strike_field – Attribute field for strike values.

  Returns:

    (is_valid, error_message)

      - is_valid (bool): True if the entire configuration is valid.

      - error_message (str): First encountered configuration error.

  Return type:

    tuple

sec_interp.core.validation.validate_crs_compatibility(layers: List[qgis.core.QgsMapLayer]) → Tuple[bool, str]

  Validate that a list of layers have compatible Coordinate Reference Systems.

  If layers have different CRSs, it returns a warning message instead of an error, as QGIS can reproject on-the-fly, but accuracy might be impaired.

  Parameters:

    layers – List of QgsMapLayer objects to compare.

  Returns:

    (is_compatible, message)

      - is_compatible (bool): True if all layers share the same CRS.

      - message (str): Warning listing incompatible layers if any.

  Return type:

    tuple

sec_interp.core.validation.validate_safe_output_path(path: str, base_dir: Path | None = None, must_exist: bool = False, create_if_missing: bool = False) → Tuple[bool, str, Path | None]

  Validate an output path string with security and path traversal protection.

  Parameters:

    - path – Original path string to validate.

    - base_dir – Optional base directory to restrict the path to (security sandbox).

    - must_exist – If True, validation fails if the path is not currently found on disk.

    - create_if_missing – If True, attempts to create the directory if it does not exist.

  Returns:

    (is_valid, error_message, resolved_path)

      - is_valid (bool): True if the path is safe and meets requirements.

      - error_message (str): Reason for validation failure.

      - resolved_path (Path | None): Cleaned, absolute Path object if valid.

  Return type:

    tuple

sec_interp.core.validation.validate_output_path(path: str) → Tuple[bool, str, Path | None]

  Validate that an output path is a valid directory and currently writable.

  This is a convenience wrapper around validate_safe_output_path() for general directory validation.

  Parameters:

    path – The path string to validate.

  Returns:

    (is_valid, error_message, resolved_path)

      - is_valid (bool): True if the directory is valid and writable.

      - error_message (str): Error details if validation fails.

      - resolved_path (Path | None): Absolute Path object if valid.

  Return type:

    tuple

sec_interp.core.validation.validate_reasonable_ranges(values: Dict[str, Any]) → List[str]

  Check for unreasonable or potentially erroneous parameter values.

  This function does not return hard errors, but a list of warning strings to inform the user about extreme values (e.g., vertical exaggeration > 10).

  Parameters:

    values – Dictionary containing parameter names and their current values.

  Returns:

    A list of warning messages. If empty, all values are reasonable.

  Return type:

    list[str]

class sec_interp.core.validation.ValidationParams(raster_layer: qgis.core.QgsRasterLayer | None = None, band_number: int | None = None, line_layer: qgis.core.QgsVectorLayer | None = None, output_path: str = '', scale: float = 1.0, vert_exag: float = 1.0, buffer_dist: float = 0.0, outcrop_layer: qgis.core.QgsVectorLayer | None = None, outcrop_field: str | None = None, struct_layer: qgis.core.QgsVectorLayer | None = None, struct_dip_field: str | None = None, struct_strike_field: str | None = None, dip_scale_factor: float = 1.0)

  Bases: `object`

  Data container for all parameters that need cross-layer validation.

  band_number: int | None = None
  buffer_dist: float = 0.0
  dip_scale_factor: float = 1.0
  line_layer: qgis.core.QgsVectorLayer | None = None
  outcrop_field: str | None = None
  outcrop_layer: qgis.core.QgsVectorLayer | None = None
  output_path: str = ''
  raster_layer: qgis.core.QgsRasterLayer | None = None
  scale: float = 1.0
  struct_dip_field: str | None = None
  struct_layer: qgis.core.QgsVectorLayer | None = None
  struct_strike_field: str | None = None
  vert_exag: float = 1.0

class sec_interp.core.validation.ProjectValidator

  Bases: `object`

  Orchestrates validation of project parameters independent of the GUI.

  static validate_all(params: ValidationParams) → Tuple[bool, str]

    Perform a comprehensive validation of all project parameters.

    This includes checking for required files, geometry types, field existence, and numeric range constraints.

    Parameters:

      params – The parameters to validate.

    Returns:

      (is_valid, error_message)

        - is_valid (bool): True if all checks passed.

        - error_message (str): Newline-separated list of all found errors.

    Return type:

      tuple

  static validate_preview_requirements(params: ValidationParams) → Tuple[bool, str]

    Validate only the minimum requirements needed to generate a preview.

    Parameters:

      params – The parameters containing at least raster and line layers.

    Returns:

      (is_valid, error_message)

        - is_valid (bool): True if the core preview can be generated.

        - error_message (str): Description of missing core components.

    Return type:

      tuple