(*
 * $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 Physical unit 3d design view - EXPRESS ARM
   by LKSoftWare GmbH for implementation purpose within IDA-STEP(TM)
*)

SCHEMA Physical_unit_3d_design_view_xim;
  
USE FROM Layered_3d_shape_xim;

USE FROM Part_template_shape_with_parameters_xim;  -- ISO/TS 10303-1720
	
USE FROM Physical_unit_design_view_xim;

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

  
  ENTITY Assembly_component_3d_shape_model
    (* CONNOTATIONAL *) SUBTYPE OF (Shape_representation);
      shape_characterized_component : SET[1:?] OF Assembly_component_armx;
    DERIVE
      SELF\Representation.name : label := '3d bound volume shape';
      equivalent_reference_shape_model : SET [0:1] OF Shape_representation_relationship :=
        bag_to_set(QUERY( gmr <* USEDIN(SELF, 'PRODUCT_PROPERTY_REPRESENTATION_SCHEMA.SHAPE_REPRESENTATION_RELATIONSHIP.REP_2') |
        (gmr\Representation_relationship.relation_type = 'equivalent reference shape model')));      
    WHERE
      WR1 : SIZEOF(equivalent_reference_shape_model) < 2;         
  END_ENTITY;

  ENTITY Component_3d_location_armx
    SUBTYPE OF (Contextual_shape_representation, Geometric_composition_with_operator_transformation);
      SELF\Geometric_relationship_with_operator_transformation.transformation : Cartesian_transformation_operator_3d;
      placement_fixed : BOOLEAN;
      SELF\shape_representation_relationship.rep_1 RENAMED component_model : Assembly_component_3d_shape_model;
      SELF\shape_representation_relationship.rep_2 RENAMED assembly_model : Physical_unit_3d_shape_model;
    DERIVE
      component : next_assembly_usage_occurrence := SELF\Contextual_shape_representation.contextual_shape.described_element;    
      the_context : geometric_representation_context := assembly_model\Shape_representation\Representation.context_of_items;
      SELF\Contextual_shape_representation.representing_relationship : Shape_representation_relationship := SELF;   -- NEW
      SELF\representation_relationship.name : label := '';
    WHERE
     WR1: NOT('PHYSICAL_UNIT_3D_DESIGN_VIEW_XIM.ASSEMBLY_COMPONENT_3D_SHAPE_MODEL' IN TYPEOF(component_model)) OR
     (component\Next_assembly_usage_occurrence_relationship_armx.related_view IN component_model.shape_characterized_component);
     WR2: NOT('PHYSICAL_UNIT_SHAPE_WITH_PARAMETERS_XIM.PHYSICAL_UNIT_SHAPE_MODEL' IN TYPEOF(component_model)) OR
     (component\Next_assembly_usage_occurrence_relationship_armx.related_view IN component_model\Assembly_component_3d_shape_model.shape_characterized_component);
     WR3: NOT('PHYSICAL_UNIT_SHAPE_WITH_PARAMETERS_XIM.PHYSICAL_UNIT_SHAPE_MODEL' IN TYPEOF(component_model)) OR
     (component_model\Physical_unit_shape_model.shape_characterized_definition :=: 
     component\Next_assembly_usage_occurrence_relationship_armx.related_view\Assembly_component_armx.derived_from);
     WR4: NOT('PART_TEMPLATE_SHAPE_WITH_PARAMETERS_XIM.PART_TEMPLATE_SHAPE_MODEL' IN TYPEOF(component_model)) OR
     (component\Next_assembly_usage_occurrence_relationship_armx.related_view\Assembly_component_armx.derived_from IN
      component_model\Part_template_shape_model.shape_characterized_definition);
  END_ENTITY;

  ENTITY Component_part_3d_geometric_representation_relationship
    (* CONNOTATIONAL *) SUBTYPE OF (shape_representation_relationship);
		SELF\Shape_representation_relationship.rep_1 RENAMED part_shape				: part_template_or_physical_unit_3d_shape_model_select;
	  SELF\Shape_representation_relationship.rep_2 RENAMED component_shape	: Assembly_component_3d_shape_model;
	DERIVE
	  SELF\Representation_relationship.name : label := 'component part 3d shape';
	WHERE
      WR1 : SIZEOF(QUERY(ac <* component_shape.shape_characterized_component |
                   NOT(part_shape.shape_characterized_definition :=: ac\Assembly_component_armx.derived_from)
                   )) = 0;
      WR2 : part_shape :<>: component_shape;	  
  END_ENTITY;

RULE unique_assembly_component_3d_shape_model FOR (Assembly_component_3d_shape_model);
   LOCAL
     ac : BAG OF Assembly_component_armx := [];
   END_LOCAL;
   REPEAT i := 1 to SIZEOF(Assembly_component_3d_shape_model) by 1;
     ac  := ac + Assembly_component_3d_shape_model[i].shape_characterized_component;
   END_REPEAT;  
  WHERE
   WR1 : SIZEOF(ac) = SIZEOF(bag_to_set(ac));
  END_RULE;

  RULE unique_physical_unit_3d_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 (pu3dsm1 <*
        USEDIN (pdv,'PHYSICAL_UNIT_SHAPE_WITH_PARAMETERS_XIM.PHYSICAL_UNIT_SHAPE_MODEL.SHAPE_CHARACTERIZED_DEFINITION') |  
        ('PHYSICAL_UNIT_2D_SHAPE_ARM.PHYSICAL_UNIT_PLANAR_SHAPE_MODEL' IN TYPEOF
        (pu3dsm1)) AND (SIZEOF (QUERY (pu3dsm2 <* USEDIN
        (pdv,'PHYSICAL_UNIT_SHAPE_WITH_PARAMETERS_XIM.PHYSICAL_UNIT_SHAPE_MODEL.SHAPE_CHARACTERIZED_DEFINITION') |  
        ('PHYSICAL_UNIT_2D_SHAPE_XIM.PHYSICAL_UNIT_PLANAR_SHAPE_MODEL' IN TYPEOF
        (pu3dsm2)) AND (pu3dsm1 = pu3dsm2))) > 1))) > 0))) = 0;  
      WR2:  SIZEOF(QUERY (puv <* Part_usage_view | 
        (SIZEOF (QUERY (pu3dsm1 <* USEDIN
        (puv,'PHYSICAL_UNIT_SHAPE_WITH_PARAMETERS_XIM.PHYSICAL_UNIT_SHAPE_MODEL.SHAPE_CHARACTERIZED_DEFINITION') |  
        ('PHYSICAL_UNIT_2D_SHAPE_XIM.PHYSICAL_UNIT_PLANAR_SHAPE_MODEL' IN TYPEOF
        (pu3dsm1)) AND (SIZEOF (QUERY (pu3dsm2 <* USEDIN
        (puv,'PHYSICAL_UNIT_SHAPE_WITH_PARAMETERS_XIM.PHYSICAL_UNIT_SHAPE_MODEL.SHAPE_CHARACTERIZED_DEFINITION') |  
        ('PHYSICAL_UNIT_2D_SHAPE_XIM.PHYSICAL_UNIT_PLANAR_SHAPE_MODEL' IN TYPEOF
        (pu3dsm2)) AND (pu3dsm1 = pu3dsm2))) > 1))) > 0))) = 0;  
  END_RULE;

END_SCHEMA;

