コード例 #1
0
ファイル: IFCSite.cs プロジェクト: whztt07/RevitIFC
        /// <summary>
        /// Creates or populates Revit elements based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        protected override void Create(Document doc)
        {
            // Only set the project location for the site that contains the building.
            bool hasBuilding = false;

            foreach (IFCObjectDefinition objectDefinition in ComposedObjectDefinitions)
            {
                if (objectDefinition is IFCBuilding)
                {
                    hasBuilding = true;
                    break;
                }
            }

            if (hasBuilding)
            {
                ProjectLocation projectLocation = doc.ActiveProjectLocation;
                if (projectLocation != null)
                {
                    SiteLocation siteLocation = projectLocation.SiteLocation;
                    if (siteLocation != null)
                    {
                        if (RefLatitude.HasValue)
                        {
                            siteLocation.Latitude = RefLatitude.Value * Math.PI / 180.0;
                        }
                        if (RefLongitude.HasValue)
                        {
                            siteLocation.Longitude = RefLongitude.Value * Math.PI / 180.0;
                        }
                    }

                    if (ObjectLocation != null)
                    {
                        XYZ projectLoc = (ObjectLocation.RelativeTransform != null) ? ObjectLocation.RelativeTransform.Origin : XYZ.Zero;

                        // Get true north from IFCProject.
                        double         trueNorth     = 0.0;
                        IList <double> trueNorthList = IFCImportFile.TheFile.IFCProject.TrueNorthDirection;
                        if (trueNorthList != null && trueNorthList.Count >= 2)
                        {
                            trueNorth = Math.Atan2(trueNorthList[1], trueNorthList[0]);
                        }

                        ProjectPosition projectPosition = new ProjectPosition(projectLoc.X, projectLoc.Y, RefElevation, trueNorth);

                        XYZ origin = new XYZ(0, 0, 0);
                        projectLocation.set_ProjectPosition(origin, projectPosition);

                        // Now that we've set the project position, remove the site relative transform.
                        IFCLocation.RemoveRelativeTransformForSite(this);
                    }
                }
            }

            base.Create(doc);
        }
コード例 #2
0
        /// <summary>
        /// Creates or populates Revit elements based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        protected override void Create(Document doc)
        {
            // Only set the project location for the site that contains the building.
            bool hasBuilding = false;

            foreach (IFCObjectDefinition objectDefinition in ComposedObjectDefinitions)
            {
                if (objectDefinition is IFCBuilding)
                {
                    hasBuilding = true;
                    break;
                }
            }

            if (hasBuilding)
            {
                ProjectLocation projectLocation = doc.ActiveProjectLocation;
                if (projectLocation != null)
                {
                    SiteLocation siteLocation = projectLocation.GetSiteLocation();
                    if (siteLocation != null)
                    {
                        // Some Tekla files may have invalid information here that would otherwise cause the
                        // link to fail.  Recover with a warning.
                        try
                        {
                            if (RefLatitude.HasValue)
                            {
                                siteLocation.Latitude = RefLatitude.Value * Math.PI / 180.0;
                            }
                            if (RefLongitude.HasValue)
                            {
                                siteLocation.Longitude = RefLongitude.Value * Math.PI / 180.0;
                            }
                        }
                        catch (Exception ex)
                        {
                            Importer.TheLog.LogWarning(Id, "Invalid latitude or longitude value supplied for IFCSITE: " + ex.Message, false);
                        }
                    }

                    if (ObjectLocation != null)
                    {
                        XYZ projectLoc = (ObjectLocation.RelativeTransform != null) ? ObjectLocation.RelativeTransform.Origin : XYZ.Zero;
                        if (!MathUtil.IsAlmostZero(projectLoc.Z))
                        {
                            Importer.TheLog.LogError(Id, "The Z-value of the IfcSite object placement relative transform should be 0.  This will be ignored in favor of the RefElevation value.", false);
                        }

                        // Get true north from IFCProject.
                        double trueNorth   = 0.0;
                        UV     trueNorthUV = IFCImportFile.TheFile.IFCProject.TrueNorthDirection;
                        if (trueNorthUV != null)
                        {
                            double geometricAngle = Math.Atan2(trueNorthUV.V, trueNorthUV.U);
                            // Convert from geometric angle to compass direction.
                            // This involves two steps: (1) subtract PI/2 from the angle, staying in (-PI, PI], then (2) reversing the result.
                            trueNorth = (geometricAngle > -Math.PI / 2.0) ? geometricAngle - Math.PI / 2.0 : geometricAngle + Math.PI * 1.5;
                            trueNorth = -trueNorth;
                        }

                        ProjectPosition projectPosition = new ProjectPosition(projectLoc.X, projectLoc.Y, RefElevation, trueNorth);

                        projectLocation.SetProjectPosition(XYZ.Zero, projectPosition);

                        // Now that we've set the project position, remove the site relative transform, if the file is created correctly (that is, all entities contained in the site
                        // have the local placements relative to the site.
                        IFCLocation.RemoveRelativeTransformForSite(this);
                    }
                }
            }

            base.Create(doc);

            if (hasBuilding)
            {
                // There should only be one IfcSite in the file, but in case there are multiple, we want to make sure that the one
                // containing the IfcBuilding has its parameters stored somewhere.
                // In the case where we didn't create an element above, use the ProjectInfo element in the document to store its parameters.
                if (CreatedElementId == ElementId.InvalidElementId)
                {
                    CreatedElementId = Importer.TheCache.ProjectInformationId;
                }
            }
        }
コード例 #3
0
ファイル: IFCSite.cs プロジェクト: arif-hanif/IFC-For-Revit
        /// <summary>
        /// Creates or populates Revit elements based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        protected override void Create(Document doc)
        {
            // Only set the project location for the site that contains the building.
            bool hasBuilding = false;

            foreach (IFCObjectDefinition objectDefinition in ComposedObjectDefinitions)
            {
                if (objectDefinition is IFCBuilding)
                {
                    hasBuilding = true;
                    break;
                }
            }

            if (hasBuilding)
            {
                ProjectLocation projectLocation = doc.ActiveProjectLocation;
                if (projectLocation != null)
                {
                    SiteLocation siteLocation = projectLocation.SiteLocation;
                    if (siteLocation != null)
                    {
                        if (RefLatitude.HasValue)
                        {
                            siteLocation.Latitude = RefLatitude.Value * Math.PI / 180.0;
                        }
                        if (RefLongitude.HasValue)
                        {
                            siteLocation.Longitude = RefLongitude.Value * Math.PI / 180.0;
                        }
                    }

                    if (ObjectLocation != null)
                    {
                        XYZ projectLoc = (ObjectLocation.RelativeTransform != null) ? ObjectLocation.RelativeTransform.Origin : XYZ.Zero;

                        // Get true north from IFCProject.
                        double         trueNorth     = 0.0;
                        IList <double> trueNorthList = IFCImportFile.TheFile.IFCProject.TrueNorthDirection;
                        if (trueNorthList != null && trueNorthList.Count >= 2)
                        {
                            double geometricAngle = Math.Atan2(trueNorthList[1], trueNorthList[0]);
                            // Convert from geometric angle to compass direction.
                            // This involves two steps: (1) subtract PI/2 from the angle, staying in (-PI, PI], then (2) reversing the result.
                            trueNorth = (geometricAngle > -Math.PI / 2.0) ? geometricAngle - Math.PI / 2.0 : geometricAngle + Math.PI * 1.5;
                            trueNorth = -trueNorth;
                        }

                        ProjectPosition projectPosition = new ProjectPosition(projectLoc.X, projectLoc.Y, RefElevation, trueNorth);

                        XYZ origin = new XYZ(0, 0, 0);
                        projectLocation.set_ProjectPosition(origin, projectPosition);

                        // Now that we've set the project position, remove the site relative transform.
                        IFCLocation.RemoveRelativeTransformForSite(this);
                    }
                }
            }

            base.Create(doc);

            if (hasBuilding)
            {
                // There should only be one IfcSite in the file, but in case there are multiple, we want to make sure that the one
                // containing the IfcBuilding has its parameters stored somewhere.
                // In the case where we didn't create an element above, use the ProjectInfo element in the document to store its parameters.
                if (CreatedElementId == ElementId.InvalidElementId)
                {
                    CreatedElementId = Importer.TheCache.ProjectInformationId;
                }
            }
        }