/*************************************************************************** graph.h --------- begin : Thu Oct 2 2003 copyright : (C) 2003 by Michael Margraf email : michael.margraf@alumni.tu-berlin.de ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#ifndef GRAPH_H#define GRAPH_H#include "marker.h"#include "../element.h"#include <QColor>#include <QtCore/QList>#include <QtCore/QDate>#include <QtCore/QTime>// meaning of the values in a graph "Points" list#define STROKEEND -2#define GRAPHARROW -5#define GRAPHCIRCLE -6#define GRAPHSTAR -7#define BRANCHEND -10#define GRAPHEND -100class Diagram;class ViewPainter;struct DataX { DataX(const QString& Var_, double *Points_=0, int count_=0) : Var(Var_), Points(Points_), count(count_) {}; ~DataX() { if(Points) delete[] Points; }; QString Var; double *Points; int count;};class Graph : public Element {public: Graph(const QString& _Line=""); ~Graph(); void paint(ViewPainter*, int, int); void paintLines(ViewPainter*, int, int); QString save(); bool load(const QString&); int getSelected(int, int); Graph* sameNewOne(); QDateTime lastLoaded; // when it was loaded into memory int yAxisNo; // which y axis is used QList <DataX> cPointsX; double *cPointsY; int *Points, countY; // data in screen coordinates, countY = curves number QString Var; QColor Color; int Thick; int Style; QList<Marker> Markers; // for tabular diagram int Precision; // number of digits to show int numMode; // real/imag or polar (deg/rad)};#endif
/*************************************************************************** element.h ----------- begin : Sat Sep 20 2003 copyright : (C) 2003 by Michael Margraf email : michael.margraf@alumni.tu-berlin.de ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#ifndef ELEMENT_H#define ELEMENT_H#include <QPen>#include <QBrush>class Node;class QPainter;class WireLabel;struct Line { Line(int _x1, int _y1, int _x2, int _y2, QPen _style) : x1(_x1), y1(_y1), x2(_x2), y2(_y2), style(_style) {}; int x1, y1, x2, y2; QPen style;};struct Arc { Arc(int _x, int _y, int _w, int _h, int _angle, int _arclen, QPen _style) : x(_x), y(_y), w(_w), h(_h), angle(_angle), arclen(_arclen), style(_style) {}; int x, y, w, h, angle, arclen; QPen style;};struct Area { Area(int _x, int _y, int _w, int _h, QPen _Pen, QBrush _Brush = QBrush(Qt::NoBrush)) : x(_x), y(_y), w(_w), h(_h), Pen(_Pen), Brush(_Brush) {}; int x, y, w, h; QPen Pen; QBrush Brush; // filling style/color};struct Port { Port() {}; Port(int _x, int _y) : x(_x), y(_y) {}; int x, y; Node *Connection;};struct Text { Text(int _x, int _y, const QString& _s, QColor _Color = QColor(0,0,0), float _Size = 10.0, float _mCos=1.0, float _mSin=0.0) : x(_x), y(_y), s(_s), Color(_Color), Size(_Size), mSin(_mSin), mCos(_mCos) { over = under = false; }; int x, y; QString s; QColor Color; float Size, mSin, mCos; // font size and rotation coefficients bool over, under; // text attributes};struct Property { Property(const QString& _Name="", const QString& _Value="", bool _display=false, const QString& Desc="") : Name(_Name), Value(_Value), display(_display), Description(Desc) {}; QString Name, Value; bool display; // show on schematic or not ? QString Description;};// valid values for Element.Type// The 4 least significant bits of each value are reserved for special// additionals !!!#define isDummy 0#define isSpecialMask -16#define isComponent 0x30000#define isComponentText 0x30002#define isAnalogComponent 0x10000#define isDigitalComponent 0x20000#define isGraph 0x0020#define isNode 0x0040#define isMarker 0x0080#define isWire 0x0100#define isPainting 0x2000#define isPaintingResize 0x2001#define isLabel 0x4000#define isHWireLabel 0x4020#define isVWireLabel 0x4040#define isNodeLabel 0x4080#define isMovingLabel 0x4001#define isHMovingLabel 0x4002#define isVMovingLabel 0x4004#define isDiagram 0x8000#define isDiagramResize 0x8001#define isDiagramHScroll 0x8002#define isDiagramVScroll 0x8003class Element {public: Element(); virtual ~Element(); virtual void paintScheme(QPainter*); virtual void setCenter(int, int, bool relative=false); virtual void getCenter(int&, int&); bool isSelected; int Type; // whether it is Component, Wire, ... int cx, cy, x1, y1, x2, y2; // center and relative boundings};// label for Node and Wire classesclass Conductor : public Element {public: WireLabel *Label;};#endif
/*************************************************************************** marker.h ---------- begin : Sat Apr 10 2004 copyright : (C) 2003 by Michael Margraf email : michael.margraf@alumni.tu-berlin.de ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#ifndef MARKER_H#define MARKER_H#include "../element.h"#include "../viewpainter.h"#include <qpainter.h>#include <QLinkedList>class Diagram;class Graph;class Marker : public Element {public: Marker(Diagram *Diag_, Graph *pg_=0, int _nn=0, int cx_=0, int cy_=0); ~Marker(); void initText(int); void createText(); void makeInvalid(); bool moveLeftRight(bool); bool moveUpDown(bool); void paint(ViewPainter*, int, int); void paintScheme(QPainter*); void setCenter(int, int, bool); void Bounding(int& _x1, int& _y1, int& _x2, int& _y2); QString save(); bool load(const QString& Line); bool getSelected(int, int); Marker* sameNewOne(Graph*); void getTextSize(const QFont&); Diagram *Diag; // the corresponding diagram Graph *pGraph; // the corresponding graph int nVarPos; // number of values in "VarPos" double VarPos[256]; // values the marker is pointing to QString Text; // the string to be displayed in the marker text bool transparent; // background shines through marker body int Precision; // number of digits to show int numMode; // real/imag or polar (deg/rad)};#endif
#include "marker.h" #include "../element.h" #include <QColor> #include <QtCore/QList> #include <QtCore/QDate> #include <QtCore/QTime>
#include <QColor> #include <QtCore/QList> #include <QtCore/QDate> #include <QtCore/QTime>#include "marker.h" #include "../element.h"
#include <QtCore/QDate> #include <QtCore/QTime>
#include <QDateTime>
#include <qpainter.h> #include <QLinkedList>
/*************************************************************************** * Copyright (C) 2006 by Gopala Krishna A <krishna.ggk@gmail.com> * * * * This is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2, or (at your option) * * any later version. * * * * This software is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; see the file COPYING. If not, write to * * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, * * Boston, MA 02110-1301, USA. * ***************************************************************************/#ifndef __ITEM_H#define __ITEM_H#include <QtGui/QGraphicsItem>class QGraphicsScene;class QGraphicsView;class SchematicScene;class QucsMainWindow;class QMenu;class QucsItem : public QGraphicsItem{ public: enum QucsItemTypes { QucsItemType = (UserType << 14), ComponentType = (UserType << 13) | QucsItemType, MultiSymbolComponentType = (UserType << 12) | ComponentType, NodeType = (UserType << 11) | QucsItemType, WireType = (UserType << 10) | QucsItemType, PaintingType = (UserType << 9) | QucsItemType, DisplayType = (UserType << 8) | QucsItemType }; enum { Type = QucsItemType }; using QGraphicsItem::rotate; QucsItem(QGraphicsItem* parent = 0, SchematicScene* scene = 0); virtual ~QucsItem() {}; int type() const; QRectF boundingRect() const {return QRectF(); } SchematicScene* schematicScene() const; QGraphicsView* activeView() const; QucsMainWindow* mainWindow() const; virtual QString saveString() const { return QString(""); } virtual bool loadFromString(QString ) { return true; } virtual void mirrorX(); virtual void mirrorY(); virtual void rotate(); virtual void invokePropertiesDialog() {} QMenu* defaultContextMenu() const;};#endif //__ITEM_H
/*************************************************************************** * Copyright (C) 2006 by Gopala Krishna A <krishna.ggk@gmail.com> * * * * This is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2, or (at your option) * * any later version. * * * * This software is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; see the file COPYING. If not, write to * * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, * * Boston, MA 02110-1301, USA. * ***************************************************************************/#ifndef __WIRE_H#define __WIRE_H#include <QtCore/QList>#include "item.h"#include "wireline.h"#include "node.h"class SchematicScene;class QGraphicsLineItem;class QRubberBand;class Wire : public QucsItem{ public: enum { Type = QucsItem::WireType}; Wire(SchematicScene *scene, Node *n1,Node *n2); ~Wire(); void rebuild(); inline Node* node1() const; inline Node* node2() const; inline void setNode1(Node *n1); inline void setNode2(Node *n2); void replaceNode(Node *oldNode,Node *newNode); QRectF boundingRect() const; inline int type() const; void paint(QPainter * p, const QStyleOptionGraphicsItem * o, QWidget * w = 0 ); QPainterPath shape() const; bool contains ( const QPointF & point ) const; static Wire* connectedWire(const Node *n1,const Node *n2); void grabMoveEvent( QGraphicsSceneMouseEvent * event ); void grabReleaseEvent ( QGraphicsSceneMouseEvent * event ); void startMoveAndResize(); void moveAndResizeBy(qreal dx, qreal dy); void stopMoveAndResize(); void setWireLines(const QList<WireLine>& lines); inline QList<WireLine> wireLines() const; QString saveString() const; // Reimplemented virtuals to not to react void rotate() {} void mirrorX() {} void mirrorY() {} protected: QVariant itemChange(GraphicsItemChange change, const QVariant &value); void mousePressEvent ( QGraphicsSceneMouseEvent * event ); void mouseMoveEvent ( QGraphicsSceneMouseEvent * event ); void mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * event ); private: void createLines(const QPointF& p1, const QPointF& p2); void createProxyWires(); QList<WireLine> linesBetween(const QPointF& p1, const QPointF& p2) const; QRect proxyRect(const WireLine& line) const; void updateProxyWires(); void clearProxyWires(); QRectF rectForLine(const WireLine& line) const; int indexForPos(const QPointF& pos) const; void deleteNullLines(); bool m_proxyWiring; QList<WireLine> m_lines; QList<QRubberBand*> m_proxyWires; Node *m_node1; Node *m_node2; int m_grabbedLineIndex; bool m_wasGrabbed;};inline Node* Wire::node1() const{ return m_node1;}inline Node* Wire::node2() const{ return m_node2;}inline void Wire::setNode1(Node *n1){ m_node1 = n1;}inline void Wire::setNode2(Node *n2){ m_node2 = n2;}inline int Wire::type() const{ return Wire::Type;}inline QList<WireLine> Wire::wireLines() const{ return m_lines;}#endif //__WIRE_H
#include "item.h" #include "wireline.h" #include "node.h"