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 CONNECTOR_H 00012 #define CONNECTOR_H 00013 00014 #include <qcanvas.h> 00015 #include <qguardedptr.h> 00016 #include <qvaluevector.h> 00017 00018 class Cell; 00019 class ConnectorData; 00020 class ConnectorLine; 00021 class ConRouter; 00022 class CNItem; 00023 class ICNDocument; 00024 class Node; 00025 class NodeGroup; 00026 class Wire; 00027 00028 typedef QValueList<ConnectorLine*> ConnectorLineList; 00029 typedef QValueList<QPoint> QPointList; 00030 typedef QValueVector<QGuardedPtr<Wire> > WireVector; 00031 00032 00038 /* 00039 TODO: Audit/enhance this code. 00040 */ 00041 00042 class Connector : public QObject, public QCanvasPolygon 00043 { 00044 Q_OBJECT 00045 public: 00046 Connector( Node *startNode, Node *endNode, ICNDocument *_ICNDocument, QString *id = 0 ); 00047 ~Connector(); 00048 00049 virtual int rtti() const; 00050 00054 Node * startNode() const { return m_startNode; } 00055 00059 Node * endNode() const { return m_endNode; } 00060 00064 ConnectorData connectorData() const; 00065 00069 void restoreFromConnectorData( const ConnectorData &connectorData ); 00070 00074 virtual void setSelected( bool yes ); 00075 00079 QString id() const { return m_id; } 00080 00085 void updateDrawList(); 00086 00092 void setNodeGroup( NodeGroup *nodeGroup ) { p_nodeGroup = nodeGroup; } 00093 00097 NodeGroup *nodeGroup() const { return p_nodeGroup; } 00098 00105 void updateConnectorPoints( bool add ); 00106 00114 void setRoutePoints( QPointList pointList, bool setManual, bool checkEndPoints = false ); 00115 00121 void setSemiHidden( bool semiHidden ); 00122 00126 void setParentContainer( const QString &cnItemId ); 00127 00131 CNItem *parentContainer() const { return p_parentContainer; } 00132 00136 bool usesManualPoints() const { return b_manualPoints; } 00137 00142 QValueList<QPointList> splitConnectorPoints( const QPoint &pos ) const; 00143 00147 ICNDocument *icnDocument() const { return p_icnDocument; } 00148 00153 bool pointsAreReverse( const QPointList &pointList ) const; 00154 00160 QPointList connectorPoints( bool reverse = false ) const; 00161 00166 void rerouteConnector(); 00167 00172 void translateRoute( int dx, int dy ); 00173 virtual void setVisible( bool yes ); 00174 WireVector wires() const { return m_wires; } 00175 unsigned numWires() const { return m_wires.size(); } 00176 Wire * wire( unsigned num = 0 ) const { return (num < m_wires.size()) ? m_wires[num] : 0; } 00177 00178 signals: 00179 void removed( Connector *connector ); 00180 void selected( bool yes ); 00181 void numWiresChanged( unsigned newNum ); 00182 00183 public slots: 00184 void removeConnector( Node* = 0 ); 00189 void syncWiresWithNodes(); 00190 00191 protected: 00192 void updateConnectorLines(); 00193 00194 bool m_bIsSyncingWires; 00195 bool b_semiHidden; 00196 QGuardedPtr<Node> m_startNode; 00197 QGuardedPtr<Node> m_endNode; 00198 NodeGroup *p_nodeGroup; 00199 CNItem *p_parentContainer; 00200 ICNDocument *p_icnDocument; 00201 ConRouter *m_conRouter; 00202 QString m_id; 00203 ConnectorLineList m_connectorLineList; 00204 QRect m_oldBoundRect; 00205 WireVector m_wires; 00206 bool b_deleted; 00207 bool b_manualPoints; 00208 bool b_pointsAdded; 00209 }; 00210 typedef QValueList<QGuardedPtr<Connector> > ConnectorList; 00211 00212 00213 //BEGIN ConnectorLine things 00214 class ConnectorLine : public QObject, public QCanvasLine 00215 { 00216 public: 00217 ConnectorLine( Connector *connector ); 00218 Connector *parent() const { return p_connector; } 00219 virtual int rtti() const; 00220 00221 protected: 00222 Connector *p_connector; 00223 }; 00224 //END ConnectorLine things 00225 00226 #endif 00227
1.5.1