(*
ISO TC184/SC4/WG12 N4830 - ISO/CD 10303-46 Visual presentation - EXPRESS
*) 


SCHEMA presentation_organization_schema;

REFERENCE FROM presentation_resource_schema
   (colour,
    planar_box,
    planar_extent,
    presentation_scaled_placement);

REFERENCE FROM presentation_definition_schema
    (annotation_occurrence,
     symbol_representation,
     symbol_representation_relationship);

REFERENCE FROM presentation_appearance_schema
    (styled_item);

REFERENCE FROM geometry_schema
    (axis2_placement,    
     axis2_placement_2d,
     axis2_placement_3d,
     cartesian_point,
     curve,
     direction,
     dot_product,
     geometric_representation_context,
     geometric_representation_item,
     plane
     );
 
REFERENCE FROM representation_schema
    (founded_item,
     item_defined_transformation,
     item_in_context,
     mapped_item,
     representation,
     representation_item,
     representation_map,
     representation_relationship,
     representation_relationship_with_transformation,
     using_representations);
 
REFERENCE FROM measure_schema
   (length_measure,
    positive_ratio_measure,
    positive_plane_angle_measure);
 
REFERENCE FROM support_resource_schema
    (identifier,
     label,
     text,
     bag_to_set);

  TYPE area_or_view = SELECT 
    (presentation_area,
     presentation_view);
  END_TYPE;

  TYPE camera_model_d3_multi_clipping_interection_select = SELECT ( 
    camera_model_d3_multi_clipping_union, 
    plane); 
  END_TYPE; 
 
  TYPE camera_model_d3_multi_clipping_union_select = SELECT ( 
    camera_model_d3_multi_clipping_intersection, 
    plane); 
  END_TYPE; 

  TYPE central_or_parallel = ENUMERATION OF 
    (central, 
     parallel);
  END_TYPE;

  TYPE layered_item = SELECT 
    (presentation_representation,
     representation_item);
  END_TYPE;

  SUBTYPE_CONSTRAINT pos_geometric_representation_item_subtypes FOR geometric_representation_item;  
      (ONEOF ( 
    camera_model, 
    camera_model_d3_multi_clipping_intersection,
    camera_model_d3_multi_clipping_union, 
    curve,
    direction,
    light_source)); 
  END_SUBTYPE_CONSTRAINT; 

  TYPE presentation_representation_select = SELECT 
    (presentation_representation,
     presentation_set);
  END_TYPE;

  TYPE presentation_size_assignment_select = SELECT 
    (presentation_view,
     presentation_area,
     area_in_set);
  END_TYPE;

  TYPE annotation_representation_select = EXTENSIBLE SELECT (
    area_dependent_annotation_representation, 
    presentation_area,
    presentation_view,
    symbol_representation,
    view_dependent_annotation_representation);
  END_TYPE;

  TYPE area_dependent_annotation_representation_item = SELECT (
    annotation_occurrence, 
    axis2_placement); 
  END_TYPE;

  TYPE product_data_representation_view_item = SELECT (
    camera_image, 
    axis2_placement); 
  END_TYPE; 

  TYPE view_dependent_annotation_representation_item = SELECT (
    annotation_occurrence, 
    axis2_placement); 
  END_TYPE;

  ENTITY area_dependent_annotation_representation
    SUBTYPE OF (presentation_representation);
      SELF\representation.items : SET[1:?] OF area_dependent_annotation_representation_item; 
    WHERE
      WR1: SIZEOF (QUERY (item <* SELF\representation.items | 
        ('PRESENTATION_DEFINITION_SCHEMA.ANNOTATION_OCCURRENCE' IN
        TYPEOF (item))
        )) >= 1;
      WR2: (SIZEOF (QUERY (prr <* USEDIN (SELF, 'REPRESENTATION_SCHEMA.' +
                                                'REPRESENTATION_RELATIONSHIP.REP_2') | 
           'PRESENTATION_ORGANIZATION_SCHEMA.PRESENTATION_AREA' IN
           TYPEOF (prr\representation_relationship.rep_1))) > 0)
                                  OR 
           (SIZEOF(QUERY( rm <* USEDIN(SELF, 'REPRESENTATION_SCHEMA.'+ 
                                             'REPRESENTATION_MAP.'+ 
                                             'MAPPED_REPRESENTATION') | 
            SIZEOF(QUERY( mi <* USEDIN(rm, 'REPRESENTATION_SCHEMA.'+
                                           'MAPPED_ITEM.'+
                                           'MAPPING_SOURCE') |   
            SIZEOF(QUERY( rep <* using_representations (mi) |                              
                                           'PRESENTATION_ORGANIZATION_SCHEMA.'+
                                           'PRESENTATION_AREA' IN 
                                           TYPEOF (rep))) > 0
            )) > 0))  
            > 0);
      WR3: (SIZEOF (QUERY (prr <* USEDIN (SELF, 'REPRESENTATION_SCHEMA.' +
                                                'REPRESENTATION_RELATIONSHIP.REP_2') | 
           NOT('PRESENTATION_ORGANIZATION_SCHEMA.PRESENTATION_AREA' IN
           TYPEOF (prr\representation_relationship.rep_1)))) = 0)
                                  AND 
           (SIZEOF(QUERY( rm <* USEDIN(SELF, 'REPRESENTATION_SCHEMA.'+ 
                                             'REPRESENTATION_MAP.'+ 
                                             'MAPPED_REPRESENTATION') | 
            SIZEOF(QUERY( mi <* USEDIN(rm, 'REPRESENTATION_SCHEMA.'+
                                           'MAPPED_ITEM.'+
                                           'MAPPING_SOURCE') |   
            SIZEOF(QUERY( rep <* using_representations (mi) |                              
                                      NOT('PRESENTATION_ORGANIZATION_SCHEMA.'+
                                          'PRESENTATION_AREA' IN 
                                          TYPEOF (rep)))) > 0
            )) > 0))  
            = 0);
  END_ENTITY;

  ENTITY area_in_set;
    area   : presentation_area;
    in_set : presentation_set;
  END_ENTITY;

  ENTITY background_colour
    SUBTYPE OF (colour);
      presentation : area_or_view;
    UNIQUE
      UR1:  presentation;
  END_ENTITY;

  ENTITY camera_image
    SUPERTYPE OF(ONEOF(camera_image_2d_with_scale,
  	  camera_image_3d_with_scale))
    SUBTYPE OF (mapped_item); 
      SELF\mapped_item.mapping_source : camera_usage;
      SELF\mapped_item.mapping_target : planar_box;
    WHERE
      WR1: 'GEOMETRY_SCHEMA.GEOMETRIC_REPRESENTATION_ITEM'
        IN TYPEOF (SELF);
  END_ENTITY;

  ENTITY camera_image_2d_with_scale
    SUBTYPE OF (camera_image);
    DERIVE
      scale : positive_ratio_measure := (SELF\mapped_item.mapping_target\planar_extent.size_in_x)/
      (SELF\mapped_item.mapping_source.mapping_origin\camera_model_d2.view_window\planar_extent.size_in_x);
    WHERE
      WR1: ('PRESENTATION_ORGANIZATION_SCHEMA.CAMERA_MODEL_D2' IN TYPEOF(SELF\mapped_item.mapping_source.mapping_origin));
      WR2: aspect_ratio (SELF\mapped_item.mapping_target) = aspect_ratio (SELF\mapped_item.mapping_source.mapping_origin\camera_model_d2.view_window);
      WR3: SELF\mapped_item.mapping_source.mapping_origin\camera_model_d2.view_window_clipping;
      WR4: NOT('PRESENTATION_ORGANIZATION_SCHEMA.CAMERA_MODEL_D2' IN TYPEOF(SELF));
  END_ENTITY;
 
  ENTITY camera_image_3d_with_scale
    SUBTYPE OF (camera_image);
    DERIVE
      scale: positive_ratio_measure := ((SELF\mapped_item.mapping_target\
           planar_extent.size_in_x) / (SELF\mapped_item.mapping_source.
           mapping_origin\camera_model_d3.perspective_of_volume.view_window.
           size_in_x));
    WHERE
      WR1: ('PRESENTATION_ORGANIZATION_SCHEMA.CAMERA_MODEL_D3'
         IN TYPEOF (SELF\mapped_item.mapping_source.mapping_origin));
      WR2: aspect_ratio(SELF\mapped_item.mapping_target) =
           aspect_ratio(SELF\mapped_item.mapping_source.mapping_origin\
           camera_model_d3.perspective_of_volume.view_window);
      WR3: SELF\mapped_item.mapping_source.mapping_origin\camera_model_d3.
           perspective_of_volume.front_plane_clipping
           AND
           SELF\mapped_item.mapping_source.mapping_origin\camera_model_d3.
           perspective_of_volume.view_volume_sides_clipping;
      WR4: (SELF\mapped_item.mapping_target\planar_extent.size_in_x > 0)
           AND
           (SELF\mapped_item.mapping_target\planar_extent.size_in_y > 0);
      WR5: (SELF\mapped_item.mapping_source.mapping_origin\camera_model_d3.
           perspective_of_volume.view_window.size_in_x > 0)
           AND
           (SELF\mapped_item.mapping_source.mapping_origin\camera_model_d3.
           perspective_of_volume.view_window.size_in_y > 0);
      WR6: ('GEOMETRY_SCHEMA.' +
            'AXIS2_PLACEMENT_2D' IN TYPEOF (SELF\mapped_item.
           mapping_target\planar_box.placement))
           AND NOT ('GEOMETRY_SCHEMA.' +
           'AXIS2_PLACEMENT_3D' IN TYPEOF (SELF\mapped_item.
           mapping_target\planar_box.placement));
  END_ENTITY;

  ENTITY camera_model
    ABSTRACT
    SUPERTYPE OF (ONEOF(camera_model_d2, camera_model_d3))
    SUBTYPE OF (geometric_representation_item);
    WHERE
      WR1: (SIZEOF (USEDIN (SELF, 'REPRESENTATION_SCHEMA.' +
                                  'ITEM_DEFINED_TRANSFORMATION.' +
                                  'TRANSFORM_ITEM_1')) +
            SIZEOF (USEDIN (SELF, 'REPRESENTATION_SCHEMA.' +
                                  'REPRESENTATION_MAP.MAPPING_ORIGIN'))
            ) > 0;
      WR2: SIZEOF(USEDIN(SELF,'PRESENTATION_APPEARANCE_SCHEMA.'+
                              'STYLED_ITEM.ITEM')) = 0;
  END_ENTITY;

  ENTITY camera_model_d2
    SUBTYPE OF (camera_model);
      view_window          : planar_box;
      view_window_clipping : BOOLEAN;
    WHERE
      WR1: SELF\geometric_representation_item.dim = 2;
      WR2: NOT('PRESENTATION_ORGANIZATION_SCHEMA.CAMERA_IMAGE_2D_WITH_SCALE' IN TYPEOF(SELF));      
  END_ENTITY;

  ENTITY camera_model_d2_shape_clipping
    SUBTYPE OF (camera_model_d2);
      shape_clipping : curve;
  END_ENTITY;

  ENTITY camera_model_d3
    SUBTYPE OF (camera_model);
      view_reference_system : axis2_placement_3d;
      perspective_of_volume : view_volume;
    WHERE
      WR1: (dot_product (SELF.view_reference_system.p[3],
           SELF.perspective_of_volume.view_window.placement.p[3]) = 1.0)
           AND
           (SELF.view_reference_system.location.coordinates[3] =
           SELF.perspective_of_volume.view_window.
             placement.location.coordinates[3]);
      WR2: SELF\geometric_representation_item.dim = 3;
  END_ENTITY;

  ENTITY camera_model_d3_multi_clipping 
    SUBTYPE OF (camera_model_d3); 
      shape_clipping : SET [1:?] OF camera_model_d3_multi_clipping_interection_select; 
  END_ENTITY; 
 
  ENTITY camera_model_d3_multi_clipping_union 
    SUBTYPE OF (geometric_representation_item); 
      shape_clipping : SET [2:?] OF camera_model_d3_multi_clipping_union_select; 
  END_ENTITY;   
 
  ENTITY camera_model_d3_multi_clipping_intersection 
    SUBTYPE OF (geometric_representation_item); 
      shape_clipping : SET [2:?] OF camera_model_d3_multi_clipping_interection_select; 
  END_ENTITY;

  ENTITY camera_model_d3_with_hlhsr
    SUBTYPE OF (camera_model_d3);
      hidden_line_surface_removal : BOOLEAN;
  END_ENTITY;

  ENTITY camera_model_with_light_sources
    SUBTYPE OF (camera_model_d3);
      sources : SET [1:?] OF light_source;
  END_ENTITY;

  ENTITY camera_usage
    SUBTYPE OF (representation_map);
      SELF\representation_map.mapping_origin : camera_model;
    WHERE
      WR1: NOT ('PRESENTATION_ORGANIZATION_SCHEMA.PRESENTATION_REPRESENTATION'
          IN TYPEOF(SELF\representation_map.mapped_representation));
  END_ENTITY;

  ENTITY graphical_transformation
    SUBTYPE OF (item_defined_transformation);
      SELF\item_defined_transformation.transform_item_1 : axis2_placement_2d;
      SELF\item_defined_transformation.transform_item_2 : presentation_scaled_placement;
  END_ENTITY;

  ENTITY light_source
    SUPERTYPE OF (ONEOF(light_source_ambient,
                        light_source_directional,
                        light_source_positional,
                        light_source_spot))
    SUBTYPE OF (geometric_representation_item);
      light_colour : colour;
    WHERE
      WR1: SIZEOF(USEDIN(SELF,'PRESENTATION_APPEARANCE_SCHEMA.'+
                              'STYLED_ITEM.ITEM')) = 0;
  END_ENTITY;

  ENTITY light_source_ambient
    SUBTYPE OF (light_source);
  END_ENTITY;

  ENTITY light_source_directional
    SUBTYPE OF (light_source);
      orientation : direction;
  END_ENTITY;

  ENTITY light_source_positional
    SUBTYPE OF (light_source);
      position             : cartesian_point;
      constant_attenuation : REAL;
      distance_attenuation : REAL;
  END_ENTITY;

  ENTITY light_source_spot
    SUBTYPE OF (light_source);
      position               : cartesian_point;
      orientation            : direction;
      concentration_exponent : REAL;
      constant_attenuation   : REAL;
      distance_attenuation   : REAL;
      spread_angle           : positive_plane_angle_measure;
  END_ENTITY;

  ENTITY presentation_area
    SUBTYPE OF (presentation_representation);
    WHERE
      WR1: ((SIZEOF (QUERY (ais <* USEDIN (SELF, 'PRESENTATION_ORGANIZATION_SCHEMA.' +
                                                 'AREA_IN_SET.AREA') | 
             SIZEOF (USEDIN (ais, 'PRESENTATION_ORGANIZATION_SCHEMA.' +
                                  'PRESENTATION_SIZE.UNIT')) =1)) > 0) OR
            (SIZEOF (USEDIN (SELF, 'PRESENTATION_ORGANIZATION_SCHEMA.' +
                                   'PRESENTATION_SIZE.UNIT')) =1));
  END_ENTITY;

  ENTITY presentation_layer_assignment;
    name           : label;
    description    : text;
    assigned_items : SET [1:?] OF layered_item;
  END_ENTITY;

  ENTITY presentation_layer_usage;
      assignment   : presentation_layer_assignment;
      presentation : presentation_representation;
    UNIQUE
      UR1: assignment, presentation;
  END_ENTITY;

  ENTITY presentation_representation
    SUPERTYPE OF (ONEOF(area_dependent_annotation_representation,
      presentation_area,
      presentation_view,
      product_data_representation_view,
      view_dependent_annotation_representation))
    SUBTYPE OF (representation);
      SELF\representation.context_of_items : geometric_representation_context;
    WHERE
      WR1: SELF\representation.
           context_of_items\geometric_representation_context.
           coordinate_space_dimension = 2;
      WR2: ('PRESENTATION_ORGANIZATION_SCHEMA.PRESENTATION_AREA' IN TYPEOF (SELF))
           OR
           (SIZEOF (QUERY (prr <* USEDIN (SELF, 'REPRESENTATION_SCHEMA.' +
                                                'REPRESENTATION_RELATIONSHIP.REP_2') | 
           'PRESENTATION_ORGANIZATION_SCHEMA.PRESENTATION_REPRESENTATION' IN
           TYPEOF (prr\representation_relationship.rep_1))) > 0)
           OR 
           (SIZEOF(QUERY( rm <* USEDIN(SELF, 'REPRESENTATION_SCHEMA.'+ 
                                             'REPRESENTATION_MAP.'+ 
                                             'MAPPED_REPRESENTATION') | 
           SIZEOF(QUERY( mi <* USEDIN(rm, 'REPRESENTATION_SCHEMA.'+
                                          'MAPPED_ITEM.'+
                                          'MAPPING_SOURCE') |   
           SIZEOF(QUERY( rep <* using_representations (mi) |                              
                                        'PRESENTATION_ORGANIZATION_SCHEMA.'+
                                        'PRESENTATION_REPRESENTATION' IN 
                                        TYPEOF (rep))) > 0
           )) > 0))  
           > 0);
  END_ENTITY;

  ENTITY presentation_representation_relationship
    SUBTYPE OF (representation_relationship_with_transformation);
      SELF\representation_relationship.rep_1                                       : presentation_representation; 
      SELF\representation_relationship.rep_2                                       : presentation_representation; 
      SELF\representation_relationship_with_transformation.transformation_operator : graphical_transformation;
    WHERE
      WR1: acyclic_presentation_representation_relationship (SELF,
           [SELF\representation_relationship.rep_2]);
      WR2: NOT (('PRESENTATION_ORGANIZATION_SCHEMA.PRESENTATION_AREA' IN
           TYPEOF (SELF\representation_relationship.rep_1)) 
           AND
           NOT (SIZEOF (['PRESENTATION_ORGANIZATION_SCHEMA.' +
                         'PRODUCT_DATA_REPRESENTATION_VIEW',
                         'PRESENTATION_ORGANIZATION_SCHEMA.' +
                         'VIEW_DEPENDENT_ANNOTATION_REPRESENTATION'] *
           TYPEOF (SELF\representation_relationship.rep_2)) = 0));
      WR3: NOT (('PRESENTATION_ORGANIZATION_SCHEMA.PRESENTATION_VIEW'
           IN TYPEOF (SELF\representation_relationship.rep_1))
           AND
           NOT (SIZEOF (['PRESENTATION_ORGANIZATION_SCHEMA.' +
                         'PRESENTATION_AREA',
                         'PRESENTATION_ORGANIZATION_SCHEMA.' +
                         'PRESENTATION_VIEW',
                         'PRESENTATION_ORGANIZATION_SCHEMA.' +
                         'AREA_DEPENDENT_ANNOTATION_REPRESENTATION'] *
                TYPEOF (SELF\representation_relationship.rep_2))=0));
      WR4: (NOT ('PRESENTATION_ORGANIZATION_SCHEMA.PRESENTATION_VIEW' IN
           TYPEOF(SELF\representation_relationship.rep_2)))
              XOR
           ('PRESENTATION_ORGANIZATION_SCHEMA.PRESENTATION_AREA'IN
           TYPEOF(SELF\representation_relationship.rep_1));
      WR5: (NOT ('PRESENTATION_ORGANIZATION_SCHEMA.' +
                 'PRODUCT_DATA_REPRESENTATION_VIEW' IN
           (TYPEOF(SELF\representation_relationship.rep_1) +
            TYPEOF(SELF\representation_relationship.rep_2))))
              XOR
           ('PRESENTATION_ORGANIZATION_SCHEMA.PRESENTATION_VIEW' IN
            TYPEOF(SELF\representation_relationship.rep_1))
              AND
           ('PRESENTATION_ORGANIZATION_SCHEMA.PRODUCT_DATA_REPRESENTATION_VIEW' IN
            TYPEOF(SELF\representation_relationship.rep_2));
  END_ENTITY;

  ENTITY presentation_set;
   INVERSE
     areas : SET [1:?] OF area_in_set FOR in_set;
  END_ENTITY;

  ENTITY presentation_size;
      unit : presentation_size_assignment_select;
      size : planar_box;
    UNIQUE
      UR1: unit;
    WHERE
      WR1: (('PRESENTATION_ORGANIZATION_SCHEMA.PRESENTATION_REPRESENTATION'
           IN TYPEOF (SELF.unit)) AND
           item_in_context (SELF.size, 
                            SELF.unit\representation.context_of_items)
           )
           OR
           (('PRESENTATION_ORGANIZATION_SCHEMA.AREA_IN_SET'
           IN TYPEOF (SELF.unit)) AND
           (SIZEOF (QUERY ( ais <* SELF.unit\area_in_set.in_set.areas |
                NOT item_in_context (SELF.size, ais.area\representation.
                                                context_of_items) )) = 0)); 
  END_ENTITY;

  ENTITY presentation_view
    SUBTYPE OF (presentation_representation);
  END_ENTITY;

  ENTITY presented_item
    ABSTRACT SUPERTYPE;
  END_ENTITY;

  ENTITY presented_item_representation;
    presentation : presentation_representation_select;
    item         : presented_item;
  END_ENTITY;

  ENTITY product_data_representation_view
    SUBTYPE OF (presentation_representation);
      SELF\representation.items : SET[1:?] OF product_data_representation_view_item;
    WHERE
      WR1: SIZEOF (QUERY (item <* SELF\representation.items | 
        ('PRESENTATION_ORGANIZATION_SCHEMA.CAMERA_IMAGE' IN
         TYPEOF (item))
        )) >= 1;
      WR2: (SIZEOF (QUERY (prr <* USEDIN (SELF, 'REPRESENTATION_SCHEMA.' +
                                                'REPRESENTATION_RELATIONSHIP.REP_2') | 
           'PRESENTATION_ORGANIZATION_SCHEMA.PRESENTATION_VIEW' IN
           TYPEOF (prr\representation_relationship.rep_1))) > 0)
                                  OR 
           (SIZEOF(QUERY( rm <* USEDIN(SELF, 'REPRESENTATION_SCHEMA.'+ 
                                             'REPRESENTATION_MAP.'+ 
                                             'MAPPED_REPRESENTATION') | 
           SIZEOF(QUERY( mi <* USEDIN(rm, 'REPRESENTATION_SCHEMA.'+
                                          'MAPPED_ITEM.'+
                                          'MAPPING_SOURCE') |   
           SIZEOF(QUERY( rep <* using_representations (mi) |                              
                                       'PRESENTATION_ORGANIZATION_SCHEMA.'+
                                       'PRESENTATION_VIEW' IN 
                                        TYPEOF (rep))) > 0
           )) > 0))  
               > 0);
      WR3: (SIZEOF (QUERY (prr <* USEDIN (SELF, 'REPRESENTATION_SCHEMA.' +
                                                'REPRESENTATION_RELATIONSHIP.REP_2') | 
            NOT('PRESENTATION_ORGANIZATION_SCHEMA.PRESENTATION_VIEW' IN
            TYPEOF (prr\representation_relationship.rep_1)))) = 0)
                                  AND 
           (SIZEOF(QUERY( rm <* USEDIN(SELF, 'REPRESENTATION_SCHEMA.'+ 
                                             'REPRESENTATION_MAP.'+ 
                                             'MAPPED_REPRESENTATION') | 
            SIZEOF(QUERY( mi <* USEDIN(rm, 'REPRESENTATION_SCHEMA.'+
                                           'MAPPED_ITEM.'+
                                           'MAPPING_SOURCE') |   
            SIZEOF(QUERY( rep <* using_representations (mi) |                              
                                       NOT('PRESENTATION_ORGANIZATION_SCHEMA.'+
                                           'PRESENTATION_VIEW' IN 
                                       TYPEOF (rep)))) > 0
            )) > 0))  
            = 0);
  END_ENTITY;

  ENTITY representation_item_dependent_layer_assignment
    SUBTYPE OF (presentation_layer_assignment);
      item_context : representation_item;
  END_ENTITY;

  ENTITY view_dependent_annotation_representation
    SUBTYPE OF (presentation_representation);
      SELF\representation.items : SET [1:?] OF view_dependent_annotation_representation_item;
    WHERE
      WR1: SIZEOF (QUERY (item <* SELF\representation.items |
        ('PRESENTATION_DEFINITION_SCHEMA.ANNOTATION_OCCURRENCE' IN
        TYPEOF (item))
        )) >= 1;
      WR2: (SIZEOF (QUERY (prr <* USEDIN (SELF, 'REPRESENTATION_SCHEMA.' +
                                                'REPRESENTATION_RELATIONSHIP.REP_2') | 
           'PRESENTATION_ORGANIZATION_SCHEMA.PRESENTATION_VIEW' IN
           TYPEOF (prr\representation_relationship.rep_1))) > 0)
                                  OR 
          (SIZEOF(QUERY( rm <* USEDIN(SELF, 'REPRESENTATION_SCHEMA.'+ 
                                            'REPRESENTATION_MAP.'+ 
                                            'MAPPED_REPRESENTATION') | 
           SIZEOF(QUERY( mi <* USEDIN(rm, 'REPRESENTATION_SCHEMA.'+
                                          'MAPPED_ITEM.'+
                                          'MAPPING_SOURCE') |   
           SIZEOF(QUERY( rep <* using_representations (mi) |                              
                                       'PRESENTATION_ORGANIZATION_SCHEMA.'+
                                       'PRESENTATION_VIEW' IN 
                                        TYPEOF (rep))) > 0
           )) > 0))  
           > 0);
      WR3: (SIZEOF (QUERY (prr <* USEDIN (SELF, 'REPRESENTATION_SCHEMA.' +
                                                'REPRESENTATION_RELATIONSHIP.REP_2') | 
           NOT('PRESENTATION_ORGANIZATION_SCHEMA.PRESENTATION_VIEW' IN
           TYPEOF (prr\representation_relationship.rep_1)))) = 0)
                                  AND 
           (SIZEOF(QUERY( rm <* USEDIN(SELF, 'REPRESENTATION_SCHEMA.'+ 
                                             'REPRESENTATION_MAP.'+ 
                                             'MAPPED_REPRESENTATION') | 
            SIZEOF(QUERY( mi <* USEDIN(rm, 'REPRESENTATION_SCHEMA.'+
                                           'MAPPED_ITEM.'+
                                           'MAPPING_SOURCE') |   
            SIZEOF(QUERY( rep <* using_representations (mi) |                              
                                      NOT('PRESENTATION_ORGANIZATION_SCHEMA.'+
                                          'PRESENTATION_VIEW' IN 
                                      TYPEOF (rep)))) > 0
           )) > 0))  
           = 0);
  END_ENTITY;

  ENTITY view_volume
    SUBTYPE OF (founded_item);
      projection_type            : central_or_parallel;
      projection_point           : cartesian_point;
      view_plane_distance        : length_measure;
      front_plane_distance       : length_measure;
      front_plane_clipping       : BOOLEAN;
      back_plane_distance        : length_measure;
      back_plane_clipping        : BOOLEAN;
      view_volume_sides_clipping : BOOLEAN;
      view_window                : planar_box;
  END_ENTITY;

  RULE symbol_representation_rule
    FOR (presentation_representation_relationship);
    WHERE
      WR1: SIZEOF(QUERY(each_1 <* presentation_representation_relationship  |
                NOT ('PRESENTATION_DEFINITION_SCHEMA.'+
                'SYMBOL_REPRESENTATION_RELATIONSHIP' IN TYPEOF(each_1)) AND
          (SIZEOF(QUERY(each_2 <* [each_1\representation_relationship.rep_1,
                                   each_1\representation_relationship.rep_2] |
          'PRESENTATION_DEFINITION_SCHEMA.SYMBOL_REPRESENTATION' IN TYPEOF(each_2)
          )) > 0)
          )) = 0;
  END_RULE;

  FUNCTION acyclic_presentation_representation_relationship
    ( relation : presentation_representation_relationship;
      children : SET OF presentation_representation ) : BOOLEAN;

    LOCAL
      x : SET OF presentation_representation_relationship;
      local_children : SET OF presentation_representation;
    END_LOCAL;

    REPEAT i:=1 TO HIINDEX(children);
      IF relation\representation_relationship.rep_1 :=: children[i] THEN
        RETURN(FALSE);
      END_IF;
    END_REPEAT;

    x := bag_to_set (USEDIN ( relation\representation_relationship.rep_1,
                  'REPRESENTATION_SCHEMA.'+
                  'REPRESENTATION_RELATIONSHIP.REP_2'));
    local_children := children + relation\representation_relationship.rep_1;

    IF SIZEOF (x) > 0 THEN
      REPEAT i:=1 TO HIINDEX (x);
        IF NOT acyclic_presentation_representation_relationship
          (x[i] , local_children) THEN
          RETURN (FALSE);
        END_IF;
      END_REPEAT;
    END_IF;

    RETURN (TRUE);

  END_FUNCTION;

  FUNCTION aspect_ratio (p : planar_box) : positive_ratio_measure;
    IF (p.size_in_x > 0.) AND (p.size_in_y > 0.) THEN
      RETURN (p.size_in_x / p.size_in_y);
    ELSE
      RETURN (?);
    END_IF;
  END_FUNCTION; 

END_SCHEMA; 
