(*
 * $Id$
 *
 * JSDAI(TM), a way to implement STEP, ISO 10303
 * Copyright (C) 1997-2008, LKSoftWare GmbH, Germany
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License
 * version 3 as published by the Free Software Foundation (AGPL v3).
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * JSDAI is a registered trademark of LKSoftWare GmbH, Germany
 * This software is also available under commercial licenses.
 * See also http://www.jsdai.net/
 *)

(*
   Derived from ISO TC184/SC4/WG12 N - ISO/CD-TS 10303-xxxx Package - EXPRESS ARM
   by LKSoftWare GmbH for implementation purpose within IDA-STEP(TM)
*)



SCHEMA Package_xim;

USE FROM Extended_geometric_tolerance_xim;

USE FROM Part_feature_function_xim;

USE FROM Feature_and_connection_zone_mim;

USE FROM Package_mim;

REFERENCE FROM Product_identification_xim(types_of_product);

REFERENCE FROM support_resource_schema   -- ISO 10303-41
  (bag_to_set);

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

  TYPE pa_material_item_select = EXTENSIBLE GENERIC_ENTITY SELECT BASED_ON material_item_select  WITH
     (Package_body_armx,
      Package_terminal_armx,
      Package_terminal_template_definition_armx);
  END_TYPE;

  SUBTYPE_CONSTRAINT part_feature_subtypes FOR Part_feature; 
    (ONEOF (Package_body_armx,
	  Package_body_surface_armx,
      Package_orientation_feature,
      Polarity_indication_feature,
      Visual_orientation_feature_armx));
  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;
  		SELF\Shape_element.element_name : STRING := '';
  END_ENTITY; 

  ENTITY Connection_zone_package_interface_plane_relationship
  (* CONNOTATIONAL *) SUBTYPE OF (connection_zone_interface_plane_relationship);
      SELF\shape_aspect_relationship.relating_shape_aspect RENAMED interface_plane : interface_plane_or_seating_plane;
      SELF\shape_aspect_relationship.related_shape_aspect RENAMED mating_zone      : Connection_zone_in_part_feature_template_definition;
      derived_zone                                                                 : Connection_zone_in_part_feature_template_definition;
      SELF\shape_aspect_relationship.description RENAMED derived_zone_shape_class  : text;
    DERIVE
      SELF\shape_aspect.of_shape : product_definition_shape := ?;
      SELF\shape_aspect.description : text := ?;
      SELF\shape_aspect.product_definitional : LOGICAL := ?;
      SELF\shape_aspect.name : label := ?;
    INVERSE
      associated_package_terminal  : SET[0:1] OF package_terminal_template_definition_armx 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_armx
    (* CONNOTATIONAL *) SUBTYPE OF (visual_orientation_feature, Part_feature);
      associated_body_vertical_extent : OPTIONAL SET[1:2] OF Package_body_surface_armx;
      associated_terminal             : Package_terminal_armx;
  END_ENTITY;

  ENTITY Guided_wave_terminal_armx
    (* CONNOTATIONAL *) SUBTYPE OF (Package_terminal_armx, guided_wave_terminal);
  END_ENTITY;

  ENTITY Package_armx
    (* CONNOTATIONAL *) SUBTYPE OF (Part_usage_view, package);
      mounting_technology                        : mounting_technology_type;
      maximum_seating_plane_installation_offset  : OPTIONAL length_measure_with_unit;
      nominal_mounting_lead_pitch                : OPTIONAL length_measure_with_unit;
      nominal_mounting_lead_span                 : OPTIONAL length_measure_with_unit;
      maximum_body_height_above_seating_plane    : length_measure_with_unit;
      maximum_body_height_below_seating_plane    : OPTIONAL length_measure_with_unit;
      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_measure_with_unit;
      least_lead_length_below_seating_plane      : OPTIONAL length_measure_with_unit;
    DERIVE
      maximum_package_total_vertical_extent : length_measure_with_unit := 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\measure_with_unit.value_component > 0.0);
      maximum_installed_height              : length_measure_with_unit := 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_armx := bag_to_set(QUERY(nfse <* USEDIN(SELF, 'NON_FEATURE_SHAPE_ELEMENT_XIM.NON_FEATURE_SHAPE_ELEMENT.SCOPE')|
                                                'NON_FEATURE_SHAPE_ELEMENT_XIM.SEATING_PLANE_ARMX' IN TYPEOF(nfse)));
      interface_plane                       : SET OF Interface_plane := bag_to_set(QUERY(nfse <* USEDIN(SELF, 'NON_FEATURE_SHAPE_ELEMENT_XIM.NON_FEATURE_SHAPE_ELEMENT.SCOPE')|
                                                'NON_FEATURE_SHAPE_ELEMENT_ARM.INTERFACE_PLANE' IN TYPEOF(nfse)));      
    INVERSE
      body                                  : SET[0:1] OF package_body_armx FOR containing_shape(* TEMP-AD! *);
      package_accesses                      : SET[0:?] OF package_terminal_armx FOR containing_shape(* TEMP-AD! *);
      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\measure_with_unit.value_component > 0.0);
      WR3  : NOT (EXISTS(least_lead_length_below_seating_plane)) OR (least_lead_length_below_seating_plane\measure_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_XIM.PRIMARY_REFERENCE_TERMINAL_ARMX' 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_XIM.PRIMARY_ORIENTATION_FEATURE_ARMX' IN TYPEOF(orientation_feature[1]));
      WR10 : NOT two_orientation_features   OR ((SIZEOF(QUERY(orf <* orientation_feature |
                                                  ('PACKAGE_XIM.PRIMARY_ORIENTATION_FEATURE_ARMX' IN TYPEOF(orf)))) = 1) AND
                                                (SIZEOF(QUERY(orf <* orientation_feature |
                                                  ('PACKAGE_XIM.SECONDARY_ORIENTATION_FEATURE_ARMX' IN TYPEOF(orf)))) = 1));
      WR11 : NOT three_orientation_features OR ((SIZEOF(QUERY(orf <* orientation_feature |      
                                                  ('PACKAGE_XIM.PRIMARY_ORIENTATION_FEATURE_ARMX' IN TYPEOF(orf)))) = 1) AND
                                                (SIZEOF(QUERY(orf <* orientation_feature |
                                                  ('PACKAGE_XIM.SECONDARY_ORIENTATION_FEATURE_ARMX' IN TYPEOF(orf)))) = 1) AND
                                                (SIZEOF(QUERY(orf <* orientation_feature |
                                                  ('PACKAGE_XIM.TERTIARY_ORIENTATION_FEATURE_ARMX' IN TYPEOF(orf)))) = 1));
  END_ENTITY;

  ENTITY Package_body_armx
    (* CONNOTATIONAL *) SUBTYPE OF (Part_feature, package_body);
      SELF\Shape_element.containing_shape(* TEMP-PF! *) : Package_armx;
    INVERSE
      body_material : material_designation FOR definitions;
    WHERE
      WR1 : SIZEOF(QUERY(pf <* USEDIN(SELF,
 'PACKAGE_XIM.PACKAGE_BODY_SURFACE_ARMX.ASSOCIATED_PACKAGE_BODY') | ('PACKAGE_XIM.' + 'PACKAGE_BODY_TOP_SURFACE_ARMX' IN TYPEOF(pf)))) <= 1;
      WR2 : SIZEOF(QUERY(pf <* USEDIN(SELF,
 'PACKAGE_XIM.PACKAGE_BODY_SURFACE_ARMX.ASSOCIATED_PACKAGE_BODY') | ('PACKAGE_XIM.' + 'PACKAGE_BODY_BOTTOM_SURFACE_ARMX' IN TYPEOF(pf)))) <= 1;
      WR3 : SIZEOF(QUERY(pf <* USEDIN(SELF,
 'PACKAGE_XIM.PACKAGE_BODY_SURFACE_ARMX.ASSOCIATED_PACKAGE_BODY') | ('PACKAGE_XIM.' + 'PACKAGE_BODY_EDGE_SURFACE_ARMX' IN TYPEOF(pf)))) <= 1;
     WR4: 'CONDUCTIVITY_MATERIAL_ASPECTS_XIM.'+ 'MATERIAL_IDENTIFICATION_WITH_CONDUCTIVITY_CLASSIFICATION' IN TYPEOF (body_material);
  END_ENTITY;

  ENTITY Package_body_bottom_surface_armx
    (* CONNOTATIONAL *) SUBTYPE OF (Package_body_surface_armx, package_body_bottom_surface);
  END_ENTITY;

  ENTITY Package_body_edge_segment_surface_armx
    (* CONNOTATIONAL *) SUBTYPE OF (Package_body_surface_armx, package_body_edge_segment_surface);
      composed_surface 																													: Package_body_edge_surface_armx;
      SELF\shape_aspect_relationship.relating_shape_aspect RENAMED start_vertex	: Edge_segment_vertex_armx;
      SELF\shape_aspect_relationship.related_shape_aspect RENAMED end_vertex		: Edge_segment_vertex_armx;
    WHERE
      WR1 : start_vertex :<>: end_vertex;
  END_ENTITY;

  ENTITY Package_body_edge_surface_armx
    (* CONNOTATIONAL *) SUBTYPE OF (Package_body_surface_armx, package_body_edge_surface);
  END_ENTITY;
 
  ENTITY Package_body_surface_armx
    ABSTRACT SUPERTYPE OF (ONEOF (Package_body_bottom_surface_armx,
 Package_body_top_surface_armx,
 Package_body_edge_segment_surface_armx,
 Package_body_edge_surface_armx))
    (* CONNOTATIONAL *) SUBTYPE OF (Part_feature, package_body_surface);
      associated_package_body : Package_body_armx;
  END_ENTITY;

  ENTITY Package_body_top_surface_armx
    (* CONNOTATIONAL *) SUBTYPE OF (Package_body_surface_armx, package_body_top_surface);
  END_ENTITY;

  ENTITY Package_orientation_feature
    ABSTRACT SUPERTYPE OF (ONEOF(Primary_orientation_feature_armx, Secondary_orientation_feature_armx, Tertiary_orientation_feature_armx))
    (* CONNOTATIONAL *) SUBTYPE OF (Part_feature);    
      associated_body_vertical_extent         : OPTIONAL SET [1:2] OF Package_body_surface_armx;
      SELF\Part_feature.associated_definition : Package_armx;
    WHERE
     WR1 : SIZEOF(USEDIN(SELF, 'GEOMETRIC_TOLERANCE_XIM.DATUM_DEFINED_BY_FEATURE.DEFINED_BY')) > 0;
  END_ENTITY;

(** attribute model_representation changed to analytical_model_assignment
*)

  ENTITY Package_terminal_armx
    SUBTYPE OF (Part_feature, Placed_feature_armx, package_terminal);
      SELF\Placed_feature_armx.definition 	  : Package_terminal_template_definition_armx;
      SELF\Part_feature.associated_definition : Package_armx;
   INVERSE
      feature_shape : SET[1:?] OF usage_concept_usage_relationship_armx FOR associated_usage;
   WHERE
      WR1: SIZEOF(SELF\Shape_feature.surface_conditions) = 0;	        
  END_ENTITY;

  ENTITY Package_terminal_template_definition_armx
    SUBTYPE OF (Part_feature_template_definition_armx, package_terminal_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             : OPTIONAL 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_designation := bag_to_set(QUERY( temp <* USEDIN(SELF,
     'MATERIAL_PROPERTY_DEFINITION_SCHEMA.MATERIAL_DESIGNATION.DEFINITIONS') | 
     (SIZEOF( QUERY( cla <* USEDIN(temp,'CLASSIFICATION_ASSIGNMENT_MIM.' + 
 	'APPLIED_CLASSIFICATION_ASSIGNMENT.' + 'ITEMS') | cla.role = 'terminal core material')) = 1)));
      terminal_surface_material : SET [0:1] OF material_designation := bag_to_set(QUERY( temp <* USEDIN(SELF,
     'MATERIAL_PROPERTY_DEFINITION_SCHEMA.MATERIAL_DESIGNATION.DEFINITIONS') | 
     (SIZEOF( QUERY( cla <* USEDIN(temp,'CLASSIFICATION_ASSIGNMENT_MIM.' + 
 	'APPLIED_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_XIM.MATERIAL_IDENTIFICATION_WITH_CONDUCTIVITY_CLASSIFICATION' IN TYPEOF (terminal_core_material[1]));
      WR6: (SIZEOF(terminal_surface_material) = 1) AND
                ('CONDUCTIVITY_MATERIAL_ASPECTS_XIM.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
    (* CONNOTATIONAL *) SUBTYPE OF (Shape_element_constituent_relationship);
      SELF\Shape_element_relationship.relating : Package_body_surface_armx;
      SELF\Shape_element_relationship.related  : Package_terminal_armx;
  END_ENTITY;

  ENTITY Polarity_indication_feature
    (* CONNOTATIONAL *) SUBTYPE OF (Part_feature);
      associated_body_vertical_extent         : OPTIONAL SET[1:2] OF Package_body_surface_armx;
      associated_terminal                     : Package_terminal_armx;
      SELF\Part_feature.associated_definition : Package_armx;      
  END_ENTITY;

  ENTITY Primary_orientation_feature_armx
    (* CONNOTATIONAL *) SUBTYPE OF (Package_orientation_feature, primary_orientation_feature);
  END_ENTITY;

  ENTITY Primary_reference_terminal_armx
  	(* CONNOTATIONAL *) SUBTYPE OF (Package_terminal_armx, primary_reference_terminal);
    WHERE
      WR1 : NOT (EXISTS(SELF\Part_feature.precedent_feature));
  END_ENTITY;

  ENTITY Secondary_orientation_feature_armx
    (* CONNOTATIONAL *) SUBTYPE OF (Package_orientation_feature, secondary_orientation_feature);
  END_ENTITY;

  ENTITY Tertiary_orientation_feature_armx
    (* CONNOTATIONAL *) SUBTYPE OF (Package_orientation_feature, tertiary_orientation_feature);
  END_ENTITY;

  ENTITY Wire_terminal_armx
    SUBTYPE OF (Package_terminal_armx, wire_terminal);
   WHERE
    WR1 : SIZEOF(SELF\Package_terminal_armx.feature_shape) = 0;
  END_ENTITY;

  ENTITY Wire_terminal_template_definition_armx
    (* CONNOTATIONAL *) SUBTYPE OF (Package_terminal_template_definition_armx, wire_terminal_template_definition);
      SELF\Package_terminal_template_definition_armx.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_measure_with_unit ;
    input2 : length_measure_with_unit
  ) : length_measure_with_unit;
    RETURN(input1);
  END_FUNCTION;

  FUNCTION max_data_element(
    input1 : length_measure_with_unit ;
    input2 : length_measure_with_unit
  ) : length_measure_with_unit;
    RETURN(input1);
  END_FUNCTION;

END_SCHEMA;




