(*
 * $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 generic_product_occurrence(Generic_product_occurrence_arm, Generic_product_occurrence_mim);*)


entity_mapping Definition_based_product_occurrence(Definition_based_product_occurrence, 
(* GL - I think it is too strict *)
(* (/SUBTYPE(Definition_based_part_occurrence)/) *)
product_definition
);

attribute_mapping derived_from(derived_from, $PATH, Product_view_definition);
product_definition <-
product_definition_relationship.related_product_definition
{product_definition_relationship
product_definition_relationship.name = 'definition usage'}
product_definition_relationship
product_definition_relationship.relating_product_definition ->
product_definition

end_attribute_mapping;


end_entity_mapping;

entity_mapping Product_occurrence(Product_occurrence, (assembly_component_usage)(
product_definition)(product_definition));

mapping_constraints;
(
assembly_component_usage <= product_definition_usage
product_definition_usage <= product_definition_relationship
product_definition_relationship.related_product_definition ->
product_definition
)(
product_definition
({[product_definition
([product_definition <- 
product_definition_occurrence_relationship.occurrence 
product_definition_occurrence_relationship 
product_definition_occurrence_relationship.occurrence_usage ->] 
[product_definition <- 
product_definition_relationship.related_product_definition 
product_definition_relationship 
{product_definition_relationship.name = 'definition usage'} 
product_definition_relationship.relating_product_definition -> 
product_definition <- 
{product_definition.frame_of_reference ->
product_definition_context <= 
application_context_element 
application_context_element.name = 'part definition'} 
product_definition_relationship.related_product_definition 
product_definition_relationship =>
product_definition_usage =>] 
assembly_component_usage) 
([product_definition <- 
product_definition_relationship.related_product_definition 
product_definition_relationship 
product_definition_relationship.name = 'definition usage'] 
[product_definition <- 
product_definition_relationship.related_product_definition 
product_definition_relationship =>
product_definition_usage])]})

)(
product_definition <- product_definition_relationship.related_product_definition
product_definition_relationship
{product_definition_relationship.name = 'definition usage'}
)
end_mapping_constraints;

end_entity_mapping;

entity_mapping Product_occurrence_with_quantity(Product_occurrence_with_quantity, 
			(/SUBTYPE(Quantified_instance)/)
			(/SUBTYPE(Selected_instance)/)
		);

attribute_mapping occurrence_quantity(occurrence_quantity, $PATH, measure_with_unit);

product_definition = characterized_product_definition
characterized_product_definition = characterized_definition 
characterized_definition <- property_definition.definition
property_definition 
{property_definition.name = 'occurrence selection'}
represented_definition = property_definition
represented_definition <- property_definition_representation.definition
property_definition_representation
property_definition_representation.used_representation -> representation
{representation.name = 'selection criteria'}
representation.items[i] ->
representation_item
{representation_item.name = 'selection quantity'}
representation_item =>
measure_representation_item
end_attribute_mapping;

attribute_mapping occurrence_quantity(occurrence_quantity, $PATH, Value_limit);

product_definition = characterized_product_definition
characterized_product_definition = characterized_definition 
characterized_definition <- property_definition.definition
property_definition 
{property_definition.name = 'occurrence selection'}
represented_definition = property_definition
represented_definition <- property_definition_representation.definition
property_definition_representation
property_definition_representation.used_representation -> representation
{representation.name = 'selection criteria'}
representation.items[i] -> representation_item
{representation_item.name = 'selection quantity'}
representation_item => 
[measure_representation_item]
[qualified_representation_item]

end_attribute_mapping;

attribute_mapping occurrence_quantity(occurrence_quantity, $PATH, Value_range);

product_definition = characterized_product_definition
characterized_product_definition = characterized_definition 
characterized_definition <- property_definition.definition
property_definition 
{property_definition.name = 'occurrence selection'}
represented_definition = property_definition
represented_definition <- property_definition_representation.definition
property_definition_representation
property_definition_representation.used_representation -> representation
{representation.name = 'selection criteria'}
representation.items[i] ->
representation_item => compound_representation_item
{representation_item.name = 'selection quantity'}
compound_representation_item => value_range

end_attribute_mapping;

end_entity_mapping;

entity_mapping Quantified_instance(Quantified_instance, (product_definition)(quantified_assembly_component_usage)(quantified_assembly_component_usage)(product_definition));

mapping_constraints;
(
product_definition
{product_definition.name='quantified instance'}
{product_definition.frame_of_reference -> product_definition_context
product_definition_context <= application_context_element 
application_context_element.name = 'part occurrence'}
)(
	quantified_assembly_component_usage <= assembly_component_usage
assembly_component_usage <= product_definition_usage
product_definition_usage <= product_definition_relationship
product_definition_relationship.related_product_definition -> product_definition
{product_definition.frame_of_reference -> product_definition_context
product_definition_context <= application_context_element 
application_context_element.name = 'part definition'}
	)(
quantified_assembly_component_usage <= assembly_component_usage
assembly_component_usage <= product_definition_usage
product_definition_usage <= product_definition_relationship
product_definition_relationship.related_product_definition -> product_definition
{product_definition.frame_of_reference -> product_definition_context
product_definition_context <= application_context_element 
application_context_element.name = 'part occurrence'}
	)(
product_definition
{product_definition.name='quantified instance'}
{product_definition.frame_of_reference -> product_definition_context
product_definition_context <= application_context_element 
application_context_element.name = 'part occurrence'}
product_definition <- product_definition_occurrence_relationship.occurrence
product_definition_occurrence_relationship.occurrence_usage -> assembly_component_usage
{assembly_component_usage => quantified_assembly_component_usage}
	)
end_mapping_constraints;

attribute_mapping occurrence_quantity(occurrence_quantity, ($PATH)($PATH)($PATH)($PATH), measure_with_unit);
(
product_definition = characterized_product_definition 
characterized_product_definition = characterized_definition
characterized_definition <- property_definition.definition
property_definition 
{property_definition.name = 'occurrence quantity'}
property_definition = represented_definition 
represented_definition <- property_definition_representation.definition
property_definition_representation
property_definition_representation.used_representation -> representation
{representation.name = 'quantity'}
representation.items[i] -> representation_item 
{representation_item.name = 'quantity measure'}
representation_item => measure_representation_item
	)(
quantified_assembly_component_usage.quantity -> measure_with_unit
	)(
quantified_assembly_component_usage.quantity -> measure_with_unit
	)(
product_definition = characterized_product_definition 
characterized_product_definition = characterized_definition
characterized_definition <- property_definition.definition
property_definition 
{property_definition.name = 'occurrence quantity'}
property_definition = represented_definition 
represented_definition <- property_definition_representation.definition
property_definition_representation
property_definition_representation.used_representation -> representation
{representation.name = 'quantity'}
representation.items[i] -> representation_item 
{representation_item.name = 'quantity measure'}
representation_item => measure_representation_item <=
measure_with_unit <-
quantified_assembly_component_usage.quantity
quantified_assembly_component_usage
	)
end_attribute_mapping;

end_entity_mapping;

entity_mapping Selected_instance(Selected_instance, (product_definition)(assembly_component_usage)(* ([product_definition][assembly_component_usage]) *)
);

mapping_constraints;
(
product_definition
{product_definition.name='selected instance'}
{product_definition.frame_of_reference -> product_definition_context
product_definition_context <= application_context_element 
application_context_element.name = 'part occurrence'}
)(
assembly_component_usage <= product_definition_usage
product_definition_usage <= product_definition_relationship
{product_definition_relationship.name = 'selected instance usage'}
product_definition_relationship.related_product_definition -> product_definition
{product_definition.frame_of_reference -> product_definition_context
product_definition_context <= application_context_element 
application_context_element.name = 'part occurrence'}
	)
(* It is overlapping with 1st alternative fully - so skip it 
(
product_definition
{product_definition.name='selected instance'}
{product_definition.frame_of_reference -> product_definition_context
product_definition_context <= application_context_element 
application_context_element.name = 'part occurrence'}
product_definition <- product_definition_occurrence_relationship.occurrence
product_definition_occurrence_relationship.occurrence_usage -> assembly_component_usage
{assembly_component_usage <= product_definition_usage
product_definition_usage <= product_definition_relationship
product_definition_relationship.name = 'selected instance usage'}
	) *)
end_mapping_constraints;

attribute_mapping quantity_criterion(quantity_criterion, (descriptive_representation_item.description)(descriptive_representation_item.description));
(
assembly_component_usage <= product_definition_usage 
product_definition_usage <= product_definition_relationship
characterized_product_definition = product_definition_relationship
characterized_definition = characterized_product_definition
characterized_definition <- property_definition.definition
property_definition 
{property_definition.name = 'occurrence selection'}
represented_definition = property_definition
represented_definition <- property_definition_representation.definition
property_definition_representation
property_definition_representation.used_representation -> representation
{representation.name = 'selection criteria'}
representation.items[i] -> representation_item
representation_item => descriptive_representation_item
{representation_item.name = 'selection control'}
descriptive_representation_item.description
)(
product_definition = characterized_product_definition
characterized_product_definition = characterized_definition
characterized_definition <- property_definition.definition
property_definition 
{property_definition.name = 'occurrence selection'}
represented_definition = property_definition
represented_definition <- property_definition_representation.definition
property_definition_representation
property_definition_representation.used_representation -> representation
{representation.name = 'selection criteria'}
representation.items[i] -> representation_item
representation_item => descriptive_representation_item
{representation_item.name = 'selection control'}
descriptive_representation_item.description
)
end_attribute_mapping;

end_entity_mapping;

entity_mapping Single_instance(Single_instance, 
(product_definition)
(* We are not supporting those alternatives
(assembly_component_usage) 
(assembly_component_usage)*)
(product_definition));

mapping_constraints;
(
product_definition
{product_definition.name='single instance'}
(* 
{product_definition.frame_of_reference -> product_definition_context
product_definition_context <= application_context_element 
application_context_element.name = 'part occurrence'} *)
)
(* We are not supporting those alternatives
(
assembly_component_usage <= product_definition_usage
product_definition_usage <= product_definition_relationship
product_definition_relationship.related_product_definition -> product_definition
{product_definition.frame_of_reference -> product_definition_context
product_definition_context <= application_context_element 
application_context_element.name = 'part definition'}
	)(
assembly_component_usage <= product_definition_usage
product_definition_usage <= product_definition_relationship
product_definition_relationship.related_product_definition -> product_definition
{product_definition.frame_of_reference -> product_definition_context
product_definition_context <= application_context_element 
application_context_element.name = 'part occurrence'}
	) 
*)
	(
product_definition
{product_definition.name='single instance'}
(* {product_definition.frame_of_reference -> product_definition_context
product_definition_context <= application_context_element 
application_context_element.name = 'part occurrence'} *)
product_definition <- product_definition_occurrence_relationship.occurrence
product_definition_occurrence_relationship.occurrence_usage -> assembly_component_usage
	)
end_mapping_constraints;

end_entity_mapping;

entity_mapping Specification_based_product_occurrence(Specification_based_product_occurrence, 
product_definition
);

mapping_constraints;

end_mapping_constraints;

attribute_mapping defined_version(defined_version, $PATH, Specification_based_product_version);

product_definition
product_definition.formation -> product_definition_formation
{product_definition_formation = configuration_design_item
configuration_design_item <- configuration_design.design
{configuration_design.name = 'product design'}
configuration_design.configuration -> configuration_item
(configuration_item => product_identification)
(configuration_item => product_identification
product_identification => product_specification)}

end_attribute_mapping;

end_entity_mapping;
(*end_schema_mapping;*)
