|
@@ -9,6 +9,8 @@ using System.Windows.Ink;
|
9
|
9
|
using System.Windows.Input;
|
10
|
10
|
using System.Windows.Media;
|
11
|
11
|
|
|
12
|
+using TStudyDigitalPen.HID;
|
|
13
|
+
|
12
|
14
|
using XHWK.Model;
|
13
|
15
|
|
14
|
16
|
namespace XHWK.WKTool
|
|
@@ -42,6 +44,7 @@ namespace XHWK.WKTool
|
42
|
44
|
public PracticeWindow()
|
43
|
45
|
{
|
44
|
46
|
InitializeComponent();
|
|
47
|
+ InitPen();
|
45
|
48
|
}
|
46
|
49
|
public void Initialize(string _imgPath = null)
|
47
|
50
|
{
|
|
@@ -434,6 +437,355 @@ namespace XHWK.WKTool
|
434
|
437
|
});
|
435
|
438
|
}))).Start();
|
436
|
439
|
}
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+ #region 点阵笔相关
|
|
443
|
+ #region 值初始化
|
|
444
|
+ // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
|
|
445
|
+
|
|
446
|
+ /// <summary>
|
|
447
|
+ /// A4点阵纸点阵宽度
|
|
448
|
+ /// </summary>
|
|
449
|
+ private const int A4_WIDTH = 5600;
|
|
450
|
+
|
|
451
|
+ /// <summary>
|
|
452
|
+ /// A4点阵纸点阵高度
|
|
453
|
+ /// </summary>
|
|
454
|
+ private const int A4_HEIGHT = 7920;
|
|
455
|
+
|
|
456
|
+ ///// <summary>
|
|
457
|
+ ///// 画板
|
|
458
|
+ ///// </summary>
|
|
459
|
+ //private Graphics graphics;
|
|
460
|
+
|
|
461
|
+ /// <summary>
|
|
462
|
+ /// 笔画坐标数组
|
|
463
|
+ /// </summary>
|
|
464
|
+ private List<System.Drawing.Point> stroke;
|
|
465
|
+
|
|
466
|
+ /// <summary>
|
|
467
|
+ /// 笔序列号
|
|
468
|
+ /// </summary>
|
|
469
|
+ private string penSerial;
|
|
470
|
+
|
|
471
|
+ /// <summary>
|
|
472
|
+ /// 笔是否在点
|
|
473
|
+ /// </summary>
|
|
474
|
+ private bool isPenDown;
|
|
475
|
+
|
|
476
|
+ //当前点阵地址
|
|
477
|
+ private string currentPageSerial = string.Empty;
|
|
478
|
+
|
|
479
|
+ //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
|
|
480
|
+ //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
|
|
481
|
+ private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
|
|
482
|
+ #endregion
|
|
483
|
+ public void InitPen()
|
|
484
|
+ {
|
|
485
|
+ stroke = new List<System.Drawing.Point>();
|
|
486
|
+ //获取点阵笔实例,并绑定点阵笔事件
|
|
487
|
+ //将授权文件内容传入,获取点阵笔对象实例
|
|
488
|
+ APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
|
|
489
|
+ //绑定笔连接事件
|
|
490
|
+ APP.digitalPen.PenConnected += OnPenConnect;
|
|
491
|
+ //绑定笔断开事件
|
|
492
|
+ APP.digitalPen.PenDisconnect += OnPenDisconnect;
|
|
493
|
+ //绑定笔书写输出坐标事件
|
|
494
|
+ APP.digitalPen.PenCoordinate += OnPenCoordinate;
|
|
495
|
+ //绑定抬笔事件
|
|
496
|
+ APP.digitalPen.PenUp += OnPenUp;
|
|
497
|
+ //绑定落笔事件
|
|
498
|
+ APP.digitalPen.PenDown += OnPenDown;
|
|
499
|
+ APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
|
|
500
|
+ APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
|
|
501
|
+ //完成初始化点阵笔,开始与点阵笔通信
|
|
502
|
+ ERROR_CODE ER = APP.digitalPen.Start();
|
|
503
|
+
|
|
504
|
+ ////绑定笔在新的点阵地址页面书写事件
|
|
505
|
+ //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
|
|
506
|
+ ////绑定笔信息事件
|
|
507
|
+ //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
|
|
508
|
+ //启动接收笔数据,完成初始化工作
|
|
509
|
+ //ERROR_CODE rc = APP.digitalPen.Start();
|
|
510
|
+ //判断是否成功
|
|
511
|
+ if (ER != ERROR_CODE.ERROR_OK)
|
|
512
|
+ {
|
|
513
|
+ MessageWindow.Show("初始化失败,授权过期,返回值:" + ER.ToString());
|
|
514
|
+ }
|
|
515
|
+ }
|
|
516
|
+
|
|
517
|
+ /// <summary>
|
|
518
|
+ /// 落笔
|
|
519
|
+ /// </summary>
|
|
520
|
+ /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
|
|
521
|
+ /// <param name="penSerial">点阵笔序列号</param>
|
|
522
|
+ /// <param name="penType">点阵笔型号编号</param>
|
|
523
|
+ private void OnPenDown(ulong time, string penSerial, int penType)
|
|
524
|
+ {
|
|
525
|
+ if (CheckAccess())
|
|
526
|
+ {
|
|
527
|
+ Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
|
|
528
|
+ Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
|
|
529
|
+ }
|
|
530
|
+ else
|
|
531
|
+ {
|
|
532
|
+ isPenDown = true;
|
|
533
|
+ }
|
|
534
|
+ }
|
|
535
|
+
|
|
536
|
+ /// <summary>
|
|
537
|
+ /// 抬笔
|
|
538
|
+ /// </summary>
|
|
539
|
+ /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
|
|
540
|
+ /// <param name="penSerial">点阵笔序列号</param>
|
|
541
|
+ /// <param name="penType">点阵笔型号编号</param>
|
|
542
|
+ private void OnPenUp(ulong time, string penSerial, int penType)
|
|
543
|
+ {
|
|
544
|
+ if (CheckAccess())
|
|
545
|
+ {
|
|
546
|
+ Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
|
|
547
|
+ Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
|
|
548
|
+ }
|
|
549
|
+ else
|
|
550
|
+ {
|
|
551
|
+ isPenDown = false;
|
|
552
|
+ APP.PenSerial = penSerial;
|
|
553
|
+
|
|
554
|
+ stroke.Clear();
|
|
555
|
+ }
|
|
556
|
+ //if (APP.pageData.currpage > 0)
|
|
557
|
+ //{
|
|
558
|
+ // Dispatcher.Invoke(new Action(() =>
|
|
559
|
+ // {
|
|
560
|
+ // myblackboard.changepages(0, 0, true, Color, PenSize, APP.pageData.currpage - 1, 0);
|
|
561
|
+ // }));
|
|
562
|
+ //}
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+ }
|
|
566
|
+
|
|
567
|
+ /// <summary>
|
|
568
|
+ /// 笔断开
|
|
569
|
+ /// </summary>
|
|
570
|
+ /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
|
|
571
|
+ /// <param name="penSerial">点阵笔序列号</param>
|
|
572
|
+ /// <param name="penType">点阵笔型号编号</param>
|
|
573
|
+ private void OnPenDisconnect(ulong time, string penSerial, int penType)
|
|
574
|
+ {
|
|
575
|
+ if (CheckAccess())
|
|
576
|
+ {
|
|
577
|
+ Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
|
|
578
|
+ Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
|
|
579
|
+ }
|
|
580
|
+ else
|
|
581
|
+ {
|
|
582
|
+ APP.PenSerial = penSerial;
|
|
583
|
+ APP.PenStatus = false;
|
|
584
|
+ //UpdateDevStatus();
|
|
585
|
+ ////Dispatcher.Invoke(new Action(() =>
|
|
586
|
+ ////{
|
|
587
|
+ //// txbNotConnected.Text = "未连接";
|
|
588
|
+ //// txbNotConnecteds.Text = "未连接";
|
|
589
|
+ ////}));
|
|
590
|
+ }
|
|
591
|
+ }
|
|
592
|
+
|
|
593
|
+ /// <summary>
|
|
594
|
+ /// 笔连接
|
|
595
|
+ /// </summary>
|
|
596
|
+ /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
|
|
597
|
+ /// <param name="penSerial">点阵笔序列号</param>
|
|
598
|
+ /// <param name="penType">点阵笔型号编号</param>
|
|
599
|
+ private void OnPenConnect(ulong time, string penSerial, int penType)
|
|
600
|
+ {
|
|
601
|
+ if (CheckAccess())
|
|
602
|
+ {
|
|
603
|
+ Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
|
|
604
|
+ Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
|
|
605
|
+ }
|
|
606
|
+ else
|
|
607
|
+ {
|
|
608
|
+ APP.PenSerial = penSerial;
|
|
609
|
+ APP.PenStatus = true;
|
|
610
|
+ this.penSerial = penSerial;
|
|
611
|
+ //连接后,在获取笔数据前,可以清除笔内的历史数据
|
|
612
|
+ //APP.digitalPen.ClearMemory(penSerial);
|
|
613
|
+
|
|
614
|
+ //开始接收笔数据
|
|
615
|
+ APP.digitalPen.GetPenData(penSerial);
|
|
616
|
+ //UpdateDevStatus();
|
|
617
|
+ ////Dispatcher.Invoke(new Action(() =>
|
|
618
|
+ ////{
|
|
619
|
+ //// txbNotConnected.Text = "已连接";
|
|
620
|
+ //// txbNotConnecteds.Text = "已连接";
|
|
621
|
+ ////}));
|
|
622
|
+
|
|
623
|
+ }
|
|
624
|
+ }
|
|
625
|
+ /// <summary>
|
|
626
|
+ /// 电池电量
|
|
627
|
+ /// </summary>
|
|
628
|
+ /// <param name="time"></param>
|
|
629
|
+ /// <param name="penSerial"></param>
|
|
630
|
+ /// <param name="penType"></param>
|
|
631
|
+ /// <param name="capacity"></param>
|
|
632
|
+ private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
|
|
633
|
+ {
|
|
634
|
+ if (CheckAccess())
|
|
635
|
+ {
|
|
636
|
+ Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
|
|
637
|
+ Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
|
|
638
|
+ }
|
|
639
|
+ else
|
|
640
|
+ {
|
|
641
|
+ //System.Windows.MessageWindow.Show("电池电量:" + capacity.ToString());
|
|
642
|
+ }
|
|
643
|
+ }
|
|
644
|
+
|
|
645
|
+ /// <summary>
|
|
646
|
+ /// 已用存储
|
|
647
|
+ /// </summary>
|
|
648
|
+ /// <param name="time"></param>
|
|
649
|
+ /// <param name="penSerial"></param>
|
|
650
|
+ /// <param name="penType"></param>
|
|
651
|
+ /// <param name="fillLevel"></param>
|
|
652
|
+ private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
|
|
653
|
+ {
|
|
654
|
+ if (CheckAccess())
|
|
655
|
+ {
|
|
656
|
+ Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
|
|
657
|
+ Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
|
|
658
|
+ }
|
|
659
|
+ else
|
|
660
|
+ {
|
|
661
|
+ //System.Windows.MessageWindow.Show("存储:" + fillLevel.ToString());
|
|
662
|
+ }
|
|
663
|
+ }
|
|
664
|
+
|
|
665
|
+ /// <summary>
|
|
666
|
+ /// 笔书写,收到坐标
|
|
667
|
+ /// </summary>
|
|
668
|
+ /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
|
|
669
|
+ /// <param name="penSerial">点阵笔序列号</param>
|
|
670
|
+ /// <param name="penType">点阵笔型号编号</param>
|
|
671
|
+ /// <param name="pageSerial">点阵地址</param>
|
|
672
|
+ /// <param name="cx">x坐标</param>
|
|
673
|
+ /// <param name="cy">y坐标</param>
|
|
674
|
+ /// <param name="force">压力值</param>
|
|
675
|
+ private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
|
|
676
|
+ {
|
|
677
|
+ if (CheckAccess())
|
|
678
|
+ {
|
|
679
|
+ Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
|
|
680
|
+ Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
|
|
681
|
+ }
|
|
682
|
+ else
|
|
683
|
+ {
|
|
684
|
+ //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
|
|
685
|
+ if (!isPenDown)
|
|
686
|
+ {
|
|
687
|
+ return;
|
|
688
|
+ }
|
|
689
|
+ stroke.Add(new System.Drawing.Point(cx, cy));
|
|
690
|
+
|
|
691
|
+ double PropW = blackboard_canvas.ActualWidth / A4_HEIGHT;
|
|
692
|
+ double PropH = blackboard_canvas.ActualHeight / A4_WIDTH;
|
|
693
|
+ //点
|
|
694
|
+ double testX = cy * PropW;
|
|
695
|
+ double testY = (A4_WIDTH - cx) * PropH;
|
|
696
|
+ //pageSerial //点阵IP地址 与打印的页面关联
|
|
697
|
+ if (APP.pageData.currpage > 0)
|
|
698
|
+ {
|
|
699
|
+ Dispatcher.Invoke(new Action(() =>
|
|
700
|
+ {
|
|
701
|
+ float Pressure = force / 100f;
|
|
702
|
+ //添加笔画
|
|
703
|
+ //myblackboard.changepages(testX, testY, false, Color, PenSize, APP.pageData.currpage - 1, Pressure);
|
|
704
|
+
|
|
705
|
+ //设置鼠标位置
|
|
706
|
+ if (testX > 0 && testY > 0)
|
|
707
|
+ {
|
|
708
|
+ //System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(testX, testY - scroMain.VerticalOffset));
|
|
709
|
+ SetCursorPos((int)testX, (int)testY);
|
|
710
|
+ }
|
|
711
|
+ }));
|
|
712
|
+ }
|
|
713
|
+
|
|
714
|
+ }
|
|
715
|
+ }
|
|
716
|
+
|
|
717
|
+ /// <summary>
|
|
718
|
+ /// 停止笔
|
|
719
|
+ /// </summary>
|
|
720
|
+ public void StopDigitalPen()
|
|
721
|
+ {
|
|
722
|
+ //停止,释放资源
|
|
723
|
+ APP.digitalPen.Stop();
|
|
724
|
+ }
|
|
725
|
+ /// <summary>
|
|
726
|
+ /// 清空笔内存储
|
|
727
|
+ /// </summary>
|
|
728
|
+ public void ClearPenStorage()
|
|
729
|
+ {
|
|
730
|
+ if (!string.IsNullOrEmpty(penSerial))
|
|
731
|
+ {
|
|
732
|
+ APP.digitalPen.ClearMemory(penSerial);
|
|
733
|
+ }
|
|
734
|
+ }
|
|
735
|
+ /// <summary>
|
|
736
|
+ /// 获取剩余电量
|
|
737
|
+ /// </summary>
|
|
738
|
+ public void GetPenElectricityQuantity()
|
|
739
|
+ {
|
|
740
|
+ if (!string.IsNullOrEmpty(penSerial))
|
|
741
|
+ {
|
|
742
|
+ APP.digitalPen.GetBatteryCapacity(penSerial);
|
|
743
|
+ }
|
|
744
|
+ }
|
|
745
|
+
|
|
746
|
+ /// <summary>
|
|
747
|
+ /// 获取存储空间
|
|
748
|
+ /// </summary>
|
|
749
|
+ public void GetUsedStorage()
|
|
750
|
+ {
|
|
751
|
+ if (!string.IsNullOrEmpty(penSerial))
|
|
752
|
+ {
|
|
753
|
+ APP.digitalPen.GetMemoryFillLevel(penSerial);
|
|
754
|
+ }
|
|
755
|
+ }
|
|
756
|
+
|
|
757
|
+ /// <summary>
|
|
758
|
+ /// 开启悬浮
|
|
759
|
+ /// </summary>
|
|
760
|
+ public void 开启悬浮()
|
|
761
|
+ {
|
|
762
|
+ if (!string.IsNullOrEmpty(penSerial))
|
|
763
|
+ {
|
|
764
|
+ APP.digitalPen.SetPenHoverMode(true, penSerial);
|
|
765
|
+ }
|
|
766
|
+ }
|
|
767
|
+
|
|
768
|
+ /// <summary>
|
|
769
|
+ /// 关闭悬浮
|
|
770
|
+ /// </summary>
|
|
771
|
+ public void 关闭悬浮()
|
|
772
|
+ {
|
|
773
|
+ if (!string.IsNullOrEmpty(penSerial))
|
|
774
|
+ {
|
|
775
|
+ APP.digitalPen.SetPenHoverMode(false, penSerial);
|
|
776
|
+ }
|
|
777
|
+ }
|
|
778
|
+
|
|
779
|
+ /// <summary>
|
|
780
|
+ /// 引用user32.dll动态链接库(windows api),
|
|
781
|
+ /// 使用库中定义 API:SetCursorPos
|
|
782
|
+ /// 设置光标位置
|
|
783
|
+ /// </summary>
|
|
784
|
+ [System.Runtime.InteropServices.DllImport("user32.dll")]
|
|
785
|
+ private static extern int SetCursorPos(int x, int y);
|
|
786
|
+
|
|
787
|
+ #endregion
|
|
788
|
+
|
437
|
789
|
}
|
438
|
790
|
}
|
439
|
791
|
|