Skip to content
Snippets Groups Projects
Commit b5f0cb04 authored by Ruben Heinrich's avatar Ruben Heinrich
Browse files

[base] 7 Added parameters

parent 9e6a576d
No related branches found
No related tags found
2 merge requests!47 parameter,!2Basic import and export functionality
...@@ -3,21 +3,34 @@ ...@@ -3,21 +3,34 @@
#'r2ogs6_parameter #'r2ogs6_parameter
#'@description S3 class describing a .prj parameter #'@description tag: parameter
#'@param name The parameter name #'@param name string:
#'@param type The parameter type #'@param type string:
#'@param values Optional: string | numeric: Parameter values
#'@param value Optional: string | double: Parameter value #'@param value Optional: string | double: Parameter value
#'@param values Optional: string | double: Parameter values
#'@param curve Optional: string:
#'@param parameter Optional: string:
#'@param group_id_property Optional: string:
#'@param index_values Optional: list:
#'@param field_name Optional: string:
#'@param mesh Optional: string:
#'@param expression Optional: string:
#'@param time_series Optional: list:
#'@param use_local_coordinate_system Optional: string, "true" | "false":
#'@export #'@export
r2ogs6_parameter <- function(name, r2ogs6_parameter <- function(name,
type, type,
value = NULL,
values = NULL, values = NULL,
value = NULL) { curve = NULL,
parameter = NULL,
if(!is.null(values) && !is.null(value)){ group_id_property = NULL,
stop(paste("r2ogs6_parameter: Use either 'values' or 'value'", index_values = NULL,
"parameter (XOR)"), call. = FALSE) field_name = NULL,
} mesh = NULL,
expression = NULL,
time_series = NULL,
use_local_coordinate_system = NULL) {
#Coerce input #Coerce input
value <- coerce_string_to_numeric(value) value <- coerce_string_to_numeric(value)
...@@ -25,32 +38,107 @@ r2ogs6_parameter <- function(name, ...@@ -25,32 +38,107 @@ r2ogs6_parameter <- function(name,
new_r2ogs6_parameter(name, new_r2ogs6_parameter(name,
type, type,
value,
values, values,
value) curve,
parameter,
group_id_property,
index_values,
field_name,
mesh,
expression,
time_series,
use_local_coordinate_system)
} }
new_r2ogs6_parameter <- function(name, new_r2ogs6_parameter <- function(name,
type, type,
values, value = NULL,
value) { values = NULL,
curve = NULL,
parameter = NULL,
group_id_property = NULL,
index_values = NULL,
field_name = NULL,
mesh = NULL,
expression = NULL,
time_series = NULL,
use_local_coordinate_system = NULL) {
assertthat::assert_that(assertthat::is.string(name)) assertthat::assert_that(assertthat::is.string(name))
assertthat::assert_that(assertthat::is.string(type)) assertthat::assert_that(assertthat::is.string(type))
validate_is_null_or_numeric(values)
validate_is_null_or_number(value) validate_is_null_or_number(value)
validate_is_null_or_numeric(values)
validate_is_null_or_string(curve,
parameter,
group_id_property,
field_name,
mesh,
expression)
validate_is_null_or_str_flag(use_local_coordinate_system)
structure( index_values <- validate_index_values(index_values)
list(
name = name, if(!is.null(time_series)){
type = type, assertthat::assert_that(is.list(time_series))
values = values, names(time_series) <- rep("pair", length(time_series))
value = value,
is_subclass = FALSE, for(i in seq_len(length(time_series))){
attr_names = character(), time_series[[i]] <- validate_param_list(time_series[[i]],
flatten_on_exp = c("values") c("time",
), "parameter_name"))
class = "r2ogs6_parameter" }
}
structure(list(name = name,
type = type,
value = value,
values = values,
curve = curve,
parameter = parameter,
group_id_property = group_id_property,
index_values = index_values,
field_name = field_name,
mesh = mesh,
expression = expression,
time_series = time_series,
use_local_coordinate_system = use_local_coordinate_system,
is_subclass = TRUE,
attr_names = character(),
flatten_on_exp = c("values")
),
class = "r2ogs6_parameter"
) )
} }
#===== validation utility =====
validate_index_values <- function(index_values){
if(!is.null(index_values)){
assertthat::assert_that(is.list(index_values))
assertthat::assert_that(length(index_values == 2))
#Coerce index
index_values[[1]] <- coerce_string_to_numeric(index_values[[1]])
names(index_values)[[1]] <- "index"
#Coerce value / values
index_values[[2]] <- coerce_string_to_numeric(index_values[[2]],
TRUE)
if(length(index_values[[2]]) > 1){
names(index_values)[[2]] <- "values"
}else{
names(index_values)[[2]] <- "value"
}
}
return(invisible(index_values))
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment