CASE.Navis2BCF.IfcGuid.ToIfcGuid C# (CSharp) Метод

ToIfcGuid() публичный статический Метод

Conversion of a GUID to a string representing the GUID
public static ToIfcGuid ( System.Guid guid ) : string
guid System.Guid The GUID to convert
Результат string
        public static string ToIfcGuid( Guid guid )
        {
            uint[] num = new uint[6];
              char[] str = new char[22];
              int i, n;
              byte[] b = guid.ToByteArray();

              // Creation of six 32 Bit integers from the components of the GUID structure
              num[0] = ( uint ) ( BitConverter.ToUInt32( b, 0 ) / 16777216 );
              num[1] = ( uint ) ( BitConverter.ToUInt32( b, 0 ) % 16777216 );
              num[2] = ( uint ) ( BitConverter.ToUInt16( b, 4 ) * 256 + BitConverter.ToInt16( b, 6 ) / 256 );
              num[3] = ( uint ) ( ( BitConverter.ToUInt16( b, 6 ) % 256 ) * 65536 + b[8] * 256 + b[9] );
              num[4] = ( uint ) ( b[10] * 65536 + b[11] * 256 + b[12] );
              num[5] = ( uint ) ( b[13] * 65536 + b[14] * 256 + b[15] );

              // Conversion of the numbers into a system using a base of 64
              n = 2;
              int pos = 0;
              for( i = 0; i < 6; i++ )
              {
            cv_to_64( num[i], ref str, pos, n );
            pos += n; n = 4;
              }
              return new String( str );
        }

Usage Example

Пример #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);
        }