Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion crates/app/src/ui/canvas/interactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ pub(crate) fn handle_selection_drag(
plot: PlotRect,
ui: &Ui,
) {
if app.doc.datasets[dataset].as_afm().is_some()
&& app.afm_force_plot_dataset(ci, object_id).is_none()
{
return;
}
if app.plot_rejects_legacy_selection(ci, object_id)
&& app.plot_interaction_descriptor(ci, object_id).is_none()
{
Expand Down Expand Up @@ -138,7 +143,10 @@ pub(crate) fn finish_selection_drag(
unit: None,
source_stream: None,
});
let unit = if app.doc.datasets[dataset].as_mass_spec().is_some() {
let unit = if app.doc.datasets[dataset].as_afm().is_some() {
app.session.status = format!("Selected AFM X range: {:.3}-{:.3}.", x.min, x.max);
return;
} else if app.doc.datasets[dataset].as_mass_spec().is_some() {
"min"
} else {
"ppm"
Expand Down
2 changes: 2 additions & 0 deletions crates/app/src/ui/command_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ fn execute_inner(
CommandId::LineFit => reveal_tool_group(app, Tool::LineFit, ToolGroup::LineFit),
CommandId::RunPeakFit => run_peak_fit(app, ctx),
CommandId::CurveFit => open_curve_fit(app),
CommandId::FitAfmForce(branch) => super::tools::open_afm_force_fit_task(app, branch),
CommandId::AfmFit(command) => super::tools::run_afm_fit_command(app, command),
CommandId::RunCurveFit => run_curve_fit(app),
CommandId::Statistics => open_statistics(app),
CommandId::ChartType => open_chart_type(app),
Expand Down
30 changes: 28 additions & 2 deletions crates/app/src/ui/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use plotium_core::layout::{Align, Distribute, GutterPreset, SpacingMode};
use plotium_core::properties::PropertyStep;
#[cfg(test)]
use plotium_core::state::WorkflowTab;
use plotium_core::state::{Dataset, PlotiumApp, Tool, ToolGroup};
use plotium_core::state::{AfmForceBranch, Dataset, PlotiumApp, Tool, ToolGroup};
mod craft;
mod identity;
use identity::command_identity;
Expand All @@ -23,7 +23,7 @@ pub use ribbon::{Applicability, RibbonPlacement};
use roster::command_ids;
pub(crate) const REPOSITORY_URL: &str = "https://github.com/nmrtist/plotium";
mod types;
pub use types::{CommandDescriptor, CommandExecutionClass, CommandId};
pub use types::{AfmFitCommand, CommandDescriptor, CommandExecutionClass, CommandId};

pub fn catalog(app: &PlotiumApp) -> Vec<CommandDescriptor> {
command_ids(app.session.recent_files.len())
Expand Down Expand Up @@ -70,6 +70,7 @@ pub fn describe(app: &PlotiumApp, id: CommandId) -> CommandDescriptor {
})
};
let has_selectable_analysis_trace = || has_trace() && !is_time_nmr();
let afm = || dataset().and_then(Dataset::as_afm);
let has_generic_peak_fit_trace = || has_trace() && (is_frequency_nmr() || is_table());
let range = || active_dataset.and_then(|di| app.analysis_range_for(di));
let is_series = || dataset().is_some_and(Dataset::supports_region_analysis);
Expand Down Expand Up @@ -329,6 +330,7 @@ pub fn describe(app: &PlotiumApp, id: CommandId) -> CommandDescriptor {
),
CommandId::SelectRange => requires(
has_selectable_analysis_trace()
|| afm().is_some_and(|afm| afm.data.forces.is_some())
|| dataset().is_some_and(|dataset| {
dataset.tool_groups().contains(&ToolGroup::MassSpectrometry)
}),
Expand Down Expand Up @@ -443,6 +445,26 @@ pub fn describe(app: &PlotiumApp, id: CommandId) -> CommandDescriptor {
)
}),
CommandId::CurveFit => requires(is_table(), "Select a data table before fitting curves."),
CommandId::AfmFit(command) => super::tools::afm_fit_gate(app, command),
CommandId::FitAfmForce(branch) => requires(
afm().is_some(),
"Select an AFM dataset before fitting a force curve.",
).and_then(|()| {
requires(
afm().is_some_and(|afm| afm.data.forces.is_some()),
"Import an AFM dataset containing force curves.",
)
}).and_then(|()| {
requires(
afm().is_some_and(|afm| afm.force_branch_sample_count(branch) >= 3),
"Select an AFM dataset with at least three samples in this branch.",
)
}).and_then(|()| {
requires(
afm().and_then(|data| app.afm_fit_target(data.resource_id, branch)).is_some(),
"Show an AFM force plot before fitting.",
)
}),
CommandId::RunCurveFit => {
requires(is_table(), "Select a data table before running Curve Fit.").and_then(|()| {
requires(
Expand Down Expand Up @@ -585,6 +607,7 @@ pub fn describe(app: &PlotiumApp, id: CommandId) -> CommandDescriptor {
Applicability::Always => true,
Applicability::LineAlignmentOnly => app.trace_alignment_target().is_some(),
Applicability::TableOnly => is_table(),
Applicability::AfmOnly => afm().is_some(),
Applicability::XasOnly => dataset().and_then(Dataset::as_xas).is_some(),
Applicability::SeriesOnly => is_series(),
Applicability::Homonuclear2dOnly => dataset()
Expand All @@ -607,6 +630,9 @@ pub fn describe(app: &PlotiumApp, id: CommandId) -> CommandDescriptor {
}
}
#[cfg(test)]
#[path = "commands_afm_tests.rs"]
mod afm_tests;
#[cfg(test)]
#[path = "commands_alignment_tests.rs"]
mod alignment_tests;
#[cfg(test)]
Expand Down
24 changes: 23 additions & 1 deletion crates/app/src/ui/commands/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use egui_phosphor::regular as icon;
use plotium_core::actions::ZOrder;
use plotium_core::layout::{Align, Distribute, GutterPreset, SpacingMode};
use plotium_core::properties::PropertyStep;
use plotium_core::state::{PanelLayout, PlotiumApp, Tool};
use plotium_core::state::{AfmForceBranch, PanelLayout, PlotiumApp, Tool};

use super::CommandId;

Expand Down Expand Up @@ -290,7 +290,26 @@ pub(super) fn command_identity(
),
CommandId::RunPeakFit => plain("Run Peak Fit", Some(icon::PLAY)),
CommandId::CurveFit => plain("Fit Curves", Some(icon::FUNCTION)),
CommandId::FitAfmForce(branch) => plain(
match branch {
AfmForceBranch::Approach => "Fit Approach",
AfmForceBranch::Retract => "Fit Retract",
},
Some(icon::FUNCTION),
),
CommandId::RunCurveFit => plain("Run Fit", Some(icon::PLAY)),
CommandId::AfmFit(command) => {
let (label, _, icon) = command.identity();
let checked = (command == super::AfmFitCommand::ToggleOverlay).then(|| {
app.session
.ui
.afm_fit_task
.as_ref()
.and_then(|draft| app.afm_fit_result(draft.target))
.is_some_and(|fit| fit.shown)
});
(label.into(), Some(icon), checked)
}
CommandId::Statistics => plain("Statistics", Some(icon::CHART_BAR)),
CommandId::ChartType => plain("Chart Type…", Some(icon::CHART_SCATTER)),
CommandId::FigureTypography => plain("Figure Typography…", Some(icon::TEXT_AA)),
Expand Down Expand Up @@ -599,7 +618,10 @@ fn simple_stable_id(id: CommandId) -> &'static str {
CommandId::LineFit => "analysis.line_fit",
CommandId::RunPeakFit => "analysis.run_peak_fit",
CommandId::CurveFit => "analysis.curve_fit",
CommandId::FitAfmForce(AfmForceBranch::Approach) => "analysis.afm_fit_approach",
CommandId::FitAfmForce(AfmForceBranch::Retract) => "analysis.afm_fit_retract",
CommandId::RunCurveFit => "analysis.run_curve_fit",
CommandId::AfmFit(command) => command.identity().1,
CommandId::Statistics => "analysis.statistics",
CommandId::ChartType => "figure.chart_type",
CommandId::FigureTypography => "figure.typography",
Expand Down
2 changes: 2 additions & 0 deletions crates/app/src/ui/commands/ribbon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum Applicability {
Always,
LineAlignmentOnly,
TableOnly,
AfmOnly,
XasOnly,
SeriesOnly,
Homonuclear2dOnly,
Expand Down Expand Up @@ -99,6 +100,7 @@ pub(super) fn ribbon_placement(id: CommandId) -> Option<RibbonPlacement> {
Applicability::ToolGroup(ToolGroup::LineFit),
),
CommandId::CurveFit | CommandId::RunCurveFit => (Analyze, "Curve Fit", 0, TableOnly),
CommandId::FitAfmForce(_) => (Analyze, "AFM Force Fit", 0, Applicability::AfmOnly),
CommandId::Statistics => (Analyze, "Statistics", 0, TableOnly),
CommandId::Integrate | CommandId::Multiplets => (
Analyze,
Expand Down
12 changes: 11 additions & 1 deletion crates/app/src/ui/commands/roster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
use plotium_core::export::ExportFormat;
use plotium_core::layout::{Align, Distribute, GutterPreset, SpacingMode};
use plotium_core::properties::PropertyStep;
use plotium_core::state::AfmForceBranch;

use super::helpers::tool_commands;
use super::{CommandId, ZOrder};
use super::{AfmFitCommand, CommandId, ZOrder};

/// The full command roster; only the recent-files arm depends on app state.
pub(super) fn command_ids(recent_files: usize) -> Vec<CommandId> {
Expand Down Expand Up @@ -126,6 +127,15 @@ pub(super) fn command_ids(recent_files: usize) -> Vec<CommandId> {
CommandId::LineFit,
CommandId::RunPeakFit,
CommandId::CurveFit,
CommandId::FitAfmForce(AfmForceBranch::Approach),
CommandId::FitAfmForce(AfmForceBranch::Retract),
CommandId::AfmFit(AfmFitCommand::Run),
CommandId::AfmFit(AfmFitCommand::ToggleOverlay),
CommandId::AfmFit(AfmFitCommand::ZoomRange),
CommandId::AfmFit(AfmFitCommand::Duplicate),
CommandId::AfmFit(AfmFitCommand::ResidualPlot),
CommandId::AfmFit(AfmFitCommand::DataSheet),
CommandId::AfmFit(AfmFitCommand::ShowSource),
CommandId::RunCurveFit,
CommandId::Statistics,
CommandId::ChartType,
Expand Down
52 changes: 52 additions & 0 deletions crates/app/src/ui/commands/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
use super::*;

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AfmFitCommand {
Run,
ToggleOverlay,
ZoomRange,
Duplicate,
ResidualPlot,
DataSheet,
ShowSource,
}

impl AfmFitCommand {
pub(super) const fn identity(self) -> (&'static str, &'static str, &'static str) {
use egui_phosphor::regular as icon;
match self {
Self::Run => ("Run AFM Fit", "analysis.afm_fit_run", icon::PLAY),
Self::ToggleOverlay => (
"Show Fit on Source Plot",
"analysis.afm_fit_overlay",
icon::EYE,
),
Self::ZoomRange => (
"Zoom to Fit Range",
"analysis.afm_fit_zoom",
icon::MAGNIFYING_GLASS_PLUS,
),
Self::Duplicate => (
"Duplicate Plot with Fit",
"analysis.afm_fit_duplicate",
icon::COPY,
),
Self::ResidualPlot => (
"Create Residual Plot",
"analysis.afm_fit_residual",
icon::CHART_LINE,
),
Self::DataSheet => (
"Create Fit Data Sheet",
"analysis.afm_fit_sheet",
icon::TABLE,
),
Self::ShowSource => (
"Show AFM Source Plot",
"analysis.afm_fit_source",
icon::ARROW_LEFT,
),
}
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CommandId {
NewProject,
Expand Down Expand Up @@ -121,6 +171,8 @@ pub enum CommandId {
LineFit,
RunPeakFit,
CurveFit,
FitAfmForce(AfmForceBranch),
AfmFit(AfmFitCommand),
RunCurveFit,
Statistics,
ChartType,
Expand Down
Loading
Loading