Inheritance: BaseClassIfc
        public List <T> Extract <T>() where T : IBaseClassIfc
        {
            List <T>         extracted = Extract <T>(typeof(T));
            HashSet <string> rootIds   = new HashSet <string>();
            List <T>         result    = new List <T>(extracted.Count);

            foreach (T t in extracted)
            {
                if (t is IfcRoot)
                {
                    IfcRoot root     = (IfcRoot)(IBaseClassIfc)t;
                    string  globalId = root.GlobalId;
                    if (rootIds.Contains(globalId))
                    {
                        continue;
                    }
                    rootIds.Add(globalId);
                }
                result.Add(t);
            }
            return(result);
        }
 public BaseClassIfc this[int index]
 {
     get { return(index < mIfcObjects.Count ? mIfcObjects[index] : null); }
     set
     {
         IfcRoot root = this[index] as IfcRoot;
         if (root != null)
         {
             mGlobalIDs.Remove(root.GlobalId);
         }
         if (value == null)
         {
             if (mIfcObjects.Count > index)
             {
                 mIfcObjects[index] = null;
             }
             if (index < mNextBlank && index > 0)
             {
                 mNextBlank = index;
             }
             return;
         }
         if (mIfcObjects.Count <= index)
         {
             for (int ncounter = mIfcObjects.Count; ncounter <= index; ncounter++)
             {
                 mIfcObjects.Add(null);
             }
         }
         mIfcObjects[index] = value;
         if (index == mNextBlank)
         {
             mNextBlank = mNextBlank + 1;
         }
         value.mDatabase = this;
         value.mIndex    = index;
     }
 }
        protected void ReplaceDatabase(BaseClassIfc revised)
        {
            IfcRoot thisRoot = this as IfcRoot, revisedRoot = revised as IfcRoot;

            if (thisRoot != null && revisedRoot != null)
            {
                revisedRoot.GlobalId     = thisRoot.GlobalId;
                revisedRoot.OwnerHistory = thisRoot.OwnerHistory;
                revisedRoot.Name         = thisRoot.Name;
                revisedRoot.Description  = thisRoot.Description;
                IfcObjectDefinition thisObjectDefinition = this as IfcObjectDefinition, revisedObjectDefinition = revised as IfcObjectDefinition;
                if (thisObjectDefinition != null && revisedObjectDefinition != null)
                {
                    foreach (IfcRelAggregates rel in thisObjectDefinition.IsDecomposedBy.ToList())
                    {
                        rel.RelatingObject = revisedObjectDefinition;
                    }
                    foreach (IfcRelNests rel in thisObjectDefinition.IsNestedBy.ToList())
                    {
                        rel.RelatingObject = revisedObjectDefinition;
                    }

                    IfcRelAggregates relAggregates = thisObjectDefinition.Decomposes;
                    if (relAggregates != null)
                    {
                        relAggregates.RelatedObjects.Remove(thisObjectDefinition);
                        relAggregates.RelatedObjects.Add(revisedObjectDefinition);
                    }
                    IfcRelNests relNests = thisObjectDefinition.Nests;
                    if (relNests != null)
                    {
                        relNests.RelatedObjects.Remove(thisObjectDefinition);
                        relNests.RelatedObjects.Add(thisObjectDefinition);
                    }

                    foreach (IfcRelDefinesByProperties relDefinesByProperties in thisObjectDefinition.mIsDefinedBy.ToList())
                    {
                        relDefinesByProperties.RelatedObjects.Remove(thisObjectDefinition);
                        relDefinesByProperties.RelatedObjects.Add(revisedObjectDefinition);
                    }

                    foreach (IfcRelAssigns assigns in thisObjectDefinition.HasAssignments.ToList())
                    {
                        assigns.RelatedObjects.Remove(thisObjectDefinition);
                        assigns.RelatedObjects.Add(revisedObjectDefinition);
                    }
                    IfcRelDeclares relDeclares = thisObjectDefinition.HasContext;
                    if (relDeclares != null)
                    {
                        relDeclares.RelatedDefinitions.Remove(thisObjectDefinition);
                        relDeclares.RelatedDefinitions.Add(revisedObjectDefinition);
                    }
                    foreach (IfcRelAssociates associates in thisObjectDefinition.HasAssociations.ToList())
                    {
                        associates.RelatedObjects.Remove(thisObjectDefinition);
                        associates.RelatedObjects.Add(revisedObjectDefinition);
                    }
                    IfcObject thisObject = this as IfcObject, revisedObject = revised as IfcObject;
                    if (thisObject != null && revisedObject != null)
                    {
                        if (!string.IsNullOrEmpty(thisObject.ObjectType))
                        {
                            revisedObject.ObjectType = thisObject.ObjectType;
                        }

                        if (thisObject.mIsTypedBy != null)
                        {
                            thisObject.mIsTypedBy.mRelatedObjects.Remove(thisObject);
                        }
                        IfcProduct thisProduct = this as IfcProduct, revisedProduct = revised as IfcProduct;
                        if (thisProduct != null && revisedProduct != null)
                        {
                            IfcRelContainedInSpatialStructure containedInSpatialStructure = thisProduct.mContainedInStructure;
                            if (containedInSpatialStructure != null)
                            {
                                containedInSpatialStructure.RelatedElements.Remove(thisProduct);
                                containedInSpatialStructure.RelatedElements.Add(revisedProduct);
                            }
                            IfcElement thisElement = this as IfcElement, revisedElement = revised as IfcElement;
                            if (thisElement != null && revisedElement != null)
                            {
                                revisedElement.Tag = thisElement.Tag;
                                List <IfcRelVoidsElement> voids = thisElement.HasOpenings.ToList();
                                foreach (var relVoids in voids)
                                {
                                    relVoids.RelatingBuildingElement = revisedElement;
                                }
                            }
                            IfcSpatialElement thisSpatial = this as IfcSpatialElement, revisedSpatial = revised as IfcSpatialElement;
                            if (thisSpatial != null && revisedSpatial != null)
                            {
                                foreach (IfcRelContainedInSpatialStructure contained in thisSpatial.ContainsElements.ToList())
                                {
                                    contained.RelatingStructure = revisedSpatial;
                                }
                            }
                            else if (revisedSpatial != null && thisElement != null)
                            {
                                if (containedInSpatialStructure != null)
                                {
                                    containedInSpatialStructure.RelatedElements.Remove(revisedProduct);
                                    containedInSpatialStructure.RelatingStructure.AddAggregated(revisedProduct);
                                }
                                List <IfcProduct> subProducts = thisObjectDefinition.IsDecomposedBy.SelectMany(x => x.RelatedObjects).OfType <IfcProduct>().ToList();
                                if (subProducts.Count > 0)
                                {
                                    new IfcRelContainedInSpatialStructure(subProducts, revisedSpatial);
                                }
                                foreach (IfcRelAssociatesMaterial associates in revisedSpatial.HasAssociations.OfType <IfcRelAssociatesMaterial>().ToList())
                                {
                                    associates.RelatedObjects.Remove(revisedSpatial);
                                }

                                IfcFacilityPart facilityPart = revisedSpatial as IfcFacilityPart;
                                if (facilityPart != null)
                                {
                                    IfcFacility facility = revisedSpatial.FindHost <IfcFacility>();
                                    if (facility != null)
                                    {
                                        facility.AddAggregated(revisedSpatial);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        IfcTypeObject thisTypeObject = this as IfcTypeObject, revisedTypeObject = revised as IfcTypeObject;
                        if (thisTypeObject != null && revisedTypeObject != null)
                        {
                            IfcTypeProduct thisTypeProduct = this as IfcTypeProduct, revisedTypeProduct = revised as IfcTypeProduct;
                            if (thisTypeProduct != null && revisedTypeProduct != null)
                            {
                                revisedTypeProduct.Tag = thisTypeProduct.Tag;
                                IfcElementType thisElementType = this as IfcElementType, revisedElementType = revised as IfcElementType;
                                if (thisElementType != null && revisedElementType != null)
                                {
                                    revisedElementType.ElementType = thisElementType.ElementType;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                IfcRepresentationItem representationItem = this as IfcRepresentationItem, revisedItem = revised as IfcRepresentationItem;
                if (representationItem != null && revisedItem != null)
                {
                    IfcStyledItem styledItem = representationItem.StyledByItem;
                    if (styledItem != null)
                    {
                        styledItem.Item = revisedItem;
                    }

                    foreach (IfcShapeModel shapeModel in representationItem.Represents.ToList())
                    {
                        shapeModel.Items.Remove(representationItem);
                        shapeModel.Items.Add(revisedItem);
                    }
                    IfcPresentationLayerAssignment layerAssignment = representationItem.mLayerAssignment;
                    if (layerAssignment != null)
                    {
                        layerAssignment.AssignedItems.Remove(representationItem);
                        layerAssignment.AssignedItems.Add(revisedItem);
                    }
                }
            }
            mDatabase[revised.mStepId] = null;
            revised.mStepId            = StepId;
            mDatabase[StepId]          = revised;
        }
Example #4
0
        public T ParseJObject <T>(JObject obj) where T : IBaseClassIfc
        {
            if (obj == null)
            {
                return(default(T));
            }

            BaseClassIfc result = null;
            JToken       token  = obj.GetValue("href", StringComparison.InvariantCultureIgnoreCase);

            if (token != null)
            {
                mDictionary.TryGetValue(token.Value <string>(), out result);
                if (result != null && obj.Count == 1)
                {
                    return((T)(IBaseClassIfc)result);
                }
            }
            if (result == null)
            {
                Type type = null;
                token = obj.GetValue("type", StringComparison.InvariantCultureIgnoreCase);
                if (token != null)
                {
                    string keyword = token.Value <string>();
                    type = Type.GetType("GeometryGym.Ifc." + keyword, false, true);
                }
                if (token == null)
                {
                    type = typeof(T);
                }
                if (type != null)
                {
                    if (type.IsAbstract)
                    {
                        JProperty jtoken    = (JProperty)obj.First;
                        Type      valueType = Type.GetType("GeometryGym.Ifc." + jtoken.Name, false, true);
                        if (valueType != null && valueType.IsSubclassOf(typeof(IfcValue)))
                        {
                            return((T)(IBaseClassIfc)ParserIfc.extractValue(jtoken.Name, jtoken.Value.ToString()));
                        }
                    }
                    else
                    {
                        ConstructorInfo constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
                                                                          null, Type.EmptyTypes, null);
                        if (constructor != null)
                        {
                            bool common = false;
                            result = constructor.Invoke(new object[] { }) as BaseClassIfc;
                            if (result != null)
                            {
                                result.mDatabase = this;

                                IfcCartesianPoint point = result as IfcCartesianPoint;
                                if (point != null)
                                {
                                    point.parseJObject(obj);
                                    if (point.isOrigin)
                                    {
                                        if (point.is2D)
                                        {
                                            result = Factory.Origin2d;
                                        }
                                        else
                                        {
                                            result = Factory.Origin;
                                        }
                                        common = true;
                                    }
                                }
                                else
                                {
                                    IfcDirection direction = result as IfcDirection;
                                    if (direction != null)
                                    {
                                        direction.parseJObject(obj);
                                        if (!direction.is2D)
                                        {
                                            common = true;
                                            if (direction.isXAxis)
                                            {
                                                result = Factory.XAxis;
                                            }
                                            else if (direction.isYAxis)
                                            {
                                                result = Factory.YAxis;
                                            }
                                            else if (direction.isZAxis)
                                            {
                                                result = Factory.ZAxis;
                                            }
                                            else if (direction.isXAxisNegative)
                                            {
                                                result = Factory.XAxisNegative;
                                            }
                                            else if (direction.isYAxisNegative)
                                            {
                                                result = Factory.YAxisNegative;
                                            }
                                            else if (direction.isZAxisNegative)
                                            {
                                                result = Factory.ZAxisNegative;
                                            }
                                            else
                                            {
                                                common = false;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        IfcAxis2Placement3D placement = result as IfcAxis2Placement3D;
                                        if (placement != null)
                                        {
                                            placement.parseJObject(obj);
                                            if (placement.IsXYPlane)
                                            {
                                                result = Factory.XYPlanePlacement;
                                                common = true;
                                            }
                                        }
                                    }
                                }
                                token = obj.GetValue("id", StringComparison.InvariantCultureIgnoreCase);
                                if (token != null)
                                {
                                    string id = token.Value <string>();
                                    if (!(result is IfcRoot))
                                    {
                                        result.mGlobalId = id;
                                    }
                                    mDictionary.TryAdd(id, result);
                                }

                                if (common)
                                {
                                    return((T)(IBaseClassIfc)result);
                                }

                                int index = NextBlank();
                                this[index] = result;
                            }
                        }
                    }
                }
            }
            if (result == null)
            {
                return(default(T));
            }
            result.parseJObject(obj);
            parseBespoke(result, obj);
            IfcRoot root = result as IfcRoot;

            if (root != null)
            {
                mDictionary[root.GlobalId] = root;
            }
            return((T)(IBaseClassIfc)result);
        }
Example #5
0
 protected static void parseFields(IfcObjectDefinition objDef, List <string> arrFields, ref int ipos)
 {
     IfcRoot.parseFields(objDef, arrFields, ref ipos);
 }
Example #6
0
		protected static void parseFields(IfcRoot root, List<string> arrFields, ref int ipos)
		{
			root.mGlobalId = arrFields[ipos++].Replace("'", "");
			root.mOwnerHistory = ParserSTEP.ParseLink(arrFields[ipos++]);
			root.mName = arrFields[ipos++].Replace("'", "");
			root.mDescription = arrFields[ipos++].Replace("'", "");
		}
Example #7
0
		protected IfcRoot(IfcRoot r) : base(r) { mGlobalId = r.mGlobalId; mOwnerHistory = r.mOwnerHistory; mName = r.mName; mDescription = r.mDescription; }
        protected void ReplaceDatabase(BaseClassIfc revised)
        {
            IfcRoot thisRoot = this as IfcRoot, revisedRoot = revised as IfcRoot;

            if (thisRoot != null && revisedRoot != null)
            {
                revisedRoot.GlobalId     = thisRoot.GlobalId;
                revisedRoot.OwnerHistory = thisRoot.OwnerHistory;
                revisedRoot.Name         = thisRoot.Name;
                revisedRoot.Description  = thisRoot.Description;
                IfcObjectDefinition thisObjectDefinition = this as IfcObjectDefinition, revisedObjectDefinition = revised as IfcObjectDefinition;
                if (thisObjectDefinition != null && revisedObjectDefinition != null)
                {
                    foreach (IfcRelAggregates rel in thisObjectDefinition.IsDecomposedBy.ToList())
                    {
                        rel.RelatingObject = revisedObjectDefinition;
                    }
                    foreach (IfcRelNests rel in thisObjectDefinition.IsNestedBy.ToList())
                    {
                        rel.RelatingObject = revisedObjectDefinition;
                    }

                    foreach (IfcRelAssigns assigns in thisObjectDefinition.HasAssignments.ToList())
                    {
                        assigns.RelatedObjects.Remove(thisObjectDefinition);
                        assigns.RelatedObjects.Add(revisedObjectDefinition);
                    }
                    IfcRelDeclares relDeclares = thisObjectDefinition.HasContext;
                    if (relDeclares != null)
                    {
                        relDeclares.RelatedDefinitions.Remove(thisObjectDefinition);
                        relDeclares.RelatedDefinitions.Add(revisedObjectDefinition);
                    }
                    foreach (IfcRelAssociates associates in thisObjectDefinition.HasAssociations.ToList())
                    {
                        associates.RelatedObjects.Remove(thisObjectDefinition);
                        associates.RelatedObjects.Add(revisedObjectDefinition);
                    }
                    IfcObject thisObject = this as IfcObject, revisedObject = revised as IfcObject;
                    if (thisObject != null && revisedObject != null)
                    {
                        revisedObject.ObjectType = thisObject.ObjectType;

                        if (thisObject.mIsTypedBy != null)
                        {
                            thisObject.mIsTypedBy.mRelatedObjects.Remove(thisObject);
                        }
                        IfcProduct thisProduct = this as IfcProduct, revisedProduct = revised as IfcProduct;
                        if (thisProduct != null && revisedProduct != null)
                        {
                            thisProduct.detachFromHost();
                            IfcElement thisElement = this as IfcElement, revisedElement = revised as IfcElement;
                            if (thisElement != null && revisedElement != null)
                            {
                                revisedElement.Tag = thisElement.Tag;
                            }
                        }
                    }
                    else
                    {
                        IfcTypeObject thisTypeObject = this as IfcTypeObject, revisedTypeObject = revised as IfcTypeObject;
                        if (thisTypeObject != null && revisedTypeObject != null)
                        {
                            IfcTypeProduct thisTypeProduct = this as IfcTypeProduct, revisedTypeProduct = revised as IfcTypeProduct;
                            if (thisTypeProduct != null && revisedTypeProduct != null)
                            {
                                revisedTypeProduct.Tag = thisTypeProduct.Tag;
                                IfcElementType thisElementType = this as IfcElementType, revisedElementType = revised as IfcElementType;
                                if (thisElementType != null && revisedElementType != null)
                                {
                                    revisedElementType.ElementType = thisElementType.ElementType;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                IfcRepresentationItem representationItem = this as IfcRepresentationItem, revisedItem = revised as IfcRepresentationItem;
                if (representationItem != null && revisedItem != null)
                {
                    IfcStyledItem styledItem = representationItem.StyledByItem;
                    if (styledItem != null)
                    {
                        styledItem.Item = revisedItem;
                    }

                    foreach (IfcShapeModel shapeModel in representationItem.mRepresents.ToList())
                    {
                        shapeModel.Items.Remove(representationItem);
                        shapeModel.Items.Add(revisedItem);
                    }
                    IfcPresentationLayerAssignment layerAssignment = representationItem.mLayerAssignment;
                    if (layerAssignment != null)
                    {
                        layerAssignment.AssignedItems.Remove(representationItem);
                        layerAssignment.AssignedItems.Add(revisedItem);
                    }
                }
            }
            mDatabase[revised.mIndex] = null;
            revised.mIndex            = mIndex;
            mDatabase[mIndex]         = revised;
        }
		public T ParseJObject<T>(JObject obj) where T : IBaseClassIfc
		{
			if (obj == null)
				return default(T);

			Type type = typeof(T);
			
			BaseClassIfc result = null;
			JToken token = obj.GetValue("href", StringComparison.InvariantCultureIgnoreCase);
			if (token != null)
			{
				string hrefId = token.Value<string>();
				if(mDictionary.TryGetValue(hrefId, out result) && obj.Count == 1)
					return (T)(IBaseClassIfc)result;
			}
			if (result == null)
			{
				if (type.IsAbstract)
				{
					JProperty jtoken = (JProperty)obj.First;
					Type valueType = BaseClassIfc.GetType(jtoken.Name);
					if (valueType != null && valueType.IsSubclassOf(typeof(IfcValue)))
					{
						IBaseClassIfc val = ParserIfc.extractValue(jtoken.Name, jtoken.Value.ToString()) as IBaseClassIfc;
						if (val != null)
							return (T)val;
						return default(T);
					}
				}
				else
				{
					token = obj.GetValue("type", StringComparison.InvariantCultureIgnoreCase);
					if(token != null)
					{
						Type nominatedType = BaseClassIfc.GetType(token.Value<string>());
						if (nominatedType != null)
							type = nominatedType;
					}
					string hrefId = "";
					token = obj.GetValue("id", StringComparison.InvariantCultureIgnoreCase);
					if (token != null)
						hrefId = token.Value<string>();
					if (string.IsNullOrEmpty(hrefId) || !mDictionary.TryGetValue(hrefId, out result))
					{
						ConstructorInfo constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
		null, Type.EmptyTypes, null);
						if (constructor != null)
						{
							bool common = false;
							result = constructor.Invoke(new object[] { }) as BaseClassIfc;
							if (result != null)
							{
								result.mDatabase = this;

								IfcCartesianPoint point = result as IfcCartesianPoint;
								if (point != null)
								{
									point.parseJObject(obj);
									if (point.isOrigin(Tolerance))
									{
										if (point.is2D)
											result = Factory.Origin2d;
										else
											result = Factory.Origin;
										common = true;
									}
								}
								else
								{
									IfcDirection direction = result as IfcDirection;
									if (direction != null)
									{
										direction.parseJObject(obj);
										if (!direction.is2D)
										{
											common = true;
											if (direction.isXAxis)
												result = Factory.XAxis;
											else if (direction.isYAxis)
												result = Factory.YAxis;
											else if (direction.isZAxis)
												result = Factory.ZAxis;
											else if (direction.isXAxisNegative)
												result = Factory.XAxisNegative;
											else if (direction.isYAxisNegative)
												result = Factory.YAxisNegative;
											else if (direction.isZAxisNegative)
												result = Factory.ZAxisNegative;
											else
												common = false;
										}
									}
									else
									{
										IfcAxis2Placement3D placement = result as IfcAxis2Placement3D;
										if (placement != null)
										{
											placement.parseJObject(obj);
											if (placement.IsXYPlane(Tolerance))
											{
												result = Factory.XYPlanePlacement;
												common = true;
											}
										}
									}
								}
								token = obj.GetValue("id", StringComparison.InvariantCultureIgnoreCase);
								if (!string.IsNullOrEmpty(hrefId))
								{
									if (!(result is IfcRoot))
										result.setGlobalId(hrefId);
									mDictionary.TryAdd(hrefId, result);
								}

								if (common)
									return (T)(IBaseClassIfc)result;

								int index = NextBlank();
								this[index] = result;
							}
						}
					}
				}
			}
			if(result == null)
				return default(T);
			result.parseJObject(obj);
			parseBespoke(result, obj);
			IfcRoot root = result as IfcRoot;
			if (root != null)
				mDictionary[root.GlobalId] = root;
			return (T)(IBaseClassIfc)result;
		}