Fixes problem with bool shapes

This commit is contained in:
alonso.torres 2022-11-17 09:18:51 +01:00
parent 32756db1c1
commit afa6a97693
7 changed files with 54 additions and 33 deletions

View file

@ -160,6 +160,7 @@
(dm/export gpr/join-selrects) (dm/export gpr/join-selrects)
(dm/export gpr/contains-selrect?) (dm/export gpr/contains-selrect?)
(dm/export gpr/contains-point?) (dm/export gpr/contains-point?)
(dm/export gpr/close-selrect?)
(dm/export gtr/move) (dm/export gtr/move)
(dm/export gtr/absolute-move) (dm/export gtr/absolute-move)
@ -170,6 +171,7 @@
(dm/export gtr/calculate-adjust-matrix) (dm/export gtr/calculate-adjust-matrix)
(dm/export gtr/update-group-selrect) (dm/export gtr/update-group-selrect)
(dm/export gtr/update-mask-selrect) (dm/export gtr/update-mask-selrect)
(dm/export gtr/update-bool-selrect)
(dm/export gtr/transform-shape) (dm/export gtr/transform-shape)
(dm/export gtr/transform-selrect) (dm/export gtr/transform-selrect)
(dm/export gtr/transform-selrect-matrix) (dm/export gtr/transform-selrect-matrix)
@ -194,7 +196,7 @@
(dm/export gin/rect-contains-shape?) (dm/export gin/rect-contains-shape?)
;; Bool ;; Bool
(dm/export gsb/update-bool-selrect)
(dm/export gsb/calc-bool-content) (dm/export gsb/calc-bool-content)
;; Constraints ;; Constraints

View file

@ -7,8 +7,6 @@
(ns app.common.geom.shapes.bool (ns app.common.geom.shapes.bool
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.shapes.path :as gsp]
[app.common.geom.shapes.transforms :as gtr]
[app.common.path.bool :as pb] [app.common.path.bool :as pb]
[app.common.path.shapes-to-path :as stp])) [app.common.path.shapes-to-path :as stp]))
@ -25,17 +23,5 @@
(into [] extract-content-xf (:shapes shape))] (into [] extract-content-xf (:shapes shape))]
(pb/content-bool (:bool-type shape) shapes-content))) (pb/content-bool (:bool-type shape) shapes-content)))
(defn update-bool-selrect
"Calculates the selrect+points for the boolean shape"
[shape children objects]
(let [bool-content (calc-bool-content shape objects)
shape (assoc shape :bool-content bool-content)
[points selrect] (gsp/content->points+selrect shape bool-content)]
(if (and (some? selrect) (d/not-empty? points))
(-> shape
(assoc :selrect selrect)
(assoc :points points))
(gtr/update-group-selrect shape children))))

View file

@ -133,13 +133,17 @@
[modif-tree objects parent] [modif-tree objects parent]
(letfn [(apply-modifiers [modif-tree child] (letfn [(apply-modifiers [modif-tree child]
(let [modifiers (dm/get-in modif-tree [(:id child) :modifiers])] (let [modifiers (-> (dm/get-in modif-tree [(:id child) :modifiers])
(cond-> child (ctm/select-geometry))]
(and (not (cph/group-shape? child)) (some? modifiers)) (cond
(gtr/transform-shape modifiers) (cph/group-like-shape? child)
(gtr/apply-group-modifiers child objects modif-tree)
(cph/group-shape? child) (some? modifiers)
(gtr/apply-group-modifiers objects modif-tree)))) (gtr/transform-shape child modifiers)
:else
child)))
(set-child-modifiers [parent [layout-line modif-tree] child] (set-child-modifiers [parent [layout-line modif-tree] child]
(let [[modifiers layout-line] (let [[modifiers layout-line]
@ -208,7 +212,8 @@
[objects ignore-constraints [modif-tree autolayouts] parent] [objects ignore-constraints [modif-tree autolayouts] parent]
(let [parent-id (:id parent) (let [parent-id (:id parent)
root? (= uuid/zero parent-id) root? (= uuid/zero parent-id)
modifiers (dm/get-in modif-tree [parent-id :modifiers]) modifiers (-> (dm/get-in modif-tree [parent-id :modifiers])
(ctm/select-geometry))
transformed-parent (gtr/transform-shape parent modifiers) transformed-parent (gtr/transform-shape parent modifiers)
has-modifiers? (ctm/child-modifiers? modifiers) has-modifiers? (ctm/child-modifiers? modifiers)
@ -233,10 +238,9 @@
(defn- apply-structure-modifiers (defn- apply-structure-modifiers
[objects modif-tree] [objects modif-tree]
(letfn [(apply-shape [objects [id {:keys [modifiers]}]] (letfn [(apply-shape [objects [id {:keys [modifiers]}]]
(if (ctm/has-structure? modifiers) (cond-> objects
(let [shape (get objects id)] (ctm/has-structure? modifiers)
(update objects id ctm/apply-structure-modifiers modifiers)) (update id ctm/apply-structure-modifiers modifiers)))]
objects))]
(reduce apply-shape objects modif-tree))) (reduce apply-shape objects modif-tree)))
(defn- apply-partial-objects-modifiers (defn- apply-partial-objects-modifiers

View file

@ -10,6 +10,7 @@
[app.common.data.macros :as dm] [app.common.data.macros :as dm]
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes.bool :as gshb]
[app.common.geom.shapes.common :as gco] [app.common.geom.shapes.common :as gco]
[app.common.geom.shapes.path :as gpa] [app.common.geom.shapes.path :as gpa]
[app.common.geom.shapes.rect :as gpr] [app.common.geom.shapes.rect :as gpr]
@ -408,6 +409,20 @@
(assoc :flip-x (-> mask :flip-x)) (assoc :flip-x (-> mask :flip-x))
(assoc :flip-y (-> mask :flip-y))))) (assoc :flip-y (-> mask :flip-y)))))
(defn update-bool-selrect
"Calculates the selrect+points for the boolean shape"
[shape children objects]
(let [bool-content (gshb/calc-bool-content shape objects)
shape (assoc shape :bool-content bool-content)
[points selrect] (gpa/content->points+selrect shape bool-content)]
(if (and (some? selrect) (d/not-empty? points))
(-> shape
(assoc :selrect selrect)
(assoc :points points))
(update-group-selrect shape children))))
(defn transform-shape (defn transform-shape
([shape] ([shape]
(let [modifiers (:modifiers shape)] (let [modifiers (:modifiers shape)]
@ -513,6 +528,9 @@
(cph/mask-shape? group) (cph/mask-shape? group)
(update-mask-selrect group children) (update-mask-selrect group children)
(cph/bool-shape? group)
(transform-shape group modifiers)
(cph/group-shape? group) (cph/group-shape? group)
(update-group-selrect group children) (update-group-selrect group children)

View file

@ -11,7 +11,6 @@
[app.common.data.macros :as dm] [app.common.data.macros :as dm]
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.geom.shapes.bool :as gshb]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages.common :refer [component-sync-attrs]] [app.common.pages.common :refer [component-sync-attrs]]
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
@ -170,7 +169,7 @@
group group
(= :bool (:type group)) (= :bool (:type group))
(gshb/update-bool-selrect group children objects) (gsh/update-bool-selrect group children objects)
(:masked-group? group) (:masked-group? group)
(set-mask-selrect group children) (set-mask-selrect group children)

View file

@ -12,8 +12,6 @@
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.geom.shapes.bool :as gshb]
[app.common.geom.shapes.rect :as gshr]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
@ -419,7 +417,7 @@
(every? #(apply gpt/close? %) (d/zip old-val new-val)) (every? #(apply gpt/close? %) (d/zip old-val new-val))
(= attr :selrect) (= attr :selrect)
(gshr/close-selrect? old-val new-val) (gsh/close-selrect? old-val new-val)
:else :else
(= old-val new-val))] (= old-val new-val))]
@ -438,7 +436,7 @@
nil ;; so it does not need resize nil ;; so it does not need resize
(= (:type parent) :bool) (= (:type parent) :bool)
(gshb/update-bool-selrect parent children objects) (gsh/update-bool-selrect parent children objects)
(= (:type parent) :group) (= (:type parent) :group)
(if (:masked-group? parent) (if (:masked-group? parent)

View file

@ -150,6 +150,19 @@
child-set (set (get-in objects [target-frame :shapes])) child-set (set (get-in objects [target-frame :shapes]))
layout? (ctl/layout? objects target-frame) layout? (ctl/layout? objects target-frame)
set-parent-ids
(fn [modif-tree shapes target-frame]
(reduce
(fn [modif-tree id]
(update-in
modif-tree
[id :modifiers]
#(-> %
(ctm/change-property :frame-id target-frame)
(ctm/change-property :parent-id target-frame))))
modif-tree
shapes))
update-frame-modifiers update-frame-modifiers
(fn [modif-tree [original-frame shapes]] (fn [modif-tree [original-frame shapes]]
(let [shapes (->> shapes (d/removev #(= target-frame %))) (let [shapes (->> shapes (d/removev #(= target-frame %)))
@ -160,7 +173,8 @@
(cond-> modif-tree (cond-> modif-tree
(not= original-frame target-frame) (not= original-frame target-frame)
(-> (update-in [original-frame :modifiers] ctm/remove-children shapes) (-> (update-in [original-frame :modifiers] ctm/remove-children shapes)
(update-in [target-frame :modifiers] ctm/add-children shapes drop-index)) (update-in [target-frame :modifiers] ctm/add-children shapes drop-index)
(set-parent-ids shapes target-frame))
(and layout? (= original-frame target-frame)) (and layout? (= original-frame target-frame))
(update-in [target-frame :modifiers] ctm/add-children shapes drop-index))))] (update-in [target-frame :modifiers] ctm/add-children shapes drop-index))))]