Esempio n. 1
0
        public void SameBeginning()
        {
            var body1 = TestData.GetBodyFromBRep(Path.Combine(_BasePath, "Source1.brep"));
            var body2 = TestData.GetBodyFromBRep(Path.Combine(_BasePath, "Source2.brep"));

            var(first, second)  = BoxJoint.Create(body1, body2);
            first.ReverseOrder  = false;
            first.BoxCount      = 4; // Only visible if boxcount is even
            first.RemoveExcess  = true;
            second.RemoveExcess = true;
            Assert.IsTrue(first.Make(Shape.MakeFlags.None));
            Assert.IsTrue(second.Make(Shape.MakeFlags.None));

            var compound = new TopoDS_Compound();
            var builder  = new BRep_Builder();

            builder.MakeCompound(compound);
            builder.Add(compound, body1.GetTransformedBRep());
            builder.Add(compound, body2.GetTransformedBRep());
            AssertHelper.IsSameModel(compound, Path.Combine(_BasePath, "SameBeginning"));

            first.ReverseOrder = true;
            Assert.IsTrue(first.Make(Shape.MakeFlags.None));
            Assert.IsTrue(second.Make(Shape.MakeFlags.None));

            compound = new TopoDS_Compound();
            builder.MakeCompound(compound);
            builder.Add(compound, body1.GetTransformedBRep());
            builder.Add(compound, body2.GetTransformedBRep());
            AssertHelper.IsSameModel(compound, Path.Combine(_BasePath, "SameBeginning2"));
        }
        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");
            });
        }
Esempio n. 3
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"));
        }
Esempio n. 4
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"));
        }
Esempio n. 5
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"));
        }
Esempio n. 6
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"));
        }
Esempio n. 7
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"));
        }
Esempio n. 8
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"));
        }
Esempio n. 9
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"));
        }
Esempio n. 10
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.");
        }
Esempio n. 11
0
        public void Cascaded()
        {
            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 body3 = TestGeomGenerator.CreateBody(Box.Create(2, 10, 10), new Pnt(0, -5, -5));

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

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

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

            Assert.IsTrue(third.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(third, Path.Combine(_BasePath, "Cascaded3"));
        }
Esempio n. 12
0
        public void Ratio()
        {
            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.Ratio        = 0.25;

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

            second.ReverseOrder = true;
            Assert.IsTrue(first.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(first, Path.Combine(_BasePath, "Ratio11"));
            Assert.IsTrue(second.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(second, Path.Combine(_BasePath, "Ratio12"));
        }
Esempio n. 13
0
        public void VaryBoxCount()
        {
            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     = 4;

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

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

            second.BoxCount = 5;

            Assert.IsTrue(first.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(first, Path.Combine(_BasePath, "VaryBoxCount3"));
        }
Esempio n. 14
0
        //--------------------------------------------------------------------------------------------------

        void _OnActionFinished(ToolAction toolAction)
        {
            var ta = toolAction as SelectEntityAction <Body>;

            if (ta == null)
            {
                return;
            }

            ta.Stop();

            if (ta.SelectedEntity != null)
            {
                var boxJoint = BoxJoint.Create(_TargetBody1, ta.SelectedEntity);
                InteractiveContext.Current.UndoHandler.Commit();
            }

            Stop();

            WorkspaceController.Invalidate();
        }
Esempio n. 15
0
        public void DeleteOneBody()
        {
            var model = CoreContext.Current.Document;
            var body1 = TestGeomGenerator.CreateBody(Box.Create(10, 2, 10), new Pnt(-5, -5, -5));

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

            model.Add(body2);

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

            model.SafeDelete(new[] { body1 });
            model.UndoHandler.Commit();

            Assert.IsNull(body1.Shape);

            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.");

            Assert.IsNull(first.Body, "The reference to the first shape still exists.");

            // Check undo
            Assert.IsTrue(model.UndoHandler.CanUndo);
            model.UndoHandler.DoUndo(1);

            Assert.IsInstanceOf <BoxJoint>(body2.Shape);
            Assert.IsTrue(body2.Shape.Make(Shape.MakeFlags.None));
            Assert.Less(6, body2.Shape.GetBRep().Faces().Count);

            body1 = model.FindInstance(body1.Guid) as Body;
            Assert.IsNotNull(body1);
            Assert.IsInstanceOf <BoxJoint>(body1.Shape);
            Assert.IsTrue(body1.Shape.Make(Shape.MakeFlags.None));
            Assert.Less(6, body1.Shape.GetBRep().Faces().Count);
        }
Esempio n. 16
0
        //--------------------------------------------------------------------------------------------------

        public override bool Start()
        {
            if (_TargetBody2 != null)
            {
                var boxJoint = BoxJoint.Create(_TargetBody1, _TargetBody2);
                InteractiveContext.Current.UndoHandler.Commit();
                Stop();
                WorkspaceController.Invalidate();
                return(false);
            }

            var toolAction = new SelectEntityAction <Body>(this);

            if (!WorkspaceController.StartToolAction(toolAction))
            {
                return(false);
            }
            toolAction.Previewed += _OnActionPreview;
            toolAction.Finished  += _OnActionFinished;
            toolAction.Exclude(_TargetBody1);
            UpdateStatusText(null);
            WorkspaceController.HudManager?.SetCursor(Cursors.SelectShape);
            return(true);
        }