@@ -256,19 +256,12 @@ public static void EventClear()
256
256
public static string GetIFCEntityTypeName ( IFCEntityType entityType )
257
257
{
258
258
string entityTypeName ;
259
- try
259
+ if ( ! m_sIFCEntityTypeToNames . TryGetValue ( entityType , out entityTypeName ) )
260
260
{
261
- if ( ! m_sIFCEntityTypeToNames . TryGetValue ( entityType , out entityTypeName ) )
262
- {
263
- entityTypeName = entityType . ToString ( ) ;
264
- m_sIFCEntityTypeToNames [ entityType ] = entityTypeName ;
265
- }
266
- return entityTypeName ;
267
- }
268
- catch
269
- {
270
- return null ;
261
+ entityTypeName = entityType . ToString ( ) ;
262
+ m_sIFCEntityTypeToNames [ entityType ] = entityTypeName ;
271
263
}
264
+ return entityTypeName ;
272
265
}
273
266
274
267
/// <summary>
@@ -445,7 +438,6 @@ public static void SetAttribute(IFCAnyHandle handle, string name, string value)
445
438
// This allows you to set empty strings, which may not always be intended, but should be allowed.
446
439
if ( value != null )
447
440
{
448
- value = new string ( value . Where ( c => ! char . IsControl ( c ) ) . ToArray ( ) ) ;
449
441
int maxStrLen = IFCLimits . CalculateMaxAllowedSize ( value ) ;
450
442
if ( value . Length > maxStrLen )
451
443
{
@@ -1247,15 +1239,7 @@ public static void SetAttribute(IFCAnyHandle handle, string name, IFCData value)
1247
1239
/// <returns>The collection of attribute values.</returns>
1248
1240
public static T GetValidAggregateInstanceAttribute < T > ( IFCAnyHandle handle , string name ) where T : ICollection < IFCAnyHandle > , new ( )
1249
1241
{
1250
- IFCData ifcData = null ;
1251
- try
1252
- {
1253
- ifcData = handle . GetAttribute ( name ) ;
1254
- }
1255
- catch
1256
- {
1257
- return default ( T ) ;
1258
- }
1242
+ IFCData ifcData = handle . GetAttribute ( name ) ;
1259
1243
1260
1244
T aggregateAttribute = default ( T ) ;
1261
1245
@@ -1717,6 +1701,44 @@ public static string GetRepresentationType(IFCAnyHandle representation)
1717
1701
return null ;
1718
1702
}
1719
1703
1704
+ /// <summary>
1705
+ /// Get the base representation in case of MappedItem
1706
+ /// </summary>
1707
+ /// <param name="representation">the representation</param>
1708
+ /// <returns>the base representation type</returns>
1709
+ /// <exception cref="ArgumentException"></exception>
1710
+ public static string GetBaseRepresentationType ( IFCAnyHandle representation )
1711
+ {
1712
+ if ( ! IsSubTypeOf ( representation , IFCEntityType . IfcRepresentation ) )
1713
+ throw new ArgumentException ( "The operation is not valid for this handle." ) ;
1714
+
1715
+ IFCData ifcData = representation . GetAttribute ( "RepresentationType" ) ;
1716
+ if ( ifcData . PrimitiveType == IFCDataPrimitiveType . String )
1717
+ {
1718
+ string repType = ifcData . AsString ( ) ;
1719
+ if ( repType . Equals ( "MappedRepresentation" , StringComparison . InvariantCultureIgnoreCase ) )
1720
+ {
1721
+ HashSet < IFCAnyHandle > mapItems = GetItems ( representation ) ;
1722
+ if ( mapItems . Count > 0 )
1723
+ {
1724
+ // The mapped representation should be of the same type. Use the first one will suffice
1725
+ IFCAnyHandle mapSrc = GetInstanceAttribute ( mapItems . First ( ) , "MappingSource" ) ;
1726
+ if ( ! IsNullOrHasNoValue ( mapSrc ) )
1727
+ {
1728
+ IFCAnyHandle mapRep = GetInstanceAttribute ( mapSrc , "MappedRepresentation" ) ;
1729
+ if ( ! IsNullOrHasNoValue ( mapRep ) )
1730
+ {
1731
+ repType = GetRepresentationType ( mapRep ) ;
1732
+ }
1733
+ }
1734
+ }
1735
+ }
1736
+ return repType ;
1737
+ }
1738
+
1739
+ return null ;
1740
+ }
1741
+
1720
1742
/// <summary>
1721
1743
/// Gets set of Items of a representation handle.
1722
1744
/// </summary>
@@ -1853,7 +1875,13 @@ public static void AssociatesAddRelated(IFCAnyHandle relAssociates, IFCAnyHandle
1853
1875
}
1854
1876
else
1855
1877
{
1856
- aggregate . Add ( IFCData . CreateIFCAnyHandle ( related ) ) ;
1878
+ IFCData newData = IFCData . CreateIFCAnyHandle ( related ) ;
1879
+ try
1880
+ {
1881
+ //if (!aggregate.Contains(newData))
1882
+ aggregate . Add ( newData ) ;
1883
+ }
1884
+ catch { }
1857
1885
}
1858
1886
}
1859
1887
@@ -1938,21 +1966,7 @@ public static void AddProductRepresentations(IFCAnyHandle productHandle, IList<I
1938
1966
/// <returns>True if it is null or has no value, false otherwise.</returns>
1939
1967
public static bool IsNullOrHasNoValue ( IFCAnyHandle handle )
1940
1968
{
1941
- if ( handle == null || ! handle . HasValue )
1942
- return true ;
1943
-
1944
- // Temporary code for 2022 until HasValue is set propertly when handle has become invalid
1945
- bool staleHandle = false ;
1946
- try
1947
- {
1948
- string entityTypeName = handle . TypeName ;
1949
- }
1950
- catch
1951
- {
1952
- staleHandle = true ;
1953
- }
1954
-
1955
- return staleHandle ;
1969
+ return handle == null || ! handle . HasValue ;
1956
1970
}
1957
1971
1958
1972
/// <summary>
@@ -1991,14 +2005,7 @@ public static bool IsSubTypeOf(IFCAnyHandle handle, IFCEntityType type)
1991
2005
/// <returns>True if the handle entity is an entity of either the given type or one of its sub-types.</returns>
1992
2006
public static bool IsValidSubTypeOf ( IFCAnyHandle handle , IFCEntityType type )
1993
2007
{
1994
- try
1995
- {
1996
- return handle . IsSubTypeOf ( GetIFCEntityTypeName ( type ) ) ;
1997
- }
1998
- catch
1999
- {
2000
- return false ;
2001
- }
2008
+ return handle . IsSubTypeOf ( GetIFCEntityTypeName ( type ) ) ;
2002
2009
}
2003
2010
2004
2011
/// <summary>
0 commit comments