Ejemplo n.º 1
0
        private void PopInstance(
            string InLogLinePrefix
            )
        {
            FDocumentData DocumentData = DocumentDataStack.Peek();

            DocumentData.LogElement(DebugLog, InLogLinePrefix, -1);
            DocumentData.PopInstance();
        }
Ejemplo n.º 2
0
        private void PushInstance(
            ElementType InInstanceType,
            Transform InWorldTransform,
            string InLogLinePrefix
            )
        {
            FDocumentData DocumentData = DocumentDataStack.Peek();

            DocumentData.PushInstance(InInstanceType, InWorldTransform);
            DocumentData.LogElement(DebugLog, InLogLinePrefix, +1);
        }
Ejemplo n.º 3
0
        private void SetMaterial(
            MaterialNode InMaterialNode,
            IList <string> InExtraTexturePaths
            )
        {
            FDocumentData DocumentData = DocumentDataStack.Peek();

            if (DocumentData.SetMaterial(InMaterialNode, InExtraTexturePaths))
            {
                DocumentData.LogMaterial(InMaterialNode, DebugLog, "Add Material");
            }
        }
Ejemplo n.º 4
0
        private void PopDocument()
        {
            FDocumentData DocumentData = DocumentDataStack.Pop();

            if (DocumentDataStack.Count == 0)
            {
                DocumentData.WrapupScene(DatasmithScene, UniqueTextureNameSet);
            }
            else
            {
                DocumentData.WrapupLink(DatasmithScene, DocumentDataStack.Peek().GetCurrentActor(), UniqueTextureNameSet);
                DirectLink?.OnEndLinkedDocument();
            }
        }
Ejemplo n.º 5
0
        private void PopElement(
            string InLogLinePrefix
            )
        {
            if (CurrentElementSkipped)
            {
                CurrentElementSkipped = false;
                return;
            }

            FDocumentData DocumentData = DocumentDataStack.Peek();

            DocumentData.LogElement(DebugLog, InLogLinePrefix, -1);
            DocumentData.PopElement();
        }
Ejemplo n.º 6
0
        private bool PushElement(
            Element InElement,
            Transform InWorldTransform,
            string InLogLinePrefix
            )
        {
            FDocumentData DocumentData = DocumentDataStack.Peek();

            if (DocumentData.PushElement(InElement, InWorldTransform))
            {
                DocumentData.LogElement(DebugLog, InLogLinePrefix, +1);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 7
0
        private void PushDocument(
            Document InDocument,
            bool bInAddLocationActors = true
            )
        {
            // Check if we have cache for this document.
            FDocumentData DocumentData = new FDocumentData(InDocument, ref MessageList, DirectLink);

            DocumentDataStack.Push(DocumentData);

            if (DocumentDataStack.Count > 1 && DirectLink != null)
            {
                DirectLink.OnBeginLinkedDocument(InDocument);
            }

            if (bInAddLocationActors)
            {
                DocumentDataStack.Peek().AddLocationActors(WorldTransformStack.Peek());
            }

            ExportedDocuments.Add(DocumentData);
        }
        void ExportMetadata()
        {
            int DelayExport      = 2000;                // milliseconds
            int ExportBatchSize  = 1000;                // After each batch is exported, the process will wait for DelayExport and resume (unless cancelled)
            int CurrentBatchSize = 0;

            Func <FCachedDocumentData, bool> AddElements = (FCachedDocumentData CacheData) =>
            {
                while (CacheData.ElementsWithoutMetadata.Count > 0)
                {
                    if (CurrentBatchSize == ExportBatchSize)
                    {
                        // Add some delay before exporting next batch.
                        CurrentBatchSize = 0;

                        // Send metadata to DirectLink.
                        DatasmithScene.BuildScene(SceneName);
                        DatasmithDirectLink.UpdateScene(DatasmithScene);

                        MetadataEvent.WaitOne(DelayExport);
                    }

                    if (MetadataCancelToken.IsCancellationRequested)
                    {
                        return(false);
                    }

                    var Entry = CacheData.ElementsWithoutMetadata.Dequeue();

                    // Handle the case where element might be deleted in the main export path.
                    if (!CacheData.CachedElements.ContainsKey(Entry.Key))
                    {
                        continue;
                    }

                    Element RevitElement = CacheData.SourceDocument.GetElement(Entry.Key);

                    if (RevitElement == null)
                    {
                        continue;
                    }

                    FDocumentData.FBaseElementData ElementData = Entry.Value;
                    FDatasmithFacadeActor          Actor       = ElementData.ElementActor;

                    ElementData.ElementMetaData = new FDatasmithFacadeMetaData(Actor.GetName() + "_DATA");
                    ElementData.ElementMetaData.SetLabel(Actor.GetLabel());
                    ElementData.ElementMetaData.SetAssociatedElement(Actor);

                    FDocumentData.AddActorMetadata(RevitElement, ElementData.ElementMetaData);

                    ++CurrentBatchSize;

#if DEBUG
                    Debug.WriteLine($"metadata batch element {CurrentBatchSize}, remain in Q {CacheData.ElementsWithoutMetadata.Count}");
#endif
                }

                return(true);
            };

            List <FCachedDocumentData> CachesToExport = new List <FCachedDocumentData>();

            Action <FCachedDocumentData> GetLinkedDocuments = null;

            GetLinkedDocuments = (FCachedDocumentData InParent) =>
            {
                CachesToExport.Add(InParent);
                foreach (var Cache in InParent.LinkedDocumentsCache.Values)
                {
                    GetLinkedDocuments(Cache);
                }
            };

            GetLinkedDocuments(RootCache);

            foreach (var Cache in CachesToExport)
            {
                bool Success = AddElements(Cache);
                if (!Success)
                {
#if DEBUG
                    Debug.WriteLine("metadata cancelled");
#endif
                    return;                     // Metadata export was cancelled.
                }
            }

            if (CurrentBatchSize > 0)
            {
                // Send remaining chunk of metadata.
                DatasmithScene.BuildScene(SceneName);
                DatasmithDirectLink.UpdateScene(DatasmithScene);
            }

#if DEBUG
            Debug.WriteLine("metadata exported");
#endif
        }