private static List <ClashResultGroup> GroupByGridIntersection(List <ClashResult> results) { //TODO Check if the grid system exist GridSystem gridSystem = Application.MainDocument.Grids.ActiveSystem; Dictionary <GridIntersection, ClashResultGroup> groups = new Dictionary <GridIntersection, ClashResultGroup>(); ClashResultGroup currentGroup; foreach (ClashResult result in results) { //Cannot add original result to new clash test, so I create a copy ClashResult copiedResult = (ClashResult)result.CreateCopy(); GridIntersection closestIntersection = gridSystem.ClosestIntersection(copiedResult.Center); if (!groups.TryGetValue(closestIntersection, out currentGroup)) { currentGroup = new ClashResultGroup(); currentGroup.DisplayName = closestIntersection.DisplayName; groups.Add(closestIntersection, currentGroup); } currentGroup.Children.Add(copiedResult); } IOrderedEnumerable <KeyValuePair <GridIntersection, ClashResultGroup> > list = groups.OrderBy(key => key.Key.Position.X).OrderBy(key => key.Key.Level.Elevation); groups = list.ToDictionary((keyItem) => keyItem.Key, (valueItem) => valueItem.Value); return(groups.Values.ToList()); }
private void CutTrees(EntityCommandBuffer.ParallelWriter ecb, int sortKey, Environment env) { /* Burst requires conversion to locals */ NativeMultiHashMap <uint2, TreeHashNode> hashTable = this.hashTable; Entities.ForEach((Entity entity, int entityInQueryIndex, in RoadSegment roadSegment) => { NativeList <uint2> nodes = new NativeList <uint2>(Allocator.Temp); float3 mid = (roadSegment.initial + roadSegment.final) / 2; float length = math.distance(roadSegment.initial, roadSegment.final) / 2; float2 center = (mid.xz - Environment.TerrainBoundaries.Min.xz) / env.gridSize; float radius = (length + env.roadWidth) / env.gridSize; Circle influenceZone = new Circle(center, radius); GridIntersection.Circle(influenceZone, nodes); for (int i = 0; i < nodes.Length; i++) { RemoveTreeFromSegment(hashTable, nodes[i], roadSegment, ecb, sortKey, env); } ecb.DestroyEntity(entityInQueryIndex, entity); nodes.Dispose(); }) .WithReadOnly(hashTable) .ScheduleParallel(Dependency).Complete(); }
public List <object> getClashInfo(object input) { var output = new List <object>(); if (MainTools.IsList(input)) { foreach (var item in (IList <object>)input) { var clash = item as IClashResult; if (clash != null) { var name = clash.DisplayName; var status = clash.Status; var ApprovedBy = clash.ApprovedBy; var ApprovedTime = clash.ApprovedTime; var AssignedTo = clash.AssignedTo; var Description = clash.Description; string grid = null; string level = null; //DANGER WILL ROBINSON!! string GUID = (clash as ClashResult) != null? (clash as ClashResult).Guid.ToString(): (clash as ClashResultGroup).Guid.ToString(); var x = clash.Center.X; var y = clash.Center.Y; var z = clash.Center.Z; GridSystem gridSystem = Application.MainDocument.Grids.ActiveSystem; if (gridSystem.ClosestIntersection(clash.Center) != null) { GridIntersection closestGridIntersection = gridSystem.ClosestIntersection(clash.Center); grid = closestGridIntersection.Line1.DisplayName + "-" + closestGridIntersection.Line2.DisplayName; level = closestGridIntersection.Level.DisplayName; } output.Add(new List <object>() { name, status, ApprovedBy, ApprovedTime, AssignedTo, Description, grid, level, GUID, x, y, z }); } } } return(output); }
private static List <ClashResultGroup> GroupByGridIntersection(List <ClashResult> results, string initialName) { //I already check if it exists GridSystem gridSystem = Application.MainDocument.Grids.ActiveSystem; Dictionary <GridIntersection, ClashResultGroup> groups = new Dictionary <GridIntersection, ClashResultGroup>(); ClashResultGroup currentGroup; //Create a group for the null GridIntersection ClashResultGroup nullGridGroup = new ClashResultGroup(); nullGridGroup.DisplayName = initialName + "No Grid intersection"; foreach (ClashResult result in results) { //Cannot add original result to new clash test, so I create a copy ClashResult copiedResult = (ClashResult)result.CreateCopy(); if (gridSystem.ClosestIntersection(copiedResult.Center) != null) { GridIntersection closestGridIntersection = gridSystem.ClosestIntersection(copiedResult.Center); if (!groups.TryGetValue(closestGridIntersection, out currentGroup)) { currentGroup = new ClashResultGroup(); string displayName = closestGridIntersection.DisplayName; if (string.IsNullOrEmpty(displayName)) { displayName = "Unnamed Grid Intersection"; } currentGroup.DisplayName = initialName + displayName; groups.Add(closestGridIntersection, currentGroup); } currentGroup.Children.Add(copiedResult); } else { nullGridGroup.Children.Add(copiedResult); } } IOrderedEnumerable <KeyValuePair <GridIntersection, ClashResultGroup> > list = groups.OrderBy(key => key.Key.Position.X).OrderBy(key => key.Key.Level.Elevation); groups = list.ToDictionary((keyItem) => keyItem.Key, (valueItem) => valueItem.Value); List <ClashResultGroup> groupsByGridIntersection = groups.Values.ToList(); if (nullGridGroup.Children.Count != 0) { groupsByGridIntersection.Add(nullGridGroup); } return(groupsByGridIntersection); }
private static void RemaneGroupBySortingMode(ref List <ClashResultGroup> clashResultGroups, GroupingMode mode) { GridSystem gridSystem = Application.MainDocument.Grids.ActiveSystem; foreach (ClashResultGroup clashResultGroup in clashResultGroups) { switch (mode) { case GroupingMode.None: return; case GroupingMode.ByLevel: GridLevel closestLevel = gridSystem.ClosestIntersection(clashResultGroup.Center).Level; clashResultGroup.DisplayName = closestLevel.DisplayName + "_" + clashResultGroup.DisplayName; break; case GroupingMode.ByGridIntersection: GridIntersection closestIntersection = gridSystem.ClosestIntersection(clashResultGroup.Center); clashResultGroup.DisplayName = closestIntersection.DisplayName + "_" + clashResultGroup.DisplayName; break; case GroupingMode.BySelectionA: case GroupingMode.BySelectionB: break; case GroupingMode.ByApprovedBy: string approvedByValue = "N/A"; if (!String.IsNullOrEmpty(clashResultGroup.ApprovedBy)) { approvedByValue = clashResultGroup.ApprovedBy; } clashResultGroup.DisplayName = approvedByValue + "_" + clashResultGroup.DisplayName; break; case GroupingMode.ByAssignedTo: string assignedToValue = "N/A"; if (!String.IsNullOrEmpty(clashResultGroup.AssignedTo)) { assignedToValue = clashResultGroup.ApprovedBy; } clashResultGroup.DisplayName = assignedToValue + "_" + clashResultGroup.DisplayName; break; case GroupingMode.ByStatus: clashResultGroup.DisplayName = clashResultGroup.Status.ToString() + "_" + clashResultGroup.DisplayName; break; } } }
public object getLocationFromGrids(object input) { var output = new List <List <string> >(); var grids = new List <object>(); var level = new List <object>(); var X = new List <object>(); var Y = new List <object>(); var Z = new List <object>(); if (MainTools.IsList(input)) { foreach (var item in (IList <object>)input) { if (item.GetType() == typeof(IClashResult)) { var clash = item as IClashResult; GridSystem gridSystem = Application.MainDocument.Grids.ActiveSystem; if (gridSystem.ClosestIntersection(clash.Center) != null) { GridIntersection closestGridIntersection = gridSystem.ClosestIntersection(clash.Center); grids.Add(closestGridIntersection.DisplayName); level.Add(closestGridIntersection.Level.DisplayName); X.Add(clash.Center.X); Y.Add(clash.Center.Y); Z.Add(clash.Center.Z); } } } } return(new List <List <object> >() { grids, level, X, Y, Z }); }
public bool MuzzleHitSelf() { for (int i = 0; i < Muzzles.Length; i++) { var m = Muzzles[i]; var grid = Comp.Ai.MyGrid; var dummy = Dummies[i]; var newInfo = dummy.Info; m.Direction = newInfo.Direction; m.Position = newInfo.Position; m.LastUpdateTick = Comp.Session.Tick; var start = m.Position; var end = m.Position + (m.Direction * grid.PositionComp.LocalVolume.Radius); Vector3D?hit; if (GridIntersection.BresenhamGridIntersection(grid, ref start, ref end, out hit, Comp.MyCube, Comp.Ai)) { return(true); } } return(false); }
private void Update() { NativeList <uint2> collectedNodes = new NativeList <uint2>(Allocator.Temp); foreach (PaintedNode node in cells.Values) { node.Paint(Color.white); } float3 center = pointA.position; Circle circle = new Circle(center.xy, math.distance(pointB.position, pointA.position)); GridIntersection.Circle(circle, collectedNodes); foreach (uint2 cell in collectedNodes) { if (cells.ContainsKey(cell)) { cells[cell].Paint(Color.green); } } collectedNodes.Dispose(); }
//using Tuple to return values public (double gridXMin, double gridXMax, double gridYMin, double gridYMax) GridCoord() { Document document = Autodesk.Navisworks.Api.Application.ActiveDocument; DocumentClash documentClash = document.GetClash(); DocumentClashTests allTests = documentClash.TestsData; DocumentModels docModel = document.Models; DocumentGrids docGrids = document.Grids; GridSystem docGridSys = docGrids.ActiveSystem; List <double> gridXCoord = new List <double>(); List <double> gridYCoord = new List <double>(); try { //get objects in project foreach (Model model in docModel) { ModelItem root = model.RootItem as ModelItem; string dn = root.DisplayName.ToString(); string[] disName = dn.Split('_', '-', '.', ' '); //determine source file type by searching model file properties foreach (PropertyCategory oPC in root.PropertyCategories) { if (oPC.DisplayName.ToString() == "Item") { foreach (DataProperty oDP in oPC.Properties) { if (oDP.DisplayName.ToString() == "Source File Name") { string val = oDP.Value.ToDisplayString(); string[] valName = val.Split('.'); //source file is RVT (Revit) if (valName.Last() == "rvt") { foreach (ModelItem item in root.Children) { ModelItem subLayer2 = item as ModelItem; foreach (ModelItem subLaye3 in subLayer2.Children) { ModelItem subLayer4 = subLaye3 as ModelItem; foreach (ModelItem subLayer5 in subLayer4.Children) { ModelItem subLayer6 = subLayer5 as ModelItem; foreach (ModelItem subLayer7 in subLayer6.Children) { ModelItem subLayer8 = subLayer7 as ModelItem; foreach (ModelItem subLayer9 in subLayer8.Children) { //Get object center position (X,Y,Z) by setting a 3D bounding box ModelItem subLayer10 = subLayer9 as ModelItem; if (subLayer10 != null) { BoundingBox3D bbox = subLayer10.BoundingBox(); //find closest grid intersection to object center position using API GridIntersection gridCross = docGridSys.ClosestIntersection(bbox.Center); //Get closest grid intersection X,Y coord gridXCoord.Add(gridCross.Position.X); gridYCoord.Add(gridCross.Position.Y); } } } } } } } //if source file is DWG format (AutoCAD) else if (valName.Last() == "dwg") { foreach (ModelItem item in root.Children) { ModelItem subLayer2 = item as ModelItem; foreach (ModelItem subLayer3 in subLayer2.Children) { if (subLayer3 != null) { //Get object center position (X,Y,Z) by setting a 3D bounding box BoundingBox3D bbox = subLayer3.BoundingBox(); //find closest grid intersection to object center position using API GridIntersection gridCross = docGridSys.ClosestIntersection(bbox.Center); //Get closest grid intersection X,Y coord gridXCoord.Add(gridCross.Position.X); gridYCoord.Add(gridCross.Position.Y); } } } } //if file in selection tree is an NWD file else if (disName.Last() == "nwd") { foreach (ModelItem item in root.Children) { ModelItem disfile = item as ModelItem; string disNwd = disfile.DisplayName.ToString(); string[] disNameNwd = disNwd.Split('_', '-', '.'); foreach (PropertyCategory oPCnwd in disfile.PropertyCategories) { if (oPCnwd.DisplayName.ToString() == "Item") { foreach (DataProperty oDPnwd in oPCnwd.Properties) { if (oDPnwd.DisplayName.ToString() == "Source File Name") { string valNwd = oDPnwd.Value.ToDisplayString(); string[] valNameNwd = valNwd.Split('.'); if (valNameNwd.Last() == "rvt") { foreach (ModelItem itemNwd in disfile.Children) { ModelItem subLayer2Nwd = itemNwd as ModelItem; foreach (ModelItem subLayer3Nwd in subLayer2Nwd.Children) { ModelItem subLayer4Nwd = subLayer3Nwd as ModelItem; foreach (ModelItem subLayer5Nwd in subLayer4Nwd.Children) { ModelItem subLayer6Nwd = subLayer5Nwd as ModelItem; foreach (ModelItem subLayer7Nwd in subLayer6Nwd.Children) { ModelItem subLayer8Nwd = subLayer7Nwd as ModelItem; foreach (ModelItem subLayer9Nwd in subLayer8Nwd.Children) { if (subLayer9Nwd != null) { //Get object center position (X,Y,Z) by setting a 3D bounding box BoundingBox3D bbox = subLayer9Nwd.BoundingBox(); //find closest grid intersection to object center position using API GridIntersection gridCross = docGridSys.ClosestIntersection(bbox.Center); gridXCoord.Add(gridCross.Position.X); gridYCoord.Add(gridCross.Position.Y); } } } } } } } //Source file is DWG format (AutoCAD) else if (valNameNwd.Last() == "dwg") { foreach (ModelItem itemNwd in disfile.Children) { ModelItem subLayer2Nwd = itemNwd as ModelItem; foreach (ModelItem subLayer3Nwd in subLayer2Nwd.Children) { if (subLayer3Nwd != null) { //Get object center position (X,Y,Z) by setting a 3D bounding box BoundingBox3D bbox = subLayer3Nwd.BoundingBox(); //find closest grid intersection to object center position using API GridIntersection gridCross = docGridSys.ClosestIntersection(bbox.Center); //Get closest grid intersection X,Y coord gridXCoord.Add(gridCross.Position.X); gridYCoord.Add(gridCross.Position.Y); } } } } } } } } } } } } } } } //store max & min values to return for scatter plot data double gridXMin = gridXCoord.Min(); double gridXMax = gridXCoord.Max(); double gridYMin = gridYCoord.Min(); double gridYMax = gridYCoord.Max(); return(gridXMin, gridXMax, gridYMin, gridYMax); } catch (Exception exception) { MessageBox.Show("Error in Grid Coordinates Analysis!"); exception.Message.ToString(); } return(0, 0, 0, 0); }