public void CreateTwoFlangesOnTheSameFace()
        {
            // The problem of this test case ist:
            // We've selected the right face beside the flangeSheet2. The face reference was translated
            // to the parent face, which was splitted. We get the first of the split face always,
            // which is the left face. The flange is on the false side.

            var ctx          = Context.Current;
            var box          = Box.Create(20.0, 20.0, 1.0);
            var body         = TestGeomGenerator.CreateBody(box);
            var flangeSheet1 = FlangeSheet.Create(body, new SubshapeReference(SubshapeType.Face, box.Guid, 3), 20.0, 5.0, 1.0);

            flangeSheet1.Reverse = true;
            var flangeSheet2 = FlangeSheet.Create(body, new SubshapeReference(SubshapeType.Face, flangeSheet1.Guid, "Flange", 5), 70.0, 10.0, 1.0);

            flangeSheet2.StartGap = 8.0;
            flangeSheet2.EndGap   = 8.0;
            ctx.UndoHandler.Commit();

            ctx.ViewportController.ZoomFitAll();

            ctx.WorkspaceController.Selection.SelectEntity(body);
            ctx.WorkspaceController.StartTool(new CreateFlangeSheetTool(body));

            ctx.ViewportController.MouseMove(new Point(370, 225));
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "CreateTwoFlangesOnTheSameFace1"));

            ctx.ViewportController.MouseDown();
            ctx.ViewportController.MouseUp(false);
            ctx.ViewportController.ZoomFitAll();
            ctx.ViewportController.MouseMove(new Point(0, 0));
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "CreateTwoFlangesOnTheSameFace2"));
        }
        public void FlangeSheetReselectTargetFace()
        {
            var ctx  = Context.Current;
            var box  = Box.Create(10.0, 10.0, 1.0);
            var body = TestGeomGenerator.CreateBody(box);

            ctx.ViewportController.ZoomFitAll();

            // Build imprint
            ctx.WorkspaceController.Selection.SelectEntity(body);
            ctx.WorkspaceController.StartTool(new CreateFlangeSheetTool(body));
            ctx.SelectAt(300, 350);
            ctx.MoveTo(250, 250);
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "ReselectTargetFace1"));

            // Start reselection, then cancel it
            ctx.WorkspaceController.StartTool(new CreateFlangeSheetTool(body.Shape as FlangeSheet));
            ctx.MoveTo(140, 320);
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "ReselectTargetFace2"));
            ctx.WorkspaceController.CancelTool(ctx.WorkspaceController.CurrentTool, true);
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "ReselectTargetFace1"));

            // Start reselection, perform
            ctx.WorkspaceController.StartTool(new CreateFlangeSheetTool(body.Shape as FlangeSheet));
            ctx.SelectAt(140, 320);
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "ReselectTargetFace3"));
            Assert.IsNull(ctx.WorkspaceController.CurrentTool);
        }
        public void RecenterGrid()
        {
            var ctx = Context.Current;

            var sketch = TestGeomGenerator.CreateSketch(TestGeomGenerator.SketchType.MultiCircle);
            var body   = TestGeomGenerator.CreateBody(sketch);

            ctx.ViewportController.ZoomFitAll();

            Assert.Multiple(() =>
            {
                var sketchEditor = new SketchEditorTool(sketch);
                ctx.WorkspaceController.StartTool(sketchEditor);

                Assert.IsTrue(SketchCommands.RecenterGrid.CanExecute());
                SketchCommands.RecenterGrid.Execute();
                Assert.IsInstanceOf <RecenterGridSketchTool>(sketchEditor.CurrentTool);

                ctx.MoveTo(200, 200);
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "RecenterGrid01"));

                ctx.ClickAt(200, 200);
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "RecenterGrid02"));

                // Elements selectable again
                ctx.ClickAt(288, 143);
                Assert.AreEqual(1, sketchEditor.SelectedSegments.Count);
            });
        }
        public void MoveInTopView()
        {
            var ctx = Context.Current;

            var body = TestGeomGenerator.CreateBody(Box.Create(10, 5, 2));

            ctx.ViewportController.SetPredefinedView(ViewportController.PredefinedViews.WorkingPlane);
            ctx.ViewportController.ZoomFitAll();

            var tool = new TransformBodyTool(new[] { body }, TransformBodyTool.PivotPoint.BodyPivot, TransformBodyTool.Options.None);

            ctx.WorkspaceController.StartTool(tool);

            // X-Axis
            ctx.ViewportController.MouseMove(new Point(90, 363));
            ctx.ViewportController.MouseDown();
            ctx.ViewportController.MouseMove(new Point(100, 363));
            ctx.ViewportController.MouseUp(false);
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "MoveInTopView01"));

            // Y-Axis
            ctx.ViewportController.MouseMove(new Point(31, 300));
            ctx.ViewportController.MouseDown();
            ctx.ViewportController.MouseMove(new Point(31, 280));
            ctx.ViewportController.MouseUp(false);
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "MoveInTopView02"));

            // Z-Axis
            ctx.ViewportController.MouseMove(new Point(33, 343));
            ctx.ViewportController.MouseDown();
            ctx.ViewportController.MouseMove(new Point(50, 320));
            ctx.ViewportController.MouseUp(false);
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "MoveInTopView03"));
        }
        public void BooleanCutModifications()
        {
            // Make Box
            var box = new Box()
            {
                DimensionX = 10,
                DimensionY = 10,
                DimensionZ = 10,
            };
            var tsBox    = box.GetTransformedBRep();
            var edgesBox = tsBox.Edges();
            var facesBox = tsBox.Faces();

            Assert.AreEqual(12, edgesBox.Count);

            // Make Cylinder
            var cyl = new Cylinder()
            {
                Height = 10,
                Radius = 2,
            };
            var cylBody = TestGeomGenerator.CreateBody(cyl, new Pnt(5, 5, 0));

            var tsCyl    = cyl.GetTransformedBRep();
            var edgesCyl = tsCyl.Edges();
            var facesCyl = tsCyl.Faces();

            Assert.AreEqual(3, edgesCyl.Count);

            // Boolean Op
            var cut       = new BRepAlgoAPI_Cut(tsBox, tsCyl);
            var tsBool    = cut.Shape();
            var edgesBool = tsBool.Edges();
            var facesBool = tsBool.Faces();

            Assert.AreEqual(15, edgesBool.Count);
            Assert.False(cut.HasGenerated());
            Assert.True(cut.HasDeleted());
            Assert.True(cut.HasModified());

            // All edges of box and cyl are in boolop
            Assert.AreEqual(12, edgesBox.Count(e => edgesBool.Any(edgeBool => edgeBool.IsSame(e))));
            Assert.AreEqual(3, edgesCyl.Count(e => edgesBool.Any(edgeBool => edgeBool.IsSame(e))));

            // Deleted no edges
            Assert.AreEqual(0, edgesBox.Count(e => cut.IsDeleted(e)));
            Assert.AreEqual(0, edgesCyl.Count(e => cut.IsDeleted(e)));

            // 4 faces from box and none from cylinder are in boolop
            Assert.AreEqual(4, facesBox.Count(f => facesBool.Any(faceBool => faceBool.IsSame(f))));
            Assert.AreEqual(1, facesCyl.Count(f => facesBool.Any(faceBool => faceBool.IsSame(f))));

            // Deleted no faces from box, 2 faces from cylinder
            Assert.AreEqual(0, facesBox.Count(f => cut.IsDeleted(f)));
            Assert.AreEqual(2, facesCyl.Count(f => cut.IsDeleted(f)));

            // Modified 2 faces from box, 0 face from cylinder
            Assert.AreEqual(2, facesBox.Count(f => cut.Modified(f).Size() > 0));
            Assert.AreEqual(0, facesCyl.Count(f => cut.Modified(f).Size() > 0));
        }
        public void MovePointSnap()
        {
            var ctx = Context.Current;

            var sketch = TestGeomGenerator.CreateSketch(TestGeomGenerator.SketchType.MultiCircle);
            var body   = TestGeomGenerator.CreateBody(sketch);

            ctx.ViewportController.ZoomFitAll();

            var tool = new SketchEditorTool(sketch);

            ctx.WorkspaceController.StartTool(tool);
            ctx.EditorState.SnappingEnabled    = true;
            ctx.EditorState.SnapToGridSelected = true;

            Assert.Multiple(() =>
            {
                // Select Point
                ctx.ClickAt(377, 122);
                // Move on progress
                ctx.MoveTo(390, 108);
                ctx.ViewportController.MouseDown();
                ctx.ViewportController.MouseMove(new Point(257, 83));
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "MovePointSnap01"));
                // Move released
                ctx.ViewportController.MouseUp(false);
                ctx.ClickAt(1, 1);
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "MovePointSnap02"));

                // Cleanup
                tool.Stop();
            });
        }
        public void BoxJointReference()
        {
            void __BuildAndRemove()
            {
                var model = CoreContext.Current.Document;
                var body1 = TestGeomGenerator.CreateBody(Box.Create(10, 2, 10), new Pnt(-5, -5, -5));

                model.AddChild(body1);
                var body2 = TestGeomGenerator.CreateBody(Box.Create(2, 10, 10), new Pnt(-5, -5, -5));

                model.AddChild(body2);

                var(first, second) = BoxJoint.Create(body1, body2);
                Assert.IsTrue(first.Make(Shape.MakeFlags.None));
                Assert.IsTrue(second.Make(Shape.MakeFlags.None));

                model.SafeDelete(new[] { body1, body2 });
            }

            __BuildAndRemove();

            dotMemory.Check(memory =>
            {
                Assert.AreEqual(0, memory.ObjectsCount <Body>(), "a Body is alive");
                Assert.AreEqual(0, memory.ObjectsCount <BoxJoint>(), "a BoxJoint is alive");
            });
        }
        Core.Shapes.Sketch CreateSketch(SketchType sketchType)
        {
            var sketch = new Core.Shapes.Sketch();

            Assert.IsNotNull(sketch);

            var body = TestGeomGenerator.CreateBody(sketch);

            body.Rotation = new Quaternion(Dir.DZ.ToVec(), new Vec(0.4, 0.5, 0.1));

            sketch.Points.Add(0, new Pnt2d(0, 30));
            sketch.Points.Add(1, new Pnt2d(20, 30));
            sketch.Segments.Add(0, new SketchSegmentLine(0, 1));

            sketch.Points.Add(2, new Pnt2d(30, 0));
            sketch.Points.Add(3, new Pnt2d(30, 20));
            sketch.Segments.Add(1, new SketchSegmentArc(1, 2, 3));

            sketch.Points.Add(4, new Pnt2d(10, 0));
            sketch.Points.Add(5, new Pnt2d(0, -20));
            sketch.Segments.Add(2, new SketchSegmentBezier(2, 4, 5));

            sketch.Segments.Add(3, new SketchSegmentLine(5, 0));

            if (sketchType == SketchType.MultiCurve)
            {
                sketch.Points.Add(6, new Pnt2d(5, 10));
                sketch.Points.Add(7, new Pnt2d(10, 0));
                sketch.Points.Add(8, new Pnt2d(5, -10));
                sketch.Segments.Add(4, new SketchSegmentLine(6, 7));
                sketch.Segments.Add(5, new SketchSegmentLine(7, 8));
                sketch.Segments.Add(6, new SketchSegmentLine(8, 6));
            }
            return(sketch);
        }
Beispiel #9
0
        public void CreateSingleSelected()
        {
            var ctx = Context.Current;

            var body1 = TestGeomGenerator.CreateBody(Box.Create(-10, -2, 10));
            var body2 = TestGeomGenerator.CreateBody(Box.Create(-2, -10, 10));

            ctx.ViewportController.ZoomFitAll();

            ctx.WorkspaceController.Selection.SelectEntity(body1);
            ctx.WorkspaceController.StartTool(new CreateBoxJointTool(body1));
            Assert.That(ctx.WorkspaceController.CurrentTool is CreateBoxJointTool);

            Assert.Multiple(() =>
            {
                ctx.MoveTo(150, 300);
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "CreateSingleSelected01"));

                ctx.ClickAt(150, 300);
                Assert.IsNull(ctx.WorkspaceController.CurrentTool);
                Assert.That(body1.Shape is BoxJoint);
                Assert.That(body2.Shape is BoxJoint);

                ctx.MoveTo(0, 0);
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "CreateSingleSelected02"));
            });
        }
        public void DeleteElements()
        {
            var ctx = Context.Current;

            var sketch = TestGeomGenerator.CreateSketch(TestGeomGenerator.SketchType.Rectangle);
            var body   = TestGeomGenerator.CreateBody(sketch);

            ctx.ViewportController.ZoomFitAll();

            Assert.Multiple(() =>
            {
                var tool = new SketchEditorTool(sketch);
                ctx.WorkspaceController.StartTool(tool);
                Assert.IsFalse(ctx.WorkspaceController.CanDelete());

                // Delete Point
                ctx.SelectAt(411, 88);
                Assert.IsTrue(ctx.WorkspaceController.CanDelete());
                ctx.WorkspaceController.Delete();
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "DeleteElements01"));

                // Delete Segment
                ctx.SelectAt(90, 230);
                Assert.IsTrue(ctx.WorkspaceController.CanDelete());
                ctx.WorkspaceController.Delete();
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "DeleteElements02"));

                // Undo twice
                ctx.UndoHandler.DoUndo(2);
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "DeleteElements03"));
            });
        }
        public void RecenterGridSegmentTools()
        {
            // Check that segment creation tools also respect the recentered grid
            var ctx = Context.Current;

            var sketch = TestGeomGenerator.CreateSketch(TestGeomGenerator.SketchType.MultiCircle);
            var body   = TestGeomGenerator.CreateBody(sketch);

            ctx.ViewportController.ZoomFitAll();

            var sketchEditor = new SketchEditorTool(sketch);

            ctx.WorkspaceController.StartTool(sketchEditor);

            Assert.IsTrue(SketchCommands.RecenterGrid.CanExecute());
            SketchCommands.RecenterGrid.Execute();
            Assert.IsInstanceOf <RecenterGridSketchTool>(sketchEditor.CurrentTool);
            ctx.ClickAt(200, 200);

            Assert.Multiple(() =>
            {
                sketchEditor.StartSegmentCreation <SketchSegmentArcCenterCreator>();
                ctx.ClickAt(120, 120); // Center point
                ctx.MoveTo(120, 160);
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "RecenterGridSegmentTools01"));
                ctx.ClickAt(120, 160); // Edge point 1
                ctx.ClickAt(160, 120); // Edge point 2
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "RecenterGridSegmentTools03"));
            });
        }
        public void GetPlaneFromFace()
        {
            var shape = new Box
            {
                DimensionX = 20,
                DimensionY = 20,
                DimensionZ = 1,
            };
            var body = TestGeomGenerator.CreateBody(shape, new Pnt(-10, -20, 0));

            // Local space
            Assert.IsTrue(FaceAlgo.GetCenteredPlaneFromFace(shape, 5, true, out var plane));
            TestContext.WriteLine(plane.Location.X + " " + plane.Location.Y + " " + plane.Location.Z);
            Assert.IsTrue(plane.Location.IsEqual(new Pnt(10, 10, 1), Double.Epsilon));
            Assert.IsTrue(plane.Rotation().IsEqual(Quaternion.Identity));

            // Transformed
            Assert.IsTrue(FaceAlgo.GetCenteredPlaneFromFace(shape, 5, false, out plane));
            Assert.IsNotNull(plane);
            TestContext.WriteLine(plane.Location.X + " " + plane.Location.Y + " " + plane.Location.Z);
            Assert.AreEqual(new Pnt(0, -10, 1), plane.Location);
            Assert.AreEqual(Quaternion.Identity, plane.Rotation());
            Assert.IsTrue(plane.Location.IsEqual(new Pnt(0, -10, 1), Double.Epsilon));
            Assert.IsTrue(plane.Rotation().IsEqual(Quaternion.Identity));
        }
        public void RubberbandSelection()
        {
            var ctx = Context.Current;

            var sketch = TestGeomGenerator.CreateSketch(TestGeomGenerator.SketchType.MultiCircle);
            var body   = TestGeomGenerator.CreateBody(sketch);

            ctx.ViewportController.ZoomFitAll();

            var tool = new SketchEditorTool(sketch);

            ctx.WorkspaceController.StartTool(tool);

            ctx.MoveTo(170, 50);
            ctx.ViewportController.MouseDown();
            ctx.ViewportController.StartRubberbandSelection(ViewportController.RubberbandSelectionMode.Rectangle, false);
            ctx.MoveTo(450, 300);
            ctx.ViewportController.MouseUp(false);
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "RubberbandSelection01"));
            Assert.AreEqual(4, tool.SelectedPoints.Count);
            Assert.AreEqual(1, tool.SelectedSegments.Count);

            // Cleanup
            tool.Stop();
        }
Beispiel #14
0
        public void Clone()
        {
            var body1 = TestGeomGenerator.CreateBody(Box.Create(10, 2, 10), new Pnt(-5, -5, -5));
            var body2 = TestGeomGenerator.CreateBody(Box.Create(2, 10, 10), new Pnt(-5, -5, -5));

            var(first, second) = BoxJoint.Create(body1, body2);

            var serialized = Serializer.Serialize(body2, new SerializationContext());
            var context    = new SerializationContext(SerializationScope.CopyPaste);

            context.SetInstance(CoreContext.Current.Document);
            context.SetInstance <IDocument>(CoreContext.Current.Document);
            context.SetInstance(ReadOptions.RecreateGuids);
            context.SetInstance(new CloneOptions(cloneReferencedBodies: false));
            var third = (Serializer.Deserialize <Entity>(serialized, context) as Body)?.Shape as BoxJoint;

            Assume.That(third != null);
            third.Body.Position = new Pnt(0, -5, -5);

            Assert.AreEqual(body1, (third.Operands[1] as BodyShapeOperand)?.Body);
            Assert.AreEqual(third.Body, ((body1.Shape as ModifierBase)?.Operands[1] as BodyShapeOperand)?.Body);

            Assert.IsTrue(body1.Shape.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(body1.Shape, Path.Combine(_BasePath, "Clone1"));

            Assert.IsTrue(third.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(third, Path.Combine(_BasePath, "Clone3"));
        }
Beispiel #15
0
        public void CreateUnfoldManual()
        {
            var ctx = Context.Current;

            var box         = Box.Create(10.0, 10.0, 1.0);
            var body        = TestGeomGenerator.CreateBody(box);
            var flangeSheet = FlangeSheet.Create(body, new SubshapeReference(SubshapeType.Face, box.Guid, 1), 70.0, 10.0, 1.0);

            flangeSheet.Relief = FlangeSheet.ReliefFlags.Rectangular;
            ctx.UndoHandler.Commit();

            ctx.ViewportController.ZoomFitAll();

            ctx.WorkspaceController.Selection.SelectEntity(body);
            ctx.WorkspaceController.StartTool(new CreateUnfoldSheetTool(body, CreateUnfoldSheetTool.Flags.ForceManualSelect));
            Assert.That(ctx.WorkspaceController.CurrentTool, Is.Not.Null);

            // Check selection filter
            ctx.ViewportController.MouseMove(new Point(279, 413));
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "CreateUnfoldManual1"));

            // Select correct face
            ctx.ViewportController.MouseMove(new Point(100, 250));
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "CreateUnfoldManual2"));

            ctx.ViewportController.MouseDown();
            ctx.ViewportController.MouseUp(false);
            ctx.ViewportController.MouseMove(new Point(0, 0));
            ctx.ViewportController.ZoomFitAll();
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "CreateUnfoldManual3"));
        }
Beispiel #16
0
        public void SplitPeriodicSegment()
        {
            var ctx = Context.Current;

            var sketch = TestSketchGenerator.CreateSketch(TestSketchGenerator.SketchType.Circle);
            var body   = TestGeomGenerator.CreateBody(sketch);

            ctx.ViewportController.ZoomFitAll();

            var tool = new SketchEditorTool(sketch);

            ctx.WorkspaceController.StartTool(tool);

            Assert.Multiple(() =>
            {
                // Select Segment
                ctx.ClickAt(140, 90);

                // Start split tool
                var splitTool = new SplitElementSketchTool();
                tool.StartTool(splitTool);
                ctx.MoveTo(184, 103);
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "SplitPeriodicSegment01"), 1.0);
                ctx.ClickAt(184, 103);

                // Cleanup
                tool.StopTool();
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "SplitPeriodicSegment02"), 1.0);
            });

            tool.Stop();
        }
        public void MovePointMerge()
        {
            var ctx = Context.Current;

            var sketch = TestGeomGenerator.CreateSketch(TestGeomGenerator.SketchType.MultiCircle);
            var body   = TestGeomGenerator.CreateBody(sketch);

            ctx.ViewportController.ZoomFitAll();

            var tool = new SketchEditorTool(sketch);

            ctx.WorkspaceController.StartTool(tool);

            // Select Point
            ctx.ClickAt(377, 122);
            Assume.That(ctx.WorkspaceController.CurrentToolAction is MoveSketchPointAction);
            // Move to MergePoint
            ctx.MoveTo(392, 116);
            ctx.WorkspaceController.MouseDown(ctx.ViewportController);
            ctx.MoveTo(265, 245);
            // Hilighted MergePoint
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "MovePointMerge01"));

            // End
            ctx.WorkspaceController.CancelTool(tool, false);
            // Check Cleanup
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "MovePointMerge02"));
        }
        public void RecenterGridSnapRef()
        {
            // Check that RecenterGrid also updates the reference grid for snapping
            var ctx = Context.Current;

            var sketch = TestGeomGenerator.CreateSketch(TestGeomGenerator.SketchType.MultiCircle);
            var body   = TestGeomGenerator.CreateBody(sketch);

            ctx.ViewportController.ZoomFitAll();

            var sketchEditor = new SketchEditorTool(sketch);

            ctx.WorkspaceController.StartTool(sketchEditor);

            Assert.IsTrue(SketchCommands.RecenterGrid.CanExecute());
            SketchCommands.RecenterGrid.Execute();
            Assert.IsInstanceOf <RecenterGridSketchTool>(sketchEditor.CurrentTool);

            ctx.ClickAt(200, 200);

            SketchCommands.CreateSegment.Execute(SketchCommands.Segments.Line);
            ctx.EditorState.SnappingEnabled    = true;
            ctx.EditorState.SnapToGridSelected = true;
            ctx.MoveTo(44, 44);
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "RecenterGridSnapRef01"));
        }
Beispiel #19
0
        public void ReversedFace()
        {
            var baseShape = new Box
            {
                DimensionX = 20,
                DimensionY = 20,
                DimensionZ = 20,
            };
            var body = TestGeomGenerator.CreateBody(baseShape, new Pnt(-10, -10, 0));

            var imprint = Imprint.Create(body, baseShape.GetSubshapeReference(SubshapeType.Face, 0));

            var sketch = imprint.Operands[1] as Sketch;

            Assert.IsNotNull(sketch);

            sketch.Points.Add(0, new Pnt2d(0, 0));
            sketch.Points.Add(1, new Pnt2d(0, 11));
            sketch.Segments.Add(0, new SketchSegmentCircle(0, 1));

            Assert.IsNotNull(imprint);

            imprint.Depth = 2.5;
            imprint.Mode  = Imprint.ImprintMode.Raise;

            Assert.IsTrue(imprint.Make(Shape.MakeFlags.None));
            Assert.IsTrue(ModelCompare.CompareShape(imprint, Path.Combine(_BasePath, "ReversedFace")));
        }
        public void SelectPointAfterMove()
        {
            var ctx = Context.Current;

            var sketch = TestGeomGenerator.CreateSketch(TestGeomGenerator.SketchType.MultiCircle);
            var body   = TestGeomGenerator.CreateBody(sketch);

            ctx.ViewportController.ZoomFitAll();

            var tool = new SketchEditorTool(sketch);

            ctx.WorkspaceController.StartTool(tool);

            // Move point
            ctx.ClickAt(377, 122);
            Assert.AreEqual(1, tool.SelectedPoints.Count);
            ctx.MoveTo(392, 104);
            ctx.ViewportController.MouseDown();
            ctx.MoveTo(387, 141);
            ctx.ViewportController.MouseUp(false);

            // Return to idle
            ctx.ClickAt(1, 1);
            ctx.ViewportController.MouseDown();
            ctx.ViewportController.MouseUp(false);
            Assert.AreEqual(0, tool.SelectedPoints.Count);

            // Try to select point
            ctx.ClickAt(371, 160);
            Assert.AreEqual(1, tool.SelectedPoints.Count);

            // Cleanup
            tool.Stop();
        }
Beispiel #21
0
        public void DifferentHeights()
        {
            var body1 = TestGeomGenerator.CreateBody(Box.Create(10, 2, 10), new Pnt(-5, -5, -5));
            var body2 = TestGeomGenerator.CreateBody(Box.Create(2, 10, 10), new Pnt(-5, -5, 0));

            var(first, second) = BoxJoint.Create(body1, body2);
            Assert.IsTrue(first.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(first, Path.Combine(_BasePath, "DifferentHeights1"));

            Assert.IsTrue(second.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(second, Path.Combine(_BasePath, "DifferentHeights2"));
        }
        public void Rendering()
        {
            var ctx = Context.Current;

            var body = TestGeomGenerator.CreateBody(Box.Create(10, 5, 2));

            ctx.ViewportController.ZoomFitAll();

            var tool = new TransformBodyTool(new[] { body }, TransformBodyTool.PivotPoint.BodyPivot, TransformBodyTool.Options.None);

            ctx.WorkspaceController.StartTool(tool);

            Assert.Multiple(() =>
            {
                // Translate Idle
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "RenderingTranslateIdle"));

                // Translate Hilite X
                ctx.ViewportController.MouseMove(new Point(264, 188));
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "RenderingTranslateHiliteX"));
                // Translate Hilite Y
                ctx.ViewportController.MouseMove(new Point(385, 187));
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "RenderingTranslateHiliteY"));
                // Translate Hilite Z
                ctx.ViewportController.MouseMove(new Point(325, 84));
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "RenderingTranslateHiliteZ"));

                // Translate Hilite XY
                ctx.ViewportController.MouseMove(new Point(326, 182));
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "RenderingTranslateHiliteXY"));
                // Translate Hilite YZ
                ctx.ViewportController.MouseMove(new Point(350, 136));
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "RenderingTranslateHiliteYZ"));
                // Translate Hilite XZ
                ctx.ViewportController.MouseMove(new Point(296, 136));
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "RenderingTranslateHiliteXZ"));

                // Rotate Idle
                tool.ToggleTransformMode();
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "RenderingRotateIdle"));

                // Rotate Hilite Y
                ctx.ViewportController.MouseMove(new Point(324, 211));
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "RenderingRotateHiliteY"));
                // Rotate Hilite P
                ctx.ViewportController.MouseMove(new Point(357, 62));
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "RenderingRotateHiliteP"));
                // Rotate Hilite R
                ctx.ViewportController.MouseMove(new Point(293, 62));
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "RenderingRotateHiliteR"));
            });
        }
Beispiel #23
0
        public void HalfIntrusion()
        {
            var body1 = TestGeomGenerator.CreateBody(Box.Create(10, 2, 10), new Pnt(-5, -5, -5));
            var body2 = TestGeomGenerator.CreateBody(Box.Create(2, 10, 10), new Pnt(0, -4, -5));

            var(first, second) = BoxJoint.Create(body1, body2);

            Assert.IsTrue(first.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(first, Path.Combine(_BasePath, "HalfIntrusion1"));

            Assert.IsTrue(second.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(second, Path.Combine(_BasePath, "HalfIntrusion2"));
        }
Beispiel #24
0
        public void CustomBoxRatiosLessEntries()
        {
            var body1 = TestGeomGenerator.CreateBody(Box.Create(10, 2, 10), new Pnt(-5, -5, -5));
            var body2 = TestGeomGenerator.CreateBody(Box.Create(2, 10, 10), new Pnt(-5, -5, -5));

            var(first, second) = BoxJoint.Create(body1, body2);

            first.BoxCount        = 5;
            first.CustomBoxRatios = new[] { 0.1, 0.2, 0.3, 0.4 };

            Assert.IsTrue(first.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(first, Path.Combine(_BasePath, "CustomBoxRatiosLessEntries01"));
        }
        public void MovePoint()
        {
            var ctx = Context.Current;

            var sketch = TestGeomGenerator.CreateSketch(TestGeomGenerator.SketchType.MultiCircle);
            var body   = TestGeomGenerator.CreateBody(sketch);

            ctx.ViewportController.ZoomFitAll();

            var tool = new SketchEditorTool(sketch);

            ctx.WorkspaceController.StartTool(tool);

            Assert.Multiple(() =>
            {
                // MovePoints Idle
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "MovePoint01"));
                // Hilite Point
                ctx.ViewportController.MouseMove(new Point(377, 122));
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "MovePoint02"));
                // Select Point, move gizmo shown
                ctx.ViewportController.MouseDown();
                ctx.ViewportController.MouseUp(false);
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "MovePoint03"));
                // Hilite Gizmo X-Axis
                ctx.ViewportController.MouseMove(new Point(459, 122));
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "MovePoint04"));
                // Hilite Gizmo Y-Axis
                ctx.ViewportController.MouseMove(new Point(377, 38));
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "MovePoint05"));
                // Hilite Gizmo XY-Plane
                ctx.ViewportController.MouseMove(new Point(392, 104));
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "MovePoint06"));
                // Move on progress
                ctx.ViewportController.MouseDown();
                ctx.ViewportController.MouseMove(new Point(387, 141));
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "MovePoint07"));
                // Move released
                ctx.ViewportController.MouseUp(false);
                ctx.ViewportController.MouseMove(new Point(1, 1));
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "MovePoint08"));
                // Return to idle
                ctx.ViewportController.MouseDown();
                ctx.ViewportController.MouseUp(false);
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "MovePoint09"));

                // Cleanup
                tool.Stop();
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "MovePoint10"));
            });
        }
Beispiel #26
0
        public void RemoveExcess()
        {
            var body1 = TestGeomGenerator.CreateBody(Box.Create(10, 2, 10), new Pnt(-5, -5, -5));
            var body2 = TestGeomGenerator.CreateBody(Box.Create(2, 10, 10), new Pnt(0, -6, -5));

            var(first, second)  = BoxJoint.Create(body1, body2);
            second.RemoveExcess = true;

            Assert.IsTrue(first.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(first, Path.Combine(_BasePath, "RemoveExcess1"));

            Assert.IsTrue(second.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(second, Path.Combine(_BasePath, "RemoveExcess2"));
        }
Beispiel #27
0
        public void SplitSegmentUndo()
        {
            var ctx = Context.Current;

            var sketch = TestSketchGenerator.CreateSketch(TestSketchGenerator.SketchType.Rectangle);
            var body   = TestGeomGenerator.CreateBody(sketch);

            ctx.ViewportController.ZoomFitAll();

            Assert.IsFalse(ctx.UndoHandler.CanUndo);
            Assert.IsFalse(ctx.UndoHandler.CanRedo);

            var tool = new SketchEditorTool(sketch);

            ctx.WorkspaceController.StartTool(tool);

            Assert.Multiple(() =>
            {
                // Select Segment
                ctx.ClickAt(140, 90);

                // Start split tool
                var splitTool = new SplitElementSketchTool();
                tool.StartTool(splitTool);

                // Split
                ctx.ClickAt(150, 88);
                Assert.AreEqual(5, tool.Sketch.Segments.Count);
                Assert.IsTrue(ctx.UndoHandler.CanUndo);
                Assert.IsFalse(ctx.UndoHandler.CanRedo);

                // Undo
                ctx.UndoHandler.DoUndo(1);
                Assert.AreEqual(4, tool.Sketch.Segments.Count);
                Assert.IsFalse(ctx.UndoHandler.CanUndo);
                Assert.IsTrue(ctx.UndoHandler.CanRedo);

                // Redo
                ctx.UndoHandler.DoRedo(1);
                Assert.AreEqual(5, tool.Sketch.Segments.Count);
                Assert.IsTrue(ctx.UndoHandler.CanUndo);
                Assert.IsFalse(ctx.UndoHandler.CanRedo);

                // Cleanup
                tool.StopTool();
            });

            tool.Stop();
        }
Beispiel #28
0
        public void CustomBoxRatiosOrder()
        {
            var body1 = TestGeomGenerator.CreateBody(Box.Create(10, 2, 10), new Pnt(-5, -5, -5));
            var body2 = TestGeomGenerator.CreateBody(Box.Create(2, 10, 10), new Pnt(-5, -5, -5));

            var(first, second) = BoxJoint.Create(body1, body2);

            first.BoxCount        = 5;
            first.CustomBoxRatios = new[] { 0.1, 0.2, 0.3, 0.4, 0.5 };
            first.ReverseOrder    = true;

            Assert.IsTrue(first.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(first, Path.Combine(_BasePath, "CustomBoxRatiosOrder01a"));
            Assert.IsTrue(second.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(second, Path.Combine(_BasePath, "CustomBoxRatiosOrder01b"));
        }
Beispiel #29
0
        public void DeleteBoth()
        {
            var body1 = TestGeomGenerator.CreateBody(Box.Create(10, 2, 10), new Pnt(-5, -5, -5));
            var body2 = TestGeomGenerator.CreateBody(Box.Create(2, 10, 10), new Pnt(-5, -5, -5));

            var(first, second) = BoxJoint.Create(body1, body2);

            body1.RemoveShape(first);

            Assert.IsTrue(body1.Shape.Make(Shape.MakeFlags.None));
            Assert.AreEqual(6, body1.Shape.GetBRep().Faces().Count);

            Assert.IsTrue(body2.Shape.Make(Shape.MakeFlags.None));
            Assert.IsNull(second.Body, "The associated shape is still connected to it's body.");
            Assert.AreEqual(6, body2.Shape.GetBRep().Faces().Count, "The associated shape was not deleted.");
        }
Beispiel #30
0
        public void MultipleSolids()
        {
            var body1     = TestGeomGenerator.CreateBody(Box.Create(10, 2, 10), new Pnt(-5, -5, -5));
            var body2     = TestGeomGenerator.CreateBody(Box.Create(2, 10, 10), new Pnt(0, -5, -5));
            var carveBody = TestGeomGenerator.CreateBody(Box.Create(2, 5, 4), new Pnt(0, -5, -2));

            BooleanCut.Create(body2, new BodyShapeOperand(carveBody));

            var(first, second) = BoxJoint.Create(body1, body2);

            Assert.IsTrue(first.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(first, Path.Combine(_BasePath, "MultipleSolids1"));

            Assert.IsTrue(second.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(second, Path.Combine(_BasePath, "MultipleSolids2"));
        }