/// <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> /// Constructs an instance of <see cref="DefaultLabelStyle"/> representing this Style /// </summary> /// <param name="xStyle">The XML Element to be converted into this style</param> public BpmnLabelStyle(XElement xStyle) { Id = null; Font = "Arial"; Size = 0; IsBold = false; IsItalic = false; IsUnderline = false; IsStrikeThrough = false; Id = BpmnNM.GetAttributeValue(xStyle, BpmnNM.Dc, BpmnDiConstants.IdAttribute); // Parse Values of the Label Style var xFont = BpmnNM.GetElement(xStyle, BpmnNM.Dc, BpmnDiConstants.FontElement); if (xFont != null) { Font = BpmnNM.GetAttributeValue(xFont, BpmnNM.Dc, BpmnDiConstants.NameAttribute); var attr = BpmnNM.GetAttributeValue(xFont, BpmnNM.Dc, BpmnDiConstants.SizeAttribute); if (attr != null) { Size = float.Parse(attr, CultureInfo.InvariantCulture); } attr = BpmnNM.GetAttributeValue(xFont, BpmnNM.Dc, BpmnDiConstants.IsBoldAttribute); if (attr != null) { IsBold = bool.Parse(attr); } attr = BpmnNM.GetAttributeValue(xFont, BpmnNM.Dc, BpmnDiConstants.IsItalicAttribute); if (attr != null) { IsItalic = bool.Parse(attr); } attr = BpmnNM.GetAttributeValue(xFont, BpmnNM.Dc, BpmnDiConstants.IsUnderlineAttribute); if (attr != null) { IsUnderline = bool.Parse(attr); } attr = BpmnNM.GetAttributeValue(xFont, BpmnNM.Dc, BpmnDiConstants.IsStrikeThroughAttribute); if (attr != null) { IsStrikeThrough = bool.Parse(attr); } } LabelStyle = new DefaultLabelStyle { StringFormat = { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center } }; var fontStyle = FontStyle.Regular; // Set Boldness if (IsBold) { fontStyle |= FontStyle.Bold; } // Set Italic if (IsItalic) { fontStyle |= FontStyle.Italic; } // Set Underline if (IsUnderline) { fontStyle |= FontStyle.Underline; } // Set StrikeThrough if (IsStrikeThrough) { fontStyle |= FontStyle.Strikeout; } LabelStyle.Font = new Font(Font, Size > 0 ? Size : LabelTextSize, fontStyle, GraphicsUnit.Pixel); LabelStyle.StringFormat.FormatFlags &= ~StringFormatFlags.NoWrap; }
/// <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); }
/// <summary> /// Class for BPMNElement objects /// </summary> /// <param name="xNode">The XML Node to turn into a BpmnElement</param> public BpmnElement(XElement xNode) { Children = new List <BpmnElement>(); ForeignChildren = new List <XNode>(); Attributes = new Dictionary <string, string>(); //Initialize blank Label Label = ""; // Parsing all Attributes foreach (var attribute in BpmnNM.AttributesInNamespace(xNode.Attributes(), BpmnNM.Bpmn)) { var localName = attribute.Name.LocalName; switch (localName) { case BpmnDiConstants.IdAttribute: Id = attribute.Value; break; case BpmnDiConstants.NameAttribute: Label = attribute.Value; break; case BpmnDiConstants.SourceRefAttribute: Source = attribute.Value; break; case BpmnDiConstants.TargetRefAttribute: Target = attribute.Value; break; case BpmnDiConstants.ProcessRefAttribute: Process = attribute.Value; break; case BpmnDiConstants.CalledElementAttribute: case BpmnDiConstants.CalledChoreographyRefAttribute: CalledElement = attribute.Value; break; default: Attributes.Add(localName, attribute.Value); break; } } Value = xNode.Value; Name = xNode.Name.LocalName; switch (Name) { case BpmnDiConstants.GroupElement: Label = BpmnNM.GetAttributeValue(xNode, BpmnNM.Bpmn, BpmnDiConstants.CategoryValueRefAttribute); break; case BpmnDiConstants.TextAnnotationElement: var element = BpmnNM.GetElement(xNode, BpmnNM.Bpmn, BpmnDiConstants.TextElement); if (element != null) { Label = element.Value; } break; } }
/// <summary> /// Constructs an instance of <see cref="DefaultLabelStyle"/> representing this Style /// </summary> /// <param name="xStyle">The XML Element to be converted into this style</param> public BpmnLabelStyle(XElement xStyle) { Id = null; Font = "Arial"; Size = 0; IsBold = false; IsItalic = false; IsUnderline = false; IsStrikeThrough = false; Id = BpmnNM.GetAttributeValue(xStyle, BpmnNM.Dc, BpmnDiConstants.IdAttribute); // Parse Values of the Label Style var xFont = BpmnNM.GetElement(xStyle, BpmnNM.Dc, BpmnDiConstants.FontElement); if (xFont != null) { Font = BpmnNM.GetAttributeValue(xFont, BpmnNM.Dc, BpmnDiConstants.NameAttribute); var attr = BpmnNM.GetAttributeValue(xFont, BpmnNM.Dc, BpmnDiConstants.SizeAttribute); if (attr != null) { Size = double.Parse(attr, CultureInfo.InvariantCulture); } attr = BpmnNM.GetAttributeValue(xFont, BpmnNM.Dc, BpmnDiConstants.IsBoldAttribute); if (attr != null) { IsBold = bool.Parse(attr); } attr = BpmnNM.GetAttributeValue(xFont, BpmnNM.Dc, BpmnDiConstants.IsItalicAttribute); if (attr != null) { IsItalic = bool.Parse(attr); } attr = BpmnNM.GetAttributeValue(xFont, BpmnNM.Dc, BpmnDiConstants.IsUnderlineAttribute); if (attr != null) { IsUnderline = bool.Parse(attr); } attr = BpmnNM.GetAttributeValue(xFont, BpmnNM.Dc, BpmnDiConstants.IsStrikeThroughAttribute); if (attr != null) { IsStrikeThrough = bool.Parse(attr); } } LabelStyle = new DefaultLabelStyle { TextAlignment = TextAlignment.Center, VerticalTextAlignment = VerticalAlignment.Center }; var fontStyle = FontStyles.Normal; var fontWeight = FontWeights.Normal; // Set text size if (Size > 0) { LabelStyle.TextSize = Size; } else { LabelStyle.TextSize = LabelTextSize; } // Set Boldness if (IsBold) { fontWeight = FontWeights.Bold; } // Set Italic if (IsItalic) { fontStyle = FontStyles.Italic; } LabelStyle.Typeface = new Typeface(new FontFamily(Font), fontStyle, fontWeight, FontStretches.Normal); LabelStyle.TextDecorations = new TextDecorationCollection(); // Set Underline if (IsUnderline) { LabelStyle.TextDecorations.Add(TextDecorations.Underline); } // Set StrikeThrough if (IsStrikeThrough) { LabelStyle.TextDecorations.Add(TextDecorations.Strikethrough); } LabelStyle.TextWrapping = TextWrapping.Wrap; }