public void GenerateHolesR() { if (Holes.Count == 5) { return; } int x = r.Next(50, 700); int y = r.Next(50, 350); bool touch = false; foreach (Hole d in Holes) { touch = d.Colliding(new Hole(new Point(x, y))); if (touch) { break; } } if (!touch) { Holes.Add(new Hole(new Point(x, y))); } GenerateHolesR(); }
public void GenerateHoleData() { if (holes.Count > 0) { holes.Clear(); } foreach (Transform hole in holesObject.transform) { Holes temp = new Holes(); foreach (Transform setPiece in hole.transform) { switch (setPiece.gameObject.name) { case ("Tee"): temp.teepad = setPiece.gameObject; break; case ("FowardDirection"): temp.fowardDirection = setPiece.gameObject; break; case ("Hole"): temp.hole = setPiece.gameObject; break; } } holes.Add(temp); } holes = new List <Holes>(holes); }
public Area GetArea() { var calculator = GeoContext.Current.GeodeticCalculator; var area = calculator.CalculateArea(Shell.Coordinates); return(Holes.Aggregate(area, (current, hole) => current - calculator.CalculateArea(hole.Coordinates))); }
public bool Equals(IPolygon2D other) { var poly = other as Polygon2DWithHoles; if (poly == null) { return(false); } if (!Outside.Equals(poly.Outside)) { return(false); } if (Holes.Count != poly.Holes.Count) { return(false); } var holes = Holes.ToList(); var otherHoles = poly.Holes.ToList(); for (var i = 0; i < holes.Count; i++) { if (!holes[i].Equals(otherHoles[i])) { return(false); } } return(true); }
public async Task <IActionResult> Edit(int id, [Bind("HoleId,Number,Par,Handicap")] Holes holes) { if (id != holes.HoleId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(holes); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HolesExists(holes.HoleId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(holes)); }
/// <summary> /// Add list of Holes to this Section. /// </summary> /// <param name="holes"></param> /// <returns></returns> public Section AddHoleRange(List<Hole> holes) { if(holes != null) Holes.AddRange(holes); return this; }
/// <summary> /// Load the course info from the current map. /// </summary> public void LoadFromMap() { Host.AssertServer(); Holes.Clear(); foreach (var hole in Entity.All.OfType <HoleSpawn>()) { var goal = Entity.All.OfType <HoleGoal>().Where(x => x.Hole == hole.Number).First(); if (goal == null) { Log.Error($"No ball goal found for [Hole {hole.Number}]"); continue; } Log.Info($"Hole ({hole.Number}) - {hole.Name}"); // todo: sort this list Holes.Add(new HoleInfo() { Number = hole.Number, // Name = hole.Name, Par = hole.Par, SpawnPosition = hole.Position, SpawnAngles = hole.WorldAng, // GoalPosition = goal.Position, // Bounds = Entity.All.OfType<HoleBounds>().Where(x => x.Hole == hole.Number).ToList() }); } }
public HB.Face3D ToHoneybee() { return(new HB.Face3D( Boundary?.ToHoneybee(), Holes?.ToHoneybee(), Plane )); }
public void ClearHoles() { if (Holes == null) { return; } Holes.Clear(); }
/// <summary> /// Add list of Holes to this Section. /// </summary> /// <param name="holes"></param> /// <returns></returns> public Section AddHoleRange(List <Hole> holes) { if (holes != null) { Holes.AddRange(holes); } return(this); }
//Marble fell in its hole private void FillTheHoleIfMarbleIsIn(Marble marble) { Hole marbleHole = Holes.First(h => h.Number == marble.Number); if (marbleHole.Position.Row == marble.Position.Row && marbleHole.Position.Column == marble.Position.Column) { marbleHole.IsFilled = true; marble.IsInHole = true; } }
public PegBoard Clone() { var temp = new PegBoard(); foreach (var hole in Holes.Select((x, i) => new { x.Filled, Index = i })) { temp.Holes[hole.Index].Filled = hole.Filled; } return(temp); }
public void HolesTest() { Holes h = new Holes(); for (int i = 1; i < 19; i++) { Debug.WriteLine(h.GetHole(i)); } Assert.AreEqual(1, 1); }
/// <summary> /// Converts the face to a SFA polygon. /// </summary> /// <param name="factory">The geometry factory used to produce the polygon.</param> /// <returns>The polygon geometry representing the face.</returns> public IPolygon ToGeometry(IGeometryFactory factory = null) { if (factory == null) { factory = FactoryRegistry.GetFactory <IGeometryFactory>(); } return(factory.CreatePolygon(Vertices.Select(vertex => vertex.Position), Holes.Select(hole => hole.Vertices.Select(vertex => vertex.Position).Reverse()))); }
//It checks if ball is in a hole //Return Value : 1 if ball is in a hole; 0 if ball is not in any hole. private static int ball_in_hole(Ball ball, int hole_type = Holes.BORDERS_8GAME) { for (int i = 0; i < Holes.GetHoleNum(hole_type); i++) { if (Maths.vec_abs(Holes.GetHole(hole_type, i).pos - ball.r) < Holes.GetHole(hole_type, i).r *3) { return(i); } } return(-1); }
public async Task <IActionResult> Create([Bind("HoleId,Number,Par,Handicap")] Holes holes) { if (ModelState.IsValid) { _context.Add(holes); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(holes)); }
public override string ToString() { var pointsStr = Points.ConvertAll(latLng => latLng.ToString()); var points = pointsStr.Aggregate((acc, next) => acc + ", " + next); var holesStringBuilder = new StringBuilder(); Holes.ForEach(hole => hole.ForEach(point => holesStringBuilder.Append(point + ", "))); return(string.Format("[Polygon: Id={0}, Points={1}, Holes={2}, StrokeWidth={3}, Color={4}, FillColor={5}, StrokeJointType={6}, ZIndex={7}, IsVisible={8}, IsGeodesic={9}, IsClickable={10}]", Id, points, holesStringBuilder.ToString(), StrokeWidth, StrokeColor, FillColor, StrokeJointType, ZIndex, IsVisible, IsGeodesic, IsClickable)); }
private void RemoveHolesTouchingRegions() { foreach (Region r in Regions) { for (int i = 0; i < Holes.Count; ++i) { if (r.Touches(Holes[i], true, true, true)) { Holes.RemoveAt(i--); } } } }
public void AddHole(Polygon2f hole) { if (hole.HasHoles) { throw new NotImplementedException("Hole with holes not implemented."); } if (Holes == null) { Holes = new List <Polygon2f>(); } Holes.Add(hole); }
private DirectionResponse MoveMarbles(Sides liftedSide) { var newBoardState = new Board { Size = this.Size, Marbles = Marbles.Select(m => new Marble { IsInHole = m.IsInHole, Number = m.Number, Position = new Position { Row = m.Position.Row, Column = m.Position.Column } }).ToArray(), Holes = Holes.Select(h => new Hole { IsFilled = h.IsFilled, Number = h.Number, Position = new Position { Row = h.Position.Row, Column = h.Position.Column } }).ToArray(), Walls = this.Walls }; var lineMarbles = new List <Marble>(); for (int i = 0; i < Size; i++) { lineMarbles = newBoardState.GetMarblesInTheLine(i, liftedSide); //in a row or column, depending on the direction for (int j = 0; j < lineMarbles.Count; j++) { int targetPosition = newBoardState.MarbleTargetPosition(lineMarbles, j, liftedSide); while (MarbleDidNotGetTheDestination(lineMarbles[j].Position, targetPosition, liftedSide) && !lineMarbles[j].IsInHole) //move till it either doesn't reach the destination or fell in its hole { lineMarbles[j].Move(liftedSide); if (newBoardState.FellInAnotherHole(lineMarbles[j])) //wrong route, break the move { return(new DirectionResponse()); } newBoardState.FillTheHoleIfMarbleIsIn(lineMarbles[j]); if (newBoardState.Marbles.All(m => m.IsInHole)) //solution found { return new DirectionResponse { Success = true, Finished = true, BoardState = newBoardState } } ; } } } return(new DirectionResponse { Success = true, Finished = false, BoardState = newBoardState }); }
private unsafe void ParseMcnkHeader(byte *cur) { var mcnk = (McnkHeader *)cur; _bounds = new BoundingBox( mcnk->Position + new Vector3(-ChunkWidth, -ChunkWidth, 0.0f), mcnk->Position ); _flags = mcnk->Flags; Holes = _flags.HasFlag(McnkHeaderFlags.HighResHoleMap) ? mcnk->HighResHoles : TransformToHighRes(mcnk->Holes); if (Holes.All(b => b == 0)) { Holes = NoHoles; // easier to check for } X = mcnk->X; Y = mcnk->Y; }
private Solution LiftBoard(Sides liftedSide, string moves) { var newBoardState = new Board { Size = this.Size, Marbles = Marbles.Select(m => new Marble { IsInHole = m.IsInHole, Number = m.Number, Position = new Position { Row = m.Position.Row, Column = m.Position.Column } }).ToArray(), Holes = Holes.Select(h => new Hole { IsFilled = h.IsFilled, Number = h.Number, Position = new Position { Row = h.Position.Row, Column = h.Position.Column } }).ToArray(), Walls = this.Walls }; DirectionResponse response = newBoardState.MoveMarbles(liftedSide); if (response.Success && !newBoardState.BoardStateDidNotChange(response.BoardState)) { moves += liftedSide.ToString()[0]; if (response.Finished) { return new Solution { Success = true, Route = moves } } ; else { bool marblesStateChanged = newBoardState.Marbles.Count(m => !m.IsInHole) != response.BoardState.Marbles.Count(m => !m.IsInHole); newBoardState.UpdateBoardState(response.BoardState); return(newBoardState.FindRoute(moves, marblesStateChanged)); } } return(new Solution { Route = moves += '*' }); }
public YAMLNode ExportYAML(IExportContainer container) { YAMLMappingNode node = new YAMLMappingNode(); node.AddSerializedVersion(ToSerializedVersion(container.ExportVersion)); node.Add(HeightsName, Heights.ExportYAML(true)); if (HasHoles(container.ExportVersion)) { node.Add(HolesName, Holes.ExportYAML()); node.Add(HolesLODName, HolesLOD.ExportYAML()); node.Add(EnableHolesTextureCompressionName, EnableHolesTextureCompression); } if (HasShifts(container.ExportVersion)) { node.Add(ShiftsName, Shifts.ExportYAML(container)); } node.Add(PrecomputedErrorName, PrecomputedError.ExportYAML()); node.Add(MinMaxPatchHeightsName, MinMaxPatchHeights.ExportYAML()); if (HasDefaultPhysicMaterial(container.ExportVersion)) { node.Add(DefaultPhysicMaterialName, DefaultPhysicMaterial.ExportYAML(container)); } if (HasWidth(container.ExportVersion)) { node.Add(WidthName, Width); node.Add(HeightName, Height); } if (HasThickness(container.ExportVersion)) { node.Add(ThicknessName, Thickness); } if (HasResolution(container.ExportVersion)) { node.Add(ResolutionName, Resolution); } node.Add(LevelsName, Levels); node.Add(ScaleName, Scale.ExportYAML(container)); return(node); }
public override bool Equals(object obj, SpatialEqualityOptions options) { var other = obj as Polygon; if (ReferenceEquals(null, other)) { return(false); } if (IsEmpty && other.IsEmpty) { return(true); } return(Shell.Equals(other.Shell, options) && Holes.Count == other.Holes.Count && !Holes .Where((t, i) => !t.Equals(other.Holes[i], options)) .Any()); }
private void SplitHorizontalAt(Stack <Region> regionsToSplit, Region beingSplitted, int splitY) { //Get the number of holes. int holes = Settings.HolesInLine(beingSplitted.Width + 1); if (holes < 1) { holes = 1; } if (holes >= beingSplitted.Width + 1) { Regions.Add(beingSplitted); return; } //First make the line. for (int i = beingSplitted.Left; i <= beingSplitted.Right; ++i) { Map[i, splitY] = true; } //Make sure the line isn't blocking a hole at the edge of the region. if (beingSplitted.Left > 0 && (!Map[beingSplitted.Left - 1, splitY] || Holes.Contains(new Location(beingSplitted.Left - 1, splitY)))) { Map[beingSplitted.Left, splitY] = false; Holes.Add(new Location(beingSplitted.Left, splitY)); } if (beingSplitted.Right < Map.GetLength(1) - 1 && (!Map[beingSplitted.Right + 1, splitY] || Holes.Contains(new Location(beingSplitted.Right + 1, splitY)))) { Map[beingSplitted.Right, splitY] = false; Holes.Add(new Location(beingSplitted.Right, splitY)); } //Now make holes. //Get the possible cells to put a hole in. List <int> cellXs = new List <int>(beingSplitted.Width + 1); for (int i = 0; i < beingSplitted.Width + 1; ++i) { cellXs.Add(i + beingSplitted.Left); } //Randomly pick from them. int randomIndex; for (int i = 0; i < holes; ++i) { randomIndex = MathF.R.Next(0, cellXs.Count); Map[cellXs[randomIndex], splitY] = false; Holes.Add(new Location(cellXs[randomIndex], splitY)); cellXs.RemoveAt(randomIndex); } //Now split the region into two regions (assuming both regions are large enough). Move the regions around a bit to make sure the line we just made is not part of the regions. Region one = new Region(beingSplitted.TopLeft, new Location { X = beingSplitted.Right, Y = splitY - 1 }); Region two = new Region(new Location { X = beingSplitted.Left, Y = splitY + 1 }, beingSplitted.BottomRight); if (one.Width >= 0 && one.Height >= 0 && one.Left >= 0 && one.Right < Map.GetLength(0) && one.Top >= 0 && one.Bottom < Map.GetLength(1)) { regionsToSplit.Push(one); } if (two.Width >= 0 && two.Height >= 0 && two.Left >= 0 && two.Right < Map.GetLength(0) && two.Top >= 0 && two.Bottom < Map.GetLength(1)) { regionsToSplit.Push(two); } }
public static Vector3 ai_get_stroke_dir_8ball(Frame frame) { BALL_TYPE full_half = Player.ball_type; Vector3 r_hit; float angle; float minangle = Mathf.PI; float minangle_beta = Mathf.PI; Ball bhit, bcue; Hole hole; int minball = 0, minball_beta = 0; int minhole = -1, minhole_beta = -1; int i, j; Vector3 ai_err = Vector3.zero; if (ai_level == AI_LEVEL.LOW_LEVEL) { ai_err = Maths.vec_unit(new Vector3(Random.Range(-1.0f, 1.0f), 0, Random.Range(-1.0f, 1.0f))) * Constant.HOLE1_R * 1.5f; //ai_err=Maths.vec_unit (new Vector3(1.0f,0,-1.0f))*Constant.HOLE1_R*1.5f; } else if (ai_level == AI_LEVEL.MEDIUM_LEVEL) { ai_err = Maths.vec_unit(new Vector3(Random.Range(-1.0f, 1.0f), 0, Random.Range(-1.0f, 1.0f))) * Constant.HOLE1_R * 1.0f; } bcue = new Ball(frame.Balls[0]); for (i = 1; i < 16; i++) { if (frame.Balls[i].in_game) { if ((full_half == BALL_TYPE.BALL_HALF && frame.Balls[i].nr > 8) || (full_half == BALL_TYPE.BALL_FULL && frame.Balls[i].nr < 8) || (full_half == BALL_TYPE.BALL_ANY && frame.Balls[i].nr != 8) || (frame.Balls[i].nr == 8 && frame.Balls_in_game(full_half) == 0)) { bhit = new Ball(frame.Balls[i]); for (j = 0; j < Holes.GetHoleNum(Holes.BORDERS_8GAME); j++) { hole = Holes.GetHole(Holes.BORDERS_8GAME, j); r_hit = Maths.vec_unit(bhit.r - hole.aim) * (bcue.d + bhit.d) / 2.0f; r_hit = bhit.r + r_hit; if (!ball_in_way(0, r_hit, frame) && !ball_in_way(i, hole.aim, frame)) { angle = Mathf.Abs(Maths.vec_angle(r_hit - bcue.r, hole.aim - r_hit)); if (angle < minangle) { minball = i; minhole = j; minangle = angle; } } else if (!ball_in_way(0, r_hit, frame)) { angle = Mathf.Abs(Maths.vec_angle(r_hit - bcue.r, hole.aim - r_hit)); if (angle < minangle_beta) { minball_beta = i; minhole_beta = j; minangle_beta = angle; } } } } } } if (minball == 0) /* no proper ball found */ { minball = minball_beta; minhole = minhole_beta; minangle = minangle_beta; /* switch(full_half) { * case BALL_TYPE.BALL_FULL: * if( BallEvents.BM_get_balls_out_full()!=7 ){ * minball=1+my_rand(7-BallEvents.BM_get_balls_out_full()); * } * break; * case BALL_TYPE.BALL_HALF: * if( BallEvents.BM_get_balls_out_half()!=7 ){ * minball=1+my_rand(7-BallEvents.BM_get_balls_out_half()); * } * break; * case BALL_TYPE.BALL_ANY: * if( BallEvents.BM_get_balls_out_total()!=15 ){ * minball=1+my_rand(15-BallEvents.BM_get_balls_out_total()); * } * break; * } * if( minball==0 ){ * minball = ind_ball_nr(8,frame); * } else { * minball = nth_in_game(minball,frame,full_half); * }*/ } bhit = frame.Balls[minball]; if (minhole != -1) { hole = Holes.GetHole(Holes.BORDERS_8GAME, minhole); r_hit = Maths.vec_unit(bhit.r - hole.aim + ai_err * Maths.vec_abs(hole.aim - bhit.r) / 10.0f) * (bcue.d + bhit.d) / 2.0f; r_hit = bhit.r + r_hit - bcue.r; } else /* no proper ball found */ { r_hit = bhit.r - bcue.r; minhole = Random.Range(0, 6); } GamePlayUI.instance.SetAIPocket(minhole); return(Maths.vec_unit(r_hit)); }
public override int GetHashCode(SpatialEqualityOptions options) { unchecked { return(((Shell != null ? Shell.GetHashCode(options) : 0) * 397) ^ (Holes != null ? Holes.GetHashCode(options) : 0)); } }
//creates a hole private void create_hole(double PointOnGraphic_X, double PointOnGraphic_Y, double PointOnGraphic_Z, SolidEdgeGeometry.Face selected_face, int[] face_norm, string selected_face_normal) { // var selected_face = pGraphicDispatch as SolidEdgeGeometry.Face; PartDocument _doc = _application.ActiveDocument as PartDocument; RefPlanes refPlanes = null; RefPlane refPlane = null; refPlanes = _doc.RefPlanes; //Adding parallel refplane to the selected face refPlane = refPlanes.AddParallelByDistance(selected_face, 0.0, ReferenceElementConstants.igNormalSide, false, false, true, false); //Running windows form application System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.Run(new Form1()); MessageBox.Show("Cancel Hole Dimension?"); Form1 form1 = new Form1(); //Hole diameter from user input double cc = form1.Hole_dia; while (cc < 0.0) { MessageBox.Show("Enter valid dimension"); System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.Run(new Form1()); Form1 form2 = new Form1(); double dd = form2.Hole_dia; MessageBox.Show("Cancel diamension?"); if (cc == dd) { MessageBox.Show("invalid argument"); dd = 0.0; } cc = dd; } ProfileSets profileSets = null; ProfileSet profileSet = null; Profiles profiles = null; Profile profile = null; Models models = null; HoleDataCollection holeDataCollection = null; HoleData holeData = null; Holes2d holes2D = null; Holes holes = null; Sketchs sketchs = null; Sketch sketch = null; Array ref_dir = new double[3] as Array; //getting the unit vector of the reference direction refPlane.GetReferenceDirection(ref ref_dir); var Ref_dirX = ref_dir as double[]; Array root_point = new double[3] as Array; refPlane.GetRootPoint(ref root_point); var Root_point = root_point as double[]; //calculating the cross-product between ref_dir and normal vector double[] Ref_dirY = new double[3] { Ref_dirX[2] * face_norm[1] - Ref_dirX[1] * face_norm[2], Ref_dirX[0] * face_norm[2] - Ref_dirX[2] * face_norm[0], Ref_dirX[1] * face_norm[0] - Ref_dirX[0] * face_norm[1] }; double Xcenter = -0.06; //local coordinates double Ycenter = -0.06; //calculating global coordinates from local coordinates double[] X_bar = new double[3] { Xcenter *Ref_dirX[0] + Ycenter * Ref_dirY[0] + Root_point[0], Xcenter *Ref_dirX[1] + Ycenter * Ref_dirY[1] + Root_point[1], Xcenter *Ref_dirX[2] + Ycenter * Ref_dirY[2] + Root_point[2] }; //Calculating the angle between vectors root_point and global double[] OX = new double[3] { PointOnGraphic_X - Root_point[0], PointOnGraphic_Y - Root_point[1], PointOnGraphic_Z - Root_point[2] }; //calculating the modulus of vector OX double OX_Mod = Math.Sqrt(Math.Pow(OX[0], 2) + Math.Pow(OX[1], 2) + Math.Pow(OX[2], 2)); //calculating the modulus of vector Ref_dirX double Ref_dirX_Mod = Math.Sqrt(Math.Pow(Ref_dirX[0], 2) + Math.Pow(Ref_dirX[1], 2) + Math.Pow(Ref_dirX[2], 2)); //calculating the modulus of the vector ReF_dirY double Ref_dirY_Mod = Math.Sqrt(Math.Pow(Ref_dirY[0], 2) + Math.Pow(Ref_dirY[1], 2) + Math.Pow(Ref_dirY[2], 2)); //calculating the dot product between vector OX and Ref_dirY double dotY = (OX[0] * Ref_dirY[0]) + (OX[1] * Ref_dirY[1]) + (OX[2] * Ref_dirY[2]); //calculating the dot product between vector OX and Ref_dirX double dotX = (OX[0] * Ref_dirX[0]) + (OX[1] * Ref_dirX[1]) + (OX[2] * Ref_dirX[2]); //calculating the angle between vector OX and Ref_dirY double angleY = Math.Acos(dotY / (OX_Mod * Ref_dirY_Mod)); //calculating the angle between vector OX and Ref_dirX double angleX = Math.Acos(dotX / (OX_Mod * Ref_dirX_Mod)); double X_dir = 0.0; double Y_dir = 0.0; if (angleY > Math.PI / 2) { X_dir = OX_Mod * Math.Cos(-angleX); Y_dir = OX_Mod * Math.Sin(-angleX); } else { X_dir = OX_Mod * Math.Cos(angleX); Y_dir = OX_Mod * Math.Sin(angleX); } if (OX_Mod == 0.0) { X_dir = 0.0; Y_dir = 0.0; } if (cc > 0.0) { sketchs = _doc.Sketches; sketch = sketchs.Add(); holeDataCollection = _doc.HoleDataCollection; //Defining hole properties holeData = holeDataCollection.Add( HoleType: SolidEdgePart.FeaturePropertyConstants.igRegularHole, HoleDiameter: cc / 1000); profileSets = _doc.ProfileSets; profileSet = profileSets.Add(); //profiles = profileSet.Profiles; profiles = sketch.Profiles; profile = profiles.Add(refPlane); holes2D = profile.Holes2d; var dd = holes2D.Add(X_dir, Y_dir); profile.End(ProfileValidationType.igProfileClosed); // dd.Move(X_dir, Y_dir, 0.0, 0.0); //_application.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewLookatFace); //getting the hole collection and creating a simple hole Model model = _doc.Models.Item(1); holes = model.Holes; holes.AddThroughNext( Profile: profile, ProfilePlaneSide: SolidEdgePart.FeaturePropertyConstants.igBoth, Data: holeData); } }
async void ISEMouseEvents.MouseClick(short sButton, short sShift, double dX, double dY, double dZ, object pWindowDispatch, int lKeyPointType, object pGraphicDispatch) { if (checkhole) { try { //MessageBox.Show($"dx{1000 * dX}, dy{1000 * dY}, dz{1000 * dZ}"); _getting_suggestions = true; _application = SolidEdgeCommunity.SolidEdgeUtils.Connect(); PartDocument _doc = _application.ActiveDocument as PartDocument; Model _model = _doc.Models.Item(1); Holes _holes = _model.Holes; var cc = _holes.Count; var selected_face = pGraphicDispatch as SolidEdgeGeometry.Face; Array minparams = new double[2] as Array; Array maxparams = new double[2] as Array; selected_face.GetParamRange(ref minparams, ref maxparams); var mins = minparams as double[]; var maxs = maxparams as double[]; Array u = new double[2] { mins[0] + 0.5 * (maxs[0] - mins[0]), mins[1] + 0.5 * (maxs[1] - mins[1]) }; Array n = new double[3] as Array; //getting the normal vector of the selected face selected_face.GetNormal(1, ref u, ref n); var norm = n as double[]; int x = (int)Math.Round(norm[0]); int y = (int)Math.Round(norm[1]); int z = (int)Math.Round(norm[2]); int[] face_norm = new int[3] { x, y, z }; string Face_normal_vector = string.Format("{0:0}{1:0}{2:0}", x, y, z); //Accessing 3D mouse coordinates _mouse.PointOnGraphic(out int PointOnGraphicFlag, out double PointOnGraphic_X, out double PointOnGraphic_Y, out double PointOnGraphic_Z); MessageBox.Show($"PointonGraphic {PointOnGraphicFlag}, {PointOnGraphic_X}, {PointOnGraphic_Y}, {PointOnGraphic_Z}"); // create_hole(PointOnGraphic_X, PointOnGraphic_Y, PointOnGraphic_Z, selected_face, face_norm, Face_normal_vector); List <HoleInfo> _holeInfos = new List <HoleInfo>(); foreach (Hole hole in _holes) { HoleInfo _holeInfo = default(HoleInfo); SolidEdgePart.HoleData _holedata = hole.HoleData as SolidEdgePart.HoleData; _holeInfo.diameter = 1000 * _holedata.HoleDiameter; Profile profile = hole.Profile as Profile; Holes2d holes2d = profile.Holes2d as Holes2d; Hole2d hole2d = holes2d.Item(1); double x_2d, y_2d, x_3d, y_3d, z_3d; hole2d.GetCenterPoint(out x_2d, out y_2d); profile.Convert2DCoordinate(x_2d, y_2d, out x_3d, out y_3d, out z_3d); _holeInfo.xd = x_2d * 1000; _holeInfo.yd = y_2d * 1000; _holeInfo.x = x_3d * 1000; _holeInfo.y = y_3d * 1000; _holeInfo.z = z_3d * 1000; RefPlane plane = profile.Plane as RefPlane; Array normals = new double[3] as Array; plane.GetNormal(ref normals); double[] ns = normals as double[]; _holeInfo.nx = ns[0]; _holeInfo.ny = ns[1]; _holeInfo.nz = ns[2]; _holeInfos.Add(_holeInfo); // MessageBox.Show(string.Format("diam: {0:0.000} x: {1:0.000}, y: {2:0.000}, z: {3:0.000}, nx: {3:0.000}, ny: {3:0.000}, nz: {3:0.000}", // _holeInfo.diameter, _holeInfo.x, _holeInfo.y, _holeInfo.z, _holeInfo.nx, _holeInfo.ny, _holeInfo.nz)); } _holeInfos = _holeInfos.OrderBy(p => p.diameter).ToList(); string query = "http://trapezohedron.shapespace.com:9985/v1/suggestions?query={\"status\": {\"v\": ["; bool first = true; //adding the hole diameters to query foreach (HoleInfo hi in _holeInfos) { if (!first) { query += ", "; } first = false; string add_v = String.Format("\"{0:0.0}\"", hi.diameter); query += add_v; } query += "], \"e\": ["; double dist_bucket_size = 50; int v_source = 0; first = true; foreach (HoleInfo hi_source in _holeInfos) { int v_dest = 0; string bucket_dir_source = string.Format("{0:0.0000}{1:0.0000}{2:0.0000}", hi_source.nx, hi_source.ny, hi_source.nz); // MessageBox.Show($"Source {hi_source.x}, {hi_source.y}, {hi_source.z} --- {hi_source.nx}, {hi_source.ny}, {hi_source.nz} "); // MessageBox.Show($"{bucket_dir_source}"); foreach (HoleInfo hi_dest in _holeInfos) { if (v_dest > v_source) { //MessageBox.Show($"destination {hi_dest.x}, {hi_dest.y}, {hi_dest.z} --- {hi_dest.nx}, {hi_dest.ny}, {hi_dest.nz}"); if (!first) { query += ", "; } first = false; string bucket_dir_dest = string.Format("{0:0.0000}{1:0.0000}{2:0.0000}", hi_dest.nx, hi_dest.ny, hi_dest.nz); double e_dist = Math.Sqrt(Math.Pow(hi_source.x - hi_dest.x, 2) + Math.Pow(hi_source.y - hi_dest.y, 2) + Math.Pow(hi_source.z - hi_dest.z, 2)); //MessageBox.Show($"Bucket_dir_dest {bucket_dir_dest}, e_dist {e_dist}"); double e_dist_bucket = Math.Ceiling(e_dist / dist_bucket_size); //MessageBox.Show($"e_dist_bucket {e_dist_bucket}"); string add_e = string.Format("[[\"{0:0.0}\", \"{1:0.0}\"], \"{2:0}\"]", hi_source.diameter, hi_dest.diameter, e_dist_bucket); if (bucket_dir_source == bucket_dir_dest) { add_e += string.Format(",[[\"{0:0.0}\", \"{1:0.0}\"], \"co_dir\"]", hi_source.diameter, hi_dest.diameter); //add_e += string.Format("[[\"{0:0.0}\", \"{1:0.0}\"], \"co_dir\"]", hi_source.diameter, hi_dest.diameter); } query += add_e; } v_dest += 1; } v_source += 1; } // query += "]}, \"location\":[[[\"32.0\", \"*\"], \"co_dir\"],"; query += "]}, \"location\": ["; first = true; //Calculating distance from the mouse location to the hole center points foreach (HoleInfo H_dest in _holeInfos) { if (!first) { query += ", "; } first = false; double e_dest = Math.Sqrt(Math.Pow(H_dest.x - (1000 * PointOnGraphic_X), 2) + Math.Pow(H_dest.y - (1000 * PointOnGraphic_Y), 2) + Math.Pow(H_dest.z - (1000 * PointOnGraphic_Z), 2)); double e_dist_bucket = Math.Ceiling(e_dest / dist_bucket_size); string add_e = string.Format("[[\"{0:0.0}\", \"*\"], \"{1:0}\"]", H_dest.diameter, e_dist_bucket); string Hole_Normal_vector = string.Format("{0:0}{1:0}{2:0}", H_dest.nx, H_dest.ny, H_dest.nz); if (Hole_Normal_vector == Face_normal_vector) { add_e += string.Format(", [[\"{0:0.0}\", \"*\"], \"co_dir\"]", H_dest.diameter); //MessageBox.Show($"2D coordinates {H_dest.xd},{H_dest.yd}"); } query += add_e; } query += "]}"; MessageBox.Show($"{query}"); //string query = "http://trapezohedron.shapespace.com:9985/v1/suggestions?query={\"status\": {\"v\": [\"32.0\", \"57.0\"], \"e\": [[[\"32.0\", \"57.0\"], \"co_dir\"]]}, \"location\": [[[\"32.0\", \"*\"], \"co_dir\"]]}"; var values = new Dictionary <string, string> { }; var content = new FormUrlEncodedContent(values); var response = await _client.GetAsync(query); var responseString = await response.Content.ReadAsStringAsync(); MessageBox.Show(responseString); string pattern = @"\d*\.\d"; matchCollection = Regex.Matches(responseString, pattern); count = matchCollection.Count; Match = new double[count]; int i = 0; string match = ""; foreach (Match m in matchCollection) { match += string.Format("{0} ", m.Value); Match[i] = Convert.ToDouble(m.Value); i++; } // MessageBox.Show($"{match}"); create_hole(PointOnGraphic_X, PointOnGraphic_Y, PointOnGraphic_Z, selected_face, face_norm, Face_normal_vector); _getting_suggestions = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (checkcutout) { try { //MessageBox.Show("cutout feature selected"); _getting_suggestions = true; _application = SolidEdgeCommunity.SolidEdgeUtils.Connect(); PartDocument _doc = _application.ActiveDocument as PartDocument; Model _model = _doc.Models.Item(1); ExtrudedCutouts _extrudedCutouts = _model.ExtrudedCutouts; int a = _extrudedCutouts.Count; var selected_face = pGraphicDispatch as SolidEdgeGeometry.Face; Array minparams = new double[2] as Array; Array maxparams = new double[2] as Array; selected_face.GetParamRange(ref minparams, ref maxparams); var mins = minparams as double[]; var maxs = maxparams as double[]; Array u = new double[2] { mins[0] + 0.5 * (maxs[0] - mins[0]), mins[1] + 0.5 * (maxs[1] - mins[1]) }; Array n = new double[3] as Array; //getting the normal vector of the selected face selected_face.GetNormal(1, ref u, ref n); var norm = n as double[]; int x = (int)Math.Round(norm[0]); int y = (int)Math.Round(norm[1]); int z = (int)Math.Round(norm[2]); int[] face_norm = new int[3] { x, y, z }; string Face_normal_vector = string.Format("{0:0}{1:0}{2:0}", x, y, z); //Accessing 3D mouse coordinates _mouse.PointOnGraphic(out int PointOnGraphicFlag, out double PointOnGraphic_X, out double PointOnGraphic_Y, out double PointOnGraphic_Z); List <CutoutInfo> _Cutoutinfos = new List <CutoutInfo>(); foreach (ExtrudedCutout extrudedCutout in _extrudedCutouts) { CutoutInfo _cutoutInfo = default(CutoutInfo); _cutoutInfo.KeyPoints = new List <double>(); Profile profile = extrudedCutout.Profile as Profile; SolidEdgeFrameworkSupport.Lines2d lines2D = profile.Lines2d; double x_3d, y_3d, z_3d, x_3D, y_3D, z_3D; int handletype; SolidEdgeFramework.KeyPointType KeyPointType; int rc = lines2D.Count; for (int j = 1; j <= rc; j++) { var ii = lines2D.Item(j); int keycout = ii.KeyPointCount; for (int i = 0; i < keycout; i++) { ii.GetKeyPoint(i, out x_3d, out y_3d, out z_3d, out KeyPointType, out handletype); profile.Convert2DCoordinate(x_3d, y_3d, out x_3D, out y_3D, out z_3D); _cutoutInfo.KeyPoints.Add(x_3D * 1000); _cutoutInfo.KeyPoints.Add(y_3D * 1000); _cutoutInfo.KeyPoints.Add(z_3D * 1000); } } RefPlane plane = profile.Plane as RefPlane; Array normals = new double[3] as Array; plane.GetNormal(ref normals); //getting the normal vector of the cutout profile double[] ns = normals as double[]; _cutoutInfo.nx = ns[0]; _cutoutInfo.ny = ns[1]; _cutoutInfo.nz = ns[2]; _Cutoutinfos.Add(_cutoutInfo); } var dd = _Cutoutinfos[0].KeyPoints[0]; foreach (CutoutInfo info in _Cutoutinfos) { //MessageBox.Show($"{Math.Round(info.nx)},{Math.Round(info.ny)},{Math.Round(info.nz)}"); string Cutout_normal_vector = string.Format("{0:0}{1:0}{2:0}", Math.Round(info.nx), Math.Round(info.ny), Math.Round(info.nz)); if (Face_normal_vector == Cutout_normal_vector) { MessageBox.Show("Co-dir"); } } Create_Cutout(PointOnGraphic_X, PointOnGraphic_Y, PointOnGraphic_Z, selected_face, face_norm, Face_normal_vector); } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (checkslot) { try { // MessageBox.Show("Slot feature selected"); _getting_suggestions = true; _application = SolidEdgeCommunity.SolidEdgeUtils.Connect(); PartDocument _doc = _application.ActiveDocument as PartDocument; Model _model = _doc.Models.Item(1); Slots slots = _model.Slots; int cc = slots.Count; var selected_face = pGraphicDispatch as SolidEdgeGeometry.Face; Array minparams = new double[2] as Array; Array maxparams = new double[2] as Array; selected_face.GetParamRange(ref minparams, ref maxparams); var mins = minparams as double[]; var maxs = maxparams as double[]; Array u = new double[2] { mins[0] + 0.5 * (maxs[0] - mins[0]), mins[1] + 0.5 * (maxs[1] - mins[1]) }; Array n = new double[3] as Array; //getting the normal vector of the selected face selected_face.GetNormal(1, ref u, ref n); var norm = n as double[]; int x = (int)Math.Round(norm[0]); int y = (int)Math.Round(norm[1]); int z = (int)Math.Round(norm[2]); int[] face_norm = new int[3] { x, y, z }; string Face_normal_vector = string.Format("{0:0}{1:0}{2:0}", x, y, z); //Accessing 3D mouse coordinates _mouse.PointOnGraphic(out int PointOnGraphicFlag, out double PointOnGraphic_X, out double PointOnGraphic_Y, out double PointOnGraphic_Z); List <Slotinfo> _Slotinfos = new List <Slotinfo>(); foreach (Slot slot in slots) { Slotinfo _SlotInfo = default(Slotinfo); _SlotInfo.KeyPoints = new List <double>(); Profile profile = slot.Profile as Profile; Lines2d lines2D = profile.Lines2d; int lincount = lines2D.Count; double x_3d, y_3d, z_3d, x_3D, y_3D, z_3D; int handletype; KeyPointType KeyPointType; int rc = lines2D.Count; for (int j = 1; j <= rc; j++) { var ii = lines2D.Item(j); int keycout = ii.KeyPointCount; for (int i = 0; i < keycout; i++) { ii.GetKeyPoint(i, out x_3d, out y_3d, out z_3d, out KeyPointType, out handletype); profile.Convert2DCoordinate(x_3d, y_3d, out x_3D, out y_3D, out z_3D); _SlotInfo.KeyPoints.Add(x_3D * 1000); _SlotInfo.KeyPoints.Add(y_3D * 1000); _SlotInfo.KeyPoints.Add(z_3D * 1000); } } RefPlane plane = profile.Plane as RefPlane; Array normals = new double[3] as Array; plane.GetNormal(ref normals); //getting the normal vector of the cutout profile double[] ns = normals as double[]; _SlotInfo.nx = ns[0]; _SlotInfo.ny = ns[1]; _SlotInfo.nz = ns[2]; _Slotinfos.Add(_SlotInfo); } var dd = _Slotinfos[0].KeyPoints[0]; foreach (Slotinfo info in _Slotinfos) { //Comparing the normal vector of the face to the slot normal vector string Slot_normal_vector = string.Format("{0:0}{1:0}{2:0}", Math.Round(info.nx), Math.Round(info.ny), Math.Round(info.nz)); if (Face_normal_vector == Slot_normal_vector) { MessageBox.Show("Co-dir"); } } Create_Slot(PointOnGraphic_X, PointOnGraphic_Y, PointOnGraphic_Z, selected_face, face_norm, Face_normal_vector); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public virtual void AddHole(Hole hole) { hole.Courseconfiguration = this; Holes.Add(hole); }