浏览代码

- added a new TcL Command named Nregions who generate non-copper regions

Marius Stanciu 6 年之前
父节点
当前提交
a29f8ec43d
共有 3 个文件被更改,包括 98 次插入0 次删除
  1. 1 0
      README.md
  2. 96 0
      tclCommands/TcLCommandNregions.py
  3. 1 0
      tclCommands/__init__.py

+ 1 - 0
README.md

@@ -18,6 +18,7 @@ CAD program, and create G-Code for Isolation routing.
 - modified the Paint Tool. Now the Single Polygon and Area/Reference Object painting works with multiple tools too. The tools have to be selected in the Tool Table.
 - 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
+- added a new TcL Command named Nregions who generate non-copper regions
 
 23.08.2019
 

+ 96 - 0
tclCommands/TcLCommandNregions.py

@@ -0,0 +1,96 @@
+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 TclCommandNregions(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 = ['non_copper_regions', 'ncr']
+
+    # 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 with the non-copper regions.",
+        'args': collections.OrderedDict([
+            ('name', 'Object name for which to create non-copper regions. String'),
+            ('outname', 'Name of the resulting Geometry object. String.'),
+            ('margin', "Specify the edge of the PCB by drawing a box around all objects with this minimum distance. "
+                       "Float number."),
+            ('rounded', "Resulting geometry will have rounded corners. True or False.")
+        ]),
+        'examples': ['ncr name -outname name_ncr']
+    }
+
+    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 + "_noncopper"
+
+        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):
+            self.raise_tcl_error('%s %s %s.' % (_("Expected FlatCAMGerber, got"), name, type(obj)))
+
+        if 'margin' not in args:
+            args['margin'] = float(self.app.defaults["gerber_noncoppermargin"])
+        margin = args['margin']
+
+        if 'rounded' not in args:
+            args['rounded'] = self.app.defaults["gerber_noncopperrounded"]
+        rounded = args['rounded']
+
+        del args['name']
+
+        try:
+            def geo_init(geo_obj, app_obj):
+                assert isinstance(geo_obj, FlatCAMGeometry)
+
+                bounding_box = obj.solid_geometry.envelope.buffer(float(margin))
+                if not rounded:
+                    bounding_box = bounding_box.envelope
+
+                non_copper = bounding_box.difference(obj.solid_geometry)
+                geo_obj.solid_geometry = non_copper
+
+            self.app.new_object("geometry", name, geo_init)
+        except Exception as e:
+            return "Operation failed: %s" % str(e)
+
+        # in the end toggle the visibility of the origin object so we can see the generated Geometry
+        self.app.collection.get_by_name(name).ui.plot_cb.toggle()

+ 1 - 0
tclCommands/__init__.py

@@ -31,6 +31,7 @@ import tclCommands.TclCommandListSys
 import tclCommands.TclCommandMillHoles
 import tclCommands.TclCommandMirror
 import tclCommands.TclCommandNew
+import tclCommands.TcLCommandNregions
 import tclCommands.TclCommandNewGeometry
 import tclCommands.TclCommandOffset
 import tclCommands.TclCommandOpenExcellon