public IHttpActionResult GetLineSegmentForLine(int lineID) { if (GetRoles == string.Empty || User.IsInRole(GetRoles)) { using (AdoDataConnection connection = new AdoDataConnection(Connection)) { LineDetails result = new LineDetails(); List <LineSegment> record = new TableOperations <LineSegment>(connection).QueryRecordsWhere("ID in (select ChildID from AssetRelationship where AssetRelationshipTypeID = (SELECT ID FROM AssetRelationshipType WHERE Name = 'Line-LineSegment') AND ParentID = {0})", lineID).ToList(); record = record.Concat(new TableOperations <LineSegment>(connection).QueryRecordsWhere("ID in (select ParentID from AssetRelationship where AssetRelationshipTypeID = (SELECT ID FROM AssetRelationshipType WHERE Name = 'Line-LineSegment') AND ChildID = {0})", lineID)).ToList(); result.Length = record.Select(item => item.Length).Sum(); result.X0 = record.Select(item => item.X0).Sum(); result.R0 = record.Select(item => item.R0).Sum(); result.X1 = record.Select(item => item.X1).Sum(); result.R1 = record.Select(item => item.R1).Sum(); result.ThermalRating = record.Select(item => item.ThermalRating).Count() > 0 ? record.Select(item => item.ThermalRating).Min() : 0; return(Ok(result)); } } else { return(Unauthorized()); } }
private int FindStartingYPosition(ViewLayoutContext context, LineDetails lineDetails, bool reversePosition) { RelativePositionAlign align = ItemAlignment; // Do we need to apply right to left by aligning in opposite direction? if (IsOneLine && !BarVertical && (context.Control.RightToLeft == RightToLeft.Yes)) { if (align == RelativePositionAlign.Near) { align = RelativePositionAlign.Far; } else if (align == RelativePositionAlign.Far) { align = RelativePositionAlign.Near; } } switch (align) { case RelativePositionAlign.Near: if (reversePosition) { return(ClientRectangle.Bottom); } else { return(ClientLocation.Y); } case RelativePositionAlign.Center: if (reversePosition) { return(ClientRectangle.Bottom - (ClientRectangle.Height - lineDetails.InlineLength) / 2); } else { return(ClientLocation.Y + (ClientRectangle.Height - lineDetails.InlineLength) / 2); } case RelativePositionAlign.Far: if (reversePosition) { return(ClientRectangle.Bottom - (ClientRectangle.Height - lineDetails.InlineLength)); } else { return(ClientLocation.Y + (ClientRectangle.Height - lineDetails.InlineLength)); } default: // Should never happen! Debug.Assert(false); return(ClientLocation.Y); } }
/// <summary> /// Updates the state of the trimmer, indicating that the given text was encountered before an inline tag. /// </summary> /// <param name="value">The text at the end of the format string.</param> /// <param name="generator">The generator created for the inline tag.</param> /// <returns>A static generator containing the passed text.</returns> public IEnumerable<StaticGenerator> RecordText(string value, bool isTag, bool isOutput) { int newLineIndex = value.IndexOf(Environment.NewLine); if (newLineIndex == -1) { StaticGenerator generator = new StaticGenerator() { Value = value }; _currentLine.Value.Generators.Add(generator); _currentLine.Value.HasTag |= isTag; _currentLine.Value.HasOutput |= !String.IsNullOrWhiteSpace(value); yield return generator; } else { string[] lines = value.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); // get the trailing generator string trailing = lines[0]; StaticGenerator trailingGenerator = new StaticGenerator() { Value = trailing }; _currentLine.Value.Generators.Add(trailingGenerator); _currentLine.Value.HasOutput |= !String.IsNullOrWhiteSpace(trailing); yield return trailingGenerator; // get the middle generators for (int lineIndex = 1; lineIndex < lines.Length - 1; ++lineIndex) { string middle = lines[lineIndex]; StaticGenerator middleGenerator = new StaticGenerator() { Value = middle }; LineDetails middleDetails = new LineDetails() { HasTag = false }; _currentLine = _lines.AddLast(middleDetails); _currentLine.Value.Generators.Add(middleGenerator); _currentLine.Value.HasOutput = true; yield return middleGenerator; } // get the leading generator string leading = lines[lines.Length - 1]; StaticGenerator leadingGenerator = new StaticGenerator() { Value = leading }; LineDetails details = new LineDetails() { HasTag = isTag }; _currentLine = _lines.AddLast(details); _currentLine.Value.Generators.Add(leadingGenerator); _currentLine.Value.HasOutput = !String.IsNullOrWhiteSpace(leading); yield return leadingGenerator; } if (isOutput) { _currentLine.Value.HasOutput = true; } }
/// <summary> /// Discover the preferred size of the element. /// </summary> /// <param name="context">Layout context.</param> public override Size GetPreferredSize(ViewLayoutContext context) { Debug.Assert(context != null); // Reset the largest child size to empty _maximumItem = Size.Empty; // Keep track of the total preferred size Size preferredSize = Size.Empty; // Nothing to calculate if there are no children if (Count > 0) { // Default to no space between each child item // If we have a metric provider then get the child gap to use int gap = _paletteMetric?.GetMetricInt(State, _metricGap) ?? context.Renderer.RenderTabBorder.GetTabBorderSpacingGap(TabBorderStyle); // Line spacing gap can never be less than zero int lineGap = (gap < 0 ? 0 : gap); // Do we need to apply right to left by positioning children in reverse order? bool reversed = (IsOneLine && !BarVertical && (context.Control.RightToLeft == RightToLeft.Yes)); // Allocate caching for size of each child element _childSizes = new Size[Count]; // Find the child index of the selected page int selectedChildIndex = -1; // Find the size of each child in turn for (int i = 0; i < Count; i++) { // Get access to the indexed child ViewBase child = this[reversed ? (Count - i - 1) : i]; INavCheckItem checkItem = (INavCheckItem)child; // Only examine visible children if (child.Visible) { // Cache child index of the selected page if (checkItem.Navigator.SelectedPage == checkItem.Page) { selectedChildIndex = i; } // Ask child for it's own preferred size _childSizes[i] = child.GetPreferredSize(context); // Enfore the minimum and maximum sizes if (ItemVertical) { _childSizes[i].Width = Math.Max(Math.Min(_childSizes[i].Width, ItemMaximumSize.Height), ItemMinimumSize.Height); _childSizes[i].Height = Math.Max(Math.Min(_childSizes[i].Height, ItemMaximumSize.Width), ItemMinimumSize.Width); } else { _childSizes[i].Width = Math.Max(Math.Min(_childSizes[i].Width, ItemMaximumSize.Width), ItemMinimumSize.Width); _childSizes[i].Height = Math.Max(Math.Min(_childSizes[i].Height, ItemMaximumSize.Height), ItemMinimumSize.Height); } // Remember the largest child encountered _maximumItem.Width = Math.Max(_childSizes[i].Width, _maximumItem.Width); _maximumItem.Height = Math.Max(_childSizes[i].Height, _maximumItem.Height); } } // Apply the item sizing method switch (BarItemSizing) { case BarItemSizing.Individual: // Do nothing, each item can be its own size break; case BarItemSizing.SameHeight: if (!BarVertical) { for (int i = 0; i < _childSizes.Length; i++) { if (!_childSizes[i].IsEmpty) { _childSizes[i].Height = _maximumItem.Height; } } } else { for (int i = 0; i < _childSizes.Length; i++) { if (!_childSizes[i].IsEmpty) { _childSizes[i].Width = _maximumItem.Width; } } } break; case BarItemSizing.SameWidth: if (!BarVertical) { for (int i = 0; i < _childSizes.Length; i++) { if (!_childSizes[i].IsEmpty) { _childSizes[i].Width = _maximumItem.Width; } } } else { for (int i = 0; i < _childSizes.Length; i++) { if (!_childSizes[i].IsEmpty) { _childSizes[i].Height = _maximumItem.Height; } } } break; case BarItemSizing.SameWidthAndHeight: for (int i = 0; i < _childSizes.Length; i++) { if (!_childSizes[i].IsEmpty) { _childSizes[i] = _maximumItem; } } break; default: // Should never happen! Debug.Assert(false); break; } // Store a list of the individual line vectors (height or width depending on orientation) _lineDetails = new List <LineDetails>(); int itemCount = 0; int startIndex = 0; int visibleItems = 0; if (BarVertical) { int yPos = 0; int yMaxPos = 0; int lineWidth = 0; _preferredOrientLength = 0; for (int i = 0; i < _childSizes.Length; i++) { // Ignore invisible items, which are zero sized if (!_childSizes[i].IsEmpty) { // If not the first visible item on line, then need a spacing gap int yAdd = (visibleItems > 0) ? gap : 0; // Add on the heght of the child yAdd += _childSizes[i].Height; // Does this item extend beyond visible line? // (unless first item, we always have at least one item on a line) if (!IsOneLine && (yPos > 0) && ((yPos + yAdd) > context.DisplayRectangle.Height)) { // Remember the line metrics _lineDetails.Add(new LineDetails(yPos, lineWidth, startIndex, itemCount)); // Track the widest line encountered yMaxPos = Math.Max(yPos, yMaxPos); // Reset back to start of the next line yPos = 0; itemCount = 0; startIndex = i; _preferredOrientLength += (lineGap + lineWidth); lineWidth = 0; // First item on new line does not need a spacing gap yAdd = _childSizes[i].Height; } // Add on to the current line yPos += yAdd; visibleItems++; // Track the tallest item on this line if (lineWidth < _childSizes[i].Width) { lineWidth = _childSizes[i].Width; } } // Visible and Invisible items are added to the item count itemCount++; } // Add the last line to the height _preferredOrientLength += lineWidth; // Check if the last line is the tallest line yMaxPos = Math.Max(yPos, yMaxPos); // If we extended past end of the line if (yMaxPos > context.DisplayRectangle.Height) { // If the mode requires we do not extend over the line if ((BarMultiline == BarMultiline.Shrinkline) || (BarMultiline == BarMultiline.Exactline)) { bool changed; // Keep looping to reduce item sizes until all are zero sized or finished removing extra space do { changed = false; // Are there any items avaiable for reducing? if (visibleItems > 0) { // How much do we need to shrink each item by? int shrink = Math.Max(1, (yMaxPos - context.DisplayRectangle.Height) / visibleItems); // Reduce size of each item for (int i = 0; i < _childSizes.Length; i++) { // Cannot make smaller then zero height if (_childSizes[i].Height > 0) { // Reduce size int tempHeight = _childSizes[i].Height; _childSizes[i].Height -= shrink; // Prevent going smaller then zero if (_childSizes[i].Height <= 0) { _childSizes[i].Height = 0; visibleItems--; } // Reduce total width by the height removed from item yMaxPos -= (tempHeight - _childSizes[i].Height); // All reduction made, exit the loop if (yMaxPos <= context.DisplayRectangle.Height) { break; } changed = true; } } } } while (changed && (yMaxPos > context.DisplayRectangle.Height)); } } // If we are shorter than the available height if (yMaxPos < context.DisplayRectangle.Height) { // If the mode requires we extend to the end of the line if ((BarMultiline == BarMultiline.Expandline) || (BarMultiline == BarMultiline.Exactline)) { bool changed; // Keep looping to expand item sizes until all extra space is allocated do { changed = false; // Are there any items avaiable for expanding? if (visibleItems > 0) { // How much do we need to expand each item by? int expand = Math.Max(1, (context.DisplayRectangle.Height - yMaxPos) / visibleItems); // Expand size of each item for (int i = 0; i < _childSizes.Length; i++) { // Expand size _childSizes[i].Height += expand; // Reduce free space by that allocated yMaxPos += expand; changed = true; // All expansion made, exit the loop if (yMaxPos >= context.DisplayRectangle.Height) { break; } } } } while (changed && (yMaxPos < context.DisplayRectangle.Height)); } } // Remember the line metrics _lineDetails.Add(new LineDetails(yMaxPos, lineWidth, startIndex, itemCount)); // Our preferred size is tall enough to show the longest line and total width preferredSize.Width = _preferredOrientLength; preferredSize.Height = yMaxPos; } else { int xPos = 0; int xMaxPos = 0; int lineHeight = 0; _preferredOrientLength = 0; for (int i = 0; i < _childSizes.Length; i++) { // Ignore invisible items, which are zero sized if (!_childSizes[i].IsEmpty) { // If not the first item on line, then need a spacing gap int xAdd = (visibleItems > 0) ? gap : 0; // Add on the width of the child xAdd += _childSizes[i].Width; // Does this item extend beyond visible line? // (unless first item, we always have at least one item on a line) if (!IsOneLine && (xPos > 0) && ((xPos + xAdd) > context.DisplayRectangle.Width)) { // Remember the line metrics _lineDetails.Add(new LineDetails(xPos, lineHeight, startIndex, itemCount)); // Track the widest line encountered xMaxPos = Math.Max(xPos, xMaxPos); // Reset back to start of the next line xPos = 0; itemCount = 0; startIndex = i; _preferredOrientLength += (lineGap + lineHeight); lineHeight = 0; // First item on new line does not need a spacing gap xAdd = _childSizes[i].Width; } // Add on to the current line xPos += xAdd; visibleItems++; // Track the tallest item on this line if (lineHeight < _childSizes[i].Height) { lineHeight = _childSizes[i].Height; } } // Visible and Invisible items are added to the item count itemCount++; } // Add the last line to the height _preferredOrientLength += lineHeight; // Check if the last line is the widest line xMaxPos = Math.Max(xPos, xMaxPos); // If we extended past end of the line if (xMaxPos > context.DisplayRectangle.Width) { // If the mode requires we do not extend over the line if ((BarMultiline == BarMultiline.Shrinkline) || (BarMultiline == BarMultiline.Exactline)) { bool changed; // Keep looping to reduce item sizes until all are zero sized or finished removing extra space do { changed = false; // Are there any items avaiable for reducing? if (visibleItems > 0) { // How much do we need to shrink each item by? int shrink = Math.Max(1, (xMaxPos - context.DisplayRectangle.Width) / visibleItems); // Reduce size of each item for (int i = 0; i < _childSizes.Length; i++) { // Cannot make smaller then zero width if (_childSizes[i].Width > 0) { // Reduce size int tempWidth = _childSizes[i].Width; _childSizes[i].Width -= shrink; // Prevent going smaller then zero if (_childSizes[i].Width <= 0) { _childSizes[i].Width = 0; visibleItems--; } // Reduce total width by the width removed from item xMaxPos -= (tempWidth - _childSizes[i].Width); // All reduction made, exit the loop if (xMaxPos <= context.DisplayRectangle.Width) { break; } changed = true; } } } } while (changed && (xMaxPos > context.DisplayRectangle.Width)); } } // If we are shorter than the line width if (xMaxPos < context.DisplayRectangle.Width) { // If the mode requires we extend to the end of the line if ((BarMultiline == BarMultiline.Expandline) || (BarMultiline == BarMultiline.Exactline)) { bool changed; // Keep looping to expand item sizes until all the extra space is removed do { changed = false; // Are there any items avaiable for reducing? if (visibleItems > 0) { // How much do we need to expand each item by? int expand = Math.Max(1, (context.DisplayRectangle.Width - xMaxPos) / visibleItems); // Expand size of each item for (int i = 0; i < _childSizes.Length; i++) { // Expand size _childSizes[i].Width += expand; // Increase total width taken up by items xMaxPos += expand; changed = true; // All expansion made, exit the loop if (xMaxPos >= context.DisplayRectangle.Width) { break; } } } } while (changed && (xMaxPos < context.DisplayRectangle.Width)); } } // Remember the line metrics _lineDetails.Add(new LineDetails(xMaxPos, lineHeight, startIndex, itemCount)); // Our preferred size is tall enough to show the widest line and total height preferredSize.Width = xMaxPos; preferredSize.Height = _preferredOrientLength; } // Reverse the order of the lines when at top or left edge, as the // items should be positioned from the inside edge moving outwards if ((Orientation == VisualOrientation.Top) || (Orientation == VisualOrientation.Left)) { _lineDetails.Reverse(); } // If we are using tabs then we need to move the line with the selection if (ReorderSelectedLine) { // Did we find a selected child index? if (selectedChildIndex >= 0) { // Find the line details that contains this child index for (int i = 0; i < _lineDetails.Count; i++) { // Is the selected item in the range of items for this line? if ((selectedChildIndex >= _lineDetails[i].StartIndex) && (selectedChildIndex < (_lineDetails[i].StartIndex + _lineDetails[i].ItemCount))) { // Remove the line details LineDetails ld = _lineDetails[i]; _lineDetails.RemoveAt(i); if ((Orientation == VisualOrientation.Top) || (Orientation == VisualOrientation.Left)) { // Move to end of the list _lineDetails.Add(ld); } else { // Move to start of the list _lineDetails.Insert(0, ld); } } } } } } // Enfore the minimum height of the bar if (BarVertical) { preferredSize.Width = Math.Max(preferredSize.Width, BarMinimumHeight); } else { preferredSize.Height = Math.Max(preferredSize.Height, BarMinimumHeight); } return(preferredSize); }
public virtual BaseCommandReference ExtractBaseCommandId(LineDetails lineDetails) { return(new BaseCommandReference { BaseCommandId = 5 }); }
private int FindStartingXPosition(ViewLayoutContext context, LineDetails lineDetails, bool reversePosition) { RelativePositionAlign align = ItemAlignment; // Do we need to apply right to left by aligning in opposite direction? if (IsOneLine && !BarVertical && (context.Control.RightToLeft == RightToLeft.Yes)) { if (align == RelativePositionAlign.Near) align = RelativePositionAlign.Far; else if (align == RelativePositionAlign.Far) align = RelativePositionAlign.Near; } switch (align) { case RelativePositionAlign.Near: if (reversePosition) return ClientRectangle.Right; else return ClientLocation.X; case RelativePositionAlign.Center: if (reversePosition) return ClientRectangle.Right - (ClientRectangle.Width - lineDetails.InlineLength) / 2; else return ClientLocation.X + (ClientRectangle.Width - lineDetails.InlineLength) / 2; case RelativePositionAlign.Far: if (reversePosition) return ClientRectangle.Right - (ClientRectangle.Width - lineDetails.InlineLength); else return ClientLocation.X + (ClientRectangle.Width - lineDetails.InlineLength); default: // Should never happen! Debug.Assert(false); return ClientLocation.X; } }