chr
2024-08-07 22beee93f14d042aa184148c53efb79e23416526
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using SolidWorks.Interop.sldworks;
 
namespace PdmSwPlugin.Main.EventHandler
{
    public class PartDocEventHandler : BaseEventHandler
    {
        PartDoc doc;
        BaseAttacher swPlugin;
 
        public PartDocEventHandler(ModelDoc2 modDoc, BaseAttacher addin) : base(modDoc, addin)
        {
            doc = (PartDoc)document;
            swPlugin = addin;
        }
 
        override public bool AttachEventHandlers()
        {
            doc.DestroyNotify += new DPartDocEvents_DestroyNotifyEventHandler(OnDestroy);
            doc.NewSelectionNotify += new DPartDocEvents_NewSelectionNotifyEventHandler(OnNewSelection);
            // 自定义属性变更事件
            doc.ChangeCustomPropertyNotify += new DPartDocEvents_ChangeCustomPropertyNotifyEventHandler(swPlugin.OnActiveDocCustomPropertyChanged);
            ConnectModelViews();
            return true;
        }
 
        override public bool DetachEventHandlers()
        {
            doc.DestroyNotify -= new DPartDocEvents_DestroyNotifyEventHandler(OnDestroy);
            doc.NewSelectionNotify -= new DPartDocEvents_NewSelectionNotifyEventHandler(OnNewSelection);
 
            doc.ChangeCustomPropertyNotify -= new DPartDocEvents_ChangeCustomPropertyNotifyEventHandler(swPlugin.OnActiveDocCustomPropertyChanged);
 
            DisconnectModelViews();
 
            userAddIn.DetachModelEventHandler(document);
            return true;
        }
 
        //Event Handlers
        public int OnDestroy()
        {
            swPlugin.OnDocDestory((ModelDoc2)doc);
            DetachEventHandlers();
            return 0;
        }
 
        public int OnNewSelection()
        {
            return 0;
        }
    }
}