title: Changing object data using with_mode method
body: <p>I have added some <a href="http://origen-sdk.org/origen/guides/models/modes/#Mode" rel="nofollow noreferrer">ChipModes</a> as follows:</p>
  
  <pre><code>  add_mode :mode1
    add_mode :mode2
  </code></pre>
  
  <p>When I set the DUT mode to :mode1 I want to have some clocks change their set point.</p>
  
  <pre><code>  with_mode :mode1 do
      clocks(:clk1).setpoint = 1.0.Ghz
      clocks(:clk2).setpoint = 1.2.Ghz
    end
  
    with_mode :mode2 do
      clocks(:clk1).setpoint = 2.0.Ghz
      clocks(:clk2).setpoint = 2.4.Ghz
    end
  </code></pre>
  
  <p>What I expected was that when the DUT chip mode was set to either :mode1 or :mode 2, the clock values would change.  But instead it seems these code blocks are executed regardless of the DUT chip mode.</p>
  
  <p><a href="https://i.stack.imgur.com/eywEU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eywEU.png" alt="enter image description here"></a></p>
  
  <p>The clocks end up getting set to the values in the second with_mode code block.  Is there a way to define mode dependent actions that only get executed when the mode is set?</p>
  
  <p>** EDIT **</p>
  
  <p>Using <a href="http://origen-sdk.org/origen/guides/misc/appcallbacks/" rel="nofollow noreferrer">this doc</a> as a model, I added the on_mode_changed callback to the <a href="https://github.com/Origen-SDK/origen/blob/master/lib/origen/model.rb" rel="nofollow noreferrer">origen/model.rb file</a> as so:</p>
  
  <pre><code># Set the current mode configuration of the current model
  def current_mode=(id)
    @current_mode = id.is_a?(ChipMode) ? id.id : id
    Origen.app.listeners_for(:on_mode_changed).each do |listener|
      listener.on_mode_changed(mode: @current_mode)
    end
    @current_mode
  end
  alias_method :mode=, :current_mode=
  </code></pre>
  
  <p>When I set the breakpoint, directly after I set the mode I do see the mode has changed and that the DUT responds to the callback method, but the callback method does not get called.</p>
  
  <p><a href="https://i.stack.imgur.com/OXYA8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OXYA8.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/MTp2a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MTp2a.png" alt="enter image description here"></a></p>
  
  <p>Here is the callback method within the DUT scope:</p>
  
  <pre><code>def on_mode_changed(options)
    binding.pry
    puts 'found callback method'
    return if options[:mode].nil?
  end
  </code></pre>
  
  <p>** UPDATE **</p>
  
  <p>The code works above, thx!</p>