/* file: camera_image.swift 	 generated: Mon Jan  3 16:32:52 2022 */

/* This file was generated by the EXPRESS to Swift translator "exp2swift", 
    derived from STEPcode (formerly NIST's SCL).
 exp2swift version: v.1.0.1, derived from stepcode v0.8 as of 2019/11/23 
 WARNING: You probably don't want to edit it since your modifications 
    will be lost if exp2swift is used to regenerate it.
 */

 
import SwiftSDAIcore

extension AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF {
//MARK: -ENTITY DEFINITION in EXPRESS
/*

  ENTITY camera_image
    SUPERTYPE OF ( 
        ONEOF ( 
            camera_image_2d_with_scale, 
            camera_image_3d_with_scale ) )
    SUBTYPE OF ( mapped_item );
      SELF\mapped_item.mapping_source : camera_usage;
      SELF\mapped_item.mapping_target : planar_box;
    WHERE
      wr1: ( 'AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF.GEOMETRIC_REPRESENTATION_ITEM' IN TYPEOF( SELF ) );
  END_ENTITY; -- camera_image (line:8731 file:ap242ed2_mim_lf_v1.101.TY.exp)

*/


//MARK: - ALL DEFINED ATTRIBUTES
/*
  SUPER- ENTITY(1)	representation_item
    ATTR:  name,	TYPE: label -- EXPLICIT


  SUPER- ENTITY(2)	mapped_item
    ATTR:  mapping_source,	TYPE: representation_map -- EXPLICIT
      -- observed by
        ENTITY(1): representation_map,	ATTR: map_usage,	TYPE: SET [1 : ?] OF mapped_item
      -- possibly overriden by
      *** ENTITY: camera_image,	TYPE: camera_usage
          ENTITY: annotation_symbol,	TYPE: symbol_representation_map

    ATTR:  mapping_target,	TYPE: representation_item -- EXPLICIT
      -- possibly overriden by
          ENTITY: annotation_text_character,	TYPE: axis2_placement
      *** ENTITY: camera_image,	TYPE: planar_box
          ENTITY: annotation_text,	TYPE: axis2_placement
          ENTITY: annotation_symbol,	TYPE: symbol_target


  ENTITY(SELF)	camera_image
    REDCR: mapping_source,	TYPE: camera_usage -- EXPLICIT
      -- OVERRIDING ENTITY: mapped_item

    REDCR: mapping_target,	TYPE: planar_box -- EXPLICIT
      -- OVERRIDING ENTITY: mapped_item


  SUB- ENTITY(4)	camera_image_3d_with_scale
    ATTR:  scale,	TYPE: positive_ratio_measure -- DERIVED	(AMBIGUOUS/MASKED)
      := SELF\mapped_item.mapping_target\planar_extent.size_in_x / SELF\mapped_item.mapping_source.
        mapping_origin\camera_model_d3.perspective_of_volume.view_window.size_in_x


  SUB- ENTITY(5)	camera_image_2d_with_scale
    ATTR:  scale,	TYPE: positive_ratio_measure -- DERIVED	(AMBIGUOUS/MASKED)
      := SELF\mapped_item.mapping_target\planar_extent.size_in_x / SELF\mapped_item.mapping_source.
        mapping_origin\camera_model_d2.view_window\planar_extent.size_in_x


*/


//MARK: - Partial Entity
  public final class _camera_image : SDAI.PartialEntity {
    public override class var entityReferenceType: SDAI.EntityReference.Type {
      eCAMERA_IMAGE.self
    }

    //ATTRIBUTES
    /* override var _mapping_source: eCAMERA_USAGE	//EXPLICIT REDEFINITION(eMAPPED_ITEM) */

    /* override var _mapping_target: ePLANAR_BOX	//EXPLICIT REDEFINITION(eMAPPED_ITEM) */

    public override var typeMembers: Set<SDAI.STRING> {
      var members = Set<SDAI.STRING>()
      members.insert(SDAI.STRING(Self.typeName))
      return members
    }


    //VALUE COMPARISON SUPPORT
    public override func hashAsValue(into hasher: inout Hasher, visited complexEntities: inout Set<SDAI.ComplexEntity>) {
      super.hashAsValue(into: &hasher, visited: &complexEntities)
    }

    public override func isValueEqual(to rhs: SDAI.PartialEntity, visited comppairs: inout Set<SDAI.ComplexPair>) -> Bool {
      guard let rhs = rhs as? Self else { return false }
      if !super.isValueEqual(to: rhs, visited: &comppairs) { return false }
      return true
    }

    public override func isValueEqualOptionally(to rhs: SDAI.PartialEntity, visited comppairs: inout Set<SDAI.ComplexPair>) -> Bool? {
      guard let rhs = rhs as? Self else { return false }
      var result: Bool? = true
      if let comp = super.isValueEqualOptionally(to: rhs, visited: &comppairs) {
        if !comp { return false }
      }
      else { result = nil }
      return result
    }


    //MARK: WHERE RULES (ENTITY)
    public static func WHERE_wr1(SELF: eCAMERA_IMAGE?) -> SDAI.LOGICAL {
      guard let SELF = SELF else { return SDAI.UNKNOWN }

      let _TEMP1 = SDAI.TYPEOF(SELF, IS: eGEOMETRIC_REPRESENTATION_ITEM.self)
      return _TEMP1
    }

    //EXPRESS IMPLICIT PARTIAL ENTITY CONSTRUCTOR
    public init() {
      super.init(asAbstructSuperclass:())

    }

    //p21 PARTIAL ENTITY CONSTRUCTOR
    public required convenience init?(parameters: [P21Decode.ExchangeStructure.Parameter], exchangeStructure: P21Decode.ExchangeStructure) {
      let numParams = 0
      guard parameters.count == numParams
      else { exchangeStructure.error = "number of p21 parameters(\(parameters.count)) are different from expected(\(numParams)) for entity(\(Self.entityName)) constructor"; return nil }

      self.init( )
    }
  }


//MARK: - Entity Reference

/** ENTITY reference
- EXPRESS:
```express
  ENTITY camera_image
    SUPERTYPE OF ( 
        ONEOF ( 
            camera_image_2d_with_scale, 
            camera_image_3d_with_scale ) )
    SUBTYPE OF ( mapped_item );
      SELF\mapped_item.mapping_source : camera_usage;
      SELF\mapped_item.mapping_target : planar_box;
    WHERE
      wr1: ( 'AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF.GEOMETRIC_REPRESENTATION_ITEM' IN TYPEOF( SELF ) );
  END_ENTITY; -- camera_image (line:8731 file:ap242ed2_mim_lf_v1.101.TY.exp)

```
*/
  public final class eCAMERA_IMAGE : SDAI.EntityReference {

    //MARK: PARTIAL ENTITY
    public override class var partialEntityType: SDAI.PartialEntity.Type {
      _camera_image.self
    }
    public let partialEntity: _camera_image

    //MARK: SUPERTYPES
    public let super_eREPRESENTATION_ITEM: eREPRESENTATION_ITEM 	// [1]
    public let super_eMAPPED_ITEM: eMAPPED_ITEM 	// [2]
    public var super_eCAMERA_IMAGE: eCAMERA_IMAGE { return self } 	// [3]

    //MARK: SUBTYPES
    public var sub_eCAMERA_IMAGE_3D_WITH_SCALE: eCAMERA_IMAGE_3D_WITH_SCALE? {	// [4]
      return self.complexEntity.entityReference(eCAMERA_IMAGE_3D_WITH_SCALE.self)
    }

    public var sub_eCAMERA_IMAGE_2D_WITH_SCALE: eCAMERA_IMAGE_2D_WITH_SCALE? {	// [5]
      return self.complexEntity.entityReference(eCAMERA_IMAGE_2D_WITH_SCALE.self)
    }


    //MARK: ATTRIBUTES
    // SCALE: (2 AMBIGUOUS REFs)

    /// __EXPLICIT REDEF__ attribute
    /// - origin: SELF( ``eCAMERA_IMAGE`` )
    public var MAPPING_SOURCE: eCAMERA_USAGE {
      get {
        return SDAI.UNWRAP( eCAMERA_USAGE( super_eMAPPED_ITEM.partialEntity._mapping_source ) )
      }
      set(newValue) {
        let partial = super_eMAPPED_ITEM.partialEntity
        partial._mapping_source = SDAI.UNWRAP(
          eREPRESENTATION_MAP(newValue))
      }
    }

    /// __EXPLICIT REDEF__ attribute
    /// - origin: SELF( ``eCAMERA_IMAGE`` )
    public var MAPPING_TARGET: ePLANAR_BOX {
      get {
        return SDAI.UNWRAP( ePLANAR_BOX( super_eMAPPED_ITEM.partialEntity._mapping_target ) )
      }
      set(newValue) {
        let partial = super_eMAPPED_ITEM.partialEntity
        partial._mapping_target = SDAI.UNWRAP(
          eREPRESENTATION_ITEM(newValue))
      }
    }

    /// __EXPLICIT__ attribute
    /// - origin: SUPER( ``eREPRESENTATION_ITEM`` )
    public var NAME: tLABEL {
      get {
        return SDAI.UNWRAP( super_eREPRESENTATION_ITEM.partialEntity._name )
      }
      set(newValue) {
        let partial = super_eREPRESENTATION_ITEM.partialEntity
        partial._name = SDAI.UNWRAP(newValue)
      }
    }


    //MARK: INITIALIZERS
    public convenience init?(_ entityRef: SDAI.EntityReference?) {
      let complex = entityRef?.complexEntity
      self.init(complex: complex)
    }

    public required init?(complex complexEntity: SDAI.ComplexEntity?) {
      guard let partial = complexEntity?.partialEntityInstance(_camera_image.self) else { return nil }
      self.partialEntity = partial

      guard let super1 = complexEntity?.entityReference(eREPRESENTATION_ITEM.self) else { return nil }
      self.super_eREPRESENTATION_ITEM = super1

      guard let super2 = complexEntity?.entityReference(eMAPPED_ITEM.self) else { return nil }
      self.super_eMAPPED_ITEM = super2

      super.init(complex: complexEntity)
    }

    public required convenience init?<G: SDAIGenericType>(fromGeneric generic: G?) {
      guard let entityRef = generic?.entityReference else { return nil }
      self.init(complex: entityRef.complexEntity)
    }

    public convenience init?<S: SDAISelectType>(_ select: S?) { self.init(possiblyFrom: select) }
    public convenience init?(_ complex: SDAI.ComplexEntity?) { self.init(complex: complex) }


    //MARK: WHERE RULE VALIDATION (ENTITY)
    public override class func validateWhereRules(instance:SDAI.EntityReference?, prefix:SDAI.WhereLabel) -> [SDAI.WhereLabel:SDAI.LOGICAL] {
      guard let instance = instance as? Self else { return [:] }

      let prefix2 = prefix + " \(instance)"

      var result = super.validateWhereRules(instance:instance, prefix:prefix2)
      result[prefix2 + " .WHERE_wr1"] = _camera_image.WHERE_wr1(SELF: instance)
      return result
    }


    //MARK: DICTIONARY DEFINITION
    public class override var entityDefinition: SDAIDictionarySchema.EntityDefinition { _entityDefinition }
    private static let _entityDefinition: SDAIDictionarySchema.EntityDefinition = createEntityDefinition()

    private static func createEntityDefinition() -> SDAIDictionarySchema.EntityDefinition {
      let entityDef = SDAIDictionarySchema.EntityDefinition(name: "CAMERA_IMAGE", type: self, explicitAttributeCount: 0)

      //MARK: SUPERTYPE REGISTRATIONS
      entityDef.add(supertype: eREPRESENTATION_ITEM.self)
      entityDef.add(supertype: eMAPPED_ITEM.self)
      entityDef.add(supertype: eCAMERA_IMAGE.self)

      //MARK: ATTRIBUTE REGISTRATIONS
      entityDef.addAttribute(name: "MAPPING_SOURCE", keyPath: \eCAMERA_IMAGE.MAPPING_SOURCE, 
        kind: .explicitRedeclaring, source: .thisEntity, mayYieldEntityReference: true)
      entityDef.addAttribute(name: "MAPPING_TARGET", keyPath: \eCAMERA_IMAGE.MAPPING_TARGET, 
        kind: .explicitRedeclaring, source: .thisEntity, mayYieldEntityReference: true)
      entityDef.addAttribute(name: "NAME", keyPath: \eCAMERA_IMAGE.NAME, 
        kind: .explicit, source: .superEntity, mayYieldEntityReference: false)

      return entityDef
    }

  }
}
