component.h

00001 /***************************************************************************
00002  *   Copyright (C) 2003 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 COMPONENT_H
00012 #define COMPONENT_H
00013 
00014 #include "cnitem.h"
00015 
00016 #include <qvaluelist.h>
00017 
00018 class ICNDocument;
00019 class CircuitDocument;
00020 class ECNode;
00021 class ECSubcircuit;
00022 class Element;
00023 class Node;
00024 class Pin;
00025 
00026 class BJT;
00027 class Capacitance;
00028 class CCCS;
00029 class CCVS;
00030 class CurrentSignal;
00031 class CurrentSource;
00032 class Diode;
00033 class Inductance;
00034 class LogicIn;
00035 class LogicOut;
00036 class OpAmp;
00037 class Resistance;
00038 class Switch;
00039 class Transformer;
00040 class VCCS;
00041 class VCVS;
00042 class VoltagePoint;
00043 class VoltageSignal;
00044 class VoltageSource;
00045 
00046 typedef QValueList<ECNode*> ECNodeList;
00047 typedef QValueList<Element*> ElementList;
00048 typedef QValueList<Switch*> SwitchList;
00049 
00050 typedef QValueList< QValueList<Pin*> > PinListList;
00051 
00056 // FIXME: should be in it's own header/source file regardless of how tiny it is.
00057 // OR it should be moved to the same file as the other element classes. 
00058 class ElementMap
00059 {
00060         public:
00061                 ElementMap();
00062                 
00063                 Element *e; // The element
00064                 Pin *n[4]; // The Pins associated with the CNodes in the element
00065         
00067                 PinListList interCircuitDependent;
00068         
00070                 PinListList interGroundDependent;
00071 };
00072 
00073 typedef QValueList<ElementMap> ElementMapList;
00074 
00079 class Component : public CNItem
00080 {
00081         Q_OBJECT
00082 public:
00083         Component( ICNDocument *icnDocument, bool newItem, const QString &id );
00084         virtual ~Component();
00085         
00086         ECNode* createPin( double _x, double _y, int orientation, const QString &name );
00087 
00091 // Positioning
00092         virtual bool canRotate() const { return true; }
00096         int angleDegrees() const { return m_angleDegrees; }
00097 
00101         void setAngleDegrees( int degrees );
00102 
00106         bool flipped() const { return b_flipped; }
00107 
00111         void setFlipped( bool flipped );
00112 
00118         void setNodalCurrents();
00119 
00123         CircuitDocument *circuitDocument() const { return m_pCircuitDocument; }
00124 
00125         void initElements( const uint stage );
00126         virtual void finishedCreation();
00127 
00134 // FIXME: probably should be renamed to "TimeDependant" and "UpdateFortime".
00135         virtual bool doesStepNonLogic() const { return false; }
00136         virtual void stepNonLogic() {};
00137 
00146         static QWMatrix transMatrix(int angleDegrees, bool flipped, int x, int y, bool inverse = false );
00147 
00151         virtual ItemData itemData() const;
00152 
00156         virtual void restoreFromItemData(const ItemData &itemData );
00157 
00158 // FIXME: I think a common design principal states that a parent class must not know
00159 // anything about it's children. =( 
00160         BJT *createBJT(Pin *c, Pin *b, Pin *e, bool isNPN = true );
00161         BJT *createBJT(ECNode *c, ECNode *b, ECNode *e, bool isNPN = true );
00162 
00163         Capacitance *createCapacitance(Pin *n0, Pin *n1, double capacitance );
00164         Capacitance *createCapacitance(ECNode *n0, ECNode *n1, double capacitance );
00165 
00166         CCCS *createCCCS(Pin *n0, Pin *n1, Pin *n2, Pin *n3, double gain );
00167         CCCS *createCCCS(ECNode *n0, ECNode *n1, ECNode *n2, ECNode *n3, double gain );
00168 
00169         CCVS *createCCVS(Pin *n0, Pin *n1, Pin *n2, Pin *n3, double gain );
00170         CCVS *createCCVS(ECNode *n0, ECNode *n1, ECNode *n2, ECNode *n3, double gain );
00171 
00172         CurrentSignal *createCurrentSignal(Pin *n0, Pin *n1, double current );
00173         CurrentSignal *createCurrentSignal(ECNode *n0, ECNode *n1, double current );
00174 
00175         CurrentSource *createCurrentSource(Pin *n0, Pin *n1, double current );
00176         CurrentSource *createCurrentSource(ECNode *n0, ECNode *n1, double current );
00177 
00178         Diode *createDiode(Pin *n0, Pin *n1 );
00179         Diode *createDiode(ECNode *n0, ECNode *n1 );
00180 
00181         Inductance *createInductance(Pin *n0, Pin *n1, double inductance );
00182         Inductance *createInductance(ECNode *n0, ECNode *n1, double inductance );
00183 
00184         LogicIn *createLogicIn(Pin *node );
00185         LogicIn *createLogicIn(ECNode *node );
00186 
00187         LogicOut *createLogicOut(Pin *node, bool isHigh );
00188         LogicOut *createLogicOut(ECNode *node, bool isHigh );
00189 
00190         OpAmp *createOpAmp(Pin * nonInverting, Pin * out, Pin * inverting );
00191         OpAmp *createOpAmp(ECNode * nonInverting, ECNode * out, ECNode * inverting );
00192 
00193         Resistance *createResistance(Pin *n0, Pin *n1, double resistance );
00194         Resistance *createResistance(ECNode *n0, ECNode *n1, double resistance );
00195 
00196         Switch *createSwitch(Pin *n0, Pin *n1, bool open );
00197         Switch *createSwitch(ECNode *n0, ECNode *n1, bool open );
00198 
00199         VCCS *createVCCS(Pin *n0, Pin *n1, Pin *n2, Pin *n3, double gain );
00200         VCCS *createVCCS(ECNode *n0, ECNode *n1, ECNode *n2, ECNode *n3, double gain);
00201 
00202         VCVS *createVCVS(Pin *n0, Pin *n1, Pin *n2, Pin *n3, double gain );
00203         VCVS *createVCVS(ECNode *n0, ECNode *n1, ECNode *n2, ECNode *n3, double gain );
00204 
00205         VoltagePoint *createVoltagePoint(Pin *n0, double voltage );
00206         VoltagePoint *createVoltagePoint(ECNode *n0, double voltage );
00207 
00208         VoltageSignal *createVoltageSignal(Pin *n0, Pin *n1, double voltage );
00209         VoltageSignal *createVoltageSignal(ECNode *n0, ECNode *n1, double voltage );
00210 
00211         VoltageSource *createVoltageSource(Pin *n0, Pin *n1, double voltage );
00212         VoltageSource *createVoltageSource(ECNode *n0, ECNode *n1, double voltage );
00213 
00214         ECNode* ecNodeWithID(const QString &ecNodeId);
00215 
00224         void removeElement(Element *element, bool setPinsInterIndependent);
00225 
00230         void removeSwitch(Switch *sw);
00231 
00238         void removeElements( bool setPinsInterIndependent = false );
00239 
00243         SwitchList switchList() const { return m_switchList; }
00244 
00245 // Random idiot: what's this "Signals:" thing? is it a C++ feature I'm too stupid to
00246 // understand? 
00247 signals:
00251         void elementCreated(Element *element);
00252 
00256         void elementDestroyed(Element *element);
00257 
00262         void switchCreated(Switch *sw);
00263 
00267         void switchDestroyed(Switch *sw);
00268 
00269 // What's a public "slots"? Another crazy C++ Feature? 
00270 public slots:
00271         virtual void slotUpdateConfiguration();
00272         virtual void removeItem();
00273 
00274 protected:
00279         void drawPortShape(QPainter & p );
00280         virtual void itemPointsChanged();
00281         virtual void updateAttachedPositioning();
00282         virtual void initPainter(QPainter &p );
00283 
00288         virtual void deinitPainter(QPainter &p );
00289 
00294 // FIXME:  Implies special knowledge of subclass (or what should be subclass.) 
00295         void initDIP(const QStringList & pins );
00296 
00302 // FIXME: SHOULD BE SUBCLASS
00303         void initDIPSymbol(const QStringList & pins, int width );
00304 
00309         void init1PinLeft(int h1 = -1 );
00310 
00315         void init2PinLeft(int h1 = -1, int h2 = -1 );
00316 
00321         void init3PinLeft(int h1 = -1, int h2 = -1, int h3 = -1 );
00322 
00327         void init4PinLeft(int h1 = -1, int h2 = -1, int h3 = -1, int h4 = -1 );
00328 
00333         void init1PinRight(int h1 = -1 );
00334 
00339         void init2PinRight(int h1 = -1, int h2 = -1 );
00340 
00345         void init3PinRight(int h1 = -1, int h2 = -1, int h3 = -1 );
00346 
00351         void init4PinRight(int h1 = -1, int h2 = -1, int h3 = -1, int h4 = -1 );
00352 
00357         void rebuildPinInterDepedence();
00358 
00359         // Pointers to commonly used nodes
00360 // design issue: In a very complex class, performance tweeks of this type tend to
00361 // promote bugs. Perhaps a "fast component" subclass could add caching and other
00362 // performance enhancements while building on a stable, reliable API. 
00363         ECNode *m_pPNode[4];
00364         ECNode *m_pNNode[4];
00365 
00366         QGuardedPtr<CircuitDocument> m_pCircuitDocument;
00367         int m_angleDegrees;
00368         bool b_flipped;
00369 
00370 private:
00377         void setInterDependent(ElementMapList::iterator it, const QValueList<Pin*> & pins);
00378 
00382         void setAllPinsInterIndependent();
00383 
00388         void setInterCircuitDependent( ElementMapList::iterator it, const QValueList<Pin*> & pins );
00389 
00394         void setInterGroundDependent( ElementMapList::iterator it, const QValueList<Pin*> & pins );
00395 
00402         ElementMapList m_elementMapList;
00403 
00407 // FIXME: again with the switches! bleh! 
00408         SwitchList m_switchList;
00409 
00413         ElementMapList::iterator handleElement(Element *e, const QValueList<Pin*> &pins );
00414 };
00415 
00416 #endif
00417 

Generated on Tue May 8 17:05:28 2007 for KTechLab by  doxygen 1.5.1