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));
        }
Ejemplo n.º 2
0
        //--------------------------------------------------------------------------------------------------

        bool _DoCutoutBoxes(MakeContext context)
        {
            var listOfTools = new TopTools_ListOfShape();

            foreach (var boxes in context.Boxes)
            {
                for (int boxIndex = _ReverseOrder == _IsFirst ? 0 : 1; boxIndex < boxes.Count; boxIndex += 2)
                {
                    listOfTools.Append(boxes[boxIndex]);
                }
            }

            var listOfArguments = new TopTools_ListOfShape();

            listOfArguments.Append(context.OwnBrep);

            var cutter = new BRepAlgoAPI_Cut();

            cutter.SetArguments(listOfArguments);
            cutter.SetTools(listOfTools);
            cutter.Build();
            if (!cutter.IsDone())
            {
                Messages.Error("Cannot cut boxes out of shape.");
                return(false);
            }

            context.Result = cutter.Shape();
            UpdateModifiedSubshapes(context.OwnBrep, cutter);

            return(true);
        }
Ejemplo n.º 3
0
        //--------------------------------------------------------------------------------------------------

        bool _DoCutoffExcess(MakeContext context)
        {
            var listOfArguments = new TopTools_ListOfShape();

            listOfArguments.Append(context.OwnBrep);

            // Cutout Commons
            var listOfTools = new TopTools_ListOfShape();

            foreach (var commonSolid in context.Common)
            {
                listOfTools.Append(commonSolid);
            }

            var cutter = new BRepAlgoAPI_Cut();

            cutter.SetArguments(listOfArguments);
            cutter.SetTools(listOfTools);
            cutter.Build();
            if (!cutter.IsDone())
            {
                Messages.Error("Cannot determine excess of instrusion.");
                return(false);
            }

            // Check if we have more solids than before
            var originalSolidCount = context.OwnBrep.Solids().Count;
            var solids             = cutter.Shape().Solids();
            var excessCount        = solids.Count - originalSolidCount;

            if (excessCount <= 0)
            {
                return(true); // No excess found
            }
            // Cutout additional solids
            listOfTools = new TopTools_ListOfShape();
            var orderedSolids = solids.OrderBy(solid => solid.Volume()).Take(excessCount);

            foreach (var solid in orderedSolids)
            {
                listOfTools.Append(solid);
            }

            cutter = new BRepAlgoAPI_Cut();
            cutter.SetArguments(listOfArguments);
            cutter.SetTools(listOfTools);
            cutter.Build();
            if (!cutter.IsDone())
            {
                Messages.Error("Cannot remove excess of instrusion from shape.");
                return(false);
            }

            UpdateModifiedSubshapes(context.OwnBrep, cutter);
            context.OwnBrep = cutter.Shape();
            return(true);
        }