My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
smithdiagram.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  smithdiagram.cpp - description
3  -------------------
4  begin : Sat Oct 18 2003
5  copyright : (C) 2003 by Michael Margraf
6  email : michael.margraf@alumni.tu-berlin.de
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 #if HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 
22 #include <math.h>
23 #include <float.h>
24 #ifdef __MINGW32__
25 # define finite(x) _finite(x)
26 #endif
27 #if HAVE_IEEEFP_H
28 # include <ieeefp.h>
29 #endif
30 
31 #include "smithdiagram.h"
32 #include "main.h"
33 
34 
35 SmithDiagram::SmithDiagram(int _cx, int _cy, bool ImpMode) : Diagram(_cx, _cy)
36 {
37  x1 = 10; // position of label text
38  y1 = 2;
39  x2 = 200; // initial size of diagram
40  y2 = 200;
41  y3 = 0;
42  x3 = 207; // with some distance for right axes text
43  if(ImpMode) Name = "Smith"; // with impedance circles
44  else Name = "ySmith"; // with admittance circles
45 
46  Arcs.append(new struct Arc(0, y2, x2, y2, 0, 16*360, QPen(QPen::black,0)));
47 // calcDiagram(); // calculate circles for smith chart with |r|=1
48 }
49 
51 {
52 }
53 
54 // ------------------------------------------------------------
55 // calculate the screen coordinates for the graph data
56 void SmithDiagram::calcCoordinate(double* &, double* &yD, double* &,
57  float *px, float *py, Axis*)
58 {
59  double yr = *(yD++);
60  double yi = *(yD++);
61  *px = float((yr/yAxis.up + 1.0)*double(x2)/2.0);
62  *py = float((yi/yAxis.up + 1.0)*double(y2)/2.0);
63 
64  if(finite(*px))
65  if(finite(*py))
66  return;
67 
68  *px = *py = float(cx) / 2.0;
69 }
70 
71 // ------------------------------------------------------------
73 {
74  int a;
75  calcSmithAxisScale(&yAxis, a, a);
76  yAxis.limit_min = 0.0;
77  yAxis.step = double(a);
79 }
80 
81 // ------------------------------------------------------------
82 // calculate the circles and arcs of the smith chart
84 {
85  Lines.clear();
86  Texts.clear();
87  Arcs.clear();
88 
89  x3 = x2 + 7;
90  if(Name.at(0) == 'y') createSmithChart(&yAxis, 6);
91  else createSmithChart(&yAxis);
92 
93  // outer most circle
94  Arcs.append(new Arc(0, x2, x2, x2, 0, 16*360, QPen(QPen::black,0)));
95 
96  // horizontal line Im(r)=0
97  Lines.append(new Line(0, x2>>1, x2, x2>>1, GridPen));
98 
99  return 3;
100 }
101 
102 // ------------------------------------------------------------
104 {
105  return new SmithDiagram();
106 }
107 
108 // ------------------------------------------------------------
109 Element* SmithDiagram::info(QString& Name, char* &BitmapFile, bool getNewOne)
110 {
111  Name = QObject::tr("Smith Chart");
112  BitmapFile = (char *) "smith";
113 
114  if(getNewOne) return new SmithDiagram();
115  return 0;
116 }
117 
118 // ------------------------------------------------------------
119 Element* SmithDiagram::info_y(QString& Name, char* &BitmapFile, bool getNewOne)
120 {
121  Name = QObject::tr("Admittance Smith");
122  BitmapFile = (char *) "ysmith";
123 
124  if(getNewOne) return new SmithDiagram(0, 0, false);
125  return 0;
126 }