(*
 * $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/
 *)

SCHEMA Failure_mode_effects_causes_analysis_xim;

USE FROM State_definition_xim; -- AP239 module

TYPE failure_cause_select = SELECT (Failure_mode, Failure_cause);
END_TYPE;

TYPE failure_effect_select = SELECT (Failure_mode, Failure_cause_assignment);
END_TYPE;

-- extend this select with the entity types from xims, representing:
-- a) an item;
-- b) a system;
-- c) a function;
-- d) a component.
TYPE failure_mode_select = EXTENSIBLE SELECT ;
END_TYPE;

TYPE failure_detection_method_select = SELECT (Failure_mode, Failure_cause_assignment);
END_TYPE;

TYPE roll_up_item_select = SELECT (roll_up_relationship, failure_cause_assignment);
END_TYPE;

ENTITY Failure_mode
  SUBTYPE OF (state_type);
  id	: identifier;
END_ENTITY;

ENTITY Failure_cause
  SUBTYPE OF (state_type);
END_ENTITY;

ENTITY Failure_effect
  SUBTYPE OF (state_type);
END_ENTITY;

ENTITY Failure_detection_method
  SUBTYPE OF (state_type);
END_ENTITY;

ENTITY Failure_cause_assignment
  SUBTYPE OF (Applied_state_definition_assignment);
    SELF\Applied_state_definition_assignment.assigned_to RENAMED cause : failure_cause_select;
    SELF\Applied_state_definition_assignment.described_state_definition RENAMED for_failure : Failure_mode;
  DERIVE
    SELF\Applied_state_definition_assignment.role : State_type_role := State_type_role('failure cause assignment', ?);
END_ENTITY;
-- note: role becomes a "re-declared as derived attribute" and will consequently show up with an "*" in a XIM-p21 file.

ENTITY failure_effect_assignment
 SUBTYPE OF (Applied_state_definition_assignment);
   SELF\Applied_state_definition_assignment.assigned_to RENAMED target : failure_effect_select;
   SELF\Applied_state_definition_assignment.described_state_definition RENAMED related_effect : Failure_effect;
 DERIVE
   SELF\Applied_state_definition_assignment.role : State_type_role := State_type_role('failure effect assignment', ?);
END_ENTITY;

ENTITY failure_mode_assignment
 SUBTYPE OF (Applied_state_definition_assignment);
   SELF\Applied_state_definition_assignment.assigned_to RENAMED target : failure_mode_select;
   SELF\Applied_state_definition_assignment.described_state_definition RENAMED related_failure : Failure_mode;
 DERIVE
  SELF\Applied_state_definition_assignment.role : State_type_role := State_type_role('failure mode assignment', ?);
END_ENTITY;

ENTITY failure_detection_method_assignment
 SUBTYPE OF (Applied_state_definition_assignment);
   SELF\Applied_state_definition_assignment.assigned_to RENAMED target:  failure_detection_method_select;
   SELF\Applied_state_definition_assignment.described_state_definition RENAMED related_detection_method : Failure_detection_method;
 DERIVE
  SELF\Applied_state_definition_assignment.role : State_type_role := State_type_role('failure detection method assignment', ?);
END_ENTITY;

ENTITY roll_up_relationship SUPERTYPE OF (ONEOF 
	(or_consequential_failure_relationship, 
	xor_consequential_failure_relationship,
	and_consequential_failure_relationship));
	included_items : SET [0:?] OF roll_up_item_select;
END_ENTITY;

ENTITY xor_consequential_failure_relationship
	SUBTYPE OF (roll_up_relationship);
END_ENTITY;

ENTITY or_consequential_failure_relationship
	SUBTYPE OF (roll_up_relationship);
END_ENTITY;

ENTITY and_consequential_failure_relationship
	SUBTYPE OF (roll_up_relationship);
END_ENTITY;

SUBTYPE_CONSTRAINT FMECA_state_type_subtypes FOR state_type;
  ONEOF (Failure_mode, Failure_cause, Failure_effect, Failure_detection_method);
END_SUBTYPE_CONSTRAINT;

END_SCHEMA;
