154 lines
5.7 KiB
C#
154 lines
5.7 KiB
C#
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.UI;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
|
|
namespace HYJig
|
|
{
|
|
public class JigFuncs
|
|
{
|
|
public static short LOWORD(int value)
|
|
{
|
|
return (short)(value & 65535);
|
|
}
|
|
|
|
public static short HIWORD(int value)
|
|
{
|
|
return (short)(value >> 16);
|
|
}
|
|
|
|
public static XYZ GetProjectPoint(UIDocument UIDoc, XYZ ptUser, XYZ ptOrigin, double dLineAngle)
|
|
{
|
|
View activeView = UIDoc.ActiveView;
|
|
Transform transform = Transform.CreateRotation(activeView.ViewDirection, dLineAngle);
|
|
XYZ xyz = transform.OfVector(activeView.RightDirection);
|
|
Line line = Line.CreateUnbound(ptOrigin, xyz);
|
|
XYZ xyz2 = JigFuncs.PointToPlane(ptOrigin, activeView.ViewDirection, ptUser);
|
|
return line.Project(xyz2).XYZPoint;
|
|
}
|
|
|
|
public static XYZ GetOrthoPoint(UIDocument UIDoc, XYZ ptUser, XYZ ptOrigin)
|
|
{
|
|
View activeView = UIDoc.ActiveView;
|
|
Line line = Line.CreateUnbound(ptOrigin, activeView.RightDirection);
|
|
Line line2 = Line.CreateUnbound(ptOrigin, activeView.UpDirection);
|
|
XYZ xyz = JigFuncs.PointToPlane(ptOrigin, activeView.ViewDirection, ptUser);
|
|
XYZ xyzpoint = line.Project(xyz).XYZPoint;
|
|
XYZ xyzpoint2 = line2.Project(xyz).XYZPoint;
|
|
XYZ xyz2;
|
|
if (xyz.DistanceTo(xyzpoint) < xyz.DistanceTo(xyzpoint2))
|
|
{
|
|
xyz2 = xyzpoint;
|
|
}
|
|
else
|
|
{
|
|
xyz2 = xyzpoint2;
|
|
}
|
|
return xyz2;
|
|
}
|
|
|
|
public static XYZ GetAxisPoint(UIDocument UIDoc, XYZ ptUser, XYZ ptOrigin)
|
|
{
|
|
XYZ xyz = JigFuncs.PointToPlane(ptOrigin, UIDoc.ActiveView.ViewDirection, ptUser);
|
|
XYZ xyz2;
|
|
if (xyz.DistanceTo(ptOrigin) < 0.0032808398950131233)
|
|
{
|
|
xyz2 = null;
|
|
}
|
|
else
|
|
{
|
|
View activeView = UIDoc.ActiveView;
|
|
Line line = Line.CreateUnbound(ptOrigin, activeView.RightDirection);
|
|
XYZ xyz3 = line.Project(xyz).XYZPoint;
|
|
if (xyz3.DistanceTo(ptOrigin) > 0.1 && JigFuncs.smethod_0(xyz3, ptOrigin, xyz) < 0.017453292519943295)
|
|
{
|
|
xyz2 = xyz3;
|
|
}
|
|
else
|
|
{
|
|
line = Line.CreateUnbound(ptOrigin, activeView.UpDirection);
|
|
xyz3 = line.Project(xyz).XYZPoint;
|
|
if (xyz3.DistanceTo(ptOrigin) > 0.1 && JigFuncs.smethod_0(xyz3, ptOrigin, xyz) < 0.017453292519943295)
|
|
{
|
|
xyz2 = xyz3;
|
|
}
|
|
else
|
|
{
|
|
Transform transform = Transform.CreateRotation(activeView.ViewDirection, 0.78539816339744828);
|
|
XYZ xyz4 = transform.OfVector(activeView.RightDirection);
|
|
line = Line.CreateUnbound(ptOrigin, xyz4);
|
|
xyz3 = line.Project(xyz).XYZPoint;
|
|
if (xyz3.DistanceTo(ptOrigin) > 0.1 && JigFuncs.smethod_0(xyz3, ptOrigin, xyz) < 0.017453292519943295)
|
|
{
|
|
xyz2 = xyz3;
|
|
}
|
|
else
|
|
{
|
|
xyz4 = transform.OfVector(activeView.UpDirection);
|
|
line = Line.CreateUnbound(ptOrigin, xyz4);
|
|
xyz3 = line.Project(xyz).XYZPoint;
|
|
if (xyz3.DistanceTo(ptOrigin) > 0.1 && JigFuncs.smethod_0(xyz3, ptOrigin, xyz) < 0.017453292519943295)
|
|
{
|
|
xyz2 = xyz3;
|
|
}
|
|
else
|
|
{
|
|
xyz2 = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return xyz2;
|
|
}
|
|
|
|
public static double smethod_0(XYZ pt1, XYZ ptOrigin, XYZ pt2)
|
|
{
|
|
XYZ xyz = pt1 - ptOrigin;
|
|
XYZ xyz2 = pt2 - ptOrigin;
|
|
return xyz.AngleTo(xyz2);
|
|
}
|
|
|
|
public static bool Screen2Client(IntPtr hWnd, ref Point pt)
|
|
{
|
|
return Class1.ScreenToClient(hWnd, ref pt);
|
|
}
|
|
|
|
public static bool Client2Screen(IntPtr hWnd, ref Point pt)
|
|
{
|
|
return Class1.ClientToScreen(hWnd, ref pt);
|
|
}
|
|
|
|
public static double RevitToScreenScale(UIView uiView, View view)
|
|
{
|
|
IList<XYZ> zoomCorners = uiView.GetZoomCorners();
|
|
XYZ xyz = zoomCorners[0];
|
|
XYZ xyz2 = zoomCorners[1];
|
|
Transform inverse = view.CropBox.Transform.Inverse;
|
|
xyz = inverse.OfPoint(xyz);
|
|
xyz2 = inverse.OfPoint(xyz2);
|
|
int num = 0;
|
|
int num2 = 0;
|
|
int num3 = 0;
|
|
int num4 = 0;
|
|
GetRevitWndRectangle(uiView, ref num, ref num2, ref num3, ref num4);
|
|
return (xyz2.Y - xyz.Y) / (double)(num4 - num2);
|
|
}
|
|
public static void GetRevitWndRectangle(UIView view, ref int left, ref int top, ref int right, ref int bottom)
|
|
{
|
|
var windowRectangle = view.GetWindowRectangle();
|
|
left = windowRectangle.Left;
|
|
top = windowRectangle.Top;
|
|
right = windowRectangle.Right;
|
|
bottom = windowRectangle.Bottom;
|
|
}
|
|
public static XYZ PointToPlane(XYZ ptPlaneOrigin, XYZ vtPlane, XYZ ptUser)
|
|
{
|
|
Line line = Line.CreateUnbound(ptUser, vtPlane);
|
|
return line.Project(ptPlaneOrigin).XYZPoint;
|
|
}
|
|
}
|
|
}
|