示例#1
0
        public void RemoveReferencedBody()
        {
            void __CreateTwoBodiesAndRemoveOne()
            {
                Context.InitWithDefault();
                var model   = CoreContext.Current.Document;
                var boxBody = Body.Create(Box.Create(20, 20, 10));

                boxBody.Position = new Pnt(-10, -10, 0);
                model.Add(boxBody);

                var cylBody = Body.Create(Sphere.Create(20));

                cylBody.Position = new Pnt(-15, 0, 0);
                model.Add(cylBody);

                BooleanCut.Create(boxBody, new BodyShapeOperand(cylBody));

                model.SafeDelete(new[] { cylBody });
            }

            __CreateTwoBodiesAndRemoveOne();

            dotMemory.Check(memory =>
            {
                Assert.AreEqual(1, memory.ObjectsCount <Body>(), "Body is alive");
                Assert.AreEqual(1, memory.ObjectsCount <Solid>(), "Solid not found");
                Assert.AreEqual(0, memory.ObjectsCount <Sphere>(), "Sphere is alive");
            });
        }
示例#2
0
    //--------------------------------------------------------------------------------------------------

    ModifierBase Execute(Body body, IShapeOperand[] operands)
    {
        InteractiveContext.Current.WorkspaceController.Selection.SelectEntity(null);

        ModifierBase boolOpShape = null;

        switch (Operation)
        {
        case Operations.Cut:
            boolOpShape = BooleanCut.Create(body, operands);
            break;

        case Operations.Common:
            boolOpShape = BooleanCommon.Create(body, operands);
            break;

        case Operations.Fuse:
            boolOpShape = BooleanFuse.Create(body, operands);
            break;
        }

        foreach (var operandBody in operands.OfType <BodyShapeOperand>())
        {
            operandBody.Body.IsVisible = false;
        }

        return(boolOpShape);
    }
        public void CollapsedToSolidTransform()
        {
            // Bugcheck: The solid operand shape, which is created by collapsing a body on deletion,
            // is not drawn at the correct place (but is correctly processed in the making of the body)
            var model   = CoreContext.Current.Document;
            var boxBody = Body.Create(new Box()
            {
                DimensionX = 20,
                DimensionY = 20,
                DimensionZ = 10,
            });

            boxBody.Position = new Pnt(-10, -10, 0);
            model.AddChild(boxBody);

            var cylBody = Body.Create(new Sphere()
            {
                Radius = 20
            });

            cylBody.Position = new Pnt(-15, 0, 0);
            model.AddChild(cylBody);

            BooleanCut.Create(boxBody, new BodyShapeOperand(cylBody));

            Context.Current.ViewportController.ZoomFitAll();
            //AssertHelper.IsSameViewport(Path.Combine(_BasePath, "CollapsedToSolidTransform1"));

            model.SafeDelete(new[] { cylBody });
            //AssertHelper.IsSameViewport(Path.Combine(_BasePath, "CollapsedToSolidTransform2"));

            boxBody.Shape = (boxBody.RootShape as ModifierBase).Operands[1] as Shape;
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "CollapsedToSolidTransform3"));
        }
示例#4
0
        public void Cut()
        {
            var shapes = TestGeomGenerator.CreateBooleanBodies(false);

            var boolOp = BooleanCut.Create(shapes.target, shapes.operands);

            Assert.IsTrue(boolOp.Make(Shape.MakeFlags.None));
            Assert.IsTrue(ModelCompare.CompareShape(boolOp, Path.Combine(_BasePath, "Cut")));
        }
示例#5
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"));
        }
        //--------------------------------------------------------------------------------------------------

        ShapeDesc MakeBooleanCut(ShapeDesc op1, ShapeDesc op2)
        {
            var desc = new ShapeDesc
            {
                Shape = BooleanCut.Create(op1.Body, new BodyShapeOperand(op2.Body))
            };

            desc.OcShape  = desc.Shape.GetBRep();
            desc.Vertices = desc.OcShape.Vertices();
            Assert.AreEqual(10, desc.Vertices.Count);
            desc.Edges = desc.OcShape.Edges();
            Assert.AreEqual(15, desc.Edges.Count);
            desc.Faces = desc.OcShape.Faces();
            Assert.AreEqual(7, desc.Faces.Count);

            return(desc);
        }
示例#7
0
        public void DeleteReferencedBody()
        {
            var model   = CoreContext.Current.Document;
            var boxBody = Body.Create(new Box()
            {
                DimensionX = 20,
                DimensionY = 20,
                DimensionZ = 10,
            });

            boxBody.Position = new Pnt(-10, -10, 0);
            model.Add(boxBody);

            var cylBody = Body.Create(new Sphere()
            {
                Radius = 15
            });

            cylBody.Position = new Pnt(-10, -10, 0);
            model.Add(cylBody);

            Assume.That(CoreContext.Current.Document.EntityCount, Is.EqualTo(2));

            var boolOp = BooleanCut.Create(boxBody, new BodyShapeOperand(cylBody));

            model.UndoHandler.Commit();
            Assert.IsTrue(boolOp.Make(Shape.MakeFlags.None));
            Assert.IsTrue(ModelCompare.CompareShape(boxBody.Shape, Path.Combine(_BasePath, "DeleteReferencedBody")));

            model.SafeDelete(new[] { cylBody });
            model.UndoHandler.Commit();
            Assert.AreEqual(1, CoreContext.Current.Document.EntityCount);
            Assert.IsFalse(boxBody.Shape.IsValid);
            Assert.That((boxBody.Shape as ModifierBase)?.Operands[1] is Solid);
            Assert.IsTrue(boolOp.Make(Shape.MakeFlags.None));
            Assert.IsTrue(ModelCompare.CompareShape(boxBody.Shape, Path.Combine(_BasePath, "DeleteReferencedBody")));

            // Check Undo
            CoreContext.Current.UndoHandler.DoUndo(1);
            Assert.AreEqual(2, CoreContext.Current.Document.EntityCount);
            Assert.That((boxBody.Shape as ModifierBase)?.Operands[1] is BodyShapeOperand);
            Assert.IsTrue(ModelCompare.CompareShape(boxBody.Shape, Path.Combine(_BasePath, "DeleteReferencedBody")));
        }
示例#8
0
        public void InsertShapeInTheMiddle()
        {
            var imprint = TestGeomGenerator.CreateImprint();
            var body    = imprint.Body;

            BooleanFuse.Create(body, Box.Create(1, 1, 10));

            // Current and root shape is boolean fuse
            Assert.That(body.Shape, Is.TypeOf <BooleanFuse>());
            Assert.That(body.RootShape, Is.TypeOf <BooleanFuse>());

            // Set current and add new shape
            body.Shape = imprint;
            Assert.That(body.Shape, Is.TypeOf <Imprint>());
            BooleanCut.Create(body, Box.Create(2, 2, 5));
            Assert.That(body.Shape, Is.TypeOf <BooleanCut>());

            // Check result shape
            AssertHelper.IsSameModel(body.Shape, Path.Combine(_BasePath, "InsertShapeInTheMiddle1"));
            AssertHelper.IsSameModel(body.RootShape, Path.Combine(_BasePath, "InsertShapeInTheMiddle2"));
        }
示例#9
0
        public void BodyTopologyUndo()
        {
            // Create object and body, -> State1
            var box  = TestGeomGenerator.CreateBox();
            var body = box.Body;
            var box2 = TestGeomGenerator.CreateBox();

            Assert.IsFalse(Context.Current.UndoHandler.CanUndo);
            Assert.IsFalse(Context.Current.UndoHandler.CanRedo);
            var state1 = Serializer.Serialize(body, new SerializationContext());

            // Change topology -> State2
            body.SaveTopologyUndo();
            var fillet = Fillet.Create(body);

            fillet.Radius = 1;
            Context.Current.UndoHandler.Commit();
            Assert.IsTrue(Context.Current.UndoHandler.CanUndo);
            Assert.IsFalse(Context.Current.UndoHandler.CanRedo);
            var state2 = Serializer.Serialize(body, new SerializationContext());

            // Change toplogy -> State3
            box.DimensionZ = 8;
            body.SaveTopologyUndo();
            var boolean = BooleanCut.Create(body, box2);

            Context.Current.UndoHandler.Commit();
            Assert.IsTrue(Context.Current.UndoHandler.CanUndo);
            Assert.IsFalse(Context.Current.UndoHandler.CanRedo);
            var state3 = Serializer.Serialize(body, new SerializationContext());

            // Undo -> State2
            Context.Current.UndoHandler.DoUndo(1);
            Assert.IsTrue(Context.Current.UndoHandler.CanUndo);
            Assert.IsTrue(Context.Current.UndoHandler.CanRedo);
            var state2a = Serializer.Serialize(body, new SerializationContext());

            Assert.AreEqual(state2, state2a);

            // Redo -> State3
            Context.Current.UndoHandler.DoRedo(1);
            Assert.IsTrue(Context.Current.UndoHandler.CanUndo);
            Assert.IsFalse(Context.Current.UndoHandler.CanRedo);
            var state3a = Serializer.Serialize(body, new SerializationContext());

            Assert.AreEqual(state3, state3a);

            // Undo, Undo -> State 1
            Context.Current.UndoHandler.DoUndo(2);
            Assert.IsFalse(Context.Current.UndoHandler.CanUndo);
            Assert.IsTrue(Context.Current.UndoHandler.CanRedo);
            var state1a = Serializer.Serialize(body, new SerializationContext());

            Assert.AreEqual(state1, state1a);

            // Redo, Redo -> State 3
            Context.Current.UndoHandler.DoRedo(2);
            Assert.IsTrue(Context.Current.UndoHandler.CanUndo);
            Assert.IsFalse(Context.Current.UndoHandler.CanRedo);
            var state3b = Serializer.Serialize(body, new SerializationContext());

            Assert.AreEqual(state3, state3b);
        }