using Autodesk.Revit.DB; using Autodesk.Revit.UI; using HYJig; using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Reflection; using System.Runtime.InteropServices; using Transfer.Utils; using Point = System.Drawing.Point; namespace ShowGridNumber { public class GridNumberShowManager { public GridNumberShowManager(UIDocument uiDoc) { this.uidocument_0 = uiDoc; this.document_0 = uiDoc.Document; } public void RefreshUIDocument(UIDocument uiDoc) { this.uidocument_0 = uiDoc; this.document_0 = uiDoc.Document; this.uiview_0 = null; this.list_1.Clear(); this.list_2.Clear(); this.m_lstGridNumShowInfo.Clear(); } private void method_0() { this.list_0.Clear(); foreach (ElementId elementId in new FilteredElementCollector(this.document_0).OfClass(typeof(RevitLinkInstance)).ToElementIds()) { Element element = this.document_0.GetElement(elementId); if (!(element.GetType() != typeof(RevitLinkInstance))) { RevitLinkInstance revitLinkInstance = element as RevitLinkInstance; if (revitLinkInstance != null) { this.list_0.Add(revitLinkInstance); } } } } public CalcGridInfoResult GetGridNumberShowInfo(bool bIdling, DllImportManeger.Rect rcMDIClientWin, ref Point ptForm, ref Size sizeForm) { if (this.uidocument_0 == null) { return CalcGridInfoResult.eError; } if (this.uiview_0 == null) { foreach (UIView uiview in this.uidocument_0.GetOpenUIViews()) { if (uiview.ViewId == this.uidocument_0.ActiveView.Id) { this.uiview_0 = uiview; break; } } } if (this.uiview_0 == null) { return CalcGridInfoResult.eError; } this.method_0(); this.list_1.Clear(); this.list_2.Clear(); this.m_lstGridNumShowInfo.Clear(); CalcGridInfoResult calcGridInfoResult = this.method_1(bIdling, rcMDIClientWin, ref sizeForm, ref ptForm); if (calcGridInfoResult != CalcGridInfoResult.eSucceded) { return calcGridInfoResult; } this.method_2(); if (!File.Exists(Assembly.GetExecutingAssembly().Location + "\\ShowGridNumber.txt")) { return CalcGridInfoResult.eError; } if (ShowGridApplication.m_ThisApp.m_bShowLink) { this.method_3(); } this.urkYrwAqb(); if (ShowGridApplication.m_ThisApp.m_bShowLink) { this.method_4(); } this.method_5(); if (this.list_2.Count <= 0) { return CalcGridInfoResult.eError; } this.method_7(); if (this.m_lstGridNumShowInfo.Count <= 0) { return CalcGridInfoResult.eError; } return CalcGridInfoResult.eSucceded; } private CalcGridInfoResult method_1(bool bool_0, DllImportManeger.Rect rect_0, ref Size size_0, ref Point point_0) { int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; JigFuncs.GetRevitWndRectangle(this.uiview_0, ref num, ref num3, ref num2, ref num4); if (Geometry.IsEqual((double)num, (double)num2) || Geometry.IsEqual((double)num3, (double)num4)) { return CalcGridInfoResult.eMin; } if (bool_0 && Geometry.IsEqual((double)num, (double)this.wiqmPnEuc) && Geometry.IsEqual((double)num3, (double)this.int_1) && Geometry.IsEqual((double)num2, (double)this.int_0) && Geometry.IsEqual((double)num4, (double)this.int_2)) { return CalcGridInfoResult.eIdling; } this.wiqmPnEuc = num; this.int_0 = num2; this.int_1 = num3; this.int_2 = num4; if (Geometry.GreaterThan((double)rect_0.left, (double)num)) { num = rect_0.left; } if (Geometry.LessThan((double)rect_0.right, (double)num2)) { num2 = rect_0.right; } if (Geometry.GreaterThan((double)rect_0.top, (double)num3)) { num3 = rect_0.top; } if (Geometry.LessThan((double)rect_0.bottom, (double)num4)) { num4 = rect_0.bottom; } XYZ xyz = new XYZ((double)num, (double)num4, 0.0); XYZ xyz2 = new XYZ((double)num, (double)num3, 0.0); XYZ xyz3 = new XYZ((double)num2, (double)num3, 0.0); XYZ xyz4 = new XYZ((double)num2, (double)num4, 0.0); size_0.Width = num2 - num; size_0.Height = num4 - num3; point_0.X = num; point_0.Y = num3; ViewOutLineInfo viewOutLineInfo = new ViewOutLineInfo(Line.CreateBound(xyz4, xyz), OutLineSide.eBottom); this.list_1.Add(viewOutLineInfo); ViewOutLineInfo viewOutLineInfo2 = new ViewOutLineInfo(Line.CreateBound(xyz, xyz2), OutLineSide.eLeft); this.list_1.Add(viewOutLineInfo2); ViewOutLineInfo viewOutLineInfo3 = new ViewOutLineInfo(Line.CreateBound(xyz2, xyz3), OutLineSide.eUp); this.list_1.Add(viewOutLineInfo3); ViewOutLineInfo viewOutLineInfo4 = new ViewOutLineInfo(Line.CreateBound(xyz3, xyz4), OutLineSide.eRight); this.list_1.Add(viewOutLineInfo4); return CalcGridInfoResult.eSucceded; } private void method_2() { FilteredElementCollector filteredElementCollector = new FilteredElementCollector(this.document_0, this.uidocument_0.ActiveView.Id); filteredElementCollector.OfClass(typeof(Grid)); foreach (Element element in filteredElementCollector) { Grid grid = element as Grid; if (grid != null) { DrawElement drawElement = new DrawElement(grid, ElemType.eGrid, false, grid.Curve); this.list_2.Add(drawElement); } } } private void method_3() { Transform transform = this.document_0.ActiveView.CropBox.Transform; foreach (RevitLinkInstance revitLinkInstance in this.list_0) { Document linkDocument = revitLinkInstance.GetLinkDocument(); if (linkDocument != null && this.document_0.ActiveView.ViewType != ViewType.Section) { try { Transform transform2 = revitLinkInstance.GetTransform().Multiply(transform); foreach (Element element in new FilteredElementCollector(linkDocument).OfClass(typeof(Grid)).ToElements()) { Grid grid = element as Grid; if (grid != null) { DrawElement drawElement; if (grid.Curve is Line) { XYZ xyz = grid.Curve.GetEndPoint(0); XYZ xyz2 = grid.Curve.GetEndPoint(1); xyz = transform2.OfPoint(xyz); xyz2 = transform2.OfPoint(xyz2); Line line = Line.CreateBound(xyz, xyz2); drawElement = new DrawElement(grid, ElemType.eGrid, true, line); } else { XYZ xyz3 = grid.Curve.GetEndPoint(0); XYZ xyz4 = grid.Curve.GetEndPoint(1); XYZ xyz5 = grid.Curve.Evaluate(0.5, true); xyz3 = transform2.OfPoint(xyz3); xyz4 = transform2.OfPoint(xyz4); xyz5 = transform2.OfPoint(xyz5); Arc arc = Arc.Create(xyz3, xyz4, xyz5); drawElement = new DrawElement(grid, ElemType.eGrid, true, arc); } this.list_2.Add(drawElement); } } } catch (Exception) { } } } } private void urkYrwAqb() { FilteredElementCollector filteredElementCollector = new FilteredElementCollector(this.document_0, this.uidocument_0.ActiveView.Id); filteredElementCollector.OfClass(typeof(MultiSegmentGrid)); foreach (Element element in filteredElementCollector) { MultiSegmentGrid multiSegmentGrid = element as MultiSegmentGrid; if (multiSegmentGrid != null) { foreach (ElementId elementId in multiSegmentGrid.GetGridIds()) { Grid grid = this.document_0.GetElement(elementId) as Grid; if (grid != null) { DrawElement drawElement = new DrawElement(grid, ElemType.eMultiSegGrid, false, grid.Curve); this.list_2.Add(drawElement); } } } } } private void method_4() { Transform transform = this.document_0.ActiveView.CropBox.Transform; foreach (RevitLinkInstance revitLinkInstance in this.list_0) { Document linkDocument = revitLinkInstance.GetLinkDocument(); if (linkDocument != null && this.document_0.ActiveView.ViewType != ViewType.Section) { try { Transform transform2 = revitLinkInstance.GetTransform().Multiply(transform); FilteredElementCollector filteredElementCollector = new FilteredElementCollector(linkDocument); filteredElementCollector.OfClass(typeof(MultiSegmentGrid)); foreach (Element element in filteredElementCollector) { MultiSegmentGrid multiSegmentGrid = element as MultiSegmentGrid; if (multiSegmentGrid != null) { foreach (ElementId elementId in multiSegmentGrid.GetGridIds()) { Grid grid = this.document_0.GetElement(elementId) as Grid; if (grid != null) { DrawElement drawElement; if (grid.Curve is Line) { XYZ xyz = grid.Curve.GetEndPoint(0); XYZ xyz2 = grid.Curve.GetEndPoint(1); xyz = transform2.OfPoint(xyz); xyz2 = transform2.OfPoint(xyz2); Line line = Line.CreateBound(xyz, xyz2); drawElement = new DrawElement(grid, ElemType.eMultiSegGrid, true, line); } else { XYZ xyz3 = grid.Curve.GetEndPoint(0); XYZ xyz4 = grid.Curve.GetEndPoint(1); XYZ xyz5 = grid.Curve.Evaluate(0.5, true); xyz3 = transform2.OfPoint(xyz3); xyz4 = transform2.OfPoint(xyz4); xyz5 = transform2.OfPoint(xyz5); Arc arc = Arc.Create(xyz3, xyz4, xyz5); drawElement = new DrawElement(grid, ElemType.eMultiSegGrid, true, arc); } this.list_2.Add(drawElement); } } } } } catch (Exception) { } } } } private void method_5() { if (this.uidocument_0.ActiveView.ViewType != ViewType.Elevation && this.uidocument_0.ActiveView.ViewType != ViewType.Section) { return; } FilteredElementCollector filteredElementCollector = new FilteredElementCollector(this.document_0, this.uidocument_0.ActiveView.Id); filteredElementCollector.OfClass(typeof(Level)); foreach (Element element in filteredElementCollector) { Level level = element as Level; if (level != null) { DrawElement drawElement = new DrawElement(level, ElemType.eLevel, false, null); this.list_2.Add(drawElement); } } } private void method_6() { if (this.uidocument_0.ActiveView.ViewType != ViewType.Elevation && this.uidocument_0.ActiveView.ViewType != ViewType.Section) { return; } foreach (RevitLinkInstance revitLinkInstance in this.list_0) { Document linkDocument = revitLinkInstance.GetLinkDocument(); if (linkDocument != null) { try { FilteredElementCollector filteredElementCollector = new FilteredElementCollector(linkDocument, this.uidocument_0.ActiveView.Id); filteredElementCollector.OfClass(typeof(Level)); foreach (Element element in filteredElementCollector) { Level level = element as Level; if (level != null) { DrawElement drawElement = new DrawElement(level, ElemType.eLevel, true, null); this.list_2.Add(drawElement); } } } catch (Exception) { } } } } private void method_7() { foreach (ViewOutLineInfo viewOutLineInfo in this.list_1) { foreach (DrawElement drawElement in this.list_2) { Curve curve = null; if (drawElement.DrawElemType != ElemType.eGrid) { if (drawElement.DrawElemType != ElemType.eMultiSegGrid) { if (drawElement.DrawElemType != ElemType.eLevel) { goto IL_011A; } Level level = drawElement.DrawElem as Level; if (level != null) { curve = (level.Location as LocationCurve).Curve; goto IL_011A; } continue; } } Grid grid = drawElement.DrawElem as Grid; if (grid == null) { continue; } if (!drawElement.InLinkDoc) { if (drawElement.DrawElemType == ElemType.eMultiSegGrid && (this.document_0.ActiveView.ViewType == ViewType.Section || this.document_0.ActiveView.ViewType == ViewType.Elevation)) { continue; } curve = (grid.Location as LocationCurve).Curve; } else if (this.document_0.ActiveView.ViewType != ViewType.Section && this.document_0.ActiveView.ViewType != ViewType.Elevation) { curve = drawElement.LinkGridCurve; } IL_011A: if (!(curve == null)) { Curve curve2; if (curve is Arc) { Point point = this.Revit2Screen(curve.GetEndPoint(0)); Point point2 = this.Revit2Screen(curve.GetEndPoint(1)); Point point3 = this.Revit2Screen(curve.Evaluate(0.5, true)); XYZ xyz = new XYZ((double)point.X, (double)point.Y, 0.0); XYZ xyz2 = new XYZ((double)point2.X, (double)point2.Y, 0.0); XYZ xyz3 = new XYZ((double)point3.X, (double)point3.Y, 0.0); curve2 = Arc.Create(xyz, xyz2, xyz3); } else { Point point4 = this.Revit2Screen(curve.GetEndPoint(0)); Point point5 = this.Revit2Screen(curve.GetEndPoint(1)); XYZ xyz4 = new XYZ((double)point4.X, (double)point4.Y, 0.0); XYZ xyz5 = new XYZ((double)point5.X, (double)point5.Y, 0.0); curve2 = Line.CreateBound(xyz4, xyz5); } IntersectionResultArray intersectionResultArray = new IntersectionResultArray(); if (viewOutLineInfo.ViewOutLine.Intersect(curve2, out intersectionResultArray) == SetComparisonResult.Overlap && intersectionResultArray != null && intersectionResultArray.Size > 0) { for (int i = 0; i < intersectionResultArray.Size; i++) { GridNumShowInfo gridNumShowInfo = new GridNumShowInfo(); gridNumShowInfo.IntersectPoint = intersectionResultArray.get_Item(i).XYZPoint; gridNumShowInfo.OutlineSide = viewOutLineInfo.OutlineSide; gridNumShowInfo.ElemText = drawElement.DrawElem.Name; gridNumShowInfo.ElemClass = drawElement.DrawElemType; this.m_lstGridNumShowInfo.Add(gridNumShowInfo); } } } } } } public void TranformIntersectPt(IntPtr hFormClient) { try { foreach (GridNumShowInfo gridNumShowInfo in this.m_lstGridNumShowInfo) { XYZ intersectPoint = gridNumShowInfo.IntersectPoint; if (intersectPoint != null) { XYZ xyz = null; XYZ xyz2 = null; switch (gridNumShowInfo.OutlineSide) { case OutLineSide.eUp: xyz2 = intersectPoint + XYZ.BasisY * 25.0; xyz = intersectPoint - XYZ.BasisX * 25.0; break; case OutLineSide.eLeft: xyz2 = intersectPoint + XYZ.BasisX * 5.0; xyz = intersectPoint - XYZ.BasisY * 25.0; break; case OutLineSide.eRight: xyz2 = intersectPoint - XYZ.BasisX * 5.0; xyz = intersectPoint - XYZ.BasisY * 25.0 - XYZ.BasisX * 52.0; break; case OutLineSide.eBottom: xyz2 = intersectPoint - XYZ.BasisY * 25.0; xyz = intersectPoint - XYZ.BasisY * 52.0 - XYZ.BasisX * 25.0; break; } Point point = new Point((int)xyz.X, (int)xyz.Y); GridNumberShowManager.ScreenToClient(hFormClient, ref point); gridNumShowInfo.CirlLocation = point; Point point2 = new Point((int)xyz2.X, (int)xyz2.Y); GridNumberShowManager.ScreenToClient(hFormClient, ref point2); gridNumShowInfo.TextLocation = point2; } } } catch { } } [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern bool ScreenToClient(IntPtr hWnd, ref Point pt); public Point Revit2Screen(XYZ point) { try { int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; JigFuncs.GetRevitWndRectangle(this.uiview_0, ref num, ref num2, ref num3, ref num4); Transform inverse = this.uidocument_0.ActiveView.CropBox.Transform.Inverse; IList zoomCorners = this.uiview_0.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 List m_lstGridNumShowInfo = new List(); private List list_0 = new List(); private List list_1 = new List(); private List list_2 = new List(); private UIDocument uidocument_0; private Document document_0; private UIView uiview_0; private int wiqmPnEuc; private int int_0; private int int_1; private int int_2; } }