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); }
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 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 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 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 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); } }