Adaptagrams
connector.h
Go to the documentation of this file.
1 /*
2  * vim: ts=4 sw=4 et tw=0 wm=0
3  *
4  * libavoid - Fast, Incremental, Object-avoiding Line Router
5  *
6  * Copyright (C) 2004-2015 Monash University
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  * See the file LICENSE.LGPL distributed with the library.
13  *
14  * Licensees holding a valid commercial license may use this file in
15  * accordance with the commercial license agreement provided with the
16  * library.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21  *
22  * Author(s): Michael Wybrow
23 */
24 
27 
28 
29 #ifndef AVOID_CONNECTOR_H
30 #define AVOID_CONNECTOR_H
31 
32 #include <utility>
33 #include <list>
34 #include <vector>
35 
36 #include "libavoid/dllexport.h"
37 #include "libavoid/vertices.h"
38 #include "libavoid/geometry.h"
39 #include "libavoid/connend.h"
40 
41 
42 namespace Avoid {
43 
44 class Router;
45 class ConnRef;
46 class JunctionRef;
47 class ShapeRef;
48 typedef std::list<ConnRef *> ConnRefList;
49 
50 
53 enum ConnType {
54  ConnType_None = 0,
62 };
63 
68 class AVOID_EXPORT Checkpoint
69 {
70  public:
77  Checkpoint(const Point& p)
78  : point(p),
79  arrivalDirections(ConnDirAll),
80  departureDirections(ConnDirAll)
81  {
82  }
96  : point(p),
97  arrivalDirections(ad),
98  departureDirections(dd)
99  {
100  }
101  // Default constructor.
102  Checkpoint()
103  : point(Point()),
104  arrivalDirections(ConnDirAll),
105  departureDirections(ConnDirAll)
106  {
107  }
108 
109  Point point;
110  ConnDirFlags arrivalDirections;
111  ConnDirFlags departureDirections;
112 };
113 
114 
131 class AVOID_EXPORT ConnRef
132 {
133  public:
155  ConnRef(Router *router, const unsigned int id = 0);
175  ConnRef(Router *router, const ConnEnd& src, const ConnEnd& dst,
176  const unsigned int id = 0);
177 
178 // To prevent C++ objects from being destroyed in garbage collected languages
179 // when the libraries are called from SWIG, we hide the declarations of the
180 // destructors and prevent generation of default destructors.
181 #ifndef SWIG
182  ~ConnRef();
188 #endif
189  void setEndpoints(const ConnEnd& srcPoint, const ConnEnd& dstPoint);
199 
207  void setSourceEndpoint(const ConnEnd& srcPoint);
208 
216  void setDestEndpoint(const ConnEnd& dstPoint);
217 
220  unsigned int id(void) const;
221 
224  Router *router(void) const;
225 
235  bool needsRepaint(void) const;
236 
248  const PolyLine& route(void) const;
249 
259  PolyLine& displayRoute(void);
260 
271  void setCallback(void (*cb)(void *), void *ptr);
272 
276  ConnType routingType(void) const;
277 
288  void setRoutingType(ConnType type);
289 
301  std::pair<JunctionRef *, ConnRef *> splitAtSegment(
302  const size_t segmentN);
303 
315  void setRoutingCheckpoints(const std::vector<Checkpoint>& checkpoints);
316 
321  std::vector<Checkpoint> routingCheckpoints(void) const;
322 
340  std::pair<ConnEnd, ConnEnd> endpointConnEnds(void) const;
341 
342  // @brief Returns the source endpoint vertex in the visibility graph.
343  // @returns The source endpoint vertex.
344  VertInf *src(void) const;
345  // @brief Returns the destination endpoint vertex in the
346  // visibility graph.
347  // @returns The destination endpoint vertex.
348  VertInf *dst(void) const;
349 
368  void setFixedRoute(const PolyLine& route);
369 
384  void setFixedExistingRoute(void);
385 
390  bool hasFixedRoute(void) const;
391 
397  void clearFixedRoute(void);
398 
399  void set_route(const PolyLine& route);
400  void calcRouteDist(void);
401  void makeActive(void);
402  void makeInactive(void);
403  VertInf *start(void);
404  void removeFromGraph(void);
405  bool isInitialised(void) const;
406  void makePathInvalid(void);
407  void setHateCrossings(bool value);
408  bool doesHateCrossings(void) const;
409  void setEndpoint(const unsigned int type, const ConnEnd& connEnd);
410  bool setEndpoint(const unsigned int type, const VertID& pointID,
411  Point *pointSuggestion = nullptr);
412  std::vector<Point> possibleDstPinPoints(void) const;
413 
414  private:
415  friend class Router;
416  friend class ConnEnd;
417  friend class JunctionRef;
418  friend class ConnRerouteFlagDelegate;
419  friend class HyperedgeImprover;
420  friend struct HyperedgeTreeEdge;
421  friend struct HyperedgeTreeNode;
422  friend class HyperedgeRerouter;
423 
424  PolyLine& routeRef(void);
425  void freeRoutes(void);
426  void performCallback(void);
427  bool generatePath(void);
428  void generateCheckpointsPath(std::vector<Point>& path,
429  std::vector<VertInf *>& vertices);
430  void generateStandardPath(std::vector<Point>& path,
431  std::vector<VertInf *>& vertices);
432  void unInitialise(void);
433  void updateEndPoint(const unsigned int type, const ConnEnd& connEnd);
434  void common_updateEndPoint(const unsigned int type, ConnEnd connEnd);
435  void freeActivePins(void);
436  bool getConnEndForEndpointVertex(VertInf *vertex, ConnEnd& connEnd)
437  const;
438  std::pair<Obstacle *, Obstacle *> endpointAnchors(void) const;
439  void outputCode(FILE *fp) const;
440  std::pair<bool, bool> assignConnectionPinVisibility(const bool connect);
441 
442 
443  Router *m_router;
444  unsigned int m_id;
445  ConnType m_type;
446  bool *m_reroute_flag_ptr;
447  bool m_needs_reroute_flag:1;
448  bool m_false_path:1;
449  bool m_needs_repaint:1;
450  bool m_active:1;
451  bool m_initialised:1;
452  bool m_hate_crossings:1;
453  bool m_has_fixed_route:1;
454  PolyLine m_route;
455  Polygon m_display_route;
456  double m_route_dist;
457  ConnRefList::iterator m_connrefs_pos;
458  VertInf *m_src_vert;
459  VertInf *m_dst_vert;
460  VertInf *m_start_vert;
461  void (*m_callback_func)(void *);
462  void *m_connector;
463  ConnEnd *m_src_connend;
464  ConnEnd *m_dst_connend;
465  std::vector<Checkpoint> m_checkpoints;
466  std::vector<VertInf *> m_checkpoint_vertices;
467 };
468 
469 
470 typedef std::pair<Point *, ConnRef *> PtConnPtrPair;
471 
472 typedef std::vector< PtConnPtrPair > PointRepVector;
473 typedef std::list<std::pair<size_t, size_t> > NodeIndexPairLinkList;
474 
475 class PtOrder
476 {
477  public:
478  PtOrder();
479  ~PtOrder();
480  void addPoints(const size_t dim, const PtConnPtrPair& arg1,
481  const PtConnPtrPair& arg2);
482  void addOrderedPoints(const size_t dim, const PtConnPtrPair& innerArg,
483  const PtConnPtrPair& outerArg, bool swapped);
484  int positionFor(const size_t dim, const ConnRef *conn);
485  PointRepVector sortedPoints(const size_t dim);
486  private:
487  size_t insertPoint(const size_t dim, const PtConnPtrPair& point);
488  void sort(const size_t dim);
489 
490  // One for each dimension.
491  bool sorted[2];
492  PointRepVector nodes[2];
493  NodeIndexPairLinkList links[2];
494  PointRepVector sortedConnVector[2];
495 };
496 
497 typedef std::map<Avoid::Point,PtOrder> PtOrderMap;
498 typedef std::set<Avoid::Point> PointSet;
499 
500 
501 const unsigned int CROSSING_NONE = 0;
502 const unsigned int CROSSING_TOUCHES = 1;
503 const unsigned int CROSSING_SHARES_PATH = 2;
504 const unsigned int CROSSING_SHARES_PATH_AT_END = 4;
505 const unsigned int CROSSING_SHARES_FIXED_SEGMENT = 8;
506 
507 
508 typedef std::pair<int, unsigned int> CrossingsInfoPair;
509 typedef std::vector<Avoid::Point> PointList;
510 typedef std::vector<PointList> SharedPathList;
511 
512 class ConnectorCrossings
513 {
514  public:
515  ConnectorCrossings(Avoid::Polygon& poly, bool polyIsConn,
516  Avoid::Polygon& conn, ConnRef *polyConnRef = nullptr,
517  ConnRef *connConnRef = nullptr);
518  void clear(void);
519  void countForSegment(size_t cIndex, const bool finalSegment);
520 
521  Avoid::Polygon& poly;
522  bool polyIsConn;
523  Avoid::Polygon& conn;
524  bool checkForBranchingSegments;
525  ConnRef *polyConnRef;
526  ConnRef *connConnRef;
527 
528  unsigned int crossingCount;
529  unsigned int crossingFlags;
530  PointSet *crossingPoints;
531  PtOrderMap *pointOrders;
532  SharedPathList *sharedPaths;
533 
534  double firstSharedPathAtEndLength;
535  double secondSharedPathAtEndLength;
536 };
537 
538 extern void splitBranchingSegments(Avoid::Polygon& poly, bool polyIsConn,
539  Avoid::Polygon& conn, const double tolerance = 0);
540 extern bool validateBendPoint(VertInf *aInf, VertInf *bInf, VertInf *cInf);
541 
542 }
543 
544 
545 #endif
546 
547 
The ConnEnd class represents different possible endpoints for connectors.
Definition: connend.h:110
Checkpoint(const Point &p, ConnDirFlags ad, ConnDirFlags dd)
A point that a route must visit.
Definition: connector.h:95
unsigned int ConnDirFlags
One or more Avoid::ConnDirFlag options.
Definition: connend.h:83
The ConnRef class represents a connector object.
Definition: connector.h:131
A dynamic Polygon, to which points can be easily added and removed.
Definition: geomtypes.h:207
This option, provided for convenience, specifies the point should be given visibility to all four sid...
Definition: connend.h:79
A checkpoint is a point that the route for a particular connector must visit. They may optionally be ...
Definition: connector.h:68
std::list< ConnRef * > ConnRefList
A list of ConnRef objects.
Definition: connector.h:47
The connector path will be a shortest-path orthogonal poly-line (only vertical and horizontal line se...
Definition: connector.h:61
The HyperedgeRerouter class is a convenience object that can be used to register hyperedges to be rer...
Definition: hyperedge.h:129
Checkpoint(const Point &p)
A point that a route must visit.
Definition: connector.h:77
ConnType
Describes the type of routing that is performed for each connector.
Definition: connector.h:53
Contains the interface for the ConnEnd class.
The connector path will be a shortest-path poly-line that routes around obstacles.
Definition: connector.h:57
The Point class defines a point in the plane.
Definition: geomtypes.h:52
libavoid: Object-avoiding orthogonal and polyline connector routing library.
Definition: actioninfo.cpp:33
The Router class represents a libavoid router instance.
Definition: router.h:386
The ShapeRef class represents a shape object.
Definition: shape.h:81
The JunctionRef class represents a fixed or free-floating point that connectors can be attached to...
Definition: junction.h:57