CadDrawingGraph
from OpenCAD2D import CadDrawingGraph
class CadDrawingGraph(System.Object) ยท CadDrawingGraph in the .NET reference
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.
Properties and fields
Edges
@property
def Edges(self) -> System.Collections.Generic.IReadOnlyList[CadGraphEdge]
Gets the edges, sorted by kind, then source, then target.
EdgesFound
@property
def EdgesFound(self) -> int
Gets how many edges had been found when the search stopped: the number of CadDrawingGraph.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
@property
def Flat(self) -> CadFlatDrawing
Gets the walked drawing: its entities are the nodes, in this order.
NodeCount
@property
def NodeCount(self) -> int
Gets the number of nodes.
Tolerance
@property
def Tolerance(self) -> float
Gets the tolerance in millimetres the touches were found to.
Truncated
@property
def Truncated(self) -> bool
Gets whether the graph was cut at the cap it was built with: there are edges beyond those of CadDrawingGraph.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
@staticmethod
def Build(flat: CadFlatDrawing, tolerance: float) -> CadDrawingGraph
Builds the graph of a drawing already walked.
@staticmethod
def Build(document: CadDocument, layout: str, tolerance: float) -> CadDrawingGraph
Builds the graph of a drawing: walks it (CadFlatten.Walk) and finds the edges.
@staticmethod
def Build(flat: CadFlatDrawing, tolerance: float, maxEdges: int) -> CadDrawingGraph
Builds the graph of a drawing already walked, with a cap on its edges (see CadDrawingGraph.Build).
@staticmethod
def Build(document: CadDocument, layout: str, tolerance: float, maxEdges: int) -> CadDrawingGraph
Builds the graph of a drawing, stopping when it has more than maxEdges edges, 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 first maxEdges edges of the whole one in its order (kind, source, target) and says so with CadDrawingGraph.Truncated and CadDrawingGraph.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 has EdgesFound 600.
EdgeArray
def EdgeArray(self) -> System.Array[float]
Gets the edges as numbers, for an array: source, target, kind of 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
def ToJson(self) -> str
Writes the graph as JSON: schemaopencad2d.graph, version 1, tolerance, nodes (each with its id, handle, kind, layer, colour, linetype, layout, box in millimetres, block path and words) and edges (source, target, kind as touches, contains, dimensions or annotates, and at, the place in millimetres or null), then truncated and edgesFound (CadDrawingGraph.Truncated, CadDrawingGraph.EdgesFound).