SCHEMA integrated_cnc_schema;

(*  AP-238 AIM shortform schema 
    ISO TC184/SC4/WG3 N1540 (superceeds wg3n1111)
    Author: David Loffredo (loffredo@steptools.com)

    2002-10-29 -- wg3n1540 (shortform), wg3n1541 (longform) schema
	          distributed with DIS ballot.
    2004-10-22 -- Fixed some EXPRESS warnings for DIS ballot.
    2004-10-12 -- Added GD&T definitions harmonized across AP-214,
		  AP-224, and Module 1050.  All mappings should now
		  be complete and ready for DIS ballot.
    2004-09-09 -- Finished adding subtypes for the action method
		  relationships as discussed in Bath.  Rebuilding
		  with the latest IRs and AICs, particularly the
		  AIC 522e2 definitions.
    2004-06-09 -- Short and longform to accompany the draft of the DIS
	          (wg3n1360) circulated for discussion at the Bath ISO
		  meeting.    	
    2003-12-16 -- Finalized turning definitions and functions.
    2003-11-20 -- Adding new AIM types and updating where rules 
	          on existing types to support the turning model.
		  See changelog in AP document for details.
    2003-09-03 -- Updating with comment resolutions from NWI/CD.
	          See changelog in AP document for details.
    2002-04-24 -- wg3n1111 (shortform), wg3n1112 (longform) schema
	          distributed with NWI/CD ballot.
    2002-03-07 -- Added temporary rule restricing use of turning 
		  features.  Fixed EXPRESS problems in rules (entity
		  value compares changed to instance compares, added
		  group qualifier and guard to nc_variable rule).
    2002-02-24 -- Changed return type of verify_* functions to logical, 
	          removed three extraneous numeric_expression subtypes
 		  brought in by SHTOLO, corrected warnings in a couple
	          local rules.
    2002-02-24 -- wg3n1090 (shortform), wg3n1091 (longform) schema
 		  distributed with NWI/CD documents for review at Myrtle 
		  Beach.

    All prior dates were distributed with AIM versions prior to v2.8
    Prior to this, the longform was hand-edited rather than generated
    from the shortform.  They are now synchronized and the longform is
    produced using the short-to-long tools.

    2001-10-18 -- Added material_designation_characterization
    2001-09-25 -- Added machining_operator_instruction and made
		  machining_adaptive_control_strategy a subtype 
		  of machining_strategy.
    2001-09-24 -- Added machining_offset_vector_representation
	          representation subtype, an action resource subtype
		  machining_cutting_component, and the representation 
		  item relationship type from Part 43.
    2001-09-17 -- Added the AP-214 value_range entity and the
		  surface_texture_representation.
    2001-08-23 -- Added classification assignment and new
 		  machining_feature_process subtype
    2001-07-25 -- Added machining_strategies subtypes and the freeform
		  milling tolerance representation.
    2001-07-13 -- Added machining_tool_dimension_representation
    2001-07-05 -- Updated measure_value to add numeric_measure
    2001-07-05 -- Updated with new Part 11 subtypes, DTL
    2001-06-22 -- Original, DTL
*)

(* ======================================== *)
(* IMPORT LISTS *)

USE FROM action_schema						 -- 10303-41
    (action,
     action_method,
     action_method_relationship,
     action_resource,
     action_resource_relationship,
     action_resource_type);

USE FROM aic_advanced_brep					 -- 10303-514
    (advanced_brep_shape_representation);

USE FROM aic_geometric_tolerances				 -- 10303-519
    (angularity_tolerance,
     circular_runout_tolerance,
     coaxiality_tolerance,
     common_datum,
     concentricity_tolerance,
     cylindricity_tolerance,
     flatness_tolerance,
     line_profile_tolerance,
     parallelism_tolerance,
     perpendicularity_tolerance,
     position_tolerance,
     roundness_tolerance,
     straightness_tolerance,
     surface_profile_tolerance,
     symmetry_tolerance,
     total_runout_tolerance);

USE FROM aic_geometrically_bounded_surface			 -- 10303-507
    (geometrically_bounded_surface_shape_representation);

USE FROM aic_machining_feature					 -- 10303-522
    (applied_area,
     boss,
     boss_top,
     chamfer,
     chamfer_offset,
     circular_closed_profile,
     circular_pattern,
     closed_path_profile,
     composite_hole,
     compound_feature,
     direction_shape_representation,
     edge_round,
     externally_defined_feature_definition,
     face_shape_representation,
     feature_component_definition,
     feature_component_relationship,
     feature_definition,
     feature_pattern,
     fillet,
     flat_face,
     gear,
     hole_bottom,
     instanced_feature,
     linear_profile,
     location_shape_representation,
     marking,
     modified_pattern,
     ngon_closed_profile,
     open_path_profile,
     outer_round,
     outside_profile,
     partial_circular_profile,
     path_feature_component,
     path_shape_representation,
     pattern_offset_membership,
     pattern_omit_membership,
     planar_shape_representation,
     pocket,
     pocket_bottom,
     profile_floor,
     protrusion,
     rectangular_closed_profile,
     rectangular_pattern,
     removal_volume,
     replicate_feature,
     revolved_profile,
     rib_top,
     rib_top_floor,
     round_hole,
     rounded_end,
     rounded_u_profile,
     shape_defining_relationship,
     shape_representation_with_parameters,
     slot,
     slot_end,
     spherical_cap,
     square_u_profile,
     step,
     taper,
     tee_profile,
     thread,
     transition_feature,
     turned_knurl,
     vee_profile);

USE FROM aic_manifold_surface					 -- 10303-509
    (manifold_surface_shape_representation);

USE FROM aic_topologically_bounded_surface			 -- 10303-511
    (advanced_face);

USE FROM application_context_schema				 -- 10303-41
    (application_context,
     application_context_element,
     application_protocol_definition,
     product_context,
     product_definition_context);

USE FROM approval_schema					 -- 10303-41
    (approval,
     approval_date_time,
     approval_person_organization,
     approval_relationship,
     approval_status);

USE FROM date_time_schema					 -- 10303-41
    (calendar_date,
     date,
     date_and_time,
     ordinal_date,
     week_of_year_and_day_date);

USE FROM document_schema					 -- 10303-41
    (document,
     document_usage_constraint,
     document_with_class);

USE FROM external_reference_schema				 -- 10303-41
    (externally_defined_item);

USE FROM geometric_model_schema					 -- 10303-42
    (block,
     right_circular_cylinder);

USE FROM geometry_schema					 -- 10303-42
    (bounded_curve,
     bounded_surface,
     elementary_surface,
     geometric_representation_context);

USE FROM iso13584_expressions_schema				 -- 13584-20
    (and_expression,
     binary_boolean_expression,
     boolean_expression,
     comparison_equal,
     comparison_expression,
     comparison_greater,
     comparison_greater_equal,
     comparison_less,
     comparison_less_equal,
     comparison_not_equal,
     expression,
     int_literal,
     int_numeric_variable,
     literal_number,
     multiple_arity_boolean_expression,
     not_expression,
     numeric_expression,
     numeric_variable,
     or_expression,
     real_literal,
     real_numeric_variable,
     simple_numeric_expression,
     unary_boolean_expression,
     xor_expression);

USE FROM iso13584_generic_expressions_schema			 -- 13584-20
    (binary_generic_expression,
     generic_expression);

USE FROM management_resources_schema				 -- 10303-41
    (approval_assignment,
     date_and_time_assignment,
     document_reference,
     document_usage_constraint_assignment,
     identification_assignment,
     identification_role,
     person_and_organization_assignment,
     security_classification_assignment);

USE FROM material_property_definition_schema			 -- 10303-45
    (material_designation,
     material_designation_characterization,
     material_property);

USE FROM material_property_representation_schema		 -- 10303-45
    (material_property_representation);

USE FROM measure_schema						 -- 10303-41
    (context_dependent_measure,
     context_dependent_unit,
     conversion_based_unit,
     count_measure,
     derived_unit,
     descriptive_measure,
     global_unit_assigned_context,
     length_measure_with_unit,
     length_unit,
     measure_with_unit,
     named_unit,
     numeric_measure,
     parameter_value,
     plane_angle_measure_with_unit,
     plane_angle_unit,
     positive_plane_angle_measure,
     ratio_measure,
     ratio_measure_with_unit,
     ratio_unit,
     si_unit,
     solid_angle_measure,
     solid_angle_measure_with_unit,
     solid_angle_unit,
     time_measure,
     time_measure_with_unit,
     time_unit);

USE FROM method_definition_schema				 -- 10303-49
    (action_method_with_associated_documents,
     concurrent_action_method,
     sequential_method,
     serial_action_method);

USE FROM person_organization_schema				 -- 10303-41
    (organizational_address,
     person,
     person_and_organization,
     personal_address);

USE FROM process_property_representation_schema			 -- 10303-49
    (action_property_representation,
     resource_property_representation);

USE FROM process_property_schema				 -- 10303-49
    (action_property,
     action_resource_requirement,
     characterized_action_definition,
     characterized_resource_definition,
     process_product_association,
     process_property_association,
     property_process,
     requirement_for_action_resource,
     resource_property,
     resource_requirement_type);

USE FROM product_definition_schema				 -- 10303-41
    (product,
     product_category,
     product_category_relationship,
     product_definition,
     product_definition_formation,
     product_definition_relationship,
     product_definition_with_associated_documents,
     product_related_product_category);

USE FROM product_property_definition_schema			 -- 10303-41
    (characterized_object,
     product_definition_shape,
     property_definition,
     shape_aspect,
     shape_aspect_relationship,
     shape_definition);

USE FROM product_property_representation_schema			 -- 10303-41
    (context_dependent_shape_representation,
     property_definition_representation,
     shape_definition_representation,
     shape_representation,
     shape_representation_relationship);

USE FROM product_structure_schema				 -- 10303-44
    (make_from_usage_option);

USE FROM qualified_measure_schema				 -- 10303-45
    (descriptive_representation_item,
     expanded_uncertainty,
     measure_qualification,
     measure_representation_item,
     precision_qualifier,
     qualified_representation_item,
     qualitative_uncertainty,
     standard_uncertainty,
     uncertainty_qualifier,
     value_qualifier);

USE FROM representation_schema					 -- 10303-43
    (compound_representation_item,
     global_uncertainty_assigned_context,
     item_defined_transformation,
     list_representation_item,
     representation,
     representation_item,
     representation_item_relationship,
     representation_relationship,
     representation_relationship_with_transformation,
     set_representation_item);

USE FROM security_classification_schema				 -- 10303-41
    (security_classification,
     security_classification_level);

USE FROM shape_aspect_definition_schema				 -- 10303-47
    (apex,
     centre_of_symmetry,
     datum,
     datum_feature,
     datum_reference,
     datum_target,
     derived_shape_aspect,
     extension,
     geometric_alignment,
     geometric_intersection,
     parallel_offset,
     perpendicular_to,
     referenced_modified_datum,
     tangent);

USE FROM shape_dimension_schema					 -- 10303-47
    (angular_location,
     angular_size,
     dimensional_characteristic_representation,
     dimensional_location,
     dimensional_location_with_path,
     dimensional_size,
     dimensional_size_with_path,
     shape_dimension_representation);

USE FROM shape_tolerance_schema					 -- 10303-47
    (limits_and_fits,
     modified_geometric_tolerance,
     plus_minus_tolerance,
     projected_zone_definition,
     runout_zone_definition,
     tolerance_value,
     tolerance_zone,
     tolerance_zone_definition,
     tolerance_zone_form);


(* ======================================== *)
(* ASSIGNMENT SUBTYPES *)


TYPE approval_item = SELECT (
        product_definition_formation	-- project
        );
END_TYPE; 

TYPE date_and_time_item = SELECT (
	approval_person_organization,	-- approval
	machining_operation,		-- last modified timestamp
	machining_process_executable,	-- last modified timestamp
	machining_toolpath,		-- last modified timestamp
	product_definition,		-- last modified timestamp
	product_definition_formation	-- project, last modified timestamp
        );
END_TYPE;

TYPE document_reference_item = SELECT (
        externally_defined_dimension_definition, -- dimension
        externally_defined_feature_definition,	-- catalog thread
        material_designation,			-- material
        property_definition
        );
END_TYPE;


TYPE identification_item = SELECT (
        dimensional_size		-- gdt id
        );
END_TYPE; 


TYPE person_and_organization_item = SELECT (
        product_definition_formation 	-- project
        );
END_TYPE; 

TYPE security_classification_item = SELECT (
	machining_operation,		-- security assignment
	machining_process_executable,	-- security assignment
	machining_toolpath,		-- security assignment
	product_definition,		-- security assignment
	product_definition_formation	-- security assignment
        );
END_TYPE;


ENTITY applied_approval_assignment
  SUBTYPE OF (approval_assignment);
  items : SET [1:?] OF approval_item;
END_ENTITY;

ENTITY applied_date_and_time_assignment
  SUBTYPE OF (date_and_time_assignment);
  items : SET[1:?] OF date_and_time_item;
END_ENTITY;

ENTITY applied_document_reference
  SUBTYPE OF (document_reference);
  items : SET [1:?] OF document_reference_item;
END_ENTITY;

ENTITY applied_document_usage_constraint_assignment
  SUBTYPE OF (document_usage_constraint_assignment);
  items : SET [1:?] OF document_reference_item;
END_ENTITY;

ENTITY applied_identification_assignment
  SUBTYPE OF (identification_assignment);
  items : SET [1:?] OF identification_item;
END_ENTITY;

ENTITY applied_person_and_organization_assignment
  SUBTYPE OF (person_and_organization_assignment);
  items : SET [1:?] OF person_and_organization_item;
END_ENTITY;

ENTITY applied_security_classification_assignment
  SUBTYPE OF (security_classification_assignment);
  items : SET [1:?] OF security_classification_item;
END_ENTITY;

(* ======================================== *)
(* GENERAL CNC PROCESS SUBTYPES (From Part 10) *)

ENTITY machining_process_executable
  SUBTYPE OF (action_method);
  WHERE
  WR1:  NOT (0 = SIZEOF (TYPEOF (SELF) *
            ['INTEGRATED_CNC_SCHEMA.MACHINING_FEATURE_PROCESS',
             'INTEGRATED_CNC_SCHEMA.MACHINING_NC_FUNCTION',
             'INTEGRATED_CNC_SCHEMA.MACHINING_RAPID_MOVEMENT',
             'INTEGRATED_CNC_SCHEMA.MACHINING_TOUCH_PROBING',
             'INTEGRATED_CNC_SCHEMA.MACHINING_WORKINGSTEP',
             'INTEGRATED_CNC_SCHEMA.MACHINING_WORKPLAN']
        )) OR
        (SELF.description IN ['assignment', 'if statement',
                'non-sequential', 'parallel', 'selective',
                'while statement', 'setup instructions']);

  WR2:  NOT (SELF.description = 'assignment') OR
        ((verify_required_action_property       (SELF, 'lvalue')) AND
         (verify_rep_item_for_action_property   (SELF, 'lvalue',
          ['INTEGRATED_CNC_SCHEMA.EXPRESSION_REPRESENTATION_ITEM',
           'INTEGRATED_CNC_SCHEMA.NUMERIC_VARIABLE'])) AND

         (verify_required_action_property       (SELF, 'rvalue')) AND
         (verify_rep_item_for_action_property   (SELF, 'rvalue',
          ['INTEGRATED_CNC_SCHEMA.EXPRESSION_REPRESENTATION_ITEM'])));

  WR3:  NOT (SELF.description = 'if statement') OR
        ((verify_required_action_property       (SELF, 'condition')) AND
         (verify_rep_item_for_action_property   (SELF, 'condition',
          ['INTEGRATED_CNC_SCHEMA.EXPRESSION_REPRESENTATION_ITEM',
           'INTEGRATED_CNC_SCHEMA.BOOLEAN_EXPRESSION'])) AND

         (verify_required_relating_amr_with_name  (SELF, 'true branch',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_BRANCH_RELATIONSHIP'])) AND
         (verify_related_type_for_amr_with_name   (SELF, 'true branch',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_BRANCH_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_EXECUTABLE'])) AND

         (verify_optional_relating_amr_with_name  (SELF, 'false branch',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_BRANCH_RELATIONSHIP'])) AND
         (verify_related_type_for_amr_with_name   (SELF, 'false branch',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_BRANCH_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_EXECUTABLE']))
        );

  WR4:  NOT (SELF.description = 'while statement') OR
        ((verify_required_action_property       (SELF, 'condition')) AND
         (verify_rep_item_for_action_property   (SELF, 'condition',
          ['INTEGRATED_CNC_SCHEMA.EXPRESSION_REPRESENTATION_ITEM',
           'INTEGRATED_CNC_SCHEMA.BOOLEAN_EXPRESSION'])) AND

         (verify_required_relating_amr  (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_BODY_RELATIONSHIP'])) AND
         (verify_related_type_for_amr   (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_BODY_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_EXECUTABLE']))
        );

  WR5:  NOT (SELF.description = 'parallel') OR
        ((2 <= get_count_of_relating_amr (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_CONCURRENT_RELATIONSHIP']))
        AND
         (verify_related_type_for_amr   (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_CONCURRENT_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_EXECUTABLE']))
        );

  WR6:  NOT (SELF.description = 'non-sequential') OR
        ((2 <= get_count_of_relating_amr (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_BODY_RELATIONSHIP'])) AND
         (verify_related_type_for_amr   (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_BODY_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_EXECUTABLE']))
        );

  WR7:  NOT (SELF.description = 'selective') OR
        ((2 <= get_count_of_relating_amr (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_BRANCH_RELATIONSHIP'])) AND
         (verify_related_type_for_amr   (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_BRANCH_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_EXECUTABLE']))
        );

  WR8:  NOT (SELF.description = 'setup instructions') OR
        ((verify_related_type_for_amr   (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_OPERATOR_INSTRUCTION_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_OPERATOR_INSTRUCTION']))
        );
END_ENTITY;




ENTITY machining_workingstep
  SUBTYPE OF (machining_process_executable);
  WHERE
  WR1:  ((verify_required_action_property     (SELF, 'security plane')) AND
         (verify_rep_item_for_action_property (SELF, 'security plane',
          ['INTEGRATED_CNC_SCHEMA.ELEMENTARY_SURFACE'])));

  WR2:  NOT (SELF.description = 'machining') OR
        ((verify_required_relating_amr (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_FEATURE_RELATIONSHIP'])) AND
         (verify_related_type_for_amr  (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_FEATURE_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_FEATURE_PROCESS'])) AND

         (verify_related_type_for_amr (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_FINAL_FEATURE_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_FEATURE_PROCESS'])) AND

         (verify_required_relating_amr  (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_OPERATION_RELATIONSHIP'])) AND
         (verify_related_type_for_amr   (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_OPERATION_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_OPERATION']))
        );

  WR3:  NOT (SELF.description = 'turning') OR
        ((2 <= get_count_of_relating_amr (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_FEATURE_SEQUENCE_RELATIONSHIP'])) AND
         (verify_related_type_for_amr    (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_FEATURE_SEQUENCE_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_FEATURE_PROCESS'])) AND

         (verify_required_relating_amr  (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_OPERATION_RELATIONSHIP'])) AND
         (verify_related_type_for_amr   (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_OPERATION_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.TURNING_TYPE_OPERATION']))
        );

  WR4:  NOT (SELF.description IN ['machining', 'turning']) OR
        (verify_optional_in_process_geometry (SELF));
END_ENTITY;

ENTITY machining_workplan
  SUBTYPE OF (machining_process_executable);
  WHERE
  WR1:  (1 <= get_count_of_relating_amr (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_SEQUENCE_RELATIONSHIP'])) AND
        (verify_related_type_for_amr   (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_SEQUENCE_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_EXECUTABLE']));

  WR2:  (verify_optional_action_property (SELF, 'channel'));

  WR3:  (1 >= SIZEOF (QUERY (act <*
          USEDIN (SELF, 'INTEGRATED_CNC_SCHEMA.ACTION.CHOSEN_METHOD') |
          (act.name = 'setup')))) AND
        (0 = SIZEOF (QUERY (act <*
          USEDIN (SELF, 'INTEGRATED_CNC_SCHEMA.ACTION.CHOSEN_METHOD') |
          (act.name = 'setup') AND NOT
          ('INTEGRATED_CNC_SCHEMA.PRODUCT_DEFINITION_PROCESS' IN TYPEOF (act))
        )));

  WR4:  (verify_optional_in_process_geometry (SELF));
END_ENTITY;



ENTITY machining_feature_process
  SUBTYPE OF (machining_process_executable);
  WHERE
  WR1:  (1 = SIZEOF (QUERY (act <*
          USEDIN (SELF, 'INTEGRATED_CNC_SCHEMA.ACTION.CHOSEN_METHOD') |
          (act.name = 'machining')))) AND
        (0 = SIZEOF (QUERY (act <*
          USEDIN (SELF, 'INTEGRATED_CNC_SCHEMA.ACTION.CHOSEN_METHOD') |
          (act.name = 'machining') AND NOT
          ('INTEGRATED_CNC_SCHEMA.PROPERTY_PROCESS' IN TYPEOF (act))
        )));
END_ENTITY;



ENTITY machining_operator_instruction
  SUBTYPE OF (action_method_with_associated_documents);
  WHERE
  WR1:  EXISTS (self.description) OR (0 < SIZEOF(self.documents));
END_ENTITY;


ENTITY machining_operation
  SUBTYPE OF (action_method);
  WHERE
  WR1: ((verify_related_type_for_amr    (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_TOOLPATH_SEQUENCE_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_TOOLPATH']))
       );

  WR2:  (verify_optional_action_property     (SELF, 'tool direction')) AND
        (verify_rep_type_for_action_property (SELF, 'tool direction',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_TOOL_DIRECTION_REPRESENTATION']));

  WR3:  ('INTEGRATED_CNC_SCHEMA.MACHINING_RAPID_MOVEMENT' IN TYPEOF(SELF)) OR
        ('INTEGRATED_CNC_SCHEMA.MACHINING_TOUCH_PROBING'  IN TYPEOF(SELF)) OR
        ((verify_optional_action_property       (SELF, 'retract plane')) AND
         (verify_length_measure_action_property (SELF, 'retract plane')) AND

         (verify_optional_action_property       (SELF, 'cut start point')) AND
         (verify_rep_item_for_action_property   (SELF, 'cut start point',
          ['INTEGRATED_CNC_SCHEMA.CARTESIAN_POINT'])) AND

         (1 = SIZEOF (QUERY (mt <*
          USEDIN (SELF, 'INTEGRATED_CNC_SCHEMA.ACTION_RESOURCE.USAGE') |
          ('INTEGRATED_CNC_SCHEMA.MACHINING_TOOL' in TYPEOF(mt))))) AND

         (verify_required_relating_amr  (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_TECHNOLOGY_RELATIONSHIP'])) AND
         (verify_related_type_for_amr   (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_TECHNOLOGY_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_TECHNOLOGY'])) AND

         (verify_required_relating_amr  (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_FUNCTIONS_RELATIONSHIP'])) AND
         (verify_related_type_for_amr   (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_FUNCTIONS_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_FUNCTIONS']))
        );
END_ENTITY;



ENTITY machining_technology
  SUBTYPE OF (action_method);
  WHERE
  WR1:  (verify_optional_action_property      (SELF, 'feedrate')) AND
        (verify_rep_type_for_action_property  (SELF, 'feedrate',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_FEED_SPEED_REPRESENTATION']));

  WR2:  (verify_required_action_property      (SELF, 'feedrate reference')) AND
        (verify_enumeration_action_property   (SELF, 'feedrate reference',
          ['tool center point', 'cutter contact point']));

  WR3:  NOT (SELF.description = 'milling') OR
        ((verify_optional_action_property     (SELF, 'spindle')) AND
         (verify_rep_type_for_action_property (SELF, 'spindle',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_SPINDLE_SPEED_REPRESENTATION'])) AND

         (verify_required_action_property
           (SELF, 'synchronize spindle with feed')) AND
         (verify_enumeration_action_property
           (SELF, 'synchronize spindle with feed',
           ['synchronized', 'not synchronized'])) AND

         (verify_required_action_property
           (SELF, 'inhibit feedrate override')) AND
         (verify_enumeration_action_property
           (SELF, 'inhibit feedrate override',
           ['override allowed', 'override not allowed'])) AND

         (verify_required_action_property
           (SELF, 'inhibit spindle override')) AND
         (verify_enumeration_action_property
           (SELF, 'inhibit spindle override',
           ['override allowed', 'override not allowed'])) AND

         (verify_optional_relating_amr  (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_ADAPTIVE_CONTROL_RELATIONSHIP'])) AND
         (verify_related_type_for_amr   (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_ADAPTIVE_CONTROL_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_TECHNOLOGY']))
        );

  WR4:  NOT (SELF.description = 'milling') OR
        ((verify_required_relating_amr (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_ADAPTIVE_CONTROL_RELATIONSHIP'])) OR

         (verify_required_action_property     (SELF, 'spindle') AND
          verify_rep_desc_for_action_property (SELF, 'spindle',
           ['spindle speed', 'cutting speed']))
        );

  WR5:  NOT (SELF.description = 'milling') OR
        ((verify_required_relating_amr (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_ADAPTIVE_CONTROL_RELATIONSHIP'])) OR

         (verify_required_action_property     (SELF, 'feedrate') AND
          verify_rep_desc_for_action_property (SELF, 'feedrate',
           ['feed speed', 'feed per tooth']))
        );

  WR6:  NOT (SELF.description = 'turning') OR
        ((verify_optional_action_property     (SELF, 'spindle')) AND
         (verify_rep_type_for_action_property (SELF, 'spindle',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_SPINDLE_SPEED_REPRESENTATION'])) AND
         (verify_rep_desc_for_action_property (SELF, 'spindle',
           ['spindle speed', 'cutting speed'])) AND

         (verify_rep_desc_for_action_property (SELF, 'feedrate',
           ['feed speed', 'feed per revolution'])) AND

         (verify_required_action_property
           (SELF, 'synchronize spindle with z feed')) AND
         (verify_enumeration_action_property
           (SELF, 'synchronize spindle with z feed',
           ['synchronized', 'not synchronized'])) AND

         (verify_required_action_property
           (SELF, 'inhibit feedrate override')) AND
         (verify_enumeration_action_property
           (SELF, 'inhibit feedrate override',
           ['override allowed', 'override not allowed'])) AND

         (verify_required_action_property
           (SELF, 'inhibit spindle override')) AND
         (verify_enumeration_action_property
           (SELF, 'inhibit spindle override',
           ['override allowed', 'override not allowed'])) AND

         (verify_optional_relating_amr  (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_ADAPTIVE_CONTROL_RELATIONSHIP'])) AND
         (verify_related_type_for_amr   (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_ADAPTIVE_CONTROL_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_TECHNOLOGY']))
        );
END_ENTITY;


ENTITY machining_functions
  SUBTYPE OF (action_method);
  WHERE
  WR1:  NOT (SELF.description = 'milling') OR
        ((verify_required_action_property       (SELF, 'coolant')) AND
         (verify_enumeration_action_property    (SELF, 'coolant',
           ['coolant on', 'coolant off'])) AND

         (verify_optional_action_property
           (SELF, 'coolant pressure')) AND
         (verify_pressure_measure_action_property
           (SELF, 'coolant pressure')) AND

         (verify_optional_action_property       (SELF, 'mist')) AND
         (verify_enumeration_action_property    (SELF, 'mist',
           ['mist on', 'mist off'])) AND

         (verify_required_action_property
           (SELF, 'through spindle coolant')) AND
         (verify_enumeration_action_property
           (SELF, 'through spindle coolant',
           ['through spindle coolant on', 'through spindle coolant off'])) AND

         (verify_optional_action_property
           (SELF, 'through spindle pressure')) AND
         (verify_pressure_measure_action_property
           (SELF, 'through spindle pressure')) AND

         -- axis constraints property must contain zero or more ranges
         (0 = SIZEOF (QUERY (prop <* get_action_property
                (SELF, 'axis constraints') | NOT
                 ((0 < SIZEOF (QUERY (prep <* USEDIN (prop,
            'INTEGRATED_CNC_SCHEMA.ACTION_PROPERTY_REPRESENTATION.PROPERTY') |
              (0 <= SIZEOF (QUERY (it <* prep.representation.items |
                 ('INTEGRATED_CNC_SCHEMA.VALUE_RANGE' in TYPEOF(it)))))
                )))))))
        );

  WR2:  NOT (SELF.description = 'turning') OR
        ((verify_required_action_property       (SELF, 'coolant')) AND
         (verify_enumeration_action_property    (SELF, 'coolant',
           ['coolant on', 'coolant off'])) AND

         (verify_optional_action_property       (SELF, 'coolant type')) AND
         (verify_enumeration_action_property    (SELF, 'coolant type',
           ['flood', 'mist', 'through tool'])) AND

         (verify_optional_action_property
           (SELF, 'coolant pressure')) AND
         (verify_pressure_measure_action_property
           (SELF, 'coolant pressure')) AND

         (verify_optional_action_property       (SELF, 'tail stock')) AND
         (verify_enumeration_action_property    (SELF, 'tail stock',
           ['tail stock used', 'tail stock not used'])) AND

         (verify_optional_action_property       (SELF, 'steady rest')) AND
         (verify_enumeration_action_property    (SELF, 'steady rest',
           ['steady rest used', 'steady rest not used'])) AND

         (verify_optional_action_property       (SELF, 'follow rest')) AND
         (verify_enumeration_action_property    (SELF, 'follow rest',
           ['follow rest used', 'follow rest not used']))
        );

  WR3:  NOT (SELF.description IN ['milling', 'turning']) OR
        ((verify_optional_action_property       (SELF, 'axis clamping')) AND
         (0 = SIZEOF (QUERY (prop <*
           get_action_property (SELF, 'axis clamping') | NOT
           (0 < SIZEOF (QUERY (prep <* USEDIN (prop, 'INTEGRATED_CNC_SCHEMA.' +
              'ACTION_PROPERTY_REPRESENTATION.PROPERTY') |
             (1 = SIZEOF (QUERY (it <* prep.representation.items |
                (('INTEGRATED_CNC_SCHEMA.COMPOUND_REPRESENTATION_ITEM'
                   IN TYPEOF(it)) AND
                 ('INTEGRATED_CNC_SCHEMA.LIST_REPRESENTATION_ITEM'
                   IN TYPEOF(it.item_element)) AND
                 (0 = SIZEOF (QUERY (ie <* it.item_element | NOT
                   ('INTEGRATED_CNC_SCHEMA.DESCRIPTIVE_REPRESENTATION_ITEM'
                    IN TYPEOF(ie)) )))
             ))))
           )))
         ))) AND

         (verify_required_action_property     (SELF, 'chip removal')) AND
         (verify_enumeration_action_property  (SELF, 'chip removal',
           ['chip removal on', 'chip removal off'])) AND

         (verify_optional_action_property     (SELF, 'oriented spindle stop')) AND
         (verify_rep_item_for_action_property (SELF, 'oriented spindle stop',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_related_type_for_amr   (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_MODEL_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_PROCESS_MODEL'])) AND

         (verify_optional_action_property (SELF, 'other functions')) AND
         (0 = SIZEOF (QUERY (prop <* get_action_property
                             (SELF, 'other functions') | NOT
           (0 < SIZEOF (QUERY (prep <* USEDIN (prop, 'INTEGRATED_CNC_SCHEMA.' +
              'ACTION_PROPERTY_REPRESENTATION.PROPERTY') |
             (1 = SIZEOF (QUERY (it <* prep.representation.items |
                (('INTEGRATED_CNC_SCHEMA.COMPOUND_REPRESENTATION_ITEM'
                   IN TYPEOF(it)) AND
                 ('INTEGRATED_CNC_SCHEMA.SET_REPRESENTATION_ITEM'
                   IN TYPEOF(it.item_element)))
             )))
           )))
         )))
        );
END_ENTITY;

ENTITY machining_toolpath
  SUBTYPE OF (action_method);
  WHERE
  WR1:  (SELF.description IN ['feedstop', 'axis trajectory',
        'cutter location trajectory', 'cutter contact trajectory',
        'approach lift path angle', 'approach lift path tangent',
        'connect security plane', 'connect direct']);

  WR2:  (verify_required_action_property        (SELF, 'priority')) AND
        (verify_enumeration_action_property     (SELF, 'priority',
         ['required', 'suggested']));

  WR3:  (verify_required_action_property        (SELF, 'trajectory type')) AND
        (verify_enumeration_action_property     (SELF, 'trajectory type',
         ['approach', 'lift', 'connect', 'non-contact',
          'contact', 'trajectory path']));

  WR4:  ((verify_optional_action_property        (SELF, 'speed profile')) AND
         (0 = SIZEOF (QUERY (prop <*
           get_action_property (SELF, 'speed profile') | NOT
           (0 < SIZEOF (QUERY (prep <* USEDIN (prop,
                'INTEGRATED_CNC_SCHEMA.' +
                'ACTION_PROPERTY_REPRESENTATION.PROPERTY') |
                ('INTEGRATED_CNC_SCHEMA.' +
                 'MACHINING_TOOLPATH_SPEED_PROFILE_REPRESENTATION'
                 IN TYPEOF(prep.representation)) )))
         )))
        );

  WR5:  (verify_optional_relating_amr   (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_TECHNOLOGY_RELATIONSHIP'])) AND
        (verify_related_type_for_amr    (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_TECHNOLOGY_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_TECHNOLOGY']));

  WR6:  (verify_optional_relating_amr   (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_FUNCTIONS_RELATIONSHIP'])) AND
        (verify_related_type_for_amr    (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_FUNCTIONS_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_FUNCTIONS']));


  WR7:  NOT (SELF.description IN ['axis trajectory',
                'cutter location trajectory',
                'cutter contact trajectory']) OR
        ((verify_optional_action_property    (SELF, 'direction')) AND
         (verify_enumeration_action_property (SELF, 'direction',
          ['beginning to end', 'end to beginning']))
        );


  WR8:  NOT (SELF.description = 'connect security plane') OR
        ((verify_optional_action_property     (SELF, 'up direction')) AND
         (verify_rep_item_for_action_property (SELF, 'up direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_optional_action_property     (SELF, 'down direction')) AND
         (verify_rep_item_for_action_property (SELF, 'down direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION']))
        );

  WR9:  NOT (SELF.description = 'feedstop') OR
        ((verify_required_action_property     (SELF, 'dwell')) AND
         (verify_time_measure_action_property (SELF, 'dwell'))
        );

  WR10: NOT (SELF.description = 'axis trajectory') OR
        ((verify_required_action_property     (SELF, 'axis commands')) AND

         -- axis commands property must contain one or more bounded curves
         (0 = SIZEOF (QUERY (prop <* get_action_property (SELF, 'axis commands') |
          NOT ((0 < SIZEOF (QUERY (prep <* USEDIN (prop,
               'INTEGRATED_CNC_SCHEMA.ACTION_PROPERTY_REPRESENTATION.PROPERTY') |
              (1 <= SIZEOF (QUERY (it <* prep.representation.items |
                 ('INTEGRATED_CNC_SCHEMA.BOUNDED_CURVE' in TYPEOF(it)))))
                )))))))
        );

  WR11: NOT (SELF.description IN ['approach lift path angle',
           'approach lift path tangent']) OR
        ((verify_required_action_property     (SELF, 'fix point')) AND
         (verify_rep_item_for_action_property (SELF, 'fix point',
           ['INTEGRATED_CNC_SCHEMA.CARTESIAN_POINT'])) AND

         (verify_optional_action_property     (SELF, 'fix point direction')) AND
         (verify_rep_item_for_action_property (SELF, 'fix point direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION']))
        );

  WR12: NOT (SELF.description = 'approach lift path angle') OR
        ((verify_required_action_property      (SELF, 'angle')) AND
         (verify_angle_measure_action_property (SELF, 'angle')) AND

         (verify_required_action_property       (SELF, 'bend distance')) AND
         (verify_length_measure_action_property (SELF, 'bend distance'))
        );

  WR13: NOT (SELF.description = 'approach lift path tangent') OR
        ((verify_required_action_property       (SELF, 'radius')) AND
         (verify_length_measure_action_property (SELF, 'radius'))
        );

  WR14: NOT (SELF.description = 'cutter location trajectory') OR
        ((verify_required_action_property     (SELF, 'basic curve')) AND
         (verify_rep_item_for_action_property (SELF, 'basic curve',
           ['INTEGRATED_CNC_SCHEMA.BOUNDED_CURVE'])) AND

         (verify_optional_action_property     (SELF, 'surface normal')) AND
         (verify_rep_item_for_action_property (SELF, 'surface normal',
           ['INTEGRATED_CNC_SCHEMA.BOUNDED_CURVE'])) AND

         (verify_optional_action_property     (SELF, 'tool axis')) AND
         (verify_rep_item_for_action_property (SELF, 'tool axis',
           ['INTEGRATED_CNC_SCHEMA.BOUNDED_CURVE'])) AND

         (verify_optional_action_property
          (SELF, 'path maximum deviation')) AND
         (verify_length_measure_action_property
          (SELF, 'path maximum deviation')) AND

         (verify_optional_action_property
          (SELF, 'tool axis maximum deviation')) AND
         (verify_angle_measure_action_property
          (SELF, 'tool axis maximum deviation'))
        );

  WR15: NOT (SELF.description = 'cutter contact trajectory') OR
        ((((verify_required_action_property     (SELF, 'basic curve')) AND
           (verify_rep_item_for_action_property (SELF, 'basic curve',
            ['INTEGRATED_CNC_SCHEMA.BOUNDED_PCURVE'])) )

           OR

          ((verify_required_action_property     (SELF, 'basic curve')) AND
           (verify_rep_item_for_action_property (SELF, 'basic curve',
            ['INTEGRATED_CNC_SCHEMA.BOUNDED_CURVE'])) AND

           (verify_required_action_property     (SELF, 'surface normal')) AND
           (verify_rep_item_for_action_property (SELF, 'surface normal',
            ['INTEGRATED_CNC_SCHEMA.BOUNDED_CURVE'])) )
          ) AND

         (verify_optional_action_property     (SELF, 'tool axis')) AND
         (verify_rep_item_for_action_property (SELF, 'tool axis',
           ['INTEGRATED_CNC_SCHEMA.BOUNDED_CURVE'])) AND

         (verify_optional_action_property     (SELF, 'contact type')) AND
         (verify_enumeration_action_property  (SELF, 'contact type',
           ['side', 'front'])) AND

         (verify_optional_action_property
          (SELF, 'path maximum deviation')) AND
         (verify_length_measure_action_property
          (SELF, 'path maximum deviation')) AND

         (verify_optional_action_property
          (SELF, 'tool axis maximum deviation')) AND
         (verify_angle_measure_action_property
          (SELF, 'tool axis maximum deviation'))
        );

END_ENTITY;


ENTITY machining_process_model
  SUBTYPE OF (action_method);
  WHERE
  WR1:  (verify_required_action_property    (SELF, 'initialization data')) AND
        (verify_descriptive_action_property (SELF, 'initialization data'));
END_ENTITY;



(* ======================================== *)
(* MIXED EXECUTABLE / OPERATION SUBTYPES *)



ENTITY machining_rapid_movement
  SUBTYPE OF (machining_process_executable, machining_operation);
  WHERE
  WR1:  ((verify_required_action_property       (SELF, 'security plane')) AND
         (verify_rep_item_for_action_property   (SELF, 'security plane',
          ['INTEGRATED_CNC_SCHEMA.ELEMENTARY_SURFACE'])));
END_ENTITY;



ENTITY machining_touch_probing
  SUBTYPE OF (machining_process_executable, machining_operation);
  WHERE
  WR1:  (SELF.description IN ['tool length probing', 'tool radius probing',
          'workpiece probing', 'workpiece complete probing']);

  WR2:  ((verify_required_action_property       (SELF, 'security plane')) AND
         (verify_rep_item_for_action_property   (SELF, 'security plane',
          ['INTEGRATED_CNC_SCHEMA.ELEMENTARY_SURFACE'])));

  WR3:  ((verify_required_action_property       (SELF, 'measured offset')) AND
         (verify_rep_item_for_action_property   (SELF, 'measured offset',
          ['INTEGRATED_CNC_SCHEMA.EXPRESSION_REPRESENTATION_ITEM',
           'INTEGRATED_CNC_SCHEMA.NUMERIC_VARIABLE'])));

  WR4:  NOT (SELF.description = 'workpiece probing') OR
        ((verify_required_action_property       (SELF, 'start position')) AND
         (verify_rep_item_for_action_property   (SELF, 'start position',
          ['INTEGRATED_CNC_SCHEMA.AXIS2_PLACEMENT_3D'])) AND

        (1 = SIZEOF (QUERY (act <*
          USEDIN (SELF, 'INTEGRATED_CNC_SCHEMA.ACTION.CHOSEN_METHOD') |
          (act.name = 'workpiece probing')))) AND
        (0 = SIZEOF (QUERY (act <*
          USEDIN (SELF, 'INTEGRATED_CNC_SCHEMA.ACTION.CHOSEN_METHOD') |
          (act.name = 'workpiece probing') AND NOT
          ('INTEGRATED_CNC_SCHEMA.PRODUCT_DEFINITION_PROCESS'
            IN TYPEOF (act))))) AND

         (verify_required_action_property       (SELF, 'direction')) AND
         (verify_rep_item_for_action_property   (SELF, 'direction',
          ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_required_action_property       (SELF, 'expected value')) AND
         (verify_rep_item_for_action_property   (SELF, 'expected value',
          ['INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT',
           'INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
           'INTEGRATED_CNC_SCHEMA.QUALIFIED_REPRESENTATION_ITEM'])) AND

         (verify_required_action_property       (SELF, 'probe'))
        );

  WR5:  NOT (SELF.description = 'workpiece complete probing') OR
        ((1 = SIZEOF (QUERY (act <*
          USEDIN (SELF, 'INTEGRATED_CNC_SCHEMA.ACTION.CHOSEN_METHOD') |
          (act.name = 'workpiece complete probing')))) AND
         (0 = SIZEOF (QUERY (act <*
          USEDIN (SELF, 'INTEGRATED_CNC_SCHEMA.ACTION.CHOSEN_METHOD') |
          (act.name = 'workpiece complete probing') AND NOT
          ('INTEGRATED_CNC_SCHEMA.PRODUCT_DEFINITION_PROCESS'
            IN TYPEOF (act))))) AND

         (verify_required_action_property       (SELF, 'probing distance')) AND
         (verify_rep_item_for_action_property   (SELF, 'probing distance',
          ['INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT',
           'INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
           'INTEGRATED_CNC_SCHEMA.QUALIFIED_REPRESENTATION_ITEM'])) AND

         (verify_required_action_property       (SELF, 'probe')) AND

         (verify_required_action_property       (SELF, 'computed offset')) AND
         (verify_rep_type_for_action_property   (SELF, 'computed offset',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_OFFSET_VECTOR_REPRESENTATION']))
        );

  WR6:  NOT (SELF.description IN ['tool length probing',
          'tool radius probing']) OR
        ((verify_required_action_property       (SELF, 'offset')) AND
         (verify_rep_item_for_action_property   (SELF, 'offset',
          ['INTEGRATED_CNC_SCHEMA.CARTESIAN_POINT'])) AND

         (verify_required_action_property       (SELF, 'maximum wear')) AND
         (verify_length_measure_action_property (SELF, 'maximum wear')) AND

         (1 = SIZEOF (QUERY (mt <*
          USEDIN (SELF, 'INTEGRATED_CNC_SCHEMA.ACTION_RESOURCE.USAGE') |
          ('INTEGRATED_CNC_SCHEMA.MACHINING_TOOL' in TYPEOF(mt)))))
        );
END_ENTITY;



ENTITY machining_nc_function
  SUBTYPE OF (machining_process_executable);
  WHERE
  WR1:  (SELF.description IN ['display message',
        'optional stop', 'program stop', 'set mark', 'wait for mark',
        'exchange pallet', 'index pallet', 'load tool', 'unload tool',
        'legacy function']);

  WR2:  NOT (SELF.description = 'display message') OR
        ((verify_required_action_property       (SELF, 'message text')) AND
         (verify_descriptive_action_property    (SELF, 'message text')));

  WR3:  NOT (SELF.description = 'wait for mark') OR
        ((verify_required_action_property       (SELF, 'channel')));

  WR4:  NOT (SELF.description = 'index pallet') OR
        ((verify_required_action_property       (SELF, 'pallet index')) AND
         (verify_parameter_action_property      (SELF, 'pallet index')));

  WR5:  NOT (SELF.description = 'index table') OR
        ((verify_required_action_property       (SELF, 'table index')) AND
         (verify_parameter_action_property      (SELF, 'table index')));

  WR6:  NOT (SELF.description = 'load tool') OR
        (1 = SIZEOF (QUERY (mt <*
         USEDIN (SELF, 'INTEGRATED_CNC_SCHEMA.ACTION_RESOURCE.USAGE') |
         ('INTEGRATED_CNC_SCHEMA.MACHINING_TOOL' in TYPEOF(mt)))));

  WR7:  NOT (SELF.description = 'unload tool') OR
        (1 >= SIZEOF (QUERY (mt <*
         USEDIN (SELF, 'INTEGRATED_CNC_SCHEMA.ACTION_RESOURCE.USAGE') |
         ('INTEGRATED_CNC_SCHEMA.MACHINING_TOOL' in TYPEOF(mt)))));

  WR8:  NOT (SELF.description = 'legacy function') OR
        ((verify_required_action_property       (SELF, 'function text')) AND
         (verify_descriptive_action_property    (SELF, 'function text')));
END_ENTITY;



(* ======================================== *)
(* MILLING OPERATION SUBTYPES (From Part 11) *)


ENTITY milling_type_operation
  SUBTYPE OF (machining_operation);
  WHERE
  WR1:  (verify_optional_action_property        (SELF, 'overcut length')) AND
        (verify_length_measure_action_property  (SELF, 'overcut length'));

  WR2:  ((verify_optional_relating_amr_with_name  (SELF, 'approach',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_STRATEGY_RELATIONSHIP'])) AND
         (verify_related_type_for_amr_with_name   (SELF, 'approach',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_STRATEGY_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_APPROACH_RETRACT_STRATEGY']))
        );

  WR3:  ((verify_optional_relating_amr_with_name  (SELF, 'retract',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_STRATEGY_RELATIONSHIP'])) AND
         (verify_related_type_for_amr_with_name   (SELF, 'retract',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_STRATEGY_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_APPROACH_RETRACT_STRATEGY']))
        );

  WR4:  ((verify_optional_relating_amr_with_name  (SELF, 'machining',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_STRATEGY_RELATIONSHIP'])) AND
         (verify_related_type_for_amr_with_name   (SELF, 'machining',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_STRATEGY_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MILLING_TYPE_STRATEGY']))
        );
END_ENTITY;


ENTITY freeform_milling_operation
  SUBTYPE OF (milling_type_operation);
  WHERE
  WR1:  ((verify_optional_relating_amr_with_name  (SELF, 'machining',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_STRATEGY_RELATIONSHIP'])) AND
         (verify_related_type_for_amr_with_name   (SELF, 'machining',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_STRATEGY_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.FREEFORM_MILLING_STRATEGY']))
        );
END_ENTITY;



ENTITY bottom_and_side_milling_operation
  SUBTYPE OF (milling_type_operation);
  WHERE
  WR1:  (SELF.description IN ['roughing','finishing']);

  WR2:  (verify_optional_action_property        (SELF, 'axial cutting depth')) AND
        (verify_length_measure_action_property  (SELF, 'axial cutting depth'));

  WR3:  (verify_optional_action_property        (SELF, 'radial cutting depth')) AND
        (verify_length_measure_action_property  (SELF, 'radial cutting depth'));

  WR4:  (verify_optional_action_property        (SELF, 'allowance side')) AND
        (verify_length_measure_action_property  (SELF, 'allowance side'));

  WR5:  (verify_optional_action_property        (SELF, 'allowance bottom')) AND
        (verify_length_measure_action_property  (SELF, 'allowance bottom'));

  WR6:  NOT (SELF.description = 'roughing') OR
        ((verify_required_action_property (SELF, 'allowance side')) AND
         (verify_required_action_property (SELF, 'allowance bottom')));
END_ENTITY;


ENTITY side_milling_operation
  SUBTYPE OF (milling_type_operation);
  WHERE
  WR1:  (SELF.description IN ['roughing','finishing']);

  WR2:  (verify_optional_action_property        (SELF, 'axial cutting depth')) AND
        (verify_length_measure_action_property  (SELF, 'axial cutting depth'));

  WR3:  (verify_optional_action_property        (SELF, 'radial cutting depth')) AND
        (verify_length_measure_action_property  (SELF, 'radial cutting depth'));

  WR4:  (verify_optional_action_property        (SELF, 'allowance side')) AND
        (verify_length_measure_action_property  (SELF, 'allowance side'));

  WR5:  NOT (SELF.description = 'roughing') OR
        (verify_required_action_property (SELF, 'allowance side'));
END_ENTITY;


ENTITY plane_milling_operation
  SUBTYPE OF (milling_type_operation);
  WHERE
  WR1:  (SELF.description IN ['roughing','finishing']);

  WR2:  (verify_optional_action_property        (SELF, 'axial cutting depth')) AND
        (verify_length_measure_action_property  (SELF, 'axial cutting depth'));

  WR3:  (verify_optional_action_property        (SELF, 'allowance bottom')) AND
        (verify_length_measure_action_property  (SELF, 'allowance bottom'));

  WR4:  NOT (SELF.description = 'roughing') OR
        (verify_required_action_property (SELF, 'allowance bottom'));
END_ENTITY;



ENTITY drilling_type_operation
  SUBTYPE OF (machining_operation);
  WHERE
  WR1:  (verify_optional_action_property        (SELF, 'overcut length')) AND
        (verify_length_measure_action_property  (SELF, 'overcut length'));

  WR2:  (verify_optional_action_property        (SELF, 'cutting depth')) AND
        (verify_length_measure_action_property  (SELF, 'cutting depth'));

  WR3:  (verify_optional_action_property        (SELF, 'previous diameter')) AND
        (verify_length_measure_action_property  (SELF, 'previous diameter'));

  WR4:  (verify_optional_action_property        (SELF, 'dwell time bottom')) AND
        (verify_rep_type_for_action_property    (SELF, 'dwell time bottom',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_DWELL_TIME_REPRESENTATION'])) AND
        (verify_rep_desc_for_action_property    (SELF, 'dwell time bottom',
           ['dwell time']));

  WR5:  (verify_optional_action_property        (SELF, 'feedrate on retract')) AND
        (verify_rep_type_for_action_property    (SELF, 'feedrate on retract',
           ['INTEGRATED_CNC_SCHEMA.MACHINING_FEED_SPEED_REPRESENTATION'])) AND
        (verify_rep_desc_for_action_property    (SELF, 'feedrate on retract',
           ['relative speed']));

  WR6:  ((verify_optional_relating_amr_with_name  (SELF, 'machining',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_STRATEGY_RELATIONSHIP'])) AND
         (verify_related_type_for_amr_with_name   (SELF, 'machining',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_STRATEGY_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.DRILLING_TYPE_STRATEGY']))
        );
END_ENTITY;


ENTITY drilling_operation
  SUBTYPE OF (drilling_type_operation);
  WHERE
  WR1:  (SELF.description IN ['drilling','counter sinking',
         'center drilling', 'multistep drilling']);

  WR2:  NOT (SELF.description = 'multistep drilling') OR
        ((verify_required_action_property       (SELF, 'retract distance')) AND
         (verify_length_measure_action_property (SELF, 'retract distance')) AND

         (verify_required_action_property       (SELF, 'first depth')) AND
         (verify_length_measure_action_property (SELF, 'first depth')) AND

         (verify_required_action_property       (SELF, 'depth of step')) AND
         (verify_length_measure_action_property (SELF, 'depth of step')) AND

         (verify_optional_action_property       (SELF, 'dwell time step')) AND
         (verify_rep_type_for_action_property   (SELF, 'dwell time step',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_DWELL_TIME_REPRESENTATION'])) AND
         (verify_rep_desc_for_action_property   (SELF, 'dwell time step',
           ['dwell time']))
        );
END_ENTITY;


ENTITY boring_operation
  SUBTYPE OF (drilling_type_operation);
  WHERE
  WR1:  (SELF.description IN ['boring','reaming']);

  WR2:  (verify_required_action_property        (SELF, 'spindle stop')) AND
        (verify_enumeration_action_property     (SELF, 'spindle stop',
         ['spindle stop at bottom', 'spindle nonstop']));

  WR3:  (verify_optional_action_property        (SELF, 'testcut depth')) AND
        (verify_length_measure_action_property  (SELF, 'testcut depth'));

  WR4:  (verify_optional_action_property        (SELF, 'waiting position')) AND
        (verify_rep_item_for_action_property    (SELF, 'waiting position',
         ['INTEGRATED_CNC_SCHEMA.CARTESIAN_POINT']));
END_ENTITY;



ENTITY back_boring_operation
  SUBTYPE OF (drilling_type_operation);
  WHERE
  WR1:  (0 = SIZEOF (QUERY (amr <* get_relating_amr (SELF) |
           ('INTEGRATED_CNC_SCHEMA.MACHINING_FUNCTIONS_RELATIONSHIP'
              IN TYPEOF (amr)) AND NOT
           (verify_required_action_property
                (amr.related_method, 'oriented spindle stop')))));
END_ENTITY;


ENTITY tapping_operation
  SUBTYPE OF (drilling_type_operation);
  WHERE
  WR1:  (SELF.description IN ['tapping','thread drilling']);

  WR2:  NOT (SELF.description = 'tapping') OR
        ((verify_required_action_property    (SELF, 'compensation chuck')) AND
         (verify_enumeration_action_property (SELF, 'compensation chuck',
          ['compensation chuck used', 'compensation chuck not used'])));

  WR3:  NOT (SELF.description = 'thread drilling') OR
        ((verify_required_action_property    (SELF, 'helical movement on forward')) AND
         (verify_enumeration_action_property (SELF, 'helical movement on forward',
          ['helical movement on forward', 'no helical movement on forward'])));
END_ENTITY;



(* ======================================== *)
(* MILLING STRATEGY SUBTYPES (From Part 11) *)


ENTITY machining_strategy
  SUBTYPE OF (action_method);
END_ENTITY;


ENTITY machining_approach_retract_strategy
  SUBTYPE OF (machining_strategy);
  WHERE
  WR1:  (SELF.description IN ['along path',
         'approach retract angle', 'approach retract tangent',
         'plunge helix', 'plunge ramp', 'plunge toolaxis',
         'plunge zigzag']);

  WR2:  (verify_optional_action_property       (SELF, 'tool orientation')) AND
        (verify_rep_item_for_action_property   (SELF, 'tool orientation',
          ['INTEGRATED_CNC_SCHEMA.DIRECTION']));

  WR3:  NOT (SELF.description = 'along path') OR
        ((1 <= get_count_of_relating_amr (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_TOOLPATH_SEQUENCE_RELATIONSHIP'])) AND
         (verify_related_type_for_amr   (SELF,
          ['INTEGRATED_CNC_SCHEMA.MACHINING_TOOLPATH_SEQUENCE_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_TOOLPATH']))
        );

  WR4:  NOT (SELF.description = 'approach retract angle') OR
        ((verify_required_action_property       (SELF, 'travel angle')) AND
         (verify_angle_measure_action_property  (SELF, 'travel angle')) AND

         (verify_required_action_property       (SELF, 'travel length')) AND
         (verify_length_measure_action_property (SELF, 'travel length')));

  WR5:  NOT (SELF.description = 'approach retract tangent') OR
        ((verify_required_action_property       (SELF, 'travel radius')) AND
         (verify_length_measure_action_property (SELF, 'travel radius')));

  WR6:  NOT (SELF.description IN ['plunge helix', 'plunge ramp', 'plunge zigzag']) OR
        ((verify_required_action_property       (SELF, 'plunge angle')) AND
         (verify_angle_measure_action_property  (SELF, 'plunge angle')));

  WR7:  NOT (SELF.description = 'plunge helix') OR
        ((verify_required_action_property       (SELF, 'plunge radius')) AND
         (verify_length_measure_action_property (SELF, 'plunge radius')));

  WR8:  NOT (SELF.description = 'plunge zigzag') OR
        ((verify_required_action_property       (SELF, 'plunge width')) AND
         (verify_length_measure_action_property (SELF, 'plunge width')));
END_ENTITY;


ENTITY drilling_type_strategy
  SUBTYPE OF (machining_strategy);
  WHERE
  WR1:  (verify_optional_action_property        (SELF, 'reduced cut at start')) AND
        (verify_rep_type_for_action_property    (SELF, 'reduced cut at start',
           ['INTEGRATED_CNC_SCHEMA.MACHINING_SPINDLE_SPEED_REPRESENTATION'])) AND
        (verify_rep_desc_for_action_property    (SELF, 'reduced cut at start',
           ['relative speed']));

  WR2:  (verify_optional_action_property        (SELF, 'reduced feedrate at start')) AND
        (verify_rep_type_for_action_property    (SELF, 'reduced feedrate at start',
           ['INTEGRATED_CNC_SCHEMA.MACHINING_FEED_SPEED_REPRESENTATION'])) AND
        (verify_rep_desc_for_action_property    (SELF, 'reduced feedrate at start',
           ['relative speed']));

  WR3:  (verify_optional_action_property        (SELF, 'depth of start')) AND
        (verify_length_measure_action_property  (SELF, 'depth of start'));

  WR4:  (verify_optional_action_property        (SELF, 'reduced cut at end')) AND
        (verify_rep_type_for_action_property    (SELF, 'reduced cut at end',
           ['INTEGRATED_CNC_SCHEMA.MACHINING_SPINDLE_SPEED_REPRESENTATION'])) AND
        (verify_rep_desc_for_action_property    (SELF, 'reduced cut at end',
           ['relative speed']));

  WR5:  (verify_optional_action_property        (SELF, 'reduced feedrate at end')) AND
        (verify_rep_type_for_action_property    (SELF, 'reduced feedrate at end',
           ['INTEGRATED_CNC_SCHEMA.MACHINING_FEED_SPEED_REPRESENTATION'])) AND
        (verify_rep_desc_for_action_property    (SELF, 'reduced feedrate at end',
           ['relative speed']));

  WR6:  (verify_optional_action_property        (SELF, 'depth of end')) AND
        (verify_length_measure_action_property  (SELF, 'depth of end'));

  WR7:  (verify_required_action_property (SELF, 'depth of start')) OR
        ((0 = SIZEOF (get_action_property (SELF, 'reduced cut at start'))) AND
         (0 = SIZEOF (get_action_property (SELF, 'reduced feedrate at start'))));

  WR8:  (verify_required_action_property (SELF, 'depth of end')) OR
        ((0 = SIZEOF (get_action_property (SELF, 'reduced cut at end'))) AND
         (0 = SIZEOF (get_action_property (SELF, 'reduced feedrate at end'))));
END_ENTITY;



ENTITY milling_type_strategy
  SUBTYPE OF (machining_strategy);
  WHERE
  WR1:  NOT (SELF.description IN ['bidirectional', 'bidirectional contour',
          'center milling', 'contour bidirectional', 'contour parallel',
          'contour spiral', 'explicit', 'unidirectional']) OR
        ((verify_optional_action_property       (SELF, 'overlap ratio')) AND
         (verify_ratio_measure_action_property  (SELF, 'overlap ratio')) AND

         (verify_optional_action_property       (SELF, 'multiple passes')) AND
         (verify_enumeration_action_property    (SELF, 'multiple passes',
          ['multiple passes allowed', 'multiple passes not allowed'])) );

  WR2:  NOT (SELF.description = 'bidirectional') OR
        ((verify_optional_action_property       (SELF, 'feed direction')) AND
         (verify_rep_item_for_action_property   (SELF, 'feed direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_optional_action_property       (SELF, 'stepover direction')) AND
         (verify_enumeration_action_property    (SELF, 'stepover direction',
           ['left', 'right'])) AND

         (verify_optional_action_property       (SELF, 'connection strategy')) AND
         (verify_enumeration_action_property    (SELF, 'connection strategy',
           ['straight line', 'lift shift plunge', 'degouge', 'loop back'])) );

  WR3:  NOT (SELF.description IN ['bidirectional contour',
                'contour bidirectional']) OR
        ((verify_optional_action_property       (SELF, 'feed direction')) AND
         (verify_rep_item_for_action_property   (SELF, 'feed direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_optional_action_property       (SELF, 'stepover direction')) AND
         (verify_enumeration_action_property    (SELF, 'stepover direction',
           ['left', 'right'])) AND

         (verify_optional_action_property       (SELF, 'rotation direction')) AND
         (verify_enumeration_action_property    (SELF, 'rotation direction',
           ['clockwise', 'counterclockwise'])) AND

         (verify_optional_action_property       (SELF, 'spiral cutmode')) AND
         (verify_enumeration_action_property    (SELF, 'spiral cutmode',
           ['climb', 'conventional'])) );

  WR4:  NOT (SELF.description IN ['contour parallel', 'contour spiral']) OR
        ((verify_optional_action_property       (SELF, 'rotation direction')) AND
         (verify_enumeration_action_property    (SELF, 'rotation direction',
           ['clockwise', 'counterclockwise'])) AND

         (verify_optional_action_property       (SELF, 'cutmode')) AND
         (verify_enumeration_action_property    (SELF, 'cutmode',
           ['climb', 'conventional'])) );

  WR5:  NOT (SELF.description = 'unidirectional') OR
        ((verify_optional_action_property       (SELF, 'feed direction')) AND
         (verify_rep_item_for_action_property   (SELF, 'feed direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_optional_action_property       (SELF, 'cutmode')) AND
         (verify_enumeration_action_property    (SELF, 'cutmode',
           ['climb', 'conventional'])) );
END_ENTITY;

ENTITY freeform_milling_strategy
  SUBTYPE OF (milling_type_strategy);
  WHERE
  WR1:  NOT (SELF.description IN ['leading line', 'plane cutter contact',
          'plane cutter location', 'uv']) OR
        ((verify_required_action_property       (SELF, 'pathmode')) AND
         (verify_enumeration_action_property    (SELF, 'pathmode',
           ['forward', 'zigzag'])) AND

         (verify_required_action_property       (SELF, 'cutmode')) AND
         (verify_enumeration_action_property    (SELF, 'cutmode',
           ['climb', 'conventional'])) AND

         (verify_required_action_property       (SELF, 'milling tolerances')) AND
         (verify_rep_type_for_action_property   (SELF, 'milling tolerances',
           ['INTEGRATED_CNC_SCHEMA.FREEFORM_MILLING_TOLERANCE_REPRESENTATION'])) AND

         (verify_optional_action_property       (SELF, 'stepover length')) AND
         (verify_length_measure_action_property (SELF, 'stepover length')) );

  WR2:  NOT (SELF.description = 'leading line') OR
        ((verify_required_action_property       (SELF, 'leading line')) AND
         (verify_rep_item_for_action_property   (SELF, 'leading line',
           ['INTEGRATED_CNC_SCHEMA.BOUNDED_CURVE'])) );

  WR3:  NOT (SELF.description IN ['plane cutter contact', 'plane cutter location']) OR
        ((verify_required_action_property       (SELF, 'plane normal')) AND
         (verify_rep_item_for_action_property   (SELF, 'plane normal',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) );

  WR4:  NOT (SELF.description = 'uv') OR
        ((verify_required_action_property       (SELF, 'forward direction')) AND
         (verify_rep_item_for_action_property   (SELF, 'forward direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_required_action_property       (SELF, 'sideward direction')) AND
         (verify_rep_item_for_action_property   (SELF, 'sideward direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) );
END_ENTITY;



(* ======================================== *)
(* TURNING OPERATION SUBTYPES (From Part 12) *)

ENTITY turning_type_operation
  SUBTYPE OF (machining_operation);
  WHERE
  WR1:  ((verify_optional_relating_amr_with_name  (SELF, 'approach',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_STRATEGY_RELATIONSHIP'])) AND
         (verify_related_type_for_amr_with_name   (SELF, 'approach',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_STRATEGY_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_APPROACH_RETRACT_STRATEGY']))
        );

  WR2:  ((verify_optional_relating_amr_with_name  (SELF, 'retract',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_STRATEGY_RELATIONSHIP'])) AND
         (verify_related_type_for_amr_with_name   (SELF, 'retract',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_STRATEGY_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.MACHINING_APPROACH_RETRACT_STRATEGY']))
        );

  WR3:  ((verify_optional_relating_amr_with_name  (SELF, 'machining',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_STRATEGY_RELATIONSHIP'])) AND
         (verify_related_type_for_amr_with_name   (SELF, 'machining',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_STRATEGY_RELATIONSHIP'],
          ['INTEGRATED_CNC_SCHEMA.TURNING_TYPE_STRATEGY']))
        );

END_ENTITY;

ENTITY facing_turning_operation
  SUBTYPE OF (turning_type_operation);
  WHERE
  WR1:  (SELF.description IN ['roughing','finishing']);

  WR2:  (verify_optional_action_property        (SELF, 'allowance')) AND
        (verify_length_measure_action_property  (SELF, 'allowance'));

  WR3:  NOT (SELF.description = 'roughing') OR
        (verify_required_action_property (SELF, 'allowance'));
END_ENTITY;

ENTITY grooving_turning_operation
  SUBTYPE OF (turning_type_operation);
  WHERE
  WR1:  (SELF.description IN ['roughing', 'finishing', 'cutting in']);

  WR2:  (verify_optional_action_property     (SELF, 'dwell')) AND
        (verify_rep_type_for_action_property (SELF, 'dwell',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_DWELL_TIME_REPRESENTATION']));

  WR3:  (verify_optional_action_property        (SELF, 'allowance')) AND
        (verify_length_measure_action_property  (SELF, 'allowance'));

  -- allowance propery required for roughing
  WR4:  NOT (SELF.description = 'roughing') OR
        (verify_required_action_property (SELF, 'allowance'));

  -- allowance propery forbidden for cutting in
  WR5:  NOT (SELF.description = 'cutting in') OR
        (0 = SIZEOF (get_action_property (SELF, 'allowance')));
END_ENTITY;

ENTITY contouring_turning_operation
  SUBTYPE OF (turning_type_operation);
  WHERE
  WR1:  (SELF.description IN ['roughing','finishing']);

  WR2:  (verify_optional_action_property        (SELF, 'allowance')) AND
        (verify_length_measure_action_property  (SELF, 'allowance'));

  WR3:  NOT (SELF.description = 'roughing') OR
        (verify_required_action_property (SELF, 'allowance'));
END_ENTITY;

ENTITY threading_turning_operation
  SUBTYPE OF (turning_type_operation);
  WHERE
  WR1:  (SELF.description IN ['roughing','finishing']);

  WR2:  (verify_optional_action_property        (SELF, 'allowance')) AND
        (verify_length_measure_action_property  (SELF, 'allowance'));

  WR3:  NOT (SELF.description = 'roughing') OR
        (verify_required_action_property (SELF, 'allowance'));
END_ENTITY;

ENTITY knurling_turning_operation
  SUBTYPE OF (turning_type_operation);
END_ENTITY;


(* ======================================== *)
(* TURNING STRATEGY SUBTYPES (From Part 12) *)

ENTITY turning_type_strategy
  SUBTYPE OF (machining_strategy);
  WHERE
  WR1:  (SELF.description IN ['unidirectional', 'bidirectional',
          'contour', 'thread', 'grooving', 'multistep grooving',
          'explicit']);

  WR2:  ((verify_optional_action_property       (SELF, 'overcut length')) AND
         (verify_length_measure_action_property (SELF, 'overcut length'))
        );

  WR3:  ((verify_optional_action_property       (SELF, 'multiple passes')) AND
         (verify_enumeration_action_property    (SELF, 'multiple passes',
          ['multiple passes allowed', 'multiple passes not allowed']))
        );

  WR4:  ((verify_optional_action_property (SELF, 'cutting depth')) AND
         (0 = SIZEOF (QUERY (prop <*
           get_action_property (SELF, 'cutting depth') | NOT
           (0 < SIZEOF (QUERY (prep <* USEDIN (prop, 'INTEGRATED_CNC_SCHEMA.' +
              'ACTION_PROPERTY_REPRESENTATION.PROPERTY') |
             (1 = SIZEOF (QUERY (it <* prep.representation.items |
                (('INTEGRATED_CNC_SCHEMA.COMPOUND_REPRESENTATION_ITEM'
                   IN TYPEOF(it)) AND
                 ('INTEGRATED_CNC_SCHEMA.LIST_REPRESENTATION_ITEM'
                   IN TYPEOF(it.item_element)) AND
                 (0 = SIZEOF (QUERY (ie <* it.item_element | NOT (SIZEOF([
                    'INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
                    'INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT'] *
                    TYPEOF(ie)) = 2))))
             ))))
           )))
         )))
        );

  WR5:  ((verify_optional_action_property     (SELF, 'variable feedrate')) AND
         (verify_rep_type_for_action_property (SELF, 'variable feedrate',
           ['INTEGRATED_CNC_SCHEMA.MACHINING_FEED_SPEED_REPRESENTATION'])) AND
         (verify_rep_desc_for_action_property (SELF, 'variable feedrate',
           ['relative speed']))
        );

  WR6:  NOT (SELF.description = 'unidirectional') OR
        ((verify_optional_action_property     (SELF, 'feed direction')) AND
         (verify_rep_item_for_action_property (SELF, 'feed direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_optional_action_property     (SELF, 'back path direction')) AND
         (verify_rep_item_for_action_property (SELF, 'back path direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_optional_action_property     (SELF, 'lift direction')) AND
         (verify_rep_item_for_action_property (SELF, 'lift direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_optional_action_property     (SELF, 'stepover direction')) AND
         (verify_rep_item_for_action_property (SELF, 'stepover direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_optional_action_property       (SELF, 'lift height')) AND
         (verify_length_measure_action_property (SELF, 'lift height')) AND

         (verify_optional_action_property     (SELF, 'lift feedrate')) AND
         (verify_rep_type_for_action_property (SELF, 'lift feedrate',
           ['INTEGRATED_CNC_SCHEMA.MACHINING_FEED_SPEED_REPRESENTATION'])) AND
         (verify_rep_desc_for_action_property (SELF, 'lift feedrate',
           ['feed speed', 'feed per revolution'])) AND

         (verify_optional_action_property     (SELF, 'stepover feedrate')) AND
         (verify_rep_type_for_action_property (SELF, 'stepover feedrate',
           ['INTEGRATED_CNC_SCHEMA.MACHINING_FEED_SPEED_REPRESENTATION'])) AND
         (verify_rep_desc_for_action_property (SELF, 'stepover feedrate',
           ['feed speed', 'feed per revolution']))
        );

  WR7:  NOT (SELF.description = 'bidirectional') OR
        ((verify_optional_action_property     (SELF, 'feed direction')) AND
         (verify_rep_item_for_action_property (SELF, 'feed direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_optional_action_property     (SELF, 'stepover direction')) AND
         (verify_rep_item_for_action_property (SELF, 'stepover direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_optional_action_property     (SELF, 'stepover feedrate')) AND
         (verify_rep_type_for_action_property (SELF, 'stepover feedrate',
           ['INTEGRATED_CNC_SCHEMA.MACHINING_FEED_SPEED_REPRESENTATION'])) AND
         (verify_rep_desc_for_action_property (SELF, 'stepover feedrate',
           ['feed speed', 'feed per revolution']))
        );

  WR8:  NOT (SELF.description = 'contour') OR
        ((verify_optional_action_property     (SELF, 'back path direction')) AND
         (verify_rep_item_for_action_property (SELF, 'back path direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_optional_action_property     (SELF, 'lift direction')) AND
         (verify_rep_item_for_action_property (SELF, 'lift direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_optional_action_property     (SELF, 'stepover direction')) AND
         (verify_rep_item_for_action_property (SELF, 'stepover direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_optional_action_property       (SELF, 'lift height')) AND
         (verify_length_measure_action_property (SELF, 'lift height')) AND

         (verify_optional_action_property     (SELF, 'lift feedrate')) AND
         (verify_rep_type_for_action_property (SELF, 'lift feedrate',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_FEED_SPEED_REPRESENTATION'])) AND
         (verify_rep_desc_for_action_property (SELF, 'lift feedrate',
           ['feed speed', 'feed per revolution'])) AND

         (verify_optional_action_property     (SELF, 'stepover feedrate')) AND
         (verify_rep_type_for_action_property (SELF, 'stepover feedrate',
           ['INTEGRATED_CNC_SCHEMA.MACHINING_FEED_SPEED_REPRESENTATION'])) AND
         (verify_rep_desc_for_action_property (SELF, 'stepover feedrate',
           ['feed speed', 'feed per revolution'])) AND

         (verify_optional_action_property
           (SELF, 'variable stepover feedrate')) AND
         (verify_rep_type_for_action_property
           (SELF, 'variable stepover feedrate',
           ['INTEGRATED_CNC_SCHEMA.MACHINING_FEED_SPEED_REPRESENTATION'])) AND
         (verify_rep_desc_for_action_property
           (SELF, 'variable stepover feedrate', ['relative speed']))
        );

  WR9:  NOT (SELF.description = 'thread') OR
        ((verify_required_action_property     (SELF, 'cut in amount')) AND
         (verify_enumeration_action_property  (SELF, 'cut in amount',
           ['constant depth', 'variable depth', 'constant removal amount'])) AND

         (verify_required_action_property     (SELF, 'threading direction')) AND
         (verify_enumeration_action_property  (SELF, 'threading direction',
           ['left', 'right', 'center', 'left zigzag', 'right zigzag'])) AND

         (verify_optional_action_property       (SELF, 'path return angle')) AND
         (verify_angle_measure_action_property  (SELF, 'path return angle')) AND

         (verify_optional_action_property       (SELF, 'lift height')) AND
         (verify_length_measure_action_property (SELF, 'lift height'))
        );

  WR10: NOT (SELF.description IN ['grooving', 'multistep grooving']) OR
        ((verify_optional_action_property     (SELF, 'grooving direction')) AND
         (verify_rep_item_for_action_property (SELF, 'grooving direction',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_optional_action_property       (SELF, 'travel distance')) AND
         (verify_length_measure_action_property (SELF, 'travel distance'))
        );

  WR11: NOT (SELF.description = 'multistep grooving') OR
        ((verify_optional_action_property       (SELF, 'retract distance')) AND
         (verify_length_measure_action_property (SELF, 'retract distance'))
        );
END_ENTITY;



(* ======================================== *)
(* ACTION RESOURCE SUBTYPES *)

ENTITY machining_tool
  SUBTYPE OF (action_resource);
  WHERE
  WR1: NOT (SELF.kind.name IN ['cutting tool', 'milling cutting tool',
        'turning cutting tool']) OR
        ((verify_required_resource_property     (SELF, 'tool body')) AND
         (verify_rep_type_for_resource_property (SELF, 'tool body',
          ['INTEGRATED_CNC_SCHEMA.MACHINING_TOOL_BODY_REPRESENTATION'])) AND

        -- Must have at least one cutting component
        -- note that this is a set, not a list.
        (0 < SIZEOF (QUERY (arr <* USEDIN (SELF,
          'INTEGRATED_CNC_SCHEMA.ACTION_RESOURCE_RELATIONSHIP.RELATING_RESOURCE') |
         ('INTEGRATED_CNC_SCHEMA.MACHINING_CUTTING_COMPONENT'
          IN TYPEOF (arr.related_resource)) ))) AND

         (verify_optional_resource_property
           (SELF, 'overall assembly length')) AND
         (verify_length_measure_resource_property
           (SELF, 'overall assembly length')) AND

         (verify_optional_resource_property
           (SELF, 'tool holder profile')) AND
         (verify_rep_item_for_resource_property
           (SELF, 'tool holder profile',
           ['INTEGRATED_CNC_SCHEMA.SURFACE_OF_REVOLUTION']))
        );

  WR2: NOT (SELF.kind.name = 'milling cutting tool') OR
        ((verify_optional_resource_property
           (SELF, 'direction for spindle orientation')) AND
         (verify_rep_item_for_resource_property
           (SELF, 'direction for spindle orientation',
           ['INTEGRATED_CNC_SCHEMA.DIRECTION'])) AND

         (verify_optional_resource_property
           (SELF, 'tool holder diameter for spindle orientation')) AND
         (verify_length_measure_resource_property
           (SELF, 'tool holder diameter for spindle orientation'))
        );

  WR3: NOT (SELF.kind.name = 'turning cutting tool') OR
        ((verify_optional_resource_property
           (SELF, 'overall assembly width')) AND
         (verify_length_measure_resource_property
           (SELF, 'overall assembly width')) AND

         (verify_optional_resource_property
           (SELF, 'minimum cutting diameter')) AND
         (verify_length_measure_resource_property
           (SELF, 'minimum cutting diameter'))
        );
END_ENTITY;

ENTITY machining_cutting_component
  SUBTYPE OF (action_resource,characterized_object);
  WHERE
  WR1:  (verify_required_resource_property       (SELF, 'offset length')) AND
        (verify_length_measure_resource_property (SELF, 'offset length'));

  WR2:  (1 >= SIZEOF (USEDIN (SELF, 'INTEGRATED_CNC_SCHEMA.' +
           'MATERIAL_DESIGNATION.DEFINITIONS')));

  WR3:  (verify_optional_resource_property
          (SELF, 'technological data')) AND
        (0 = SIZEOF (QUERY (prop <* get_resource_property
          (SELF, 'technological data') |
           NOT (0 < SIZEOF (QUERY (prep <* USEDIN (prop,
                'INTEGRATED_CNC_SCHEMA.' +
                'RESOURCE_PROPERTY_REPRESENTATION.PROPERTY') |

                ((verify_optional_rep_item
                   (prep.representation, 'cutting angle')) AND
                 (verify_angle_measure_rep_item
                   (prep.representation, 'cutting angle')) AND

                 (verify_optional_rep_item
                   (prep.representation, 'free angle')) AND
                 (verify_angle_measure_rep_item
                   (prep.representation, 'free angle')) AND

                 (verify_optional_rep_item
                   (prep.representation, 'aux angle')) AND
                 (verify_angle_measure_rep_item
                   (prep.representation, 'aux angle'))
                )
            )))
         )));

  WR4:  (verify_optional_resource_property     (SELF, 'expected life')) AND
        (verify_time_measure_resource_property (SELF, 'expected life'));

  WR5: (1 >= SIZEOF (QUERY (arr <* USEDIN (SELF,
          'INTEGRATED_CNC_SCHEMA.REQUIREMENT_FOR_ACTION_RESOURCE.RESOURCES') |
          (arr.kind.name = 'cutting component') AND
          (0 < SIZEOF (QUERY (mt <* arr.operations |
           'INTEGRATED_CNC_SCHEMA.MACHINING_TECHNOLOGY' IN TYPEOF (mt))))
        )));
END_ENTITY;



(* ======================================== *)
(* REPRESENTATION SUBTYPES *)


ENTITY machining_dwell_time_representation
  SUBTYPE OF (representation);
  WHERE
  WR1:  (SELF.name IN ['dwell time', 'dwell revolution']);

  WR2:  NOT (SELF.name = 'dwell time') OR
        ((verify_required_rep_item       (SELF, 'dwell time')) AND
         (verify_time_measure_rep_item   (SELF, 'dwell time'))
        );

  WR3:  NOT (SELF.name = 'dwell revolution') OR
        ((verify_required_rep_item       (SELF, 'dwell revolution')) AND
         (verify_count_measure_rep_item  (SELF, 'dwell revolution'))
        );
END_ENTITY;

ENTITY machining_feed_speed_representation
  SUBTYPE OF (representation);
  WHERE
  WR1:  (SELF.name IN ['feed speed', 'feed per revolution',
         'feed per tooth', 'relative speed']);

  WR2:  NOT (SELF.name = 'feed speed') OR
        ((verify_required_rep_item             (SELF, 'feed speed')) AND
         (verify_linear_speed_measure_rep_item (SELF, 'feed speed'))
        );

  WR3:  NOT (SELF.name = 'feed per revolution') OR
        ((verify_required_rep_item       (SELF, 'feed per revolution')) AND
         (verify_length_measure_rep_item (SELF, 'feed per revolution'))
        );

  WR4:  NOT (SELF.name = 'feed per tooth') OR
        ((verify_required_rep_item       (SELF, 'feed per tooth')) AND
         (verify_length_measure_rep_item (SELF, 'feed per tooth'))
        );

  WR5:  NOT (SELF.name = 'relative speed') OR
        ((verify_required_rep_item       (SELF, 'relative speed')) AND
         (verify_ratio_measure_rep_item  (SELF, 'relative speed'))
        );
END_ENTITY;

ENTITY machining_offset_vector_representation
  SUBTYPE OF (representation);
  WHERE
  WR1: (1 = SIZEOF (QUERY ( it <* SELF.items | (it.name = 'translate')))) AND
       (0 = SIZEOF (QUERY ( it <* SELF.items | (it.name = 'translate') AND NOT
         (('INTEGRATED_CNC_SCHEMA.COMPOUND_REPRESENTATION_ITEM'
            IN TYPEOF(it)) AND
          ('INTEGRATED_CNC_SCHEMA.LIST_REPRESENTATION_ITEM'
            IN TYPEOF(it.item_element)) AND
          (SIZEOF(it.item_element) = 3) AND
          (0 = SIZEOF (QUERY (ie <* it.item_element | NOT
           (('INTEGRATED_CNC_SCHEMA.EXPRESSION_REPRESENTATION_ITEM'
              IN TYPEOF(ie)) AND
            ('INTEGRATED_CNC_SCHEMA.NUMERIC_VARIABLE'
              IN TYPEOF(ie))))))
         )
        )));

  WR2: (1 >= SIZEOF (QUERY ( it <* SELF.items | (it.name = 'rotate')))) AND
       (0  = SIZEOF (QUERY ( it <* SELF.items | (it.name = 'rotate') AND NOT
         (('INTEGRATED_CNC_SCHEMA.COMPOUND_REPRESENTATION_ITEM'
            IN TYPEOF(it)) AND
          ('INTEGRATED_CNC_SCHEMA.LIST_REPRESENTATION_ITEM'
            IN TYPEOF(it.item_element)) AND
          (SIZEOF(it.item_element) = 3) AND
          (0 = SIZEOF (QUERY (ie <* it.item_element | NOT
           (('INTEGRATED_CNC_SCHEMA.EXPRESSION_REPRESENTATION_ITEM'
              IN TYPEOF(ie)) AND
            ('INTEGRATED_CNC_SCHEMA.NUMERIC_VARIABLE'
              IN TYPEOF(ie))))))
         )
        )));
END_ENTITY;

ENTITY machining_spindle_speed_representation
  SUBTYPE OF (representation);
  WHERE
  WR1:  (SELF.name IN ['spindle speed', 'cutting speed', 'relative speed']);

  WR2:  NOT (SELF.name = 'spindle speed') OR
        ((verify_required_rep_item             (SELF, 'rotational speed')) AND
         (verify_rotary_speed_measure_rep_item (SELF, 'rotational speed'))
        );

  WR3:  NOT (SELF.name = 'cutting speed') OR
        ((verify_required_rep_item             (SELF, 'surface speed')) AND
         (verify_linear_speed_measure_rep_item (SELF, 'surface speed')) AND

         (verify_optional_rep_item
           (SELF, 'maximum rotational speed')) AND
         (verify_rotary_speed_measure_rep_item
           (SELF, 'maximum rotational speed'))
        );

  WR4:  NOT (SELF.name = 'relative speed') OR
        ((verify_required_rep_item             (SELF, 'relative speed')) AND
         (verify_ratio_measure_rep_item        (SELF, 'relative speed'))
        );
END_ENTITY;


ENTITY machining_tool_body_representation
  SUBTYPE OF (representation);
  WHERE
  WR1:  NOT (SELF.name IN ['backside counterbore', 'backside countersink',
        'ball endmill', 'boring tool', 'bullnose endmill', 'centerdrill',
        'combined drill and reamer', 'combined drill and tap', 'counterbore',
        'countersink','dovetail mill', 'endmill', 'facemill', 'reamer',
        'side mill', 'spade drill', 'tap', 'tapered drill', 'tapered endmill',
        'tapered reamer', 'tapered tap', 'tee slot mill', 'thread mill',
        'threading tool', 'twist drill', 'user defined milling tool',
        'woodruff keyseat mill']) OR

        ((1 = SIZEOF (QUERY (rr <* USEDIN (SELF,
           'INTEGRATED_CNC_SCHEMA.REPRESENTATION_RELATIONSHIP.REP_1') |
          ('INTEGRATED_CNC_SCHEMA.MACHINING_TOOL_DIMENSION_REPRESENTATION'
           IN TYPEOF(rr.rep_2))))
          ) AND

         (verify_optional_rep_item      (SELF, 'number of teeth')) AND
         (verify_count_measure_rep_item (SELF, 'number of teeth')) AND

         (verify_optional_rep_item    (SELF, 'hand of cut')) AND
         (verify_enumeration_rep_item (SELF, 'hand of cut',
           ['left', 'right', 'neutral'])) AND

         (verify_optional_rep_item    (SELF, 'coolant through tool')) AND
         (verify_enumeration_rep_item (SELF, 'coolant through tool',
           ['supported', 'not supported'])) AND

         (verify_optional_rep_item       (SELF, 'pilot length')) AND
         (verify_length_measure_rep_item (SELF, 'pilot length'))
        );

  WR2:  NOT (SELF.name = 'boring tool') OR
        ((verify_required_rep_item    (SELF, 'retract movement')) AND
         (verify_enumeration_rep_item (SELF, 'retract movement',
           ['permitted', 'forbidden']))
        );

  WR3:  NOT (SELF.name IN ['combined drill and reamer',
         'combined drill and tap']) OR
        ((verify_optional_rep_item       (SELF, 'drill length')) AND
         (verify_length_measure_rep_item (SELF, 'drill length'))
        );

  WR4:  NOT (SELF.name IN ['countersink', 'backside countersink']) OR
        ((verify_optional_rep_item       (SELF, 'countersink radius')) AND
         (verify_length_measure_rep_item (SELF, 'countersink radius'))
        );

  WR5:  NOT (SELF.name = 'dovetail mill') OR
        ((verify_optional_rep_item       (SELF, 'included angle')) AND
         (verify_angle_measure_rep_item  (SELF, 'included angle'))
        );

  WR6:  NOT (SELF.name IN ['side mill', 'woodruff keyseat mill']) OR
        ((verify_optional_rep_item       (SELF, 'cutter width')) AND
         (verify_length_measure_rep_item (SELF, 'cutter width'))
        );

  WR7:  NOT (SELF.name = 'tee slot mill') OR
        ((verify_optional_rep_item       (SELF, 'cutting thickness')) AND
         (verify_length_measure_rep_item (SELF, 'cutting thickness'))
        );

  WR8:  NOT (SELF.name IN ['tapered drill', 'tapered endmill',
         'tapered reamer', 'tapered tap']) OR
        ((verify_optional_rep_item       (SELF, 'taper angle')) AND
         (verify_angle_measure_rep_item  (SELF, 'taper angle'))
        );

  WR9:  NOT (SELF.name = 'user defined milling tool') OR
        ((verify_required_rep_item (SELF, 'tool identifier')) AND
         (0 = SIZEOF (QUERY ( it <* SELF.items |
          (it.name = 'tool identifier') AND NOT
          (('INTEGRATED_CNC_SCHEMA.DESCRIPTIVE_REPRESENTATION_ITEM'
            IN TYPEOF(it))))))
        );

  -- tool types for turning
  WR10: NOT (SELF.name IN ['general turning tool',
        'grooving tool', 'knurling tool', 'turning threading tool',
        'user defined turning tool']) OR

        ((1 = SIZEOF (QUERY (rr <* USEDIN (SELF,
           'INTEGRATED_CNC_SCHEMA.REPRESENTATION_RELATIONSHIP.REP_1') |
          ('INTEGRATED_CNC_SCHEMA.MACHINING_TOOL_DIMENSION_REPRESENTATION'
           IN TYPEOF(rr.rep_2))))) AND

         (verify_optional_rep_item    (SELF, 'hand of cut')) AND
         (verify_enumeration_rep_item (SELF, 'hand of cut',
           ['left', 'right', 'neutral'])) AND

         (verify_optional_rep_item
           (SELF, 'maximum side cutting depth')) AND
         (verify_length_measure_rep_item
           (SELF, 'maximum side cutting depth')) AND

         (verify_optional_rep_item
           (SELF, 'maximum end cutting depth')) AND
         (verify_length_measure_rep_item
           (SELF, 'maximum end cutting depth')) AND

         (verify_optional_rep_item       (SELF, 'tool body height')) AND
         (verify_length_measure_rep_item (SELF, 'tool body height')) AND

         (verify_optional_rep_item       (SELF, 'tool body width')) AND
         (verify_length_measure_rep_item (SELF, 'tool body width'))
        );

  WR11: NOT (SELF.name = 'grooving tool') OR
        ((verify_required_rep_item       (SELF, 'cutting width')) AND
         (verify_length_measure_rep_item (SELF, 'cutting width')) AND

         (verify_required_rep_item       (SELF, 'maximum grooving depth')) AND
         (verify_length_measure_rep_item (SELF, 'maximum grooving depth')) AND

         (verify_optional_rep_item       (SELF, 'corner radius')) AND
         (verify_length_measure_rep_item (SELF, 'corner radius')) AND

         (verify_optional_rep_item
           (SELF, 'maximum axial grooving diameter')) AND
         (verify_length_measure_rep_item
           (SELF, 'maximum axial grooving diameter')) AND

         (verify_optional_rep_item
           (SELF, 'minimum axial grooving diameter')) AND
         (verify_length_measure_rep_item
           (SELF, 'minimum axial grooving diameter'))
        );

  WR12: NOT (SELF.name = 'knurling tool') OR
        ((verify_required_rep_item    (SELF, 'knurl pattern')) AND
         (verify_enumeration_rep_item (SELF, 'knurl pattern',
           ['straight', 'diagonal', 'diamond'])) AND

         (verify_optional_rep_item       (SELF, 'cutting length')) AND
         (verify_length_measure_rep_item (SELF, 'cutting length')) AND

         (verify_optional_rep_item       (SELF, 'cutting angle')) AND
         (verify_angle_measure_rep_item  (SELF, 'cutting angle')) AND

         (verify_optional_rep_item       (SELF, 'cutting pitch')) AND
         (verify_length_measure_rep_item (SELF, 'cutting pitch'))
        );

  WR13: NOT (SELF.name = 'turning threading tool') OR
        ((verify_required_rep_item       (SELF, 'threading pitch')) AND
         (verify_length_measure_rep_item (SELF, 'threading pitch')) AND

         (verify_optional_rep_item       (SELF, 'threading angle')) AND
         (verify_angle_measure_rep_item  (SELF, 'threading angle'))
        );

  WR14: NOT (SELF.name = 'user defined turning tool') OR
        ((verify_required_rep_item       (SELF, 'tool identifier')) AND
         (verify_descriptive_rep_item    (SELF, 'tool identifier'))
        );
END_ENTITY;


ENTITY machining_tool_dimension_representation
  SUBTYPE OF (representation);
  WHERE
  WR1:  NOT (SELF.name = 'milling') OR
        ((verify_required_rep_item       (SELF, 'diameter')) AND
         (verify_length_measure_rep_item (SELF, 'diameter')) AND

         (verify_optional_rep_item       (SELF, 'tool tip half angle')) AND
         (verify_angle_measure_rep_item  (SELF, 'tool tip half angle')) AND

         (verify_optional_rep_item       (SELF, 'tool circumference angle')) AND
         (verify_angle_measure_rep_item  (SELF, 'tool circumference angle')) AND

         (verify_optional_rep_item       (SELF, 'cutting edge length')) AND
         (verify_length_measure_rep_item (SELF, 'cutting edge length')) AND

         (verify_optional_rep_item       (SELF, 'edge radius')) AND
         (verify_length_measure_rep_item (SELF, 'edge radius')) AND

         (verify_optional_rep_item       (SELF, 'edge center vertical')) AND
         (verify_length_measure_rep_item (SELF, 'edge center vertical')) AND

         (verify_optional_rep_item       (SELF, 'edge center horizontal')) AND
         (verify_length_measure_rep_item (SELF, 'edge center horizontal'))
        );

  WR2:  NOT (SELF.name = 'turning') OR
        ((verify_optional_rep_item       (SELF, 'cutting edge length')) AND
         (verify_length_measure_rep_item (SELF, 'cutting edge length')) AND

         (verify_optional_rep_item       (SELF, 'side cutting edge angle')) AND
         (verify_angle_measure_rep_item  (SELF, 'side cutting edge angle')) AND

         (verify_optional_rep_item       (SELF, 'end cutting edge angle')) AND
         (verify_angle_measure_rep_item  (SELF, 'end cutting edge angle')) AND

         (verify_optional_rep_item       (SELF, 'side rake angle')) AND
         (verify_angle_measure_rep_item  (SELF, 'side rake angle')) AND

         (verify_optional_rep_item       (SELF, 'back rake angle')) AND
         (verify_angle_measure_rep_item  (SELF, 'back rake angle')) AND

         (verify_optional_rep_item       (SELF, 'side clearance angle')) AND
         (verify_angle_measure_rep_item  (SELF, 'side clearance angle')) AND

         (verify_optional_rep_item       (SELF, 'back clearance angle')) AND
         (verify_angle_measure_rep_item  (SELF, 'back clearance angle')) AND

         (verify_optional_rep_item       (SELF, 'nose radius')) AND
         (verify_length_measure_rep_item (SELF, 'nose radius')) AND

         (verify_optional_rep_item       (SELF, 'circle diameter')) AND
         (verify_length_measure_rep_item (SELF, 'circle diameter'))
        );

  WR3:  (0 = SIZEOF (QUERY (rr <* USEDIN (SELF,
          'INTEGRATED_CNC_SCHEMA.REPRESENTATION_RELATIONSHIP.REP_2') |
         ('INTEGRATED_CNC_SCHEMA.MACHINING_TOOL_BODY_REPRESENTATION'
          IN TYPEOF(rr.rep_1)) AND (rr.rep_1.name = 'ball endmill')))
        ) OR (verify_ball_endmill_edge_dimensions (SELF));


  WR4:  (0 = SIZEOF (QUERY (rr <* USEDIN (SELF,
          'INTEGRATED_CNC_SCHEMA.REPRESENTATION_RELATIONSHIP.REP_2') |
         ('INTEGRATED_CNC_SCHEMA.MACHINING_TOOL_BODY_REPRESENTATION'
          IN TYPEOF(rr.rep_1)) AND
         (rr.rep_1.name IN ['bullnose endmill', 'ball endmill'])))
        ) OR (
         (0 = SIZEOF (QUERY ( it <* SELF.items |
          (it.name = 'tool tip half angle') AND NOT
          (it.value_component = 0)))
         ) AND
         (0 = SIZEOF (QUERY ( it <* SELF.items |
          (it.name = 'tool circumference angle') AND NOT
          (it.value_component = 0)))
         )
        );
END_ENTITY;


ENTITY machining_tool_direction_representation
  SUBTYPE OF (representation);
  WHERE
  WR1:  (SELF.name IN ['two axes', 'three axes', 'three axes tilted tool',
        'five axes const tilt yaw', 'five axes var tilt yaw']);

  WR2:  NOT (SELF.name = 'three axes tilted tool') OR
        ((verify_required_rep_item       (SELF, 'tool direction orientation')) AND
         (0 = SIZEOF (QUERY ( it <* SELF.items |
          (it.name = 'tool direction orientation') AND NOT
          ('INTEGRATED_CNC_SCHEMA.DIRECTION' IN TYPEOF(it)))))
        );

  WR3:  NOT (SELF.name = 'five axes const tilt yaw') OR
        ((verify_required_rep_item       (SELF, 'tool direction tilt angle')) AND
         (verify_angle_measure_rep_item  (SELF, 'tool direction tilt angle')) AND

         (verify_required_rep_item       (SELF, 'tool direction yaw angle')) AND
         (verify_angle_measure_rep_item  (SELF, 'tool direction yaw angle'))
        );
END_ENTITY;

ENTITY machining_toolpath_speed_profile_representation
  SUBTYPE OF (representation);
  WHERE
  WR1:  (1 = SIZEOF (QUERY ( it <* SELF.items |
          ( (('INTEGRATED_CNC_SCHEMA.BOUNDED_CURVE'
              IN TYPEOF(it))) OR

            (('INTEGRATED_CNC_SCHEMA.DESCRIPTIVE_REPRESENTATION_ITEM'
              IN TYPEOF(it)) AND
             (it.description IN ['rapid']))  OR

            ((SIZEOF([
              'INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
              'INTEGRATED_CNC_SCHEMA.RATIO_MEASURE_WITH_UNIT'] *
              TYPEOF(it)) = 2))
           )
        )));
END_ENTITY;

ENTITY freeform_milling_tolerance_representation
  SUBTYPE OF (representation);
  WHERE
  WR1:   (verify_required_rep_item       (SELF, 'chordal tolerance')) AND
         (verify_length_measure_rep_item (SELF, 'chordal tolerance'));

  WR2:   (verify_required_rep_item       (SELF, 'scallop height')) AND
         (verify_length_measure_rep_item (SELF, 'scallop height'));
END_ENTITY;




(* ========================================  *)
(* PRODUCT SUBTYPES *)

ENTITY machining_setup
  SUBTYPE OF (product);
  WHERE
  WR1: (0 = SIZEOF (QUERY (pdf <* USEDIN (SELF,
          'INTEGRATED_CNC_SCHEMA.' +
          'PRODUCT_DEFINITION_FORMATION.OF_PRODUCT') | NOT

          (0 = SIZEOF (QUERY (pd <* USEDIN (pdf,
           'INTEGRATED_CNC_SCHEMA.PRODUCT_DEFINITION.FORMATION') | NOT

          -- it has one associated security plane.
          (1 = SIZEOF (QUERY (prop <* USEDIN (pd,
             'INTEGRATED_CNC_SCHEMA.PROPERTY_DEFINITION.DEFINITION') |
             (prop.name = 'security plane'))))
          )))
        )));
END_ENTITY;


ENTITY machining_project
          SUBTYPE OF (product);
  WHERE
  WR1: (0 = SIZEOF (QUERY (pdf <* USEDIN (SELF,
          'INTEGRATED_CNC_SCHEMA.' +
          'PRODUCT_DEFINITION_FORMATION.OF_PRODUCT') | NOT

          -- it has at most one associated owner.
          (1 >= SIZEOF (QUERY (poa <* USEDIN (pdf,
             'INTEGRATED_CNC_SCHEMA.' +
             'APPLIED_PERSON_AND_ORGANIZATION_ASSIGNMENT.ITEMS') |
               (poa.role.name = 'owner'))))
        )));


  WR2: (0 = SIZEOF (QUERY (pdf <* USEDIN (SELF,
          'INTEGRATED_CNC_SCHEMA.' +
          'PRODUCT_DEFINITION_FORMATION.OF_PRODUCT') | NOT

          -- it has at most one associated release date.
          (1 >= SIZEOF (QUERY (dta <* USEDIN (pdf,
             'INTEGRATED_CNC_SCHEMA.' +
             'APPLIED_DATE_AND_TIME_ASSIGNMENT.ITEMS') |
               (dta.role.name = 'release date'))))
        )));


  WR3: (0 = SIZEOF (QUERY (pdf <* USEDIN (SELF,
          'INTEGRATED_CNC_SCHEMA.' +
          'PRODUCT_DEFINITION_FORMATION.OF_PRODUCT') | NOT

          (0 = SIZEOF (QUERY (pd <* USEDIN (pdf,
           'INTEGRATED_CNC_SCHEMA.PRODUCT_DEFINITION.FORMATION') | NOT

          -- it has one associated workplan.
          (1 = SIZEOF (QUERY (ppa <* USEDIN (pd,
             'INTEGRATED_CNC_SCHEMA.' +
             'PROCESS_PRODUCT_ASSOCIATION.DEFINED_PRODUCT') |
             (ppa.process.name = 'machining') AND
             ('INTEGRATED_CNC_SCHEMA.MACHINING_WORKPLAN'
               IN TYPEOF (ppa.process.chosen_method)))))
          )))
        )));
END_ENTITY;


(* ========================================  *)
(* RELATIONSHIP SUBTYPES *)


ENTITY machining_setup_workpiece_relationship
  SUBTYPE OF (product_definition_relationship);
END_ENTITY;

ENTITY machining_project_workpiece_relationship
  SUBTYPE OF (product_definition_relationship);
END_ENTITY;




ENTITY machining_adaptive_control_relationship
  SUBTYPE OF (action_method_relationship);
END_ENTITY;

ENTITY machining_functions_relationship
  SUBTYPE OF (action_method_relationship);
END_ENTITY;

ENTITY machining_operation_relationship
  SUBTYPE OF (action_method_relationship);
END_ENTITY;

ENTITY machining_operator_instruction_relationship
  SUBTYPE OF (sequential_method);
END_ENTITY;

ENTITY machining_process_model_relationship
  SUBTYPE OF (sequential_method);
END_ENTITY;

ENTITY machining_strategy_relationship
  SUBTYPE OF (action_method_relationship);
END_ENTITY;

ENTITY machining_technology_relationship
  SUBTYPE OF (action_method_relationship);
END_ENTITY;

ENTITY machining_toolpath_sequence_relationship
  SUBTYPE OF (sequential_method);
END_ENTITY;



ENTITY machining_feature_relationship
  SUBTYPE OF (action_method_relationship);
END_ENTITY;

ENTITY machining_feature_sequence_relationship
  SUBTYPE OF (machining_feature_relationship, sequential_method);
END_ENTITY;

ENTITY machining_final_feature_relationship
  SUBTYPE OF (action_method_relationship);
END_ENTITY;


ENTITY machining_process_body_relationship
  SUBTYPE OF (action_method_relationship);
END_ENTITY;

ENTITY machining_process_sequence_relationship
  SUBTYPE OF (machining_process_body_relationship, sequential_method);
END_ENTITY;

ENTITY machining_process_concurrent_relationship
  SUBTYPE OF (machining_process_body_relationship, concurrent_action_method);
END_ENTITY;

ENTITY machining_process_branch_relationship
  SUBTYPE OF (machining_process_body_relationship);
END_ENTITY;


(* ========================================  *)
(* OTHER *)

(* Brings in the PLIB Part 20 expressions for use in properties *)
ENTITY expression_representation_item
  SUBTYPE OF (representation_item, generic_expression);
END_ENTITY;


(* ========================================  *)
(* Geometric Dimension and Tolerance *)


(* GDT AIM Definitions.   

   The geometric tolerances are handled by AIC 519, but the AIM
   definitions for dimensional tolerances are not covered by an AIC.
   Many of the definitions come from Part 47, but there are some
   local subtypes.

*)

ENTITY directed_dimensional_location
  SUBTYPE OF (dimensional_location);
END_ENTITY;


ENTITY externally_defined_dimension_definition
     SUBTYPE OF (externally_defined_item, dimensional_size);
WHERE 
 WR1: (SELF\externally_defined_item.item_id = 
        'external size dimension')  AND
      (SELF\externally_defined_item.source.source_id =
        'external size dimension specification');  
     
 WR2: 1 >= SIZEOF(QUERY ( adr <* USEDIN(SELF,
      'INTEGRATED_CNC_SCHEMA.APPLIED_DOCUMENT_REFERENCE.ITEMS')| 
      (adr.assigned_document.description =
      'external size dimension specification')
      )); 
END_ENTITY;


ENTITY placed_datum_target_feature
    SUBTYPE OF (datum_target);
WHERE
 WR1 : (SELF.description IN ['point','line','rectangle','circle']);
 WR2 : (SIZEOF(QUERY ( pd <* USEDIN(SELF,
	'INTEGRATED_CNC_SCHEMA.PROPERTY_DEFINITION.DEFINITION') |
	 (NOT (SIZEOF(QUERY ( pdr <* USEDIN(pd,
 	'INTEGRATED_CNC_SCHEMA.' +
 	'PROPERTY_DEFINITION_REPRESENTATION.DEFINITION') | ((
 	'INTEGRATED_CNC_SCHEMA.' + 
 	'SHAPE_REPRESENTATION_WITH_PARAMETERS') IN TYPEOF(pdr.
 	used_representation)) )) = 1)) )) = 0);
 WR3 : (SIZEOF(QUERY ( pd <* USEDIN(SELF,
	'INTEGRATED_CNC_SCHEMA.PROPERTY_DEFINITION.DEFINITION')
 	| (NOT (SIZEOF(QUERY ( dtm_rep <* QUERY ( pdr <* USEDIN(pd,
 	'INTEGRATED_CNC_SCHEMA.' + 
 	'PROPERTY_DEFINITION_REPRESENTATION.DEFINITION') | ((
 	'INTEGRATED_CNC_SCHEMA.' + 
 	'SHAPE_REPRESENTATION_WITH_PARAMETERS') IN TYPEOF(pdr.
 	used_representation)) ) | (NOT (SIZEOF(QUERY ( it <* 
 	dtm_rep.used_representation.items | ((
 	'INTEGRATED_CNC_SCHEMA.PLACEMENT' IN TYPEOF(it)) 
 	AND (it.name = 'orientation')) )) = 1)) )) = 0)) )) = 0);
 WR4 : ((NOT (SELF.description = 'point')) OR 
	(SIZEOF(QUERY ( pd <* USEDIN(SELF,
	'INTEGRATED_CNC_SCHEMA.PROPERTY_DEFINITION.DEFINITION')
 	| (NOT (SIZEOF(QUERY ( dtm_rep <* QUERY ( pdr <* USEDIN(pd,
 	'INTEGRATED_CNC_SCHEMA.' + 
 	'PROPERTY_DEFINITION_REPRESENTATION.DEFINITION') | ((
 	'INTEGRATED_CNC_SCHEMA.' + 
 	'SHAPE_REPRESENTATION_WITH_PARAMETERS') IN TYPEOF(pdr.
 	used_representation)) ) | (NOT (SIZEOF(dtm_rep.
 	used_representation.items) = 1)) )) = 0)) )) = 0));
 WR5 : ((NOT (SELF.description IN ['line','circle'])) OR
	(SIZEOF(QUERY ( pd <* USEDIN(SELF,
	'INTEGRATED_CNC_SCHEMA.PROPERTY_DEFINITION.DEFINITION')
 	| (NOT (SIZEOF(QUERY ( dtm_rep <* QUERY ( pdr <* USEDIN(pd,
 	'INTEGRATED_CNC_SCHEMA.' + 
 	'PROPERTY_DEFINITION_REPRESENTATION.DEFINITION') | ((
 	'INTEGRATED_CNC_SCHEMA.' + 
 	'SHAPE_REPRESENTATION_WITH_PARAMETERS') IN TYPEOF(pdr.
 	used_representation)) ) | (NOT (SIZEOF(dtm_rep.
 	used_representation.items) = 2)) )) = 0)) )) = 0));
 WR6 : ((NOT (SELF.description = 'rectangle')) OR
	(SIZEOF(QUERY ( pd <* USEDIN(SELF,
	'INTEGRATED_CNC_SCHEMA.PROPERTY_DEFINITION.DEFINITION')
 	| (NOT (SIZEOF(QUERY ( dtm_rep <* QUERY ( pdr <* USEDIN(pd,
 	'INTEGRATED_CNC_SCHEMA.' + 
 	'PROPERTY_DEFINITION_REPRESENTATION.DEFINITION') | ((
 	'INTEGRATED_CNC_SCHEMA.' + 
 	'SHAPE_REPRESENTATION_WITH_PARAMETERS') IN TYPEOF(pdr.
 	used_representation)) ) | (NOT (SIZEOF(dtm_rep.
 	used_representation.items) = 3)) )) = 0)) )) = 0));
 WR7 : ((NOT (SELF.description = 'circle')) OR 
	(SIZEOF(QUERY ( pd <* USEDIN(SELF,
	'INTEGRATED_CNC_SCHEMA.PROPERTY_DEFINITION.DEFINITION')
 	| (NOT (SIZEOF(QUERY ( dtm_rep <* QUERY ( pdr <* USEDIN(pd,
 	'INTEGRATED_CNC_SCHEMA.' + 
 	'PROPERTY_DEFINITION_REPRESENTATION.DEFINITION') | ((
 	'INTEGRATED_CNC_SCHEMA.' + 
 	'SHAPE_REPRESENTATION_WITH_PARAMETERS') IN TYPEOF(pdr.
 	used_representation)) ) | (NOT (SIZEOF(QUERY ( it <* 
 	dtm_rep.used_representation.items | 
	((SIZEOF(['INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
 	'INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT'] 
 	* TYPEOF(it)) = 2) AND (it.name = 'target diameter')) )) = 
 	1)) )) = 0)) )) = 0));
 WR8 : ((NOT (SELF.description = 'line')) OR 
	(SIZEOF(QUERY ( pd <* USEDIN(SELF,
	'INTEGRATED_CNC_SCHEMA.PROPERTY_DEFINITION.DEFINITION')
 	| (NOT (SIZEOF(QUERY ( dtm_rep <* QUERY ( pdr <* USEDIN(pd,
 	'INTEGRATED_CNC_SCHEMA.' + 
 	'PROPERTY_DEFINITION_REPRESENTATION.DEFINITION') | ((
 	'INTEGRATED_CNC_SCHEMA.' + 
 	'SHAPE_REPRESENTATION_WITH_PARAMETERS') IN TYPEOF(pdr.
 	used_representation)) ) | (NOT (SIZEOF(QUERY ( it <* 
 	dtm_rep.used_representation.items | 
	((SIZEOF(['INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
 	'INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT'] 
 	* TYPEOF(it)) = 2) AND (it.name = 'target length')) )) = 1)) )) 
 	= 0)) )) = 0));
 WR9 : ((NOT (SELF.description = 'rectangle')) OR
 	(SIZEOF(QUERY ( pd <* USEDIN(SELF,
	'INTEGRATED_CNC_SCHEMA.PROPERTY_DEFINITION.DEFINITION')
 	| (NOT (SIZEOF(QUERY ( dtm_rep <* QUERY ( pdr <* USEDIN(pd,
 	'INTEGRATED_CNC_SCHEMA.' + 
 	'PROPERTY_DEFINITION_REPRESENTATION.DEFINITION') | ((
 	'INTEGRATED_CNC_SCHEMA.' + 
 	'SHAPE_REPRESENTATION_WITH_PARAMETERS') IN TYPEOF(pdr.
 	used_representation)) ) | (NOT (SIZEOF(QUERY ( it <* 
 	dtm_rep.used_representation.items | 
	((SIZEOF(['INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
 	'INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT'] 
 	* TYPEOF(it)) = 2) AND (it.name = 'target length')) )) = 1)) )) 
 	= 0)) )) = 0));
 WR10: ((NOT (SELF.description = 'rectangle')) OR 
	(SIZEOF(QUERY ( pd <* USEDIN(SELF,
	'INTEGRATED_CNC_SCHEMA.PROPERTY_DEFINITION.DEFINITION')
 	| (NOT (SIZEOF(QUERY ( dtm_rep <* QUERY ( pdr <* USEDIN(pd,
 	'INTEGRATED_CNC_SCHEMA.' + 
 	'PROPERTY_DEFINITION_REPRESENTATION.DEFINITION') | ((
 	'INTEGRATED_CNC_SCHEMA.' + 
 	'SHAPE_REPRESENTATION_WITH_PARAMETERS') IN TYPEOF(pdr.
 	used_representation)) ) | (NOT (SIZEOF(QUERY ( it <* 
 	dtm_rep.used_representation.items | 
	((SIZEOF(['INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
 	'INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT'] 
 	* TYPEOF(it)) = 2) AND (it.name = 'target width')) )) = 1)) )) 
 	= 0)) )) = 0));
END_ENTITY; -- placed_datum_target_feature

(* ========================================  *)
(* Overlapping AP Definitions brought in for harmonization *)


-- Definitions from other APs that do not appear in any AICs, but 
-- are needed for harmonization 

-- Extra AP-224 definitions for workpiece base shape and catalog
-- threads

ENTITY block_shape_representation
  SUBTYPE OF (shape_representation_with_parameters);
  WHERE
    WR1: (SIZEOF(SELF.items) = 4);
    WR2: (SIZEOF(QUERY ( it <* SELF.items | 
	 (('INTEGRATED_CNC_SCHEMA.PLACEMENT' 
	 IN TYPEOF(it)) AND (it.name = 'orientation')) )) = 1);
    WR3: (SIZEOF(QUERY ( it <* SELF.items | 
	 ((SIZEOF(
	 ['INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
	 'INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT'] *
	  TYPEOF(it)) = 2) AND (it.name = 'length')) )) = 1);
    WR4: (SIZEOF(QUERY ( it <* SELF.items | 
	 ((SIZEOF([
	 'INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
	 'INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT'] *
	 TYPEOF(it)) = 2) AND (it.name = 'width')) )) = 1);
    WR5: (SIZEOF(QUERY ( it <* SELF.items | 
	 ((SIZEOF([
	 'INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
	 'INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT'] *
	 TYPEOF(it)) = 2) AND (it.name = 'height')) )) = 1);
END_ENTITY; -- block_shape_representation


ENTITY cylindrical_shape_representation
  SUBTYPE OF (shape_representation_with_parameters);
  WHERE
    WR1: (SIZEOF(SELF.items) = 3);
    WR2: (SIZEOF(QUERY ( it <* SELF.items | ((
	 'INTEGRATED_CNC_SCHEMA.PLACEMENT' 
	 IN TYPEOF(it)) AND (it.name = 'orientation')) )) = 1);
    WR3: (SIZEOF(QUERY ( it <* SELF.items | ((SIZEOF([
	 'INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
	 'INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT'] *
	  TYPEOF(it)) = 2) AND (it.name = 'length')) )) = 1);
    WR4: (SIZEOF(QUERY ( it <* SELF.items | ((SIZEOF([
	 'INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
	 'INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT'] *
	  TYPEOF(it)) = 2) AND (it.name = 'diameter')) )) = 1);
END_ENTITY; -- cylindrical_shape_representation

ENTITY ngon_shape_representation
  SUBTYPE OF (shape_representation_with_parameters);
  WHERE
    WR1: (SIZEOF(SELF.items) = 5);
    WR2: (SIZEOF(QUERY ( it <* SELF.items | 
	 (('INTEGRATED_CNC_SCHEMA.PLACEMENT' 
	 IN TYPEOF(it)) AND (it.name = 'orientation')) )) = 1);
    WR3: (SIZEOF(QUERY ( it <* SELF.items | 
	 ((SIZEOF([
	 'INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
	 'INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT'] *
	 TYPEOF(it)) = 2) AND (it.name = 'length')) )) = 1);
    WR4: (SIZEOF(QUERY ( it <* SELF.items | 
	 ((SIZEOF([
	 'INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
	 'INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT'] *
	 TYPEOF(it)) = 2) AND (it.name = 'corner radius')) )) = 1);
    WR5: SIZEOF (QUERY (it <* SELF.items |
	 (SIZEOF 
	 (['INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
	 'INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT'] *	
	 TYPEOF (it)) = 2) AND
       (it.name IN ['circumscribed diameter','diameter across flats']) ))= 1;

    WR6: (SIZEOF(QUERY ( it <* SELF.items |
	 (('INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM' 
	 IN TYPEOF(it)) AND 
	 ('INTEGRATED_CNC_SCHEMA.COUNT_MEASURE' 
	 IN TYPEOF(it\measure_with_unit.value_component)) AND 
	 (it.name = 'number of sides')) )) = 1);
END_ENTITY; -- ngon_shape_representation


ENTITY document_file
  SUBTYPE OF (characterized_object, document);
  WHERE
    WR1: (SIZEOF(QUERY(adr<* QUERY(dr <* USEDIN(SELF,
	 'INTEGRATED_CNC_SCHEMA.DOCUMENT_REFERENCE.ASSIGNED_DOCUMENT') |
	 'INTEGRATED_CNC_SCHEMA.APPLIED_DOCUMENT_REFERENCE'
	 IN TYPEOF(dr))|
	'INTEGRATED_CNC_SCHEMA.EXTERNALLY_DEFINED_FEATURE_DEFINITION'
	 IN TYPEOF(adr.items)
	 ))=1) OR 
	 (SIZEOF(QUERY (duc <* USEDIN(SELF,
	 'INTEGRATED_CNC_SCHEMA.DOCUMENT_USAGE_CONSTRAINT.SOURCE') |
	 NOT 
	 (SIZEOF(QUERY(aduc<* QUERY(duca <* USEDIN(duc,
	 'INTEGRATED_CNC_SCHEMA.DOCUMENT_USAGE_CONSTRAINT_ASSIGNMENT.'+
	 'ASSIGNED_DOCUMENT_USAGE') |
	 'INTEGRATED_CNC_SCHEMA.'+
	 'APPLIED_DOCUMENT_USAGE_CONSTRAINT_ASSIGNMENT'
	 IN TYPEOF(duca))|
	'INTEGRATED_CNC_SCHEMA.EXTERNALLY_DEFINED_FEATURE_DEFINITION'
	 IN TYPEOF(aduc.items)
	 ))=1))) = 0);

    WR2: (SIZEOF(QUERY(drt <* USEDIN(SELF,
	 'INTEGRATED_CNC_SCHEMA.'+
	 'DOCUMENT_REPRESENTATION_TYPE.REPRESENTED_DOCUMENT') |
	 (drt.name='physical')))=1);
END_ENTITY; -- document_file




(* ========================================  *)
(* Value range and surface texture things from AP 214 *)

ENTITY value_range
  SUBTYPE OF (compound_representation_item);
END_ENTITY;  -- 10303-214: automotive_design

ENTITY surface_texture_representation
  SUBTYPE OF (representation);
END_ENTITY;  -- 10303-214: automotive_design


(* ========================================  *)
(* FUNCTIONS *)


FUNCTION get_action_property (
    cad :       characterized_action_definition;
    prop_name : STRING
    ): SET OF action_property;

    RETURN (bag_to_set (QUERY (ap <*
        USEDIN (cad, 'INTEGRATED_CNC_SCHEMA.ACTION_PROPERTY.DEFINITION') |
        (ap.name = prop_name))));
END_FUNCTION;


FUNCTION get_resource_property (
    crd :       characterized_resource_definition;
    prop_name : STRING
    ): SET OF resource_property;

    RETURN (bag_to_set (QUERY (rp <*
        USEDIN (crd, 'INTEGRATED_CNC_SCHEMA.RESOURCE_PROPERTY.RESOURCE') |
        (rp.name = prop_name))));
END_FUNCTION;

FUNCTION get_relating_amr (
    am : action_method
    ) : SET OF action_method_relationship;

    RETURN (bag_to_set (USEDIN (am,
       'INTEGRATED_CNC_SCHEMA.ACTION_METHOD_RELATIONSHIP.RELATING_METHOD')));
END_FUNCTION;

FUNCTION get_count_of_relating_amr (
    am :        action_method;
    amr_types : SET OF STRING
    ): INTEGER;

    RETURN (SIZEOF (QUERY (amr <* get_relating_amr (am) | 
               (SIZEOF(amr_types * TYPEOF(amr)) = 
                SIZEOF(amr_types)) )));
END_FUNCTION;

FUNCTION get_count_of_relating_amr_with_name (
    am :        action_method;
    amr_name :  STRING;
    amr_types : SET OF STRING
    ): INTEGER;

    RETURN (SIZEOF (QUERY (amr <* get_relating_amr (am) | 
              ((amr.name = amr_name) AND
               (SIZEOF(amr_types * TYPEOF(amr)) = 
                SIZEOF(amr_types))) )));
END_FUNCTION;

FUNCTION verify_optional_relating_amr (
    am :        action_method;
    amr_types : SET OF STRING
    ): LOGICAL;

    RETURN (1 >= get_count_of_relating_amr (am, amr_types));
END_FUNCTION;

FUNCTION verify_optional_relating_amr_with_name (
    am :        action_method;
    amr_name :  STRING;
    amr_types : SET OF STRING
    ): LOGICAL;

    RETURN (1 >= get_count_of_relating_amr_with_name (
                am, amr_name, amr_types));
END_FUNCTION;

FUNCTION verify_required_relating_amr (
    am : 	action_method;
    amr_types : SET OF STRING
    ): LOGICAL;

    RETURN (1 = get_count_of_relating_amr (am, amr_types));
END_FUNCTION;

FUNCTION verify_required_relating_amr_with_name (
    am :        action_method;
    amr_name :  STRING;
    amr_types : SET OF STRING
    ): LOGICAL;

    RETURN (1 = get_count_of_relating_amr_with_name (
                am, amr_name, amr_types));
END_FUNCTION;

FUNCTION verify_related_type_for_amr (
    am :        action_method;
    amr_types : SET OF STRING;
    types :     SET OF STRING
    ): LOGICAL;

    RETURN  (0 = SIZEOF (QUERY (amr <* get_relating_amr (am) |
               (SIZEOF(amr_types * TYPEOF(amr)) = 
                SIZEOF(amr_types)) AND 
                NOT
               (SIZEOF(types * TYPEOF(amr.related_method)) = 
                SIZEOF(types)) )));
END_FUNCTION;

FUNCTION verify_related_type_for_amr_with_name (
    am :        action_method;
    amr_name :  STRING;
    amr_types : SET OF STRING;
    types :     SET OF STRING
    ): LOGICAL;

    RETURN  (0 = SIZEOF (QUERY (amr <* get_relating_amr (am) |
               (amr.name = amr_name) AND 
               (SIZEOF(amr_types * TYPEOF(amr)) = 
                SIZEOF(amr_types)) AND 
                NOT
               (SIZEOF(types * TYPEOF(amr.related_method)) = 
                SIZEOF(types)) )));
END_FUNCTION;

FUNCTION verify_optional_action_property (
    cad :   	characterized_action_definition;
    prop_name : STRING
    ): LOGICAL;

    RETURN (1 >= SIZEOF (get_action_property (cad, prop_name)));
END_FUNCTION;

FUNCTION verify_optional_rep_item (
    rep : 	representation;
    prop_name : STRING
    ): LOGICAL;

    RETURN (1 >= SIZEOF (QUERY ( it <* rep.items | 
            (it.name = prop_name))));
END_FUNCTION;

FUNCTION verify_optional_resource_property (
    crd : 	characterized_resource_definition;
    prop_name : STRING
    ): LOGICAL;

    RETURN (1 >= SIZEOF (get_resource_property (crd, prop_name)));
END_FUNCTION;

FUNCTION verify_required_action_property (
    cad :	characterized_action_definition;
    prop_name : STRING
    ): LOGICAL;

    RETURN (1 = SIZEOF (get_action_property (cad, prop_name)));
END_FUNCTION;

FUNCTION verify_required_rep_item (
    rep :	representation;
    prop_name : STRING
    ): LOGICAL;

    RETURN (1 = SIZEOF (QUERY ( it <* rep.items | 
            (it.name = prop_name))));
END_FUNCTION;

FUNCTION verify_required_resource_property (
    crd : 	characterized_resource_definition;
    prop_name : STRING
    ): LOGICAL;

    RETURN (1 = SIZEOF (get_resource_property (crd, prop_name)));
END_FUNCTION;

FUNCTION verify_rep_desc_for_action_property (
    cad : 	 characterized_action_definition;
    prop_name :  STRING;
    desc_names : SET OF STRING
    ): LOGICAL;

    RETURN (0 = SIZEOF (QUERY (prop <* 
            get_action_property (cad, prop_name) | NOT 
            (0 < SIZEOF (QUERY (prep <* USEDIN (prop, 'INTEGRATED_CNC_SCHEMA.'+
               'ACTION_PROPERTY_REPRESENTATION.PROPERTY') |
               (prep.representation.description IN desc_names)
                )))
        )));
END_FUNCTION;


FUNCTION verify_rep_item_for_action_property (
    cad : 	     characterized_action_definition;
    prop_name :      STRING;
    rep_item_types : SET OF STRING
    ): LOGICAL;

    -- All properties have matching representations.  The reason we test
    -- for "nothing matching the negation" rather than "something matching
    -- the positive" is so that we return true if there are no properties.
    --
    RETURN (0 = SIZEOF (QUERY (prop <* get_action_property (cad, prop_name) |

        -- property has no matching representations
        NOT (

        -- there is at least one rep with matching rep items
        (0 < SIZEOF (QUERY (prep <* USEDIN (prop, 'INTEGRATED_CNC_SCHEMA.' +
                'ACTION_PROPERTY_REPRESENTATION.PROPERTY') |

           -- property representation has at least one matching rep item
           (0 < SIZEOF (QUERY (it <* prep.representation.items |
               (SIZEOF (rep_item_types * TYPEOF(it)) = 
                SIZEOF (rep_item_types))))
           )))
        ))
    )));
END_FUNCTION;

FUNCTION verify_rep_item_for_resource_property (
    crd :            characterized_resource_definition;
    prop_name :      STRING;
    rep_item_types : SET OF STRING
    ): LOGICAL;

    RETURN (0 = SIZEOF (QUERY (prop <* get_resource_property (crd, prop_name) |
        NOT (0 < SIZEOF (QUERY (prep <* USEDIN (prop, 'INTEGRATED_CNC_SCHEMA.' +
                'RESOURCE_PROPERTY_REPRESENTATION.PROPERTY') |

           (0 < SIZEOF (QUERY (it <* prep.representation.items |
               (SIZEOF (rep_item_types * TYPEOF(it)) = 
                SIZEOF (rep_item_types)))))
           )))
        )));
END_FUNCTION;


FUNCTION verify_rep_type_for_action_property (
    cad : 	characterized_action_definition;
    prop_name : STRING;
    rep_types : SET OF STRING
    ): LOGICAL;

    RETURN (0 = SIZEOF (QUERY (prop <* 
            get_action_property (cad, prop_name) | NOT 
            (0 < SIZEOF (QUERY (prep <* USEDIN (prop, 'INTEGRATED_CNC_SCHEMA.'+
               'ACTION_PROPERTY_REPRESENTATION.PROPERTY') |

               (SIZEOF(rep_types * TYPEOF(prep.representation)) = 
                SIZEOF(rep_types))
                )))
        )));
END_FUNCTION;


FUNCTION verify_rep_type_for_resource_property (
    crd : 	characterized_resource_definition;
    prop_name : STRING;
    rep_types : SET OF STRING
    ): LOGICAL;

    RETURN (0 = SIZEOF (QUERY (prop <* 
            get_resource_property (crd, prop_name) | NOT 
            (0 < SIZEOF (QUERY (prep <* USEDIN (prop, 'INTEGRATED_CNC_SCHEMA.'+
               'RESOURCE_PROPERTY_REPRESENTATION.PROPERTY') |

               (SIZEOF(rep_types * TYPEOF(prep.representation)) = 
                SIZEOF(rep_types))
                )))
        )));
END_FUNCTION;



(* ======================================== *)
(* VERIFY REPRESENTATION ITEM TYPES AND VALUES *)

FUNCTION verify_angle_measure_action_property (
    cad : 	characterized_action_definition;
    prop_name : STRING
    ): LOGICAL;

    RETURN (verify_rep_item_for_action_property(cad, prop_name,
        ['INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
         'INTEGRATED_CNC_SCHEMA.PLANE_ANGLE_MEASURE_WITH_UNIT']));
END_FUNCTION;

FUNCTION verify_angle_measure_rep_item (
    rep : 	representation;
    prop_name : STRING
    ): LOGICAL;

    RETURN (0 = SIZEOF (QUERY ( it <* rep.items |
          (it.name = prop_name) AND NOT (SIZEOF([
           'INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
           'INTEGRATED_CNC_SCHEMA.PLANE_ANGLE_MEASURE_WITH_UNIT'] *
            TYPEOF(it)) = 2))));
END_FUNCTION;

FUNCTION verify_count_measure_rep_item (
    rep : 	representation;
    prop_name : STRING
    ): LOGICAL;

    RETURN (0 = SIZEOF (QUERY ( it <* rep.items |
          (it.name = prop_name) AND NOT
          (('INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM' 
            IN TYPEOF(it)) AND
           ('INTEGRATED_CNC_SCHEMA.COUNT_MEASURE' 
            IN TYPEOF(it.value_component))))));
END_FUNCTION;

FUNCTION verify_descriptive_action_property (
    cad : 	characterized_action_definition;
    prop_name : STRING
    ): LOGICAL;

    RETURN (verify_rep_item_for_action_property(cad, prop_name,
        ['INTEGRATED_CNC_SCHEMA.DESCRIPTIVE_REPRESENTATION_ITEM']));
END_FUNCTION;


FUNCTION verify_descriptive_rep_item (
    rep : 	representation;
    prop_name : STRING
    ): LOGICAL;

    RETURN (0 = SIZEOF (QUERY ( it <* rep.items |
          (it.name = prop_name) AND NOT (
           'INTEGRATED_CNC_SCHEMA.DESCRIPTIVE_REPRESENTATION_ITEM'
            IN TYPEOF(it)))));
END_FUNCTION;


FUNCTION verify_enumeration_action_property (
    cad : 	  characterized_action_definition;
    prop_name :   STRING;
    prop_values : SET OF STRING
    ): LOGICAL;

    -- Each action property has at least one representation that contains
    -- a descriptive rep item, and that descriptive rep item has a value
    -- drawn from the prop_values set.

    -- there are no properties that do not have matching representations
    RETURN (0 = SIZEOF (QUERY (prop <* get_action_property (cad, prop_name) |

        NOT (
        -- there is at least one rep with matching rep items
        (0 < SIZEOF (QUERY (prep <* USEDIN (prop, 'INTEGRATED_CNC_SCHEMA.' +
                'ACTION_PROPERTY_REPRESENTATION.PROPERTY') |

           -- property representation has at least one matching rep item
           (0 < SIZEOF (QUERY (it <* prep.representation.items |
               (('INTEGRATED_CNC_SCHEMA.DESCRIPTIVE_REPRESENTATION_ITEM' 
                  IN TYPEOF(it)) AND
                (it.description IN prop_values))
           )))
        )))
    ))));
END_FUNCTION;

FUNCTION verify_enumeration_rep_item (
    rep : 	  representation;
    prop_name :   STRING;
    prop_values : SET OF STRING
    ): LOGICAL;

    RETURN (0 = SIZEOF (QUERY ( it <* rep.items |
          (it.name = prop_name) AND NOT
          (('INTEGRATED_CNC_SCHEMA.DESCRIPTIVE_REPRESENTATION_ITEM' 
            IN TYPEOF(it)) AND
           (it.description IN prop_values)))));
END_FUNCTION;

FUNCTION verify_length_measure_action_property (
    cad : 	characterized_action_definition;
    prop_name : STRING
    ): LOGICAL;

    RETURN (verify_rep_item_for_action_property (cad, prop_name,
        ['INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
         'INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT']));
END_FUNCTION;

FUNCTION verify_length_measure_rep_item (
    rep : 	representation;
    prop_name : STRING
    ): LOGICAL;

    RETURN (0 = SIZEOF (QUERY ( it <* rep.items |
          (it.name = prop_name) AND NOT (SIZEOF([
           'INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
           'INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT'] *
            TYPEOF(it)) = 2))));
END_FUNCTION;

FUNCTION verify_length_measure_resource_property (
    crd : 	characterized_resource_definition;
    prop_name : STRING
    ): LOGICAL;

    RETURN (verify_rep_item_for_resource_property (crd, prop_name,
        ['INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
         'INTEGRATED_CNC_SCHEMA.LENGTH_MEASURE_WITH_UNIT']));
END_FUNCTION;

FUNCTION verify_linear_speed_measure_rep_item (
    rep : 	representation;
    prop_name : STRING
    ): LOGICAL;

    RETURN (0 = SIZEOF (QUERY ( it <* rep.items |
          (it.name = prop_name) AND NOT
          (('INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM' 
            IN TYPEOF(it)) AND
           ('INTEGRATED_CNC_SCHEMA.NUMERIC_MEASURE' 
            IN TYPEOF(it.value_component))))));
END_FUNCTION;

FUNCTION verify_numeric_measure_action_property (
    cad : 	characterized_action_definition;
    prop_name : STRING
    ): LOGICAL;

    -- All properties have matching representations.  The reason we test
    -- for "nothing matching the negation" rather than "something matching
    -- the positive" is so that we return true if there are no properties.
    --
    RETURN (0 = SIZEOF (QUERY (prop <* get_action_property (cad, prop_name) |

        -- property has no matching representations
        NOT (

        -- there is at least one rep with matching rep items
        (0 < SIZEOF (QUERY (prep <* USEDIN (prop, 'INTEGRATED_CNC_SCHEMA.' +
                'ACTION_PROPERTY_REPRESENTATION.PROPERTY') |

           -- property representation has at least one matching rep item
           (0 < SIZEOF (QUERY (it <* prep.representation.items |
               (('INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM' 
                  IN TYPEOF(it)) AND
                ('INTEGRATED_CNC_SCHEMA.NUMERIC_MEASURE' 
                  IN TYPEOF(it.value_component)))
           )))
        )))
    ))));
END_FUNCTION;

FUNCTION verify_parameter_action_property (
    cad : 	characterized_action_definition;
    prop_name : STRING
    ): LOGICAL;

    -- All properties have matching representations.  The reason we test
    -- for "nothing matching the negation" rather than "something matching
    -- the positive" is so that we return true if there are no properties.
    --
    RETURN (0 = SIZEOF (QUERY (prop <* get_action_property (cad, prop_name) |

        -- property has no matching representations
        NOT (

        -- there is at least one rep with matching rep items
        (0 < SIZEOF (QUERY (prep <* USEDIN (prop, 'INTEGRATED_CNC_SCHEMA.' +
                'ACTION_PROPERTY_REPRESENTATION.PROPERTY') |

           -- property representation has at least one matching rep item
           (0 < SIZEOF (QUERY (it <* prep.representation.items |
               (('INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM' 
                  IN TYPEOF(it)) AND
                ('INTEGRATED_CNC_SCHEMA.PARAMETER_VALUE' 
                  IN TYPEOF(it.value_component)))
           )))
        )))
    ))));
END_FUNCTION;

FUNCTION verify_pressure_measure_action_property (
    cad : 	characterized_action_definition;
    prop_name : STRING
    ): LOGICAL;

    RETURN (verify_numeric_measure_action_property (cad, prop_name));
END_FUNCTION;

FUNCTION verify_ratio_measure_action_property (
    cad : 	characterized_action_definition;
    prop_name : STRING
    ): LOGICAL;

    RETURN (verify_rep_item_for_action_property (cad, prop_name,
        ['INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
         'INTEGRATED_CNC_SCHEMA.RATIO_MEASURE_WITH_UNIT']));
END_FUNCTION;

FUNCTION verify_ratio_measure_rep_item (
    rep : 	representation;
    prop_name : STRING
    ): LOGICAL;

    RETURN (0 = SIZEOF (QUERY ( it <* rep.items |
          (it.name = prop_name) AND NOT (SIZEOF([
           'INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
           'INTEGRATED_CNC_SCHEMA.RATIO_MEASURE_WITH_UNIT'] *
            TYPEOF(it)) = 2))));
END_FUNCTION;

FUNCTION verify_rotary_speed_measure_rep_item (
    rep : 	representation;
    prop_name : STRING
    ): LOGICAL;

    RETURN (0 = SIZEOF (QUERY ( it <* rep.items |
          (it.name = prop_name) AND NOT
          (('INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM' 
            IN TYPEOF(it)) AND
           ('INTEGRATED_CNC_SCHEMA.NUMERIC_MEASURE' 
            IN TYPEOF(it.value_component))))));
END_FUNCTION;

FUNCTION verify_time_measure_action_property (
    cad : 	characterized_action_definition;
    prop_name : STRING
    ): LOGICAL;

    RETURN (verify_rep_item_for_action_property(cad, prop_name,
        ['INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
         'INTEGRATED_CNC_SCHEMA.TIME_MEASURE_WITH_UNIT']));
END_FUNCTION;

FUNCTION verify_time_measure_rep_item (
    rep : 	representation;
    prop_name : STRING
    ): LOGICAL;

    RETURN (0 = SIZEOF (QUERY ( it <* rep.items |
          (it.name = prop_name) AND NOT (SIZEOF([
           'INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
           'INTEGRATED_CNC_SCHEMA.TIME_MEASURE_WITH_UNIT'] *
            TYPEOF(it)) = 2))));
END_FUNCTION;

FUNCTION verify_time_measure_resource_property (
    crd : 	characterized_resource_definition;
    prop_name : STRING
    ): LOGICAL;

    RETURN (verify_rep_item_for_resource_property (crd, prop_name,
        ['INTEGRATED_CNC_SCHEMA.MEASURE_REPRESENTATION_ITEM',
         'INTEGRATED_CNC_SCHEMA.TIME_MEASURE_WITH_UNIT']));
END_FUNCTION;


--- MORE COMPLEX CONSTRAINTS
--- MORE COMPLEX CONSTRAINTS
--- MORE COMPLEX CONSTRAINTS
--- MORE COMPLEX CONSTRAINTS

FUNCTION verify_ball_endmill_edge_dimensions (
    rep : machining_tool_dimension_representation
    ): LOGICAL;

    LOCAL
      diameter : length_measure;
      dia_items : SET OF REPRESENTATION_ITEM := 
        QUERY (it <* rep.items | (it.name = 'diameter'));
    END_LOCAL;

    diameter := dia_items[1].value_component;

    RETURN
         ((0 = SIZEOF (QUERY ( it <* rep.items |
           (it.name = 'edge center horizontal') AND NOT 
           (it.value_component = 0))))
          AND
          (0 = SIZEOF (QUERY ( it <* rep.items |
           (it.name = 'edge center vertical') AND NOT 
           (it.value_component = diameter/2))))
          AND
          (0 = SIZEOF (QUERY ( it <* rep.items |
           (it.name = 'edge radius') AND NOT 
           (it.value_component = diameter/2))))
          );
END_FUNCTION;

FUNCTION verify_optional_in_process_geometry (
    mpe : machining_process_executable
    ): LOGICAL;

    RETURN 
      ((verify_optional_action_property (mpe, 'as-is shape')) AND
       (verify_optional_action_property (mpe, 'to-be shape')) AND
       (verify_optional_action_property (mpe, 'removal shape')) AND

        -- All properties need advanced brep shape reps
       (0 = SIZEOF (QUERY (prop <* 
         USEDIN (mpe, 'INTEGRATED_CNC_SCHEMA.ACTION_PROPERTY.DEFINITION') |
         ((prop.name IN ['as-is shape', 'to-be shape', 'removal shape']) AND 
          (0 = SIZEOF (QUERY (prep <* USEDIN (prop, 'INTEGRATED_CNC_SCHEMA.' +
             'ACTION_PROPERTY_REPRESENTATION.PROPERTY') |
             ('INTEGRATED_CNC_SCHEMA.ADVANCED_BREP_SHAPE_REPRESENTATION' 
               IN TYPEOF (prep.representation))))))
          )))
      );
END_FUNCTION;


(* ========================================  *)
(* GLOBAL RULES *)


RULE application_context_requires_ap_definition FOR 
  (application_context,
   application_protocol_definition);
WHERE
  WR1:  (0 = SIZEOF (QUERY (ac <* application_context | NOT
           (1 = SIZEOF (QUERY (apd <* application_protocol_definition | 
                (apd.application :=: ac) AND
                (apd.application_interpreted_model_schema_name =   
                 'integrated_cnc_schema'))))
        )));
END_RULE;

RULE approval_requires_approval_person_organization FOR 
  (approval,
   approval_person_organization);
WHERE
  WR1:  (0 = SIZEOF (QUERY (app <* approval | NOT
           (1 <= SIZEOF (QUERY (apo <* approval_person_organization |
               (app :=: apo.authorized_approval))))
        )));
END_RULE;


RULE approval_requires_assignment FOR
  (approval,
   approval_assignment);
WHERE
  WR1:  (0 = SIZEOF (QUERY (app <* approval | NOT
           (1 <= SIZEOF (QUERY (aa <* approval_assignment |
               (app :=: aa.assigned_approval))))
        )));
END_RULE; 

RULE chamfer_requires_faces_or_features FOR
  (chamfer, 
   property_definition_representation,
   feature_component_relationship);
WHERE
  WR1:  (0 = SIZEOF (QUERY (cf <* chamfer | NOT (

  -- chamfer relates two sets of faces in AP-224 style
  ((1 = SIZEOF (QUERY (pdr <* property_definition_representation |
        ((pdr.used_representation.name = 'chamfer face') AND
         (pdr.definition.definition :=: cf) AND
         ('INTEGRATED_CNC_SCHEMA.FACE_SHAPE_REPRESENTATION' 
           IN TYPEOF (pdr.used_representation)))))) AND

   (1 = SIZEOF (QUERY (fcr <* feature_component_relationship |
        ((fcr.relating_shape_aspect :=: cf) AND
         (fcr.related_shape_aspect.description = 'first offset') AND
         ('INTEGRATED_CNC_SCHEMA.CHAMFER_OFFSET' 
           IN TYPEOF (fcr.related_shape_aspect)) AND
         ((1 = SIZEOF (QUERY (pdr <* property_definition_representation |
               ((pdr.used_representation.name = 'first face shape') AND
                (pdr.definition.definition :=: fcr.related_shape_aspect) AND
                ('INTEGRATED_CNC_SCHEMA.FACE_SHAPE_REPRESENTATION' 
                  IN TYPEOF (pdr.used_representation)))
         )))) )))) AND

   (1 = SIZEOF (QUERY (fcr <* feature_component_relationship |
        ((fcr.relating_shape_aspect :=: cf) AND
         (fcr.related_shape_aspect.description = 'second offset') AND
         ('INTEGRATED_CNC_SCHEMA.CHAMFER_OFFSET' 
           IN TYPEOF (fcr.related_shape_aspect)) AND
         ((1 = SIZEOF (QUERY (pdr <* property_definition_representation |
               ((pdr.used_representation.name = 'second face shape') AND
                (pdr.definition.definition :=: fcr.related_shape_aspect) AND
                ('INTEGRATED_CNC_SCHEMA.FACE_SHAPE_REPRESENTATION' 
                  IN TYPEOF (pdr.used_representation)))
         )))) ))))
  )
  OR
  -- chamfer relates two features in ISO 14649 style
  ((1 = SIZEOF (QUERY (fcr <* feature_component_relationship |
        ((fcr.name = 'first feature') AND
         (fcr.relating_shape_aspect.of_shape.definition :=: cf) AND
         ('INTEGRATED_CNC_SCHEMA.COMPOSITE_SHAPE_ASPECT' 
           IN TYPEOF (fcr.relating_shape_aspect))))))  AND

   (1 = SIZEOF (QUERY (fcr <* feature_component_relationship |
        ((fcr.name = 'second feature') AND
         (fcr.relating_shape_aspect.of_shape.definition :=: cf) AND
         ('INTEGRATED_CNC_SCHEMA.COMPOSITE_SHAPE_ASPECT' 
           IN TYPEOF (fcr.relating_shape_aspect)))))))
   ))));
END_RULE;

RULE dependent_instantiable_approval_status FOR
  (approval_status);
WHERE
  WR1:  (0 = SIZEOF (QUERY (ast <* approval_status | NOT
           (1 <= SIZEOF (USEDIN (ast, '')))
        )));
END_RULE;


RULE dependent_instantiable_named_unit FOR
  (named_unit);
WHERE
  WR1:  (0 = SIZEOF (QUERY (nu <* named_unit | NOT
           (1 <= SIZEOF (USEDIN (nu, '')))
        )));
END_RULE;

RULE edge_round_requires_faces_or_features FOR
  (edge_round, 
   property_definition_representation,
   feature_component_relationship);
WHERE
  WR1:  (0 = SIZEOF (QUERY (er <* edge_round | NOT (

  -- edge round relates two sets of faces in AP-224 style
  ((1 = SIZEOF (QUERY (pdr <* property_definition_representation |
        ((pdr.used_representation.name = 'edge round face') AND
         (pdr.definition.definition :=: er) AND
         ('INTEGRATED_CNC_SCHEMA.FACE_SHAPE_REPRESENTATION' 
           IN TYPEOF (pdr.used_representation)))))) AND

   (1 = SIZEOF (QUERY (pdr <* property_definition_representation |
        ((pdr.used_representation.name = 'first face shape') AND
         (pdr.definition.definition :=: er) AND
         ('INTEGRATED_CNC_SCHEMA.FACE_SHAPE_REPRESENTATION' 
           IN TYPEOF (pdr.used_representation)))))) AND

   (1 = SIZEOF (QUERY (pdr <* property_definition_representation |
        ((pdr.used_representation.name = 'second face shape') AND
         (pdr.definition.definition :=: er) AND
         ('INTEGRATED_CNC_SCHEMA.FACE_SHAPE_REPRESENTATION' 
           IN TYPEOF (pdr.used_representation))))))
  )
  OR
  -- edge round relates two features in ISO 14649 style
  ((1 = SIZEOF (QUERY (fcr <* feature_component_relationship |
        ((fcr.name = 'first feature') AND
         (fcr.relating_shape_aspect.of_shape.definition :=: er) AND
         ('INTEGRATED_CNC_SCHEMA.COMPOSITE_SHAPE_ASPECT' 
           IN TYPEOF (fcr.relating_shape_aspect))))))  AND

   (1 = SIZEOF (QUERY (fcr <* feature_component_relationship |
        ((fcr.name = 'second feature') AND
         (fcr.relating_shape_aspect.of_shape.definition :=: er) AND
         ('INTEGRATED_CNC_SCHEMA.COMPOSITE_SHAPE_ASPECT' 
           IN TYPEOF (fcr.relating_shape_aspect)))))))
   ))));
END_RULE;


RULE feature_optional_machining_property_process FOR
  (shape_aspect, 
   process_property_association);
WHERE
  WR1:  (0 = SIZEOF (QUERY (sa <* shape_aspect | 
        (('INTEGRATED_CNC_SCHEMA.FEATURE_DEFINITION' IN TYPEOF (sa)) OR
         ('INTEGRATED_CNC_SCHEMA.TRANSITION_FEATURE' IN TYPEOF (sa)))
         AND NOT
         (1 >= SIZEOF (QUERY (ppa <* process_property_association |
            ((ppa.property_or_shape :=: sa) AND
             (ppa.process.name = 'machining')))))
        )));
END_RULE;


RULE nc_variable_compatible_initial_value FOR
  (expression_representation_item,
   representation_item_relationship);
WHERE
  -- each nc_variable has at most one one initial value
  WR1: (0 = SIZEOF (QUERY (nv <* expression_representation_item | 
            ('INTEGRATED_CNC_SCHEMA.NUMERIC_VARIABLE'
	      IN TYPEOF (nv)) AND NOT
            (1 >= SIZEOF (QUERY (rir <* representation_item_relationship |
                   (rir.description = 'initial value')  AND
                   (rir.relating_representation_item :=: nv)
	))))));

  -- the types on either side of the initial value relationship must match
  -- each nc_variable has at most one one initial value
  WR2: (0 = SIZEOF (QUERY (rir <* representation_item_relationship |
            (rir.description = 'initial value')  AND 
            ('INTEGRATED_CNC_SCHEMA.NUMERIC_VARIABLE'
              IN TYPEOF (rir.relating_representation_item)) 
	    AND NOT
            ((('INTEGRATED_CNC_SCHEMA.INT_NUMERIC_VARIABLE' 
                IN TYPEOF (rir.relating_representation_item)) AND
              ('INTEGRATED_CNC_SCHEMA.INT_LITERAL' 
                IN TYPEOF (rir.related_representation_item)))
             OR
            ((('INTEGRATED_CNC_SCHEMA.REAL_NUMERIC_VARIABLE' 
                IN TYPEOF (rir.relating_representation_item)) AND
              ('INTEGRATED_CNC_SCHEMA.REAL_LITERAL' 
                IN TYPEOF (rir.related_representation_item)
	)))))));
END_RULE;

RULE product_requires_version FOR 
  (product,
   product_definition_formation);
WHERE
  WR1:  (0 = SIZEOF (QUERY (prod <* product  | NOT
           (1 <= SIZEOF (QUERY (pdf <* product_definition_formation |
               (prod :=: pdf.of_product))))
        )));
END_RULE;


(* Extra features are present for compatibility with AP-224, but are
   restricted until ISO 14649-10 or some other part requires them.
 *)
RULE restrict_unneeded_feature_usage FOR (feature_definition);
  WHERE
  WR1:  (0 = SIZEOF (QUERY (fd <* feature_definition |
         ('INTEGRATED_CNC_SCHEMA.FILLET' IN TYPEOF(fd)) OR 
         ('INTEGRATED_CNC_SCHEMA.GEAR' IN TYPEOF(fd)) OR 
         ('INTEGRATED_CNC_SCHEMA.MARKING' IN TYPEOF(fd)) OR 
         ('INTEGRATED_CNC_SCHEMA.PROTRUSION' IN TYPEOF(fd)) OR 
         ('INTEGRATED_CNC_SCHEMA.RIB_TOP' IN TYPEOF(fd))
        )));
END_RULE;


RULE security_classification_requires_assignment FOR 
  (security_classification,
   security_classification_assignment);
WHERE
  WR1:  (0 = SIZEOF (QUERY (sc <* security_classification  | NOT
           (1 <= SIZEOF (QUERY (sca <* security_classification_assignment |
               (sc :=: sca.assigned_security_classification))))
        )));
END_RULE; 


END_SCHEMA;  -- integrated_cnc_schema