(* 
	$Id$
	ISO TC184/SC4/WG12 N4807 - ISO/CD-TS 10303-1032 Shape property assignment - EXPRESS ARM
	Supersedes ISO TC184/SC4/WG12 N4357
*)


SCHEMA Shape_property_assignment_arm; 

USE FROM Assembly_structure_arm; -- ISO/TS 10303-1026

USE FROM Characterizable_object_arm;  -- ISO/TS 10303-1765

USE FROM External_model_arm; -- ISO/TS 10303-1033

USE FROM Product_view_definition_relationship_arm; -- ISO/TS 10303-1041


  TYPE described_element_select = SELECT (
    View_definition_usage,
    Product_occurrence_definition_relationship);
  END_TYPE;  

  TYPE geometric_item_specific_usage_select = SELECT (
    Shape_element,
    Shape_element_relationship);
  END_TYPE;  

  TYPE shape_dependent_select = SELECT
    (Item_shape, 
     Shape_element);
  END_TYPE; 

  TYPE shape_model = SELECT
    (External_geometric_model, 
     Geometric_model);
  END_TYPE; 

  TYPE shape_select = SELECT
    (Item_shape, 
     Shape_element, 
     Shape_element_relationship);
  END_TYPE; 

  TYPE shapeable_item = SELECT
    (Characterizable_object,
     Product_occurrence_definition_relationship, 
     Product_view_definition, 
     View_definition_usage);
  END_TYPE; 

  ENTITY Contextual_item_shape
    SUBTYPE OF (Item_shape);
      SELF\Item_shape.described_element : described_element_select;
    DERIVE
      shaped_product : Product_view_definition := spa_get_definition(SELF);
  END_ENTITY;

  ENTITY Geometric_item_specific_usage;
      name            : STRING;
      description     : OPTIONAL STRING;
      definition      : geometric_item_specific_usage_select;
      identified_item : Detailed_geometric_model_element;
      used_model      : shape_model;      
  END_ENTITY;
 
  ENTITY Item_shape;
    id                : OPTIONAL STRING;
    description       : OPTIONAL STRING;
    described_element : shapeable_item;
  END_ENTITY;

  ENTITY Shape_dependent_property_representation;
    characteristic_type     : STRING;
    description             : OPTIONAL STRING;
    described_element       : shape_dependent_select;
    property_representation : Representation;
  END_ENTITY;

  ENTITY Shape_description_association;
    represented_characteristic : shape_select;
    representation             : shape_model;
    role                       : OPTIONAL STRING;
    description                : OPTIONAL STRING;
  END_ENTITY;

  ENTITY Shape_element;
      id               : OPTIONAL STRING;
      element_name     : OPTIONAL STRING;
      description      : OPTIONAL STRING;
      containing_shape : Item_shape;
    WHERE
      WR1: EXISTS(element_name) OR (TYPEOF(SELF\Shape_element) <> TYPEOF(SELF));
  END_ENTITY;

  ENTITY Shape_element_relationship;
      relation_type : OPTIONAL STRING;
      description   : OPTIONAL STRING;
      relating      : Shape_element;
      related       : Shape_element;
    WHERE
      WR1: EXISTS(relation_type) OR (TYPEOF(SELF\Shape_element_relationship) <> TYPEOF(SELF));
  END_ENTITY;

  FUNCTION spa_get_definition ( input : Contextual_item_shape ): Product_view_definition;
    IF ('PRODUCT_VIEW_DEFINITION_RELATIONSHIP_ARM.VIEW_DEFINITION_USAGE'
      IN TYPEOF(input\Item_shape.described_element))
      THEN
        RETURN(input\Item_shape.described_element\View_definition_relationship.related_view);
    END_IF;
    IF ('ASSEMBLY_STRUCTURE_ARM.PRODUCT_OCCURRENCE_DEFINITION_RELATIONSHIP' IN
        TYPEOF(input\Item_shape.described_element))
      THEN
        RETURN(input\Item_shape.described_element\Product_occurrence_definition_relationship.related_view);
    END_IF;    
    RETURN(?);
  END_FUNCTION;

END_SCHEMA;  
