private static void AddOriginPoint(List <SolverGeometricObject> solverGeometry) { var originPoint = new SolverGeometricObject(null); originPoint.AddPoint(new SolverDataPoint(new Point3D())); AddGeometry(originPoint, solverGeometry); }
public void SameXCoordinateMatch() { var document = TestUtils.DefaultsSetup(); var solver = new Solver(document); document.Transact(); var sketchCreator = new SketchCreator(document, false); var sketchNode = sketchCreator.BuildSketchNode(); document.Commit("Added sketch"); document.Transact(); var point = new SolverGeometricObject(sketchNode); point.AddPoint(new SolverDataPoint(new Point3D(10, 2, 0))); solver.Geometry.Add(point); solver.LastGeometry.Add(point); var coordinateMatch = new SameCoordinatePoints(solver, 2); var pointN = new Point3D(10 + 0.1, 20 - 0.1, 0.1); var plnOfTheView = new gpPln(new gpPnt(0, 0, 0), new gpDir(0, 0, 1)); var solutions = coordinateMatch.InterestingShapeAroundPoint(plnOfTheView, pointN); Assert.AreEqual(solutions.Count, 1); var solution = solutions.First(); Assert.IsTrue(solution != null, "A solution should be found"); Assert.IsTrue(solution is SolverEdgeTwoPointsResult, "Invalid solution type"); Assert.IsTrue(solution.Point.IsEqual(new Point3D(10, 19.9, 0)), "Invalid magic point found"); }
public void XYCoordinatesMatch() { var document = TestUtils.DefaultsSetup(); var solver = new Solver(document); document.Transact(); var sketchCreator = new SketchCreator(document, false); var sketchNode = sketchCreator.BuildSketchNode(); document.Commit("Added sketch"); document.Transact(); var point = new SolverGeometricObject(sketchNode); point.AddPoint(new SolverDataPoint(new Point3D(4, 11, 0))); solver.Geometry.Add(point); solver.LastGeometry.Add(point); var interestingPoints = new List <SolverPreviewObject>(); var pointN = new Point3D(3.9, 2.9, 0.1); var plnOfTheView = new gpPln(new gpPnt(0, 0, 0), new gpDir(0, 0, 1)); var coordinateMatch = new SameCoordinatePoints(solver, 2); var solutions = coordinateMatch.InterestingShapeAroundPoint(plnOfTheView, pointN); Assert.AreEqual(solutions.Count, 1); var solution = solutions.First(); Assert.IsTrue(solution != null, "A solution should be found"); Assert.IsTrue(solution is SolverEdgeTwoPointsResult, "Invalid solution type"); interestingPoints.Add(solution); point = new SolverGeometricObject(sketchNode); point.AddPoint(new SolverDataPoint(new Point3D(10, 3, 0))); solver.Geometry.Clear(); solver.LastGeometry.Clear(); solver.Geometry.Add(point); solver.LastGeometry.Add(point); coordinateMatch = new SameCoordinatePoints(solver, 2); solutions = coordinateMatch.InterestingShapeAroundPoint(plnOfTheView, pointN); Assert.AreEqual(solutions.Count, 1); solution = solutions.First(); interestingPoints.Add(solution); Assert.IsTrue(solution != null, "A solution should be found"); Assert.IsTrue(solution is SolverEdgeTwoPointsResult, "Invalid solution type"); var results = SolverTestsUtils.GetIntersectionPoints(interestingPoints, document); Assert.AreEqual(results.Count, 1, "Wrong number of intersection results!"); Assert.IsTrue(results[0].IsEqual(new Point3D(4, 3, 0)), "Invalid magic point found"); }
public override List <SolverPreviewObject> InterestingShapeAroundPoint(gpPln planeOfTheView, Point3D point) { var qosLock = QosFactory.Instance.Get(QosNames.EdgeMatchLock); qosLock.Begin(); foreach (var edge in Geometry.SelectMany(geometricObject => geometricObject.Edges)) { // Calculate the distance from the point to the curve GeomCurve curve; var first = 0.0; var last = 0.0; unsafe { curve = BRepTool.Curve(edge.Edge, ref first, ref last); } if (curve == null) { continue; } // Add a curve domain protection if (first > last) { continue; } ExtremaExtPC extrema = null; try { var adaptor = new GeomAdaptorCurve(curve, first, last); extrema = new ExtremaExtPC(point.GpPnt, adaptor, Precision.Confusion); } catch { Log.Debug("Exception on generate extrema points"); } if (extrema == null) { continue; } if (!extrema.IsDone) { continue; } if (extrema.NbExt < 1) { continue; } // The point is on edge if (extrema.SquareDistance(1) >= CoreGlobalPreferencesSingleton.Instance.ZoomLevel * _precision) { continue; } // Generate a point on the edge by projecting var projectionPoint = new GeomAPIProjectPointOnCurve(point.GpPnt, curve); if (projectionPoint.NbPoints <= 0) { continue; } List <SolverGeometricObject> selectedEdge = Geometry.Where(geomObj => geomObj.Edges.Contains(edge)).ToList(); //LastGeometry.Clear(); //LastGeometry.AddRange(selectedEdge); var originPoint = new SolverGeometricObject(null); originPoint.AddPoint(new SolverDataPoint(new Point3D())); var result = GeomUtils.ProjectPointOnPlane(new Point3D().GpPnt, planeOfTheView, Precision.Confusion); //if(result == new gpPnt(0,0,0)) //{ // LastGeometry.Add(originPoint); //} if (selectedEdge.Count > 0 && selectedEdge.First().Edges.Count > 0) { return new List <SolverPreviewObject>() { new SolverPointResult(new Point3D(projectionPoint.NearestPoint), selectedEdge.First().Edges.First().ParentIndex) } } ; // {Text = "On Edge"}; else { return new List <SolverPreviewObject>() { new SolverPointResult(new Point3D(projectionPoint.NearestPoint)) } }; } qosLock.End(); return(new List <SolverPreviewObject>()); } }