Example #1
0
 public Tracer(string methodName, ILogger logger, IXbimGeometryObject geometryObject)
 {
     this.methodName = methodName;
     this.logger     = logger ?? throw new ArgumentNullException(nameof(logger));
     if (logger.IsEnabled(LogLevel.Trace)) // Optimisation to avoid GetType reflection unless Trace enabled
     {
         logger.LogTrace("Entering GeometryEngine {function} with {tag} [{type}]",
                         methodName, geometryObject.Tag, geometryObject.GetType().Name);
     }
 }
Example #2
0
        public void TestCuttingOpenings()
        {
            //   var w = new XbimOccWriter();
            const string modelDirectory = "";//define where your files to test are @"D:\Users\steve\xBIM\Test Models\Use Cases\Live";

            if (string.IsNullOrWhiteSpace(modelDirectory))
            {
                Trace.WriteLine("TestCuttingOpenings tests skipped. Enter a directory where the test models can be found");
                return;
            }
            var di = new DirectoryInfo(modelDirectory);

            FileInfo[] toProcess = di.GetFiles("*.IFC", SearchOption.TopDirectoryOnly);
            foreach (var file in toProcess)
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom(file.FullName, null, null, true, true);

                    using (var eventTrace = LoggerFactory.CreateEventTrace())
                    {
                        var theElements = _xbimGeometryCreator.CreateSolidSet();
                        var openings    = m.Instances.OfType <IfcRelVoidsElement>()
                                          .Where(
                            r =>
                            r.RelatingBuildingElement.Representation != null &&
                            r.RelatedOpeningElement.Representation != null)
                                          .Select(
                            f =>
                            new
                        {
                            element = f.RelatingBuildingElement,
                            feature = f.RelatedOpeningElement
                        });

                        var toCut = openings.GroupBy(x => x.element, y => y.feature).ToList();

                        Parallel.ForEach(toCut, new ParallelOptions(), rel =>
                                         //         foreach (var rel in toCut)
                        {
                            var elem          = rel.Key;
                            var elemTransform = elem.Transform();
                            var elemSolids    = _xbimGeometryCreator.CreateSolidSet();
                            foreach (var rep in elem.Representation.Representations)
                            {
                                if (rep.ContextOfItems.ContextType != null &&
                                    "Model" == rep.ContextOfItems.ContextType.Value.ToString() && (rep.RepresentationIdentifier.HasValue && rep.RepresentationIdentifier == "Body"))
                                {
                                    foreach (var item in rep.Items.OfType <IfcGeometricRepresentationItem>())
                                    {
                                        IXbimGeometryObject shape = _xbimGeometryCreator.Create(item);
                                        if (!shape.IsValid)
                                        {
                                            Assert.IsTrue(shape.IsValid, "Invalid shape found in #" + item.EntityLabel);
                                        }
                                        var solid = shape as IXbimSolid;
                                        if (solid != null)
                                        {
                                            IfcCsgTests.GeneralTest(solid, true, item is IfcHalfSpaceSolid,
                                                                    rep.EntityLabel);

                                            solid = (IXbimSolid)solid.Transform(elemTransform);
                                            elemSolids.Add(solid);
                                        }
                                        else if (shape is IXbimSolidSet)
                                        {
                                            foreach (var subSolid in shape as IXbimSolidSet)
                                            {
                                                IfcCsgTests.GeneralTest(subSolid, true, item is IfcHalfSpaceSolid,
                                                                        rep.EntityLabel);
                                                elemSolids.Add(subSolid.Transform(elemTransform));
                                            }
                                        }
                                        else if (shape is IXbimGeometryObjectSet)
                                        {
                                            foreach (var subShape in shape as IXbimGeometryObjectSet)
                                            {
                                                if (subShape is IXbimSolid)
                                                {
                                                    IfcCsgTests.GeneralTest((IXbimSolid)subShape, true,
                                                                            item is IfcHalfSpaceSolid,
                                                                            rep.EntityLabel);
                                                }
                                                elemSolids.Add(subShape.Transform(elemTransform));
                                            }
                                        }
                                        else
                                        {
                                            Trace.WriteLine("No Solid found #" + item.EntityLabel + " " +
                                                            shape.GetType().Name);
                                        }
                                    }
                                }
                            }

                            var openingSolids = _xbimGeometryCreator.CreateSolidSet();
                            foreach (var opening in rel)
                            {
                                var openingTransform = opening.Transform();
                                foreach (var openingrep in opening.Representation.Representations)
                                {
                                    if (openingrep.ContextOfItems.ContextType != null &&
                                        "Model" == openingrep.ContextOfItems.ContextType.Value.ToString() && (openingrep.RepresentationIdentifier.HasValue && openingrep.RepresentationIdentifier == "Body"))
                                    {
                                        foreach (
                                            var openingitem in openingrep.Items.OfType <IfcGeometricRepresentationItem>()
                                            )
                                        {
                                            IXbimGeometryObject openingshape = _xbimGeometryCreator.Create(openingitem);

                                            if (!openingshape.IsValid)
                                            {
                                                Trace.WriteLine("Invalid shape found in #" + openingitem.EntityLabel);
                                                continue;
                                            }
                                            var openingsolid = openingshape as IXbimSolid;
                                            if (openingsolid != null)
                                            {
                                                IfcCsgTests.GeneralTest((IXbimSolid)openingshape, true,
                                                                        openingitem is IfcHalfSpaceSolid,
                                                                        openingrep.EntityLabel);
                                                openingsolid = (IXbimSolid)openingsolid.Transform(openingTransform);
                                                openingSolids.Add(openingsolid);
                                            }
                                            else if (openingshape is IXbimSolidSet)
                                            {
                                                foreach (var subOpeningSolid in openingshape as IXbimSolidSet)
                                                {
                                                    IfcCsgTests.GeneralTest(subOpeningSolid, true,
                                                                            openingitem is IfcHalfSpaceSolid,
                                                                            openingrep.EntityLabel);
                                                    openingSolids.Add(subOpeningSolid.Transform(openingTransform));
                                                }
                                            }
                                            else if (openingshape is IXbimGeometryObjectSet)
                                            {
                                                foreach (var subShape in openingshape as IXbimGeometryObjectSet)
                                                {
                                                    if (subShape is IXbimSolid)
                                                    {
                                                        IfcCsgTests.GeneralTest((IXbimSolid)subShape, true,
                                                                                openingitem is IfcHalfSpaceSolid,
                                                                                openingrep.EntityLabel);
                                                    }
                                                    openingSolids.Add(subShape.Transform(openingTransform));
                                                }
                                            }
                                            else
                                            {
                                                Trace.WriteLine("No Solid found #" + openingitem.EntityLabel + " " +
                                                                openingshape.GetType().Name);
                                            }
                                        }
                                    }
                                }
                            }

                            // ReSharper disable once AccessToDisposedClosure

                            var solidResult = elemSolids.Cut(openingSolids, m.ModelFactors.PrecisionBoolean);
                            foreach (var result in solidResult)
                            {
                                IfcCsgTests.GeneralTest(result, true, false,
                                                        elem.EntityLabel);
                                theElements.Add(result);
                            }
                        }
                                         );
                        // w.Write(theElements, "d:\\xbim\\r");
                        if (eventTrace.Events.Count > 0)
                        {
                            //var assertNow = false;
                            Trace.WriteLine("Model: " + file.Name);
                            foreach (var err in eventTrace.Events)
                            {
                                Trace.WriteLine(err.Message);
                                //if (err.EventLevel == EventLevel.ERROR)
                                //    assertNow = true;
                            }

                            // Assert.IsTrue(assertNow == false, "Error events were raised");
                        }
                    }
                }
            }
        }