← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] expose BOARD_COMMIT to python

 

Miles,

I'm not opposite to exposing the BOARD_COMMIT object but there are some serious ramifications of doing so. Although we already expose objects that can crash the board editor from python scripting so I don't know that one more will be all that significant. Can anyone else think of a reason not to expose the BOARD_COMMIT object to the python scripting? Before I merged your patch I am going to ask you to reformat the c++ code in the pcbnew_scripting_helpers.cpp file. If you are unsure of the code formating, please take a look at the kicad coding policy[1].

Thanks,

Wayne

[1]: http://docs.kicad-pcb.org/doxygen/md_Documentation_development_coding-style-policy.html

On 02/24/2018 05:04 AM, miles mccoo wrote:
Back in November I was in a thread about board_commit:
https://lists.launchpad.net/kicad-developers/msg32063.html

The topic had come up in another patch:
https://lists.launchpad.net/kicad-developers/msg32134.html


See attached path file. added needed code to SWIG to enable using BOARD_COMMIT


As a basic test, I ran the attached commit.py [1] on the attached commit.kicad_pcb. It just moves some modules and adds some vias. undo seems to work fine and (perhaps more important) the canvas updates correctly (there are some bugs in fresh that I haven't figured out)

I have also updated some of my other scripts to use it and almost all seems well.
*
*
*The thing that doesn't work...*

If I run a script as an external plugin, undoing, brings me back to an empty canvas. I don't know how to debug that. Some guidance could be helpful. I don't think this is a problem in the python interface, but rather some multi-threading thing in BOARD_COMMIT itself.

Here's a demo of the problem:
https://youtu.be/YR-9dx_lkUo

place_by_sch described in the video is here: https://github.com/mmccoo/kicad_mmccoo/blob/master/place_by_sch/place_by_sch.py

The board_commit stuff isn't in that version[2]


Miles


[1] I have a feeling the py file will be filtered, so here it is
toplayer = layertable['F.Cu']
bottomlayer = layertable['B.Cu']
for mod in board.GetModules():
     print("mod {}".format(mod.GetReference()))
     newvia = pcbnew.VIA(board)
     board.Add(newvia)
     newvia.SetNet(gnd)
     nc = gnd.GetNetClass()
     newvia.SetWidth(nc.GetViaDiameter())
     newvia.SetPosition(mod.GetPosition())
     newvia.SetLayerPair(toplayer, bottomlayer)
     newvia.SetViaType(pcbnew.VIA_THROUGH)
     bc.Added(newvia)
     bc.Modify(mod)
    mod.SetPosition(pcbnew.wxPoint(mod.GetPosition().x + pcbnew.Millimeter2iu(10),                                    mod.GetPosition().y + pcbnew.Millimeter2iu(10)))


bc.Push("moved stuff")


[2]
diff --git a/place_by_sch/place_by_sch.py b/place_by_sch/place_by_sch.py
index 22bc21c..5f70354 100644
--- a/place_by_sch/place_by_sch.py
+++ b/place_by_sch/place_by_sch.py
@@ -7,7 +7,9 @@ import re
  def PlaceBySch():
      board = pcbnew.GetBoard()
-
+    print("getting board commit")
+    bc = pcbnew.NewBoardCommit()
+
      board_path = board.GetFileName()
      sch_path = board_path.replace(".kicad_pcb", ".sch")
@@ -114,9 +116,10 @@ def PlaceBySch():
          # oldvalue * 25.4 / 10e4
          newx = locs[ref][0] * 25.4 * 1000.0
          newy = locs[ref][1] * 25.4 * 1000.0
+        bc.Modify(mod)
          mod.SetPosition(pcbnew.wxPoint(int(newx), int(newy)))
          mod.SetOrientation(locs[ref][2]*10)
          print("placing {} at {},{}".format(ref, newx, newy))
-
-    pcbnew.Refresh();
+    bc.Push("place_by_sch")
+    #pcbnew.Refresh();




for my personal reference: this is my sixth patch



_______________________________________________
Mailing list: https://launchpad.net/~kicad-developers
Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp



Follow ups

References