コード例 #1
0
        protected override void OnPointerReleased(PointerRoutedEventArgs args)
        {
            // Get information
            PointerPoint pointerPoint = args.GetCurrentPoint(this);
            uint         id           = pointerPoint.PointerId;

            if (pointerDictionary.ContainsKey(id))
            {
                // Give PointerPoint to InkManager
                inkManager.ProcessPointerUp(pointerPoint);

                if (inkManager.Mode == InkManipulationMode.Inking)
                {
                    // Get rid of the little Line segments
                    newLineGrid.Children.Clear();

                    // Render the new stroke
                    IReadOnlyList <InkStroke> inkStrokes = inkManager.GetStrokes();
                    InkStroke inkStroke = inkStrokes[inkStrokes.Count - 1];
                    RenderStroke(inkStroke);
                }
                pointerDictionary.Remove(id);
            }
            base.OnPointerReleased(args);
        }
コード例 #2
0
        // </SnippetPointerReleasedHandler>

        // Render ink strokes as cubic bezier segments.
        // <SnippetRenderAllStrokes>
        private void RenderAllStrokes()
        {
            // Clear the canvas.
            InkCanvas.Children.Clear();

            // Get the InkStroke objects.
            IReadOnlyList <InkStroke> inkStrokes = _inkManager.GetStrokes();

            // Process each stroke.
            foreach (InkStroke inkStroke in inkStrokes)
            {
                PathGeometry          pathGeometry = new PathGeometry();
                PathFigureCollection  pathFigures  = new PathFigureCollection();
                PathFigure            pathFigure   = new PathFigure();
                PathSegmentCollection pathSegments = new PathSegmentCollection();

                // Create a path and define its attributes.
                Windows.UI.Xaml.Shapes.Path path = new Windows.UI.Xaml.Shapes.Path();
                path.Stroke          = new SolidColorBrush(Colors.Red);
                path.StrokeThickness = STROKETHICKNESS;

                // Get the stroke segments.
                IReadOnlyList <InkStrokeRenderingSegment> segments;
                segments = inkStroke.GetRenderingSegments();

                // Process each stroke segment.
                bool first = true;
                foreach (InkStrokeRenderingSegment segment in segments)
                {
                    // The first segment is the starting point for the path.
                    if (first)
                    {
                        pathFigure.StartPoint = segment.BezierControlPoint1;
                        first = false;
                    }

                    // Copy each ink segment into a bezier segment.
                    BezierSegment bezSegment = new BezierSegment();
                    bezSegment.Point1 = segment.BezierControlPoint1;
                    bezSegment.Point2 = segment.BezierControlPoint2;
                    bezSegment.Point3 = segment.Position;

                    // Add the bezier segment to the path.
                    pathSegments.Add(bezSegment);
                }

                // Build the path geometerty object.
                pathFigure.Segments = pathSegments;
                pathFigures.Add(pathFigure);
                pathGeometry.Figures = pathFigures;

                // Assign the path geometry object as the path data.
                path.Data = pathGeometry;

                // Render the path by adding it as a child of the Canvas object.
                InkCanvas.Children.Add(path);
            }
        }
コード例 #3
0
        private void InkPresenter_StrokesErased(InkPresenter sender, InkStrokesErasedEventArgs args)
        {
            var removed    = args.Strokes;
            var strokeList = inkManager.GetStrokes().Except(removed).ToList();

            inkManager = new InkManager();
            strokeList.ForEach(inkManager.AddStroke);

            ClearSelection();

            canvasControl.Invalidate();
        }
コード例 #4
0
        private void DeleteSelected_Clicked(object sender, RoutedEventArgs e)
        {
            inkManager.DeleteSelected();
            strokeList.Clear();

            var strokes = inkManager.GetStrokes();

            strokeList.AddRange(strokes);

            selectionBoundingRect = null;

            needsInkSurfaceValidation = true;

            canvasControl.Invalidate();
        }
コード例 #5
0
ファイル: InkExample.xaml.cs プロジェクト: mjeanrichard/Win2D
        private void canvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            if (needToCreateSizeDependentResources)
            {
                CreateSizeDependentResources();
            }

            if (needToRedrawInkSurface)
            {
                ClearInkSurface();
                DrawStrokeCollectionToInkSurface(inkManager.GetStrokes());

                needToRedrawInkSurface = false;
            }

            DrawBackgroundText(args.DrawingSession);

            if (pendingDry != null && deferredDryDelay == 0)
            {
                // Incremental draw only.
                DrawStrokeCollectionToInkSurface(pendingDry);

                // Register to call EndDry on the next-but-one draw,
                // by which time our dry ink will be visible.
                deferredDryDelay             = 1;
                CompositionTarget.Rendering += DeferredEndDry;
            }

            args.DrawingSession.DrawImage(renderTarget);

            DrawForegroundText(args.DrawingSession);
            DrawSelectionBoundingRect(args.DrawingSession);
            DrawSelectionLasso(sender, args.DrawingSession);
        }
コード例 #6
0
        private async void btnSaveWritingAsImage_Click(object sender, RoutedEventArgs e)
        {
            if (MyInkManager.GetStrokes().Count > 0)
            {
                try
                {
                    Windows.Storage.Pickers.FileSavePicker SavePicker = new Windows.Storage.Pickers.FileSavePicker();
                    SavePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
                    SavePicker.DefaultFileExtension   = ".png";
                    SavePicker.FileTypeChoices.Add("PNG", new string[] { ".png" });
                    SavePicker.FileTypeChoices.Add("JPG", new string[] { ".jpg" });
                    StorageFile filesave = await SavePicker.PickSaveFileAsync();

                    IOutputStream ab = await filesave.OpenAsync(FileAccessMode.ReadWrite);

                    if (ab != null)
                    {
                        await MyInkManager.SaveAsync(ab);
                    }
                }

                catch (Exception)
                {
                    var MsgDlg = new MessageDialog("Only handwriting can be saved as image.", "Error while saving");
                    MsgDlg.ShowAsync();
                }
            }
            else
            {
                var MsgDlg = new MessageDialog("Only handwriting can be saved as image.", "Error while saving");
                await MsgDlg.ShowAsync();
            }
        }
コード例 #7
0
 /// <summary>
 /// Selects all of the strokes.
 /// </summary>
 /// <param name="inkManager">
 /// The <see cref="InkManager"/>.
 /// </param>
 public static void SelectAllStrokes(this InkManager inkManager)
 {
     foreach (var stroke in inkManager.GetStrokes())
     {
         stroke.Selected = true;
     }
 }
コード例 #8
0
        protected override void OnPointerReleased(PointerRoutedEventArgs args)
        {
            // Get information
            PointerPoint pointerPoint = args.GetCurrentPoint(sheetPanel);
            uint         id           = pointerPoint.PointerId;
            InkManager   inkManager   = this.InkFileManager.InkManager;

            if (pointerDictionary.ContainsKey(id))
            {
                // Give PointerPoint to InkManager
                inkManager.ProcessPointerUp(pointerPoint);

                if (inkManager.Mode == InkManipulationMode.Inking)
                {
                    // Get rid of the little line segments
                    newLineGrid.Children.Clear();

                    // Render the new stroke
                    IReadOnlyList <InkStroke> inkStrokes = inkManager.GetStrokes();
                    InkStroke inkStroke = inkStrokes[inkStrokes.Count - 1];
                    this.InkFileManager.RenderStroke(inkStroke);
                }
                else if (inkManager.Mode == InkManipulationMode.Selecting)
                {
                    // Get rid of the enclosure line
                    newLineGrid.Children.Clear();

                    // Render everything so selected items are identified
                    this.InkFileManager.RenderAll();
                }
                pointerDictionary.Remove(id);
            }
            base.OnPointerReleased(args);
        }
コード例 #9
0
        private async void SetImage(byte[] ImageData)
        {
            MedicalCanvas.Children.Clear();
            if (ImageData == null)
            {
                MedcialInkManager = new InkManager();
                return;
            }
            InkManager inkMgr = MedcialInkManager;

            renderer = new XamlInkRenderer(MedicalCanvas);

            using (var stream = new InMemoryRandomAccessStream())
            {
                await stream.WriteAsync(ImageData.AsBuffer());

                await stream.FlushAsync();

                stream.Seek(0);

                await inkMgr.LoadAsync(stream);

                var iskList  = inkMgr.GetStrokes();
                int iskCount = iskList.Count;
                renderer.Clear();
                renderer.AddInk(iskList);
            }
        }
コード例 #10
0
 /// <summary>
 /// Clears the selection of any stroke.
 /// </summary>
 /// <param name="inkManager">
 /// The <see cref="InkManager"/>.
 /// </param>
 public static void ClearStrokeSelection(this InkManager inkManager)
 {
     foreach (var stroke in inkManager.GetStrokes())
     {
         stroke.Selected = false;
     }
 }
コード例 #11
0
        private void canvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            if (needToCreateSizeDependentResources)
            {
                CreateSizeDependentResources();
            }

            if (needToRedrawInkSurface)
            {
                ClearInkSurface();
                DrawStrokeCollectionToInkSurface(inkManager.GetStrokes());

                needToRedrawInkSurface = false;
            }

            DrawBackgroundText(args.DrawingSession);

            if (pendingDry != null && deferredDryDelay == 0)
            {
                // Incremental draw only.
                DrawStrokeCollectionToInkSurface(pendingDry);

                // We want to transition from displaying wet ink to our newly drawn dry ink with minimum possible risk of flicker.
                // If the ink is opaque, the safest approach is to delay calling EndDry for a couple of frames, deferring it via
                // the CompositionTarget.Rendering event. This will usually briefly overlap the wet and dry ink, which looks fine
                // for regular pen strokes but not for pencil or highlighter rendering. When using such non-opaque drawing modes,
                // we must call EndDry immediately to minimize risk of any overlap.
                if (usePencil)
                {
                    inkSynchronizer.EndDry();
                    pendingDry = null;
                }
                else
                {
                    // Register to call EndDry on the next-but-one draw,
                    // by which time our dry ink will be visible.
                    deferredDryDelay             = 1;
                    CompositionTarget.Rendering += DeferredEndDry;
                }
            }

            args.DrawingSession.DrawImage(renderTarget);

            DrawForegroundText(args.DrawingSession);
            DrawSelectionBoundingRect(args.DrawingSession);
            DrawSelectionLasso(sender, args.DrawingSession);
        }
コード例 #12
0
ファイル: ImageMarkupPage.xaml.cs プロジェクト: pithline/FMS
        async private void panelcanvas_PointerReleased(object sender, PointerRoutedEventArgs e)
        {
            try
            {
                if (e.Pointer.PointerId == _penID)
                {
                    Windows.UI.Input.PointerPoint pt = e.GetCurrentPoint(PanelCanvas);


                    // Pass the pointer information to the InkManager.
                    _inkManager.ProcessPointerUp(pt);
                }

                else if (e.Pointer.PointerId == _touchID)
                {
                    // Process touch input
                    PointerPoint pt = e.GetCurrentPoint(PanelCanvas);


                    // Pass the pointer information to the InkManager.
                    _inkManager.ProcessPointerUp(pt);
                }

                _touchID = 0;
                _penID   = 0;

                var backMarkup = await ApplicationData.Current.RoamingFolder.CreateFileAsync("markupimage_" + App.Task.CaseNumber + this.listView.SelectedIndex, CreationCollisionOption.ReplaceExisting);

                if (_inkManager.GetStrokes().Count > 0)
                {
                    //buffer.Seek(0);
                    using (var os = await backMarkup.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        await _inkManager.SaveAsync(os);
                    }
                }

                // Call an application-defined function to render the ink strokes.
                e.Handled = true;
            }
            catch (Exception ex)
            {
                //new MessageDialog(ex.Message,"Error").ShowAsync();
            }
        }
コード例 #13
0
ファイル: Drawable.cs プロジェクト: e-/FlexTable
        private void PointerReleased(object sender, PointerRoutedEventArgs e)
        {
            //Debug.WriteLine("Released");
            if (e.Pointer.PointerDeviceType == PointerDeviceType.Pen)
            {
                //Debug.WriteLine("Released");
                PointerPoint pointerPoint = e.GetCurrentPoint(root);
                uint         id           = pointerPoint.PointerId;

                if (pointerDictionary.ContainsKey(id))
                {
                    // Give PointerPoint to InkManager
                    inkManager.ProcessPointerUp(pointerPoint);

                    if (inkManager.Mode == InkManipulationMode.Inking)
                    {
                        // Get rid of the little Line segments
                        NewStrokeGrid.Children.Clear();

                        // Render the new stroke
                        IReadOnlyList <InkStroke> inkStrokes = inkManager.GetStrokes();
                        InkStroke inkStroke = inkStrokes[inkStrokes.Count - 1];

                        if (IgnoreSmallStrokes && inkStroke.BoundingRect.Width < 10 && inkStroke.BoundingRect.Height < 10)
                        {
                            inkStroke.Selected = true;
                            inkManager.DeleteSelected();
                        }
                        else
                        {
                            RenderStroke(inkStroke);
                        }
                    }

                    pointerDictionary.Remove(id);

                    if (StrokeAdded != null)
                    {
                        StrokeAdded(inkManager);
                    }
                }

                e.Handled = true;
            }
        }
コード例 #14
0
        private void ClearButton_Click(object sender, RoutedEventArgs e)
        {
            var strokes = inkManager.GetStrokes();

            foreach (var stroke in strokes)
            {
                stroke.Selected = true;
            }
            inkManager.DeleteSelected();
        }
コード例 #15
0
ファイル: InkPage.xaml.cs プロジェクト: HenokG/paint-app-uwp
        private async Task OpenIt() {
            try
            {
                Windows.Storage.Pickers.FileOpenPicker fopen = new Windows.Storage.Pickers.FileOpenPicker();
                fopen.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
                fopen.FileTypeFilter.Add(".jpg");
                StorageFile file = await fopen.PickSingleFileAsync();
                using (var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    await inkManager.LoadAsync(stream);

                    if (inkManager.GetStrokes().Count > 0)
                    {
                        RenderStrokes();
                    }
                }
            }
            catch (Exception e)
            {
                var dlg = new MessageDialog("PLease Choose A Correct File");
                dlg.ShowAsync();
            }
        }
コード例 #16
0
        private void HandlePenUp(PointerRoutedEventArgs e)
        {
            //Get a pointer point relative to the inkCanvas
            PointerPoint pointerPoint = e.GetCurrentPoint(this.inkCanvas);

            //Use the InkManager to process the pointer up event
            m_inkMan.ProcessPointerUp(pointerPoint);
            //Stop live stroke rendering
            m_renderer.FinishRendering(pointerPoint);
            //Get all of the InkManger's strokes
            IReadOnlyList <InkStroke> strokes = m_inkMan.GetStrokes();
            //Get the last stroke's index
            int lastStrokeIndex = strokes.Count - 1;

            //check if the last index is valid and add a permanent ink rendering using the local InkAttributes
            if (lastStrokeIndex >= 0)
            {
                m_renderer.AddPermaInk(strokes[lastStrokeIndex], m_inkAttr);
            }
            //Clear the active pointer id
            m_activePointerId = 0;
            //Mark the event as handled
            e.Handled = true;
        }
コード例 #17
0
ファイル: EditableTitle.xaml.cs プロジェクト: e-/FlexTable
        private void Drawable_StrokeAdded(InkManager inkManager)
        {
            if (inkManager.GetStrokes().Count > 0)
            {
                var    stroke  = inkManager.GetStrokes()[0];
                Double centerX = stroke.BoundingRect.Left + stroke.BoundingRect.Width / 2;

                if (stroke.BoundingRect.Height < 30)
                {
                    foreach (UIElement element in TitleContainer.Children)
                    {
                        if (element is ComboBox)
                        {
                            ComboBox comboBox = (ComboBox)element;
                            element.Measure(new Size(1000, 1000));
                            Point position = comboBox.TransformToVisual(Root).TransformPoint(new Point(0, 0));

                            if (position.X <= centerX && centerX < position.X + comboBox.ActualWidth)
                            {
                                if (comboBox.Tag != null && ((String)comboBox.Tag).Length > 0)
                                {
                                    IEnumerable <ColumnViewModel> candidates = ViewModel.MainPageViewModel.SheetViewModel.ColumnViewModels.Where(cvm => cvm.Column.Name == (String)comboBox.Tag);

                                    if (candidates.Count() > 0)
                                    {
                                        ColumnViewModel cvm = candidates.First();
                                        ViewModel.RemoveColumnViewModel(cvm);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            drawable.RemoveAllStrokes();
        }
コード例 #18
0
        private void RenderStrokes()
        {
            var strokes = m_InkManager.GetStrokes();

            foreach (var stroke in strokes)
            {
                if (stroke.Selected)
                {
                    RenderStroke(stroke, stroke.DrawingAttributes.Color, stroke.DrawingAttributes.Size.Width * 2);
                }
                else
                {
                    RenderStroke(stroke, stroke.DrawingAttributes.Color, stroke.DrawingAttributes.Size.Width);
                }
            }
        }
コード例 #19
0
        // 文字認識
        private async void Recognize()
        {
            string text = "";

            if (inkManager.GetStrokes().Count() != 0)
            {
                var recognizer = inkManager.GetRecognizers().FirstOrDefault(r => r.Name.Contains("日本語"));
                // 文字認識エンジンの設定
                inkManager.SetDefaultRecognizer(recognizer);

                // 文字認識
                IReadOnlyList <InkRecognitionResult> results = await inkManager.RecognizeAsync(InkRecognitionTarget.All);

                text = results.Select(x => x.GetTextCandidates().First()).Aggregate((x, y) => x + y);
            }
            Result += "," + text;
        }
コード例 #20
0
        private void InstantiateCommands()
        {
            EraseCommand = new RelayCommand(() =>
            {
                _inkManager.Mode = InkManipulationMode.Erasing;
                var strokes      = _inkManager.GetStrokes();

                for (int i = 0; i < strokes.Count; i++)
                {
                    strokes[i].Selected = true;
                }

                _inkManager.DeleteSelected();

                DrawingCanvas.Background = CanvasBackground;
                DrawingCanvas.Children.Clear();
            });

            SaveCommand = new RelayCommand(SaveDrawing);
        }
コード例 #21
0
        private async Task <byte[]> GetImage()
        {
            InkManager inkMgr = MedcialInkManager;

            if (inkMgr.GetStrokes().Count == 0)
            {
                return(null);
            }
            using (var stream = new InMemoryRandomAccessStream())
            {
                await inkMgr.SaveAsync(stream);

                await stream.FlushAsync();

                stream.Seek(0);
                byte[]  bytes  = new byte[stream.Size];
                IBuffer buffer = bytes.AsBuffer();
                await stream.ReadAsync(buffer, (uint)stream.Size, InputStreamOptions.None);

                return(bytes);
            }
        }
コード例 #22
0
        public void InkCanvas_PointerReleased(object sender, PointerRoutedEventArgs e)
        {
            if (e.Pointer.PointerId == pointerId)
            {
                try
                {
                    PointerPoint pt = e.GetCurrentPoint(inkCanvas);
                    inkManager.ProcessPointerUp(pt);
                    pointerId = -1;

                    renderer.ExitLiveRendering(pt);
                    renderer.AddInk(inkManager.GetStrokes()[inkManager.GetStrokes().Count - 1]);
                }
                catch (Exception ex)
                {
                    status.Log(ex.Message);
                }
            }
        }
コード例 #23
0
ファイル: TableView.xaml.cs プロジェクト: e-/FlexTable
        void StrokeAdded(InkManager inkManager)
        {
            IReadOnlyList <InkStroke> strokes = inkManager.GetStrokes();

            this.inkManager = inkManager;

            Double centerX = strokes[0].BoundingRect.X + strokes[0].BoundingRect.Width / 2 -
                             Const.RowHeaderWidth + ActivatedScrollViewer.HorizontalOffset;

            Double screenHeight       = this.ViewModel.MainPageViewModel.Bounds.Height;
            Double columnHeaderHeight = Const.ColumnHeaderHeight;

            ColumnViewModel selectedColumnViewModel = null;

            foreach (ColumnViewModel columnViewModel in ViewModel.SheetViewModel.ColumnViewModels) // 현재 그 아래에 있는 컬럼을 찾고
            {
                if (columnViewModel.X <= centerX && centerX < columnViewModel.X + columnViewModel.Width)
                {
                    selectedColumnViewModel = columnViewModel;
                    break;
                }
            }

            if (selectedColumnViewModel == null)
            {
                drawable.RemoveAllStrokes();
                return;
            }

            if (
                strokes[0].BoundingRect.Y + strokes[0].BoundingRect.Height < columnHeaderHeight * 1.2 ||
                screenHeight - columnHeaderHeight * 1.2 < strokes[0].BoundingRect.Y

                /*(firstInkPoint.Position.Y < columnHeaderHeight
                || firstInkPoint.Position.Y > screenHeight - columnHeaderHeight) */

                ) // 컬럼 헤더에서 스트로크가 쓰여졌을때에는 다음 글자가 쓰여질때까지 기다린다
            {
                if (timer.IsEnabled)
                {
                    timer.Stop();
                }
                timer.Start();
            }
            else // 아니면 바로 실행해버린다.
            {
                if (strokes[0].BoundingRect.Width <VerticalStrokeMaxWidth && strokes[0].BoundingRect.Height> VerticalStrokeMinHeight)   // 세로 스트로크면 소팅하라는 것임
                {
                    var points     = strokes[0].GetInkPoints();
                    var firstPoint = points.First();
                    var lastPoint  = points.Last();

                    if (firstPoint.Position.Y < lastPoint.Position.Y - VerticalStrokeHeightDifferenceThreshold)
                    {
                        // 오름차순 정렬
                        this.ViewModel.SheetViewModel.Sort(selectedColumnViewModel, SortOption.Ascending);
                        this.ViewModel.MainPageViewModel.ReflectAll(ReflectReason.ColumnSorted);// 2.SelectionChanged);
                        Logger.Instance.Log("sort,tableview,pen,asc");
                    }
                    else if (lastPoint.Position.Y < firstPoint.Position.Y + VerticalStrokeHeightDifferenceThreshold)
                    {
                        // 내림차순 정렬
                        this.ViewModel.SheetViewModel.Sort(selectedColumnViewModel, SortOption.Descending);
                        this.ViewModel.MainPageViewModel.ReflectAll(ReflectReason.ColumnSorted); // 2.SelectionChanged);
                        Logger.Instance.Log("sort,tableview,pen,desc");
                    }
                }
                else if (strokes[0].BoundingRect.Width > HorizontalStrokeMinWidth && strokes[0].BoundingRect.Height < HorizontalStrokeMaxHeight)
                {
                    // filterout

                    Double centerY = ActivatedScrollViewer.VerticalOffset - columnHeaderHeight + strokes[0].BoundingRect.Top + strokes[0].BoundingRect.Height / 2;
                    ViewModel.FilterRowsByValueAtPosition(centerX, centerY);

                    Logger.Instance.Log("filter out,tableview,pen");
                }
                else // 아니면 선택하라는 것임
                {
                    Double startY = strokes[0].BoundingRect.Y + ActivatedScrollViewer.VerticalOffset - columnHeaderHeight,
                           endY   = strokes[0].BoundingRect.Y + strokes[0].BoundingRect.Height + ActivatedScrollViewer.VerticalOffset - columnHeaderHeight;

                    ViewModel.SelectRowsByRange(startY, endY);
                    Logger.Instance.Log("selection,tableview,pen");
                }
                drawable.RemoveAllStrokes();
            }
        }
コード例 #24
0
        private void Drawable_StrokeAdded(InkManager inkManager)
        {
            if (inkManager.GetStrokes().Count > 0)
            {
                List <Point> points       = inkManager.GetStrokes()[0].GetInkPoints().Select(ip => ip.Position).ToList();
                Rect         boundingRect = inkManager.GetStrokes()[0].BoundingRect;

                // 먼저 boundingRect와 겹친 row들을 모두 찾는다.
                List <Row> intersectedRows = new List <Row>();
                Int32      index           = 0;

                index = 0;
                foreach (D3Rectangle rect in HandleRectangleElement.ChildRectangles)
                {
                    Rect r = new Rect(rect.X, rect.Y, rect.Width, rect.Height);

                    if (Const.IsIntersected(r, boundingRect))
                    {
                        BarChartDatum datum = Data[index];
                        intersectedRows = intersectedRows.Concat(datum.EnvelopeRows).ToList();
                    }
                    index++;
                }

                index = 0;
                foreach (D3Rectangle rect in LegendHandleRectangleElement.ChildRectangles)
                {
                    Rect r = new Rect(rect.X + ChartAreaEndX, rect.Y, rect.Width, rect.Height);

                    if (Const.IsIntersected(r, boundingRect))
                    {
                        BarChartDatum datum = Data[index];
                        intersectedRows = intersectedRows.Concat(datum.EnvelopeRows).ToList();
                    }
                    index++;
                }

                index = 0;
                foreach (TextBlock label in HorizontalAxis.TickLabels)
                {
                    Rect r = new Rect(Canvas.GetLeft(label), Canvas.GetTop(label) + ChartAreaEndY, label.ActualWidth, label.ActualHeight);

                    if (Const.IsIntersected(r, boundingRect))
                    {
                        BarChartDatum datum = Data[index];
                        intersectedRows = intersectedRows.Concat(datum.EnvelopeRows).ToList();
                    }
                    index++;
                }

                intersectedRows = intersectedRows.Distinct().ToList();

                if (Const.IsStrikeThrough(boundingRect)) // strikethrough 및 무조건 필터아웃
                {
                    Logger.Instance.Log($"filter out,barchart,pen");
                    if (FilterOut != null && intersectedRows.Count > 0)
                    {
                        ColumnViewModel columnViewModel = Data[0].ColumnViewModel;
                        if (columnViewModel.Type == ColumnType.Categorical)
                        {
                            IEnumerable <Category> categories = intersectedRows.Select(row => row.Cells[columnViewModel.Index].Content as Category)
                                                                .OrderBy(cate => cate.Order)
                                                                .Distinct();

                            FilterOut(this, categories);
                        }
                    }
                }
                else // 아니면 무조건 셀렉션
                {
                    Logger.Instance.Log($"selection,barchart,pen");
                    if (SelectionChanged != null)
                    {
                        SelectionChanged(this, intersectedRows, SelectionChangedType.Add);//, ReflectReason2.SelectionChanged);
                    }
                }
            }

            drawable.RemoveAllStrokes();
        }
コード例 #25
0
 /// <summary>
 /// Clones the ink strokes of the specified <see cref="InkManager"/>.
 /// </summary>
 /// <param name="inkManager">
 /// The <see cref="InkManager"/>.
 /// </param>
 /// <returns>
 /// Returns a collection of cloned strokes.
 /// </returns>
 public static IEnumerable <InkStroke> CloneInkStrokes(this InkManager inkManager)
 {
     return(inkManager.GetStrokes().Select(stroke => stroke.Clone()).ToList());
 }
コード例 #26
0
        private void Drawable_StrokeAdded(InkManager inkManager)
        {
            if (inkManager.GetStrokes().Count > 0)
            {
                List <Point> points = inkManager.GetStrokes()[0].GetInkPoints().Select(ip => ip.Position).ToList();
                Rect         boundingRect = inkManager.GetStrokes()[0].BoundingRect;
                List <Row>   intersectedRows = new List <Row>();
                Int32        index = 0;
                Boolean      horizontalAxisStroke = false, legendStroke = false;

                index = 0;
                foreach (D3Rectangle rect in LegendHandleRectangleElement.ChildRectangles)
                {
                    Rect r = new Rect(rect.X + ChartAreaEndX, rect.Y, rect.Width, rect.Height);

                    if (Const.IsIntersected(r, boundingRect))
                    {
                        if (IsCNN)
                        {
                            RemoveColumnViewModel(this, Data[index].Key.ToString());
                            drawable.RemoveAllStrokes();
                        }
                        else
                        {
                            LineChartDatum datum = Data[index];
                            intersectedRows = intersectedRows.Concat(datum.EnvelopeRows).ToList();
                            legendStroke    = true;
                        }
                    }
                    index++;
                }

                index = 0;
                foreach (TextBlock label in HorizontalAxis.TickLabels)
                {
                    Rect r = new Rect(Canvas.GetLeft(label), Canvas.GetTop(label) + ChartAreaEndY, label.ActualWidth, label.ActualHeight);

                    if (Const.IsIntersected(r, boundingRect))
                    {
                        Object xScaleCategory = XScale.Domain[index];
                        intersectedRows = intersectedRows.Concat(
                            Data.SelectMany(d => d.DataPoints).Where(dp => dp.Item1 == xScaleCategory)
                            .Where(dp => dp.EnvelopeRows != null)
                            .SelectMany(dp => dp.EnvelopeRows)
                            ).ToList();
                        horizontalAxisStroke = true;
                    }
                    index++;
                }

                index = 0;
                foreach (LineChartDatum datum in Data)
                {
                    List <Point> circlePoints = EnvelopeLineCoordinateGetter(datum, index);

                    if (circlePoints.Exists(cp => cp.X >= 0 && boundingRect.Contains(cp))) // 하나라도 포함되는 포인트가 있으면 예를 선택
                    {
                        intersectedRows = intersectedRows.Concat(datum.EnvelopeRows).ToList();
                    }

                    index++;
                }

                intersectedRows = intersectedRows.Distinct().ToList();

                if (Const.IsStrikeThrough(boundingRect)) // strikethrough 및 무조건 필터아웃
                {
                    if (FilterOut != null && intersectedRows.Count > 0)
                    {
                        Logger.Instance.Log($"filter out,linechart,pen");
                        if (horizontalAxisStroke && !legendStroke)
                        {
                            IEnumerable <Category> categories = intersectedRows
                                                                .Select(row => row.Cells[SecondColumnViewModel.Index].Content as Category)
                                                                .Distinct()
                                                                .OrderBy(cate => cate.Order);

                            FilterOut(this, categories);
                        }
                        else if (legendStroke && !horizontalAxisStroke && FirstColumnViewModel.Type == ColumnType.Categorical)
                        {
                            IEnumerable <Category> categories = intersectedRows
                                                                .Select(row => row.Cells[FirstColumnViewModel.Index].Content as Category)
                                                                .Distinct()
                                                                .OrderBy(cate => cate.Order);

                            FilterOut(this, categories);
                        }
                    }
                }
                else // 아니면 무조건 셀렉션
                {
                    Logger.Instance.Log($"selection,linechart,pen");
                    if (SelectionChanged != null)
                    {
                        SelectionChanged(this, intersectedRows, SelectionChangedType.Add);//, ReflectReason2.SelectionChanged);
                    }
                }
            }

            drawable.RemoveAllStrokes();
        }
コード例 #27
0
 /// <summary>
 /// Checks whether any strokes are selected.
 /// </summary>
 /// <param name="inkManager">
 /// The <see cref="InkManager"/>.
 /// </param>
 /// <returns>
 /// Returns true if any strokes are selected; else false.
 /// </returns>
 public static bool AnyStrokesSelected(this InkManager inkManager)
 {
     return(inkManager.GetStrokes().Any(stroke => stroke.Selected));
 }
コード例 #28
0
 public IReadOnlyList <InkStroke> GetStrokes()
 {
     return(inkManager.GetStrokes());
 }
コード例 #29
0
        private void Drawable_StrokeAdded(InkManager inkManager)
        {
            if (inkManager.GetStrokes().Count > 0)
            {
                List <Point> points       = inkManager.GetStrokes()[0].GetInkPoints().Select(ip => ip.Position).ToList();
                Rect         boundingRect = inkManager.GetStrokes()[0].BoundingRect;

                Int32      index = 0;
                List <Row> intersectedRows = new List <Row>();
                Boolean    horizontalAxisStroke = false, legendStroke = false;

                index = 0;
                foreach (D3Rectangle rect in HandleRectangleElement.ChildRectangles)
                {
                    Rect r = new Rect(rect.X, rect.Y, rect.Width, rect.Height);

                    if (Const.IsIntersected(r, boundingRect))
                    {
                        GroupedBarChartDatum datum = ChartData[index].Parent;
                        intersectedRows = intersectedRows.Concat(datum.EnvelopeRows).ToList();
                    }
                    index++;
                }


                index = 0;
                foreach (D3Rectangle rect in LegendHandleRectangleElement.ChildRectangles)
                {
                    Rect r = new Rect(rect.X + ChartAreaEndX, rect.Y, rect.Width, rect.Height);

                    if (Const.IsIntersected(r, boundingRect))
                    {
                        if (secondColumnViewModel != null)
                        {
                            BarChartDatum     datum = LegendData[index];
                            IEnumerable <Row> rows  = ChartData.Where(cd => cd.Key == datum.Key).SelectMany(cd => cd.EnvelopeRows);
                            intersectedRows = intersectedRows.Concat(rows).ToList();
                            legendStroke    = true;
                        }
                        else
                        {
                            RemoveColumnViewModel(this, LegendData[index].Key.ToString());
                            drawable.RemoveAllStrokes();
                            return;
                        }
                    }
                    index++;
                }

                index = 0;
                foreach (TextBlock label in HorizontalAxis.TickLabels)
                {
                    Rect r = new Rect(Canvas.GetLeft(label), Canvas.GetTop(label) + ChartAreaEndY, label.ActualWidth, label.ActualHeight);

                    if (Const.IsIntersected(r, boundingRect))
                    {
                        GroupedBarChartDatum datum = Data[index];
                        intersectedRows      = intersectedRows.Concat(datum.EnvelopeRows).ToList();
                        horizontalAxisStroke = true;
                    }
                    index++;
                }

                if (Const.IsStrikeThrough(boundingRect)) // strikethrough 및 무조건 필터아웃
                {
                    if (FilterOut != null && intersectedRows.Count > 0)
                    {
                        Logger.Instance.Log($"filter out,groupedbarchart,pen");
                        if (horizontalAxisStroke && !legendStroke)
                        {
                            IEnumerable <Category> categories = intersectedRows
                                                                .Select(row => row.Cells[firstColumnViewModel.Index].Content as Category)
                                                                .Distinct()
                                                                .OrderBy(cate => cate.Order);

                            FilterOut(this, categories);
                        }
                        else if (legendStroke && !horizontalAxisStroke)
                        {
                            IEnumerable <Category> categories = intersectedRows
                                                                .Select(row => row.Cells[secondColumnViewModel.Index].Content as Category)
                                                                .Distinct()
                                                                .OrderBy(cate => cate.Order);

                            FilterOut(this, categories);
                        }
                        else
                        {
                            //throw new Exception("ojioij");
                            //FilterOut(this, String.Format(FlexTable.Const.Loader.GetString("FilterOutMessage"), intersectedRows.Count()), intersectedRows);
                        }
                    }
                }
                else // 하나라도 선택 안된게 있으면 선택
                {
                    if (SelectionChanged != null)
                    {
                        Logger.Instance.Log($"selection,groupedbarchart,pen");
                        SelectionChanged(this, intersectedRows, SelectionChangedType.Add);//, ReflectReason2.SelectionChanged);
                    }
                }
            }

            drawable.RemoveAllStrokes();
        }
コード例 #30
0
        protected override void OnPointerReleased(PointerRoutedEventArgs args)
        {
            if (args.Pointer.PointerDeviceType != PointerDeviceType.Pen && hasPen)
            {
                return;
            }

            inkManager.ProcessPointerUp(args.GetCurrentPoint(this));

            // Render the most recent InkStroke
            IReadOnlyList <InkStroke> inkStrokes = inkManager.GetStrokes();
            InkStroke inkStroke = inkStrokes[inkStrokes.Count - 1];

            // Create SolidColorBrush used for all segments in the stroke
            Brush brush = new SolidColorBrush(inkStroke.DrawingAttributes.Color);

            // Get the segments
            IReadOnlyList <InkStrokeRenderingSegment> inkSegments = inkStroke.GetRenderingSegments();

            // Notice loop starts at 1
            for (int i = 1; i < inkSegments.Count; i++)
            {
                InkStrokeRenderingSegment inkSegment = inkSegments[i];

                // Create a BezierSegment from the points
                BezierSegment bezierSegment = new BezierSegment
                {
                    Point1 = inkSegment.BezierControlPoint1,
                    Point2 = inkSegment.BezierControlPoint2,
                    Point3 = inkSegment.Position
                };

                // Create a PathFigure that begins at the preceding Position
                PathFigure pathFigure = new PathFigure
                {
                    StartPoint = inkSegments[i - 1].Position,
                    IsClosed   = false,
                    IsFilled   = false
                };
                pathFigure.Segments.Add(bezierSegment);

                // Create a PathGeometry with that PathFigure
                PathGeometry pathGeometry = new PathGeometry();
                pathGeometry.Figures.Add(pathFigure);

                // Create a Path with that PathGeometry
                Path path = new Path
                {
                    Stroke          = brush,
                    StrokeThickness = inkStroke.DrawingAttributes.Size.Width *
                                      inkSegment.Pressure,
                    StrokeStartLineCap = PenLineCap.Round,
                    StrokeEndLineCap   = PenLineCap.Round,
                    Data = pathGeometry
                };

                // Add it to the Grid
                contentGrid.Children.Add(path);
            }
            base.OnPointerReleased(args);
        }