Beispiel #1
0
        /// <summary>
        /// Generates the name for the element to be created.
        /// </summary>
        /// <param name="baseName">If not null, generates a name if Name is invalid.</param>
        /// <returns>The name.</returns>
        protected string GetName(string baseName)
        {
            if (string.IsNullOrWhiteSpace(Name))
            {
                if (!string.IsNullOrWhiteSpace(baseName))
                {
                    return(baseName + " " + Id);
                }
                return(null);
            }

            return(IFCNamingUtil.CleanIFCName(Name));
        }
        private static string GetMaterialName(int id, string originalName)
        {
            // Disallow creating multiple materials with the same name.  This means that the
            // same material, with different styles, will be created with different names.
            string materialName = Importer.TheCache.CreatedMaterials.GetUniqueMaterialName(originalName, id);

            string revitMaterialName = IFCNamingUtil.CleanIFCName(materialName);

            if (revitMaterialName != null)
            {
                return(revitMaterialName);
            }

            return(String.Format(Resources.IFCDefaultMaterialName, id));
        }
Beispiel #3
0
        /// <summary>
        /// Does a top-level check to see if this entity may be equivalent to otherEntity.
        /// </summary>
        /// <param name="otherEntity">The other IFCEntity.</param>
        /// <returns>True if they are equivalent, false if they aren't, null if not enough information.</returns>
        /// <remarks>This isn't intended to be an exhaustive check, and isn't implemented for all types.  This is intended
        /// to be used by derived classes.</remarks>
        public override bool?MaybeEquivalentTo(IFCEntity otherEntity)
        {
            bool?maybeEquivalentTo = base.MaybeEquivalentTo(otherEntity);

            if (maybeEquivalentTo.HasValue)
            {
                return(maybeEquivalentTo.Value);
            }

            if (!(otherEntity is IFCPresentationLayerAssignment))
            {
                return(false);
            }

            IFCPresentationLayerAssignment other = otherEntity as IFCPresentationLayerAssignment;

            if (!IFCNamingUtil.SafeStringsAreEqual(Name, other.Name))
            {
                return(false);
            }

            if (!IFCNamingUtil.SafeStringsAreEqual(Description, other.Description))
            {
                return(false);
            }

            if (!IFCEntity.AreIFCEntityListsEquivalent(AssignedItems, other.AssignedItems))
            {
                return(false);
            }

            if (!IFCNamingUtil.SafeStringsAreEqual(Identifier, other.Identifier))
            {
                return(false);
            }

            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// Create a schedule for a given property set.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The element being created.</param>
        /// <param name="category">The category of the element.</param>
        /// <param name="parameterGroupMap">The parameters of the element.  Cached for performance.</param>
        /// <param name="parametersCreated">The created parameters.</param>
        protected void CreateScheduleForPropertySet(Document doc, Element element, Category category,
                                                    IFCParameterSetByGroup parameterGroupMap, ISet <string> parametersCreated)
        {
            // Don't bother creating schedules if we are maximizing performance.
            if (IFCImportFile.TheFile.Options.UseStreamlinedOptions)
            {
                return;
            }

            if (parametersCreated.Count == 0)
            {
                return;
            }

            if (category == null)
            {
                return;
            }

            ElementId categoryId    = category.Id;
            bool      elementIsType = (element is ElementType);

            string cleanName = IFCNamingUtil.CleanIFCName(Name);
            Tuple <ElementId, bool, string> scheduleKey = Tuple.Create(categoryId, elementIsType, cleanName);

            ISet <string> viewScheduleNames = Importer.TheCache.ViewScheduleNames;
            IDictionary <Tuple <ElementId, bool, string>, ElementId> viewSchedules = Importer.TheCache.ViewSchedules;

            ElementId viewScheduleId;

            if (!viewSchedules.TryGetValue(scheduleKey, out viewScheduleId))
            {
                string scheduleName     = scheduleKey.Item3;
                string scheduleTypeName = elementIsType ? " " + Resources.IFCTypeSchedule : string.Empty;

                int index = 1;
                while (viewScheduleNames.Contains(scheduleName))
                {
                    string indexString = (index > 1) ? " " + index.ToString() : string.Empty;
                    scheduleName += " (" + category.Name + scheduleTypeName + indexString + ")";
                    index++;
                    if (index > 1000)
                    {
                        Importer.TheLog.LogWarning(Id, "Too many property sets with the name " + scheduleKey.Item3 +
                                                   ", no longer creating schedules with that name.", true);
                        return;
                    }
                }

                // Not all categories allow creating schedules.  Skip these.
                ViewSchedule viewSchedule = null;
                try
                {
                    viewSchedule = ViewSchedule.CreateSchedule(doc, scheduleKey.Item1);
                }
                catch
                {
                    // Only try to create the schedule once per key.
                    viewSchedules[scheduleKey] = ElementId.InvalidElementId;
                    return;
                }

                if (viewSchedule != null)
                {
                    viewSchedule.Name          = scheduleName;
                    viewSchedules[scheduleKey] = viewSchedule.Id;
                    viewScheduleNames.Add(scheduleName);

                    ElementId ifcGUIDId           = new ElementId(elementIsType ? BuiltInParameter.IFC_TYPE_GUID : BuiltInParameter.IFC_GUID);
                    string    propertySetListName = elementIsType ? Resources.IFCTypeSchedule + " IfcPropertySetList" : "IfcPropertySetList";

                    ScheduleDefinition       viewScheduleDefinition = viewSchedule.Definition;
                    IList <SchedulableField> schedulableFields      = viewScheduleDefinition.GetSchedulableFields();

                    bool filtered = false;
                    foreach (SchedulableField sf in schedulableFields)
                    {
                        string fieldName = sf.GetName(doc);
                        if (parametersCreated.Contains(fieldName) || sf.ParameterId == ifcGUIDId)
                        {
                            viewScheduleDefinition.AddField(sf);
                        }
                        else if (!filtered && fieldName == propertySetListName)
                        {
                            // We want to filter the schedule for specifically those elements that have this property set assigned.
                            ScheduleField scheduleField = viewScheduleDefinition.AddField(sf);
                            scheduleField.IsHidden = true;
                            ScheduleFilter filter = new ScheduleFilter(scheduleField.FieldId, ScheduleFilterType.Contains, "\"" + Name + "\"");
                            viewScheduleDefinition.AddFilter(filter);
                            filtered = true;
                        }
                    }
                }
            }

            return;
        }