(*
   $Id$
   ISO TC184/SC4/WG12 N4119 - ISO/TS 10303-1724 Physical unit 2d design view - EXPRESS ARM
   Supersedes ISO TC184/SC4/WG12 N3546
*)

SCHEMA Physical_unit_2d_design_view_arm;

	USE FROM Part_template_shape_with_parameters_arm;  -- ISO/TS 10303-1720
	USE FROM Physical_unit_2d_shape_arm;	-- ISO/TS 10303-1726
	USE FROM Physical_unit_design_view_arm;	-- ISO/TS 10303-1728
	REFERENCE FROM Characterizable_object_arm(bag_to_set);  -- ISO/TS 10303-1765

  ENTITY Assembly_component_2d_shape_model
    SUBTYPE OF (Planar_projected_shape_model);
      shape_characterized_component : SET[1:?] OF Assembly_component;
    DERIVE
      equivalent_reference_shape_model : SET [0:1] OF Geometric_model_relationship :=
        bag_to_set(QUERY( gmr <* USEDIN(SELF, 'EXTENDED_BASIC_GEOMETRY_ARM.GEOMETRIC_MODEL_RELATIONSHIP.REP_2') |
        (gmr\Representation_relationship.relation_type = 'equivalent reference shape model')));      
    WHERE
      WR1 : SIZEOF(equivalent_reference_shape_model) < 2;        
  END_ENTITY;

  ENTITY Component_2d_location
   SUBTYPE OF (Contextual_shape_representation, Geometric_composition_with_operator_transformation);
     placement_fixed : BOOLEAN;
     SELF\Geometric_relationship_with_operator_transformation.transformation : Cartesian_transformation_2d; -- enforce rep_rel_w_trans by mapping
     SELF\Geometric_model_relationship.rep_2 RENAMED assembly_model : Physical_unit_planar_shape_model;  -- CHANGED
     SELF\Geometric_model_relationship.rep_1 RENAMED component_model : Geometric_model; -- CHANGED
   DERIVE
     component : Next_assembly_usage := SELF\Contextual_shape_representation.contextual_shape.described_element;
     substrate_location : BOOLEAN := substrate_in_assembly(SELF);
     the_context : Geometric_coordinate_space := assembly_model\Representation.context_of_items;
     SELF\Contextual_shape_representation.representing_relationship : Geometric_model_relationship := SELF;   -- NEW
     SELF\Representation_relationship.relation_type : STRING := 'component 2d location';
   WHERE
     WR1: EXISTS (component);  
     WR2: NOT('PHYSICAL_UNIT_2D_DESIGN_VIEW_ARM.ASSEMBLY_COMPONENT_2D_SHAPE_MODEL' IN TYPEOF(component_model)) OR
     (component\Product_occurrence_definition_relationship.related_view IN component_model\Assembly_component_2d_shape_model.shape_characterized_component);
     WR3: NOT('PHYSICAL_UNIT_SHAPE_WITH_PARAMETERS_ARM.PHYSICAL_UNIT_SHAPE_MODEL' IN TYPEOF(component_model)) OR
     (component_model\Physical_unit_shape_model.shape_characterized_definition :=: 
     component\Product_occurrence_definition_relationship.related_view\Assembly_component.derived_from);
     WR4: NOT('PART_TEMPLATE_SHAPE_WITH_PARAMETERS_ARM.PART_TEMPLATE_SHAPE_MODEL' IN TYPEOF(component_model)) OR
     (component\Product_occurrence_definition_relationship.related_view\Assembly_component.derived_from IN
      component_model\Part_template_shape_model.shape_characterized_definition);
  END_ENTITY;

  ENTITY Component_part_2d_geometric_representation_relationship
    SUBTYPE OF (Geometric_model_relationship);
    	SELF\Geometric_model_relationship.rep_1 RENAMED part_shape  : part_template_or_physical_unit_2d_shape_select;
    	SELF\Geometric_model_relationship.rep_2 RENAMED component_shape : Assembly_component_2d_shape_model;
    WHERE
      WR1 : NOT EXISTS(SELF\Representation_relationship.relation_type);
      WR2 : SIZEOF(QUERY(ac <* component_shape.shape_characterized_component |
                   NOT(part_shape.shape_characterized_definition :=: ac\Assembly_component.derived_from)
                   )) = 0;
      WR3 : part_shape :<>: component_shape;
  END_ENTITY;

  RULE unique_assembly_component_2d_shape_model FOR (Assembly_component_2d_shape_model);
   LOCAL
     ac : BAG OF Assembly_component := [];
     pass : BOOLEAN := TRUE;
   END_LOCAL;
   REPEAT i := 1 to SIZEOF(Assembly_component_2d_shape_model) by 1;
     ac  := ac + Assembly_component_2d_shape_model[i].shape_characterized_component;
   END_REPEAT;
  WHERE
   WR1 : SIZEOF(ac) = SIZEOF(bag_to_set(ac));
  END_RULE;

  FUNCTION substrate_in_assembly(
    c2dl : Component_2d_location
  ) : BOOLEAN;

    RETURN(TRUE);
  END_FUNCTION;

  RULE unique_physical_unit_planar_shape_model_for_part_design_and_usage_view FOR
      (Part_design_view, Part_usage_view);
    WHERE
      WR1:  SIZEOF(QUERY (pdv <* Part_design_view | 
        (SIZEOF (QUERY (pupsm1 <* USEDIN
        (pdv,'PHYSICAL_UNIT_SHAPE_WITH_PARAMETERS_ARM.PHYSICAL_UNIT_SHAPE_MODEL.SHAPE_CHARACTERIZED_DEFINITION') |  
        ('PHYSICAL_UNIT_2D_SHAPE_ARM.PHYSICAL_UNIT_PLANAR_SHAPE_MODEL' IN TYPEOF
        (pupsm1)) AND (SIZEOF (QUERY (pupsm2 <* USEDIN
        (pdv,'PHYSICAL_UNIT_SHAPE_WITH_PARAMETERS_ARM.PHYSICAL_UNIT_SHAPE_MODEL.SHAPE_CHARACTERIZED_DEFINITION') |  
        ('PHYSICAL_UNIT_2D_SHAPE_ARM.PHYSICAL_UNIT_PLANAR_SHAPE_MODEL' IN TYPEOF (pupsm2)) AND (pupsm1 = pupsm2))) > 1)
        )) > 0) )) = 0;  
      WR2:  SIZEOF(QUERY (puv <* Part_usage_view | (SIZEOF (QUERY (pupsm1 <*
        USEDIN (puv,'PHYSICAL_UNIT_SHAPE_WITH_PARAMETERS_ARM.PHYSICAL_UNIT_SHAPE_MODEL.SHAPE_CHARACTERIZED_DEFINITION') |  
          ('PHYSICAL_UNIT_2D_SHAPE_ARM.PHYSICAL_UNIT_PLANAR_SHAPE_MODEL' IN TYPEOF (pupsm1)) AND 
          (SIZEOF (QUERY (pupsm2 <* USEDIN (puv,'PHYSICAL_UNIT_SHAPE_WITH_PARAMETERS_ARM.PHYSICAL_UNIT_SHAPE_MODEL.SHAPE_CHARACTERIZED_DEFINITION') |
          ('PHYSICAL_UNIT_2D_SHAPE_ARM.PHYSICAL_UNIT_PLANAR_SHAPE_MODEL' IN TYPEOF (pupsm2)) AND 
          (pupsm1 = pupsm2))) > 1) )) > 0) )) = 0;  
  END_RULE;

END_SCHEMA;
