This repository has been archived on 2023-01-27. You can view files and clone it, but cannot push or open issues or pull requests.
cad/ref/xcad/docs/_src/EventsAddIn.cs
2022-10-15 19:16:08 +02:00

75 lines
2.0 KiB
C#

using System;
using System.Runtime.InteropServices;
using Xarial.XCad;
using Xarial.XCad.Annotations;
using Xarial.XCad.Data;
using Xarial.XCad.Documents;
using Xarial.XCad.Documents.Services;
using Xarial.XCad.SolidWorks;
namespace Xarial.XCad.Documentation
{
//--- EventHandlers
public class MyDocumentHandler : IDocumentHandler
{
private IXDocument m_Model;
private IXProperty m_DescPrp;
private IXDimension m_D1Dim;
public void Init(IXApplication app, IXDocument model)
{
m_Model = model;
m_DescPrp = m_Model.Properties["Description"];
m_D1Dim = m_Model.Dimensions["D1@Sketch1"];
m_Model.Closing += OnModelClosing;
m_Model.Selections.NewSelection += OnNewSelection;
m_DescPrp.ValueChanged += OnPropertyValueChanged;
m_D1Dim.ValueChanged += OnDimensionValueChanged;
}
private void OnModelClosing(IXDocument doc)
{
//TODO: handle closing
}
private void OnNewSelection(IXDocument doc, IXSelObject selObject)
{
//TODO: handle new selection
}
private void OnPropertyValueChanged(IXProperty prp, object newValue)
{
//TODO: handle property change
}
private void OnDimensionValueChanged(IXDimension dim, double newVal)
{
//TODO: handle dimension change
}
public void Dispose()
{
m_Model.Closing -= OnModelClosing;
m_Model.Selections.NewSelection -= OnNewSelection;
m_DescPrp.ValueChanged -= OnPropertyValueChanged;
m_D1Dim.ValueChanged -= OnDimensionValueChanged;
}
}
//---
[ComVisible(true), Guid("A57F10A3-D23F-40C9-92DA-D4AE92E4FE8C")]
public class EventsAddIn : SwAddInEx
{
public override void OnConnect()
{
//--- RegisterHandler
Application.Documents.RegisterHandler<MyDocumentHandler>();
//---
}
}
}