00001 #ifndef _GRAPH_H_ 00002 #define _GRAPH_H_ 00003 00004 #include <vector> 00005 00006 #define GME_GRID_SIZE 7 // from GME GMEStd.h 00007 00008 struct Node; 00009 struct Edge; 00010 00011 typedef std::vector<Node*> NodeVec; 00012 typedef std::vector<Edge*> EdgeVec; 00013 00014 struct IMgaFCO; 00015 00016 struct Node 00017 { 00018 Node( int sx, int sy ) 00019 { 00020 m_sx = sx; 00021 m_sy = sy; 00022 m_parent = NULL; 00023 m_fco = NULL; 00024 } 00025 00026 Node( Node * parent, int x, int y, int sx, int sy ) 00027 { 00028 m_parent = parent; 00029 m_x = x; 00030 m_y = y; 00031 m_sx = sx; 00032 m_sy = sy; 00033 m_fco = NULL; 00034 } 00035 00036 int m_nodeId; 00037 bool m_connectedToOthers; 00038 int m_subGraph; // for graph coloring algorithms 00039 Node * m_parent; 00040 int m_x; 00041 int m_y; 00042 int m_sx; 00043 int m_sy; 00044 NodeVec m_ports; 00045 EdgeVec m_edges; 00046 IMgaFCO * m_fco; 00047 }; 00048 00049 struct Edge 00050 { 00051 Edge( Node * nodeFrom, Node * nodeTo ) 00052 { 00053 m_nodeFrom = nodeFrom; 00054 m_nodeTo = nodeTo; 00055 cannotStartToEast = false; 00056 cannotStartToEast = false; 00057 cannotStartToWest = false; 00058 cannotStartToNorth = false; 00059 cannotStartToSouth = false; 00060 cannotEndFromEast = false; 00061 cannotEndFromWest = false; 00062 cannotEndFromNorth = false; 00063 cannotEndFromSouth = false; 00064 } 00065 00066 Node * getTopLevelFrom() 00067 { 00068 if( m_nodeFrom == NULL || m_nodeFrom->m_parent == NULL ) 00069 return m_nodeFrom; 00070 else 00071 return m_nodeFrom->m_parent; 00072 } 00073 00074 Node * getTopLevelTo() 00075 { 00076 if( m_nodeTo == NULL || m_nodeTo->m_parent == NULL ) 00077 return m_nodeTo; 00078 else 00079 return m_nodeTo->m_parent; 00080 } 00081 00082 Node * m_nodeFrom; 00083 Node * m_nodeTo; 00084 bool cannotStartToEast; 00085 bool cannotStartToWest; 00086 bool cannotStartToNorth; 00087 bool cannotStartToSouth; 00088 bool cannotEndFromEast; 00089 bool cannotEndFromWest; 00090 bool cannotEndFromNorth; 00091 bool cannotEndFromSouth; 00092 int x1; 00093 int y1; 00094 int x2; 00095 int y2; 00096 }; 00097 00098 class Graph 00099 { 00100 public: 00101 Graph (); 00102 00103 Graph ( int nodeNum, int edgeNum ); 00104 00105 virtual ~Graph (); 00106 00107 int getNumberOfSubGraphs (); 00108 00109 //protected: 00110 void fillConnectedToOthersFiled (); 00111 00112 void fillSubGraphFieldForOneNode( Node * n, int subGraph ); 00113 00114 void fillSubGraphField (); 00115 00116 void clear(); 00117 00118 int m_numberOfSubGraphs; 00119 NodeVec m_nodes; 00120 EdgeVec m_edges; 00121 00122 }; 00123 00124 #endif // _GRAPH_H_