(*
   $Id$
   ISO TC184/SC4/WG12 N3951 - ISO/TS 10303-1668 Fabrication joint - EXPRESS ARM
   Supersedes ISO TC184/SC4/WG12 N3402
*)

SCHEMA Fabrication_joint_arm;

	USE FROM Land_arm;	-- ISO/TS 10303-1692
	USE FROM Layered_interconnect_module_with_printed_component_design_arm;	-- ISO/TS 10303-1700
	REFERENCE FROM Characterizable_object_arm(bag_to_set);  -- ISO/TS 10303-1765

 	TYPE fabricated_feature_select = SELECT(
 		Component_termination_passage_join_terminal,
 		Conductive_interconnect_element_terminal,
	    Embedded_physical_component_terminal,
 		Land_join_terminal,
 		Printed_component_join_terminal,
         Via_terminal);
	END_TYPE;

  ENTITY Connection_zone_based_fabrication_joint
    SUBTYPE OF (Fabrication_joint);
      zone_1 : Connection_zone_in_design_view;
      zone_2 : Connection_zone_in_design_view;
    WHERE
      WR1 : zone_1 :<>: zone_2;
  END_ENTITY;

  ENTITY Fabrication_joint
  	SUBTYPE OF (Component_feature_joint);
      SELF\Component_feature_joint.feature_1 RENAMED fabrication_feature_1                      : fabricated_feature_select;
      SELF\Component_feature_joint.feature_2 RENAMED fabrication_feature_2                      : fabricated_feature_select;
      auxiliary_joint_material                                                                  : OPTIONAL Stratum_feature_template_component;
      SELF\Component_feature_joint.associated_definition RENAMED associated_interconnect_module : Interconnect_module;      
    WHERE
      WR1 : fabrication_feature_1 <> fabrication_feature_2;
      WR2 : TYPEOF(fabrication_feature_1) <> TYPEOF(auxiliary_joint_material);
      WR3 : TYPEOF(fabrication_feature_2) <> TYPEOF(auxiliary_joint_material);        
  END_ENTITY;
  
  ENTITY Passage_terminal_based_fabrication_joint_link;
      associated_terminal : fabricated_feature_select;
      precedent_point     : Fabrication_joint;
      subsequent_point    : Fabrication_joint;
    UNIQUE
      UR1 : associated_terminal, precedent_point, subsequent_point;
    WHERE
      WR1 : precedent_point <> subsequent_point;
      WR2 : precedent_point.fabrication_feature_2 = associated_terminal;
      WR3 : subsequent_point.fabrication_feature_1 = associated_terminal;
      WR4 : SIZEOF(TYPEOF(associated_terminal) *
            ['LAYERED_INTERCONNECT_MODULE_DESIGN_ARM.' + 
             'COMPONENT_TERMINATION_PASSAGE_JOIN_TERMINAL',
             'LAYERED_INTERCONNECT_MODULE_DESIGN_ARM.' + 
             'VIA_TERMINAL']) = 1;
      WR5 : acyclic_passage_terminal_based_fabrication_joint_link (SELF,
        [subsequent_point],
        'FABRICATION_JOINT_ARM.PASSAGE_TERMINAL_BASED_FABRICATION_JOINT_LINK');
  END_ENTITY; 
  
  FUNCTION acyclic_passage_terminal_based_fabrication_joint_link
     (relation : Passage_terminal_based_fabrication_joint_link; 
     relatives : SET[1:?] OF Fabrication_joint; 
     specific_relation : STRING) : BOOLEAN; 
     LOCAL
       x : SET OF Passage_terminal_based_fabrication_joint_link;
     END_LOCAL;

     IF relation.precedent_point IN relatives THEN
       RETURN (FALSE);
     END_IF;
     x := QUERY(pd <* bag_to_set(USEDIN(relation.precedent_point,
       'FABRICATION_JOINT_ARM.' + 'PASSAGE_TERMINAL_BASED_FABRICATION_JOINT_LINK.' +
       'SUBSEQUENT_POINT')) | specific_relation IN TYPEOF(pd));
     REPEAT i := 1 TO HIINDEX(x);
       IF NOT acyclic_passage_terminal_based_fabrication_joint_link(x[i],
         relatives + relation.precedent_point, specific_relation) THEN
         RETURN (FALSE);
       END_IF;
     END_REPEAT;
   RETURN (TRUE);
  END_FUNCTION;  

END_SCHEMA;
