Пример #1
0
        private void finish()
        {
            Dictionary <DateTime, double[]> win = Program.nose.getMesureData();

            int len = prof.Settings.Count;

            bool[]   used  = new bool[len];
            Sensor[] sens  = new Sensor[len];
            double[] inite = new double[len];
            for (int i = 0; i < len; i++)
            {
                used[i] = true;
            }

            int p = 0;

            foreach (int pos in prof.Settings.Keys)
            {
                inite[p]  = init[p];
                sens[p++] = prof.Settings[pos];
            }

            MeasureData md = new MeasureData(win, inite, used, sens, -1, name, "", -1, length, 1d, true, mask, longitude, latitude);

            measureData = md;
        }
Пример #2
0
        private void экспортВCSVcp1251ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormSelectOneMeasure inst = FormSelectOneMeasure.Instance;

            if (inst.ShowDialog() == DialogResult.OK)
            {
                MeasureData data = inst.GetMeasureData();
                saveFileDialog.Filter       = "CSV файлы|*.csv";
                saveFileDialog.AddExtension = true;
                saveFileDialog.DefaultExt   = "csv";
                if (data != null)
                {
                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            string       txt = data.ToCSV(data.DefaultMask);
                            StreamWriter sw  = new StreamWriter(new FileStream(saveFileDialog.FileName, FileMode.Create, FileAccess.Write), Encoding.GetEncoding(1251));
                            sw.Write(txt);
                            sw.Flush();
                            sw.Close();
                        }
                        catch (Exception ex) { Error.Log(ex); MessageBox.Show("Ошибка сохранения: " + ex.Message); }
                    }
                }
                else
                {
                    MessageBox.Show("Измерение не выбрано. Экспорт не будет произведён.");
                }
            }

            stackPlotters(Program.Presets.CurrentProfile);
        }
Пример #3
0
        private void stackSensors()
        {
            List <Sensor> sensors = new List <Sensor>();

            foreach (object o in listBoxMeasures.Items)
            {
                MeasureData data = o as MeasureData;
                foreach (Sensor sen in data.AllData.Keys)
                {
                    if (!sensors.Contains(sen))
                    {
                        sensors.Add(sen);
                    }
                }
            }
            sensors.Sort();

            checkedListBoxSensors.Items.Clear();
            checkedListBoxSensors.Items.AddRange(sensors.ToArray());

            for (int i = 0; i < checkedListBoxSensors.Items.Count; i++)
            {
                bool checkd = false;
                foreach (object o in listBoxMeasures.Items)
                {
                    MeasureData data = o as MeasureData;
                    if (data.Used.ContainsKey(checkedListBoxSensors.Items[i] as Sensor) && data.Used[checkedListBoxSensors.Items[i] as Sensor])
                    {
                        checkd = true;
                    }
                }
                checkedListBoxSensors.SetItemChecked(i, checkd);
            }
        }
Пример #4
0
        private void FormMeasure_Shown(object sender, EventArgs e)
        {
            plotter1.Adjusting = true;
            plotter1.PenWidth  = 2;
            Program.nose.startMeasure();
            measureData = null;

            dataGridView1.RowCount = prof.Settings.Count;
            Dictionary <int, Sensor> .Enumerator en = prof.Settings.GetEnumerator();

            for (int i = 0; i < prof.Settings.Count; i++)
            {
                en.MoveNext();
                dataGridView1.Rows[i].Cells[0].Value = en.Current.Key + 1;
                Color c = plotter1.CurveColor[i];
                int   s = c.R + c.G + c.B;
                dataGridView1.Rows[i].DefaultCellStyle.BackColor = c;
                Color f = s > 383 ? Color.Black : Color.White;
                dataGridView1.Rows[i].DefaultCellStyle.ForeColor = f;

                dataGridView1.Rows[i].Cells[1].Value = en.Current.Value;
                dataGridView1.Rows[i].Cells[2].Value = init[i];
            }
            plotter1.Label = "Измерение";

            timer.Start();
            buttonOpen.Enabled = buttonSave.Enabled = buttonRepeat.Enabled = false;
        }
Пример #5
0
        private static void ParseMeasureData(UnitUnderTest unit, XDocument document)
        {
            var data = (from dt in document.Descendants("MeasureData") select dt);

            foreach (var dt in data)
            {
                var md = new MeasureData()
                {
                    Id = int.Parse(dt.Element("Id").Value)
                };

                var channels = (from ch in dt.Descendants("Channel") select ch);

                foreach (var ch in channels)
                {
                    var channel = new Channel()
                    {
                        Name = ch.Element("Name").Value,
                        Unit = ch.Element("Unit").Value,
                        Data = ch.Element("Data").Value
                    };

                    channel.Attributes = (from attr in ch.Descendants("Attribute")
                                          select new Domain.Attribute()
                    {
                        Key = attr.Element("Key").Value,
                        Value = attr.Element("Value").Value
                    }).ToList();
                    md.Channels.Add(channel);
                }

                unit.MeasureDatas.Add(md);
            }
        }
Пример #6
0
        public IHttpActionResult PutMeasureData(int id, MeasureData measureData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != measureData.Id)
            {
                return(BadRequest());
            }

            db.Entry(measureData).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MeasureDataExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #7
0
 public void setValues(MeasureData down, MeasureData up, Mask mask)
 {
     Data1     = down;
     Data2     = up;
     this.mask = mask;
     RePlot();
 }
Пример #8
0
        public static Measure Create(MeasureView v)
        {
            var d = new MeasureData();

            Copy.Members(v, d);
            return(new Measure(d));
        }
Пример #9
0
        public bool updateMeasureData(MeasureData mdata)
        {
            int id_Adress = 0;

            if (mdata.lng != "" && mdata.ltt != "")
            {
                id_Adress = insertAddress(mdata.lng, mdata.ltt);
            }
            if (id_Adress != 0)
            {
                string query = "UPDATE Measures SET GroupID=" + deNullID(mdata.GroupID);
                query += ", [Name]=" + qouted(mdata.Name);
                query += ", [Description]=" + qouted(mdata.Description);
                query += ", DefaultMask=" + deNullMaskID(mdata.DefaultMask);
                query += ", Coordinate=" + Convert.ToString(id_Adress);
                query += ", Quality=" + Convert.ToString(mdata.quality);
                query += " WHERE ID=" + mdata.ID;
                int res = executeNonQuery(query);
                return(res == 1);
            }
            else
            {
                string query = "UPDATE Measures SET GroupID=" + deNullID(mdata.GroupID);
                query += ", [Name]=" + qouted(mdata.Name);
                query += ", [Description]=" + qouted(mdata.Description);
                query += ", DefaultMask=" + deNullMaskID(mdata.DefaultMask);
                query += ", Quality=" + Convert.ToString(mdata.quality);
                query += " WHERE ID=" + mdata.ID;
                int res = executeNonQuery(query);
                return(res == 1);
            }
        }
Пример #10
0
 private void treeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
 {
     if (e.Button == MouseButtons.Right || e.Button == MouseButtons.Left)
     {
         treeView.SelectedNode = e.Node;
     }
     if (e.Node.Tag != null)
     {
         TreeNode treeNode = e.Node;
         int      count    = treeNode.GetNodeCount(true);
         if (count != 0)
         {
             MainWindow.ClearMareker();
             foreach (TreeNode tn in treeNode.Nodes)
             {
                 MeasureData mdata = Program.DataProvider.getMeasureDataByID((int)tn.Tag);
                 MainWindow.setMarekersToMap(mdata.lng, mdata.ltt, mdata.quality, mdata.Description);
             }
         }
         else
         {
             try
             {
                 MeasureData mdata = Program.DataProvider.getMeasureDataByID((int)treeView.SelectedNode.Tag);
                 MainWindow.setMarekerToMap(mdata.lng, mdata.ltt, mdata.quality, mdata.Description);
             }
             catch (Exception ex)
             {
             }
         }
         //FormViewMeasure f = FormViewMeasure.getFormForMeasure(Program.DataProvider.getMeasureDataByID((int)treeView.SelectedNode.Tag));
     }
 }
Пример #11
0
        private void экспортВCSVutf8ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormSelectOneMeasure inst = FormSelectOneMeasure.Instance;

            if (inst.ShowDialog() == DialogResult.OK)
            {
                MeasureData data = inst.GetMeasureData();
                saveFileDialog.Filter       = "CSV файлы|*.csv";
                saveFileDialog.AddExtension = true;
                saveFileDialog.DefaultExt   = "csv";
                if (data != null)
                {
                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            File.WriteAllText(saveFileDialog.FileName, data.ToCSV(data.DefaultMask));
                        }
                        catch (Exception ex) { Error.Log(ex); MessageBox.Show("Ошибка сохранения: " + ex.Message); }
                    }
                }
                else
                {
                    MessageBox.Show("Измерение не выбрано. Экспорт не будет произведён.");
                }
            }
        }
Пример #12
0
        public static Measure Create(MeasureView v)
        {
            var d = new MeasureData();

            Copy.Members(v, d); //võta v ja kopeeri see dsse

            return(new Measure(d));
        }
Пример #13
0
 /// <summary>
 /// расставить сенсоры в чеклистбоксе
 /// </summary>
 /// <param name="md">измерение</param>
 private void setChecks(MeasureData md)
 {
     checkedListBoxSensors.Items.Clear();
     foreach (Sensor sensor in md.Data.Keys)
     {
         checkedListBoxSensors.Items.Add(sensor, true);
     }
 }
Пример #14
0
 private void BtnDeleteMeasure_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("确定要删除所有测量日记记录么?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
     {
         int count = new MeasureData().DeleteData();
         MessageBox.Show($"您成功删除{count}条记录");
         GetMeasureDataLog();
     }
 }
Пример #15
0
        public static FormViewMeasure getFormForMeasure(MeasureData data)
        {
            FormViewMeasure form = new FormViewMeasure(data);

            form.Text = "Просмотр измерения: " + data.ToString() + (data.ID != -1 ? "" : " * ");
            form.ShowReport();
            form.Show();
            return(form);
        }
Пример #16
0
 public void setValues(MeasureData down, double dd, MeasureData up, double du, Mask mask)
 {
     Data1     = down;
     Data2     = up;
     this.du   = du;
     this.dd   = dd;
     this.mask = mask;
     recolor();
     RePlot();
 }
Пример #17
0
        /*Auther: Amity Timalsina
         * Date  : 11/18/2015
         * Reson : Read and Get the data from the navigator controller to the file in specified location. */

        #region getstoragedata

        /// <summary>
        /// "Amity:GetStorageData" button clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public string GetStorageData_value()
        {
            _sendCommand = SendCommand.GetStorageData;
            GetStorageDataForm getStorageData = new GetStorageDataForm();

            _measureDatas.Clear();
            LJV7IF_GET_STORAGE_REQ req = getStorageData.Req;
            // @Point
            // † dwReadArea is the target surface to read.
            //    The target surface to read indicates where in the internal memory usage area to read.
            // † The method to use in specifying dwReadArea varies depending on how internal memory is allocated.
            //   * Double buffer
            //      0 indicates the active surface, 1 indicates surface A, and 2 indicates surface B.
            //   * Entire area (overwrite)
            //      Fixed to 1
            //   * Entire area (do not overwrite)
            //      After a setting modification, data is saved in surfaces 1, 2, 3, and so on in order, and 0 is set as the active surface.
            // † For details, see "9.2.9.2 Internal memory."

            LJV7IF_STORAGE_INFO    storageInfo = new LJV7IF_STORAGE_INFO();
            LJV7IF_GET_STORAGE_RSP rsp         = new LJV7IF_GET_STORAGE_RSP();
            uint oneDataSize = (uint)(Marshal.SizeOf(typeof(uint)) + (uint)Utility.GetByteSize(Utility.TypeOfStruct.MEASURE_DATA) * (uint)NativeMethods.MeasurementDataCount);
            uint allDataSize = Math.Min(LJV_Dllconsolesample.Define.READ_DATA_SIZE, oneDataSize * getStorageData.Req.dwDataCnt);

            byte[] receiveData = new byte[allDataSize];

            using (PinnedObject pin = new PinnedObject(receiveData))
            {
                int rc = NativeMethods.LJV7IF_GetStorageData(0, ref req, ref storageInfo, ref rsp, pin.Pointer, allDataSize);
                AddLogResult(rc, Resources.SID_GET_STORAGE_DATA);
                // @Point
                // † Terminology
                //  * Base time … time expressed with 32 bits (<- the time when the setting was changed)
                //  * Accumulated date and time	 … counter value that indicates the elapsed time, in units of 10 ms, from the base time
                // † The accumulated date and time are stored in the accumulated data.
                // † The accumulated time of read data is calculated as shown below.
                //   Accumulated time = "base time (stBaseTime of LJV7IF_GET_STORAGE_RSP)" + "accumulated date and time × 10 ms"

                if (rc == (int)Rc.Ok)
                {
                    // Temporarily retain the get data.
                    int byteSize = MeasureData.GetByteSize();
                    for (int i = 0; i < (int)rsp.dwDataCnt; i++)
                    {
                        _measureDatas.Add(new MeasureData(receiveData, byteSize * i));
                    }

                    //// Response data display
                    //AddLog(Utility.ConvertToLogString(storageInfo).ToString());
                    //AddLog(Utility.ConvertToLogString(rsp).ToString());
                }
                return(rc.ToString());
            }
        }
Пример #18
0
        private MeasureData[] toArray(System.Windows.Forms.ListBox.ObjectCollection collection)
        {
            MeasureData[] data = new MeasureData[collection.Count];
            int           i    = 0;

            foreach (object o in collection)
            {
                data[i++] = o as MeasureData;
            }
            return(data);
        }
Пример #19
0
        public IHttpActionResult GetMeasureData(int id)
        {
            MeasureData measureData = db.MeasureDatas.Find(id);

            if (measureData == null)
            {
                return(NotFound());
            }

            return(Ok(measureData));
        }
Пример #20
0
 public void initWData(MeasureData data)
 {
     if (data != null)
     {
         this.measureData = data;
         this.mask        = data.DefaultMask;
         plotter.Viewport = new RectangleD(0, -100, data.FullMeasureLength + 0.5d, 200);
         plotter.Label    = data.ToString();
         RePlot();
     }
 }
Пример #21
0
 public MovableGraph(MeasureData measureData)
 {
     InitializeComponent();
     if (measureData != null)
     {
         this.measureData = measureData;
         this.mask        = measureData.DefaultMask;
         plotter.Viewport = new RectangleD(0, -100, measureData.FullMeasureLength + 0.5d, 200);
         plotter.Label    = measureData.ToString();
         RePlot();
     }
 }
Пример #22
0
        public override void TestInitialize()
        {
            base.TestInitialize(); //kasutab inmemorydb extensionit, mis on malus!
            units    = new unitsRepository();
            measures = new measuresRepository();
            data     = GetRandom.Object <MeasureData>(); //uks data on juba olemas
            var m = new Measure(data);                   //measure sisse ara data

            measures.Add(m).GetAwaiter();
            addRandomMeasures();
            obj = new testClass(units, measures); //annan repository katte
        }
        public bool updateMeasureData(MeasureData mdata)
        {
            string query = "UPDATE Measures SET GroupID=" + deNullID(mdata.GroupID);

            query += ", [Name]=" + qouted(mdata.Name);
            query += ", [Description]=" + qouted(mdata.Description);
            query += ", DefaultMask=" + deNullMaskID(mdata.DefaultMask);
            query += " WHERE ID=" + mdata.ID;
            int res = executeNonQuery(query);

            return(res == 1);
        }
Пример #24
0
        [TestInitialize] public override void TestInitialize()
        {
            base.TestInitialize();
            units    = new unitsRepository();
            measures = new measuresRepository();
            data     = GetRandom.Object <MeasureData>();
            var m = new Measure(data);

            measures.Add(m).GetAwaiter();
            addRandomMeasures();
            obj = new testClass(units, measures);
        }
Пример #25
0
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            object o = TagOfSelected;

            DataProvider.GroupTreeNode other;

            if (o == null)
            {
                MessageBox.Show("Нечего непемещать!");
            }
            else
            {
                if (o is DataProvider.GroupTreeNode)
                {
                    if ((other = FormSelectOneGroup.getNode()) != null)
                    {
                        if (!Program.DataProvider.willMakeCycle((o as DataProvider.GroupTreeNode).ID, other.ID))
                        {
                            Program.DataProvider.updateGroupParentId((o as DataProvider.GroupTreeNode).ID, other.ID);
                        }
                        else
                        {
                            MessageBox.Show("Такое перемещение запрещено из-за образования цикла в дереве!");
                        }
                    }
                    else
                    {
                        Program.DataProvider.updateGroupParentId((o as DataProvider.GroupTreeNode).ID, -1);
                    }
                }
                else if (o is Int32)
                {
                    MeasureData md = Program.DataProvider.getMeasureDataByID((int)o);

                    if (md != null)
                    {
                        if ((other = FormSelectOneGroup.getNode()) != null)
                        {
                            md.GroupID = other.ID;
                        }
                        else
                        {
                            md.GroupID = -1;
                        }

                        Program.DataProvider.updateMeasureData(md);
                    }
                }

                this.ShowMeasures = this.ShowMeasures;
            }
        }
Пример #26
0
        /// <summary>
        /// "Get current values" button pressed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _btnGetMeasureData_Click(object sender, EventArgs e)
        {
            LJV7IF_MEASURE_DATA[] measureData = new LJV7IF_MEASURE_DATA[NativeMethods.MesurementDataCount];
            Rc rc = (Rc)NativeMethods.LJV7IF_GetMeasurementValue(DEVICE_ID, measureData);

            if (!CheckReturnCode(rc))
            {
                return;
            }
            MeasureData data = new MeasureData(measureData);

            _txtMeasureData.Text = data.ToString();
        }
Пример #27
0
        public FormViewMeasure(MeasureData data)
        {
            InitializeComponent();

            try
            {
                init();

                this.mask = data.DefaultMask;

                if (mask == null)
                {
                    if (comboBoxMask.Items.Count > 0)
                    {
                        this.mask = comboBoxMask.Items[0] as Mask;
                    }
                }

                this.Data  = data;
                this.saved = data.ID != -1;

                if (mask != null)
                {
                    for (int i = 0; i < comboBoxMask.Items.Count; i++)
                    {
                        if (mask.ID == (comboBoxMask.Items[i] as Mask).ID)
                        {
                            comboBoxMask.SelectedIndex = i;
                            break;
                        }
                    }
                }

                plotter.Viewport = new RectangleD(0, 1000000, measureData.FullMeasureLength + 0.5d, 200);
                if (data.quality != -1)
                {
                    comboBox1.SelectedIndex = data.quality;
                }
                textBox6.Text = data.lng;
                textBox7.Text = data.ltt;
                textBox8.Text = data.Description;
                RePlot();
                btnFit_Click(null, null);
                button1_Click(null, null);
            }
            catch (Exception ex)
            {
                Error.Log(ex);
                MessageBox.Show("Ошибка инициализаци: " + ex.Message);
            }
        }
Пример #28
0
        public static Measure Create(MeasureView v)
        {
            var d = new MeasureData
            {
                Id         = v.Id,
                Name       = v.Name,
                Code       = v.Code,
                Definition = v.Definition,
                ValidFrom  = v.ValidFrom,
                ValidTo    = v.ValidTo
            };

            return(new Measure(d));
        }
Пример #29
0
        public IHttpActionResult DeleteMeasureData(int id)
        {
            MeasureData measureData = db.MeasureDatas.Find(id);

            if (measureData == null)
            {
                return(NotFound());
            }

            db.MeasureDatas.Remove(measureData);
            db.SaveChanges();

            return(Ok(measureData));
        }
Пример #30
0
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            object o = TagOfSelected;

            if (o == null)
            {
                MessageBox.Show("Нечего переименовывыть!");
            }
            else
            {
                if (o is DataProvider.GroupTreeNode)
                {
                    string s = null;
                    if ((s = FormStringRequest.GetString("Новое название группы")) != null)
                    {
                        if (s.Trim() != "")
                        {
                            Program.DataProvider.RenameGroup((o as DataProvider.GroupTreeNode).ID, s);
                        }
                        else
                        {
                            MessageBox.Show("Введено неосмысленное название!");
                        }
                    }
                }
                else if (o is Int32)
                {
                    MeasureData md = Program.DataProvider.getMeasureDataByID((int)o);

                    if (md != null)
                    {
                        string s = null;
                        if ((s = FormStringRequest.GetString("Новое название измерения")) != null)
                        {
                            if (s.Trim() != "")
                            {
                                md.Name = s;
                                Program.DataProvider.updateMeasureData(md);
                            }
                            else
                            {
                                MessageBox.Show("Введено неосмысленное название!");
                            }
                        }
                    }
                }
                this.ShowMeasures = this.ShowMeasures;
            }
        }
Пример #31
0
        //------------------------------------------------------ 
        //
        //  Private Methods 
        //
        //-----------------------------------------------------

        #region Private Methods 

 
        // 
        // MeasureOverride Helpers
        // 

        #region MeasureOverride Helpers

        /// <summary> 
        /// Extends the viewport of the given MeasureData to give a focus trail.  Returns by how much it extended the viewport.
        /// </summary> 
        /// <param name="childData"></param> 
        /// <returns></returns>
        private MeasureData AddFocusTrail(MeasureData measureData, bool isHorizontal) 
        {
            //
            // Create the before / after focus trail for interior panels that use MeasureData's viewport to virtualize.
            // We expand the viewport so that roughly two extra items are generated at the top and the bottom. 
            //
            // For the before / after focus trail good values are 
            //  padding = header height * 4; 
            //
            // To make page up / down work without rewriting TreeView's algorithm we actually extend the viewport one extra page 
            // top and bottm.
            //
            Debug.Assert(IsScrolling, "The scrolling panel is the only one that should extend the viewport");
            Invariant.Assert(IsPixelBased, "If we're sending down a viewport to the children we should be doing pixel-based computations"); 

            double page = isHorizontal ? ViewportWidth : ViewportHeight; 
            Rect viewport = measureData.Viewport; 

            if (isHorizontal) 
            {
                viewport.Width += page * 2;
                viewport.X -= page;
            } 
            else
            { 
                viewport.Height += page * 2; 
                viewport.Y -= page;
            } 

            measureData.Viewport = viewport;
            return measureData;
        } 
Пример #32
0
        private MeasureData CreateChildMeasureData(MeasureData measureData, Size layoutSlotSize, Size stackDesiredSize, bool isHorizontal)
        { 
            Invariant.Assert(IsPixelBased && measureData != null, "We can only use MeasureData when pixel-based"); 
            Rect viewport = measureData.Viewport;
 
            //
            // Adjust viewport offset for the child
            //
            if (isHorizontal) 
            {
                viewport.X -= stackDesiredSize.Width; 
            } 
            else
            { 
                viewport.Y -= stackDesiredSize.Height;
            }

            return new MeasureData(layoutSlotSize, viewport); 
        }
Пример #33
0
        /// <summary> 
        /// Returns the MeasureData we'll be using for computations in MeasureOverride.  This updates the viewport offset
        /// based on the one set in the MeasureData property prior to the call to MeasureOverride. 
        /// </summary> 
        /// <param name="constraint"></param>
        /// <param name="itemsControl"></param> 
        /// <param name="isHorizontal"></param>
        /// <returns></returns>
        private MeasureData AdjustViewportOffset(MeasureData givenMeasureData, ItemsControl itemsControl, bool isHorizontal)
        { 
            // Note that a panel should not modify its own MeasureData -- it needs to be treated exactly as if it was a variable
            // passed into MeasureOverride.  That's why we make a copy of MeasureData in this method and return that. 
 
            Rect viewport;
            MeasureData newMeasureData = null; 
            IProvideStackingSize stackingSize;
            double offset = 0d;
            Debug.Assert(MeasureData == null || IsPixelBased, "If a panel has measure data then it must be pixel based");
            Debug.Assert(!IsScrolling && IsPixelBased, "This only applies to internal panels"); 

            // 
            // This panel isn't a scroll owner but some panel above it is.  It will be able to use the viewport data 
            // to virtualize.
            // 

            if (givenMeasureData != null)
            {
                viewport = givenMeasureData.Viewport; 
                stackingSize = itemsControl as IProvideStackingSize;
 
                Debug.Assert(givenMeasureData.HasViewport, "MeasureData is only set on objects when we want to pass down viewport information."); 

                // 
                // We need to offset the viewport to take into account the delta between the top of the items control
                // and this panel (i.e. the header).  Ask for the header, and, if not available, use the estimated container size.

                if (stackingSize != null) 
                {
                    offset = stackingSize.HeaderSize(isHorizontal); 
 
                    if (offset <= 0d || DoubleUtil.IsNaN(offset))
                    { 
                        offset = ContainerStackingSizeEstimate(stackingSize, isHorizontal);
                    }
                }
 
                if (isHorizontal)
                { 
                    viewport.X -= offset; 
                }
                else 
                {
                    // adjust viewport for the header of the TreeViewItem containing this as an ItemsPanel.
                    viewport.Y -= offset;
                } 

                newMeasureData = new MeasureData(givenMeasureData.AvailableSize, viewport); 
            } 

 
            return newMeasureData;
        }
Пример #34
0
 public void AddData(MeasureData _data)
 {
     data.Add(_data.timestamp, _data);
 }
Пример #35
0
        private Size RealMeasureOverride(Size constraint)
        {
#endif
            bool etwTracingEnabled = IsScrolling && EventTrace.IsEnabled(EventTrace.Keyword.KeywordGeneral, EventTrace.Level.Info); 
            if (etwTracingEnabled)
            { 
                EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientStringBegin, EventTrace.Keyword.KeywordGeneral, EventTrace.Level.Info, "VirtualizingStackPanel :MeasureOverride"); 
            }
            Size stackDesiredSize = new Size(); 
            bool invalidOffset = false;
            try
            {
 
                Debug.Assert(MeasureData == null || constraint == MeasureData.AvailableSize, "MeasureData needs to be passed down in [....] with size");
 
                MeasureData measureData = MeasureData; 

                Size layoutSlotSize = constraint; 
                bool fHorizontal = (Orientation == Orientation.Horizontal);
                int firstViewport;                              // First child index in the viewport.
                double firstItemOffset;                         // Offset of the top of the first child relative to the top of the viewport.
                double virtualizedItemsSize = 0d;               // Amount that virtualized children contribute to the desired size in the stacking direction 
                int lastViewport = -1;                          // Last child index in the viewport.  -1 indicates we have not yet iterated through the last child.
                double logicalVisibleSpace, childLogicalSize; 
                Rect originalViewport = Rect.Empty;             // Only used if this is the scrolling panel.  Saves off the given viewport for scroll computations. 

                // Collect information from the ItemsControl, if there is one. 
                ItemsControl itemsControl = ItemsControl.GetItemsOwner(this);
                int itemCount = (itemsControl != null) ? itemsControl.Items.Count : 0;
                SetVirtualizationState(itemsControl, /* hasMeasureData = */ measureData != null && measureData.HasViewport);
 
                IList children = RealizedChildren;  // yes, this is weird, but this property ensures the Generator is properly initialized.
                IItemContainerGenerator generator = Generator; 
 
                // Adjust the viewport
                if (IsPixelBased) 
                {
                    if (IsScrolling)
                    {
 
                        // We're the top level scrolling panel.  Set the viewport and extend it to add a focus trail
                        originalViewport = new Rect(_scrollData._offset.X, _scrollData._offset.Y, constraint.Width, constraint.Height); 
                        measureData = new MeasureData(constraint, originalViewport); 

                        // The way we have a focus trail when pixel-based is to artificially extend the viewport.  All calculations are done 
                        // with this 'artificial' viewport with the exception of the scroll offset, extent, etc.
                        measureData = AddFocusTrail(measureData, fHorizontal);
                        Debug.Assert(!object.ReferenceEquals(originalViewport, measureData.Viewport), "original viewport should not have a focus trail");
                    } 
                    else
                    { 
                        measureData = AdjustViewportOffset(measureData, itemsControl, fHorizontal); 
                        Debug.Assert(!object.ReferenceEquals(MeasureData, measureData), "The value set in the MeasureData property should not be modified");
                    } 
                }


                // 
                // Initialize child sizing and iterator data
                // Allow children as much size as they want along the stack. 
                // 
                if (fHorizontal)
                { 
                    layoutSlotSize.Width = Double.PositiveInfinity;
                    if (IsScrolling && CanVerticallyScroll) { layoutSlotSize.Height = Double.PositiveInfinity; }
                    logicalVisibleSpace = constraint.Width;
                } 
                else
                { 
                    layoutSlotSize.Height = Double.PositiveInfinity; 
                    if (IsScrolling && CanHorizontallyScroll) { layoutSlotSize.Width = Double.PositiveInfinity; }
                    logicalVisibleSpace = constraint.Height; 
                }

                // Compute index of first item in the viewport
                firstViewport = ComputeIndexOfFirstVisibleItem(measureData, itemsControl, fHorizontal, out firstItemOffset, out invalidOffset); 

                if (IsPixelBased) 
                { 
                    // Acount for the size of items that won't be generated
                    Debug.Assert(stackDesiredSize.Width == 0 && stackDesiredSize.Height == 0, "stack desired size must be 0 for virtualizedItemsSize to work"); 
                    stackDesiredSize = ExtendDesiredSize(itemsControl, stackDesiredSize, firstViewport, /*before = */ true, fHorizontal);

                    virtualizedItemsSize = fHorizontal ? stackDesiredSize.Width : stackDesiredSize.Height;
                } 

 
                debug_AssertRealizedChildrenEqualVisualChildren(); 

                // If recycling clean up before generating children. 
                if (IsVirtualizing && InRecyclingMode)
                {
                    CleanupContainers(firstViewport, itemsControl);
                    debug_VerifyRealizedChildren(); 
                }
 
                // 
                // Figure out the position of the first visible item
                // 
                GeneratorPosition startPos = IndexToGeneratorPositionForStart(IsVirtualizing ? firstViewport : 0, out _firstVisibleChildIndex);
                int childIndex = _firstVisibleChildIndex;

                // 
                // Main loop: generate and measure all children (or all visible children if virtualizing).
                // 
                bool ranOutOfItems = true; 
                bool visualOrderChanged = false;
                _visibleCount = 0; 
                if (itemCount > 0)
                {
                    _afterTrail = 0;
                    using (generator.StartAt(startPos, GeneratorDirection.Forward, true)) 
                    {
                        for (int i = IsVirtualizing ? firstViewport : 0, count = itemCount; i < count; ++i) 
                        { 
                            // Get next child.
                            bool newlyRealized; 
                            UIElement child = generator.GenerateNext(out newlyRealized) as UIElement;

                            if (child == null)
                            { 
                                Debug.Assert(!newlyRealized, "The generator realized a null value.");
 
                                // We reached the end of the items (because of a group) 
                                break;
                            } 

                            visualOrderChanged |= AddContainerFromGenerator(childIndex, child, newlyRealized);

                            childIndex++; 
                            _visibleCount++;
 
                            if (IsPixelBased) 
                            {
                                // Pass along MeasureData so it continues down the tree. 
                                child.MeasureData = CreateChildMeasureData(measureData, layoutSlotSize, stackDesiredSize, fHorizontal);
                            }

                            Size childDesiredSize = child.DesiredSize; 
                            child.Measure(layoutSlotSize);
 
                            if (childDesiredSize != child.DesiredSize) 
                            {
                                childDesiredSize = child.DesiredSize; 

                                // Reset the _maxDesiredSize cache if child DesiredSize changes
                                if (_scrollData != null)
                                    _scrollData._maxDesiredSize = new Size(); 
                            }
 
 
                            // Accumulate child size.
                            if (fHorizontal) 
                            {
                                stackDesiredSize.Width += childDesiredSize.Width;
                                stackDesiredSize.Height = Math.Max(stackDesiredSize.Height, childDesiredSize.Height);
                                childLogicalSize = childDesiredSize.Width; 
                            }
                            else 
                            { 
                                stackDesiredSize.Width = Math.Max(stackDesiredSize.Width, childDesiredSize.Width);
                                stackDesiredSize.Height += childDesiredSize.Height; 
                                childLogicalSize = childDesiredSize.Height;
                            }

 

                            // Adjust remaining viewport space if we are scrolling and within the viewport region. 
                            // While scrolling (not virtualizing), we always measure children before and after the viewport. 
                            if (IsScrolling && lastViewport == -1 && i >= firstViewport)
                            { 
                                logicalVisibleSpace -= childLogicalSize;
                                if (DoubleUtil.LessThanOrClose(logicalVisibleSpace, 0.0))
                                {
                                    lastViewport = i; 
                                }
                            } 
 

                            // When under a viewport, virtualizing and at or beyond the first element, stop creating elements when out of space. 
                            if (IsVirtualizing && (i >= firstViewport))
                            {
                                double viewportSize;
                                double totalGenerated; 

                                // 
                                // Decide if the end of the item is outside the viewport. 
                                //
                                // StackDesiredSize, with some adjustment, is a measure of exactly how much viewport space we have used. 
                                //
                                // StackDesiredSize is the sum of all generated children (starting with the first visible item).  The first
                                // visible item doesn't always start at the top of the viewport, so we have to adjust by the firstItemoffset.
                                // 
                                // When pixel-based we add the sum of all virtualized children to the stackDesiredSize; this has to be removed as well.
                                // 
                                Debug.Assert(IsPixelBased || virtualizedItemsSize == 0d); 

                                if (fHorizontal) 
                                {
                                    viewportSize = IsPixelBased ? measureData.Viewport.Width : constraint.Width;
                                    totalGenerated = stackDesiredSize.Width - virtualizedItemsSize + firstItemOffset;
 
                                }
                                else 
                                { 
                                    viewportSize = IsPixelBased ? measureData.Viewport.Height : constraint.Height;
                                    totalGenerated = stackDesiredSize.Height - virtualizedItemsSize + firstItemOffset; 
                                }


                                if (totalGenerated > viewportSize) 
                                {
                                    // The end of this child is outside the viewport.  Check if we want to generate some more. 
 
                                    if (IsPixelBased)
                                    { 
                                        // For pixel-based virtualization (specifically TreeView virtualization) we deal with
                                        // the after trail later, since it has to function hierarchically.
                                        break;
                                    } 
                                    else
                                    { 
                                        // We want to keep a focusable item after the end so that keyboard navigation 
                                        // can work, but we want to limit that to FocusTrail number of items
                                        // in case all the items are not focusable. 
                                        if (_afterTrail > 0 && (_afterTrail >= FocusTrail || Keyboard.IsFocusable(child)))
                                        {
                                            // Either we passed the limit or the child was focusable
                                            ranOutOfItems = false; 
                                            break;
                                        } 
 
                                        _afterTrail++;
                                        // Loop around and generate another item 
                                    }
                                }
                            }
                        } 
                    }
                } 
 
#if DEBUG
                if (IsVirtualizing && InRecyclingMode) 
                {
                    debug_VerifyRealizedChildren();
                }
#endif 

                _visibleStart = firstViewport; 
 

                if (IsPixelBased) 
                {
                    // Acount for the size of items that won't be generated
                    stackDesiredSize = ExtendDesiredSize(itemsControl, stackDesiredSize, firstViewport + _visibleCount, /*before = */ false, fHorizontal);
                } 

 
                // 
                // Adjust the scroll offset, extent, etc.
                // 
                if (IsScrolling)
                {
                    if (IsPixelBased)
                    { 

                        Vector offset = new Vector(originalViewport.Location.X, originalViewport.Location.Y); 
                        SetAndVerifyScrollingData(originalViewport.Size, stackDesiredSize, offset); 
                    }
                    else 
                    {
                        // Compute the extent before we fill remaining space and modify the stack desired size
                        Size extent = ComputeLogicalExtent(stackDesiredSize, itemCount, fHorizontal);
 
                        if (ranOutOfItems)
                        { 
                            // If we or children have resized, it's possible that we can now display more content. 
                            // This is true if we started at a nonzero offeset and still have space remaining.
                            // In this case, we loop back through previous children until we run out of space. 
                            FillRemainingSpace(ref firstViewport, ref logicalVisibleSpace, ref stackDesiredSize, layoutSlotSize, fHorizontal);
                        }

                        // Create the Before focus trail 
                        // NOTE: the call here (under IsScrolling) implicitly assumes that only a scrolling panel can virtualize and thus requires
                        // a focus trail.  That's not true for hierarchical (pixel-based) virtualization, but it handles the focus trail differently anyway. 
                        EnsureTopCapGenerated(layoutSlotSize); 

                        // Compute Scrolling data such as extent, viewport, and offset. 
                        stackDesiredSize = UpdateLogicalScrollData(stackDesiredSize, constraint, logicalVisibleSpace,
                                                                   extent, firstViewport, lastViewport, itemCount, fHorizontal);
                    }
                } 

                // 
                // Cleanup items no longer in the viewport 
                //
                if (IsVirtualizing && !InRecyclingMode) 
                {
                    if (IsPixelBased)
                    {
                        // Immediate cleanup 
                        CleanupContainers(firstViewport, itemsControl);
                    } 
                    else 
                    {
                        // Less aggressive backwards-compat background cleanup operation 
                        EnsureCleanupOperation(false /* delay */);
                    }
                }
 

                if (IsVirtualizing && InRecyclingMode) 
                { 
                    DisconnectRecycledContainers();
 
                    if (visualOrderChanged)
                    {
                        // We moved some containers in the visual tree without firing changed events.  ZOrder is now invalid.
                        InvalidateZState(); 
                    }
                } 
            } 
            finally
            { 

                if (etwTracingEnabled)
                {
                    EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientStringEnd, EventTrace.Keyword.KeywordGeneral, EventTrace.Level.Info, "VirtualizingStackPanel :MeasureOverride"); 
                }
            } 
 
            debug_AssertRealizedChildrenEqualVisualChildren();
 
            if (_remeasureOnInvalidOffset)
            {
                _remeasureOnInvalidOffset = false;
                if (invalidOffset) 
                {
                    // Make another pass of MeasureOverride if remeasure is true. 
                    return MeasureOverride(constraint); 
                }
            } 

            return stackDesiredSize;
        }
Пример #36
0
        /* 
           MeasureDistance: measure the distance between 2 points in mm
           sample: is the photo instance
           startPoint, endPoint: are the start pont and end point of the distance that need to be measured.
           Note: Depth data must be availible and accurate at the start and end point selected. 
        */

        public pxcmStatus MeasureDistance(PXCMPhoto sample, PXCMPointI32 startPoint, PXCMPointI32 endPoint, out MeasureData outData)
        {
            outData = new MeasureData();
            return PXCMEnhancedPhoto_MeasureDistance(instance, sample.instance, startPoint, endPoint, outData);
        }
Пример #37
0
        // 
        // Returns the index of the first item visible (even partially) in the viewport.
        // 
        private int ComputeIndexOfFirstVisibleItem(MeasureData measureData, ItemsControl itemsControl, bool isHorizontal, out double firstItemOffset, out bool offsetPastLastItem) 
        {
            firstItemOffset = 0d;   // offset of the top of the first visible child from the top of the viewport.  The child always 
                                    // starts before the top of the viewport so this is always negative.
            offsetPastLastItem = false;

            if (itemsControl != null) 
            {
                ItemCollection items = itemsControl.Items; 
                int itemsCount = items.Count; 

                if (!IsPixelBased) 
                {
                    //
                    // Classic case that shipped with V1
                    // 
                    // If the panel is implementing IScrollInfo then _scrollData keeps track of the
                    // current offset, extent, etc in logical units 
                    // 
                    if (IsScrolling)
                    { 
                        return CoerceIndexToInteger(isHorizontal ? _scrollData._offset.X : _scrollData._offset.Y, itemsCount);
                    }
                }
                else 
                {
                    Size containerSize; 
                    double totalSpan = 0.0;      // total height or width in the stacking direction 
                    double containerSpan = 0.0;
                    double viewportOffset = isHorizontal ? measureData.Viewport.X : measureData.Viewport.Y; 

                    for (int i = 0; i < itemsCount; i++)
                    {
                        containerSize = ContainerSizeForItem(itemsControl, items[i], i); 
                        containerSpan = isHorizontal ? containerSize.Width : containerSize.Height;
                        totalSpan += containerSpan; 
 
                        if (totalSpan > viewportOffset)
                        { 
                            // This is the first item that starts before the viewportOffset but ends after it; i is thus the index
                            // to the first item in the viewport.
                            firstItemOffset = totalSpan - containerSpan - viewportOffset;
                            return i; 
                        }
                    } 
                    offsetPastLastItem = true; 
                }
            } 

            return 0;
        }