Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/dialog width #167

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 40 additions & 36 deletions src/sketchup-stl/exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ def self.select_export_file
end

def self.export(path, export_entities, options = OPTIONS)
filemode = 'w'
if RUBY_VERSION.to_f > 1.8
filemode << ':ASCII-8BIT'
end
file = File.new(path , filemode)
if options['stl_format'] == STL_BINARY
file.binmode
@write_face = method(:write_face_binary)
else
@write_face = method(:write_face_ascii)
end
scale = scale_factor(options['export_units'])
write_header(file, model_name, options['stl_format'])
facet_count = find_faces(file, export_entities, 0, scale, Geom::Transformation.new)
write_footer(file, facet_count, model_name, options['stl_format'])
filemode = 'w'
if RUBY_VERSION.to_f > 1.8
filemode << ':ASCII-8BIT'
end
file = File.new(path , filemode)
if options['stl_format'] == STL_BINARY
file.binmode
@write_face = method(:write_face_binary)
else
@write_face = method(:write_face_ascii)
end
scale = scale_factor(options['export_units'])
write_header(file, model_name, options['stl_format'])
facet_count = find_faces(file, export_entities, 0, scale, Geom::Transformation.new)
write_footer(file, facet_count, model_name, options['stl_format'])
end

def self.find_faces(file, entities, facet_count, scale, tform)
Expand Down Expand Up @@ -133,7 +133,7 @@ def self.write_face_binary(file, scale, mesh, normal)
file.write(pt.pack("e3"))
end
# 2-byte "Attribute byte count" spacer. Nonstandard use by some stl software
# to store color data. Was never widely supported. Should be 0.
# to store color data. Was never widely supported. Should be 0.
# "S<" - 16-bit unsigned integer, little-endian
file.write([0].pack("S<"))
facets_written += 1
Expand Down Expand Up @@ -269,11 +269,13 @@ def self.do_options
window_options = {
:title => STL.translate('STL Export Options'),
:preferences_key => PREF_KEY,
:height => 160,
:width => 290,
:height => 170,
:width => 300,
:modal => true
}
window = SKUI::Window.new(window_options)
window.background_color = Sketchup::Color.new(240, 240, 240)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this is needed. Default SKUI is to use system colors. If the user change system color theme this hard coded value might make things look odd...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be a Windows 10 thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the contrast to the white background.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we deal with the background color in another PR?
At the moment all colors are based on system colors, using system color codes in the CSS stylesheet. I'd rather find a solution where we don't have a mix of hard coded and system colors.

list_width = 160
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes things look ok in SU2017 as well as older versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

00083


# Row 1 Export Selected
chk_selection = SKUI::Checkbox.new(
Expand All @@ -292,7 +294,7 @@ def self.do_options
#
lst_units = SKUI::Listbox.new(units_translated)
lst_units.position(col[2], row[2])
lst_units.width = 169
lst_units.width = list_width
lst_units.value = STL.translate(OPTIONS['export_units'])
lst_units.on(:change) { |control, value|
unit_index = units_translated.index(value)
Expand All @@ -310,7 +312,7 @@ def self.do_options
lst_format = SKUI::Listbox.new(formats_translated)
lst_format.value = lst_format.items.first
lst_format.position(col[2], row[3])
lst_format.width = 169
lst_format.width = list_width
lst_format.value = STL.translate(OPTIONS['stl_format'])
lst_format.on(:change) { |control, value|
format_index = formats_translated.index(value)
Expand All @@ -325,34 +327,36 @@ def self.do_options
#
# Export and Cancel Buttons
#
btn_cancel = SKUI::Button.new('Cancel') { |control|
control.window.close
}
btn_cancel.position(-10, -10)
window.add_control(btn_cancel)
window.cancel_button = btn_cancel

btn_export = SKUI::Button.new('Export') { |control|
write_setting('export_units' , OPTIONS['export_units'])
write_setting('stl_format' , OPTIONS['stl_format'])
write_setting('selection_only' , OPTIONS['selection_only'])
control.window.close
export_entities = get_export_entities
if export_entities
path = select_export_file
begin
export(path, export_entities, OPTIONS) unless path.nil?
rescue => exception
msg = "SketchUp STL Exporter:\n"
msg << "An error occured during export.\n\n"
msg << exception.message << "\n"
msg << exception.backtrace.join("\n")
UI.messagebox(msg, MB_MULTILINE)
end
path = select_export_file
begin
export(path, export_entities, OPTIONS) unless path.nil?
rescue => exception
msg = "SketchUp STL Exporter:\n"
msg << "An error occured during export.\n\n"
msg << exception.message << "\n"
msg << exception.backtrace.join("\n")
UI.messagebox(msg, MB_MULTILINE)
end
end
}

btn_export.position(125, -5)
btn_export.position(-btn_cancel.width - 25, -10)
window.add_control(btn_export)

btn_cancel = SKUI::Button.new('Cancel') { |control|
control.window.close
}
btn_cancel.position(-5, -5)
window.add_control(btn_cancel)

window.default_button = btn_export
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No what does it do? The docs are rather sparse. 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd think a developer properly document it's code... tsk tsk...

If I recall correctly setting default/cancel buttons will hook up default triggers for Return/ESC keys.

Technically it's unrelated to this CL, can defer to a separate fix.

window.show
Expand Down