Esempio n. 1
0
        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 oCurVP = oDoc.vi.CurrentViewpoint.ToViewpoint;
                // get copy viewpoint
                Viewpoint oCopyVP = new Viewpoint();



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



                // **** CUSTOM VALUE FOR TEKLA **** //
                // otherwise = 1
                // **** CUSTOM VALUE FOR TEKLA **** //
                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
                {
                    //double angle = tuple.Item5 * Math.PI / 180;
                    // MessageBox.Show(tuple.Item5.ToString() + "  " +(Math.Tan(angle / 2)*2).ToString());
                    oCopyVP.FocalDistance = tuple.Item5;
                    //oCopyVP.SetExtentsAtFocalDistance(Math.Tan(angle / 2) * 2, Math.Tan(angle / 2) * 2 / oCopyVP.AspectRatio);
                    oCopyVP.Position = tuple.Item1;
                }

                oDoc.CurrentViewpoint.CopyFrom(oCopyVP);

                if (v.Components != null && v.Components.Any())
                {
                    // ModelItemCollection selected = new ModelItemCollection();
                    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 (MySettings.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());
            }
            //setVisibility(v);


        }
Esempio n. 2
0
        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 oCurVP = oDoc.vi.CurrentViewpoint.ToViewpoint;
                // get copy viewpoint
                Viewpoint oCopyVP = new Viewpoint();



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



                // **** CUSTOM VALUE FOR TEKLA **** //
                // otherwise = 1
                // **** CUSTOM VALUE FOR TEKLA **** //
                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
                {
                    //double angle = tuple.Item5 * Math.PI / 180;
                    // MessageBox.Show(tuple.Item5.ToString() + "  " +(Math.Tan(angle / 2)*2).ToString());
                    oCopyVP.FocalDistance = tuple.Item5;
                    //oCopyVP.SetExtentsAtFocalDistance(Math.Tan(angle / 2) * 2, Math.Tan(angle / 2) * 2 / oCopyVP.AspectRatio);
                    oCopyVP.Position = tuple.Item1;
                }

                oDoc.CurrentViewpoint.CopyFrom(oCopyVP);

                if (v.Components != null && v.Components.Any())
                {
                    // ModelItemCollection selected = new ModelItemCollection();
                    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 (MySettings.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());
            }
            //setVisibility(v);
        }
Esempio n. 3
0
        public static void Open(Document doc, VisualizationInfo v)
        {
            try
            {
                NavisUtils.GetGunits(doc);
                Viewpoint viewpoint = new Viewpoint();

                //orthogonal
                if (v.OrthogonalCamera != null)
                {
                    if (v.OrthogonalCamera.CameraViewPoint == null || v.OrthogonalCamera.CameraUpVector == null ||
                        v.OrthogonalCamera.CameraDirection == null)
                    {
                        return;
                    }

                    var zoom            = v.OrthogonalCamera.ViewToWorldScale.ToInternal();
                    var cameraDirection = NavisUtils.GetNavisVector(v.OrthogonalCamera.CameraDirection);
                    var cameraUpVector  = NavisUtils.GetNavisVector(v.OrthogonalCamera.CameraUpVector);
                    var cameraViewPoint = NavisUtils.GetNavisXYZ(v.OrthogonalCamera.CameraViewPoint);

                    viewpoint.Position = cameraViewPoint;
                    viewpoint.AlignUp(cameraUpVector);
                    viewpoint.AlignDirection(cameraDirection);
                    viewpoint.Projection    = ViewpointProjection.Orthographic;
                    viewpoint.FocalDistance = 1;

                    //TODO
                    //for better zooming from revit should use > zoom * 1.25
                    //for better zooming from tekla should use > zoom / 1.25
                    //still not sure why
                    Point3D xyzTL = cameraViewPoint.Add(cameraUpVector.Multiply(zoom));
                    var     dist  = xyzTL.DistanceTo(cameraViewPoint);
                    viewpoint.SetExtentsAtFocalDistance(1, dist);
                }
                //perspective
                else if (v.PerspectiveCamera != null)
                {
                    if (v.PerspectiveCamera.CameraViewPoint == null || v.PerspectiveCamera.CameraUpVector == null ||
                        v.PerspectiveCamera.CameraDirection == null)
                    {
                        return;
                    }

                    var zoom            = v.PerspectiveCamera.FieldOfView;
                    var cameraDirection = NavisUtils.GetNavisVector(v.PerspectiveCamera.CameraDirection);
                    var cameraUpVector  = NavisUtils.GetNavisVector(v.PerspectiveCamera.CameraUpVector);
                    var cameraViewPoint = NavisUtils.GetNavisXYZ(v.PerspectiveCamera.CameraViewPoint);

                    viewpoint.Position = cameraViewPoint;
                    viewpoint.AlignUp(cameraUpVector);
                    viewpoint.AlignDirection(cameraDirection);
                    viewpoint.Projection    = ViewpointProjection.Perspective;
                    viewpoint.FocalDistance = zoom;
                }

                doc.CurrentViewpoint.CopyFrom(viewpoint);


                //show/hide elements
                //todo: needs improvement
                //todo: add settings
                if (v.Components != null)
                {
                    List <ModelItem> attachedElems = new List <ModelItem>();
                    List <ModelItem> elems         = doc.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);
                            }

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

            catch (System.Exception ex1)
            {
                MessageBox.Show("exception: " + ex1, "Error opening view");
            }
        }
Esempio n. 4
0
    public static void Open(Document doc, VisualizationInfo v)
    {
      try
      {

        NavisUtils.GetGunits(doc);
        Viewpoint viewpoint = new Viewpoint();

        //orthogonal
        if (v.OrthogonalCamera != null)
        {
          if (v.OrthogonalCamera.CameraViewPoint == null || v.OrthogonalCamera.CameraUpVector == null ||
              v.OrthogonalCamera.CameraDirection == null)
            return;

          var zoom = v.OrthogonalCamera.ViewToWorldScale.ToInternal();
          var cameraDirection = NavisUtils.GetNavisVector(v.OrthogonalCamera.CameraDirection);
          var cameraUpVector = NavisUtils.GetNavisVector(v.OrthogonalCamera.CameraUpVector);
          var cameraViewPoint = NavisUtils.GetNavisXYZ(v.OrthogonalCamera.CameraViewPoint);

          viewpoint.Position = cameraViewPoint;
          viewpoint.AlignUp(cameraUpVector);
          viewpoint.AlignDirection(cameraDirection);
          viewpoint.Projection = ViewpointProjection.Orthographic;
          viewpoint.FocalDistance = 1;

          //TODO
          //for better zooming from revit should use > zoom * 1.25
          //for better zooming from tekla should use > zoom / 1.25
          //still not sure why
          Point3D xyzTL = cameraViewPoint.Add(cameraUpVector.Multiply(zoom));
          var dist = xyzTL.DistanceTo(cameraViewPoint);
          viewpoint.SetExtentsAtFocalDistance(1, dist);
        }
        //perspective
        else if (v.PerspectiveCamera != null)
        {
          if (v.PerspectiveCamera.CameraViewPoint == null || v.PerspectiveCamera.CameraUpVector == null ||
              v.PerspectiveCamera.CameraDirection == null)
            return;

          var zoom = v.PerspectiveCamera.FieldOfView;
          var cameraDirection = NavisUtils.GetNavisVector(v.PerspectiveCamera.CameraDirection);
          var cameraUpVector = NavisUtils.GetNavisVector(v.PerspectiveCamera.CameraUpVector);
          var cameraViewPoint = NavisUtils.GetNavisXYZ(v.PerspectiveCamera.CameraViewPoint);

          viewpoint.Position = cameraViewPoint;
          viewpoint.AlignUp(cameraUpVector);
          viewpoint.AlignDirection(cameraDirection);
          viewpoint.Projection = ViewpointProjection.Perspective;
          viewpoint.FocalDistance = zoom;
        }

        doc.CurrentViewpoint.CopyFrom(viewpoint);


        //show/hide elements
        //todo: needs improvement
        //todo: add settings
        if (v.Components != null && v.Components.Any())
        {
          List<ModelItem> attachedElems = new List<ModelItem>();
          List<ModelItem> elems = doc.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);

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

      catch (System.Exception ex1)
      {
        MessageBox.Show("exception: " + ex1, "Error opening view");
      }
    }