Debian Codegraph @

wxgeometrie/modules/graphes/barre_outils_graphes.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 ##--------------------------------------##
4 # Barre d'outils pour la géométrie #
5 ##--------------------------------------##
6 # WxGeometrie
7 # Dynamic geometry, graph plotter, and more for french mathematic teachers.
8 # Copyright (C) 2005-2013 Nicolas Pourcelot
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
24 #from LIB import *
25 #from GUI.wxlib import png
26 from ...GUI.barre_outils import BarreOutils
27 from ...geolib import Arc_oriente, Arc_points, Point_generique
28
29
30 class BarreOutilsGraphes(BarreOutils):
31 def __init__(self, parent):
32 BarreOutils.__init__(self, parent)
33
34
35 def creer_boutons(self):
36 self.add("F1", ("Pointeur", "fleche4", "Déplacer ou modifier un objet.", self.curseur),
37 ("Zoomer", "zoombox2", "Recentrer la zone d'affichage.", self.zoombox),
38 ("Sélectionner", "selection", "Sélectionner une partie de la feuille.",
39 self.selectionner)).select()
40 self.add("F2", ("Sommet", "point2","Créer un point.", self.point))
41 self.add("F3", ("Arête", "segment2", "Créer une arête droite.", self.segment))
42 self.add("F4", ("Arête orientée", "vecteur", "Créer une arête orientée droite.", self.vecteur),
43 )
44 self.add("F5", ("Arête courbe", "arc_points",
45 "Créer une arête courbe (définir 3 points).", self.arc_points),
46 )
47 self.add("F6", ("Arête orientée (courbe)", "arc_oriente",
48 "Créer une arête orientée courbe (définir 3 points).", self.arc_oriente),
49 )
50 self.add("F7", ("Texte", "texte", "Créer un texte.", self.texte))
51 self.add("F8", ("Masquer", "masquer", "Masquer des objets.", self.masque))
52 self.add("F9", ("Gommer", "gomme", "Supprimer des objets.", self.gomme))
53 self.add("Shift+F2", ("Copier", "pinceau", "Copier le style d'un objet.", self.pinceau))
54
55
56
57
58 def arc_points(self, event = False, **kw):
59 if event is False:
60 self.arc(Arc_points, nom_style='arc', **kw)
61 else:
62 self.interagir(self.arc_points, "Choisissez ou créez 3 points.")
63
64 def arc_oriente(self, event = False, **kw):
65 if event is False:
66 self.arc(Arc_oriente, nom_style='arcs_orientes', **kw)
67 else:
68 self.interagir(self.arc_oriente, "Choisissez ou créez 3 points.")
69
70
71 def arc(self, classe, nom_style = '', **kw):
72 "Création d'un arc défini par 3 points. Un style spécial est appliqué au point intermédaire."
73 if self.test(True, **kw):
74 self.cache = [obj for obj in self.cache if obj.nom and obj.feuille is self.feuille_actuelle]
75 selection = kw["selection"]
76
77 n = len(self.cache)
78
79 if n == 1:
80 # Le point intermédiaire a un style différent,
81 # et ne doit donc pas coïncider avec un point déjà existant.
82 point = self.point(nom_style='points_ancrage', editer=None, **kw)
83 self.cache.append(point)
84 style = self.style(nom_style)
85 style["previsualisation"] = True
86 self.feuille_actuelle.objet_temporaire(classe(*(tuple(self.cache) + (self.feuille_actuelle.point_temporaire(),)), **style))
87 elif isinstance(selection, Point_generique):
88 self.cache.append(selection)
89 nouveau_point = False
90 else:
91 self.cache.append(self.point(**kw))
92 nouveau_point = True
93
94 if n == 2:
95 self.feuille_actuelle.objet_temporaire(None)
96 code = classe.__name__ + "(" + ",".join(obj.nom for obj in self.cache) + ", **%s)" %self.style(nom_style)
97 if nouveau_point: # on edite le nom du nouveau point (dernier parametre de self.executer)
98 self.executer(code, editer = self.cache[-1])
99 else: # si c'est un vieux point, pas besoin d'editer son nom
100 self.executer(code)
101
102 elif n > 3: # ne se produit que si l'execution a plante...
103 self.initialiser()
104
105 elif self.cache:
106 style = self.style(nom_style)
107 style["previsualisation"] = True
108 self.feuille_actuelle.objet_temporaire(classe(*(tuple(self.cache) + (self.feuille_actuelle.point_temporaire(),)), **style))
109 else:
110 self.feuille_actuelle.objet_temporaire(None)