47
55
#include <X11/Xaw/Simple.h>
48
56
#include <X11/Xaw/Viewport.h>
58
#ifdef HAVE_LIBDMALLOC
62
RCSID("$Id: pinout.c,v 1.10 2005/01/03 12:57:00 danmc Exp $");
50
67
/* ---------------------------------------------------------------------------
53
typedef struct /* information of one window */
70
typedef struct /* information of one window */
55
ElementType Element; /* element data to display */
56
String Title; /* window title */
57
Widget Shell, /* shell widget */
58
Output, /* output widget managed by a viewport widget */
59
Enlarge, /* enlarge button */
60
Shrink; /* shrink button */
61
int Zoom; /* zoom factor of window */
62
Position MaxX, /* size of used drawing area independend */
63
MaxY; /* from zoom setting */
64
} PinoutType, *PinoutTypePtr;
72
ElementType Element; /* element data to display */
73
String Title; /* window title */
74
Widget Shell, /* shell widget */
75
Output, /* output widget managed by a viewport widget */
76
Enlarge, /* enlarge button */
77
Shrink; /* shrink button */
78
float Zoom, /* zoom factor of window */
79
scale; /* scale factor of zoom */
80
LocationType MaxX, /* size of used drawing area independend */
81
MaxY; /* from zoom setting */
83
PinoutType, *PinoutTypePtr;
66
85
/* ---------------------------------------------------------------------------
67
86
* some local prototypes
69
static void CB_Dismiss(Widget, XtPointer, XtPointer);
70
static void CB_ShrinkOrEnlarge(Widget, XtPointer, XtPointer);
71
static void RedrawPinoutWindow(PinoutTypePtr);
72
static void PinoutEvent(Widget, XtPointer, XEvent *, Boolean *);
88
static void CB_Dismiss (Widget, XtPointer, XtPointer);
89
static void CB_ShrinkOrEnlarge (Widget, XtPointer, XtPointer);
90
static void RedrawPinoutWindow (PinoutTypePtr);
91
static void PinoutEvent (Widget, XtPointer, XEvent *, Boolean *);
74
94
/* ---------------------------------------------------------------------------
75
95
* creates a new window to display an elements pinout
77
void PinoutWindow(Widget Parent, ElementTypePtr Element)
98
PinoutWindow (Widget Parent, ElementTypePtr Element)
84
Dimension tx, ty, minx, miny;
89
/* allocate memory for title and pinout data, init zoom factor */
90
pinout = (PinoutTypePtr) MyCalloc(1, sizeof(PinoutType), "PinoutWindow()");
91
pinout->Title = (String) MyCalloc(strlen(UNKNOWN(NAMEONPCB_NAME(Element)))+
92
strlen(UNKNOWN(DESCRIPTION_NAME(Element)))+
93
strlen(UNKNOWN(VALUE_NAME(Element)))+5,
94
sizeof(char), "PinoutWindow()");
95
sprintf(pinout->Title, "%s [%s,%s]", UNKNOWN(DESCRIPTION_NAME(Element)),
96
UNKNOWN(NAMEONPCB_NAME(Element)),
97
UNKNOWN(VALUE_NAME(Element)));
100
* enable output of pin- and padnames
101
* move element to a 5% offset from zero position
102
* set all package lines/arcs to zero with
104
CopyElementLowLevel(PCB->Data, &pinout->Element, Element, False);
106
PIN_LOOP(&pinout->Element,
107
tx = abs(pinout->Element.Pin[0].X - pin->X);
108
ty = abs(pinout->Element.Pin[0].Y - pin->Y);
109
if (tx !=0 && tx < minx)
111
if (ty != 0 && ty < miny)
113
SET_FLAG(DISPLAYNAMEFLAG, pin);
116
PAD_LOOP(&pinout->Element,
117
tx = abs(pinout->Element.Pad[0].Point1.X - pad->Point1.X);
118
ty = abs(pinout->Element.Pad[0].Point1.Y - pad->Point1.Y);
119
if (tx !=0 && tx < minx)
121
if (ty != 0 && ty < miny)
123
SET_FLAG(DISPLAYNAMEFLAG, pad);
126
RotateElementLowLevel(&pinout->Element, pinout->Element.BoundingBox.X1,
127
pinout->Element.BoundingBox.Y1, 1);
129
MoveElementLowLevel(&pinout->Element,
130
-pinout->Element.BoundingBox.X1 +Settings.PinoutOffsetX,
131
-pinout->Element.BoundingBox.Y1 +Settings.PinoutOffsetY);
132
pinout->Zoom = Settings.PinoutZoom;
133
pinout->MaxX = pinout->Element.BoundingBox.X2 +Settings.PinoutOffsetX;
134
pinout->MaxY = pinout->Element.BoundingBox.Y2 +Settings.PinoutOffsetY;
135
ELEMENTLINE_LOOP(&pinout->Element, line->Thickness = 0;);
136
ARC_LOOP(&pinout->Element, arc->Thickness = 0;);
138
/* create shell window with viewport,
139
* shrink, enlarge and exit button
141
pinout->Shell = XtVaCreatePopupShell("pinout",
142
topLevelShellWidgetClass,
144
XtNtitle, pinout->Title,
145
XtNallowShellResize, False,
146
XtNmappedWhenManaged, False,
148
masterform = XtVaCreateManagedWidget("pinoutMasterForm",
155
viewport = XtVaCreateManagedWidget("viewport",
165
pinout->Output = XtVaCreateManagedWidget("output",
169
XtNwidth, pinout->MaxX >> pinout->Zoom,
170
XtNheight, pinout->MaxY >> pinout->Zoom,
172
dismiss = XtVaCreateManagedWidget("dismiss",
175
XtNfromVert, viewport,
178
pinout->Shrink = XtVaCreateManagedWidget("shrink",
181
XtNfromVert, viewport,
182
XtNfromHoriz, dismiss,
185
pinout->Enlarge = XtVaCreateManagedWidget("enlarge",
188
XtNfromVert, viewport,
189
XtNfromHoriz, pinout->Shrink,
193
/* install accelerators for WM messages and to
194
* move scrollbars with keys
196
XtInstallAccelerators(pinout->Shell, dismiss);
197
if ((scrollbar = XtNameToWidget(viewport, "horizontal")) != NULL)
198
XtInstallAccelerators(masterform, scrollbar);
199
if ((scrollbar = XtNameToWidget(viewport, "vertical")) != NULL)
200
XtInstallAccelerators(masterform, scrollbar);
202
/* add event handler for viewport and callbacks for buttons
203
* the pointer to the pinout structure is passed to these functions
206
XtAddCallback(dismiss, XtNcallback, CB_Dismiss, (XtPointer) pinout);
207
XtAddCallback(pinout->Shrink, XtNcallback,
208
CB_ShrinkOrEnlarge, (XtPointer) pinout);
209
XtAddCallback(pinout->Enlarge, XtNcallback,
210
CB_ShrinkOrEnlarge, (XtPointer) pinout);
211
XtAddEventHandler(pinout->Output,
213
False, (XtEventHandler) PinoutEvent, (XtPointer) pinout);
215
/* realize (without mapping) and handle 'delete' messages */
216
XtRealizeWidget(pinout->Shell);
217
XSetWMProtocols(Dpy, XtWindow(pinout->Shell), &WMDeleteWindowAtom, 1);
219
/* bring all stuff to the screen */
220
XtPopup(pinout->Shell, XtGrabNone);
100
Widget masterform, dismiss, scrollbar, viewport;
101
PinoutTypePtr pinout;
102
Dimension tx, ty, minx, miny;
107
/* allocate memory for title and pinout data, init zoom factor */
109
(PinoutTypePtr) MyCalloc (1, sizeof (PinoutType), "PinoutWindow()");
111
(String) MyCalloc (strlen (UNKNOWN (NAMEONPCB_NAME (Element))) +
112
strlen (UNKNOWN (DESCRIPTION_NAME (Element))) +
113
strlen (UNKNOWN (VALUE_NAME (Element))) + 5,
114
sizeof (char), "PinoutWindow()");
115
sprintf (pinout->Title, "%s [%s,%s]", UNKNOWN (DESCRIPTION_NAME (Element)),
116
UNKNOWN (NAMEONPCB_NAME (Element)),
117
UNKNOWN (VALUE_NAME (Element)));
120
* enable output of pin- and padnames
121
* move element to a 5% offset from zero position
122
* set all package lines/arcs to zero with
124
CopyElementLowLevel (NULL, &pinout->Element, Element, False);
126
PIN_LOOP (&pinout->Element);
128
tx = abs (pinout->Element.Pin[0].X - pin->X);
129
ty = abs (pinout->Element.Pin[0].Y - pin->Y);
130
if (tx != 0 && tx < minx)
132
if (ty != 0 && ty < miny)
134
SET_FLAG (DISPLAYNAMEFLAG, pin);
138
PAD_LOOP (&pinout->Element);
140
tx = abs (pinout->Element.Pad[0].Point1.X - pad->Point1.X);
141
ty = abs (pinout->Element.Pad[0].Point1.Y - pad->Point1.Y);
142
if (tx != 0 && tx < minx)
144
if (ty != 0 && ty < miny)
146
SET_FLAG (DISPLAYNAMEFLAG, pad);
150
RotateElementLowLevel (NULL, &pinout->Element,
151
pinout->Element.BoundingBox.X1,
152
pinout->Element.BoundingBox.Y1, 1);
154
MoveElementLowLevel (NULL, &pinout->Element,
155
-pinout->Element.BoundingBox.X1 +
156
Settings.PinoutOffsetX,
157
-pinout->Element.BoundingBox.Y1 +
158
Settings.PinoutOffsetY);
159
pinout->Zoom = Settings.PinoutZoom;
160
pinout->scale = 1. / (100. * exp (pinout->Zoom * LN_2_OVER_2));
161
pinout->MaxX = pinout->Element.BoundingBox.X2 + Settings.PinoutOffsetX;
162
pinout->MaxY = pinout->Element.BoundingBox.Y2 + Settings.PinoutOffsetY;
163
ELEMENTLINE_LOOP (&pinout->Element);
168
ARC_LOOP (&pinout->Element);
174
/* create shell window with viewport,
175
* shrink, enlarge and exit button
177
pinout->Shell = XtVaCreatePopupShell ("pinout",
178
topLevelShellWidgetClass,
180
XtNtitle, pinout->Title,
181
XtNallowShellResize, False,
182
XtNmappedWhenManaged, False, NULL);
183
masterform = XtVaCreateManagedWidget ("pinoutMasterForm",
188
XtNfromVert, NULL, NULL);
189
viewport = XtVaCreateManagedWidget ("viewport",
197
XtNuseBottom, True, NULL);
198
pinout->Output = XtVaCreateManagedWidget ("output",
203
(Dimension) (pinout->MaxX *
206
(Dimension) (pinout->MaxY *
210
XtVaCreateManagedWidget ("dismiss", commandWidgetClass, masterform,
211
XtNfromVert, viewport, LAYOUT_BOTTOM, NULL);
213
XtVaCreateManagedWidget ("shrink", commandWidgetClass, masterform,
214
XtNfromVert, viewport, XtNfromHoriz, dismiss,
215
LAYOUT_BOTTOM, NULL);
217
XtVaCreateManagedWidget ("enlarge", commandWidgetClass, masterform,
218
XtNfromVert, viewport, XtNfromHoriz,
219
pinout->Shrink, LAYOUT_BOTTOM, NULL);
221
/* install accelerators for WM messages and to
222
* move scrollbars with keys
224
XtInstallAccelerators (pinout->Shell, dismiss);
225
if ((scrollbar = XtNameToWidget (viewport, "horizontal")) != NULL)
226
XtInstallAccelerators (masterform, scrollbar);
227
if ((scrollbar = XtNameToWidget (viewport, "vertical")) != NULL)
228
XtInstallAccelerators (masterform, scrollbar);
230
/* add event handler for viewport and callbacks for buttons
231
* the pointer to the pinout structure is passed to these functions
234
XtAddCallback (dismiss, XtNcallback, CB_Dismiss, (XtPointer) pinout);
235
XtAddCallback (pinout->Shrink, XtNcallback,
236
CB_ShrinkOrEnlarge, (XtPointer) pinout);
237
XtAddCallback (pinout->Enlarge, XtNcallback,
238
CB_ShrinkOrEnlarge, (XtPointer) pinout);
239
XtAddEventHandler (pinout->Output,
241
False, (XtEventHandler) PinoutEvent, (XtPointer) pinout);
243
/* realize (without mapping) and handle 'delete' messages */
244
XtRealizeWidget (pinout->Shell);
245
XSetWMProtocols (Dpy, XtWindow (pinout->Shell), &WMDeleteWindowAtom, 1);
247
/* bring all stuff to the screen */
248
XtPopup (pinout->Shell, XtGrabNone);
223
251
/* ---------------------------------------------------------------------------
224
252
* redraws pinout window
226
static void RedrawPinoutWindow(PinoutTypePtr Pinout)
255
RedrawPinoutWindow (PinoutTypePtr Pinout)
228
Window window = XtWindow(Pinout->Output);
230
if (window) /* check for valid ID */
232
/* setup drawable and zoom factor for drawing routines */
233
SwitchDrawingWindow(Pinout->Zoom, window, False, False);
235
/* clear background call the drawing routine */
236
XFillRectangle(Dpy, window, Output.bgGC, 0, 0, MAX_COORD, MAX_COORD);
237
DrawElement(&Pinout->Element, 0);
239
/* reset drawing routines to normal operation */
240
SwitchDrawingWindow(PCB->Zoom, Output.OutputWindow,
241
Settings.ShowSolderSide, True);
257
Window window = XtWindow (Pinout->Output);
259
if (window) /* check for valid ID */
261
/* setup drawable and zoom factor for drawing routines */
262
SwitchDrawingWindow (Pinout->Zoom, window, False, False);
264
/* clear background call the drawing routine */
265
XFillRectangle (Dpy, window, Output.bgGC, 0, 0, MAX_COORD, MAX_COORD);
266
DrawElement (&Pinout->Element, 0);
268
/* reset drawing routines to normal operation */
269
SwitchDrawingWindow (PCB->Zoom, Output.OutputWindow,
270
Settings.ShowSolderSide, True);
245
274
/* ---------------------------------------------------------------------------
246
275
* event handler for all pinout windows
247
276
* a pointer to the pinout struct is passed as ClientData
249
static void PinoutEvent(Widget W, XtPointer ClientData,
250
XEvent *Event, Boolean *Flag)
279
PinoutEvent (Widget W, XtPointer ClientData, XEvent * Event, Boolean * Flag)
254
case Expose: /* just redraw the complete window */
255
RedrawPinoutWindow((PinoutTypePtr) ClientData);
283
case Expose: /* just redraw the complete window */
284
RedrawPinoutWindow ((PinoutTypePtr) ClientData);
260
289
/* ---------------------------------------------------------------------------
261
290
* callback routine of the dismiss buttons of all pinout windows
262
291
* a pointer to the pinout struct is passed as ClientData
264
static void CB_Dismiss(Widget W, XtPointer ClientData, XtPointer CallData)
294
CB_Dismiss (Widget W, XtPointer ClientData, XtPointer CallData)
266
PinoutTypePtr pinout = (PinoutTypePtr) ClientData;
296
PinoutTypePtr pinout = (PinoutTypePtr) ClientData;
269
XtDestroyWidget(pinout->Shell);
270
SaveFree(pinout->Title);
271
FreeElementMemory(&pinout->Element);
299
XtDestroyWidget (pinout->Shell);
300
SaveFree (pinout->Title);
301
FreeElementMemory (&pinout->Element);
275
305
/* ---------------------------------------------------------------------------
276
306
* callback routine of the shrink or enlarge buttons of all windows
277
307
* a pointer to the pinout struct is passed as ClientData
279
static void CB_ShrinkOrEnlarge(Widget W,
280
XtPointer ClientData, XtPointer CallData)
310
CB_ShrinkOrEnlarge (Widget W, XtPointer ClientData, XtPointer CallData)
282
PinoutTypePtr pinout = (PinoutTypePtr) ClientData;
312
PinoutTypePtr pinout = (PinoutTypePtr) ClientData;
284
if (W == pinout->Shrink && pinout->Zoom < MAX_ZOOM)
286
if (W == pinout->Enlarge && pinout->Zoom > MIN_ZOOM)
288
XtVaSetValues(pinout->Output,
289
XtNwidth, pinout->MaxX >> pinout->Zoom,
290
XtNheight, pinout->MaxY >> pinout->Zoom,
292
RedrawPinoutWindow(pinout);
314
if (W == pinout->Shrink && pinout->Zoom < MAX_ZOOM)
316
if (W == pinout->Enlarge && pinout->Zoom > MIN_ZOOM)
318
XtVaSetValues (pinout->Output,
319
XtNwidth, (Dimension) (pinout->MaxX * pinout->scale),
320
XtNheight, (Dimension) (pinout->MaxY * pinout->scale), NULL);
321
RedrawPinoutWindow (pinout);