/// <summary> /// Creates a <see cref="BpmnDiagram"/>. /// </summary> /// <param name="xNode">The XML node to start with</param> /// <returns>The parsed <see cref="BpmnDiagram"/></returns> private BpmnDiagram BuildDiagram(XElement xNode) { var diagram = new BpmnDiagram(xNode); var bpmnPlane = BuildPlane(BpmnNM.GetElement(xNode, BpmnNM.BpmnDi, BpmnDiConstants.BpmnPlaneElement)); if (bpmnPlane != null) { diagram.AddPlane(bpmnPlane); } foreach (var xChild in BpmnNM.GetElements(xNode, BpmnNM.BpmnDi, BpmnDiConstants.BpmnLabelStyleElement)) { var style = new BpmnLabelStyle(xChild); diagram.AddStyle(style); } // Setting a default LabelStyle for all labels that do not have their own style. diagram.DefaultStyle = BpmnLabelStyle.NewDefaultInstance(); return(diagram); }
/// <summary> /// Parse all bpmn shapes and bpmn edges and their associations and attributes from one <see cref="BpmnPlane"/> /// </summary> /// <param name="xNode">The XML node to start with</param> private BpmnPlane BuildPlane(XElement xNode) { var plane = new BpmnPlane(xNode, Elements); if (plane.Element == null) { return(null); } // All Shapes foreach (var xChild in BpmnNM.GetElements(xNode, BpmnNM.BpmnDi, BpmnDiConstants.BpmnShapeElement)) { var shape = new BpmnShape(xChild, Elements); if (shape.Element != null) { plane.AddShape(shape); } else { Messages.Add("Error in parsing shape " + (shape.Id) + ", could not find corresponding BPMNElement."); continue; } // Shapes usually define their bounds shape.AddBounds(BpmnNM.GetElement(xChild, BpmnNM.Dc, BpmnDiConstants.BoundsElement)); // Shapes can have a BPMNLabel as child var bpmnLabel = BpmnNM.GetElement(xChild, BpmnNM.BpmnDi, BpmnDiConstants.BpmnLabelElement); if (bpmnLabel != null) { // Label bounds var bounds = BpmnNM.GetElement(bpmnLabel, BpmnNM.Dc, BpmnDiConstants.BoundsElement); shape.AddLabel(bounds); // BpmnLabelStyle shape.LabelStyle = BpmnNM.GetAttributeValue(bpmnLabel, BpmnNM.BpmnDi, BpmnDiConstants.LabelStyleAttribute); } } foreach (var xChild in BpmnNM.GetElements(xNode, BpmnNM.BpmnDi, BpmnDiConstants.BpmnEdgeElement)) { var edge = new BpmnEdge(xChild, Elements); if (edge.Element != null) { plane.AddEdge(edge); } else { Messages.Add("Error in parsing edge " + (edge.Id) + ", could not find corresponding BPMNElement."); continue; } // Edges define 2 or more Waypoints foreach (var waypoint in BpmnNM.GetElements(xChild, BpmnNM.Di, BpmnDiConstants.WaypointElement)) { edge.AddWayPoint(waypoint); } // Edges can have a BPMNLabel as child var bpmnLabel = BpmnNM.GetElement(xChild, BpmnNM.BpmnDi, BpmnDiConstants.BpmnLabelElement); if (bpmnLabel != null) { // Label bounds var bounds = BpmnNM.GetElement(bpmnLabel, BpmnNM.Dc, BpmnDiConstants.BoundsElement); edge.AddLabel(bounds); // BpmnLabelStyle edge.LabelStyle = BpmnNM.GetAttributeValue(bpmnLabel, BpmnNM.BpmnDi, BpmnDiConstants.LabelStyleAttribute); } } return(plane); }