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

(*
   Derived from ISO TC184/SC4/WG12 N - ISO/CD-TS 10303-xxxx Requirement decomposition - EXPRESS ARM
   by LKSoftWare GmbH for implementation purpose within IDA-STEP(TM)
*)

SCHEMA Requirement_decomposition_xim;

USE FROM Elemental_geometric_shape_xim;

USE FROM Production_rule_xim;

USE FROM Functional_specification_xim;

USE FROM Conductivity_material_aspects_xim;

USE FROM support_resource_schema(label);

USE FROM Requirement_decomposition_mim;

USE FROM product_property_definition_schema(characterized_definition);

USE FROM application_context_schema(application_context);

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

REFERENCE FROM Specification_document_xim(get_document_definition);	-- ISO/TS 10303-1747

	TYPE rd_documented_element_select = EXTENSIBLE GENERIC_ENTITY SELECT BASED_ON documented_element_select WITH 
	   (Predefined_requirement_view_definition_armx);
	END_TYPE; 

  TYPE rd_requirement_assignment_item = EXTENSIBLE GENERIC_ENTITY SELECT BASED_ON requirement_assignment_item WITH
    (group, group_relationship);
  END_TYPE;

	TYPE characteristic_select = SELECT
      (characteristic,
       boolean_representation_item,
       date_time_representation_item,
       integer_representation_item,
       logical_representation_item,
       Property_value_representation,
       Rational_representation_item_xim,
       real_representation_item,
       compound_representation_item);
	END_TYPE; 

  TYPE material_conductivity_classification = ENUMERATION OF
    (conductive,
     resistive,
     semi_conductive,
     non_conductive);
  END_TYPE;

	TYPE rd_material_item_select = EXTENSIBLE GENERIC_ENTITY SELECT BASED_ON material_item_select WITH
		(Predefined_requirement_view_definition_armx);
	END_TYPE;

	TYPE rd_property_assignment_select = EXTENSIBLE GENERIC_ENTITY SELECT BASED_ON property_assignment_select WITH
		(Requirement_view_definition);
	END_TYPE;

	TYPE relationship_operation = ENUMERATION OF
    	(and_operation,
		or_operation);
	END_TYPE;

	TYPE requirement_view_relationship_type = ENUMERATION OF
    	(derived_from,
	     precedence,
    	 supplemental);
	END_TYPE;

  ENTITY Constraint_occurrence
    SUPERTYPE OF (View_based_constraint_occurrence)
    (* CONNOTATIONAL *) SUBTYPE OF (Predefined_requirement_view_definition_armx);
      logical_relation : OPTIONAL Complex_clause_armx;
    DERIVE
      SELF\product_definition.id : identifier := ?;      
    WHERE
      WR1 : (('REQUIREMENT_DECOMPOSITION_XIM.' + 'VIEW_BASED_CONSTRAINT_OCCURRENCE') IN TYPEOF(SELF)) OR EXISTS(logical_relation);
  END_ENTITY;

  ENTITY Design_characteristic_occurrence
    (* CONNOTATIONAL *) SUBTYPE OF (Predefined_requirement_view_definition_armx);
  END_ENTITY;

  ENTITY View_based_constraint_occurrence
    SUPERTYPE OF (Shape_and_view_based_constraint_occurrence)
    (* CONNOTATIONAL *) SUBTYPE OF (Constraint_occurrence);
      constraining_part : Product_view_definition;
  END_ENTITY;

  ENTITY Material_electrical_conductivity_requirement_occurrence
    (* CONNOTATIONAL *) SUBTYPE OF (Predefined_requirement_view_definition_armx);
      electrical_conductivity_characteristic : material_conductivity_classification;
  END_ENTITY;

 ENTITY Requirement_view_definition_relationship_armx
     (* CONNOTATIONAL *) SUBTYPE OF (requirement_view_definition_relationship);
       SELF\product_definition_relationship.relating_product_definition RENAMED primary  : Requirement_view_definition;
       SELF\product_definition_relationship.related_product_definition RENAMED secondary : Requirement_view_definition;
     (** GL in ARM it is o type STRINg, but here we leave ENUMERATION for easier handling **)       
       relation_type                                                                     : requirement_view_relationship_type;
    DERIVE      
      SELF\product_definition_relationship.id : identifier := ?;
      SELF\product_definition_relationship.name : label := ?;
     WHERE
       WR1 : primary :<>: secondary;
  END_ENTITY;
  
  ENTITY Operational_requirement_occurrence_relationship_armx
     (* CONNOTATIONAL *) SUBTYPE OF (Assigned_property, operational_requirement_occurrence_relationship);
       SELF\product_definition_relationship.relating_product_definition RENAMED operand_1 : Requirement_view_definition;
       SELF\product_definition_relationship.related_product_definition RENAMED operand_2  : Requirement_view_definition;
       SELF\Assigned_property.described_element RENAMED result           									: Requirement_view_definition;
       relationship_type                                                 									: relationship_operation;
    DERIVE      
      SELF\product_definition_relationship.id : identifier := ?;
   WHERE
      WR1 : operand_1 :<>: operand_2;
  END_ENTITY;

  ENTITY Predefined_requirement_view_definition_armx
SUPERTYPE OF(ONEOF(Constraint_occurrence,
		 Design_characteristic_occurrence))
    SUBTYPE OF(Requirement_view_definition, predefined_requirement_view_definition);
      required_analytical_representation                                : OPTIONAL SET[1:?] OF Analytical_model_application;
      required_functional_specification                                 : OPTIONAL SET[1:?] OF Functional_specification;
      required_characteristic                                           : OPTIONAL characteristic_select;
      required_material					                                : OPTIONAL material_designation; -- in the ARM it is INVERSE, but since it is kind of representation in XIM, it can be only this way.
    DERIVE
        requirement_specification: SET[1:?] OF Document_definition :=
  			get_document_definition(SELF, 'requirement specification', 
  			'SPECIFICATION_DOCUMENT_XIM.SPECIFICATION_DEFINITION_ARMX');
		reference_clause: SET[0:1] OF Document_definition :=
  			get_document_definition(SELF, 'reference clause', 
  			'SPECIFICATION_DOCUMENT_XIM.DOCUMENT_DEFINITION');    
      SELF\product_definition.description : text := ?;
    WHERE  
	  WR1 : NOT (SIZEOF(required_material) = 1) OR
            ('CONDUCTIVITY_MATERIAL_ASPECTS_XIM.'+ 'MATERIAL_IDENTIFICATION_WITH_CONDUCTIVITY_CLASSIFICATION' IN TYPEOF (required_material));
      WR2: SELF\Product_view_definition.initial_context.application_domain IN 
          ['mechanical', 'thermal', 'electromechancial', 'electromagnetic compatibility', 'electrical'];
      WR3: SELF\Product_view_definition.initial_context.life_cycle_stage in ['design', 'qualify', 'inspect', 'test'];
  END_ENTITY;

  ENTITY Shape_and_view_based_constraint_occurrence
    (* CONNOTATIONAL *) SUBTYPE OF (View_based_constraint_occurrence);
      constraining_shape : SET[1:?] OF Shape_representation;
    WHERE
      WR1 : valid_constraining_shape(constraining_shape,
 SELF\View_based_constraint_occurrence.constraining_part);
  END_ENTITY;
(*
FUNCTION get_predefined_requirement_view_definition
  (ra : Requirement_assignment_armx;
  req_type : STRING) : Predefined_requirement_view_definition_armx;
  LOCAL
    requirements : SET[0:?] OF Predefined_requirement_view_definition_armx;
  END_LOCAL;
	requirements := USEDIN (ra.assigned_requirement, 'REQUIREMENT_DECOMPOSITION_XIM.' + 'PREDEFINED_REQUIREMENT_VIEW_DEFINITION_ARMX.ASSOCIATED_DEFINITION') ;
	REPEAT i := 1 to SIZEOF(requirements) by 1;
	  IF (req_type IN TYPEOF (requirements[i])) THEN
	  	RETURN (requirements[i]);
	  END_IF;
	END_REPEAT;
	RETURN (?);
END_FUNCTION;
*)
  FUNCTION valid_constraining_shape(
    sd   : SET OF Shape_representation ;
    eepd : Product_view_definition
  ) : BOOLEAN;

    RETURN(TRUE);
  END_FUNCTION;

FUNCTION get_rvd(
	input : requirement_assignment_item;
	id : STRING
) : SET OF Requirement_view_definition; 

LOCAL
	rvd : SET[0:?] OF Requirement_view_definition := [];  --this gives us access to the information base
	ra : SET[0:?] OF Requirement_assignment_armx :=[];
END_LOCAL;
	ra := bag_to_set((QUERY(rai <* USEDIN (input, 'REQUIREMENT_ASSIGNMENT_XIM.'+
	'REQUIREMENT_ASSIGNMENT_ARMX.ASSIGNED_TO') | (rai.id = id))));

	-- iterate over ra
	REPEAT i := 1 to SIZEOF(ra) by 1;
		rvd := rvd + ra[i].assigned_requirement;
	END_REPEAT;

	RETURN(rvd);
END_FUNCTION;


END_SCHEMA;


