(*
   $Id$
   ISO TC184/SC4/WG12 N4077 - ISO/TS 10303-1710 Packaged part black box model - EXPRESS ARM
   Supersedes ISO TC184/SC4/WG12 N3345
*)

SCHEMA Packaged_part_black_box_model_arm;

	USE FROM Functional_assignment_to_part_arm;	-- ISO/TS 10303-1674
	USE FROM Functional_usage_view_arm;	-- ISO/TS 10303-1705
	USE FROM Package_arm;	-- ISO/TS 10303-1707
	USE FROM Part_external_reference_arm;	-- ISO/TS 10303-1711

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

	TYPE package_or_package_external_reference = SELECT
  		(Package,
   		package_external_reference);
	END_TYPE;

	TYPE ppbbm_material_item_select = EXTENSIBLE GENERIC_ENTITY SELECT BASED_ON material_item_select WITH
		(Packaged_part);
	END_TYPE;

  ENTITY Packaged_part
    SUBTYPE OF (Part_usage_view);
      used_package         : SET[1:?] OF package_or_package_external_reference;
      implemented_function : OPTIONAL Functional_unit_usage_view;
    DERIVE
		potting_compound : 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 = 'potting compound')) = 1)));
		base_package : SET [1:?] OF Package := bag_to_set(QUERY(up <* used_package | 
		                                       (SIZEOF(['ALTERED_PACKAGE_ARM.ALTERED_PACKAGE',
		                                          'PART_EXTERNAL_REFERENCE_ARM.PACKAGE_EXTERNAL_REFERENCE'] * TYPEOF(up)) = 0)
		                                          ));
    INVERSE
      access_mechanisms : SET[0:?] OF packaged_part_terminal FOR associated_definition;
    WHERE
      WR1 : NOT (EXISTS(implemented_function) XOR (SIZEOF(access_mechanisms) > 0));
      WR2 : SIZEOF(base_package) = 1;
      WR3 : single_package_product(base_package, used_package);
  END_ENTITY;

  ENTITY Packaged_part_join_terminal
    SUBTYPE OF (Packaged_part_terminal);
  END_ENTITY;

  ENTITY Packaged_part_terminal
  	ABSTRACT SUPERTYPE
    SUBTYPE OF (Part_terminal);
      terminal_of_package                     : SET[1:?] OF Package_terminal;
      SELF\Part_feature.associated_definition : Packaged_part;
    WHERE
      WR1 : disjoint_package_terminals(terminal_of_package);
      WR2 : NOT EXISTS(SELF\Part_feature.precedent_feature);
  END_ENTITY;

  FUNCTION disjoint_package_terminals(
    input : SET OF Package_terminal
  ) : BOOLEAN;
  LOCAL
   pk : SET OF Package := []; -- get access to information base
  END_LOCAL;
  
  REPEAT i := 1 to HIINDEX( input);
  pk := pk + input[i].associated_definition;
  END_REPEAT;
  
    RETURN(SIZEOF(input) = SIZEOF(pk));
  END_FUNCTION;

  FUNCTION single_package_product(
    input1 : SET OF Package;
    input2 : SET OF package_or_package_external_reference
  ) : BOOLEAN;
    RETURN(TRUE);
  END_FUNCTION;

END_SCHEMA;
