2022-12-10 18:44:20 +01:00
|
|
|
|
import bge # Blender Game Engine (UPBGE)
|
|
|
|
|
import bpy # Blender
|
2023-01-28 01:10:05 +01:00
|
|
|
|
import os
|
2022-12-11 15:50:38 +01:00
|
|
|
|
import sys
|
2023-01-28 01:10:05 +01:00
|
|
|
|
import importlib
|
|
|
|
|
import subprocess # Multiprocessus
|
2022-12-10 18:44:20 +01:00
|
|
|
|
import math
|
2022-12-13 02:42:31 +01:00
|
|
|
|
import time
|
2022-12-10 18:44:20 +01:00
|
|
|
|
import xml.etree.ElementTree as ET # Creating/parsing XML file
|
2022-12-11 15:50:38 +01:00
|
|
|
|
import runpy # Exécution de script Python légère (sans import)
|
2022-12-10 18:44:20 +01:00
|
|
|
|
|
2022-12-11 10:28:41 +01:00
|
|
|
|
import twin_doc # Documentation
|
|
|
|
|
import twin_about # About
|
2022-12-10 18:44:20 +01:00
|
|
|
|
|
|
|
|
|
###############################################################################
|
2022-12-11 10:28:41 +01:00
|
|
|
|
# twin.py
|
2022-12-11 15:50:38 +01:00
|
|
|
|
# @title: Bibliothèque générale de l'environnement 3D pour le développement de jumeau numérique
|
2022-12-10 18:44:20 +01:00
|
|
|
|
# @project: Blender-EduTech
|
|
|
|
|
# @lang: fr
|
|
|
|
|
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
2024-01-04 14:51:42 +01:00
|
|
|
|
# @copyright: Copyright (C) 2020-2024 Philippe Roy
|
2022-12-10 18:44:20 +01:00
|
|
|
|
# @license: GNU GPL
|
|
|
|
|
#
|
2022-12-11 08:40:31 +01:00
|
|
|
|
# Cet environnement 3D est programmable en Python. Il est destiné à la découverte de la programmation de système pluritechnologique.
|
2022-12-22 05:02:33 +01:00
|
|
|
|
#
|
2022-12-10 18:44:20 +01:00
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
# UPBGE scene
|
|
|
|
|
scene = bge.logic.getCurrentScene()
|
2022-12-31 16:48:54 +01:00
|
|
|
|
eevee = bpy.context.scene.eevee
|
2023-01-28 01:10:05 +01:00
|
|
|
|
system=importlib.import_module(scene.objects['System']['system']) # Système
|
|
|
|
|
scene.objects['System']['script'] = os.path.join(os.getcwd(), scene.objects['System']['system']+"_cmd.py") # Script par défaut
|
2022-12-11 15:50:38 +01:00
|
|
|
|
|
|
|
|
|
# Memory
|
|
|
|
|
sys.setrecursionlimit(10**5) # Limite sur la récursivité (valeur par défaut : 1000) -> segfault de Blender
|
|
|
|
|
|
2022-12-10 18:44:20 +01:00
|
|
|
|
# Config file
|
2023-01-25 06:03:02 +01:00
|
|
|
|
twin_config = ET.parse('twin_config.xml').getroot()
|
2022-12-10 18:44:20 +01:00
|
|
|
|
|
|
|
|
|
# Couleurs
|
2022-12-15 06:20:48 +01:00
|
|
|
|
color_cmd = (0.8, 0.8, 0.8, 1) # Blanc
|
|
|
|
|
color_cmd_hl = (0.8, 0.619, 0.021, 1) # Jaune
|
2022-12-22 05:02:33 +01:00
|
|
|
|
color_passive = (0.800, 0.005, 0.315,1) # bouton non activable : magenta
|
|
|
|
|
color_active = (0.799, 0.130, 0.063,1) # bouton activable : orange
|
|
|
|
|
color_hl = (0.8, 0.8, 0.8, 1) # bouton focus : blanc
|
2023-01-07 10:42:19 +01:00
|
|
|
|
color_activated = (0.8, 0.619, 0.021, 1) # bouton activé numériquement uniquement : jaune
|
|
|
|
|
color_activated_real = (0.799, 0.031, 0.038, 1) # élément activé physiquement uniquement : rouge (hors clic)
|
|
|
|
|
color_activated_dbl = (0.246, 0.687, 0.078, 1) # élément activé physiquement et numériquement : vert clair
|
2022-12-10 18:44:20 +01:00
|
|
|
|
|
2023-01-11 18:48:45 +01:00
|
|
|
|
color_blue = (0.007, 0.111, 0.638, 1) # Couleur Blue (Actionneur type moteur)
|
|
|
|
|
color_blue_dark = (0.004, 0.054, 0.296, 1) # Couleur Blue (Actionneur type moteur)
|
|
|
|
|
color_grey = (0.285, 0.285, 0.285, 1) # Couleur Blue (Actionneur type moteur)
|
|
|
|
|
color_led_yellow = (0.799, 0.617, 0.021, 1) # Couleur Led Jaune
|
|
|
|
|
|
2022-12-10 18:44:20 +01:00
|
|
|
|
# Constantes
|
|
|
|
|
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
|
|
|
|
|
JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
|
|
|
|
|
ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
|
|
|
|
# JUST_DEACTIVATED = bge.logic.KX_SENSOR_JUST_DEACTIVATED
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
# Gestion du clavier
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
# Mode : Orbit(0) par défaut, Pan(1) avec Shift, Zoom (2) avec Ctrl, Eclaté (1) avec Shift
|
|
|
|
|
def keyboard(cont):
|
2022-12-11 08:40:31 +01:00
|
|
|
|
obj = scene.objects['System']
|
2022-12-10 18:44:20 +01:00
|
|
|
|
keyboard = bge.logic.keyboard
|
|
|
|
|
|
|
|
|
|
# Touche ESC
|
|
|
|
|
if JUST_ACTIVATED in keyboard.inputs[bge.events.ESCKEY].queue:
|
|
|
|
|
|
|
|
|
|
# Maj du fichier de config (screen size : data/config/screen/width-> [0][0].text)
|
|
|
|
|
screen_width = bge.render.getWindowWidth()
|
|
|
|
|
screen_height = bge.render.getWindowHeight()
|
2023-01-25 06:03:02 +01:00
|
|
|
|
twin_config[0][0].text=str(screen_width)
|
|
|
|
|
twin_config[0][1].text=str(screen_height)
|
|
|
|
|
twin_config[0][2].text=str(scene.objects['About']['quality'])
|
|
|
|
|
buffer_xml = ET.tostring(twin_config)
|
2022-12-11 10:28:41 +01:00
|
|
|
|
with open("twin_config.xml", "wb") as f:
|
2022-12-10 18:44:20 +01:00
|
|
|
|
f.write(buffer_xml)
|
|
|
|
|
|
|
|
|
|
# Sortir
|
|
|
|
|
bge.logic.endGame()
|
|
|
|
|
|
|
|
|
|
# Shift -> mode 1 : Pan (clic milieu) ou Eclaté (clic gauche)
|
|
|
|
|
if JUST_ACTIVATED in keyboard.inputs[bge.events.LEFTSHIFTKEY].queue:
|
|
|
|
|
obj['manip_mode']=1
|
|
|
|
|
if JUST_ACTIVATED in keyboard.inputs[bge.events.RIGHTSHIFTKEY].queue:
|
|
|
|
|
obj['manip_mode']=1
|
|
|
|
|
|
|
|
|
|
# Ctrl -> mode 2 : Zoom (clic milieu)
|
|
|
|
|
if JUST_ACTIVATED in keyboard.inputs[bge.events.LEFTCTRLKEY].queue:
|
|
|
|
|
obj['manip_mode']=2
|
|
|
|
|
if JUST_ACTIVATED in keyboard.inputs[bge.events.RIGHTCTRLKEY].queue:
|
|
|
|
|
obj['manip_mode']=2
|
|
|
|
|
|
|
|
|
|
# Pas de modificateur -> mode 0 : Orbit (clic milieu)
|
|
|
|
|
if JUST_RELEASED in keyboard.inputs[bge.events.LEFTSHIFTKEY].queue:
|
|
|
|
|
obj['manip_mode']=0
|
|
|
|
|
if JUST_RELEASED in keyboard.inputs[bge.events.RIGHTSHIFTKEY].queue:
|
|
|
|
|
obj['manip_mode']=0
|
|
|
|
|
if JUST_RELEASED in keyboard.inputs[bge.events.LEFTCTRLKEY].queue:
|
|
|
|
|
obj['manip_mode']=0
|
|
|
|
|
if JUST_RELEASED in keyboard.inputs[bge.events.RIGHTCTRLKEY].queue:
|
|
|
|
|
obj['manip_mode']=0
|
|
|
|
|
|
|
|
|
|
# Touche Home -> Reset de la vue
|
|
|
|
|
if JUST_ACTIVATED in keyboard.inputs[bge.events.HOMEKEY].queue:
|
|
|
|
|
manip_reset()
|
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
# Touche F5 -> Run et Pause
|
|
|
|
|
if JUST_ACTIVATED in keyboard.inputs[bge.events.F5KEY].queue:
|
|
|
|
|
cycle_run ()
|
|
|
|
|
|
|
|
|
|
# Touche F6 -> Stop / Init
|
|
|
|
|
if JUST_ACTIVATED in keyboard.inputs[bge.events.F6KEY].queue:
|
|
|
|
|
cycle_stop ()
|
2022-12-10 18:44:20 +01:00
|
|
|
|
|
|
|
|
|
###############################################################################
|
2022-12-11 15:50:38 +01:00
|
|
|
|
# Commandes
|
2022-12-10 18:44:20 +01:00
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Initialisation des commandes
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def cmd_init():
|
2022-12-18 00:55:45 +01:00
|
|
|
|
|
2023-02-07 03:40:50 +01:00
|
|
|
|
# Configuration de l'écran
|
2023-01-25 06:03:02 +01:00
|
|
|
|
bge.render.setWindowSize(int(twin_config[0][0].text),int(twin_config[0][1].text))
|
|
|
|
|
scene.objects['About']['quality'] = int(twin_config[0][2].text)
|
2023-07-11 15:49:37 +02:00
|
|
|
|
twin_about.quality_apply(scene.objects['About']['quality'], True)
|
2022-12-18 00:55:45 +01:00
|
|
|
|
|
2022-12-21 05:43:56 +01:00
|
|
|
|
# Ajout du Hud
|
|
|
|
|
# scene.active_camera = scene.objects["Camera"]
|
|
|
|
|
# scene.objects['Sun'].setVisible(True,True)
|
|
|
|
|
# scene.addOverlayCollection(scene.cameras['Camera-Hud'], bpy.data.collections['Hud'])
|
|
|
|
|
|
2022-12-18 00:55:45 +01:00
|
|
|
|
# UI : Commands
|
2022-12-11 15:50:38 +01:00
|
|
|
|
scene.objects['Run-Hl'].setVisible(False,False)
|
2022-12-26 18:10:17 +01:00
|
|
|
|
# scene.objects['Pause-Hl'].setVisible(False,False)
|
2022-12-11 08:40:31 +01:00
|
|
|
|
scene.objects['Doc-cmd-Hl'].setVisible(False,False)
|
2023-01-27 21:26:33 +01:00
|
|
|
|
scene.objects['ResetView-Hl'].setVisible(False,False)
|
|
|
|
|
scene.objects['File-Hl'].setVisible(False,False)
|
2022-12-10 18:44:20 +01:00
|
|
|
|
scene.objects['About-cmd-Hl'].setVisible(False,False)
|
|
|
|
|
|
2022-12-18 00:55:45 +01:00
|
|
|
|
# UI : Text, ...
|
|
|
|
|
scene.objects['Cmd-text']['Text']=""
|
|
|
|
|
scene.objects['Cmd-text'].setVisible(True,False)
|
2023-01-28 01:10:05 +01:00
|
|
|
|
scene.objects['Script-text']['Text']=scene.objects['System']['script']
|
2022-12-21 05:43:56 +01:00
|
|
|
|
scene.objects['Twins-text']['Text']="Connection fermée."
|
2022-12-18 00:55:45 +01:00
|
|
|
|
|
2022-12-15 06:20:48 +01:00
|
|
|
|
# Windows
|
2023-02-11 23:52:07 +01:00
|
|
|
|
windows=("Doc", "Doc_chap-general", "Doc_chap-system", "Doc_chap-python", "About", "Credits")
|
2022-12-15 06:20:48 +01:00
|
|
|
|
for window in windows:
|
|
|
|
|
scene.objects[window].setVisible(False,True)
|
|
|
|
|
|
2023-01-07 00:01:01 +01:00
|
|
|
|
# Jumeau
|
|
|
|
|
scene.objects['System']['twins'] = False
|
|
|
|
|
|
2022-12-10 18:44:20 +01:00
|
|
|
|
##
|
|
|
|
|
# Highlight des commandes
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def cmd_hl(cont):
|
|
|
|
|
obj = cont.owner
|
|
|
|
|
|
|
|
|
|
# Activation
|
2022-12-11 08:40:31 +01:00
|
|
|
|
if cont.sensors['MO'].status == JUST_ACTIVATED and scene.objects['System']['manip_mode']==0:
|
2022-12-13 02:42:31 +01:00
|
|
|
|
if obj.name!="Run" and obj.name!="Pause" and obj.name!="Stop" and obj.name!="Doc-cmd-colbox":
|
|
|
|
|
# if obj.name!="Run" and obj.name!="Pause" and obj.name!="Run-Hl" and obj.name!="Pause-Hl" and obj.name!="Pause-Hl":
|
2022-12-10 18:44:20 +01:00
|
|
|
|
obj.setVisible(False,True)
|
|
|
|
|
scene.objects[obj.name+'-Hl'].setVisible(True,True)
|
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
# Run et pause
|
|
|
|
|
if obj.name=="Pause" or obj.name=="Run":
|
|
|
|
|
if scene.objects['System']['run'] == True:
|
|
|
|
|
pass
|
|
|
|
|
# scene.objects['Pause'].setVisible(False,False) FIXME pause pas implémenté
|
|
|
|
|
# scene.objects['Pause-Hl'].setVisible(True,False) FIXME pause pas implémenté
|
2022-12-10 18:44:20 +01:00
|
|
|
|
else:
|
2022-12-11 15:50:38 +01:00
|
|
|
|
scene.objects['Run'].setVisible(False,False)
|
|
|
|
|
scene.objects['Run-Hl'].setVisible(True,False)
|
|
|
|
|
|
|
|
|
|
# Stop
|
|
|
|
|
if obj.name=="Stop":
|
|
|
|
|
scene.objects['Stop'].setVisible(False,False)
|
|
|
|
|
scene.objects['Stop-Hl'].setVisible(True,False)
|
|
|
|
|
|
|
|
|
|
# Doc
|
|
|
|
|
if obj.name=="Doc-cmd-colbox":
|
|
|
|
|
scene.objects['Doc-cmd'].setVisible(False,False)
|
|
|
|
|
scene.objects['Doc-cmd-Hl'].setVisible(True,False)
|
|
|
|
|
|
|
|
|
|
# Text
|
2022-12-18 00:55:45 +01:00
|
|
|
|
text_hl ={"Run":"Exécuter (F5)",
|
|
|
|
|
"Stop":"Stop et initialisation (F6)",
|
|
|
|
|
# "Pause":"Pause (F5)",
|
|
|
|
|
"Doc-cmd-colbox":"Documentation",
|
|
|
|
|
"ResetView": "Reset de la vue (Touche Début)",
|
2023-01-28 10:33:25 +01:00
|
|
|
|
"File": "Changer le fichier de commandes",
|
2022-12-18 00:55:45 +01:00
|
|
|
|
"About-cmd": "A propos"}
|
2022-12-18 01:35:36 +01:00
|
|
|
|
scene.objects['Cmd-text']['modal']= False
|
2022-12-18 00:55:45 +01:00
|
|
|
|
scene.objects['Cmd-text']['Text']= text_hl[obj.name]
|
2022-12-18 01:35:36 +01:00
|
|
|
|
if scene.objects['Doc']['page_chap']== "" and obj.name =="Doc-cmd-colbox" :
|
|
|
|
|
scene.objects['Cmd-text']['Text']= "Chargement de la documentation ..."
|
2023-01-05 00:40:14 +01:00
|
|
|
|
if scene.objects['Doc']['page_chap']!= "" and obj.name =="Doc-cmd-colbox" :
|
|
|
|
|
bpy.context.view_layer.update() # Bug de mise à jour
|
2022-12-18 00:55:45 +01:00
|
|
|
|
scene.objects['Cmd-text'].setVisible(True,False)
|
2022-12-11 15:50:38 +01:00
|
|
|
|
|
|
|
|
|
# Désactivation
|
|
|
|
|
if cont.sensors['MO'].status == JUST_RELEASED and (scene.objects['System']['manip_mode']==0 or scene.objects['System']['manip_mode']==9):
|
2024-01-02 15:13:14 +01:00
|
|
|
|
|
|
|
|
|
# Texte
|
|
|
|
|
if scene.objects['Cmd-text']['modal']:
|
|
|
|
|
scene.objects['Cmd-text']['Text']= "Erreur dans le script ... "
|
|
|
|
|
scene.objects['Cmd-text'].setVisible(True,False)
|
|
|
|
|
else:
|
2022-12-18 01:35:36 +01:00
|
|
|
|
scene.objects['Cmd-text']['Text']= ""
|
|
|
|
|
scene.objects['Cmd-text'].setVisible(False,False)
|
2024-01-02 15:13:14 +01:00
|
|
|
|
|
|
|
|
|
# Icone
|
2022-12-11 15:50:38 +01:00
|
|
|
|
if obj.name!="Run" and obj.name!="Pause" and obj.name!="Stop" and obj.name!="Doc-cmd-colbox":
|
2022-12-10 18:44:20 +01:00
|
|
|
|
scene.objects[obj.name+'-Hl'].setVisible(False,True)
|
|
|
|
|
obj.setVisible(True,True)
|
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
# Run et pause
|
|
|
|
|
if obj.name=="Pause" or obj.name=="Run":
|
|
|
|
|
if scene.objects['System']['run'] == True:
|
|
|
|
|
pass
|
|
|
|
|
# scene.objects['Pause-Hl'].setVisible(False,False) FIXME pause pas implémenté
|
|
|
|
|
# scene.objects['Pause'].setVisible(True,False) FIXME pause pas implémenté
|
2022-12-10 18:44:20 +01:00
|
|
|
|
else:
|
2022-12-11 15:50:38 +01:00
|
|
|
|
scene.objects['Run-Hl'].setVisible(False,False)
|
|
|
|
|
scene.objects['Run'].setVisible(True,False)
|
|
|
|
|
|
|
|
|
|
# Stop
|
|
|
|
|
if obj.name=="Stop":
|
|
|
|
|
scene.objects['Stop-Hl'].setVisible(False,False)
|
|
|
|
|
scene.objects['Stop'].setVisible(True,False)
|
|
|
|
|
|
|
|
|
|
# Doc
|
|
|
|
|
if obj.name=="Doc-cmd-colbox":
|
|
|
|
|
scene.objects['Doc-cmd-Hl'].setVisible(False,False)
|
|
|
|
|
scene.objects['Doc-cmd'].setVisible(True,False)
|
2022-12-10 18:44:20 +01:00
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Click sur les commandes
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def cmd_click(cont):
|
|
|
|
|
obj = cont.owner
|
2022-12-11 08:40:31 +01:00
|
|
|
|
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['System']['manip_mode']==0:
|
2022-12-10 18:44:20 +01:00
|
|
|
|
|
|
|
|
|
# Play et pause
|
|
|
|
|
if obj.name=="Pause" or obj.name=="Run":
|
2022-12-11 15:50:38 +01:00
|
|
|
|
cycle_run ()
|
2022-12-10 18:44:20 +01:00
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
# Stop
|
|
|
|
|
if obj.name=="Stop":
|
|
|
|
|
cycle_stop ()
|
2022-12-10 18:44:20 +01:00
|
|
|
|
|
2023-01-27 21:26:33 +01:00
|
|
|
|
# Aide
|
|
|
|
|
if obj.name=="Doc-cmd-colbox" :
|
|
|
|
|
twin_doc.open()
|
|
|
|
|
|
2022-12-10 18:44:20 +01:00
|
|
|
|
# Reset-view
|
2022-12-11 15:50:38 +01:00
|
|
|
|
if obj.name=="ResetView" :
|
2022-12-10 18:44:20 +01:00
|
|
|
|
manip_reset()
|
|
|
|
|
|
2023-01-27 21:26:33 +01:00
|
|
|
|
# Fichier de commande
|
|
|
|
|
if obj.name=="File" :
|
2023-01-28 01:10:05 +01:00
|
|
|
|
file_open()
|
2023-02-12 00:34:37 +01:00
|
|
|
|
system.system_reset()
|
2023-01-27 21:26:33 +01:00
|
|
|
|
|
2022-12-10 18:44:20 +01:00
|
|
|
|
# About
|
|
|
|
|
if obj.name=="About-cmd" :
|
2022-12-11 10:28:41 +01:00
|
|
|
|
twin_about.open()
|
2022-12-10 18:44:20 +01:00
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
# Manipulation du mécanisme
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Dessiner une cercle (bas niveau)
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def circle (center, radius, color):
|
|
|
|
|
ang = 0
|
|
|
|
|
ang_step = 0.1
|
|
|
|
|
while ang< 2 * math.pi:
|
2022-12-11 15:50:38 +01:00
|
|
|
|
x0 = center[0]+float(radius*math.cos(ang)*0.95)
|
|
|
|
|
y0 = center[1]
|
2022-12-10 18:44:20 +01:00
|
|
|
|
z0 = center[2]+float(radius*math.sin(ang))
|
|
|
|
|
x1 = center[0]+float(radius*math.cos(ang+ang_step)*0.95)
|
|
|
|
|
y1 = center[1]
|
|
|
|
|
z1 = center[2]+float(radius*math.sin(ang+ang_step))
|
|
|
|
|
bge.render.drawLine([x0,y0,z0],[x1,y1,z1],color)
|
|
|
|
|
ang += ang_step
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Initialisation de la vue 3D
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
# def manip_init(cont):
|
|
|
|
|
def manip_init():
|
|
|
|
|
|
2022-12-21 05:43:56 +01:00
|
|
|
|
# Ajout du Hud
|
|
|
|
|
scene.active_camera = scene.objects["Camera"]
|
|
|
|
|
scene.objects['Sun'].setVisible(True,True)
|
|
|
|
|
scene.addOverlayCollection(scene.cameras['Camera-Hud'], bpy.data.collections['Hud'])
|
|
|
|
|
|
2023-02-11 23:52:07 +01:00
|
|
|
|
# # Fenêtres
|
|
|
|
|
# scene.objects['About'].setVisible(False,True)
|
|
|
|
|
# scene.objects['Credits'].setVisible(False,True)
|
|
|
|
|
# scene.objects['Doc'].setVisible(False,True)
|
2022-12-10 18:44:20 +01:00
|
|
|
|
|
|
|
|
|
# Mémorisation de la position de la caméra
|
|
|
|
|
scene.objects['Camera']['init_lx']=scene.objects['Camera'].worldPosition.x
|
|
|
|
|
scene.objects['Camera']['init_ly']=scene.objects['Camera'].worldPosition.y
|
|
|
|
|
scene.objects['Camera']['init_lz']=scene.objects['Camera'].worldPosition.z
|
|
|
|
|
|
|
|
|
|
# Mémorisation de la position du modèle
|
2022-12-11 08:40:31 +01:00
|
|
|
|
scene.objects['System']['init_lx']=scene.objects['System'].worldPosition.x
|
|
|
|
|
scene.objects['System']['init_ly']=scene.objects['System'].worldPosition.y
|
|
|
|
|
scene.objects['System']['init_lz']=scene.objects['System'].worldPosition.z
|
|
|
|
|
scene.objects['System']['init_rx']=scene.objects['System'].worldOrientation.to_euler().x
|
|
|
|
|
scene.objects['System']['init_ry']=scene.objects['System'].worldOrientation.to_euler().y
|
|
|
|
|
scene.objects['System']['init_rz']=scene.objects['System'].worldOrientation.to_euler().z
|
2022-12-10 18:44:20 +01:00
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Atteindre une orientation (bas niveau)
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def applyRotationTo(obj, rx=None, ry=None, rz=None):
|
|
|
|
|
rres=0.001 # resolution rotation
|
|
|
|
|
|
|
|
|
|
# x
|
|
|
|
|
if rx is not None:
|
|
|
|
|
while (abs(rx-obj.worldOrientation.to_euler().x) > rres) :
|
|
|
|
|
if obj.worldOrientation.to_euler().x-rx > rres:
|
|
|
|
|
obj.applyRotation((-rres, 0, 0), True)
|
|
|
|
|
if rx-obj.worldOrientation.to_euler().x > rres:
|
|
|
|
|
obj.applyRotation((rres, 0, 0), True)
|
|
|
|
|
# print ("delta x ",rx-obj.worldOrientation.to_euler().x)
|
2022-12-18 01:35:36 +01:00
|
|
|
|
|
2022-12-10 18:44:20 +01:00
|
|
|
|
# y
|
|
|
|
|
if ry is not None:
|
|
|
|
|
while (abs(ry-obj.worldOrientation.to_euler().y) > rres) :
|
|
|
|
|
if obj.worldOrientation.to_euler().y-ry > rres:
|
|
|
|
|
obj.applyRotation((0, -rres, 0), True)
|
|
|
|
|
if ry-obj.worldOrientation.to_euler().y > rres:
|
|
|
|
|
obj.applyRotation((0, rres, 0), True)
|
|
|
|
|
# print ("delta y ",ry-obj.worldOrientation.to_euler().y)
|
|
|
|
|
|
|
|
|
|
# z
|
|
|
|
|
if rz is not None:
|
|
|
|
|
while (abs(rz-obj.worldOrientation.to_euler().z) > rres) :
|
|
|
|
|
if obj.worldOrientation.to_euler().z-rz > rres:
|
|
|
|
|
obj.applyRotation((0, 0, -rres), True)
|
|
|
|
|
if rz-obj.worldOrientation.to_euler().z > rres:
|
|
|
|
|
obj.applyRotation((0, 0, rres), True)
|
|
|
|
|
# print ("delta z ",rz-obj.worldOrientation.to_euler().z)
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Reset de la manipulation de la vue
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def manip_reset():
|
|
|
|
|
scene.objects['Camera'].worldPosition.x = scene.objects['Camera']['init_lx']
|
|
|
|
|
scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['init_ly']
|
|
|
|
|
scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['init_lz']
|
2022-12-11 08:40:31 +01:00
|
|
|
|
applyRotationTo(scene.objects['System'], 0, 0, 0)
|
|
|
|
|
scene.objects['System'].worldPosition.x = scene.objects['System']['init_lx']
|
|
|
|
|
scene.objects['System'].worldPosition.y = scene.objects['System']['init_ly']
|
|
|
|
|
scene.objects['System'].worldPosition.z = scene.objects['System']['init_lz']
|
2022-12-16 00:37:11 +01:00
|
|
|
|
# for objet in scene.objects['System']['objects'] :
|
|
|
|
|
# scene.objects[objet].setVisible(True,False)
|
|
|
|
|
# scene.objects[objet].restorePhysics()
|
|
|
|
|
# if objet+"_Lines.GP" in scene.objects:
|
|
|
|
|
# scene.objects[objet+"_Lines.GP"].setVisible(True,False)
|
2022-12-10 18:44:20 +01:00
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Position de départ pour la manipulation de la vue
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def manip_start(cont):
|
|
|
|
|
obj = cont.owner
|
|
|
|
|
obj['click_x']=cont.sensors['ClickM'].position[0]
|
|
|
|
|
obj['click_y']=cont.sensors['ClickM'].position[1]
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Manipulation du modèle ou de la caméra
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def manip(cont):
|
|
|
|
|
obj = cont.owner
|
|
|
|
|
sensibilite_orbit=0.0005
|
|
|
|
|
sensibilite_pan=0.005
|
|
|
|
|
sensibilite_zoom=0.01
|
|
|
|
|
delta_x=cont.sensors['DownM'].position[0]-obj['click_x']
|
|
|
|
|
delta_y=cont.sensors['DownM'].position[1]-obj['click_y']
|
|
|
|
|
|
|
|
|
|
# Orbit
|
|
|
|
|
if obj['manip_mode']==0:
|
2022-12-21 05:43:56 +01:00
|
|
|
|
x0 = scene.objects['Orbit-Hud'].worldPosition.x
|
|
|
|
|
y0 =scene.objects['Orbit-Hud'].worldPosition.y
|
|
|
|
|
z0 =scene.objects['Orbit-Hud'].worldPosition.z
|
2022-12-10 18:44:20 +01:00
|
|
|
|
width = bge.render.getWindowWidth()
|
|
|
|
|
height = bge.render.getWindowHeight()
|
|
|
|
|
dist_orbit_y_base=200 # Pour 1280 x 720
|
2022-12-13 02:42:31 +01:00
|
|
|
|
# radius_orbit_y_base=5
|
|
|
|
|
radius_orbit_y_base=0.875
|
2022-12-10 18:44:20 +01:00
|
|
|
|
diag_base= math.sqrt(1280**2+720**2)
|
|
|
|
|
diag= math.sqrt(width**2+height**2)
|
|
|
|
|
dist_orbit_y = dist_orbit_y_base*(diag/diag_base)
|
|
|
|
|
radius_orbit_y=radius_orbit_y_base*(diag/diag_base)
|
|
|
|
|
dist_orbit = math.sqrt(((width/2)-obj['click_x'])**2+((height/2)-obj['click_y'])**2)
|
|
|
|
|
if obj['click_y']> height/2 :
|
|
|
|
|
dist_orbit = dist_orbit+((math.sqrt(((height/2)-obj['click_y'])**2)/175)*25) # Correction des Y sous le centre ?
|
|
|
|
|
if dist_orbit<dist_orbit_y : # Orbit sur xz
|
|
|
|
|
circle ([x0,y0,z0], radius_orbit_y_base, color_cmd)
|
|
|
|
|
n=10
|
2022-12-13 02:42:31 +01:00
|
|
|
|
# pas_x=(delta_x*40*sensibilite_orbit)/n
|
|
|
|
|
pas_x=(delta_x*4*sensibilite_orbit)/n
|
|
|
|
|
# pas_y=(((width/2)-cont.sensors['DownM'].position[0])+((height/2)-cont.sensors['DownM'].position[1]))*0.005
|
|
|
|
|
pas_y=((((width/2)-cont.sensors['DownM'].position[0])+((height/2)-cont.sensors['DownM'].position[1]))*0.005)/10
|
|
|
|
|
# pas_z=(delta_y*40*sensibilite_orbit)/n
|
|
|
|
|
pas_z=(delta_y*4*sensibilite_orbit)/n
|
2022-12-10 18:44:20 +01:00
|
|
|
|
for i in range (n):
|
|
|
|
|
bge.render.drawLine([x0+pas_x*i, y0+abs(pas_y*math.sin((3.14*i)/n)), z0-pas_z*i],
|
|
|
|
|
[x0+pas_x*(i+1), y0+abs(pas_y*math.sin((3.14*(i+1))/n)), z0-pas_z*(i+1)],
|
|
|
|
|
[0.8, 0.619, 0.021])
|
2022-12-11 08:40:31 +01:00
|
|
|
|
scene.objects['System'].applyRotation((delta_y*sensibilite_orbit, 0, delta_x*sensibilite_orbit), False)
|
2022-12-10 18:44:20 +01:00
|
|
|
|
else: # Orbit sur y
|
2022-12-13 02:42:31 +01:00
|
|
|
|
circle ([x0,y0,z0], radius_orbit_y_base, color_cmd_hl)
|
2022-12-10 18:44:20 +01:00
|
|
|
|
if abs(delta_x) >= abs(delta_y):
|
2022-12-11 08:40:31 +01:00
|
|
|
|
scene.objects['System'].applyRotation((0, delta_x*sensibilite_orbit, 0), False)
|
2022-12-10 18:44:20 +01:00
|
|
|
|
else:
|
2022-12-11 08:40:31 +01:00
|
|
|
|
scene.objects['System'].applyRotation((0, delta_y*sensibilite_orbit, 0), False)
|
2022-12-10 18:44:20 +01:00
|
|
|
|
|
|
|
|
|
# Pan
|
|
|
|
|
if obj['manip_mode']==1: # Shift
|
2022-12-11 08:40:31 +01:00
|
|
|
|
scene.objects['System'].applyMovement((delta_x*sensibilite_pan, -delta_y*sensibilite_pan, -delta_y*sensibilite_pan), False)
|
2022-12-10 18:44:20 +01:00
|
|
|
|
# scene.objects['Camera'].applyMovement((delta_x*-sensibilite_pan, delta_y*sensibilite_pan, 0), True)
|
|
|
|
|
|
|
|
|
|
# Zoom
|
|
|
|
|
if obj['manip_mode']==2: # Ctrl
|
|
|
|
|
scene.objects['Camera'].applyMovement((0, 0, (delta_x+delta_y)*sensibilite_zoom), True)
|
|
|
|
|
scene.objects['Camera'].applyMovement((0, 0, (delta_x+delta_y)*sensibilite_zoom), True)
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Zoom
|
|
|
|
|
##
|
|
|
|
|
|
2023-01-30 07:36:11 +01:00
|
|
|
|
def manip_wheel(cont):
|
2022-12-10 18:44:20 +01:00
|
|
|
|
obj = cont.owner
|
|
|
|
|
sensibilite_wheel = 20
|
|
|
|
|
if cont.sensors['WheelUp'].positive:
|
|
|
|
|
scene.objects['Camera'].applyMovement((0, 0, -sensibilite_wheel), True)
|
|
|
|
|
if cont.sensors['WheelDown'].positive:
|
|
|
|
|
scene.objects['Camera'].applyMovement((0, 0, sensibilite_wheel), True)
|
2022-12-11 15:50:38 +01:00
|
|
|
|
|
2023-01-28 01:10:05 +01:00
|
|
|
|
###############################################################################
|
|
|
|
|
# Fichier
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
def file_open():
|
|
|
|
|
|
|
|
|
|
# Terminer le processus file précédent
|
|
|
|
|
if ('file_proc' in scene.objects['System']):
|
|
|
|
|
if scene.objects['System']['file_proc'].poll()==None:
|
|
|
|
|
scene.objects['System']['file_proc'].terminate()
|
|
|
|
|
|
|
|
|
|
# Démarrer le processus file
|
2023-02-07 03:40:50 +01:00
|
|
|
|
if sys.platform=="linux": # wxPython ne s'installe pas bien sur GNU/linux -> Qt5
|
2023-01-30 07:36:11 +01:00
|
|
|
|
scene.objects['System']['file_proc'] = subprocess.Popen([sys.executable, os.path.join(os.getcwd(), "twin_file_qt.py")], stdout=subprocess.PIPE, encoding = 'utf8')
|
2023-02-07 03:40:50 +01:00
|
|
|
|
else: # Qt5 ne s'installe pas bien sur Windows -> wxPython
|
2023-01-30 07:36:11 +01:00
|
|
|
|
scene.objects['System']['file_proc'] = subprocess.Popen([sys.executable, os.path.join(os.getcwd(), "twin_file_wx.py")], stdout=subprocess.PIPE, encoding = 'utf8')
|
|
|
|
|
|
2023-02-12 00:34:37 +01:00
|
|
|
|
# Récupérer le nom du fchier
|
2023-01-28 01:10:05 +01:00
|
|
|
|
stout = scene.objects['System']['file_proc'].communicate()
|
2023-02-07 03:40:50 +01:00
|
|
|
|
if stout[0][:-1] != 'None' and len(stout[0][:-1])>0 :
|
2023-01-28 01:10:05 +01:00
|
|
|
|
scene.objects['System']['script'] = stout[0][:-1]
|
|
|
|
|
scene.objects['Script-text']['Text']=scene.objects['System']['script']
|
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
###############################################################################
|
|
|
|
|
# Cycle
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##
|
2022-12-22 05:02:33 +01:00
|
|
|
|
# Validation du code Python
|
2022-12-11 15:50:38 +01:00
|
|
|
|
##
|
|
|
|
|
|
2022-12-13 02:42:31 +01:00
|
|
|
|
def python_validation(file):
|
2024-01-02 15:13:14 +01:00
|
|
|
|
|
|
|
|
|
# Terminer le processus fils précédent
|
|
|
|
|
if ('pylint_proc' in scene.objects['Commands']):
|
|
|
|
|
if scene.objects['Commands']['pylint_proc'].poll()==None:
|
|
|
|
|
scene.objects['Commands']['pylint_proc'].terminate()
|
|
|
|
|
|
|
|
|
|
# Lancer le processus fils
|
|
|
|
|
scene.objects['Commands']['pylint_proc'] = subprocess.Popen([sys.executable, os.path.join(os.getcwd(), "twin_pylint.py"), file], stdout=subprocess.PIPE, encoding = 'utf8')
|
|
|
|
|
stout = scene.objects['Commands']['pylint_proc'].communicate()
|
|
|
|
|
|
|
|
|
|
# Présence d'erreur
|
|
|
|
|
if stout[0][:-1] != 'None' and len(stout[0][:-1])>0 :
|
2022-12-18 01:35:36 +01:00
|
|
|
|
|
|
|
|
|
# UI : information
|
|
|
|
|
scene.objects['Cmd-text']['modal']= True
|
|
|
|
|
scene.objects['Cmd-text']['Text']= "Erreur dans le script ... "
|
|
|
|
|
scene.objects['Cmd-text'].setVisible(True,False)
|
2024-01-02 15:13:14 +01:00
|
|
|
|
|
|
|
|
|
# Affichage console
|
|
|
|
|
stout_lines = stout[0].split("\n")
|
|
|
|
|
for stout_line in stout_lines:
|
|
|
|
|
print ("Pylint :", stout_line) # Affichage console
|
2022-12-11 15:50:38 +01:00
|
|
|
|
return False
|
2024-01-02 15:13:14 +01:00
|
|
|
|
|
|
|
|
|
# Absence d'erreur
|
|
|
|
|
scene.objects['Cmd-text']['modal']= False
|
|
|
|
|
scene.objects['Cmd-text']['Text']= ""
|
|
|
|
|
scene.objects['Cmd-text'].setVisible(False,False)
|
|
|
|
|
return True
|
2022-12-11 15:50:38 +01:00
|
|
|
|
|
2022-12-22 05:02:33 +01:00
|
|
|
|
##
|
|
|
|
|
# Mise en route et pause du cycle
|
|
|
|
|
##
|
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
def cycle_run ():
|
|
|
|
|
|
|
|
|
|
# Pause
|
|
|
|
|
if scene.objects['System']['run'] == True:
|
|
|
|
|
scene.objects['System']['run']=False
|
|
|
|
|
scene.objects['Pause'].setVisible(False,False)
|
|
|
|
|
scene.objects['Pause'].suspendPhysics()
|
|
|
|
|
scene.objects['Pause-Hl'].setVisible(False,False)
|
|
|
|
|
scene.objects['Run'].restorePhysics()
|
|
|
|
|
scene.objects['Run-Hl'].setVisible(True,False)
|
|
|
|
|
|
|
|
|
|
# Run
|
|
|
|
|
else :
|
|
|
|
|
scene.objects['System']['run']=True
|
|
|
|
|
scene.objects['Run'].setVisible(False,False)
|
|
|
|
|
scene.objects['Run'].suspendPhysics()
|
|
|
|
|
scene.objects['Run-Hl'].setVisible(False,False)
|
|
|
|
|
# scene.objects['Pause']. restorePhysics() # FIXME pause pas implémentée
|
|
|
|
|
# scene.objects['Pause'].setVisible(True,False) # FIXME pause pas implémentée
|
|
|
|
|
|
|
|
|
|
# Démarrage du cycle
|
|
|
|
|
if scene.objects['System']['thread_cmd']==False:
|
|
|
|
|
time.sleep(0.125)
|
|
|
|
|
scene.objects['System']['thread_cmd']=True
|
2022-12-13 02:42:31 +01:00
|
|
|
|
system.system_reset()
|
2022-12-11 15:50:38 +01:00
|
|
|
|
time.sleep(0.125)
|
2023-01-18 06:06:15 +01:00
|
|
|
|
scene.objects['System']['time']=0
|
2023-01-28 17:24:21 +01:00
|
|
|
|
scene.objects['System']['daq']=False
|
|
|
|
|
scene.objects['System']['plot']=False
|
2023-02-07 03:40:50 +01:00
|
|
|
|
scene.objects['Twins-text']['Text'] = "Connection fermée."
|
2023-01-28 01:10:05 +01:00
|
|
|
|
module_name=os.path.split((scene.objects['System']['script']))[1][:-3]
|
|
|
|
|
if python_validation(scene.objects['System']['script']):
|
|
|
|
|
runpy.run_path(scene.objects['System']['script'], run_name='start') # Execution du script utilisateur
|
2022-12-11 15:50:38 +01:00
|
|
|
|
|
|
|
|
|
# Arrêt de la pause
|
|
|
|
|
else:
|
2022-12-22 05:02:33 +01:00
|
|
|
|
# FIXME : Relancer la maquette
|
2022-12-11 15:50:38 +01:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Arrêt et réinitialisation du cycle (forçage)
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def cycle_stop ():
|
|
|
|
|
scene.objects['System']['thread_cmd']=False
|
2022-12-13 02:42:31 +01:00
|
|
|
|
system.system_reset()
|
2022-12-11 15:50:38 +01:00
|
|
|
|
|
|
|
|
|
##
|
2023-01-28 17:24:21 +01:00
|
|
|
|
# Fin du cycle
|
2022-12-11 15:50:38 +01:00
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def cycle_end (cont):
|
|
|
|
|
if cont.sensors['End cycle'].positive:
|
|
|
|
|
scene.objects['System']['run']=False
|
2023-01-28 01:10:05 +01:00
|
|
|
|
module_name=os.path.split((scene.objects['System']['script']))[1][:-3]
|
|
|
|
|
if python_validation(scene.objects['System']['script']):
|
|
|
|
|
runpy.run_path(scene.objects['System']['script'], run_name='stop') # Fin du script utilisateur
|
2022-12-11 15:50:38 +01:00
|
|
|
|
|
|
|
|
|
# Commandes
|
|
|
|
|
scene.objects['Pause'].setVisible(False,False)
|
|
|
|
|
scene.objects['Pause'].suspendPhysics()
|
|
|
|
|
scene.objects['Pause-Hl'].setVisible(False,False)
|
|
|
|
|
scene.objects['Run'].setVisible(True,False)
|
|
|
|
|
scene.objects['Run'].restorePhysics()
|
2022-12-22 05:02:33 +01:00
|
|
|
|
|
|
|
|
|
##
|
2023-01-07 10:42:19 +01:00
|
|
|
|
# Highlight sur les éléments cliquable du systèmes
|
2022-12-22 05:02:33 +01:00
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def cycle_hl(cont):
|
2023-01-11 18:48:45 +01:00
|
|
|
|
if "-colbox" in cont.owner.name:
|
|
|
|
|
obj= scene.objects[cont.owner.name[:-7]]
|
|
|
|
|
else:
|
|
|
|
|
obj = cont.owner
|
2022-12-22 05:02:33 +01:00
|
|
|
|
|
|
|
|
|
# Activation
|
2023-01-11 18:48:45 +01:00
|
|
|
|
if cont.sensors['MO'].status == JUST_ACTIVATED:
|
2022-12-22 08:11:43 +01:00
|
|
|
|
obj['mo'] = True
|
2023-01-11 18:48:45 +01:00
|
|
|
|
|
2023-02-11 23:52:07 +01:00
|
|
|
|
# Composant avec un groupe de couleur
|
2023-01-11 18:48:45 +01:00
|
|
|
|
if "color_group" in obj.getPropertyNames():
|
|
|
|
|
for obj_name in obj['color_group']:
|
|
|
|
|
scene.objects[obj_name].color = color_hl
|
|
|
|
|
else:
|
|
|
|
|
obj.color = color_hl
|
|
|
|
|
|
|
|
|
|
# Description
|
2023-01-06 21:23:44 +01:00
|
|
|
|
if obj['description'] is not None:
|
|
|
|
|
scene.objects['Cmd-text']['Text']=obj['description']
|
|
|
|
|
scene.objects['Cmd-text'].setVisible(True,True)
|
2022-12-22 05:02:33 +01:00
|
|
|
|
|
|
|
|
|
# Désactivation
|
2023-01-11 18:48:45 +01:00
|
|
|
|
if cont.sensors['MO'].status == JUST_RELEASED :
|
2022-12-22 08:11:43 +01:00
|
|
|
|
obj['mo'] = False
|
2023-01-06 21:23:44 +01:00
|
|
|
|
scene.objects['Cmd-text']['Text']=""
|
2022-12-22 05:02:33 +01:00
|
|
|
|
|
2023-01-11 18:48:45 +01:00
|
|
|
|
# Composant passif
|
|
|
|
|
if "active" in obj.getPropertyNames():
|
|
|
|
|
if obj['active'] == False: # Composant passif
|
|
|
|
|
obj.color = color_passive
|
|
|
|
|
return
|
|
|
|
|
|
2023-02-11 23:52:07 +01:00
|
|
|
|
# Composant avec un groupe de couleur
|
2023-01-11 18:48:45 +01:00
|
|
|
|
if "color_group" in obj.getPropertyNames():
|
|
|
|
|
for obj_name in obj['color_group']:
|
|
|
|
|
cycle_actuator_color(obj_name)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Composant simple
|
|
|
|
|
obj.color = color_active
|
|
|
|
|
|
2022-12-22 05:02:33 +01:00
|
|
|
|
##
|
2023-01-07 10:42:19 +01:00
|
|
|
|
# Click sur les éléments cliquables du système (activation numérique)
|
2022-12-22 05:02:33 +01:00
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def cycle_click(cont):
|
|
|
|
|
obj = cont.owner
|
2022-12-28 14:16:14 +01:00
|
|
|
|
if scene.objects['System']['run'] ==False:
|
|
|
|
|
return
|
2022-12-22 08:11:43 +01:00
|
|
|
|
|
|
|
|
|
# Passif
|
|
|
|
|
if "active" in obj.getPropertyNames():
|
2022-12-31 16:48:54 +01:00
|
|
|
|
if obj['active'] == False:
|
|
|
|
|
obj.color = color_passive
|
2022-12-22 08:11:43 +01:00
|
|
|
|
return
|
2022-12-22 05:02:33 +01:00
|
|
|
|
|
|
|
|
|
# Activation
|
2023-02-01 06:06:50 +01:00
|
|
|
|
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['System']['manip_mode']==0 and obj['prior']:
|
2022-12-22 08:11:43 +01:00
|
|
|
|
obj.color = color_activated
|
2022-12-22 05:02:33 +01:00
|
|
|
|
obj['activated'] = True
|
|
|
|
|
obj['click'] = True
|
|
|
|
|
|
|
|
|
|
# Désactivation
|
2023-02-01 06:06:50 +01:00
|
|
|
|
if cont.sensors['Click'].status == JUST_RELEASED and obj['prior']:
|
2022-12-22 05:02:33 +01:00
|
|
|
|
obj['activated'] = False
|
|
|
|
|
obj['click'] = False
|
|
|
|
|
if cont.sensors['MO'].positive:
|
2022-12-22 08:11:43 +01:00
|
|
|
|
obj.color = color_hl
|
2022-12-22 05:02:33 +01:00
|
|
|
|
else:
|
2022-12-22 08:11:43 +01:00
|
|
|
|
obj.color = color_active
|
2023-01-07 10:42:19 +01:00
|
|
|
|
|
2023-02-11 23:52:07 +01:00
|
|
|
|
|
|
|
|
|
##
|
2023-02-15 17:56:49 +01:00
|
|
|
|
# Click sur les éléments commutables du système (activation numérique)
|
2023-02-11 23:52:07 +01:00
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def cycle_switch(cont):
|
|
|
|
|
obj = cont.owner
|
|
|
|
|
obj_on=scene.objects[obj.name+"-on"]
|
|
|
|
|
if scene.objects['System']['run'] ==False:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Passif
|
|
|
|
|
if "active" in obj.getPropertyNames():
|
|
|
|
|
if obj['active'] == False:
|
|
|
|
|
obj.color = color_passive
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Activation
|
|
|
|
|
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['System']['manip_mode']==0 and obj['prior']:
|
|
|
|
|
|
|
|
|
|
if obj['activated']: # On -> Off
|
|
|
|
|
obj.color = color_hl
|
|
|
|
|
obj['activated'] = False
|
|
|
|
|
obj['click'] = True
|
|
|
|
|
obj.setVisible(True,False)
|
|
|
|
|
obj_on.setVisible(False,False)
|
|
|
|
|
else: # Off -> On
|
|
|
|
|
obj_on.color = color_activated
|
|
|
|
|
obj['activated'] = True
|
|
|
|
|
obj['click'] = True
|
|
|
|
|
obj_on.setVisible(True,False)
|
|
|
|
|
obj.setVisible(False,False)
|
|
|
|
|
|
|
|
|
|
# Désactivation
|
|
|
|
|
if cont.sensors['Click'].status == JUST_RELEASED and obj['prior']:
|
|
|
|
|
obj['click'] = False
|
|
|
|
|
if cont.sensors['MO'].positive:
|
|
|
|
|
obj.color = color_hl
|
|
|
|
|
else:
|
|
|
|
|
if obj['activated']:
|
|
|
|
|
obj_on.color = color_activated
|
|
|
|
|
else:
|
|
|
|
|
obj.color = color_active
|
|
|
|
|
|
2023-01-07 10:42:19 +01:00
|
|
|
|
##
|
|
|
|
|
# Couleurs sur les éléments sensibles du système
|
2023-02-15 17:56:49 +01:00
|
|
|
|
# obj : objet numérique
|
|
|
|
|
# obj_on : objet numérique à l'état activé (si différent)
|
2023-01-07 10:42:19 +01:00
|
|
|
|
##
|
|
|
|
|
|
2023-02-15 17:56:49 +01:00
|
|
|
|
def cycle_sensitive_color(obj, obj_on=None):
|
|
|
|
|
|
2023-01-11 18:48:45 +01:00
|
|
|
|
# Mouse over
|
2023-01-07 10:42:19 +01:00
|
|
|
|
if obj['mo'] == True and obj['click'] == False and obj.color !=color_hl:
|
|
|
|
|
obj.color =color_hl
|
2023-01-11 18:48:45 +01:00
|
|
|
|
|
|
|
|
|
# Jumeau
|
2023-01-07 10:42:19 +01:00
|
|
|
|
elif scene.objects['System']['twins']:
|
|
|
|
|
if obj['activated_real'] ==False and obj['activated']==False and obj.color !=color_active:
|
|
|
|
|
obj.color =color_active
|
|
|
|
|
elif obj['activated_real'] and obj['activated'] and obj.color !=color_activated_dbl:
|
|
|
|
|
obj.color =color_activated_dbl
|
2023-02-15 17:56:49 +01:00
|
|
|
|
if obj_on is not None:
|
|
|
|
|
obj_on.color =color_activated_dbl
|
2023-01-07 10:42:19 +01:00
|
|
|
|
elif obj['activated_real'] and obj['activated']==False and obj.color !=color_activated_real:
|
|
|
|
|
obj.color =color_activated_real
|
|
|
|
|
elif obj['activated_real'] ==False and obj['activated'] and obj.color !=color_activated:
|
|
|
|
|
obj.color =color_activated
|
2023-02-15 17:56:49 +01:00
|
|
|
|
if obj_on is not None:
|
|
|
|
|
obj_on.color =color_activated
|
2023-01-07 10:42:19 +01:00
|
|
|
|
elif obj['activated_real'] ==False and obj['activated']==False and obj.color !=color_activated:
|
|
|
|
|
obj.color =color_active
|
2023-01-11 18:48:45 +01:00
|
|
|
|
|
|
|
|
|
# Uniquement maquette 3D
|
2023-01-07 10:42:19 +01:00
|
|
|
|
else:
|
|
|
|
|
if obj['activated'] == True and obj.color !=color_activated:
|
|
|
|
|
obj.color =color_activated
|
|
|
|
|
elif obj['activated'] == False and obj.color !=color_active:
|
|
|
|
|
obj.color =color_active
|
|
|
|
|
|
2023-01-11 18:48:45 +01:00
|
|
|
|
##
|
|
|
|
|
# Couleurs des actionneurs
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def cycle_actuator_color(name):
|
|
|
|
|
obj = scene.objects[name]
|
|
|
|
|
if obj['color']== "blue":
|
|
|
|
|
obj.color = color_blue
|
|
|
|
|
elif obj['color']== "blue-dark":
|
|
|
|
|
obj.color = color_blue_dark
|
|
|
|
|
elif obj['color']== "grey":
|
|
|
|
|
obj.color = color_grey
|
|
|
|
|
elif obj['color']== "led_yellow":
|
|
|
|
|
obj.color = color_led_yellow
|
|
|
|
|
|
2023-01-07 10:42:19 +01:00
|
|
|
|
##
|
2023-02-11 23:52:07 +01:00
|
|
|
|
# Comportement standard des boutons poussoirs
|
2023-01-07 10:42:19 +01:00
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def cycle_bp(cont):
|
|
|
|
|
obj = cont.owner
|
|
|
|
|
|
|
|
|
|
# Arduino -> Modele 3D
|
2023-02-01 06:06:50 +01:00
|
|
|
|
if scene.objects['System']['twins'] and obj['prior_real']:
|
|
|
|
|
if obj['pin'] is not None :
|
2023-01-07 10:42:19 +01:00
|
|
|
|
if obj['pin'].read()==True and obj['activated_real'] == False :
|
|
|
|
|
obj['activated_real'] = True
|
|
|
|
|
if obj['pin'].read()==False and obj['activated_real'] == True :
|
|
|
|
|
obj['activated_real'] = False
|
|
|
|
|
|
|
|
|
|
# Couleurs
|
|
|
|
|
cycle_sensitive_color(obj)
|
2023-01-07 18:01:03 +01:00
|
|
|
|
|
2023-02-11 23:52:07 +01:00
|
|
|
|
##
|
|
|
|
|
# Comportement standard des boutons à glissière
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def cycle_bg(cont):
|
|
|
|
|
obj = cont.owner
|
2023-02-15 17:56:49 +01:00
|
|
|
|
obj_on=scene.objects[obj.name+"-on"]
|
2023-02-11 23:52:07 +01:00
|
|
|
|
|
|
|
|
|
# Arduino -> Modele 3D
|
|
|
|
|
if scene.objects['System']['twins'] and obj['prior_real']:
|
|
|
|
|
if obj['pin'] is not None :
|
|
|
|
|
if obj['pin'].read()==True and obj['activated_real'] == False :
|
|
|
|
|
obj['activated_real'] = True
|
|
|
|
|
if obj['pin'].read()==False and obj['activated_real'] == True :
|
|
|
|
|
obj['activated_real'] = False
|
|
|
|
|
|
|
|
|
|
# Couleurs
|
2023-02-15 17:56:49 +01:00
|
|
|
|
cycle_sensitive_color(obj, obj_on)
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Comportement standard des capteurs (analogique)
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def cycle_sensor(cont):
|
|
|
|
|
obj = cont.owner
|
|
|
|
|
|
|
|
|
|
# Physique du modèle 3D
|
|
|
|
|
if scene.objects['System']['run']:
|
|
|
|
|
if obj['activated'] and obj['value']!=obj['value_click']:
|
|
|
|
|
obj['value']=obj['value_click']
|
|
|
|
|
if obj['activated']==False and obj['value']!=obj['value_unclick']:
|
|
|
|
|
obj['value']=obj['value_unclick']
|
|
|
|
|
|
|
|
|
|
# Arduino -> Modele 3D
|
|
|
|
|
if scene.objects['System']['twins'] and obj['prior_real']:
|
|
|
|
|
if obj['pin'] is not None :
|
|
|
|
|
obj['value_real'] = obj['pin'].read()
|
2023-02-11 23:52:07 +01:00
|
|
|
|
|
2023-01-07 18:01:03 +01:00
|
|
|
|
##
|
|
|
|
|
# Comportement standard des voyants
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def cycle_voy(cont):
|
|
|
|
|
obj = cont.owner
|
|
|
|
|
obj_on=scene.objects[obj.name+"-on"]
|
|
|
|
|
|
2023-01-11 18:48:45 +01:00
|
|
|
|
# Mouse over
|
|
|
|
|
if obj['mo'] == True and obj.color !=color_hl:
|
|
|
|
|
obj.color =color_hl
|
|
|
|
|
|
|
|
|
|
elif scene.objects['System']['run']:
|
2023-01-07 18:01:03 +01:00
|
|
|
|
|
|
|
|
|
# Activation
|
2023-02-03 10:27:45 +01:00
|
|
|
|
if obj['activated']:
|
2023-02-01 06:06:50 +01:00
|
|
|
|
|
2023-02-03 10:27:45 +01:00
|
|
|
|
# Physique du modèle 3D
|
|
|
|
|
if obj_on.visible == False and obj['prior']:
|
2023-02-01 06:06:50 +01:00
|
|
|
|
obj_on.setVisible(True,False)
|
|
|
|
|
obj.setVisible(False,False)
|
2023-01-07 18:01:03 +01:00
|
|
|
|
|
|
|
|
|
# Modele 3D -> Arduino
|
2023-02-01 06:06:50 +01:00
|
|
|
|
if scene.objects['System']['twins'] and obj['prior_real']:
|
2023-01-07 18:01:03 +01:00
|
|
|
|
if obj['pin'] is not None:
|
|
|
|
|
obj['pin'].write(1)
|
|
|
|
|
|
|
|
|
|
# Désactivation
|
2023-02-03 10:27:45 +01:00
|
|
|
|
if obj['activated']==False:
|
2023-02-01 06:06:50 +01:00
|
|
|
|
|
2023-02-03 10:27:45 +01:00
|
|
|
|
# Physique du modèle 3D
|
|
|
|
|
if obj_on.visible == True and obj['prior']:
|
2023-02-01 06:06:50 +01:00
|
|
|
|
obj.setVisible(True,False)
|
|
|
|
|
obj_on.setVisible(False,False)
|
2023-01-07 18:01:03 +01:00
|
|
|
|
|
|
|
|
|
# Modele 3D -> Arduino
|
2023-02-01 06:06:50 +01:00
|
|
|
|
if scene.objects['System']['twins'] and obj['prior_real']:
|
2023-01-07 18:01:03 +01:00
|
|
|
|
if obj['pin'] is not None:
|
|
|
|
|
obj['pin'].write(0)
|
2023-01-11 18:48:45 +01:00
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Mise en couleur des actionneurs
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def cycle_def_focusgroup(focusgroup, description):
|
|
|
|
|
group=[]
|
|
|
|
|
for obj in focusgroup:
|
|
|
|
|
group.append(obj[0])
|
|
|
|
|
for obj in focusgroup:
|
|
|
|
|
scene.objects[obj[0]]['color_group'] = group
|
|
|
|
|
scene.objects[obj[0]]['color'] = obj[1]
|
|
|
|
|
scene.objects[obj[0]]['description']=description
|
|
|
|
|
cycle_actuator_color(obj[0])
|