소스 검색

- added a new TclCommand named "bounds" which will return a list of bounds values from a supplied list of objects names. For use in Tcl Scripts.

Marius Stanciu 6 년 전
부모
커밋
27b7a7dce6
5개의 변경된 파일86개의 추가작업 그리고 3개의 파일을 삭제
  1. 2 1
      README.md
  2. 81 0
      tclCommands/TclCommandBounds.py
  3. 1 0
      tclCommands/TclCommandCopperClear.py
  4. 1 2
      tclCommands/TclCommandSetOrigin.py
  5. 1 0
      tclCommands/__init__.py

+ 2 - 1
README.md

@@ -14,7 +14,8 @@ CAD program, and create G-Code for Isolation routing.
 - in legacy graphic engine, fixed bug that made the old object disappear when a new object was loaded
 - in legacy graphic engine, fixed bug that crashed the app when creating a new project
 - in legacy graphic engine, fixed a bug that when deleting an object all objects where deleted
-- added a new TclCommand named set_origin which will set the origin for all loaded objects to zero if the -auto True argument is used and to a certain x,y location if the format is: set_origin 5,7
+- added a new TclCommand named "set_origin" which will set the origin for all loaded objects to zero if the -auto True argument is used and to a certain x,y location if the format is: set_origin 5,7
+- added a new TclCommand named "bounds" which will return a list of bounds values from a supplied list of objects names. For use in Tcl Scripts
 
 22.09.2019
 

+ 81 - 0
tclCommands/TclCommandBounds.py

@@ -0,0 +1,81 @@
+from tclCommands.TclCommand import TclCommand
+from ObjectCollection import *
+
+from camlib import get_bounds
+
+import gettext
+import FlatCAMTranslation as fcTranslate
+import builtins
+
+fcTranslate.apply_language('strings')
+if '_' not in builtins.__dict__:
+    _ = gettext.gettext
+
+
+class TclCommandBounds(TclCommand):
+    """
+    Tcl shell command to return the bounds values for a supplied list of objects (identified by their names).
+    example:
+
+    """
+
+    # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
+    aliases = ['get_bounds', 'bounds']
+
+    # Dictionary of types from Tcl command, needs to be ordered
+    arg_names = collections.OrderedDict([
+        ('objects', str)
+    ])
+
+    # Dictionary of types from Tcl command, needs to be ordered , this  is  for options  like -optionname value
+    option_types = collections.OrderedDict([
+    ])
+
+    # array of mandatory options for current Tcl command: required = {'name','outname'}
+    required = []
+
+    # structured help for current command, args needs to be ordered
+    help = {
+        'main': "Will return a list of bounds values, each set of bound values is "
+                "a list itself: [xmin, ymin, xmax, ymax].",
+        'args': collections.OrderedDict([
+            ('objects', 'A list of object names separated by comma without spaces.'),
+        ]),
+        'examples': ['bounds a_obj.GTL,b_obj.DRL']
+    }
+
+    def execute(self, args, unnamed_args):
+        """
+
+        :param args:
+        :param unnamed_args:
+        :return:
+        """
+
+        obj_list = list()
+        if 'objects' in args:
+            try:
+                obj_list = [str(obj_name) for obj_name in str(args['objects']).split(",") if obj_name != '']
+            except AttributeError as e:
+                log.debug("TclCommandBounds.execute --> %s" % str(e))
+
+            if not obj_list:
+                self.raise_tcl_error('%s: %s:' % (
+                    _("Expected a list of objects names separated by comma. Got"), str(args['objects'])))
+                return 'fail'
+        else:
+            self.raise_tcl_error('%s: %s:' % (
+                _("Expected a list of objects names separated by comma. Got"), str(args['objects'])))
+            return 'fail'
+
+        result_list = list()
+        for name in obj_list:
+            obj = self.app.collection.get_by_name(name)
+
+            xmin, ymin, xmax, ymax = obj.bounds()
+            result_list.append([xmin, ymin, xmax, ymax])
+
+        self.app.inform.emit('[success] %s ...' %
+                             _('TclCommand Bounds done.'))
+
+        return result_list

+ 1 - 0
tclCommands/TclCommandCopperClear.py

@@ -136,6 +136,7 @@ class TclCommandCopperClear(TclCommand):
             tools = [float(eval(dia)) for dia in tooldia.split(",") if dia != '']
         except AttributeError:
             tools = [float(tooldia)]
+
         # store here the default data for Geometry Data
         default_data = {}
         default_data.update({

+ 1 - 2
tclCommands/TclCommandSetOrigin.py

@@ -14,7 +14,7 @@ if '_' not in builtins.__dict__:
 
 class TclCommandSetOrigin(TclCommand):
     """
-    Tcl shell command to clear the text in the Tcl Shell browser.
+    Tcl shell command to set the origin to zero or to a specified location for all loaded objects in FlatCAM.
 
     example:
 
@@ -55,7 +55,6 @@ class TclCommandSetOrigin(TclCommand):
         :return:
         """
 
-        print(args)
         loc = list()
         if 'auto' in args:
             if args['auto'] == 1:

+ 1 - 0
tclCommands/__init__.py

@@ -10,6 +10,7 @@ import tclCommands.TclCommandAddRectangle
 import tclCommands.TclCommandAlignDrill
 import tclCommands.TclCommandAlignDrillGrid
 import tclCommands.TclCommandBbox
+import tclCommands.TclCommandBounds
 import tclCommands.TclCommandClearShell
 import tclCommands.TclCommandCncjob
 import tclCommands.TclCommandCopperClear