@@ -18,7 +18,6 @@ use crate::{
1818 config:: CanvasConfig ,
1919 connection_manager:: { Connection , ConnectionManager } ,
2020 drag:: Drag ,
21- module:: Module ,
2221} ;
2322
2423pub const PANEL_BUTTON_MAX_HEIGHT : f32 = 50.0 ;
@@ -538,10 +537,7 @@ impl App {
538537 InstanceKind :: Wire => self . db . circuit . new_wire ( Wire :: new_at ( pos) ) ,
539538 InstanceKind :: Lamp => self . db . circuit . new_lamp ( Lamp { pos } ) ,
540539 InstanceKind :: Clock => self . db . circuit . new_clock ( Clock { pos } ) ,
541- InstanceKind :: Module ( c) => self . db . new_module_with_flattening ( Module {
542- pos,
543- definition_index : c,
544- } ) ,
540+ InstanceKind :: Module ( c) => self . db . new_module ( c, pos) ,
545541 } ;
546542 self . set_drag ( Drag :: Canvas ( crate :: drag:: CanvasDrag :: Single {
547543 id,
@@ -556,7 +552,7 @@ impl App {
556552 {
557553 let mut ids = Vec :: new ( ) ;
558554 for ( id, m) in & self . circuit ( ) . modules {
559- if m. definition_index == i {
555+ if m. definition_id == i {
560556 ids. push ( id) ;
561557 }
562558 }
@@ -1077,18 +1073,19 @@ impl App {
10771073 fn draw_module ( & mut self , ui : & mut Ui , id : InstanceId ) {
10781074 let ( pos, definition_index) = {
10791075 let module = self . db . circuit . get_module ( id) ;
1080- ( module. pos , module. definition_index )
1076+ ( module. pos , module. definition_id )
10811077 } ;
10821078 let screen_center = pos - self . viewport_offset ;
10831079
10841080 let ( name, pins, pin_offsets) = {
10851081 let definition = self . db . circuit . get_module ( id) . definition ( & self . db ) ;
10861082 let name = definition. name . clone ( ) ;
1087- let pins = definition. get_unconnected_pins ( & self . db , id) ;
1088-
1083+ let pins = self . db . circuit . get_module ( id) . pins ( ) ;
10891084 let pin_offsets: Vec < Vec2 > = pins
10901085 . iter ( )
1091- . map ( |pin| definition. calculate_pin_offset ( & self . db , pin, & self . canvas_config ) )
1086+ . map ( |pin| {
1087+ definition. calculate_pin_offset ( & self . db , & pins, pin, & self . canvas_config )
1088+ } )
10921089 . collect ( ) ;
10931090
10941091 ( name, pins, pin_offsets)
@@ -1128,7 +1125,7 @@ impl App {
11281125 } ) ) ;
11291126 }
11301127
1131- for ( pin_index , ( & pin, & pin_offset) ) in pins. iter ( ) . zip ( pin_offsets. iter ( ) ) . enumerate ( ) {
1128+ for ( & pin, & pin_offset) in pins. iter ( ) . zip ( pin_offsets. iter ( ) ) {
11321129 let pin_pos_world = pos + pin_offset;
11331130 let pin_screen_pos = self . adjusted_pos ( pin_pos_world) ;
11341131
@@ -1140,7 +1137,7 @@ impl App {
11401137 ui. painter ( )
11411138 . circle_filled ( pin_screen_pos, self . canvas_config . base_pin_size , pin_color) ;
11421139
1143- let has_current = self . is_on ( Pin :: new ( id , pin_index as u32 , pin. kind ) ) ;
1140+ let has_current = self . is_on ( pin) ;
11441141
11451142 if has_current {
11461143 ui. painter ( ) . circle_stroke (
@@ -1155,15 +1152,12 @@ impl App {
11551152 Vec2 :: splat ( self . canvas_config . base_pin_size + PIN_HOVER_THRESHOLD ) ,
11561153 ) ;
11571154 let pin_resp = ui. allocate_rect ( pin_rect, Sense :: drag ( ) ) ;
1158- let pin_obj = Pin :: new ( id, pin_index as u32 , pin. kind ) ;
11591155 if pin_resp. hovered ( ) {
1160- self . hovered = Some ( Hover :: Pin ( pin_obj ) ) ;
1156+ self . hovered = Some ( Hover :: Pin ( pin ) ) ;
11611157 }
11621158 if pin_resp. dragged ( ) {
11631159 self . selected . clear ( ) ;
1164- self . set_drag ( Drag :: PinToWire {
1165- source_pin : pin_obj,
1166- } ) ;
1160+ self . set_drag ( Drag :: PinToWire { source_pin : pin } ) ;
11671161 }
11681162 }
11691163 }
@@ -1551,30 +1545,31 @@ impl App {
15511545
15521546 fn debug_string ( & self , ui : & Ui ) -> String {
15531547 let mut out = String :: new ( ) ;
1548+
1549+ // App state (compact)
1550+ writeln ! ( out, "======================================" ) . ok ( ) ;
1551+ writeln ! ( out, " APP STATE" ) . ok ( ) ;
1552+ writeln ! ( out, "======================================" ) . ok ( ) ;
15541553 let mouse_pos_world = self . mouse_pos_world ( ui) ;
15551554 writeln ! ( out, "mouse: {mouse_pos_world:?}" ) . ok ( ) ;
1556-
15571555 writeln ! ( out, "hovered: {:?}" , self . hovered) . ok ( ) ;
15581556 writeln ! ( out, "drag: {:?}" , self . drag) . ok ( ) ;
1559- writeln ! ( out, "viewport_offset: {:?}" , self . viewport_offset) . ok ( ) ;
1560- writeln ! ( out, "potential_conns: {}" , self . potential_connections. len( ) ) . ok ( ) ;
1561- writeln ! ( out, "clipboard: {:?}" , self . clipboard) . ok ( ) ;
15621557 writeln ! ( out, "selected: {:?}" , self . selected) . ok ( ) ;
1563- writeln ! ( out, "editing_label: {:?}" , self . editing_label) . ok ( ) ;
1564- writeln ! ( out, "label_edit_buffer: {}" , self . label_edit_buffer) . ok ( ) ;
15651558 writeln ! ( out, "viewing_module: {:?}" , self . viewing_module) . ok ( ) ;
15661559
15671560 // Simulation status
1568- writeln ! ( out, "\n === Simulation Status ===" ) . ok ( ) ;
1569- writeln ! ( out, "needs update {}" , self . current_dirty) . ok ( ) ;
1561+ writeln ! ( out) . ok ( ) ;
1562+ writeln ! ( out, "======================================" ) . ok ( ) ;
1563+ writeln ! ( out, " SIMULATION" ) . ok ( ) ;
1564+ writeln ! ( out, "======================================" ) . ok ( ) ;
15701565 match self . simulator . status {
15711566 SimulationStatus :: Stable { iterations } => {
1572- writeln ! ( out, "Status: STABLE (after {iterations} iterations )" ) . ok ( ) ;
1567+ writeln ! ( out, "Status: STABLE ({iterations} iters )" ) . ok ( ) ;
15731568 }
15741569 SimulationStatus :: Unstable { max_reached } => {
15751570 if max_reached {
15761571 let iters = self . simulator . last_iterations ;
1577- writeln ! ( out, "Status: UNSTABLE (max iterations : {iters})" ) . ok ( ) ;
1572+ writeln ! ( out, "Status: UNSTABLE (max: {iters})" ) . ok ( ) ;
15781573 } else {
15791574 writeln ! ( out, "Status: UNSTABLE" ) . ok ( ) ;
15801575 }
@@ -1583,44 +1578,31 @@ impl App {
15831578 writeln ! ( out, "Status: RUNNING..." ) . ok ( ) ;
15841579 }
15851580 }
1586- let iters = self . simulator . last_iterations ;
1587- writeln ! ( out, "Iterations: {iters}" ) . ok ( ) ;
1588-
1589- // Clock controller state
1590- writeln ! ( out, "\n --- Clock Controller ---" ) . ok ( ) ;
1591- writeln ! ( out, "State: {:?}" , self . clock_controller. state) . ok ( ) ;
15921581 writeln ! (
15931582 out,
1594- "Tick interval: {:.2}s" ,
1595- self . clock_controller. tick_interval
1583+ "Clock: {:?}, interval: {:.2}s" ,
1584+ self . clock_controller. state , self . clock_controller . tick_interval
15961585 )
15971586 . ok ( ) ;
1598- writeln ! ( out, "Voltage: {}" , self . clock_controller. voltage) . ok ( ) ;
15991587
1600- if self . potential_connections . is_empty ( ) {
1601- writeln ! ( out, "\n Potential Connections: none" ) . ok ( ) ;
1602- } else {
1603- writeln ! ( out, "\n Potential Connections:" ) . ok ( ) ;
1604- for c in & self . potential_connections {
1605- writeln ! ( out, " {}" , c. display( self . circuit( ) ) ) . ok ( ) ;
1606- }
1607- }
1608-
1609- writeln ! ( out, "\n {}" , self . connection_manager. debug_info( ) ) . ok ( ) ;
1610-
1611- writeln ! ( out, "\n " ) . ok ( ) ;
1612-
1613- out. write_str ( & self . circuit ( ) . display ( & self . db ) ) . ok ( ) ;
1588+ // Circuit instances (main content)
1589+ writeln ! ( out) . ok ( ) ;
1590+ out. write_str ( & self . circuit ( ) . display ( & self . db , Some ( & self . simulator ) ) )
1591+ . ok ( ) ;
16141592
1593+ // Module definitions (at the bottom, summary only)
16151594 if !self . db . module_definitions . is_empty ( ) {
1616- writeln ! ( out, "\n Module Def:" ) . ok ( ) ;
1617- let mut iter = self . db . module_definitions . iter ( ) ;
1618- if let Some ( ( id, first) ) = iter. next ( ) {
1619- writeln ! ( out, " {}" , first. display_definition( & self . db, id) ) . ok ( ) ;
1620- }
1621- for ( id, m) in iter {
1622- writeln ! ( out) . ok ( ) ;
1623- writeln ! ( out, " {}" , m. display_definition( & self . db, id) ) . ok ( ) ;
1595+ writeln ! ( out) . ok ( ) ;
1596+ writeln ! ( out, "======================================" ) . ok ( ) ;
1597+ writeln ! (
1598+ out,
1599+ " MODULE DEFINITIONS ({} total)" ,
1600+ self . db. module_definitions. len( )
1601+ )
1602+ . ok ( ) ;
1603+ writeln ! ( out, "======================================" ) . ok ( ) ;
1604+ for ( id, m) in & self . db . module_definitions {
1605+ writeln ! ( out, "{}" , m. display_definition( & self . db, id) ) . ok ( ) ;
16241606 }
16251607 }
16261608
@@ -1691,7 +1673,7 @@ impl App {
16911673 }
16921674 InstanceKind :: Module ( _) => {
16931675 let cc = self . db . circuit . get_module ( id) ;
1694- object_pos. push ( ClipBoardItem :: Module ( cc. definition_index , center - cc. pos ) ) ;
1676+ object_pos. push ( ClipBoardItem :: Module ( cc. definition_id , center - cc. pos ) ) ;
16951677 }
16961678 }
16971679 }
@@ -1742,12 +1724,13 @@ impl App {
17421724 self . selected . insert ( id) ;
17431725 }
17441726 ClipBoardItem :: Module ( def_index, offset) => {
1745- let id = self . db . new_module_with_flattening ( Module {
1746- pos : mouse - offset,
1747- definition_index : def_index,
1748- } ) ;
1749- self . connection_manager . mark_instance_dirty ( id) ;
1750- self . selected . insert ( id) ;
1727+ // TODO: Modules
1728+ // let id = self.db.new_module_with_flattening(Module {
1729+ // pos: mouse - offset,
1730+ // definition_index: def_index,
1731+ // });
1732+ // self.connection_manager.mark_instance_dirty(id);
1733+ // self.selected.insert(id);
17511734 }
17521735 ClipBoardItem :: Lamp ( offset) => {
17531736 let id = self . db . circuit . new_lamp ( Lamp {
0 commit comments