My Project
0.0.16
QUCS Mapping
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
DownLoad
QUCS-src
qucs-0.0.16
qucs
module.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
module.cpp
3
------------
4
begin : Thu Nov 5 2009
5
copyright : (C) 2009 by Stefan Jahn
6
email : stefan@lkcc.org
7
***************************************************************************/
8
9
/***************************************************************************
10
* *
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
15
* *
16
***************************************************************************/
17
18
#include <qdict.h>
19
#include <qstring.h>
20
#include <qstringlist.h>
21
22
#include "
element.h
"
23
#include "components/component.h"
24
#include "components/components.h"
25
#include "
paintings/paintings.h
"
26
#include "
diagrams/diagrams.h
"
27
#include "
module.h
"
28
29
// Global category and component lists.
30
QDict<Module>
Module::Modules
;
31
QPtrList<Category>
Category::Categories
;
32
33
// Constructor creates instance of module object.
34
Module::Module
() {
35
info
= 0;
36
category
=
"#special"
;
37
}
38
39
// Destructor removes instance of module object from memory.
40
Module::~Module
() {
41
}
42
43
// Module registration using a category name and the appropriate
44
// function returning a modules instance object.
45
void
Module::registerModule
(QString category,
pInfoFunc
info) {
46
Module
* m =
new
Module
();
47
m->
info
=
info
;
48
m->
category
=
category
;
49
intoCategory
(m);
50
}
51
52
// Component registration using a category name and the appropriate
53
// function returning a components instance object.
54
void
Module::registerComponent
(QString category,
pInfoFunc
info) {
55
Module
* m =
new
Module
();
56
m->
info
=
info
;
57
m->
category
=
category
;
58
59
// instantiation of the component once in order to obtain "Model"
60
// property of the component
61
QString Name, Model;
62
char
*
File
;
63
Component
*
c
= (
Component
*) info (Name, File,
true
);
64
Model = c->
Model
;
65
delete
c
;
66
67
// put into category and the component hash
68
intoCategory
(m);
69
if
(!
Modules
.find (Model))
70
Modules
.insert (Model, m);
71
}
72
73
// Returns instantiated component based on the given "Model" name. If
74
// there is no such component registers the function returns NULL.
75
Component
*
Module::getComponent
(QString Model) {
76
Module
* m =
Modules
.find (Model);
77
if
(m) {
78
QString Name;
79
char
*
File
;
80
return
(
Component
*) m->
info
(Name, File,
true
);
81
}
82
return
0;
83
}
84
85
// The function appends the given module to the appropriate category.
86
// If there is no such category yet, then the category gets created.
87
void
Module::intoCategory
(
Module
* m) {
88
89
// look through existing categories
90
Category
* cat =
Category::Categories
.first ();
91
for
(; cat; cat =
Category::Categories
.next ()) {
92
if
(cat->
Name
== m->
category
) {
93
cat->
Content
.append (m);
94
break
;
95
}
96
}
97
98
// if there is no such category, then create it
99
if
(!cat) {
100
cat =
new
Category
(m->
category
);
101
Category::Categories
.append (cat);
102
cat->
Content
.append (m);
103
}
104
}
105
106
// Helper macros for module registration.
107
#define REGISTER_MOD_1(cat,val) \
108
registerModule (cat, &val::info)
109
#define REGISTER_MOD_2(cat,val,inf1,inf2) \
110
registerModule (cat, &val::inf1); \
111
registerModule (cat, &val::inf2)
112
#define REGISTER_MOD_3(cat,val,inf1,inf2,inf3) \
113
registerModule (cat, &val::inf1); \
114
registerModule (cat, &val::inf2); \
115
registerModule (cat, &val::inf3)
116
117
#define REGISTER_COMP_1(cat,val) \
118
registerComponent (cat, &val::info)
119
#define REGISTER_COMP_2(cat,val,inf1,inf2) \
120
registerComponent (cat, &val::inf1); \
121
registerComponent (cat, &val::inf2)
122
#define REGISTER_COMP_3(cat,val,inf1,inf2,inf3) \
123
registerComponent (cat, &val::inf1); \
124
registerComponent (cat, &val::inf2); \
125
registerComponent (cat, &val::inf3)
126
127
#define REGISTER_LUMPED_1(val) \
128
REGISTER_COMP_1 (QObject::tr("lumped components"),val)
129
#define REGISTER_LUMPED_2(val,inf1,inf2) \
130
REGISTER_COMP_2 (QObject::tr("lumped components"),val,inf1,inf2)
131
#define REGISTER_SOURCE_1(val) \
132
REGISTER_COMP_1 (QObject::tr("sources"),val)
133
#define REGISTER_PROBE_1(val) \
134
REGISTER_COMP_1 (QObject::tr("probes"),val)
135
#define REGISTER_TRANS_1(val) \
136
REGISTER_COMP_1 (QObject::tr("transmission lines"),val)
137
#define REGISTER_NONLINEAR_1(val) \
138
REGISTER_COMP_1 (QObject::tr("nonlinear components"),val)
139
#define REGISTER_NONLINEAR_2(val,inf1,inf2) \
140
REGISTER_COMP_2 (QObject::tr("nonlinear components"),val,inf1,inf2)
141
#define REGISTER_NONLINEAR_3(val,inf1,inf2,inf3) \
142
REGISTER_COMP_3 (QObject::tr("nonlinear components"),val,inf1,inf2,inf3)
143
#define REGISTER_VERILOGA_1(val) \
144
REGISTER_COMP_1 (QObject::tr("verilog-a devices"),val)
145
#define REGISTER_VERILOGA_2(val,inf1,inf2) \
146
REGISTER_COMP_2 (QObject::tr("verilog-a devices"),val,inf1,inf2)
147
#define REGISTER_DIGITAL_1(val) \
148
REGISTER_COMP_1 (QObject::tr("digital components"),val)
149
#define REGISTER_FILE_1(val) \
150
REGISTER_COMP_1 (QObject::tr("file components"),val)
151
#define REGISTER_FILE_3(val,inf1,inf2,inf3) \
152
REGISTER_COMP_3 (QObject::tr("file components"),val,inf1,inf2,inf3)
153
#define REGISTER_SIMULATION_1(val) \
154
REGISTER_COMP_1 (QObject::tr("simulations"),val)
155
#define REGISTER_DIAGRAM_1(val) \
156
REGISTER_MOD_1 (QObject::tr("diagrams"),val)
157
#define REGISTER_DIAGRAM_2(val,inf1,inf2) \
158
REGISTER_MOD_2 (QObject::tr("diagrams"),val,inf1,inf2)
159
#define REGISTER_PAINT_1(val) \
160
REGISTER_MOD_1 (QObject::tr("paintings"),val)
161
#define REGISTER_PAINT_2(val,inf1,inf2) \
162
REGISTER_MOD_2 (QObject::tr("paintings"),val,inf1,inf2)
163
164
// This function has to be called once at application startup. It
165
// registers every component available in the application. Put here
166
// any new component.
167
void
Module::registerModules
(
void
) {
168
169
// lumped components
170
REGISTER_LUMPED_2
(
Resistor
,
info
, info_us);
171
REGISTER_LUMPED_1
(
Capacitor
);
172
REGISTER_LUMPED_1
(
Inductor
);
173
REGISTER_LUMPED_1
(
Ground
);
174
REGISTER_LUMPED_1
(
SubCirPort
);
175
REGISTER_LUMPED_1
(
Transformer
);
176
REGISTER_LUMPED_1
(
symTrafo
);
177
REGISTER_LUMPED_1
(
dcBlock
);
178
REGISTER_LUMPED_1
(
dcFeed
);
179
REGISTER_LUMPED_1
(
BiasT
);
180
REGISTER_LUMPED_1
(
Attenuator
);
181
REGISTER_LUMPED_1
(
Amplifier
);
182
REGISTER_LUMPED_1
(
Isolator
);
183
REGISTER_LUMPED_1
(
Circulator
);
184
REGISTER_LUMPED_1
(
Gyrator
);
185
REGISTER_LUMPED_1
(
Phaseshifter
);
186
REGISTER_LUMPED_1
(
Coupler
);
187
REGISTER_LUMPED_1
(
Hybrid
);
188
REGISTER_LUMPED_1
(
iProbe
);
189
REGISTER_LUMPED_1
(
vProbe
);
190
REGISTER_LUMPED_1
(
Mutual
);
191
REGISTER_LUMPED_1
(
Mutual2
);
192
REGISTER_LUMPED_1
(
Switch
);
193
REGISTER_LUMPED_1
(
Relais
);
194
REGISTER_LUMPED_1
(
RFedd
);
195
REGISTER_LUMPED_1
(
RFedd2P
);
196
197
// sources
198
REGISTER_SOURCE_1
(
Volt_dc
);
199
REGISTER_SOURCE_1
(
Ampere_dc
);
200
REGISTER_SOURCE_1
(
Volt_ac
);
201
REGISTER_SOURCE_1
(
Ampere_ac
);
202
REGISTER_SOURCE_1
(
Source_ac
);
203
REGISTER_SOURCE_1
(
Volt_noise
);
204
REGISTER_SOURCE_1
(
Ampere_noise
);
205
REGISTER_SOURCE_1
(
VCCS
);
206
REGISTER_SOURCE_1
(
CCCS
);
207
REGISTER_SOURCE_1
(
VCVS
);
208
REGISTER_SOURCE_1
(
CCVS
);
209
REGISTER_SOURCE_1
(
vPulse
);
210
REGISTER_SOURCE_1
(
iPulse
);
211
REGISTER_SOURCE_1
(
vRect
);
212
REGISTER_SOURCE_1
(
iRect
);
213
REGISTER_SOURCE_1
(
Noise_ii
);
214
REGISTER_SOURCE_1
(
Noise_vv
);
215
REGISTER_SOURCE_1
(
Noise_iv
);
216
REGISTER_SOURCE_1
(
AM_Modulator
);
217
REGISTER_SOURCE_1
(
PM_Modulator
);
218
REGISTER_SOURCE_1
(
iExp
);
219
REGISTER_SOURCE_1
(
vExp
);
220
REGISTER_SOURCE_1
(
vFile
);
221
REGISTER_SOURCE_1
(
iFile
);
222
223
// probes
224
REGISTER_PROBE_1
(
iProbe
);
225
REGISTER_PROBE_1
(
vProbe
);
226
227
// transmission lines
228
REGISTER_TRANS_1
(
TLine
);
229
REGISTER_TRANS_1
(
TLine_4Port
);
230
REGISTER_TRANS_1
(
CoupledTLine
);
231
REGISTER_TRANS_1
(
TwistedPair
);
232
REGISTER_TRANS_1
(
CoaxialLine
);
233
REGISTER_TRANS_1
(
RectLine
);
234
REGISTER_TRANS_1
(
RLCG
);
235
REGISTER_TRANS_1
(
Substrate
);
236
REGISTER_TRANS_1
(
MSline
);
237
REGISTER_TRANS_1
(
MScoupled
);
238
REGISTER_TRANS_1
(
MScorner
);
239
REGISTER_TRANS_1
(
MSmbend
);
240
REGISTER_TRANS_1
(
MSstep
);
241
REGISTER_TRANS_1
(
MStee
);
242
REGISTER_TRANS_1
(
MScross
);
243
REGISTER_TRANS_1
(
MSopen
);
244
REGISTER_TRANS_1
(
MSgap
);
245
REGISTER_TRANS_1
(
MSvia
);
246
REGISTER_TRANS_1
(
MSrstub
);
247
REGISTER_TRANS_1
(
Coplanar
);
248
REGISTER_TRANS_1
(
CPWopen
);
249
REGISTER_TRANS_1
(
CPWshort
);
250
REGISTER_TRANS_1
(
CPWgap
);
251
REGISTER_TRANS_1
(
CPWstep
);
252
REGISTER_TRANS_1
(
BondWire
);
253
254
// nonlinear components
255
REGISTER_NONLINEAR_1
(
Diode
);
256
REGISTER_NONLINEAR_2
(
BJT
,
info
, info_pnp);
257
REGISTER_NONLINEAR_2
(
BJTsub
,
info
, info_pnp);
258
REGISTER_NONLINEAR_2
(
JFET
,
info
, info_p);
259
REGISTER_NONLINEAR_3
(
MOSFET
,
info
, info_p, info_depl);
260
REGISTER_NONLINEAR_3
(
MOSFET_sub
,
info
, info_p, info_depl);
261
REGISTER_NONLINEAR_1
(
OpAmp
);
262
REGISTER_NONLINEAR_1
(
EqnDefined
);
263
REGISTER_NONLINEAR_1
(
Diac
);
264
REGISTER_NONLINEAR_1
(
Triac
);
265
REGISTER_NONLINEAR_1
(
Thyristor
);
266
REGISTER_NONLINEAR_1
(
TunnelDiode
);
267
268
// verilog-a devices
269
REGISTER_VERILOGA_1
(
hicumL2V2p1
);
270
REGISTER_VERILOGA_1
(
HBT_X
);
271
REGISTER_VERILOGA_1
(
mod_amp
);
272
REGISTER_VERILOGA_1
(
hic2_full
);
273
REGISTER_VERILOGA_1
(
log_amp
);
274
REGISTER_VERILOGA_2
(
hic0_full
,
info
, info_pnp);
275
REGISTER_VERILOGA_1
(
potentiometer
);
276
REGISTER_VERILOGA_1
(
MESFET
);
277
REGISTER_VERILOGA_2
(
EKV26MOS
,
info
, info_pmos);
278
REGISTER_VERILOGA_2
(
hicumL0V1p2
,
info
, info_pnp);
279
REGISTER_VERILOGA_2
(
hicumL0V1p2g
,
info
, info_pnp);
280
REGISTER_VERILOGA_2
(
hicumL0V1p3
,
info
, info_pnp);
281
REGISTER_VERILOGA_1
(
hicumL2V2p23
);
282
REGISTER_VERILOGA_1
(
hicumL2V2p24
);
283
REGISTER_VERILOGA_1
(
photodiode
);
284
REGISTER_VERILOGA_1
(
phototransistor
);
285
REGISTER_VERILOGA_1
(
nigbt
);
286
287
// digital components
288
REGISTER_DIGITAL_1
(
Digi_Source
);
289
REGISTER_DIGITAL_1
(
Logical_Inv
);
290
REGISTER_DIGITAL_1
(
Logical_OR
);
291
REGISTER_DIGITAL_1
(
Logical_NOR
);
292
REGISTER_DIGITAL_1
(
Logical_AND
);
293
REGISTER_DIGITAL_1
(
Logical_NAND
);
294
REGISTER_DIGITAL_1
(
Logical_XOR
);
295
REGISTER_DIGITAL_1
(
Logical_XNOR
);
296
REGISTER_DIGITAL_1
(
Logical_Buf
);
297
REGISTER_DIGITAL_1
(
andor4x2
);
298
REGISTER_DIGITAL_1
(
andor4x3
);
299
REGISTER_DIGITAL_1
(
andor4x4
);
300
REGISTER_DIGITAL_1
(
mux2to1
);
301
REGISTER_DIGITAL_1
(
mux4to1
);
302
REGISTER_DIGITAL_1
(
mux8to1
);
303
REGISTER_DIGITAL_1
(
dmux2to4
);
304
REGISTER_DIGITAL_1
(
dmux3to8
);
305
REGISTER_DIGITAL_1
(
dmux4to16
);
306
REGISTER_DIGITAL_1
(
ha1b
);
307
REGISTER_DIGITAL_1
(
fa1b
);
308
REGISTER_DIGITAL_1
(
fa2b
);
309
REGISTER_DIGITAL_1
(
RS_FlipFlop
);
310
REGISTER_DIGITAL_1
(
D_FlipFlop
);
311
REGISTER_DIGITAL_1
(
dff_SR
);
312
REGISTER_DIGITAL_1
(
JK_FlipFlop
);
313
REGISTER_DIGITAL_1
(
jkff_SR
);
314
REGISTER_DIGITAL_1
(
tff_SR
);
315
REGISTER_DIGITAL_1
(
gatedDlatch
);
316
REGISTER_DIGITAL_1
(
logic_0
);
317
REGISTER_DIGITAL_1
(
logic_1
);
318
REGISTER_DIGITAL_1
(
pad2bit
);
319
REGISTER_DIGITAL_1
(
pad3bit
);
320
REGISTER_DIGITAL_1
(
pad4bit
);
321
REGISTER_DIGITAL_1
(
DLS_nto1
);
322
REGISTER_DIGITAL_1
(
DLS_1ton
);
323
REGISTER_DIGITAL_1
(
binarytogrey4bit
);
324
REGISTER_DIGITAL_1
(
greytobinary4bit
);
325
REGISTER_DIGITAL_1
(
comp_1bit
);
326
REGISTER_DIGITAL_1
(
comp_2bit
);
327
REGISTER_DIGITAL_1
(
comp_4bit
);
328
REGISTER_DIGITAL_1
(
hpribin4bit
);
329
REGISTER_DIGITAL_1
(
VHDL_File
);
330
REGISTER_DIGITAL_1
(
Verilog_File
);
331
REGISTER_DIGITAL_1
(
Digi_Sim
);
332
333
// file components
334
REGISTER_FILE_1
(
SpiceFile
);
335
REGISTER_FILE_3
(
SParamFile
, info1, info2,
info
);
336
REGISTER_FILE_1
(
Subcircuit
);
337
338
// simulations
339
REGISTER_SIMULATION_1
(
DC_Sim
);
340
REGISTER_SIMULATION_1
(
TR_Sim
);
341
REGISTER_SIMULATION_1
(
AC_Sim
);
342
REGISTER_SIMULATION_1
(
SP_Sim
);
343
REGISTER_SIMULATION_1
(
HB_Sim
);
344
REGISTER_SIMULATION_1
(
Param_Sweep
);
345
REGISTER_SIMULATION_1
(
Digi_Sim
);
346
REGISTER_SIMULATION_1
(
Optimize_Sim
);
347
348
// diagrams
349
REGISTER_DIAGRAM_1
(
RectDiagram
);
350
REGISTER_DIAGRAM_1
(
PolarDiagram
);
351
REGISTER_DIAGRAM_1
(
TabDiagram
);
352
REGISTER_DIAGRAM_2
(
SmithDiagram
,
info
, info_y);
353
REGISTER_DIAGRAM_2
(
PSDiagram
,
info
, info_sp);
354
REGISTER_DIAGRAM_1
(
Rect3DDiagram
);
355
REGISTER_DIAGRAM_1
(
CurveDiagram
);
356
REGISTER_DIAGRAM_1
(
TimingDiagram
);
357
REGISTER_DIAGRAM_1
(
TruthDiagram
);
358
359
// paintings
360
REGISTER_PAINT_1
(
GraphicLine
);
361
REGISTER_PAINT_1
(
Arrow
);
362
REGISTER_PAINT_1
(
GraphicText
);
363
REGISTER_PAINT_2
(
Ellipse
,
info
, info_filled);
364
REGISTER_PAINT_2
(
Rectangle
,
info
, info_filled);
365
REGISTER_PAINT_1
(
EllipseArc
);
366
}
367
368
// This function has to be called once at application end. It removes
369
// all categories and registered modules from memory.
370
void
Module::unregisterModules
(
void
) {
371
Category::Categories
.setAutoDelete (
true
);
372
Category::Categories
.clear ();
373
Modules
.clear ();
374
}
375
376
// Constructor creates instance of module object.
377
Category::Category
() {
378
Name
=
"#special"
;
379
Content
.clear ();
380
}
381
382
// Constructor creates named instance of module object.
383
Category::Category
(
const
QString name) {
384
Name
= name;
385
Content
.clear ();
386
}
387
388
// Destructor removes instance of module object from memory.
389
Category::~Category
() {
390
Content
.setAutoDelete (
true
);
391
Content
.clear ();
392
}
393
394
// Returns the available category names in a list of strings.
395
QStringList
Category::getCategories
(
void
) {
396
QStringList res;
397
Category
* cat =
Categories
.first ();
398
for
(; cat; cat =
Categories
.next ()) {
399
res.append (cat->
Name
);
400
}
401
return
res;
402
}
403
404
// The function returns the registered modules in the given category
405
// as a pointer list. The pointer list is empty if there is no such
406
// category available.
407
QPtrList<Module>
Category::getModules
(QString category) {
408
QPtrList<Module> res;
409
Category
* cat =
Categories
.first ();
410
for
(; cat; cat =
Categories
.next ()) {
411
if
(category == cat->
Name
)
412
res = cat->
Content
;
413
}
414
return
res;
415
}
416
417
// Returns the index number into the category list for the given
418
// category name. The function returns zero if there is no such
419
// category.
420
int
Category::getModulesNr
(QString category) {
421
Category
* cat =
Categories
.first ();
422
for
(
int
i
= 0; cat; cat =
Categories
.next (),
i
++) {
423
if
(category == cat->
Name
)
424
return
i
;
425
}
426
return
0;
427
}
Generated on Tue Dec 25 2012 14:30:43 for My Project by
1.8.2