Пример #1
0
        private void CreateAlignments()
        {
            var site    = i.FirstOrDefault <IfcSite>();
            var imports = new FilteredElementCollector(_document)
                          .OfClass(typeof(ImportInstance))
                          .ToElements()
                          .Cast <ImportInstance>()
                          .ToList();
            var containment = site?.ContainsElements.FirstOrDefault()?.RelatedElements ?? i.New <IfcRelContainedInSpatialStructure>(r => r.RelatingStructure = site).RelatedElements;

            foreach (var import in imports)
            {
                var name = import.Category != null ? $"{import.Category.Name}: {import.Name}" : import.UniqueId;

                var geom = import.get_Geometry(new Options {
                    DetailLevel = ViewDetailLevel.Medium, IncludeNonVisibleObjects = false, ComputeReferences = false
                });
                var polylines = GetPolylines(geom).ToList();

                if (polylines.Count == 0)
                {
                    continue;
                }
                foreach (var polyline in polylines)
                {
                    // export as IfcAlignment and curve
                    var alignment = i.New <IfcAlignment>(a =>
                    {
                        a.Name = name;
                        //a.GlobalId = GetIfcGUID(dwg);
                        a.Representation = i.New <IfcProductDefinitionShape>(r => r.Representations.Add(i.New <IfcShapeRepresentation>(s =>
                        {
                            s.ContextOfItems = ModelContext;
                            s.Items.Add(GetSolid(polyline));
                            SetRedStyle(s.Items);
                        })));
                        a.ObjectPlacement = i.New <IfcLocalPlacement>(op =>
                        {
                            op.PlacementRelTo    = i.FirstOrDefault <IfcSite>()?.ObjectPlacement;
                            op.RelativePlacement = i.New <IfcAxis2Placement3D>();
                        });
                        a.Axis = GetAlignmentCurve(polyline, 0);
                    });

                    // add alignment to the default railway part
                    containment?.Add(alignment);

                    var record = new AlignmentRecord
                    {
                        Alignment = alignment,
                        Polylines = polyline
                    };
                    _alignments.Add(record);
                }
            }
        }
Пример #2
0
        private void MatchElementsToAlignments()
        {
            // find all elements for the curves (railings and sleepers)
            var railParts = new FilteredElementCollector(_document)
                            .OfClass(typeof(FamilyInstance))
                            .ToElements()
                            .Cast <FamilyInstance>()
                            .Where(e => AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(e))
                            .ToList();

            foreach (var element in railParts)
            {
                // get adaptive points
                var points = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(element)
                             .Select(r => _document.GetElement(r))
                             .Cast <ReferencePoint>()
                             .ToList();

                // match addaptive points to curves
                if (points.Count > 0)
                {
                    foreach (var record in _alignments)
                    {
                        if (ArePointsOnCurve(record.Polylines, points))
                        {
                            // find IFC element
                            IfcGloballyUniqueId id = GetIfcGUID(element);
                            var ifcElement         = i.FirstOrDefault <IfcBuildingElement>(e => e.GlobalId == id);
                            if (ifcElement != null)
                            {
                                record.Elements.Add(ifcElement);
                            }
                        }
                    }
                }
            }

            // find building elements which were not matched, possibly because they were not modelled with adaptive points
            var notMatched = i.Where <IfcBuildingElement>(e => !_alignments.Any(a => a.Elements.Contains(e)))
                             .ToList();

            foreach (var element in notMatched)
            {
                var matrix   = GetMatrixRelativeToSite(element);
                var position = matrix.Transform(new XbimPoint3D(0, 0, 0));

                Intersection    intersection = null;
                AlignmentRecord record       = null;
                // find closes alignment intersection (if any)
                foreach (var alignmentRecord in _alignments)
                {
                    var i = GetIntersection2D(alignmentRecord.Segments.ToList(), position);
                    if (i == null)
                    {
                        continue;
                    }
                    if (intersection == null || Math.Abs(intersection.OffsetLateral) > Math.Abs(i.OffsetLateral))
                    {
                        intersection = i;
                        record       = alignmentRecord;
                    }
                }

                // we found one working so lets use it
                if (record != null)
                {
                    record.Elements.Add(element);
                }
            }
        }