(*
   $Id$
   ISO TC184/SC4/WG12 N4820 - ISO/CD-TS 10303-1771 Stock material - EXPRESS MIM
   Supersedes ISO TC184/SC4/WG12 N4383
*)

SCHEMA Stock_material_mim;

USE FROM Approval_mim; -- ISO/TS 10303-1012

USE FROM Elemental_geometric_shape_mim; -- ISO/CD-TS 10303-1004

USE FROM Generic_material_aspects_mim; -- ISO/TS 10303-1681

USE FROM Specification_document_mim; -- ISO/TS 10303-1747

USE FROM Part_view_definition_mim; -- ISO/TS 10303-1023

USE FROM product_structure_schema (make_from_usage_option);

  TYPE sm_approval_item = EXTENSIBLE GENERIC_ENTITY SELECT BASED_ON approval_item WITH
    (product_definition);
  END_TYPE;

  RULE ply_stock_material_select FOR
   (product_related_product_category,
    make_from_usage_option);
  LOCAL
    i,j,k,kp :  INTEGER;
    dkuhr    :  LOGICAL;
    nmfuo    :  INTEGER;
    nprpc    :  INTEGER := 0;
    rp       :  product;
  END_LOCAL;

  dkuhr := TRUE;
  REPEAT kp:= LOINDEX (product_related_product_category) TO
              HIINDEX (product_related_product_category);
 
    IF (product_related_product_category[kp].name = 'ply') THEN
    REPEAT i:= LOINDEX (product_related_product_category[kp].products) TO
               HIINDEX (product_related_product_category[kp].products);

      nmfuo := 0;  
      REPEAT j:= LOINDEX (make_from_usage_option) TO 
                 HIINDEX (make_from_usage_option);

        IF (product_related_product_category[kp].products[i] = 
          make_from_usage_option[j].relating_product_definition.
          formation.of_product) THEN

          rp := make_from_usage_option[j].related_product_definition.
                formation.of_product;
          REPEAT k:= LOINDEX (product_related_product_category) TO
                     HIINDEX (product_related_product_category);

            IF ((rp IN product_related_product_category[k].products) AND
                (product_related_product_category[k].name IN 
                 ['isotropic material', 'filament assembly', 
                  'discontinuous fiber assembly'])) THEN
                nprpc := nprpc + 1;
            END_IF;

          END_REPEAT;

          IF (nprpc = 1) THEN
            nmfuo := nmfuo + 1;
          ELSE
            dkuhr := FALSE;
            ESCAPE;
          END_IF;

        END_IF;

      END_REPEAT;

      IF (dkuhr = FALSE) THEN
        ESCAPE; 
      END_IF;
      IF(nmfuo <> 1) THEN
        dkuhr := FALSE;
        ESCAPE;
      END_IF;

    END_REPEAT;
    END_IF;

  END_REPEAT;

  WHERE
    WR1: dkuhr;
  END_RULE;

END_SCHEMA;
