12 #include "xincludes.h"
23 #include "crosshair.h"
26 #include "../hidint.h"
29 #ifdef HAVE_LIBDMALLOC
37 #define stdarg(t,v) XtSetArg(args[n], t, v); n++
39 static Widget netlist_dialog
= 0;
40 static Widget netlist_list
, netnode_list
;
42 static XmString
*netlist_strings
= 0;
43 static XmString
*netnode_strings
= 0;
44 static int last_pick
= -1;
46 static int NetlistChanged (int argc
, char **argv
, int x
, int y
);
51 LibraryMenuType
*menu
= PCB
->NetlistLib
.Menu
+ pick
;
54 if (pick
== last_pick
)
59 free (netnode_strings
);
60 netnode_strings
= (XmString
*) malloc (menu
->EntryN
* sizeof (XmString
));
61 for (i
= 0; i
< menu
->EntryN
; i
++)
62 netnode_strings
[i
] = XmStringCreateLocalized (menu
->Entry
[i
].ListEntry
);
64 stdarg (XmNitems
, netnode_strings
);
65 stdarg (XmNitemCount
, menu
->EntryN
);
66 XtSetValues (netnode_list
, args
, n
);
70 netlist_select (Widget w
, void *v
, XmListCallbackStruct
* cbs
)
73 int pos
= cbs
->item_position
;
74 LibraryMenuTypePtr net
= & (PCB
->NetlistLib
.Menu
[pos
- 1]);
75 char *name
= net
->Name
;
87 str
= XmStringCreateLocalized (name
);
88 XmListReplaceItemsPos (netlist_list
, &str
, 1, pos
);
90 XmListSelectPos (netlist_list
, pos
, False
);
94 netlist_extend (Widget w
, void *v
, XmListCallbackStruct
* cbs
)
96 if (cbs
->selected_item_count
== 1)
97 pick_net (cbs
->item_position
- 1);
100 typedef void (*Std_Nbcb_Func
)(LibraryMenuTypePtr
, int);
103 nbcb_rat_on (LibraryMenuTypePtr net
, int pos
)
106 char *name
= net
->Name
;
109 str
= XmStringCreateLocalized (name
);
110 XmListReplaceItemsPos (netlist_list
, &str
, 1, pos
);
115 nbcb_rat_off (LibraryMenuTypePtr net
, int pos
)
118 char *name
= net
->Name
;
121 str
= XmStringCreateLocalized (name
);
122 XmListReplaceItemsPos (netlist_list
, &str
, 1, pos
);
127 /* Select on the layout the current net treeview selection
130 nbcb_select_common (LibraryMenuTypePtr net
, int pos
, int select_flag
)
132 LibraryEntryType
*entry
;
136 InitConnectionLookup ();
137 ResetFoundPinsViasAndPads (False
);
138 ResetFoundLinesAndPolygons (False
);
139 SaveUndoSerialNumber ();
141 for (i
= net
->EntryN
, entry
= net
->Entry
; i
; i
--, entry
++)
142 if (SeekPad (entry
, &conn
, False
))
143 RatFindHook (conn
.type
, conn
.ptr1
, conn
.ptr2
, conn
.ptr2
, True
, True
);
144 RestoreUndoSerialNumber ();
145 SelectConnection (select_flag
);
146 ResetFoundPinsViasAndPads (False
);
147 ResetFoundLinesAndPolygons (False
);
148 FreeConnectionLookupMemory ();
149 IncrementUndoSerialNumber ();
153 nbcb_select (LibraryMenuTypePtr net
, int pos
)
155 nbcb_select_common (net
, pos
, 1);
159 nbcb_deselect (LibraryMenuTypePtr net
, int pos
)
161 nbcb_select_common (net
, pos
, 0);
165 nbcb_find (LibraryMenuTypePtr net
, int pos
)
167 char *name
= net
->Name
+ 2;
168 hid_actionl ("netlist", "find", name
, NULL
);
172 nbcb_std_callback (Widget w
, Std_Nbcb_Func v
, XmPushButtonCallbackStruct
* cbs
)
175 XmString
**items
, **selected
;
176 if (XmListGetSelectedPos (netlist_list
, &posl
, &posc
) == False
)
179 hid_actionl ("connection", "reset", NULL
);
180 for (i
=0; i
<posc
; i
++)
182 LibraryMenuTypePtr net
= & (PCB
->NetlistLib
.Menu
[posl
[i
] - 1]);
186 stdarg (XmNitems
, &items
);
187 XtGetValues (netlist_list
, args
, n
);
188 selected
= (XmString
**) malloc (posc
* sizeof (XmString
*));
189 for (i
=0; i
<posc
; i
++)
190 selected
[i
] = items
[posl
[i
]-1];
193 stdarg (XmNselectedItems
, selected
);
194 XtSetValues (netlist_list
, args
, n
);
198 nbcb_ripup (Widget w
, Std_Nbcb_Func v
, XmPushButtonCallbackStruct
* cbs
)
200 nbcb_std_callback (w
, nbcb_find
, cbs
);
202 VISIBLELINE_LOOP (PCB
->Data
);
204 if (TEST_FLAG (FOUNDFLAG
, line
) && !TEST_FLAG (LOCKFLAG
, line
))
205 RemoveObject (LINE_TYPE
, layer
, line
, line
);
209 VISIBLEARC_LOOP (PCB
->Data
);
211 if (TEST_FLAG (FOUNDFLAG
, arc
) && !TEST_FLAG (LOCKFLAG
, arc
))
212 RemoveObject (ARC_TYPE
, layer
, arc
, arc
);
217 VIA_LOOP (PCB
->Data
);
219 if (TEST_FLAG (FOUNDFLAG
, via
) && !TEST_FLAG (LOCKFLAG
, via
))
220 RemoveObject (VIA_TYPE
, via
, via
, via
);
226 netnode_browse (Widget w
, XtPointer v
, XmListCallbackStruct
* cbs
)
228 LibraryMenuType
*menu
= PCB
->NetlistLib
.Menu
+ last_pick
;
229 char *name
= menu
->Entry
[cbs
->item_position
- 1].ListEntry
;
232 ename
= strdup (name
);
233 pname
= strchr (ename
, '-');
241 ELEMENT_LOOP (PCB
->Data
);
243 if (strcmp (element
->Name
[NAMEONPCB_INDEX
].TextString
, ename
) == 0)
247 if (strcmp (pin
->Number
, pname
) == 0)
249 MoveCrosshairAbsolute (pin
->X
, pin
->Y
);
257 if (strcmp (pad
->Number
, pname
) == 0)
259 int x
= (pad
->Point1
.X
+ pad
->Point2
.X
) / 2;
260 int y
= (pad
->Point1
.Y
+ pad
->Point2
.Y
) / 2;
261 gui
->set_crosshair (x
, y
, HID_SC_PAN_VIEWPORT
);
273 #define NLB_FORM ((Widget)(~0))
275 netlist_button (Widget parent
, char *name
, char *string
,
276 Widget top
, Widget bottom
, Widget left
, Widget right
,
277 XtCallbackProc callback
, void *user_data
)
282 #define NLB_W(w) if (w == NLB_FORM) { stdarg(XmN ## w ## Attachment, XmATTACH_FORM); } \
283 else if (w) { stdarg(XmN ## w ## Attachment, XmATTACH_WIDGET); \
284 stdarg (XmN ## w ## Widget, w); }
290 str
= XmStringCreateLocalized (string
);
291 stdarg(XmNlabelString
, str
);
292 rv
= XmCreatePushButton (parent
, name
, args
, n
);
295 XtAddCallback (rv
, XmNactivateCallback
, callback
, (XtPointer
)user_data
);
301 build_netlist_dialog ()
303 Widget b_sel
, b_unsel
, b_find
, b_ripup
, b_rat_on
, b_rat_off
, l_ops
;
312 stdarg (XmNresizePolicy
, XmRESIZE_GROW
);
313 stdarg (XmNtitle
, "Netlists");
314 stdarg (XmNautoUnmanage
, False
);
315 netlist_dialog
= XmCreateFormDialog (mainwind
, "netlist", args
, n
);
318 b_rat_on
= netlist_button (netlist_dialog
, "rat_on", "Enable for rats",
319 0, NLB_FORM
, NLB_FORM
, 0,
320 (XtCallbackProc
)nbcb_std_callback
, nbcb_rat_on
);
323 b_rat_off
= netlist_button (netlist_dialog
, "rat_off", "Disable for rats",
324 0, NLB_FORM
, b_rat_on
, 0,
325 (XtCallbackProc
)nbcb_std_callback
, nbcb_rat_off
);
328 b_sel
= netlist_button (netlist_dialog
, "select", "Select",
329 0, b_rat_on
, NLB_FORM
, 0,
330 (XtCallbackProc
)nbcb_std_callback
, nbcb_select
);
333 b_unsel
= netlist_button (netlist_dialog
, "deselect", "Deselect",
334 0, b_rat_on
, b_sel
, 0,
335 (XtCallbackProc
)nbcb_std_callback
, nbcb_deselect
);
338 b_find
= netlist_button (netlist_dialog
, "find", "Find",
339 0, b_rat_on
, b_unsel
, 0,
340 (XtCallbackProc
)nbcb_std_callback
, nbcb_find
);
344 b_ripup
= netlist_button (netlist_dialog
, "ripup", "Rip Up",
345 0, b_rat_on
, b_find
, 0,
346 (XtCallbackProc
)nbcb_ripup
, 0);
349 stdarg (XmNbottomAttachment
, XmATTACH_WIDGET
);
350 stdarg (XmNbottomWidget
, b_sel
);
351 stdarg (XmNleftAttachment
, XmATTACH_FORM
);
352 ops_str
= XmStringCreateLocalized ("Operations on selected net names:");
353 stdarg (XmNlabelString
, ops_str
);
354 l_ops
= XmCreateLabel (netlist_dialog
, "ops", args
, n
);
355 XtManageChild (l_ops
);
358 stdarg (XmNtopAttachment
, XmATTACH_FORM
);
359 stdarg (XmNbottomAttachment
, XmATTACH_WIDGET
);
360 stdarg (XmNbottomWidget
, l_ops
);
361 stdarg (XmNleftAttachment
, XmATTACH_FORM
);
362 stdarg (XmNrightAttachment
, XmATTACH_POSITION
);
363 stdarg (XmNrightPosition
, 50);
364 stdarg (XmNvisibleItemCount
, 10);
365 stdarg (XmNselectionPolicy
, XmEXTENDED_SELECT
);
366 netlist_list
= XmCreateScrolledList (netlist_dialog
, "nets", args
, n
);
367 XtManageChild (netlist_list
);
368 XtAddCallback (netlist_list
, XmNdefaultActionCallback
, (XtCallbackProc
)netlist_select
, 0);
369 XtAddCallback (netlist_list
, XmNextendedSelectionCallback
, (XtCallbackProc
)netlist_extend
, 0);
372 stdarg (XmNtopAttachment
, XmATTACH_FORM
);
373 stdarg (XmNbottomAttachment
, XmATTACH_WIDGET
);
374 stdarg (XmNbottomWidget
, l_ops
);
375 stdarg (XmNrightAttachment
, XmATTACH_FORM
);
376 stdarg (XmNleftAttachment
, XmATTACH_POSITION
);
377 stdarg (XmNleftPosition
, 50);
378 netnode_list
= XmCreateScrolledList (netlist_dialog
, "nodes", args
, n
);
379 XtManageChild (netnode_list
);
380 XtAddCallback (netnode_list
, XmNbrowseSelectionCallback
, (XtCallbackProc
)netnode_browse
, 0);
386 NetlistChanged (int argc
, char **argv
, int x
, int y
)
389 if (!PCB
->NetlistLib
.MenuN
)
391 if (build_netlist_dialog ())
395 free (netlist_strings
);
397 (XmString
*) malloc (PCB
->NetlistLib
.MenuN
* sizeof (XmString
));
398 for (i
= 0; i
< PCB
->NetlistLib
.MenuN
; i
++)
400 XmStringCreateLocalized (PCB
->NetlistLib
.Menu
[i
].Name
);
402 stdarg (XmNitems
, netlist_strings
);
403 stdarg (XmNitemCount
, PCB
->NetlistLib
.MenuN
);
404 XtSetValues (netlist_list
, args
, n
);
409 static const char netlistshow_syntax
[] =
412 static const char netlistshow_help
[] =
413 "Displays the netlist window.";
415 /* %start-doc actions NetlistShow
420 NetlistShow (int argc
, char **argv
, int x
, int y
)
422 if (build_netlist_dialog ())
428 lesstif_show_netlist ()
430 build_netlist_dialog ();
431 XtManageChild (netlist_dialog
);
434 HID_Action lesstif_netlist_action_list
[] = {
435 {"NetlistChanged", 0, NetlistChanged
,
436 netlistchanged_help
, netlistchanged_syntax
},
437 {"NetlistShow", 0, NetlistShow
,
438 netlistshow_help
, netlistshow_syntax
}
441 REGISTER_ACTIONS (lesstif_netlist_action_list
)