org.autopipes.graph
Class GraphUtil

java.lang.Object
  extended by org.autopipes.graph.GraphUtil

public final class GraphUtil
extends java.lang.Object

Helper statics for building and maintaining a DirectedGraph derived from a drawing.


Nested Class Summary
static class GraphUtil.TraversalListener
           
 
Field Summary
static int FOOT_BASE
          feet to inches conversion factor.
 
Method Summary
static HydroEdge addEdgeToGraph(org._3pq.jgrapht.Graph graph, HydroVertex startVertex, HydroVertex endVertex, ConfigurationMgr.Layer layer)
          Creates a directed edge from 2 graph vertices with validation.
static HydroVertex addPointEntity(org._3pq.jgrapht.Graph graph, CtEntity ent, double linearDelta)
          Adds a point-centered symbol from a drawing to a graph.
static void addSegmentEntity(org._3pq.jgrapht.Graph graph, CtEntity ent, ConfigurationMgr conf)
          Adds a segment from a drawing to a graph.
static double angleBetwenEdges(org._3pq.jgrapht.Edge e1, org._3pq.jgrapht.Edge e2)
          Angle between 2 Edges.
static org._3pq.jgrapht.DirectedGraph branchSubgraph(org._3pq.jgrapht.DirectedGraph graph)
          Creates a subgraph induced by vertices of branch edges in a graph.
static HydroVertex findRaiser(org._3pq.jgrapht.DirectedGraph graph)
          Attempts to locate a raiser vertex in a drawing graph.
static boolean isMultipleOfPI(double angle, double factor, double angularDelta)
          Checks if an angle is a multiple of Math.PI.
static org._3pq.jgrapht.DirectedGraph mainSubgraph(org._3pq.jgrapht.DirectedGraph graph)
          Creates a subgraph induced by vertices of main edges in a graph.
static java.util.Set orderGraph(org._3pq.jgrapht.DirectedGraph graph, HydroVertex raiser, ConfigurationMgr conf)
          Finds edges that need to be reversed in a graph to create a 'proper' ordering.
static void processOneJump(org._3pq.jgrapht.Graph graph, HydroVertex v, ConfigurationMgr conf)
          Adds a vertical edge to a graph at a vertex containing a jump symbol.
static void reverseEdgeInSubgraph(HydroEdge edge, org._3pq.jgrapht.DirectedGraph base, org._3pq.jgrapht.DirectedGraph sub)
          Replaces an edge with one built from it using its endpoints in reverse order.
static HydroEdge[] subdivideEdge(org._3pq.jgrapht.Graph graph, HydroEdge edge, HydroVertex v)
          Breaks up a graph edge at a vertex.
static void validateMainSubgraph(org._3pq.jgrapht.DirectedGraph graph)
          Preliminary validation of the main subgraph within a connected graph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FOOT_BASE

public static final int FOOT_BASE
feet to inches conversion factor.

See Also:
Constant Field Values
Method Detail

isMultipleOfPI

public static boolean isMultipleOfPI(double angle,
                                     double factor,
                                     double angularDelta)
Checks if an angle is a multiple of Math.PI.

Parameters:
angle - the angle to be checked
factor - the multiple required
angularDelta - tolerance in angular measurements
Returns:
true if angle is PI*factor

angleBetwenEdges

public static double angleBetwenEdges(org._3pq.jgrapht.Edge e1,
                                      org._3pq.jgrapht.Edge e2)
Angle between 2 Edges. The edges must have a vertex in common.

Parameters:
e1 - 1st edge
e2 - 2nd egde
Returns:
the angle

processOneJump

public static void processOneJump(org._3pq.jgrapht.Graph graph,
                                  HydroVertex v,
                                  ConfigurationMgr conf)
                           throws java.lang.CloneNotSupportedException,
                                  java.lang.IllegalAccessException
Adds a vertical edge to a graph at a vertex containing a jump symbol. Distributes edges at the vertex between the endpoints of the vertical edge.

Parameters:
graph - the graph
v - the vertex with jump
conf - drawing configuration
Throws:
java.lang.CloneNotSupportedException
java.lang.IllegalAccessException

addPointEntity

public static HydroVertex addPointEntity(org._3pq.jgrapht.Graph graph,
                                         CtEntity ent,
                                         double linearDelta)
                                  throws IllegalDrawingException
Adds a point-centered symbol from a drawing to a graph.

Parameters:
graph - the graph
ent - the symbol
linearDelta - tolerance of liner measurements
Returns:
vertex which was created or updated as a result.
Throws:
IllegalDrawingException

subdivideEdge

public static HydroEdge[] subdivideEdge(org._3pq.jgrapht.Graph graph,
                                        HydroEdge edge,
                                        HydroVertex v)
                                 throws IllegalDrawingException
Breaks up a graph edge at a vertex.

Parameters:
graph - the graph
edge - the edge used
v - the vertex
Returns:
The 2 halfs the orignal edge is broken into. The 1st half has the same source as the edge used and the 2nd half has the same target as the edge used
Throws:
IllegalDrawingException

addEdgeToGraph

public static HydroEdge addEdgeToGraph(org._3pq.jgrapht.Graph graph,
                                       HydroVertex startVertex,
                                       HydroVertex endVertex,
                                       ConfigurationMgr.Layer layer)
                                throws IllegalDrawingException
Creates a directed edge from 2 graph vertices with validation.

Parameters:
graph - the graph
startVertex - the start vertes
endVertex - the end vertex
layer - layer of the created vertex
Returns:
the new edge
Throws:
IllegalDrawingException - if the edge would not be valid.

addSegmentEntity

public static void addSegmentEntity(org._3pq.jgrapht.Graph graph,
                                    CtEntity ent,
                                    ConfigurationMgr conf)
                             throws java.lang.IllegalAccessException,
                                    IllegalDrawingException
Adds a segment from a drawing to a graph. Multiple edges may be added to insure that no existing vertex touches the segment.

Parameters:
graph - the graph
ent - segment from the drawing
conf - drawing configuration
Throws:
java.lang.IllegalAccessException
IllegalDrawingException - If created edges would be incompatible with this graph's type.

findRaiser

public static HydroVertex findRaiser(org._3pq.jgrapht.DirectedGraph graph)
                              throws java.lang.IllegalAccessException,
                                     IllegalDrawingException
Attempts to locate a raiser vertex in a drawing graph.

Parameters:
graph - the graph
Returns:
the raiser vertex
Throws:
java.lang.IllegalAccessException
IllegalDrawingException - if raiser cannot be determined

orderGraph

public static java.util.Set orderGraph(org._3pq.jgrapht.DirectedGraph graph,
                                       HydroVertex raiser,
                                       ConfigurationMgr conf)
                                throws IllegalDrawingException
Finds edges that need to be reversed in a graph to create a 'proper' ordering. At a minimum the resulting graph should not have internal sinks and exactly one source at a specified raiser vertex.

Parameters:
graph - the graph to be checked.
raiser - the source point
conf - graph configuration
Returns:
the edges that must be reversed
Throws:
IllegalDrawingException

reverseEdgeInSubgraph

public static void reverseEdgeInSubgraph(HydroEdge edge,
                                         org._3pq.jgrapht.DirectedGraph base,
                                         org._3pq.jgrapht.DirectedGraph sub)
Replaces an edge with one built from it using its endpoints in reverse order. The operation applies to the main graph and its subgraph view.

Parameters:
edge - the edge to be replaced
base - the main graph
sub - the subgraph

mainSubgraph

public static org._3pq.jgrapht.DirectedGraph mainSubgraph(org._3pq.jgrapht.DirectedGraph graph)
Creates a subgraph induced by vertices of main edges in a graph.

Parameters:
graph - the graph
Returns:
the subgraph

branchSubgraph

public static org._3pq.jgrapht.DirectedGraph branchSubgraph(org._3pq.jgrapht.DirectedGraph graph)
Creates a subgraph induced by vertices of branch edges in a graph.

Parameters:
graph - the graph
Returns:
the subgraph

validateMainSubgraph

public static void validateMainSubgraph(org._3pq.jgrapht.DirectedGraph graph)
                                 throws IllegalDrawingException
Preliminary validation of the main subgraph within a connected graph.

Parameters:
graph - the connected graph
Throws:
IllegalDrawingException