Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/schematic.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                                schematic.h
00003                               -------------
00004     begin                : Sat Mar 11 2006
00005     copyright            : (C) 2006 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 
00018 #ifndef SCHEMATIC_H
00019 #define SCHEMATIC_H
00020 
00021 // maybe in another place...
00022 #ifdef NDEBUG
00023 // cast without overhead
00024 #  define prechecked_cast static_cast
00025 #else
00026 // cast safely, for debugging purposes
00027 #  define prechecked_cast dynamic_cast
00028 #endif
00029 
00030 #include "wire.h"
00031 #include "node.h"
00032 #include "qucsdoc.h"
00033 #include "viewpainter.h"
00034 #include "diagrams/diagram.h"
00035 #include "paintings/painting.h"
00036 #include "components/component.h"
00037 
00038 #include <Q3ScrollView>
00039 #include <Q3PtrList>
00040 #include <QVector>
00041 #include <QStringList>
00042 #include <QFileInfo>
00043 
00044 class QTextStream;
00045 class QTextEdit;
00046 class QPlainTextEdit;
00047 class QDragMoveEvent;
00048 class QDropEvent;
00049 class QDragLeaveEvent;
00050 class QWheelEvent;
00051 class QMouseEvent;
00052 class QDragEnterEvent;
00053 class QPainter;
00054 
00055 // digital signal data
00056 struct DigSignal {
00057   DigSignal() { Name=""; Type=""; }
00058   DigSignal(const QString& _Name, const QString& _Type = "")
00059     : Name(_Name), Type(_Type) {}
00060   QString Name; // name
00061   QString Type; // type of signal
00062 };
00063 typedef QMap<QString, DigSignal> DigMap;
00064 typedef enum {_NotRop, _Rect, _Line, _Ellipse, _Arc, _DotLine, _Translate, _Scale}PE;
00065 typedef struct {PE pe; int x1; int y1;int x2;int y2;int a; int b; bool PaintOnViewport;}PostedPaintEvent;
00066 
00067 // subcircuit, vhdl, etc. file structure
00068 struct SubFile {
00069   SubFile() { Type=""; File=""; PortTypes.clear(); }
00070   SubFile(const QString& _Type, const QString& _File)
00071     : Type(_Type), File(_File) { PortTypes.clear(); }
00072   QString Type;          // type of file
00073   QString File;          // file name identifier
00074   QStringList PortTypes; // data types of in/out signals
00075 };
00076 typedef QMap<QString, SubFile> SubMap;
00077 
00078 class Schematic : public Q3ScrollView, public QucsDoc {
00079   Q_OBJECT
00080 public:
00081   Schematic(QucsApp*, const QString&);
00082  ~Schematic();
00083 
00084   void setName(const QString&);
00085   void setChanged(bool, bool fillStack=false, char Op='*');
00086   void paintGrid(ViewPainter*, int, int, int, int);
00087   void print(QPrinter*, QPainter*, bool, bool);
00088 
00089   void paintSchToViewpainter(ViewPainter* p, bool printAll, bool toImage, int screenDpiX=96, int printerDpiX=300);
00090 
00091   void PostPaintEvent(PE pe, int x1=0, int y1=0, int x2=0, int y2=0, int a=0, int b=0,bool PaintOnViewport=false);
00092 
00093   float textCorr();
00094   bool sizeOfFrame(int&, int&);
00095   void  sizeOfAll(int&, int&, int&, int&);
00096   bool  rotateElements();
00097   bool  mirrorXComponents();
00098   bool  mirrorYComponents();
00099   void  setOnGrid(int&, int&);
00100   bool  elementsOnGrid();
00101 
00102   float zoom(float);
00103   float zoomBy(float);
00104   void  showAll();
00105   void  showNoZoom();
00106   void  enlargeView(int, int, int, int);
00107   void  switchPaintMode();
00108   int   adjustPortNumbers();
00109   void  reloadGraphs();
00110   bool  createSubcircuitSymbol();
00111 
00112   void    cut();
00113   void    copy();
00114   bool    paste(QTextStream*, Q3PtrList<Element>*);
00115   bool    load();
00116   int     save();
00117   int     saveSymbolCpp (void);
00118   int     saveSymbolJSON (void);
00119   void    becomeCurrent(bool);
00120   bool    undo();
00121   bool    redo();
00122 
00123   bool scrollUp(int);
00124   bool scrollDown(int);
00125   bool scrollLeft(int);
00126   bool scrollRight(int);
00127 
00128   // The pointers points to the current lists, either to the schematic
00129   // elements "Doc..." or to the symbol elements "SymbolPaints".
00130   Q3PtrList<Wire>      *Wires, DocWires;
00131   Q3PtrList<Node>      *Nodes, DocNodes;
00132   Q3PtrList<Diagram>   *Diagrams, DocDiags;
00133   Q3PtrList<Painting>  *Paintings, DocPaints;
00134   Q3PtrList<Component> *Components, DocComps;
00135 
00136   Q3PtrList<Painting>  SymbolPaints;  // symbol definition for subcircuit
00137 
00138   QList<PostedPaintEvent>   PostedPaintEvents;
00139   bool symbolMode;  // true if in symbol painting mode
00140 
00141 
00142   int GridX, GridY;
00143   int ViewX1, ViewY1, ViewX2, ViewY2;  // size of the document area
00144   int UsedX1, UsedY1, UsedX2, UsedY2;  // document area used by elements
00145 
00146   int showFrame;
00147   QString Frame_Text0, Frame_Text1, Frame_Text2, Frame_Text3;
00148 
00149   // Two of those data sets are needed for Schematic and for symbol.
00150   // Which one is in "tmp..." depends on "symbolMode".
00151   float tmpScale;
00152   int tmpViewX1, tmpViewY1, tmpViewX2, tmpViewY2;
00153   int tmpUsedX1, tmpUsedY1, tmpUsedX2, tmpUsedY2;
00154 
00155   int undoActionIdx;
00156   QVector<QString *> undoAction;
00157   int undoSymbolIdx;
00158   QVector<QString *> undoSymbol;    // undo stack for circuit symbol
00159 
00161   QFileInfo getFileInfo (void) { return FileInfo; }
00163   void setFileInfo(QString FileName) { FileInfo = QFileInfo(FileName); }
00164 
00165 signals:
00166   void signalCursorPosChanged(int, int);
00167   void signalUndoState(bool);
00168   void signalRedoState(bool);
00169   void signalFileChanged(bool);
00170 
00171 protected:
00172   void paintFrame(ViewPainter*);
00173 
00174   // overloaded function to get actions of user
00175   void drawContents(QPainter*, int, int, int, int);
00176   void contentsMouseMoveEvent(QMouseEvent*);
00177   void contentsMousePressEvent(QMouseEvent*);
00178   void contentsMouseDoubleClickEvent(QMouseEvent*);
00179   void contentsMouseReleaseEvent(QMouseEvent*);
00180   void contentsWheelEvent(QWheelEvent*);
00181   void contentsDropEvent(QDropEvent*);
00182   void contentsDragEnterEvent(QDragEnterEvent*);
00183   void contentsDragLeaveEvent(QDragLeaveEvent*);
00184   void contentsDragMoveEvent(QDragMoveEvent*);
00185 
00186 protected slots:
00187   void slotScrollUp();
00188   void slotScrollDown();
00189   void slotScrollLeft();
00190   void slotScrollRight();
00191 
00192 private:
00193   bool dragIsOkay;
00195   QFileInfo FileInfo;
00196 
00197 /* ********************************************************************
00198    *****  The following methods are in the file                   *****
00199    *****  "schematic_element.cpp". They only access the QPtrList  *****
00200    *****  pointers "Wires", "Nodes", "Diagrams", "Paintings" and  *****
00201    *****  "Components".                                           *****
00202    ******************************************************************** */
00203 
00204 public:
00205   Node* insertNode(int, int, Element*);
00206   Node* selectedNode(int, int);
00207 
00208   int   insertWireNode1(Wire*);
00209   bool  connectHWires1(Wire*);
00210   bool  connectVWires1(Wire*);
00211   int   insertWireNode2(Wire*);
00212   bool  connectHWires2(Wire*);
00213   bool  connectVWires2(Wire*);
00214   int   insertWire(Wire*);
00215   void  selectWireLine(Element*, Node*, bool);
00216   Wire* selectedWire(int, int);
00217   Wire* splitWire(Wire*, Node*);
00218   bool  oneTwoWires(Node*);
00219   void  deleteWire(Wire*);
00220 
00221   Marker* setMarker(int, int);
00222   void    markerLeftRight(bool, Q3PtrList<Element>*);
00223   void    markerUpDown(bool, Q3PtrList<Element>*);
00224 
00225   Element* selectElement(float, float, bool, int *index=0);
00226   void     deselectElements(Element*);
00227   int      selectElements(int, int, int, int, bool);
00228   void     selectMarkers();
00229   void     newMovingWires(Q3PtrList<Element>*, Node*, int);
00230   int      copySelectedElements(Q3PtrList<Element>*);
00231   bool     deleteElements();
00232   bool     aligning(int);
00233   bool     distributeHorizontal();
00234   bool     distributeVertical();
00235 
00236   void       setComponentNumber(Component*);
00237   void       insertRawComponent(Component*, bool noOptimize=true);
00238   void       recreateComponent(Component*);
00239   void       insertComponent(Component*);
00240   void       activateCompsWithinRect(int, int, int, int);
00241   bool       activateSpecifiedComponent(int, int);
00242   bool       activateSelectedComponents();
00243   void       setCompPorts(Component*);
00244   Component* selectCompText(int, int, int&, int&);
00245   Component* searchSelSubcircuit();
00246   Component* selectedComponent(int, int);
00247   void       deleteComp(Component*);
00248 
00249   void     oneLabel(Node*);
00250   int      placeNodeLabel(WireLabel*);
00251   Element* getWireLabel(Node*);
00252   void     insertNodeLabel(WireLabel*);
00253   void     copyLabels(int&, int&, int&, int&, QList<Element *> *);
00254 
00255   Painting* selectedPainting(float, float);
00256   void      copyPaintings(int&, int&, int&, int&, QList<Element *> *);
00257 
00258   void      getSelAreaWidthAndHeight(int &wsel, int& hsel, int& xmin_sel_, int& ymin_sel_); // and selected area width and height in pixels
00259 
00260 private:
00261   void insertComponentNodes(Component*, bool);
00262   int  copyWires(int&, int&, int&, int&, QList<Element *> *);
00263   int  copyComponents(int&, int&, int&, int&, QList<Element *> *);
00264   void copyComponents2(int&, int&, int&, int&, QList<Element *> *);
00265   bool copyComps2WiresPaints(int&, int&, int&, int&, QList<Element *> *);
00266   int  copyElements(int&, int&, int&, int&, QList<Element *> *);
00267 
00268 
00269 /* ********************************************************************
00270    *****  The following methods are in the file                   *****
00271    *****  "schematic_file.cpp". They only access the QPtrLists    *****
00272    *****  and their pointers. ("DocComps", "Components" etc.)     *****
00273    ******************************************************************** */
00274 
00275 public:
00276   static int testFile(const QString &);
00277   bool createLibNetlist(QTextStream*, QPlainTextEdit*, int);
00278   bool createSubNetlist(QTextStream *, int&, QStringList&, QPlainTextEdit*, int);
00279   void createSubNetlistPlain(QTextStream*, QPlainTextEdit*, int);
00280   int  prepareNetlist(QTextStream&, QStringList&, QPlainTextEdit*);
00281   QString createNetlist(QTextStream&, int);
00282   bool loadDocument();
00283   void highlightWireLabels (void);
00284 
00285 private:
00286   int  saveDocument();
00287 
00288   bool loadProperties(QTextStream*);
00289   void simpleInsertComponent(Component*);
00290   bool loadComponents(QTextStream*, Q3PtrList<Component> *List=0);
00291   void simpleInsertWire(Wire*);
00292   bool loadWires(QTextStream*, Q3PtrList<Element> *List=0);
00293   bool loadDiagrams(QTextStream*, Q3PtrList<Diagram>*);
00294   bool loadPaintings(QTextStream*, Q3PtrList<Painting>*);
00295   bool loadIntoNothing(QTextStream*);
00296 
00297   QString createClipboardFile();
00298   bool    pasteFromClipboard(QTextStream *, Q3PtrList<Element>*);
00299 
00300   QString createUndoString(char);
00301   bool    rebuild(QString *);
00302   QString createSymbolUndoString(char);
00303   bool    rebuildSymbol(QString *);
00304 
00305   static void createNodeSet(QStringList&, int&, Conductor*, Node*);
00306   void throughAllNodes(bool, QStringList&, int&);
00307   void propagateNode(QStringList&, int&, Node*);
00308   void collectDigitalSignals(void);
00309   bool giveNodeNames(QTextStream *, int&, QStringList&, QPlainTextEdit*, int);
00310   void beginNetlistDigital(QTextStream &);
00311   void endNetlistDigital(QTextStream &);
00312   bool throughAllComps(QTextStream *, int&, QStringList&, QPlainTextEdit *, int);
00313 
00314   DigMap Signals; // collecting node names for VHDL signal declarations
00315   QStringList PortTypes;
00316 
00317 public:
00318   bool isAnalog;
00319   bool isVerilog;
00320   bool creatingLib;
00321 };
00322 
00323 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines