QSapecNG
 All Classes Functions Enumerations Properties
workplane.h
00001 /*
00002     QSapecNG - Qt based SapecNG GUI front-end
00003     Copyright (C) 2009, Michele Caini
00004 
00005     This program is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation, either version 3 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 
00020 #ifndef WORKPLANE_H
00021 #define WORKPLANE_H
00022 
00023 
00024 #include "model/metacircuit.h"
00025 
00026 #include <QtGui/QWidget>
00027 #include <QtGui/QMenu>
00028 #include <QtGui/QContextMenuEvent>
00029 #include <QtGui/QPrinter>
00030 
00031 #include <QtCore/QObject>
00032 #include <QtCore/QVector>
00033 #include <QtCore/QPair>
00034 
00035 #include <qwt_plot.h>
00036 #include <qwt_plot_curve.h>
00037 
00038 #include <string>
00039 #include <map>
00040 
00041 
00042 class QVBoxLayout;
00043 class QHBoxLayout;
00044 class QDoubleSpinBox;
00045 class QTableWidget;
00046 
00047 class QwtPlotGrid;
00048 class QwtPickerMachine;
00049 class QwtPlotPicker;
00050 class QwtPlotMarker;
00051 class QwtSymbol;
00052 
00053 
00054 namespace qsapecng
00055 {
00056 
00057 
00058 class QwtPlot_ContextMenu: public QwtPlot
00059 {
00060 
00061 public:
00062   QwtPlot_ContextMenu(QWidget* parent = 0): QwtPlot(parent), contextMenu_(0) { }
00063   QwtPlot_ContextMenu(const QwtText& title, QWidget* parent = 0)
00064     : QwtPlot(title, parent), contextMenu_(0) { }
00065 
00066   inline void setContextMenu(QMenu* menu) { contextMenu_ = menu; }
00067   inline QMenu* contextMenu() const { return contextMenu_; }
00068 
00069   void contextMenuEvent(QContextMenuEvent* event)
00070     { if(contextMenu_) contextMenu_->exec(event->globalPos()); }
00071 
00072 private:
00073   QMenu* contextMenu_;
00074 
00075 };
00076 
00077 
00078 
00079 typedef
00080   std::pair< std::vector<double>, std::vector<double> >
00081   (*functor)
00082     (
00083       const sapecng::metacircuit::expression& numerator,
00084       const sapecng::metacircuit::expression& denominator,
00085       std::map< std::string, double > values
00086     )
00087   ;
00088 
00089 class MarkableCurve: public QObject, public QwtPlotCurve
00090 {
00091 
00092   Q_OBJECT
00093 
00094 public:
00095   MarkableCurve(): QwtPlotCurve() { initialize(); }
00096   ~MarkableCurve();
00097 
00098   void setVisible(bool on);
00099 
00100 public slots:
00101   void selected();
00102   void appended(const QPointF& pos);
00103   void moved(const QPointF& pos);
00104 
00105 private:
00106   void initialize();
00107 
00108 private:
00109   QwtPlotMarker* marker_;
00110   QwtSymbol* symbol_;
00111 
00112 };
00113 
00114 
00115 
00116 class MarkedCurve: public QwtPlotCurve
00117 {
00118 
00119 public:
00120   MarkedCurve(): QwtPlotCurve() { }
00121   ~MarkedCurve();
00122 
00123   void setVisible(bool on);
00124   void replotMarker();
00125 
00126 private:
00127   void resetMarker();
00128 
00129 private:
00130   QVector<QwtPlotMarker*> markers_;
00131 
00132 };
00133 
00134 
00135 
00136 class WorkPlane: public QWidget
00137 {
00138 
00139   Q_OBJECT
00140 
00141 public:
00142   enum F
00143   {
00144     MAGNITUDE,
00145     MAGNITUDE_RAD,
00146     PHASE,
00147     PHASE_RAD,
00148     GAIN,
00149     GAIN_RAD,
00150     LOSS,
00151     LOSS_RAD,
00152     ZEROS,
00153     POLES,
00154     NOOP
00155   };
00156 
00157 public:
00158   WorkPlane(QWidget* parent = 0);
00159   ~WorkPlane();
00160 
00161   void setData(const std::map<std::string, double>& values,
00162       const sapecng::metacircuit::expression& numerator,
00163       const sapecng::metacircuit::expression& denominator
00164     );
00165 
00166   inline void setContextMenu(QMenu* menu) { plot_->setContextMenu(menu); }
00167   inline QMenu* contextMenu() const { return plot_->contextMenu(); }
00168 
00169   const QwtPlot& const_plot() const { return *plot_; }
00170 
00171 public slots:
00172   void setDirty();
00173   void xAxisLogScale(bool log = true);
00174   void yAxisLogScale(bool log = false);
00175   void plot(WorkPlane::F f);
00176   void plot(int f);
00177   void redraw();
00178   void print(QPrinter& printer);
00179 
00180 private:
00181   std::map<std::string, double> actValues() const;
00182   void createMainLayout();
00183   void setupCurves();
00184   void setupCurve(
00185       std::pair< std::vector<double>, std::vector<double> > data,
00186       WorkPlane::F f
00187     );
00188 
00189 private:
00190   sapecng::metacircuit::expression num_;
00191   sapecng::metacircuit::expression den_;
00192 
00193   QwtPlotGrid* grid_;
00194   QwtPlot_ContextMenu* plot_;
00195   QVector< QwtPlotCurve* > attached_;
00196   QVector< QPair< QwtPlotCurve*, bool > > curves_;
00197   QwtPickerMachine *clickPointMachine_;
00198   QwtPlotPicker* tracker_;
00199   F lastId_;
00200 
00201   QDoubleSpinBox* startFreq_;
00202   QDoubleSpinBox* endFreq_;
00203   QDoubleSpinBox* stepFreq_;
00204   double oldStartFreq_;
00205   double oldEndFreq_;
00206   double oldStepFreq_;
00207 
00208   QTableWidget* data_;
00209 
00210   QVBoxLayout* dataLayout_;
00211   QVBoxLayout* centralLayout_;
00212   QHBoxLayout* mainLayout_;
00213 
00214 };
00215 
00216 
00217 }
00218 
00219 
00220 #endif // WORKPLANE_H
 All Classes Functions Enumerations Properties