graphics/GraphicCommons.py
changeset 825 0623820aa14a
parent 814 5743cbdff669
child 852 1009f956d2ee
equal deleted inserted replaced
824:be669f4c51c4 825:0623820aa14a
  1343     # Forbids to change the group position
  1343     # Forbids to change the group position
  1344     def SetPosition(x, y):
  1344     def SetPosition(x, y):
  1345         pass
  1345         pass
  1346     
  1346     
  1347     # Returns the position of this group
  1347     # Returns the position of this group
  1348     def GetPosition(self):
  1348     def GetPosition(self, exclude_wires=False):
       
  1349         if exclude_wires:
       
  1350             posx = posy = None
       
  1351             for element in self.Elements:
       
  1352                 if not isinstance(element, Wire) or element in self.WireExcluded:
       
  1353                     bbox = element.GetBoundingBox()
       
  1354                     if posx is None and posy is None:
       
  1355                         posx, posy = bbox.x, bbox.y
       
  1356                     else:
       
  1357                         posx = min(posx, bbox.x)
       
  1358                         posy = min(posy, bbox.y)
       
  1359             if posx is None and posy is None:
       
  1360                 return 0, 0
       
  1361             return posx, posy
  1349         return self.BoundingBox.x, self.BoundingBox.y
  1362         return self.BoundingBox.x, self.BoundingBox.y
  1350     
  1363     
  1351     # Forbids to change the group size
  1364     # Forbids to change the group size
  1352     def SetSize(width, height):
  1365     def SetSize(width, height):
  1353         pass
  1366         pass
  1376                 movex = round_scaling(movex, scaling[0])
  1389                 movex = round_scaling(movex, scaling[0])
  1377                 movey = round_scaling(movey, scaling[1])
  1390                 movey = round_scaling(movey, scaling[1])
  1378             if event.ControlDown():
  1391             if event.ControlDown():
  1379                 self.CurrentDrag.x = self.CurrentDrag.x + movex
  1392                 self.CurrentDrag.x = self.CurrentDrag.x + movex
  1380                 self.CurrentDrag.y = self.CurrentDrag.y + movey
  1393                 self.CurrentDrag.y = self.CurrentDrag.y + movey
       
  1394                 posx, posy = self.GetPosition(True)
  1381                 if abs(self.CurrentDrag.x) > abs(self.CurrentDrag.y):
  1395                 if abs(self.CurrentDrag.x) > abs(self.CurrentDrag.y):
  1382                     movex = self.StartPos.x + self.CurrentDrag.x - self.Pos.x
  1396                     movex = self.StartPos.x + self.CurrentDrag.x - posx
  1383                     movey = self.StartPos.y - self.Pos.y
  1397                     movey = self.StartPos.y - posy
  1384                 else:
  1398                 else:
  1385                     movex = self.StartPos.x - self.Pos.x
  1399                     movex = self.StartPos.x - posx
  1386                     movey = self.StartPos.y + self.CurrentDrag.y - self.Pos.y
  1400                     movey = self.StartPos.y + self.CurrentDrag.y - posy
  1387             self.Move(movex, movey)
  1401             self.Move(movex, movey)
  1388             return movex, movey
  1402             return movex, movey
  1389         return 0, 0
  1403         return 0, 0
  1390     
  1404     
  1391     # Change the variable that indicates if this element is highlighted
  1405     # Change the variable that indicates if this element is highlighted
  1399                 element.HighlightPoint(pos)
  1413                 element.HighlightPoint(pos)
  1400     
  1414     
  1401     # Method called when a LeftDown event have been generated
  1415     # Method called when a LeftDown event have been generated
  1402     def OnLeftDown(self, event, dc, scaling):
  1416     def OnLeftDown(self, event, dc, scaling):
  1403         Graphic_Element.OnLeftDown(self, event, dc, scaling)
  1417         Graphic_Element.OnLeftDown(self, event, dc, scaling)
       
  1418         self.StartPos = wx.Point(*self.GetPosition(True))
  1404         for element in self.Elements:
  1419         for element in self.Elements:
  1405             element.Handle = self.Handle
  1420             element.Handle = self.Handle
  1406 
  1421 
  1407     # Change the variable that indicates if the elemente is selected
  1422     # Change the variable that indicates if the elemente is selected
  1408     def SetSelected(self, selected):
  1423     def SetSelected(self, selected):