public IfcGeometricRepresentationContext GeometricRepresentationContext(ContextIdentifier nature) { IfcGeometricRepresentationContext result = null; if (mContexts.TryGetValue(nature, out result)) { return(result); } string type = "Model"; int dimension = 3; if (nature == ContextIdentifier.Annotation) { type = "Annotation"; } result = new IfcGeometricRepresentationContext(mDatabase, dimension, mDatabase.Tolerance) { ContextType = type }; IfcContext context = mDatabase.Context; if (context != null) { context.addRepresentationContext(result); } mContexts.Add(nature, result); return(result); }
public XmlDocument XmlDocument() { XmlDocument doc = new XmlDocument(); XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes"); doc.AppendChild(dec); XmlElement el = doc.CreateElement("ifcXML", mXmlNamespace); doc.AppendChild(el); XmlAttribute schemaLocation = doc.CreateAttribute("xsi", "schemaLocation", mXsiNamespace); schemaLocation.Value = mXmlSchema; el.SetAttributeNode(schemaLocation); Dictionary <string, XmlElement> processed = new Dictionary <string, XmlElement>(); IfcContext context = Context; if (context != null) { el.AppendChild(Context.GetXML(doc, "", null, processed)); } List <BaseClassIfc> toProcess = new List <BaseClassIfc>(); foreach (BaseClassIfc e in this) { string id = e.xmlId(); if (!processed.ContainsKey(id)) { if (e is IfcRelationship) { el.AppendChild(e.GetXML(doc, "", null, processed)); } else { toProcess.Add(e); } } } foreach (BaseClassIfc e in toProcess) { string id = e.xmlId(); if (!processed.ContainsKey(id)) { el.AppendChild(e.GetXML(doc, "", null, processed)); } } return(doc); }
public JObject ToJSON(string filename) { CultureInfo current = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); JObject ifcFile = new JObject(); JObject header = new JObject(); JObject fileDescription = new JObject(); fileDescription["description"] = "ViewDefinition[" + viewDefinition + "]"; fileDescription["implementation_level"] = "2;1"; header["FILE_DESCRIPTION"] = fileDescription; JObject fileName = new JObject(); fileName["name"] = filename; DateTime now = DateTime.Now; fileName["time_stamp"] = now.Year + "-" + (now.Month < 10 ? "0" : "") + now.Month + "-" + (now.Day < 10 ? "0" : "") + now.Day + "T" + (now.Hour < 10 ? "0" : "") + now.Hour + ":" + (now.Minute < 10 ? "0" : "") + now.Minute + ":" + (now.Second < 10 ? "0" : "") + now.Second; fileName["author"] = System.Environment.UserName; fileName["organization"] = IfcOrganization.Organization; fileName["preprocessor_version"] = mFactory.ToolkitName; fileName["originating_system"] = Factory.ApplicationFullName; fileName["authorization"] = "None"; header["FILE_NAME"] = fileName; JObject fileSchema = new JObject(); fileSchema["schema_identifiers"] = mRelease == ReleaseVersion.IFC2x3 ? "IFC2X3" : "IFC4"; header["FILE_SCHEMA"] = fileSchema; ifcFile["HEADER"] = header; IfcContext context = this.mContext; JObject jcontext = context.getJson(null, new HashSet <int>()); //null);// JArray data = new JArray(); data.Add(jcontext); ifcFile["DATA"] = data; if (!string.IsNullOrEmpty(filename)) { StreamWriter sw = new StreamWriter(filename); sw.Write(ifcFile.ToString()); sw.Close(); } Thread.CurrentThread.CurrentUICulture = current; return(ifcFile); }
public JObject ToJSON(string filename) { CultureInfo current = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); JObject ifcFile = new JObject(); JObject header = new JObject(); JObject fileDescription = new JObject(); fileDescription["description"] = "ViewDefinition[" + viewDefinition + "]"; fileDescription["implementation_level"] = "2;1"; header["FILE_DESCRIPTION"] = fileDescription; JObject fileName = new JObject(); fileName["name"] = filename; DateTime now = DateTime.Now; fileName["time_stamp"] = now.Year + "-" + (now.Month < 10 ? "0" : "") + now.Month + "-" + (now.Day < 10 ? "0" : "") + now.Day + "T" + (now.Hour < 10 ? "0" : "") + now.Hour + ":" + (now.Minute < 10 ? "0" : "") + now.Minute + ":" + (now.Second < 10 ? "0" : "") + now.Second; fileName["author"] = System.Environment.UserName; fileName["organization"] = IfcOrganization.Organization; fileName["preprocessor_version"] = mFactory.ToolkitName; fileName["originating_system"] = Factory.ApplicationFullName; fileName["authorization"] = "None"; header["FILE_NAME"] = fileName; JObject fileSchema = new JObject(); fileSchema["schema_identifiers"] = mRelease == ReleaseVersion.IFC2x3 ? "IFC2X3" : "IFC4"; header["FILE_SCHEMA"] = fileSchema; ifcFile["HEADER"] = header; JArray data = new JArray(); IfcContext context = this.mContext; BaseClassIfc.SetJsonOptions options = new BaseClassIfc.SetJsonOptions() { LengthDigitCount = mLengthDigits, Version = this.Release }; if (context != null) { JObject jcontext = context.getJson(null, options); //null);// data.Add(jcontext); } if (context == null || (context.mIsDecomposedBy.Count == 0 && context.Declares.Count == 0)) { foreach (BaseClassIfc e in this) { if (!string.IsNullOrEmpty(e.mGlobalId)) { if (!options.Encountered.Contains(e.mGlobalId)) { data.Add(e.getJson(null, options)); } } else { NamedObjectIfc named = e as NamedObjectIfc; if (named != null) { data.Add(named.getJson(null, options)); } } } } ifcFile["DATA"] = data; if (!string.IsNullOrEmpty(filename)) { StreamWriter sw = new StreamWriter(filename); #if (DEBUG) sw.Write(ifcFile.ToString()); #else sw.Write(ifcFile.ToString(Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonConverter[0])); #endif sw.Close(); } Thread.CurrentThread.CurrentUICulture = current; return(ifcFile); }
internal BaseClassIfc InterpretLine(string line) { if (line.StartsWith("ISO")) { return(null); } string ts = line.Trim().Replace(" ", ""); if (ts.StartsWith("FILE_SCHEMA(('IFC2X4", true, System.Globalization.CultureInfo.CurrentCulture) || ts.StartsWith("FILE_SCHEMA(('IFC4", true, System.Globalization.CultureInfo.CurrentCulture)) { mRelease = ReleaseVersion.IFC4; return(null); } BaseClassIfc result = ParserIfc.ParseLine(line, mRelease); if (result == null) { int ifcID = 0; string kw = "", str = ""; ParserIfc.GetKeyWord(line, out ifcID, out kw, out str); if (string.IsNullOrEmpty(kw)) { return(null); } result = new BaseClassIfc(ifcID, kw, str); } if (result == null) { return(null); } IfcApplication application = result as IfcApplication; if (application != null) { IfcApplication ea = mFactory.mApplication; if (ea != null && ea.mVersion == application.mVersion) { if (string.Compare(ea.ApplicationFullName, application.ApplicationFullName, true) == 0) { if (string.Compare(ea.mApplicationIdentifier, application.mApplicationIdentifier) == 0) { mIfcObjects[ea.mIndex] = null; mFactory.mApplication = application; mFactory.OwnerHistory(IfcChangeActionEnum.ADDED).mLastModifyingApplication = application.mIndex; if (mFactory.mOwnerHistoryModify != null) { mFactory.mOwnerHistoryModify.mLastModifyingApplication = application.mIndex; } } } } } IfcContext context = result as IfcContext; if (context != null) { mContext = context; } IfcGeometricRepresentationContext geometricRepresentationContext = result as IfcGeometricRepresentationContext; if (geometricRepresentationContext != null) { if (string.Compare(geometricRepresentationContext.mContextType, "Plan", true) != 0) { mFactory.mGeomRepContxt = geometricRepresentationContext; } if (geometricRepresentationContext.mPrecision > 1e-6) { Tolerance = geometricRepresentationContext.mPrecision; } } IfcSIUnit unit = result as IfcSIUnit; if (unit != null) { if (unit.Name == IfcSIUnitName.METRE && unit.Prefix == IfcSIPrefix.NONE) { mFactory.mSILength = unit; } else if (unit.Name == IfcSIUnitName.SQUARE_METRE && unit.Prefix == IfcSIPrefix.NONE) { mFactory.mSIArea = unit; } else if (unit.Name == IfcSIUnitName.CUBIC_METRE && unit.Prefix == IfcSIPrefix.NONE) { mFactory.mSIVolume = unit; } } this[result.mIndex] = result; //IfcWorkPlan workPlan = result as IfcWorkPlan; //if(workPlan != null) //{ // mWorkPlans.Add(workPlan); // return workPlan; //} return(result); }
internal IfcRelDeclares(IfcContext c, List<IfcDefinitionSelect> defs) : this(c) { for (int icounter = 0; icounter < defs.Count; icounter++) { mRelatedDefinitions.Add(defs[icounter].Index); defs[icounter].HasContext = this; } }
public IfcRelDeclares(IfcContext c, IfcDefinitionSelect def) : this(c, new List<IfcDefinitionSelect>() { def }) { }
internal IfcRelDeclares(IfcContext c) : base(c.mDatabase) { mRelatingContext = c.mIndex; c.mDeclares.Add(this); }
internal static void parseFields(IfcContext p, List<string> arrFields, ref int ipos) { IfcObjectDefinition.parseFields(p, arrFields, ref ipos); p.mObjectType = arrFields[ipos++].Replace("'", ""); p.mLongName = arrFields[ipos++].Replace("'", ""); p.mPhase = arrFields[ipos++].Replace("'", ""); string s = arrFields[ipos++]; if (s != "$") p.mRepresentationContexts = ParserSTEP.SplitListLinks(s); p.mUnitsInContext = ParserSTEP.ParseLink(arrFields[ipos++]); }
protected IfcContext(IfcContext o) : base(o) { mObjectType = o.mObjectType; mLongName = o.mLongName; mPhase = o.mPhase; mRepresentationContexts = new List<int>(o.mRepresentationContexts.ToArray()); mUnitsInContext = o.mUnitsInContext; }
internal override void parseJObject(JObject obj) { base.parseJObject(obj); JObject jobj = obj.GetValue("ContextOfItems", StringComparison.InvariantCultureIgnoreCase) as JObject; if (jobj != null) { JToken tok = jobj["href"]; if (tok != null) { mContextOfItems = tok.Value <int>(); } else { IfcRepresentationContext rc = extractObject <IfcRepresentationContext>(jobj); IfcContext context = mDatabase.Context; if (context != null) { foreach (IfcRepresentationContext repContext in context.RepresentationContexts) { IfcGeometricRepresentationSubContext gsc = rc as IfcGeometricRepresentationSubContext; if (gsc != null) { IfcGeometricRepresentationContext grc = repContext as IfcGeometricRepresentationContext; if (grc != null) { foreach (IfcGeometricRepresentationSubContext sub in grc.HasSubContexts) { if (string.Compare(sub.mContextIdentifier, gsc.mContextIdentifier, true) == 0) { ContextOfItems = sub; mDatabase[rc.mIndex] = null; } } } } } } if (mContextOfItems == 0) { ContextOfItems = rc; } } } JToken token = obj.GetValue("RepresentationIdentifier", StringComparison.InvariantCultureIgnoreCase); if (token != null) { RepresentationIdentifier = token.Value <string>(); } token = obj.GetValue("RepresentationType", StringComparison.InvariantCultureIgnoreCase); if (token != null) { RepresentationType = token.Value <string>(); } mDatabase.extractJArray <IfcRepresentationItem>(obj.GetValue("Items", StringComparison.InvariantCultureIgnoreCase) as JArray).ForEach(x => addItem(x)); List <IfcPresentationLayerAssignment> assignments = mDatabase.extractJArray <IfcPresentationLayerAssignment>(obj.GetValue("LayerAssignments", StringComparison.InvariantCultureIgnoreCase) as JArray); foreach (IfcPresentationLayerAssignment a in assignments) { a.addItem(this); } }
public bool WriteXMLFile(string filename) { CultureInfo current = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); XmlDocument doc = new XmlDocument(); XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes"); doc.AppendChild(dec); XmlElement el = doc.CreateElement("ifc:ifcXML", mXmlNamespace); doc.AppendChild(el); XmlAttribute schemaLocation = doc.CreateAttribute("xsi", "schemaLocation", mXsiNamespace); schemaLocation.Value = mXmlSchema; el.SetAttributeNode(schemaLocation); XmlAttribute ns = doc.CreateAttribute("xlmns", "ifc", mXmlNamespace); ns.Value = mXmlNamespace; el.SetAttribute("xlmns", mXmlNamespace); Dictionary <int, XmlElement> processed = new Dictionary <int, XmlElement>(); IfcContext context = Context; if (context != null) { el.AppendChild(Context.GetXML(doc, "", null, processed)); } if (context == null || (context.mIsDecomposedBy.Count == 0 && context.Declares.Count == 0)) { foreach (BaseClassIfc e in this) { if (!processed.ContainsKey(e.Index)) { el.AppendChild(e.GetXML(doc, "", null, processed)); } } } XmlTextWriter writer; try { writer = new XmlTextWriter(filename, Encoding.UTF8); writer.Formatting = Formatting.Indented; try { doc.WriteTo(writer); } finally { writer.Flush(); writer.Close(); } } catch (Exception) { } Thread.CurrentThread.CurrentUICulture = current; return(true); }
internal BaseClassIfc InterpretLine(string line,Aggregate aggregate) { if (line.StartsWith("ISO")) return null; string ts = line.Trim().Replace(" ", ""); if (ts.StartsWith("FILE_SCHEMA(('IFC2X4", true, System.Globalization.CultureInfo.CurrentCulture) || ts.StartsWith("FILE_SCHEMA(('IFC4", true, System.Globalization.CultureInfo.CurrentCulture)) { mSchema = Schema.IFC4; return null; } BaseClassIfc result = ParserIfc.ParseLine(line, mSchema); if (result == null) { int ifcID = 0; string kw = "", str = ""; ParserIfc.GetKeyWord(line, out ifcID, out kw, out str); if (string.IsNullOrEmpty(kw)) return null; result = new BaseClassIfc(ifcID, kw,str); } if(result == null) return null; IfcApplication application = result as IfcApplication; if (application != null) { IfcApplication ea = mApplication; if (ea != null && ea.mVersion == application.mVersion) { if (string.Compare(ea.ApplicationFullName, application.ApplicationFullName, true) == 0) { if (string.Compare(ea.mApplicationIdentifier, application.mApplicationIdentifier) == 0) { mIfcObjects[ea.mIndex] = null; mApplication = application; OwnerHistory(IfcChangeActionEnum.ADDED).mLastModifyingApplication = application.mIndex; if (mOwnerHistoryModify != null) mOwnerHistoryModify.mLastModifyingApplication = application.mIndex; } } } } IfcContext context = result as IfcContext; if (context != null) { mContext = context; #warning merge project if existing } IfcGeometricRepresentationContext geometricRepresentationContext = result as IfcGeometricRepresentationContext; if (geometricRepresentationContext != null) { if (string.Compare(geometricRepresentationContext.mContextType, "Plan", true) != 0) mGeomRepContxt = geometricRepresentationContext; if (geometricRepresentationContext.mPrecision > 1e-6) Tolerance = geometricRepresentationContext.mPrecision; } IfcSIUnit unit = result as IfcSIUnit; if(unit != null) { if (unit.Name == IfcSIUnitName.METRE && unit.Prefix == IfcSIPrefix.NONE) mSILength = unit; else if (unit.Name == IfcSIUnitName.SQUARE_METRE && unit.Prefix == IfcSIPrefix.NONE) mSIArea = unit; else if (unit.Name == IfcSIUnitName.CUBIC_METRE && unit.Prefix == IfcSIPrefix.NONE) mSIVolume = unit; } aggregate.setAggregate(result); if (mIfcObjects.Count <= result.mIndex) for (int ncounter = mIfcObjects.Count; ncounter <= result.mIndex; ncounter++) mIfcObjects.Add(new BaseClassIfc()); mIfcObjects[result.mIndex] = result; result.mDatabase = this; //IfcWorkPlan workPlan = result as IfcWorkPlan; //if(workPlan != null) //{ // mWorkPlans.Add(workPlan); // return workPlan; //} return result; }