(*
Copyright by:
buildingSMART International Limited, 1996-2019

Any technical documentation made available by buildingSMART International Limited
is the copyrighted work of buildingSMART International Limited and is owned by the 
buildingSMART International Limited. It may be photocopied, used in software development, 
or translated into another computer language without prior written consent from 
buildingSMART International Limited provided that full attribution is given. 
Prior written consent is required if changes are made to the technical specification.

This material is delivered to you as is and buildingSMART International Limited makes 
no warranty of any kind with regard to it, including, but not limited to, the implied 
warranties as to its accuracy or fitness for a particular purpose. Any use of the 
technical documentation or the information contained therein is at the risk of the user. 
Documentation may include technical or other inaccuracies or typographical errors. 
buildingSMART International Limited shall not be liable for errors contained therein or 
for incidental consequential damages in connection with the furnishing, performance or use 
of the material. The information contained in this document is subject to change without notice.

Issue date:
Friday, July 26, 2019

*)

SCHEMA IFCPRESENTATIONAPPEARANCERESOURCE;

REFERENCE FROM IFCGEOMETRYRESOURCE
(
  IfcGeometricRepresentationItem,
  IfcCartesianPoint,
  IfcVector,
  IfcCartesianTransformationOperator2D,
  IfcRepresentationItem
);

REFERENCE FROM IFCPRESENTATIONDEFINITIONRESOURCE
(
  IfcPresentationItem
);

REFERENCE FROM IFCMEASURERESOURCE
(
  IfcLabel,
  IfcPositiveLengthMeasure,
  IfcLengthMeasure,
  IfcRatioMeasure,
  IfcPlaneAngleMeasure,
  IfcPositiveRatioMeasure,
  IfcNormalisedRatioMeasure,
  IfcParameterValue,
  IfcIdentifier,
  IfcInteger,
  IfcReal,
  IfcDescriptiveMeasure,
  IfcSIUnit,
  IfcBoolean,
  IfcBinary,
  IfcPositiveInteger
);

REFERENCE FROM IFCEXTERNALREFERENCERESOURCE
(
  IfcExternalReference,
  IfcClassificationReference,
  IfcURIReference
);

REFERENCE FROM IFCTOPOLOGYRESOURCE
(
  IfcFace
);

REFERENCE FROM IFCGEOMETRICMODELRESOURCE
(
  IfcTessellatedFaceSet
);

TYPE IfcFontStyle = STRING;
 WHERE
	WR1 : SELF IN ['normal','italic','oblique'];
END_TYPE;

TYPE IfcFontVariant = STRING;
 WHERE
	WR1 : SELF IN ['normal','small-caps'];
END_TYPE;

TYPE IfcFontWeight = STRING;
 WHERE
	WR1 : SELF IN ['normal','small-caps','100','200','300','400','500','600','700','800','900'];
END_TYPE;

TYPE IfcPresentableText = STRING;
END_TYPE;

TYPE IfcSpecularExponent = REAL;
END_TYPE;

TYPE IfcSpecularRoughness = REAL;
 WHERE
	WR1 : {0.0 <= SELF <= 1.0};
END_TYPE;

TYPE IfcTextAlignment = STRING;
 WHERE
	WR1 : SELF IN ['left', 'right', 'center', 'justify'];
END_TYPE;

TYPE IfcTextDecoration = STRING;
 WHERE
	WR1 : SELF IN ['none', 'underline', 'overline', 'line-through', 'blink'];
END_TYPE;

TYPE IfcTextFontName = STRING;
END_TYPE;

TYPE IfcTextTransformation = STRING;
 WHERE
	WR1 : SELF IN ['capitalize', 'uppercase', 'lowercase', 'none'];
END_TYPE;

TYPE IfcNullStyle = ENUMERATION OF
	(NULL);
END_TYPE;

TYPE IfcReflectanceMethodEnum = ENUMERATION OF
	(BLINN
	,FLAT
	,GLASS
	,MATT
	,METAL
	,MIRROR
	,PHONG
	,PLASTIC
	,STRAUSS
	,NOTDEFINED);
END_TYPE;

TYPE IfcSurfaceSide = ENUMERATION OF
	(POSITIVE
	,NEGATIVE
	,BOTH);
END_TYPE;

TYPE IfcColour = SELECT
	(IfcColourSpecification
	,IfcPreDefinedColour);
END_TYPE;

TYPE IfcColourOrFactor = SELECT
	(IfcColourRgb
	,IfcNormalisedRatioMeasure);
END_TYPE;

TYPE IfcCurveFontOrScaledCurveFontSelect = SELECT
	(IfcCurveStyleFontAndScaling
	,IfcCurveStyleFontSelect);
END_TYPE;

TYPE IfcCurveStyleFontSelect = SELECT
	(IfcCurveStyleFont
	,IfcPreDefinedCurveFont);
END_TYPE;

TYPE IfcFillStyleSelect = SELECT
	(IfcColour
	,IfcExternallyDefinedHatchStyle
	,IfcFillAreaStyleHatching
	,IfcFillAreaStyleTiles);
END_TYPE;

TYPE IfcHatchLineDistanceSelect = SELECT
	(IfcPositiveLengthMeasure
	,IfcVector);
END_TYPE;

TYPE IfcPresentationStyleSelect = SELECT
	(IfcCurveStyle
	,IfcFillAreaStyle
	,IfcNullStyle
	,IfcSurfaceStyle
	,IfcTextStyle);
END_TYPE;

TYPE IfcSizeSelect = SELECT
	(IfcDescriptiveMeasure
	,IfcLengthMeasure
	,IfcNormalisedRatioMeasure
	,IfcPositiveLengthMeasure
	,IfcPositiveRatioMeasure
	,IfcRatioMeasure);
END_TYPE;

TYPE IfcSpecularHighlightSelect = SELECT
	(IfcSpecularExponent
	,IfcSpecularRoughness);
END_TYPE;

TYPE IfcStyleAssignmentSelect = SELECT
	(IfcPresentationStyle
	,IfcPresentationStyleAssignment);
END_TYPE;

TYPE IfcSurfaceStyleElementSelect = SELECT
	(IfcExternallyDefinedSurfaceStyle
	,IfcSurfaceStyleLighting
	,IfcSurfaceStyleRefraction
	,IfcSurfaceStyleShading
	,IfcSurfaceStyleWithTextures);
END_TYPE;

TYPE IfcTextFontSelect = SELECT
	(IfcExternallyDefinedTextFont
	,IfcPreDefinedTextFont);
END_TYPE;

ENTITY IfcBlobTexture
 SUBTYPE OF (IfcSurfaceTexture);
	RasterFormat : IfcIdentifier;
	RasterCode : IfcBinary;
 WHERE
	SupportedRasterFormat : SELF.RasterFormat IN ['BMP', 'JPG', 'GIF', 'PNG'];
	RasterCodeByteStream : BLENGTH(RasterCode) MOD 8 = 0;
END_ENTITY;

ENTITY IfcColourRgb
 SUBTYPE OF (IfcColourSpecification);
	Red : IfcNormalisedRatioMeasure;
	Green : IfcNormalisedRatioMeasure;
	Blue : IfcNormalisedRatioMeasure;
END_ENTITY;

ENTITY IfcColourRgbList
 SUBTYPE OF (IfcPresentationItem);
	ColourList : LIST [1:?] OF LIST [3:3] OF IfcNormalisedRatioMeasure;
END_ENTITY;

ENTITY IfcColourSpecification
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcColourRgb))
 SUBTYPE OF (IfcPresentationItem);
	Name : OPTIONAL IfcLabel;
END_ENTITY;

ENTITY IfcCurveStyle
 SUBTYPE OF (IfcPresentationStyle);
	CurveFont : OPTIONAL IfcCurveFontOrScaledCurveFontSelect;
	CurveWidth : OPTIONAL IfcSizeSelect;
	CurveColour : OPTIONAL IfcColour;
	ModelOrDraughting : OPTIONAL IfcBoolean;
 WHERE
	MeasureOfWidth : (NOT(EXISTS(CurveWidth))) OR
('IFCMEASURERESOURCE.IFCPOSITIVELENGTHMEASURE' IN TYPEOF(CurveWidth)) OR 
 (('IFCMEASURERESOURCE.IFCDESCRIPTIVEMEASURE' IN TYPEOF(CurveWidth)) AND
 (CurveWidth = 'by layer'));
	IdentifiableCurveStyle : EXISTS(CurveFont) OR EXISTS(CurveWidth) OR EXISTS(CurveColour);
END_ENTITY;

ENTITY IfcCurveStyleFont
 SUBTYPE OF (IfcPresentationItem);
	Name : OPTIONAL IfcLabel;
	PatternList : LIST [1:?] OF IfcCurveStyleFontPattern;
END_ENTITY;

ENTITY IfcCurveStyleFontAndScaling
 SUBTYPE OF (IfcPresentationItem);
	Name : OPTIONAL IfcLabel;
	CurveFont : IfcCurveStyleFontSelect;
	CurveFontScaling : IfcPositiveRatioMeasure;
END_ENTITY;

ENTITY IfcCurveStyleFontPattern
 SUBTYPE OF (IfcPresentationItem);
	VisibleSegmentLength : IfcLengthMeasure;
	InvisibleSegmentLength : IfcPositiveLengthMeasure;
 WHERE
	VisibleLengthGreaterEqualZero : VisibleSegmentLength >= 0.;
END_ENTITY;

ENTITY IfcDraughtingPreDefinedColour
 SUBTYPE OF (IfcPreDefinedColour);
 WHERE
	PreDefinedColourNames : SELF\IfcPreDefinedItem.Name IN ['black','red','green','blue','yellow',
     'magenta','cyan','white','by layer'];
END_ENTITY;

ENTITY IfcDraughtingPreDefinedCurveFont
 SUBTYPE OF (IfcPreDefinedCurveFont);
 WHERE
	PreDefinedCurveFontNames : SELF\IfcPredefinedItem.Name IN
       ['continuous',
        'chain',
        'chain double dash',
        'dashed',
        'dotted',
        'by layer'];
END_ENTITY;

ENTITY IfcExternallyDefinedHatchStyle
 SUBTYPE OF (IfcExternalReference);
END_ENTITY;

ENTITY IfcExternallyDefinedSurfaceStyle
 SUBTYPE OF (IfcExternalReference);
END_ENTITY;

ENTITY IfcExternallyDefinedTextFont
 SUBTYPE OF (IfcExternalReference);
END_ENTITY;

ENTITY IfcFillAreaStyle
 SUBTYPE OF (IfcPresentationStyle);
	FillStyles : SET [1:?] OF IfcFillStyleSelect;
	ModelorDraughting : OPTIONAL IfcBoolean;
 WHERE
	MaxOneColour : SIZEOF(QUERY(Style <* SELF.FillStyles |
  'IFCPRESENTATIONAPPEARANCERESOURCE.IFCCOLOUR' IN
   TYPEOF(Style)
  )) <= 1;
	MaxOneExtHatchStyle : SIZEOF(QUERY(Style <* SELF.FillStyles |
  'IFCPRESENTATIONAPPEARANCERESOURCE.IFCEXTERNALLYDEFINEDHATCHSTYLE' IN
   TYPEOF(Style)
  )) <= 1;
	ConsistentHatchStyleDef : IfcCorrectFillAreaStyle(SELF.FillStyles);
END_ENTITY;

ENTITY IfcFillAreaStyleHatching
 SUBTYPE OF (IfcGeometricRepresentationItem);
	HatchLineAppearance : IfcCurveStyle;
	StartOfNextHatchLine : IfcHatchLineDistanceSelect;
	PointOfReferenceHatchLine : OPTIONAL IfcCartesianPoint;
	PatternStart : OPTIONAL IfcCartesianPoint;
	HatchLineAngle : IfcPlaneAngleMeasure;
 WHERE
	PatternStart2D : NOT(EXISTS(PatternStart)) OR (PatternStart.Dim = 2)
;
	RefHatchLine2D : NOT(EXISTS(PointOfReferenceHatchLine)) OR (PointOfReferenceHatchLine.Dim = 2);
END_ENTITY;

ENTITY IfcFillAreaStyleTiles
 SUBTYPE OF (IfcGeometricRepresentationItem);
	TilingPattern : LIST [2:2] OF IfcVector;
	Tiles : SET [1:?] OF IfcStyledItem;
	TilingScale : IfcPositiveRatioMeasure;
END_ENTITY;

ENTITY IfcImageTexture
 SUBTYPE OF (IfcSurfaceTexture);
	URLReference : IfcURIReference;
END_ENTITY;

ENTITY IfcIndexedColourMap
 SUBTYPE OF (IfcPresentationItem);
	MappedTo : IfcTessellatedFaceSet;
	Opacity : OPTIONAL IfcNormalisedRatioMeasure;
	Colours : IfcColourRgbList;
	ColourIndex : LIST [1:?] OF IfcPositiveInteger;
END_ENTITY;

ENTITY IfcIndexedTextureMap
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcIndexedTriangleTextureMap))
 SUBTYPE OF (IfcTextureCoordinate);
	MappedTo : IfcTessellatedFaceSet;
	TexCoords : IfcTextureVertexList;
END_ENTITY;

ENTITY IfcIndexedTriangleTextureMap
 SUBTYPE OF (IfcIndexedTextureMap);
	TexCoordIndex : OPTIONAL LIST [1:?] OF LIST [3:3] OF IfcPositiveInteger;
END_ENTITY;

ENTITY IfcPixelTexture
 SUBTYPE OF (IfcSurfaceTexture);
	Width : IfcInteger;
	Height : IfcInteger;
	ColourComponents : IfcInteger;
	Pixel : LIST [1:?] OF IfcBinary;
 WHERE
	MinPixelInS : Width >= 1;
	MinPixelInT : Height >= 1;
	NumberOfColours : {1 <= ColourComponents <= 4};
	SizeOfPixelList : SIZEOF(Pixel) = (Width * Height);
	PixelAsByteAndSameLength : SIZEOF(QUERY(temp<* Pixel |
 (BLENGTH(temp) MOD 8 = 0) AND
 (BLENGTH(temp) = BLENGTH(Pixel[1]))
)) = SIZEOF(Pixel);
END_ENTITY;

ENTITY IfcPreDefinedColour
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcDraughtingPreDefinedColour))
 SUBTYPE OF (IfcPreDefinedItem);
END_ENTITY;

ENTITY IfcPreDefinedCurveFont
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcDraughtingPreDefinedCurveFont))
 SUBTYPE OF (IfcPreDefinedItem);
END_ENTITY;

ENTITY IfcPreDefinedItem
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcPreDefinedColour
    ,IfcPreDefinedCurveFont
    ,IfcPreDefinedTextFont))
 SUBTYPE OF (IfcPresentationItem);
	Name : IfcLabel;
END_ENTITY;

ENTITY IfcPreDefinedTextFont
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcTextStyleFontModel))
 SUBTYPE OF (IfcPreDefinedItem);
END_ENTITY;

ENTITY IfcPresentationStyle
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcCurveStyle
    ,IfcFillAreaStyle
    ,IfcSurfaceStyle
    ,IfcTextStyle));
	Name : OPTIONAL IfcLabel;
END_ENTITY;

ENTITY IfcPresentationStyleAssignment;
	Styles : SET [1:?] OF IfcPresentationStyleSelect;
END_ENTITY;

ENTITY IfcStyledItem
 SUBTYPE OF (IfcRepresentationItem);
	Item : OPTIONAL IfcRepresentationItem;
	Styles : SET [1:?] OF IfcStyleAssignmentSelect;
	Name : OPTIONAL IfcLabel;
 WHERE
	ApplicableItem : NOT('IFCPRESENTATIONAPPEARANCERESOURCE.IFCSTYLEDITEM' IN TYPEOF(Item));
END_ENTITY;

ENTITY IfcSurfaceStyle
 SUBTYPE OF (IfcPresentationStyle);
	Side : IfcSurfaceSide;
	Styles : SET [1:5] OF IfcSurfaceStyleElementSelect;
 WHERE
	MaxOneShading : SIZEOF(QUERY(Style <* SELF.Styles |
  'IFCPRESENTATIONAPPEARANCERESOURCE.IFCSURFACESTYLESHADING' IN
   TYPEOF(Style)
  )) <= 1;
	MaxOneLighting : SIZEOF(QUERY(Style <* SELF.Styles |
  'IFCPRESENTATIONAPPEARANCERESOURCE.IFCSURFACESTYLELIGHTING' IN
   TYPEOF(Style)
  )) <= 1;
	MaxOneRefraction : SIZEOF(QUERY(Style <* SELF.Styles |
  'IFCPRESENTATIONAPPEARANCERESOURCE.IFCSURFACESTYLEREFRACTION' IN
   TYPEOF(Style)
  )) <= 1;
	MaxOneTextures : SIZEOF(QUERY(Style <* SELF.Styles |
  'IFCPRESENTATIONAPPEARANCERESOURCE.IFCSURFACESTYLEWITHTEXTURES' IN
   TYPEOF(Style)
  )) <= 1;
	MaxOneExtDefined : SIZEOF(QUERY(Style <* SELF.Styles |
  'IFCPRESENTATIONAPPEARANCERESOURCE.IFCEXTERNALLYDEFINEDSURFACESTYLE' IN
   TYPEOF(Style)
  )) <= 1;
END_ENTITY;

ENTITY IfcSurfaceStyleLighting
 SUBTYPE OF (IfcPresentationItem);
	DiffuseTransmissionColour : IfcColourRgb;
	DiffuseReflectionColour : IfcColourRgb;
	TransmissionColour : IfcColourRgb;
	ReflectanceColour : IfcColourRgb;
END_ENTITY;

ENTITY IfcSurfaceStyleRefraction
 SUBTYPE OF (IfcPresentationItem);
	RefractionIndex : OPTIONAL IfcReal;
	DispersionFactor : OPTIONAL IfcReal;
END_ENTITY;

ENTITY IfcSurfaceStyleRendering
 SUBTYPE OF (IfcSurfaceStyleShading);
	DiffuseColour : OPTIONAL IfcColourOrFactor;
	TransmissionColour : OPTIONAL IfcColourOrFactor;
	DiffuseTransmissionColour : OPTIONAL IfcColourOrFactor;
	ReflectionColour : OPTIONAL IfcColourOrFactor;
	SpecularColour : OPTIONAL IfcColourOrFactor;
	SpecularHighlight : OPTIONAL IfcSpecularHighlightSelect;
	ReflectanceMethod : IfcReflectanceMethodEnum;
END_ENTITY;

ENTITY IfcSurfaceStyleShading
 SUPERTYPE OF (ONEOF
    (IfcSurfaceStyleRendering))
 SUBTYPE OF (IfcPresentationItem);
	SurfaceColour : IfcColourRgb;
	Transparency : OPTIONAL IfcNormalisedRatioMeasure;
END_ENTITY;

ENTITY IfcSurfaceStyleWithTextures
 SUBTYPE OF (IfcPresentationItem);
	Textures : LIST [1:?] OF IfcSurfaceTexture;
END_ENTITY;

ENTITY IfcSurfaceTexture
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcBlobTexture
    ,IfcImageTexture
    ,IfcPixelTexture))
 SUBTYPE OF (IfcPresentationItem);
	RepeatS : IfcBoolean;
	RepeatT : IfcBoolean;
	Mode : OPTIONAL IfcIdentifier;
	TextureTransform : OPTIONAL IfcCartesianTransformationOperator2D;
	Parameter : OPTIONAL LIST [1:?] OF IfcIdentifier;
 INVERSE
	IsMappedBy : SET [0:?] OF IfcTextureCoordinate FOR Maps;
	UsedInStyles : SET [0:?] OF IfcSurfaceStyleWithTextures FOR Textures;
END_ENTITY;

ENTITY IfcTextStyle
 SUBTYPE OF (IfcPresentationStyle);
	TextCharacterAppearance : OPTIONAL IfcTextStyleForDefinedFont;
	TextStyle : OPTIONAL IfcTextStyleTextModel;
	TextFontStyle : IfcTextFontSelect;
	ModelOrDraughting : OPTIONAL IfcBoolean;
END_ENTITY;

ENTITY IfcTextStyleFontModel
 SUBTYPE OF (IfcPreDefinedTextFont);
	FontFamily : LIST [1:?] OF IfcTextFontName;
	FontStyle : OPTIONAL IfcFontStyle;
	FontVariant : OPTIONAL IfcFontVariant;
	FontWeight : OPTIONAL IfcFontWeight;
	FontSize : IfcSizeSelect;
 WHERE
	MeasureOfFontSize : ('IFCMEASURERESOURCE.IFCLENGTHMEASURE' IN TYPEOF(SELF.FontSize)) AND
(SELF.FontSize > 0.);
END_ENTITY;

ENTITY IfcTextStyleForDefinedFont
 SUBTYPE OF (IfcPresentationItem);
	Colour : IfcColour;
	BackgroundColour : OPTIONAL IfcColour;
END_ENTITY;

ENTITY IfcTextStyleTextModel
 SUBTYPE OF (IfcPresentationItem);
	TextIndent : OPTIONAL IfcSizeSelect;
	TextAlign : OPTIONAL IfcTextAlignment;
	TextDecoration : OPTIONAL IfcTextDecoration;
	LetterSpacing : OPTIONAL IfcSizeSelect;
	WordSpacing : OPTIONAL IfcSizeSelect;
	TextTransform : OPTIONAL IfcTextTransformation;
	LineHeight : OPTIONAL IfcSizeSelect;
END_ENTITY;

ENTITY IfcTextureCoordinate
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcIndexedTextureMap
    ,IfcTextureCoordinateGenerator
    ,IfcTextureMap))
 SUBTYPE OF (IfcPresentationItem);
	Maps : LIST [1:?] OF IfcSurfaceTexture;
END_ENTITY;

ENTITY IfcTextureCoordinateGenerator
 SUBTYPE OF (IfcTextureCoordinate);
	Mode : IfcLabel;
	Parameter : OPTIONAL LIST [1:?] OF IfcReal;
END_ENTITY;

ENTITY IfcTextureMap
 SUBTYPE OF (IfcTextureCoordinate);
	Vertices : LIST [3:?] OF IfcTextureVertex;
	MappedTo : IfcFace;
END_ENTITY;

ENTITY IfcTextureVertex
 SUBTYPE OF (IfcPresentationItem);
	Coordinates : LIST [2:2] OF IfcParameterValue;
END_ENTITY;

ENTITY IfcTextureVertexList
 SUBTYPE OF (IfcPresentationItem);
	TexCoordsList : LIST [1:?] OF LIST [2:2] OF IfcParameterValue;
END_ENTITY;

FUNCTION IfcCorrectFillAreaStyle
  (Styles : SET[1:?] OF IfcFillStyleSelect)
  :LOGICAL;

LOCAL
   Hatching : INTEGER := 0;
   Tiles    : INTEGER := 0;
   Colour   : INTEGER := 0;
   External : INTEGER := 0;
END_LOCAL;


External := SIZEOF(QUERY(Style <* Styles |
  'IFCPRESENTATIONAPPEARANCERESOURCE.IFCEXTERNALLYDEFINEDHATCHSTYLE' IN
   TYPEOF(Style)));

Hatching  := SIZEOF(QUERY(Style <* Styles |
  'IFCPRESENTATIONAPPEARANCERESOURCE.IFCFILLAREASTYLEHATCHING' IN
   TYPEOF(Style)));

Tiles     := SIZEOF(QUERY(Style <* Styles |
  'IFCPRESENTATIONAPPEARANCERESOURCE.IFCFILLAREASTYLETILES' IN
   TYPEOF(Style)));

Colour    := SIZEOF(QUERY(Style <* Styles |
  'IFCPRESENTATIONAPPEARANCERESOURCE.IFCCOLOUR' IN
   TYPEOF(Style)));


IF (External > 1) THEN
  RETURN (FALSE);
END_IF;


IF ((External = 1) AND ((Hatching > 0) OR (Tiles > 0) OR (Colour > 0))) THEN
  RETURN (FALSE);
END_IF;


IF (Colour > 1) THEN
  RETURN (FALSE);
END_IF;

IF ((Hatching > 0) AND (Tiles >0)) THEN
  RETURN (FALSE);
END_IF;

RETURN(TRUE);
END_FUNCTION;

END_SCHEMA;
