Skip to content

Commit 9925e5b

Browse files
author
Brad Carman
committed
fixed
1 parent c5f0264 commit 9925e5b

File tree

5 files changed

+224
-10
lines changed

5 files changed

+224
-10
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ModelingToolkitDesigner"
22
uuid = "23d639d0-9462-4d1e-84fe-d700424865b8"
33
authors = ["Brad Carman <[email protected]>"]
4-
version = "0.2.0"
4+
version = "0.3.0"
55

66
[deps]
77
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ The ModelingToolkitDesigner.jl package is a helper tool for visualizing and edit
44

55
# Updates
66
## v0.3.0
7+
- Connector nodes are now correctly positioned around the component with natural ordering
8+
9+
![moving](https://user-images.githubusercontent.com/40798837/242108325-0736b264-5374-4b63-8823-589c0e447de7.gif)
10+
11+
12+
## v0.2.0
713
- Settings Files (*.toml) Updates/Breaking Changes
814
- icon rotation now saved with key `r`, previously was `wall` which was not the best name
915
- connectors nodes now saved with an underscore: `_name`, this helps prevent a collision with nodes named `x`, `y`, or `r`
3.89 KB
Loading
Lines changed: 106 additions & 0 deletions
Loading

src/ModelingToolkitDesigner.jl

Lines changed: 111 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,21 @@ function ODESystemDesign(
153153
kwargs...,
154154
)
155155

156+
for wall in [:E, :W, :N, :S]
157+
connectors_on_wall = filter(x -> get_wall(x) == wall, connectors)
158+
n = length(connectors_on_wall)
159+
if n > 1
160+
i = 0
161+
for conn in connectors_on_wall
162+
order = get_wall_order(conn)
163+
i = max(i, order) + 1
164+
if order == 0
165+
conn.wall[] = Symbol(wall, i)
166+
end
167+
end
168+
end
169+
end
170+
156171

157172
for eq in equations(system)
158173

@@ -586,16 +601,83 @@ function view(design::ODESystemDesign, interactive = true)
586601
on(next_wall_button.clicks) do clicks
587602
for component in design.components
588603
for connector in component.connectors
604+
605+
589606
if connector.color[] == :pink
590-
if get_wall(connector) == :N
591-
connector.wall[] = :E
592-
elseif get_wall(connector) == :W
593-
connector.wall[] = :N
594-
elseif get_wall(connector) == :S
595-
connector.wall[] = :W
596-
elseif get_wall(connector) == :E
597-
connector.wall[] = :S
598-
end
607+
608+
current_wall = get_wall(connector)
609+
current_order = get_wall_order(connector)
610+
611+
612+
613+
if current_order > 1
614+
connectors_on_wall = filter(x -> get_wall(x) == current_wall, component.connectors)
615+
for cow in connectors_on_wall
616+
617+
order = max(get_wall_order(cow), 1)
618+
619+
if order == current_order - 1
620+
cow.wall[] = Symbol(current_wall, current_order)
621+
end
622+
623+
if order == current_order
624+
cow.wall[] = Symbol(current_wall, current_order - 1)
625+
end
626+
end
627+
628+
else
629+
630+
next_wall = if current_wall == :N
631+
:E
632+
elseif current_wall == :W
633+
:N
634+
elseif current_wall == :S
635+
:W
636+
elseif current_wall == :E
637+
:S
638+
end
639+
640+
connectors_on_wall = filter(x -> get_wall(x) == next_wall, component.connectors)
641+
642+
# connector is added to wall, need to fix any un-ordered connectors
643+
for cow in connectors_on_wall
644+
order = get_wall_order(cow)
645+
646+
if order == 0
647+
cow.wall[] = Symbol(next_wall, 1)
648+
end
649+
end
650+
651+
652+
current_order = length(connectors_on_wall) + 1
653+
if current_order > 1
654+
connector.wall[] = Symbol(next_wall, current_order)
655+
else
656+
connector.wall[] = next_wall
657+
end
658+
659+
660+
661+
662+
# connector is leaving wall, need to reduce the order
663+
connectors_on_wall = filter(x -> get_wall(x) == current_wall, component.connectors)
664+
if length(connectors_on_wall) > 1
665+
for cow in connectors_on_wall
666+
order = get_wall_order(cow)
667+
668+
if order == 0
669+
cow.wall[] = Symbol(current_wall, 1)
670+
else
671+
cow.wall[] = Symbol(current_wall, order - 1)
672+
end
673+
end
674+
else
675+
for cow in connectors_on_wall
676+
cow.wall[] = current_wall
677+
end
678+
end
679+
680+
end
599681
end
600682
end
601683
end
@@ -1037,6 +1119,26 @@ end
10371119

10381120
get_wall(design::ODESystemDesign) = Symbol(string(design.wall[])[1])
10391121

1122+
function get_wall_order(design::ODESystemDesign)
1123+
1124+
wall = string(design.wall[])
1125+
if length(wall) > 1
1126+
order = tryparse(Int, wall[2:end])
1127+
1128+
if isnothing(order)
1129+
order = 1
1130+
end
1131+
1132+
return order
1133+
else
1134+
1135+
1136+
return 0
1137+
1138+
end
1139+
1140+
1141+
end
10401142

10411143
get_node_position(w::Symbol, delta, i) = get_node_position(Val(w), delta, i)
10421144
get_node_label_position(w::Symbol, x, y) = get_node_label_position(Val(w), x, y)

0 commit comments

Comments
 (0)