00001 /*************************************************************************** 00002 * Copyright (C) 2003-2005 by David Saxton * 00003 * david@bluehaze.org * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 ***************************************************************************/ 00010 00011 #ifndef CIRCUITDOCUMENT_H 00012 #define CIRCUITDOCUMENT_H 00013 00014 #include "icndocument.h" 00015 00016 // TODO: should probably be moved to electronics. 00017 00018 class Circuit; 00019 class Component; 00020 class Connector; 00021 class ECNode; 00022 class Element; 00023 class ICNDocument; 00024 class KTechlab; 00025 class Pin; 00026 class QTimer; 00027 class Switch; 00028 class Wire; 00029 00030 class KActionMenu; 00031 00032 typedef QValueList<Circuit*> CircuitList; 00033 typedef QValueList<Component*> ComponentList; 00034 typedef QValueList<QGuardedPtr<Connector> > ConnectorList; 00035 typedef QValueList<ECNode*> ECNodeList; 00036 typedef QValueList<Element*> ElementList; 00037 typedef QValueList<QGuardedPtr<Pin> > PinList; 00038 typedef QValueList<Switch*> SwitchList; 00039 typedef QValueList<QGuardedPtr<Wire> > WireList; 00040 00041 class Circuitoid 00042 { 00043 public: 00044 bool contains( Pin *node ) { return pinList.contains(node); } 00045 bool contains( Wire *con ) { return wireList.contains(con); } 00046 bool contains( Element *ele ) { return elementList.contains(ele); } 00047 00048 void addPin( Pin *node ) { if (node && !contains(node)) pinList += node; } 00049 void addWire( Wire *con ) { if (con && !contains(con)) wireList += con; } 00050 void addElement( Element *ele ) { if (ele && !contains(ele)) elementList += ele; } 00051 00052 WireList wireList; 00053 PinList pinList; 00054 ElementList elementList; 00055 }; 00056 00064 class CircuitDocument : public ICNDocument 00065 { 00066 Q_OBJECT 00067 public: 00068 CircuitDocument( const QString &caption, KTechlab *ktechlab, const char *name = 0 ); 00069 ~CircuitDocument(); 00070 00071 virtual View *createView( ViewContainer *viewContainer, uint viewAreaId, const char *name = 0 ); 00072 00073 void calculateConnectorCurrents(); 00077 int countExtCon( const ItemList &cnItemList ) const; 00078 00079 virtual void update(); 00080 00081 public slots: 00085 void createSubcircuit(); 00086 void displayEquations(); 00087 void setOrientation0(); 00088 void setOrientation90(); 00089 void setOrientation180(); 00090 void setOrientation270(); 00091 void rotateCounterClockwise(); 00092 void rotateClockwise(); 00093 void itemFlip(); 00099 virtual void slotInitItemActions( Item *item = 0 ); 00100 void requestAssignCircuits(); 00101 void componentAdded( Item * item ); 00102 void componentRemoved( Item * item ); 00103 void connectorAdded( Connector * connector ); 00104 virtual void slotUpdateConfiguration(); 00105 00106 protected: 00107 virtual void itemAdded( Item * item ); 00108 virtual void fillContextMenu( const QPoint &pos ); 00109 virtual bool isValidItem( Item *item ); 00110 virtual bool isValidItem( const QString &itemId ); 00111 00112 KActionMenu * m_pOrientationAction; 00113 00114 private slots: 00115 void assignCircuits(); 00116 00117 private: 00122 bool tryAsLogicCircuit( Circuitoid *circuitoid ); 00126 Circuit *createCircuit( Circuitoid *circuitoid ); 00137 void getPartition( Pin * pin, PinList * pinList, PinList * unassignedPins, bool onlyGroundDependent = false ); 00142 void splitIntoCircuits( PinList * pinList ); 00146 void recursivePinAdd( Pin * pin, Circuitoid *circuitoid, PinList * unassignedPins ); 00147 void deleteCircuits(); 00148 00149 QTimer *m_updateCircuitsTmr; 00150 CircuitList m_circuitList; 00151 ComponentList m_toSimulateList; 00152 ComponentList m_componentList; // List is built up during call to assignCircuits 00153 PinList m_pinList; 00154 WireList m_wireList; 00155 SwitchList m_switchList; 00156 }; 00157 00158 #endif 00159
1.5.1