(*
   $Id$
   ISO TC184/SC4/WG12 N4107 - ISO/TS 10303-1720 Part template shape with parameters - EXPRESS ARM
   Supersedes ISO TC184/SC4/WG12 N3531
*)

SCHEMA Part_template_shape_with_parameters_arm;

USE FROM Non_feature_shape_element_arm;	-- ISO/TS 10303-1706
USE FROM Physical_layout_template_arm;	-- ISO/TS 10303-1722

REFERENCE FROM Characterizable_object_arm(bag_to_set);  -- ISO/TS 10303-1765

  SUBTYPE_CONSTRAINT shape_element_subtypes FOR Shape_element;
    ONEOF (Shape_feature,
      Non_feature_shape_element);
  END_SUBTYPE_CONSTRAINT;

  TYPE ptswp_external_identification_item = EXTENSIBLE GENERIC_ENTITY SELECT BASED_ON external_identification_item WITH  
    (Part_template_keepout_shape_model);
  END_TYPE;

  TYPE ptswp_requirement_assignment_item = EXTENSIBLE GENERIC_ENTITY SELECT BASED_ON requirement_assignment_item WITH 
    (Part_template_keepout_shape_model);
  END_TYPE; 

  TYPE ptswp_view_shape_select = EXTENSIBLE GENERIC_ENTITY SELECT BASED_ON view_shape_select WITH 
    (Part_template_shape_model);
  END_TYPE; 

  ENTITY Geometric_template
    ABSTRACT SUPERTYPE
    SUBTYPE OF (Template_definition);
    INVERSE
      shapes : SET [0:?] OF Part_template_shape_model FOR shape_characterized_definition;
    WHERE
      WR1 : SIZEOF(QUERY( gm <* USEDIN(SELF,'')|
        (('ELEMENTAL_GEOMETRIC_SHAPE_ARM.GEOMETRIC_MODEL' IN TYPEOF(gm)) AND 
        NOT('PART_TEMPLATE_SHAPE_WITH_PARAMETERS_ARM.PART_TEMPLATE_SHAPE_MODEL' IN
        TYPEOF(gm)))
        )) = 0;
  END_ENTITY;

  ENTITY Part_template_keepout_shape_model
		ABSTRACT SUPERTYPE
    SUBTYPE OF (Geometric_model);		
	  constrained_design_object_category : keepout_product_design_object_category;
      shape_characterized_definition     : Geometric_template;
      shape_material_condition           : material_condition;
      centroid_location                  : OPTIONAL Cartesian_point;
      shape_environment                  : application_environment;
      shape_purpose                      : OPTIONAL predefined_keepout_purpose;
    DERIVE
      principal_part_shape : SET [0:1] OF Geometric_model_relationship :=
        bag_to_set(QUERY( gmr <* USEDIN(SELF,
        'EXTENDED_BASIC_GEOMETRY_ARM.GEOMETRIC_MODEL_RELATIONSHIP.REP_2') |
         (gmr\Representation_relationship.relation_type = 'principal part shape')));      
    INVERSE
	  external_shape_purpose : SET [0:1] OF External_source_identification FOR item;      
	WHERE
	  WR1: (EXISTS (shape_purpose)) XOR ((SIZEOF(external_shape_purpose)) = 1);
      WR2: SIZEOF(USEDIN(SELF, 'SHAPE_PROPERTY_ASSIGNMENT_ARM.SHAPE_DESCRIPTION_ASSOCIATION.REPRESENTATION'))=0;      
      WR3 : SIZEOF(principal_part_shape) < 2;
  END_ENTITY;

  ENTITY Part_template_shape_model
    ABSTRACT SUPERTYPE
    SUBTYPE OF (Geometric_model);
      shape_characterized_definition : SET[1:?] OF Geometric_template;
      shape_environment              : OPTIONAL application_environment;
      shape_material_condition       : material_condition;
    DERIVE
      principal_part_shape : SET [0:1] OF Geometric_model_relationship :=
        bag_to_set(QUERY( gmr <* USEDIN(SELF,
        'EXTENDED_BASIC_GEOMETRY_ARM.GEOMETRIC_MODEL_RELATIONSHIP.REP_2') |
         (gmr\Representation_relationship.relation_type = 'principal part shape')));      
    WHERE
      WR1 : SIZEOF(principal_part_shape) < 2;
  END_ENTITY;

  ENTITY Part_template_shape_representation_relationship
  	SUBTYPE OF (Geometric_model_relationship);
      SELF\Geometric_model_relationship.rep_1 RENAMED principal_part_shape : Part_template_shape_model;
      SELF\Geometric_model_relationship.rep_2 RENAMED related_part_shape   : Part_template_shape_model;
    UNIQUE
      UR1 : principal_part_shape, related_part_shape;
    WHERE
      WR1 : principal_part_shape :<>: related_part_shape;
      WR2 : NOT EXISTS(SELF\Representation_relationship.relation_type);
      WR3 : principal_part_shape\Geometric_model.context_of_items :=: related_part_shape\Geometric_model.context_of_items;
      WR4 : principal_part_shape\Part_template_shape_model.shape_characterized_definition :=:
            related_part_shape\Part_template_shape_model.shape_characterized_definition;
  END_ENTITY;

  RULE unique_part_template_shape_model_for_geometric_template FOR
    (Geometric_template);
    LOCAL
      ptsm : SET OF Part_template_shape_model := [];
    END_LOCAL;      
    WHERE
      WR1:  SIZEOF(QUERY (gt <* Geometric_template | 
        (SIZEOF (QUERY (ptsm1 <*
        USEDIN(gt,'PART_TEMPLATE_SHAPE_WITH_PARAMETERS_ARM.PART_TEMPLATE_SHAPE_MODEL.SHAPE_CHARACTERIZED_DEFINITION') |  
        (SIZEOF (QUERY (ptsm2 <*
        USEDIN(gt,'PART_TEMPLATE_SHAPE_WITH_PARAMETERS_ARM.PART_TEMPLATE_SHAPE_MODEL.SHAPE_CHARACTERIZED_DEFINITION') |  
        ptsm1 = ptsm2)) > 1)
        )) > 0) )) = 0;  
  END_RULE;

END_SCHEMA;
