(*
 * $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_mapping task_specification(Task_specification_arm, Task_specification_mim);*)

uof_mapping Task_specification(Task_specification);
end_uof_mapping;


(* GL - moved from pre_defined_product_...specializations *)
entity_mapping Pre_defined_task_element_assignment(Pre_defined_task_element_assignment, applied_action_method_assignment);

mapping_constraints;
			applied_action_method_assignment <=
			action_method_assignment
			action_method_assignment.role -> action_method_role
			action_method_role.name
			{(action_method_role.name = 'actual') 
			(action_method_role.name = 'planned') 
			(action_method_role.name = 'required')}
		
end_mapping_constraints;

end_entity_mapping;

entity_mapping Task_element_assignment__input(Task_element_assignment__input, applied_action_method_assignment);

mapping_constraints;
			applied_action_method_assignment <=
			action_method_assignment
			action_method_assignment.role -> action_method_role
			action_method_role.name
			{action_method_role.name = 'input'}
			
end_mapping_constraints;

end_entity_mapping;

entity_mapping Task_element_assignment__output(task_element_assignment__output, applied_action_method_assignment);

mapping_constraints;
			applied_action_method_assignment <=
			action_method_assignment
			action_method_assignment.role -> action_method_role
			action_method_role.name
			{action_method_role.name = 'output'}
			
end_mapping_constraints;

end_entity_mapping;
(* GL - ENDOF pre_defined_product_...specializations *)

entity_mapping Advisory_task_step(Advisory_task_step, advisory_task_element);

mapping_constraints;
advisory_task_element <=
	   task_element <=
	   action_method

end_mapping_constraints;

end_entity_mapping;
(* Take AIM
entity_mapping Classification_assignment(Classification_assignment, applied_classification_assignment)
extended;

attribute_mapping items(items, $PATH, Activity_method);
 
	classification_item *> task_classification_item
	task_classification_item = action_method

end_attribute_mapping;

attribute_mapping items(items, $PATH, Activity_method_relationship);
 
	classification_item *> task_classification_item
	task_classification_item = action_method_relationship

end_attribute_mapping;

attribute_mapping items(items, $PATH, Applied_activity_method_assignment);
 
	classification_item *> task_classification_item
	task_classification_item = applied_action_method_assignment

end_attribute_mapping;

attribute_mapping items(items, $PATH, Task_element_state_relationship);
 
	classification_item *> task_classification_item
	( task_classification_item = applied_state_type_assignment )
	( task_classification_item = applied_state_observed_assignment )

end_attribute_mapping;

attribute_mapping items(items, $PATH, Task_method_armx);

	classification_item *> task_classification_item
	task_classification_item = action_method
    action_method => task_method
  
end_attribute_mapping;

attribute_mapping items(items, $PATH, Task_objective);
 
	classification_item *> task_classification_item
	task_classification_item = action_method
	=> task_objective

end_attribute_mapping;

attribute_mapping items(items, $PATH, Task_objective_state_relationship);
 
	classification_item *> task_classification_item
	( task_classification_item = applied_state_type_assignment )
	( task_classification_item = applied_state_observed_assignment )

end_attribute_mapping;

attribute_mapping items(items, $PATH, Task_method_state_relationship);
 
	classification_item *> task_classification_item
	( task_classification_item = applied_state_type_assignment )
	( task_classification_item = applied_state_observed_assignment )

end_attribute_mapping;

end_entity_mapping;
*)
entity_mapping Concurrent_elements(Concurrent_elements, concurrent_task_element);

mapping_constraints;
concurrent_task_element <=
				task_element <=
				action_method
			
end_mapping_constraints;

attribute_mapping elements(elements, $PATH, task_element);
concurrent_task_element <=
					task_element <=
					action_method <-
					[(action_method_relationship.relating_method
action_method_relationship =>
concurrent_action_method <=
action_method_relationship
action_method_relationship.related_method ->
action_method =>
task_element)*]

end_attribute_mapping;

end_entity_mapping;

entity_mapping Decision_point(Decision_point, action_method_to_select_from);

mapping_constraints;
action_method_to_select_from
{action_method_to_select_from.number_of_elements = 1}
action_method_to_select_from <=
action_method
{action_method.purpose='decision'}

end_mapping_constraints;

attribute_mapping condition(condition, action_method, Condition);
action_method_to_select_from <=
action_method <-
action_method_relationship.relating_method
action_method_relationship
{action_method_relationship.description='decision point condition'}
action_method_relationship.related_method ->
action_method
	{action_method.purpose='condition'}
	
end_attribute_mapping;

attribute_mapping true_case_element(true_case_element, $PATH, task_element);
action_method_to_select_from <=
action_method <-
action_method_relationship.relating_method
action_method_relationship
{action_method_relationship.description='true case method'}
action_method_relationship.related_method ->
action_method =>
task_element

end_attribute_mapping;

attribute_mapping false_case_element(false_case_element, $PATH, task_element);
action_method_to_select_from <=
action_method <-
action_method_relationship.relating_method
action_method_relationship
{action_method_relationship.description='false case method'}
action_method_relationship.related_method ->
action_method =>
task_element

end_attribute_mapping;

attribute_mapping unknown_case_element(unknown_case_element, $PATH, task_element);
action_method_to_select_from <=
action_method <-
action_method_relationship.relating_method
action_method_relationship
{action_method_relationship.description='unknown case method'}
action_method_relationship.related_method ->
action_method =>
task_element

end_attribute_mapping;

end_entity_mapping;

entity_mapping Looping_element_armx(Looping_element_armx, looping_element);

mapping_constraints;
looping_element <=
	   task_element <= 
	   action_method

end_mapping_constraints;

attribute_mapping repeated_element(repeated_element, $PATH, task_element);
looping_element <=
	      task_element <= 
	      action_method <-
action_method_relationship.relating_method
action_method_relationship
{action_method_relationship.description='repeated element'}
action_method_relationship.related_method ->
action_method =>
task_element

end_attribute_mapping;

end_entity_mapping;

entity_mapping Element_constraint(Element_constraint, action_method_relationship);

mapping_constraints;

		action_method_relationship = task_specification_groupable_item
		task_specification_groupable_item <* groupable_item
		groupable_item <- applied_group_assignment.items
		applied_group_assignment <=
		group_assignment
		group_assignment.assigned_group ->
		group
		{group.description = 'element constraint'}
	
end_mapping_constraints;

attribute_mapping applies_in(applies_in, $PATH, constraint_context);

            action_method_relationship
          
end_attribute_mapping;

attribute_mapping applies_in(applies_in, $PATH, task_element);
action_method_relationship = task_specification_groupable_item
		task_specification_groupable_item <* groupable_item
		groupable_item <- applied_group_assignment.items
		applied_group_assignment <=
		group_assignment
		group_assignment.assigned_group ->
		group <-
		{group.description = 'element constraint'}
		group_assignment.assigned_group
		group_assignment =>
		applied_group_assignment 
		applied_group_assignment.items -> 
		groupable_item *> task_specification_groupable_item
		task_specification_groupable_item = action_method
		action_method =>
		task_element
end_attribute_mapping;

attribute_mapping applies_in(applies_in, $PATH, Task_method_version_armx);
action_method_relationship = task_specification_groupable_item
		task_specification_groupable_item <* groupable_item
		groupable_item <- applied_group_assignment.items
		applied_group_assignment <=
		group_assignment
		group_assignment.assigned_group ->
		group <- 
		{group.description = 'element constraint'}
		group_assignment.assigned_group
		group_assignment =>
		applied_group_assignment 
		applied_group_assignment.items -> 
		groupable_item *> task_specification_groupable_item
		task_specification_groupable_item = action_method
		action_method =>
		task_method_version
		
end_attribute_mapping;

end_entity_mapping;

entity_mapping Repeat_count(Repeat_count, relationship_condition);

mapping_constraints;
relationship_condition
{relationship_condition.name='repeat count'}
(* GL - this is simply wrong - comment it out
relationship_condition.applicable_relationships[1] ->
action_method =>
task_element =>
looping_element
*)
end_mapping_constraints;

attribute_mapping count(count, relationship_condition.condition_description);

end_attribute_mapping;

end_entity_mapping;

entity_mapping Repeat_until(Repeat_until, relationship_condition);

mapping_constraints;
relationship_condition
{relationship_condition.name='repeat until'}
(* GL - this is simply wrong - comment it out
relationship_condition.applicable_relationships[1] ->
action_method =>
task_element =>
looping_element
*)
end_mapping_constraints;
(* GL - this is simply wrong - comment it out
attribute_mapping condition(condition, action_method, Condition);

	relationship_condition
	relationship_condition.applicable_relationships[2] ->
	action_method
	{action_method.purpose='condition'}
	
end_attribute_mapping;
*)
end_entity_mapping;

entity_mapping Repeat_while(Repeat_while, relationship_condition);

mapping_constraints;
relationship_condition
{relationship_condition.name='repeat while'}
(* GL - this is simply wrong - comment it out
relationship_condition.applicable_relationships[1] ->
action_method =>
task_element =>
looping_element
*)
end_mapping_constraints;
(* GL - this is simply wrong - comment it out
attribute_mapping condition(condition, action_method, Condition);

	relationship_condition
	relationship_condition.applicable_relationships[2] ->
	action_method
	{action_method.purpose='condition'}
	
end_attribute_mapping;
*)
end_entity_mapping;

entity_mapping Simultaneous_elements(Simultaneous_elements, simultaneous_task_element);

mapping_constraints;
simultaneous_task_element <=
	      concurrent_task_element <= 
	      task_element <= 
	      action_method

end_mapping_constraints;

end_entity_mapping;

entity_mapping Structured_task_element(Structured_task_element, (/SUBTYPE(Looping_element_armx)/)
		(/SUBTYPE(task_element_sequence_armx)/)
		(/SUBTYPE(Concurrent_elements)/));

mapping_constraints;

end_mapping_constraints;

end_entity_mapping;

entity_mapping Task_element_assignment(Task_element_assignment, applied_action_method_assignment);

mapping_constraints;
{applied_action_method_assignment 
applied_action_method_assignment <= action_method_assignment
action_method_assignment
action_method_assignment.role -> action_method_role
{action_method_role.name = 'Task element assignment'}}
		
end_mapping_constraints;

attribute_mapping assigned_task_element(assigned_task_element, $PATH, task_element);
applied_action_method_assignment 
applied_action_method_assignment <= action_method_assignment
action_method_assignment
action_method_assignment.assigned_action_method -> action_method
=> task_element

end_attribute_mapping;

attribute_mapping items(items, $PATH, task_item);
applied_action_method_assignment
applied_action_method_assignment.items[i] -> action_method_items

end_attribute_mapping;

end_entity_mapping;

entity_mapping Task_element_levels(Task_element_levels, action_method_to_select_from);

mapping_constraints;
action_method_to_select_from <=
action_method
{action_method.purpose='task element levels'}

end_mapping_constraints;

attribute_mapping alternatives(alternatives, $PATH, task_element);

action_method <-
[(action_method_relationship.relating_method
action_method_relationship  =>
concurrent_action_method <=
action_method_relationship
{action_method_relationship.description='task element levels'}
action_method_relationship.related_method ->
action_method)*]

end_attribute_mapping;

end_entity_mapping;


entity_mapping Task_element_sequence_armx(Task_element_sequence_armx, task_element_sequence);

mapping_constraints;
task_element_sequence <=
	   task_element <= 
	   action_method
   
end_mapping_constraints;

attribute_mapping elements(elements, $PATH, task_element);
task_element_sequence <=
	   task_element <= 
action_method <-
[(action_method_relationship.relating_method
action_method_relationship  =>
serial_action_method  =>
sequential_method <=
serial_action_method  <=
action_method_relationship
action_method_relationship.related_method ->
action_method)*]

end_attribute_mapping;

end_entity_mapping;
(* Take AIM entity instead
entity_mapping Task_element_state_relationship(Task_element_state_relationship, applied_action_method_assignment);

mapping_constraints;

end_mapping_constraints;

attribute_mapping task_element(task_element, $PATH, task_element);

		           applied_action_method_assignment <= action_method_assignment
		           action_method_assignment
		           action_method_assignment -> action_method
		           action_method => task_element
		           
end_attribute_mapping;

attribute_mapping state(state, $PATH, State);

				applied_action_method_assignment.items -> action_method_items
				action_method_items *> task_state_items
				task_state_items = state_observed
				
end_attribute_mapping;

attribute_mapping state(state, $PATH, State_definition);

				applied_action_method_assignment.items -> action_method_items
				action_method_items *> task_state_items
				task_state_items = state_type
				
end_attribute_mapping;

attribute_mapping state(state, $PATH, Applied_state_definition_assignment);

				applied_action_method_assignment.items -> action_method_items
				action_method_items *> task_state_items
				task_state_items = applied_state_type_assignment
				
end_attribute_mapping;

attribute_mapping state(state, $PATH, Applied_state_assignment);

				applied_action_method_assignment.items -> action_method_items
				action_method_items *> task_state_items
				task_state_items = applied_state_observed_assignment
				
end_attribute_mapping;

end_entity_mapping;
*)
entity_mapping Task_invocation_armx(Task_invocation_armx, task_invocation);

mapping_constraints;
task_invocation <=
	   task_element <= 
	   action_method

end_mapping_constraints;

attribute_mapping task_method(task_method, action_method_relationship, Task_method_armx);
action_method <-
action_method_relationship.relating_method
action_method_relationship
{action_method_relationship.description='invoked task method'}
action_method_relationship.related_method ->
action_method =>
task_method

end_attribute_mapping;

attribute_mapping task_method(task_method, action_method_relationship, Task_method_version_armx);
action_method <-
action_method_relationship.relating_method
action_method_relationship
{action_method_relationship.description='invoked task method version'}
action_method_relationship.related_method ->
action_method =>
task_method_version

end_attribute_mapping;

end_entity_mapping;

entity_mapping Task_method_armx(Task_method_armx, task_method);

mapping_constraints;
task_method <=
	   action_method

end_mapping_constraints;

attribute_mapping objective(objective, $PATH, Task_objective);
task_method <=
action_method <-
(action_method_relationship.relating_method
action_method_relationship
{action_method_relationship.description='objective'} 
action_method_relationship.related_method ->
action_method =>
task_objective )*

end_attribute_mapping;

end_entity_mapping;

entity_mapping Task_method_assignment(Task_method_assignment, applied_action_method_assignment);

mapping_constraints;
        {applied_action_method_assignment <= 
        action_method_assignment
        action_method_assignment.role -> 
        action_method_role
				{action_method_role.name = 'Task method assignment'}}
end_mapping_constraints;

attribute_mapping assigned_activity_method(assigned_activity_method, $PATH, Task_method_armx);

        applied_action_method_assignment 
        applied_action_method_assignment <= action_method_assignment
        action_method_assignment
        action_method_assignment.assigned_action_method -> 
        action_method => 
        task_method
      
end_attribute_mapping;

attribute_mapping items(items, $PATH, task_item);

        applied_action_method_assignment
        applied_action_method_assignment.items[i] -> 
        action_method_items
      
end_attribute_mapping;

end_entity_mapping;

entity_mapping Task_method_relationship(Task_method_relationship, task_method_relationship);

mapping_constraints;

			task_method_relationship <=
			action_method_relationship
			
end_mapping_constraints;

attribute_mapping relating_method(relating_method, $PATH, Task_method_armx);

				task_method_relationship <=
				action_method_relationship 
	      action_method_relationship.relating_method ->
	      action_method =>
	      task_method
      
end_attribute_mapping;

attribute_mapping related_method(related_method, $PATH, Task_method_armx);

				task_method_relationship <=
				action_method_relationship 
	      action_method_relationship.related_method ->
	      action_method =>
	      task_method
      
end_attribute_mapping;

end_entity_mapping;
(* Take AIM entity instead
entity_mapping Task_method_state_relationship(Task_method_state_relationship, applied_action_method_assignment);

mapping_constraints;

end_mapping_constraints;

attribute_mapping task_method(task_method, $PATH, Task_method_version_armx);

		           applied_action_method_assignment <= action_method_assignment
		           action_method_assignment
		           action_method_assignment -> action_method
		           action_method => task_method_version
		           
end_attribute_mapping;

attribute_mapping state(state, $PATH, State);

				applied_action_method_assignment.items -> action_method_items
				action_method_items *> task_state_items
				task_state_items = state_observed
				
end_attribute_mapping;

attribute_mapping state(state, $PATH, State_definition);

				applied_action_method_assignment.items -> action_method_items
				action_method_items *> task_state_items
				task_state_items = state_type
				
end_attribute_mapping;

attribute_mapping state(state, $PATH, Applied_state_definition_assignment);

				applied_action_method_assignment.items -> action_method_items
				action_method_items *> task_state_items
				task_state_items = applied_state_type_assignment
				
end_attribute_mapping;

attribute_mapping state(state, $PATH, Applied_state_assignment);

				applied_action_method_assignment.items -> action_method_items
				action_method_items *> task_state_items
				task_state_items = applied_state_observed_assignment
				
end_attribute_mapping;

end_entity_mapping;
*)
entity_mapping Task_method_version_armx(Task_method_version_armx, task_method_version);

mapping_constraints;
task_method_version <=
	   action_method
		
end_mapping_constraints;

attribute_mapping of_task_method(of_task_method, $PATH, Task_method_armx);
task_method_version <=
			action_method <-
action_method_relationship.relating_method
action_method_relationship
{action_method_relationship.description='of task method'}
action_method_relationship.related_method ->
action_method =>
task_method
			
end_attribute_mapping;

attribute_mapping content(content, $PATH, task_element);
task_method_version <=
action_method <-
action_method_relationship.relating_method
action_method_relationship
{action_method_relationship.description='method'}
action_method_relationship.related_method ->
action_method =>
task_element

end_attribute_mapping;

end_entity_mapping;

entity_mapping Task_method_version_assignment(Task_method_version_assignment, applied_action_method_assignment);

mapping_constraints;
{applied_action_method_assignment 
applied_action_method_assignment <= action_method_assignment
action_method_assignment
action_method_assignment.role -> action_method_role
{action_method_role.name = 'Task method version assignment'}}
		
end_mapping_constraints;
attribute_mapping assigned_task_method(assigned_task_method, $PATH, Task_method_version_armx);

        applied_action_method_assignment 
        applied_action_method_assignment <= action_method_assignment
        action_method_assignment
        action_method_assignment.assigned_action_method -> action_method
        => task_method_version
      
end_attribute_mapping;

attribute_mapping items(items, $PATH, task_item);

        applied_action_method_assignment
        applied_action_method_assignment.items[i] -> action_method_items
      
end_attribute_mapping;

end_entity_mapping;

entity_mapping Task_method_version_relationship_armx(Task_method_version_relationship_armx, task_method_version_relationship);

mapping_constraints;

			task_method_version_relationship <=
			action_method_relationship
			
end_mapping_constraints;

attribute_mapping relating_task_method(relating_task_method, $PATH, Task_method_version_armx);

				task_method_version_relationship <=
				action_method_relationship 
	      action_method_relationship.relating_method ->
	      action_method =>
	      task_method_version
      
end_attribute_mapping;

attribute_mapping related_task_method(related_task_method, $PATH, Task_method_version_armx);

				task_method_version_relationship <=
				action_method_relationship 
	      action_method_relationship.related_method ->
	      action_method =>
	      task_method_version
      
end_attribute_mapping;

end_entity_mapping;
(* Take AIM instead
entity_mapping Task_objective(Task_objective, task_objective);

mapping_constraints;
task_objective <=
	   action_method

end_mapping_constraints;

attribute_mapping name(name, action_method.name);

end_attribute_mapping;

attribute_mapping description(description, action_method.description);

end_attribute_mapping;

end_entity_mapping;

entity_mapping Task_objective_state_relationship(Task_objective_state_relationship, applied_action_method_assignment);

mapping_constraints;

end_mapping_constraints;

attribute_mapping task_objective(task_objective, $PATH, Task_objective);

		           applied_action_method_assignment <= action_method_assignment
		           action_method_assignment
		           action_method_assignment -> action_method
		           action_method => task_objective
		           
end_attribute_mapping;

attribute_mapping state(state, $PATH, State);

				applied_action_method_assignment.items -> action_method_items
				action_method_items *> task_state_items
				task_state_items = state_observed
				
end_attribute_mapping;

attribute_mapping state(state, $PATH, State_definition);

				applied_action_method_assignment.items -> action_method_items
				action_method_items *> task_state_items
				task_state_items = state_type
				
end_attribute_mapping;

attribute_mapping state(state, $PATH, Applied_state_definition_assignment);

				applied_action_method_assignment.items -> action_method_items
				action_method_items *> task_state_items
				task_state_items = applied_state_type_assignment
				
end_attribute_mapping;

attribute_mapping state(state, $PATH, Applied_state_assignment);

				applied_action_method_assignment.items -> action_method_items
				action_method_items *> task_state_items
				task_state_items = applied_state_observed_assignment
				
end_attribute_mapping;

end_entity_mapping;
*)
entity_mapping Task_step_armx(Task_step_armx, task_step);

mapping_constraints;
task_step <=
	   task_element <= 
	   action_method

end_mapping_constraints;

attribute_mapping step_text(step_text, action_method.description);

end_attribute_mapping;

end_entity_mapping;
(*end_schema_mapping;*)
