@@ -179,6 +179,9 @@ function view(model::ODESystemDesign)
179179 for system in model. systems
180180 add_system (system)
181181 notify (system. xy)
182+ for connector in system. connectors
183+ notify (connector. wall)
184+ end
182185 end
183186
184187 for connection in model. connections
@@ -198,7 +201,6 @@ function view(model::ODESystemDesign)
198201 println (" $plt i=$i " )
199202
200203 if ! isnothing (plt)
201- Main. _x[] = plt
202204
203205 if plt isa Image
204206
@@ -411,79 +413,150 @@ function get_color(system::ODESystem)
411413end
412414
413415
414- function add_system (system:: ODESystemDesign )
416+ function draw_box (system:: ODESystemDesign )
415417
418+ xo = Observable (zeros (5 ))
419+ yo = Observable (zeros (5 ))
420+
421+ on (system. xy) do val
422+ x = val[1 ]
423+ y = val[2 ]
424+ xo[], yo[] = box (x,y)
425+ end
416426
417- xso = Observable ( zeros ( 5 ) )
418- yso = Observable ( zeros ( 5 ))
427+ lines! (ax[], xo, yo; color = system . color )
428+ end
419429
420- xo = Observable (0.0 )
421- yo = Observable (0.0 )
430+ function draw_icon (system:: ODESystemDesign )
422431
423- xro = Observable (zeros (2 ))
424- yro = Observable (zeros (2 ))
432+ xo = Observable (zeros (2 ))
433+ yo = Observable (zeros (2 ))
425434
426435 on (system. xy) do val
427- xs, ys = box (val[1 ], val[2 ])
428- xso[] = xs
429- yso[] = ys
430436
431- xro[] = [ minimum (xs), maximum (xs) ]
432- yro[] = [ minimum (ys), maximum (ys) ]
437+ x = val[ 1 ]
438+ y = val[ 2 ]
433439
434- xo[] = val[1 ]
435- yo[] = val[2 ]
436- end
440+ xo[] = [x - Δh, x + Δh]
441+ yo[] = [y - Δh, y + Δh]
437442
438- lines! (ax[], xso, yso; color = system . color)
443+ end
439444
445+
440446 if ! isnothing (system. icon)
441447 img = load (system. icon)
442- image! (ax[], xro, yro, rotr90 (img))
443- end
448+ image! (ax[], xo, yo, rotr90 (img))
449+ end
450+ end
444451
445- ylabelo = Observable (0.0 )
446- on (yo) do val
447- ylabelo[] = val - 0.1
448- end
452+ function draw_label (system:: ODESystemDesign )
453+
454+ xo = Observable (0.0 )
455+ yo = Observable (0.0 )
456+
457+ on (system. xy) do val
458+
459+ x = val[1 ]
460+ y = val[2 ]
449461
450- text! (ax[], xo, ylabelo; text= string (system. system. name), align= (:center , :bottom ))
462+ xo[] = x
463+ yo[] = y - 0.1
451464
452- draw_connector_nodes = () -> begin
453- wall (y) = filter (x-> get_wall (x) == y, system. connectors)
465+ end
454466
455- # walls = [ModelingToolkitComponents.N, ModelingToolkitComponents.S, ModelingToolkitComponents.E, ModelingToolkitComponents.W]
456- for w in [ :N , :S , :E , :W ]
467+ text! (ax[], xo, yo; text = string (system . system . name), align = ( :center , :bottom ))
468+ end
457469
470+ function draw_nodes (system:: ODESystemDesign )
471+
472+ for connector in system. connectors
458473
459- connectors_on_wall = wall (w)
474+ on (connector. wall) do val
475+ println (" updating node: $(system. system. name) $(connector. system. name) " )
476+ connectors_on_wall = filter (x-> x. wall[] == val, system. connectors)
460477
461478 n_items = length (connectors_on_wall)
462479 delta = 2 * Δh/ (n_items+ 1 )
463480
464- # TODO : Order by item.node_order
465-
466481 for i= 1 : n_items
467-
468- draw_connector_node (connectors_on_wall[i], delta, i, w)
469-
482+ x,y = get_node_position (val, delta, i)
483+ connectors_on_wall[i]. xy[] = (x,y)
470484 end
485+ end
471486
487+ draw_node (connector)
488+ draw_node_label (connector)
489+ end
490+
491+ end
492+
493+ function draw_node (connector:: ODESystemDesign )
494+ xo = Observable (0.0 )
495+ yo = Observable (0.0 )
496+
497+ on (connector. xy) do val
498+
499+ x = val[1 ]
500+ y = val[2 ]
501+
502+ xo[] = x
503+ yo[] = y
472504
473- end
474505 end
475506
476- draw_connector_nodes ()
507+ scatter! (ax[], xo, yo; marker= :rect , color = connector. color, markersize= 15 )
508+ end
477509
478- for connector in system. connectors
479- on (connector. wall) do val
480- draw_connector_nodes ()
481- end
510+ function draw_node_label (connector:: ODESystemDesign )
511+ xo = Observable (0.0 )
512+ yo = Observable (0.0 )
513+ alignment = Observable ((:left , :top ))
514+
515+ on (connector. xy) do val
516+
517+ x = val[1 ]
518+ y = val[2 ]
519+
520+ xt, yt = get_node_label_position (connector. wall[], x, y)
521+
522+ xo[] = xt
523+ yo[] = yt
524+
525+ alignment[] = get_text_alignment (connector. wall[])
482526 end
483527
528+ text! (ax[], xo, yo; text= string (connector. system. name), color = connector. color, align= alignment, fontsize= 10 )
529+ end
530+
531+ get_node_position (w:: Symbol , delta, i) = get_node_position (Val (w), delta, i)
532+ get_node_label_position (w:: Symbol , x, y) = get_node_label_position (Val (w), x, y)
533+
534+ get_node_position (:: Val{:N} , delta, i) = (delta* i - Δh, + Δh)
535+ get_node_label_position (:: Val{:N} , x, y) = (x, y* 0.6 )
536+
537+ get_node_position (:: Val{:S} , delta, i) = (delta* i - Δh, - Δh)
538+ get_node_label_position (:: Val{:S} , x, y) = (x, y* 0.6 )
539+
540+ get_node_position (:: Val{:E} , delta, i) = (+ Δh, delta* i - Δh)
541+ get_node_label_position (:: Val{:E} , x, y) = (x* 1.4 , y)
542+
543+ get_node_position (:: Val{:W} , delta, i) = (- Δh, delta* i - Δh)
544+ get_node_label_position (:: Val{:W} , x, y) = (x* 1.4 , y)
545+
546+
547+
548+
549+
550+ function add_system (system:: ODESystemDesign )
551+
552+ draw_box (system)
553+ draw_icon (system)
554+ draw_label (system)
555+ draw_nodes (system)
556+
484557end
485558
486- function draw_connector_node (connector:: ODESystemDesign , delta, i, w)
559+ function draw_node (connector:: ODESystemDesign , delta, i, w, xo, yo )
487560 if w == :N
488561 x = delta* i - Δh
489562 xt = x
0 commit comments