@@ -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
10381120get_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
10411143get_node_position (w:: Symbol , delta, i) =  get_node_position (Val (w), delta, i)
10421144get_node_label_position (w:: Symbol , x, y) =  get_node_label_position (Val (w), x, y)
0 commit comments