1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
/***************************************************************************
* Copyright (C) 2003-2005 by David Saxton *
* [email protected] *
* *
* 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 CIRCUITDOCUMENT_H
#define CIRCUITDOCUMENT_H
#include "icndocument.h"
class Circuit;
class Component;
class Connector;
class ECNode;
class Element;
class ICNDocument;
class KTechlab;
class Pin;
class QTimer;
class Switch;
class Wire;
class KActionMenu;
typedef QValueList<Circuit*> CircuitList;
typedef QValueList<Component*> ComponentList;
typedef QValueList<QGuardedPtr<Connector> > ConnectorList;
typedef QValueList<ECNode*> ECNodeList;
typedef QValueList<Element*> ElementList;
typedef QValueList<QGuardedPtr<Pin> > PinList;
typedef QValueList<Switch*> SwitchList;
typedef QValueList<QGuardedPtr<Wire> > WireList;
class Circuitoid
{
public:
bool contains( Pin *node ) { return pinList.contains(node); }
bool contains( Wire *con ) { return wireList.contains(con); }
bool contains( Element *ele ) { return elementList.contains(ele); }
void addPin( Pin *node ) { if (node && !contains(node)) pinList += node; }
void addWire( Wire *con ) { if (con && !contains(con)) wireList += con; }
void addElement( Element *ele ) { if (ele && !contains(ele)) elementList += ele; }
WireList wireList;
PinList pinList;
ElementList elementList;
};
/**
CircuitDocument handles allocation of the components displayed in the ICNDocument
to various Circuits, where the simulation can be performed, and displays the
information from those simulations back on the ICNDocument
@short Circuit view
@author David Saxton
*/
class CircuitDocument : public ICNDocument
{
Q_OBJECT
public:
CircuitDocument( const QString &caption, KTechlab *ktechlab, const char *name = 0L );
~CircuitDocument();
virtual View *createView( ViewContainer *viewContainer, uint viewAreaId, const char *name = 0l );
void calculateConnectorCurrents();
/**
* Count the number of ExternalConnection components in the CNItemList
*/
int countExtCon( const ItemList &cnItemList ) const;
virtual void update();
public slots:
/**
* Creates a subcircuit from the currently selected components
*/
void createSubcircuit();
void displayEquations();
void setOrientation0();
void setOrientation90();
void setOrientation180();
void setOrientation270();
void rotateCounterClockwise();
void rotateClockwise();
void itemFlip();
/**
* Enables / disables / selects various actions depending on what is
* selected or not.
* @param plugContextMenu If true, then will insert actions into contextmenu
*/
virtual void slotInitItemActions( Item *item = 0L );
void requestAssignCircuits();
void componentAdded( Item * item );
void componentRemoved( Item * item );
void connectorAdded( Connector * connector );
virtual void slotUpdateConfiguration();
protected:
virtual void itemAdded( Item * item );
virtual void fillContextMenu( const QPoint &pos );
virtual bool isValidItem( Item *item );
virtual bool isValidItem( const QString &itemId );
KActionMenu * m_pOrientationAction;
private slots:
void assignCircuits();
private:
/**
* If the given circuitoid can be a LogicCircuit, then it will be added to
* m_logicCircuits, and return true. Else returns false.
*/
bool tryAsLogicCircuit( Circuitoid *circuitoid );
/**
* Creates a circuit from the circuitoid
*/
Circuit *createCircuit( Circuitoid *circuitoid );
/**
* @param node Current node (will be added, then tested for further
* connections).
* @param nodeList List of nodes in current partition.
* @param unassignedNodes The pool of all nodes in the CircuitDocument
* waiting for assignment.
* @param onlyGroundDependent if true, then the partition will not use
* circuit-dependent pins to include new pins while growing the
* partition.
*/
void getPartition( Pin * pin, PinList * pinList, PinList * unassignedPins, bool onlyGroundDependent = false );
/**
* Takes the nodeList (generated by getPartition), splits it at ground nodes,
* and creates circuits from each split.
*/
void splitIntoCircuits( PinList * pinList );
/**
* Construct a circuit from the given node, stopping at the groundnodes
*/
void recursivePinAdd( Pin * pin, Circuitoid *circuitoid, PinList * unassignedPins );
void deleteCircuits();
QTimer *m_updateCircuitsTmr;
CircuitList m_circuitList;
ComponentList m_toSimulateList;
ComponentList m_componentList; // List is built up during call to assignCircuits
PinList m_pinList;
WireList m_wireList;
SwitchList m_switchList;
};
#endif
|