"""Pictogrammes Klimat, « le trait ouvert » : les 14 pictogrammes de la charte, tracés par code.

Usage : python3 pictogrammes.py DOSSIER_DE_SORTIE
open_circle() calcule l’ouverture entre 1 h et 2 h ; dot() pose la pastille (classe k-pastille).
Ajoutez un pictogramme en complétant le dictionnaire I, puis contrôlez-le à 32, 48 et 96 px.

Trois versions sont écrites : mono (DOSSIER/, à currentColor, la source), duo (DOSSIER/duo/ :
encre nuit, pastille Véroné, ou Orge pour une question ou un commentaire) et nuit (DOSSIER/nuit/ :
trait onyx-200, pastille véroné-300), ces deux dernières pour un usage en <img> (e-mail, PowerPoint).
Les thématiques portent le slug de config('klimat.categories-name').
"""
import math, os, sys
OUT=sys.argv[1]
def f(v): 
    s=('%.2f'%v).rstrip('0').rstrip('.'); return '0' if s=='-0' else s
def pt(cx,cy,r,a): return (cx+r*math.cos(math.radians(a)), cy+r*math.sin(math.radians(a)))
GAP=(-62,-34)  # ouverture : entre 1 h et 2 h
def open_circle(cx,cy,r,gap=GAP):
    a0,a1=gap  # trace de a1 à a0+360 dans le sens horaire (y vers le bas)
    x0,y0=pt(cx,cy,r,a1); x1,y1=pt(cx,cy,r,a0)
    large=1 if (a0+360-a1)>180 else 0
    return f'<path d="M{f(x0)} {f(y0)}A{f(r)} {f(r)} 0 {large} 1 {f(x1)} {f(y1)}"/>'
def arc(cx,cy,r,a_from,a_to):
    x0,y0=pt(cx,cy,r,a_from); x1,y1=pt(cx,cy,r,a_to)
    sweep=(a_to-a_from)%360; large=1 if sweep>180 else 0
    return f'<path d="M{f(x0)} {f(y0)}A{f(r)} {f(r)} 0 {large} 1 {f(x1)} {f(y1)}"/>'
def line(*p): return '<path d="M'+'L'.join(f'{f(x)} {f(y)}' for x,y in p)+'"/>'
def P(d): return f'<path d="{d}"/>'
def dot(cx,cy,r=3.5,question=False):
    cls='k-pastille k-pastille--question' if question else 'k-pastille'
    return f'<circle class="{cls}" cx="{f(cx)}" cy="{f(cy)}" r="{f(r)}" fill="currentColor" stroke="none"/>'
def circ(cx,cy,r): return f'<circle cx="{f(cx)}" cy="{f(cy)}" r="{f(r)}"/>'
def svg(body,title):
    return ('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" fill="none" stroke="currentColor" '
            'stroke-width="2" stroke-linecap="round" stroke-linejoin="round" role="img" aria-label="%s">' % title
            + ''.join(body) + '</svg>\n')
I={}
# Thématiques
I['theme-autonomie']=('Autonomie',[open_circle(22,26,15), line((22,26),(37.5,10.5)), line((29.5,10.5),(37.5,10.5),(37.5,18.5)), dot(22,26)])
I['theme-charge-travail']=('Charge de travail',[P('M7 34A17 17 0 0 1 41 34'), line((24,34),(34.5,21.5)), line((16,41),(32,41)), dot(24,34)])
I['theme-reconnaissance']=('Reconnaissance',[open_circle(24,19,11), line((19.5,28.5),(16,42),(21,39.5)), line((28.5,28.5),(32,42),(27,39.5)), dot(24,19,4)])
I['theme-soutien']=('Soutien',[circ(15.5,16,5), circ(32.5,16,5), P('M5 38a10.5 10.5 0 0 1 21 0'), P('M22 38a10.5 10.5 0 0 1 21 0'), dot(24,25,3)])
I['theme-equilibre-travail-vie-perso']=('Équilibre vie professionnelle et personnelle',[line((24,9),(24,40)), line((15,40),(33,40)), line((9,15),(39,15)), P('M5 26a6 6 0 0 0 12 0Z'), P('M31 26a6 6 0 0 0 12 0Z'), line((11,15),(5,26)), line((11,15),(17,26)), line((37,15),(31,26)), line((37,15),(43,26)), dot(24,15,3)])
I['theme-clarte-roles']=('Clarté des rôles',[P('M31 11H12a4 4 0 0 0-4 4v19a4 4 0 0 0 4 4h24a4 4 0 0 0 4-4V19'), dot(17,22), P('M11.5 33a5.5 5.5 0 0 1 11 0'), line((27,22),(35,22)), line((27,28),(33,28))])
I['theme-changement']=('Changement',[arc(24,24,14,150,330), line((34.6,9.2),(37.8,15.1),(31.4,17)), arc(24,24,14,330,510), line((13.4,38.8),(10.2,32.9),(16.6,31)), dot(24,24)])
I['theme-sante']=('Santé',[open_circle(24,24,16), line((9,25),(16,25),(19.5,17),(25,33),(28.5,25),(33,25)), dot(33,25,3)])
# Thématiques ajoutées le 2026-11-05 (les douze qui restaient)
I['theme-proximite']=('Proximité',[open_circle(24,24,17), circ(18,19,4), arc(18,33,7,180,360), arc(30,33,7,180,360), dot(30,19,3.5)])
I['theme-respect']=('Respect',[P('M24 7l14 5v11c0 8.5-5.8 15-14 18-8.2-3-14-9.5-14-18V12Z'), arc(24,32,7,180,360), dot(24,20,3.5)])
I['theme-equipe']=('Équipe',[circ(13,17,4), circ(35,17,4), arc(13,31,7,180,290), arc(35,31,7,250,360), arc(24,39,9,180,360), dot(24,23,4)])
I['theme-outils-digitaux']=('Outils digitaux',[P('M31 9H11a3 3 0 0 0-3 3v18a3 3 0 0 0 3 3h26a3 3 0 0 0 3-3V18'), line((6,39),(42,39)), line((15,27),(21,21),(25,25),(32,18)), dot(32,18,3)])
I['theme-qualite-travail']=('Qualité du travail',[open_circle(24,24,16), line((16,24.5),(21.5,30),(32,19.5)), dot(*pt(24,24,16,-48),r=3)])
I['theme-orientation-strategique']=('Orientation stratégique',[open_circle(24,24,16), open_circle(24,24,9), dot(24,24,3.5)])
I['theme-teletravail']=('Télétravail',[line((7,23),(24,6),(41,23)), P('M11 19v19a3 3 0 0 0 3 3h20a3 3 0 0 0 3-3V19'), P('M18 25h12v8H18Z'), line((16,37),(32,37)), dot(24,13,3)])
def spicules(cx,cy,r0,r1,angles,demi=2.2):
    d=''
    for a in angles:
        (x0,y0),(x1,y1)=pt(cx,cy,r0,a),pt(cx,cy,r1,a)
        nx,ny=-math.sin(math.radians(a))*demi,math.cos(math.radians(a))*demi
        d+=f'M{f(x0)} {f(y0)}L{f(x1)} {f(y1)}M{f(x1-nx)} {f(y1-ny)}L{f(x1+nx)} {f(y1+ny)}'
    return P(d)
I['theme-covid']=('Covid',[open_circle(24,24,10), spicules(24,24,12.5,16,(0,45,90,135,180,225,270)), dot(*pt(24,24,15,-45),r=3)])
I['theme-mobilisation']=('Mobilisation',[P('M24 42c-7 0-12-4.8-12-11.3 0-6.9 5.4-10.4 7.3-17.7 3.7 2.6 5.2 6 5.1 9.4 2.3-2.2 3.3-5.4 3.1-9 5.5 3.8 8.5 10.6 8.5 17.3 0 6.5-5 11.3-12 11.3Z'), dot(24,34,3.5)])
I['theme-diversite']=('Diversité',[circ(18,18,9), open_circle(30,18,9), circ(24,28.4,9), dot(24,21.5,3)])
I['theme-retour-au-bureau']=('Retour au bureau',[P('M35 7H23a3 3 0 0 0-3 3v31h21V13'), line((26,15),(35,15)), line((4,30),(15,30)), line((10.5,24.5),(16,30),(10.5,35.5)), dot(30.5,30,3.5)])
I['theme-travail-hybride']=('Travail hybride',[line((4,24),(12,16),(20,24)), P('M7 21v20M17 21v20'), P('M38 9h-7a3 3 0 0 0-3 3v29h13V12'), line((4,41),(44,41)), dot(22.5,31,3)])
# Fonctionnalités
I['fonction-questionnaire']=('Questionnaire',[P('M33 8H14a6 6 0 0 0-6 6v20a6 6 0 0 0 6 6h20a6 6 0 0 0 6-6V15'), circ(15.5,16.5,2.5), line((21.5,16.5),(32,16.5)), dot(15.5,24.5,3), line((21.5,24.5),(32,24.5)), circ(15.5,32.5,2.5), line((21.5,32.5),(28,32.5))])
I['fonction-resultats']=('Résultats',[arc(24,24,15,-34,-62+360), line((17,29),(17,24)), line((24,29),(24,19)), line((31,29),(31,22)), dot(*pt(24,24,15,-62),r=3.5)])
I['fonction-confidentialite']=('Confidentialité',[P('M16 22v-5a8 8 0 0 1 16 0v5'), P('M14 22h20a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H14a3 3 0 0 1-3-3V25a3 3 0 0 1 3-3Z'), dot(24,30,3), line((24,33),(24,35.5))])
I['fonction-plan-actions']=('Plan d’actions',[line((7,40),(16,32),(23,35),(32,24),(32,7)), P('M32 8h9l-2.5 4 2.5 4h-9'), dot(16,32,3.5)])
# États
I['etat-aucune-donnee']=('Aucune donnée',[open_circle(21,21,12), line((30,30),(40,40)), dot(21,21,3)])
I['etat-introuvable']=('Page introuvable',[line((24,13),(24,42)), line((17,42),(31,42)), P('M24 13h12l4 4.5-4 4.5H24'), P('M24 26H12l-4 4.5 4 4.5h12'), dot(24,8,3)])
I['etat-aucun-sondage']=('Aucun sondage',[P('M19 9h-6a4 4 0 0 0-4 4v25a4 4 0 0 0 4 4h22a4 4 0 0 0 4-4V17'), P('M21 5h6a2 2 0 0 1 2 2v5H19V7a2 2 0 0 1 2-2Z'), dot(24,25,3.5), line((18,33),(30,33))])
I['etat-aucun-commentaire']=('Aucun commentaire',[P('M30 9H14a6 6 0 0 0-6 6v11a6 6 0 0 0 6 6h3v7l8-7h9a6 6 0 0 0 6-6V17'), dot(24,20.5,3.5,question=True)])
I['etat-resultat-masque']=('Résultat masqué',[P('M5 24c4.4-7.3 11-11 19-11s14.6 3.7 19 11c-4.4 7.3-11 11-19 11S9.4 31.3 5 24Z'), line((11,37),(37,11)), dot(24,24,4)])
I['etat-acces-refuse']=('Accès refusé',[circ(24,24,16), line((14,24),(34,24)), dot(24,24,3.5)])
I['etat-erreur-serveur']=('Erreur serveur',[P('M31 8H11a3 3 0 0 0-3 3v7a3 3 0 0 0 3 3h26a3 3 0 0 0 3-3v-4'), line((14,14.5),(26,14.5)), P('M11 27h26a3 3 0 0 1 3 3v7a3 3 0 0 1-3 3H11a3 3 0 0 1-3-3v-7a3 3 0 0 1 3-3Z'), dot(15,33.5,3), line((22,33.5),(33,33.5))])
I['etat-email-envoye']=('E-mail envoyé',[P('M32 11H10a3 3 0 0 0-3 3v20a3 3 0 0 0 3 3h28a3 3 0 0 0 3-3V20'), line((8,13.5),(24,25),(34,18)), dot(38.5,11.5,3.5)])
os.makedirs(OUT,exist_ok=True)
VARIANTES={'duo':('#0e1917','#009f7f','#e7ad45'),'nuit':('#e1e9e6','#6cc9b0','#e7ad45')}
for v in VARIANTES: os.makedirs(os.path.join(OUT,v),exist_ok=True)
for k,(t,b) in I.items():
    s=svg(b,t)
    open(os.path.join(OUT,k+'.svg'),'w').write(s)
    for v,(encre,pastille,question) in VARIANTES.items():
        d=s.replace('stroke="currentColor"',f'stroke="{encre}"',1)
        d=d.replace('class="k-pastille k-pastille--question" ','').replace('fill="currentColor" stroke="none"/>',f'fill="{question}" stroke="none"/>') if 'k-pastille--question' in s else d
        d=d.replace('class="k-pastille" ','').replace('fill="currentColor"',f'fill="{pastille}"')
        open(os.path.join(OUT,v,k+'.svg'),'w').write(d)
print(len(I),'pictogrammes, en trois versions')
