(*
 * $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 N3226 - ISO/TS 10303-1126 Document properties - EXPRESS ARM
by LKSoftWare GmbH for implementation purpose within IDA-STEP(TM)
*) 


SCHEMA Document_properties_xim;

USE FROM Document_definition_xim;    -- ISO/TS 10303-1123

USE FROM File_identification_xim;    -- ISO/TS 10303-1127

USE FROM Foundation_representation_xim;    -- ISO/TS 10303-1006

USE FROM Measure_representation_xim;    -- ISO/TS 10303-1118

USE FROM Property_assignment_xim;    -- ISO/TS 10303-1030


TYPE descriptive_or_numerical = SELECT
   (Descriptive_document_property, 
    Numerical_document_property);
END_TYPE; 

TYPE document_property_item = SELECT BASED_ON property_assignment_select WITH 
   (Document_definition, 
    File);
END_TYPE; 

ENTITY Assigned_document_property
  (* CONNOTATIONAL *) SUBTYPE OF (Assigned_property);
  SELF\Assigned_property.described_element : document_property_item;
DERIVE
  SELF\Assigned_property.name : STRING := 'document property';
UNIQUE
  UR1: SELF\Assigned_property.described_element;
WHERE
  WR1: SIZEOF(['DOCUMENT_PROPERTIES_XIM.DOCUMENT_DEFINITION', 'DOCUMENT_PROPERTIES_XIM.FILE']*TYPEOF(SELF\Assigned_property.described_element)) = 1;
END_ENTITY;

ENTITY Descriptive_document_property
  (* CONNOTATIONAL *) SUBTYPE OF (descriptive_representation_item);
INVERSE
  valued_characteristic : SET[1:1] OF Document_property_representation FOR items;
END_ENTITY;

ENTITY Document_property_representation
  (* CONNOTATIONAL *) SUBTYPE OF (Representation);
  SELF\Representation.items : SET[1:?] OF descriptive_or_numerical;
WHERE
  WR1: SIZEOF(QUERY( pr <* USEDIN(SELF, 'PROPERTY_ASSIGNMENT_XIM.PROPERTY_DEFINITION_REPRESENTATION.REP') | 'DOCUMENT_PROPERTIES_XIM.ASSIGNED_PROPERTY' IN TYPEOF (pr\property_definition_representation.definition)))> 0;
  WR2: SELF\Representation.context_of_items.kind = 'document parameters';
  WR3: valid_document_property_representation(SELF);
  WR4: SIZEOF(QUERY(it1 <* SELF\Representation.items | SIZEOF(QUERY(it2 <* SELF\Representation.items | it1.name = it2.name)) > 1 ))= 0;
END_ENTITY;

ENTITY Numerical_document_property
  (* CONNOTATIONAL *) SUBTYPE OF (measure_representation_item);
-- DERIVE
	(* It must be set here !!! *)
--  SELF\measure_with_unit.unit_component : unit := ?;
INVERSE
  valued_characteristic : SET[1:1] OF Document_property_representation FOR items;
END_ENTITY;

FUNCTION valid_document_property_representation
 (rep : Document_property_representation) : LOGICAL; 

CASE rep.name OF
'document content': 
   BEGIN
RETURN (
  SIZEOF(QUERY( items <* rep\Representation.items | 
  NOT (items.name IN ['detail level', 'geometry type', 'real world scale'])))= 0
 );
   END;

'document creation': 
   BEGIN
IF NOT (SIZEOF(QUERY( items <* rep\Representation.items | 
  NOT (items.name IN ['creating interface', 'creating system', 'operating system'])))= 0
 ) THEN
  RETURN(FALSE);
END_IF;
IF NOT (SIZEOF(QUERY( items <* rep\Representation.items | 
  NOT (items.name IN ['creating system'])))= 1
 ) THEN
  RETURN(FALSE);
ELSE
  RETURN(TRUE);
END_IF;

   END;

'document format': 
   BEGIN
RETURN (
  SIZEOF(QUERY( items <* rep\Representation.items | 
  NOT (items.name IN ['character code', 'data format', 'size format', 'size format standard'])))= 0
 );
   END;

'document size': 
   BEGIN
RETURN (
  SIZEOF(QUERY( items <* rep\Representation.items | 
  NOT (items.name IN ['file size', 'page count'])))= 0
 );
   END;

OTHERWISE:
  RETURN(UNKNOWN);
END_CASE;
        END_FUNCTION; 

END_SCHEMA;  -- Document_properties_arm
