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