22 #include <qdragobject.h>
23 #include <qtextstream.h>
30 "1 1 1 1",
" c None",
" "};
36 Arcs.setAutoDelete(
true);
37 Lines.setAutoDelete(
true);
38 Rects.setAutoDelete(
true);
39 Ellips.setAutoDelete(
true);
40 Texts.setAutoDelete(
true);
43 PaintText = tr(
"Symbol:");
45 TextWidth = metrics.width(PaintText) + 4;
47 DragNDropText = tr(
"! Drag n'Drop me !");
48 DragNDropWidth = metrics.width(DragNDropText);
49 TextHeight = metrics.lineSpacing();
51 setPaletteBackgroundColor(Qt::white);
52 setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
68 return "<Lib " +
Prefix +
" 1 0 0 " +
69 QString::number(
Text_x) +
" " +
70 QString::number(
Text_y) +
" 0 0 \"" +
77 myDragObject =
new QTextDrag(
"QucsComponent:"+
theModel(),
this);
78 myDragObject->setPixmap( QPixmap(
empty_xpm), QPoint(0, 0) );
79 myDragObject->dragCopy();
83 void SymbolWidget::paintEvent(QPaintEvent*)
85 QPainter Painter(
this);
86 Painter.drawText(2, 2, 0, 0, Qt::AlignAuto | Qt::DontClip, PaintText);
88 int dx = (x2-x1)/2 + TextWidth - DragNDropWidth/2;
90 Painter.drawText(dx, y2-y1+2, 0, 0, Qt::AlignAuto | Qt::DontClip, DragNDropText);
93 for(
Line *pl = Lines.first(); pl != 0; pl = Lines.next()) {
94 Painter.setPen(pl->style);
95 Painter.drawLine(cx+pl->x1, cy+pl->y1, cx+pl->x2, cy+pl->y2);
99 for(
Arc *pc = Arcs.first(); pc != 0; pc = Arcs.next()) {
100 Painter.setPen(pc->style);
101 Painter.drawArc(cx+pc->x, cy+pc->y, pc->w, pc->h, pc->angle, pc->arclen);
106 for(pa = Rects.first(); pa != 0; pa = Rects.next()) {
107 Painter.setPen(pa->
Pen);
108 Painter.setBrush(pa->
Brush);
109 Painter.drawRect(cx+pa->
x, cy+pa->
y, pa->
w, pa->
h);
113 for(pa = Ellips.first(); pa != 0; pa = Ellips.next()) {
114 Painter.setPen(pa->
Pen);
115 Painter.setBrush(pa->
Brush);
116 Painter.drawEllipse(cx+pa->
x, cy+pa->
y, pa->
w, pa->
h);
119 Painter.setPen(QPen(QPen::black,1));
120 QFont Font = Painter.font();
123 for(
Text *pt = Texts.first(); pt != 0; pt = Texts.next()) {
124 Font.setPointSizeFloat(pt->Size);
125 Painter.setFont(Font);
126 Painter.setPen(pt->Color);
127 Painter.drawText(cx+pt->x, cy+pt->y, 0, 0, Qt::DontClip, pt->s);
150 Lines.append(
new Line(-10,-15,-10, 15,QPen(QPen::darkBlue,3)));
151 Lines.append(
new Line(-30, 0,-10, 0,QPen(QPen::darkBlue,2)));
152 Lines.append(
new Line(-10, -5, 0,-15,QPen(QPen::darkBlue,2)));
153 Lines.append(
new Line( 0,-15, 0,-30,QPen(QPen::darkBlue,2)));
154 Lines.append(
new Line(-10, 5, 0, 15,QPen(QPen::darkBlue,2)));
155 Lines.append(
new Line( 0, 15, 0, 30,QPen(QPen::darkBlue,2)));
157 if(FirstProp ==
"npn") {
158 Lines.append(
new Line( -6, 15, 0, 15,QPen(QPen::darkBlue,2)));
159 Lines.append(
new Line( 0, 9, 0, 15,QPen(QPen::darkBlue,2)));
162 Lines.append(
new Line( -5, 10, -5, 16,QPen(QPen::darkBlue,2)));
163 Lines.append(
new Line( -5, 10, 1, 10,QPen(QPen::darkBlue,2)));
166 Arcs.append(
new struct Arc(-34, -4, 8, 8, 0, 16*360,
168 Arcs.append(
new struct Arc(-4, -34, 8, 8, 0, 16*360,
170 Arcs.append(
new struct Arc(-4, 26, 8, 8, 0, 16*360,
177 else if(Comp ==
"JFET") {
178 Lines.append(
new Line(-10,-15,-10, 15,QPen(QPen::darkBlue,3)));
179 Lines.append(
new Line(-30, 0,-10, 0,QPen(QPen::darkBlue,2)));
180 Lines.append(
new Line(-10,-10, 0,-10,QPen(QPen::darkBlue,2)));
181 Lines.append(
new Line( 0,-10, 0,-30,QPen(QPen::darkBlue,2)));
182 Lines.append(
new Line(-10, 10, 0, 10,QPen(QPen::darkBlue,2)));
183 Lines.append(
new Line( 0, 10, 0, 30,QPen(QPen::darkBlue,2)));
185 Lines.append(
new Line( -4, 24, 4, 20,QPen(QPen::darkBlue,2)));
187 if(FirstProp ==
"nfet") {
188 Lines.append(
new Line(-16, -5,-11, 0,QPen(QPen::darkBlue,2)));
189 Lines.append(
new Line(-16, 5,-11, 0,QPen(QPen::darkBlue,2)));
192 Lines.append(
new Line(-18, 0,-13, -5,QPen(QPen::darkBlue,2)));
193 Lines.append(
new Line(-18, 0,-13, 5,QPen(QPen::darkBlue,2)));
196 Arcs.append(
new struct Arc(-34, -4, 8, 8, 0, 16*360,
198 Arcs.append(
new struct Arc(-4, -34, 8, 8, 0, 16*360,
200 Arcs.append(
new struct Arc(-4, 26, 8, 8, 0, 16*360,
207 else if(Comp ==
"_MOSFET") {
208 Lines.append(
new Line(-14,-13,-14, 13,QPen(QPen::darkBlue,3)));
209 Lines.append(
new Line(-30, 0,-14, 0,QPen(QPen::darkBlue,2)));
211 Lines.append(
new Line(-10,-11, 0,-11,QPen(QPen::darkBlue,2)));
212 Lines.append(
new Line( 0,-11, 0,-30,QPen(QPen::darkBlue,2)));
213 Lines.append(
new Line(-10, 11, 0, 11,QPen(QPen::darkBlue,2)));
214 Lines.append(
new Line( 0, 0, 0, 30,QPen(QPen::darkBlue,2)));
215 Lines.append(
new Line(-10, 0, 0, 0,QPen(QPen::darkBlue,2)));
217 Lines.append(
new Line(-10,-16,-10, -7,QPen(QPen::darkBlue,3)));
218 Lines.append(
new Line(-10, 7,-10, 16,QPen(QPen::darkBlue,3)));
220 if(FirstProp ==
"nfet") {
221 Lines.append(
new Line( -9, 0, -4, -5,QPen(QPen::darkBlue,2)));
222 Lines.append(
new Line( -9, 0, -4, 5,QPen(QPen::darkBlue,2)));
225 Lines.append(
new Line( -1, 0, -6, -5,QPen(QPen::darkBlue,2)));
226 Lines.append(
new Line( -1, 0, -6, 5,QPen(QPen::darkBlue,2)));
230 if((
ModelString.section(
'"', 3,3).stripWhiteSpace().at(0) ==
'-') ==
231 (FirstProp ==
"nfet"))
232 Lines.append(
new Line(-10, -8,-10, 8,QPen(QPen::darkBlue,3)));
234 Lines.append(
new Line(-10, -4,-10, 4,QPen(QPen::darkBlue,3)));
236 Arcs.append(
new struct Arc(-34, -4, 8, 8, 0, 16*360,
238 Arcs.append(
new struct Arc(-4, -34, 8, 8, 0, 16*360,
240 Arcs.append(
new struct Arc(-4, 26, 8, 8, 0, 16*360,
247 else if(Comp ==
"Diode") {
248 Lines.append(
new Line(-30, 0, 30, 0,QPen(QPen::darkBlue,2)));
249 Lines.append(
new Line( -6, -9, -6, 9,QPen(QPen::darkBlue,2)));
250 Lines.append(
new Line( 6, -9, 6, 9,QPen(QPen::darkBlue,2)));
251 Lines.append(
new Line( -6, 0, 6, -9,QPen(QPen::darkBlue,2)));
252 Lines.append(
new Line( -6, 0, 6, 9,QPen(QPen::darkBlue,2)));
254 Arcs.append(
new struct Arc(-34, -4, 8, 8, 0, 16*360,
256 Arcs.append(
new struct Arc(26, -4, 8, 8, 0, 16*360,
263 else if(Comp ==
"hicumL2V2p1" || Comp ==
"hic2_full" ||
264 Comp ==
"hic0_full" || Comp ==
"hicumL0V1p2" ||
265 Comp ==
"hicumL2V2p23" || Comp ==
"hicumL2V2p24" ||
266 Comp ==
"hicumL0V1p2g" || Comp ==
"hicumL0V1p3") {
268 Lines.append(
new Line(-10,-15,-10, 15,QPen(QPen::darkBlue,3)));
269 Lines.append(
new Line(-30, 0,-10, 0,QPen(QPen::darkBlue,2)));
270 Lines.append(
new Line(-10, -5, 0,-15,QPen(QPen::darkBlue,2)));
271 Lines.append(
new Line( 0,-15, 0,-30,QPen(QPen::darkBlue,2)));
272 Lines.append(
new Line(-10, 5, 0, 15,QPen(QPen::darkBlue,2)));
273 Lines.append(
new Line( 0, 15, 0, 30,QPen(QPen::darkBlue,2)));
276 Lines.append(
new Line( 9, 0, 30, 0,QPen(QPen::darkBlue,2)));
277 Lines.append(
new Line( 9, -7, 9, 7,QPen(QPen::darkBlue,3)));
280 Lines.append(
new Line(-30, 20,-20, 20,QPen(QPen::darkBlue,2)));
281 Lines.append(
new Line(-20, 17,-20, 23,QPen(QPen::darkBlue,2)));
284 if(FirstProp ==
"npn" || Comp ==
"hic2_full" || Comp ==
"hicumL2V2p23" ||
285 Comp ==
"hicumL2V2p1") {
286 Lines.append(
new Line( -6, 15, 0, 15,QPen(QPen::darkBlue,2)));
287 Lines.append(
new Line( 0, 9, 0, 15,QPen(QPen::darkBlue,2)));
289 Lines.append(
new Line( -5, 10, -5, 16,QPen(QPen::darkBlue,2)));
290 Lines.append(
new Line( -5, 10, 1, 10,QPen(QPen::darkBlue,2)));
294 Lines.append(
new Line(-30,-30,-30,-24,QPen(QPen::darkBlue,1)));
295 Lines.append(
new Line(-30,-27,-26,-27,QPen(QPen::darkBlue,1)));
296 Lines.append(
new Line(-26,-30,-26,-24,QPen(QPen::darkBlue,1)));
298 Lines.append(
new Line(-24,-30,-24,-24,QPen(QPen::darkBlue,1)));
300 Lines.append(
new Line(-22,-30,-22,-24,QPen(QPen::darkBlue,1)));
301 Lines.append(
new Line(-22,-30,-19,-30,QPen(QPen::darkBlue,1)));
302 Lines.append(
new Line(-22,-24,-19,-24,QPen(QPen::darkBlue,1)));
304 Lines.append(
new Line(-17,-30,-17,-24,QPen(QPen::darkBlue,1)));
305 Lines.append(
new Line(-14,-30,-14,-24,QPen(QPen::darkBlue,1)));
306 Lines.append(
new Line(-17,-24,-14,-24,QPen(QPen::darkBlue,1)));
308 Lines.append(
new Line(-12,-30,-12,-24,QPen(QPen::darkBlue,1)));
309 Lines.append(
new Line( -8,-30, -8,-24,QPen(QPen::darkBlue,1)));
310 Lines.append(
new Line(-12,-30,-10,-28,QPen(QPen::darkBlue,1)));
311 Lines.append(
new Line( -8,-30,-10,-28,QPen(QPen::darkBlue,1)));
314 Arcs.append(
new struct Arc( -4, -34, 8, 8, 0, 16*360,
316 Arcs.append(
new struct Arc(-34, -4, 8, 8, 0, 16*360,
318 Arcs.append(
new struct Arc( -4, 26, 8, 8, 0, 16*360,
320 Arcs.append(
new struct Arc( 26, -4, 8, 8, 0, 16*360,
322 Arcs.append(
new struct Arc(-34, 16, 8, 8, 0, 16*360,
329 else if(Comp ==
"SUBST") {
330 Lines.append(
new Line(-30,-16, 30,-16,QPen(QPen::darkBlue,2)));
331 Lines.append(
new Line(-30,-12, 30,-12,QPen(QPen::darkBlue,2)));
332 Lines.append(
new Line(-30, 16, 30, 16,QPen(QPen::darkBlue,2)));
333 Lines.append(
new Line(-30, 12, 30, 12,QPen(QPen::darkBlue,2)));
334 Lines.append(
new Line(-30,-16,-30, 16,QPen(QPen::darkBlue,2)));
335 Lines.append(
new Line( 30,-16, 30, 16,QPen(QPen::darkBlue,2)));
337 Lines.append(
new Line(-30,-16, 16,-40,QPen(QPen::darkBlue,2)));
338 Lines.append(
new Line( 30,-16, 80,-40,QPen(QPen::darkBlue,2)));
339 Lines.append(
new Line( 30,-12, 80,-36,QPen(QPen::darkBlue,2)));
340 Lines.append(
new Line( 30, 12, 80,-16,QPen(QPen::darkBlue,2)));
341 Lines.append(
new Line( 30, 16, 80,-12,QPen(QPen::darkBlue,2)));
342 Lines.append(
new Line( 16,-40, 80,-40,QPen(QPen::darkBlue,2)));
343 Lines.append(
new Line( 80,-40, 80,-12,QPen(QPen::darkBlue,2)));
345 Lines.append(
new Line(-30, 0,-18,-12,QPen(QPen::darkBlue,1)));
346 Lines.append(
new Line(-22, 12, 2,-12,QPen(QPen::darkBlue,1)));
347 Lines.append(
new Line( -2, 12, 22,-12,QPen(QPen::darkBlue,1)));
348 Lines.append(
new Line( 18, 12, 30, 0,QPen(QPen::darkBlue,1)));
350 Lines.append(
new Line( 30, 1, 37, 8,QPen(QPen::darkBlue,1)));
351 Lines.append(
new Line( 37,-15, 52, 0,QPen(QPen::darkBlue,1)));
352 Lines.append(
new Line( 52,-22, 66, -8,QPen(QPen::darkBlue,1)));
353 Lines.append(
new Line( 66,-30, 80,-16,QPen(QPen::darkBlue,1)));
364 cx = -x1 + TextWidth;
367 int dx = x2-x1 + TextWidth;
368 if((x2-x1) < DragNDropWidth)
369 dx = (x2-x1 + DragNDropWidth)/2 + TextWidth;
370 if(dx < DragNDropWidth)
372 setMinimumSize(dx, y2-y1 + TextHeight+4);
373 if(width() > dx) dx = width();
374 resize(dx, y2-y1 + TextHeight+4);
383 const QString& Lib_,
const QString& Comp_)
394 QTextIStream stream(&SymbolString);
400 while(!stream.atEnd()) {
401 Line = stream.readLine();
402 Line = Line.stripWhiteSpace();
403 if(Line.isEmpty())
continue;
405 if(Line.at(0) !=
'<')
return -1;
406 if(Line.at(Line.length()-1) !=
'>')
return -1;
407 Line = Line.mid(1, Line.length()-2);
408 Result = analyseLine(Line);
409 if(Result < 0)
return -6;
417 cx = -x1 + TextWidth;
420 int dx = x2-x1 + TextWidth;
421 if((x2-x1) < DragNDropWidth)
422 dx = (x2-x1 + DragNDropWidth)/2 + TextWidth;
423 if(dx < DragNDropWidth)
425 setMinimumSize(dx, y2-y1 + TextHeight+4);
426 if(width() > dx) dx = width();
427 resize(dx, y2-y1 + TextHeight+4);
433 int SymbolWidget::analyseLine(
const QString& Row)
439 int i1, i2, i3, i4, i5, i6;
441 s = Row.section(
' ',0,0);
442 if(s ==
".PortSym") {
443 if(!getIntegers(Row, &i1, &i2, &i3))
return -1;
444 Arcs.append(
new struct Arc(i1-4, i2-4, 8, 8, 0, 16*360,
447 if((i1-4) < x1) x1 = i1-4;
448 if((i1+4) > x2) x2 = i1+4;
449 if((i2-4) < y1) y1 = i2-4;
450 if((i2+4) > y2) y2 = i2+4;
453 else if(s ==
"Line") {
454 if(!getIntegers(Row, &i1, &i2, &i3, &i4))
return -1;
455 if(!getPen(Row, Pen, 5))
return -1;
458 Lines.append(
new Line(i1, i2, i3, i4, Pen));
470 else if(s ==
"EArc") {
471 if(!getIntegers(Row, &i1, &i2, &i3, &i4, &i5, &i6))
return -1;
472 if(!getPen(Row, Pen, 7))
return -1;
473 Arcs.append(
new struct Arc(i1, i2, i3, i4, i5, i6, Pen));
476 if(i1+i3 > x2) x2 = i1+i3;
478 if(i2+i4 > y2) y2 = i2+i4;
481 else if(s ==
".ID") {
482 if(!getIntegers(Row, &i1, &i2))
return -1;
485 Prefix = Row.section(
' ',3,3);
489 else if(s ==
"Arrow") {
490 if(!getIntegers(Row, &i1, &i2, &i3, &i4, &i5, &i6))
return -1;
491 if(!getPen(Row, Pen, 7))
return -1;
493 double beta =
atan2(
double(i6),
double(i5));
494 double phi =
atan2(
double(i4),
double(i3));
495 double Length =
sqrt(
double(i6*i6 + i5*i5));
508 Lines.append(
new Line(i1, i2, i3, i4, Pen));
511 i5 = i3-int(Length*
cos(w));
512 i6 = i4-int(Length*
sin(w));
513 Lines.append(
new Line(i3, i4, i5, i6, Pen));
520 i5 = i3-int(Length*
cos(w));
521 i6 = i4-int(Length*
sin(w));
522 Lines.append(
new Line(i3, i4, i5, i6, Pen));
530 else if(s ==
"Ellipse") {
531 if(!getIntegers(Row, &i1, &i2, &i3, &i4))
return -1;
532 if(!getPen(Row, Pen, 5))
return -1;
533 if(!getBrush(Row, Brush, 8))
return -1;
534 Ellips.append(
new Area(i1, i2, i3, i4, Pen, Brush));
540 if(i1+i3 < x1) x1 = i1+i3;
541 if(i1+i3 > x2) x2 = i1+i3;
542 if(i2+i4 < y1) y1 = i2+i4;
543 if(i2+i4 > y2) y2 = i2+i4;
546 else if(s ==
"Rectangle") {
547 if(!getIntegers(Row, &i1, &i2, &i3, &i4))
return -1;
548 if(!getPen(Row, Pen, 5))
return -1;
549 if(!getBrush(Row, Brush, 8))
return -1;
550 Rects.append(
new Area(i1, i2, i3, i4, Pen, Brush));
556 if(i1+i3 < x1) x1 = i1+i3;
557 if(i1+i3 > x2) x2 = i1+i3;
558 if(i2+i4 < y1) y1 = i2+i4;
559 if(i2+i4 > y2) y2 = i2+i4;
562 else if(s ==
"Text") {
563 if(!getIntegers(Row, &i1, &i2, &i3))
return -1;
564 Color.setNamedColor(Row.section(
' ',4,4));
565 if(!Color.isValid())
return -1;
567 s = Row.mid(Row.find(
'"')+1);
568 s = s.left(s.length()-1);
569 if(s.isEmpty())
return -1;
570 s.replace(
"\\n",
"\n");
571 s.replace(
"\\\\",
"\\");
573 Texts.append(
new Text(i1, i2, s, Color,
float(i3)));
576 Font.setPointSizeFloat(
float(i3));
577 QFontMetrics metrics(Font);
578 QSize r = metrics.size(0, s);
580 i4 = i2 + r.height();
592 bool SymbolWidget::getIntegers(
const QString& s,
int *i1,
int *i2,
int *i3,
593 int *i4,
int *i5,
int *i6)
599 n = s.section(
' ',1,1);
601 if(!ok)
return false;
604 n = s.section(
' ',2,2);
606 if(!ok)
return false;
609 n = s.section(
' ',3,3);
611 if(!ok)
return false;
614 n = s.section(
' ',4,4);
616 if(!ok)
return false;
619 n = s.section(
' ',5,5);
621 if(!ok)
return false;
624 n = s.section(
' ',6,6);
626 if(!ok)
return false;
632 bool SymbolWidget::getPen(
const QString& s, QPen& Pen,
int i)
637 n = s.section(
' ',i,i);
641 if(!Pen.color().isValid())
return false;
644 n = s.section(
' ',i,i);
645 Pen.setWidth(n.toInt(&ok));
646 if(!ok)
return false;
649 n = s.section(
' ',i,i);
650 Pen.setStyle((Qt::PenStyle)n.toInt(&ok));
651 if(!ok)
return false;
657 bool SymbolWidget::getBrush(
const QString& s, QBrush& Brush,
int i)
662 n = s.section(
' ',i,i);
666 if(!Brush.color().isValid())
return false;
669 n = s.section(
' ',i,i);
670 Brush.setStyle((Qt::BrushStyle)n.toInt(&ok));
671 if(!ok)
return false;
674 n = s.section(
' ',i,i);
675 if(n.toInt(&ok) == 0) Brush.setStyle(QBrush::NoBrush);
676 if(!ok)
return false;