(*
 * $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 N3654 - ISO/CD-TS 10303-1756 Conductivity material aspects - EXPRESS ARM
   by LKSoftWare GmbH for implementation purpose within IDA-STEP(TM)
*)

SCHEMA Conductivity_material_aspects_xim;

	USE FROM Classification_assignment_xim;	-- ISO/TS 10303-1114
	USE FROM Generic_material_aspects_xim;	-- ISO/TS 10303-1681
	USE FROM Part_view_definition_xim;	-- ISO/TS 10303-1023
	
	USE FROM Conductivity_material_aspects_mim;

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


	TYPE cma_material_item_select = EXTENSIBLE GENERIC_ENTITY SELECT BASED_ON material_item_select WITH
		(Part_view_definition);
	END_TYPE;

   SUBTYPE_CONSTRAINT cma_class_subtypes FOR Class; 
	    (ONEOF (Conductivity_material_property_class,
		 Relative_permeability_material_property_class,
		 Relative_optical_insertion_loss_material_property_class,
		 Relative_permittivity_material_property_class));
	END_SUBTYPE_CONSTRAINT;
		
 ENTITY Conductivity_material_property_class
	ABSTRACT SUPERTYPE OF (ONEOF (Material_electrical_conductivity_class, 
		Material_thermal_conductivity_class))
  SUBTYPE OF (Class_armx);
  WHERE
	WR1: SELF\group.name IN ['conductive', 'non conductive', 'resistive', 'semi conductive', 'super conductive'];
 END_ENTITY;

ENTITY Material_electrical_conductivity_class
  SUBTYPE OF (Conductivity_material_property_class);
  DERIVE
    SELF\group.description : text := 'electrical conductivity';
END_ENTITY;

ENTITY Material_thermal_conductivity_class
  SUBTYPE OF (Conductivity_material_property_class);
  DERIVE
    SELF\group.description : text := 'thermal conductivity';
END_ENTITY;

ENTITY Relative_permeability_material_property_class
  SUBTYPE OF (Class_armx);
  DERIVE
    SELF\group.description : text := 'relative permeability';
  WHERE
	WR1: SELF\group.name IN 
       ['free space permeabilty', 'low permeability', 'medium permeability', 'highly permeable'];
 END_ENTITY;

 ENTITY Relative_optical_insertion_loss_material_property_class
  SUBTYPE OF (Class_armx);
  DERIVE
    SELF\group.description : text := 'relative optical insertion loss';
  WHERE
	WR1: SELF\group.name IN 
       ['vacuum', 'very low loss', 'low loss', 'medium loss', 'high loss'];
 END_ENTITY;

 ENTITY Relative_permittivity_material_property_class
  SUBTYPE OF (Class_armx);
  DERIVE
    SELF\group.description : text := 'relative permittivity';
  WHERE
	WR1: SELF\group.name IN 
       ['vacuum permittivity', 'low permittivity', 'medium permittivity', 'high permittivity'];
 END_ENTITY;
 
 ENTITY Material_identification_with_conductivity_classification
  SUBTYPE OF (material_designation_with_conductivity_classification);
  DERIVE
    electrical_conductivity_classification : STRING := get_cond_class(SELF,'MATERIAL_ELECTRICAL_CONDUCTIVITY_CLASS');
	magnetic_permeability_classification   : STRING := get_cond_class(SELF,'RELATIVE_PERMEABILITY_MATERIAL_PROPERTY_CLASS');
    optical_insertion_loss_classification  : STRING := get_cond_class(SELF,'RELATIVE_OPTICAL_INSERTION_LOSS_MATERIAL_PROPERTY_CLASS');
    thermal_conductivity_classification    : STRING := get_cond_class(SELF,'MATERIAL_THERMAL_CONDUCTIVITY_CLASS');
    dielectric_permittivity_classification : STRING := get_cond_class(SELF,'RELATIVE_PERMITTIVITY_MATERIAL_PROPERTY_CLASS');
  WHERE 	
  	WR1: (SIZEOF(QUERY(ca <* USEDIN(SELF,
	 	'CLASSIFICATION_ASSIGNMENT_MIM.' + 
	 	'APPLIED_CLASSIFICATION_ASSIGNMENT.' + 'ITEMS') |
	 	('CONDUCTIVITY_MATERIAL_ASPECTS_XIM.'+
	 	'MATERIAL_ELECTRICAL_CONDUCTIVITY_CLASS' IN TYPEOF (ca.assigned_class)))) = 1);
  	WR2: (SIZEOF(QUERY(ca <* USEDIN(SELF,
	 	'CLASSIFICATION_ASSIGNMENT_MIM.' + 
	 	'APPLIED_CLASSIFICATION_ASSIGNMENT.' + 'ITEMS') |
	 	('CONDUCTIVITY_MATERIAL_ASPECTS_XIM.'+
	 	'MATERIAL_THERMAL_CONDUCTIVITY_CLASS' IN TYPEOF (ca.assigned_class)))) <= 1);
  	WR3: (SIZEOF(QUERY(ca <* USEDIN(SELF,
	 	'CLASSIFICATION_ASSIGNMENT_MIM.' + 
	 	'APPLIED_CLASSIFICATION_ASSIGNMENT.' + 'ITEMS') |
	 	('CONDUCTIVITY_MATERIAL_ASPECTS_XIM.'+
	 	'RELATIVE_PERMEABILITY_MATERIAL_PROPERTY_CLASS' IN TYPEOF (ca.assigned_class)))) <= 1);
  	WR4: (SIZEOF(QUERY(ca <* USEDIN(SELF,
	 	'CLASSIFICATION_ASSIGNMENT_MIM.' + 
	 	'APPLIED_CLASSIFICATION_ASSIGNMENT.' + 'ITEMS') |
	 	('CONDUCTIVITY_MATERIAL_ASPECTS_XIM.'+
		'RELATIVE_PERMITTIVITY_MATERIAL_PROPERTY_CLASS' IN TYPEOF (ca.assigned_class)))) <= 1);
  	WR5: (SIZEOF(QUERY(ca <* USEDIN(SELF,
	 	'CLASSIFICATION_ASSIGNMENT_MIM.' + 
	 	'APPLIED_CLASSIFICATION_ASSIGNMENT.' + 'ITEMS') |
	 	('CONDUCTIVITY_MATERIAL_ASPECTS_XIM.'+
	 	'RELATIVE_OPTICAL_INSERTION_LOSS_MATERIAL_PROPERTY_CLASS' IN TYPEOF (ca.assigned_class)))) <= 1); 
 END_ENTITY;
 
 FUNCTION get_cond_class(input1 : Material_identification_with_conductivity_classification;
                         input2 : STRING) : STRING;
 LOCAL
  car : SET OF Applied_classification_assignment := [];
 END_LOCAL;
  car := QUERY(ca <* bag_to_set(USEDIN(input1,
	 	'CLASSIFICATION_ASSIGNMENT_MIM.' + 
	 	'APPLIED_CLASSIFICATION_ASSIGNMENT.' + 'ITEMS')) |
	 	('CONDUCTIVITY_MATERIAL_ASPECTS_XIM.'+
	 	input2 IN TYPEOF (ca.assigned_class)));
 IF SIZEOF(car) = 1
  THEN
    RETURN(car[1].assigned_class\group.name);
  ELSE
    RETURN('?');
 END_IF;
 END_FUNCTION;

 END_SCHEMA;



