public override void OnActivate() { base.OnActivate(); var sketchBuilder = new SketchCreator(Document, false); sketchNode = sketchBuilder.CurrentSketch; if (sketchNode == null) { ActionsGraph.SwitchAction(ModifierNames.StartSketch, ModifierNames.ArcCenterStartEnd); return; } normalOnPlane = sketchBuilder.NormalOnSketch.Value.GpAxis; sketchNode = sketchBuilder.CurrentSketch; // Block drawing plane Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.Suspend); ActionsGraph[InputNames.CoordinateParser].Send(CoordinatateParserNames.SetStage, ParserStage.Unknown); var pointBuilder = GetSketchNode(Document, new Point3D(), sketchNode); var pointBuilder2 = GetSketchNode(Document, new Point3D(0.0, 0, 0), sketchNode); var pointBuilder3 = GetSketchNode(Document, new Point3D(0, 0.0, 0), sketchNode); var builder = new NodeBuilder(Document, FunctionNames.Arc); builder[0].Reference = pointBuilder.Node; builder[1].Reference = pointBuilder2.Node; builder[2].Reference = pointBuilder3.Node; builder.ExecuteFunction(); Inputs[InputNames.UiElementsItem].Send(NotificationNames.RefreshPropertyTab, builder.Node); Reset(); }
public void PointOnPointTest() { var document = TestUtils.DefaultsSetup(); var sketch = new SketchCreator(document); var sketchNode = sketch.BuildSketchNode(); document.Transact(); var firstPoint = sketch.GetPoint(new Point3D(3, 1, 0)); var secondPoint = sketch.GetPoint(new Point3D(4, 2, 0)); document.Commit("Draw"); var constraintBuilder = new NodeBuilder(document, Constraint2DNames.PointOnPointFunction); constraintBuilder[0].Reference = firstPoint.Node; constraintBuilder[1].Reference = secondPoint.Node; var docSolverAdapter = new DocumentToSolverAdapter(document, sketchNode); docSolverAdapter.ImpactedNodes(firstPoint.Node, -1); docSolverAdapter.Solve(); firstPoint = new NodeBuilder(firstPoint.Node); secondPoint = new NodeBuilder(secondPoint.Node); Assert.IsTrue(Math.Abs(firstPoint[1].TransformedPoint3D.X - secondPoint[1].TransformedPoint3D.X) < 0.01, "invalid x axis values"); Assert.IsTrue(Math.Abs(firstPoint[1].TransformedPoint3D.Y - secondPoint[1].TransformedPoint3D.Y) < 0.01, "invalid y axis values"); }
public override void OnActivate() { base.OnActivate(); var mouseCursorInput = ActionsGraph[InputNames.MouseCursorInput]; mouseCursorInput.Send(NotificationNames.SetResourceManager, MetaActionResource.ResourceManager); mouseCursorInput.Send(NotificationNames.SetCursorName, "arcRSE.cur"); var sketchBuilder = new SketchCreator(Document, false); sketchNode = sketchBuilder.CurrentSketch; if (sketchNode == null) { ActionsGraph.SwitchAction(ModifierNames.StartSketch, ModifierNames.ArcStartEndRadius); return; } normalOnPlane = sketchBuilder.NormalOnSketch.Value.GpAxis; sketchNode = sketchBuilder.CurrentSketch; // Block drawing plane Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.Suspend); ActionsGraph[InputNames.CoordinateParser].Send(CoordinatateParserNames.SetStage, ParserStage.Unknown); Reset(); }
public void GeometryParallelismTest() { 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(); // Test parallelism var parallelMatch = new ParallelLineMatch(solver, 5.0 / 180 * Math.PI); var initialPosition = new Point3D(3, 1, 0); var currentPosition = new Point3D(4.05, 1.95, 0); var line = TestUtils.Line(document, sketchNode, new Point3D(1, 1, 0), new Point3D(3, 3, 0)); var result = new SolverGeometricObject(line.Node); NodeHelper.BuildSolverInfo(result, result.Parent, 0.0872, true); solver.Refresh(); var solution = parallelMatch.GeometryParallel(currentPosition, initialPosition); Assert.IsTrue(solution.Point.X - 4 < Precision.Confusion, "Invalid X axis parallelism"); Assert.IsTrue(solution.Point.Y - 2 < Precision.Confusion, "Invalid Y axis parallelism"); Assert.IsTrue(solution.Point.Z < Precision.Confusion, "Invalid Z axis parallelism"); }
public override void OnActivate() { base.OnActivate(); GetOptions(); var documentGraph = Document.Root.Get <DocumentContextInterpreter>().ShapesGraph; var sketchCreator = new SketchCreator(Document); var sketchNode = sketchCreator.CurrentSketch; var linkedPoints = documentGraph.GetReferredByNodes(sketchNode); _referencedNodes.Clear(); var constraints = new List <int>(); foreach (var child in Document.Root.Children) { var nb = new NodeBuilder(child.Value); if (nb.FunctionName == Constraint2DNames.PositionToCenterFunction) { constraints.Add(nb.Dependency[0].ReferenceBuilder.Node.Index); } } foreach (var node in linkedPoints) { var builder = new NodeBuilder(node); if (builder.FunctionName != FunctionNames.Point) { continue; } _referencedNodes[node.Index] = constraints.Contains(node.Index); } DrawPreviewPoints(); }
public void EdgeContinuationDetectionTest() { var plnOfTheView = new gpPln(new gpPnt(0, 0, 0), new gpDir(0, 0, 1)); 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(); // Test parallelism var linecontinuationMatch = new EdgeContinuationMatch(solver, 5.0 / 180 * Math.PI); var currentPosition = new Point3D(4.02, 4, 0); var line = TestUtils.Line(document, sketchNode, new Point3D(1, 1, 0), new Point3D(3, 3, 0)); var result = new SolverGeometricObject(line.Node); NodeHelper.BuildSolverInfo(result, result.Parent, 0.0872, true); solver.Refresh(); var solutions = linecontinuationMatch.InterestingShapeAroundPoint(plnOfTheView, currentPosition); Assert.AreEqual(solutions.Count, 1); var solution = solutions.First(); Assert.IsTrue(solution.Point.X - 4.01 < Precision.Confusion, "Invalid X solution"); Assert.IsTrue(solution.Point.Y - 4.01 < Precision.Confusion, "Invalid Y solution"); Assert.IsTrue(solution.Point.Z < Precision.Confusion, "Invalid Z solution"); }
public void GeometryPerpendicularTest() { var plnOfTheView = new gpPln(new gpPnt(0, 0, 0), new gpDir(0, 0, 1)); 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(); // Test parallelism var perpendicularMatch = new OrthogonalLineMatch(solver, 5.0 / 180 * Math.PI); var initialPosition = new Point3D(6, 2, 0); var currentPosition = new Point3D(3.9, 4, 0); var line = TestUtils.Line(document, sketchNode, new Point3D(1, 1, 0), new Point3D(4, 4, 0)); var result = new SolverGeometricObject(line.Node); NodeHelper.BuildSolverInfo(result, result.Parent, 0.0872, true); solver.Refresh(); var solution = perpendicularMatch.InterestingShapeAroundPoint(plnOfTheView, currentPosition, initialPosition); Assert.IsTrue(solution.Point.X - 3.95 < Precision.Confusion, "Invalid X solution"); Assert.IsTrue(solution.Point.Y - 4.05 < Precision.Confusion, "Invalid Y solution"); Assert.IsTrue(solution.Point.Z < Precision.Confusion, "Invalid Z solution"); }
public void ExtrudeSketchTest() { var document = TestUtils.DefaultsSetup(); var sketchCreator = new SketchCreator(document, false); var sketchNode = sketchCreator.BuildSketchNode(); document.Transact(); var circleBuilder = TestUtils.Circle(document, sketchNode, new Point3D(0, 0, 0), 10); TestUtils.Circle(document, sketchNode, new Point3D(20, 20, 0), 10); Assert.AreEqual(circleBuilder.LastExecute, true); sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = AutoGroupLogic.RebuildSketchFace(sketchNode, document); var extrudeBuilder = new NodeBuilder(document, FunctionNames.Extrude); extrudeBuilder[0].Reference = sketchNode; extrudeBuilder[1].Integer = 0; extrudeBuilder[2].Real = 10; extrudeBuilder.ExecuteFunction(); Assert.AreEqual(extrudeBuilder.LastExecute, true); document.Commit("Extrude created"); document.Transact(); var volume = GeomUtils.GetSolidVolume(extrudeBuilder.Shape); Assert.AreEqual(volume, 2 * Math.PI * 1000); Assert.AreEqual(document.Root.Children.Count, 6); }
public static void AddRectangleToNode(Document document, int point1, int point2) { if (!document.Root.Children.ContainsKey(point1) || !document.Root.Children.ContainsKey(point2)) { return; } var sketchNode = AutoGroupLogic.FindSketchNode(document.Root[point1]); var axis = new gpAx2(); axis.Axis = (sketchNode.Children[1].Get <Axis3DInterpreter>().Axis.GpAxis); var pointLinker = new SketchCreator(document).PointLinker; var point3Ds = new List <Point3D>(); var nb1 = new NodeBuilder(document.Root[point1]); var nb2 = new NodeBuilder(document.Root[point2]); var _firstPoint = nb1.Dependency[1].TransformedPoint3D; var _secondPoint = nb2.Dependency[1].TransformedPoint3D; var firstPoint2D = _firstPoint.ToPoint2D(axis); var secondPoint2D = _secondPoint.ToPoint2D(axis); var x1 = firstPoint2D.X; var y1 = firstPoint2D.Y; var x2 = secondPoint2D.X; var y2 = secondPoint2D.Y; point3Ds.Add(GeomUtils.Point2DTo3D(axis, x1, y1)); point3Ds.Add(GeomUtils.Point2DTo3D(axis, x2, y1)); point3Ds.Add(GeomUtils.Point2DTo3D(axis, x2, y2)); point3Ds.Add(GeomUtils.Point2DTo3D(axis, x1, y2)); document.Root.Remove(nb1.Node.Index); document.Root.Remove(nb2.Node.Index); BuildLine(document, pointLinker, point3Ds[0], point3Ds[1]); BuildLine(document, pointLinker, point3Ds[1], point3Ds[2]); BuildLine(document, pointLinker, point3Ds[2], point3Ds[3]); BuildLine(document, pointLinker, point3Ds[3], point3Ds[0]); }
public void TryLoadNewFile() { try { var document = TestUtils.DefaultsSetup(); const string startDir = @"..\..\bin\Debug\"; document.LoadFromXml(startDir + @"NewFile.naroxml"); document.Transact(); var sketchCreator = new SketchCreator(document, false); var sketchNode = sketchCreator.BuildSketchNode(); var builder = new NodeBuilder(document, FunctionNames.Point); builder[0].Reference = sketchNode; builder[1].TransformedPoint3D = new Point3D(0, 10, 10); Assert.IsTrue(builder.ExecuteFunction()); document.Commit(@"Check consistency"); Assert.IsTrue(true); } catch (Exception) { Assert.IsTrue(false, "Failed to load NewFile.naroxml Did you change the format of file?"); } }
protected override void OnMouseDownAction(Mouse3DPosition mouseData) { if (Points.Count == 0) { Points.Add(mouseData.Point); _firstCoordinateSet = true; Points.Add(new Point3D()); return; } if (Points.Count == 2) { InitSession(); var sketchCreator = new SketchCreator(Document); var normalOnPlane = sketchCreator.NormalOnSketch.Value.GpAxis; var builder = NodeBuilderUtils.BuildLineInDocument(Document, false, normalOnPlane, Points[0], Points[1]); NodeBuilderUtils.BuildDimensionForLine(Document, builder, Points[0], Points[1]); UpdateView(); Points.Clear(); AddNodeToTree(builder.Node); RebuildTreeView(); Document.Commit("Added Dimension"); } }
public void ComputeHorizontal() { var document = TestUtils.DefaultsSetup(); var sketch = new SketchCreator(document); var sketchNode = sketch.BuildSketchNode(); document.Transact(); var pointLinker = sketch.PointLinker; var line = ConstraintUtils.BuildLine(document, pointLinker, new Point3D(1, 1, 0), new Point3D(3, 1, 0)); var options = new SketchHinterOptions { ParallelAngle = GeomUtils.DegreesToRadians(5.0), PointRange = 3.0 }; var sketchHinter = new Hinter2D(sketchNode, document, options); sketchHinter.Populate(); var result = sketchHinter.ApplyAlgorithms(line); document.Commit("Drawn line"); Assert.AreEqual(sketchHinter.HinterShapes[line.Node.Index].Builder.Node.Index, line.Node.Index); Assert.IsNotEmpty(result); }
private void ConeBaseCircle(bool updateShape) { if (Dependency.Steps[1].Data is Mouse3DPosition) { // If point received from mouse Dependency.Steps[0].Get <gpAx1>().Direction = Dependency.Steps[1].Get <Mouse3DPosition>().Axis.Direction; var currentPoint = Dependency.Steps[1].Get <Mouse3DPosition>().Point.GpPnt; Dependency.Steps[1].Data = Dependency.Steps[0].Get <gpAx1>().Location.Distance(currentPoint); } else if (Dependency.Steps[1].Data is Point3D) { var currentPoint = Dependency.Steps[1].Get <Point3D>().GpPnt; Dependency.Steps[1].Data = Dependency.Steps[0].Get <gpAx1>().Location.Distance(currentPoint); } var sketchCreator = new SketchCreator(Dependency.AnimationDocument); var center = sketchCreator.GetPoint(new Point3D((Dependency.Steps[0].Data as gpAx1).Location)).Node; sketchCreator = new SketchCreator(Dependency.AnimationDocument); var builder = new NodeBuilder(Dependency.AnimationDocument, FunctionNames.Circle); builder[0].Reference = center; builder[1].Real = Dependency.Steps[1].Get <double>(); builder.EnableSelection = false; builder.Color = Color.Red; builder.DisplayMode = AISDisplayMode.AIS_WireFrame; builder.Transparency = 0.2; builder.ExecuteFunction(); Dependency.AnimationNodeBuilder = builder; }
public void CutDeleteBaseTest2() { var document = TestUtils.DefaultsSetup(); var sketchCreator = new SketchCreator(document, false); var sketchNode = sketchCreator.BuildSketchNode(); document.Transact(); var circleBuilder = TestUtils.Circle(document, sketchNode, new Point3D(0, 0, 0), 10); TestUtils.Circle(document, sketchNode, new Point3D(20, 20, 0), 10); Assert.AreEqual(circleBuilder.LastExecute, true); sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = AutoGroupLogic.RebuildSketchFace(sketchNode, document); var extrudeBuilder = new NodeBuilder(document, FunctionNames.Extrude); extrudeBuilder[0].Reference = sketchNode; extrudeBuilder[1].Integer = 0; extrudeBuilder[2].Real = 10; extrudeBuilder.ExecuteFunction(); Assert.AreEqual(extrudeBuilder.LastExecute, true); document.Commit("Extrude created"); document.Transact(); var volume = GeomUtils.GetSolidVolume(extrudeBuilder.Shape); Assert.AreEqual(volume, 2 * Math.PI * 1000); Assert.AreEqual(document.Root.Children.Count, 6); var sketchNode2 = sketchCreator.BuildSketchNode(); document.Commit("Second sketch created"); document.Transact(); TestUtils.Circle(document, sketchNode2, new Point3D(0, 0, 0), 5); sketchNode2.Children[2].Set <MeshTopoShapeInterpreter>().Shape = AutoGroupLogic.RebuildSketchFace(sketchNode2, document); var cutBuilder = new NodeBuilder(document, FunctionNames.Cut); cutBuilder[0].Reference = sketchNode2; cutBuilder[2].Integer = (int)ExtrusionTypes.MidPlane; cutBuilder[1].Real = 10000; cutBuilder.ExecuteFunction(); Assert.AreEqual(cutBuilder.LastExecute, true); volume = GeomUtils.GetSolidVolume(cutBuilder.Shape); Assert.AreEqual(volume, 2 * Math.PI * 1000 - Math.PI * 250); Assert.AreEqual(document.Root.Children.Count, 10); var nodeToDelete = document.Root[2]; NodeBuilderUtils.DeleteNode(nodeToDelete, document); document.Commit("Deleted"); document.Transact(); NodeUtils.RebuildAllSketchFaces(document); extrudeBuilder.ExecuteFunction(); cutBuilder.ExecuteFunction(); document.Commit("Finished"); Assert.IsTrue(cutBuilder.LastExecute); volume = GeomUtils.GetSolidVolume(cutBuilder.Shape); Assert.AreEqual(8, document.Root.Children.Count, "Circle is not deleted"); Assert.AreEqual(volume, Math.PI * 1000); }
public void DeleteLineTest() { var document = TestUtils.DefaultsSetup(); document.Transact(); var sketchCreator = new SketchCreator(document, false); var sketchNode = sketchCreator.BuildSketchNode(); var pointBuilder = new NodeBuilder(document, FunctionNames.Point); pointBuilder[0].Reference = sketchNode; pointBuilder[1].TransformedPoint3D = new Point3D(); var pointBuilder2 = new NodeBuilder(document, FunctionNames.Point); pointBuilder2[0].Reference = sketchNode; pointBuilder2[1].TransformedPoint3D = new Point3D(1, 1, 0); pointBuilder.ExecuteFunction(); var lineBuilder = new NodeBuilder(document, FunctionNames.LineTwoPoints); lineBuilder[0].Reference = pointBuilder.Node; lineBuilder[1].Reference = pointBuilder2.Node; lineBuilder.ExecuteFunction(); var nodeToDelete = document.Root[3]; NodeBuilderUtils.DeleteNode(nodeToDelete, document); document.Commit("Deleted"); Assert.AreEqual(1, document.Root.Children.Count, "Line is not deleted"); Assert.AreEqual(FunctionNames.Sketch, document.Root[0].Get <ShapeFunctionsInterface.Functions.FunctionInterpreter>().Name); }
public void Rotation30AroundOx() { var rotationAxis = gp.OX; var document = TestUtils.DefaultsSetup(); document.Transact(); var sketchCreator = new SketchCreator(document, false); var sketchNode = sketchCreator.BuildSketchNode(); var interpreter = sketchNode.Set <TransformationInterpreter>(); // Disable parent notification interpreter.Disable(); interpreter.RotateAroundAxis(rotationAxis, 30); var nb = new NodeBuilder(sketchNode); nb.ExecuteFunction(); Assert.IsTrue(Math.Abs(1 - interpreter.CurrTransform.Value(1, 1)) < 0.1, "incorrect rotation"); Assert.IsTrue(Math.Abs(interpreter.CurrTransform.Value(1, 2)) < 0.1, "incorrect rotation"); Assert.IsTrue(Math.Abs(interpreter.CurrTransform.Value(1, 3)) < 0.1, "incorrect rotation"); Assert.IsTrue(Math.Abs(interpreter.CurrTransform.Value(2, 1)) < 0.1, "incorrect rotation"); Assert.IsTrue(Math.Abs(0.86 - interpreter.CurrTransform.Value(2, 2)) < 0.1, "incorrect rotation"); Assert.IsTrue(Math.Abs(-0.5 - interpreter.CurrTransform.Value(2, 3)) < 0.1, "incorrect rotation"); Assert.IsTrue(Math.Abs(interpreter.CurrTransform.Value(3, 1)) < 0.1, "incorrect rotation"); Assert.IsTrue(Math.Abs(0.5 - interpreter.CurrTransform.Value(3, 2)) < 0.1, "incorrect rotation"); Assert.IsTrue(Math.Abs(0.86 - interpreter.CurrTransform.Value(3, 3)) < 0.1, "incorrect rotation"); Assert.IsTrue(Math.Abs(interpreter.CurrTransform.Value(1, 4)) < 0.1, "incorrect translation"); Assert.IsTrue(Math.Abs(interpreter.CurrTransform.Value(2, 4)) < 0.1, "incorrect translation"); Assert.IsTrue(Math.Abs(interpreter.CurrTransform.Value(3, 4)) < 0.1, "incorrect translation"); }
public void AppliedConstraintsMappingTest() { var document = TestUtils.DefaultsSetup(); var sketch = new SketchCreator(document); var sketchNode = sketch.BuildSketchNode(); document.Transact(); var pointLinker = sketch.PointLinker; var line = ConstraintUtils.BuildLine(document, pointLinker, new Point3D(1, 1, 0), new Point3D(3, 1.5, 0)); var line2 = ConstraintUtils.BuildLine(document, pointLinker, new Point3D(1, 3, 0), new Point3D(3, 2.5, 0)); const string constraintFunctionName = Constraint2DNames.ParallelFunction; var constraintBuilder = new NodeBuilder(document, constraintFunctionName); constraintBuilder[0].Reference = line.Node; constraintBuilder[1].Reference = line2.Node; document.Commit("Draw"); var constraintMapper = new ConstraintDocumentHelper(document, sketchNode); var selection = new List <Node> { line.Node, line2.Node }; var condition = constraintMapper.IsApplied(selection, constraintFunctionName); Assert.IsTrue(condition); }
public void BackAfterSetPivot() { var aPoint = new Point3D(10, 10, 0); var document = TestUtils.DefaultsSetup(); var sketchCreator = new SketchCreator(document, false); var sketchNode = sketchCreator.BuildSketchNode(); document.Transact(); var builder = new NodeBuilder(document, FunctionNames.Point); builder[0].Reference = sketchNode; builder[1].TransformedPoint3D = aPoint; Assert.IsTrue(builder.ExecuteFunction()); document.Commit("Point drawn"); document.Transact(); var interpreter = builder.Node.Get <TransformationInterpreter>(); interpreter.Pivot = new gpPnt(15, 10, 0); document.Commit("Set pivot done"); document.Undo(); Assert.IsTrue(Math.Abs(10 - interpreter.Pivot.X) < 0.1, "incorrect pivot"); Assert.IsTrue(Math.Abs(10 - interpreter.Pivot.Y) < 0.1, "incorrect pivot"); Assert.IsTrue(Math.Abs(interpreter.Pivot.Z) < 0.1, "incorrect pivot"); }
public void CheckTranslateValueTest() { var colomnAxis = new gpAx1(new gpPnt(0, 0, 0), new gpDir(0, 1, 0)); var rowAxis = new gpAx1(new gpPnt(0, 0, 0), new gpDir(1, 0, 0)); var document = TestUtils.DefaultsSetup(); document.Transact(); var sketchCreator = new SketchCreator(document, false); var sketchNode = sketchCreator.BuildSketchNode(); var pointBuilder = TestUtils.Point(document, sketchNode, new Point3D(10, 10, 0)); Assert.IsTrue(pointBuilder.ExecuteFunction()); var interpreter = pointBuilder.Node.Get <TransformationInterpreter>(); interpreter.ApplyGeneralArrayPattern(rowAxis, colomnAxis, 5, 5); document.Commit("Array Pattern done"); Assert.IsTrue(Math.Abs(15 - interpreter.CurrTransform.Value(1, 4)) < 0.1, "incorrect array pattern base point"); Assert.IsTrue(Math.Abs(15 - interpreter.CurrTransform.Value(2, 4)) < 0.1, "incorrect array pattern base point"); Assert.IsTrue(Math.Abs(0 - interpreter.CurrTransform.Value(3, 4)) < 0.1, "incorrect array pattern base point"); }
private void BuildAndEnterSketch(Document document) { var sketchCreator = new SketchCreator(document); var currentSketch = sketchCreator.CurrentSketch; var sketchNodeBuilder = new NodeBuilder(currentSketch); Document.Transact(); Log.InfoFormat("StartSketch - Command line input"); var firstvector = new gpDir(Points[1].GpPnt.X - Points[0].GpPnt.X, Points[1].GpPnt.Y - Points[0].GpPnt.Y, Points[1].GpPnt.Z - Points[0].GpPnt.Z); var secondvector = new gpDir(Points[2].GpPnt.X - Points[0].GpPnt.X, Points[2].GpPnt.Y - Points[0].GpPnt.Y, Points[2].GpPnt.Z - Points[0].GpPnt.Z); var normal = firstvector.Crossed(secondvector); var _normalOnPlane = new gpAx1(Points[0].GpPnt, normal); var sketchAx2 = new gpAx2(); sketchAx2.Axis = (_normalOnPlane); var plane = new gpPln(new gpAx3(sketchAx2)); Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.SetPlane, plane); sketchNodeBuilder[0].Axis3D = new Axis(sketchNodeBuilder[0].Axis3D.Location, new Point3D(new gpPnt(_normalOnPlane.Direction.XYZ))); HighlightCurrentSketchNodes(sketchNodeBuilder.Node); NodeBuilderUtils.HidePlanes(Document); Document.Commit("sketch created"); AddNodeToTree(sketchNodeBuilder.Node); Document.Transact(); Document.Root.Get <DocumentContextInterpreter>().ActiveSketch = sketchNodeBuilder.Node.Index; _sketchButton.Block(); Document.Commit("Started editing sketch"); }
public override void OnActivate() { base.OnActivate(); var sketchBuilder = new SketchCreator(Document, false); sketchNode = sketchBuilder.CurrentSketch; if (sketchNode == null) { ActionsGraph.SwitchAction(ModifierNames.StartSketch, ModifierNames.DrawCircle); return; } Inputs[InputNames.SelectionContainerPipe].Send(NotificationNames.Disable); normalOnPlane = sketchBuilder.NormalOnSketch.Value.GpAxis; var trsf = sketchBuilder.CurrentSketch.Get <TransformationInterpreter>().CurrTransform; normalOnPlane = normalOnPlane.Transformed(trsf); sketchNode = sketchBuilder.CurrentSketch; Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.Suspend); var pointBuilder = GetSketchNode(Document, new Point3D(), sketchNode); pointBuilder.Visibility = ObjectVisibility.Hidden; builder = new NodeBuilder(Document, FunctionNames.Circle); builder[0].Reference = pointBuilder.Node; builder[1].Real = 0.0; builder.Visibility = ObjectVisibility.Hidden; builder.ExecuteFunction(); AddNodeToTree(builder.Node); ActionsGraph[InputNames.CoordinateParser].Send(CoordinatateParserNames.SetStage, ParserStage.Unknown); Reset(); }
public void CircularPatternTestWithoutPivotSet() { var aPoint = new Point3D(10, 10, 0); var axisPoint = new Point3D(10, 0, 0); var rotationAxis = new gpAx1(axisPoint.GpPnt, new gpDir(0, 0, 1)); var document = TestUtils.DefaultsSetup(); document.Transact(); var sketchCreator = new SketchCreator(document, false); var sketchNode = sketchCreator.BuildSketchNode(); var pointBuilder = new NodeBuilder(document, FunctionNames.Point); pointBuilder[0].Reference = sketchNode; pointBuilder[1].TransformedPoint3D = aPoint; Assert.IsTrue(pointBuilder.ExecuteFunction()); var interpreter = pointBuilder.Node.Get <TransformationInterpreter>(); interpreter.ApplyGeneralCircularPattern(rotationAxis, 180, 10); document.Commit("rotations done"); Assert.IsTrue(Math.Abs(10 - interpreter.CurrTransform.Value(1, 4)) < 0.1, "incorrect rotation base point"); Assert.IsTrue(Math.Abs(-10 - interpreter.CurrTransform.Value(2, 4)) < 0.1, "incorrect rotation base point"); Assert.IsTrue(Math.Abs(10 - interpreter.CurrTransform.Value(3, 4)) < 0.1, "incorrect rotation base point"); Assert.IsTrue(Math.Abs(10 - interpreter.Pivot.X) < 0.1, "incorrect rotation pivot"); Assert.IsTrue(Math.Abs(-10 - interpreter.Pivot.Y) < 0.1, "incorrect rotation pivot"); Assert.IsTrue(Math.Abs(10 - interpreter.Pivot.Z) < 0.1, "incorrect rotation pivot"); }
protected override void OnMouseDownAction(Mouse3DPosition mouseData) { var shapeIndex = GetSplineIndex(mouseData); var sketch = Document.Root.Get <DocumentContextInterpreter>().ActiveSketch; var sketchBuilder = new SketchCreator(Document); var nodeBuilder = new NodeBuilder(sketchBuilder.CurrentSketch); nodeBuilder[0].TransformedAxis3D = sketchBuilder.NormalOnSketch.Value.GpAxis; if (shapeIndex == -1) { return; } var root = Document.Root; var builder = new NodeBuilder(root[shapeIndex]); var pointCount = builder[0].Integer; var subIndex = -1; for (var i = 1; i < pointCount - 1; ++i) { var pointInSpline = builder[i].TransformedPoint3D; if (ArePointsOutOfZoomRange(pointInSpline, mouseData.Point)) { subIndex = i - 1; } } Ensure.IsNotTrue(subIndex == -1); InitSession(); SplitSplineLogic(builder, subIndex); CommitFinal("Split Spline"); UpdateView(); ActionsGraph.SwitchAction(ModifierNames.SplitSpline); }
public void CheckAppliedConstraintTest() { var document = TestUtils.DefaultsSetup(); var sketch = new SketchCreator(document); var sketchNode = sketch.BuildSketchNode(); document.Transact(); var pointLinker = sketch.PointLinker; var line = ConstraintUtils.BuildLine(document, pointLinker, new Point3D(1, 1, 0), new Point3D(3, 1.5, 0)); var line2 = ConstraintUtils.BuildLine(document, pointLinker, new Point3D(1, 3, 0), new Point3D(3, 2.5, 0)); var constraintBuilder = new NodeBuilder(document, Constraint2DNames.ParallelFunction); constraintBuilder[0].Reference = line.Node; constraintBuilder[1].Reference = line2.Node; document.Commit("Draw"); var constraintMapper = new ConstraintDocumentHelper(document, sketchNode); var result = constraintMapper.CheckAppliedConstraints(new List <Node> { line.Node, line2.Node }); var appliedFunctions = GetAppliedFunctions(result); Assert.IsTrue(appliedFunctions.Contains(Constraint2DNames.ParallelFunction)); }
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 override void OnActivate() { base.OnActivate(); //var sketchCreator = new SketchCreator(Document, false); //if (sketchCreator.CurrentSketch == null) //{ // BackToNeutralModifier(); // return; //} var sketchBuilder = new SketchCreator(Document, false); var sketchNode = sketchBuilder.CurrentSketch; if (sketchNode == null) { ActionsGraph.SwitchAction(ModifierNames.StartSketch, ModifierNames.Point3D); return; } var axis = sketchBuilder.NormalOnSketch.Value; var trsf = sketchBuilder.CurrentSketch.Get <TransformationInterpreter>().CurrTransform; axis.Location = new Point3D(axis.Location.GpPnt.Transformed(trsf)); // Block drawing plane Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.Resume); //Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.SetPlane, // new gpPln(axis.GpAxis.Location, // axis.GpAxis.Direction)); Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.Suspend); ActionsGraph[InputNames.CoordinateParser].Send(CoordinatateParserNames.SetStage, ParserStage.Unknown); Reset(); }
public void RotationAroundAxisWithoutPivotSet() { var aPoint = new Point3D(10, 10, 0); var axisPoint = new Point3D(10, 0, 0); var rotationAxis = new gpAx1(axisPoint.GpPnt, new gpDir(0, 0, 1)); var document = TestUtils.DefaultsSetup(); document.Transact(); var sketchCreator = new SketchCreator(document, false); var sketchNode = sketchCreator.BuildSketchNode(); var builder = new NodeBuilder(document, FunctionNames.Point); builder[0].Reference = sketchNode; builder[1].TransformedPoint3D = aPoint; Assert.IsTrue(builder.ExecuteFunction()); var interpreter = builder.Node.Set <TransformationInterpreter>(); // Disable parent notification interpreter.Disable(); interpreter.RotateAroundAxis(rotationAxis, 90); builder.ExecuteFunction(); document.Commit("rotations done"); Assert.IsTrue(Math.Abs(0 - interpreter.CurrTransform.Value(1, 4)) < 0.1, "incorrect rotation"); }
public void DeleteCircleTest() { var document = TestUtils.DefaultsSetup(); document.Transact(); var sketchCreator = new SketchCreator(document, false); var sketchNode = sketchCreator.BuildSketchNode(); var pointBuilder = new NodeBuilder(document, FunctionNames.Point); pointBuilder[0].Reference = sketchNode; pointBuilder[1].TransformedPoint3D = new Point3D(); pointBuilder.ExecuteFunction(); var circleBuilder = new NodeBuilder(document, FunctionNames.Circle); circleBuilder[0].Reference = pointBuilder.Node; circleBuilder[1].Real = 20; circleBuilder.ExecuteFunction(); //document.Commit("Draw first circle"); var nodeToDelete = document.Root[2]; NodeBuilderUtils.DeleteNode(nodeToDelete, document); document.Commit("Deleted"); Assert.AreEqual(1, document.Root.Children.Count, "Circle is not deleted"); Assert.AreEqual(FunctionNames.Sketch, document.Root[0].Get <ShapeFunctionsInterface.Functions.FunctionInterpreter>().Name); }
public override void OnActivate() { ActionsGraph[InputNames.CoordinateParser].Send(CoordinatateParserNames.SetStage, ParserStage.Unknown); //if (Document.Root.Children.Count == 0) //{ // sketchNode = CreateDefaultSketchNode(Document); //} //else //{ // var currentSketchNode = Document.Root[Document.Root.Get<DocumentContextInterpreter>().ActiveSketch]; // sketchNode = currentSketchNode; //} var sketchBuilder = new SketchCreator(Document, false); sketchNode = sketchBuilder.CurrentSketch; if (sketchNode == null) { ActionsGraph.SwitchAction(ModifierNames.StartSketch, ModifierNames.Line3D); return; } Document.Transact(); SetupHinter(sketchNode); normalOnPlane = sketchNode.Children[1].Get <Axis3DInterpreter>().GpAxis; var pointBuilder = GetSketchNode(Document, new Point3D(), sketchNode); pointBuilder.Visibility = ObjectVisibility.Hidden; var builder = new NodeBuilder(Document, FunctionNames.LineTwoPoints); builder[0].Reference = pointBuilder.Node; builder[1].Reference = pointBuilder.Node; builder.ExecuteFunction(); AddNodeToTree(builder.Node); Reset(); Hinter2D.Populate(); }
public void SetArcInternalAngleBothPositiveTest() { var sketchCreator = new SketchCreator(_document, false); var sketchNode = sketchCreator.BuildSketchNode(); _document.Transact(); // s >0, e > 0, s > e var arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(0.535898, 2, 0), new Point3D(7.464101, 2, 0)); Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 240) < 0.00001, "Incorrect internal angle"); var endPoint = NodeBuilderUtils.SetInternalAngle(arcBuilder, 300); Assert.IsTrue(Math.Abs(endPoint.X - 4) < 0.00001); Assert.IsTrue(Math.Abs(endPoint.Y - 4) < 0.00001); arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(0.535898, 2, 0), new Point3D(7.464101, 2, 0)); Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 240) < 0.00001, "Incorrect internal angle"); endPoint = NodeBuilderUtils.SetInternalAngle(arcBuilder, 180); Assert.IsTrue(Math.Abs(endPoint.X - 7.464101) < 0.00001); Assert.IsTrue(Math.Abs(endPoint.Y + 2) < 0.00001); arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(4, 4, 0), new Point3D(7.464101, 2, 0)); Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 300) < 0.00001, "Incorrect internal angle"); endPoint = NodeBuilderUtils.SetInternalAngle(arcBuilder, 60); Assert.IsTrue(Math.Abs(endPoint.X - 0.535898) < 0.00001); Assert.IsTrue(Math.Abs(endPoint.Y - 2) < 0.00001); // s >0, e > 0, s < e arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(7.464101, 2, 0), new Point3D(0.535898, 2, 0)); Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 120) < 0.00001, "Incorrect internal angle"); endPoint = NodeBuilderUtils.SetInternalAngle(arcBuilder, 60); Assert.IsTrue(Math.Abs(endPoint.X - 4) < 0.00001); Assert.IsTrue(Math.Abs(endPoint.Y - 4) < 0.00001); arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(7.464101, 2, 0), new Point3D(0.535898, 2, 0)); Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 120) < 0.00001, "Incorrect internal angle"); endPoint = NodeBuilderUtils.SetInternalAngle(arcBuilder, 180); Assert.IsTrue(Math.Abs(endPoint.X - 0.535898) < 0.00001); Assert.IsTrue(Math.Abs(endPoint.Y + 2) < 0.00001); arcBuilder = TestUtils.Arc(_document, sketchNode, new Point3D(4, 0, 0), new Point3D(4, 4, 0), new Point3D(0.535898, 2, 0)); Assert.IsTrue(Math.Abs(NodeBuilderUtils.GetInternalAngle(arcBuilder) - 60) < 0.00001, "Incorrect internal angle"); endPoint = NodeBuilderUtils.SetInternalAngle(arcBuilder, 300); Assert.IsTrue(Math.Abs(endPoint.X - 7.464101) < 0.00001); Assert.IsTrue(Math.Abs(endPoint.Y - 2) < 0.00001); }