Пример #1
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);
    }
Пример #2
0
        public void Fuse()
        {
            var shapes = TestGeomGenerator.CreateBooleanBodies(false);

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

            Assert.IsTrue(boolOp.Make(Shape.MakeFlags.None));
            Assert.IsTrue(ModelCompare.CompareShape(boolOp, Path.Combine(_BasePath, "Fuse")));
        }
Пример #3
0
        public void AddShapeOnTop()
        {
            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>());

            // Check result shape
            AssertHelper.IsSameModel(body.Shape, Path.Combine(_BasePath, "AddShapeOnTop"));
        }
Пример #4
0
        public void CloneReferenceBodies()
        {
            var model        = CoreContext.Current.Document;
            var operandBody1 = TestGeomGenerator.CreateBody(Box.Create(5, 5, 5), new Pnt());

            model.Add(operandBody1);
            var targetBody1 = TestGeomGenerator.CreateBody(Box.Create(5, 5, 5), new Pnt(2, 2, 0));

            model.Add(targetBody1);
            BooleanFuse.Create(targetBody1, new BodyShapeOperand(operandBody1));
            var serialized = Serializer.Serialize(targetBody1, new SerializationContext());

            // Deserialize with reusing existing referenced bodies
            var context = new SerializationContext(SerializationScope.CopyPaste);

            context.SetInstance(model);
            context.SetInstance <IDocument>(model);
            context.SetInstance(ReadOptions.RecreateGuids);
            context.SetInstance(new CloneOptions(false));
            var targetBody2 = Serializer.Deserialize <Entity>(serialized, context) as Body;

            Assert.IsNotNull(targetBody2);
            var operandBody2 = ((targetBody2.RootShape as ModifierBase)?.Operands[1] as BodyShapeOperand)?.Body;

            Assert.IsNotNull(operandBody2);
            Assert.AreSame(operandBody1, operandBody2);

            // Deserialize with cloning referenced bodies
            context = new SerializationContext(SerializationScope.CopyPaste);
            context.SetInstance(model);
            context.SetInstance <IDocument>(model);
            context.SetInstance(ReadOptions.RecreateGuids);
            context.SetInstance(new CloneOptions(true));
            var targetBody3 = Serializer.Deserialize <Entity>(serialized, context) as Body;

            Assert.IsNotNull(targetBody3);
            var operandBody3 = ((targetBody3.RootShape as ModifierBase)?.Operands[1] as BodyShapeOperand)?.Body;

            Assert.IsNotNull(operandBody3);
            Assert.AreNotSame(operandBody1, operandBody3);
        }
Пример #5
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"));
        }
Пример #6
0
        public void InvalidationAcrossBodyOperand()
        {
            var box1  = TestGeomGenerator.CreateBox();
            var body1 = box1.Body;

            TransformUtils.Translate(body1, new Vec(-2.5, -2.5, 0));

            var box2  = TestGeomGenerator.CreateBox();
            var body2 = box2.Body;

            TransformUtils.Translate(body2, new Vec(2.5, 2.5, 0));
            BooleanFuse.Create(body2, new BodyShapeOperand(body1));

            AssertHelper.IsSameModel(body2.Shape, Path.Combine(_BasePath, "InvalidationAcrossBodyOperand1"));

            // Change the first, the second should get invalid, too
            box1.DimensionZ = 5;
            AssertHelper.IsSameModel(body2.Shape, Path.Combine(_BasePath, "InvalidationAcrossBodyOperand2"));

            // Move body
            body1.Position = body1.Position.Translated(new Vec(0, 0, 2.5));
            AssertHelper.IsSameModel(body2.Shape, Path.Combine(_BasePath, "InvalidationAcrossBodyOperand3"));
        }
Пример #7
0
        public void UndoDeletionOfReferencingBody()
        {
            var model = CoreContext.Current.Document;
            var body1 = TestGeomGenerator.CreateBody(Box.Create(5, 5, 5), new Pnt());

            model.Add(body1);
            var body2 = TestGeomGenerator.CreateBody(Box.Create(5, 5, 5), new Pnt(2, 2, 0));

            model.Add(body2);
            BooleanFuse.Create(body2, new BodyShapeOperand(body1));
            model.UndoHandler.Commit();
            Assume.That(model.EntityCount, Is.EqualTo(2));

            model.SafeDelete(new [] { body2 });
            model.UndoHandler.Commit();
            Assume.That(model.EntityCount, Is.EqualTo(1));

            // Undo should link to the SAME body as before
            CoreContext.Current.UndoHandler.DoUndo(1);
            Assert.AreEqual(2, model.EntityCount);
            var newBody2 = model.Get(1) as Body;

            Assert.AreSame(body1, ((newBody2.RootShape as ModifierBase)?.Operands[1] as BodyShapeOperand)?.Body);
        }