(*
 * $Id$
 *
 * JSDAI(TM), a way to implement STEP, ISO 10303
 * Copyright (C) 1997-2008, LKSoftWare GmbH, Germany
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License
 * version 3 as published by the Free Software Foundation (AGPL v3).
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * JSDAI is a registered trademark of LKSoftWare GmbH, Germany
 * This software is also available under commercial licenses.
 * See also http://www.jsdai.net/
 *)

(*
Derived from ISO TC184/SC4/WG12 N4261 - ISO/TS 10303-1052 Default tolerance - EXPRESS ARM
by LKSoftWare GmbH for implementation purpose within IDA-STEP(TM)
*) 

(* This is based on ARM *)
(* VERY badly modules, module, especially the mapping *)

SCHEMA Default_tolerance_xim;

USE FROM Foundation_representation_xim;    -- ISO/TS 10303-1006

USE FROM Measure_representation_xim;    -- ISO/TS 10303-1118

USE FROM Shape_property_assignment_xim;    -- ISO/TS 10303-1032

USE FROM Default_tolerance_mim;

USE FROM product_property_representation_schema(represented_definition);

TYPE cell_entry_select = SELECT
   (Plus_minus_toleranced_datum, 
    Upper_lower_toleranced_datum);
END_TYPE; 

TYPE default_context_select = SELECT
   (Item_shape);
END_TYPE; 

TYPE default_setting_select = EXTENSIBLE SELECT
   (General_tolerances);
END_TYPE; 

TYPE general_tolerance_table_select = EXTENSIBLE SELECT
   (General_tolerance_table);
END_TYPE; 

TYPE limit_select = SELECT
   (Significant_number_of_digits, 
    Upper_lower_limit);
END_TYPE; 

ENTITY Default_setting_association
(* CONNOTATIONAL *) SUBTYPE OF (property_definition_representation);
  default_value : OPTIONAL SET[1:?] OF default_setting_select; (** Originally it is mandatory SET[0:?] **)
  default_context : default_context_select;
DERIVE
  SELF\property_definition_representation.used_representation : representation := ?;
  SELF\property_definition_representation.definition : represented_definition := ?;
END_ENTITY;

ENTITY General_tolerance_table
(* CONNOTATIONAL *) SUBTYPE OF (default_tolerance_table);
  SELF\Representation.name RENAMED tolerance_type : STRING;
DERIVE
  SELF\representation.items : SET [1:?] OF representation_item := ?;
  SELF\representation.context_of_items : representation_context := ?;
INVERSE
  cell : SET[1:?] OF Tolerance_table_cell FOR tolerance_table;
END_ENTITY;

ENTITY General_tolerances
(* CONNOTATIONAL *) SUBTYPE OF (Representation);
  table_definition : general_tolerance_table_select;
  tolerance_class : STRING;
DERIVE
  SELF\representation.items : SET [1:?] OF representation_item := ?;
  SELF\representation.context_of_items : representation_context := ?;
  SELF\representation.name : label := ?;
END_ENTITY;

ENTITY Plus_minus_toleranced_datum
(* CONNOTATIONAL *) SUBTYPE OF (measure_representation_item);
  tolerance_value : measure_representation_item;
  DERIVE
    SELF\measure_with_unit.value_component : measure_value := ?;
    SELF\measure_with_unit.unit_component : unit := ?;
    SELF\representation_item.name : label := ?;
  WHERE
  	WR1: tolerance_value = SELF; -- this is derived from the fact thas tolerance_value is IDENTICAL mapping
END_ENTITY;

ENTITY Significant_number_of_digits
(* CONNOTATIONAL *) SUBTYPE OF (measure_representation_item);
  SELF\Measure_with_unit.value_component RENAMED number_of_digits : count_measure;
DERIVE
  SELF\measure_with_unit.unit_component : unit := ?;
  SELF\representation_item.name : label := ?;
END_ENTITY;

ENTITY Tolerance_table_cell
(* CONNOTATIONAL *) SUBTYPE OF (default_tolerance_table_cell);
  cell_value : cell_entry_select;
  description : STRING;
  limit : limit_select;
  SELF\representation_item.name RENAMED tolerance_class : STRING;
  tolerance_table : General_tolerance_table;
DERIVE
  SELF\compound_representation_item.item_element : compound_item_definition := ?;
END_ENTITY;

ENTITY Upper_lower_limit
(* CONNOTATIONAL *) SUBTYPE OF (measure_representation_item);
  upper_limit : measure_representation_item;
  lower_limit : measure_representation_item;
DERIVE
  SELF\measure_with_unit.value_component : measure_value := ?;
  SELF\measure_with_unit.unit_component : unit := ?;
  SELF\representation_item.name : label := ?;
END_ENTITY;

ENTITY Upper_lower_toleranced_datum
(* CONNOTATIONAL *) SUBTYPE OF (measure_representation_item);
  lower_tolerance_value : measure_representation_item;
  upper_tolerance_value : measure_representation_item;
DERIVE
  SELF\measure_with_unit.value_component : measure_value := ?;
  SELF\measure_with_unit.unit_component : unit := ?;
  SELF\representation_item.name : label := ?;
END_ENTITY;

END_SCHEMA;  -- Default_tolerance_xim

