GME  13
AutoRouterGraph.h
Go to the documentation of this file.
00001 // AutoRouterGraph.h : Declaration of the CAutoRouterGraph
00002 
00003 #pragma once
00004 #include "../resource.h"       // main symbols
00005 
00006 #include "ArHelper.h" 
00007 #include "AutoRouterPath.h"
00008 #include "AutoRouterEdge.h"
00009 #include "AutoRouterPort.h"
00010 #include "AutoRouterBox.h"
00011 
00012 #include <vector>
00013 #include <algorithm>
00014 
00015 
00016 typedef std::vector<CAutoRouterBox*> CAutoRouterBoxList;
00017 typedef std::vector<CAutoRouterPath*> CAutoRouterPathList;
00018 
00019 typedef CList<CPoint, CPoint&> CPointList;
00020 
00021 
00022 // CAutoRouterGraph
00023 class CAutoRouterGraph : public CObject
00024 {
00025 public:
00026         CAutoRouterGraph();
00027 
00028 //box:
00029 
00030 private:
00031         void Remove(CAutoRouterBox* box);
00032 
00033         void DeleteAllBoxes();
00034         const CAutoRouterBoxList& GetBoxList() const { return boxes; }
00035         bool HasNoBox() const { return boxes.size() == 0; }
00036         int GetBoxCount() const { return boxes.size(); }
00037 
00038         void SetPortAttr(CAutoRouterPort* port, unsigned int attr);
00039 
00040         bool IsRectClipBoxes(const CRect& rect) const;
00041         bool IsLineClipBoxes(const CPoint& p1, const CPoint& p2) const;
00042         bool CanBoxAt(const CRect& rect) const;
00043         CAutoRouterBox* GetBoxAt(const CPoint& point, int nearness = 0) const;
00044 
00045         CAutoRouterBox* AddAtomicPort(const CRect& rect, unsigned int attr);
00046 
00047 //path:
00048         void Add(CAutoRouterPath* path);
00049         void Remove(CAutoRouterPath* path);
00050 
00051         void DeleteAllPaths();
00052         bool HasNoPath() const { return paths.size() == 0; }
00053         int GetPathCount() const { return paths.size(); }
00054 
00055         CAutoRouterEdge* GetListEdgeAt(const CPoint& point, int nearness = 0) const;
00056 
00057 // --- Boxes && Paths (FOR EXTERNAL USE)
00058 
00059         bool IsEmpty() const { return (boxes.size() == 0) && (paths.size() == 0); }
00060 
00061         CRect GetSurroundRect(void) const;
00062 
00063 // --- Navigation
00064 
00065         CAutoRouterBox* GetOutOfBox(CPoint& point, RoutingDirection dir) const;
00066         CAutoRouterBox* GoToNextBox(CPoint& point, RoutingDirection dir, long stophere) const;
00067         CAutoRouterBox* GoToNextBox(CPoint& point, RoutingDirection dir, CPoint& stophere) const 
00068                 { return GoToNextBox(point, dir, GetPointCoord(stophere, dir)); }
00069 
00070         CAutoRouterBox* GoToNextBox(CPoint& point, RoutingDirection dir, long stop1, long stop2) const
00071                 { return GoToNextBox(point, dir, ChooseInDir(stop1, stop2, ReverseDir(dir))); }
00072         CAutoRouterBox* GoToNextBox(CPoint& point, RoutingDirection dir, CPoint& stop1, CPoint& stop2) const
00073                 { return GoToNextBox(point, dir, GetPointCoord(stop1, dir), GetPointCoord(stop2, dir)); }
00074 
00075         void GetLimitsOfEdge(const CPoint& start, const CPoint& end, long& min, long& max) const;
00076         bool IsPointInBox(const CPoint& point) const { return GetBoxAt(point) != NULL; }
00077 
00078         bool Connect(CAutoRouterPath* path);
00079         bool Connect(CAutoRouterPath* path, CPoint& startpoint, CPoint& endpoint);
00080 
00081         void ConnectPoints(CPointListPath& ret, CPoint& startpoint, CPoint& endpoint, RoutingDirection hintstartdir, RoutingDirection hintenddir);
00082 
00083         void DisconnectAll();
00084         void Disconnect(CAutoRouterPath* path);
00085 
00086         void DisconnectPathsClipping(const CRect& rect);
00087         void DisconnectPathsFrom(CAutoRouterBox* box);
00088         void DisconnectPathsFrom(CAutoRouterPort* port);
00089 
00090 // --- Edges
00091 
00092         void AddSelfEdges(void);
00093         void AddEdges(CAutoRouterGraph* graph);
00094         void AddEdges(CAutoRouterBox* box);
00095         void AddEdges(CAutoRouterPort* port);
00096         bool AddEdges(CAutoRouterPath* path);
00097         void DeleteEdges(CObject* object);
00098 
00099         void AddAllEdges();
00100         void DeleteAllEdges();
00101 
00102         void AddBoxAndPortEdges(CAutoRouterBox* box);
00103         void DeleteBoxAndPortEdges(CAutoRouterBox* box);
00104 
00105         CAutoRouterEdgeList& GetEdgeList(bool ishorizontal);
00106 
00107         CAutoRouterEdgeList horizontal;
00108         CAutoRouterEdgeList vertical;
00109 
00110 // --- Path && Edges
00111 
00112         bool CanDeleteTwoEdgesAt(CAutoRouterPath* path, CPointListPath& points, POSITION pos) const;
00113         void DeleteTwoEdgesAt(CAutoRouterPath* path, CPointListPath& points, POSITION pos);
00114         void DeleteSamePointsAt(CAutoRouterPath* path, CPointListPath& points, POSITION pos);
00115         bool SimplifyPaths();
00116         void CenterStairsInPathPoints(CAutoRouterPath* path, RoutingDirection hintstartdir, RoutingDirection hintenddir);
00117         void SimplifyPathPoints(CAutoRouterPath* path);
00118         void ConnectAllDisconnectedPaths();
00119 
00120 public:
00121         CAutoRouterBox* CreateBox(void) const;
00122         void AddBox(CAutoRouterBox* box);
00123         void DeleteBox(CAutoRouterBox* box);
00124         void ShiftBoxBy(CAutoRouterBox* box, const CPoint& offset);
00125 
00126         long AutoRoute(long aspect);
00127         void DeletePath(CAutoRouterPath* path);
00128         void DeleteAll(bool addBackSelfEdges = false);
00129         CAutoRouterPath* GetPathAt(const CPoint& point, long nearness);
00130         CAutoRouterPath* AddPath(bool isAutoRouted, CAutoRouterPort* startport, CAutoRouterPort* endport);
00131         bool IsEdgeFixed(CAutoRouterPath* path, const CPoint& startpoint, const CPoint& endpoint);
00132 
00133         CPoint* GetSelfPoints(void) const;
00134         const CAutoRouterPathList& GetPathList() const { return paths; }
00135 
00136         void Destroy(void);
00137 
00138 private:
00139         CAutoRouterBoxList boxes;
00140         CAutoRouterPathList paths;
00141 
00142         CPoint selfpoints[4];
00143         void CalculateSelfPoints();
00144 
00145 // --- Debug
00146 
00147 #ifdef _DEBUG
00148 public:
00149         virtual void AssertValid() const;
00150         void AssertValidBox(CAutoRouterBox* box) const;
00151         void AssertValidPath(CAutoRouterPath* path) const;
00152         void DumpPaths(int pos, int c);
00153         void DumpEdgeLists(void);
00154 #endif
00155 };