Selaa lähdekoodia

Merged in merge-excellons (pull request #3)

Merge excellons
Kamil Sopko 10 vuotta sitten
vanhempi
commit
3011c6d2ce
3 muutettua tiedostoa jossa 75 lisäystä ja 33 poistoa
  1. 7 4
      FlatCAMApp.py
  2. 47 29
      FlatCAMObj.py
  3. 21 0
      ObjectCollection.py

+ 7 - 4
FlatCAMApp.py

@@ -2774,6 +2774,8 @@ class App(QtCore.QObject):
 
         def delete(obj_name):
             try:
+                #deselect all  to avoid  delete selected object when run  delete  from  shell
+                self.collection.set_all_inactive()
                 self.collection.set_active(str(obj_name))
                 self.on_delete()
             except Exception, e:
@@ -2815,7 +2817,7 @@ class App(QtCore.QObject):
                     objs.append(obj)
 
             def initialize(obj, app):
-                FlatCAMExcellon.merge(objs, obj,True)
+                FlatCAMExcellon.merge(objs, obj)
 
             if objs is not None:
                 self.new_object("excellon", obj_name, initialize)
@@ -2880,14 +2882,14 @@ class App(QtCore.QObject):
                 obj_init.offset([float(currentx), float(currenty)]),
 
             def initialize_local_excellon(obj_init, app):
-                FlatCAMExcellon.merge(obj, obj_init,True)
+                FlatCAMExcellon.merge(obj, obj_init)
                 obj_init.offset([float(currentx), float(currenty)]),
 
             def initialize_geometry(obj_init, app):
                 FlatCAMGeometry.merge(objs, obj_init)
 
             def initialize_excellon(obj_init, app):
-                FlatCAMExcellon.merge(objs, obj_init,True)
+                FlatCAMExcellon.merge(objs, obj_init)
 
             objs=[]
             if obj is not None:
@@ -2909,7 +2911,8 @@ class App(QtCore.QObject):
                 else:
                     self.new_object("geometry", outname, initialize_geometry)
 
-
+                #deselect all  to avoid  delete selected object when run  delete  from  shell
+                self.collection.set_all_inactive()
                 for delobj in objs:
                     self.collection.set_active(delobj.options['name'])
                     self.on_delete()

+ 47 - 29
FlatCAMObj.py

@@ -123,8 +123,12 @@ class FlatCAMObj(QtCore.QObject):
 
         :return: None
         """
+        FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + "--> FlatCAMObj.to_form()")
         for option in self.options:
-            self.set_form_item(option)
+            try:
+                self.set_form_item(option)
+            except:
+                self.app.log.warning("Unexpected error:", sys.exc_info())
 
     def read_form(self):
         """
@@ -135,7 +139,11 @@ class FlatCAMObj(QtCore.QObject):
         """
         FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + "--> FlatCAMObj.read_form()")
         for option in self.options:
-            self.read_form_item(option)
+            try:
+                self.read_form_item(option)
+            except:
+                self.app.log.warning("Unexpected error:", sys.exc_info())
+
 
     def build_ui(self):
         """
@@ -191,11 +199,16 @@ class FlatCAMObj(QtCore.QObject):
         :type option: str
         :return: None
         """
-
-        try:
-            self.options[option] = self.form_fields[option].get_value()
-        except KeyError:
-            self.app.log.warning("Failed to read option from field: %s" % option)
+        #try read field only when option have equivalent in form_fields
+        if option in self.form_fields:
+            option_type=type(self.options[option])
+            try:
+                value=self.form_fields[option].get_value()
+            #catch per option as it was ignored anyway, also when syntax error (probably uninitialized field),don't read either.
+            except (KeyError,SyntaxError):
+                self.app.log.warning("Failed to read option from field: %s" % option)
+        else:
+            self.app.log.warning("Form fied does not exists: %s" % option)
 
     def plot(self):
         """
@@ -631,13 +644,16 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
         self.ser_attrs += ['options', 'kind']
 
     @staticmethod
-    def merge(exc_list, exc_final, copy_options):
+    def merge(exc_list, exc_final):
         """
-        Merges(copy if used on one) the excellon of objects in exc_list into
-        options  have same like exc_final
-        the geometry of geo_final.
+        Merge excellons in exc_list into exc_final.
+        Options are allways copied from source .
+
+        Tools are also merged, if  name for  tool is same and   size differs, then as name is used next available  number from both lists
 
-        :param exc_list: List of FlatCAMExcellon Objects to join.
+        if only one object is  specified in exc_list then this acts  as copy only
+
+        :param exc_list: List or one object of FlatCAMExcellon Objects to join.
         :param exc_final: Destination FlatCAMExcellon object.
         :return: None
         """
@@ -648,26 +664,27 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
         else:
             exc_list_real=exc_list
 
-
         for exc in exc_list_real:
             # Expand lists
             if type(exc) is list:
-                FlatCAMExcellon.merge(exc, exc_final, copy_options)
-
-            # If not list, just append
+                FlatCAMExcellon.merge(exc, exc_final)
+            # If not list, merge excellons
             else:
-                if copy_options is True:
-                    exc_final.options["plot"]=exc.options["plot"]
-                    exc_final.options["solid"]=exc.options["solid"]
-                    exc_final.options["drillz"]=exc.options["drillz"]
-                    exc_final.options["travelz"]=exc.options["travelz"]
-                    exc_final.options["feedrate"]=exc.options["feedrate"]
-                    exc_final.options["tooldia"]=exc.options["tooldia"]
-                    exc_final.options["toolchange"]=exc.options["toolchange"]
-                    exc_final.options["toolchangez"]=exc.options["toolchangez"]
-                    exc_final.options["spindlespeed"]=exc.options["spindlespeed"]
-
 
+                #    TODO: I realize forms does not save values into options , when  object is deselected
+                #    leave this  here for future use
+                #    this  reinitialize options based on forms, all steps may not be necessary
+                #    exc.app.collection.set_active(exc.options['name'])
+                #    exc.to_form()
+                #    exc.read_form()
+                for option in exc.options:
+                    if option is not 'name':
+                        try:
+                            exc_final.options[option] = exc.options[option]
+                        except:
+                            exc.app.log.warning("Failed to copy option.",option)
+
+                #deep copy of all drills,to avoid any references
                 for drill in exc.drills:
                     point = Point(drill['point'].x,drill['point'].y)
                     exc_final.drills.append({"point": point, "tool": drill['tool']})
@@ -679,7 +696,7 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
                         max_numeric_tool=numeric_tool
                     toolsrework[exc.tools[toolname]['C']]=toolname
 
-                #final as last  becouse  names from final tools  will be used
+                #exc_final as last because names from final tools will be used
                 for toolname in exc_final.tools.iterkeys():
                     numeric_tool=int(toolname)
                     if numeric_tool>max_numeric_tool:
@@ -692,9 +709,10 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
                             exc_final.tools[str(max_numeric_tool+1)]={"C": toolvalues}
                     else:
                         exc_final.tools[toolsrework[toolvalues]]={"C": toolvalues}
+                #this value  was not co
+                exc_final.zeros=exc.zeros
                 exc_final.create_geometry()
 
-
     def build_ui(self):
         FlatCAMObj.build_ui(self)
 

+ 21 - 0
ObjectCollection.py

@@ -244,6 +244,27 @@ class ObjectCollection(QtCore.QAbstractListModel):
         iobj = self.createIndex(self.get_names().index(name), 0)  # Column 0
         self.view.selectionModel().select(iobj, QtGui.QItemSelectionModel.Select)
 
+    def set_inactive(self, name):
+        """
+        Unselect object by name from the project list. This triggers the
+        list_selection_changed event and call on_list_selection_changed.
+
+        :param name: Name of the FlatCAM Object
+        :return: None
+        """
+        iobj = self.createIndex(self.get_names().index(name), 0)  # Column 0
+        self.view.selectionModel().select(iobj, QtGui.QItemSelectionModel.Deselect)
+
+    def set_all_inactive(self):
+        """
+        Unselect all objects from the project list. This triggers the
+        list_selection_changed event and call on_list_selection_changed.
+
+        :return: None
+        """
+        for name in self.get_names():
+            self.set_inactive(name)
+
     def on_list_selection_change(self, current, previous):
         FlatCAMApp.App.log.debug("on_list_selection_change()")
         FlatCAMApp.App.log.debug("Current: %s, Previous %s" % (str(current), str(previous)))