(*
   $Id$
   ISO TC184/SC4/WG12 N4068 - ISO/TS 10303-1707 Package - EXPRESS ARM
   Supersedes ISO TC184/SC4/WG12 N3498
*)

SCHEMA Package_arm;

	USE FROM Extended_geometric_tolerance_arm;	-- ISO/TS 10303-1666
	USE FROM Part_feature_function_arm;	-- ISO/TS 10303-1712
	
	REFERENCE FROM Product_identification_arm(types_of_product); -- ISO/TS 10303-1017 

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

  	TYPE mounting_technology_type = ENUMERATION OF
    	(surface_mount,
     	through_hole);
  	END_TYPE;

	TYPE pa_ee_product_definition_with_annotation_elements = EXTENSIBLE GENERIC_ENTITY SELECT BASED_ON ee_product_definition_with_annotation_elements WITH 
   		(Package);
	END_TYPE; 

 	TYPE pa_external_identification_item = EXTENSIBLE GENERIC_ENTITY SELECT BASED_ON external_identification_item WITH  
		(Package_terminal_template_definition,
		 Package);
	END_TYPE;
 
 	TYPE pa_material_item_select = EXTENSIBLE GENERIC_ENTITY SELECT BASED_ON material_item_select  WITH
   		(Package_body,
    	Package_terminal_template_definition);
	END_TYPE; 

	SUBTYPE_CONSTRAINT part_feature_subtypes FOR Part_feature; 
		(ONEOF (Package_body,
		Package_body_surface,
		Package_orientation_feature,
		Polarity_indication_feature,
		Visual_orientation_feature));
	END_SUBTYPE_CONSTRAINT;

  TYPE predefined_lead_form = ENUMERATION OF
    (gull_wing,
     j_lead,
     reversed_j_lead,
     integral_terminal,
     undefined,
     ball,
     straight);
  END_TYPE;

  TYPE seating_plane_intersection_type = ENUMERATION OF
    (surface_intersection,
     through_intersection,
     does_not_intersect);
  END_TYPE;

 	TYPE interface_plane_or_seating_plane =  SELECT
		(Seating_plane,
		 Interface_plane);
	END_TYPE;
 
  ENTITY Connection_zone_in_part_feature_template_definition
  	SUBTYPE OF (Connection_zone);
  	DERIVE
  		associated_definition : Part_feature_template_definition := containing_shape.described_element;
    WHERE
      WR1 : NOT EXISTS(SELF\Shape_element.element_name);
  END_ENTITY; 

  ENTITY Connection_zone_package_interface_plane_relationship;
      interface_plane          : interface_plane_or_seating_plane;
      mating_zone              : Connection_zone_in_part_feature_template_definition;
      derived_zone             : Connection_zone_in_part_feature_template_definition;
      derived_zone_shape_class : STRING;
    INVERSE
      associated_package_terminal  : SET[0:1] OF package_terminal_template_definition FOR seating_plane_zone;
    UNIQUE
      UR1 : interface_plane, mating_zone;
    WHERE
      WR1 : derived_zone_shape_class IN ['area','edge'];
  END_ENTITY;

  ENTITY Visual_orientation_feature
    SUBTYPE OF (Part_feature);
      associated_body_vertical_extent : OPTIONAL SET[1:2] OF Package_body_surface;
      associated_terminal             : Package_terminal;
  END_ENTITY;

  ENTITY Guided_wave_terminal
    SUBTYPE OF (Package_terminal);
  END_ENTITY;

  ENTITY Package
    SUBTYPE OF (Part_usage_view);
      mounting_technology                        : mounting_technology_type;
      maximum_seating_plane_installation_offset  : OPTIONAL Length_data_element;
      nominal_mounting_lead_pitch                : OPTIONAL Length_data_element;
      nominal_mounting_lead_span                 : OPTIONAL Length_data_element;
      maximum_body_height_above_seating_plane    : Length_data_element;
      maximum_body_height_below_seating_plane    : OPTIONAL Length_data_element;
      body_clearance_above_seating_plane         : OPTIONAL Length_tolerance_characteristic;
      body_clearance_below_seating_plane         : OPTIONAL Length_tolerance_characteristic;
      maximum_lead_length_below_seating_plane    : OPTIONAL Length_data_element;
      least_lead_length_below_seating_plane      : OPTIONAL Length_data_element;
    DERIVE
      maximum_package_total_vertical_extent : length_data_element := max_data_element(add_data_element(maximum_body_height_above_seating_plane,
 maximum_body_height_below_seating_plane),
 add_data_element(maximum_body_height_above_seating_plane,
 maximum_lead_length_below_seating_plane));
      cutout_required                       : LOGICAL := (maximum_body_height_below_seating_plane\Value_with_unit.value_component > 0.0);
      maximum_installed_height              : length_data_element := add_data_element(maximum_body_height_above_seating_plane,
 maximum_seating_plane_installation_offset);
      one_orientation_feature               : LOGICAL := (SIZEOF(orientation_feature) = 1);
      two_orientation_features              : LOGICAL := (SIZEOF(orientation_feature) = 2);
      three_orientation_features            : LOGICAL := (SIZEOF(orientation_feature) = 3);
      package_seating_plane                 : SET OF Seating_plane := bag_to_set(QUERY(nfse <* USEDIN(SELF, 'NON_FEATURE_SHAPE_ELEMENT_ARM.NON_FEATURE_SHAPE_ELEMENT.SCOPE')|
                                                'NON_FEATURE_SHAPE_ELEMENT_ARM.SEATING_PLANE' IN TYPEOF(nfse)));
      interface_plane                       : SET OF Interface_plane := bag_to_set(QUERY(nfse <* USEDIN(SELF, 'NON_FEATURE_SHAPE_ELEMENT_ARM.NON_FEATURE_SHAPE_ELEMENT.SCOPE')|
                                                'NON_FEATURE_SHAPE_ELEMENT_ARM.INTERFACE_PLANE' IN TYPEOF(nfse)));
    INVERSE
      body                                  : SET[0:1] OF Package_body FOR associated_definition;
      package_accesses                      : SET[0:?] OF Package_terminal FOR associated_definition;
      package_polarity_indication           : SET[0:1] OF Polarity_indication_feature FOR associated_definition;
      orientation_feature                   : SET[0:3] OF Package_orientation_feature FOR associated_definition;
    WHERE
      WR1  : NOT (mounting_technology = surface_mount) OR (NOT (EXISTS(maximum_lead_length_below_seating_plane) OR EXISTS(least_lead_length_below_seating_plane)));
      WR2  : NOT (EXISTS(maximum_lead_length_below_seating_plane)) OR (maximum_lead_length_below_seating_plane\Value_with_unit.value_component > 0.0);
      WR3  : NOT (EXISTS(least_lead_length_below_seating_plane)) OR (least_lead_length_below_seating_plane\Value_with_unit.value_component > 0.0);
      WR4  : SIZEOF(package_seating_plane) = 1;
      WR5  : 'package' IN types_of_product(SELF\Product_view_definition.defined_version.of_product);
      WR6  : SIZEOF(QUERY(pa <* package_accesses | 'PACKAGE_ARM.PRIMARY_REFERENCE_TERMINAL' IN TYPEOF(pa))) = 1;
	  WR7  : SIZEOF(QUERY(nt <* package_accesses |
	                      EXISTS(nt\Part_feature.precedent_feature)
	               )) = (SIZEOF(package_accesses) - 1);
	  WR8  : SIZEOF(QUERY(nt <* package_accesses |
	                     (SIZEOF(nt\Part_feature.subsequent_feature) = 1)
	               )) = (SIZEOF(package_accesses) - 1);
      WR9  : NOT one_orientation_feature    OR ('PACKAGE_ARM.PRIMARY_ORIENTATION_FEATURE' IN TYPEOF(orientation_feature[1]));
      WR10 : NOT two_orientation_features   OR ((SIZEOF(QUERY(orf <* orientation_feature |
                                                  ('PACKAGE_ARM.PRIMARY_ORIENTATION_FEATURE' IN TYPEOF(orf)))) = 1) AND
                                                (SIZEOF(QUERY(orf <* orientation_feature |
                                                  ('PACKAGE_ARM.SECONDARY_ORIENTATION_FEATURE' IN TYPEOF(orf)))) = 1));
      WR11 : NOT three_orientation_features OR ((SIZEOF(QUERY(orf <* orientation_feature |
                                                  ('PACKAGE_ARM.PRIMARY_ORIENTATION_FEATURE' IN TYPEOF(orf)))) = 1) AND
                                                (SIZEOF(QUERY(orf <* orientation_feature |
                                                  ('PACKAGE_ARM.SECONDARY_ORIENTATION_FEATURE' IN TYPEOF(orf)))) = 1) AND
                                                (SIZEOF(QUERY(orf <* orientation_feature |
                                                  ('PACKAGE_ARM.TERTIARY_ORIENTATION_FEATURE' IN TYPEOF(orf)))) = 1));
  END_ENTITY;

  ENTITY Package_body
    SUBTYPE OF (Part_feature);
      SELF\Part_feature.associated_definition : Package;
INVERSE
   body_material : Material_identification FOR items;
    WHERE
      WR1 : SIZEOF(QUERY(pf <* USEDIN(SELF,
 'PACKAGE_ARM.PACKAGE_BODY_SURFACE.ASSOCIATED_PACKAGE_BODY') | ('PACKAGE_ARM.' + 'PACKAGE_BODY_TOP_SURFACE' IN TYPEOF(pf)))) <= 1;
      WR2 : SIZEOF(QUERY(pf <* USEDIN(SELF,
 'PACKAGE_ARM.PACKAGE_BODY_SURFACE.ASSOCIATED_PACKAGE_BODY') | ('PACKAGE_ARM.' + 'PACKAGE_BODY_BOTTOM_SURFACE' IN TYPEOF(pf)))) <= 1;
      WR3 : SIZEOF(QUERY(pf <* USEDIN(SELF,
 'PACKAGE_ARM.PACKAGE_BODY_SURFACE.ASSOCIATED_PACKAGE_BODY') | ('PACKAGE_ARM.' + 'PACKAGE_BODY_EDGE_SURFACE' IN TYPEOF(pf)))) <= 1;
     WR4: 'CONDUCTIVITY_MATERIAL_ASPECTS_ARM.'+ 'MATERIAL_IDENTIFICATION_WITH_CONDUCTIVITY_CLASSIFICATION' IN TYPEOF (body_material);
  END_ENTITY;

  ENTITY Package_body_bottom_surface
    SUBTYPE OF (Package_body_surface);
  END_ENTITY;

  ENTITY Package_body_edge_segment_surface
    SUBTYPE OF (Package_body_surface);
      composed_surface : Package_body_edge_surface;
      start_vertex     : Edge_segment_vertex;
      end_vertex       : Edge_segment_vertex;
    WHERE
      WR1 : start_vertex :<>: end_vertex;
  END_ENTITY;

  ENTITY Package_body_edge_surface
    SUBTYPE OF (Package_body_surface);
  END_ENTITY;

  ENTITY Package_body_surface
    ABSTRACT SUPERTYPE OF (ONEOF (Package_body_bottom_surface,
 Package_body_top_surface,
 Package_body_edge_segment_surface,
 Package_body_edge_surface))
    SUBTYPE OF (Part_feature);
      associated_package_body : Package_body;
  END_ENTITY;

  ENTITY Package_body_top_surface
    SUBTYPE OF (Package_body_surface);
  END_ENTITY;

  ENTITY Package_orientation_feature
    ABSTRACT SUPERTYPE OF (ONEOF(Primary_orientation_feature, Secondary_orientation_feature, Tertiary_orientation_feature))
    SUBTYPE OF (Part_feature);    
           associated_body_vertical_extent : OPTIONAL SET [1:2] OF Package_body_surface;
      SELF\Part_feature.associated_definition : Package;
    WHERE
     WR1 : SIZEOF(USEDIN(SELF, 'GEOMETRIC_TOLERANCE_ARM.DATUM_DEFINED_BY_FEATURE.DEFINED_BY')) > 0;
  END_ENTITY;

  ENTITY Package_terminal
    SUBTYPE OF (Part_feature, Placed_feature);
      SELF\Placed_feature.definition 		  : Package_terminal_template_definition;
      SELF\Part_feature.associated_definition : Package;
   INVERSE
      feature_shape : SET[1:?] OF usage_concept_usage_relationship FOR associated_usage;
    WHERE
      WR1: SIZEOF(SELF\Shape_feature.surface_conditions) = 0;	  
  END_ENTITY;

  ENTITY Package_terminal_template_definition
    SUBTYPE OF (Part_feature_template_definition);
      external_connection_zone                : OPTIONAL SET[1:?] OF Connection_zone_in_part_feature_template_definition;
      internal_connection_zone                : OPTIONAL SET[1:?] OF Connection_zone_in_part_feature_template_definition;
      lead_form                               : OPTIONAL predefined_lead_form;
      seating_plane_intersection              : seating_plane_intersection_type;
      terminal_characteristic                 : OPTIONAL SET[1:?] OF characteristic;
      terminal_diametrical_extent             : Length_tolerance_characteristic;
      seating_plane_zone                      : OPTIONAL Connection_zone_package_interface_plane_relationship;
    DERIVE
      mates_with_substrate : BOOLEAN := (EXISTS(seating_plane_zone));
      terminal_core_material : SET [0:1] OF Material_identification := bag_to_set(QUERY( temp <* USEDIN(SELF,
     'GENERIC_MATERIAL_ASPECTS_ARM.MATERIAL_IDENTIFICATION.ITEMS') | 
     (SIZEOF( QUERY( cla <* USEDIN(temp,'CLASSIFICATION_ASSIGNMENT_ARM.' + 
 	'CLASSIFICATION_ASSIGNMENT.' + 'ITEMS') | cla.role = 'terminal core material')) = 1)));
      terminal_surface_material : SET [0:1] OF Material_identification := bag_to_set(QUERY( temp <* USEDIN(SELF,
     'GENERIC_MATERIAL_ASPECTS_ARM.MATERIAL_IDENTIFICATION.ITEMS') | 
     (SIZEOF( QUERY( cla <* USEDIN(temp,'CLASSIFICATION_ASSIGNMENT_ARM.' + 
 	'CLASSIFICATION_ASSIGNMENT.' + 'ITEMS') | cla.role = 'terminal surface material')) = 1)));
 	INVERSE
	  external_lead_form                      : SET[0:1] OF External_source_identification FOR item;            
    WHERE
      WR1 : NOT EXISTS(seating_plane_zone) OR (SIZEOF(QUERY(cz <* external_connection_zone | (seating_plane_zone.derived_zone = cz))) = 1);
      WR2 : NOT EXISTS(seating_plane_zone) OR (SIZEOF(QUERY(cz <* external_connection_zone | (seating_plane_zone.mating_zone = cz))) = 1);
      WR3 : NOT EXISTS(seating_plane_zone) OR ((seating_plane_intersection = surface_intersection) OR (seating_plane_intersection = through_intersection));
      WR4 : NOT ((seating_plane_intersection = does_not_intersect) AND (EXISTS(seating_plane_zone)));
      WR5 : NOT (SIZEOF(terminal_core_material) = 1) OR
                ('CONDUCTIVITY_MATERIAL_ASPECTS_ARM.MATERIAL_IDENTIFICATION_WITH_CONDUCTIVITY_CLASSIFICATION' IN TYPEOF (terminal_core_material[1]));
      WR6: (SIZEOF(terminal_surface_material) = 1) AND
                ('CONDUCTIVITY_MATERIAL_ASPECTS_ARM.MATERIAL_IDENTIFICATION_WITH_CONDUCTIVITY_CLASSIFICATION' IN TYPEOF (terminal_surface_material[1]));
	  WR7: (EXISTS (lead_form)) XOR ((SIZEOF(external_lead_form)) = 1);
  END_ENTITY;

  ENTITY Package_terminal_surface_constituent_relationship
    SUBTYPE OF (Shape_element_constituent_relationship);
      SELF\Shape_element_relationship.relating : Package_body_surface;
      SELF\Shape_element_relationship.related  : Package_terminal;
  END_ENTITY;

  ENTITY Polarity_indication_feature
    SUBTYPE OF (Part_feature);
      associated_body_vertical_extent : OPTIONAL SET[1:2] OF Package_body_surface;
      associated_terminal             : Package_terminal;
      SELF\Part_feature.associated_definition : Package;
  END_ENTITY;

  ENTITY Primary_orientation_feature
    SUBTYPE OF (Package_orientation_feature);
  END_ENTITY;

  ENTITY Primary_reference_terminal
    SUBTYPE OF (Package_terminal);
    WHERE
      WR1 : NOT (EXISTS(SELF\Part_feature.precedent_feature));
  END_ENTITY;

  ENTITY Secondary_orientation_feature
    SUBTYPE OF (Package_orientation_feature);
  END_ENTITY;

  ENTITY Tertiary_orientation_feature
    SUBTYPE OF (Package_orientation_feature);
  END_ENTITY;

  ENTITY Wire_terminal
    SUBTYPE OF (Package_terminal);
   WHERE
    WR1 : SIZEOF(SELF\Package_terminal.feature_shape) = 0;
  END_ENTITY;

  ENTITY Wire_terminal_template_definition
    SUBTYPE OF (Package_terminal_template_definition);
      SELF\Package_terminal_template_definition.internal_connection_zone : SET[1:?] OF Connection_zone_in_part_feature_template_definition;
      wire_terminal_length                                               : Length_tolerance_characteristic;
  END_ENTITY;

  FUNCTION add_data_element(
    input1 : Length_data_element ;
    input2 : Length_data_element
  ) : Length_data_element;

    RETURN(input1);
  END_FUNCTION;

  FUNCTION max_data_element(
    input1 : Length_data_element ;
    input2 : Length_data_element
  ) : Length_data_element;

    RETURN(input1);
  END_FUNCTION;

END_SCHEMA;
