Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 #include <QtGui>
18 #include <Q3Dict>
19 #include <QString>
20 #include <QStringList>
21 //Added by qt3to4:
22 #include <Q3PtrList>
23 
24 #include "element.h"
25 #include "components/component.h"
26 #include "components/components.h"
27 #include "paintings/paintings.h"
28 #include "diagrams/diagrams.h"
29 #include "module.h"
30 
31 // Global category and component lists.
32 Q3Dict<Module> Module::Modules;
33 Q3PtrList<Category> Category::Categories;
34 
35 QMap<QString, QString> Module::vaComponents;
36 
37 // Constructor creates instance of module object.
39  info = 0;
40  category = "#special";
41 }
42 
43 // Destructor removes instance of module object from memory.
45 }
46 
47 // Module registration using a category name and the appropriate
48 // function returning a modules instance object.
49 void Module::registerModule (QString category, pInfoFunc info) {
50  Module * m = new Module ();
51  m->info = info;
52  m->category = category;
53  intoCategory (m);
54 }
55 
56 // Component registration using a category name and the appropriate
57 // function returning a components instance object.
58 void Module::registerComponent (QString category, pInfoFunc info) {
59  Module * m = new Module ();
60  m->info = info;
61  m->category = category;
62 
63  // instantiation of the component once in order to obtain "Model"
64  // property of the component
65  QString Name, Model;
66  char * File;
67  Component * c = (Component *) info (Name, File, true);
68  Model = c->Model;
69  delete c;
70 
71  // put into category and the component hash
72  intoCategory (m);
73  if (!Modules.find (Model))
74  Modules.insert (Model, m);
75 }
76 
77 // Returns instantiated component based on the given "Model" name. If
78 // there is no such component registers the function returns NULL.
79 Component * Module::getComponent (QString Model) {
80  Module * m = Modules.find (Model);
81  if (m) {
82  QString Name;
83  char * File;
84  QString vaBitmap;
85  if (vaComponents.contains(Model))
86  return (Component *)
87  vacomponent::info (Name, vaBitmap, true, vaComponents[Model]);
88  else
89  return (Component *) m->info (Name, File, true);
90  }
91  return 0;
92 }
93 
95 {
96  qDebug() << "Module::registerDynamicComponents()";
97 
98 
99  // vaComponents is populated in QucsApp::slotLoadModule
100 
101  // register modules symbol and properties out of in vaComponents
102  QMapIterator<QString, QString> i(vaComponents);
103  while (i.hasNext()) {
104  i.next();
105 
106 // qDebug() << i.key() << ": " << i.value() << endl;
107 
108  Module * m = new Module ();
109 
110  // what now? pointer to info?
111 
112  // the typedef needs to be different
113  //passes the pointer, but it has no idea how to call the JSON
115 
116  // TODO maybe allow user load into custom category?
117  m->category = QObject::tr("verilog-a user devices");
118 
119  // instantiation of the component once in order
120  // to obtain "Model" property of the component
121  //QString Name, Model;
122  //char * File;
123  QString Name, Model, vaBitmap;
124 // char * File;
125  Component * c = (Component *)
126  vacomponent::info (Name, vaBitmap, true, vaComponents[i.key()]);
127  Model = c->Model;
128  delete c;
129 
130  // put into category and the component hash
131  intoCategory (m);
132 
133  if (!Modules.find (Model))
134  Modules.insert (Model, m);
135 
136  } // while
137 }
138 
139 // The function appends the given module to the appropriate category.
140 // If there is no such category yet, then the category gets created.
142 
143  // look through existing categories
144  Category * cat = Category::Categories.first ();
145  for (; cat; cat = Category::Categories.next ()) {
146  if (cat->Name == m->category) {
147  cat->Content.append (m);
148  break;
149  }
150  }
151 
152  // if there is no such category, then create it
153  if (!cat) {
154  cat = new Category (m->category);
155  Category::Categories.append (cat);
156  cat->Content.append (m);
157  }
158 }
159 
160 // Helper macros for module registration.
161 #define REGISTER_MOD_1(cat,val) \
162  registerModule (cat, &val::info)
163 #define REGISTER_MOD_2(cat,val,inf1,inf2) \
164  registerModule (cat, &val::inf1); \
165  registerModule (cat, &val::inf2)
166 #define REGISTER_MOD_3(cat,val,inf1,inf2,inf3) \
167  registerModule (cat, &val::inf1); \
168  registerModule (cat, &val::inf2); \
169  registerModule (cat, &val::inf3)
170 
171 #define REGISTER_COMP_1(cat,val) \
172  registerComponent (cat, &val::info)
173 #define REGISTER_COMP_2(cat,val,inf1,inf2) \
174  registerComponent (cat, &val::inf1); \
175  registerComponent (cat, &val::inf2)
176 #define REGISTER_COMP_3(cat,val,inf1,inf2,inf3) \
177  registerComponent (cat, &val::inf1); \
178  registerComponent (cat, &val::inf2); \
179  registerComponent (cat, &val::inf3)
180 
181 #define REGISTER_LUMPED_1(val) \
182  REGISTER_COMP_1 (QObject::tr("lumped components"),val)
183 #define REGISTER_LUMPED_2(val,inf1,inf2) \
184  REGISTER_COMP_2 (QObject::tr("lumped components"),val,inf1,inf2)
185 #define REGISTER_SOURCE_1(val) \
186  REGISTER_COMP_1 (QObject::tr("sources"),val)
187 #define REGISTER_PROBE_1(val) \
188  REGISTER_COMP_1 (QObject::tr("probes"),val)
189 #define REGISTER_TRANS_1(val) \
190  REGISTER_COMP_1 (QObject::tr("transmission lines"),val)
191 #define REGISTER_NONLINEAR_1(val) \
192  REGISTER_COMP_1 (QObject::tr("nonlinear components"),val)
193 #define REGISTER_NONLINEAR_2(val,inf1,inf2) \
194  REGISTER_COMP_2 (QObject::tr("nonlinear components"),val,inf1,inf2)
195 #define REGISTER_NONLINEAR_3(val,inf1,inf2,inf3) \
196  REGISTER_COMP_3 (QObject::tr("nonlinear components"),val,inf1,inf2,inf3)
197 #define REGISTER_VERILOGA_1(val) \
198  REGISTER_COMP_1 (QObject::tr("verilog-a devices"),val)
199 #define REGISTER_VERILOGA_2(val,inf1,inf2) \
200  REGISTER_COMP_2 (QObject::tr("verilog-a devices"),val,inf1,inf2)
201 #define REGISTER_DIGITAL_1(val) \
202  REGISTER_COMP_1 (QObject::tr("digital components"),val)
203 #define REGISTER_FILE_1(val) \
204  REGISTER_COMP_1 (QObject::tr("file components"),val)
205 #define REGISTER_FILE_3(val,inf1,inf2,inf3) \
206  REGISTER_COMP_3 (QObject::tr("file components"),val,inf1,inf2,inf3)
207 #define REGISTER_SIMULATION_1(val) \
208  REGISTER_COMP_1 (QObject::tr("simulations"),val)
209 #define REGISTER_DIAGRAM_1(val) \
210  REGISTER_MOD_1 (QObject::tr("diagrams"),val)
211 #define REGISTER_DIAGRAM_2(val,inf1,inf2) \
212  REGISTER_MOD_2 (QObject::tr("diagrams"),val,inf1,inf2)
213 #define REGISTER_PAINT_1(val) \
214  REGISTER_MOD_1 (QObject::tr("paintings"),val)
215 #define REGISTER_PAINT_2(val,inf1,inf2) \
216  REGISTER_MOD_2 (QObject::tr("paintings"),val,inf1,inf2)
217 #define REGISTER_EXTERNAL_1(val) \
218  REGISTER_COMP_1 (QObject::tr("external sim components"),val)
219 
220 // This function has to be called once at application startup. It
221 // registers every component available in the application. Put here
222 // any new component.
224 
225  // lumped components
226  REGISTER_LUMPED_2 (Resistor, info, info_us);
252 
253  // sources
278 
279  // probes
282 
283  // transmission lines
310 
311  // nonlinear components
313  REGISTER_NONLINEAR_2 (BJT, info, info_pnp);
314  REGISTER_NONLINEAR_2 (BJTsub, info, info_pnp);
315  REGISTER_NONLINEAR_2 (JFET, info, info_p);
316  REGISTER_NONLINEAR_3 (MOSFET, info, info_p, info_depl);
317  REGISTER_NONLINEAR_3 (MOSFET_sub, info, info_p, info_depl);
324 
325  // verilog-a devices
331  REGISTER_VERILOGA_2 (hic0_full, info, info_pnp);
334  REGISTER_VERILOGA_2 (EKV26MOS, info, info_pmos);
339  REGISTER_VERILOGA_2 (hicumL0V1p2, info, info_pnp);
341  REGISTER_VERILOGA_2 (hicumL0V1p3, info, info_pnp);
349 
350  // digital components
395 
396  // file components
398  REGISTER_FILE_3 (SParamFile, info1, info2, info);
400 
401  // simulations
410 
411  // diagrams
416  REGISTER_DIAGRAM_2 (PSDiagram, info, info_sp);
421 
422  // external simulation
425 
426  // paintings
430  REGISTER_PAINT_2 (Ellipse, info, info_filled);
431  REGISTER_PAINT_2 (Rectangle, info, info_filled);
433 
434 }
435 
436 // This function has to be called once at application end. It removes
437 // all categories and registered modules from memory.
439  Category::Categories.setAutoDelete (true);
440  Category::Categories.clear ();
441  Modules.clear ();
442 }
443 
444 // Constructor creates instance of module object.
446  Name = "#special";
447  Content.clear ();
448 }
449 
450 // Constructor creates named instance of module object.
451 Category::Category (const QString name) {
452  Name = name;
453  Content.clear ();
454 }
455 
456 // Destructor removes instance of module object from memory.
458  Content.setAutoDelete (true);
459  Content.clear ();
460 }
461 
462 // Returns the available category names in a list of strings.
463 QStringList Category::getCategories (void) {
464  QStringList res;
465  Category * cat = Categories.first ();
466  for (; cat; cat = Categories.next ()) {
467  res.append (cat->Name);
468  }
469  return res;
470 }
471 
472 // The function returns the registered modules in the given category
473 // as a pointer list. The pointer list is empty if there is no such
474 // category available.
475 Q3PtrList<Module> Category::getModules (QString category) {
476  Q3PtrList<Module> res;
477  Category * cat = Categories.first ();
478  for (; cat; cat = Categories.next ()) {
479  if (category == cat->Name)
480  res = cat->Content;
481  }
482  return res;
483 }
484 
485 // Returns the index number into the category list for the given
486 // category name. The function returns zero if there is no such
487 // category.
488 int Category::getModulesNr (QString category) {
489  Category * cat = Categories.first ();
490  for (int i = 0; cat; cat = Categories.next (), i++) {
491  if (category == cat->Name)
492  return i;
493  }
494  return 0;
495 }
Definition: fa1b.h:16
#define REGISTER_DIAGRAM_2(val, inf1, inf2)
Definition: module.cpp:211
Definition: msstep.h:24
static void registerModule(QString, pInfoFunc)
Definition: module.cpp:49
Defines drawing elements for schematics.
Definition: biast.h:24
Definition: ha1b.h:16
Definition: vfile.h:24
Definition: rlcg.h:23
Definition: cccs.h:24
Definition: mutual.h:24
QString category
Definition: module.h:52
Definition: vprobe.h:24
#define REGISTER_DIGITAL_1(val)
Definition: module.cpp:201
static Component * getComponent(QString)
Definition: module.cpp:79
Definition: MESFET.h:16
Definition: dcfeed.h:24
Definition: diac.h:24
Q3PtrList< Module > Content
Definition: module.h:72
#define REGISTER_PAINT_1(val)
Definition: module.cpp:213
#define REGISTER_VERILOGA_2(val, inf1, inf2)
Definition: module.cpp:199
Definition: hybrid.h:20
Definition: ac_sim.h:24
static void registerModules(void)
Definition: module.cpp:223
~Category()
Definition: module.cpp:457
Definition: iprobe.h:24
~Module()
Definition: module.cpp:44
static Q3Dict< Module > Modules
Definition: module.h:42
Definition: bjtsub.h:30
Element *(* pInfoFunc)(QString &, char *&, bool)
Definition: module.h:26
static void unregisterModules(void)
Definition: module.cpp:438
static QStringList getCategories(void)
Definition: module.cpp:463
static int getModulesNr(QString)
Definition: module.cpp:488
pInfoFunc info
Definition: module.h:50
#define REGISTER_SOURCE_1(val)
Definition: module.cpp:185
Definition: mstee.h:24
Definition: msline.h:24
Definition: switch.h:24
#define REGISTER_TRANS_1(val)
Definition: module.cpp:189
static void intoCategory(Module *)
Definition: module.cpp:141
Definition: tff_SR.h:16
#define REGISTER_LUMPED_1(val)
Definition: module.cpp:181
#define REGISTER_LUMPED_2(val, inf1, inf2)
Definition: module.cpp:183
Definition: msgap.h:24
Definition: hb_sim.h:24
Definition: module.h:30
Definition: mosfet.h:24
Definition: vrect.h:24
Definition: ccvs.h:24
Definition: opamp.h:24
Definition: jfet.h:24
#define REGISTER_NONLINEAR_1(val)
Definition: module.cpp:191
Definition: diode.h:24
Definition: HBT_X.h:16
static Q3PtrList< Module > getModules(QString)
Definition: module.cpp:475
Definition: sp_sim.h:24
Definition: vccs.h:24
Definition: vexp.h:24
#define REGISTER_PROBE_1(val)
Definition: module.cpp:187
Definition: tline.h:24
static Element * info(QString &, QString &, bool getNewOne=false, QString filename="")
vacomponent::info is used to either get information or create objects.
Definition: cpwgap.h:24
static QMap< QString, QString > vaComponents
Definition: module.h:43
Definition: nigbt.h:16
Definition: vpulse.h:24
pInfoVAFunc infoVA
Definition: module.h:51
Definition: bjt.h:24
#define REGISTER_FILE_3(val, inf1, inf2, inf3)
Definition: module.cpp:205
static void registerComponent(QString, pInfoFunc)
Definition: module.cpp:58
QString Model
Definition: component.h:80
#define REGISTER_FILE_1(val)
Definition: module.cpp:203
Definition: fa2b.h:16
Definition: ipulse.h:24
Definition: triac.h:24
QString Name
Definition: module.h:71
#define REGISTER_PAINT_2(val, inf1, inf2)
Definition: module.cpp:215
static void registerDynamicComponents(void)
Definition: module.cpp:94
#define REGISTER_NONLINEAR_3(val, inf1, inf2, inf3)
Definition: module.cpp:195
Category()
Definition: module.cpp:445
Definition: ifile.h:24
Definition: iexp.h:24
Definition: tr_sim.h:24
Definition: rfedd.h:24
Module()
Definition: module.cpp:38
Definition: dc_sim.h:24
Definition: dff_SR.h:16
Definition: ground.h:24
static Q3PtrList< Category > Categories
Definition: module.h:63
Definition: ecvs.h:33
Definition: irect.h:24
Definition: relais.h:24
Definition: arrow.h:26
Definition: msopen.h:24
Definition: msvia.h:24
#define REGISTER_EXTERNAL_1(val)
Definition: module.cpp:217
#define REGISTER_SIMULATION_1(val)
Definition: module.cpp:207
#define REGISTER_VERILOGA_1(val)
Definition: module.cpp:197
#define REGISTER_NONLINEAR_2(val, inf1, inf2)
Definition: module.cpp:193
#define REGISTER_DIAGRAM_1(val)
Definition: module.cpp:209
Definition: vcvs.h:24