Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
router.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_ROUTER_H
30#define AVOID_ROUTER_H
31
32#include <ctime>
33#include <list>
34#include <utility>
35#include <string>
36
37#include "libavoid/dllexport.h"
38#include "libavoid/connector.h"
39#include "libavoid/vertices.h"
40#include "libavoid/graph.h"
41#include "libavoid/timer.h"
42#include "libavoid/hyperedge.h"
43#include "libavoid/actioninfo.h"
45
46
47namespace Avoid {
48
49// LineReps: Used for highlighting certain areas in debugging output.
50struct LineRep
51{
54};
55typedef std::list<LineRep> LineReps;
56
57
58typedef std::list<unsigned int> IntList;
59
60class ShapeRef;
61class JunctionRef;
62class ClusterRef;
63typedef std::list<ClusterRef *> ClusterRefList;
64class Obstacle;
65typedef std::list<Obstacle *> ObstacleList;
66class DebugHandler;
67
79
80
81static const unsigned int runningTo = 1;
82static const unsigned int runningFrom = 2;
83static const unsigned int runningToAndFrom = runningTo | runningFrom;
84
89{
98
107
115
124
132
143
150
155
163
164 // Used for determining the size of the routing parameter array.
165 // This should always we the last value in the enum.
168
169// Backwards compatibility
171
172
292
322
323// NOTE: This is an internal helper class that should not be used by the user.
324//
325// This class allows edges in the visibility graph to store a
326// pointer to a boolean registering when a connector needs to
327// reroute, while allowing connectors to be deleted without
328// needing to scan and remove these references from the visibility
329// graph. Instead the bool is stored in this delegate and the
330// connector is alerted later, so long as it hasn't since been
331// deleted.
333 public:
336 bool *addConn(ConnRef *conn);
337 void removeConn(ConnRef *conn);
338 void alertConns(void);
339 private:
340 std::list<std::pair<ConnRef *, bool> > m_mapping;
341};
342
343static const double zeroParamValue = 0;
344static const double chooseSensibleParamValue = -1;
345
346// NOTE: This is an internal helper class that should not be used by the user.
347//
348// It is used by libtopology to add additional functionality to libavoid
349// while keeping libavoid dependency free.
351{
352 public:
357 {
358 }
359 virtual TopologyAddonInterface *clone(void) const
360 {
361 return new TopologyAddonInterface(*this);
362 }
363
364 virtual void improveOrthogonalTopology(Router *router)
365 {
366 (void)(router); // Avoid unused parameter warning.
367 }
368 virtual bool outputCode(FILE *fp) const
369 {
370 (void)(fp); // Avoid unused parameter warning.
371 return false;
372 }
373 virtual bool outputDeletionCode(FILE *fp) const
374 {
375 (void)(fp); // Avoid unused parameter warning.
376 return false;
377 }
378};
379
380
385//
386class AVOID_EXPORT Router {
387 public:
392 Router(const unsigned int flags);
393
399 virtual ~Router();
400
410
414
415 // Poly-line routing options:
419
420 // General routing options:
422
425
426
427 // Instrumentation:
428#ifdef AVOID_PROFILE
430#endif
432
453 void setTransactionUse(const bool transactions);
454
462 bool transactionUse(void) const;
463
479 bool processTransaction(void);
480
495 void deleteShape(ShapeRef *shape);
496
515 void moveShape(ShapeRef *shape, const Polygon& newPoly,
516 const bool first_move = false);
517
535 void moveShape(ShapeRef *shape, const double xDiff, const double yDiff);
536
549 void deleteJunction(JunctionRef *junction);
550
563 void deleteConnector(ConnRef *connector);
564
578 void moveJunction(JunctionRef *junction, const Point& newPosition);
579
597 void moveJunction(JunctionRef *junction, const double xDiff,
598 const double yDiff);
599
626 void setRoutingParameter(const RoutingParameter parameter,
627 const double value = chooseSensibleParamValue);
628
635 double routingParameter(const RoutingParameter parameter) const;
636
642 void setRoutingOption(const RoutingOption option, const bool value);
643
649 bool routingOption(const RoutingOption option) const;
650
655 // method. See its documentation for more details.
661 void setRoutingPenalty(const RoutingParameter penType,
662 const double penVal = chooseSensibleParamValue);
663
669 HyperedgeRerouter *hyperedgeRerouter(void);
670
682 void outputInstanceToSVG(std::string filename = std::string());
683
694 virtual unsigned int newObjectId(void) const;
695
703 bool objectIdIsUnused(const unsigned int id) const;
704
743 virtual bool shouldContinueTransactionWithProgress(
744 unsigned int elapsedTime, unsigned int phaseNumber,
745 unsigned int totalPhases, double proportion);
746
763 newAndDeletedObjectListsFromHyperedgeImprovement(void) const;
764
765 void setDebugHandler(DebugHandler *handler);
766 DebugHandler *debugHandler(void) const;
767
768 // Processes the actions list for the transaction. You shouldn't
769 // need to cal this. Instead use processTransaction().
770 void processActions(void);
771
772 void deleteCluster(ClusterRef *cluster);
773 void attachedShapes(IntList &shapes, const unsigned int shapeId,
774 const unsigned int type);
775 void attachedConns(IntList &conns, const unsigned int shapeId,
776 const unsigned int type);
777 void markPolylineConnectorsNeedingReroutingForDeletedObstacle(
778 Obstacle *obstacle);
779 void generateContains(VertInf *pt);
780 void printInfo(void);
781 void regenerateStaticBuiltGraph(void);
782 void destroyOrthogonalVisGraph(void);
783 void setStaticGraphInvalidated(const bool invalidated);
784 ConnType validConnType(const ConnType select = ConnType_None) const;
785 bool isInCrossingPenaltyReroutingStage(void) const;
786 void markAllObstaclesAsMoved(void);
787 ShapeRef *shapeContainingPoint(const Point& point);
788 void performContinuationCheck(unsigned int phaseNumber,
789 size_t stepNumber, size_t totalSteps);
790 void registerSettingsChange(void);
791
799 void setTopologyAddon(TopologyAddonInterface *topologyAddon);
800 void improveOrthogonalTopology(void);
801
802 // Testing and debugging methods.
803 bool existsOrthogonalSegmentOverlap(const bool atEnds = false);
804 bool existsOrthogonalFixedSegmentOverlap(const bool atEnds = false);
805 bool existsOrthogonalTouchingPaths(void);
806 int existsCrossings(const bool optimisedForConnectorType = false);
807 bool existsInvalidOrthogonalPaths(void);
808
809 // Outputs the current diagram. Used for visualising individual
810 // steps of various algorithms. lineReps can be used to draw
811 // attention to specific parts of the diagram that have changed
812 // between steps.
813 void outputDiagramSVG(std::string instanceName = std::string(),
814 LineReps *lineReps = nullptr);
815
816 void outputDiagramText(std::string instanceName = std::string());
817 void outputDiagram(std::string instanceName = std::string());
818
819 private:
820 friend class ShapeRef;
821 friend class ConnRef;
822 friend class JunctionRef;
823 friend class Obstacle;
824 friend class ClusterRef;
825 friend class ShapeConnectionPin;
827 friend class ConnEnd;
828 friend struct HyperedgeTreeNode;
829 friend class HyperedgeRerouter;
830 friend class HyperedgeImprover;
831
832 unsigned int assignId(const unsigned int suggestedId);
833 void addShape(ShapeRef *shape);
834 void addJunction(JunctionRef *junction);
835 void addCluster(ClusterRef *cluster);
836 void modifyConnector(ConnRef *conn);
837 void modifyConnector(ConnRef *conn, unsigned int type,
838 const ConnEnd &connEnd, bool connPinUpdate = false);
839 void modifyConnectionPin(ShapeConnectionPin *pin);
840
841 void removeObjectFromQueuedActions(const void *object);
842 void newBlockingShape(const Polygon& poly, int pid);
843 void checkAllBlockedEdges(int pid);
844 void checkAllMissingEdges(void);
845 void adjustContainsWithAdd(const Polygon& poly, const int p_shape);
846 void adjustContainsWithDel(const int p_shape);
847 void adjustClustersWithAdd(const PolygonInterface& poly,
848 const int p_cluster);
849 void adjustClustersWithDel(const int p_cluster);
850 void rerouteAndCallbackConnectors(void);
851 void improveCrossings(void);
852
857 double m_routing_parameters[lastRoutingParameterMarker];
858 bool m_routing_options[lastRoutingOptionMarker];
859
862
863 // Progress tracking and transaction cancelling.
866
868
869 // Overall modes:
872
875
877
879
881};
882
883
884}
885
886
887
888#endif
SimpleSnap option
The ClusterRef class represents a cluster object.
Definition viscluster.h:56
The ConnEnd class represents different possible endpoints for connectors.
Definition connend.h:111
The ConnRef class represents a connector object.
Definition connector.h:132
std::list< std::pair< ConnRef *, bool > > m_mapping
Definition router.h:340
bool * addConn(ConnRef *conn)
Definition router.cpp:3097
void removeConn(ConnRef *conn)
Definition router.cpp:3103
The HyperedgeRerouter class is a convenience object that can be used to register hyperedges to be rer...
Definition hyperedge.h:130
The JunctionRef class represents a fixed or free-floating point that connectors can be attached to.
Definition junction.h:58
The Point class defines a point in the plane.
Definition geomtypes.h:53
A common interface used by the Polygon classes.
Definition geomtypes.h:151
A dynamic Polygon, to which points can be easily added and removed.
Definition geomtypes.h:208
The Router class represents a libavoid router instance.
Definition router.h:386
bool PartialFeedback
Definition router.h:423
bool SimpleRouting
Definition router.h:412
TopologyAddonInterface * m_topology_addon
Definition router.h:867
int st_checked_edges
Definition router.h:431
bool InvisibilityGrph
Definition router.h:418
bool m_static_orthogonal_graph_invalidated
Definition router.h:873
ObstacleList m_obstacles
Definition router.h:401
HyperedgeImprover m_hyperedge_improver
Definition router.h:878
bool PartialTime
Definition router.h:411
bool ClusteredRouting
Definition router.h:413
VertInfList vertices
Definition router.h:408
unsigned int m_largest_assigned_id
Definition router.h:854
DebugHandler * m_debug_handler
Definition router.h:880
EdgeList invisGraph
Definition router.h:405
ClusterRefList clusterRefs
Definition router.h:403
bool UseLeesAlgorithm
Definition router.h:417
bool m_consolidate_actions
Definition router.h:855
bool m_abort_transaction
Definition router.h:865
bool m_allows_orthogonal_routing
Definition router.h:871
bool m_in_crossing_rerouting_stage
Definition router.h:874
ContainsMap enclosingClusters
Definition router.h:409
bool SelectiveReroute
Definition router.h:421
ConnRerouteFlagDelegate m_conn_reroute_flags
Definition router.h:860
ContainsMap contains
Definition router.h:407
bool m_settings_changes
Definition router.h:876
ActionInfoList actionList
Definition router.h:853
clock_t m_transaction_start_time
Definition router.h:864
ConnRefList connRefs
Definition router.h:402
bool m_allows_polyline_routing
Definition router.h:870
bool m_currently_calling_destructors
Definition router.h:856
EdgeList visOrthogGraph
Definition router.h:406
EdgeList visGraph
Definition router.h:404
HyperedgeRerouter m_hyperedge_rerouter
Definition router.h:861
Timer timers
Definition router.h:429
bool RubberBandRouting
Definition router.h:424
bool IgnoreRegions
Definition router.h:416
The ShapeConnectionPin class represents a fixed point or "pin" on a shape that can be connected to.
The ShapeRef class represents a shape object.
Definition shape.h:82
virtual bool outputDeletionCode(FILE *fp) const
Definition router.h:373
virtual ~TopologyAddonInterface()
Definition router.h:356
virtual void improveOrthogonalTopology(Router *router)
Definition router.h:364
virtual TopologyAddonInterface * clone(void) const
Definition router.h:359
virtual bool outputCode(FILE *fp) const
Definition router.h:368
Contains the interface for the ConnRef class.
void outputDiagram(Avoid::Router *router)
Contains the interface for the HyperedgeRerouter class.
libavoid: Object-avoiding orthogonal and polyline connector routing library.
static const unsigned int runningTo
Definition router.h:81
std::map< VertID, ShapeSet > ContainsMap
Definition vertices.h:218
ConnType
Describes the type of routing that is performed for each connector.
Definition connector.h:53
TransactionPhases
Types of routing phases reported by Router::shouldContinueTransactionWithProgress().
Definition router.h:300
@ TransactionPhaseOrthogonalNudgingY
Orthogonal edge segments are nudged apart in the y-dimension.
Definition router.h:317
@ TransactionPhaseOrthogonalVisibilityGraphScanX
The orthogonal visibility graph is built by conducting a scan in each dimension.
Definition router.h:303
@ TransactionPhaseRouteSearch
Initial routes are searched for in the visibility graph.
Definition router.h:308
@ TransactionPhaseCrossingDetection
With crossing penalties enabled, crossing detection is performed to find all crossings.
Definition router.h:311
@ TransactionPhaseCompleted
Not a real phase, but represents the router is finished (or has aborted) the transaction and you may ...
Definition router.h:320
@ TransactionPhaseRerouteSearch
Crossing connectors are rerouted to search for better routes.
Definition router.h:313
@ TransactionPhaseOrthogonalVisibilityGraphScanY
The orthogonal visibility graph is built by conducting a scan in each dimension.
Definition router.h:306
@ TransactionPhaseOrthogonalNudgingX
Orthogonal edge segments are nudged apart in the x-dimension.
Definition router.h:315
std::list< unsigned int > IntList
Definition router.h:58
std::list< Obstacle * > ObstacleList
Definition obstacle.h:49
std::list< LineRep > LineReps
Definition router.h:55
std::list< ActionInfo > ActionInfoList
Definition actioninfo.h:84
static const unsigned int runningFrom
Definition router.h:82
std::list< ClusterRef * > ClusterRefList
Definition router.h:63
static const double zeroParamValue
Definition router.h:343
RoutingParameter
Types of routing parameters and penalties that can be used to tailor the style and improve the qualit...
Definition router.h:89
@ lastRoutingParameterMarker
Definition router.h:166
@ crossingPenalty
This penalty is applied whenever a connector path crosses another connector path.
Definition router.h:114
@ clusterCrossingPenalty
This penalty is applied whenever a connector path crosses a cluster boundary.
Definition router.h:123
@ reverseDirectionPenalty
This penalty is applied whenever a connector path travels in the direction opposite of the destinatio...
Definition router.h:162
@ portDirectionPenalty
This penalty is applied to port selection choice when the other end of the connector being routed doe...
Definition router.h:142
@ fixedSharedPathPenalty
This penalty is applied whenever a connector path shares some segments with an immovable portion of a...
Definition router.h:131
@ anglePenalty
This penalty is applied in its full amount to tight acute bends in the connector path.
Definition router.h:106
@ segmentPenalty
This penalty is applied for each segment in the connector path beyond the first.
Definition router.h:97
@ shapeBufferDistance
This parameter defines the spacing distance that will be added to the sides of each shape when determ...
Definition router.h:149
@ idealNudgingDistance
This parameter defines the spacing distance that will be used for nudging apart overlapping corners a...
Definition router.h:154
RouterFlag
Flags that can be passed to the router during initialisation to specify options.
Definition router.h:71
@ OrthogonalRouting
This option specifies that the router should maintain the structures necessary to allow orthogonal co...
Definition router.h:77
@ PolyLineRouting
This option specifies that the router should maintain the structures necessary to allow poly-line con...
Definition router.h:74
std::list< ConnRef * > ConnRefList
A list of ConnRef objects.
Definition connector.h:48
enum RoutingParameter PenaltyType
Definition router.h:170
RoutingOption
Types of routing options that can be enabled.
Definition router.h:175
@ performUnifyingNudgingPreprocessingStep
This option can be used to control whether the router performs a preprocessing step before orthogonal...
Definition router.h:249
@ lastRoutingOptionMarker
Definition router.h:290
@ improveHyperedgeRoutesMovingJunctions
This option causes hyperedge routes to be locally improved fixing obviously bad paths.
Definition router.h:210
@ improveHyperedgeRoutesMovingAddingAndDeletingJunctions
This option causes hyperedge routes to be locally improved fixing obviously bad paths.
Definition router.h:275
@ nudgeOrthogonalTouchingColinearSegments
This option can be used to control whether collinear line segments that touch just at their ends will...
Definition router.h:237
@ nudgeSharedPathsWithCommonEndPoint
This option determines whether intermediate segments of connectors that are attached to common endpoi...
Definition router.h:285
@ penaliseOrthogonalSharedPathsAtConnEnds
This option penalises and attempts to reroute orthogonal shared connector paths terminating at a comm...
Definition router.h:228
@ nudgeOrthogonalSegmentsConnectedToShapes
This option causes the final segments of connectors, which are attached to shapes,...
Definition router.h:190
static const double chooseSensibleParamValue
Definition router.h:344
static const unsigned int runningToAndFrom
Definition router.h:83
The HyperedgeNewAndDeletedObjectLists class stores lists of objects created and deleted during hypere...
Definition hyperedge.h:80
Point end
Definition router.h:53
Point begin
Definition router.h:52