Beispiel #1
0
        public IssueBCF()
        {
            guid = Guid.NewGuid();
            markup = new Markup();
            markup.Topic = new Topic();
            markup.Topic.Guid = guid.ToString();
            markup.Comment = new ObservableCollection<CommentBCF>();
            markup.Header = new HeaderFile[1];
            markup.Header[0] = new HeaderFile();
            markup.Header[0].Date = new DateTime();
            markup.Header[0].DateSpecified = true;

            viewpoint = new VisualizationInfo();
        }
        public IssueBCF()
        {
            guid                           = Guid.NewGuid();
            markup                         = new Markup();
            markup.Topic                   = new Topic();
            markup.Topic.Guid              = guid.ToString();
            markup.Comment                 = new ObservableCollection <CommentBCF>();
            markup.Header                  = new HeaderFile[1];
            markup.Header[0]               = new HeaderFile();
            markup.Header[0].Date          = new DateTime();
            markup.Header[0].DateSpecified = true;



            viewpoint = new VisualizationInfo();
        }
        /// <summary>
        /// returns XYZ and ZOOM/FOV value
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="viewport"></param>
        /// <returns></returns>
        public Tuple<ViewOrientation3D, double, string, string> GetViewCoordinates(Document doc, VisualizationInfo viewport)
        {
            string type = ""; //change if i force ortho mode
              double zoom = 0; //fov or worldscale

              XYZ CameraDirection = new XYZ();
              XYZ CameraUpVector = new XYZ();
              XYZ CameraViewPoint = new XYZ();
              //retrive the force perspective value

              // IS ORTHOGONAL
              if (viewport.OrthogonalCamera != null)
              {
            if (viewport.OrthogonalCamera.CameraViewPoint == null || viewport.OrthogonalCamera.CameraUpVector == null || viewport.OrthogonalCamera.CameraDirection == null)
              return null;
            type = "OrthogonalCamera";
            zoom = UnitUtils.ConvertToInternalUnits(viewport.OrthogonalCamera.ViewToWorldScale, DisplayUnitType.DUT_METERS);
            CameraDirection = GetXYZ(viewport.OrthogonalCamera.CameraDirection.X, viewport.OrthogonalCamera.CameraDirection.Y, viewport.OrthogonalCamera.CameraDirection.Z);
            CameraUpVector = GetXYZ(viewport.OrthogonalCamera.CameraUpVector.X, viewport.OrthogonalCamera.CameraUpVector.Y, viewport.OrthogonalCamera.CameraUpVector.Z);
            CameraViewPoint = GetXYZ(viewport.OrthogonalCamera.CameraViewPoint.X, viewport.OrthogonalCamera.CameraViewPoint.Y, viewport.OrthogonalCamera.CameraViewPoint.Z);

              }

              else if (viewport.PerspectiveCamera != null)
              {
            if (viewport.PerspectiveCamera.CameraViewPoint == null || viewport.PerspectiveCamera.CameraUpVector == null || viewport.PerspectiveCamera.CameraDirection == null)
              return null;

            type = "PerspectiveCamera";
            zoom = viewport.PerspectiveCamera.FieldOfView;
            double z1 = 18 / Math.Tan(zoom / 2 * Math.PI / 180);//focale 1
            double z = 18 / Math.Tan(25 / 2 * Math.PI / 180);//focale, da controllare il 18, vedi PDF
            double factor = z1 - z;

            CameraDirection = GetXYZ(viewport.PerspectiveCamera.CameraDirection.X, viewport.PerspectiveCamera.CameraDirection.Y, viewport.PerspectiveCamera.CameraDirection.Z);
            CameraUpVector = GetXYZ(viewport.PerspectiveCamera.CameraUpVector.X, viewport.PerspectiveCamera.CameraUpVector.Y, viewport.PerspectiveCamera.CameraUpVector.Z);
            XYZ oldO = GetXYZ(viewport.PerspectiveCamera.CameraViewPoint.X, viewport.PerspectiveCamera.CameraViewPoint.Y, viewport.PerspectiveCamera.CameraViewPoint.Z);
            CameraViewPoint = (oldO.Subtract(CameraDirection.Divide(factor)));
              }
              else
            return null;
              // CHAGE VALUES ACCORDING TO BASEPOINT
              //THIS WAS the one with DOC
              ViewOrientation3D orient3d = ConvertBasePoint(CameraViewPoint, CameraDirection, CameraUpVector, true);

              return new Tuple<ViewOrientation3D, double, string, string>(orient3d, zoom, type, "New View");
        }
        public Tuple<Point3D, Vector3D, Vector3D, Autodesk.Navisworks.Api.ViewpointProjection, double> GetViewCoordinates(VisualizationInfo viewport)
        {
            try
              {
            double units = GetGunits();

            Point3D Position = new Point3D();
            Vector3D VectorUp = new Vector3D();
            Vector3D VectorTo = new Vector3D();
            ViewpointProjection vp = ViewpointProjection.Perspective;
            double zoom = 0;
            if (viewport.OrthogonalCamera != null)
            {
              if (viewport.OrthogonalCamera.CameraViewPoint == null || viewport.OrthogonalCamera.CameraUpVector == null || viewport.OrthogonalCamera.CameraDirection == null)
            return null;

              vp = ViewpointProjection.Orthographic;
              zoom = units * viewport.OrthogonalCamera.ViewToWorldScale;
              Position = GetXYZ(viewport.OrthogonalCamera.CameraViewPoint.X, viewport.OrthogonalCamera.CameraViewPoint.Y, viewport.OrthogonalCamera.CameraViewPoint.Z);
              VectorUp = GetXYZ(viewport.OrthogonalCamera.CameraUpVector.X, viewport.OrthogonalCamera.CameraUpVector.Y, viewport.OrthogonalCamera.CameraUpVector.Z).ToVector3D().Normalize();
              VectorTo = GetXYZ(viewport.OrthogonalCamera.CameraDirection.X, viewport.OrthogonalCamera.CameraDirection.Y, viewport.OrthogonalCamera.CameraDirection.Z).ToVector3D().Normalize();
            }
            else if (viewport.PerspectiveCamera != null)
            {
              if (viewport.PerspectiveCamera.CameraViewPoint == null || viewport.PerspectiveCamera.CameraUpVector == null || viewport.PerspectiveCamera.CameraDirection == null)
            return null;

              zoom = viewport.PerspectiveCamera.FieldOfView;
              Position = GetXYZ(viewport.PerspectiveCamera.CameraViewPoint.X, viewport.PerspectiveCamera.CameraViewPoint.Y, viewport.PerspectiveCamera.CameraViewPoint.Z);
              VectorUp = GetXYZ(viewport.PerspectiveCamera.CameraUpVector.X, viewport.PerspectiveCamera.CameraUpVector.Y, viewport.PerspectiveCamera.CameraUpVector.Z).ToVector3D().Normalize();
              VectorTo = GetXYZ(viewport.PerspectiveCamera.CameraDirection.X, viewport.PerspectiveCamera.CameraDirection.Y, viewport.PerspectiveCamera.CameraDirection.Z).ToVector3D().Normalize();

            }
            else
              return null;

            return new Tuple<Point3D, Vector3D, Vector3D, ViewpointProjection, double>(Position, VectorUp, VectorTo, vp, zoom);
              }
              catch (Exception ex)
              {
            MessageBox.Show(ex.ToString());
              }
              return null;
        }
Beispiel #5
0
        /// <summary>
        /// Load from BCF 2.0 as BCF 1.0
        /// </summary>
        /// <param name="bcf2">BCF 2.0 file</param>
        /// <returns></returns>
        public static IssueBCF LoadBcf1IssueFromBcf2(BCF2.Markup bcf2Markup, BCF2.VisualizationInfo bcf2Viewpoint)
        {
            // Convert headers
            List <HeaderFile> bcf1Headers = new List <HeaderFile>();

            foreach (BCF2.HeaderFile bcf2Header in bcf2Markup.Header)
            {
                HeaderFile bcf1Header = new HeaderFile()
                {
                    Filename   = bcf2Header.Filename,
                    Date       = bcf2Header.Date,
                    IfcProject = bcf2Header.IfcProject,
                    IfcSpatialStructureElement = bcf2Header.IfcSpatialStructureElement
                };
                bcf1Headers.Add(bcf1Header);
            }

            // Convert topic
            Topic bcf1Topic = new Topic();

            if (bcf2Markup.Topic != null)
            {
                bcf1Topic.Guid          = bcf2Markup.Topic.Guid;
                bcf1Topic.ReferenceLink = bcf2Markup.Topic.ReferenceLink;
                bcf1Topic.Title         = bcf2Markup.Topic.Title;
            }
            ;

            // Convert comments
            ObservableCollection <CommentBCF> bcf1Comments = new ObservableCollection <CommentBCF>();

            foreach (BCF2.Comment bcf2Comment in bcf2Markup.Comment)
            {
                CommentBCF bcf1Comment = new CommentBCF()
                {
                    Author   = bcf2Comment.Author,
                    Comment1 = bcf2Comment.Comment1,
                    Date     = bcf2Comment.Date,
                    Guid     = bcf2Comment.Guid,
                    Status   = CommentStatus.Unknown,  // default unknown for now
                    Topic    = new CommentTopic()
                    {
                        Guid = bcf2Markup.Topic == null?Guid.NewGuid().ToString() : bcf2Markup.Topic.Guid
                    },
                    VerbalStatus = bcf2Comment.VerbalStatus
                };
                bcf1Comments.Add(bcf1Comment);
            }

            // Convert markups/issues
            Markup bcf1Markup = new Markup()
            {
                Header  = bcf1Headers.ToArray(),
                Topic   = bcf1Topic,
                Comment = bcf1Comments
            };

            // Convert ClippingPlane
            List <ClippingPlane> bcf1ClippingPlanes = new List <ClippingPlane>();

            if (bcf2Viewpoint.ClippingPlanes != null)
            {
                foreach (BCF2.ClippingPlane bcf2ClippingPlane in bcf2Viewpoint.ClippingPlanes)
                {
                    if (bcf2ClippingPlane != null)
                    {
                        bcf1ClippingPlanes.Add(new ClippingPlane()
                        {
                            Direction = new Direction()
                            {
                                X = bcf2ClippingPlane.Direction.X,
                                Y = bcf2ClippingPlane.Direction.Y,
                                Z = bcf2ClippingPlane.Direction.Z
                            },
                            Location = new Point()
                            {
                                X = bcf2ClippingPlane.Location.X,
                                Y = bcf2ClippingPlane.Location.Y,
                                Z = bcf2ClippingPlane.Location.Z
                            }
                        });
                    }
                }
            }

            // Convert Components
            List <Component> bcf1Components = new List <Component>();

            if (bcf2Viewpoint.Components != null)
            {
                foreach (BCF2.Component bcf2Component in bcf2Viewpoint.Components)
                {
                    if (bcf2Component != null)
                    {
                        bcf1Components.Add(new Component()
                        {
                            AuthoringToolId   = bcf2Component.AuthoringToolId,
                            IfcGuid           = bcf2Component.IfcGuid,
                            OriginatingSystem = bcf2Component.OriginatingSystem
                        });
                    }
                }
            }

            // Convert Lines
            List <Line> bcf1Lines = new List <Line>();

            if (bcf2Viewpoint.Lines != null)
            {
                foreach (BCF2.Line bcf2Line in bcf2Viewpoint.Lines)
                {
                    if (bcf2Line != null)
                    {
                        bcf1Lines.Add(new Line()
                        {
                            StartPoint = new Point()
                            {
                                X = bcf2Line.StartPoint.X,
                                Y = bcf2Line.StartPoint.Y,
                                Z = bcf2Line.StartPoint.Z
                            },
                            EndPoint = new Point()
                            {
                                X = bcf2Line.EndPoint.X,
                                Y = bcf2Line.EndPoint.Y,
                                Z = bcf2Line.EndPoint.Z
                            }
                        });
                    }
                }
            }

            // Convert viewpoints
            VisualizationInfo bcf1Viewpoint = new VisualizationInfo()
            {
                ClippingPlanes   = bcf1ClippingPlanes.ToArray(),
                Components       = bcf1Components.ToArray(),
                Lines            = bcf1Lines.ToArray(),
                OrthogonalCamera = bcf2Viewpoint.OrthogonalCamera == null ? null : new OrthogonalCamera()
                {
                    CameraDirection = new Direction()
                    {
                        X = bcf2Viewpoint.OrthogonalCamera.CameraDirection.X,
                        Y = bcf2Viewpoint.OrthogonalCamera.CameraDirection.Y,
                        Z = bcf2Viewpoint.OrthogonalCamera.CameraDirection.Z
                    },
                    CameraUpVector = new Direction()
                    {
                        X = bcf2Viewpoint.OrthogonalCamera.CameraUpVector.X,
                        Y = bcf2Viewpoint.OrthogonalCamera.CameraUpVector.Y,
                        Z = bcf2Viewpoint.OrthogonalCamera.CameraUpVector.Z
                    },
                    CameraViewPoint = new Point()
                    {
                        X = bcf2Viewpoint.OrthogonalCamera.CameraViewPoint.X,
                        Y = bcf2Viewpoint.OrthogonalCamera.CameraViewPoint.Y,
                        Z = bcf2Viewpoint.OrthogonalCamera.CameraViewPoint.Z
                    },
                    ViewToWorldScale = bcf2Viewpoint.OrthogonalCamera.ViewToWorldScale
                },
                PerspectiveCamera = bcf2Viewpoint.PerspectiveCamera == null ? null : new PerspectiveCamera()
                {
                    CameraDirection = new Direction()
                    {
                        X = bcf2Viewpoint.PerspectiveCamera.CameraDirection.X,
                        Y = bcf2Viewpoint.PerspectiveCamera.CameraDirection.Y,
                        Z = bcf2Viewpoint.PerspectiveCamera.CameraDirection.Z
                    },
                    CameraUpVector = new Direction()
                    {
                        X = bcf2Viewpoint.PerspectiveCamera.CameraUpVector.X,
                        Y = bcf2Viewpoint.PerspectiveCamera.CameraUpVector.Y,
                        Z = bcf2Viewpoint.PerspectiveCamera.CameraUpVector.Z
                    },
                    CameraViewPoint = new Point()
                    {
                        X = bcf2Viewpoint.PerspectiveCamera.CameraViewPoint.X,
                        Y = bcf2Viewpoint.PerspectiveCamera.CameraViewPoint.Y,
                        Z = bcf2Viewpoint.PerspectiveCamera.CameraViewPoint.Z
                    },
                    FieldOfView = bcf2Viewpoint.PerspectiveCamera.FieldOfView
                },
                SheetCamera = bcf2Viewpoint.SheetCamera == null ? null : new SheetCamera()
                {
                    SheetID = bcf2Viewpoint.SheetCamera.SheetID,
                    TopLeft = new Point()
                    {
                        X = bcf2Viewpoint.SheetCamera.TopLeft.X,
                        Y = bcf2Viewpoint.SheetCamera.TopLeft.Y,
                        Z = bcf2Viewpoint.SheetCamera.TopLeft.Z
                    },
                    BottomRight = new Point()
                    {
                        X = bcf2Viewpoint.SheetCamera.BottomRight.X,
                        Y = bcf2Viewpoint.SheetCamera.BottomRight.Y,
                        Z = bcf2Viewpoint.SheetCamera.BottomRight.Z
                    }
                }
            };

            // Create a new BCF 1.0 issue
            IssueBCF bcf1 = new IssueBCF()
            {
                markup    = bcf1Markup,
                viewpoint = bcf1Viewpoint
            };

            return(bcf1);
        }
        /// <summary>
        /// Generate Viewpoint
        /// </summary>
        /// <param name="elemCheck"></param>
        /// <returns></returns>
        private VisualizationInfo generateViewpoint(int elemCheck)
        {
            try
              {
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document doc = uidoc.Document;

            VisualizationInfo v = new VisualizationInfo();

            XYZ centerIMP = new XYZ();
            string type = "";
            double zoomValue = 1;

            if (uidoc.ActiveView.ViewType != ViewType.ThreeD) //is a 2D view
            {
              XYZ TL = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0];
              XYZ BR = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1];
              v.SheetCamera = new SheetCamera();
              v.SheetCamera.SheetID = uidoc.ActiveView.Id.IntegerValue;
              v.SheetCamera.TopLeft = new IssueTracker.Data.Point(TL.X, TL.Y, TL.Z);
              v.SheetCamera.BottomRight = new IssueTracker.Data.Point(BR.X, BR.Y, BR.Z);
            }
            else
            {
              View3D view3D = (View3D)uidoc.ActiveView;
              if (!view3D.IsPerspective) //IS ORTHO
              {
            XYZ TL = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0];
            XYZ BR = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1];

            double xO = (TL.X + BR.X) / 2;
            double yO = (TL.Y + BR.Y) / 2;
            double zO = (TL.Z + BR.Z) / 2;
            //converto to METERS
            centerIMP = new XYZ(xO, yO, zO);
            double dist = TL.DistanceTo(BR) / 2; //custom value to get solibri zoom value from Corners of Revit UiView
            XYZ diagVector = TL.Subtract(BR);
            double customZoomValue = (ProjectSettings.Get("useDefaultZoom", doc.PathName) == "1") ? 1 : 2.5;

            zoomValue = UnitUtils.ConvertFromInternalUnits(dist * Math.Sin(diagVector.AngleTo(view3D.RightDirection)), DisplayUnitType.DUT_METERS) * customZoomValue;
            type = "OrthogonalCamera";
              }
              else // it is a perspective view
              {
            centerIMP = uidoc.ActiveView.Origin;
            type = "PerspectiveCamera";
            zoomValue = 45;
              }
              ViewOrientation3D t = ConvertBasePoint(centerIMP, uidoc.ActiveView.ViewDirection, uidoc.ActiveView.UpDirection, false);
              XYZ c = t.EyePosition;
              XYZ vi = t.ForwardDirection;
              XYZ up = t.UpDirection;

              if (type == "OrthogonalCamera")
              {
            v.OrthogonalCamera = new OrthogonalCamera();
            v.OrthogonalCamera.CameraViewPoint.X = UnitUtils.ConvertFromInternalUnits(c.X, DisplayUnitType.DUT_METERS);
            v.OrthogonalCamera.CameraViewPoint.Y = UnitUtils.ConvertFromInternalUnits(c.Y, DisplayUnitType.DUT_METERS);
            v.OrthogonalCamera.CameraViewPoint.Z = UnitUtils.ConvertFromInternalUnits(c.Z, DisplayUnitType.DUT_METERS);
            v.OrthogonalCamera.CameraUpVector.X = UnitUtils.ConvertFromInternalUnits(up.X, DisplayUnitType.DUT_METERS);
            v.OrthogonalCamera.CameraUpVector.Y = UnitUtils.ConvertFromInternalUnits(up.Y, DisplayUnitType.DUT_METERS);
            v.OrthogonalCamera.CameraUpVector.Z = UnitUtils.ConvertFromInternalUnits(up.Z, DisplayUnitType.DUT_METERS);
            v.OrthogonalCamera.CameraDirection.X = UnitUtils.ConvertFromInternalUnits(vi.X, DisplayUnitType.DUT_METERS) * -1;
            v.OrthogonalCamera.CameraDirection.Y = UnitUtils.ConvertFromInternalUnits(vi.Y, DisplayUnitType.DUT_METERS) * -1;
            v.OrthogonalCamera.CameraDirection.Z = UnitUtils.ConvertFromInternalUnits(vi.Z, DisplayUnitType.DUT_METERS) * -1;
            v.OrthogonalCamera.ViewToWorldScale = zoomValue;
              }
              else
              {
            v.PerspectiveCamera = new PerspectiveCamera();
            v.PerspectiveCamera.CameraViewPoint.X = UnitUtils.ConvertFromInternalUnits(c.X, DisplayUnitType.DUT_METERS);
            v.PerspectiveCamera.CameraViewPoint.Y = UnitUtils.ConvertFromInternalUnits(c.Y, DisplayUnitType.DUT_METERS);
            v.PerspectiveCamera.CameraViewPoint.Z = UnitUtils.ConvertFromInternalUnits(c.Z, DisplayUnitType.DUT_METERS);
            v.PerspectiveCamera.CameraUpVector.X = UnitUtils.ConvertFromInternalUnits(up.X, DisplayUnitType.DUT_METERS);
            v.PerspectiveCamera.CameraUpVector.Y = UnitUtils.ConvertFromInternalUnits(up.Y, DisplayUnitType.DUT_METERS);
            v.PerspectiveCamera.CameraUpVector.Z = UnitUtils.ConvertFromInternalUnits(up.Z, DisplayUnitType.DUT_METERS);
            v.PerspectiveCamera.CameraDirection.X = UnitUtils.ConvertFromInternalUnits(vi.X, DisplayUnitType.DUT_METERS) * -1;
            v.PerspectiveCamera.CameraDirection.Y = UnitUtils.ConvertFromInternalUnits(vi.Y, DisplayUnitType.DUT_METERS) * -1;
            v.PerspectiveCamera.CameraDirection.Z = UnitUtils.ConvertFromInternalUnits(vi.Z, DisplayUnitType.DUT_METERS) * -1;
            v.PerspectiveCamera.FieldOfView = zoomValue;
              }
            }

            //COMPONENTS PART
            FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id).WhereElementIsNotElementType();
            System.Collections.Generic.ICollection<ElementId> collection = null;

            if (elemCheck == 0)
              collection = collector.ToElementIds();
            else if (elemCheck == 1)
              collection = uidoc.Selection.GetElementIds();

            if (null != collection && collection.Any())
            {
              v.Components = new IssueTracker.Data.Component[collection.Count];
              for (var i = 0; i < collection.Count; i++)
              {
            Guid guid = ExportUtils.GetExportId(doc, collection.ElementAt(i));
            string ifcguid = IfcGuid.ToIfcGuid(guid).ToString();
            ;
            v.Components[i] = new Case.IssueTracker.Data.Component(doc.Application.VersionName, collection.ElementAt(i).ToString(), ifcguid);

              }
            }

            return v;

              }
              catch (System.Exception ex1)
              {
            TaskDialog.Show("Error!", "exception: " + ex1);
              }
              return null;
        }
        /// <summary>
        /// Open a 3D View
        /// </summary>
        /// <param name="v"></param>
        private void doOpen3DView(VisualizationInfo v)
        {
            try
              {
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document doc = uidoc.Document;

            if (uidoc.ActiveView.ViewType == ViewType.ThreeD)
            {
              View3D view3D = (View3D)uidoc.ActiveView;
              if (view3D.IsPerspective) //ORTHO
              {
            MessageBox.Show("This operation is not allowed in a Perspective View.\nPlease close the current window(s) and retry.",
                "Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
            return;
              }

            }
            m_Handler.v = v;

            m_ExEvent.Raise();
              }
              catch (System.Exception ex1)
              {
            TaskDialog.Show("Error!", "exception: " + ex1);
              }
        }
        private void Open3DView(VisualizationInfo v)
        {
            try
              {
            //    {
            //
            Tuple<Point3D, Vector3D, Vector3D, ViewpointProjection, double> tuple = GetViewCoordinates(v);

            if (tuple == null)
            {
              MessageBox.Show("Viewpoint not formatted correctly.", "Viewpoint Error", MessageBoxButton.OK, MessageBoxImage.Error);
              return;
            }

            Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;

            // get current viewpoint
            Viewpoint oCopyVP = new Viewpoint();

            oCopyVP.AlignDirection(tuple.Item3);
            oCopyVP.AlignUp(tuple.Item2);
            oCopyVP.Projection = tuple.Item4;

            const double TEKLA = 1.25;

            double x = tuple.Item5 / TEKLA;

            if (oCopyVP.Projection == ViewpointProjection.Orthographic)
            {

              oCopyVP.Position = tuple.Item1;
              oCopyVP.FocalDistance = 1;
              //top center point of view
              Point3D xyzTL = oCopyVP.Position.Add(tuple.Item2.Multiply(x));
              oCopyVP.SetExtentsAtFocalDistance(1, xyzTL.DistanceTo(oCopyVP.Position));
            }
            else
            {
              oCopyVP.FocalDistance = tuple.Item5;
              oCopyVP.Position = tuple.Item1;
            }

            oDoc.CurrentViewpoint.CopyFrom(oCopyVP);

            if (v.Components != null && v.Components.Any())
            {
              List<ModelItem> attachedElems = new List<ModelItem>();

              List<ModelItem> elems = oDoc.Models.First.RootItem.DescendantsAndSelf.ToList<ModelItem>();

              foreach (var item in elems.Where(o => o.InstanceGuid != Guid.Empty))
              {
            string ifcguid = IfcGuid.ToIfcGuid(item.InstanceGuid).ToString();
            if (v.Components.Any(o => o.IfcGuid == ifcguid))
              attachedElems.Add(item);

              }
              if (attachedElems.Any())//avoid to hide everything if no elements matches
              {
            if (UserSettings.Get("selattachedelems") == "0")
            {
              List<ModelItem> elemsVisible = new List<ModelItem>();
              foreach (var item in attachedElems)
              {
                elemsVisible.AddRange(item.AncestorsAndSelf);
              }
              foreach (var item in elemsVisible)
                elems.Remove(item);

              oDoc.Models.ResetAllHidden();
              oDoc.Models.SetHidden(elems, true);
            }
            else
            {
              oDoc.CurrentSelection.Clear();
              oDoc.CurrentSelection.AddRange(attachedElems);
            }
              }

            }
              }
              catch (Exception ex)
              {
            MessageBox.Show(ex.ToString());
              }
        }
        private VisualizationInfo generateViewpoint(Viewpoint oVP, int elemCheck)
        {
            double units = GetGunits();
              VisualizationInfo v = new VisualizationInfo();
              try
              {

            Vector3D vi = getViewDir(oVP);
            Vector3D up = getViewUp(oVP);
            Point3D center = new Point3D(oVP.Position.X / units, oVP.Position.Y / units, oVP.Position.Z / units);
            double zoomValue = 1;

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

            if (oVP.Projection == ViewpointProjection.Orthographic) //IS ORTHO
            {

              double dist = oVP.VerticalExtentAtFocalDistance / 2 / units;
              zoomValue = 3.125 * dist / (up.Length * 1.25);
             v.OrthogonalCamera = new OrthogonalCamera();
              v.OrthogonalCamera.CameraViewPoint.X = center.X;
              v.OrthogonalCamera.CameraViewPoint.Y = center.Y;
              v.OrthogonalCamera.CameraViewPoint.Z = center.Z;
              v.OrthogonalCamera.CameraUpVector.X = up.X;
              v.OrthogonalCamera.CameraUpVector.Y = up.Y;
              v.OrthogonalCamera.CameraUpVector.Z = up.Z;
              v.OrthogonalCamera.CameraDirection.X = vi.X;
              v.OrthogonalCamera.CameraDirection.Y = vi.Y;
              v.OrthogonalCamera.CameraDirection.Z = vi.Z;
              v.OrthogonalCamera.ViewToWorldScale = zoomValue;
            }
            else // it is a perspective view
            {
              zoomValue = oVP.FocalDistance;

              v.PerspectiveCamera = new PerspectiveCamera();
              v.PerspectiveCamera.CameraViewPoint.X = center.X;
              v.PerspectiveCamera.CameraViewPoint.Y = center.Y;
              v.PerspectiveCamera.CameraViewPoint.Z = center.Z;
              v.PerspectiveCamera.CameraUpVector.X = up.X;
              v.PerspectiveCamera.CameraUpVector.Y = up.Y;
              v.PerspectiveCamera.CameraUpVector.Z = up.Z;
              v.PerspectiveCamera.CameraDirection.X = vi.X;
              v.PerspectiveCamera.CameraDirection.Y = vi.Y;
              v.PerspectiveCamera.CameraDirection.Z = vi.Z;
              v.PerspectiveCamera.FieldOfView = zoomValue;
            }

            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)
            {
              v.Components = new Data.Component[_elementList.Count];
              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.Components[i] = new Case.IssueTracker.Data.Component(appname, "", ifcguid);

              }
            }
              }
              catch (Exception ex)
              {
            MessageBox.Show(ex.ToString());
              }
              return v;
        }
Beispiel #10
0
        /// <summary>
        /// Load from BCF 2.0 as BCF 1.0
        /// </summary>
        /// <param name="bcf2">BCF 2.0 file</param>
        /// <returns></returns>
        public static IssueBCF LoadBcf1IssueFromBcf2(BCF2.Markup bcf2Markup, BCF2.VisualizationInfo bcf2Viewpoint)
        {
            // Convert headers
            List<HeaderFile> bcf1Headers = new List<HeaderFile>();
            foreach (BCF2.HeaderFile bcf2Header in bcf2Markup.Header)
            {
                HeaderFile bcf1Header = new HeaderFile()
                {
                    Filename = bcf2Header.Filename,
                    Date = bcf2Header.Date,
                    IfcProject = bcf2Header.IfcProject,
                    IfcSpatialStructureElement = bcf2Header.IfcSpatialStructureElement
                };
                bcf1Headers.Add(bcf1Header);
            }

            // Convert topic
            Topic bcf1Topic = new Topic();
            if (bcf2Markup.Topic != null)
            {
                bcf1Topic.Guid = bcf2Markup.Topic.Guid;
                bcf1Topic.ReferenceLink = bcf2Markup.Topic.ReferenceLink;
                bcf1Topic.Title = bcf2Markup.Topic.Title;
            };

            // Convert comments
            ObservableCollection<CommentBCF> bcf1Comments = new ObservableCollection<CommentBCF>();
            foreach(BCF2.Comment bcf2Comment in bcf2Markup.Comment)
            {
                CommentBCF bcf1Comment = new CommentBCF()
                {
                    Author = bcf2Comment.Author,
                    Comment1 = bcf2Comment.Comment1,
                    Date = bcf2Comment.Date,
                    Guid = bcf2Comment.Guid,
                    Status = CommentStatus.Unknown,    // default unknown for now
                    Topic = new CommentTopic() { Guid = bcf2Markup.Topic == null ? Guid.NewGuid().ToString() : bcf2Markup.Topic.Guid },
                    VerbalStatus = bcf2Comment.VerbalStatus
                };
                bcf1Comments.Add(bcf1Comment);
            }

            // Convert markups/issues
            Markup bcf1Markup = new Markup()
            {
                Header = bcf1Headers.ToArray(),
                Topic = bcf1Topic,
                Comment = bcf1Comments
            };

            // Convert ClippingPlane
            List<ClippingPlane> bcf1ClippingPlanes = new List<ClippingPlane>();
            if (bcf2Viewpoint.ClippingPlanes != null)
            {
                foreach (BCF2.ClippingPlane bcf2ClippingPlane in bcf2Viewpoint.ClippingPlanes)
                {
                    if (bcf2ClippingPlane != null)
                    {
                        bcf1ClippingPlanes.Add(new ClippingPlane()
                        {
                            Direction = new Direction()
                            {
                                X = bcf2ClippingPlane.Direction.X,
                                Y = bcf2ClippingPlane.Direction.Y,
                                Z = bcf2ClippingPlane.Direction.Z
                            },
                            Location = new Point()
                            {
                                X = bcf2ClippingPlane.Location.X,
                                Y = bcf2ClippingPlane.Location.Y,
                                Z = bcf2ClippingPlane.Location.Z
                            }
                        });
                    }
                }
            }

            // Convert Components
            List<Component> bcf1Components = new List<Component>();
            if (bcf2Viewpoint.Components != null)
            {
                foreach (BCF2.Component bcf2Component in bcf2Viewpoint.Components)
                {
                    if (bcf2Component != null)
                    {
                        bcf1Components.Add(new Component()
                        {
                            AuthoringToolId = bcf2Component.AuthoringToolId,
                            IfcGuid = bcf2Component.IfcGuid,
                            OriginatingSystem = bcf2Component.OriginatingSystem
                        });
                    }
                }
            }

            // Convert Lines
            List<Line> bcf1Lines = new List<Line>();
            if (bcf2Viewpoint.Lines != null)
            {
                foreach (BCF2.Line bcf2Line in bcf2Viewpoint.Lines)
                {
                    if (bcf2Line != null)
                    {
                        bcf1Lines.Add(new Line()
                        {
                            StartPoint = new Point()
                            {
                                X = bcf2Line.StartPoint.X,
                                Y = bcf2Line.StartPoint.Y,
                                Z = bcf2Line.StartPoint.Z
                            },
                            EndPoint = new Point()
                            {
                                X = bcf2Line.EndPoint.X,
                                Y = bcf2Line.EndPoint.Y,
                                Z = bcf2Line.EndPoint.Z
                            }
                        });
                    }
                }
            }

            // Convert viewpoints
            VisualizationInfo bcf1Viewpoint = new VisualizationInfo()
            {
                ClippingPlanes = bcf1ClippingPlanes.ToArray(),
                Components = bcf1Components.ToArray(),
                Lines = bcf1Lines.ToArray(),
                OrthogonalCamera = bcf2Viewpoint.OrthogonalCamera == null ? null : new OrthogonalCamera()
                {
                    CameraDirection = new Direction()
                    {
                        X = bcf2Viewpoint.OrthogonalCamera.CameraDirection.X,
                        Y = bcf2Viewpoint.OrthogonalCamera.CameraDirection.Y,
                        Z = bcf2Viewpoint.OrthogonalCamera.CameraDirection.Z
                    },
                    CameraUpVector = new Direction()
                    {
                        X = bcf2Viewpoint.OrthogonalCamera.CameraUpVector.X,
                        Y = bcf2Viewpoint.OrthogonalCamera.CameraUpVector.Y,
                        Z = bcf2Viewpoint.OrthogonalCamera.CameraUpVector.Z
                    },
                    CameraViewPoint = new Point()
                    {
                        X = bcf2Viewpoint.OrthogonalCamera.CameraViewPoint.X,
                        Y = bcf2Viewpoint.OrthogonalCamera.CameraViewPoint.Y,
                        Z = bcf2Viewpoint.OrthogonalCamera.CameraViewPoint.Z
                    },
                    ViewToWorldScale = bcf2Viewpoint.OrthogonalCamera.ViewToWorldScale
                },
                PerspectiveCamera = bcf2Viewpoint.PerspectiveCamera == null ? null : new PerspectiveCamera()
                {
                    CameraDirection = new Direction()
                    {
                        X = bcf2Viewpoint.PerspectiveCamera.CameraDirection.X,
                        Y = bcf2Viewpoint.PerspectiveCamera.CameraDirection.Y,
                        Z = bcf2Viewpoint.PerspectiveCamera.CameraDirection.Z
                    },
                    CameraUpVector = new Direction()
                    {
                        X = bcf2Viewpoint.PerspectiveCamera.CameraUpVector.X,
                        Y = bcf2Viewpoint.PerspectiveCamera.CameraUpVector.Y,
                        Z = bcf2Viewpoint.PerspectiveCamera.CameraUpVector.Z
                    },
                    CameraViewPoint = new Point()
                    {
                        X = bcf2Viewpoint.PerspectiveCamera.CameraViewPoint.X,
                        Y = bcf2Viewpoint.PerspectiveCamera.CameraViewPoint.Y,
                        Z = bcf2Viewpoint.PerspectiveCamera.CameraViewPoint.Z
                    },
                    FieldOfView = bcf2Viewpoint.PerspectiveCamera.FieldOfView
                },
                SheetCamera = bcf2Viewpoint.SheetCamera == null ? null : new SheetCamera()
                {
                    SheetID = bcf2Viewpoint.SheetCamera.SheetID,
                    TopLeft = new Point()
                    {
                        X = bcf2Viewpoint.SheetCamera.TopLeft.X,
                        Y = bcf2Viewpoint.SheetCamera.TopLeft.Y,
                        Z = bcf2Viewpoint.SheetCamera.TopLeft.Z
                    },
                    BottomRight = new Point()
                    {
                        X = bcf2Viewpoint.SheetCamera.BottomRight.X,
                        Y = bcf2Viewpoint.SheetCamera.BottomRight.Y,
                        Z = bcf2Viewpoint.SheetCamera.BottomRight.Z
                    }
                }
            };

            // Create a new BCF 1.0 issue
            IssueBCF bcf1 = new IssueBCF()
            {
                markup = bcf1Markup,
                viewpoint = bcf1Viewpoint
            };

            return bcf1;
        }