Conversion methods between an IFC encoded GUID string and a .NET GUID. This is a translation of the C code found here: http://www.iai-tech.org/ifc/IFC2x3/TC1/html/index.htm
Пример #1
0
        /// <summary>
        /// convert navisworks coordinates to the ones used by BCF
        /// </summary>
        /// <param name="oVP"></param>
        /// <returns></returns>
        private XDocument generateViewpoint(Viewpoint oVP)
        {
            double units = GetGunits();

            Vector3D vi        = getViewDir(oVP);
            Vector3D up        = getViewUp(oVP);
            Point3D  c         = new Point3D(oVP.Position.X / units, oVP.Position.Y / units, oVP.Position.Z / units);
            string   type      = "";
            string   zoom      = "";
            double   zoomValue = 1;

            oVP = oVP.CreateCopy();
            if (!oVP.HasFocalDistance)
            {
                oVP.FocalDistance = 1;
            }


            if (oVP.Projection == ViewpointProjection.Orthographic) //IS ORTHO
            {
                type = "OrthogonalCamera";
                zoom = "ViewToWorldScale";
                // zoomValue = oVP.VerticalExtentAtFocalDistance / 2 / _ftConversion;

                double dist = oVP.VerticalExtentAtFocalDistance / 2 / units;
                zoomValue = 3.125 * dist / up.Length;
            }
            else // it is a perspective view
            {
                type      = "PerspectiveCamera";
                zoom      = "FieldOfView";
                zoomValue = oVP.FocalDistance;
            }

            XDocument v = new XDocument(
                new XElement("VisualizationInfo",
                             new XElement("Components"),
                             new XElement(type,
                                          new XElement("CameraViewPoint",
                                                       new XElement("X", c.X.ToString(CultureInfo.InvariantCulture)),
                                                       new XElement("Y", c.Y.ToString(CultureInfo.InvariantCulture)),
                                                       new XElement("Z", c.Z.ToString(CultureInfo.InvariantCulture))),
                                          new XElement("CameraDirection",
                                                       new XElement("X", vi.X.ToString(CultureInfo.InvariantCulture)),
                                                       new XElement("Y", vi.Y.ToString(CultureInfo.InvariantCulture)),
                                                       new XElement("Z", vi.Z.ToString(CultureInfo.InvariantCulture))),
                                          new XElement("CameraUpVector",
                                                       new XElement("X", up.X.ToString(CultureInfo.InvariantCulture)),
                                                       new XElement("Y", up.Y.ToString(CultureInfo.InvariantCulture)),
                                                       new XElement("Z", up.Z.ToString(CultureInfo.InvariantCulture))),
                                          new XElement(zoom, zoomValue.ToString(CultureInfo.InvariantCulture)))));

            try
            {
                //COMPONENTS PART
                if (_elemCheck == 0)//visible (0)
                {
                    elementList = oDoc.Models.First.RootItem.DescendantsAndSelf.Where(o => o.InstanceGuid != Guid.Empty && ChechHidden(o.AncestorsAndSelf) && o.FindFirstGeometry() != null && !o.FindFirstGeometry().Item.IsHidden).ToList <ModelItem>();
                }

                if (null != elementList && elementList.Any() && _elemCheck != 2) //not if none (2)
                {
                    string appname = Autodesk.Navisworks.Api.Application.Title;
                    for (var i = 0; i < elementList.Count(); i++)
                    {
                        string ifcguid = IfcGuid.ToIfcGuid(elementList.ElementAt(i).InstanceGuid).ToString();
                        v.Element("VisualizationInfo").Element("Components").Add(
                            new XElement("Component", new XAttribute("IfcGuid", ifcguid),
                                         new XElement("OriginatingSystem", appname),
                                         new XElement("AuthoringToolId", "")));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return(v);
        }