Skip to content

Commit

Permalink
Merge pull request #24 from FlachyJoe/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
FlachyJoe authored Oct 13, 2021
2 parents 699788e + bbbd6ab commit 66037b6
Show file tree
Hide file tree
Showing 13 changed files with 312 additions and 96 deletions.
52 changes: 30 additions & 22 deletions pdinclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,44 @@ def __init__(self, obj):
self.object = obj
self.Type = "PDInclude"
obj.addProperty('App::PropertyFileIncluded', 'PDFile', '', '')
self.isOpen = False

def startEdit(self):
sFile = self.object.PDFile
pdServer = locator.getFCPDWorkbench().pdServer
if sFile:
if not pdServer or not pdServer.isRunning:
Gui.activateWorkbench("FCPDWorkbench")
Gui.runCommand("FCPD_Launch")
pdServer = locator.getFCPDWorkbench().pdServer
Log('wait for PureData\n')
while pdServer.isWaiting:
Gui.updateGui()
Log('PureData is ready\n')

_, self.tmpFile = tempfile.mkstemp()
shutil.copyfile(sFile, self.tmpFile)
dirName, fileName = os.path.split(self.tmpFile)
pdServer.send('0 pd open %s %s' % (fileName, dirName))
# watch for file change
self.fs_watcher = QtCore.QFileSystemWatcher([self.tmpFile])
self.fs_watcher.fileChanged.connect(self.endEdit)

def endEdit(self, filename):
Log("%s have changed\n" % filename)
if not self.isOpen:
sFile = self.object.PDFile
pdServer = locator.getFCPDWorkbench().pdServer
if sFile:
if not pdServer or not pdServer.isRunning:
Gui.activateWorkbench("FCPDWorkbench")
Gui.runCommand("FCPD_Launch")
pdServer = locator.getFCPDWorkbench().pdServer
Log('wait for PureData\n')
while pdServer.isWaiting:
Gui.updateGui()
Log('PureData is ready\n')

_, self.tmpFile = tempfile.mkstemp()
shutil.copyfile(sFile, self.tmpFile)
dirName, fileName = os.path.split(self.tmpFile)
pdServer.send('0 pd open %s %s' % (fileName, dirName))
self.isOpen = True
# watch for file change
self.fs_watcher = QtCore.QFileSystemWatcher([self.tmpFile])
self.fs_watcher.fileChanged.connect(self.fileChanged)

def fileChanged(self, filename):
Log("%s has changed\n" % filename)
if self.tmpFile:
self.object.PDFile = self.tmpFile
App.ActiveDocument.recompute()

def endEdit(self):
os.remove(self.tmpFile)
self.isOpen = False

def onDocumentRestored(self, obj):
self.object = obj
self.isOpen = False

def __getstate__(self):
return None
Expand Down
47 changes: 47 additions & 0 deletions pdlib/fc_castList.pd
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#N canvas 1950 162 734 537 12;
#X obj 130 70 fc_isList;
#X obj 190 450 fc_list;
#X obj 130 100 list;
#X obj 190 100 list;
#X obj 130 10 inlet;
#X obj 130 490 outlet;
#X msg 190 420 \$1 \$2 \$3;
#X obj 130 40 t a a a;
#X obj 190 220 list;
#X obj 250 220 list;
#X obj 190 130 t a a a;
#X obj 190 190 fc_isVector;
#X obj 190 390 list trim;
#X obj 190 160 list trim;
#X obj 310 360 list;
#X obj 370 360 list;
#X obj 310 270 t a a a;
#X obj 310 300 list trim;
#X obj 310 330 fc_isRotation;
#X connect 0 0 2 0;
#X connect 0 1 3 0;
#X connect 1 0 5 0;
#X connect 2 0 5 0;
#X connect 3 0 10 0;
#X connect 4 0 7 0;
#X connect 6 0 1 0;
#X connect 7 0 0 0;
#X connect 7 1 2 1;
#X connect 7 2 3 1;
#X connect 8 0 12 0;
#X connect 9 0 16 0;
#X connect 10 0 13 0;
#X connect 10 1 8 1;
#X connect 10 2 9 1;
#X connect 11 0 8 0;
#X connect 11 1 9 0;
#X connect 12 0 6 0;
#X connect 13 0 11 0;
#X connect 14 0 12 0;
#X connect 15 0 5 0;
#X connect 16 0 17 0;
#X connect 16 1 14 1;
#X connect 16 2 15 1;
#X connect 17 0 18 0;
#X connect 18 0 14 0;
#X connect 18 1 15 0;
40 changes: 40 additions & 0 deletions pdlib/fc_isList.pd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#N canvas 1633 170 570 570 12;
#X obj 50 10 inlet;
#X msg 210 280 0;
#X obj 100 180 list split 1;
#X obj 100 210 list trim;
#X obj 100 80 route list;
#X obj 210 180 list length;
#X obj 100 110 t l l;
#X obj 100 280 ==;
#X obj 210 210 - 1;
#X obj 50 40 t b a;
#X obj 30 400 spigot;
#X obj 30 430 outlet;
#X obj 148 364 == 0;
#X obj 100 400 spigot;
#X obj 104 316 t f f;
#X obj 100 430 outlet;
#X obj 100 240 route float;
#X connect 0 0 9 0;
#X connect 1 0 14 0;
#X connect 2 0 3 0;
#X connect 2 2 1 0;
#X connect 3 0 16 0;
#X connect 4 0 6 0;
#X connect 4 1 1 0;
#X connect 5 0 8 0;
#X connect 6 0 2 0;
#X connect 6 1 5 0;
#X connect 7 0 14 0;
#X connect 8 0 7 1;
#X connect 9 0 10 0;
#X connect 9 0 13 0;
#X connect 9 1 4 0;
#X connect 10 0 11 0;
#X connect 12 0 13 1;
#X connect 13 0 15 0;
#X connect 14 0 10 1;
#X connect 14 1 12 0;
#X connect 16 0 7 0;
#X connect 16 1 1 0;
23 changes: 12 additions & 11 deletions pdlib/fc_isRotation.pd
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#N canvas 182 391 450 325 12;
#X obj 113 74 inlet;
#X obj 113 206 outlet;
#X msg 194 162 0;
#X msg 113 162 1;
#X obj 113 118 route Rot Yaw-Pitch-Roll;
#X connect 0 0 4 0;
#X connect 2 0 1 0;
#N canvas 1911 264 450 325 12;
#X obj 10 10 inlet;
#X obj 10 110 outlet;
#X obj 10 40 route Rot Yaw-Pitch-Roll;
#X msg 10 70 bang;
#X msg 90 70 bang;
#X obj 90 110 outlet;
#X connect 0 0 2 0;
#X connect 2 0 3 0;
#X connect 2 1 3 0;
#X connect 2 2 4 0;
#X connect 3 0 1 0;
#X connect 4 0 3 0;
#X connect 4 1 3 0;
#X connect 4 2 2 0;
#X connect 4 0 5 0;
25 changes: 13 additions & 12 deletions pdlib/fc_isVector.pd
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#N canvas 167 388 450 300 12;
#X obj 113 74 inlet;
#X obj 113 206 outlet;
#X msg 194 162 0;
#X msg 113 162 1;
#X obj 113 118 route Vector Pos;
#X connect 0 0 4 0;
#X connect 2 0 1 0;
#X connect 3 0 1 0;
#X connect 4 0 3 0;
#X connect 4 1 3 0;
#X connect 4 2 2 0;
#N canvas 1695 264 450 325 12;
#X obj 20 10 inlet;
#X obj 20 130 outlet;
#X obj 20 50 route Vector Pos;
#X obj 110 130 outlet;
#X msg 20 90 bang;
#X msg 110 90 bang;
#X connect 0 0 2 0;
#X connect 2 0 4 0;
#X connect 2 1 4 0;
#X connect 2 2 5 0;
#X connect 4 0 1 0;
#X connect 5 0 3 0;
24 changes: 14 additions & 10 deletions pdlib/fc_placement.pd
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#N canvas 592 406 604 449 12;
#N canvas 573 232 604 613 12;
#X obj 90 10 inlet;
#X obj 270 10 inlet;
#X obj 90 130 list prepend Placement;
#X obj 90 230 list append;
#X obj 90 160 t a b;
#X obj 130 200 any;
#X obj 90 170 list prepend Placement;
#X obj 90 340 list append;
#X obj 90 200 t a b;
#X obj 130 310 any;
#X obj 410 70 fc_rotation 0 0 0;
#X obj 410 40 loadbang;
#X obj 120 70 fc_isVector;
#X obj 90 40 t a a;
#X obj 90 100 spigot;
#X obj 90 130 spigot;
#X obj 300 70 fc_isRotation;
#X obj 270 40 t a a;
#X obj 270 100 spigot;
#X obj 90 259 outlet;
#X obj 270 130 spigot;
#X obj 90 369 outlet;
#X msg 120 100 1;
#X msg 300 100 1;
#X connect 0 0 9 0;
#X connect 1 0 12 0;
#X connect 2 0 4 0;
Expand All @@ -23,11 +25,13 @@
#X connect 5 0 3 1;
#X connect 6 0 5 1;
#X connect 7 0 6 0;
#X connect 8 0 10 1;
#X connect 8 0 15 0;
#X connect 9 0 10 0;
#X connect 9 1 8 0;
#X connect 10 0 2 0;
#X connect 11 0 13 1;
#X connect 11 0 16 0;
#X connect 12 0 13 0;
#X connect 12 1 11 0;
#X connect 13 0 5 1;
#X connect 15 0 10 1;
#X connect 16 0 13 1;
6 changes: 6 additions & 0 deletions pdlib/fc_print.pd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#N canvas 911 212 450 325 12;
#X obj 90 90 print \$1;
#X obj 90 30 inlet;
#X obj 90 60 fc_str;
#X connect 1 0 2 0;
#X connect 2 0 0 0;
10 changes: 10 additions & 0 deletions pdlib/fc_str.pd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#N canvas 580 378 450 300 12;
#X obj 10 100 fc_process;
#X obj 10 71 list prepend str;
#X obj 10 10 inlet;
#X obj 10 40 fc_unList;
#X obj 10 129 outlet;
#X connect 0 0 4 0;
#X connect 1 0 0 0;
#X connect 2 0 3 0;
#X connect 3 0 1 0;
21 changes: 21 additions & 0 deletions pdlib/fc_unList.pd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#N canvas 1856 254 816 576 12;
#X obj 100 10 inlet;
#X obj 150 240 outlet;
#X obj 100 90 fc_isList;
#X obj 160 120 any;
#X obj 100 40 t a a a;
#X obj 100 120 any;
#X obj 100 150 list split 2;
#X obj 180 210 print;
#X msg 180 180 ERROR in list computation;
#X connect 0 0 4 0;
#X connect 2 0 5 0;
#X connect 2 1 3 0;
#X connect 3 0 1 0;
#X connect 4 0 2 0;
#X connect 4 1 5 1;
#X connect 4 2 3 1;
#X connect 5 0 6 0;
#X connect 6 1 1 0;
#X connect 6 2 8 0;
#X connect 8 0 7 0;
24 changes: 24 additions & 0 deletions pdlib/fc_vectorMult.pd
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#N canvas 560 324 450 325 12;
#X obj 110 30 inlet;
#X obj 110 60 fc_vectorXYZ;
#X obj 10 30 inlet;
#X obj 110 110 *;
#X obj 140 110 *;
#X obj 170 110 *;
#X obj 110 150 fc_vector;
#X obj 110 180 outlet;
#X text 110 10 vector;
#X text 10 10 scalar;
#X obj 10 60 t f f f;
#X connect 0 0 1 0;
#X connect 1 0 3 1;
#X connect 1 1 4 1;
#X connect 1 2 5 1;
#X connect 2 0 10 0;
#X connect 3 0 6 0;
#X connect 4 0 6 1;
#X connect 5 0 6 2;
#X connect 6 0 7 0;
#X connect 10 0 3 0;
#X connect 10 1 4 0;
#X connect 10 2 5 0;
25 changes: 16 additions & 9 deletions pdmsgtranslator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

# this module translate PD message to/from Python values

import numbers

import FreeCAD as App

# shortcuts of FreeCAD console
Expand Down Expand Up @@ -73,14 +75,19 @@ def strFromValue(cls, val):
else:
# empty list
string = 'None'
else:
elif (isinstance(val, numbers.Number) or
isinstance(val, bool) or
isinstance(val, App.Vector) or
isinstance(val, App.Rotation) or
isinstance(val, App.Placement)
):
string = str(val)
if string.startswith("<") and string.endswith(">"):
if val in cls.objectsStore:
return "^%i" % cls.objectsStore.index(val)
# store this object and return a ref
cls.objectsStore.append(val)
return "^%i" % (len(cls.objectsStore)-1)
elif isinstance(val, str):
string = val
else:
# store this object and return a ref
cls.objectsStore.append(val)
return "^%i" % (len(cls.objectsStore)-1)

return string.translate(str.maketrans(',=', ' ', ';()[]{}"\''))

Expand Down Expand Up @@ -126,8 +133,8 @@ def valueFromStr(cls, words):
count = int(words[1])
usedWords = 2
for _ in range(0, count):
(val, typ), cnt = cls.valueFromStr(words[usedWords:])
retValue.append(val)
val, cnt = cls.valueFromStr(words[usedWords:])
retValue.append(val.value)
usedWords += cnt
elif words[0] == "True":
retValue = True
Expand Down
Loading

0 comments on commit 66037b6

Please sign in to comment.