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::{
|
use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
graph::{MakePrimitive, PrimitiveIndex},
|
graph::{GetLayer, MakePrimitive, PrimitiveIndex},
|
||||||
primitive::MakeShape,
|
primitive::MakeShape,
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
},
|
},
|
||||||
|
|
@ -16,35 +16,66 @@ use crate::{
|
||||||
|
|
||||||
pub struct Overlay {
|
pub struct Overlay {
|
||||||
selection: HashSet<Node<PrimitiveIndex, GenericIndex<ZoneWeight>>>,
|
selection: HashSet<Node<PrimitiveIndex, GenericIndex<ZoneWeight>>>,
|
||||||
|
active_layer: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Overlay {
|
impl Overlay {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
selection: HashSet::new(),
|
selection: HashSet::new(),
|
||||||
|
active_layer: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn click<R: RulesTrait>(&mut self, layout: &Layout<R>, at: Point) {
|
pub fn click<R: RulesTrait>(&mut self, layout: &Layout<R>, at: Point) {
|
||||||
for geom in layout.drawing().rtree().locate_in_envelope_intersecting(
|
let geoms: Vec<_> = layout
|
||||||
&AABB::<[f64; 3]>::from_corners(
|
.drawing()
|
||||||
|
.rtree()
|
||||||
|
.locate_in_envelope_intersecting(&AABB::<[f64; 3]>::from_corners(
|
||||||
[at.x(), at.y(), -f64::INFINITY],
|
[at.x(), at.y(), -f64::INFINITY],
|
||||||
[at.x(), at.y(), f64::INFINITY],
|
[at.x(), at.y(), f64::INFINITY],
|
||||||
),
|
))
|
||||||
) {
|
.collect();
|
||||||
match geom.data {
|
|
||||||
Node::Primitive(primitive) => {
|
if let Some(geom) = geoms.iter().find(|&&geom| match geom.data {
|
||||||
if primitive
|
Node::Primitive(primitive) => {
|
||||||
.primitive(layout.drawing())
|
primitive.primitive(layout.drawing()).layer() == self.active_layer
|
||||||
.shape()
|
}
|
||||||
.contains_point(at)
|
Node::Compound(compound) => false,
|
||||||
{
|
}) {
|
||||||
self.toggle_selection(geom.data);
|
if self.toggle_selection_if_contains_point(layout, geom.data, at) {
|
||||||
}
|
return;
|
||||||
}
|
|
||||||
Node::Compound(compound) => (), // TODO.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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>>) {
|
fn toggle_selection(&mut self, node: Node<PrimitiveIndex, GenericIndex<ZoneWeight>>) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue