My Project  0.0.16
QUCS Mapping
 All Classes Namespaces 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 
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.
35  info = 0;
36  category = "#special";
37 }
38 
39 // Destructor removes instance of module object from memory.
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.
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.
168 
169  // lumped components
170  REGISTER_LUMPED_2 (Resistor, info, info_us);
196 
197  // sources
222 
223  // probes
226 
227  // transmission lines
253 
254  // nonlinear components
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);
267 
268  // verilog-a devices
274  REGISTER_VERILOGA_2 (hic0_full, info, info_pnp);
277  REGISTER_VERILOGA_2 (EKV26MOS, info, info_pmos);
278  REGISTER_VERILOGA_2 (hicumL0V1p2, info, info_pnp);
280  REGISTER_VERILOGA_2 (hicumL0V1p3, info, info_pnp);
286 
287  // digital components
332 
333  // file components
335  REGISTER_FILE_3 (SParamFile, info1, info2, info);
337 
338  // simulations
347 
348  // diagrams
353  REGISTER_DIAGRAM_2 (PSDiagram, info, info_sp);
358 
359  // paintings
363  REGISTER_PAINT_2 (Ellipse, info, info_filled);
364  REGISTER_PAINT_2 (Rectangle, info, info_filled);
366 }
367 
368 // This function has to be called once at application end. It removes
369 // all categories and registered modules from memory.
371  Category::Categories.setAutoDelete (true);
372  Category::Categories.clear ();
373  Modules.clear ();
374 }
375 
376 // Constructor creates instance of module object.
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.
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 }