127 |
128 |
128 """ |
129 """ |
129 Basic vector operations for calculate wire points |
130 Basic vector operations for calculate wire points |
130 """ |
131 """ |
131 |
132 |
132 # Create a vector from two points and define if vector must be normal |
133 |
133 def vector(p1, p2, normal = True): |
134 def vector(p1, p2, normal = True): |
|
135 """ |
|
136 Create a vector from two points and define if vector must be normal |
|
137 """ |
134 vector = (p2.x - p1.x, p2.y - p1.y) |
138 vector = (p2.x - p1.x, p2.y - p1.y) |
135 if normal: |
139 if normal: |
136 return normalize(vector) |
140 return normalize(vector) |
137 return vector |
141 return vector |
138 |
142 |
139 # Calculate the norm of a given vector |
143 |
140 def norm(v): |
144 def norm(v): |
|
145 """ |
|
146 Calculate the norm of a given vector |
|
147 """ |
141 return sqrt(v[0] * v[0] + v[1] * v[1]) |
148 return sqrt(v[0] * v[0] + v[1] * v[1]) |
142 |
149 |
143 # Normalize a given vector |
150 |
144 def normalize(v): |
151 def normalize(v): |
|
152 """ |
|
153 Normalize a given vector |
|
154 """ |
145 v_norm = norm(v) |
155 v_norm = norm(v) |
146 # Verifie if it is not a null vector |
156 # Verifie if it is not a null vector |
147 if v_norm > 0: |
157 if v_norm > 0: |
148 return (v[0] / v_norm, v[1] / v_norm) |
158 return (v[0] / v_norm, v[1] / v_norm) |
149 else: |
159 else: |
150 return v |
160 return v |
151 |
161 |
152 # Calculate the scalar product of two vectors |
162 |
153 def is_null_vector(v): |
163 def is_null_vector(v): |
|
164 """ |
|
165 Calculate the scalar product of two vectors |
|
166 """ |
154 return v == (0, 0) |
167 return v == (0, 0) |
155 |
168 |
156 # Calculate the scalar product of two vectors |
169 |
157 def add_vectors(v1, v2): |
170 def add_vectors(v1, v2): |
|
171 """ |
|
172 Calculate the scalar product of two vectors |
|
173 """ |
158 return (v1[0] + v2[0], v1[1] + v2[1]) |
174 return (v1[0] + v2[0], v1[1] + v2[1]) |
159 |
175 |
160 # Calculate the scalar product of two vectors |
176 |
161 def product(v1, v2): |
177 def product(v1, v2): |
|
178 """ |
|
179 Calculate the scalar product of two vectors |
|
180 """ |
162 return v1[0] * v2[0] + v1[1] * v2[1] |
181 return v1[0] * v2[0] + v1[1] * v2[1] |
163 |
182 |
164 |
183 |
165 """ |
|
166 Function that calculates the nearest point of the grid defined by scaling for the given point |
|
167 """ |
|
168 |
|
169 def GetScaledEventPosition(event, dc, scaling): |
184 def GetScaledEventPosition(event, dc, scaling): |
|
185 """ |
|
186 Function that calculates the nearest point of the grid defined by scaling for the given point |
|
187 """ |
170 pos = event.GetLogicalPosition(dc) |
188 pos = event.GetLogicalPosition(dc) |
171 if scaling: |
189 if scaling: |
172 pos.x = round(float(pos.x) / float(scaling[0])) * scaling[0] |
190 pos.x = round(float(pos.x) / float(scaling[0])) * scaling[0] |
173 pos.y = round(float(pos.y) / float(scaling[1])) * scaling[1] |
191 pos.y = round(float(pos.y) / float(scaling[1])) * scaling[1] |
174 return pos |
192 return pos |
175 |
193 |
176 |
194 |
177 """ |
|
178 Function that choose a direction during the wire points generation |
|
179 """ |
|
180 |
195 |
181 def DirectionChoice(v_base, v_target, dir_target): |
196 def DirectionChoice(v_base, v_target, dir_target): |
|
197 """ |
|
198 Function that choose a direction during the wire points generation |
|
199 """ |
182 dir_product = product(v_base, v_target) |
200 dir_product = product(v_base, v_target) |
183 if dir_product < 0: |
201 if dir_product < 0: |
184 return (-v_base[0], -v_base[1]) |
202 return (-v_base[0], -v_base[1]) |
185 elif dir_product == 0 and product(v_base, dir_target) != 0: |
203 elif dir_product == 0 and product(v_base, dir_target) != 0: |
186 return dir_target |
204 return dir_target |
187 return v_base |
205 return v_base |
188 |
206 |
|
207 |
189 def MiterPen(colour, width=1, style=wx.SOLID): |
208 def MiterPen(colour, width=1, style=wx.SOLID): |
190 pen = wx.Pen(colour, width, style) |
209 pen = wx.Pen(colour, width, style) |
191 pen.SetJoin(wx.JOIN_MITER) |
210 pen.SetJoin(wx.JOIN_MITER) |
192 pen.SetCap(wx.CAP_PROJECTING) |
211 pen.SetCap(wx.CAP_PROJECTING) |
193 return pen |
212 return pen |
194 |
213 |
195 #------------------------------------------------------------------------------- |
214 #------------------------------------------------------------------------------- |
196 # Helpers for highlighting text |
215 # Helpers for highlighting text |
197 #------------------------------------------------------------------------------- |
216 #------------------------------------------------------------------------------- |
198 |
217 |
|
218 |
199 def AddHighlight(highlights, infos): |
219 def AddHighlight(highlights, infos): |
200 RemoveHighlight(highlights, infos) |
220 RemoveHighlight(highlights, infos) |
201 highlights.append(infos) |
221 highlights.append(infos) |
|
222 |
202 |
223 |
203 def RemoveHighlight(highlights, infos): |
224 def RemoveHighlight(highlights, infos): |
204 if infos in highlights: |
225 if infos in highlights: |
205 highlights.remove(infos) |
226 highlights.remove(infos) |
206 return True |
227 return True |
207 return False |
228 return False |
208 |
229 |
|
230 |
209 def ClearHighlight(highlights, highlight_type=None): |
231 def ClearHighlight(highlights, highlight_type=None): |
210 if highlight_type is not None: |
232 if highlight_type is not None: |
211 return [highlight for highlight in highlights if highlight[2] != highlight_type] |
233 return [highlight for highlight in highlights if highlight[2] != highlight_type] |
212 return [] |
234 return [] |
|
235 |
213 |
236 |
214 def DrawHighlightedText(dc, text, highlights, x, y): |
237 def DrawHighlightedText(dc, text, highlights, x, y): |
215 current_pen = dc.GetPen() |
238 current_pen = dc.GetPen() |
216 dc.SetPen(wx.TRANSPARENT_PEN) |
239 dc.SetPen(wx.TRANSPARENT_PEN) |
217 for start, end, highlight_type in highlights: |
240 for start, end, highlight_type in highlights: |
1000 |
1023 |
1001 #------------------------------------------------------------------------------- |
1024 #------------------------------------------------------------------------------- |
1002 # Connector for all types of blocks |
1025 # Connector for all types of blocks |
1003 #------------------------------------------------------------------------------- |
1026 #------------------------------------------------------------------------------- |
1004 |
1027 |
1005 """ |
|
1006 Class that implements a connector for any type of block |
|
1007 """ |
|
1008 |
1028 |
1009 class Connector(DebugDataConsumer, ToolTipProducer): |
1029 class Connector(DebugDataConsumer, ToolTipProducer): |
|
1030 """ |
|
1031 Class that implements a connector for any type of block |
|
1032 """ |
1010 |
1033 |
1011 # Create a new connector |
1034 # Create a new connector |
1012 def __init__(self, parent, name, type, position, direction, negated = False, edge = "none", onlyone = False): |
1035 def __init__(self, parent, name, type, position, direction, negated = False, edge = "none", onlyone = False): |
1013 DebugDataConsumer.__init__(self) |
1036 DebugDataConsumer.__init__(self) |
1014 ToolTipProducer.__init__(self, parent.Parent) |
1037 ToolTipProducer.__init__(self, parent.Parent) |
2725 if end[0] > row: |
2749 if end[0] > row: |
2726 end = (row, length) |
2750 end = (row, length) |
2727 _highlights.append((start, end, highlight_type)) |
2751 _highlights.append((start, end, highlight_type)) |
2728 return _highlights |
2752 return _highlights |
2729 |
2753 |
|
2754 |
2730 def FilterHighlightsByColumn(highlights, start_col, end_col): |
2755 def FilterHighlightsByColumn(highlights, start_col, end_col): |
2731 _highlights = [] |
2756 _highlights = [] |
2732 for start, end, highlight_type in highlights: |
2757 for start, end, highlight_type in highlights: |
2733 if end[1] > start_col and start[1] < end_col: |
2758 if end[1] > start_col and start[1] < end_col: |
2734 start = (start[0], max(start[1], start_col) - start_col) |
2759 start = (start[0], max(start[1], start_col) - start_col) |
2735 end = (end[0], min(end[1], end_col) - start_col) |
2760 end = (end[0], min(end[1], end_col) - start_col) |
2736 _highlights.append((start, end, highlight_type)) |
2761 _highlights.append((start, end, highlight_type)) |
2737 return _highlights |
2762 return _highlights |
2738 |
2763 |
2739 """ |
|
2740 Class that implements a comment |
|
2741 """ |
|
2742 |
2764 |
2743 class Comment(Graphic_Element): |
2765 class Comment(Graphic_Element): |
|
2766 """ |
|
2767 Class that implements a comment |
|
2768 """ |
2744 |
2769 |
2745 # Create a new comment |
2770 # Create a new comment |
2746 def __init__(self, parent, content, id = None): |
2771 def __init__(self, parent, content, id = None): |
2747 Graphic_Element.__init__(self, parent) |
2772 Graphic_Element.__init__(self, parent) |
2748 self.Id = id |
2773 self.Id = id |