Qucs-GUI  0.0.18
 All Data Structures 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 #include <QtGui>
22 #include <math.h>
23 #include <float.h>
24 #if HAVE_IEEEFP_H
25 # include <ieeefp.h>
26 #endif
27 
28 #include "smithdiagram.h"
29 #include "main.h"
30 
31 
32 SmithDiagram::SmithDiagram(int _cx, int _cy, bool ImpMode) : Diagram(_cx, _cy)
33 {
34  x1 = 10; // position of label text
35  y1 = 2;
36  x2 = 200; // initial size of diagram
37  y2 = 200;
38  y3 = 0;
39  x3 = 207; // with some distance for right axes text
40  if(ImpMode) Name = "Smith"; // with impedance circles
41  else Name = "ySmith"; // with admittance circles
42 
43  Arcs.append(new struct Arc(0, y2, x2, y2, 0, 16*360, QPen(Qt::black,0)));
44 // calcDiagram(); // calculate circles for smith chart with |r|=1
45 }
46 
48 {
49 }
50 
51 // ------------------------------------------------------------
52 // calculate the screen coordinates for the graph data
53 void SmithDiagram::calcCoordinate(double* &, double* &yD, double* &,
54  float *px, float *py, Axis*)
55 {
56  double yr = *(yD++);
57  double yi = *(yD++);
58  *px = float((yr/yAxis.up + 1.0)*double(x2)/2.0);
59  *py = float((yi/yAxis.up + 1.0)*double(y2)/2.0);
60 
61  if(isfinite(*px))
62  if(isfinite(*py))
63  return;
64 
65  *px = *py = float(cx) / 2.0;
66 }
67 
68 // ------------------------------------------------------------
70 {
71  int a;
72  calcSmithAxisScale(&yAxis, a, a);
73  yAxis.limit_min = 0.0;
74  yAxis.step = double(a);
76 }
77 
78 // ------------------------------------------------------------
79 // calculate the circles and arcs of the smith chart
81 {
82  Lines.clear();
83  Texts.clear();
84  Arcs.clear();
85 
86  x3 = x2 + 7;
87  if(Name.at(0) == 'y') createSmithChart(&yAxis, 6);
88  else createSmithChart(&yAxis);
89 
90  // outer most circle
91  Arcs.append(new Arc(0, x2, x2, x2, 0, 16*360, QPen(Qt::black,0)));
92 
93  // horizontal line Im(r)=0
94  Lines.append(new Line(0, x2>>1, x2, x2>>1, GridPen));
95 
96  return 3;
97 }
98 
99 // ------------------------------------------------------------
101 {
102  return new SmithDiagram();
103 }
104 
105 // ------------------------------------------------------------
106 Element* SmithDiagram::info(QString& Name, char* &BitmapFile, bool getNewOne)
107 {
108  Name = QObject::tr("Smith Chart");
109  BitmapFile = (char *) "smith";
110 
111  if(getNewOne) return new SmithDiagram();
112  return 0;
113 }
114 
115 // ------------------------------------------------------------
116 Element* SmithDiagram::info_y(QString& Name, char* &BitmapFile, bool getNewOne)
117 {
118  Name = QObject::tr("Admittance Smith");
119  BitmapFile = (char *) "ysmith";
120 
121  if(getNewOne) return new SmithDiagram(0, 0, false);
122  return 0;
123 }
Definition: element.h:55
int y1
Definition: element.h:153
QString Name
Definition: diagram.h:92
int y2
Definition: element.h:153
int x1
Definition: element.h:153
SmithDiagram(int _cx=0, int _cy=0, bool ImpMode=true)
void calcCoordinate(double *&, double *&, double *&, float *, float *, Axis *)
double limit_min
Definition: diagram.h:56
Definitions and declarations for the main application.
int cx
Definition: element.h:153
QPen GridPen
Definition: diagram.h:93
static Element * info_y(QString &, char *&, bool getNewOne=false)
static Element * info(QString &, char *&, bool getNewOne=false)
void createSmithChart(Axis *, int Mode=7)
Definition: diagram.cpp:1415
Q3PtrList< struct Arc > Arcs
Definition: diagram.h:96
Definition: diagram.h:47
int x3
Definition: diagram.h:100
Definition: element.h:48
Superclass of all schematic drawing elements.
Definition: element.h:142
Diagram * newOne()
double limit_max
Definition: diagram.h:56
int y3
Definition: diagram.h:100
Q3PtrList< Text > Texts
Definition: diagram.h:98
void calcLimits()
Axis yAxis
Definition: diagram.h:101
double step
Definition: diagram.h:56
void calcSmithAxisScale(Axis *, int &, int &)
Definition: diagram.cpp:1395
double up
Definition: diagram.h:49
int x2
Definition: element.h:153
Q3PtrList< Line > Lines
Definition: diagram.h:97