Files
RevitArchive/HYJigPro/XUiJigBase.cs

342 lines
11 KiB
C#
Raw Normal View History

2026-02-23 14:58:05 +08:00
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace HYJig
{
public class XUiJigBase : WndMsgManager, IDisposable
{
public XUiJigBase(UIDocument uiDoc)
: base(uiDoc)
{
base.OnMouseActivity += this.XUiJigBase_OnMouseActivity;
this.OnPaintEvent = (PaintEventHandler)Delegate.Combine(this.OnPaintEvent, new PaintEventHandler(this.method_12));
this.OnKeyDownEvent = (KeyEventHandler)Delegate.Combine(this.OnKeyDownEvent, new KeyEventHandler(this.method_10));
this.OnFocusEvent = (WndMsgManager.FocusChangeEvent)Delegate.Combine(this.OnFocusEvent, new WndMsgManager.FocusChangeEvent(this.method_11));
}
public new void Dispose()
{
base.Dispose();
base.OnMouseActivity -= this.XUiJigBase_OnMouseActivity;
this.OnPaintEvent = (PaintEventHandler)Delegate.Remove(this.OnPaintEvent, new PaintEventHandler(this.method_12));
this.OnKeyDownEvent = (KeyEventHandler)Delegate.Remove(this.OnKeyDownEvent, new KeyEventHandler(this.method_10));
this.OnFocusEvent = (WndMsgManager.FocusChangeEvent)Delegate.Remove(this.OnFocusEvent, new WndMsgManager.FocusChangeEvent(this.method_11));
if (this.m_prompDlg != null)
{
this.m_prompDlg.Dispose();
this.m_prompDlg = null;
}
}
public void SetPromptState(string strPrompt, bool bShowPrompt, string strInput, bool bShowInput)
{
if (bShowPrompt || bShowInput)
{
if (this.m_prompDlg == null)
{
System.Drawing.Color viewBackgroundReverseColor = WndMsgManager.GetViewBackgroundReverseColor(base.UiDoc.Application.Application);
this.m_prompDlg = new PromptDlg(this.m_hMDIActiveChildClientWnd, viewBackgroundReverseColor);
this.m_prompDlg.Opacity = 0.5;
}
this.m_prompDlg.SetDlgState(strPrompt, bShowPrompt, strInput, bShowInput);
}
else if (this.m_prompDlg != null)
{
this.m_prompDlg.Dispose();
this.m_prompDlg = null;
}
}
public static int TwoPointDist(Point pt1, Point pt2)
{
int num = pt1.X - pt2.X;
int num2 = pt1.Y - pt2.Y;
return (int)Math.Sqrt((double)(num * num + num2 * num2));
}
public static double TwoPointAngle(Point ptFrom, Point ptTo)
{
int num = ptTo.X - ptFrom.X;
int num2 = ptTo.Y - ptFrom.Y;
double num3;
if (num == 0)
{
num3 = ((num2 > 0) ? 4.71238898038469 : 1.5707963267948966);
}
else
{
double num4 = (double)num2 / (double)num;
double num5 = Math.Atan(-num4);
if (num5 < 0.0)
{
num5 += 6.2831853071795862;
}
num3 = num5;
}
return num3;
}
public static Point OffsetPoint(Point ptFrom, double dAngle, int nDistance)
{
int num = (int)((double)nDistance * Math.Cos(dAngle));
int num2 = (int)((double)nDistance * Math.Sin(dAngle));
Point point = new Point(ptFrom.X + num, ptFrom.Y - num2);
return point;
}
public static void SortTwoPoint(ref Point pt1, ref Point pt2)
{
if (pt1.X == pt2.X)
{
if (pt1.Y < pt2.Y)
{
Point point = pt1;
pt1 = pt2;
pt2 = point;
}
}
else if (pt1.X > pt2.X)
{
Point point2 = pt1;
pt1 = pt2;
pt2 = point2;
}
}
public Point Revit2Client(XYZ point)
{
try
{
Point point2 = this.Revit2Screen(point);
JigFuncs.Screen2Client(base.JigForm.Handle, ref point2);
return point2;
}
catch
{
}
return Point.Empty;
}
public XYZ Client2Revit(Point point)
{
try
{
JigFuncs.Client2Screen(base.JigForm.Handle, ref point);
return this.Screen2Revit(point);
}
catch
{
}
return null;
}
public Point Revit2Screen(XYZ point)
{
try
{
int num = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
JigFuncs.GetRevitWndRectangle(base.UiViewActive, ref num, ref num2, ref num3, ref num4);
Transform inverse = base.ViewActive.CropBox.Transform.Inverse;
IList<XYZ> zoomCorners = base.UiViewActive.GetZoomCorners();
XYZ xyz = inverse.OfPoint(point);
XYZ xyz2 = inverse.OfPoint(zoomCorners[0]);
XYZ xyz3 = inverse.OfPoint(zoomCorners[1]);
double num5 = (double)(num3 - num) / (xyz3.X - xyz2.X);
int num6 = num + (int)((xyz.X - xyz2.X) * num5);
int num7 = num2 + (int)((xyz3.Y - xyz.Y) * num5);
return new Point(num6, num7);
}
catch
{
}
return Point.Empty;
}
public XYZ Screen2Revit(Point point)
{
try
{
int num = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
JigFuncs.GetRevitWndRectangle(base.UiViewActive, ref num, ref num2, ref num3, ref num4);
Transform inverse = base.ViewActive.CropBox.Transform.Inverse;
IList<XYZ> zoomCorners = base.UiViewActive.GetZoomCorners();
XYZ xyz = inverse.OfPoint(zoomCorners[0]);
XYZ xyz2 = inverse.OfPoint(zoomCorners[1]);
double num5 = (xyz2.Y - xyz.Y) / (double)(num4 - num2);
double num6 = xyz.X + (double)(point.X - num) * num5;
double num7 = xyz.Y + (double)(num4 - point.Y) * num5;
XYZ xyz3 = new XYZ(num6, num7, 0.0);
Transform transform = base.ViewActive.CropBox.Transform;
return transform.OfPoint(xyz3);
}
catch
{
}
return null;
}
private void XUiJigBase_OnMouseActivity(object sender, MouseEventArgs e)
{
this.m_ptCur = e.Location;
if (this.m_prompDlg != null)
{
Size size = new Size(2, 2);
Point ptCur = this.m_ptCur;
JigFuncs.Client2Screen(base.JigForm.Handle, ref ptCur);
int num = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
JigFuncs.GetRevitWndRectangle(base.UiViewActive, ref num, ref num2, ref num3, ref num4);
if (num >= ptCur.X || num3 <= ptCur.X || num2 >= ptCur.Y || num4 <= ptCur.Y)
{
this.m_prompDlg.DlgVisible(false);
}
else if (num3 - ptCur.X < this.m_prompDlg.Width + size.Width)
{
int num5 = this.m_prompDlg.Width + size.Width - (num3 - ptCur.X);
this.m_prompDlg.Location = new Point(ptCur.X + size.Width - num5, ptCur.Y - this.m_prompDlg.Height - size.Height);
this.m_prompDlg.DlgVisible(true);
}
else
{
this.m_prompDlg.Location = new Point(ptCur.X + size.Width, ptCur.Y - this.m_prompDlg.Height - size.Height);
this.m_prompDlg.DlgVisible(true);
}
if (this.m_prompDlg.Visible && this.m_prompDlg.MouseMoveArgs != null)
{
this.m_prompDlg.MouseMoveArgs();
}
}
}
private void method_10(object sender, KeyEventArgs e)
{
this.Key(e);
if (this.m_prompDlg != null && this.m_prompDlg.Visible)
{
this.m_prompDlg.OnKeyDown(sender, e);
}
}
private void method_11(object object_0, bool bool_1)
{
if (this.m_prompDlg != null && this.m_prompDlg.Visible)
{
this.m_prompDlg.OnFocusChangeEvent(object_0, bool_1);
}
}
private void method_12(object sender, PaintEventArgs e)
{
if (base.ViewActive is ViewDrafting)
{
this.Draw(e);
}
else
{
this.Draw(e);
}
}
public void EndCommand()
{
Class1.keybd_event(27, 0, 0, 0);
Class1.keybd_event(27, 0, 2, 0);
}
public virtual void Draw(PaintEventArgs paintEventArgs)
{
}
public virtual void Key(KeyEventArgs keyArg)
{
if (keyArg.KeyCode == Keys.Return)
{
if (this.m_prompDlg != null && !string.IsNullOrEmpty(this.m_prompDlg.GetInputValue()))
{
this.CmdEndType = XUiJigBase.ECmdEndType.eEnter;
this.EndCommand();
}
}
else if (keyArg.KeyCode == Keys.Escape)
{
this.CmdEndType = XUiJigBase.ECmdEndType.eEscape;
}
else
{
this.CmdEndType = XUiJigBase.ECmdEndType.eOther;
}
}
public virtual List<Curve> CreateCurves()
{
return null;
}
public void DrawAxisLine(Graphics graphis, XYZ ptBase1, XYZ ptBase2)
{
double num = 50.0 * JigFuncs.RevitToScreenScale(base.UiViewActive, base.ViewActive);
XYZ xyz = (ptBase2 - ptBase1).Normalize();
XYZ xyz2 = ptBase1 - xyz * num;
XYZ xyz3 = ptBase2 + xyz * num;
Point point = this.Revit2Client(ptBase1);
Point point2 = this.Revit2Client(ptBase2);
Point point3 = this.Revit2Client(xyz2);
Point point4 = this.Revit2Client(xyz3);
Pen pen = new Pen(base.JigPen.Color, base.JigPen.Width);
pen.DashStyle = DashStyle.Dash;
XGraphics xgraphics = new XGraphics(graphis, pen);
XLine2D xline2D = new XLine2D(point, point3);
XLine2D xline2D2 = new XLine2D(point2, point4);
xline2D.Draw(xgraphics);
xline2D2.Draw(xgraphics);
pen.Dispose();
}
public XUiJigBase.ECmdEndType CmdEndType { get; set; }
public PromptDlg m_prompDlg = null;
protected Point m_ptCur = Point.Empty;
public enum EJigResult
{
eRtUnknown,
eRtOk,
eRtCancel
}
public enum EResetPoint
{
eNoOper,
eByAngle,
eByOrtho,
eByAxis
}
public enum ECmdEndType
{
eOther,
eEscape,
eEnter,
eKeyWord
}
}
}