- added a new TclCommand named Bbox who generate a bounding box.
This commit is contained in:
@@ -1755,13 +1755,14 @@ class App(QtCore.QObject):
|
|||||||
# #######Auto-complete KEYWORDS #############
|
# #######Auto-complete KEYWORDS #############
|
||||||
# ###########################################
|
# ###########################################
|
||||||
self.tcl_commands_list = ['add_circle', 'add_poly', 'add_polygon', 'add_polyline', 'add_rectangle',
|
self.tcl_commands_list = ['add_circle', 'add_poly', 'add_polygon', 'add_polyline', 'add_rectangle',
|
||||||
'aligndrill', 'clear',
|
'aligndrill', 'bbox', 'bounding_box', 'clear',
|
||||||
'aligndrillgrid', 'cncjob', 'cutout', 'delete', 'drillcncjob',
|
'aligndrillgrid', 'cncjob', 'cutout', 'delete', 'drillcncjob',
|
||||||
'export_gcode',
|
'export_gcode',
|
||||||
'export_svg', 'ext', 'exteriors', 'follow', 'geo_union', 'geocutout', 'get_names',
|
'export_svg', 'ext', 'exteriors', 'follow', 'geo_union', 'geocutout', 'get_names',
|
||||||
'get_sys', 'getsys', 'help', 'import_svg', 'interiors', 'isolate', 'join_excellon',
|
'get_sys', 'getsys', 'help', 'import_svg', 'interiors', 'isolate', 'join_excellon',
|
||||||
'join_excellons', 'join_geometries', 'join_geometry', 'list_sys', 'listsys', 'mill',
|
'join_excellons', 'join_geometries', 'join_geometry', 'list_sys', 'listsys', 'mill',
|
||||||
'millholes', 'mirror', 'new', 'new_geometry', 'offset', 'open_excellon', 'open_gcode',
|
'millholes', 'mirror', 'new', 'new_geometry', 'non_copper_regions', 'ncr',
|
||||||
|
'offset', 'open_excellon', 'open_gcode',
|
||||||
'open_gerber', 'open_project', 'options', 'paint', 'pan', 'panel', 'panelize', 'plot',
|
'open_gerber', 'open_project', 'options', 'paint', 'pan', 'panel', 'panelize', 'plot',
|
||||||
'save', 'save_project', 'save_sys', 'scale', 'set_active', 'set_sys', 'setsys',
|
'save', 'save_project', 'save_sys', 'scale', 'set_active', 'set_sys', 'setsys',
|
||||||
'skew', 'subtract_poly', 'subtract_rectangle', 'version', 'write_gcode'
|
'skew', 'subtract_poly', 'subtract_rectangle', 'version', 'write_gcode'
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ CAD program, and create G-Code for Isolation routing.
|
|||||||
- remade the TclCommand Paint to work in the new configuration of the the app (the painting functions are now in their own tool, Paint Tool)
|
- remade the TclCommand Paint to work in the new configuration of the the app (the painting functions are now in their own tool, Paint Tool)
|
||||||
- fixed a bug in the Properties Tool
|
- fixed a bug in the Properties Tool
|
||||||
- added a new TcL Command named Nregions who generate non-copper regions
|
- added a new TcL Command named Nregions who generate non-copper regions
|
||||||
|
- added a new TclCommand named Bbox who generate a bounding box.
|
||||||
|
|
||||||
23.08.2019
|
23.08.2019
|
||||||
|
|
||||||
|
|||||||
95
tclCommands/TclCommandBbox.py
Normal file
95
tclCommands/TclCommandBbox.py
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
from ObjectCollection import *
|
||||||
|
from tclCommands.TclCommand import TclCommand
|
||||||
|
import gettext
|
||||||
|
import FlatCAMTranslation as fcTranslate
|
||||||
|
import builtins
|
||||||
|
|
||||||
|
fcTranslate.apply_language('strings')
|
||||||
|
if '_' not in builtins.__dict__:
|
||||||
|
_ = gettext.gettext
|
||||||
|
|
||||||
|
|
||||||
|
class TclCommandBbox(TclCommand):
|
||||||
|
"""
|
||||||
|
Tcl shell command to follow a Gerber file
|
||||||
|
"""
|
||||||
|
|
||||||
|
# array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
|
||||||
|
aliases = ['bounding_box', 'bbox']
|
||||||
|
|
||||||
|
# dictionary of types from Tcl command, needs to be ordered
|
||||||
|
arg_names = collections.OrderedDict([
|
||||||
|
('name', str)
|
||||||
|
])
|
||||||
|
|
||||||
|
# dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
|
||||||
|
option_types = collections.OrderedDict([
|
||||||
|
('outname', str),
|
||||||
|
('margin', float),
|
||||||
|
('rounded', bool)
|
||||||
|
])
|
||||||
|
|
||||||
|
# array of mandatory options for current Tcl command: required = {'name','outname'}
|
||||||
|
required = ['name']
|
||||||
|
|
||||||
|
# structured help for current command, args needs to be ordered
|
||||||
|
help = {
|
||||||
|
'main': "Creates a Geometry object that surrounds the object.",
|
||||||
|
'args': collections.OrderedDict([
|
||||||
|
('name', 'Object name for which to create bounding box. String'),
|
||||||
|
('outname', 'Name of the resulting Geometry object. String.'),
|
||||||
|
('margin', "Distance of the edges of the box to the nearest polygon."
|
||||||
|
"Float number."),
|
||||||
|
('rounded', "If the bounding box is to have rounded corners their radius is equal to the margin. "
|
||||||
|
"True or False.")
|
||||||
|
]),
|
||||||
|
'examples': ['bbox name -outname name_bbox']
|
||||||
|
}
|
||||||
|
|
||||||
|
def execute(self, args, unnamed_args):
|
||||||
|
"""
|
||||||
|
execute current TCL shell command
|
||||||
|
|
||||||
|
:param args: array of known named arguments and options
|
||||||
|
:param unnamed_args: array of other values which were passed into command
|
||||||
|
without -somename and we do not have them in known arg_names
|
||||||
|
:return: None or exception
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = args['name']
|
||||||
|
|
||||||
|
if 'outname' not in args:
|
||||||
|
args['outname'] = name + "_bbox"
|
||||||
|
|
||||||
|
obj = self.app.collection.get_by_name(name)
|
||||||
|
if obj is None:
|
||||||
|
self.raise_tcl_error("%s: %s" % (_("Object not found"), name))
|
||||||
|
|
||||||
|
if not isinstance(obj, FlatCAMGerber) and not isinstance(obj, FlatCAMGeometry):
|
||||||
|
self.raise_tcl_error('%s %s: %s.' % (
|
||||||
|
_("Expected FlatCAMGerber or FlatCAMGeometry, got"), name, type(obj)))
|
||||||
|
|
||||||
|
if 'margin' not in args:
|
||||||
|
args['margin'] = float(self.app.defaults["gerber_bboxmargin"])
|
||||||
|
margin = args['margin']
|
||||||
|
|
||||||
|
if 'rounded' not in args:
|
||||||
|
args['rounded'] = self.app.defaults["gerber_bboxrounded"]
|
||||||
|
rounded = args['rounded']
|
||||||
|
|
||||||
|
del args['name']
|
||||||
|
|
||||||
|
try:
|
||||||
|
def geo_init(geo_obj, app_obj):
|
||||||
|
assert isinstance(geo_obj, FlatCAMGeometry)
|
||||||
|
|
||||||
|
# Bounding box with rounded corners
|
||||||
|
geo = cascaded_union(obj.solid_geometry)
|
||||||
|
bounding_box = geo.envelope.buffer(float(margin))
|
||||||
|
if not rounded: # Remove rounded corners
|
||||||
|
bounding_box = bounding_box.envelope
|
||||||
|
geo_obj.solid_geometry = bounding_box
|
||||||
|
|
||||||
|
self.app.new_object("geometry", args['outname'], geo_init)
|
||||||
|
except Exception as e:
|
||||||
|
return "Operation failed: %s" % str(e)
|
||||||
@@ -64,8 +64,8 @@ class TclCommandNregions(TclCommand):
|
|||||||
if obj is None:
|
if obj is None:
|
||||||
self.raise_tcl_error("%s: %s" % (_("Object not found"), name))
|
self.raise_tcl_error("%s: %s" % (_("Object not found"), name))
|
||||||
|
|
||||||
if not isinstance(obj, FlatCAMGerber):
|
if not isinstance(obj, FlatCAMGerber) and not isinstance(obj, FlatCAMGeometry):
|
||||||
self.raise_tcl_error('%s %s %s.' % (_("Expected FlatCAMGerber, got"), name, type(obj)))
|
self.raise_tcl_error('%s %s: %s.' % (_("Expected FlatCAMGerber or FlatCAMGeometry, got"), name, type(obj)))
|
||||||
|
|
||||||
if 'margin' not in args:
|
if 'margin' not in args:
|
||||||
args['margin'] = float(self.app.defaults["gerber_noncoppermargin"])
|
args['margin'] = float(self.app.defaults["gerber_noncoppermargin"])
|
||||||
@@ -81,14 +81,15 @@ class TclCommandNregions(TclCommand):
|
|||||||
def geo_init(geo_obj, app_obj):
|
def geo_init(geo_obj, app_obj):
|
||||||
assert isinstance(geo_obj, FlatCAMGeometry)
|
assert isinstance(geo_obj, FlatCAMGeometry)
|
||||||
|
|
||||||
bounding_box = obj.solid_geometry.envelope.buffer(float(margin))
|
geo = cascaded_union(obj.solid_geometry)
|
||||||
|
bounding_box = geo.envelope.buffer(float(margin))
|
||||||
if not rounded:
|
if not rounded:
|
||||||
bounding_box = bounding_box.envelope
|
bounding_box = bounding_box.envelope
|
||||||
|
|
||||||
non_copper = bounding_box.difference(obj.solid_geometry)
|
non_copper = bounding_box.difference(geo)
|
||||||
geo_obj.solid_geometry = non_copper
|
geo_obj.solid_geometry = non_copper
|
||||||
|
|
||||||
self.app.new_object("geometry", name, geo_init)
|
self.app.new_object("geometry", args['outname'], geo_init)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return "Operation failed: %s" % str(e)
|
return "Operation failed: %s" % str(e)
|
||||||
|
|
||||||
@@ -9,6 +9,7 @@ import tclCommands.TclCommandAddPolyline
|
|||||||
import tclCommands.TclCommandAddRectangle
|
import tclCommands.TclCommandAddRectangle
|
||||||
import tclCommands.TclCommandAlignDrill
|
import tclCommands.TclCommandAlignDrill
|
||||||
import tclCommands.TclCommandAlignDrillGrid
|
import tclCommands.TclCommandAlignDrillGrid
|
||||||
|
import tclCommands.TclCommandBbox
|
||||||
import tclCommands.TclCommandClearShell
|
import tclCommands.TclCommandClearShell
|
||||||
import tclCommands.TclCommandCncjob
|
import tclCommands.TclCommandCncjob
|
||||||
import tclCommands.TclCommandCutout
|
import tclCommands.TclCommandCutout
|
||||||
@@ -31,7 +32,7 @@ import tclCommands.TclCommandListSys
|
|||||||
import tclCommands.TclCommandMillHoles
|
import tclCommands.TclCommandMillHoles
|
||||||
import tclCommands.TclCommandMirror
|
import tclCommands.TclCommandMirror
|
||||||
import tclCommands.TclCommandNew
|
import tclCommands.TclCommandNew
|
||||||
import tclCommands.TcLCommandNregions
|
import tclCommands.TclCommandNregions
|
||||||
import tclCommands.TclCommandNewGeometry
|
import tclCommands.TclCommandNewGeometry
|
||||||
import tclCommands.TclCommandOffset
|
import tclCommands.TclCommandOffset
|
||||||
import tclCommands.TclCommandOpenExcellon
|
import tclCommands.TclCommandOpenExcellon
|
||||||
|
|||||||
Reference in New Issue
Block a user