/// <summary> /// MoveLabel amount Pixels according to EA coordinate system. Give the type as 'OX' (horizontal) or 'OY' (vertical) /// </summary> /// <param name="obj"></param> /// <param name="type">'OX' or 'OY'</param> /// <param name="amountPixels"></param> private void MoveLabel(EA.DiagramObject obj, string type, int amountPixels) { Match match = Regex.Match((string)obj.Style, $@"{type}=([\+\-0-9]*)"); if (match.Success) { int xPos = Convert.ToInt32(match.Groups[1].Value) + amountPixels; ChangeDiagramObjectStyle(obj, $@"{type}=[\+\-0-9]*", $@"{type}={xPos}"); } }
/// <summary> /// Change Diagram Object Label (x, y, rotation) /// </summary> /// <param name="obj"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="rotation">0=none, 1=clockwise, -1 anti clockwise</param> private void ChangeDiagramObjectLabel(EA.DiagramObject obj, string x, string y, string rotation) { // make one line (works for horizontal and vertical) ChangeDiagramObjectStyle(obj, @"CX=[\+\-0-9]*", $@"CX=100"); ChangeDiagramObjectStyle(obj, @"CY=[\+\-0-9]*", $@"CY=13"); ChangeDiagramObjectStyle(obj, @"OX=[\+\-0-9]*", $@"OX={x}"); ChangeDiagramObjectStyle(obj, @"OY=[\+\-0-9]*", $@"OY={y}"); ChangeDiagramObjectStyle(obj, "ROT=(0|-1|1)", $"ROT={rotation}"); }
/// <summary> /// Set the style of an diagram object. The style is code with enum LabelStyle. /// -HDN Hide Label /// - PType: Output type /// - OX=nn; Label Position, -nn=Left, +nn = Right /// </summary> /// <param name="portObj"></param> /// <param name="style"></param> public void DoChangeLabelStyle(EA.Element el, EA.DiagramObject portObj, LabelStyle style) { Match match; switch (style) { case LabelStyle.IsHidden: ChangeDiagramObjectStyle(portObj, @"HDN=0", "HDN=1"); break; case LabelStyle.IsShown: ChangeDiagramObjectStyle(portObj, @"HDN=1", "HDN=0"); break; case LabelStyle.IsPortResizable: ChangeDiagramObjectStyle(portObj, @"PortResizable=0", "PortResizable=1"); break; case LabelStyle.IsNotPortResizable: ChangeDiagramObjectStyle(portObj, @"PortResizable=1", "PortResizable=0"); break; case LabelStyle.IsTypeHidden: ChangeDiagramObjectStyle(portObj, @"PType=1", "PType=0"); break; case LabelStyle.IsTypeShown: ChangeDiagramObjectStyle(portObj, @"PType=0", "PType=1"); break; case LabelStyle.PositionLeft: ChangeDiagramObjectStyle(portObj, @"OX=[\+\-0-9]*", @"OX=-200"); break; case LabelStyle.PositionRight: ChangeDiagramObjectStyle(portObj, @"OX=[\+\-0-9]*", @"OX=24"); break; case LabelStyle.PositionDownPlus: MoveLabel(portObj, "OY", 15); break; case LabelStyle.PositionUpPlus: MoveLabel(portObj, "OY", -15); break; case LabelStyle.PositionMinus: // get old x position MoveLabel(portObj, "OX", -15); break; // add offset to position case LabelStyle.PositionPlus: MoveLabel(portObj, "OX", +15); break; // Round robin Rotation settings (no, clockwise, anti clockwise) case LabelStyle.RotateLabel: // get old rotation string newRotationValue = ""; match = Regex.Match((string)portObj.Style, @"ROT=(0|-1|1)"); if (match.Success) { string oldRotationValue = match.Value; switch (oldRotationValue) { case "ROT=0": newRotationValue = "ROT=1"; break; case "ROT=-1": newRotationValue = "ROT=0"; break; case "ROT=1": newRotationValue = "ROT=-1"; break; } if (newRotationValue != "") { ChangeDiagramObjectStyle(portObj, oldRotationValue, newRotationValue); } } break; // Align Label to default position case LabelStyle.AlignLabel1: var edge = portObj.Edge(_rep); if (el.Type.Contains("Interface")) { // Required / Provided Interface PortAlignmentItem settingsInterface = _portAlignmentItems.Find(x => x.Type == "Interface"); AlignLabel(portObj, edge, settingsInterface); } else { // Ports, Pins,.. PortAlignmentItem settingsPort = _portAlignmentItems.Find(x => x.Type == "Port"); AlignLabel(portObj, edge, settingsPort); } break; // Align Label to default position 2 case LabelStyle.AlignLabel2: edge = portObj.Edge(_rep); if (el.Type.Contains("Interface")) { // Required / Provided Interface PortAlignmentItem settingsInterface = _portAlignmentItems.Find(x => x.Type == "Interface1"); AlignLabel(portObj, edge, settingsInterface); } else { // Ports, Pins,.. PortAlignmentItem settingsPort = _portAlignmentItems.Find(x => x.Type == "Port1"); AlignLabel(portObj, edge, settingsPort); } break; } //string style = (string)portObj.Style; //if (isHidden) style = style.Replace("HDN=0", "HDN=1"); //else style = style.Replace("HDN=1", "HDN=0"); //portObj.Style = style; }
/// <summary> /// Set the style of an diagram object. The style is code with enum LabelStyle. /// </summary> /// <param name="portObj"></param> /// <param name="style"></param> public static void DoChangeLabelStyle(EA.DiagramObject portObj, LabelStyle style) { switch (style) { case LabelStyle.IsHidden: ChangeDiagramObjectStyle(portObj, @"HDN=0", "HDN=1"); break; case LabelStyle.IsShown: ChangeDiagramObjectStyle(portObj, @"HDN=1", "HDN=0"); break; case LabelStyle.IsTypeHidden: ChangeDiagramObjectStyle(portObj, @"PType=1", "PType=0"); break; case LabelStyle.IsPortResizable: ChangeDiagramObjectStyle(portObj, @"PortResizable=0", "PortResizable=1"); break; case LabelStyle.IsNotPortResizable: ChangeDiagramObjectStyle(portObj, @"PortResizable=1", "PortResizable=0"); break; case LabelStyle.IsTypeShown: ChangeDiagramObjectStyle(portObj, @"PType=0", "PType=1"); break; case LabelStyle.PositionLeft: ChangeDiagramObjectStyle(portObj, @"OX=[\+\-0-9]*", @"OX=-200"); break; case LabelStyle.PositionRight: ChangeDiagramObjectStyle(portObj, @"OX=[\+\-0-9]*", @"OX=24"); break; case LabelStyle.PositionMinus: // get old x position Match match = Regex.Match((string)portObj.Style, @"OX=([\+\-0-9]*)"); if (match.Success) { int xPos = Convert.ToInt32(match.Groups[1].Value) - 15; ChangeDiagramObjectStyle(portObj, @"OX=[\+\-0-9]*", $@"OX={xPos}"); } break; case LabelStyle.PositionPlus: // get old x position match = Regex.Match((string)portObj.Style, @"OX=([\+\-0-9]*)"); if (match.Success) { int xPos = Convert.ToInt32(match.Groups[1].Value) + 15; ChangeDiagramObjectStyle(portObj, @"OX=[\+\-0-9]*", $@"OX={xPos}"); } break; } //string style = (string)portObj.Style; //if (isHidden) style = style.Replace("HDN=0", "HDN=1"); //else style = style.Replace("HDN=1", "HDN=0"); //portObj.Style = style; }