예제 #1
0
 public static void CompareBimSnippet(BimSnippet expected, BimSnippet actual)
 {
     Assert.Equal(expected.isExternal, actual.isExternal);
     Assert.Equal(expected.Reference, actual.Reference);
     Assert.Equal(expected.ReferenceSchema, actual.ReferenceSchema);
     Assert.Equal(expected.SnippetType, actual.SnippetType);
 }
        /*
         * private void commentCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
         * {
         * if (commentCombo.SelectedItem != null)
         * {
         *    Comment curComment = (Comment)commentCombo.SelectedItem;
         *    commentItems.SelectedObject = curComment;
         * }
         * else
         * {
         *    commentItems.SelectedObject = null;
         * }
         * }
         */

/*
 *    private void viewpointCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
 *    {
 *       if (viewpointCombo.SelectedItem != null)
 *       {
 *          ViewPoint curVp = (ViewPoint)viewpointCombo.SelectedItem;
 *          viewpointItems.SelectedObject = curVp.ViewpointRef;
 *
 *          //ModifyRevitView(curVp);
 *          ExtEvents.ChangeViewHandler.v = curVp.ViewpointRef;
 *          ExtEvents.ChangeViewEvent.Raise();
 *       }
 *       else
 *       {
 *          viewpointItems.SelectedObject = null;
 *       }
 *    }
 */


        private void topicItems_SelectedPropertyItemChanged(object sender, RoutedPropertyChangedEventArgs <PropertyItemBase> e)
        {
            PropertyItem propItem = topicItems.SelectedPropertyItem as PropertyItem;

            if (propItem != null && propItem.PropertyName.Equals("BimSnippet") && propItem.Value != null)
            {
                BimSnippet snippet   = (BimSnippet)propItem.Value;
                Markup     curMarkup = ((ResultItem)issuesList.SelectedItems[0]).IssueData;
                ExtEvents.IfcImportHandler.filePath = Path.Combine(Path.GetTempPath(), curMarkup.Topic.Guid + ".ifc");

                if (snippet.isExternal)
                {
                    // Read data from URL
                    using (var client = new WebClient())
                    {
                        client.DownloadFile(snippet.Reference, ExtEvents.IfcImportHandler.filePath);
                    }
                }
                else
                {
                    // Read data from zip
                    using (var fileStream = File.Create(ExtEvents.IfcImportHandler.filePath))
                    {
                        snippet.RefData.CopyTo(fileStream);
                    }
                }

                // Get the data and create local file
                ExtEvents.IfcImportEvent.Raise();
            }
        }
예제 #3
0
        public static BimSnippet GetBimSnippetFromXml(XElement snippetXml)
        {
            var snippet = new BimSnippet();

            snippet.isExternal      = snippetXml.Attribute("isExternal") == null ? false : bool.Parse(snippetXml.Attribute("isExternal").Value);
            snippet.Reference       = snippetXml.Descendants("Reference").FirstOrDefault().Value;
            snippet.ReferenceSchema = snippetXml.Descendants("ReferenceSchema").FirstOrDefault().Value;
            snippet.SnippetType     = snippetXml.Attribute("SnippetType").Value;
            return(snippet);
        }
예제 #4
0
        private Markup WriteDefaultMarkup()
        {
            Markup markup = new Markup();

            try
            {
                HeaderFile[] headerfiles = new HeaderFile[1];
                HeaderFile   header      = new HeaderFile();
                header.IfcProject = GUIDUtil.CreateGUID(m_doc.ProjectInformation);
                header.Filename   = m_doc.Title;
                header.Date       = DateTime.Now;
                headerfiles[0]    = header;
                markup.Header     = headerfiles;

                Topic topic = new Topic();
                topic.Guid  = Guid.NewGuid().ToString();
                topic.Title = "Color Schemes Editor";

                BimSnippet bimSnippet      = new BimSnippet();
                string     currentAssembly = System.Reflection.Assembly.GetAssembly(this.GetType()).Location;
                string     schemaPath      = Path.GetDirectoryName(currentAssembly) + "\\Resources\\colorscheme.xsd";
                bimSnippet.ReferenceSchema = schemaPath;
                bimSnippet.Reference       = "colorscheme.xml";
                topic.BimSnippet           = bimSnippet;
                markup.Topic = topic;

                Comment[] comments = new Comment[1];
                Comment   comment  = new Comment();
                comment.Guid     = Guid.NewGuid().ToString();
                comment.Date     = header.Date;
                comment.Author   = Environment.UserName;
                comment.Comment1 = "Color Schemes and Color Filters by Add-Ins";
                CommentTopic commentTopic = new CommentTopic();
                commentTopic.Guid = topic.Guid;
                comment.Topic     = commentTopic;
                comments[0]       = comment;
                markup.Comment    = comments;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to wirte the default Markup.\n" + ex.Message, "Write Default Markup", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(markup);
        }
예제 #5
0
        /// <summary>
        /// Organize raw data into BCFZIP class structure
        /// </summary>
        /// <param name="bcfzip"></param>
        /// <param name="tempVisInfoHolder"></param>
        /// <param name="tempFileContentHolder"></param>
        /// <param name="tempExtInfoHolder"></param>
        /// <returns></returns>
        private static BCFZIP MapContents(BCFZIP bcfzip, Dictionary <string, Dictionary <string, VisualizationInfo> > tempVisInfoHolder,
                                          Dictionary <string, Dictionary <string, byte[]> > tempFileContentHolder, Dictionary <string, Dictionary <string, ComponentExtensionInfo> > tempExtInfoHolder)
        {
            BCFZIP mappedBCF = null;

            try
            {
                Dictionary <string /*guid*/, RevitExtension> extensions = new Dictionary <string, RevitExtension>();
                foreach (RevitExtension ext in bcfzip.ExtensionColor.Extensions)
                {
                    if (!extensions.ContainsKey(ext.Guid))
                    {
                        extensions.Add(ext.Guid, ext);
                    }
                }

                for (int i = 0; i < bcfzip.Markups.Count; i++)
                {
                    Markup markup  = bcfzip.Markups[i];
                    string topicId = markup.Topic.Guid;

                    //BimSnippet
                    BimSnippet bimSnippet = markup.Topic.BimSnippet;
                    if (!string.IsNullOrEmpty(bimSnippet.Reference) && !bimSnippet.isExternal)
                    {
                        if (tempFileContentHolder.ContainsKey(topicId))
                        {
                            if (tempFileContentHolder[topicId].ContainsKey(bimSnippet.Reference))
                            {
                                bimSnippet.FileContent = tempFileContentHolder[topicId][bimSnippet.Reference];
                            }
                        }
                    }
                    bimSnippet.TopicGuid    = topicId;
                    markup.Topic.BimSnippet = bimSnippet;

                    //DocumentReferences
                    List <TopicDocumentReferences> docList = new List <TopicDocumentReferences>();
                    foreach (TopicDocumentReferences doc in markup.Topic.DocumentReferences)
                    {
                        TopicDocumentReferences docRef = doc;
                        docRef.TopicGuid = topicId;
                        if (!string.IsNullOrEmpty(docRef.ReferencedDocument) && !docRef.isExternal)
                        {
                            if (tempFileContentHolder.ContainsKey(topicId))
                            {
                                if (tempFileContentHolder[topicId].ContainsKey(docRef.ReferencedDocument))
                                {
                                    docRef.FileContent = tempFileContentHolder[topicId][docRef.ReferencedDocument];
                                }
                            }
                        }
                        docList.Add(docRef);
                    }
                    markup.Topic.DocumentReferences = docList;

                    if (markup.Viewpoints.Count > 0)
                    {
                        ViewPoint firstViewpoint = markup.Viewpoints.First();

                        for (int j = 0; j < markup.Comment.Count; j++)
                        {
                            string viewPointGuid = markup.Comment[j].Viewpoint.Guid;
                            if (string.IsNullOrEmpty(viewPointGuid))
                            {
                                markup.Comment[j].Viewpoint.Guid = firstViewpoint.Guid;
                            }
                        }
                    }

                    //viewpoints
                    for (int j = 0; j < markup.Viewpoints.Count; j++)
                    {
                        ViewPoint viewpoint = markup.Viewpoints[j];
                        //bitmap
                        if (tempVisInfoHolder.ContainsKey(topicId))
                        {
                            if (tempVisInfoHolder[topicId].ContainsKey(viewpoint.Viewpoint))
                            {
                                VisualizationInfo visInfo = tempVisInfoHolder[topicId][viewpoint.Viewpoint];
                                visInfo.ViewPointGuid = viewpoint.Guid;
                                List <VisualizationInfoBitmaps> bitmapList = new List <VisualizationInfoBitmaps>();
                                foreach (VisualizationInfoBitmaps bitmap in visInfo.Bitmaps)
                                {
                                    VisualizationInfoBitmaps visBitmap = bitmap;
                                    if (!string.IsNullOrEmpty(bitmap.Reference))
                                    {
                                        if (tempFileContentHolder.ContainsKey(topicId))
                                        {
                                            if (tempFileContentHolder[topicId].ContainsKey(bitmap.Reference))
                                            {
                                                visBitmap.BitmapImage = tempFileContentHolder[topicId][bitmap.Reference];
                                            }
                                        }
                                    }
                                    visBitmap.ViewPointGuid = viewpoint.Guid;
                                    bitmapList.Add(visBitmap);
                                }
                                visInfo.Bitmaps = bitmapList;

                                string viewpointExt = viewpoint.Viewpoint.Replace(".bcfv", ".bcfvx");
                                if (tempExtInfoHolder.ContainsKey(topicId))
                                {
                                    if (tempExtInfoHolder[topicId].ContainsKey(viewpointExt))
                                    {
                                        ComponentExtensionInfo extInfo = tempExtInfoHolder[topicId][viewpointExt];
                                        if (visInfo.Components.Count > 0)
                                        {
                                            foreach (ComponentExtension compExt in extInfo.Extensions)
                                            {
                                                var compFound = from comp in visInfo.Components where comp.IfcGuid == compExt.IfcGuid select comp;
                                                if (compFound.Count() > 0)
                                                {
                                                    int compIndex = visInfo.Components.IndexOf(compFound.First());
                                                    visInfo.Components[compIndex].ElementName    = compExt.ElementName;
                                                    visInfo.Components[compIndex].Action         = (extensions.ContainsKey(compExt.ActionGuid)) ? extensions[compExt.ActionGuid] : new RevitExtension();
                                                    visInfo.Components[compIndex].Responsibility = (extensions.ContainsKey(compExt.ResponsibilityGuid)) ? extensions[compExt.ResponsibilityGuid] : new RevitExtension();
                                                }
                                            }
                                        }
                                    }
                                }

                                markup.Viewpoints[j].VisInfo = visInfo;
                            }
                        }
                        //snapshot
                        if (tempFileContentHolder.ContainsKey(topicId))
                        {
                            if (tempFileContentHolder[topicId].ContainsKey(viewpoint.Snapshot))
                            {
                                markup.Viewpoints[j].SnapshotImage = tempFileContentHolder[topicId][viewpoint.Snapshot];
                                if (null == markup.TopicImage && null != markup.Viewpoints[j].SnapshotImage)
                                {
                                    markup.TopicImage = markup.Viewpoints[j].SnapshotImage;
                                }
                            }
                        }
                    }

                    if (markup.Viewpoints.Count > 0)
                    {
                        markup.SelectedViewpoint = markup.Viewpoints.First();
                    }
                    bcfzip.Markups[i] = markup;
                }
                mappedBCF = bcfzip;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create maps from BCF contents.\n" + ex.Message, "Mapping BCF Contents", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(mappedBCF);
        }