Class CadDrawingGraph
- Namespace
- OpenCAD2D
- Assembly
- OpenCAD2D.Core.dll
A drawing as a graph for a network to read: a node for each entity of CadFlatten (numbered as CadDrawingJson lists them) and an edge for each way two entities are related: they touch, one holds the other, a dimension measures one, a leader points at one.
public sealed class CadDrawingGraph
- Inheritance
-
CadDrawingGraph
- Inherited Members
Remarks
A drawing of 10 000 entities is worked with a grid over the boxes of the entities, so that only entities near each other are tested; the edges come out sorted by kind, source and target, whatever order the grid was walked in, so the same drawing gives the same graph. Relations are found within one layout, never between model space and a sheet.
touches: two curves that come within the tolerance of each other: their ends meet, an end lies on the other, they cross, or they run along each other. Lines, arcs, circles and polylines (a bulge is an arc) are measured exactly, the nearest places of their sides and arcs; an ellipse or a spline by the library, an end of one within the tolerance of the other or a crossing of the two (to the library's 0.001 mm). contains: a closed curve whose outline (arcs and splines taken as 48 chords, a polyline's bulges as 12 per arc) holds the other entity: the four corners of its box inside or on the outline and the middle of the box inside it, with a box smaller than its own, so that a line along one side touches the boundary and is not held by it. dimensions: from a dimension to the entities of its DIMASSOC where it has one, else to the curves its definition points lie on. annotates: from a leader to the curves (and hatches) its arrow tip lies on.
Properties
- Edges
Gets the edges, sorted by kind, then source, then target.
- EdgesFound
Gets how many edges had been found when the search stopped: the number of Edges for a graph that was not cut, and for one that was, at least one more than the cap (the search finishes the node it stops at, so the whole drawing has this many edges or more).
- Flat
Gets the walked drawing: its entities are the nodes, in this order.
- NodeCount
Gets the number of nodes.
- Tolerance
Gets the tolerance in millimetres the touches were found to.
- Truncated
Gets whether the graph was cut at the cap it was built with: there are edges beyond those of Edges. The edges kept are the first of the whole graph in its order (kind, source, target), so the same drawing and cap give the same graph.
Methods
- Build(CadDocument, string, double)
Builds the graph of a drawing: walks it (Walk(CadDocument, string)) and finds the edges.
- Build(CadDocument, string, double, int)
Builds the graph of a drawing, stopping when it has more than
maxEdgesedges, so that a dense drawing (thousands of lines that cross each other) does not cost as many edges as it has crossings: the graph keeps the firstmaxEdgesedges of the whole one in its order (kind, source, target) and says so with Truncated and EdgesFound. A drawing of 600 lines across 600 others, whose 360 000 crossings are the touches, built with a cap of 50, keeps the 50 edges of its first line and hasEdgesFound600.
- Build(CadFlatDrawing, double)
Builds the graph of a drawing already walked.
- Build(CadFlatDrawing, double, int)
Builds the graph of a drawing already walked, with a cap on its edges (see Build(CadDocument, string, double, int)).
- EdgeArray()
Gets the edges as numbers, for an array:
source, target, kindof each edge in turn (kind as CadGraphEdgeKind numbers it), three numbers an edge. Taken as an array of shape (n, 3) of float64 by the Python package.
- ToJson()
Writes the graph as JSON:
schemaopencad2d.graph,version1,tolerance,nodes(each with itsid, handle, kind, layer, colour, linetype, layout, box in millimetres, block path and words) andedges(source,target,kindastouches,contains,dimensionsorannotates, andat, the place in millimetres or null), thentruncatedandedgesFound(Truncated, EdgesFound).