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++;
         }
     }
 }
 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 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 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();
 }
        public Scheme(Dictionary<int, DeviceGroup> groupById, Dictionary<int, List<int>> groupIdsByCableId, Dictionary<int, CableInfo> cableInfoById, E3Text text)
        {
            /*this.groupById = groupById;
            this.groupIdsByCableId = groupIdsByCableId;
            gridStep = 4;
            height = 272 * 0.618;
            this.cableInfoById = cableInfoById;
            double minIntersectionCount = Int32.MaxValue;
            List<int> bottomGroupIds = new List<int>();
            List<int> topGroupIds = new List<int>();
            foreach (DeviceGroup group in groupById.Values)
                if (group.Level == Level.Top)
                    topGroupIds.Add(group.Id);
                else
                    bottomGroupIds.Add(group.Id);
            List<Tuple<int, int>> topToTopConnections, bottomToBottomConnections, topToBottomConnections;   // список соединений между групами, если группы на разных уровнях - первый член верхняя группа, второй - нижняя
            GetConnections(groupById, groupIdsByCableId, out topToTopConnections, out bottomToBottomConnections, out topToBottomConnections);
            Dictionary<int, Dictionary<int, int>> connectedBottomPositionByIdByTopId = GetConnectedPositionByIdByCenterId(Level.Top, topToBottomConnections);
            Dictionary<int, Dictionary<int, int>> connectedTopPositionByIdByBottomId = GetConnectedPositionByIdByCenterId(Level.Bottom, topToBottomConnections);

            foreach (List<int> bottomPermutation in Permutate(bottomGroupIds, bottomGroupIds.Count))
            {
                Dictionary<int, int> bottomPositionById = new Dictionary<int, int>(bottomPermutation.Count);
                for (int i = 0; i < bottomPermutation.Count; i++)
                    bottomPositionById.Add(bottomPermutation[i], i);
                int bottomIntersectionCount = GetLevelIntersectionCount(bottomPositionById, bottomToBottomConnections);
                foreach (List<int> topPermutation in Permutate(topGroupIds, topGroupIds.Count))
                {
                    Dictionary<int, int> topPositionById = new Dictionary<int, int>(topPermutation.Count);
                    for (int i = 0; i < topPermutation.Count; i++)
                        topPositionById.Add(topPermutation[i], i);
                    int intersectionCount = bottomIntersectionCount;
                    intersectionCount += GetLevelIntersectionCount(topPositionById, topToTopConnections);
                    intersectionCount += GetInterLevelIntersectionCount(topToBottomConnections, topPositionById, bottomPositionById, connectedBottomPositionByIdByTopId, connectedTopPositionByIdByBottomId);
                    if (intersectionCount < minIntersectionCount)
                    {
                        minIntersectionCount = intersectionCount;
                        optimalTopPositionById = topPositionById;
                        optimalBottomPositionById = bottomPositionById;
                    }
                }
            }
            cableSymbolById = GetCableSymbolById(topToBottomConnections, text);
            CalculateLayout(text);*/
        }
Example #6
0
 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 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);
        }
 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;
 }
 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 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(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 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 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 void PlaceSymbols(Sheet sheet, Graphic graphic, Group e3group, E3Text text, Dictionary<int, double> horizontalOffsetById, double startAbsciss, double groupOrdinate)
 {
     double offset = 0;
     foreach (int id in horizontalOffsetById.Keys)
     {
         ISchemeSymbol symbol = symbolById[id];
         offset += horizontalOffsetById[id];
         double absciss = sheet.MoveRight(startAbsciss, offset);
         symbol.Place(new Point(absciss, groupOrdinate), sheet, graphic, e3group, text);
     }
 }
 public void Place(Sheet sheet, Graphic graphic, Group e3group, E3Text text, Point placePositon)
 {
     //layout.Place(sheet, graphic, e3group, text, placePositon);
 }
 private Dictionary<int, CableSymbol> GetCableSymbolById(List<Tuple<int, int>> topToBottomConnections, E3Text text)
 {
     Dictionary<int, CableSymbol> cableSymbolById = new Dictionary<int, CableSymbol>(symbolIdsByCableId.Count);
     foreach (int cableId in symbolIdsByCableId.Keys)
     {
         Orientation orientation = GetCableOrientation(symbolIdsByCableId[cableId], topToBottomConnections);
         cableSymbolById.Add(cableId,new CableSymbol(cableInfoById[cableId], text, orientation));
     }
     return cableSymbolById;
 }
 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);
 }
Example #18
0
 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 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;
 }
 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;
 }
 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 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 void PlaceCableSymbols(Sheet sheet, Graphic graphic, Group e3group, E3Text text, double startAbsciss, double topGroupOrdinate, double bottomGroupOrdinate)
 {
     foreach (int cableId in cableSymbolById.Keys)
     {
         CableSymbol cableSymbol = cableSymbolById[cableId];
         if (cableSymbol.Orientation == Orientation.Horizontal)
         {
             List<int> groupIds = symbolIdsByCableId[cableId];
             groupIds.Sort((id1,id2) => GetGroupPosition(id1).CompareTo(GetGroupPosition(id2)));
             ISchemeSymbol firstSymbol = symbolById[groupIds.First()];
             ISchemeSymbol secondSymbol = symbolById[groupIds.Last()];
             double firstPointX = sheet.MoveRight(firstSymbol.PlacedPosition.X, firstSymbol.RightMargin);
             double y = (firstSymbol.Level == Level.Bottom) ? sheet.MoveDown(bottomGroupOrdinate, bottomGroupBottomMargin) : sheet.MoveDown (topGroupOrdinate, topGroupBottomMargin);
             Point firstPoint = new Point (firstPointX, y);
             double secondPointX = sheet.MoveLeft(secondSymbol.PlacedPosition.X, secondSymbol.LeftMargin);
             Point secondPoint = new Point(secondPointX, y);
             double x = (firstPoint.X + secondPoint.X) / 2;
             double cableSymbolHalfHeight = cableSymbol.Size.Height / 2;
             y = sheet.MoveDown(y, cableSymbolHalfHeight + gridStep);
             cableSymbol.Place(sheet, graphic, text, e3group, new Point(x, y));
          }
     }
     if (topGroupHorizontalOffsetById.Count > 0)
     {
         double top = symbolById[topGroupHorizontalOffsetById.Keys.First()].PlacedPosition.Y;
         ISchemeSymbol bottomSymbol = symbolById[bottomGroupHorizontalOffsetById.Keys.First()];
         double bottom = sheet.MoveUp(bottomSymbol.PlacedPosition.Y, bottomSymbol.TopMargin);
         double center = (top + bottom) / 2;
         foreach (VerticalConnection verticalConnection in verticalConnections)
             foreach (CableSymbol cableSymbol in verticalConnection.VerticalCableSymbols)
             {
                 double y = sheet.MoveDown(center, (cableSymbol.Size.Height - cableSymbol.Diameter) / 2);
                 cableSymbol.Place(sheet, graphic, text, e3group, new Point(sheet.MoveRight(startAbsciss, verticalConnection.OffsetByCableId[cableSymbol.CableId]), y));
             }
     }
 }
Example #24
0
 public StringSeparator(char[] separators, E3Font font, E3Text text)
 {
     this.separators = separators;
     this.font = font;
     determineStringLength = new Func<string, E3Font, double>(text.GetTextLength);
 }
 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;
 }
Example #26
0
 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 CalculateLayout(E3Text text)
 {
     List<int> topGroupIds = new List<int>(optimalTopPositionById.Keys);
     topGroupIds.Sort((g1, g2) => optimalTopPositionById[g1].CompareTo(optimalTopPositionById[g2]));
     List<int> bottomGroupIds = new List<int>(optimalBottomPositionById.Keys);
     bottomGroupIds.Sort((g1, g2) => optimalBottomPositionById[g1].CompareTo(optimalBottomPositionById[g2]));
     List<ISchemeSymbol> topSymbols = new List<ISchemeSymbol>(topGroupIds.Count);
     topGroupIds.ForEach(id=>topSymbols.Add(symbolById[id]));
     List<ISchemeSymbol> bottomSymbols = new List<ISchemeSymbol>(bottomGroupIds.Count);
     bottomGroupIds.ForEach(id=>bottomSymbols.Add(symbolById[id]));
     double maxBottomGroupHeight = bottomSymbols.Max(g => g.OutlineHeight);
     bottomSymbols.ForEach(g => { if (g is DeviceGroup) { DeviceGroup dg = g as DeviceGroup; dg.CalculateLayout(this, maxBottomGroupHeight, cableSymbolById, cableInfoById, text); } });
     List<CableSymbol> bottomHorizontalCableSymbols = GetGroupCableSymbols(bottomSymbols).FindAll(cs => cs.Orientation == Orientation.Horizontal);
     double maxBottomCableHeight = (bottomHorizontalCableSymbols.Count > 0) ? (bottomHorizontalCableSymbols.Max(cs => cs.Size.Height) + gridStep) : 0;
     bottomGroupBottomMargin = bottomSymbols.Max(g => g.BottomMargin);
     bottomGroupsOffset = maxBottomCableHeight + bottomGroupBottomMargin;
     double bottomHeight = bottomSymbols.Max(g => g.Height) + maxBottomCableHeight;
     if (topGroupIds.Count > 0)
     {
         double maxTopGroupHeight = topSymbols.Max(g => g.OutlineHeight);
         topSymbols.ForEach(g=>{ if (g is DeviceGroup) { DeviceGroup dg = g as DeviceGroup; dg.CalculateLayout(this, maxTopGroupHeight, cableSymbolById, cableInfoById, text);}});
         topGroupBottomMargin = topSymbols.Max(g => g.BottomMargin);
         topGroupsOffset = height - maxTopGroupHeight;
         AdjustVerticalConnections(topSymbols, bottomSymbols);
         double topWidth = topGroupHorizontalOffsetById.Values.Sum() + topSymbols.Last().RightMargin;
         double bottomWidth = bottomGroupHorizontalOffsetById.Values.Sum() + bottomSymbols.Last().RightMargin;
         double totalWidth = Math.Max(topWidth, bottomWidth);
         double totalHeight = height;
         Size = new Size(totalWidth, totalHeight);
     }
     else
     {
         topGroupHorizontalOffsetById = new Dictionary<int, double>(0);
         bottomGroupHorizontalOffsetById = GetMinHorizontalOffsetsBetweenGroups(bottomSymbols);
         double bottomWidth = bottomGroupHorizontalOffsetById.Values.Sum() + bottomSymbols.Last().RightMargin;
         Size = new Size(bottomWidth, bottomHeight);
     }
 }
Example #28
0
 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);
         }
     }
 }
 public void Place(Sheet sheet, Graphic graphic, Group e3group, E3Text text, Point placePosition)
 {
     double startAbsciss = sheet.MoveLeft(placePosition.X, Size.Width / 2);
     double startOrdinate = sheet.MoveDown(placePosition.Y, Size.Height / 2);
     double bottomGroupOrdinate = sheet.MoveUp(startOrdinate, bottomGroupsOffset);
     double topGroupOrdinate = sheet.MoveUp(startOrdinate, topGroupsOffset);
     PlaceSymbols(sheet, graphic, e3group, text, topGroupHorizontalOffsetById, startAbsciss, topGroupOrdinate);
     PlaceSymbols(sheet, graphic, e3group, text, bottomGroupHorizontalOffsetById, startAbsciss, bottomGroupOrdinate);
     PlaceCableSymbols(sheet, graphic, e3group, text, startAbsciss, topGroupOrdinate, bottomGroupOrdinate);
     PlaceConnectionLines(sheet, graphic, topGroupOrdinate, bottomGroupOrdinate);
 }