Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/diagrams/smithdiagram.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           smithdiagram.cpp  -  description
00003                              -------------------
00004     begin                : Sat Oct 18 2003
00005     copyright            : (C) 2003 by Michael Margraf
00006     email                : michael.margraf@alumni.tu-berlin.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00023 #if HAVE_CONFIG_H
00024 # include <config.h>
00025 #endif
00026 #include <cmath>
00027 #include <float.h>
00028 #if HAVE_IEEEFP_H
00029 # include <ieeefp.h>
00030 #endif
00031 
00032 #include "smithdiagram.h"
00033 #include "misc.h"
00034 #include "../dialogs/matchdialog.h" // For r2z function
00035 
00036 
00037 SmithDiagram::SmithDiagram(int _cx, int _cy, bool ImpMode) : Diagram(_cx, _cy)
00038 {
00039   x1 = 10;     // position of label text
00040   y1 = 2;
00041   x2 = 200;    // initial size of diagram
00042   y2 = 200;
00043   y3 = 0;
00044   x3 = 207;    // with some distance for right axes text
00045   if(ImpMode)  Name = "Smith";  // with impedance circles
00046   else  Name = "ySmith";        // with admittance circles
00047 
00048   Arcs.append(new struct Arc(0, y2, x2, y2, 0, 16*360, QPen(Qt::black,0)));
00049 //  calcDiagram();    // calculate circles for smith chart with |r|=1
00050 }
00051 
00052 SmithDiagram::~SmithDiagram()
00053 {
00054 }
00055 
00056 // ------------------------------------------------------------
00057 // calculate the screen coordinates for the graph data
00058 void SmithDiagram::calcCoordinate(const double*, const double* yD, const double*,
00059                                   float *px, float *py, Axis const*) const
00060 {
00061   double yr = yD[0];
00062   double yi = yD[1];
00063   *px = float((yr/yAxis.up + 1.0)*double(x2)/2.0);
00064   *py = float((yi/yAxis.up + 1.0)*double(y2)/2.0);
00065 
00066   if(std::isfinite(*px))
00067     if(std::isfinite(*py))
00068       return;
00069 
00070   *px = *py = float(cx) / 2.0;
00071 }
00072 
00073 // ------------------------------------------------------------
00074 void SmithDiagram::calcLimits()
00075 {
00076   int a;
00077   calcSmithAxisScale(&yAxis, a, a);
00078   yAxis.limit_min = 0.0;
00079   yAxis.step = double(a);
00080   yAxis.limit_max = yAxis.up;
00081 }
00082 
00083 // ------------------------------------------------------------
00084 // calculate the circles and arcs of the smith chart
00085 int SmithDiagram::calcDiagram()
00086 {
00087   Lines.clear();
00088   Texts.clear();
00089   Arcs.clear();
00090 
00091   x3 = x2 + 7;
00092   if(Name.at(0) == 'y')  createSmithChart(&yAxis, 6);
00093   else  createSmithChart(&yAxis);
00094 
00095   // outer most circle
00096   Arcs.append(new Arc(0, x2, x2, x2, 0, 16*360, QPen(Qt::black,0)));
00097 
00098   // horizontal line Im(r)=0
00099   Lines.append(new Line(0, x2>>1, x2, x2>>1, GridPen));
00100 
00101   return 3;
00102 }
00103 
00104 // ------------------------------------------------------------
00105 Diagram* SmithDiagram::newOne()
00106 {
00107   return new SmithDiagram();
00108 }
00109 
00110 // ------------------------------------------------------------
00111 Element* SmithDiagram::info(QString& Name, char* &BitmapFile, bool getNewOne)
00112 {
00113   Name = QObject::tr("Smith Chart");
00114   BitmapFile = (char *) "smith";
00115 
00116   if(getNewOne)  return new SmithDiagram();
00117   return 0;
00118 }
00119 
00120 // ------------------------------------------------------------
00121 Element* SmithDiagram::info_y(QString& Name, char* &BitmapFile, bool getNewOne)
00122 {
00123   Name = QObject::tr("Admittance Smith");
00124   BitmapFile = (char *) "ysmith";
00125 
00126   if(getNewOne)  return new SmithDiagram(0, 0, false);
00127   return 0;
00128 }
00129 
00130 QString SmithDiagram::extraMarkerText(Marker const* m) const
00131 {
00132   assert(m);
00133   Graph const* pGraph = m->graph();
00134   assert(pGraph);
00135   std::vector<double> const& Pos = m->varPos();
00136   unsigned nVarPos = pGraph->numAxes();
00137   assert(nVarPos == Pos.size());
00138   double Zr, Zi;
00139   double Z0 = m->Z0;
00140   double Precision = m->precision(); // hmmm
00141 
00142   Zr = m->powReal();
00143   Zi = m->powImag();
00144 
00145   MatchDialog::r2z(Zr, Zi, Z0);
00146   QString Var = pGraph->Var;
00147 
00148   if(Var.startsWith("S")) { // uuh, ooh hack.
00149     return "\n"+ Var.replace('S', 'Z')+": " +misc::complexRect(Zr, Zi, Precision);
00150   }else{
00151     return "\nZ("+ Var+"): " +misc::complexRect(Zr, Zi, Precision);
00152   }
00153 }
00154 
00155 // vim:ts=8:sw=2:noet
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines