GME  13
ArGraph.h
Go to the documentation of this file.
00001 //COM'd by Tamas (check AutoRouterGraph.h, AutoRouterBox.h, AutoRouterPath.h, AutoRouterPort.h)
00002 //#ifndef __ARGRAPH_H
00003 //#define __ARGRAPH_H
00004 //
00005 //#ifndef __AREDGELS_H
00006 //#include "ArEdgeLs.h"
00007 //#endif
00008 //
00009 //#ifndef __ARHELPER_H
00010 //#include "ArHelper.h"
00011 //#endif
00012 //
00013 //class CArBox;
00014 //class CArPort;
00015 //class CArPath;
00016 //class CArEdgeList;
00017 //class CArGraph;
00018 //
00019 //#define ED_MAXCOORD           100000
00020 //#define ED_MINCOORD           0
00021 //#define ED_SMALLGAP           15
00022 //
00023 //
00025 //
00026 //
00027 //typedef CTypedPtrList<CObList, CArPort*>      CArPortList;
00028 //typedef CTypedPtrList<CObList, CArBox*>               CArBoxList;
00029 //typedef CTypedPtrList<CObList, CArPath*>      CArPathList;
00030 //typedef CList<CPoint, CPoint&>                                CPointList;
00031 //
00032 //
00034 //
00035 //
00036 //#define ARPORT_EndOnTop                                       0x0001
00037 //#define ARPORT_EndOnRight                             0x0002
00038 //#define ARPORT_EndOnBottom                            0x0004
00039 //#define ARPORT_EndOnLeft                              0x0008
00040 //#define ARPORT_EndOnAll                                       0x000F
00041 //
00042 //#define ARPORT_StartOnTop                             0x0010
00043 //#define ARPORT_StartOnRight                           0x0020
00044 //#define ARPORT_StartOnBottom                  0x0040
00045 //#define ARPORT_StartOnLeft                            0x0080
00046 //#define ARPORT_StartOnAll                             0x00F0
00047 //
00048 //#define ARPORT_ConnectOnAll                           0x00FF
00049 //#define ARPORT_ConnectToCenter                        0x0100
00050 //
00051 //#define ARPORT_StartEndHorizontal             0x00AA
00052 //#define ARPORT_StartEndVertical                       0x0055
00053 //
00054 //#define ARPORT_Default                                        0x00FF
00055 //
00056 //
00057 //class CArPort: public CObject
00058 //{
00059 //public:
00060 //      CArPort();
00061 //      ~CArPort();
00062 //
00063 //      friend CArBox;
00064 //      friend CArEdgeList;
00065 //
00066 //
00067 //friend CArGraph;
00068 //friend CArPath;
00069 //friend CArEdgeList;
00070 //
00071 //      CArBox* GetOwner() const;
00072 //
00073 //private:
00074 //      void SetOwner(CArBox* box);
00075 //
00076 //      CArBox* owner;
00077 //
00079 //
00081 //private:
00082 //      int CanHaveStartEndPointOn(EArDir dir, int isstart) const;
00083 //      int CanHaveStartEndPoint(int isstart) const;
00084 //      int CanHaveStartEndPointHorizontal(int ishorizontal) const;
00085 //      int IsConnectToCenter() const { return (attributes & ARPORT_ConnectToCenter) != 0; }
00086 //      EArDir GetStartEndDirTo(CPoint point, int isstart, EArDir notthis = Dir_None) const;
00087 //
00088 //      int CanCreateStartEndPointAt(CPoint point, int isstart, int nearness = 0) const;
00089 //      CPoint CreateStartEndPointAt(CPoint point, int isstart) const;
00090 //      CPoint CreateStartEndPointOn(EArDir dir) const;
00091 //      CPoint CreateStartEndPointTo(CPoint point, int isstart) const;
00092 //
00093 //      
00094 //      unsigned int GetAttributes() const { return attributes; }
00095 //      bool HasLimitedDirs() { return limitedDirections; }
00096 //
00098 //public:
00099 //      void SetLimitedDirs( bool p_ltd) { limitedDirections = p_ltd; }
00100 //      void SetAttributes(unsigned int attr);
00101 //
00102 //private:
00103 //      unsigned int attributes;
00104 //
00106 //
00108 //private:
00109 //      CRect GetRect() const { return rect; }
00110 //      CPoint GetCenter() const { return rect.CenterPoint(); }
00111 //      int IsRectEmpty() const { return rect.IsRectEmpty(); }
00112 //      EArDir OnWhichEdge(CPoint point) const { return ::OnWhichEdge(rect, point); }
00113 //
00114 //      int IsPortAt(CPoint point, int nearness = 0) const { return IsPointIn(point, rect, nearness); }
00115 //      int IsPortIn(CRect r) const { return IsRectIn(rect, r); }
00116 //      int IsPortClip(CRect r) const { return IsRectClip(rect, r); }
00117 //
00118 //      
00119 //      void ShiftBy(CSize offset);
00121 //public:
00122 //      void SetRect(CRect rect);
00123 //
00124 //private:
00125 //      void CalculateSelfPoints();
00126 //
00127 //      bool  limitedDirections; // strictly respect the preferred directions (for ports East/West directions must be respected)
00128 //      CRect rect;
00129 //      CPoint selfpoints[4];
00130 //
00132 //
00133 //public:
00134 //      DECLARE_SERIAL(CArPort);
00135 //      virtual void Serialize(CArchive& ar);
00136 //
00137 //
00138 //private:
00139 //      int MatchStoredRef(CArPort* stored_ref) const { return stored_ref == stored_ref; }
00140 //      void ClearStoredRefs() { stored_ref = 0; }
00141 //
00142 //private:
00143 //      CArPort* stored_ref;
00144 //
00146 //
00147 //#ifdef _DEBUG
00148 //public:
00149 //      virtual void AssertValid() const;
00150 //      void AssertValidStartEndPoint(CPoint point, EArDir dir, int isstart) const;
00151 //#endif
00152 //};
00153 //
00154 //
00156 //
00157 //
00158 //class CArBox: public CObject
00159 //{
00160 //public:
00161 //      CArBox();
00162 //      ~CArBox();
00163 //
00164 //      friend CArGraph;
00165 //      friend CArEdgeList;
00166 //
00167 //      //vt:
00168 //friend CArBox;
00169 //friend CArPort;
00170 //friend CArPath;
00171 //
00172 //
00173 //      CArGraph* GetOwner() const;
00174 //
00175 //private:
00176 //      void SetOwner(CArGraph* graph);
00177 //
00178 //      CArGraph* owner;
00179 //
00181 //
00182 //public:
00183 //      CArPort* CreatePort() const;
00184 //      void Add(CArPort* port);
00185 //      void Delete(CArPort* port);
00186 //
00187 //      //vt:
00188 //private:
00189 //      void DeleteAllPorts();
00190 //      const CArPortList& GetPortList() const { return ports; }
00191 //      int HasNoPort() const { return ports.IsEmpty(); }
00192 //      int GetPortCount() const { return ports.GetCount(); }
00193 //
00194 //      CArPort* GetPortAt(CPoint point, int nearness = 0) const;
00195 //
00196 //      CArPort* AddPort(CRect rect, unsigned attr);
00197 //
00198 //private:
00199 //      CArPortList ports;
00200 //
00202 //
00204 //private:
00205 //      void SetAtomicPort(CRect rect, unsigned int attr);
00206 //      void SetAtomicPort(CArPort* port);
00207 //      CArPort* GetAtomicPort() const;
00208 //      int IsAtomic() const { return atomic; }
00209 //
00210 //private:
00211 //      int atomic;
00212 //
00214 //
00216 //private:
00217 //      CRect GetRect() const { return rect; }
00218 //      int IsRectEmpty() const { return rect.IsRectEmpty(); }
00219 //
00220 //      int IsBoxAt(CPoint point, int nearness = 0) const { return IsPointIn(point, rect, nearness); }
00221 //      int IsBoxClip(CRect r) const { return IsRectClip(rect, r); }
00222 //      int IsBoxIn(CRect r) const { return IsRectIn(rect, r); }
00223 //
00224 //
00225 //      void SetRect(CPoint point) { ShiftBy(point - rect.TopLeft()); }
00226 //      void ShiftBy(CSize offset);
00227 //
00229 //public:
00230 //      void SetRect(CRect rect);
00231 //
00232 //private:
00233 //      void CalculateSelfPoints();
00234 //
00235 //      CRect rect;
00236 //      CPoint selfpoints[4];
00237 //
00239 //
00240 //public:
00241 //      DECLARE_SERIAL(CArBox);
00242 //      virtual void Serialize(CArchive& ar);
00244 //private:
00245 //      CArPort* ResolveStoredRef(CArPort* stored_ref);
00246 //      void ClearStoredRefs();
00247 //
00249 //
00250 //#ifdef _DEBUG
00251 //public:
00252 //      virtual void AssertValid() const;
00253 //      void AssertValidPort(const CArPort* port) const;
00254 //#endif
00255 //};
00256 //
00257 //
00259 //
00260 //#define ARPATH_EndOnDefault           0x0000
00261 //#define ARPATH_EndOnTop                       0x0010
00262 //#define ARPATH_EndOnRight             0x0020
00263 //#define ARPATH_EndOnBottom            0x0040
00264 //#define ARPATH_EndOnLeft              0x0080
00265 //#define ARPATH_EndMask                        (ARPATH_EndOnTop | ARPATH_EndOnRight | ARPATH_EndOnBottom | ARPATH_EndOnLeft)
00266 //
00267 //
00268 //#define ARPATH_StartOnDefault 0x0000
00269 //#define ARPATH_StartOnTop             0x0100
00270 //#define ARPATH_StartOnRight           0x0200
00271 //#define ARPATH_StartOnBottom  0x0400
00272 //#define ARPATH_StartOnLeft            0x0800
00273 //#define ARPATH_StartMask              (ARPATH_StartOnTop | ARPATH_StartOnRight | ARPATH_StartOnBottom | ARPATH_StartOnLeft)
00274 //
00275 //#define ARPATH_HighLighted            0x0002          // attributes
00276 //#define ARPATH_Fixed                  0x0001
00277 //#define ARPATH_Default                        0x0000
00278 //
00279 //#define ARPATHST_Connected            0x0001          // states
00280 //#define ARPATHST_Default              0x0000
00281 //
00282 //class CArPath: public CObject
00283 //{
00284 //public:
00285 //      CArPath();
00286 //      ~CArPath();
00287 //
00288 //      friend CArGraph;
00289 //      friend CArEdgeList;
00290 //      friend CArPort;
00291 //      friend CArBox;
00292 //
00293 //      CArGraph* GetOwner() const;
00294 //
00295 //private:
00296 //      void SetOwner(CArGraph* graph);
00297 //
00298 //      CArGraph* owner;
00299 //
00301 //
00302 //public:
00303 //private:
00304 //      void SetStartPort(CArPort* port);
00305 //      void SetEndPort(CArPort* port);
00306 //      void ClearPorts();
00307 //      CArPort* GetStartPort() const;
00308 //      CArPort* GetEndPort() const;
00309 //      CArBox* GetStartBox() const { return GetStartPort()->GetOwner(); }
00310 //      CArBox* GetEndBox() const { return GetEndPort()->GetOwner(); }
00311 //
00312 //private:
00313 //      CArPort* startport;                                                     // reference
00314 //      CArPort* endport;                                                       // reference
00315 //
00317 //
00318 //public:
00319 //      const CPointList& GetPointList() const { return points; }
00320 //private:
00321 //      void AddTail(CPoint point);
00322 //      void DeleteAll();
00323 //      
00324 //      int HasNoPoint() const { return points.IsEmpty(); }
00325 //      int GetPointCount() const { return points.GetCount(); }
00326 //
00327 //      CPoint GetStartPoint() const;
00328 //      CPoint GetEndPoint() const;
00329 //      CPoint GetOutOfBoxStartPoint() const;
00330 //      CPoint GetOutOfBoxEndPoint() const;
00331 //
00332 //      POSITION GetPointPosAt(CPoint point, int nearness = 0) const;
00333 //      POSITION GetEdgePosAt(CPoint point, int nearness = 0) const;
00334 //
00335 //private:
00336 //      void SimplifyTrivially();
00337 //
00338 //      CPointList points;
00339 //
00341 //
00342 //public:
00343 //private:
00344 //      POSITION GetHeadEdge(CPoint& start, CPoint& end) const;
00345 //      POSITION GetTailEdge(CPoint& start, CPoint& end) const;
00346 //      void GetNextEdge(POSITION& pos, CPoint& start, CPoint& end) const;
00347 //      void GetPrevEdge(POSITION& pos, CPoint& start, CPoint& end) const;
00348 //      void GetEdge(POSITION pos, CPoint& start, CPoint& end) const;
00349 //
00350 //private:
00351 //      POSITION GetHeadEdgePtrs(CPoint*& start, CPoint*& end);
00352 //      POSITION GetTailEdgePtrs(CPoint*& start, CPoint*& end);
00353 //      void GetNextEdgePtrs(POSITION& pos, CPoint*& start, CPoint*& end);
00354 //      void GetPrevEdgePtrs(POSITION& pos, CPoint*& start, CPoint*& end);
00355 //      void GetEdgePtrs(POSITION pos, CPoint*& start, CPoint*& end);
00356 //      CPoint* GetStartPoint(POSITION pos);
00357 //      CPoint* GetEndPoint(POSITION pos);
00358 //      CPoint* GetPointBeforeEdge(POSITION pos);
00359 //      CPoint* GetPointAfterEdge(POSITION pos);
00360 //
00361 //      POSITION GetEdgePosBeforePoint(POSITION pos) const;
00362 //      POSITION GetEdgePosAfterPoint(POSITION pos) const;
00363 //      POSITION GetEdgePosForStartPoint(CPoint* startpoint);
00364 //
00365 //      int IsEdgeHorizontal(POSITION pos);
00366 //
00368 //
00369 //public:
00370 //private:
00371 //      CRect GetSurroundRect() const;
00372 //
00373 //      int IsPathAt(CPoint point, int nearness = 0) const { return GetEdgePosAt(point, nearness) != NULL; }
00374 //      int IsPathClip(CRect rect) const;
00375 //
00376 //      void SetAttributes(unsigned int attr);
00377 //      unsigned int GetAttributes() const { return attributes; }
00378 //
00379 //      int IsFixed() const { return (attributes & ARPATH_Fixed) != 0; }
00380 //      int IsMoveable() const { return (attributes & ARPATH_Fixed) == 0; }
00381 //      int IsHighLighted() const { return (attributes & ARPATH_HighLighted) != 0; }
00382 //
00383 //      int GetState() const { return state; };
00384 //      int IsConnected() const { return (state & ARPATHST_Connected) != 0; }
00385 //
00386 //      EArDir GetEndDir() const;
00387 //      EArDir GetStartDir() const;
00388 //public:
00389 //      void SetEndDir(unsigned int arpath_end) { attributes = (attributes & ~ARPATH_EndMask) + arpath_end; }
00390 //      void SetStartDir(unsigned int arpath_start) { attributes = (attributes & ~ARPATH_StartMask) + arpath_start; }
00391 //
00392 //private:
00393 //      void SetState(int state);
00394 //
00395 //public:
00396 //private:
00397 //      unsigned int attributes;
00398 //      int state;
00399 //
00401 //
00402 //public:
00403 //      void* GetExtPtr() const { return extptr; }
00404 //      void SetExtPtr(void* p) { extptr = p; }
00405 //private:
00406 //      
00407 //      
00408 //
00409 //      void* extptr;
00410 //
00412 //
00413 //public:
00414 //private:
00415 //      DECLARE_SERIAL(CArPath);
00416 //      virtual void Serialize(CArchive& ar);
00417 //
00418 //      void LocateRefs();
00419 //      int HasRealReferences() const { return ref_type == ref_type_valid; }
00420 //      enum { ref_type_stored, ref_type_valid } ref_type;
00421 //
00423 //
00424 //#ifdef _DEBUG
00425 //public:
00426 //      virtual void AssertValid() const;
00427 //      void AssertValidPos(POSITION pos) const;
00428 //      void AssertValidPoints() const;
00429 //#endif
00430 //};
00431 //
00432 //
00434 //
00435 //
00436 //class CArGraph: public CObject
00437 //{
00438 //public:
00439 //      CArGraph();
00440 //      ~CArGraph();
00441 //
00442 //      friend CArEdgeList;
00443 //      friend CArBox;
00444 //      friend CArPort;
00445 //      friend CArPath;
00446 //
00448 //
00449 //public:
00450 //      CArBox* CreateBox() const;
00451 //      void Add(CArBox* box);
00452 //      void Delete(CArBox* box);
00453 //      void ShiftBy(CArBox* box, CSize offset);
00454 //
00455 //private:
00456 //      void Remove(CArBox* box);
00457 //
00458 //      void DeleteAllBoxes();
00459 //      const CArBoxList& GetBoxList() const { return boxes; }
00460 //      int HasNoBox() const { return boxes.IsEmpty(); }
00461 //      int GetBoxCount() const { return boxes.GetCount(); }
00462 //
00463 //      CArBox* GetBoxAt(CPoint point, int nearness = 0) const;
00464 //      CArPort* GetPortAt(CPoint point, int nearness = 0) const;
00465 //
00466 //      void SetPortAttr(CArPort* port, unsigned int attr);
00467 //
00468 //      int IsRectClipBoxes(CRect rect) const;
00469 //      int IsLineClipBoxes(CPoint p1, CPoint p2) const;
00470 //      int CanBoxAt(CRect rect) const;
00471 //
00472 //
00473 //      void SetBox(CArBox* box, CPoint topleft) { ShiftBy(box, topleft - box->rect.TopLeft()); }
00474 //      int CanShiftBy(CArBox* box, CSize offset) const;
00475 //      int CanSetBox(CArBox* box, CPoint topleft) const { return CanShiftBy(box, topleft - box->rect.TopLeft()); }
00476 //
00477 //      CArBox* AddAtomicPort(CRect rect, unsigned int attr);
00478 //
00479 //private:
00480 //      CArBoxList boxes;
00481 //
00483 //
00484 //private:
00485 //      CArPath* CreatePath() const;
00486 //      void Add(CArPath* path);
00487 //      void Remove(CArPath* path);
00488 //
00489 //      void DeleteAllPaths();
00490 //      const CArPathList& GetPathList() const { return paths; }
00491 //      int HasNoPath() const { return paths.IsEmpty(); }
00492 //      int GetPathCount() const { return paths.GetCount(); }
00493 //
00494 //
00495 //      CArPath* GetPathPointAt(CPoint point, POSITION& pos, int nearness = 0) const;
00496 //      CArPath* GetPathEdgeAt(CPoint point, POSITION& pos, int nearness = 0) const;
00497 //
00498 //      SArEdge* GetPathEdgeAt(CArPath* path, POSITION pos) const;
00499 //      SArEdge* GetPathEdgeAt(CPoint point, int nearness = 0) const;
00500 //
00501 //      SArEdge* GetListEdgeAt(CPoint point, int nearness = 0) const;
00502 //
00503 //      CArPath* AddPath(const CPointList& points, unsigned int attr);
00504 //      CArPath* AddPath(CPoint startpoint, CPoint endpoint);
00505 //
00506 //
00507 //private:
00508 //      CArPathList paths;
00509 //
00511 //
00512 //private:
00513 //      int IsEmpty() const { return boxes.IsEmpty() && paths.IsEmpty(); }
00514 //
00515 //      CRect GetSurroundRect() const;
00516 //
00517 //public:
00518 //      int AutoRoute();
00519 //      void Delete(CArPath* path);
00520 //      void DeleteAll() { DeleteAllPaths(); DeleteAllBoxes(); }
00521 //      CArPath* GetPathAt(CPoint point, int nearness = 0) const;
00522 //      CArPath* AddPath(CArPort* startport, CArPort* endport);
00523 //
00525 //
00526 //private:
00527 //      CArBox* GetOutOfBox(CPoint& point, EArDir dir) const;
00528 //
00529 //      CArBox* GoToNextBox(CPoint& point, EArDir dir, long stophere) const;
00530 //      CArBox* GoToNextBox(CPoint& point, EArDir dir, CPoint stophere) const 
00531 //              { return GoToNextBox(point, dir, GetPointCoord(stophere, dir)); }
00532 //
00533 //      CArBox* GoToNextBox(CPoint& point, EArDir dir, long stop1, long stop2) const
00534 //              { return GoToNextBox(point, dir, ChooseInDir(stop1, stop2,ReverseDir(dir))); }
00535 //      CArBox* GoToNextBox(CPoint& point, EArDir dir, CPoint stop1, CPoint stop2) const
00536 //              { return GoToNextBox(point, dir, GetPointCoord(stop1, dir), GetPointCoord(stop2, dir)); }
00537 //
00538 //      void GetLimitsOfEdge(CPoint start, CPoint end, long& min, long& max) const;
00539 //
00540 //      int IsPointInBox(CPoint point) const { return GetBoxAt(point) != NULL; }
00541 //      int CanGoInDir(CPoint point, EArDir dir) const { return !IsPointInBox(StepOneInDir(point, dir)); }
00542 //
00543 //private:
00544 //      void Connect(CArPath* path);
00545 //      void Connect(CArPath* path, CPoint startpoint, CPoint endpoint);
00546 //
00547 //      void ConnectPoints(CPointList& ret, CPoint startpoint, CPoint endpoint, EArDir hintstartdir, EArDir hintenddir);
00548 //
00549 //      void DisconnectAll();
00550 //      void Disconnect(CArPath* path);
00551 //
00552 //      void DisconnectPathsClipping(CRect rect);
00553 //      void DisconnectPathsFrom(CArBox* box);
00554 //      void DisconnectPathsFrom(CArPort* port);
00555 //
00557 //
00558 //private:
00559 //      void AddEdges(CArGraph* graph) { horizontal.AddEdges(graph); vertical.AddEdges(graph); }
00560 //      void AddEdges(CArBox* box) { horizontal.AddEdges(box); vertical.AddEdges(box); }
00561 //      void AddEdges(CArPort* port) { horizontal.AddEdges(port); vertical.AddEdges(port); }
00562 //      void AddEdges(CArPath* path) { horizontal.AddEdges(path); vertical.AddEdges(path); }
00563 //      void DeleteEdges(CObject* object) { horizontal.DeleteEdges(object); vertical.DeleteEdges(object); }
00564 //
00565 //      void AddAllEdges();
00566 //      void DeleteAllEdges() { horizontal.DeleteAllEdges(); vertical.DeleteAllEdges(); }
00567 //
00568 //      void AddBoxAndPortEdges(CArBox* box);
00569 //      void DeleteBoxAndPortEdges(CArBox* box);
00570 //
00571 //      CArEdgeList& GetEdgeList(int ishorizontal) { return ishorizontal ? horizontal : vertical; }
00572 //
00573 //private://private:
00574 //
00575 //      CArEdgeList horizontal;
00576 //      CArEdgeList vertical;
00577 //
00579 //
00580 //private:
00581 //      int CanDeleteTwoEdgesAt(CArPath* path, POSITION pos);
00582 //      void DeleteTwoEdgesAt(CArPath* path, POSITION pos);
00583 //      void DeleteSamePointsAt(CArPath* path, POSITION pos);
00584 //      int SimplifyPaths();
00585 //      void CenterStairsInPathPoints(CArPath* path);
00586 //      void SimplifyPathPoints(CArPath* path);
00587 //      void ConnectAllDisconnectedPaths();
00588 //
00590 //
00591 //private:
00592 //      void CalculateSelfPoints();
00593 //
00594 //      CPoint selfpoints[4];
00595 //
00597 //
00598 //public:
00599 //      DECLARE_SERIAL(CArGraph);
00600 //      virtual void Serialize(CArchive& ar);
00601 //
00602 //private:
00603 //
00604 //      CArPort* ResolveStoredRef(CArPort* stored_ref);
00605 //      void LocateRefs();
00606 //      void ClearStoredRefs();
00607 //
00609 //
00610 //#ifdef _DEBUG
00611 //public:
00612 //      virtual void AssertValid() const;
00613 //      void AssertValidBox(CArBox* box) const;
00614 //      void AssertValidPath(CArPath* path) const;
00615 //#endif
00616 //
00617 //};
00618 //
00619 //
00621 //
00622 //
00623 //inline CPoint CArPort::CreateStartEndPointTo(CPoint point, int isstart) const
00624 //{
00625 //      return CreateStartEndPointOn(GetStartEndDirTo(point, isstart));
00626 //}
00627 //
00628 //
00629 //#endif//__ARGRAPH_H