mirror of
https://forge.apps.education.fr/blender-edutech/jumeaux-numeriques.git
synced 2024-01-27 06:56:18 +01:00
Communication entre Blender et Qt5 (point d'étape)
This commit is contained in:
parent
618c8250b8
commit
70125297bf
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
<data>
|
||||
<screen>
|
||||
<width>1039</width>
|
||||
<height>585</height>
|
||||
<width>1609</width>
|
||||
<height>905</height>
|
||||
<quality>1</quality>
|
||||
</screen>
|
||||
</data>
|
56
twin_plot.py
56
twin_plot.py
@ -53,43 +53,53 @@ def plot(data):
|
||||
scene.objects['System']['plot_data'].append(plot_config[obj][1][0])
|
||||
|
||||
# Démarrer le processus
|
||||
scene.objects['System']['plot_proc'] = subprocess.Popen([sys.executable, os.path.join(os.getcwd(), "twin_plot_qt.py")], stdin=subprocess.PIPE, stdout=subprocess.PIPE, encoding = 'utf8')
|
||||
stout, sterr = scene.objects['System']['plot_proc'].communicate() # FIXME : attente du message retour pour lancer l'acquisition
|
||||
scene.objects['System']['plot_proc'] = subprocess.Popen([sys.executable, os.path.join(os.getcwd(), "twin_plot_qt.py")], stdin=subprocess.PIPE, encoding = 'utf8', universal_newlines=True)
|
||||
# scene.objects['System']['plot_proc'] = subprocess.Popen([sys.executable, os.path.join(os.getcwd(), "twin_plot_qt.py")], stdin=subprocess.PIPE, stdout=subprocess.PIPE, encoding = 'utf8')
|
||||
# stout = scene.objects['System']['plot_proc'].communicate() # FIXME : attente du message retour pour lancer l'acquisition
|
||||
# print("Blender stout : ", stout)
|
||||
scene.objects['System']['plot']=True
|
||||
|
||||
###############################################################################
|
||||
# Mise à jour du graphique
|
||||
###############################################################################
|
||||
|
||||
def truncate(n, decimals=0):
|
||||
multiplier = 10**decimals
|
||||
return int(n* multiplier)/multiplier
|
||||
|
||||
def plot_maj(cont):
|
||||
if cont.sensors['Plot'].positive :
|
||||
|
||||
# Affichage du graphique
|
||||
if scene.objects['System']['plot_draw']:
|
||||
if scene.objects['System']['plot_ticktime'] != truncate(scene.objects['System']['plot_time'], 0) or True:
|
||||
|
||||
# Préparation du message
|
||||
# FIXME : ajouter les valeurs réelles et valeurs numériques ('activated_real')
|
||||
# msg=str(round(scene.objects['System']['plot_time'], 2))
|
||||
msg=format(scene.objects['System']['plot_time'],".2f")
|
||||
for obj in scene.objects['System']['plot_data']:
|
||||
if scene.objects[obj]['activated']:
|
||||
msg = msg+",1"
|
||||
# Préparation du message
|
||||
# FIXME : ajouter les valeurs réelles et valeurs numériques ('activated_real')
|
||||
scene.objects['System']['plot_ticktime'] = truncate(scene.objects['System']['plot_time'], 0)
|
||||
# msg=str(round(scene.objects['System']['plot_time'], 1))
|
||||
# msg=format(scene.objects['System']['plot_time'],".2f")
|
||||
msg=format(scene.objects['System']['plot_ticktime'],".2f")
|
||||
for obj in scene.objects['System']['plot_data']:
|
||||
if scene.objects[obj]['activated']:
|
||||
msg = msg+",1"
|
||||
else:
|
||||
msg = msg+",0"
|
||||
msg = msg+"\n"
|
||||
|
||||
# Envoi (Pipe)
|
||||
if scene.objects['System']['plot_proc'].poll()==None:
|
||||
# scene.objects['System']['plot_proc'].communicate(input=time_send.encode())[0] # Communication bloquante
|
||||
print ("twin : ", msg)
|
||||
scene.objects['System']['plot_proc'].stdin.write(msg)
|
||||
else:
|
||||
msg = msg+",0"
|
||||
msg = msg+"\n"
|
||||
# Arrêt
|
||||
print ("Stop")
|
||||
scene.objects['System']['plot']=False
|
||||
scene.objects['System']['plot_draw'] =False
|
||||
scene.objects['System']['plot_proc'].terminate()
|
||||
|
||||
# Envoi (Pipe)
|
||||
if scene.objects['System']['plot_proc'].poll()==None:
|
||||
# scene.objects['System']['plot_proc'].communicate(input=time_send.encode())[0] # Communication bloquante
|
||||
scene.objects['System']['plot_proc'].stdin.write(msg)
|
||||
else:
|
||||
print ("Stop")
|
||||
scene.objects['System']['plot']=False
|
||||
scene.objects['System']['plot_draw'] =False
|
||||
scene.objects['System']['plot_proc'].terminate()
|
||||
|
||||
# Arret de l'affichage du graphique
|
||||
else :
|
||||
# Arrêt de l'affichage du graphique
|
||||
if scene.objects['System']['plot_proc'].poll()==None:
|
||||
pass
|
||||
else:
|
||||
|
@ -50,11 +50,13 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
self.show()
|
||||
|
||||
# Timer pour le update_plot
|
||||
fps = 60
|
||||
fps = 120 # Blender est cadencé à 60 fps
|
||||
self.timer = QtCore.QTimer()
|
||||
self.timer.setInterval(1000/fps)
|
||||
# self.timer.setInterval(int(1000/fps))
|
||||
self.timer.setInterval(1)
|
||||
self.timer.timeout.connect(self.update_plot)
|
||||
self.timer.start()
|
||||
print("Qt : Canvas ready\n")
|
||||
|
||||
# Lecture des données et mise à jour du graphique
|
||||
def update_plot(self):
|
||||
@ -62,26 +64,85 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
|
||||
# Données
|
||||
|
||||
# donnees = ([0,1,2,3,4], [10,1,20,3,40])
|
||||
# print (self.xdata[len(self.xdata)-1]+1)
|
||||
|
||||
# Essai
|
||||
# new_x=self.xdata[len(self.xdata)-1]+1
|
||||
# self.xdata.append(new_x)
|
||||
# self.ydata.append(random.randint(0, 10))
|
||||
|
||||
# Lecture du Pipe
|
||||
# Lecture du Pipe simple
|
||||
msg=""
|
||||
# print (sys.stdin)
|
||||
# contents = sys.stdin.read(1)
|
||||
# # contents = sys.stdin.buffer
|
||||
# print ("contents :", contents)
|
||||
|
||||
for line in sys.stdin:
|
||||
msg = line.rstrip()
|
||||
break
|
||||
print(msg)
|
||||
|
||||
# X et Y
|
||||
# FIXME : temps et une valeur
|
||||
msg_list=msg.split(',')
|
||||
print(msg_list)
|
||||
if msg_list[0] != "":
|
||||
self.xdata = self.xdata + [float(msg_list[0])]
|
||||
self.ydata = self.ydata + [float(msg_list[1])]
|
||||
# msg_list=msg.split(',')
|
||||
# print(msg_list)
|
||||
# if msg_list[0] != "":
|
||||
# self.xdata = self.xdata + [float(msg_list[0])]
|
||||
# self.ydata = self.ydata + [float(msg_list[1])]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# # Lecture du Pipe
|
||||
# # i=0
|
||||
# # lines = sys.stdin.readlines()
|
||||
# # print (lines)
|
||||
# # print ("b")
|
||||
|
||||
# msg_line=""
|
||||
# # msg_lines=[]
|
||||
# for line in sys.stdin:
|
||||
# # i+=1
|
||||
# # print (i)
|
||||
# msg_line = line.rstrip()
|
||||
# # msg_lines.append(msg_line)
|
||||
# # print("Qt msg_lines :", msg)
|
||||
# # if i==2:
|
||||
# # break
|
||||
# break
|
||||
# print("Qt :", msg_line)
|
||||
# # print("Qt msg_lines :", msg_lines)
|
||||
|
||||
# # X et Y
|
||||
# # FIXME : temps msg_list[0] et une seule valeur msg_list[1]
|
||||
# msg_list=msg_line.split(',')
|
||||
# # print(msg_list)
|
||||
# if msg_list[0] != "":
|
||||
# self.xdata = self.xdata + [float(msg_list[0])]
|
||||
# self.ydata = self.ydata + [float(msg_list[1])]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# for line in msg_lines:
|
||||
# msg_list=line.split(',')
|
||||
# # print(msg_list)
|
||||
# if msg_list[0] != "":
|
||||
# self.xdata = self.xdata + [float(msg_list[0])]
|
||||
# self.ydata = self.ydata + [float(msg_list[1])]
|
||||
|
||||
|
||||
# for line in sys.stdin:
|
||||
# msg_list=msg.split(',')
|
||||
# print(msg_list)
|
||||
# if msg_list[0] != "":
|
||||
# self.xdata = self.xdata + [float(msg_list[0])]
|
||||
# self.ydata = self.ydata + [float(msg_list[1])]
|
||||
|
||||
|
||||
# self.ydata = self.ydata + [random.randint(0, 10)]
|
||||
# Drop off the first y element, append a new one.
|
||||
|
Loading…
Reference in New Issue
Block a user