/* file: elementary_surface.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 elementary_surface
    SUPERTYPE OF ( 
        ONEOF ( 
            plane, 
            cylindrical_surface, 
            conical_surface, 
            spherical_surface, 
            toroidal_surface ) )
    SUBTYPE OF ( surface );
      position  : axis2_placement_3d;
  END_ENTITY; -- elementary_surface (line:13842 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)	geometric_representation_item
    ATTR:  dim,	TYPE: dimension_count -- DERIVED
      := dimension_of( SELF )


  SUPER- ENTITY(3)	surface
    (no local attributes)

  ENTITY(SELF)	elementary_surface
    ATTR:  position,	TYPE: axis2_placement_3d -- EXPLICIT


  SUB- ENTITY(5)	degenerate_toroidal_surface
    ATTR:  select_outer,	TYPE: BOOLEAN -- EXPLICIT


  SUB- ENTITY(6)	toroidal_surface
    ATTR:  major_radius,	TYPE: positive_length_measure -- EXPLICIT

    ATTR:  minor_radius,	TYPE: positive_length_measure -- EXPLICIT


  SUB- ENTITY(7)	spherical_surface
    ATTR:  radius,	TYPE: positive_length_measure -- EXPLICIT	(AMBIGUOUS/MASKED)


  SUB- ENTITY(8)	plane
    (no local attributes)

  SUB- ENTITY(9)	cylindrical_surface
    ATTR:  radius,	TYPE: positive_length_measure -- EXPLICIT	(AMBIGUOUS/MASKED)


  SUB- ENTITY(10)	conical_surface
    ATTR:  radius,	TYPE: length_measure -- EXPLICIT	(AMBIGUOUS/MASKED)

    ATTR:  semi_angle,	TYPE: plane_angle_measure -- EXPLICIT


  SUB- ENTITY(11)	dupin_cyclide_surface
    ATTR:  generalised_major_radius,	TYPE: positive_length_measure -- EXPLICIT

    ATTR:  generalised_minor_radius,	TYPE: positive_length_measure -- EXPLICIT

    ATTR:  skewness,	TYPE: length_measure -- EXPLICIT


*/


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

    //ATTRIBUTES
    /// EXPLICIT ATTRIBUTE 
    public internal(set) var _position: eAXIS2_PLACEMENT_3D // PLAIN EXPLICIT ATTRIBUTE

    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)
      self._position.value.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 }
      if let comp = self._position.value.isValueEqualOptionally(to: rhs._position.value, visited: &comppairs)	{
        if !comp { return false }
      }
      else { 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 }
      if let comp = self._position.value.isValueEqualOptionally(to: rhs._position.value, visited: &comppairs) {
        if !comp { return false }
      }
      else { result = nil }
      return result
    }


    //EXPRESS IMPLICIT PARTIAL ENTITY CONSTRUCTOR
    public init(POSITION: eAXIS2_PLACEMENT_3D) {
      self._position = POSITION
      super.init(asAbstructSuperclass:())

    }

    //p21 PARTIAL ENTITY CONSTRUCTOR
    public required convenience init?(parameters: [P21Decode.ExchangeStructure.Parameter], exchangeStructure: P21Decode.ExchangeStructure) {
      let numParams = 1
      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 }

      guard case .success(let p0) = exchangeStructure.recoverRequiredParameter(as: eAXIS2_PLACEMENT_3D.self, from: parameters[0])
      else { exchangeStructure.add(errorContext: "while recovering parameter #0 for entity(\(Self.entityName)) constructor"); return nil }

      self.init( POSITION: p0 )
    }
  }


//MARK: - Entity Reference

/** ENTITY reference
- EXPRESS:
```express
  ENTITY elementary_surface
    SUPERTYPE OF ( 
        ONEOF ( 
            plane, 
            cylindrical_surface, 
            conical_surface, 
            spherical_surface, 
            toroidal_surface ) )
    SUBTYPE OF ( surface );
      position  : axis2_placement_3d;
  END_ENTITY; -- elementary_surface (line:13842 file:ap242ed2_mim_lf_v1.101.TY.exp)

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

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

    //MARK: SUPERTYPES
    public let super_eREPRESENTATION_ITEM: eREPRESENTATION_ITEM 	// [1]
    public let super_eGEOMETRIC_REPRESENTATION_ITEM: eGEOMETRIC_REPRESENTATION_ITEM 	// [2]
    public let super_eSURFACE: eSURFACE 	// [3]
    public var super_eELEMENTARY_SURFACE: eELEMENTARY_SURFACE { return self } 	// [4]

    //MARK: SUBTYPES
    public var sub_eDEGENERATE_TOROIDAL_SURFACE: eDEGENERATE_TOROIDAL_SURFACE? {	// [5]
      return self.complexEntity.entityReference(eDEGENERATE_TOROIDAL_SURFACE.self)
    }

    public var sub_eTOROIDAL_SURFACE: eTOROIDAL_SURFACE? {	// [6]
      return self.complexEntity.entityReference(eTOROIDAL_SURFACE.self)
    }

    public var sub_eSPHERICAL_SURFACE: eSPHERICAL_SURFACE? {	// [7]
      return self.complexEntity.entityReference(eSPHERICAL_SURFACE.self)
    }

    public var sub_ePLANE: ePLANE? {	// [8]
      return self.complexEntity.entityReference(ePLANE.self)
    }

    public var sub_eCYLINDRICAL_SURFACE: eCYLINDRICAL_SURFACE? {	// [9]
      return self.complexEntity.entityReference(eCYLINDRICAL_SURFACE.self)
    }

    public var sub_eCONICAL_SURFACE: eCONICAL_SURFACE? {	// [10]
      return self.complexEntity.entityReference(eCONICAL_SURFACE.self)
    }

    public var sub_eDUPIN_CYCLIDE_SURFACE: eDUPIN_CYCLIDE_SURFACE? {	// [11]
      return self.complexEntity.entityReference(eDUPIN_CYCLIDE_SURFACE.self)
    }


    //MARK: ATTRIBUTES
    // RADIUS: (3 AMBIGUOUS REFs)

    /// __EXPLICIT__ attribute
    /// - origin: SUB( ``eTOROIDAL_SURFACE`` )
    public var MAJOR_RADIUS: tPOSITIVE_LENGTH_MEASURE?  {
      get {
        return sub_eTOROIDAL_SURFACE?.partialEntity._major_radius
      }
      set(newValue) {
        guard let partial = sub_eTOROIDAL_SURFACE?.super_eTOROIDAL_SURFACE.partialEntity else { return }
        partial._major_radius = SDAI.UNWRAP(newValue)
      }
    }

    /// __EXPLICIT__ attribute
    /// - origin: SUB( ``eDUPIN_CYCLIDE_SURFACE`` )
    public var GENERALISED_MAJOR_RADIUS: tPOSITIVE_LENGTH_MEASURE?  {
      get {
        return sub_eDUPIN_CYCLIDE_SURFACE?.partialEntity._generalised_major_radius
      }
      set(newValue) {
        guard let partial = sub_eDUPIN_CYCLIDE_SURFACE?.super_eDUPIN_CYCLIDE_SURFACE.partialEntity
          else { return }
        partial._generalised_major_radius = SDAI.UNWRAP(newValue)
      }
    }

    /// __EXPLICIT__ attribute
    /// - origin: SUB( ``eDEGENERATE_TOROIDAL_SURFACE`` )
    public var SELECT_OUTER: SDAI.BOOLEAN?  {
      get {
        return sub_eDEGENERATE_TOROIDAL_SURFACE?.partialEntity._select_outer
      }
      set(newValue) {
        guard let partial = sub_eDEGENERATE_TOROIDAL_SURFACE?.super_eDEGENERATE_TOROIDAL_SURFACE
          .partialEntity else { return }
        partial._select_outer = SDAI.UNWRAP(newValue)
      }
    }

    /// __EXPLICIT__ attribute
    /// - origin: SUB( ``eTOROIDAL_SURFACE`` )
    public var MINOR_RADIUS: tPOSITIVE_LENGTH_MEASURE?  {
      get {
        return sub_eTOROIDAL_SURFACE?.partialEntity._minor_radius
      }
      set(newValue) {
        guard let partial = sub_eTOROIDAL_SURFACE?.super_eTOROIDAL_SURFACE.partialEntity else { return }
        partial._minor_radius = SDAI.UNWRAP(newValue)
      }
    }

    /// __EXPLICIT__ attribute
    /// - origin: SUB( ``eDUPIN_CYCLIDE_SURFACE`` )
    public var SKEWNESS: tLENGTH_MEASURE?  {
      get {
        return sub_eDUPIN_CYCLIDE_SURFACE?.partialEntity._skewness
      }
      set(newValue) {
        guard let partial = sub_eDUPIN_CYCLIDE_SURFACE?.super_eDUPIN_CYCLIDE_SURFACE.partialEntity
          else { return }
        partial._skewness = SDAI.UNWRAP(newValue)
      }
    }

    /// __EXPLICIT__ attribute
    /// - origin: SELF( ``eELEMENTARY_SURFACE`` )
    public var POSITION: eAXIS2_PLACEMENT_3D {
      get {
        return SDAI.UNWRAP( self.partialEntity._position )
      }
      set(newValue) {
        let partial = self.partialEntity
        partial._position = SDAI.UNWRAP(newValue)
      }
    }

    /// __EXPLICIT__ attribute
    /// - origin: SUB( ``eDUPIN_CYCLIDE_SURFACE`` )
    public var GENERALISED_MINOR_RADIUS: tPOSITIVE_LENGTH_MEASURE?  {
      get {
        return sub_eDUPIN_CYCLIDE_SURFACE?.partialEntity._generalised_minor_radius
      }
      set(newValue) {
        guard let partial = sub_eDUPIN_CYCLIDE_SURFACE?.super_eDUPIN_CYCLIDE_SURFACE.partialEntity
          else { return }
        partial._generalised_minor_radius = SDAI.UNWRAP(newValue)
      }
    }

    /// __EXPLICIT__ attribute
    /// - origin: SUB( ``eCONICAL_SURFACE`` )
    public var SEMI_ANGLE: tPLANE_ANGLE_MEASURE?  {
      get {
        return sub_eCONICAL_SURFACE?.partialEntity._semi_angle
      }
      set(newValue) {
        guard let partial = sub_eCONICAL_SURFACE?.super_eCONICAL_SURFACE.partialEntity else { return }
        partial._semi_angle = SDAI.UNWRAP(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)
      }
    }

    /// __DERIVE__ attribute
    /// - origin: SUPER( ``eGEOMETRIC_REPRESENTATION_ITEM`` )
    public var DIM: tDIMENSION_COUNT?  {
      get {
        if let cached = cachedValue(derivedAttributeName:"DIM") {
          return cached.value as! tDIMENSION_COUNT? 
        }
        let origin = super_eGEOMETRIC_REPRESENTATION_ITEM
        let value = tDIMENSION_COUNT(origin.partialEntity._dim__getter(SELF: origin))
        updateCache(derivedAttributeName:"DIM", value:value)
        return value
      }
    }


    //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(_elementary_surface.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(eGEOMETRIC_REPRESENTATION_ITEM.self) else { return nil }
      self.super_eGEOMETRIC_REPRESENTATION_ITEM = super2

      guard let super3 = complexEntity?.entityReference(eSURFACE.self) else { return nil }
      self.super_eSURFACE = super3

      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: 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: "ELEMENTARY_SURFACE", type: self, explicitAttributeCount: 1)

      //MARK: SUPERTYPE REGISTRATIONS
      entityDef.add(supertype: eREPRESENTATION_ITEM.self)
      entityDef.add(supertype: eGEOMETRIC_REPRESENTATION_ITEM.self)
      entityDef.add(supertype: eSURFACE.self)
      entityDef.add(supertype: eELEMENTARY_SURFACE.self)

      //MARK: ATTRIBUTE REGISTRATIONS
      entityDef.addAttribute(name: "MAJOR_RADIUS", keyPath: \eELEMENTARY_SURFACE.MAJOR_RADIUS, 
        kind: .explicit, source: .subEntity, mayYieldEntityReference: false)
      entityDef.addAttribute(name: "GENERALISED_MAJOR_RADIUS", keyPath: \eELEMENTARY_SURFACE.GENERALISED_MAJOR_RADIUS, 
        kind: .explicit, source: .subEntity, mayYieldEntityReference: false)
      entityDef.addAttribute(name: "SELECT_OUTER", keyPath: \eELEMENTARY_SURFACE.SELECT_OUTER, 
        kind: .explicit, source: .subEntity, mayYieldEntityReference: false)
      entityDef.addAttribute(name: "MINOR_RADIUS", keyPath: \eELEMENTARY_SURFACE.MINOR_RADIUS, 
        kind: .explicit, source: .subEntity, mayYieldEntityReference: false)
      entityDef.addAttribute(name: "SKEWNESS", keyPath: \eELEMENTARY_SURFACE.SKEWNESS, 
        kind: .explicit, source: .subEntity, mayYieldEntityReference: false)
      entityDef.addAttribute(name: "POSITION", keyPath: \eELEMENTARY_SURFACE.POSITION, 
        kind: .explicit, source: .thisEntity, mayYieldEntityReference: true)
      entityDef.addAttribute(name: "GENERALISED_MINOR_RADIUS", keyPath: \eELEMENTARY_SURFACE.GENERALISED_MINOR_RADIUS, 
        kind: .explicit, source: .subEntity, mayYieldEntityReference: false)
      entityDef.addAttribute(name: "SEMI_ANGLE", keyPath: \eELEMENTARY_SURFACE.SEMI_ANGLE, 
        kind: .explicit, source: .subEntity, mayYieldEntityReference: false)
      entityDef.addAttribute(name: "NAME", keyPath: \eELEMENTARY_SURFACE.NAME, 
        kind: .explicit, source: .superEntity, mayYieldEntityReference: false)
      entityDef.addAttribute(name: "DIM", keyPath: \eELEMENTARY_SURFACE.DIM, 
        kind: .derived, source: .superEntity, mayYieldEntityReference: false)

      return entityDef
    }

  }
}
