Example #1
0
        /// <summary>
        /// Adds a placement to current top scope.
        /// </summary>
        /// <param name="modifier">Action to modify placement by given relative coordinates</param>
        /// <returns>A local placement reference</returns>
        public IIfcLocalPlacement NewLocalPlacement(XbimVector3D refPosition, bool scaleUp = false)
        {
            IIfcLocalPlacement placement = null;

            Wrap(s =>
            {
                var product      = CurrentScope as IIfcProduct;
                var relPlacement = CurrentPlacement;
                if (null != product)
                {
                    if (null == product.ObjectPlacement)
                    {
                        placement = s.NewLocalPlacement(refPosition, scaleUp);
                        if (relPlacement != product.ObjectPlacement)
                        {
                            // Don't reference former placement while replacing own placement
                            placement.PlacementRelTo = relPlacement;
                        }

                        product.ObjectPlacement = placement;
                    }
                    else
                    {
                        Log.LogWarning($"#{product.EntityLabel} has already a placement #{product.ObjectPlacement.EntityLabel}");
                    }
                }
                else
                {
                    throw new OperationCanceledException("No IfcProduct as head of current hierarchy");
                }
            });
            return(placement);
        }
Example #2
0
 protected void AssertIdentityPlacement(IIfcLocalPlacement localPlacement)
 {
     if (localPlacement.RelativePlacement is IIfcAxis2Placement3D a)
     {
         if (null != a.Axis)
         {
             Assert.IsTrue(a.Axis.ToXbimVector3D().IsEqual(new XbimVector3D(0, 0, 1), Precision), "Axis fails");
         }
         if (null != a.RefDirection)
         {
             Assert.IsTrue(a.Axis.ToXbimVector3D().IsEqual(new XbimVector3D(1, 0, 0), Precision), "RefDirection fails");
         }
         if (a.Location is IIfcCartesianPoint p)
         {
             Assert.IsTrue(p.ToXbimVector3D().IsEqual(XbimVector3D.Zero, Precision), "Location fails");
         }
         else
         {
             Assert.Fail($"Wrong type Location type '{a.Location?.ExpressType.ExpressName}'");
         }
     }
     else
     {
         Assert.Fail($"Wrong type RelativePlacement type '{localPlacement.RelativePlacement?.ExpressType.ExpressName}'");
     }
 }
Example #3
0
 public IfOpening(IfOpening opening) : base(opening.IfModel)
 {
     IfWall         = opening.IfWall;
     OpeningType    = opening.OpeningType;
     Direction      = opening.Direction;
     IfcOpening     = opening.IfcOpening;
     LocalPlacement = opening.LocalPlacement;
     IfLocation     = new IfLocation(opening.IfLocation);
     IfDimension    = new IfDimension(opening.IfDimension);
 }
Example #4
0
        /// <summary>
        /// New product instance given by type parameter.
        /// </summary>
        /// <typeparam name="P">The product type</typeparam>
        /// <param name="placement">A placement</param>
        /// <param name="name">An optional name</param>
        /// <returns>New stored product</returns>
        public P NewProduct <P>(IIfcLocalPlacement placement = null, string name = null) where P : IIfcProduct
        {
            P product = default(P);

            Wrap(s =>
            {
                product                 = IfcProductScope.NewOf <P>();
                product.Name            = name;
                product.ObjectPlacement = placement;
                InitProduct(product);
            });
            return(product);
        }
Example #5
0
        /// <summary>
        /// New product instance given by type parameter.
        /// </summary>
        /// <param name="pName">A type label of the product instance</param>
        /// <param name="placement">A placement</param>
        /// <param name="name">An optional name</param>
        /// <returns>New stored product</returns>
        public IIfcProduct NewProduct(XName pName, IIfcLocalPlacement placement = null, string name = null)
        {
            IIfcProduct product = null;

            if (Store.SchemaVersion.ToString() != pName.NamespaceName)
            {
                throw new ArgumentException($"Wrong schema version of pName. Store is a {Store.SchemaVersion}");
            }

            Wrap(s =>
            {
                product                 = IfcProductScope.New(pName.LocalName);
                product.Name            = name;
                product.ObjectPlacement = placement;
                InitProduct(product);
            });
            return(product);
        }
Example #6
0
        /// <summary>
        /// Changes an existing local placement to be aligned to target axis.
        /// </summary>
        /// <param name="placement">A placement to be aligned</param>
        /// <param name="transform">The associated transform in model units</param>
        /// <returns>The given placement with (possible) additional axis components</returns>
        public IIfcLocalPlacement ChangeIfcLocalPlacement(IIfcLocalPlacement placement, XbimMatrix3D transform)
        {
            // Compute delta alignment
            var virtualParent = SourceReferenceAxis.TransformAxisTo(TargetReferenceAxis);
            // Multiply out with selected placement
            var unitsPerMeter  = placement.Model.ModelFactors.OneMeter;
            var finalAlignment = new IfcAlignReferenceAxis(transform * virtualParent.To3D(unitsPerMeter), unitsPerMeter);

            switch (placement.Model.SchemaVersion)
            {
            case Xbim.Common.Step21.XbimSchemaVersion.Ifc2X3:
                return((placement as Xbim.Ifc2x3.GeometricConstraintResource.IfcLocalPlacement).ChangeIfc2x3ObjectPlacementTo(finalAlignment, true));

            case Xbim.Common.Step21.XbimSchemaVersion.Ifc4:
            case Xbim.Common.Step21.XbimSchemaVersion.Ifc4x1:
                return((placement as Xbim.Ifc4.GeometricConstraintResource.IfcLocalPlacement).ChangeIfc4ObjectPlacementTo(finalAlignment, true));

            default:
                throw new ArgumentException($"Unhandled schema version {placement.Model.SchemaVersion}");
            }
        }
Example #7
0
        public IfcLocationData(string path)
        {
            using (IfcStore model = IfcStore.Open(path))
            {
                if (model.SchemaVersion == XbimSchemaVersion.Ifc2X3)
                {
                    Schema            = "Ifc 2x3";
                    SchemaIsSupported = true;
                }
                else if (model.SchemaVersion == XbimSchemaVersion.Ifc4)
                {
                    Schema            = "Ifc4";
                    SchemaIsSupported = false;
                    return;
                }
                else
                {
                    Schema            = model.SchemaVersion.ToString();
                    SchemaIsSupported = false;
                    return;
                }
                IIfcProject project             = model.Instances.FirstOrDefault <IIfcProject>();
                string      applicationFullname = project.OwnerHistory.OwningApplication.ApplicationFullName;
                if (applicationFullname == null)
                {
                    AuthoringTool = "N/A";
                }
                else
                {
                    AuthoringTool = project.OwnerHistory.OwningApplication.ApplicationFullName;
                }


                IIfcSIUnit lengtUnit = project.UnitsInContext.Units.FirstOrDefault <IIfcSIUnit>(q => q.UnitType == IfcUnitEnum.LENGTHUNIT);
                LengthUnit = lengtUnit.FullName;

                IIfcSite site = model.Instances.FirstOrDefault <IIfcSite>();
                if (site.RefElevation.HasValue)
                {
                    refElevation = site.RefElevation.Value;
                }
                else
                {
                    refElevation = double.NaN;
                }
                IIfcLocalPlacement   placement      = site.ObjectPlacement as IIfcLocalPlacement;
                IIfcAxis2Placement3D axis2Placement = placement.RelativePlacement as IIfcAxis2Placement3D;
                double x     = axis2Placement.RefDirection.DirectionRatios.GetAt(0);
                double y     = axis2Placement.RefDirection.DirectionRatios.GetAt(1);
                double angle = 360 - Math.Atan2(y, x) * 180 / Math.PI;
                if (angle.Equals(360))
                {
                    angle = 0;
                }
                Orientation = angle;

                EW        = axis2Placement.Location.Coordinates.GetAt(0);
                NS        = axis2Placement.Location.Coordinates.GetAt(1);
                elevation = axis2Placement.Location.Coordinates.GetAt(2);
            }
        }
Example #8
0
 public XbimPlacementNode(IIfcLocalPlacement placement)
 {
     PlacementLabel      = placement.EntityLabel;
     Matrix              = placement.RelativePlacement.ToMatrix3D();
     _isAdjustedToGlobal = false;
 }