My Project  0.0.16
QUCS Mapping
 All Classes Namespaces 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 
21 #include "wire.h"
22 #include "diagrams/diagram.h"
23 #include "paintings/painting.h"
24 #include "components/component.h"
25 #include "qucsdoc.h"
26 #include "viewpainter.h"
27 #include "node.h"
28 
29 #include <qscrollview.h>
30 #include <qpainter.h>
31 #include <qptrlist.h>
32 #include <qfile.h>
33 #include <qstringlist.h>
34 
35 class QTextEdit;
36 
37 // digital signal data
38 struct DigSignal {
39  DigSignal() { Name=""; Type=""; }
40  DigSignal(const QString& _Name, const QString& _Type = "")
41  : Name(_Name), Type(_Type) {}
42  QString Name; // name
43  QString Type; // type of signal
44 };
45 typedef QMap<QString, DigSignal> DigMap;
46 
47 // subcircuit, vhdl, etc. file structure
48 struct SubFile {
49  SubFile() { Type=""; File=""; PortTypes.clear(); }
50  SubFile(const QString& _Type, const QString& _File)
51  : Type(_Type), File(_File) { PortTypes.clear(); }
52  QString Type; // type of file
53  QString File; // file name identifier
54  QStringList PortTypes; // data types of in/out signals
55 };
56 typedef QMap<QString, SubFile> SubMap;
57 
58 class Schematic : public QScrollView, public QucsDoc {
59  Q_OBJECT
60 public:
61  Schematic(QucsApp*, const QString&);
62  ~Schematic();
63 
64  void setName(const QString&);
65  void setChanged(bool, bool fillStack=false, char Op='*');
66  void paintGrid(ViewPainter*, int, int, int, int);
67  void print(QPrinter*, QPainter*, bool, bool);
68 
69  float textCorr();
70  void sizeOfAll(int&, int&, int&, int&);
71  bool rotateElements();
72  bool mirrorXComponents();
73  bool mirrorYComponents();
74  void setOnGrid(int&, int&);
75  bool elementsOnGrid();
76 
77  float zoom(float);
78  float zoomBy(float);
79  void showAll();
80  void showNoZoom();
81  void enlargeView(int, int, int, int);
82  void switchPaintMode();
83  int adjustPortNumbers();
84  void reloadGraphs();
86 
87  QString copySelected(bool);
88  bool paste(QTextStream*, QPtrList<Element>*);
89  bool load();
90  int save();
91  int saveSymbolCpp (void);
92  void becomeCurrent(bool);
93  bool undo();
94  bool redo();
95 
96  bool scrollUp(int);
97  bool scrollDown(int);
98  bool scrollLeft(int);
99  bool scrollRight(int);
100 
101  // The pointers points to the current lists, either to the schematic
102  // elements "Doc..." or to the symbol elements "SymbolPaints".
103  QPtrList<Wire> *Wires, DocWires;
104  QPtrList<Node> *Nodes, DocNodes;
105  QPtrList<Diagram> *Diagrams, DocDiags;
106  QPtrList<Painting> *Paintings, DocPaints;
107  QPtrList<Component> *Components, DocComps;
108 
109  QPtrList<Painting> SymbolPaints; // symbol definition for subcircuit
110  bool symbolMode; // true if in symbol painting mode
111 
112 
113  int GridX, GridY;
114  int ViewX1, ViewY1, ViewX2, ViewY2; // size of the document area
115  int UsedX1, UsedY1, UsedX2, UsedY2; // document area used by elements
116 
119 
120  // Two of those data sets are needed for Schematic and for symbol.
121  // Which one is in "tmp..." depends on "symbolMode".
122  float tmpScale;
125 
126  QPtrList<QString> UndoStack;
127  QPtrList<QString> UndoSymbol; // undo stack for circuit symbol
128 
129 protected:
130  bool sizeOfFrame(int&, int&);
131  void paintFrame(ViewPainter*);
132 
133  // overloaded function to get actions of user
134  void drawContents(QPainter*, int, int, int, int);
135  void contentsMouseMoveEvent(QMouseEvent*);
136  void contentsMousePressEvent(QMouseEvent*);
137  void contentsMouseDoubleClickEvent(QMouseEvent*);
138  void contentsMouseReleaseEvent(QMouseEvent*);
139  void contentsWheelEvent(QWheelEvent*);
140  void contentsDropEvent(QDropEvent*);
141  void contentsDragEnterEvent(QDragEnterEvent*);
142  void contentsDragLeaveEvent(QDragLeaveEvent*);
143  void contentsDragMoveEvent(QDragMoveEvent*);
144 
145 protected slots:
146  void slotScrollUp();
147  void slotScrollDown();
148  void slotScrollLeft();
149  void slotScrollRight();
150 
151 private:
152  bool dragIsOkay;
153 
154 /* ********************************************************************
155  ***** The following methods are in the file *****
156  ***** "schematic_element.cpp". They only access the QPtrList *****
157  ***** pointers "Wires", "Nodes", "Diagrams", "Paintings" and *****
158  ***** "Components". *****
159  ******************************************************************** */
160 
161 public:
162  Node* insertNode(int, int, Element*);
163  Node* selectedNode(int, int);
164 
165  int insertWireNode1(Wire*);
166  bool connectHWires1(Wire*);
167  bool connectVWires1(Wire*);
168  int insertWireNode2(Wire*);
169  bool connectHWires2(Wire*);
170  bool connectVWires2(Wire*);
171  int insertWire(Wire*);
172  void selectWireLine(Element*, Node*, bool);
173  Wire* selectedWire(int, int);
174  Wire* splitWire(Wire*, Node*);
175  bool oneTwoWires(Node*);
176  void deleteWire(Wire*);
177 
178  Marker* setMarker(int, int);
179  void markerLeftRight(bool, QPtrList<Element>*);
180  void markerUpDown(bool, QPtrList<Element>*);
181 
182  Element* selectElement(float, float, bool, int *index=0);
183  void deselectElements(Element*);
184  int selectElements(int, int, int, int, bool);
185  void selectMarkers();
186  void newMovingWires(QPtrList<Element>*, Node*, int);
187  int copySelectedElements(QPtrList<Element>*);
188  bool deleteElements();
189  bool aligning(int);
190  bool distributeHorizontal();
191  bool distributeVertical();
192 
194  void insertRawComponent(Component*, bool noOptimize=true);
196  void insertComponent(Component*);
197  void activateCompsWithinRect(int, int, int, int);
198  bool activateSpecifiedComponent(int, int);
200  void setCompPorts(Component*);
201  Component* selectCompText(int, int, int&, int&);
203  Component* selectedComponent(int, int);
204  void deleteComp(Component*);
205 
206  void oneLabel(Node*);
209  void insertNodeLabel(WireLabel*);
210  void copyLabels(int&, int&, int&, int&, QPtrList<Element>*);
211 
212  Painting* selectedPainting(float, float);
213  void copyPaintings(int&, int&, int&, int&, QPtrList<Element>*);
214 
215 private:
216  void insertComponentNodes(Component*, bool);
217  int copyWires(int&, int&, int&, int&, QPtrList<Element>*);
218  int copyComponents(int&, int&, int&, int&, QPtrList<Element>*);
219  void copyComponents2(int&, int&, int&, int&, QPtrList<Element>*);
220  bool copyComps2WiresPaints(int&, int&, int&, int&, QPtrList<Element>*);
221  int copyElements(int&, int&, int&, int&, QPtrList<Element>*);
222 
223 
224 /* ********************************************************************
225  ***** The following methods are in the file *****
226  ***** "schematic_file.cpp". They only access the QPtrLists *****
227  ***** and their pointers. ("DocComps", "Components" etc.) *****
228  ******************************************************************** */
229 
230 public:
231  bool createLibNetlist(QTextStream*, QTextEdit*, int);
232  bool createSubNetlist(QTextStream*, int&, QStringList&, QTextEdit*, int);
233  void createSubNetlistPlain(QTextStream*, QTextEdit*, int);
234  int prepareNetlist(QTextStream&, QStringList&, QTextEdit*);
235  QString createNetlist(QTextStream&, int);
236  bool loadDocument();
237 
238 private:
239  int saveDocument();
240 
241  bool loadProperties(QTextStream*);
242  void simpleInsertComponent(Component*);
243  bool loadComponents(QTextStream*, QPtrList<Component> *List=0);
244  void simpleInsertWire(Wire*);
245  bool loadWires(QTextStream*, QPtrList<Element> *List=0);
246  bool loadDiagrams(QTextStream*, QPtrList<Diagram>*);
247  bool loadPaintings(QTextStream*, QPtrList<Painting>*);
248  bool loadIntoNothing(QTextStream*);
249 
250  QString createClipboardFile();
251  bool pasteFromClipboard(QTextStream*, QPtrList<Element>*);
252 
253  QString createUndoString(char);
254  bool rebuild(QString *);
255  QString createSymbolUndoString(char);
256  bool rebuildSymbol(QString *);
257 
258  static void createNodeSet(QStringList&, int&, Conductor*, Node*);
259  void throughAllNodes(bool, QStringList&, int&);
260  void propagateNode(QStringList&, int&, Node*);
261  void collectDigitalSignals(void);
262  bool giveNodeNames(QTextStream*, int&, QStringList&, QTextEdit*, int);
263  void beginNetlistDigital(QTextStream&);
264  void endNetlistDigital(QTextStream&);
265  bool throughAllComps(QTextStream *, int&, QStringList&, QTextEdit *, int);
266 
267  DigMap Signals; // collecting node names for VHDL signal declarations
268  QStringList PortTypes;
269 
270 public:
271  bool isAnalog;
272  bool isVerilog;
274 };
275 
276 #endif