示例#1
0
        public VisualLayerPresentingVM(
            SingleClassificationLayerVM backgroundTarget,
            SingleClassificationLayerVM widthTarget,
            SingleClassificationLayerVM rightSideTarget,
            SingleClassificationLayerVM bottomSideTarget)
        {
            this.backgroundTarget = backgroundTarget;
            this.widthTarget      = widthTarget;
            this.rightSideTarget  = rightSideTarget;
            this.bottomSideTarget = bottomSideTarget;

            backgroundTarget.PropertyChanged += Target_PropertyChanged;

            if (widthTarget != null)
            {
                widthTarget.PropertyChanged += Target_PropertyChanged;
            }

            if (rightSideTarget != null)
            {
                rightSideTarget.PropertyChanged += Target_PropertyChanged;
            }

            if (bottomSideTarget != null)
            {
                bottomSideTarget.PropertyChanged += Target_PropertyChanged;
            }
        }
        private void ReclacYs()
        {
            SingleClassificationLayerVM[] layers = target.Layers.Select(l => (SingleClassificationLayerVM)l).ToArray();
            VisualLayerPresentingVM[]     vLayer = Layers.ToArray();
            int    length = layers.Length;
            double y      = 0;

            for (int i = 0; i < length; i++)
            {
                SingleClassificationLayerVM vm  = layers[i];
                VisualLayerPresentingVM     vvm = vLayer[i];
                vvm.Y = y;
                y    += vm.Length;
            }
        }
        private void Layers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
                for (int i = 0; i < e.NewItems.Count; i++)
                {
                    SingleClassificationLayerVM addedVM = (SingleClassificationLayerVM)e.NewItems[i];
                    addedVM.PropertyChanged += SingleClass_Vm_PropertyChanged;
                    VisualLayerPresentingVM craftedVM = adapter(addedVM);
                    craftedVM.AvailableWidth = columnWidth;
                    if (e.NewItems.Count == 0)
                    {
                        Layers.Add(craftedVM);
                    }
                    else
                    {
                        Layers.Insert(e.NewStartingIndex + i, craftedVM);
                    }
                }
                ReclacYs();
                break;

            case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
                if (e.OldItems.Count != 1)
                {
                    throw new InvalidOperationException();
                }
                SingleClassificationLayerVM removedVM = (SingleClassificationLayerVM)e.OldItems[0];
                removedVM.PropertyChanged -= SingleClass_Vm_PropertyChanged;
                Layers.RemoveAt(e.OldStartingIndex);
                ReclacYs();
                break;

            default:
                throw new NotImplementedException();
            }
        }
 public VisualLayerPresentingVM(SingleClassificationLayerVM target)
 {
     this.target             = target;
     target.PropertyChanged += Target_PropertyChanged;
 }
示例#5
0
        /// <summary>
        /// Repopulates layers
        /// </summary>
        private void Reinit()
        {
            int N = backgroundTarget.Layers.Count;

            // continuous reiniting during adding of new layers causes cases
            // where some of the underlaying logical prop cols are already splited, while others are not
            // e.g. background image bound already contains N layers, while SideColumn bound yet contains N-1
            // eventually they will have N layers in each logical column
            // but while the layers count is different, just dropping the reinit
            if (widthTarget != null && widthTarget.Layers.Count != N)
            {
                return;
            }
            if (rightSideTarget != null && rightSideTarget.Layers.Count != N)
            {
                return;
            }
            if (bottomSideTarget != null && bottomSideTarget.Layers.Count != N)
            {
                return;
            }

            List <VisualLayerPresentingVM> content = new List <VisualLayerPresentingVM>();

            for (int i = 0; i < N; i++)
            {
                SingleClassificationLayerVM background = backgroundTarget.Layers[i] as SingleClassificationLayerVM;
                SingleClassificationLayerVM width;
                if (widthTarget != null)
                {
                    width = widthTarget.Layers[i] as SingleClassificationLayerVM;
                }
                else
                {
                    width = null; //the width source is not chosen
                }
                SingleClassificationLayerVM rightSide;
                if (rightSideTarget != null)
                {
                    rightSide = rightSideTarget.Layers[i] as SingleClassificationLayerVM;
                }
                else
                {
                    rightSide = null; // the right side source is not chosen
                }
                SingleClassificationLayerVM bottomSide;
                if (bottomSideTarget != null)
                {
                    bottomSide = bottomSideTarget.Layers[i] as SingleClassificationLayerVM;
                }
                else
                {
                    bottomSide = null; // the bottom side source is not chosen
                }
                var adapted = adapter(background, width, rightSide, bottomSide);
                adapted.AvailableWidth = ColumnWidth;
                content.Add(adapted);
            }

            Layers = new ObservableCollection <VisualLayerPresentingVM>(content);

            StringBuilder heading = new StringBuilder("");

            heading.Append(string.Format("Колонка\n\nКрап: {0}", backgroundTarget.Heading));
            if (widthTarget != null)
            {
                heading.Append(string.Format("\nШирина: {0}", widthTarget.Heading));
            }
            if (rightSideTarget != null)
            {
                heading.Append(string.Format("\nПравая граница: {0}", rightSideTarget.Heading));
            }
            if (bottomSideTarget != null)
            {
                heading.Append(string.Format("\nНижняя граница: {0}", bottomSideTarget.Heading));
            }

            Heading = heading.ToString();

            ReclacYs();
        }
示例#6
0
        public static void Generate(string fileName, SamplesColumnVM samplesCol, Intervals.BoreIntervalVM[] intervals, Layer[] layers, string[] propNames)
        {
            using (StreamWriter textWriter = new StreamWriter(File.Open(fileName, FileMode.Create), Encoding.UTF8))
            {
                var csv = new CsvWriter(textWriter);

                //writing header
                csv.WriteField("Глубина (м)");
                csv.WriteField("Описание");
                csv.WriteField("Верх интервала (м)");
                csv.WriteField("Низ интервала (м)");
                for (int j = 0; j < propNames.Length; j++)
                {
                    csv.WriteField(propNames[j]);
                }
                csv.NextRecord();


                for (int i = 0; i < samplesCol.Samples.Length; i++)
                {
                    SampleVM sVM = samplesCol.Samples[i];

                    //searching for correspondence
                    Intervals.BoreIntervalVM containingInterval = null;
                    for (int j = 0; j < intervals.Length; j++)
                    {
                        var int1 = intervals[j];
                        if (sVM.Depth > int1.UpperDepth && sVM.Depth < int1.LowerDepth)
                        {
                            containingInterval = int1;
                            break;
                        }
                    }

                    Layer containingLayer = null;
                    for (int j = 0; j < layers.Length; j++)
                    {
                        Layer l = layers[j];
                        if (sVM.Depth > l.TopDepth && sVM.Depth < l.BottomDepth)
                        {
                            containingLayer = l;
                            break;
                        }
                    }

                    //fields to write
                    string   depth     = string.Format("{0:0.##}", sVM.Depth);
                    string   name      = string.Format("{0}", sVM.Comment);
                    string   intTop    = (containingInterval == null) ? "" : string.Format("{0:0.##}", containingInterval.UpperDepth);
                    string   intBottom = (containingInterval == null) ? "" : string.Format("{0:0.##}", containingInterval.LowerDepth);
                    string[] props     = null;
                    if (containingLayer == null)
                    {
                        props = Enumerable.Repeat("", propNames.Length).ToArray();
                    }
                    else
                    {
                        props = new string[propNames.Length];
                        for (int j = 0; j < containingLayer.Classifications.Length; j++)
                        {
                            ClassificationLayerVM clVM = containingLayer.Classifications[j];

                            SingleClassificationLayerVM sclVM = clVM as SingleClassificationLayerVM;
                            if (sclVM != null)
                            {
                                if (sclVM.CurrentClass != null)
                                {
                                    props[j] = ClassToString(sclVM.CurrentClass);
                                }
                            }
                            MultiClassificationLayerVM mclVM = clVM as MultiClassificationLayerVM;
                            if (mclVM != null)
                            {
                                if (mclVM.CurrentClasses != null)
                                {
                                    props[j] = string.Join(", ", mclVM.CurrentClasses.Select(c => ClassToString(c)).ToArray());
                                }
                            }
                        }
                    }

                    //writing fields
                    csv.WriteField(depth);
                    csv.WriteField(name);
                    csv.WriteField(intTop);
                    csv.WriteField(intBottom);
                    for (int j = 0; j < props.Length; j++)
                    {
                        csv.WriteField(props[j]);
                    }
                    csv.NextRecord();
                }
            }
        }