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

(*
   Not Derived from any EXPRESS stepmod schema
   by LKSoftWare GmbH for implementation purpose within IDA-STEP(TM)
*)

SCHEMA ida_step_aim_schema;

--TOP schemas
-- AP239 - add just TOP module - requested by Eva
USE FROM ap239_product_life_cycle_support_mim;
USE FROM automotive_design;
USE FROM Ap203_configuration_controlled_3d_design_of_mechanical_parts_and_assemblies_mim;
USE FROM Ap210_electronic_assembly_interconnect_and_packaging_design_mim;
USE FROM Ap236_furniture_catalog_and_interior_design_mim;

-- Schemas not accessable by any of TOP schemas
-- Needed by EUCAM
USE FROM picture_representation_mim;

USE FROM product_as_individual_assembly_mim;

-- USE FROM Activity_relationship_specialization_mim; - no mim, only xim
--USE FROM annotated_presentation_mim;
USE FROM dimension_and_tolerance_callouts_mim;
USE FROM mechanical_design_geometric_presentation_mim;

USE FROM draughting_dimension_schema; -- ISO 10303-101 (TC1, WG12 N268)
USE FROM finite_element_analysis_control_and_result_schema; -- ISO 10303-104
-- Express schema not found in CVS
-- USE FROM finite_element_analysis_definition_relationships_schema; -- ISO/CD 10303-107
-- USE FROM finite_element_analysis_scalar_vector_tensor_schema; -- ISO 10303-104
USE FROM kinematic_motion_representation_schema; -- ISO 10303-105
USE FROM mathematical_functions_schema; -- ISO/DIS 10303-50 (WG12 N557)
USE FROM structural_response_definition_schema; -- ISO 10303-104
USE FROM structural_response_representation_schema; -- ISO 10303-104

--USE FROM aic_drawing_structure_and_administration; -- ISO 10303-505
USE FROM aic_elementary_brep; -- ISO 10303-513 (WG12 N476)

REFERENCE FROM product_property_definition_schema(acyclic_shape_aspect_relationship);

-- AP236 models causing problems at MIM level
USE FROM manufacturing_configuration_effectivity_mim;

-- Needed in order to make IDA_STEP_XIM compilable
USE FROM configuration_management_schema(configuration_design_item);
USE FROM management_resources_schema(position_in_organization_role);

-- from structural_analysis_design
TYPE retention_item = SELECT
  (control,
   document,
   material_property,
   product,
   product_definition,
   product_definition_formation,
   product_definition_relationship,
   representation,
   result);
END_TYPE;

-- from associative_draughting

TYPE draughting_group_element = SELECT
  (annotation_occurrence,
   point,
   curve,
   surface);
END_TYPE;

-- from explicit_draughting

TYPE draughting_grouped_item = EXTENSIBLE GENERIC_ENTITY SELECT;END_TYPE;


-- from technical_data_packaging
ENTITY externally_defined_planar_box
SUBTYPE OF (externally_defined_item, 
  planar_box);
END_ENTITY;

ENTITY externally_defined_symbol_and_placement
SUBTYPE OF (externally_defined_symbol, 
  placement);
END_ENTITY;

ENTITY make_from_usage_option_with_reference_designator
 SUBTYPE OF (make_from_usage_option, assembly_component_usage);
END_ENTITY;

ENTITY other_list_table_representation
  SUBTYPE OF (representation);
END_ENTITY;


-- from structural_analysis_design

ENTITY point_representation
  SUBTYPE OF (shape_representation);
END_ENTITY;

ENTITY retention_assignment
  SUBTYPE OF (action_assignment);
  items : SET [1:?] OF retention_item;
END_ENTITY;
(*
ENTITY smeared_material_definition
  SUBTYPE OF (product_definition);
END_ENTITY;
*)
-- from associative_draughting

ENTITY draughting_group_elements_assignment
  SUBTYPE OF (group_assignment);
  items : SET [1:?] OF draughting_group_element;
END_ENTITY;

ENTITY edge_based_2d_wireframe_shape_representation
  SUBTYPE OF (shape_representation);
END_ENTITY;

ENTITY elementary_2d_geometric_curve_set_shape_representation
  SUBTYPE OF (shape_representation);
END_ENTITY;

ENTITY shell_based_2d_wireframe_shape_representation
  SUBTYPE OF (shape_representation);
END_ENTITY;

-- from ship_moulded_form

ENTITY extended_property_definition
SUBTYPE OF (property_definition);
END_ENTITY;

ENTITY extended_product_definition_shape
SUBTYPE OF (product_definition_shape);
END_ENTITY;

ENTITY extended_product_related_product_category
SUBTYPE OF (product_related_product_category);
END_ENTITY;

-- from explicit_draughting

ENTITY draughting_group_assignment
  SUBTYPE OF (group_assignment);
    items : SET [1:?] OF draughting_grouped_item;
END_ENTITY;

-- BUILDING_DESIGN_SCHEMA
ENTITY building_complex
          SUBTYPE OF (product_definition);
END_ENTITY;

-- from ap212
ENTITY terminal
  SUBTYPE OF (shape_aspect);
WHERE
  WR1:  SELF\shape_aspect.product_definitional = UNKNOWN;
  WR2:  'ELECTROTECHNICAL_DESIGN.PRODUCT_DEFINITION' IN
        TYPEOF(SELF\shape_aspect.of_shape\property_definition.definition);
  WR3:  SELF\shape_aspect.of_shape\property_definition.definition.
        frame_of_reference\application_context_element.name
        IN ['functional definition',
            'functional occurrence',
            'part definition',
            'part occurrence'];
  WR4:  SELF\shape_aspect.of_shape\property_definition.definition.name
        = 'single instance';
  WR5:  SIZEOF(QUERY(des <* USEDIN(SELF, 'ELECTROTECHNICAL_DESIGN.' +
                                         'ITEM_DESIGNATION_ASSIGNMENT.' +
                                         'ITEMS') |
                 NOT(SIZEOF(TYPEOF(des) *
                            ['ELECTROTECHNICAL_DESIGN.' +
                             'DOCUMENT_DESIGNATION_ASSIGNMENT',
                             'ELECTROTECHNICAL_DESIGN.' +
                             'OBJECT_REFERENCE_DESIGNATION_ASSIGNMENT',
                             'ELECTROTECHNICAL_DESIGN.' +
                             'SIGNAL_DESIGNATION_ASSIGNMENT']
                     ) > 0 ) )
        ) = 0;
  WR6:  SIZEOF(QUERY(des <* USEDIN(SELF, 'ELECTROTECHNICAL_DESIGN.' +
                                         'ITEM_DESIGNATION_ASSIGNMENT.' +
                                         'ITEMS') |
                 ('ELECTROTECHNICAL_DESIGN.' +
                  'TERMINAL_DESIGNATION_ASSIGNMENT'
                  IN TYPEOF(des))
                 AND
                 (des.role.description = 'primary') )
        ) = 1;
  WR7:  SIZEOF(QUERY(sar <* USEDIN(SELF, 'ELECTROTECHNICAL_DESIGN.' +
                                         'SHAPE_ASPECT_RELATIONSHIP.' +
                                         'RELATED_SHAPE_ASPECT') |
          (sar.related_shape_aspect.of_shape\
           property_definition.definition.frame_of_reference\
           application_context_element.name = 'functional occurrence')
          AND
          (sar.name = 'definition usage')
          AND
          ('ELECTROTECHNICAL_DESIGN.TERMINAL'
           IN TYPEOF(sar.relating_shape_aspect))
          AND
          (sar.relating_shape_aspect.of_shape\
           property_definition.definition.frame_of_reference\
           application_context_element.name = 'functional definition')
        )) = 1;
  WR8:  SIZEOF(QUERY(sar <* USEDIN(SELF, 'ELECTROTECHNICAL_DESIGN.' +
                                         'SHAPE_ASPECT_RELATIONSHIP.' +
                                         'RELATED_SHAPE_ASPECT') |
          (sar.related_shape_aspect.of_shape\
           property_definition.definition.frame_of_reference\
           application_context_element.name = 'part occurrence')
          AND
          (sar.name = 'definition usage')
          AND
          ('ELECTROTECHNICAL_DESIGN.TERMINAL'
           IN TYPEOF(sar.relating_shape_aspect))
          AND
          (sar.relating_shape_aspect.of_shape\
           property_definition.definition.frame_of_reference\
           application_context_element.name = 'part definition')
        )) = 1;
  WR9:  SIZEOF(QUERY(sar <* USEDIN(SELF, 'ELECTROTECHNICAL_DESIGN.' +
                                         'SHAPE_ASPECT_RELATIONSHIP.' +
                                         'RELATING_SHAPE_ASPECT') |
          (sar.relating_shape_aspect.of_shape\
           property_definition.definition.frame_of_reference\
           application_context_element.name = 'functional definition')
          AND
          (sar.name = 'correspondence')
          AND
          (NOT('ELECTROTECHNICAL_DESIGN.TERMINAL'
               IN TYPEOF(sar.related_shape_aspect)))
          AND
          (NOT(sar.related_shape_aspect.of_shape\
           property_definition.definition.frame_of_reference\
           application_context_element.name = 'functional occurrence'))
        )) = 0;
  WR10: SIZEOF(QUERY(sar <* USEDIN(SELF, 'ELECTROTECHNICAL_DESIGN.' +
                                         'SHAPE_ASPECT_RELATIONSHIP.' +
                                         'RELATING_SHAPE_ASPECT') |
          (sar.relating_shape_aspect.of_shape\
           property_definition.definition.frame_of_reference\
           application_context_element.name = 'part definition')
          AND
          (sar.name = 'correspondence')
          AND
          ('ELECTROTECHNICAL_DESIGN.TERMINAL'
           IN TYPEOF(sar.related_shape_aspect))
          AND
          (sar.related_shape_aspect.of_shape\
           property_definition.definition.frame_of_reference\
           application_context_element.name = 'part occurrence')
        )) <= 1;
  WR11: SIZEOF(QUERY(corr_mem <*
                       QUERY(sar <* USEDIN(SELF,
                                      'ELECTROTECHNICAL_DESIGN.' +
                                      'SHAPE_ASPECT_RELATIONSHIP.' +
                                      'RELATING_SHAPE_ASPECT') |
                         (sar.relating_shape_aspect.of_shape\
                          property_definition.definition.
                          frame_of_reference\application_context_element.
                          name = 'functional definition')
                         AND
                         (sar.name = 'correspondence')) |
                 NOT(SIZEOF(QUERY(next_corr_mem <*
                                QUERY(sar <* (USEDIN(SELF,
                                             'ELECTROTECHNICAL_DESIGN.' +
                                             'SHAPE_ASPECT_RELATIONSHIP.' +
                                             'RELATING_SHAPE_ASPECT')
                                            - corr_mem) |
                              (sar.relating_shape_aspect.of_shape\
                               property_definition.definition.
                               frame_of_reference\
                               application_context_element.
                               name = 'functional definition')
                              AND
                              (sar.name = 'correspondence')) |
                              corr_mem.related_shape_aspect =
                              next_corr_mem.related_shape_aspect
                     )) = 0)
        )) = 0;
END_ENTITY;

TYPE item_designation_item = SELECT 
  (assembly_component_usage,
   drawing_revision,
   drawing_sheet_revision,
   installation_location,
   product,
   product_definition,
   product_definition_formation,
   signal,
   terminal);
END_TYPE;

ENTITY installation_location
  SUBTYPE OF (shape_aspect);
WHERE
  WR1:  SIZEOF(TYPEOF(SELF) *
          ['ELECTROTECHNICAL_DESIGN.PRODUCT_DEFINITION',
           'ELECTROTECHNICAL_DESIGN.SPECIFIED_HIGHER_USAGE_OCCURRENCE']
        ) = 1;
  WR2:  SELF.of_shape.definition\product_definition.frame_of_reference.name
        IN ['conceptual definition',
            'functional definition',
            'functional occurrence',
            'part definition',
            'part occurrence',
            'physical occurrence',
            'system definition'];
  WR3:  ( (SELF.of_shape.definition\product_definition_relationship.
           relating_product_definition.frame_of_reference.name
           = 'functional definition')
          AND
          (SELF.of_shape.definition\product_definition_relationship.
           related_product_definition.frame_of_reference.name
           = 'functional occurrence') )
        XOR
        ( (SELF.of_shape.definition\product_definition_relationship.
           relating_product_definition.frame_of_reference.name
           = 'part definition')
           AND
           (SELF.of_shape.definition\product_definition_relationship.
            related_product_definition.frame_of_reference.name
            = 'part occurrence') )
        AND
        (SELF.of_shape.definition\product_definition_relationship.
         related_product_definition.name = 'single instance');
  WR4:  SIZEOF(QUERY(des <* USEDIN(SELF, 'ELECTROTECHNICAL_DESIGN.' +
                                         'ITEM_DESIGNATION_ASSIGNMENT.' +
                                         'ITEMS') |
                 SIZEOF(TYPEOF(des) *
                          ['ELECTROTECHNICAL_DESIGN.' +
                           'DOCUMENT_DESIGNATION_ASSIGNMENT',
                           'ELECTROTECHNICAL_DESIGN.' +
                           'SIGNAL_DESIGNATION_ASSIGNMENT',
                           'ELECTROTECHNICAL_DESIGN.' +
                           'TERMINAL_DESIGNATION_ASSIGNMENT']
                 ) > 0 )
        ) = 0;
  WR5:  SIZEOF(QUERY(des <* USEDIN(SELF, 'ELECTROTECHNICAL_DESIGN.' +
                                         'ITEM_DESIGNATION_ASSIGNMENT.' +
                                         'ITEMS') |
                 ('ELECTROTECHNICAL_DESIGN.' +
                  'OBJECT_REFERENCE_DESIGNATION_ASSIGNMENT'
                  IN TYPEOF(des))
                 AND
                 (des.role.description = 'primary') )
        ) = 1;
  WR6:  SIZEOF(QUERY(i <* USEDIN(SELF,
                                 'ELECTROTECHNICAL_DESIGN.' +
                                 'APPLIED_IDENTIFICATION_ASSIGNMENT.' +
                                 'ITEMS') |
                 i.role.name = 'version')
        ) < 2;
END_ENTITY;

ENTITY item_designation_assignment
  SUBTYPE OF (identification_assignment);
  items : SET [1:?] OF item_designation_item;
WHERE
  WR1:  SIZEOF(SELF.items) = 1;
  WR2:  SELF\identification_assignment.role.description
        IN ['alias', 'primary'];
  WR3:  NOT(SELF\identification_assignment.role.name
            IN ['alias', 'id', 'version']);
  WR4:  SIZEOF(QUERY(aca <* USEDIN(SELF,
                                   'ELECTROTECHNICAL_DESIGN.' +
                                   'APPLIED_CLASSIFICATION_ASSIGNMENT.' +
                                   'ITEMS') |
                 'ELECTROTECHNICAL_DESIGN.CLASS_SYSTEM'
                 IN TYPEOF(aca.assigned_class) )
        ) < 2;
  WR5:  SIZEOF(QUERY(aoa <* USEDIN(SELF,
                                   'ELECTROTECHNICAL_DESIGN.' +
                                   'APPLIED_ORGANIZATION_ASSIGNMENT.' +
                                   'ITEMS') |
                     aoa.role.name = 'item designation scope')
        ) < 2;
  WR6:  SIZEOF(QUERY(i <* USEDIN(SELF,
                                 'ELECTROTECHNICAL_DESIGN.' +
                                 'APPLIED_IDENTIFICATION_ASSIGNMENT.' +
                                 'ITEMS') |
                     i.role.name = 'version')
        ) < 2;
END_ENTITY;

ENTITY terminal_designation_assignment
  SUBTYPE OF (item_designation_assignment);
WHERE
  WR1:  SIZEOF(TYPEOF(SELF.items[1]) *
                 ['ELECTROTECHNICAL_DESIGN.TERMINAL']
        ) = 1;
  WR2:  SIZEOF(TYPEOF(SELF) *
                 ['ELECTROTECHNICAL_DESIGN.' +
                  'DOCUMENT_DESIGNATION_ASSIGNMENT',
                  'ELECTROTECHNICAL_DESIGN.' +
                  'OBJECT_REFERENCE_DESIGNATION_ASSIGNMENT',
                  'ELECTROTECHNICAL_DESIGN.' +
                  'SIGNAL_DESIGNATION_ASSIGNMENT',
                  'ELECTROTECHNICAL_DESIGN.' +
                  'TERMINAL_DESIGNATION_ASSIGNMENT']
        ) = 1;
END_ENTITY;

ENTITY connectivity_definition
  SUBTYPE OF (shape_aspect);
WHERE
  WR1:  SELF\shape_aspect.product_definitional = UNKNOWN;
  WR2:  'ELECTROTECHNICAL_DESIGN.PRODUCT_DEFINITION' IN
        TYPEOF(SELF\shape_aspect.of_shape\property_definition.definition);
  WR3:  SELF\shape_aspect.of_shape\property_definition.definition.
        frame_of_reference\application_context_element.name
        IN ['functional definition', 'part definition'];
  WR4:  SIZEOF(QUERY(sar <* USEDIN(SELF, 'ELECTROTECHNICAL_DESIGN.' +
                                         'SHAPE_ASPECT_RELATIONSHIP.' +
                                         'RELATING_SHAPE_ASPECT') |
                 sar.name = 'connectivity') )
        =
        SIZEOF(QUERY(sar <* USEDIN(SELF, 'ELECTROTECHNICAL_DESIGN.' +
                                         'SHAPE_ASPECT_RELATIONSHIP.' +
                                         'RELATING_SHAPE_ASPECT') |
          (sar.name = 'connectivity')
          AND
          (
           (('ELECTROTECHNICAL_DESIGN.TERMINAL'
             IN TYPEOF(sar.related_shape_aspect))
            AND
            (sar.related_shape_aspect.of_shape\
             property_definition.definition.frame_of_reference\
             application_context_element.name = 'functional definition') )
           XOR
           (('ELECTROTECHNICAL_DESIGN.TERMINAL'
             IN TYPEOF(sar.related_shape_aspect))
            AND
            (sar.related_shape_aspect.of_shape\
             property_definition.definition.frame_of_reference\
             application_context_element.name = 'functional occurrence') )
           XOR
           (('ELECTROTECHNICAL_DESIGN.TERMINAL'
             IN TYPEOF(sar.related_shape_aspect))
            AND
            (sar.related_shape_aspect.of_shape\
             property_definition.definition.frame_of_reference\
             application_context_element.name = 'part definition') )
           XOR
           (('ELECTROTECHNICAL_DESIGN.TERMINAL'
             IN TYPEOF(sar.related_shape_aspect))
            AND
            (sar.related_shape_aspect.of_shape\
             property_definition.definition.frame_of_reference\
             application_context_element.name = 'part occurrence') )
          ) ) );
  WR5:  SIZEOF(QUERY(conn_mem <* QUERY(sar <* USEDIN(SELF,
                                             'ELECTROTECHNICAL_DESIGN.' +
                                             'SHAPE_ASPECT_RELATIONSHIP.' +
                                             'RELATING_SHAPE_ASPECT') |
                                   sar.name = 'connectivity') |
                 NOT(SIZEOF(QUERY(next_conn_mem <*
                                QUERY(sar <* (USEDIN(SELF,
                                             'ELECTROTECHNICAL_DESIGN.' +
                                             'SHAPE_ASPECT_RELATIONSHIP.' +
                                             'RELATING_SHAPE_ASPECT')
                                             - conn_mem) |
                                  sar.name = 'connectivity') |
                              conn_mem.related_shape_aspect =
                              next_conn_mem.related_shape_aspect
                     )) = 0)
        )) = 0;
  WR6:  SIZEOF(QUERY(bund_mem <* QUERY(sar <* USEDIN(SELF,
                                             'ELECTROTECHNICAL_DESIGN.' +
                                             'SHAPE_ASPECT_RELATIONSHIP.' +
                                             'RELATING_SHAPE_ASPECT') |
                                   sar.name = 'decomposition') |
                 NOT(SIZEOF(QUERY(next_bund_mem <*
                                QUERY(sar <* (USEDIN(SELF,
                                             'ELECTROTECHNICAL_DESIGN.' +
                                             'SHAPE_ASPECT_RELATIONSHIP.' +
                                             'RELATING_SHAPE_ASPECT')
                                             - bund_mem) |
                                  sar.name = 'decomposition') |
                              bund_mem.related_shape_aspect =
                              next_bund_mem.related_shape_aspect
                     )) = 0)
        )) = 0;
  WR7:  SIZEOF(QUERY(sar1 <* QUERY(sar2 <* USEDIN(SELF,
                                             'ELECTROTECHNICAL_DESIGN.' +
                                             'SHAPE_ASPECT_RELATIONSHIP.' +
                                             'RELATING_SHAPE_ASPECT') |
                               sar2.name = 'decomposition') |
                 NOT(acyclic_shape_aspect_relationship(sar1, [SELF],
                                             'ELECTROTECHNICAL_DESIGN.' +
                                             'SHAPE_ASPECT_RELATIONSHIP.' +
                                             'RELATED_SHAPE_ASPECT'))
        )) = 0;
  WR8:  SIZEOF(QUERY(sar1 <* QUERY(sar2 <* USEDIN(SELF,
                                             'ELECTROTECHNICAL_DESIGN.' +
                                             'SHAPE_ASPECT_RELATIONSHIP.' +
                                             'RELATING_SHAPE_ASPECT') |
                               sar2.name = 'decomposition') |
                 NOT(acyclic_shape_aspect_relationship(sar1, [SELF],
                                             'ELECTROTECHNICAL_DESIGN.' +
                                             'SHAPE_ASPECT_RELATIONSHIP.' +
                                             'RELATED_SHAPE_ASPECT'))
        )) = 0;
  WR9: SIZEOF(QUERY(i <* USEDIN(SELF,
                                 'ELECTROTECHNICAL_DESIGN.' +
                                 'APPLIED_IDENTIFICATION_ASSIGNMENT.' +
                                 'ITEMS') |
                 i.role.name = 'version')
        ) < 2;
END_ENTITY;

ENTITY presentation_with_association
  SUBTYPE OF (presentation_representation);
WHERE
  WR1:  SIZEOF(SELF\representation.items) = 1;
  WR2:  SIZEOF(QUERY(pir <* USEDIN(SELF, 'ELECTROTECHNICAL_DESIGN.' +
                                         'PRESENTED_ITEM_REPRESENTATION.' +
                                         'PRESENTATION') |
                 NOT('ELECTROTECHNICAL_DESIGN.' +
                     'PRESENTATION_WITH_ASSOCIATION'
                     IN TYPEOF(pir.item)))
        ) = 0;
END_ENTITY;


END_SCHEMA;