91 rect = rect.Union(input.GetConnectedRedrawRect(movex, movey)) |
91 rect = rect.Union(input.GetConnectedRedrawRect(movex, movey)) |
92 for output in self.Outputs: |
92 for output in self.Outputs: |
93 if output.IsConnected(): |
93 if output.IsConnected(): |
94 rect = rect.Union(output.GetConnectedRedrawRect(movex, movey)) |
94 rect = rect.Union(output.GetConnectedRedrawRect(movex, movey)) |
95 return rect |
95 return rect |
96 |
96 |
97 # Delete this block by calling the appropriate method |
97 # Delete this block by calling the appropriate method |
98 def Delete(self): |
98 def Delete(self): |
99 self.Parent.DeleteBlock(self) |
99 self.Parent.DeleteBlock(self) |
100 |
100 |
101 # Unconnect all inputs and outputs |
101 # Unconnect all inputs and outputs |
102 def Clean(self): |
102 def Clean(self): |
103 for input in self.Inputs: |
103 for input in self.Inputs: |
104 input.UnConnect(delete = True) |
104 input.UnConnect(delete = True) |
105 for output in self.Outputs: |
105 for output in self.Outputs: |
106 output.UnConnect(delete = True) |
106 output.UnConnect(delete = True) |
107 |
107 |
108 # Refresh the size of text for name |
108 # Refresh the size of text for name |
109 def RefreshNameSize(self): |
109 def RefreshNameSize(self): |
110 self.NameSize = self.Parent.GetTextExtent(self.Name) |
110 self.NameSize = self.Parent.GetTextExtent(self.Name) |
111 |
111 |
112 # Refresh the size of text for execution order |
112 # Refresh the size of text for execution order |
113 def RefreshExecutionOrderSize(self): |
113 def RefreshExecutionOrderSize(self): |
114 self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder)) |
114 self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder)) |
115 |
115 |
116 # Returns if the point given is in the bounding box |
116 # Returns if the point given is in the bounding box |
117 def HitTest(self, pt, connectors=True): |
117 def HitTest(self, pt, connectors=True): |
118 if self.Name != "": |
118 if self.Name != "": |
119 test_text = self.GetTextBoundingBox().InsideXY(pt.x, pt.y) |
119 test_text = self.GetTextBoundingBox().InsideXY(pt.x, pt.y) |
120 else: |
120 else: |
121 test_text = False |
121 test_text = False |
122 test_block = self.GetBlockBoundingBox(connectors).InsideXY(pt.x, pt.y) |
122 test_block = self.GetBlockBoundingBox(connectors).InsideXY(pt.x, pt.y) |
123 return test_text or test_block |
123 return test_text or test_block |
124 |
124 |
125 # Returns the bounding box of the name outside the block |
125 # Returns the bounding box of the name outside the block |
126 def GetTextBoundingBox(self): |
126 def GetTextBoundingBox(self): |
127 # Calculate the size of the name outside the block |
127 # Calculate the size of the name outside the block |
128 text_width, text_height = self.NameSize |
128 text_width, text_height = self.NameSize |
129 return wx.Rect(self.Pos.x + (self.Size[0] - text_width) / 2, |
129 return wx.Rect(self.Pos.x + (self.Size[0] - text_width) / 2, |
130 self.Pos.y - (text_height + 2), |
130 self.Pos.y - (text_height + 2), |
131 text_width, |
131 text_width, |
132 text_height) |
132 text_height) |
133 |
133 |
134 # Returns the bounding box of function block without name outside |
134 # Returns the bounding box of function block without name outside |
135 def GetBlockBoundingBox(self, connectors=True): |
135 def GetBlockBoundingBox(self, connectors=True): |
136 bbx_x, bbx_y = self.Pos.x, self.Pos.y |
136 bbx_x, bbx_y = self.Pos.x, self.Pos.y |
137 bbx_width, bbx_height = self.Size |
137 bbx_width, bbx_height = self.Size |
138 if connectors: |
138 if connectors: |
302 break |
302 break |
303 output_connectors.append(connector) |
303 output_connectors.append(connector) |
304 for output in self.Outputs: |
304 for output in self.Outputs: |
305 output.UnConnect(delete = True) |
305 output.UnConnect(delete = True) |
306 self.Outputs = output_connectors |
306 self.Outputs = output_connectors |
307 |
307 |
308 self.RefreshMinSize() |
308 self.RefreshMinSize() |
309 self.RefreshConnectors() |
309 self.RefreshConnectors() |
310 for output in self.Outputs: |
310 for output in self.Outputs: |
311 output.RefreshWires() |
311 output.RefreshWires() |
312 self.RefreshBoundingBox() |
312 self.RefreshBoundingBox() |
313 |
313 |
314 # Returns the block type |
314 # Returns the block type |
315 def GetType(self): |
315 def GetType(self): |
316 return self.Type |
316 return self.Type |
317 |
317 |
318 # Changes the block name |
318 # Changes the block name |
319 def SetName(self, name): |
319 def SetName(self, name): |
320 self.Name = name |
320 self.Name = name |
321 self.RefreshNameSize() |
321 self.RefreshNameSize() |
322 |
322 |
323 # Returs the block name |
323 # Returs the block name |
324 def GetName(self): |
324 def GetName(self): |
325 return self.Name |
325 return self.Name |
326 |
326 |
327 # Changes the extension name |
327 # Changes the extension name |
328 def SetExtension(self, extension): |
328 def SetExtension(self, extension): |
329 self.Extension = extension |
329 self.Extension = extension |
330 |
330 |
331 # Returs the extension name |
331 # Returs the extension name |
332 def GetExtension(self): |
332 def GetExtension(self): |
333 return self.Extension |
333 return self.Extension |
334 |
334 |
335 # Changes the execution order |
335 # Changes the execution order |
336 def SetExecutionOrder(self, executionOrder): |
336 def SetExecutionOrder(self, executionOrder): |
337 self.ExecutionOrder = executionOrder |
337 self.ExecutionOrder = executionOrder |
338 self.RefreshExecutionOrderSize() |
338 self.RefreshExecutionOrderSize() |
339 |
339 |
340 # Returs the execution order |
340 # Returs the execution order |
341 def GetExecutionOrder(self): |
341 def GetExecutionOrder(self): |
342 return self.ExecutionOrder |
342 return self.ExecutionOrder |
343 |
343 |
344 # Returs the execution order |
344 # Returs the execution order |
345 def GetExecutionControl(self): |
345 def GetExecutionControl(self): |
346 return self.ExecutionControl |
346 return self.ExecutionControl |
347 |
347 |
348 # Refresh the block minimum size |
348 # Refresh the block minimum size |
349 def RefreshMinSize(self): |
349 def RefreshMinSize(self): |
350 # Calculate the inputs maximum width |
350 # Calculate the inputs maximum width |
351 max_input = 0 |
351 max_input = 0 |
352 for input in self.Inputs: |
352 for input in self.Inputs: |
358 w, h = output.GetNameSize() |
358 w, h = output.GetNameSize() |
359 max_output = max(max_output, w) |
359 max_output = max(max_output, w) |
360 width = max(self.TypeSize[0] + 10, max_input + max_output + 15) |
360 width = max(self.TypeSize[0] + 10, max_input + max_output + 15) |
361 height = (max(len(self.Inputs), len(self.Outputs)) + 1) * BLOCK_LINE_SIZE |
361 height = (max(len(self.Inputs), len(self.Outputs)) + 1) * BLOCK_LINE_SIZE |
362 self.MinSize = width, height |
362 self.MinSize = width, height |
363 |
363 |
364 # Returns the block minimum size |
364 # Returns the block minimum size |
365 def GetMinSize(self): |
365 def GetMinSize(self): |
366 return self.MinSize |
366 return self.MinSize |
367 |
367 |
368 # Changes the negated property of the connector handled |
368 # Changes the negated property of the connector handled |
369 def SetConnectorNegated(self, negated): |
369 def SetConnectorNegated(self, negated): |
370 handle_type, handle = self.Handle |
370 handle_type, handle = self.Handle |
371 if handle_type == HANDLE_CONNECTOR: |
371 if handle_type == HANDLE_CONNECTOR: |
372 handle.SetNegated(negated) |
372 handle.SetNegated(negated) |
373 self.RefreshModel(False) |
373 self.RefreshModel(False) |
374 |
374 |
375 # Changes the edge property of the connector handled |
375 # Changes the edge property of the connector handled |
376 def SetConnectorEdge(self, edge): |
376 def SetConnectorEdge(self, edge): |
377 handle_type, handle = self.Handle |
377 handle_type, handle = self.Handle |
378 if handle_type == HANDLE_CONNECTOR: |
378 if handle_type == HANDLE_CONNECTOR: |
379 handle.SetEdge(edge) |
379 handle.SetEdge(edge) |
380 self.RefreshModel(False) |
380 self.RefreshModel(False) |
381 |
381 |
382 ## # Method called when a Motion event have been generated |
382 ## # Method called when a Motion event have been generated |
383 ## def OnMotion(self, event, dc, scaling): |
383 ## def OnMotion(self, event, dc, scaling): |
384 ## if not event.Dragging(): |
384 ## if not event.Dragging(): |
385 ## pos = event.GetLogicalPosition(dc) |
385 ## pos = event.GetLogicalPosition(dc) |
386 ## for input in self.Inputs: |
386 ## for input in self.Inputs: |
388 ## if rect.InsideXY(pos.x, pos.y): |
388 ## if rect.InsideXY(pos.x, pos.y): |
389 ## print "Find input" |
389 ## print "Find input" |
390 ## tip = wx.TipWindow(self.Parent, "Test") |
390 ## tip = wx.TipWindow(self.Parent, "Test") |
391 ## tip.SetBoundingRect(rect) |
391 ## tip.SetBoundingRect(rect) |
392 ## return Graphic_Element.OnMotion(self, event, dc, scaling) |
392 ## return Graphic_Element.OnMotion(self, event, dc, scaling) |
393 |
393 |
394 # Method called when a LeftDClick event have been generated |
394 # Method called when a LeftDClick event have been generated |
395 def OnLeftDClick(self, event, dc, scaling): |
395 def OnLeftDClick(self, event, dc, scaling): |
396 # Edit the block properties |
396 # Edit the block properties |
397 self.Parent.EditBlockContent(self) |
397 self.Parent.EditBlockContent(self) |
398 |
398 |
399 # Method called when a RightUp event have been generated |
399 # Method called when a RightUp event have been generated |
400 def OnRightUp(self, event, dc, scaling): |
400 def OnRightUp(self, event, dc, scaling): |
401 pos = GetScaledEventPosition(event, dc, scaling) |
401 pos = GetScaledEventPosition(event, dc, scaling) |
402 # Popup the menu with special items for a block and a connector if one is handled |
402 # Popup the menu with special items for a block and a connector if one is handled |
403 connector = self.TestConnector(pos, exclude=False) |
403 connector = self.TestConnector(pos, exclude=False) |
404 if connector: |
404 if connector: |
405 self.Handle = (HANDLE_CONNECTOR, connector) |
405 self.Handle = (HANDLE_CONNECTOR, connector) |
406 self.Parent.PopupBlockMenu(connector) |
406 self.Parent.PopupBlockMenu(connector) |
407 else: |
407 else: |
408 self.Parent.PopupBlockMenu() |
408 self.Parent.PopupBlockMenu() |
409 |
409 |
410 # Refreshes the block model |
410 # Refreshes the block model |
411 def RefreshModel(self, move=True): |
411 def RefreshModel(self, move=True): |
412 self.Parent.RefreshBlockModel(self) |
412 self.Parent.RefreshBlockModel(self) |
413 # If block has moved, refresh the model of wires connected to outputs |
413 # If block has moved, refresh the model of wires connected to outputs |
414 if move: |
414 if move: |
415 for output in self.Outputs: |
415 for output in self.Outputs: |
416 output.RefreshWires() |
416 output.RefreshWires() |
417 |
417 |
418 def GetToolTipValue(self): |
418 def GetToolTipValue(self): |
419 return self.Description |
419 return self.Description |
420 |
420 |
421 # Adds an highlight to the block |
421 # Adds an highlight to the block |
422 def AddHighlight(self, infos, start, end ,highlight_type): |
422 def AddHighlight(self, infos, start, end ,highlight_type): |
423 if infos[0] in ["type", "name"] and start[0] == 0 and end[0] == 0: |
423 if infos[0] in ["type", "name"] and start[0] == 0 and end[0] == 0: |
424 highlights = self.Highlights.setdefault(infos[0], []) |
424 highlights = self.Highlights.setdefault(infos[0], []) |
425 AddHighlight(highlights, (start, end, highlight_type)) |
425 AddHighlight(highlights, (start, end, highlight_type)) |
426 elif infos[0] == "input" and infos[1] < len(self.Inputs): |
426 elif infos[0] == "input" and infos[1] < len(self.Inputs): |
427 self.Inputs[infos[1]].AddHighlight(infos[2:], start, end, highlight_type) |
427 self.Inputs[infos[1]].AddHighlight(infos[2:], start, end, highlight_type) |
428 elif infos[0] == "output" and infos[1] < len(self.Outputs): |
428 elif infos[0] == "output" and infos[1] < len(self.Outputs): |
429 self.Outputs[infos[1]].AddHighlight(infos[2:], start, end, highlight_type) |
429 self.Outputs[infos[1]].AddHighlight(infos[2:], start, end, highlight_type) |
430 |
430 |
431 # Removes an highlight from the block |
431 # Removes an highlight from the block |
432 def RemoveHighlight(self, infos, start, end, highlight_type): |
432 def RemoveHighlight(self, infos, start, end, highlight_type): |
433 if infos[0] in ["type", "name"]: |
433 if infos[0] in ["type", "name"]: |
434 highlights = self.Highlights.get(infos[0], []) |
434 highlights = self.Highlights.get(infos[0], []) |
435 if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0: |
435 if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0: |
436 self.Highlights.pop(infos[0]) |
436 self.Highlights.pop(infos[0]) |
437 elif infos[0] == "input" and infos[1] < len(self.Inputs): |
437 elif infos[0] == "input" and infos[1] < len(self.Inputs): |
438 self.Inputs[infos[1]].RemoveHighlight(infos[2:], start, end, highlight_type) |
438 self.Inputs[infos[1]].RemoveHighlight(infos[2:], start, end, highlight_type) |
439 elif infos[0] == "output" and infos[1] < len(self.Outputs): |
439 elif infos[0] == "output" and infos[1] < len(self.Outputs): |
440 self.Outputs[infos[1]].RemoveHighlight(infos[2:], start, end, highlight_type) |
440 self.Outputs[infos[1]].RemoveHighlight(infos[2:], start, end, highlight_type) |
441 |
441 |
442 # Removes all the highlights of one particular type from the block |
442 # Removes all the highlights of one particular type from the block |
443 def ClearHighlight(self, highlight_type=None): |
443 def ClearHighlight(self, highlight_type=None): |
444 if highlight_type is None: |
444 if highlight_type is None: |
445 self.Highlights = {} |
445 self.Highlights = {} |
446 else: |
446 else: |
451 self.Highlights.pop(name) |
451 self.Highlights.pop(name) |
452 for input in self.Inputs: |
452 for input in self.Inputs: |
453 input.ClearHighlights(highlight_type) |
453 input.ClearHighlights(highlight_type) |
454 for output in self.Outputs: |
454 for output in self.Outputs: |
455 output.ClearHighlights(highlight_type) |
455 output.ClearHighlights(highlight_type) |
456 |
456 |
457 # Draws block |
457 # Draws block |
458 def Draw(self, dc): |
458 def Draw(self, dc): |
459 Graphic_Element.Draw(self, dc) |
459 Graphic_Element.Draw(self, dc) |
460 dc.SetPen(self.Pen) |
460 dc.SetPen(self.Pen) |
461 dc.SetBrush(wx.WHITE_BRUSH) |
461 dc.SetBrush(wx.WHITE_BRUSH) |
462 dc.SetTextForeground(self.Colour) |
462 dc.SetTextForeground(self.Colour) |
463 |
463 |
464 if getattr(dc, "printing", False): |
464 if getattr(dc, "printing", False): |
465 name_size = dc.GetTextExtent(self.Name) |
465 name_size = dc.GetTextExtent(self.Name) |
466 type_size = dc.GetTextExtent(self.Type) |
466 type_size = dc.GetTextExtent(self.Type) |
467 executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder)) |
467 executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder)) |
468 else: |
468 else: |
469 name_size = self.NameSize |
469 name_size = self.NameSize |
470 type_size = self.TypeSize |
470 type_size = self.TypeSize |
471 executionorder_size = self.ExecutionOrderSize |
471 executionorder_size = self.ExecutionOrderSize |
472 |
472 |
473 # Draw a rectangle with the block size |
473 # Draw a rectangle with the block size |
474 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
474 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
475 # Draw block name and block type |
475 # Draw block name and block type |
476 name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
476 name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
477 self.Pos.y - (name_size[1] + 2)) |
477 self.Pos.y - (name_size[1] + 2)) |
528 if self.Input: |
528 if self.Input: |
529 variable.Input = self.Input.Clone(variable) |
529 variable.Input = self.Input.Clone(variable) |
530 if self.Output: |
530 if self.Output: |
531 variable.Output = self.Output.Clone(variable) |
531 variable.Output = self.Output.Clone(variable) |
532 return variable |
532 return variable |
533 |
533 |
534 def GetConnectorTranslation(self, element): |
534 def GetConnectorTranslation(self, element): |
535 connectors = {} |
535 connectors = {} |
536 if self.Input is not None: |
536 if self.Input is not None: |
537 connectors[self.Input] = element.Input |
537 connectors[self.Input] = element.Input |
538 if self.Output is not None: |
538 if self.Output is not None: |
539 connectors[self.Output] = element.Output |
539 connectors[self.Output] = element.Output |
540 return connectors |
540 return connectors |
541 |
541 |
542 def Flush(self): |
542 def Flush(self): |
543 if self.Input is not None: |
543 if self.Input is not None: |
544 self.Input.Flush() |
544 self.Input.Flush() |
545 self.Input = None |
545 self.Input = None |
546 if self.Output is not None: |
546 if self.Output is not None: |
547 self.Output.Flush() |
547 self.Output.Flush() |
548 self.Output = None |
548 self.Output = None |
549 |
549 |
550 # Returns the RedrawRect |
550 # Returns the RedrawRect |
551 def GetRedrawRect(self, movex = 0, movey = 0): |
551 def GetRedrawRect(self, movex = 0, movey = 0): |
552 rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
552 rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
553 if movex != 0 or movey != 0: |
553 if movex != 0 or movey != 0: |
554 if self.Input and self.Input.IsConnected(): |
554 if self.Input and self.Input.IsConnected(): |
555 rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
555 rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
556 if self.Output and self.Output.IsConnected(): |
556 if self.Output and self.Output.IsConnected(): |
557 rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
557 rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
558 return rect |
558 return rect |
559 |
559 |
560 # Unconnect connector |
560 # Unconnect connector |
561 def Clean(self): |
561 def Clean(self): |
562 if self.Input: |
562 if self.Input: |
563 self.Input.UnConnect(delete = True) |
563 self.Input.UnConnect(delete = True) |
564 if self.Output: |
564 if self.Output: |
565 self.Output.UnConnect(delete = True) |
565 self.Output.UnConnect(delete = True) |
566 |
566 |
567 # Delete this variable by calling the appropriate method |
567 # Delete this variable by calling the appropriate method |
568 def Delete(self): |
568 def Delete(self): |
569 self.Parent.DeleteVariable(self) |
569 self.Parent.DeleteVariable(self) |
570 |
570 |
571 # Refresh the size of text for name |
571 # Refresh the size of text for name |
572 def RefreshNameSize(self): |
572 def RefreshNameSize(self): |
573 self.NameSize = self.Parent.GetTextExtent(self.Name) |
573 self.NameSize = self.Parent.GetTextExtent(self.Name) |
574 |
574 |
575 # Refresh the size of text for execution order |
575 # Refresh the size of text for execution order |
576 def RefreshExecutionOrderSize(self): |
576 def RefreshExecutionOrderSize(self): |
577 self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder)) |
577 self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder)) |
578 |
578 |
579 # Refresh the variable bounding box |
579 # Refresh the variable bounding box |
580 def RefreshBoundingBox(self): |
580 def RefreshBoundingBox(self): |
581 if self.Type in (OUTPUT, INOUT): |
581 if self.Type in (OUTPUT, INOUT): |
582 bbx_x = self.Pos.x - CONNECTOR_SIZE |
582 bbx_x = self.Pos.x - CONNECTOR_SIZE |
583 else: |
583 else: |
678 self.RefreshBoundingBox() |
678 self.RefreshBoundingBox() |
679 elif value_type != self.ValueType: |
679 elif value_type != self.ValueType: |
680 if self.Input: |
680 if self.Input: |
681 self.Input.SetType(value_type) |
681 self.Input.SetType(value_type) |
682 if self.Output: |
682 if self.Output: |
683 self.Output.SetType(value_type) |
683 self.Output.SetType(value_type) |
684 |
684 |
685 # Returns the variable type |
685 # Returns the variable type |
686 def GetType(self): |
686 def GetType(self): |
687 return self.Type |
687 return self.Type |
688 |
688 |
689 # Returns the variable value type |
689 # Returns the variable value type |
690 def GetValueType(self): |
690 def GetValueType(self): |
691 return self.ValueType |
691 return self.ValueType |
692 |
692 |
693 # Changes the variable name |
693 # Changes the variable name |
694 def SetName(self, name): |
694 def SetName(self, name): |
695 self.Name = name |
695 self.Name = name |
696 self.RefreshNameSize() |
696 self.RefreshNameSize() |
697 |
697 |
698 # Returns the variable name |
698 # Returns the variable name |
699 def GetName(self): |
699 def GetName(self): |
700 return self.Name |
700 return self.Name |
701 |
701 |
702 # Changes the execution order |
702 # Changes the execution order |
703 def SetExecutionOrder(self, executionOrder): |
703 def SetExecutionOrder(self, executionOrder): |
704 self.ExecutionOrder = executionOrder |
704 self.ExecutionOrder = executionOrder |
705 self.RefreshExecutionOrderSize() |
705 self.RefreshExecutionOrderSize() |
706 |
706 |
707 # Returs the execution order |
707 # Returs the execution order |
708 def GetExecutionOrder(self): |
708 def GetExecutionOrder(self): |
709 return self.ExecutionOrder |
709 return self.ExecutionOrder |
710 |
710 |
711 # Returns the variable minimum size |
711 # Returns the variable minimum size |
712 def GetMinSize(self): |
712 def GetMinSize(self): |
713 return self.NameSize[0] + 10, self.NameSize[1] + 10 |
713 return self.NameSize[0] + 10, self.NameSize[1] + 10 |
714 |
714 |
715 # Set size of the variable to the minimum size |
715 # Set size of the variable to the minimum size |
716 def SetBestSize(self, scaling): |
716 def SetBestSize(self, scaling): |
717 if self.Type == INPUT: |
717 if self.Type == INPUT: |
718 return Graphic_Element.SetBestSize(self, scaling, x_factor=1.) |
718 return Graphic_Element.SetBestSize(self, scaling, x_factor=1.) |
719 elif self.Type == OUTPUT: |
719 elif self.Type == OUTPUT: |
720 return Graphic_Element.SetBestSize(self, scaling, x_factor=0.) |
720 return Graphic_Element.SetBestSize(self, scaling, x_factor=0.) |
721 else: |
721 else: |
722 return Graphic_Element.SetBestSize(self, scaling) |
722 return Graphic_Element.SetBestSize(self, scaling) |
723 |
723 |
724 # Method called when a LeftDClick event have been generated |
724 # Method called when a LeftDClick event have been generated |
725 def OnLeftDClick(self, event, dc, scaling): |
725 def OnLeftDClick(self, event, dc, scaling): |
726 if event.ControlDown(): |
726 if event.ControlDown(): |
727 # Change variable type |
727 # Change variable type |
728 types = [INPUT, OUTPUT, INOUT] |
728 types = [INPUT, OUTPUT, INOUT] |
729 self.Parent.ChangeVariableType(self, |
729 self.Parent.ChangeVariableType(self, |
730 types[(types.index(self.Type) + 1) % len(types)]) |
730 types[(types.index(self.Type) + 1) % len(types)]) |
731 else: |
731 else: |
732 # Edit the variable properties |
732 # Edit the variable properties |
733 self.Parent.EditVariableContent(self) |
733 self.Parent.EditVariableContent(self) |
734 |
734 |
735 # Method called when a RightUp event have been generated |
735 # Method called when a RightUp event have been generated |
736 def OnRightUp(self, event, dc, scaling): |
736 def OnRightUp(self, event, dc, scaling): |
737 self.Parent.PopupVariableMenu() |
737 self.Parent.PopupVariableMenu() |
738 |
738 |
739 # Refreshes the variable model |
739 # Refreshes the variable model |
740 def RefreshModel(self, move=True): |
740 def RefreshModel(self, move=True): |
741 self.Parent.RefreshVariableModel(self) |
741 self.Parent.RefreshVariableModel(self) |
742 # If variable has moved and variable is not of type OUTPUT, refresh the model |
742 # If variable has moved and variable is not of type OUTPUT, refresh the model |
743 # of wires connected to output connector |
743 # of wires connected to output connector |
744 if move and self.Type != OUTPUT: |
744 if move and self.Type != OUTPUT: |
745 if self.Output: |
745 if self.Output: |
746 self.Output.RefreshWires() |
746 self.Output.RefreshWires() |
747 |
747 |
748 # Adds an highlight to the variable |
748 # Adds an highlight to the variable |
749 def AddHighlight(self, infos, start, end, highlight_type): |
749 def AddHighlight(self, infos, start, end, highlight_type): |
750 if infos[0] == "expression" and start[0] == 0 and end[0] == 0: |
750 if infos[0] == "expression" and start[0] == 0 and end[0] == 0: |
751 AddHighlight(self.Highlights, (start, end, highlight_type)) |
751 AddHighlight(self.Highlights, (start, end, highlight_type)) |
752 |
752 |
753 # Removes an highlight from the variable |
753 # Removes an highlight from the variable |
754 def RemoveHighlight(self, infos, start, end, highlight_type): |
754 def RemoveHighlight(self, infos, start, end, highlight_type): |
755 if infos[0] == "expression": |
755 if infos[0] == "expression": |
756 RemoveHighlight(self.Highlights, (start, end, highlight_type)) |
756 RemoveHighlight(self.Highlights, (start, end, highlight_type)) |
757 |
757 |
758 # Removes all the highlights of one particular type from the variable |
758 # Removes all the highlights of one particular type from the variable |
759 def ClearHighlight(self, highlight_type=None): |
759 def ClearHighlight(self, highlight_type=None): |
760 ClearHighlights(self.Highlights, highlight_type) |
760 ClearHighlights(self.Highlights, highlight_type) |
761 |
761 |
762 # Draws variable |
762 # Draws variable |
763 def Draw(self, dc): |
763 def Draw(self, dc): |
764 Graphic_Element.Draw(self, dc) |
764 Graphic_Element.Draw(self, dc) |
765 dc.SetPen(MiterPen(wx.BLACK)) |
765 dc.SetPen(MiterPen(wx.BLACK)) |
766 dc.SetBrush(wx.WHITE_BRUSH) |
766 dc.SetBrush(wx.WHITE_BRUSH) |
767 |
767 |
768 if getattr(dc, "printing", False): |
768 if getattr(dc, "printing", False): |
769 name_size = dc.GetTextExtent(self.Name) |
769 name_size = dc.GetTextExtent(self.Name) |
770 executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder)) |
770 executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder)) |
771 else: |
771 else: |
772 name_size = self.NameSize |
772 name_size = self.NameSize |
773 executionorder_size = self.ExecutionOrderSize |
773 executionorder_size = self.ExecutionOrderSize |
774 |
774 |
775 text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
775 text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
776 self.Pos.y + (self.Size[1] - name_size[1]) / 2) |
776 self.Pos.y + (self.Size[1] - name_size[1]) / 2) |
777 # Draw a rectangle with the variable size |
777 # Draw a rectangle with the variable size |
778 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
778 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
779 # Draw variable name |
779 # Draw variable name |
780 dc.DrawText(self.Name, text_pos[0], text_pos[1]) |
780 dc.DrawText(self.Name, text_pos[0], text_pos[1]) |
781 # Draw connectors |
781 # Draw connectors |
782 if self.Input: |
782 if self.Input: |
783 self.Input.Draw(dc) |
783 self.Input.Draw(dc) |
784 if self.Output: |
784 if self.Output: |
785 self.Output.Draw(dc) |
785 self.Output.Draw(dc) |
786 if self.ExecutionOrder != 0: |
786 if self.ExecutionOrder != 0: |
787 # Draw variable execution order |
787 # Draw variable execution order |
788 dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0], |
788 dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0], |
789 self.Pos.y + self.Size[1] + 2) |
789 self.Pos.y + self.Size[1] + 2) |
790 if not getattr(dc, "printing", False): |
790 if not getattr(dc, "printing", False): |
791 DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1]) |
791 DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1]) |
792 |
792 |
793 #------------------------------------------------------------------------------- |
793 #------------------------------------------------------------------------------- |
794 # Function Block Diagram Connector |
794 # Function Block Diagram Connector |
795 #------------------------------------------------------------------------------- |
795 #------------------------------------------------------------------------------- |
796 |
796 |
797 """ |
797 """ |
814 self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone = True) |
814 self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone = True) |
815 else: |
815 else: |
816 self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) |
816 self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) |
817 self.RefreshConnectors() |
817 self.RefreshConnectors() |
818 self.RefreshNameSize() |
818 self.RefreshNameSize() |
819 |
819 |
820 def Flush(self): |
820 def Flush(self): |
821 if self.Connector: |
821 if self.Connector: |
822 self.Connector.Flush() |
822 self.Connector.Flush() |
823 self.Connector = None |
823 self.Connector = None |
824 |
824 |
825 # Returns the RedrawRect |
825 # Returns the RedrawRect |
826 def GetRedrawRect(self, movex = 0, movey = 0): |
826 def GetRedrawRect(self, movex = 0, movey = 0): |
827 rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
827 rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
828 if movex != 0 or movey != 0: |
828 if movex != 0 or movey != 0: |
829 if self.Connector and self.Connector.IsConnected(): |
829 if self.Connector and self.Connector.IsConnected(): |
830 rect = rect.Union(self.Connector.GetConnectedRedrawRect(movex, movey)) |
830 rect = rect.Union(self.Connector.GetConnectedRedrawRect(movex, movey)) |
831 return rect |
831 return rect |
832 |
832 |
833 # Make a clone of this FBD_Connector |
833 # Make a clone of this FBD_Connector |
834 def Clone(self, parent, id = None, pos = None): |
834 def Clone(self, parent, id = None, pos = None): |
835 connection = FBD_Connector(parent, self.Type, self.Name, id) |
835 connection = FBD_Connector(parent, self.Type, self.Name, id) |
836 connection.SetSize(self.Size[0], self.Size[1]) |
836 connection.SetSize(self.Size[0], self.Size[1]) |
837 if pos is not None: |
837 if pos is not None: |
838 connection.SetPosition(pos.x, pos.y) |
838 connection.SetPosition(pos.x, pos.y) |
839 else: |
839 else: |
840 connection.SetPosition(self.Pos.x, self.Pos.y) |
840 connection.SetPosition(self.Pos.x, self.Pos.y) |
841 connection.Connector = self.Connector.Clone(connection) |
841 connection.Connector = self.Connector.Clone(connection) |
842 return connection |
842 return connection |
843 |
843 |
844 def GetConnectorTranslation(self, element): |
844 def GetConnectorTranslation(self, element): |
845 return {self.Connector : element.Connector} |
845 return {self.Connector : element.Connector} |
846 |
846 |
847 # Unconnect connector |
847 # Unconnect connector |
848 def Clean(self): |
848 def Clean(self): |
849 if self.Connector: |
849 if self.Connector: |
850 self.Connector.UnConnect(delete = True) |
850 self.Connector.UnConnect(delete = True) |
851 |
851 |
852 # Delete this connection by calling the appropriate method |
852 # Delete this connection by calling the appropriate method |
853 def Delete(self): |
853 def Delete(self): |
854 self.Parent.DeleteConnection(self) |
854 self.Parent.DeleteConnection(self) |
855 |
855 |
856 # Refresh the size of text for name |
856 # Refresh the size of text for name |
857 def RefreshNameSize(self): |
857 def RefreshNameSize(self): |
858 self.NameSize = self.Parent.GetTextExtent(self.Name) |
858 self.NameSize = self.Parent.GetTextExtent(self.Name) |
859 |
859 |
860 # Refresh the connection bounding box |
860 # Refresh the connection bounding box |
861 def RefreshBoundingBox(self): |
861 def RefreshBoundingBox(self): |
862 if self.Type == CONNECTOR: |
862 if self.Type == CONNECTOR: |
863 bbx_x = self.Pos.x - CONNECTOR_SIZE |
863 bbx_x = self.Pos.x - CONNECTOR_SIZE |
864 else: |
864 else: |
865 bbx_x = self.Pos.x |
865 bbx_x = self.Pos.x |
866 bbx_width = self.Size[0] + CONNECTOR_SIZE |
866 bbx_width = self.Size[0] + CONNECTOR_SIZE |
867 self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width, self.Size[1]) |
867 self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width, self.Size[1]) |
868 |
868 |
869 # Refresh the position of the connection connector |
869 # Refresh the position of the connection connector |
870 def RefreshConnectors(self): |
870 def RefreshConnectors(self): |
871 scaling = self.Parent.GetScaling() |
871 scaling = self.Parent.GetScaling() |
872 if scaling is not None: |
872 if scaling is not None: |
873 position = round_scaling(self.Pos.y + self.Size[1] / 2, scaling[1]) - self.Pos.y |
873 position = round_scaling(self.Pos.y + self.Size[1] / 2, scaling[1]) - self.Pos.y |
876 if self.Type == CONNECTOR: |
876 if self.Type == CONNECTOR: |
877 self.Connector.SetPosition(wx.Point(0, position)) |
877 self.Connector.SetPosition(wx.Point(0, position)) |
878 else: |
878 else: |
879 self.Connector.SetPosition(wx.Point(self.Size[0], position)) |
879 self.Connector.SetPosition(wx.Point(self.Size[0], position)) |
880 self.RefreshConnected() |
880 self.RefreshConnected() |
881 |
881 |
882 # Refresh the position of wires connected to connector |
882 # Refresh the position of wires connected to connector |
883 def RefreshConnected(self, exclude = []): |
883 def RefreshConnected(self, exclude = []): |
884 if self.Connector: |
884 if self.Connector: |
885 self.Connector.MoveConnected(exclude) |
885 self.Connector.MoveConnected(exclude) |
886 |
886 |
887 # Test if point given is on the connection connector |
887 # Test if point given is on the connection connector |
888 def TestConnector(self, pt, direction = None, exclude=True): |
888 def TestConnector(self, pt, direction = None, exclude=True): |
889 if self.Connector and self.Connector.TestPoint(pt, direction, exclude): |
889 if self.Connector and self.Connector.TestPoint(pt, direction, exclude): |
890 return self.Connector |
890 return self.Connector |
891 return None |
891 return None |
892 |
892 |
893 # Returns the connection connector |
893 # Returns the connection connector |
894 def GetConnector(self, position = None, name = None): |
894 def GetConnector(self, position = None, name = None): |
895 return self.Connector |
895 return self.Connector |
896 |
896 |
897 # Returns all the block connectors |
897 # Returns all the block connectors |
898 def GetConnectors(self): |
898 def GetConnectors(self): |
899 connectors = {"inputs": [], "outputs": []} |
899 connectors = {"inputs": [], "outputs": []} |
900 if self.Type == CONNECTOR: |
900 if self.Type == CONNECTOR: |
901 connectors["inputs"].append(self.Connector) |
901 connectors["inputs"].append(self.Connector) |
902 else: |
902 else: |
921 self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone = True) |
921 self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone = True) |
922 else: |
922 else: |
923 self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) |
923 self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) |
924 self.RefreshConnectors() |
924 self.RefreshConnectors() |
925 self.RefreshBoundingBox() |
925 self.RefreshBoundingBox() |
926 |
926 |
927 # Returns the connection type |
927 # Returns the connection type |
928 def GetType(self): |
928 def GetType(self): |
929 return self.Type |
929 return self.Type |
930 |
930 |
931 def GetConnectionResultType(self, connector, connectortype): |
931 def GetConnectionResultType(self, connector, connectortype): |
932 if self.Type == CONTINUATION: |
932 if self.Type == CONTINUATION: |
933 connector = self.Parent.GetConnectorByName(self.Name) |
933 connector = self.Parent.GetConnectorByName(self.Name) |
934 if connector is not None: |
934 if connector is not None: |
935 return connector.Connector.GetConnectedType() |
935 return connector.Connector.GetConnectedType() |
936 return connectortype |
936 return connectortype |
937 |
937 |
938 # Changes the connection name |
938 # Changes the connection name |
939 def SetName(self, name): |
939 def SetName(self, name): |
940 self.Name = name |
940 self.Name = name |
941 self.RefreshNameSize() |
941 self.RefreshNameSize() |
942 |
942 |
943 # Returns the connection name |
943 # Returns the connection name |
944 def GetName(self): |
944 def GetName(self): |
945 return self.Name |
945 return self.Name |
946 |
946 |
947 # Set size of the variable to the minimum size |
947 # Set size of the variable to the minimum size |
948 def SetBestSize(self, scaling): |
948 def SetBestSize(self, scaling): |
949 if self.Type == CONTINUATION: |
949 if self.Type == CONTINUATION: |
950 return Graphic_Element.SetBestSize(self, scaling, x_factor=1.) |
950 return Graphic_Element.SetBestSize(self, scaling, x_factor=1.) |
951 else: |
951 else: |
952 return Graphic_Element.SetBestSize(self, scaling, x_factor=0.) |
952 return Graphic_Element.SetBestSize(self, scaling, x_factor=0.) |
953 |
953 |
954 # Returns the connection minimum size |
954 # Returns the connection minimum size |
955 def GetMinSize(self): |
955 def GetMinSize(self): |
956 text_width, text_height = self.NameSize |
956 text_width, text_height = self.NameSize |
957 if text_height % 2 == 1: |
957 if text_height % 2 == 1: |
958 text_height += 1 |
958 text_height += 1 |
959 return text_width + text_height + 20, text_height + 10 |
959 return text_width + text_height + 20, text_height + 10 |
960 |
960 |
961 # Method called when a LeftDClick event have been generated |
961 # Method called when a LeftDClick event have been generated |
962 def OnLeftDClick(self, event, dc, scaling): |
962 def OnLeftDClick(self, event, dc, scaling): |
963 if event.ControlDown(): |
963 if event.ControlDown(): |
964 # Change connection type |
964 # Change connection type |
965 if self.Type == CONNECTOR: |
965 if self.Type == CONNECTOR: |
966 self.Parent.ChangeConnectionType(self, CONTINUATION) |
966 self.Parent.ChangeConnectionType(self, CONTINUATION) |
967 else: |
967 else: |
968 self.Parent.ChangeConnectionType(self, CONNECTOR) |
968 self.Parent.ChangeConnectionType(self, CONNECTOR) |
969 else: |
969 else: |
970 # Edit the connection properties |
970 # Edit the connection properties |
971 self.Parent.EditConnectionContent(self) |
971 self.Parent.EditConnectionContent(self) |
972 |
972 |
973 # Method called when a RightUp event have been generated |
973 # Method called when a RightUp event have been generated |
974 def OnRightUp(self, event, dc, scaling): |
974 def OnRightUp(self, event, dc, scaling): |
975 # Popup the default menu |
975 # Popup the default menu |
976 self.Parent.PopupConnectionMenu() |
976 self.Parent.PopupConnectionMenu() |
977 |
977 |
978 # Refreshes the connection model |
978 # Refreshes the connection model |
979 def RefreshModel(self, move=True): |
979 def RefreshModel(self, move=True): |
980 self.Parent.RefreshConnectionModel(self) |
980 self.Parent.RefreshConnectionModel(self) |
981 # If connection has moved and connection is of type CONTINUATION, refresh |
981 # If connection has moved and connection is of type CONTINUATION, refresh |
982 # the model of wires connected to connector |
982 # the model of wires connected to connector |
983 if move and self.Type == CONTINUATION: |
983 if move and self.Type == CONTINUATION: |
984 if self.Connector: |
984 if self.Connector: |
985 self.Connector.RefreshWires() |
985 self.Connector.RefreshWires() |
986 |
986 |
987 # Adds an highlight to the connection |
987 # Adds an highlight to the connection |
988 def AddHighlight(self, infos, start, end, highlight_type): |
988 def AddHighlight(self, infos, start, end, highlight_type): |
989 if infos[0] == "name" and start[0] == 0 and end[0] == 0: |
989 if infos[0] == "name" and start[0] == 0 and end[0] == 0: |
990 AddHighlight(self.Highlights, (start, end, highlight_type)) |
990 AddHighlight(self.Highlights, (start, end, highlight_type)) |
991 |
991 |
992 # Removes an highlight from the connection |
992 # Removes an highlight from the connection |
993 def RemoveHighlight(self, infos, start, end, highlight_type): |
993 def RemoveHighlight(self, infos, start, end, highlight_type): |
994 if infos[0] == "name": |
994 if infos[0] == "name": |
995 RemoveHighlight(self.Highlights, (start, end, highlight_type)) |
995 RemoveHighlight(self.Highlights, (start, end, highlight_type)) |
996 |
996 |
997 # Removes all the highlights of one particular type from the connection |
997 # Removes all the highlights of one particular type from the connection |
998 def ClearHighlight(self, highlight_type=None): |
998 def ClearHighlight(self, highlight_type=None): |
999 ClearHighlights(self.Highlights, highlight_type) |
999 ClearHighlights(self.Highlights, highlight_type) |
1000 |
1000 |
1001 # Draws connection |
1001 # Draws connection |
1002 def Draw(self, dc): |
1002 def Draw(self, dc): |
1003 Graphic_Element.Draw(self, dc) |
1003 Graphic_Element.Draw(self, dc) |
1004 dc.SetPen(MiterPen(wx.BLACK)) |
1004 dc.SetPen(MiterPen(wx.BLACK)) |
1005 dc.SetBrush(wx.WHITE_BRUSH) |
1005 dc.SetBrush(wx.WHITE_BRUSH) |
1006 |
1006 |
1007 if getattr(dc, "printing", False): |
1007 if getattr(dc, "printing", False): |
1008 name_size = dc.GetTextExtent(self.Name) |
1008 name_size = dc.GetTextExtent(self.Name) |
1009 else: |
1009 else: |
1010 name_size = self.NameSize |
1010 name_size = self.NameSize |
1011 |
1011 |
1012 # Draw a rectangle with the connection size with arrows inside |
1012 # Draw a rectangle with the connection size with arrows inside |
1013 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
1013 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
1014 arrowsize = min(self.Size[1] / 2, (self.Size[0] - name_size[0] - 10) / 2) |
1014 arrowsize = min(self.Size[1] / 2, (self.Size[0] - name_size[0] - 10) / 2) |
1015 dc.DrawLine(self.Pos.x, self.Pos.y, self.Pos.x + arrowsize, |
1015 dc.DrawLine(self.Pos.x, self.Pos.y, self.Pos.x + arrowsize, |
1016 self.Pos.y + self.Size[1] / 2) |
1016 self.Pos.y + self.Size[1] / 2) |
1017 dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] / 2, |
1017 dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] / 2, |
1018 self.Pos.x, self.Pos.y + self.Size[1]) |
1018 self.Pos.x, self.Pos.y + self.Size[1]) |
1019 dc.DrawLine(self.Pos.x + self.Size[0] - arrowsize, self.Pos.y, |
1019 dc.DrawLine(self.Pos.x + self.Size[0] - arrowsize, self.Pos.y, |
1020 self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2) |
1020 self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2) |
1021 dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2, |
1021 dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2, |
1022 self.Pos.x + self.Size[0] - arrowsize, self.Pos.y + self.Size[1]) |
1022 self.Pos.x + self.Size[0] - arrowsize, self.Pos.y + self.Size[1]) |
1023 # Draw connection name |
1023 # Draw connection name |
1024 text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
1024 text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
1025 self.Pos.y + (self.Size[1] - name_size[1]) / 2) |
1025 self.Pos.y + (self.Size[1] - name_size[1]) / 2) |
1026 dc.DrawText(self.Name, text_pos[0], text_pos[1]) |
1026 dc.DrawText(self.Name, text_pos[0], text_pos[1]) |
1027 # Draw connector |
1027 # Draw connector |
1028 if self.Connector: |
1028 if self.Connector: |
1029 self.Connector.Draw(dc) |
1029 self.Connector.Draw(dc) |
1030 |
1030 |
1031 if not getattr(dc, "printing", False): |
1031 if not getattr(dc, "printing", False): |
1032 DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1]) |
1032 DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1]) |
1033 |
|