コード例 #1
0
        /// <summary>
        /// Get Name from IfcDocumentInformation
        /// </summary>
        /// <param name="ifcDocumentInformation">Document Information Object</param>
        /// <returns>string or null</returns>
        private static string GetName(IIfcDocumentInformation ifcDocumentInformation)
        {
            if (ifcDocumentInformation == null)
            {
                return(null);
            }

            return(!string.IsNullOrEmpty(ifcDocumentInformation.Name) ?
                   ifcDocumentInformation.Name :
                   null);
        }
コード例 #2
0
        /// <summary>
        /// Get created by
        /// </summary>
        /// <param name="docInfo"></param>
        /// <returns></returns>
        private CobieCreatedInfo GetCreatedInfo(IIfcDocumentInformation docInfo)
        {
            if (docInfo.DocumentOwner != null)
            {
                return(Helper.GetCreatedInfo(docInfo.DocumentOwner));
            }

            //get owner from the IfcRelAssociatesDocument object
            return(Helper.DocumentOwnerLookup.ContainsKey(docInfo) ?
                   Helper.GetCreatedInfo(Helper.DocumentOwnerLookup[docInfo]) :
                   null);
        }
コード例 #3
0
        /// <summary>
        /// Get created by
        /// </summary>
        /// <param name="ifcDocumentInformation"></param>
        /// <returns></returns>
        private ContactKey GetCreatedBy(IIfcDocumentInformation ifcDocumentInformation)
        {
            if (ifcDocumentInformation.DocumentOwner != null)
            {
                return(Helper.GetCreatedBy(ifcDocumentInformation.DocumentOwner));
            }

            //get owner from the IfcRelAssociatesDocument object
            if (Helper.DocumentOwnerLookup.ContainsKey(ifcDocumentInformation))
            {
                return(Helper.GetCreatedBy(Helper.DocumentOwnerLookup[ifcDocumentInformation]));
            }
            return(null);
        }
コード例 #4
0
 public XbimReferencedModel(IIfcDocumentInformation documentInformation)
 {
     DocumentInformation = documentInformation;
     if (!File.Exists(documentInformation.Name))
     {
         throw new XbimException("Reference model not found:" + documentInformation.Name);
     }
     try
     {
         _model = IfcStore.Open(documentInformation.Name);
     }
     catch (Exception)
     {
         throw new XbimException("Unable to open reference model: " + documentInformation.Name);
     }
 }
コード例 #5
0
        /// <summary>
        /// Get createdOn
        /// </summary>
        /// <param name="ifcDocumentInformation"></param>
        /// <returns></returns>
        private DateTime?GetCreatedOn(IIfcDocumentInformation ifcDocumentInformation)
        {
            if (ifcDocumentInformation.CreationTime != null)
            {
                var created = ifcDocumentInformation.CreationTime ?? ifcDocumentInformation.LastRevisionTime;
                if (created.HasValue && created.Value != null) //appears that a true HasValue can have a null value????
                {
                    return(DateTime.Parse(created));
                }
            }

            if (Helper.DocumentOwnerLookup.ContainsKey(ifcDocumentInformation))
            {
                return(Helper.GetCreatedOn(Helper.DocumentOwnerLookup[ifcDocumentInformation]));
            }

            return(DateTime.Now);
        }
コード例 #6
0
        /// <summary>
        /// Convert a IfcDocumentReference to Document
        /// </summary>
        /// <param name="docReference">Document Reference Object</param>
        /// <param name="docInformation"></param>
        /// <returns>Document</returns>
        private CobieDocument ConvertToDocument(IIfcDocumentReference docReference, IIfcDocumentInformation docInformation)
        {
            var name = GetName(docInformation) ?? GetName(docReference);

            //fail to get from IfcDocumentReference, so try assign a default
            if (string.IsNullOrEmpty(name))
            {
                name = "Document";
            }
            //check for duplicates, if found add a (#) => "DocName(1)", if none return name unchanged
            name = Helper.GetNextName(name, UsedNames);


            var document = Exchanger.TargetRepository.Instances.New <CobieDocument>();

            document.Name    = name;
            document.Created = docInformation != null?GetCreatedInfo(docInformation) : null;

            document.DocumentType = (docInformation != null) && !string.IsNullOrEmpty(docInformation.Purpose) ?
                                    Helper.GetPickValue <CobieDocumentType>(docInformation.Purpose) :
                                    null;

            document.ApprovalType = (docInformation != null) && (!string.IsNullOrEmpty(docInformation.IntendedUse)) ?
                                    Helper.GetPickValue <CobieApprovalType>(docInformation.IntendedUse) :
                                    null; //once fixed

            document.Stage = (docInformation != null) && (!string.IsNullOrEmpty(docInformation.Scope)) ?
                             Helper.GetPickValue <CobieStageType>(docInformation.Scope) :
                             null;

            document.Directory = GetFileDirectory(docReference);
            document.File      = GetFileName(docReference);

            document.ExternalSystem = null;
            document.ExternalObject = Helper.GetExternalObject(docReference);
            document.ExternalId     = null;

            document.Description = (docInformation != null) && !string.IsNullOrEmpty(docInformation.Description) ? docInformation.Description.ToString() : null;
            document.Reference   = docInformation != null ? docInformation.Identification : null;

            UsedNames.Add(document.Name);
            return(document);
        }
コード例 #7
0
        /// <summary>
        /// Get the child documents with drill down into children of child....
        /// </summary>
        /// <param name="ifcDocumentInformation">IfcDocumentInformation</param>
        /// <returns>List of Document</returns>
        private List <Document> GetChildDocs(IIfcDocumentInformation ifcDocumentInformation)
        {
            List <Document> childDocList = new List <Document>();
            var             ChildRels    = ifcDocumentInformation.IsPointer.FirstOrDefault();//SET[0:1] gets the relationship when ifcDocumentInformation is the RelatingDocument (parent) document

            if (ChildRels != null && ChildRels.RelatedDocuments != null)
            {
                foreach (IIfcDocumentInformation item in ChildRels.RelatedDocuments)
                {
                    if (ChainInstMap == null) //set ChainInstMap, used to avoid infinite loop
                    {
                        ChainInstMap = new HashSet <IIfcDocumentInformation>();
                    }

                    if (!ChainInstMap.Contains(item))              //check we have not already evaluated this IfcDocumentInformation
                    {
                        childDocList.AddRange(MappingMulti(item)); //drill down
                    }
                }
            }
            return(childDocList);
        }
コード例 #8
0
        /// <summary>
        /// Convert a IfcDocumentReference to Document
        /// </summary>
        /// <param name="ifcDocumentReference">Document Reference Object</param>
        /// <param name="document">Document Object</param>
        /// <returns>Document</returns>
        private Document ConvertToDocument(IIfcDocumentReference ifcDocumentReference, IIfcDocumentInformation ifcDocumentInformation)
        {
            string name = GetName(ifcDocumentInformation) ?? GetName(ifcDocumentReference);

            //fail to get from IfcDocumentReference, so try assign a default
            if (string.IsNullOrEmpty(name))
            {
                name = "Document";
            }
            //check for duplicates, if found add a (#) => "DocName(1)", if none return name unchanged
            name = Helper.GetNextName(name, UsedNames);

            var document = new Document();

            document.Name      = name;
            document.CreatedBy = ifcDocumentInformation != null?GetCreatedBy(ifcDocumentInformation) : null;

            document.CreatedOn = ifcDocumentInformation != null?GetCreatedOn(ifcDocumentInformation) : null;

            document.Categories = (ifcDocumentInformation != null) && (!string.IsNullOrEmpty(ifcDocumentInformation.Purpose)) ? new List <Category>(new[] { new Category {
                                                                                                                                                                Code = ifcDocumentInformation.Purpose
                                                                                                                                                            } }) : null;

            document.ApprovalBy = (ifcDocumentInformation != null) && (!string.IsNullOrEmpty(ifcDocumentInformation.IntendedUse)) ? ifcDocumentInformation.IntendedUse : null; //once fixed

            document.Stage = (ifcDocumentInformation != null) && (!string.IsNullOrEmpty(ifcDocumentInformation.Scope)) ? ifcDocumentInformation.Scope : null;

            document.Directory = GetFileDirectory(ifcDocumentReference);
            document.File      = GetFileName(ifcDocumentReference);

            document.ExternalSystem = null;
            document.ExternalEntity = ifcDocumentReference.GetType().Name;
            document.ExternalId     = null;

            document.Description = (ifcDocumentInformation != null) && (!string.IsNullOrEmpty(ifcDocumentInformation.Description)) ? ifcDocumentInformation.Description.ToString() : null;
            document.Reference   = ifcDocumentInformation.Identification;

            UsedNames.Add(document.Name);
            return(document);
        }
コード例 #9
0
        public XbimReferencedModel(IIfcDocumentInformation documentInformation)
        {
            DocumentInformation = documentInformation;

            // for legacy purposes we should be able to load files from the name inside the document information
            // but the correct approach seems to be to have that data using the HasDocumentReferences property:
            // in the specs we read that
            // "The actual content of the document is not defined in IFC ; instead, it can be found following the reference given to IfcDocumentReference."
            //
            var searchPaths = new List <string>();

            if (documentInformation.Model is IfcStore)
            {
                var referencingStore = documentInformation.Model as IfcStore;
                var fi = new FileInfo(referencingStore.FileName);
                searchPaths.Add(fi.DirectoryName);
            }
            var headerFileName = documentInformation.Model?.Header?.FileName?.Name;

            if (Path.IsPathRooted(headerFileName))
            {
                searchPaths.Add(Path.GetDirectoryName(headerFileName));
            }

            // we will use the first valid document reference in a list that is evaluate as absolute or relative.
            //
            var candidates = DocumentInformation.HasDocumentReferences.Select(x => x.Location).ToList();

            candidates.Add(documentInformation.Name.ToString()); // this is for legacy in xbim federations

            string resourceReference = string.Empty;

            // evaluating absolute path
            foreach (var candidate in candidates)
            {
                var thisCandidate = candidate;
                // check if can be found as is
                if (File.Exists(thisCandidate))
                {
                    resourceReference = thisCandidate;
                    break;
                }
                // check if it can be relative
                if (!Path.IsPathRooted(candidate))
                {
                    foreach (var path in searchPaths)
                    {
                        thisCandidate = Path.Combine(
                            path, candidate
                            );
                        if (File.Exists(thisCandidate))
                        {
                            resourceReference = thisCandidate;
                            goto StopSearch;
                        }
                    }
                }
            }

StopSearch:
            if (string.IsNullOrEmpty(resourceReference))
            {
                throw new XbimException($"Reference model not found for IfcDocumentInformation #{documentInformation.EntityLabel}.");
            }
            try
            {
                _model = IfcStore.Open(resourceReference);
            }
            catch (Exception ex)
            {
                throw new XbimException("Error opening referenced model: " + resourceReference, ex);
            }
        }