Example #1
0
 def Activated(self):
     FreeCAD.ActiveDocument.openTransaction(self.__str__())
     if Common.localMode:
         i = 0
         Path = Common.GetSelectedLowerObjectsPath()
         objs = Common.GetSelectedLowerObjects()
         bb_a = Common.GetBoundBoxFromGlobalCoordinates(
             Path[Path.__len__() - 1], objs[objs.__len__() - 1])
         while i < objs.__len__():
             bb_i = Common.GetBoundBoxFromGlobalCoordinates(
                 Path[i], objs[i])
             base_i = Common.toGlobalCoordinates(Path[i],
                                                 objs[i].Placement.Base)
             base_i.x = bb_a.XMax - (bb_i.XMax - base_i.x)
             objs[i].Placement.Base = Common.toLocalCoordinates(
                 Path[i], base_i)
             i = i + 1
     else:
         objs = GetSelectedUpperObjects()
         if objs.__len__() > 0:
             a = GetObjectBoundBox(objs[objs.__len__() - 1]).XMax
             for obj in objs:
                 obj.Placement.Base.x = a - (GetObjectBoundBox(obj).XMax -
                                             obj.Placement.Base.x)
     return
Example #2
0
 def Activated(self):
     FreeCAD.ActiveDocument.openTransaction(self.__str__())
     if Common.localMode:
         i = 0
         Path = Common.GetSelectedLowerObjectsPath()
         objs = Common.GetSelectedLowerObjects()
         i = objs.__len__() - 1
         if i > 0:
             bb_a = Common.GetBoundBoxFromGlobalCoordinates(
                 Path[i], objs[i])
             j = 0
             while j < i:
                 bb_j = Common.GetBoundBoxFromGlobalCoordinates(
                     Path[j], objs[j])
                 base_j = Common.toGlobalCoordinates(
                     Path[j], objs[j].Placement.Base)
                 base_j.z = base_j.z - (bb_j.ZMax - bb_a.ZMin)
                 objs[j].Placement.Base = Common.toLocalCoordinates(
                     Path[j], base_j)
                 j = j + 1
     else:
         objs = GetSelectedUpperObjects()
         i = objs.__len__() - 1
         if i > 0:
             a = GetObjectBoundBox(objs[i]).ZMin
             j = 0
             while j < i:
                 objs[j].Placement.Base.z = objs[j].Placement.Base.z - (
                     GetObjectBoundBox(objs[j]).ZMax - a)
                 j = j + 1
     return
Example #3
0
 def Activated(self):
     FreeCAD.ActiveDocument.openTransaction(self.__str__())
     if Common.localMode:
         Path = Common.GetSelectedLowerObjectsPath()
         objs = Common.GetSelectedLowerObjects()
         if objs.__len__() > 0:
             i = objs.__len__() - 1
             bb = Common.GetBoundBoxFromGlobalCoordinates(Path[i], objs[i])
             a = bb.ZMin + (bb.ZMax - bb.ZMin) / 2.0
             j = 0
             while j < objs.__len__():
                 bb_j = Common.GetBoundBoxFromGlobalCoordinates(
                     Path[j], objs[j])
                 base_j = Common.toGlobalCoordinates(
                     Path[j], objs[j].Placement.Base)
                 base_j.z = base_j.z + a - (bb_j.ZMin +
                                            ((bb_j.ZMax - bb_j.ZMin) / 2.0))
                 objs[j].Placement.Base = Common.toLocalCoordinates(
                     Path[j], base_j)
                 j = j + 1
     else:
         objs = GetSelectedUpperObjects()
         if objs.__len__() > 0:
             i = objs.__len__() - 1
             bb = GetObjectBoundBox(objs[i])
             a = bb.ZMin + (bb.ZMax - bb.ZMin) / 2.0
             for obj in objs:
                 bb = GetObjectBoundBox(obj)
                 obj.Placement.Base.z = obj.Placement.Base.z + a - (
                     bb.ZMin + ((bb.ZMax - bb.ZMin) / 2.0))
     return
def Rotate(obj, x, y, z):
    c = GetObjectBoundBox(obj).Center
    a = obj.Placement.Rotation
    obj.Placement.Rotation = FreeCAD.Rotation(z, y, x)
    obj.Placement.Rotation = obj.Placement.Rotation.multiply(a)
    obj.Placement.Base = obj.Placement.Base + c.sub(
        GetObjectBoundBox(obj).Center)
    return
def testRotate(obj, x, y, z):
    c = obj.Placement.Rotation.inverted().multVec(
        GetObjectBoundBox(obj).Center.sub(obj.Placement.Base))
    if x != 0: obj.Placement.rotate(c, FreeCAD.Vector(1, 0, 0), x)
    if y != 0: obj.Placement.rotate(c, FreeCAD.Vector(0, 1, 0), y)
    if z != 0: obj.Placement.rotate(c, FreeCAD.Vector(0, 0, 1), z)
    return
Example #6
0
 def Activated(self):
     FreeCAD.ActiveDocument.openTransaction(self.__str__())
     if Common.localMode:
         Path = Common.GetSelectedLowerObjectsPath()
         objs = Common.GetSelectedLowerObjects()
         i = objs.__len__() - 2
         if i > 0:
             bb1 = Common.GetBoundBoxFromGlobalCoordinates(Path[i], objs[i])
             bb2 = Common.GetBoundBoxFromGlobalCoordinates(
                 Path[i + 1], objs[i + 1])
             a = (bb2.ZMax - bb1.ZMin) / 2.0 + bb1.ZMin
             j = 0
             while j < i:
                 bb_j = Common.GetBoundBoxFromGlobalCoordinates(
                     Path[j], objs[j])
                 base_j = Common.toGlobalCoordinates(
                     Path[j], objs[j].Placement.Base)
                 base_j.z = base_j.z + a - (bb_j.ZMin +
                                            ((bb_j.ZMax - bb_j.ZMin) / 2.0))
                 objs[j].Placement.Base = Common.toLocalCoordinates(
                     Path[j], base_j)
                 j = j + 1
     else:
         objs = GetSelectedUpperObjects()
         i = objs.__len__() - 2
         if i > 0:
             bb = GetObjectBoundBox(objs[i])
             a = (GetObjectBoundBox(objs[i + 1]).ZMax -
                  bb.ZMin) / 2.0 + bb.ZMin
             j = 0
             while j < i:
                 bb = GetObjectBoundBox(objs[j])
                 objs[j].Placement.Base.z = objs[j].Placement.Base.z + a - (
                     bb.ZMin + ((bb.ZMax - bb.ZMin) / 2.0))
                 j = j + 1
     return