Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
schematic.h
Go to the documentation of this file.
1 /***************************************************************************
2  schematic.h
3  -------------
4  begin : Sat Mar 11 2006
5  copyright : (C) 2006 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 #ifndef SCHEMATIC_H
19 #define SCHEMATIC_H
20 #include <QtGui>
21 #include "wire.h"
22 #include "diagrams/diagram.h"
23 #include "paintings/painting.h"
24 #include "components/component.h"
25 #include "qucsdoc.h"
26 //Added by qt3to4:
27 #include <QTextStream>
28 #include <QDragMoveEvent>
29 #include <QDropEvent>
30 #include <QDragLeaveEvent>
31 #include <QWheelEvent>
32 #include <QMouseEvent>
33 #include <QDragEnterEvent>
34 #include "viewpainter.h"
35 #include "node.h"
36 
37 #include <Q3ScrollView>
38 #include <QPainter>
39 #include <Q3PtrList>
40 #include <QFile>
41 #include <QStringList>
42 
43 class Q3TextEdit;
44 class QTextEdit;
45 
46 // digital signal data
47 struct DigSignal {
48  DigSignal() { Name=""; Type=""; }
49  DigSignal(const QString& _Name, const QString& _Type = "")
50  : Name(_Name), Type(_Type) {}
51  QString Name; // name
52  QString Type; // type of signal
53 };
54 typedef QMap<QString, DigSignal> DigMap;
56 typedef struct {PE pe; int x1; int y1;int x2;int y2;int a; int b; bool PaintOnViewport;}PostedPaintEvent;
57 
58 // subcircuit, vhdl, etc. file structure
59 struct SubFile {
60  SubFile() { Type=""; File=""; PortTypes.clear(); }
61  SubFile(const QString& _Type, const QString& _File)
62  : Type(_Type), File(_File) { PortTypes.clear(); }
63  QString Type; // type of file
64  QString File; // file name identifier
65  QStringList PortTypes; // data types of in/out signals
66 };
67 typedef QMap<QString, SubFile> SubMap;
68 
69 class Schematic : public Q3ScrollView, public QucsDoc {
70  Q_OBJECT
71 public:
72  Schematic(QucsApp*, const QString&);
73  ~Schematic();
74 
75  void setName(const QString&);
76  void setChanged(bool, bool fillStack=false, char Op='*');
77  void paintGrid(ViewPainter*, int, int, int, int);
78  void print(QPrinter*, QPainter*, bool, bool);
79 
80  void paintSchToViewpainter(ViewPainter* p, bool printAll, bool toImage, int screenDpiX=96, int printerDpiX=300);
81 
82  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);
83 
84  float textCorr();
85  void sizeOfAll(int&, int&, int&, int&);
86  bool rotateElements();
87  bool mirrorXComponents();
88  bool mirrorYComponents();
89  void setOnGrid(int&, int&);
90  bool elementsOnGrid();
91 
92  float zoom(float);
93  float zoomBy(float);
94  void showAll();
95  void showNoZoom();
96  void enlargeView(int, int, int, int);
97  void switchPaintMode();
98  int adjustPortNumbers();
99  void reloadGraphs();
100  bool createSubcircuitSymbol();
101 
102  QString copySelected(bool);
103  bool paste(QTextStream*, Q3PtrList<Element>*);
104  bool load();
105  int save();
106  int saveSymbolCpp (void);
107  int saveSymbolJSON (void);
108  void becomeCurrent(bool);
109  bool undo();
110  bool redo();
111 
112  bool scrollUp(int);
113  bool scrollDown(int);
114  bool scrollLeft(int);
115  bool scrollRight(int);
116 
117  // The pointers points to the current lists, either to the schematic
118  // elements "Doc..." or to the symbol elements "SymbolPaints".
119  Q3PtrList<Wire> *Wires, DocWires;
120  Q3PtrList<Node> *Nodes, DocNodes;
121  Q3PtrList<Diagram> *Diagrams, DocDiags;
122  Q3PtrList<Painting> *Paintings, DocPaints;
123  Q3PtrList<Component> *Components, DocComps;
124 
125  Q3PtrList<Painting> SymbolPaints; // symbol definition for subcircuit
126 
127  QList<PostedPaintEvent> PostedPaintEvents;
128  bool symbolMode; // true if in symbol painting mode
129 
130 
131  int GridX, GridY;
132  int ViewX1, ViewY1, ViewX2, ViewY2; // size of the document area
133  int UsedX1, UsedY1, UsedX2, UsedY2; // document area used by elements
134 
137 
138  // Two of those data sets are needed for Schematic and for symbol.
139  // Which one is in "tmp..." depends on "symbolMode".
140  float tmpScale;
143 
144  Q3PtrList<QString> UndoStack;
145  Q3PtrList<QString> UndoSymbol; // undo stack for circuit symbol
146 
147  QFileInfo getFileInfo (void) { return FileInfo; }
148 
149 protected:
150  bool sizeOfFrame(int&, int&);
151  void paintFrame(ViewPainter*);
152 
153  // overloaded function to get actions of user
154  void drawContents(QPainter*, int, int, int, int);
155  void contentsMouseMoveEvent(QMouseEvent*);
156  void contentsMousePressEvent(QMouseEvent*);
157  void contentsMouseDoubleClickEvent(QMouseEvent*);
158  void contentsMouseReleaseEvent(QMouseEvent*);
159  void contentsWheelEvent(QWheelEvent*);
160  void contentsDropEvent(QDropEvent*);
161  void contentsDragEnterEvent(QDragEnterEvent*);
162  void contentsDragLeaveEvent(QDragLeaveEvent*);
163  void contentsDragMoveEvent(QDragMoveEvent*);
164 
165 protected slots:
166  void slotScrollUp();
167  void slotScrollDown();
168  void slotScrollLeft();
169  void slotScrollRight();
170 
171 private:
173  QFileInfo FileInfo;
174 
175 /* ********************************************************************
176  ***** The following methods are in the file *****
177  ***** "schematic_element.cpp". They only access the QPtrList *****
178  ***** pointers "Wires", "Nodes", "Diagrams", "Paintings" and *****
179  ***** "Components". *****
180  ******************************************************************** */
181 
182 public:
183  Node* insertNode(int, int, Element*);
184  Node* selectedNode(int, int);
185 
186  int insertWireNode1(Wire*);
187  bool connectHWires1(Wire*);
188  bool connectVWires1(Wire*);
189  int insertWireNode2(Wire*);
190  bool connectHWires2(Wire*);
191  bool connectVWires2(Wire*);
192  int insertWire(Wire*);
193  void selectWireLine(Element*, Node*, bool);
194  Wire* selectedWire(int, int);
195  Wire* splitWire(Wire*, Node*);
196  bool oneTwoWires(Node*);
197  void deleteWire(Wire*);
198 
199  Marker* setMarker(int, int);
200  void markerLeftRight(bool, Q3PtrList<Element>*);
201  void markerUpDown(bool, Q3PtrList<Element>*);
202 
203  Element* selectElement(float, float, bool, int *index=0);
204  void deselectElements(Element*);
205  int selectElements(int, int, int, int, bool);
206  void selectMarkers();
207  void newMovingWires(Q3PtrList<Element>*, Node*, int);
208  int copySelectedElements(Q3PtrList<Element>*);
209  bool deleteElements();
210  bool aligning(int);
211  bool distributeHorizontal();
212  bool distributeVertical();
213 
215  void insertRawComponent(Component*, bool noOptimize=true);
217  void insertComponent(Component*);
218  void activateCompsWithinRect(int, int, int, int);
219  bool activateSpecifiedComponent(int, int);
221  void setCompPorts(Component*);
222  Component* selectCompText(int, int, int&, int&);
224  Component* selectedComponent(int, int);
225  void deleteComp(Component*);
226 
227  void oneLabel(Node*);
230  void insertNodeLabel(WireLabel*);
231  void copyLabels(int&, int&, int&, int&, Q3PtrList<Element>*);
232 
233  Painting* selectedPainting(float, float);
234  void copyPaintings(int&, int&, int&, int&, Q3PtrList<Element>*);
235 
236  void getSchWidthAndHeight(int& w, int& h, int& xmin_, int& ymin_); // calculates schematic
237  void getSelAreaWidthAndHeight(int &wsel, int& hsel, int& xmin_sel_, int& ymin_sel_); // and selected area width and height in pixels
238 
239 private:
240  void insertComponentNodes(Component*, bool);
241  int copyWires(int&, int&, int&, int&, Q3PtrList<Element>*);
242  int copyComponents(int&, int&, int&, int&, Q3PtrList<Element>*);
243  void copyComponents2(int&, int&, int&, int&, Q3PtrList<Element>*);
244  bool copyComps2WiresPaints(int&, int&, int&, int&, Q3PtrList<Element>*);
245  int copyElements(int&, int&, int&, int&, Q3PtrList<Element>*);
246 
247 
248 /* ********************************************************************
249  ***** The following methods are in the file *****
250  ***** "schematic_file.cpp". They only access the QPtrLists *****
251  ***** and their pointers. ("DocComps", "Components" etc.) *****
252  ******************************************************************** */
253 
254 public:
255  bool createLibNetlist(QTextStream*, QTextEdit*, int);
256  bool createSubNetlist(QTextStream *, int&, QStringList&, QTextEdit*, int);
257  void createSubNetlistPlain(QTextStream*, QTextEdit*, int);
258  int prepareNetlist(QTextStream&, QStringList&, QTextEdit*);
259  QString createNetlist(QTextStream&, int);
260  bool loadDocument();
261  void highlightWireLabels (void);
262 
263 private:
264  int saveDocument();
265 
266  bool loadProperties(QTextStream*);
268  bool loadComponents(QTextStream*, Q3PtrList<Component> *List=0);
269  void simpleInsertWire(Wire*);
270  bool loadWires(QTextStream*, Q3PtrList<Element> *List=0);
271  bool loadDiagrams(QTextStream*, Q3PtrList<Diagram>*);
272  bool loadPaintings(QTextStream*, Q3PtrList<Painting>*);
273  bool loadIntoNothing(QTextStream*);
274 
275  QString createClipboardFile();
276  bool pasteFromClipboard(QTextStream *, Q3PtrList<Element>*);
277 
278  QString createUndoString(char);
279  bool rebuild(QString *);
280  QString createSymbolUndoString(char);
281  bool rebuildSymbol(QString *);
282 
283  static void createNodeSet(QStringList&, int&, Conductor*, Node*);
284  void throughAllNodes(bool, QStringList&, int&);
285  void propagateNode(QStringList&, int&, Node*);
286  void collectDigitalSignals(void);
287  bool giveNodeNames(QTextStream *, int&, QStringList&, QTextEdit*, int);
288  void beginNetlistDigital(QTextStream &);
289  void endNetlistDigital(QTextStream &);
290  bool throughAllComps(QTextStream *, int&, QStringList&, QTextEdit *, int);
291 
292  DigMap Signals; // collecting node names for VHDL signal declarations
293  QStringList PortTypes;
294 
295 public:
296  bool isAnalog;
297  bool isVerilog;
299 };
300 
301 #endif
bool scrollRight(int)
Definition: schematic.cpp:1963
int tmpUsedY2
Definition: schematic.h:142
static void createNodeSet(QStringList &, int &, Conductor *, Node *)
void contentsMouseMoveEvent(QMouseEvent *)
Definition: schematic.cpp:543
void deleteComp(Component *)
bool undo()
Definition: schematic.cpp:1578
int saveDocument()
int insertWireNode2(Wire *)
bool distributeVertical()
bool createSubNetlist(QTextStream *, int &, QStringList &, QTextEdit *, int)
bool connectHWires2(Wire *)
QMap< QString, DigSignal > DigMap
Definition: schematic.h:54
Q3PtrList< Painting > DocPaints
Definition: schematic.h:122
void createSubNetlistPlain(QTextStream *, QTextEdit *, int)
QString Frame_Text0
Definition: schematic.h:136
float textCorr()
Definition: schematic.cpp:922
bool connectHWires1(Wire *)
Definition: node.h:30
bool aligning(int)
Marker * setMarker(int, int)
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)
Definition: schematic.cpp:533
void slotScrollRight()
Definition: schematic.cpp:2018
Definition: wire.h:31
int copyElements(int &, int &, int &, int &, Q3PtrList< Element > *)
void simpleInsertWire(Wire *)
label for Node and Wire classes
Definition: element.h:161
int tmpViewX2
Definition: schematic.h:141
SubFile(const QString &_Type, const QString &_File)
Definition: schematic.h:61
void switchPaintMode()
Definition: schematic.cpp:1822
int tmpUsedY1
Definition: schematic.h:142
bool loadComponents(QTextStream *, Q3PtrList< Component > *List=0)
Node * selectedNode(int, int)
int insertWireNode1(Wire *)
int tmpViewY1
Definition: schematic.h:141
bool giveNodeNames(QTextStream *, int &, QStringList &, QTextEdit *, int)
QString createSymbolUndoString(char)
bool rotateElements()
Definition: schematic.cpp:1022
int adjustPortNumbers()
Definition: schematic.cpp:1350
QString Name
Definition: schematic.h:51
int selectElements(int, int, int, int, bool)
Definition: marker.h:31
void becomeCurrent(bool)
Definition: schematic.cpp:197
bool paste(QTextStream *, Q3PtrList< Element > *)
Definition: schematic.cpp:1274
int insertWire(Wire *)
QString createClipboardFile()
void contentsMouseReleaseEvent(QMouseEvent *)
Definition: schematic.cpp:575
void setOnGrid(int &, int &)
Definition: schematic.cpp:858
bool creatingLib
Definition: schematic.h:298
void showAll()
Definition: schematic.cpp:776
void copyPaintings(int &, int &, int &, int &, Q3PtrList< Element > *)
bool isVerilog
Definition: schematic.h:297
void deleteWire(Wire *)
QMap< QString, SubFile > SubMap
Definition: schematic.h:67
bool activateSelectedComponents()
void contentsWheelEvent(QWheelEvent *)
Definition: schematic.cpp:1850
int copyWires(int &, int &, int &, int &, Q3PtrList< Element > *)
bool createSubcircuitSymbol()
Definition: schematic.cpp:158
QFileInfo getFileInfo(void)
Definition: schematic.h:147
Definition: schematic.h:55
Node * insertNode(int, int, Element *)
void collectDigitalSignals(void)
void insertRawComponent(Component *, bool noOptimize=true)
Painting * selectedPainting(float, float)
bool dragIsOkay
Definition: schematic.h:172
void enlargeView(int, int, int, int)
Definition: schematic.cpp:832
PE
Definition: schematic.h:55
float zoom(float)
Definition: schematic.cpp:745
Q3PtrList< Diagram > * Diagrams
Definition: schematic.h:121
void slotScrollLeft()
Definition: schematic.cpp:2008
int ViewY1
Definition: schematic.h:132
bool copyComps2WiresPaints(int &, int &, int &, int &, Q3PtrList< Element > *)
bool loadWires(QTextStream *, Q3PtrList< Element > *List=0)
QString Type
Definition: schematic.h:52
Wire * splitWire(Wire *, Node *)
int tmpViewY2
Definition: schematic.h:141
void contentsMousePressEvent(QMouseEvent *)
Definition: schematic.cpp:550
bool connectVWires1(Wire *)
int copySelectedElements(Q3PtrList< Element > *)
void print(QPrinter *, QPainter *, bool, bool)
Definition: schematic.cpp:589
QString createNetlist(QTextStream &, int)
Q3PtrList< Component > * Components
Definition: schematic.h:123
Element * selectElement(float, float, bool, int *index=0)
bool mirrorYComponents()
Definition: schematic.cpp:1188
void throughAllNodes(bool, QStringList &, int &)
bool symbolMode
Definition: schematic.h:128
bool load()
Definition: schematic.cpp:1281
void simpleInsertComponent(Component *)
bool isAnalog
Definition: schematic.h:296
void endNetlistDigital(QTextStream &)
Q3PtrList< Diagram > DocDiags
Definition: schematic.h:121
void drawContents(QPainter *, int, int, int, int)
Definition: schematic.cpp:418
bool loadPaintings(QTextStream *, Q3PtrList< Painting > *)
Component * selectCompText(int, int, int &, int &)
Component * selectedComponent(int, int)
bool rebuild(QString *)
bool scrollDown(int)
Definition: schematic.cpp:1912
int UsedX2
Definition: schematic.h:133
QString createUndoString(char)
void slotScrollDown()
Definition: schematic.cpp:1998
int placeNodeLabel(WireLabel *)
Q3PtrList< Node > * Nodes
Definition: schematic.h:120
bool oneTwoWires(Node *)
bool distributeHorizontal()
int ViewY2
Definition: schematic.h:132
float tmpScale
Definition: schematic.h:140
bool pasteFromClipboard(QTextStream *, Q3PtrList< Element > *)
void copyComponents2(int &, int &, int &, int &, Q3PtrList< Element > *)
void paintGrid(ViewPainter *, int, int, int, int)
Definition: schematic.cpp:870
int GridX
Definition: schematic.h:131
QList< PostedPaintEvent > PostedPaintEvents
Definition: schematic.h:127
void newMovingWires(Q3PtrList< Element > *, Node *, int)
void setCompPorts(Component *)
bool sizeOfFrame(int &, int &)
Definition: schematic.cpp:332
QString File
Definition: schematic.h:64
QString Frame_Text1
Definition: schematic.h:136
QString copySelected(bool)
Definition: schematic.cpp:1265
DigSignal(const QString &_Name, const QString &_Type="")
Definition: schematic.h:49
int ViewX1
Definition: schematic.h:132
Superclass of all schematic drawing elements.
Definition: element.h:142
int tmpUsedX1
Definition: schematic.h:142
DigMap Signals
Definition: schematic.h:292
int save()
Definition: schematic.cpp:1317
void insertComponentNodes(Component *, bool)
int ViewX2
Definition: schematic.h:132
bool rebuildSymbol(QString *)
QString Frame_Text2
Definition: schematic.h:136
int showFrame
Definition: schematic.h:135
bool connectVWires2(Wire *)
void getSelAreaWidthAndHeight(int &wsel, int &hsel, int &xmin_sel_, int &ymin_sel_)
Definition: schematic.cpp:2221
void slotScrollUp()
Definition: schematic.cpp:1988
void paintSchToViewpainter(ViewPainter *p, bool printAll, bool toImage, int screenDpiX=96, int printerDpiX=300)
Definition: schematic.cpp:657
bool activateSpecifiedComponent(int, int)
void paintFrame(ViewPainter *)
Definition: schematic.cpp:351
float zoomBy(float)
Definition: schematic.cpp:766
int GridY
Definition: schematic.h:131
int copyComponents(int &, int &, int &, int &, Q3PtrList< Element > *)
void markerLeftRight(bool, Q3PtrList< Element > *)
bool createLibNetlist(QTextStream *, QTextEdit *, int)
QStringList PortTypes
Definition: schematic.h:293
Element * getWireLabel(Node *)
QFileInfo FileInfo
Definition: schematic.h:173
void reloadGraphs()
Definition: schematic.cpp:1256
int UsedY2
Definition: schematic.h:133
Schematic(QucsApp *, const QString &)
Definition: schematic.cpp:70
Component * searchSelSubcircuit()
bool throughAllComps(QTextStream *, int &, QStringList &, QTextEdit *, int)
void markerUpDown(bool, Q3PtrList< Element > *)
void contentsDragMoveEvent(QDragMoveEvent *)
Definition: schematic.cpp:2140
int saveSymbolCpp(void)
QString Type
Definition: schematic.h:63
int prepareNetlist(QTextStream &, QStringList &, QTextEdit *)
DigSignal()
Definition: schematic.h:48
Q3PtrList< Painting > SymbolPaints
Definition: schematic.h:125
void copyLabels(int &, int &, int &, int &, Q3PtrList< Element > *)
Wire * selectedWire(int, int)
Q3PtrList< QString > UndoSymbol
Definition: schematic.h:145
bool mirrorXComponents()
Definition: schematic.cpp:1119
void contentsDragEnterEvent(QDragEnterEvent *)
Definition: schematic.cpp:2069
void propagateNode(QStringList &, int &, Node *)
void selectWireLine(Element *, Node *, bool)
void contentsMouseDoubleClickEvent(QMouseEvent *)
Definition: schematic.cpp:582
void setComponentNumber(Component *)
Q3PtrList< Wire > DocWires
Definition: schematic.h:119
Definition: qucs.h:61
void activateCompsWithinRect(int, int, int, int)
int UsedX1
Definition: schematic.h:133
void recreateComponent(Component *)
void sizeOfAll(int &, int &, int &, int &)
Definition: schematic.cpp:931
void deselectElements(Element *)
bool redo()
Definition: schematic.cpp:1631
Q3PtrList< QString > UndoStack
Definition: schematic.h:144
void oneLabel(Node *)
bool loadProperties(QTextStream *)
QString Frame_Text3
Definition: schematic.h:136
bool scrollLeft(int)
Definition: schematic.cpp:1938
void contentsDropEvent(QDropEvent *)
Definition: schematic.cpp:2034
void beginNetlistDigital(QTextStream &)
void showNoZoom()
Definition: schematic.cpp:801
void setName(const QString &)
Definition: schematic.cpp:260
Q3PtrList< Node > DocNodes
Definition: schematic.h:120
Q3PtrList< Painting > * Paintings
Definition: schematic.h:122
SubFile()
Definition: schematic.h:60
bool loadDocument()
bool loadIntoNothing(QTextStream *)
Q3PtrList< Wire > * Wires
Definition: schematic.h:119
int UsedY1
Definition: schematic.h:133
QStringList PortTypes
Definition: schematic.h:65
bool loadDiagrams(QTextStream *, Q3PtrList< Diagram > *)
int tmpUsedX2
Definition: schematic.h:142
void getSchWidthAndHeight(int &w, int &h, int &xmin_, int &ymin_)
Definition: schematic.cpp:2155
void insertComponent(Component *)
void highlightWireLabels(void)
bool elementsOnGrid()
Definition: schematic.cpp:1685
bool scrollUp(int)
Definition: schematic.cpp:1887
void setChanged(bool, bool fillStack=false, char Op='*')
Definition: schematic.cpp:278
int tmpViewX1
Definition: schematic.h:141
void insertNodeLabel(WireLabel *)
int saveSymbolJSON(void)
Q3PtrList< Component > DocComps
Definition: schematic.h:123
void contentsDragLeaveEvent(QDragLeaveEvent *)
Definition: schematic.cpp:2123