# Class: EnfEditor::EESession

Inherits:
  Object
  - Object
  - EnfEditor::EESession
  show all

Defined in:
  lib/enfeditor/core_ext/ee_session.rb,
  ext/enfhandler/EnfHandler_wrap2.cxx

## Overview

Proxy of C++ EnfEditor::EESession class

## Instance Attribute Summary collapse

- #display_message ⇒ Object writeonly

  Display message text to show in “Job Detail” page of TransServer.

- #parameter ⇒ Hash

  parameter.

## Class Method Summary collapse

- .open(argv = nil) {|session| ... } ⇒ Object

  Open session.

## Instance Method Summary collapse

- #calculate_bounding_box(compo, flag) ⇒ Array<Float>

  Calculate Bounding Box for component.

- #debug_level=(level) ⇒ Object

  Set debug level for log details.

- #model ⇒ EEModelSession

  Return model.

- #process_meter_main=(percent) ⇒ Object

  Update process meter.

- #read_enf(path) ⇒ Object

  Read ENF file.

- #write_enf(path, version = nil, revision = nil) ⇒ Object

  Write ENF file.

- #xmllog ⇒ EEXmlLog

  Returns EEXmlLog class instance.

## Instance Attribute Details

### #display_message=(value) ⇒ `Object` (writeonly)

Display message text to show in “Job Detail” page of TransServer

Examples:

    session.display_message = "Custom script error code: 4 (Empty part)"

Since:

- 1.1.0.0

    38
    39
    40
    # File 'lib/enfeditor/core_ext/ee_session.rb', line 38

    def display_message=(value)
      @display_message = value
    end

### #parameter ⇒ `Hash`

parameter

Examples:

    # Log parameter values
    puts session.parameter['inputfile']   # => 'c:/work/input.enf'
    puts session.parameter['outputfile']  # => 'c:/work/output.enf'

Returns:

- (`Hash`)

Since:

- 0.1.0.0

    55
    56
    57
    # File 'lib/enfeditor/core_ext/ee_session.rb', line 55

    def parameter
      @parameter
    end

## Class Method Details

### .open(argv = nil) {|session| ... } ⇒ `Object`

Open session

Examples:

    # Open session
    EESession::open(argv) do |session|
      session.read_enf(input_file)
    end

Parameters:

- argv (`String`) (defaults to: `nil`) —

  Arguments to the script (ARGV).

Yields:

- (`session`) —

  Pass the code block to edit ENF.

Since:

- 0.1.0.0

    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    # File 'lib/enfeditor/core_ext/ee_session.rb', line 80

    def self.open(argv = nil, &block)
      session = EESession.new

      begin
        session.parse_arguments(argv) unless argv.nil?
        session.lic_context = EESession.external_lic_context unless EESession.external_lic_context.nil?
        session.elybatch_process_id = EESession.external_elybatch_process_id unless EESession.external_elybatch_process_id.nil?
        session.Open
      rescue => ex
        puts "Failed in EESession::open"
        raise
      end

      begin
        xmllogfile = session.argument['-X']
        session.xmllog_initialize(xmllogfile) unless xmllogfile.nil?
      rescue => ex
        puts "Failed to initialize xml logfile"
        raise
      end

      begin
        shared_mem = session.argument['-g']
        unless shared_mem.nil?
          session.progress_info = EEProgressInfo.new
          session.progress_info.start_share_progress_info_from_kernel_side(shared_mem)
        end
      rescue => ex
        puts "Failed to initialize progress info. Ignored"
        puts ex
        session.progress_info = nil
      end

      block.call session

    ensure
      begin
        session.xmllog_finalize unless xmllogfile.nil?
        session.progress_info.end_share_progress_info_from_kernel_side unless session.progress_info.nil?
      ensure
        session.Close
      end
    end

## Instance Method Details

### #calculate_bounding_box(compo, flag) ⇒ `Array<Float>`

Calculate Bounding Box for component

Examples:

    box = session.calculate_bounding_box(compo, 2) # = >[0.0, 0.0, 0.0, 10.0, 20.0, 30.0]
    box_min_coord = box[0..2]
    box_max_coord = box[3..5]

Parameters:

- compo (`EEComponent`) —

  Component to calculate bounding box

- flag (`Integer`) —

  0: use vertices, control points of curves and control points of surfaces. 1: use vertices and control points of curves. 2: use vertices and mid points of curves(fast).

Returns:

- (`Array<Float>`) —

  Bounding Box coordinates. [Min-x, Min-y, Min-z, Max-x, Max-y, Max-z]

Since:

- 0.9.0.0

    245
    246
    247
    # File 'lib/enfeditor/core_ext/ee_session.rb', line 245

    def calculate_bounding_box(compo, flag = 2)
      calculate_bounding_box_org(compo, flag)
    end

### #debug_level=(level) ⇒ `Object`

Set debug level for log details

Examples:

    # Set debug level to 1
    session.debug_level = 1

Parameters:

- level (`Integer`) —

  Set level from 0 to 6

Since:

- 0.1.0.0

    202
    203
    204
    # File 'lib/enfeditor/core_ext/ee_session.rb', line 202

    def debug_level= (level)
      debug_level(level)
    end

### #model ⇒ `EEModelSession`

Return model

Examples:

    # Get model
    session.model

Returns:

- (`EEModelSession`) —

  return model

Since:

- 0.1.0.0

### #process_meter_main=(percent) ⇒ `Object`

Update process meter

Examples:

    # Update process meter value to 25 percent
    session.process_meter_main = 25

Parameters:

- percent (`Integer`) —

  Set progress value from 0 to 100

Since:

- 0.1.0.0

    213
    214
    215
    # File 'lib/enfeditor/core_ext/ee_session.rb', line 213

    def process_meter_main= (percent)
      @progress_info.set_process_meter_main(percent) unless @progress_info.nil?
    end

### #read_enf(path) ⇒ `Object`

Read ENF file

Examples:

    # Read ENF file
    session.read_enf(input_file)

Parameters:

- path (`String`) —

  ENF file path to read.

Raises:

- (`StandardError`)

Since:

- 0.1.0.0

    144
    145
    146
    147
    148
    149
    # File 'lib/enfeditor/core_ext/ee_session.rb', line 144

    def read_enf(path)
      path_str = path.nil? ? "" : path.to_s # for Pathname
      raise StandardError, "Failed to read ENF file. ENF file is not specified." if path_str.empty?
      raise StandardError, "ENF file does not exist (path = '#{path}')." unless File.exist?(path_str)
      _read_enf(path_str)
    end

### #write_enf(path, version = nil, revision = nil) ⇒ `Object`

Write ENF file

Examples:

    # Write ENF file
    session.write_enf(output_file)

Parameters:

- path (`String`) —

  ENF file path to write.

- version (`Integer`, `nil`) (defaults to: `nil`) —

  ENF file version (1-3). Set nil to specify the latest version.

- revision (`Integer`, `nil`) (defaults to: `nil`) —

  ENF file revision. Set nil to specify the latest revision.

Raises:

- (`StandardError`)

Since:

- 0.1.0.0

    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    # File 'lib/enfeditor/core_ext/ee_session.rb', line 161

    def write_enf(path, version = nil, revision = nil)
      path_str = path.nil? ? "" : path.to_s # for Pathname
      raise StandardError, "Failed to write ENF file. ENF file is not specified." if path_str.empty?
      if version.nil?
        prm_ver = @parameter['WriteOldFile']
        prm_rev = @parameter['WriteOldFileRev']
        version = (!prm_ver.nil? && !prm_ver.empty?) ? prm_ver.to_i : 0   # 0 means use the latest version.
        revision = (!prm_rev.nil? && !prm_rev.empty?) ? prm_rev.to_i : -1 # -1 means use the latest revision.
      end
      revision = -1 if revision.nil?
      _write_enf(path_str, version, revision)
    end

### #xmllog ⇒ `EEXmlLog`

Returns EEXmlLog class instance.

Examples:

    # session.xmllog.log_additional_output_filename('c:/work/report.csv', 'csvfile')

Returns:

- (`EEXmlLog`) —

  Returns EEXmlLog class instance.

Since:

- 1.0.0.0