Пример #1
0
 /// <summary>
 /// Adds LayoutSystemInfo to this LayoutPageContent
 /// </summary>
 /// <param name="systemInfo">LayoutSystem instance which represents visual collection of measures arranged into System</param>
 /// <returns>False if LayoutSystem can't fit on page and should be added to new page</returns>
 public bool AddSystemDimensionInfo(LayoutSystemInfo systemInfo)
 {
     systemInfo.ArrangeSystem(SystemStretchedToWidth(), PageContentWidth); //! stretch test
     if (_systemDimensionsInfo == null)
     {
         _systemDimensionsInfo = new List <LayoutSystemInfo>();
     }
     if (_availableHeight < systemInfo.SystemHeight)
     {
         return(false);
     }
     //!todo more tests
     _systemDimensionsInfo.Add(systemInfo);
     _lastSystemIndex = _systemDimensionsInfo.Count - 1;
     CalculateAvailableHeight();
     return(true);
 }
        /// <summary>
        /// Collect measures into systems
        /// </summary>
        /// <param name="unarrangedMeasures"></param>
        public void SystemsCollector(List <string> unarrangedMeasures)
        {
            //! collection of layout information about pages generated from score
            _layoutPageInfo = new Dictionary <int, LayoutPageContentInfo>();
            int pageIndex = 0;
            LayoutPageContentInfo pageContent = new LayoutPageContentInfo(pageIndex);
            double currentWidth = 0.0;
            //double currentHeight = 0.0; //! TODO horizontal layout spacing calculations

            List <SharedMeasureProperties> measuresToSystem = new List <SharedMeasureProperties>();

            for (int i = 0; i < unarrangedMeasures.Count; i++)
            {
                string measureId = unarrangedMeasures[i];
                SharedMeasureProperties currentMeasureProperties = _sharedMeasuresProps.FirstOrDefault(x => x.MeasureId == measureId);
                currentWidth += currentMeasureProperties.SharedWidth;
                //! if calculated width would be to high, collected measures represents one system
                if (currentWidth > pageContent.PageContentWidth)
                {
                    List <SharedMeasureProperties> sharedMeasuresCollection = new List <SharedMeasureProperties>(measuresToSystem);
                    LayoutSystemInfo layoutSystem = new LayoutSystemInfo(sharedMeasuresCollection);

                    bool systemFitsOnPage = pageContent.AddSystemDimensionInfo(layoutSystem);
                    //! if this system won't fit inside page (too low heigh space available - add to new page and continue
                    if (!systemFitsOnPage)
                    {
                        pageContent.ArrangeSystems();
                        _layoutPageInfo.Add(pageIndex, pageContent);
                        pageIndex++;
                        pageContent = new LayoutPageContentInfo(pageIndex);
                        pageContent.AddSystemDimensionInfo(layoutSystem);
                    }
                    measuresToSystem.Clear();
                    currentWidth = 0.0;
                }
                else
                {
                    //! add measure to collection
                    if (currentMeasureProperties != null)
                    {
                        measuresToSystem.Add(currentMeasureProperties);
                    }
                    else
                    {
                        Log.LoggIt.Log($"Measure Id: {measureId} not found in SharedMeasureProperties");
                    }
                }
                //! if any measure left unarranged
                if (i == unarrangedMeasures.Count - 1 && measuresToSystem.Count != 0)
                {
                    List <SharedMeasureProperties> sharedMeasuresCollection = new List <SharedMeasureProperties>(measuresToSystem);
                    LayoutSystemInfo layoutSystem = new LayoutSystemInfo(sharedMeasuresCollection);

                    bool systemFitsOnPage = pageContent.AddSystemDimensionInfo(layoutSystem);
                    if (!systemFitsOnPage)
                    {
                        pageContent.ArrangeSystems();
                        _layoutPageInfo.Add(pageIndex, pageContent);
                        pageIndex++;
                        pageContent = new LayoutPageContentInfo(pageIndex);
                        pageContent.AddSystemDimensionInfo(layoutSystem);
                        pageContent.ArrangeSystems();
                        _layoutPageInfo.Add(pageIndex, pageContent);
                    }
                    else
                    {
                        pageContent.ArrangeSystems();
                        _layoutPageInfo.Add(pageIndex, pageContent);
                    }
                }
                //! if it is last measure and page not added to layoutPageInfo
                if (i == unarrangedMeasures.Count - 1 && _layoutPageInfo.Count != pageIndex + 1)
                {
                    pageContent.ArrangeSystems();
                    _layoutPageInfo.Add(pageIndex, pageContent);
                }
            }
        }