CASE.Navis2BCF.Navis2JiraWin.generateViewpoint C# (CSharp) Метод

generateViewpoint() приватный Метод

convert navisworks coordinates to the ones used by BCF
private generateViewpoint ( Viewpoint oVP ) : System.Xml.Linq.XDocument
oVP Viewpoint
Результат System.Xml.Linq.XDocument
        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;
        }