Misc Improvements
This commit is contained in:
Родитель
a45248f153
Коммит
e164c2c7e5
|
@ -378,6 +378,7 @@ namespace GeometryGym.Ifc
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Encoding encoding = SerializationIfcSTEP.StepFileEncoding();
|
||||||
#if (!NOIFCZIP)
|
#if (!NOIFCZIP)
|
||||||
bool zip = ExtensionHelper.ExtensionEquals(filePath, ".ifczip");
|
bool zip = ExtensionHelper.ExtensionEquals(filePath, ".ifczip");
|
||||||
ZipArchive za = null;
|
ZipArchive za = null;
|
||||||
|
@ -387,11 +388,11 @@ namespace GeometryGym.Ifc
|
||||||
File.Delete(path);
|
File.Delete(path);
|
||||||
za = ZipFile.Open(path, System.IO.Compression.ZipArchiveMode.Create);
|
za = ZipFile.Open(path, System.IO.Compression.ZipArchiveMode.Create);
|
||||||
ZipArchiveEntry zae = za.CreateEntry(Path.GetFileNameWithoutExtension(path) + ".ifc");
|
ZipArchiveEntry zae = za.CreateEntry(Path.GetFileNameWithoutExtension(path) + ".ifc");
|
||||||
sw = new StreamWriter(zae.Open());
|
sw = new StreamWriter(zae.Open(), encoding);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
sw = new StreamWriter(FileName);
|
sw = new StreamWriter(FileName, false, encoding);
|
||||||
bool result = new SerializationIfcSTEP(this).WriteSTEP(sw, path);
|
bool result = new SerializationIfcSTEP(this).WriteSTEP(sw, path);
|
||||||
sw.Close();
|
sw.Close();
|
||||||
|
|
||||||
|
@ -1961,12 +1962,13 @@ namespace GeometryGym.Ifc
|
||||||
mTextReader.Close();
|
mTextReader.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private FormatIfcSerialization detectFormat(string fileName)
|
private FormatIfcSerialization detectFormat(string fileName)
|
||||||
{
|
{
|
||||||
if (ExtensionHelper.ExtensionEquals(fileName, ".xml"))
|
if (ExtensionHelper.ExtensionEquals(fileName, ".xml") || ExtensionHelper.ExtensionEquals(fileName, ".ifcxml"))
|
||||||
return FormatIfcSerialization.XML;
|
return FormatIfcSerialization.XML;
|
||||||
#if (!NOIFCJSON)
|
#if (!NOIFCJSON)
|
||||||
if (ExtensionHelper.ExtensionEquals(fileName, ".json"))
|
if (ExtensionHelper.ExtensionEquals(fileName, ".json") || ExtensionHelper.ExtensionEquals(fileName, "ifcjson"))
|
||||||
return FormatIfcSerialization.JSON;
|
return FormatIfcSerialization.JSON;
|
||||||
#endif
|
#endif
|
||||||
return FormatIfcSerialization.STEP;
|
return FormatIfcSerialization.STEP;
|
||||||
|
@ -1975,6 +1977,8 @@ namespace GeometryGym.Ifc
|
||||||
{
|
{
|
||||||
mDatabase.FileName = fileName;
|
mDatabase.FileName = fileName;
|
||||||
mDatabase.FolderPath = Path.GetDirectoryName(fileName);
|
mDatabase.FolderPath = Path.GetDirectoryName(fileName);
|
||||||
|
|
||||||
|
StreamReader streamReader = null;
|
||||||
#if (!NOIFCZIP)
|
#if (!NOIFCZIP)
|
||||||
if (ExtensionHelper.ExtensionEquals(fileName, ".zip") || ExtensionHelper.ExtensionEquals(fileName, ".ifczip"))
|
if (ExtensionHelper.ExtensionEquals(fileName, ".zip") || ExtensionHelper.ExtensionEquals(fileName, ".ifczip"))
|
||||||
{
|
{
|
||||||
|
@ -1985,15 +1989,25 @@ namespace GeometryGym.Ifc
|
||||||
}
|
}
|
||||||
string filename = za.Entries[0].Name.ToLower();
|
string filename = za.Entries[0].Name.ToLower();
|
||||||
FormatIfcSerialization fformat = detectFormat(filename);
|
FormatIfcSerialization fformat = detectFormat(filename);
|
||||||
StreamReader str = (fformat == FormatIfcSerialization.STEP ? new StreamReader(za.Entries[0].Open(), Encoding.GetEncoding("windows-1252")) :
|
if (fformat == FormatIfcSerialization.STEP)
|
||||||
new StreamReader(za.Entries[0].Open()));
|
{
|
||||||
return new FileStreamIfc(fformat, str);
|
Encoding encoding = SerializationIfcSTEP.StepFileEncoding();
|
||||||
|
streamReader = new StreamReader(za.Entries[0].Open(), encoding);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
streamReader = new StreamReader(za.Entries[0].Open());
|
||||||
|
return new FileStreamIfc(fformat, streamReader);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
FormatIfcSerialization format = detectFormat(fileName);
|
FormatIfcSerialization format = detectFormat(fileName);
|
||||||
StreamReader sr = format == FormatIfcSerialization.STEP ? new StreamReader(fileName, Encoding.GetEncoding("windows-1252")) :
|
if (format == FormatIfcSerialization.STEP)
|
||||||
new StreamReader(fileName);
|
{
|
||||||
return new FileStreamIfc(format, sr);
|
Encoding encoding = SerializationIfcSTEP.StepFileEncoding();
|
||||||
|
streamReader = new StreamReader(fileName, encoding);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
streamReader = new StreamReader(fileName);
|
||||||
|
return new FileStreamIfc(format, streamReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ReadFile(string filePath)
|
internal void ReadFile(string filePath)
|
||||||
|
@ -2083,6 +2097,14 @@ namespace GeometryGym.Ifc
|
||||||
|
|
||||||
CancellationTokenSource mCancellationTokenSource = new CancellationTokenSource();
|
CancellationTokenSource mCancellationTokenSource = new CancellationTokenSource();
|
||||||
|
|
||||||
|
internal static Encoding StepFileEncoding()
|
||||||
|
{
|
||||||
|
#if (NETCOREAPP)
|
||||||
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||||
|
#endif
|
||||||
|
Encoding encoding = Encoding.GetEncoding(1252);
|
||||||
|
return encoding;
|
||||||
|
}
|
||||||
private class ConstructorClass
|
private class ConstructorClass
|
||||||
{
|
{
|
||||||
internal BaseClassIfc Object { get; }
|
internal BaseClassIfc Object { get; }
|
||||||
|
@ -2570,7 +2592,8 @@ namespace GeometryGym.Ifc
|
||||||
public bool WriteSTEPFile(string filePath, SetProgressBarCallback progressBarCallback)
|
public bool WriteSTEPFile(string filePath, SetProgressBarCallback progressBarCallback)
|
||||||
{
|
{
|
||||||
mDatabase.FileName = filePath;
|
mDatabase.FileName = filePath;
|
||||||
StreamWriter sw = new StreamWriter(filePath);
|
Encoding encoding = StepFileEncoding();
|
||||||
|
StreamWriter sw = new StreamWriter(filePath, false, encoding);
|
||||||
mCachedCulture = Thread.CurrentThread.CurrentCulture;
|
mCachedCulture = Thread.CurrentThread.CurrentCulture;
|
||||||
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
|
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
|
||||||
sw.Write(getHeaderString(filePath) + "\r\n");
|
sw.Write(getHeaderString(filePath) + "\r\n");
|
||||||
|
@ -2601,7 +2624,8 @@ namespace GeometryGym.Ifc
|
||||||
public bool WriteSTEPFile(string filePath, BackgroundWorker worker, DoWorkEventArgs e)
|
public bool WriteSTEPFile(string filePath, BackgroundWorker worker, DoWorkEventArgs e)
|
||||||
{
|
{
|
||||||
mDatabase.FileName = filePath;
|
mDatabase.FileName = filePath;
|
||||||
StreamWriter sw = new StreamWriter(filePath);
|
Encoding encoding = StepFileEncoding();
|
||||||
|
StreamWriter sw = new StreamWriter(filePath, false, encoding);
|
||||||
mCachedCulture = Thread.CurrentThread.CurrentCulture;
|
mCachedCulture = Thread.CurrentThread.CurrentCulture;
|
||||||
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
|
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
|
||||||
sw.Write(getHeaderString(filePath) + "\r\n");
|
sw.Write(getHeaderString(filePath) + "\r\n");
|
||||||
|
|
|
@ -612,7 +612,7 @@ namespace GeometryGym.Ifc
|
||||||
spatial.ReferenceElement(this);
|
spatial.ReferenceElement(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public IfcGroup(List<IfcObjectDefinition> ods) : base(ods[0].mDatabase) { mIsGroupedBy.Add(new IfcRelAssignsToGroup(ods, this)); }
|
public IfcGroup(IEnumerable<IfcObjectDefinition> ods) : base(ods.First().mDatabase) { mIsGroupedBy.Add(new IfcRelAssignsToGroup(ods, this)); }
|
||||||
|
|
||||||
public void AddRelated(IfcObjectDefinition related)
|
public void AddRelated(IfcObjectDefinition related)
|
||||||
{
|
{
|
||||||
|
|
|
@ -638,8 +638,7 @@ namespace GeometryGym.Ifc
|
||||||
public partial class IfcPolyLoop : IfcLoop
|
public partial class IfcPolyLoop : IfcLoop
|
||||||
{
|
{
|
||||||
private LIST<IfcCartesianPoint> mPolygon = new LIST<IfcCartesianPoint> ();// : LIST [3:?] OF UNIQUE IfcCartesianPoint;
|
private LIST<IfcCartesianPoint> mPolygon = new LIST<IfcCartesianPoint> ();// : LIST [3:?] OF UNIQUE IfcCartesianPoint;
|
||||||
public LIST<IfcCartesianPoint> Polygon { get { return mPolygon; }
|
public LIST<IfcCartesianPoint> Polygon { get { return mPolygon; } set { mPolygon = value; } }
|
||||||
set { mPolygon = value; } }
|
|
||||||
|
|
||||||
internal IfcPolyLoop() : base() { }
|
internal IfcPolyLoop() : base() { }
|
||||||
internal IfcPolyLoop(DatabaseIfc db, IfcPolyLoop l, DuplicateOptions options) : base(db, l, options) { mPolygon.AddRange(l.Polygon.ConvertAll(x=> db.Factory.Duplicate(x) as IfcCartesianPoint)); }
|
internal IfcPolyLoop(DatabaseIfc db, IfcPolyLoop l, DuplicateOptions options) : base(db, l, options) { mPolygon.AddRange(l.Polygon.ConvertAll(x=> db.Factory.Duplicate(x) as IfcCartesianPoint)); }
|
||||||
|
@ -1263,13 +1262,17 @@ namespace GeometryGym.Ifc
|
||||||
IfcSpatialElement spatialElement = this as IfcSpatialElement;
|
IfcSpatialElement spatialElement = this as IfcSpatialElement;
|
||||||
if (spatialElement != null)
|
if (spatialElement != null)
|
||||||
{
|
{
|
||||||
if (spatialElement.mContainsElements.Count == 0)
|
IfcSpatialElement productAsSpatial = product as IfcSpatialElement;
|
||||||
|
if (productAsSpatial == null)
|
||||||
{
|
{
|
||||||
new IfcRelContainedInSpatialStructure(product, spatialElement);
|
if (spatialElement.mContainsElements.Count == 0)
|
||||||
|
{
|
||||||
|
new IfcRelContainedInSpatialStructure(product, spatialElement);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
spatialElement.ContainsElements.First().RelatedElements.Add(product);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
spatialElement.ContainsElements.First().RelatedElements.Add(product);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (mIsDecomposedBy.Count > 0)
|
if (mIsDecomposedBy.Count > 0)
|
||||||
mIsDecomposedBy.First().RelatedObjects.Add(product);
|
mIsDecomposedBy.First().RelatedObjects.Add(product);
|
||||||
|
@ -1642,6 +1645,11 @@ namespace GeometryGym.Ifc
|
||||||
return s.IsDecomposedBy.SelectMany(x=>x.RelatedObjects).OfType<IfcBuilding>().FirstOrDefault();
|
return s.IsDecomposedBy.SelectMany(x=>x.RelatedObjects).OfType<IfcBuilding>().FirstOrDefault();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
public IfcProject DuplicateProject(DuplicateOptions options)
|
||||||
|
{
|
||||||
|
DatabaseIfc db = new DatabaseIfc(mDatabase);
|
||||||
|
return db.Factory.Duplicate(this, options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public partial class IfcProjectedCRS : IfcCoordinateReferenceSystem //IFC4
|
public partial class IfcProjectedCRS : IfcCoordinateReferenceSystem //IFC4
|
||||||
|
|
|
@ -1832,8 +1832,8 @@ additional types some additional representation types are given:
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public partial class IfcStructuralLoadLinearForce : IfcStructuralLoadStatic
|
public partial class IfcStructuralLoadLinearForce : IfcStructuralLoadStatic
|
||||||
{
|
{
|
||||||
private double mLinearForceX = 0, mLinearForceY = 0, mLinearForceZ = 0; // : OPTIONAL IfcLinearForceMeasure
|
private double mLinearForceX = double.NaN, mLinearForceY = double.NaN, mLinearForceZ = double.NaN; // : OPTIONAL IfcLinearForceMeasure
|
||||||
private double mLinearMomentX = 0, mLinearMomentY = 0, mLinearMomentZ = 0;// : OPTIONAL IfcLinearMomentMeasure;
|
private double mLinearMomentX = double.NaN, mLinearMomentY = double.NaN, mLinearMomentZ = double.NaN;// : OPTIONAL IfcLinearMomentMeasure;
|
||||||
|
|
||||||
public double LinearForceX { get { return double.IsNaN(mLinearForceX) ? 0 : mLinearForceX; } set { mLinearForceX = value; } }
|
public double LinearForceX { get { return double.IsNaN(mLinearForceX) ? 0 : mLinearForceX; } set { mLinearForceX = value; } }
|
||||||
public double LinearForceY { get { return double.IsNaN(mLinearForceY) ? 0 : mLinearForceY; } set { mLinearForceY = value; } }
|
public double LinearForceY { get { return double.IsNaN(mLinearForceY) ? 0 : mLinearForceY; } set { mLinearForceY = value; } }
|
||||||
|
@ -1874,8 +1874,8 @@ additional types some additional representation types are given:
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public partial class IfcStructuralLoadSingleForce : IfcStructuralLoadStatic
|
public partial class IfcStructuralLoadSingleForce : IfcStructuralLoadStatic
|
||||||
{
|
{
|
||||||
internal double mForceX = double.NaN, mForceY = double.NaN, mForceZ = double.NaN;// : OPTIONAL IfcForceMeasure;
|
private double mForceX = double.NaN, mForceY = double.NaN, mForceZ = double.NaN;// : OPTIONAL IfcForceMeasure;
|
||||||
internal double mMomentX = double.NaN, mMomentY = double.NaN, mMomentZ = double.NaN;// : OPTIONAL IfcTorqueMeasure;
|
private double mMomentX = double.NaN, mMomentY = double.NaN, mMomentZ = double.NaN;// : OPTIONAL IfcTorqueMeasure;
|
||||||
|
|
||||||
public double ForceX { get { return double.IsNaN(mForceX) ? 0 : mForceX; } set { mForceX = value; } }
|
public double ForceX { get { return double.IsNaN(mForceX) ? 0 : mForceX; } set { mForceX = value; } }
|
||||||
public double ForceY { get { return double.IsNaN(mForceY) ? 0 : mForceY; } set { mForceY = value; } }
|
public double ForceY { get { return double.IsNaN(mForceY) ? 0 : mForceY; } set { mForceY = value; } }
|
||||||
|
|
|
@ -682,6 +682,12 @@ namespace GeometryGym.Ifc
|
||||||
IfcDuration duration = new IfcDuration();
|
IfcDuration duration = new IfcDuration();
|
||||||
if (string.IsNullOrEmpty(s))
|
if (string.IsNullOrEmpty(s))
|
||||||
return duration;
|
return duration;
|
||||||
|
if (s[0] != 'P')
|
||||||
|
{
|
||||||
|
if (int.TryParse(s, out int i))
|
||||||
|
return new IfcDuration() { Days = i };
|
||||||
|
return null;
|
||||||
|
}
|
||||||
int stringLength = s.Length;
|
int stringLength = s.Length;
|
||||||
bool inTime = false;
|
bool inTime = false;
|
||||||
for(int icounter = 1; icounter < stringLength; icounter++)
|
for(int icounter = 1; icounter < stringLength; icounter++)
|
||||||
|
|
|
@ -292,7 +292,7 @@ namespace GeometryGym.Ifc
|
||||||
{
|
{
|
||||||
var jsonObject = o.getJson(host, options);
|
var jsonObject = o.getJson(host, options);
|
||||||
if(jsonObject != null)
|
if(jsonObject != null)
|
||||||
array.Append(jsonObject);
|
array.Append(jsonObject);
|
||||||
}
|
}
|
||||||
obj[name] = array;
|
obj[name] = array;
|
||||||
}
|
}
|
||||||
|
|
|
@ -369,7 +369,7 @@ namespace GeometryGym.Ifc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class JsonIFCExtensions
|
public static partial class JsonIFCExtensions
|
||||||
{
|
{
|
||||||
|
|
||||||
#if (NEWTONSOFT)
|
#if (NEWTONSOFT)
|
||||||
|
|
|
@ -519,10 +519,9 @@ namespace GeometryGym.Ifc
|
||||||
{
|
{
|
||||||
protected override string BuildStringSTEP(ReleaseVersion release)
|
protected override string BuildStringSTEP(ReleaseVersion release)
|
||||||
{
|
{
|
||||||
return base.BuildStringSTEP(release) + "," + ParserSTEP.DoubleOptionalToString(mStartDistAlong) + "," +
|
return base.BuildStringSTEP(release) + "," + formatLength(mStartDistAlong) + "," + formatLength(mHorizontalLength) + "," +
|
||||||
ParserSTEP.DoubleOptionalToString(mHorizontalLength) + "," + ParserSTEP.DoubleOptionalToString(mStartHeight) + "," +
|
formatLength(mStartHeight) + "," + ParserSTEP.DoubleToString(mStartGradient) + "," +
|
||||||
ParserSTEP.DoubleToString(mStartGradient) + "," + ParserSTEP.DoubleToString(mEndGradient) +
|
ParserSTEP.DoubleToString(mEndGradient) + "," + formatLength(mRadiusOfCurvature) + ",." + mPredefinedType.ToString() + ".";
|
||||||
"," + ParserSTEP.DoubleOptionalToString(mRadiusOfCurvature) + ",." + mPredefinedType.ToString() + ".";
|
|
||||||
}
|
}
|
||||||
internal override void parse(string str, ref int pos, ReleaseVersion release, int len, ConcurrentDictionary<int, BaseClassIfc> dictionary)
|
internal override void parse(string str, ref int pos, ReleaseVersion release, int len, ConcurrentDictionary<int, BaseClassIfc> dictionary)
|
||||||
{
|
{
|
||||||
|
|
|
@ -722,16 +722,34 @@ namespace GeometryGym.Ifc
|
||||||
base.parse(str, ref pos, release, len, dictionary);
|
base.parse(str, ref pos, release, len, dictionary);
|
||||||
string s = ParserSTEP.StripField(str, ref pos, len);
|
string s = ParserSTEP.StripField(str, ref pos, len);
|
||||||
if (s != "$")
|
if (s != "$")
|
||||||
mUpperBoundValue = ParserIfc.parseValue(s);
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mUpperBoundValue = ParserIfc.parseValue(s);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
s = ParserSTEP.StripField(str, ref pos, len);
|
s = ParserSTEP.StripField(str, ref pos, len);
|
||||||
if (s != "$")
|
if (s != "$")
|
||||||
mLowerBoundValue = ParserIfc.parseValue(s);
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mLowerBoundValue = ParserIfc.parseValue(s);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
mUnit = dictionary[ParserSTEP.StripLink(str, ref pos, len)] as IfcUnit;
|
mUnit = dictionary[ParserSTEP.StripLink(str, ref pos, len)] as IfcUnit;
|
||||||
if (release > ReleaseVersion.IFC2x3)
|
if (release > ReleaseVersion.IFC2x3)
|
||||||
{
|
{
|
||||||
s = ParserSTEP.StripField(str, ref pos, len);
|
s = ParserSTEP.StripField(str, ref pos, len);
|
||||||
if (s != "$")
|
if (s != "$")
|
||||||
mSetPointValue = ParserIfc.parseValue(s);
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mSetPointValue = ParserIfc.parseValue(s);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче