-
-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathelement.h
213 lines (183 loc) · 6.46 KB
/
element.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/***************************************************************************
element.h
-----------
begin : Sat Sep 20 2003
copyright : (C) 2003 by Michael Margraf
email : michael.margraf@alumni.tu-berlin.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/** \file element.h
* \brief Defines drawing elements for schematics
*
* element.h contains definitions of various drawing elements used
* used to render schematics and the schematic symbols. The following
* structs are defined to hold information on various drawing types:
*
* Line
* Arc
* Area
* Port
* Text
* Property
*
* The Element class is also defined here which is a superclass
* of every component symbol.
*
*/
#ifndef ELEMENT_H
#define ELEMENT_H
#include <QPen>
#include <vector>
class Node;
class Schematic;
namespace qucs { // otherwise conflict with <windows.h>
// coming from Qt5 headers
class DrawingPrimitive {
public:
virtual ~DrawingPrimitive() {}
virtual void draw([[maybe_unused]] QPainter* painter) const {};
virtual QBrush brushHint() const { return Qt::NoBrush; }
virtual QPen penHint() const { return Qt::NoPen; }
};
struct Line : DrawingPrimitive {
Line(double _x1, double _y1, double _x2, double _y2, QPen _style)
: x1(_x1), y1(_y1), x2(_x2), y2(_y2), style(_style) {};
virtual ~Line() {}
double x1, y1, x2, y2;
QPen style;
void draw(QPainter* painter) const override;
QPen penHint() const override { return style; }
};
struct Arc : DrawingPrimitive {
Arc(double _x, double _y, double _w, double _h, int _angle, int _arclen, QPen _style)
: x(_x), y(_y), w(_w), h(_h), angle(_angle),
arclen(_arclen), style(_style) {};
virtual ~Arc() {}
double x, y, w, h;
int angle, arclen;
QPen style;
void draw(QPainter* painter) const override;
QPen penHint() const override { return style; }
};
struct Rect : DrawingPrimitive {
Rect(double _x, double _y, double _w, double _h, QPen _Pen,
QBrush _Brush = QBrush(Qt::NoBrush))
: x(_x), y(_y), w(_w), h(_h), Pen(_Pen), Brush(_Brush) {};
double x, y, w, h;
QPen Pen;
QBrush Brush; // filling style/color
void draw(QPainter* painter) const override;
QPen penHint() const override { return Pen; }
QBrush brushHint() const override { return Brush; }
};
// 'ellipse' conflicts 'ellipse' defined in paintings.h in the same namespace
struct Ellips : DrawingPrimitive {
Ellips(double _x, double _y, double _w, double _h, QPen _Pen,
QBrush _Brush = QBrush(Qt::NoBrush))
: x(_x), y(_y), w(_w), h(_h), Pen(_Pen), Brush(_Brush) {};
double x, y, w, h;
QPen Pen;
QBrush Brush; // filling style/color
void draw(QPainter* painter) const override;
QPen penHint() const override { return Pen; }
QBrush brushHint() const override { return Brush; }
};
struct Polyline : DrawingPrimitive {
std::vector<QPointF> points;
QPen pen;
QBrush brush;
Polyline(const std::vector<QPointF> &pts, QPen p = QPen{Qt::NoPen}, QBrush b = QBrush{Qt::NoBrush})
: points(pts), pen{p}, brush{b} {};
void draw(QPainter* painter) const override;
QPen penHint() const override { return pen; }
QBrush brushHint() const override { return brush; }
};
}
struct Port {
Port() {};
Port(int _x, int _y, bool _avail=true) : x(_x), y(_y), avail(_avail) {
Type=""; Connection=0;};
int x, y;
bool avail;
QString Type;
Node *Connection;
};
struct Text : qucs::DrawingPrimitive {
Text(double _x, double _y, const QString& _s, QColor _Color = QColor(0,0,0),
double _Size = 10.0, double _mCos=1.0, double _mSin=0.0)
: x(_x), y(_y), s(_s), Color(_Color), Size(_Size),
mSin(_mSin), mCos(_mCos) { over = under = false; };
virtual ~Text() {}
double x, y;
QString s;
QColor Color;
double Size, mSin, mCos; // font size and rotation coefficients
bool over, under; // text attributes
void draw(QPainter *painter) const override;
void draw(QPainter* painter, QRectF* br) const;
QPen penHint() const override { return Color; }
double angle() const;
};
struct Property {
Property(const QString& _Name="", const QString& _Value="",
bool _display=false, const QString& Desc="")
: Name(_Name), Value(_Value), display(_display), Description(Desc) {};
QString Name, Value;
bool display; // show on schematic or not ?
QString Description;
QRect boundingRect() const { return br; };
void paint(int x, int y, QPainter* p);
private:
QRect br;
};
// valid values for Element.Type
// The 4 least significant bits of each value are reserved for special
// additionals !!!
#define isDummyElement 0
#define isSpecialMask -16
#define isComponent 0x30000
#define isComponentText 0x30002
#define isAnalogComponent 0x10000
#define isDigitalComponent 0x20000
#define isGraph 0x0020
#define isNode 0x0040
#define isMarker 0x0080
#define isWire 0x0100
#define isPainting 0x2000
#define isPaintingResize 0x2001
#define isLabel 0x4000
#define isHWireLabel 0x4020
#define isVWireLabel 0x4040
#define isNodeLabel 0x4080
#define isMovingLabel 0x4001
#define isHMovingLabel 0x4002
#define isVMovingLabel 0x4004
#define isDiagram 0x8000
#define isDiagramResize 0x8001
#define isDiagramHScroll 0x8002
#define isDiagramVScroll 0x8003
/** \class Element
* \brief Superclass of all schematic drawing elements
*
*
*/
class Element {
public:
Element();
virtual ~Element();
virtual void paintScheme(Schematic *);
virtual void paintScheme(QPainter *);
virtual void setCenter(int, int, bool relative=false);
virtual void getCenter(int&, int&);
bool isSelected;
int Type; // whether it is Component, Wire, ...
int cx, cy, x1, y1, x2, y2; // center and relative boundings
};
#endif