use super::{
super::{
HexahedralFiniteElements, Remove, Scale, TetrahedralFiniteElements, Translate,
TriangularFiniteElements,
},
ErrorWrapper,
input::{read_finite_elements, read_segmentation},
output::{write_finite_elements, write_segmentation},
};
use clap::Subcommand;
#[derive(Subcommand)]
pub enum ConvertSubcommand {
Mesh(ConvertMeshArgs),
Segmentation(ConvertSegmentationArgs),
}
#[derive(clap::Args)]
pub struct ConvertMeshArgs {
#[command(subcommand)]
pub subcommand: ConvertMeshSubcommand,
}
#[derive(Subcommand)]
pub enum ConvertMeshSubcommand {
Hex(ConvertMeshSubcommandArgs),
Tet(ConvertMeshSubcommandArgs),
Tri(ConvertMeshSubcommandArgs),
}
impl ConvertMeshSubcommand {
pub fn is_quiet(&self) -> bool {
match self {
ConvertMeshSubcommand::Hex(args) => args.quiet,
ConvertMeshSubcommand::Tet(args) => args.quiet,
ConvertMeshSubcommand::Tri(args) => args.quiet,
}
}
}
#[derive(clap::Args)]
pub struct ConvertMeshSubcommandArgs {
#[arg(long, short, value_name = "FILE")]
input: String,
#[arg(long, short, value_name = "FILE")]
output: String,
#[arg(action, long, short)]
quiet: bool,
}
#[derive(clap::Args)]
pub struct ConvertSegmentationArgs {
#[arg(long, short, value_name = "FILE")]
pub input: String,
#[arg(long, short, value_name = "FILE")]
pub output: String,
#[arg(long, short = 'x', value_name = "NEL")]
pub nelx: Option<usize>,
#[arg(long, short = 'y', value_name = "NEL")]
pub nely: Option<usize>,
#[arg(long, short = 'z', value_name = "NEL")]
pub nelz: Option<usize>,
#[arg(action, long, short)]
pub quiet: bool,
}
pub fn convert_mesh(subcommand: ConvertMeshSubcommand) -> Result<(), ErrorWrapper> {
match subcommand {
ConvertMeshSubcommand::Hex(args) => write_finite_elements(
args.output,
read_finite_elements::<_, _, _, HexahedralFiniteElements>(
&args.input,
args.quiet,
true,
)?,
args.quiet,
),
ConvertMeshSubcommand::Tet(args) => write_finite_elements(
args.output,
read_finite_elements::<_, _, _, TetrahedralFiniteElements>(
&args.input,
args.quiet,
true,
)?,
args.quiet,
),
ConvertMeshSubcommand::Tri(args) => write_finite_elements(
args.output,
read_finite_elements::<_, _, _, TriangularFiniteElements>(
&args.input,
args.quiet,
true,
)?,
args.quiet,
),
}
}
pub fn convert_segmentation(
input: String,
output: String,
nelx: Option<usize>,
nely: Option<usize>,
nelz: Option<usize>,
quiet: bool,
) -> Result<(), ErrorWrapper> {
write_segmentation(
output,
read_segmentation(
input,
nelx,
nely,
nelz,
Remove::default(),
Scale::default(),
Translate::default(),
quiet,
true,
)?,
quiet,
)
}