public void Main(int processId, ScriptType scriptType) { int electricSchemeTypeCode = 0; E3Project project = new E3Project(processId); Sheet sheet = project.GetSheetById(0); E3Text text = project.GetTextById(0); HashSet <int> electricSchemeSheetIds = GetElectricSchemeSheetIds(project, sheet, electricSchemeTypeCode); Dictionary <int, DeviceConnection> deviceConnectionById; Dictionary <int, CableInfo> cableInfoById; GetDeviceConnectionByIdAndCableInfoById(project, electricSchemeSheetIds, out deviceConnectionById, out cableInfoById); Dictionary <int, DeviceSymbol> deviceSymbolById = GetDeviceSymbolById(project, text, deviceConnectionById); Dictionary <string, List <SymbolScheme> > schemesByAssignment = GetSchemesByAssignment(deviceConnectionById, deviceSymbolById, cableInfoById, sheet, text); if (scriptType == ScriptType.Scheme) { foreach (string assignment in schemesByAssignment.Keys) { PlaceSchemes(schemesByAssignment[assignment], project, sheet, text, assignment); } } else { Dictionary <string, List <int> > OWSSheetIdsByAssignment = GetOWSSheetIdsByAssignment(project, sheet, schemesByAssignment.Keys); foreach (string assignment in schemesByAssignment.Keys) { IEnumerable <int> allDeviceIds = schemesByAssignment[assignment].SelectMany(s => s.AllDeviceIds).Distinct(); int schemeSheetCount = OWSSheetIdsByAssignment[assignment].Count; new SpecificationScript(allDeviceIds, ++schemeSheetCount, subProjectAttribute, "СВП", sheetMarkAttribute, assignment); } } project.Release(); }
public SymbolPin(string name, string signal, E3Text text, E3Font font) { Name = name; Signal = signal; CableIds = new List <int>(); SignalTextWidth = text.GetTextLength(signal, font); SignalTextWidth = (SignalTextWidth % 1 > 0) ? (int)(SignalTextWidth + 1) : SignalTextWidth; }
public List <int> Place(Sheet sheet, Graphic graphic, E3Text text, Point position) { int sheetId = sheet.Id; if (isTerminal) { return(CreateTerminalSymbol(sheet, text, graphic, sheetId, position)); } else { return(CreateDeviceSymbol(sheet, text, graphic, sheetId, position)); } }
public void Place(Sheet sheet, Graphic graphic, E3Text text, Group group, Point placePosition) { E3Font smallFont = new E3Font(height: smallFontHeight, alignment: Alignment.Left); E3Font bigFont = new E3Font(height: bigFontHeight, alignment: Alignment.Left); List <int> groupIds; if (orientation == Orientation.Horizontal) { groupIds = PlaceHorizontally(sheet, graphic, text, placePosition, smallFont, bigFont); } else { groupIds = PlaceVertically(sheet, graphic, text, placePosition, smallFont, bigFont); } group.CreateGroup(groupIds); }
public CableSymbol(CableInfo cableInfo, E3Text text, Orientation orientation) { this.cableInfo = cableInfo; this.orientation = orientation; CableId = cableInfo.Id; ovalLength = 0; smallFontHeight = 2; bigFontHeight = 3; isCircle = true; E3Font smallFont = new E3Font(height: smallFontHeight); E3Font bigFont = new E3Font(height: 3); nameTextWidth = text.GetTextLength(cableInfo.Name, bigFont); typeTextWidth = text.GetTextLength(cableInfo.Type, smallFont); lengthTextWidth = text.GetTextLength(cableInfo.Length, smallFont); Size = GetSize(); }
private List <int> PlaceHorizontally(Sheet sheet, Graphic graphic, E3Text text, Point placePosition, E3Font smallFont, E3Font bigFont) { List <int> groupIds = new List <int>(6); int sheetId = sheet.Id; double x = sheet.MoveLeft(placePosition.X, Size.Width / 2); double y = sheet.MoveDown(placePosition.Y, bigOffset + smallFontHeight); groupIds.Add(text.CreateText(sheetId, cableInfo.Type, x, y, smallFont)); double x2 = sheet.MoveRight(x, typeTextWidth + smallOffset); groupIds.Add(graphic.CreateLine(sheetId, x, placePosition.Y, x2, placePosition.Y, lineHeight, connectionColorIndex)); double radius = diameter / 2; double halfNameTextWidth = nameTextWidth / 2; x = sheet.MoveRight(x2, radius - halfNameTextWidth + ovalLength / 2); y = sheet.MoveDown(placePosition.Y, bigFontHeight / 2); groupIds.Add(text.CreateText(sheetId, cableInfo.Name, x, y, bigFont)); x = sheet.MoveRight(x2, radius); if (isCircle) { groupIds.Add(graphic.CreateCircle(sheetId, x, placePosition.Y, radius)); x = sheet.MoveRight(x, radius); } else { groupIds.Add(graphic.CreateArc(sheetId, x, placePosition.Y, radius, 90, 270)); double y1 = sheet.MoveUp(placePosition.Y, radius); double y2 = sheet.MoveDown(placePosition.Y, radius); x2 = sheet.MoveRight(x, ovalLength); groupIds.Add(graphic.CreateLine(sheetId, x, y1, x2, y1)); groupIds.Add(graphic.CreateLine(sheetId, x, y2, x2, y2)); groupIds.Add(graphic.CreateArc(sheetId, x2, placePosition.Y, radius, 270, 90)); x = sheet.MoveRight(x2, radius); } x2 = sheet.MoveRight(x, smallOffset + lengthTextWidth); groupIds.Add(graphic.CreateLine(sheetId, x, placePosition.Y, x2, placePosition.Y, lineHeight, connectionColorIndex)); x = sheet.MoveRight(x, smallOffset); y = sheet.MoveUp(placePosition.Y, bigOffset); groupIds.Add(text.CreateText(sheetId, cableInfo.Length, x, y, smallFont)); PlacedPosition = placePosition; return(groupIds); }
private List <int> DrawPins(Sheet sheet, Graphic graphic, E3Text text, List <SymbolPin> pins, double pinsHeight, double pinsWidth, int sheetId, double xLeft, double pinBottom, double pinTop, Level position) { List <int> graphicIds = new List <int>(pins.Count * 2 + 1); double pinLeft = sheet.MoveRight(xLeft, (Size.Width - pinsWidth) / 2); foreach (SymbolPin pin in pins) { double pinRight = sheet.MoveRight(pinLeft, gridStep); int pinOutlineId = graphic.CreateRectangle(sheetId, pinLeft, pinBottom, pinRight, pinTop); graphicIds.Add(pinOutlineId); double textWidth = text.GetTextLength(pin.Name, smallFont); double xPinText = sheet.MoveRight(sheet.MoveRight(pinLeft, halfGridStep), smallFont.height / 2 - 0.2); double yPinText = sheet.MoveUp(pinBottom, (pinsHeight - textWidth) / 2); graphicIds.Add(text.CreateVerticalText(sheetId, pin.Name, xPinText, yPinText, smallFont)); int signalTextId = DrawSignalAndSetConnectionPoint(pin, position, sheet, text, sheetId, pinBottom, pinTop, pinLeft); graphicIds.Add(signalTextId); pinLeft = pinRight; } return(graphicIds); }
private List <int> PlaceVertically(Sheet sheet, Graphic graphic, E3Text text, Point placePosition, E3Font smallFont, E3Font bigFont) { List <int> groupIds = new List <int>(5); int sheetId = sheet.Id; double radius = diameter / 2; double x, y2; double y = sheet.MoveUp(placePosition.Y, Size.Height / 2 - radius); if (isCircle) { groupIds.Add(graphic.CreateCircle(sheetId, placePosition.X, y, radius)); } else { x = sheet.MoveLeft(placePosition.X, ovalLength / 2); groupIds.Add(graphic.CreateArc(sheetId, x, y, radius, 90, 270)); double x2 = sheet.MoveRight(x, ovalLength); groupIds.Add(graphic.CreateArc(sheetId, x2, y, radius, 270, 90)); y = sheet.MoveDown(y, radius); y2 = sheet.MoveUp(y, 2 * radius); groupIds.Add(graphic.CreateLine(sheetId, x, y, x2, y)); groupIds.Add(graphic.CreateLine(sheetId, x, y2, x2, y2)); y = sheet.MoveUp(y, radius); } x = sheet.MoveLeft(placePosition.X, nameTextWidth / 2); y = sheet.MoveDown(y, bigFontHeight / 2); groupIds.Add(text.CreateText(sheetId, cableInfo.Name, x, y, bigFont)); y = sheet.MoveDown(y, radius - bigFontHeight / 2); y2 = sheet.MoveDown(y, smallOffset + Math.Max(typeTextWidth, lengthTextWidth)); groupIds.Add(graphic.CreateLine(sheetId, placePosition.X, y, placePosition.X, y2, lineHeight, connectionColorIndex)); y = sheet.MoveDown(y, smallOffset + typeTextWidth); x = sheet.MoveLeft(placePosition.X, bigOffset); groupIds.Add(text.CreateVerticalText(sheetId, cableInfo.Type, x, y, smallFont)); x = sheet.MoveRight(placePosition.X, bigOffset + smallFontHeight); y = sheet.MoveUp(y, typeTextWidth - lengthTextWidth); groupIds.Add(text.CreateVerticalText(sheetId, cableInfo.Length, x, y, smallFont)); PlacedPosition = placePosition; return(groupIds); }
private List <int> CreateDeviceSymbol(Sheet sheet, E3Text text, Graphic graphic, int sheetId, Point position) { List <int> groupIds = new List <int>((topPins.Count + bottomPins.Count) * 2 + 2); E3Font bigFont = new E3Font(alignment: Alignment.Left); groupIds.Add(CreateOutline(sheet, graphic, sheetId, position)); double xText = sheet.MoveRight(position.X, (Size.Width - nameWidth) / 2); double spaceForName = Size.Height - bottomPinsHeight - topPinsHeight; double offsetForName = (spaceForName - bigFont.height) / 2; double yText = sheet.MoveUp(position.Y, bottomPinsHeight + offsetForName); groupIds.Add(text.CreateText(sheetId, Name, xText, yText, bigFont)); double top = sheet.MoveUp(position.Y, Size.Height); double pinBottom = sheet.MoveDown(top, topPinsHeight); List <int> topPinIds = DrawPins(sheet, graphic, text, topPins, topPinsHeight, topPinsWidth, sheetId, position.X, pinBottom, top, Level.Top); double pinTop = sheet.MoveUp(position.Y, bottomPinsHeight); List <int> bottomPinIds = DrawPins(sheet, graphic, text, bottomPins, bottomPinsHeight, bottomPinsWidth, sheetId, position.X, position.Y, pinTop, Level.Bottom); groupIds.AddRange(topPinIds); groupIds.AddRange(bottomPinIds); return(groupIds); }
private List <int> CreateTerminalSymbol(Sheet sheet, E3Text text, Graphic graphic, int sheetId, Point position) { List <int> groupIds; E3Font smallFont = new E3Font(height: 2.5, alignment: Alignment.Left); int outlineId = CreateOutline(sheet, graphic, sheetId, position); double offset = 0.5; double xText = sheet.MoveRight(sheet.MoveRight(position.X, halfGridStep), smallFont.height / 2 - 0.2); if (!String.IsNullOrEmpty(Assignment)) { double yAssignmentText = sheet.MoveUp(position.Y, offset); groupIds = new List <int>(3); groupIds.Add(text.CreateVerticalText(sheetId, Assignment, xText, yAssignmentText, smallFont)); } else { groupIds = new List <int>(2); } groupIds.Add(outlineId); nameWidth = text.GetTextLength(Name, smallFont); double top = sheet.MoveUp(position.Y, Size.Height); double yText = sheet.MoveDown(top, offset + nameWidth); groupIds.Add(text.CreateVerticalText(sheetId, Name, xText, yText, smallFont)); foreach (SymbolPin topPin in topPins) { int signalTextId = DrawSignalAndSetConnectionPoint(topPin, Level.Top, sheet, text, sheetId, position.Y, top, position.X); groupIds.Add(signalTextId); } foreach (SymbolPin bottomPin in bottomPins) { int signalTextId = DrawSignalAndSetConnectionPoint(bottomPin, Level.Bottom, sheet, text, sheetId, position.Y, top, position.X); groupIds.Add(signalTextId); } return(groupIds); }
public AssignmentReferenceSymbol(string assignment, int id, int cableId, E3Text text) { this.id = id; triangleHeight = 4; triangleBaseLength = 2; descriptionVerticalMargin = 2; description = "В " + assignment; font = new E3Font(); double descriptionLength = text.GetTextLength(description, font); height = triangleHeight + descriptionVerticalMargin + font.height; margin = Math.Max(triangleBaseLength, descriptionLength) / 2; cableIds = new List <int>() { cableId }; CableLayout cableLayout = new CableLayout(cableId, Level.Bottom); cableLayout.AddOffset(new Point(0, 0)); CableLayoutById = new Dictionary <int, CableLayout>() { { cableId, cableLayout } }; }
public void Place(Sheet sheet, Graphic graphic, Group e3group, E3Text text, Point placePositon) { //layout.Place(sheet, graphic, e3group, text, placePositon); }
private void GetPins(Dictionary <int, DeviceConnection> deviceConnectionById, Dictionary <int, DeviceSymbol> deviceSymbolById, E3Text text) { Dictionary <string, SymbolPin> topPinByName = new Dictionary <string, SymbolPin>(); Dictionary <string, SymbolPin> bottomPinByName = new Dictionary <string, SymbolPin>(); foreach (int connectionId in ConnectionIds) { DeviceConnection connection = deviceConnectionById[connectionId]; int connectedId; string pinName; if (id == connection.StartDeviceId) { connectedId = connection.EndDeviceId; pinName = connection.StartPinName; } else { connectedId = connection.StartDeviceId; pinName = connection.EndPinName; } string connectedAssignment = deviceSymbolById[connectedId].Assignment; if (!String.IsNullOrEmpty(Assignment) && String.IsNullOrEmpty(connectedAssignment)) { if (!topPinByName.ContainsKey(pinName)) { SymbolPin pin = new SymbolPin(pinName, connection.Signal, text, smallFont); topPinByName.Add(pinName, pin); } topPinByName[pinName].CableIds.Add(connection.CableId); } else { if (!bottomPinByName.ContainsKey(pinName)) { SymbolPin pin = new SymbolPin(pinName, connection.Signal, text, smallFont); bottomPinByName.Add(pinName, pin); } bottomPinByName[pinName].CableIds.Add(connection.CableId); } } topPins = topPinByName.Values.ToList(); bottomPins = bottomPinByName.Values.ToList(); NaturalSortingStringComparer stringComparer = new NaturalSortingStringComparer(); topPins.Sort((p1, p2) => stringComparer.Compare(p1.Name, p2.Name)); bottomPins.Sort((p1, p2) => stringComparer.Compare(p1.Name, p2.Name)); }
private double GetPinsHeight(List <SymbolPin> pins, E3Text text) { double offset = 2; return((pins.Count > 0) ? RoundUp(pins.Max(p => text.GetTextLength(p.Name, smallFont)) + offset) : 0); }
public void Place(Point placePosition, Sheet sheet, Graphic graphic, Group group, E3Text text) { PlacedPosition = placePosition; List <int> ids = new List <int>(); ids.AddRange(PlaceAssignmentFrame(placePosition, sheet, graphic, text)); foreach (CableLayout cableLayout in cableLayoutById.Values) { if (cableLayout.Level == Level.Bottom) { ids.AddRange(cableLayout.Place(sheet, graphic, placePosition)); } else { ids.AddRange(cableLayout.Place(sheet, graphic, placePosition)); } } foreach (DeviceSymbol symbol in deviceSymbols) { ids.AddRange(symbol.Place(sheet, graphic, text, placePosition)); placePosition.X = sheet.MoveRight(placePosition.X, symbol.Size.Width); } group.CreateGroup(ids); }
public void Place(Point placePosition, Sheet sheet, Graphic graphic, Group group, E3Text text) { PlacedPosition = placePosition; double width = 0.2; List <int> ids = new List <int>(5); double halfBaseLength = triangleBaseLength / 2; Point leftBottom = new Point(sheet.MoveLeft(placePosition.X, halfBaseLength), placePosition.Y); Point rightBottom = new Point(sheet.MoveRight(placePosition.X, halfBaseLength), placePosition.Y); Point top = new Point(placePosition.X, sheet.MoveUp(placePosition.Y, triangleHeight)); int sheetId = sheet.Id; ids.Add(graphic.CreateLine(sheetId, leftBottom.X, leftBottom.Y, rightBottom.X, rightBottom.Y, width)); ids.Add(graphic.CreateLine(sheetId, leftBottom.X, leftBottom.Y, top.X, top.Y, width)); ids.Add(graphic.CreateLine(sheetId, rightBottom.X, rightBottom.Y, top.X, top.Y, width)); ids.Add(text.CreateText(sheetId, description, top.X, sheet.MoveUp(top.Y, descriptionVerticalMargin), font)); ids.AddRange(CableLayoutById.Values.First().Place(sheet, graphic, placePosition)); group.CreateGroup(ids); }
private Dictionary <string, List <SymbolScheme> > GetSchemesByAssignment(Dictionary <int, DeviceConnection> deviceConnectionById, Dictionary <int, DeviceSymbol> deviceSymbolById, Dictionary <int, CableInfo> cableInfoById, Sheet sheet, E3Text text) { List <HashSet <int> > groupedSymbolIds = GetGroupedSymbolIds(deviceConnectionById.Values); Dictionary <string, List <SymbolScheme> > schemesByAssignment = new Dictionary <string, List <SymbolScheme> >(); foreach (HashSet <int> deviceIds in groupedSymbolIds) { List <SymbolScheme> schemes = SchemeCreator.GetSchemesForConnection(deviceIds, deviceSymbolById, cableInfoById, text); foreach (SymbolScheme scheme in schemes) { if (schemesByAssignment.ContainsKey(scheme.Assignment)) { schemesByAssignment[scheme.Assignment].Add(scheme); } else { schemesByAssignment.Add(scheme.Assignment, new List <SymbolScheme>() { scheme }); } } } return(schemesByAssignment); }
private void PlaceSchemes(List <SymbolScheme> schemes, E3Project project, Sheet sheet, E3Text text, string sheetMark) { double gridStep = 4; Group group = project.GetGroupById(0); Graphic graphic = project.GetGraphicById(0); int sheetCount = 1; CreateSheet(sheet, sheetMark, ref sheetCount); bool needToCreate = false; double availableWith = sheet.DrawingArea.Width * 0.9; double startX = sheet.MoveRight(sheet.DrawingArea.Left, sheet.DrawingArea.Width * 0.05); Point sheetCenter = new Point(sheet.MoveRight(sheet.DrawingArea.Left, sheet.DrawingArea.Width / 2), sheet.MoveDown(sheet.DrawingArea.Top, sheet.DrawingArea.Height / 2)); double totalSchemeWidth = gridStep; List <SymbolScheme> notPlacedSchemes = new List <SymbolScheme>(); foreach (SymbolScheme scheme in schemes) { if (scheme.Size.Width > availableWith) { if (needToCreate) { CreateSheet(sheet, sheetMark, ref sheetCount); } else { needToCreate = true; } scheme.Place(sheet, graphic, group, text, sheetCenter); continue; } totalSchemeWidth += scheme.Size.Width + gridStep; if (totalSchemeWidth < availableWith) { notPlacedSchemes.Add(scheme); } else { if (needToCreate) { CreateSheet(sheet, sheetMark, ref sheetCount); } else { needToCreate = true; } double width = notPlacedSchemes.Sum(s => s.Size.Width); double totalGap = availableWith - width; double gap = totalGap / (notPlacedSchemes.Count + 1); double x = startX; foreach (SymbolScheme notPlacedScheme in notPlacedSchemes) { x = sheet.MoveRight(x, gap + notPlacedScheme.Size.Width / 2); notPlacedScheme.Place(sheet, graphic, group, text, new Point(x, sheetCenter.Y)); x = sheet.MoveRight(x, notPlacedScheme.Size.Width / 2); } notPlacedSchemes.Clear(); totalSchemeWidth = gridStep + scheme.Size.Width; notPlacedSchemes.Add(scheme); } } if (notPlacedSchemes.Count > 0) { if (needToCreate) { CreateSheet(sheet, sheetMark, ref sheetCount); } double width = notPlacedSchemes.Sum(s => s.Size.Width); double totalGap = availableWith - width; double gap = totalGap / (notPlacedSchemes.Count + 1); double x = startX; foreach (SymbolScheme notPlacedScheme in notPlacedSchemes) { x = sheet.MoveRight(x, gap + notPlacedScheme.Size.Width / 2); notPlacedScheme.Place(sheet, graphic, group, text, new Point(x, sheetCenter.Y)); x = sheet.MoveRight(x, notPlacedScheme.Size.Width / 2); } } }
private int DrawSignalAndSetConnectionPoint(SymbolPin pin, Level position, Sheet sheet, E3Text text, int sheetId, double pinBottom, double pinTop, double pinLeft) { double xSignalText = sheet.MoveRight(pinLeft, 1); double ySignalText; E3Font font = new E3Font(height: smallFont.height); if (position == Level.Top) { ySignalText = sheet.MoveUp(pinTop, skewLineOffset); font.alignment = Alignment.Left; } else { ySignalText = sheet.MoveDown(pinBottom, skewLineOffset); font.alignment = Alignment.Right; } return(text.CreateVerticalText(sheetId, pin.Signal, xSignalText, ySignalText, font)); }
private static Dictionary <int, DeviceSymbol> GetDeviceSymbolById(E3Project project, E3Text text, Dictionary <int, DeviceConnection> deviceConnectionById) { NormalDevice device = project.GetNormalDeviceById(0); DevicePin pin = project.GetDevicePinById(0); Dictionary <int, DeviceSymbol> deviceSymbolById = new Dictionary <int, DeviceSymbol>(); foreach (int connectionId in deviceConnectionById.Keys) { DeviceConnection deviceConnection = deviceConnectionById[connectionId]; int startId = deviceConnection.StartDeviceId; int endId = deviceConnection.EndDeviceId; if (!deviceSymbolById.ContainsKey(startId)) { device.Id = startId; deviceSymbolById.Add(startId, new DeviceSymbol(device, pin)); } if (!deviceSymbolById.ContainsKey(endId)) { device.Id = endId; deviceSymbolById.Add(endId, new DeviceSymbol(device, pin)); } deviceSymbolById[startId].ConnectionIds.Add(connectionId); deviceSymbolById[endId].ConnectionIds.Add(connectionId); } foreach (DeviceSymbol deviceSymbol in deviceSymbolById.Values) { deviceSymbol.SetCableIds(deviceConnectionById); deviceSymbol.SetPinsAndHeightAndNameWidth(deviceConnectionById, deviceSymbolById, text); } return(deviceSymbolById); }
private static void AddConnectedSchemeSymbols(DeviceGroup deviceGroup, Dictionary <int, ISchemeSymbol> symbolById, Dictionary <int, List <int> > symbolIdsByCableId, Dictionary <int, List <int> > deviceGroupIdsByCableId, Dictionary <int, DeviceGroup> deviceGroupById, string connectingBoxAssignment, string assignment, ref int schemeSymbolId, E3Text text) { if (symbolById.ContainsKey(deviceGroup.Id)) { return; } symbolById.Add(deviceGroup.Id, deviceGroup); foreach (int cableId in deviceGroup.CableIds) { if (symbolIdsByCableId.ContainsKey(cableId)) { continue; } List <int> ids = deviceGroupIdsByCableId[cableId]; int mateId = (ids.First() == deviceGroup.Id) ? ids.Last() : ids.First(); DeviceGroup mateGroup = deviceGroupById[mateId]; if (symbolById.ContainsKey(mateId)) { if (String.IsNullOrEmpty(mateGroup.Assignment) || mateGroup.Assignment.Equals(connectingBoxAssignment) || mateGroup.Assignment.Equals(assignment)) { symbolIdsByCableId.Add(cableId, ids); } continue; } symbolIdsByCableId.Add(cableId, new List <int>(2) { deviceGroup.Id }); if (String.IsNullOrEmpty(mateGroup.Assignment) || mateGroup.Assignment.Equals(connectingBoxAssignment) || mateGroup.Assignment.Equals(assignment)) { AddConnectedSchemeSymbols(mateGroup, symbolById, symbolIdsByCableId, deviceGroupIdsByCableId, deviceGroupById, connectingBoxAssignment, assignment, ref schemeSymbolId, text); symbolIdsByCableId[cableId].Add(mateId); //schemeSymbolById.Add(mateId, deviceGroupById[mateId]); } else { symbolById.Add(schemeSymbolId, new AssignmentReferenceSymbol(mateGroup.Assignment, schemeSymbolId, cableId, text)); symbolIdsByCableId[cableId].Add(schemeSymbolId); schemeSymbolId++; } } }
/*private Scheme layout; * * public Size Size * { * get * { * return layout.Size; * } * }*/ public static List <SymbolScheme> GetSchemesForConnection(IEnumerable <int> connectedDeviceIds, Dictionary <int, DeviceSymbol> deviceSymbolById, Dictionary <int, CableInfo> cableInfoById, E3Text text) { Dictionary <int, DeviceGroup> deviceGroupById = GetGroupById(connectedDeviceIds, deviceSymbolById, cableInfoById); Dictionary <int, List <int> > deviceGroupIdsByCableId = GetDeviceGroupIdsByCableId(cableInfoById.Count, deviceGroupById.Values); string connectingBoxAssignment = "AssignmentForConnectingBox"; Dictionary <string, List <DeviceGroup> > deviceGroupsByAssignment = GetDeviceGroupsByAssignment(deviceGroupById, connectingBoxAssignment); int schemeSymbolId = deviceGroupById.Count; List <SymbolScheme> schemes = new List <SymbolScheme>(deviceGroupsByAssignment.Count); foreach (string assignment in deviceGroupsByAssignment.Keys) { Dictionary <int, ISchemeSymbol> symbolById = new Dictionary <int, ISchemeSymbol>(); Dictionary <int, List <int> > symbolIdsByCableId = new Dictionary <int, List <int> >(); List <DeviceGroup> deviceGroups = deviceGroupsByAssignment[assignment]; foreach (DeviceGroup deviceGroup in deviceGroups) { AddConnectedSchemeSymbols(deviceGroup, symbolById, symbolIdsByCableId, deviceGroupIdsByCableId, deviceGroupById, connectingBoxAssignment, assignment, ref schemeSymbolId, text); } SymbolScheme scheme = new SymbolScheme(symbolById, symbolIdsByCableId, cableInfoById, text, assignment); schemes.Add(scheme); } return(schemes); //layout = new Scheme(deviceGroupById, deviceGroupIdsByCableId, cableInfoById, text); }
public void SetPinsAndHeightAndNameWidth(Dictionary <int, DeviceConnection> deviceConnectionById, Dictionary <int, DeviceSymbol> deviceSymbolById, E3Text text) { GetPins(deviceConnectionById, deviceSymbolById, text); double height; if (isTerminal) { height = 25; } else { nameWidth = text.GetTextLength(Name, bigFont); topPinsHeight = GetPinsHeight(topPins, text); bottomPinsHeight = GetPinsHeight(bottomPins, text); height = topPinsHeight + bottomPinsHeight + RoundUp(bigFont.height) + 4; } Size = new Size(0, height); }
/*public void CalculateLayout(Scheme layout, double height, Dictionary<int, CableSymbol> cableSymbolById, Dictionary<int, CableInfo> cableInfoById, E3Text text) * { * SortSymbols(); * cableLayoutById = new Dictionary<int, CableLayout>(cableIds.Count); * foreach (DeviceSymbol deviceSymbol in deviceSymbols) * { * deviceSymbol.CalculateLayout(height); * foreach (SymbolPin topPin in deviceSymbol.TopPins) * foreach (int cableId in topPin.CableIds) * { * if (!cableLayoutById.ContainsKey(cableId)) * cableLayoutById.Add(cableId, new CableLayout(cableId, Level.Top)); * cableLayoutById[cableId].AddOffset(new Point(width + topPin.HorizontalOffset, height)); * } * foreach (SymbolPin bottomPin in deviceSymbol.BottomPins) * foreach (int cableId in bottomPin.CableIds) * { * if (!cableLayoutById.ContainsKey(cableId)) * cableLayoutById.Add(cableId, new CableLayout(cableId, Level.Bottom)); * cableLayoutById[cableId].AddOffset(new Point(width + bottomPin.HorizontalOffset, 0)); * } * width += deviceSymbol.Size.Width; * } * matePositionByCableId = layout.GetMatePositionByCableId(Id); * groupPosition = layout.GetGroupPosition(Id); * AdjustCableLayouts(cableLayoutById, cableSymbolById, cableInfoById); * assignmentWidth = text.GetTextLength("Шкаф " + assignment, new E3Font(height: 3)); * TopMargin = height + gridStep * 2 + (topCableVerticalOffsetByStep.Count > 0 ? (topCableVerticalOffsetByStep.Last().Value - height) : 0); * BottomMargin = ((bottomCableVerticalOffsetByStep.Count > 0) ? bottomCableVerticalOffsetByStep.Last().Value : 0) + gridStep; * double additionalAssignmentMargin = (width > assignmentWidth) ? gridStep : (assignmentWidth - width + gridStep / 2); * double minCablesOffset = cableLayoutById.Values.Min(cl=>cl.MinOffset); * LeftMargin = ((minCablesOffset > 0) ? 0 : -minCablesOffset) + additionalAssignmentMargin; * double maxCablesOffset = cableLayoutById.Values.Max(cl => cl.MaxOffset); * RightMargin = ((width > maxCablesOffset) ? width : maxCablesOffset) + additionalAssignmentMargin; * }*/ public void CalculateLayout(SymbolScheme scheme, double height, Dictionary <int, CableSymbol> cableSymbolById, Dictionary <int, CableInfo> cableInfoById, E3Text text) { SortSymbols(); cableLayoutById = new Dictionary <int, CableLayout>(cableIds.Count); foreach (DeviceSymbol deviceSymbol in deviceSymbols) { deviceSymbol.CalculateLayout(height); foreach (SymbolPin topPin in deviceSymbol.TopPins) { foreach (int cableId in topPin.CableIds) { if (!cableLayoutById.ContainsKey(cableId)) { cableLayoutById.Add(cableId, new CableLayout(cableId, Level.Top)); } cableLayoutById[cableId].AddOffset(new Point(width + topPin.HorizontalOffset, height)); } } foreach (SymbolPin bottomPin in deviceSymbol.BottomPins) { foreach (int cableId in bottomPin.CableIds) { if (!cableLayoutById.ContainsKey(cableId)) { cableLayoutById.Add(cableId, new CableLayout(cableId, Level.Bottom)); } cableLayoutById[cableId].AddOffset(new Point(width + bottomPin.HorizontalOffset, 0)); } } width += deviceSymbol.Size.Width; } matePositionByCableId = scheme.GetMatePositionByCableId(Id); groupPosition = scheme.GetGroupPosition(Id); AdjustCableLayouts(cableLayoutById, cableSymbolById, cableInfoById); assignmentWidth = text.GetTextLength("Шкаф " + assignment, new E3Font(height: 3)); TopMargin = height + gridStep * 2 + (topCableVerticalOffsetByStep.Count > 0 ? (topCableVerticalOffsetByStep.Last().Value - height) : 0); BottomMargin = ((bottomCableVerticalOffsetByStep.Count > 0) ? bottomCableVerticalOffsetByStep.Last().Value : 0) + gridStep; double additionalAssignmentMargin = (width > assignmentWidth) ? gridStep : (assignmentWidth - width + gridStep / 2); double minCablesOffset = cableLayoutById.Values.Min(cl => cl.MinOffset); LeftMargin = ((minCablesOffset > 0) ? 0 : -minCablesOffset) + additionalAssignmentMargin; double maxCablesOffset = cableLayoutById.Values.Max(cl => cl.MaxOffset); RightMargin = ((width > maxCablesOffset) ? width : maxCablesOffset) + additionalAssignmentMargin; }
private List <int> PlaceAssignmentFrame(Point placePosition, Sheet sheet, Graphic graphic, E3Text text) { if (String.IsNullOrEmpty(assignment) || assignment.Equals("AssignmentForConnectingBox")) { return(new List <int>(0)); } int sheetId = sheet.Id; List <int> ids = new List <int>(2); ids.Add(graphic.CreateRectangle(sheetId, sheet.MoveLeft(placePosition.X, LeftMargin), sheet.MoveDown(placePosition.Y, BottomMargin), sheet.MoveRight(placePosition.X, RightMargin), sheet.MoveUp(placePosition.Y, TopMargin))); graphic.SetLineStyle(4); E3Font assignmentFont = new E3Font(height: 3); double assignmentTextX; if (assignmentWidth > width) { assignmentFont.alignment = Alignment.Centered; assignmentTextX = sheet.MoveRight(placePosition.X, width / 2); } else { assignmentFont.alignment = Alignment.Right; assignmentTextX = sheet.MoveRight(placePosition.X, width); } double assignmentTextY = sheet.MoveUp(placePosition.Y, TopMargin - (gridStep + assignmentFont.height / 2)); ids.Add(text.CreateText(sheetId, "Шкаф " + assignment, assignmentTextX, assignmentTextY, assignmentFont)); return(ids); }