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 CIRCUIT_H 00012 #define CIRCUIT_H 00013 00014 #include <qguardedptr.h> 00015 #include "qstringlist.h" 00016 #include "qvaluelist.h" 00017 00018 #include "elementset.h" 00019 00020 class CircuitDocument; 00021 class Wire; 00022 class Pin; 00023 class Element; 00024 class LogicOut; 00025 00026 typedef QValueList<QGuardedPtr<Pin> > PinList; 00027 00028 class LogicCacheNode 00029 { 00030 public: 00031 LogicCacheNode(); 00032 ~LogicCacheNode(); 00033 00034 LogicCacheNode *high; 00035 LogicCacheNode *low; 00036 QuickVector *data; 00037 }; 00038 00052 class Circuit 00053 { 00054 public: 00055 Circuit(); 00056 ~Circuit(); 00057 00058 void addPin( Pin *node ); 00059 void addElement( Element *element ); 00060 00061 bool contains( Pin *node ); 00062 bool containsNonLinear() const { return m_elementSet->containsNonLinear(); } 00063 00064 void init(); 00065 00070 void initCache(); 00071 00075 void setCacheInvalidated(); 00076 00080 void doNonLogic(); 00081 00085 void doLogic() { m_elementSet->doLinear(false); } 00086 00087 void displayEquations(); 00088 void updateCurrents(); 00089 00090 void createMatrixMap(); 00091 00100 static int identifyGround( PinList nodeList, int *highest = 0 ); 00101 00102 void setNextChanged( Circuit * circuit, unsigned char chain ) { m_pNextChanged[chain] = circuit; } 00103 Circuit * nextChanged( unsigned char chain ) const { return m_pNextChanged[chain]; } 00104 void setCanAddChanged( bool canAdd ) { m_bCanAddChanged = canAdd; } 00105 bool canAddChanged() const { return m_bCanAddChanged; } 00106 00107 protected: 00108 void cacheAndUpdate(); 00109 00113 void updateNodalVoltages(); 00114 00118 void stepReactive(); 00119 00123 static bool recursivePinAdd( Pin *node, PinList *unassignedNodes, PinList *associated, PinList *nodes ); 00124 00125 int m_cnodeCount; 00126 int m_branchCount; 00127 int m_prepNLCount; // Count until next m_elementSet->prepareNonLinear() is called 00128 00129 PinList m_pinList; 00130 ElementList m_elementList; 00131 ElementSet *m_elementSet; 00132 00133 //Stuff for caching 00134 bool m_bCanCache; 00135 LogicCacheNode * m_pLogicCacheBase; 00136 unsigned m_logicOutCount; 00137 LogicOut ** m_pLogicOut; 00138 00139 bool m_bCanAddChanged; 00140 Circuit * m_pNextChanged[2]; 00141 }; 00142 00143 #endif 00144
1.5.1