Class: EnfEditor::EESession

Inherits:
Object
  • Object
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parameterHash

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



26
27
28
# File 'lib/enfeditor/core_ext/ee_session.rb', line 26

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/enfeditor/core_ext/ee_session.rb', line 49

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

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

  begin
    xmllogfile = session.argument['-X']
    unless xmllogfile.nil?
      session.xmllog.Initialize(xmllogfile)
      session.parameter.each do |key, value|
        session.xmllog.log_translation_option(key, value)
      end
    end
  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



217
218
219
# File 'lib/enfeditor/core_ext/ee_session.rb', line 217

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



174
175
176
# File 'lib/enfeditor/core_ext/ee_session.rb', line 174

def debug_level= (level)
  debug_level(level)
end

#modelEEModelSession

Return model

Examples:

# Get model
session.model

Returns:

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



185
186
187
# File 'lib/enfeditor/core_ext/ee_session.rb', line 185

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



116
117
118
119
120
121
# File 'lib/enfeditor/core_ext/ee_session.rb', line 116

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



133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/enfeditor/core_ext/ee_session.rb', line 133

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