SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
38 stars 10 forks source link

RenderingOptions keys "DrawHiddenGeometry" vs "DrawHidden" (v2020+) #449

Open DanRathbun opened 4 years ago

DanRathbun commented 4 years ago

SketchUp Ruby API Documentation Issue

The Sketchup::RenderingOptions class documentation mentions the addition of the integer constants ...

Sketchup::RenderingOptions::ROPDrawHiddenGeometry
Sketchup::RenderingOptions::ROPDrawHiddenObjects

... but not what the scenario is with the old constant ...

Sketchup::RenderingOptions::ROPDrawHidden

Also the docs fail to explicitly mention the v2020 addition of the options keys "DrawHiddenGeometry" and "DrawHiddenObjects" and again what is the situation concerning the old options key "DrawHidden" and it's integer constant for use with the Sketchup::RenderingOptionsObserver callback.

Is the old "DrawHidden" key deprecated for versions 2020+ ?


Rhetorical: Why was a new integer assigned for "hidden geometry" ?

... and, which integer would API coders expect to be passed to the RO observer callback going forward, 28 or 29 ?

TESTED:

Okay, we have a strange scenario. The observer callback gets the integer for the exact key used to make a change from Ruby code. (ie, 28 or 29) But ... the user's manually checking / unchecking the View menu item only sends the integer 29 (Sketchup::RenderingOptions::ROPDrawHiddenGeometry) in SketchUp 2020.

So, my conclusion would have to be that the "DrawHidden" (and it's ROPDrawHidden constant) options key should be deprecated from use in new extensions targeting v20 and higher. But extensions supporting older versions as well need to check for both integers or duck type for the new constant as a conditional within the RO observer callback.

class MyRenderingOptionsObserver < Sketchup::RenderingOptionsObserver
  def onRenderingOptionsChanged(rendering_options, type)
    puts "onRenderingOptionsChanged(#{rendering_options}, #{type})" if @debug
    if defined? Sketchup::RenderingOptions::ROPDrawHiddenGeometry
      if type == Sketchup::RenderingOptions::ROPDrawHiddenGeometry
        puts "rendering_options[\"DrawHiddenGeometry\"] was toggled"
      elsif type == Sketchup::RenderingOptions::ROPDrawHiddenObjects
        puts "rendering_options[\"DrawHiddenObjects\"] was toggled"
      end
    else
      if type == Sketchup::RenderingOptions::ROPDrawHidden
        puts "rendering_options[\"DrawHidden\"] was toggled"
      end
    end
    # check for other keys
  end
end

Answer: The new constant was defined so the new behavior could be duck typed (as shown above.) Although the existence of the new ROPDrawHiddenObjects constant could have done this job alone.


I was able to get the 2 keys ("DrawHiddenGeometry" and "DrawHidden") out of sync with each other, but only for a moment ...

ro = Sketchup.active_model.rendering_options
#=> <Sketchup::RenderingOptions:0x0000018a1bb595b8>
ro["DrawHidden"]
#=> true
ro["DrawHiddenGeometry"]
#=> true
ro["DrawHiddenGeometry"]= false
#=> false
ro["DrawHidden"]
#=> true

... but when I manually opened the View menu, it seemed to sync them back together.

Thereafter, attempts (in this same session with the same model,) to purposely get them out of sync again via the same sort if console assignments failed.

Attempts to reload the same model (in the same session) and repeat still failed to reproduce the out of sync boolean returns values. So I don't know why it happened the first time, and then won't do it again.

DanRathbun commented 3 years ago

Also dezmo points out that the doc is incorrect in the option key listing ...

Newly listed for SU2020 are:

But those are the constant names. The key names are ...

These are the two that supersede the use of "DrawHidden".

~