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(); }
private static List<ConnectionInfo> GetConnectionInfosByCoresAndWires(E3Project project) { List<ConnectionInfo> connectionInfos = new List<ConnectionInfo>(); CableDevice cable = project.GetCableDeviceById(0); Core core = project.GetCableCoreById(0); WireCore wire = project.GetWireCoreById(0); NormalDevice normalDevice = project.GetNormalDeviceById(0); DevicePin devicePin = project.GetDevicePinById(0); List<int> cableIds = project.CableIds; List<int> wireIds = project.WireIds; foreach (int cableId in cableIds) { cable.Id = cableId; foreach (int coreId in cable.CoreIds) { core.Id = coreId; connectionInfos.Add(new ConnectionInfo(core, normalDevice, devicePin, cable.Name, cable.ComponentName)); } } foreach (int wireId in wireIds) { wire.Id = wireId; connectionInfos.Add(new ConnectionInfo(wire, normalDevice, devicePin, wire.Name, wire.WireType)); } return connectionInfos; }
private static List<ConnectionInfo> GetConnectionInfosByConnections(E3Project project, Sheet sheet, int electricShemeTypeCode) { List<ConnectionInfo> connectionInfos = new List<ConnectionInfo>(); Core core = project.GetCableCoreById(0); WireCore wire = project.GetWireCoreById(0); NormalDevice normalDevice = project.GetNormalDeviceById(0); DevicePin devicePin = project.GetDevicePinById(0); Connection connection = project.GetConnectionById(0); HashSet<int> electricSchemeSheetIds = GetElectricSchemeSheetIds(project.SheetIds, sheet, electricShemeTypeCode); List<int> connectionIds = project.ConnectionIds; foreach (int connectionId in connectionIds) { connection.Id = connectionId; List<int> pinIds = new List<int>(connection.PinIds.Count); foreach (int pinId in connection.PinIds) { devicePin.Id = pinId; pinIds.Add(devicePin.Id); } pinIds = pinIds.Distinct<int>().ToList<int>(); pinIds.RemoveAll(id => { devicePin.Id = id; return !electricSchemeSheetIds.Contains(devicePin.SheetId); }); Dictionary<string, List<int>> pinsBySignals = new Dictionary<string, List<int>>(); foreach(int pinId in pinIds) { devicePin.Id = pinId; string signal = String.Intern(devicePin.SignalName); if (!pinsBySignals.ContainsKey(signal)) pinsBySignals.Add(signal, new List<int>()); pinsBySignals[signal].Add(pinId); } foreach (string signal in pinsBySignals.Keys) { pinIds = pinsBySignals[signal]; if (pinIds.Count > 1) for(int i=1; i<pinIds.Count; i++) connectionInfos.Add(new ConnectionInfo(pinIds[i - 1], pinIds[i], signal, normalDevice, devicePin, core, wire)); } } return connectionInfos; }
public Table(E3Project project, LineTemplate headerLineTemplate, List<string> headerLineTexts, LineTemplate lineTemplate, double bottomLineWidth, StringSeparator separator, TablePageTemplate firstPagetTemplate, TablePageTemplate subsequentPageTemplate = null ) { this.project = project; this.firstPageTemplate = firstPagetTemplate; if (subsequentPageTemplate == null) this.subsequentPageTemplate = firstPagetTemplate; else this.subsequentPageTemplate = subsequentPageTemplate; this.headerLineTemplate = headerLineTemplate; this.bottomLineWidth = bottomLineWidth; this.headerLineTexts = headerLineTexts; this.lineTemplate = lineTemplate; this.separator = separator; this.graphic = project.GetGraphicById(0); this.group = project.GetGroupById(0); this.text = project.GetTextById(0); currentSheet = project.GetSheetById(0); sheetCount = 0; sheetIds = new List<int>(); }
private static void GetDeviceConnectionByIdAndCableInfoById(E3Project project, HashSet<int> electricSchemeSheetIds, out Dictionary<int, DeviceConnection> deviceConnectionById, out Dictionary<int, CableInfo> cableInfoById) { CableDevice cable = project.GetCableDeviceById(0); CableCore core = project.GetCableCoreById(0); NormalDevice startDevice = project.GetNormalDeviceById(0); NormalDevice endDevice = project.GetNormalDeviceById(0); DevicePin startPin = project.GetDevicePinById(0); DevicePin endPin = project.GetDevicePinById(0); WireCore wire = project.GetWireCoreById(0); deviceConnectionById = new Dictionary<int, DeviceConnection>(); cableInfoById = new Dictionary<int, CableInfo>(); int connectionId = 0; foreach (int cableId in project.CableIds) { cable.Id = cableId; foreach (int coreId in cable.CoreIds) { core.Id = coreId; int startPinId = core.StartPinId; int endPinId = core.EndPinId; if (endPinId == 0 || startPinId == 0) // проверка на неподключенные концы continue; startPin.Id = startPinId; // id вывода if (!electricSchemeSheetIds.Contains(startPin.SheetId)) // проверка на то, что вывод расположен на принципиальной схеме continue; endPin.Id = endPinId; if (!electricSchemeSheetIds.Contains(endPin.SheetId)) continue; startDevice.Id = startPinId; endDevice.Id = endPinId; if (startDevice.Assignment.Equals(endDevice.Assignment) && !(startDevice.GetAttributeValue("IncludeInOWS").Equals("1") || endDevice.GetAttributeValue("IncludeInOWS").Equals("1"))) continue; string signal = startPin.SignalName; deviceConnectionById.Add(connectionId++, new DeviceConnection(startDevice.Id, startPin.Name, endDevice.Id, endPin.Name, cableId, signal)); string lengthAttribute = "Lenght_m_sp"; if (!cableInfoById.ContainsKey(cableId)) cableInfoById.Add(cableId, new CableInfo(cable, lengthAttribute)); cableInfoById[cableId].Signals.Add(signal); } } foreach (int wireId in project.WireIds) { wire.Id = wireId; int startPinId = wire.StartPinId; int endPinId = wire.EndPinId; if (endPinId == 0 || startPinId == 0) // проверка на неподключенные концы continue; startPin.Id = startPinId; // id вывода if (!electricSchemeSheetIds.Contains(startPin.SheetId)) // проверка на то, что вывод расположен на принципиальной схеме continue; endPin.Id = endPinId; if (!electricSchemeSheetIds.Contains(endPin.SheetId)) continue; startDevice.Id = startPinId; endDevice.Id = endPinId; if (startDevice.Assignment.Equals(endDevice.Assignment) && !(startDevice.GetAttributeValue("IncludeInOWS").Equals("1") || endDevice.GetAttributeValue("IncludeInOWS").Equals("1"))) continue; string signal = startPin.SignalName; deviceConnectionById.Add(connectionId++, new DeviceConnection(startDevice.Id, startPin.Name, endDevice.Id, endPin.Name, wireId, signal)); string lengthAttribute = "Lenght_m_sp"; if (!cableInfoById.ContainsKey(wireId)) cableInfoById.Add(wireId, new CableInfo(wire, lengthAttribute)); cableInfoById[wireId].Signals.Add(signal); } }
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 Dictionary<string, List<int>> GetOWSSheetIdsByAssignment(E3Project project, Sheet sheet, IEnumerable<string> assignments) { Dictionary<string, List<int>> sheetIdsByAssignment = new Dictionary<string, List<int>>(assignments.Count()); foreach (string assignment in assignments) sheetIdsByAssignment.Add(assignment, new List<int>()); foreach(int sheetId in project.SheetIds) { sheet.Id = sheetId; if (sheet.GetAttributeValue(subProjectAttribute).Equals("СВП")) { string assignment = sheet.GetAttributeValue(sheetMarkAttribute); if (sheetIdsByAssignment.ContainsKey(assignment)) sheetIdsByAssignment[assignment].Add(sheetId); } } return sheetIdsByAssignment; }
/*private List<int> GetPipeIds(E3Project project) { NormalDevice device = project.GetNormalDeviceById(0); List<int> pipeIds = new List<int>(); foreach (int id in project.DeviceIds) { device.Id = id; string function = device.GetComponentAttributeValue("Function"); if (ContainsIgnoreCase(function,"труб", StringComparison.OrdinalIgnoreCase) || ContainsIgnoreCase(function, "металлорукав", StringComparison.OrdinalIgnoreCase)) pipeIds.Add(id); } return pipeIds; }*/ private static HashSet<int> GetElectricSchemeSheetIds(E3Project project ,Sheet sheet, int electricShemeTypeCode) { HashSet<int> electricSchemeSheetIds = new HashSet<int>(); foreach (int sheetId in project.SheetIds) { sheet.Id = sheetId; if (sheet.IsSchematicTypeOf(electricShemeTypeCode)) electricSchemeSheetIds.Add(sheetId); } return electricSchemeSheetIds; }
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 void Start(ScriptType scriptType) { UI.Cursor = System.Windows.Input.Cursors.Wait; Settings settings = new Settings(); settings.electricSchemeTypeCode = 0; settings.firstPageFormat = "Формат А3 лист 1"; settings.firstPageHeaderLineX = 0; settings.firstPageHeaderLineY = -12; settings.firstPageUttermostPositionY = -225; settings.subsequentPageFormat = "Формат А3_каб.журнал"; settings.subsequentPageHeaderLineX = 0; settings.subsequentPageHeaderLineY = 287; settings.subsequentPageUttermostPositionY = 20; settings.lineFont = new E3Font(); settings.headerFont = new E3Font(height: 3.5); settings.separatingSymbols = "?!.:, -"; settings.verticalLineWidth = 0.5; settings.horizontalLineWidth = 0.2; settings.headerVerticalLineWidth = 0.5; settings.headerHorizontalLineWidth = 0.5; settings.bottomLineWidth = 0.5; settings.sheetTypeAttribute = "marka2"; SaveSettings(settings); E3Project project = new E3Project(applicationInfo.ProcessId); Sheet sheet = project.GetSheetById(0); List<ConnectionInfo> connectionInfos; if (scriptType == ScriptType.ByConnections) connectionInfos = GetConnectionInfosByConnections(project, sheet, settings.electricSchemeTypeCode); else connectionInfos = GetConnectionInfosByCoresAndWires(project); connectionInfos.RemoveAll(ci => ci.assignmentFrom != ci.assignmentTo || String.IsNullOrEmpty(ci.assignmentFrom)); // удаляем все соединения, не идущие внутри одного шкафа ConnectionInfoComparer comparer = new ConnectionInfoComparer(); connectionInfos.Sort(comparer); StringSeparator separator = new StringSeparator(settings.separatingSymbols.ToCharArray(), settings.lineFont, project.GetTextById(0)); LineTemplate lineTemplate = new LineTemplate(new List<double>() { 35, 45, 45, 45, 45, 45, 45, 45, 45 }, settings.lineFont, 8, settings.verticalLineWidth, settings.horizontalLineWidth); LineTemplate headerLineTemplate = new LineTemplate(new List<double>() { 35, 45, 45, 45, 45, 45, 45, 45, 45 }, settings.headerFont, 8, settings.headerVerticalLineWidth, settings.headerHorizontalLineWidth); List<string> headerColumnNames = new List<string>(9){"Имя цепи", "От \"Места\"", "От \"Поз. обозначения\"", "От \"Вывода\"", "К \"Месту\"", "К \"Поз. обозначению\"", "К \"Выводу\"", "Тип провода", "Примечание"}; Dictionary<string, Table> assignmentTables = new Dictionary<string, Table>(); foreach (ConnectionInfo info in connectionInfos) { if (!assignmentTables.ContainsKey(info.assignmentFrom)) { HeaderText headerText = new HeaderText("Таблица соединений шкафа "+info.assignmentFrom, settings.headerFont, settings.headerFont.height + 1); TablePageTemplate firstPageTemplate = new TablePageTemplate(settings.firstPageFormat, settings.firstPageHeaderLineX, settings.firstPageHeaderLineY, settings.firstPageUttermostPositionY, headerText); TablePageTemplate subsequentPageTemplate = new TablePageTemplate(settings.subsequentPageFormat, settings.subsequentPageHeaderLineX, settings.subsequentPageHeaderLineY, settings.subsequentPageUttermostPositionY); assignmentTables.Add(info.assignmentFrom, new Table(project, headerLineTemplate, headerColumnNames, lineTemplate, settings.bottomLineWidth, separator, firstPageTemplate, subsequentPageTemplate)); } assignmentTables[info.assignmentFrom].AddLine(new List<string>(8) { info.signal, info.locationFrom, info.deviceFrom, info.pinFrom, info.locationTo, info.deviceTo, info.pinTo, info.type }); } foreach (string key in assignmentTables.Keys) { assignmentTables[key].AddFinalGraphicLine(); foreach (int id in assignmentTables[key].SheetIds) { sheet.Id = id; sheet.SetAttribute(settings.sheetTypeAttribute, key); } } project.Release(); UI.Cursor = System.Windows.Input.Cursors.Arrow; }
public Table(E3Project project, LineTemplate headerLineTemplate, List<string> headerLineTexts, LineTemplate lineTemplate, double bottomLineWidth, StringSeparator separator, TablePageTemplate firstSheetTemplate) : this(project, headerLineTemplate,headerLineTexts, lineTemplate, bottomLineWidth, separator, firstSheetTemplate, null) { }