Skip to content

Commit

Permalink
feat(groups): store fixture selection in groups (#682)
Browse files Browse the repository at this point in the history
stores blocksize, group count and wings
  • Loading branch information
maxjoehnk authored Aug 7, 2024
1 parent 88653dc commit c15a45a
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 31 deletions.
9 changes: 4 additions & 5 deletions crates/api/src/handlers/programmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl<R: RuntimeApi> ProgrammerHandler<R> {
self.runtime
.run_command(AssignFixturesToGroupCommand {
group_id,
fixture_ids,
selection: fixture_ids.into(),
})
.unwrap();
}
Expand All @@ -207,16 +207,15 @@ impl<R: RuntimeApi> ProgrammerHandler<R> {
#[profiling::function]
pub fn assign_fixture_selection_to_group(&self, group_id: u32) {
let group_id = GroupId(group_id);
let fixture_ids = {
let selection = {
let programmer = self.fixture_manager.get_programmer();
let state = programmer.view().read();
state.all_fixtures()
programmer.active_selection()
};

self.runtime
.run_command(AssignFixturesToGroupCommand {
group_id,
fixture_ids,
selection,
})
.unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion crates/components/fixtures/commands/src/add_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<'a> Command<'a> for AddGroupCommand {
let group = Group {
id: group_id,
name: self.name.clone(),
fixtures: Vec::new(),
selection: Default::default(),
};

Ok((group, group_id))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use mizer_commander::{Command, Ref};
use mizer_fixtures::manager::FixtureManager;
use mizer_fixtures::{FixtureId, GroupId};
use mizer_fixtures::selection::FixtureSelection;
use mizer_fixtures::GroupId;
use serde::{Deserialize, Serialize};
use std::ops::Deref;

#[derive(Debug, Deserialize, Serialize)]
pub struct AssignFixturesToGroupCommand {
pub group_id: GroupId,
pub fixture_ids: Vec<FixtureId>,
pub selection: FixtureSelection,
}

impl<'a> Command<'a> for AssignFixturesToGroupCommand {
type Dependencies = Ref<FixtureManager>;
type State = Vec<FixtureId>;
type State = FixtureSelection;
type Result = ();

fn label(&self) -> String {
Expand All @@ -26,23 +28,22 @@ impl<'a> Command<'a> for AssignFixturesToGroupCommand {
.groups
.get_mut(&self.group_id)
.ok_or_else(|| anyhow::anyhow!("Unknown group {}", self.group_id))?;
let fixture_ids = group.fixtures.clone();
let mut add_ids = self.fixture_ids.clone();
group.fixtures.append(&mut add_ids);
let fixture_ids = group.selection.deref().clone();
group.selection = self.selection.clone().into();

Ok(((), fixture_ids))
}

fn revert(
&self,
fixture_manager: &FixtureManager,
fixture_ids: Self::State,
selection: Self::State,
) -> anyhow::Result<()> {
let mut group = fixture_manager
.groups
.get_mut(&self.group_id)
.ok_or_else(|| anyhow::anyhow!("Unknown group {}", self.group_id))?;
group.fixtures = fixture_ids;
group.selection = selection.into();

Ok(())
}
Expand Down
17 changes: 9 additions & 8 deletions crates/components/fixtures/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl FixtureManager {
let group_id = highest_id.next();
let group = Group {
id: group_id,
fixtures: Vec::new(),
selection: Default::default(),
name,
};
self.groups.insert(group_id, group);
Expand Down Expand Up @@ -341,17 +341,18 @@ impl FixtureManager {
) -> Vec<(FixtureControl, FixtureControlType)> {
if let Some(group) = self.groups.get(&group_id) {
group
.fixtures
.iter()
.fixtures()
.into_iter()
.flatten()
.filter_map(|fixture_id| match fixture_id {
FixtureId::Fixture(fixture_id) => {
let fixture = self.fixtures.get(fixture_id)?;
let fixture = self.fixtures.get(&fixture_id)?;

Some(fixture.current_mode.controls.controls())
}
FixtureId::SubFixture(fixture_id, sub_fixture_id) => {
let fixture = self.fixtures.get(fixture_id)?;
let sub_fixture = fixture.sub_fixture(*sub_fixture_id)?;
let fixture = self.fixtures.get(&fixture_id)?;
let sub_fixture = fixture.sub_fixture(sub_fixture_id)?;

Some(sub_fixture.definition.controls.controls())
}
Expand All @@ -373,8 +374,8 @@ impl FixtureManager {
priority: FixturePriority,
) {
if let Some(group) = self.groups.get(&group_id) {
for fixture_id in &group.fixtures {
self.write_fixture_control(*fixture_id, control.clone(), value, priority);
for fixture_id in group.fixtures().into_iter().flatten() {
self.write_fixture_control(fixture_id, control.clone(), value, priority);
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion crates/components/fixtures/src/programmer/groups.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
use crate::selection::BackwardsCompatibleFixtureSelection;
use crate::{FixtureId, GroupId};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct Group {
pub id: GroupId,
pub name: String,
pub fixtures: Vec<FixtureId>,
#[serde(alias = "fixtures")]
pub selection: BackwardsCompatibleFixtureSelection,
}

impl Group {
pub fn fixtures(&self) -> Vec<Vec<FixtureId>> {
self.selection.get_fixtures()
}
}
12 changes: 9 additions & 3 deletions crates/components/fixtures/src/programmer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ impl Programmer {
}
}

pub fn active_selection(&self) -> FixtureSelection {
self.active_selection.clone()
}

pub fn clear(&mut self) {
if !self.active_selection.is_empty() {
if self.has_written_to_selection {
Expand Down Expand Up @@ -481,14 +485,16 @@ impl Programmer {
}

pub fn select_group(&mut self, group: &Group) {
self.select_fixtures(group.fixtures.clone());
self.active_selection = group.selection.deref().clone();
}

// TODO: this should probably only be true when only the group is selected
// This requires tracking of the active group
pub fn is_group_active(&self, group: &Group) -> bool {
group.fixtures.iter().all(|id| {
group.fixtures().into_iter().flatten().all(|id| {
self.get_selections()
.iter()
.any(|(selection, _)| selection.contains(id))
.any(|(selection, _)| selection.contains(&id))
})
}

Expand Down
4 changes: 1 addition & 3 deletions crates/runtime/pipeline/nodes/fixture/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ impl FixtureController for FixtureManager {
}

fn get_group_fixture_ids(&self, group_id: GroupId) -> Vec<Vec<FixtureId>> {
// TODO: Return 2d fixture selection list
// Because groups are supposed to store fixture selections in the future we return multiple fixture ids at the same position here.
self.get_group(group_id)
.map(|g| g.fixtures.iter().map(|f| vec![*f]).collect::<Vec<_>>())
.map(|g| g.fixtures())
.unwrap_or_default()
}
}
2 changes: 1 addition & 1 deletion crates/ui/lib/panes/programmer/programmer_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class _ProgrammerSheetState extends State<ProgrammerSheet> {
if (group == null) {
return;
}
await programmerApi.assignFixturesToGroup(widget.fixtures.map((e) => e.id).toList(), group);
await programmerApi.assignFixtureSelectionToGroup(group);
}

_storeToPreset() async {
Expand Down
2 changes: 1 addition & 1 deletion crates/ui/lib/panes/selection/selection_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class _SelectionSheetState extends State<SelectionSheet> with SingleTickerProvid
if (group == null) {
return;
}
await programmerApi.assignFixturesToGroup(widget.fixtures.map((e) => e.id).toList(), group);
await programmerApi.assignFixtureSelectionToGroup(group);
}
}

Expand Down

0 comments on commit c15a45a

Please sign in to comment.