Jspice3
labels.c
Go to the documentation of this file.
1 /***************************************************************************
2 SCED - Schematic Capture Editor
3 JSPICE3 adaptation of Spice3e2 - Copyright (c) Stephen R. Whiteley 1992
4 Copyright 1990 Regents of the University of California. All rights reserved.
5 Authors: 1981 Giles C. Billingsley (parts of KIC layout editor)
6  1992 Stephen R. Whiteley
7 ****************************************************************************/
8 
9 /*
10  * SCED label management.
11  */
12 
13 #include "spice.h"
14 #include "sced.h"
15 #include "scedmacs.h"
16 
17 extern char *MenuLABEL;
18 extern char *MenuUNDO;
19 
20 #ifdef __STDC__
21 static void redisplay_label(struct o*);
22 static void delete_label(struct o*);
23 static char get_current_xform(void);
24 #else
25 static void redisplay_label();
26 static void delete_label();
27 static char get_current_xform();
28 #endif
29 
30 /* Label transform field:
31  * bits 0-1 : 0-no rotation, 1-90, 2-180, 3-270
32  * bit 2 : mirror y
33  * bit 3 : mirror x
34  */
35 
36 
37 void
38 Label(LookedAhead)
39 
40 int *LookedAhead;
41 {
42  struct o *Pointer;
43  char *c,*Label = NULL;
44  int NumLabelsMade = 0;
45  long X = 0,Y = 0;
46 
48  ShowPrompt("Enter label: ");
49  Label = FBEdit(NULL);
50  if (Label == NULL Or *Label == '\0')
51  goto quit;
52 
53  for (c = Label; *c; c++)
54  if (isspace(*c)) *c = '_';
55  loop {
56  ShowPrompt("Point to where you want the label.");
57  switch (PointLoop(LookedAhead)) {
58  case PL_ESC:
59  case PL_CMD:
60  goto quit;
61  case PL_UND:
62  if (NumLabelsMade == 0)
63  goto quit;
65  delete_label(Pointer);
66  NumLabelsMade--;
68  continue;
69  case PL_PCW:
70  X = SCursor.kcX;
71  Y = SCursor.kcY;
73  Label,X,Y,get_current_xform(),&Pointer)) MallocFailed();
74  redisplay_label(Pointer);
75  NumLabelsMade++;
76  }
77  }
78 quit:
79  if (NumLabelsMade > 0)
82  ErasePrompt();
83 }
84 
85 
86 void
87 BBLabel(Window,Pointer,BB)
88 
89 /* Return the effective BB of the label as seen in Window. */
90 struct ka *Window;
91 struct o *Pointer;
92 struct ka *BB;
93 {
94  struct la *LDesc;
95  long Len,Hei;
96  char Xform;
97 
98  LDesc = (struct la *)Pointer->oRep;
99  Xform = LDesc->laXform;
100  ScaledTextBB(LDesc->laLabel,&Len,&Hei);
101 
105  }
106  if (Window == View->kvCoarseWindow) {
107  Len /= View->kvCoarseRatio;
108  Hei /= View->kvCoarseRatio;
109  }
110  else {
111  Len /= View->kvFineRatio;
112  Hei /= View->kvFineRatio;
113  }
114  BB->kaLeft = LDesc->laX;
115  BB->kaBottom = LDesc->laY;
116 
117  if (Xform & 1) {
118  if (Xform & 2) {
119  if (!(Xform & 4))
120  BB->kaBottom -= Len;
121  if (Xform & 8)
122  BB->kaLeft -= Hei;
123  }
124  else {
125  if (!(Xform & 8))
126  BB->kaLeft -= Hei;
127  if (Xform & 4)
128  BB->kaBottom -= Len;
129  }
130  BB->kaRight = BB->kaLeft + Hei;
131  BB->kaTop = BB->kaBottom + Len;
132  }
133  else {
134  if (Xform & 2) {
135  if (!(Xform & 8))
136  BB->kaLeft -= Len;
137  if (!(Xform & 4))
138  BB->kaBottom -= Hei;
139  }
140  else {
141  if (Xform & 8)
142  BB->kaLeft -= Len;
143  if (Xform & 4)
144  BB->kaBottom -= Hei;
145  }
146  BB->kaRight = BB->kaLeft + Len;
147  BB->kaTop = BB->kaBottom + Hei;
148  }
149 }
150 
151 
152 void
154 
155 /* called from CD */
156 struct o *Pointer;
157 long *L,*B,*R,*T;
158 {
159  struct ka BB;
160 
161  BBLabel(View->kvCoarseWindow,Pointer,&BB);
162  *L = BB.kaLeft;
163  *B = BB.kaBottom;
164  *R = BB.kaRight;
165  *T = BB.kaTop;
166 }
167 
168 
169 void
170 ShowLabel(Color,Label,X,Y,Xform,Flag)
171 
172 int Color;
173 char *Label;
174 long X,Y;
175 char Xform;
176 int Flag; /* If Flag, label is always displayed */
177 {
178 
179  long TF[9],XT,YT;
180  char *c;
181 
182  TPoint(&X,&Y);
183 
184  /* have to fix transform */
185  TPush();
186  TIdentity();
187  if (Xform & 4) TMY();
188  if (Xform & 8) TMX();
189  Xform &= 3;
190  if (Xform != 0) {
191  if (Xform == 1) TRotate(0L,1L);
192  elif (Xform == 2) TRotate(-1L,0L);
193  elif (Xform == 3) TRotate(0L,-1L);
194  }
195  TPremultiply();
196  TCurrent(TF);
197  Xform = SetXform(TF);
198  TPop();
199 
200  strcpy(TypeOut,Label);
201  c = TypeOut;
202  while ((c = strchr(c,'_')) != NULL) *c = ' ';
203 
204  DevSetColor(Color);
205  if ((Flag Or 1/View->kvCoarseRatio < HALFRESOLUTION) And
207 
208  CoarseLToP(X,Y,XT,YT);
213  (int)View->kvCoarseViewport->kaTop);
214 
216  ScaledText(TypeOut,(int)XT,(int)YT,Xform,
218  else
219  ScaledText(TypeOut,(int)XT,(int)YT,Xform,1);
220  }
222 
223  FineLToP(X,Y,XT,YT);
225  (int)View->kvFineViewport->kaLeft,
227  (int)View->kvFineViewport->kaRight,
228  (int)View->kvFineViewport->kaTop);
229 
230  ScaledText(TypeOut,(int)XT,(int)YT,Xform,1);
231  }
233 }
234 
235 
236 static void
238 
239 struct o *Pointer;
240 {
241  struct ka BB;
242  int OldRD;
243 
244  if (Pointer->oType != CDLABEL) return;
245 
247 
248  if (OldRD != FINEVIEWPORTONLY) {
250  BBLabel(View->kvCoarseWindow,Pointer,&BB);
251  Redisplay(&BB);
252  }
253  if (OldRD != COARSEVIEWPORTONLY) {
255  BBLabel(View->kvFineWindow,Pointer,&BB);
256  Redisplay(&BB);
257  }
259 }
260 
261 
262 static void
264 
265 struct o *Pointer;
266 {
267 
268  struct ka BBC,BBF;
269  char OldRd;
270 
271  if (Pointer->oType != CDLABEL) return;
273 
274  if (OldRd != FINEVIEWPORTONLY) {
276 
277  BBLabel(View->kvCoarseWindow,Pointer,&BBC);
278 
279  TPoint(&BBC.kaLeft,&BBC.kaBottom);
280  TPoint(&BBC.kaRight,&BBC.kaTop);
281 
282  EraseBox(&BBC);
283  }
284  if (OldRd != COARSEVIEWPORTONLY) {
286 
287  BBLabel(View->kvFineWindow,Pointer,&BBF);
288 
289  TPoint(&BBF.kaLeft,&BBF.kaBottom);
290  TPoint(&BBF.kaRight,&BBF.kaTop);
291 
292  EraseBox(&BBF);
293  }
294 
295  CDDelete(Parameters.kpCellDesc,Pointer);
296 
297  if (OldRd != FINEVIEWPORTONLY) {
299  Redisplay(&BBC);
300  }
301  if (OldRd != COARSEVIEWPORTONLY) {
303  Redisplay(&BBF);
304  }
306 }
307 
308 
309 static char
311 
312 {
313  char c;
314 
315  c = (char)0;
316  c += Parameters.kpRotationAngle/90;
317  if (Parameters.kpMY) c |= 4;
318  if (Parameters.kpMX) c |= 8;
319  return (c);
320 }
321 
322 
323 char
325 
326 long *TF;
327 {
328  long A,B,C,D;
329 
330  /*
331  * Take the transformation defined in TF and set
332  * the returned bit field accordingly.
333  *
334  * | a c 0 |
335  * Transform = TM = | b d 0 |
336  * | TX TY 1 |
337  *
338  * A = TM[0][0] = TF[0];
339  * B = TM[1][0] = TF[3];
340  * C = TM[0][1] = TF[1];
341  * D = TM[1][1] = TF[4];
342  * TX = TM[2][0] = TF[6];
343  * TY = TM[2][1] = TF[7];
344  */
345 
346  A = TF[0]; B = TF[3]; C = TF[1]; D = TF[4];
347 
348  if (A == 0 && D == 0) {
349  if (B == 1 && C == 1) /* MX R 0 -1 */
350  return (11);
351 
352  if (B == -1 && C == -1) /* MX R 0 1 */
353  return (9);
354 
355  if (B == 1 && C == -1) /* R 0 -1 */
356  return (3);
357 
358  if (B == -1 && C == 1) /* R 0 1 */
359  return (1);
360  }
361  if (B == 0 && C == 0) {
362 
363  if (A == 1 && D == 1) /* translate only */
364  return (0);
365 
366  if (A == -1 && D == -1) /* R -1 0 */
367  return (2);
368 
369  if (A == -1 && D == 1) /* MX */
370  return (8);
371  }
372 
373  /* MY */
374  return (4);
375 }
376 
#define TF
Definition: ifeval.c:65
long laY
Definition: cddefs.h:202
#define PL_ESC
Definition: sced.h:62
void ErasePrompt()
Definition: viewport.c:538
#define loop
Definition: cdmacs.h:11
void TPoint()
void Redisplay()
int struct o * Pointer
Definition: cd.c:1311
#define HALFRESOLUTION
Definition: sced.h:37
#define Or
Definition: cdmacs.h:15
int ScaledText(char *text, int x, int y, int degrees, int scale)
Definition: labeltxt.c:160
struct ka * kvCoarseWindow
Definition: sced.h:149
#define PL_UND
Definition: sced.h:63
int kpModified
Definition: sced.h:261
long kaRight
Definition: sced.h:112
char * strcpy()
void ShowLabel(int Color, char *Label, long X, long Y, char Xform, int Flag)
Definition: labels.c:170
int CDMakeLabel()
void SetScaledTextClip(int xl, int yl, int xu, int yu)
Definition: labeltxt.c:131
double kvFineRatio
Definition: sced.h:154
void DevSetColor()
if(TDesc==NULL)
Definition: cd.c:1326
int PointLoop()
struct kc SCursor
Definition: init.c:21
long kaBottom
Definition: sced.h:112
double kvCoarseRatio
Definition: sced.h:155
#define COARSEVIEWPORTONLY
Definition: sced.h:51
struct s * kpCellDesc
Definition: sced.h:207
#define Not
Definition: cdmacs.h:16
#define FineLToP(X, Y, XT, YT)
Definition: sced.h:379
void TCurrent()
#define PL_PCW
Definition: sced.h:65
#define CDDelete
Definition: cddefs.h:19
Definition: sced.h:111
char kpRedisplayControl
Definition: sced.h:312
long kcY
Definition: sced.h:102
#define L
Definition: parse.c:442
struct ka * kvFineViewport
Definition: sced.h:148
int kpHardcopyTextScale
Definition: sced.h:290
static void delete_label()
#define FINEVIEWPORTONLY
Definition: sced.h:50
void MallocFailed()
Definition: scedintr.c:857
static char get_current_xform()
Definition: labels.c:310
long X
Definition: actions.c:450
void BBLabel(struct ka *Window, struct o *Pointer, struct ka *BB)
Definition: labels.c:87
int kpDoingHardcopy
Definition: sced.h:287
void MenuDeselect()
#define gi_maxx
Definition: scedmacs.h:58
int kpMY
Definition: sced.h:284
#define R
Definition: parse.c:444
#define NULL
Definition: spdefs.h:121
char TypeOut[200]
Definition: init.c:23
struct ka * kvCoarseViewport
Definition: sced.h:150
struct kp Parameters
Definition: init.c:19
void Color()
long kaTop
Definition: sced.h:112
#define elif
Definition: cdmacs.h:10
void TMX()
Definition: xforms.c:112
struct ka * kvFineWindow
Definition: sced.h:147
void TPremultiply()
Definition: xforms.c:216
#define True
Definition: scedstub.c:16
void TRotate()
struct kv * View
Definition: init.c:17
char SetXform(long *TF)
Definition: labels.c:324
static double c
Definition: vectors.c:16
static void redisplay_label()
int kpRotationAngle
Definition: sced.h:282
void EraseBox()
char * MenuLABEL
Definition: scedintr.c:84
struct o * oRep
Definition: cddefs.h:144
long kaLeft
Definition: sced.h:112
Definition: cddefs.h:201
Definition: cddefs.h:142
void Label(int *LookedAhead)
Definition: labels.c:38
#define CoarseLToP(X, Y, XT, YT)
Definition: sced.h:373
long kcX
Definition: sced.h:102
int kpMX
Definition: sced.h:283
#define And
Definition: cdmacs.h:14
void TIdentity()
Definition: xforms.c:189
void CDLabelBB(struct o *Pointer, long *L, long *B, long *R, long *T)
Definition: labels.c:153
char laXform
Definition: cddefs.h:204
char * FBEdit()
void TPop()
Definition: xforms.c:64
void ScaledTextBB(char *string, int *wid, int *hei)
Definition: labeltxt.c:144
char * laLabel
Definition: cddefs.h:203
#define PL_CMD
Definition: sced.h:64
void TMY()
Definition: xforms.c:104
void MenuSelect()
long Y
Definition: actions.c:450
void ShowPrompt(char *str)
Definition: scedstub.c:71
char * MenuUNDO
Definition: scedintr.c:108
void TPush()
Definition: xforms.c:53
#define CDLABEL
Definition: cddefs.h:46
#define gi_maxy
Definition: scedmacs.h:59
long laX
Definition: cddefs.h:202