(*
 * $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 Part template shape with parameters - EXPRESS ARM
   by LKSoftWare GmbH for implementation purpose within IDA-STEP(TM)
*)

SCHEMA Part_template_shape_with_parameters_xim;

USE FROM Non_feature_shape_element_xim;

USE FROM Physical_layout_template_xim;

USE FROM Part_template_shape_with_parameters_mim;

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

	SUBTYPE_CONSTRAINT shape_element_subtypes FOR Shape_element;
	  ONEOF (Shape_feature,
	         Non_feature_shape_element);
	END_SUBTYPE_CONSTRAINT;

	TYPE ptswp_requirement_assignment_item = EXTENSIBLE GENERIC_ENTITY SELECT BASED_ON requirement_assignment_item WITH 
	    (Part_template_keepout_shape_model);
	END_TYPE; 

	TYPE ptswp_view_shape_select = EXTENSIBLE GENERIC_ENTITY SELECT BASED_ON view_shape_select WITH 
	    (Part_template_shape_model);
	END_TYPE; 

  ENTITY Geometric_template_armx
    ABSTRACT SUPERTYPE-- OF (Continuous_template_Armx ANDOR Single_stratum_template_armx)
    SUBTYPE OF (Template_definition, geometric_template);
  INVERSE
    shapes : SET [0:?] OF Part_template_shape_model FOR shape_characterized_definition;
    WHERE
     WR1 : SIZEOF(QUERY( gm <* USEDIN(SELF,'')|
        (('ELEMENTAL_GEOMETRIC_SHAPE_XIM.SHAPE_REPRESENTATION' IN TYPEOF(gm)) AND 
        NOT('PART_TEMPLATE_SHAPE_WITH_PARAMETERS_XIM.PART_TEMPLATE_SHAPE_MODEL' IN
        TYPEOF(gm)))
        )) = 0;
  END_ENTITY;

  ENTITY Part_template_keepout_shape_model
		ABSTRACT (* CONNOTATIONAL *) SUBTYPE OF (shape_representation);      
			constrained_design_object_category : keepout_product_design_object_category;
      shape_characterized_definition     : Geometric_template_armx;
      shape_material_condition           : material_condition;
      centroid_location                  : OPTIONAL Cartesian_point;
      shape_environment                  : application_environment;
      shape_purpose                      : OPTIONAL predefined_keepout_purpose;
    DERIVE
      principal_part_shape : 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.name = 'principal part shape')));      
    INVERSE
	  external_shape_purpose : SET [0:1] OF External_source_identification FOR items;      
	WHERE
	  WR1: (EXISTS (shape_purpose)) XOR ((SIZEOF(external_shape_purpose)) = 1);
      WR2: SIZEOF(USEDIN(SELF, 'SHAPE_PROPERTY_ASSIGNMENT_XIM.SHAPE_DESCRIPTION_ASSOCIATION.REPRESENTATION'))=0;      
      WR3 : SIZEOF(principal_part_shape) < 2;
  END_ENTITY;

  ENTITY Part_template_shape_model
    ABSTRACT (* CONNOTATIONAL *) SUBTYPE OF (shape_representation);      
      shape_characterized_definition    : SET[1:?] OF Geometric_template_armx;
      shape_environment                 : OPTIONAL application_environment;
      shape_material_condition          : material_condition;
    DERIVE
      principal_part_shape : 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.name = 'principal part shape')));      
	WHERE
      WR1 : SIZEOF(principal_part_shape) < 2;
  END_ENTITY;

  ENTITY Part_template_shape_representation_relationship
  	(* CONNOTATIONAL *) SUBTYPE OF (shape_representation_relationship);
      SELF\representation_relationship.rep_1 RENAMED principal_part_shape : Part_template_shape_model;
      SELF\representation_relationship.rep_2 RENAMED related_part_shape   : Part_template_shape_model;
    DERIVE
      SELF\Representation_relationship.name : label := 'part template shape representation relationship';
    UNIQUE
      UR1 : principal_part_shape,
 related_part_shape;
    WHERE
      WR1 : principal_part_shape :<>: related_part_shape;
      WR2 : principal_part_shape\shape_representation.context_of_items :=: related_part_shape\shape_representation.context_of_items;
      WR3 : principal_part_shape\Part_template_shape_model.shape_characterized_definition :=:
            related_part_shape\Part_template_shape_model.shape_characterized_definition;
  END_ENTITY;

  RULE unique_part_template_shape_model_for_geometric_template FOR
    (Geometric_template_armx);
    LOCAL
      ptsm : SET OF Part_template_shape_model := [];
    END_LOCAL;      
    WHERE
      WR1:  SIZEOF(QUERY (gt <* Geometric_template_armx | 
        (SIZEOF (QUERY (ptsm1 <*
        USEDIN(gt,'PART_TEMPLATE_SHAPE_WITH_PARAMETERS_XIM.PART_TEMPLATE_SHAPE_MODEL.SHAPE_CHARACTERIZED_DEFINITION') |  
        (SIZEOF (QUERY (ptsm2 <*
        USEDIN(gt,'PART_TEMPLATE_SHAPE_WITH_PARAMETERS_XIM.PART_TEMPLATE_SHAPE_MODEL.SHAPE_CHARACTERIZED_DEFINITION') |  
        ptsm1 = ptsm2)) > 1)
        )) > 0) )) = 0;  
  END_RULE;


END_SCHEMA;

