mirror of https://codeberg.org/topola/topola.git
overlay: toggle only one node at a time, prioritize active layer
This commit is contained in:
parent
87f5f4e8c0
commit
4c8f7cb804
|
|
@ -5,7 +5,7 @@ use rstar::AABB;
|
|||
|
||||
use crate::{
|
||||
drawing::{
|
||||
graph::{MakePrimitive, PrimitiveIndex},
|
||||
graph::{GetLayer, MakePrimitive, PrimitiveIndex},
|
||||
primitive::MakeShape,
|
||||
rules::RulesTrait,
|
||||
},
|
||||
|
|
@ -16,35 +16,66 @@ use crate::{
|
|||
|
||||
pub struct Overlay {
|
||||
selection: HashSet<Node<PrimitiveIndex, GenericIndex<ZoneWeight>>>,
|
||||
active_layer: u64,
|
||||
}
|
||||
|
||||
impl Overlay {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
selection: HashSet::new(),
|
||||
active_layer: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn click<R: RulesTrait>(&mut self, layout: &Layout<R>, at: Point) {
|
||||
for geom in layout.drawing().rtree().locate_in_envelope_intersecting(
|
||||
&AABB::<[f64; 3]>::from_corners(
|
||||
let geoms: Vec<_> = layout
|
||||
.drawing()
|
||||
.rtree()
|
||||
.locate_in_envelope_intersecting(&AABB::<[f64; 3]>::from_corners(
|
||||
[at.x(), at.y(), -f64::INFINITY],
|
||||
[at.x(), at.y(), f64::INFINITY],
|
||||
),
|
||||
) {
|
||||
match geom.data {
|
||||
Node::Primitive(primitive) => {
|
||||
if primitive
|
||||
.primitive(layout.drawing())
|
||||
.shape()
|
||||
.contains_point(at)
|
||||
{
|
||||
self.toggle_selection(geom.data);
|
||||
}
|
||||
}
|
||||
Node::Compound(compound) => (), // TODO.
|
||||
))
|
||||
.collect();
|
||||
|
||||
if let Some(geom) = geoms.iter().find(|&&geom| match geom.data {
|
||||
Node::Primitive(primitive) => {
|
||||
primitive.primitive(layout.drawing()).layer() == self.active_layer
|
||||
}
|
||||
Node::Compound(compound) => false,
|
||||
}) {
|
||||
if self.toggle_selection_if_contains_point(layout, geom.data, at) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for geom in geoms {
|
||||
if self.toggle_selection_if_contains_point(layout, geom.data, at) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn toggle_selection_if_contains_point<R: RulesTrait>(
|
||||
&mut self,
|
||||
layout: &Layout<R>,
|
||||
node: Node<PrimitiveIndex, GenericIndex<ZoneWeight>>,
|
||||
p: Point,
|
||||
) -> bool {
|
||||
match node {
|
||||
Node::Primitive(primitive) => {
|
||||
if primitive
|
||||
.primitive(layout.drawing())
|
||||
.shape()
|
||||
.contains_point(p)
|
||||
{
|
||||
self.toggle_selection(node);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Node::Compound(compound) => (), // TODO.
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
fn toggle_selection(&mut self, node: Node<PrimitiveIndex, GenericIndex<ZoneWeight>>) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue