Inheritance: INotifyPropertyChanged
Ejemplo n.º 1
0
        /// <summary>
        /// Save BCF 1.0 as BCF 2.0
        /// </summary>
        /// <param name="bcf1">BCF 1.0 file</param>
        public static void SaveBcf2FromBcf1(BCF bcf1)
        {
            try
            {
                BCF2.BcfFile bcf2 = new BCF2.BcfFile();
                bcf2.TempPath = bcf1.path; // replace temp path with BCF 1.0's

                // bcf2.ProjectName = ;    // from Jira?
                // bcf2.ProjectId = ;      // from Jira?

                // Add issues (markups)
                foreach (IssueBCF bcf1Issue in bcf1.Issues)
                {
                    // Convert header files
                    List <BCF2.HeaderFile> bcf2Headers = new List <BCF2.HeaderFile>();
                    if (bcf1Issue.markup.Header != null)
                    {
                        foreach (HeaderFile bcf1Header in bcf1Issue.markup.Header)
                        {
                            bcf2Headers.Add(new BCF2.HeaderFile()
                            {
                                Date       = bcf1Header.Date,
                                Filename   = bcf1Header.Filename,
                                IfcProject = bcf1Header.IfcProject,
                                IfcSpatialStructureElement = bcf1Header.IfcSpatialStructureElement,
                                isExternal = true, // default true for now
                                Reference  = ""    // default empty for now
                            });
                        }
                    }

                    // Convert Comments
                    ObservableCollection <BCF2.Comment> bcf2Comments = new ObservableCollection <BCF2.Comment>();
                    if (bcf1Issue.markup.Comment != null)
                    {
                        foreach (CommentBCF bcf1Comment in bcf1Issue.markup.Comment)
                        {
                            if (bcf1Comment != null)
                            {
                                bcf2Comments.Add(new BCF2.Comment()
                                {
                                    Author         = bcf1Comment.Author,
                                    Comment1       = bcf1Comment.Comment1,
                                    Date           = bcf1Comment.Date,
                                    Guid           = bcf1Comment.Guid,
                                    ModifiedAuthor = bcf1Comment.Author, // default the same as author for now
                                    //ModifiedDate = null,   // mismatch attribute
                                    ReplyToComment = null,               // mismatch attribute
                                    Status         = bcf1Comment.Status.ToString(),
                                    Topic          = new BCF2.CommentTopic()
                                    {
                                        Guid = bcf1Issue.markup.Topic.Guid
                                    },                  // all referenced to markup's topic
                                    VerbalStatus = bcf1Comment.VerbalStatus,
                                    Viewpoint    = null //  mismatch attribute
                                });
                            }
                        }
                    }

                    // Convert Topic
                    BCF2.Topic bcf2Topic = new BCF2.Topic()
                    {
                        AssignedTo     = null,     // mismatch attribute
                        BimSnippet     = null,     // mismatch attribute
                        CreationAuthor = null,     // mismatch attribute
                        //CreationDate = null,  // mismatch attribute
                        Description        = null, // mismatch attribute
                        DocumentReferences = null, // mismatch attribute
                        Guid           = bcf1Issue.markup.Topic.Guid,
                        Index          = null,     // mismatch attribute
                        Labels         = null,     // mismatch attribute
                        ModifiedAuthor = null,     // mismatch attribute
                        //ModifiedDate = ,  // mismatch attribute
                        Priority      = null,      // mismatch attribute
                        ReferenceLink = bcf1Issue.markup.Topic.ReferenceLink,
                        RelatedTopics = null,      // mismatch attribute
                        Title         = bcf1Issue.markup.Topic.Title,
                        TopicStatus   = null,      // mismatch attribute
                        TopicType     = null       // mismatch attribute
                    };

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

                    // Convert Components
                    List <BCF2.Component> bcf2Components = new List <BCF2.Component>();
                    if (bcf1Issue.viewpoint.Components != null)
                    {
                        foreach (Component bcf1Component in bcf1Issue.viewpoint.Components)
                        {
                            if (bcf1Component != null)
                            {
                                bcf2Components.Add(new BCF2.Component()
                                {
                                    AuthoringToolId = bcf1Component.AuthoringToolId,
                                    // Color = bcf1Component,    // mismatch attribute
                                    IfcGuid           = bcf1Component.IfcGuid,
                                    OriginatingSystem = bcf1Component.OriginatingSystem
                                                        // Selected = bcf1Component,   // mismatch attribute
                                                        // Visible = bcf1Component    // mismatch attribute
                                });
                            }
                        }
                    }

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

                    // Convert VisualizationInfo
                    BCF2.VisualizationInfo bcf2VizInfo = new BCF2.VisualizationInfo()
                    {
                        Bitmaps          = null, // default null
                        ClippingPlanes   = bcf2ClippingPlanes.ToArray(),
                        Components       = bcf2Components,
                        Lines            = bcf2Lines.ToArray(),
                        OrthogonalCamera = bcf1Issue.viewpoint.OrthogonalCamera == null ? null : new BCF2.OrthogonalCamera()
                        {
                            CameraDirection = new BCF2.Direction()
                            {
                                X = bcf1Issue.viewpoint.OrthogonalCamera.CameraDirection.X,
                                Y = bcf1Issue.viewpoint.OrthogonalCamera.CameraDirection.Y,
                                Z = bcf1Issue.viewpoint.OrthogonalCamera.CameraDirection.Z
                            },
                            CameraUpVector = new BCF2.Direction()
                            {
                                X = bcf1Issue.viewpoint.OrthogonalCamera.CameraUpVector.X,
                                Y = bcf1Issue.viewpoint.OrthogonalCamera.CameraUpVector.Y,
                                Z = bcf1Issue.viewpoint.OrthogonalCamera.CameraUpVector.Z
                            },
                            CameraViewPoint = new BCF2.Point()
                            {
                                X = bcf1Issue.viewpoint.OrthogonalCamera.CameraViewPoint.X,
                                Y = bcf1Issue.viewpoint.OrthogonalCamera.CameraViewPoint.Y,
                                Z = bcf1Issue.viewpoint.OrthogonalCamera.CameraViewPoint.Z
                            },
                            ViewToWorldScale = bcf1Issue.viewpoint.OrthogonalCamera.ViewToWorldScale
                        },
                        PerspectiveCamera = bcf1Issue.viewpoint.PerspectiveCamera == null ? null : new BCF2.PerspectiveCamera()
                        {
                            CameraDirection = new BCF2.Direction()
                            {
                                X = bcf1Issue.viewpoint.PerspectiveCamera.CameraDirection.X,
                                Y = bcf1Issue.viewpoint.PerspectiveCamera.CameraDirection.Y,
                                Z = bcf1Issue.viewpoint.PerspectiveCamera.CameraDirection.Z
                            },
                            CameraUpVector = new BCF2.Direction()
                            {
                                X = bcf1Issue.viewpoint.PerspectiveCamera.CameraUpVector.X,
                                Y = bcf1Issue.viewpoint.PerspectiveCamera.CameraUpVector.Y,
                                Z = bcf1Issue.viewpoint.PerspectiveCamera.CameraUpVector.Z
                            },
                            CameraViewPoint = new BCF2.Point()
                            {
                                X = bcf1Issue.viewpoint.PerspectiveCamera.CameraViewPoint.X,
                                Y = bcf1Issue.viewpoint.PerspectiveCamera.CameraViewPoint.Y,
                                Z = bcf1Issue.viewpoint.PerspectiveCamera.CameraViewPoint.Z
                            },
                            FieldOfView = bcf1Issue.viewpoint.PerspectiveCamera.FieldOfView
                        },
                        SheetCamera = bcf1Issue.viewpoint.SheetCamera == null ? null : new BCF2.SheetCamera()
                        {
                            SheetID   = bcf1Issue.viewpoint.SheetCamera.SheetID,
                            SheetName = null, // default null
                            TopLeft   = new BCF2.Point()
                            {
                                X = bcf1Issue.viewpoint.SheetCamera.TopLeft.X,
                                Y = bcf1Issue.viewpoint.SheetCamera.TopLeft.Y,
                                Z = bcf1Issue.viewpoint.SheetCamera.TopLeft.Z
                            },
                            BottomRight = new BCF2.Point()
                            {
                                X = bcf1Issue.viewpoint.SheetCamera.BottomRight.X,
                                Y = bcf1Issue.viewpoint.SheetCamera.BottomRight.Y,
                                Z = bcf1Issue.viewpoint.SheetCamera.BottomRight.Z
                            }
                        }
                    };

                    // Convert viewpoints
                    // BCF 1.0 can only have one viewpoint
                    ObservableCollection <BCF2.ViewPoint> bcf2ViewPoints = new ObservableCollection <BCF2.ViewPoint>();
                    bcf2ViewPoints.Add(new BCF2.ViewPoint()
                    {
                        //Guid = null,    // no guid for viewpoint
                        Snapshot  = bcf1Issue.snapshot,
                        Viewpoint = "viewpoint.bcfv",
                        VisInfo   = bcf2VizInfo
                    });

                    // Add BCF 2.0 issues/markups
                    bcf2.Issues.Add(new BCF2.Markup()
                    {
                        Header     = bcf2Headers,
                        Comment    = bcf2Comments,
                        Topic      = bcf2Topic,
                        Viewpoints = bcf2ViewPoints
                    });
                }

                // Save BCF 2.0 file
                BCF2.BcfContainer.SaveBcfFile(bcf2);
                bcf1.HasBeenSaved = true;
            }
            catch (Exception ex)
            {
                // Get stack trace for the exception with source file information
                var st = new System.Diagnostics.StackTrace(ex, true);
                // Get the top stack frame
                var frame = st.GetFrame(0);
                // Get the line number from the stack frame
                var line = frame.GetFileLineNumber();
                System.Windows.MessageBox.Show("Exception:" + line + "=====" + ex.ToString());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Save BCF 1.0 as BCF 2.0
        /// </summary>
        /// <param name="bcf1">BCF 1.0 file</param>
        public static void SaveBcf2FromBcf1(BCF bcf1)
        {
            try
            {
                BCF2.BcfFile bcf2 = new BCF2.BcfFile();
                bcf2.TempPath = bcf1.path; // replace temp path with BCF 1.0's

                // bcf2.ProjectName = ;    // from Jira?
                // bcf2.ProjectId = ;      // from Jira?

                // Add issues (markups)
                foreach (IssueBCF bcf1Issue in bcf1.Issues)
                {
                    // Convert header files
                    List<BCF2.HeaderFile> bcf2Headers = new List<BCF2.HeaderFile>();
                    if (bcf1Issue.markup.Header != null)
                    {
                        foreach (HeaderFile bcf1Header in bcf1Issue.markup.Header)
                        {
                            bcf2Headers.Add(new BCF2.HeaderFile()
                            {
                                Date = bcf1Header.Date,
                                Filename = bcf1Header.Filename,
                                IfcProject = bcf1Header.IfcProject,
                                IfcSpatialStructureElement = bcf1Header.IfcSpatialStructureElement,
                                isExternal = true, // default true for now
                                Reference = "" // default empty for now
                            });
                        }
                    }

                    // Convert Comments
                    ObservableCollection<BCF2.Comment> bcf2Comments = new ObservableCollection<BCF2.Comment>();
                    if (bcf1Issue.markup.Comment != null)
                    {
                        foreach (CommentBCF bcf1Comment in bcf1Issue.markup.Comment)
                        {
                            if (bcf1Comment != null)
                            {
                                bcf2Comments.Add(new BCF2.Comment()
                                {
                                    Author = bcf1Comment.Author,
                                    Comment1 = bcf1Comment.Comment1,
                                    Date = bcf1Comment.Date,
                                    Guid = bcf1Comment.Guid,
                                    ModifiedAuthor = bcf1Comment.Author,  // default the same as author for now
                                  //ModifiedDate = null,   // mismatch attribute
                                    ReplyToComment = null, // mismatch attribute
                                    Status = bcf1Comment.Status.ToString(),
                                    Topic = new BCF2.CommentTopic() { Guid = bcf1Issue.markup.Topic.Guid }, // all referenced to markup's topic
                                    VerbalStatus = bcf1Comment.VerbalStatus,
                                    Viewpoint = null //  mismatch attribute
                                });
                            }
                        }
                    }

                    // Convert Topic
                    BCF2.Topic bcf2Topic = new BCF2.Topic()
                    {
                        AssignedTo = null,  // mismatch attribute
                        BimSnippet = null,  // mismatch attribute
                        CreationAuthor = null,  // mismatch attribute
                        //CreationDate = null,  // mismatch attribute
                        Description = null,  // mismatch attribute
                        DocumentReferences = null,  // mismatch attribute
                        Guid = bcf1Issue.markup.Topic.Guid,
                        Index = null,  // mismatch attribute
                        Labels = null,  // mismatch attribute
                        ModifiedAuthor = null,  // mismatch attribute
                        //ModifiedDate = ,  // mismatch attribute
                        Priority = null,  // mismatch attribute
                        ReferenceLink = bcf1Issue.markup.Topic.ReferenceLink,
                        RelatedTopics = null,  // mismatch attribute
                        Title = bcf1Issue.markup.Topic.Title,
                        TopicStatus = null,  // mismatch attribute
                        TopicType = null  // mismatch attribute
                    };

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

                    // Convert Components
                    List<BCF2.Component> bcf2Components = new List<BCF2.Component>();
                    if (bcf1Issue.viewpoint.Components != null)
                    {
                        foreach (Component bcf1Component in bcf1Issue.viewpoint.Components)
                        {
                            if (bcf1Component != null)
                            {
                                bcf2Components.Add(new BCF2.Component()
                                {
                                    AuthoringToolId = bcf1Component.AuthoringToolId,
                                    // Color = bcf1Component,    // mismatch attribute
                                    IfcGuid = bcf1Component.IfcGuid,
                                    OriginatingSystem = bcf1Component.OriginatingSystem
                                    // Selected = bcf1Component,   // mismatch attribute
                                    // Visible = bcf1Component    // mismatch attribute
                                });
                            }
                        }
                    }

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

                    // Convert VisualizationInfo
                    BCF2.VisualizationInfo bcf2VizInfo = new BCF2.VisualizationInfo()
                    {
                        Bitmaps = null, // default null
                        ClippingPlanes = bcf2ClippingPlanes.ToArray(),
                        Components = bcf2Components,
                        Lines = bcf2Lines.ToArray(),
                        OrthogonalCamera = bcf1Issue.viewpoint.OrthogonalCamera == null ? null : new BCF2.OrthogonalCamera()
                        {
                            CameraDirection = new BCF2.Direction()
                            {
                                X = bcf1Issue.viewpoint.OrthogonalCamera.CameraDirection.X,
                                Y = bcf1Issue.viewpoint.OrthogonalCamera.CameraDirection.Y,
                                Z = bcf1Issue.viewpoint.OrthogonalCamera.CameraDirection.Z
                            },
                            CameraUpVector = new BCF2.Direction()
                            {
                                X = bcf1Issue.viewpoint.OrthogonalCamera.CameraUpVector.X,
                                Y = bcf1Issue.viewpoint.OrthogonalCamera.CameraUpVector.Y,
                                Z = bcf1Issue.viewpoint.OrthogonalCamera.CameraUpVector.Z
                            },
                            CameraViewPoint = new BCF2.Point()
                            {
                                X = bcf1Issue.viewpoint.OrthogonalCamera.CameraViewPoint.X,
                                Y = bcf1Issue.viewpoint.OrthogonalCamera.CameraViewPoint.Y,
                                Z = bcf1Issue.viewpoint.OrthogonalCamera.CameraViewPoint.Z
                            },
                            ViewToWorldScale = bcf1Issue.viewpoint.OrthogonalCamera.ViewToWorldScale
                        },
                        PerspectiveCamera = bcf1Issue.viewpoint.PerspectiveCamera == null ? null : new BCF2.PerspectiveCamera()
                        {
                            CameraDirection = new BCF2.Direction()
                            {
                                X = bcf1Issue.viewpoint.PerspectiveCamera.CameraDirection.X,
                                Y = bcf1Issue.viewpoint.PerspectiveCamera.CameraDirection.Y,
                                Z = bcf1Issue.viewpoint.PerspectiveCamera.CameraDirection.Z
                            },
                            CameraUpVector = new BCF2.Direction()
                            {
                                X = bcf1Issue.viewpoint.PerspectiveCamera.CameraUpVector.X,
                                Y = bcf1Issue.viewpoint.PerspectiveCamera.CameraUpVector.Y,
                                Z = bcf1Issue.viewpoint.PerspectiveCamera.CameraUpVector.Z
                            },
                            CameraViewPoint = new BCF2.Point()
                            {
                                X = bcf1Issue.viewpoint.PerspectiveCamera.CameraViewPoint.X,
                                Y = bcf1Issue.viewpoint.PerspectiveCamera.CameraViewPoint.Y,
                                Z = bcf1Issue.viewpoint.PerspectiveCamera.CameraViewPoint.Z
                            },
                            FieldOfView = bcf1Issue.viewpoint.PerspectiveCamera.FieldOfView
                        },
                        SheetCamera = bcf1Issue.viewpoint.SheetCamera == null ? null : new BCF2.SheetCamera()
                        {
                            SheetID = bcf1Issue.viewpoint.SheetCamera.SheetID,
                            SheetName = null, // default null
                            TopLeft = new BCF2.Point()
                            {
                                X = bcf1Issue.viewpoint.SheetCamera.TopLeft.X,
                                Y = bcf1Issue.viewpoint.SheetCamera.TopLeft.Y,
                                Z = bcf1Issue.viewpoint.SheetCamera.TopLeft.Z
                            },
                            BottomRight = new BCF2.Point()
                            {
                                X = bcf1Issue.viewpoint.SheetCamera.BottomRight.X,
                                Y = bcf1Issue.viewpoint.SheetCamera.BottomRight.Y,
                                Z = bcf1Issue.viewpoint.SheetCamera.BottomRight.Z
                            }
                        }
                    };

                    // Convert viewpoints
                    // BCF 1.0 can only have one viewpoint
                    ObservableCollection<BCF2.ViewPoint> bcf2ViewPoints = new ObservableCollection<BCF2.ViewPoint>();
                    bcf2ViewPoints.Add(new BCF2.ViewPoint()
                    {
                        //Guid = null,    // no guid for viewpoint
                        Snapshot = bcf1Issue.snapshot,
                        Viewpoint = "viewpoint.bcfv",
                        VisInfo = bcf2VizInfo
                    });

                    // Add BCF 2.0 issues/markups
                    bcf2.Issues.Add(new BCF2.Markup()
                    {
                        Header = bcf2Headers,
                        Comment = bcf2Comments,
                        Topic = bcf2Topic,
                        Viewpoints = bcf2ViewPoints
                    });
                }

                // Save BCF 2.0 file
                BCF2.BcfContainer.SaveBcfFile(bcf2);
                bcf1.HasBeenSaved = true;
            }
            catch (Exception ex)
            {
                // Get stack trace for the exception with source file information
                var st = new System.Diagnostics.StackTrace(ex, true);
                // Get the top stack frame
                var frame = st.GetFrame(0);
                // Get the line number from the stack frame
                var line = frame.GetFileLineNumber();
                System.Windows.MessageBox.Show("Exception:" + line + "=====" + ex.ToString());
            }
        }