/// <summary>
        /// Compares two objects for geomtric equality
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b">object to compare with</param>
        /// <returns></returns>
        public static bool GeometricEquals(this IfcRectangleHollowProfileDef a, IfcProfileDef b)
        {
            IfcRectangleHollowProfileDef p = b as IfcRectangleHollowProfileDef;

            if (p == null)
            {
                return(false);           //different types are not the same
            }
            return(a.XDim == p.XDim && a.YDim == p.YDim &&
                   a.WallThickness == p.WallThickness &&
                   a.InnerFilletRadius == p.InnerFilletRadius &&
                   a.OuterFilletRadius == p.OuterFilletRadius &&
                   a.Position.GeometricEquals(p.Position));
        }
        /// <summary>
        /// returns a Hash for the geometric behaviour of this object
        /// </summary>
        /// <param name="solid"></param>
        /// <returns></returns>
        public static int GetGeometryHashCode(this IfcRectangleHollowProfileDef profile)
        {
            Func <double, int> f = profile.Model.ModelFactors.GetGeometryDoubleHash;

            if (profile.YDim != 0) //dividing x/y makes profile hash unique
            {
                return(f(profile.XDim) ^
                       f(profile.XDim / profile.YDim) ^
                       profile.Position.GetGeometryHashCode());
            }
            else
            {
                return(f(profile.XDim) ^
                       profile.Position.GetGeometryHashCode());
            }
        }
        public static double GetPerimeter(this IfcProfileDef Profile, bool addPerimetersOfVoids = true)
        {
            // Inheritance tree of IfcProfileDef:
            //
            //- IfcArbitraryClosedProfileDef
            //  - IfcArbitraryProfileDefWithVoids
            //- IfcArbitraryOpenProfileDef
            //  - IfcCenterLineProfileDef
            //- IfcParameterizedProfileDef  (abstract)
            //  - IfcIShapeProfileDef
            //    - IfcAsymmetricIShapeProfileDef
            //  - IfcCircleProfileDef
            //    - IfcCircleHollowProfileDef
            //  - IfcCraneRailAShapeProfileDef (Throw)
            //  - IfcCraneRailFShapeProfileDef (Throw)
            //  - IfcCShapeProfileDef
            //  - IfcEllipseProfileDef
            //  - IfcLShapeProfileDef (Throw)
            //  - IfcRectangleProfileDef
            //    - IfcRectangleHollowProfileDef
            //    - IfcRoundedRectangleProfileDef
            //  - IfcTrapeziumProfileDef
            //  - IfcTShapeProfileDef (Throw)
            //  - IfcUShapeProfileDef (Throw)
            //  - IfcZShapeProfileDef (Throw)
            //- IfcCompositeProfileDef
            if (Profile is IfcArbitraryProfileDefWithVoids)
            {
                throw new NotImplementedException("IfcArbitraryProfileDefWithVoids Perimeter is not implemented");
            }
            else if (Profile is IfcArbitraryClosedProfileDef)
            {
                throw new NotImplementedException("IfcArbitraryClosedProfileDef Perimeter is not implemented");
            }
            else if (Profile is IfcRoundedRectangleProfileDef)
            {
                IfcRoundedRectangleProfileDef p = Profile as IfcRoundedRectangleProfileDef;
                return(RoundedRecPerimeter(p.XDim, p.YDim, p.RoundingRadius));
            }
            else if (Profile is IfcRectangleHollowProfileDef)
            {
                IfcRectangleHollowProfileDef p = Profile as IfcRectangleHollowProfileDef;

                // outer 2P
                double outerFillet = 0;
                if (p.OuterFilletRadius.HasValue)
                {
                    outerFillet = p.OuterFilletRadius.Value;
                }
                double outer = RoundedRecPerimeter(p.XDim, p.YDim, outerFillet);

                if (!addPerimetersOfVoids)
                {
                    return(outer);
                }
                // inner 2P
                double innerFillet = 0;
                if (p.InnerFilletRadius.HasValue)
                {
                    innerFillet = p.InnerFilletRadius.Value;
                }
                double inner = RoundedRecPerimeter(p.XDim - 2 * p.WallThickness, p.YDim - 2 * p.WallThickness, innerFillet);

                // value
                return(outer + inner);
            }
            else if (Profile is IfcRectangleProfileDef)
            {
                IfcRectangleProfileDef p = Profile as IfcRectangleProfileDef;
                return(2 * (p.XDim + p.YDim));
            }
            else if (Profile is IfcCircleHollowProfileDef)
            {
                IfcCircleHollowProfileDef p = Profile as IfcCircleHollowProfileDef;
                double outer = 2 * Math.PI * p.Radius;
                if (!addPerimetersOfVoids)
                {
                    return(outer);
                }

                double inner = 2 * Math.PI * (p.Radius - p.WallThickness);

                return(outer - inner);
            }
            else if (Profile is IfcCircleProfileDef)
            {
                IfcCircleProfileDef p = Profile as IfcCircleProfileDef;
                return(2 * Math.PI * p.Radius);
            }
            else if (Profile is IfcCraneRailAShapeProfileDef)
            {
                // geometry is not clear
                throw new NotImplementedException("IfcCraneRailAShapeProfileDef Perimeter is not implemented");
            }
            else if (Profile is IfcCraneRailFShapeProfileDef)
            {
                // geometry is not clear
                throw new NotImplementedException("IfcCraneRailFShapeProfileDef Perimeter is not implemented");
            }
            else if (Profile is IfcCShapeProfileDef)
            {
                IfcCShapeProfileDef p = Profile as IfcCShapeProfileDef;

                double raIn = 0;
                if (p.InternalFilletRadius.HasValue)
                {
                    raIn = p.InternalFilletRadius.Value;
                }
                double raOut = raIn + p.WallThickness;

                return
                    (2 * Math.PI * raIn +        // internal fillet
                     2 * Math.PI * raOut +       // external fillet
                     4 * (p.Girth - raOut) +     // girt extension
                     2 * p.WallThickness +       // girt closures
                     4 * (p.Width - 2 * raOut) + // top and bottom connections
                     2 * (p.Depth - 2 * raOut)); // left connections
            }
            else if (Profile is IfcEllipseProfileDef)
            {
                IfcEllipseProfileDef p = Profile as IfcEllipseProfileDef;
                // http://www.mathsisfun.com/geometry/ellipse-perimeter.html
                // Ramanujan  approx 3
                double h = Math.Pow((p.SemiAxis1 - p.SemiAxis2), 2) / Math.Pow((p.SemiAxis1 + p.SemiAxis2), 2);
                return
                    (Math.PI * (p.SemiAxis1 + p.SemiAxis2) * (1 + 3 * h / (10 + Math.Sqrt(4 - 3 * h))));
            }
            else if (Profile is IfcLShapeProfileDef)
            {
                // geometry is not clear
                throw new NotImplementedException("IfcLShapeProfileDef Perimeter is not implemented");
            }
            else if (Profile is IfcTrapeziumProfileDef)
            {
                IfcTrapeziumProfileDef p = Profile as IfcTrapeziumProfileDef;
                double diag1             = pita(p.YDim, p.TopXOffset);
                double diag2             = pita(p.YDim, p.BottomXDim - p.TopXOffset - p.TopXDim);
                return(p.BottomXDim + p.TopXDim + diag1 + diag2);
            }
            else if (Profile is IfcTShapeProfileDef)
            {
                // geometry is not clear
                throw new NotImplementedException("IfcTShapeProfileDef Perimeter is not implemented");
            }
            else if (Profile is IfcUShapeProfileDef)
            {
                // geometry is not clear
                throw new NotImplementedException("IfcUShapeProfileDef Perimeter is not implemented");
            }
            else if (Profile is IfcZShapeProfileDef)
            {
                // geometry is not clear
                throw new NotImplementedException("IfcZShapeProfileDef Perimeter is not implemented");
            }
            else if (Profile is IfcAsymmetricIShapeProfileDef) // needs to be tested before IfcIShapeProfileDef
            {
                throw new NotImplementedException("IfcAsymmetricIShapeProfileDef Perimeter is not implemented");
                // IfcAsymmetricIShapeProfileDef p = Profile as IfcAsymmetricIShapeProfileDef;
            }
            else if (Profile is IfcIShapeProfileDef)
            {
                throw new NotImplementedException("IfcAsymmetricIShapeProfileDef Perimeter is not implemented");
                // IfcIShapeProfileDef p = Profile as IfcIShapeProfileDef;
            }
            else if (Profile is IfcArbitraryOpenProfileDef)
            {
                return(0);
            }
            return(double.NaN);
        }
        internal static DatabaseIfc Generate(ModelView mvd, string path)
        {
            DatabaseIfc db = new DatabaseIfc(true, mvd);
            //IfcGeometricRepresentationContext
            //IfcCartesianPoint
            //IfcAxis2Placement3D
            //IfcDirection
            //IfcAxis2Placement2D
            //IfcSIUnit
            //IfcLocalPlacement
            IfcSite site = new IfcSite(db, "TestSite");
            //IfcPerson  NOT RV
            //IfcOrganization  NOT RV
            //IfcPersonAndOrganization  NOT RV
            //IfcOwnerHistory  NOT RV
            //fcApplication NOT RV
            //                     IfcProjectLibrary NOT RV Can't have multiple context
            IfcProject project = new IfcProject(site, "TestProject", IfcUnitAssignment.Length.Millimetre)
            {
            };
            //IfcUnitAssignment
            //IfcRelAggregates
            IfcBuilding building = new IfcBuilding(site, "TestBuilding")
            {
            };
            IfcBuildingStorey buildingStorey = new IfcBuildingStorey(building, "TestBuildingStorey", 200);
            IfcSpace          space          = new IfcSpace(buildingStorey, null)
            {
                Name = "TestSpace"
            };

            space.setRelatingType(new IfcSpaceType(db, "TestSpaceType", IfcSpaceTypeEnum.INTERNAL));

            IfcZone zone = new IfcZone(buildingStorey, "TestZone", new List <IfcSpace>()
            {
                space
            })
            {
                LongName = "TestZoneLongName"
            };

            IfcLocalPlacement storeyLocalPlacement = buildingStorey.ObjectPlacement as IfcLocalPlacement;

            IfcMaterial material = new IfcMaterial(db, "TestMaterial")
            {
                Description = "TestDescription", Category = "TestCategory"
            };
            IfcMaterialProperties materialProperties = new IfcMaterialProperties("TestMaterialProperties", material);

            materialProperties.AddProperty(new IfcPropertySingleValue(db, "MassDensity", new IfcMassDensityMeasure(1)));
            IfcSurfaceStyleShading surfaceStyleShading = new IfcSurfaceStyleShading(new IfcColourRgb(db, 1, 0, 0)
            {
                Name = "Red"
            });
            IfcSurfaceStyle surfaceStyle = new IfcSurfaceStyle(surfaceStyleShading, null, null, null, null);
            IfcMaterialDefinitionRepresentation materialDefinitionRepresentation = new IfcMaterialDefinitionRepresentation(new IfcStyledRepresentation(new IfcStyledItem(surfaceStyle)
            {
                Name = "TestStyledItem"
            }), material);

            IfcIndexedPolyCurve          indexedPolyCurve          = IPE200Curve(db);
            IfcArbitraryClosedProfileDef arbitraryClosedProfileDef = new IfcArbitraryClosedProfileDef("IPE200", indexedPolyCurve);
            IfcMaterialProfile           materialProfile           = new IfcMaterialProfile("TestMaterialProfile", material, arbitraryClosedProfileDef);
            IfcMaterialProfileSet        materialProfileSet        = new IfcMaterialProfileSet("TestMaterialProfileSet", materialProfile);

            IfcBeamType beamType = new IfcBeamType(db, "TestBeamType", IfcBeamTypeEnum.BEAM);

            beamType.MaterialSelect = materialProfileSet;

            int beamXPosition = 1000, beamYposition = 0, beamXSpacing = 1000;
            int columnXPosition = -1000, columnYposition = 0, columnYSpacing = 1000;
            IfcCartesianPoint cartesianPoint = new IfcCartesianPoint(db, beamXPosition += beamXSpacing, beamYposition, 0);
            IfcBeam           beam           = createBeam(buildingStorey, arbitraryClosedProfileDef, cartesianPoint, "16KYUrH45BNwdHw8Y$ia8f");

            beam.setRelatingType(beamType);
            //IfcRelDefinesByType

            IfcProfileDef columnProfile = arbitraryClosedProfileDef;

            if (mvd != ModelView.Ifc4Reference)
            {
                columnProfile = new IfcIShapeProfileDef(db, "IShapeProfileDef", 500, 300, 15, 20)
                {
                    FilletRadius = 10
                }
            }
            ;

            IfcColumnType columnType = new IfcColumnType(db, "TestColumnType", IfcColumnTypeEnum.COLUMN);

            cartesianPoint = new IfcCartesianPoint(db, columnXPosition, columnYposition += columnYSpacing, 0);
            //IfcGeometricRepresentationSubContext
            IfcColumn column = createColumn(buildingStorey, columnProfile, cartesianPoint, "2jS8dBukzApveBm5m9QrBf");

            column.setRelatingType(columnType);

            if (mvd != ModelView.Ifc4Reference)
            {
                IfcCircleProfileDef circleProfileDef = circleProfileDef = new IfcCircleProfileDef(db, "TestCircleProfile", 350);
                cartesianPoint = new IfcCartesianPoint(db, columnXPosition, columnYposition += columnYSpacing, 0);
                createColumn(buildingStorey, circleProfileDef, cartesianPoint, "");

                IfcRectangleProfileDef rectangleProfileDef = new IfcRectangleProfileDef(db, "TestRectangle", 400, 600);
                cartesianPoint = new IfcCartesianPoint(db, beamXPosition += beamXSpacing, beamYposition, 0);
                createBeam(buildingStorey, rectangleProfileDef, cartesianPoint, "");

                IfcRectangleHollowProfileDef rectangleHollowProfileDef = new IfcRectangleHollowProfileDef(db, "TestRectangleHollow", 400, 600, 12);
                cartesianPoint = new IfcCartesianPoint(db, beamXPosition += beamXSpacing, beamYposition, 0);
                createBeam(buildingStorey, rectangleHollowProfileDef, cartesianPoint, "");
            }

            IfcProfileDef memberProfile = arbitraryClosedProfileDef;

            if (mvd != ModelView.Ifc4Reference)
            {
                memberProfile = new IfcCircleHollowProfileDef(db, "TestCircleHollowProfile", 75, 9);
            }
            cartesianPoint = new IfcCartesianPoint(db, -1000, -1000, 0);
            IfcProductDefinitionShape productDefinitionShape = new IfcProductDefinitionShape(new IfcShapeRepresentation(new IfcExtrudedAreaSolid(memberProfile, 2000)));
            IfcMember member = new IfcMember(buildingStorey, createLocalPlacement(buildingStorey, cartesianPoint, db.Factory.YAxisNegative), productDefinitionShape);

            //	if(mdv != ModelView.Ifc4Reference)
            //			IfcActorRole  NOT RV

            //IfcActuator
            //IfcActuatorType
            //IfcAdvancedBrep  NOT RV
            //IfcAdvancedFace   NOT RV
            //IfcAirTerminal
            //IfcAirTerminalBox
            //IfcAirTerminalBoxType
            //IfcAirTerminalType
            //IfcAirToAirHeatRecovery
            //IfcAirToAirHeatRecoveryType
            //IfcAlarm
            //IfcAlarmType
            //IfcArbitraryOpenProfileDef
            //IfcArbitraryProfileDefWithVoids
            //IfcAsymmetricIShapeProfileDef  NOT RV
            //IfcAudioVisualAppliance
            //IfcAudioVisualApplianceType
            //IfcAxis1Placement
            //IfcBeamStandardCase  NOT RV
            //IfcBlock   NOT RV
            //IfcBoiler
            //IfcBoilerType
            //IfcBooleanClippingResult  NOT RV
            //IfcBooleanResult  NOT RV
            //IfcBSplineCurveWithKnots  NOT RV
            //IfcBSplineSurface  NOT RV
            //IfcBSplineSurfaceWithKnots  NOT RV
            //IfcBuildingElementPart
            //IfcBuildingElementPartType
            //IfcBuildingElementProxy
            //IfcBuildingElementProxyType
            //IfcBuildingSystem
            //IfcBurner
            //IfcBurnerType
            //IfcCableCarrierFitting
            //IfcCableCarrierFittingType
            //IfcCableCarrierSegment
            //IfcCableCarrierSegmentType
            //IfcCableFitting
            //IfcCableFittingType
            //IfcCableSegment
            //IfcCableSegmentType
            //IfcCartesianPointList2D
            //IfcCartesianPointList3D
            //IfcCartesianTransformationOperator2D
            //IfcCartesianTransformationOperator2DnonUniform
            //IfcCartesianTransformationOperator3D
            //IfcCartesianTransformationOperator3DnonUniform
            //IfcCenterLineProfileDef
            //IfcChiller
            //IfcChillerType
            //IfcChimney
            //IfcChimneyType
            //IfcCircle
            //IfcCircleHollowProfileDef  NOT RV
            //IfcCivilElement
            //IfcCivilElementType
            //IfcClassification
            //IfcClassificationReference
            //IfcClosedShell
            //IfcCoil
            //IfcCoilType
            //IfcColourRgbList
            //IfcColourSpecification
            //IfcColumnStandardCase  NOT RV
            //IfcCommunicationsAppliance
            //IfcCommunicationsApplianceType
            //IfcComplexProperty
            //IfcCompositeProfileDef  NOT RV
            //IfcCompressor
            //IfcCompressorType
            //IfcCondenser
            //IfcCondenserType
            //IfcConnectedFaceSet  NOT RV
            //IfcConnectionCurveGeometry  NOT RV
            //IfcConnectionVolumeGeometry  NOT RV
            //IfcController
            //IfcControllerType
            //IfcConversionBasedUnit
            //IfcConversionBasedUnitWithOffset
            //IfcCooledBeam
            //IfcCooledBeamType
            //IfcCoolingTower
            //IfcCoolingTowerType
            //IfcCovering
            //IfcCoveringType
            //IfcCsgSolid  NOT RV
            //IfcCShapeProfileDef  NOT RV
            //IfcCurtainWall
            //IfcCurtainWallType
            //IfcCurveStyle
            //IfcCurveStyleFont
            //IfcCurveStyleFontPattern
            //IfcDamper
            //IfcDamperType
            //IfcDerivedProfileDef  NOT RV
            //IfcDerivedUnit
            //IfcDerivedUnitElement
            //IfcDimensionalExponents
            //IfcDiscreteAccessory
            //IfcDiscreteAccessoryType
            //IfcDistributionChamberElement
            //IfcDistributionChamberElementType
            //IfcDistributionCircuit
            //IfcDistributionControlElement
            //IfcDistributionControlElementType
            //IfcDistributionElement
            //IfcDistributionElementType
            //IfcDistributionFlowElement
            //IfcDistributionFlowElementType
            //IfcDistributionPort
            //IfcDistributionSystem
            //IfcDocumentReference
            //IfcDoor
            //IfcDoorLiningProperties
            //IfcDoorPanelProperties
            //IfcDoorStandardCase  NOT RV
            //IfcDoorType
            //IfcDuctFitting
            //IfcDuctFittingType
            //IfcDuctSegment
            //IfcDuctSegmentType
            //IfcDuctSilencer
            //IfcDuctSilencerType
            //IfcEdge	 NOT RV
            //IfcEdgeCurve  NOT RV
            //IfcEdgeLoop  NOT RV
            //IfcElectricAppliance
            //IfcElectricApplianceType
            //IfcElectricDistributionBoard
            //IfcElectricDistributionBoardType
            //IfcElectricFlowStorageDevice
            //IfcElectricFlowStorageDeviceType
            //IfcElectricGenerator
            //IfcElectricGeneratorType
            //IfcElectricMotor
            //IfcElectricMotorType
            //IfcElectricTimeControl
            //IfcElectricTimeControlType
            //IfcElementAssembly
            //IfcElementAssemblyType
            //IfcElementComponent
            //IfcElementComponentType
            //IfcElementQuantity
            //IfcEllipseProfileDef  NOT RV
            //IfcEnergyConversionDevice
            //IfcEnergyConversionDeviceType
            //IfcEngine
            //IfcEngineType
            //IfcEvaporativeCooler
            //IfcEvaporativeCoolerType
            //IfcEvaporator
            //IfcEvaporatorType
            //IfcExtendedProperties
            //IfcExternalInformation
            //IfcExternalReference
            //IfcExtrudedAreaSolidTapered  NOT RV
            //IfcFace  NOT RV
            //IfcFaceBasedSurfaceModel  NOT RV
            //IfcFaceBound  NOT RV
            //IfcFaceOuterBound  NOT RV
            //IfcFaceSurface  NOT RV
            //IfcFacetedBrep  NOT RV
            //IfcFan
            //IfcFanType
            //IfcFastener
            //IfcFastenerType
            //IfcFeatureElement
            //IfcFeatureElementAddition  NOT RV
            //IfcFeatureElementSubtraction
            //IfcFillAreaStyle
            //IfcFillAreaStyleHatching
            //IfcFilter
            //IfcFilterType
            //IfcFireSuppressionTerminal
            //IfcFireSuppressionTerminalType
            //IfcFixedReferenceSweptAreaSolid  NOT RV
            //IfcFlowController
            //IfcFlowControllerType
            //IfcFlowFitting
            //IfcFlowFittingType
            //IfcFlowInstrument
            //IfcFlowInstrumentType
            //IfcFlowMeter
            //IfcFlowMeterType
            //IfcFlowMovingDevice
            //IfcFlowMovingDeviceType
            //IfcFlowSegment
            //IfcFlowSegmentType
            //IfcFlowStorageDevice
            //IfcFlowStorageDeviceType
            //IfcFlowTerminal
            //IfcFlowTerminalType
            //IfcFlowTreatmentDevice
            //IfcFlowTreatmentDeviceType
            //IfcFooting
            //IfcFootingType
            //IfcFurnishingElement
            //IfcFurnishingElementType
            //IfcFurniture
            //IfcFurnitureType
            //IfcGeographicElement
            //IfcGeographicElementType
            //IfcGeometricCurveSet
            //IfcGeometricSet
            //IfcGrid
            //IfcGridAxis
            //IfcGridPlacement  NOT RV
            //IfcGroup
            //IfcHalfSpaceSolid  NOT RV
            //IfcHeatExchanger
            //IfcHeatExchangerType
            //IfcHumidifier
            //IfcHumidifierType
            //IfcIndexedColourMap
            //IfcIndexedTextureMap
            //IfcIndexedTriangleTextureMap
            //IfcInterceptor
            //IfcInterceptorType
            //IfcJunctionBox
            //IfcJunctionBoxType
            //IfcLamp
            //IfcLampType
            //IfcLibraryInformation  NOT RV
            //IfcLibraryReference  NOT RV
            //IfcLightFixture
            //IfcLightFixtureType
            //IfcLine
            //IfcLoop   NOT RV
            //IfcLShapeProfileDef  NOT RV
            //IfcMapConversion
            //IfcMappedItem
            //IfcMaterialConstituent
            //IfcMaterialConstituentSet
            //IfcMaterialLayer
            //IfcMaterialLayerSet
            //IfcMaterialLayerSetUsage  NOT RV
            //IfcMaterialLayerWithOffsets  NOT RV
            //IfcMaterialProfileSetUsage  NOT RV
            //IfcMaterialProfileSetUsageTapering  NOT RV
            //IfcMaterialProfileWithOffsets  NOT RV
            //IfcMaterialUsageDefinition  NOT RV
            //IfcMeasureWithUnit
            //IfcMechanicalFastener
            //IfcMechanicalFastenerType
            //IfcMedicalDevice
            //IfcMedicalDeviceType
            //IfcMemberStandardCase  NOT RV
            //IfcMonetaryUnit
            //IfcMotorConnection
            //IfcMotorConnectionType
            //IfcNamedUnit
            //IfcOpeningElement
            //IfcOpeningStandardCase  NOT RV
            //IfcOpenShell  NOT RV
            //IfcOrientedEdge  NOT RV
            //IfcOutlet
            //IfcOutletType
            //IfcPcurve  NOT RV
            //IfcPhysicalComplexQuantity
            //IfcPhysicalQuantity
            //IfcPhysicalSimpleQuantity
            //IfcPile
            //IfcPileType
            //IfcPipeFitting
            //IfcPipeFittingType
            //IfcPipeSegment
            //IfcPipeSegmentType
            //IfcPlane  NOT RV
            //IfcPlate
            //IfcPlateStandardCase  NOT RV
            //IfcPlateType
            //IfcPoint
            //IfcPolygonalBoundedHalfSpace  NOT RV
            //IfcPolyline  NOT RV
            //IfcPolyLoop  NOT RV
            //IfcPort
            //IfcPostalAddress
            //IfcPreDefinedPropertySet
            //IfcPresentationItem
            //IfcPresentationLayerAssignment
            //IfcPresentationStyle
            //IfcPresentationStyleAssignment
            //IfcProductDefinitionShape
            //IfcProductRepresentation
            //IfcProfileDef
            //IfcProfileProperties
            //IfcProjectedCRS
            //IfcProjectionElement  NOT RV
            //IfcProperty
            //IfcPropertyAbstraction
            //IfcPropertyBoundedValue
            //IfcPropertyDefinition
            //IfcPropertyEnumeratedValue
            //IfcPropertyEnumeration
            //IfcPropertyListValue
            //IfcPropertySet
            //IfcPropertySetTemplate  NOT RV
            //IfcPropertyTableValue
            //IfcPropertyTemplate  NOT RV
            //IfcPropertyTemplateDefinition  NOT RV
            //IfcProtectiveDevice
            //IfcProtectiveDeviceTrippingUnit
            //IfcProtectiveDeviceTrippingUnitType
            //IfcProtectiveDeviceType
            //IfcPump
            //IfcPumpType
            //IfcQuantityArea
            //IfcQuantityCount
            //IfcQuantityLength
            //IfcQuantitySet
            //IfcQuantityTime
            //IfcQuantityVolume
            //IfcQuantityWeight
            //IfcRailing
            //IfcRailingType
            //IfcRamp
            //IfcRampFlight
            //IfcRampFlightType
            //IfcRampType
            //IfcRectangularPyramid  NOT RV
            //IfcReinforcingBar
            //IfcReinforcingBarType
            //IfcReinforcingElement
            //IfcReinforcingElementType
            //IfcReinforcingMesh
            //IfcReinforcingMeshType
            //IfcRelAssignsToGroup
            //IfcRelAssociatesClassification
            //IfcRelAssociatesDocument
            //IfcRelAssociatesLibrary  NOT RV
            //IfcRelAssociatesMaterial
            //IfcRelConnectsElements  NOT RV
            //IfcRelConnectsPathElements  NOT RV
            //IfcRelConnectsPorts
            //IfcRelConnectsWithRealizingElements  NOT RV
            //IfcRelContainedInSpatialStructure
            //IfcRelCoversBldgElements
            //IfcRelDeclares
            //IfcRelDefinesByProperties
            //IfcRelFillsElement
            //IfcRelFlowControlElements  NOT RV
            //IfcRelInterferesElements  NOT RV
            //IfcRelNests
            //IfcRelProjectsElement  NOT RV
            //IfcRelServicesBuildings
            //IfcRelVoidsElement
            //IfcRepresentation
            //IfcRepresentationContext
            //IfcRepresentationItem
            //IfcRepresentationMap
            //IfcRevolvedAreaSolid
            //IfcRevolvedAreaSolidTapered  NOT RV
            //IfcRightCircularCone  NOT RV
            //IfcRightCircularCylinder  NOT RV
            //IfcRoof
            //IfcRoofType
            //IfcRoundedRectangleProfileDef  NOT RV
            //IfcSanitaryTerminal
            //IfcSanitaryTerminalType
            //IfcSensor
            //IfcSensorType
            //IfcShadingDevice
            //IfcShadingDeviceType
            //IfcShapeRepresentation
            //IfcShellBasedSurfaceModel  NOT RV
            //IfcSimplePropertyTemplate  NOT RV
            //IfcSlab
            //IfcSlabElementedCase  NOT RV
            //IfcSlabStandardCase  NOT RV
            //IfcSlabType
            //IfcSolarDevice
            //IfcSolarDeviceType
            //IfcSpaceHeater
            //IfcSpaceHeaterType
            //IfcSpatialZone
            //IfcSpatialZoneType
            //IfcSphere  NOT RV
            //IfcStackTerminal
            //IfcStackTerminalType
            //IfcStair
            //IfcStairFlight
            //IfcStairFlightType
            //IfcStairType
            //IfcStyleModel
            //IfcSurface  NOT RV
            //IfcSurfaceCurveSweptAreaSolid  NOT RV
            //IfcSurfaceOfLinearExtrusion  NOT RV
            //IfcSurfaceOfRevolution  NOT RV
            //IfcSurfaceStyleRendering
            //IfcSurfaceStyleWithTextures surfaceStyleWithTextures = new IfcSurfaceStyleWithTextures(new IfcImageTexture(db,true,true,""));
            //IfcSweptDiskSolid
            //IfcSwitchingDevice
            //IfcSwitchingDeviceType
            //IfcSystemFurnitureElement
            //IfcSystemFurnitureElementType
            //IfcTank
            //IfcTankType
            //IfcTelecomAddress  NOT RV
            //IfcTendon
            //IfcTendonAnchor
            //IfcTendonAnchorType
            //IfcTendonType
            //IfcTessellatedFaceSet
            //IfcTessellatedItem
            //IfcTextureCoordinate
            //IfcTextureVertexList
            //IfcTransformer
            //IfcTransformerType
            //IfcTransportElement
            //IfcTransportElementType
            //IfcTriangulatedFaceSet
            //IfcTrimmedCurve
            //IfcTShapeProfileDef  NOT RV
            //IfcTubeBundle
            //IfcTubeBundleType
            //IfcUnitaryControlElement
            //IfcUnitaryControlElementType
            //IfcUnitaryEquipment
            //IfcUnitaryEquipmentType
            //IfcUShapeProfileDef  NOT RV
            //IfcValve
            //IfcValveType
            //IfcVector
            //IfcVertex  NOT RV
            //IfcVertexPoint  NOT RV
            //IfcVibrationIsolator
            //IfcVibrationIsolatorType
            //IfcVirtualGridIntersection  NOT RV
            //IfcWall
            //IfcWallElementedCase  NOT RV
            //IfcWallStandardCase  NOT RV
            //IfcWallType
            //IfcWasteTerminal
            //IfcWasteTerminalType
            //IfcWindow
            //IfcWindowLiningProperties
            //IfcWindowPanelProperties
            //IfcWindowStandardCase  NOT RV
            //IfcWindowType
            //IfcZShapeProfileDef  NOT RV
            db.WriteFile(Path.Combine(path, mvd.ToString() + ".ifc"));
            return(db);
        }
        public static double GetArea(this IfcProfileDef Profile)
        {
            // Inheritance tree of IfcProfileDef:
            //
            //- IfcArbitraryClosedProfileDef (Throw)
            //  - IfcArbitraryProfileDefWithVoids (Throw)
            //- IfcArbitraryOpenProfileDef (x)
            //  - IfcCenterLineProfileDef (x)
            //- IfcParameterizedProfileDef  (abstract)
            //  - IfcIShapeProfileDef (x)
            //    - IfcAsymmetricIShapeProfileDef (x)
            //  - IfcCircleProfileDef (x)
            //    - IfcCircleHollowProfileDef (x)
            //  - IfcCraneRailAShapeProfileDef (Throw)
            //  - IfcCraneRailFShapeProfileDef (Throw)
            //  - IfcCShapeProfileDef (x)
            //  - IfcEllipseProfileDef (x)
            //  - IfcLShapeProfileDef (Throw)
            //  - IfcRectangleProfileDef (x)
            //    - IfcRectangleHollowProfileDef (x)
            //    - IfcRoundedRectangleProfileDef (x)
            //  - IfcTrapeziumProfileDef (x)
            //  - IfcTShapeProfileDef (Throw)
            //  - IfcUShapeProfileDef (Throw)
            //  - IfcZShapeProfileDef (Throw)
            //- IfcCompositeProfileDef
            if (Profile is IfcArbitraryProfileDefWithVoids)
            {
                throw new NotImplementedException("IfcArbitraryProfileDefWithVoids Area is not implemented");
            }
            else if (Profile is IfcArbitraryClosedProfileDef)
            {
                throw new NotImplementedException("IfcArbitraryClosedProfileDef Area is not implemented");
            }
            else if (Profile is IfcRoundedRectangleProfileDef)
            {
                IfcRoundedRectangleProfileDef p = Profile as IfcRoundedRectangleProfileDef;
                return((p.XDim * p.YDim) - (4 * ConcaveRightAngleFilletArea(p.RoundingRadius)));
            }
            else if (Profile is IfcRectangleHollowProfileDef)
            {
                IfcRectangleHollowProfileDef p = Profile as IfcRectangleHollowProfileDef;

                // outer area
                double outerFillet = 0;
                if (p.OuterFilletRadius.HasValue)
                {
                    outerFillet = p.OuterFilletRadius.Value;
                }
                double outer = (p.XDim * p.YDim) - (4 * ConcaveRightAngleFilletArea(outerFillet));
                // inner area
                double innerFillet = 0;
                if (p.InnerFilletRadius.HasValue)
                {
                    innerFillet = p.InnerFilletRadius.Value;
                }
                double inner = ((p.XDim - 2 * p.WallThickness) * (p.YDim - 2 * p.WallThickness))
                               - (4 * ConcaveRightAngleFilletArea(innerFillet));

                return(outer - inner);
            }
            else if (Profile is IfcRectangleProfileDef)
            {
                IfcRectangleProfileDef p = Profile as IfcRectangleProfileDef;
                return(p.XDim * p.YDim);
            }
            else if (Profile is IfcCircleHollowProfileDef)
            {
                IfcCircleHollowProfileDef p = Profile as IfcCircleHollowProfileDef;
                double outer = Math.PI * Math.Pow(p.Radius, 2);
                double inner = Math.PI * Math.Pow(p.Radius - p.WallThickness, 2);
                return(outer - inner);
            }
            else if (Profile is IfcCircleProfileDef)
            {
                IfcCircleProfileDef p = Profile as IfcCircleProfileDef;
                return(Math.PI * Math.Pow(p.Radius, 2));
            }
            else if (Profile is IfcCraneRailAShapeProfileDef)
            {
                // geometry is not clear
                throw new NotImplementedException("IfcCraneRailAShapeProfileDef Area is not implemented");
            }
            else if (Profile is IfcCraneRailFShapeProfileDef)
            {
                // geometry is not clear
                throw new NotImplementedException("IfcCraneRailFShapeProfileDef Area is not implemented");
            }
            else if (Profile is IfcCShapeProfileDef)
            {
                IfcCShapeProfileDef p = Profile as IfcCShapeProfileDef;

                // inner area
                double innerFillet = 0;
                if (p.InternalFilletRadius.HasValue)
                {
                    innerFillet = p.InternalFilletRadius.Value;
                }
                double inner = ((p.Width - 2 * p.WallThickness) * (p.Depth - 2 * p.WallThickness))
                               - (4 * ConcaveRightAngleFilletArea(innerFillet));

                // outer area
                double outerFillet = innerFillet + p.WallThickness;
                double outer       = (p.Width * p.Depth) - (4 * ConcaveRightAngleFilletArea(outerFillet));

                double girthSideVoid = (p.Depth - 2 * p.Girth) * p.WallThickness;

                //     closed loop area - missing part between girths
                return((outer - inner) - girthSideVoid);
            }
            else if (Profile is IfcEllipseProfileDef)
            {
                IfcEllipseProfileDef p = Profile as IfcEllipseProfileDef;
                return(Math.PI * p.SemiAxis1 * p.SemiAxis2);
            }
            else if (Profile is IfcLShapeProfileDef)
            {
                // geometry is not clear
                throw new NotImplementedException("IfcLShapeProfileDef Area is not implemented");
            }
            else if (Profile is IfcTrapeziumProfileDef)
            {
                IfcTrapeziumProfileDef p = Profile as IfcTrapeziumProfileDef;
                return((p.BottomXDim + p.TopXDim) * p.YDim / 2);
            }
            else if (Profile is IfcTShapeProfileDef)
            {
                // geometry is not clear
                throw new NotImplementedException("IfcTShapeProfileDef Area is not implemented");
            }
            else if (Profile is IfcUShapeProfileDef)
            {
                // geometry is not clear
                throw new NotImplementedException("IfcUShapeProfileDef Area is not implemented");
            }
            else if (Profile is IfcZShapeProfileDef)
            {
                // geometry is not clear
                throw new NotImplementedException("IfcZShapeProfileDef Area is not implemented");
            }
            else if (Profile is IfcAsymmetricIShapeProfileDef) // needs to be tested before IfcIShapeProfileDef
            {
                IfcAsymmetricIShapeProfileDef p = Profile as IfcAsymmetricIShapeProfileDef;
                // bottom flange
                double bottomflange = p.OverallWidth * p.FlangeThickness;
                // bottom flange
                double TopFlangeThickness = p.FlangeThickness; // if not specified differently
                if (p.TopFlangeThickness.HasValue)
                {
                    TopFlangeThickness = p.TopFlangeThickness.Value;
                }
                double topFlange = p.TopFlangeWidth * TopFlangeThickness;
                // core
                double core = (p.OverallDepth - p.FlangeThickness - TopFlangeThickness) * p.WebThickness;

                double bottomfillets = 0;
                double topFillets    = 0;
                if (p.FilletRadius.HasValue)
                {
                    bottomfillets = 2 * ConcaveRightAngleFilletArea(p.FilletRadius.Value);
                    topFillets    = bottomfillets;
                }
                if (p.TopFlangeFilletRadius.HasValue)
                {
                    topFillets = 2 * ConcaveRightAngleFilletArea(p.TopFlangeFilletRadius.Value);
                }
                return(bottomflange + topFlange + core + bottomfillets + topFillets);
            }
            else if (Profile is IfcIShapeProfileDef)
            {
                IfcIShapeProfileDef p = Profile as IfcIShapeProfileDef;
                double flanges        = p.OverallWidth * p.FlangeThickness * 2; // top and bottom flanges
                double core           = (p.OverallDepth - (p.FlangeThickness * 2)) * p.WebThickness;
                double fillets        = 0;
                if (p.FilletRadius.HasValue && p.FilletRadius.Value > 0)
                {
                    fillets = 4 * ConcaveRightAngleFilletArea(p.FilletRadius.Value);
                }
                return(flanges + core + fillets);
            }
            else if (Profile is IfcArbitraryOpenProfileDef)
            {
                return(0);
            }
            return(double.NaN);
        }