Macro Rotate To Point: Difference between revisions

From FreeCAD Documentation
m (06/04/2019 ver 00.04 : Python 3)
(Marked this version for translation)
Line 945: Line 945:
<translate>
<translate>


<!--T:17-->
06/04/2019 ver 00.04 : Python 3
06/04/2019 ver 00.04 : Python 3



Revision as of 18:44, 6 April 2019

Other languages:

Macro Rotate To Point

Description
Macro for rotate on object on itself with the axis of rotation.
Version 00.04 / 2019-04-06 Download the IconToolBar Macro_Rotate_To_Point

Macro version: 00.04
Last modified: 2019-04-06
Author: Mario52
Author
Mario52
Download
None
Links
Macro Version
00.04
Date last modified
2019-04-06
FreeCAD Version(s)
None
Default shortcut
None
See also
None

Description

Macro for rotate on object on itself with the axis of rotation the boundbox center, center of mass or last point clicked

How To Use

Run the macro and select one object and choice:

Interface Rotate to point

  • Point Rotation
    • Bounbox Center : Select the boundBox center to axis rotation
    • Center of Mass : Select the Center of Mass to axis rotation
    • Point Clicked : Select the last point mouse to axis rotation 1: select the object 2: use the CTRL for choice point extra object
  • Axis Rotation
    • Rotation(Z) Yaw : Yaw axis
    • Rotation(Y) Pitch : Pitch axis
    • Rotation(X) Roll : Roll axis
  • Coordinates Point clicked
    • DoubleSpinBox : Coordinate X on click mouse (modifiable only with the mode "Point Clicked")
    • DoubleSpinBox : Coordinate Y on click mouse (modifiable only with the mode "Point Clicked")
    • DoubleSpinBox : Coordinate Z on click mouse (modifiable only with the mode "Point Clicked")
  • Position : If this checkBox is checked the rotation is disabled, the object placement is done on the axis seleted
  • Point : If this checkBox is checked one point is created for visualise the point rotation axis : red X, green Y, blue Z
  • Line Edit : The line edit display the original coordinate to axis selected + the input data give in the spinBox
  • Free : If this checkBox is checked the Apply is switched ans the rotation or translation is executed in real time
  • DoubleSpinBox : enter the modification
  • Apply : Apply the modification to the object
  • Quit : Quit the macro
  • Original : After modify the data of the object you can return to the original placement, If you have not deselected the current object
  • 0,0,0  : This option place the object in base coordinate 0, 0, 0
  • Reset : Reset the data in the macro and deselect the current object (same click mouse in the 3DView)

Script

The icon for you toolbar PNG SVG

Macro_Rotate_To_Point.FCMacro

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
"""
***************************************************************************
*   Copyright (c) 2017 2018 2019 <mario52>                                *
*                                                                         *
*   This file is a supplement to the FreeCAD CAx development system.      *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU Lesser General Public License (LGPL)    *
*   as published by the Free Software Foundation; either version 2 of     *
*   the License, or (at your option) any later version.                   *
*   for detail see the LICENCE text file.                                 *
*                                                                         *
*   This software is distributed in the hope that it will be useful,      *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU Library General Public License for more details.                  *
*                                                                         *
*   You should have received a copy of the GNU Library General Public     *
*   License along with this macro; if not, write to the Free Software     *
*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
*   USA                                                                   *
***************************************************************************
*           WARNING! All changes in this file will be lost and            *  
*                  may cause malfunction of the program                   *
***************************************************************************
"""
#
#
#OS: Windows 10                                     #OS: Windows 10                                 #OS: Windows 10
#Word size of OS: 64-bit                            #Word size of OS: 64-bit                        #Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit                       #Word size of FreeCAD: 64-bit                   #Word size of FreeCAD: 64-bit
#Version: 0.16.6706 (Git)                           #Version: 0.17.13387 (Git)                      #Version: 0.18.16093 (Git)
#Build type: Release                                #Build type: Release                            #Build type: Release
#Branch: releases/FreeCAD-0-16                      #Branch: master                                 #Branch: releases/FreeCAD-0-18
#Hash: f86a4e411ff7848dea98d7242f43b7774bee8fa0     #Hash: c5f4079252b11e3c54cd603be7d3697fa9f9d922 #Hash: 690774c0effe4fd7b8d2b5e2fb2b8c8d145e21ce
#Python version: 2.7.8                              #Python version: 2.7.14                         #Python version: 3.6.6
#Qt version: 4.8.7                                  #Qt version: 4.8.7                              #Qt version: 5.6.2
#Coin version: 4.0.0a                               #Coin version: 4.0.0a                           #Coin version: 4.0.0a
#OCC version: 6.8.0.oce-0.17                        #OCC version: 7.1.0                             #OCC version: 7.3.0
#
#
__title__   = "Macro_Rotate_To_Point"
__author__  = "Mario52"
__url__     = "http://www.freecadweb.org/index-fr.html"
__Wiki__    = "https://www.freecadweb.org/wiki/Macro_Rotate_To_Point"
__version__ = "00.04"
__date__    = "2019/04/06"  #YYYY/MM/DD
#
import PySide
from PySide import QtGui ,QtCore
from PySide.QtGui import *
from PySide.QtCore import *
 
import Draft, Part, PartGui, FreeCADGui, FreeCAD
from FreeCAD import Base
import DraftVecUtils
import time

Gui = FreeCADGui
App = FreeCAD

global ui            ; ui             = ""
global sourisPass    ; sourisPass     = 0
global positionMouse ; positionMouse  = ""

global originalObject; originalObject = ""
global myObject      ; myObject       = ""
global originalPlacement; originalPlacement = ""
global valeur        ; valeur         = 0.0

global axisX         ; axisX          = 0.0
global axisY         ; axisY          = 0.0
global axisZ         ; axisZ          = 0.0

global posX          ; posX           = 0.0
global posY          ; posY           = 0.0
global posZ          ; posZ           = 0.0

global rotAngleX     ; rotAngleX      = 0.0
global rotAngleY     ; rotAngleY      = 0.0
global rotAngleZ     ; rotAngleZ      = 0.0

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

def errorDialog(msg):
    diag = QtGui.QMessageBox(QtGui.QMessageBox.Critical,u"Error Message",msg )
    diag.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide # cette fonction met la fenetre en avant
    diag.exec_()
        
class Ui_MainWindow(object):
    def __init__(self ):
        self.window = MainWindow
        ################################################
        #self.path  = FreeCAD.ConfigGet("AppHomePath")
        #self.path  = FreeCAD.ConfigGet("UserAppData")
        #self.path  = "your path"
        param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro")# macro path
        self.path = param.GetString("MacroPath","") + "/"                   # macro path
        self.path = self.path.replace("\\","/")
        print("Path for the icons : " , self.path)
        ################################################
        self.vueActive = FreeCADGui.ActiveDocument.ActiveView
        self.click = self.vueActive.addEventCallback("SoMouseButtonEvent",self.souris)

    def souris(self,info):
        global sourisPass
        if (info["Button"] == "BUTTON1") and (info["State"] == "DOWN"):
            time.sleep(0.02)
            sourisPass = 0
            #print("ok")

    def setupUi(self, MainWindow):
        self.window = MainWindow
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(330, 330)
        MainWindow.setMinimumSize(QtCore.QSize(330, 10))
        MainWindow.setMaximumSize(QtCore.QSize(330, 330))
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))

        self.fontGlobal_08 = QtGui.QFont()            # pour compatibilite
        self.fontGlobal_08.setFamily("Arial")         # pour compatibilite
        self.fontGlobal_08.setPointSize(8.0)          # pour compatibilite

        ####
        self.groupBox_Rotation = QtGui.QGroupBox(self.centralwidget)
        self.groupBox_Rotation.setGeometry(QtCore.QRect(20, 20, 121, 91))
        self.groupBox_Rotation.setFont(self.fontGlobal_08)       # 
        self.groupBox_Rotation.setEnabled(False)
        self.groupBox_Rotation.setObjectName(_fromUtf8("groupBox_Rotation"))

        self.RB_Bond_Box_Center = QtGui.QRadioButton(self.groupBox_Rotation)
        self.RB_Bond_Box_Center.setGeometry(QtCore.QRect(10, 20, 111, 17))
        self.RB_Bond_Box_Center.setFont(self.fontGlobal_08)       # 
        self.RB_Bond_Box_Center.setChecked(True)
        self.RB_Bond_Box_Center.setObjectName(_fromUtf8("RB_Bond_Box_Center"))
        self.RB_Bond_Box_Center.setToolTip("Point rotation on BoundBox Center")
        self.RB_Bond_Box_Center.clicked.connect(self.on_RB_CenterRot)

        self.RB_Center_Mass = QtGui.QRadioButton(self.groupBox_Rotation)
        self.RB_Center_Mass.setGeometry(QtCore.QRect(10, 40, 111, 17))
        self.RB_Center_Mass.setFont(self.fontGlobal_08)       # 
        self.RB_Center_Mass.setObjectName(_fromUtf8("RB_Center_Mass"))
        self.RB_Center_Mass.setToolTip("Point rotation on Center Mass")
        self.RB_Center_Mass.clicked.connect(self.on_RB_CenterRot)

        self.RB_Point_Clicked = QtGui.QRadioButton(self.groupBox_Rotation)
        self.RB_Point_Clicked.setGeometry(QtCore.QRect(10, 60, 111, 17))
        self.RB_Point_Clicked.setFont(self.fontGlobal_08)       # 
        self.RB_Point_Clicked.setObjectName(_fromUtf8("RB_Point_Clicked"))
        self.RB_Point_Clicked.setToolTip("Point rotation on Point Mouse clicked on the object"+"\n"
                                         "If twoo points are clicked, the second point is used for axis rotation"+"\n"
                                         "The point axis rotation Can be changed during the work as long as the object is selected"+"\n"
                                         "For this press the CTRL KEY and click the new point rotation")
        self.RB_Point_Clicked.clicked.connect(self.on_RB_CenterRot)

        ####

        self.groupBox_Axis = QtGui.QGroupBox(self.centralwidget)
        self.groupBox_Axis.setGeometry(QtCore.QRect(150, 20, 161, 91))
        self.groupBox_Axis.setFont(self.fontGlobal_08)       # 
        self.groupBox_Axis.setEnabled(False)
        self.groupBox_Axis.setObjectName(_fromUtf8("groupBox_Axis"))

        self.RB_Rotation_0 = QtGui.QRadioButton(self.groupBox_Axis)
        self.RB_Rotation_0.setGeometry(QtCore.QRect(10, 60, 111, 17))
        self.RB_Rotation_0.setFont(self.fontGlobal_08)       # 
        self.RB_Rotation_0.setObjectName(_fromUtf8("RB_Rotation_0"))
        self.RB_Rotation_0.setVisible(False)
#        self.RB_Rotation_0.clicked.connect(self.on_RB_Rotation_0)

        self.RB_Rotation_X = QtGui.QRadioButton(self.groupBox_Axis)
        self.RB_Rotation_X.setGeometry(QtCore.QRect(10, 20, 111, 17))
        self.RB_Rotation_X.setFont(self.fontGlobal_08)       # 
        self.RB_Rotation_X.setChecked(True)
        self.RB_Rotation_X.setObjectName(_fromUtf8("RB_Rotation_X"))
        self.RB_Rotation_X.setToolTip("Rotation on Axis Yaw (Z)")
        self.RB_Rotation_X.clicked.connect(self.on_RB_Rotation_X)

        self.RB_Rotation_Y = QtGui.QRadioButton(self.groupBox_Axis)
        self.RB_Rotation_Y.setGeometry(QtCore.QRect(10, 40, 111, 17))
        self.RB_Rotation_Y.setFont(self.fontGlobal_08)       # 
        self.RB_Rotation_Y.setObjectName(_fromUtf8("RB_Rotation_Y"))
        self.RB_Rotation_Y.setToolTip("Rotation on Axis Pitch (Y)")
        self.RB_Rotation_Y.clicked.connect(self.on_RB_Rotation_Y)

        self.RB_Rotation_Z = QtGui.QRadioButton(self.groupBox_Axis)
        self.RB_Rotation_Z.setGeometry(QtCore.QRect(10, 60, 111, 17))
        self.RB_Rotation_Z.setFont(self.fontGlobal_08)       # 
        self.RB_Rotation_Z.setObjectName(_fromUtf8("RB_Rotation_Z"))
        self.RB_Rotation_Z.setToolTip("Rotation on Axis Roll (X)")
        self.RB_Rotation_Z.clicked.connect(self.on_RB_Rotation_Z)

        ####

        self.groupBox_Pos_Mouse = QtGui.QGroupBox(self.centralwidget)
        self.groupBox_Pos_Mouse.setGeometry(QtCore.QRect(20, 120, 291, 51))
        self.groupBox_Pos_Mouse.setFont(self.fontGlobal_08)       # 
        self.groupBox_Pos_Mouse.setEnabled(False)
        self.groupBox_Pos_Mouse.setObjectName(_fromUtf8("groupBox_Pos_Mouse"))
        self.groupBox_Pos_Mouse.setToolTip("Position click mouse modification possible only with mode Point clicked")

        self.DS_Pos_Mouse_X = QtGui.QDoubleSpinBox(self.groupBox_Pos_Mouse)
        self.DS_Pos_Mouse_X.setGeometry(QtCore.QRect(10,20,82,22))
        self.DS_Pos_Mouse_X.setFont(self.fontGlobal_08)       # 
        self.DS_Pos_Mouse_X.setDecimals(6)
        self.DS_Pos_Mouse_X.setSuffix(" X")
        self.DS_Pos_Mouse_X.setObjectName(_fromUtf8("DS_Pos_Mouse_X"))
        self.DS_Pos_Mouse_X.setToolTip("Position click mouse X" + "\n" +
                                       "modification only with mode Point clicked")
        self.DS_Pos_Mouse_X.valueChanged.connect(self.on_DS_Pos_Mouse_X)

        self.DS_Pos_Mouse_Y = QtGui.QDoubleSpinBox(self.groupBox_Pos_Mouse)
        self.DS_Pos_Mouse_Y.setGeometry(QtCore.QRect(105,20,91,22))
        self.DS_Pos_Mouse_Y.setFont(self.fontGlobal_08)       # 
        self.DS_Pos_Mouse_Y.setDecimals(6)
        self.DS_Pos_Mouse_Y.setSuffix(" Y")
        self.DS_Pos_Mouse_Y.setObjectName(_fromUtf8("DS_Pos_Mouse_Y"))
        self.DS_Pos_Mouse_Y.setToolTip("Position click mouse Y" + "\n" +
                                       "modification only with mode Point clicked")
        self.DS_Pos_Mouse_Y.valueChanged.connect(self.on_DS_Pos_Mouse_Y)

        self.DS_Pos_Mouse_Z = QtGui.QDoubleSpinBox(self.groupBox_Pos_Mouse)
        self.DS_Pos_Mouse_Z.setGeometry(QtCore.QRect(200,20,82,22))
        self.DS_Pos_Mouse_Z.setFont(self.fontGlobal_08)       # 
        self.DS_Pos_Mouse_Z.setDecimals(6)
        self.DS_Pos_Mouse_Z.setSuffix(" Z")
        self.DS_Pos_Mouse_Z.setObjectName(_fromUtf8("DS_Pos_Mouse_Z"))
        self.DS_Pos_Mouse_Z.setToolTip("Position click mouse Z" + "\n" +
                                       "modification only with mode Point clicked")
        self.DS_Pos_Mouse_Z.valueChanged.connect(self.on_DS_Pos_Mouse_Z)

        ####

        self.SC_Slider_Bar = QtGui.QSlider(self.centralwidget)
        self.SC_Slider_Bar.setGeometry(QtCore.QRect(20, 240, 291, 22))
        self.SC_Slider_Bar.setFont(self.fontGlobal_08)       # 
        self.SC_Slider_Bar.setMinimum(-360.0)
        self.SC_Slider_Bar.setMaximum(360.0)
        self.SC_Slider_Bar.setValue(0.0)
        self.SC_Slider_Bar.setSliderPosition(0)
        self.SC_Slider_Bar.setOrientation(QtCore.Qt.Horizontal)
        self.SC_Slider_Bar.setObjectName(_fromUtf8("SC_Slider_Bar"))
        self.SC_Slider_Bar.valueChanged.connect(self.on_SC_Slider_Bar)

        self.LE_Increment = QtGui.QLineEdit(self.centralwidget)
        self.LE_Increment.setGeometry(QtCore.QRect(20,210,121,22))
        self.LE_Increment.setFont(self.fontGlobal_08)       # 
        self.LE_Increment.setObjectName(_fromUtf8("LE_Increment"))
        self.LE_Increment.setToolTip("Display the original Data + the modification")
        self.LE_Increment.setReadOnly(True)
        self.LE_Increment.setText(str(0.0))
        #self.LE_Increment.returnPressed.connect(self.on_LE_Increment_Pressed)
        self.LE_Increment.textChanged.connect(self.on_LE_Increment_Pressed)

        self.DS_Scroll_Bar = QtGui.QDoubleSpinBox(self.centralwidget)
        self.DS_Scroll_Bar.setGeometry(QtCore.QRect(150,210,91,22))
        self.DS_Scroll_Bar.setFont(self.fontGlobal_08)       # 
        self.DS_Scroll_Bar.setMinimum(-360.0)
        self.DS_Scroll_Bar.setMaximum(360.0)
        self.DS_Scroll_Bar.setDecimals(4)
        self.DS_Scroll_Bar.setObjectName(_fromUtf8("DS_Scroll_Bar"))
        self.DS_Scroll_Bar.setToolTip("Enter the modification")
        self.DS_Scroll_Bar.valueChanged.connect(self.on_DS_Scroll_Bar)

        self.PB_Apply = QtGui.QPushButton(self.centralwidget)
        self.PB_Apply.setGeometry(QtCore.QRect(250, 210, 61, 23))
        self.PB_Apply.setFont(self.fontGlobal_08)       # 
        self.PB_Apply.setObjectName(_fromUtf8("PB_Apply"))
        self.PB_Apply.setToolTip("Apply the modification")
        self.PB_Apply.clicked.connect(self.on_PB_Apply_clicked)

        self.CB_Position = QtGui.QCheckBox(self.centralwidget)
        self.CB_Position.setGeometry(QtCore.QRect(20, 180, 71, 17))
        self.CB_Position.setFont(self.fontGlobal_08)       # 
        self.CB_Position.setEnabled(False)
        self.CB_Position.setObjectName(_fromUtf8("CB_Position"))
        self.CB_Position.setToolTip("Move the object to axis choice X, Y or Z")
        self.CB_Position.clicked.connect(self.on_CB_Position)

        self.CB_Point = QtGui.QCheckBox(self.centralwidget)
        self.CB_Point.setGeometry(QtCore.QRect(150, 180, 51, 17))
        self.CB_Point.setFont(self.fontGlobal_08)       # 
        self.CB_Point.setEnabled(False)
        self.CB_Point.setObjectName(_fromUtf8("CB_Point"))
        self.CB_Point.setToolTip("If checked, create one point to visualise the point rotation")
        self.CB_Point.clicked.connect(self.on_CB_Point)

        self.CB_Free = QtGui.QCheckBox(self.centralwidget)
        self.CB_Free.setGeometry(QtCore.QRect(270, 180, 71, 17))
        self.CB_Free.setFont(self.fontGlobal_08)       # 
        self.CB_Free.setEnabled(False)
        self.CB_Free.setObjectName(_fromUtf8("CB_Free"))
        self.CB_Free.setToolTip("This checkBox switch the Application button")
#        self.CB_Free.clicked.connect(self.on_CB_Free)

        self.label_00 = QtGui.QLabel(self.centralwidget)
        self.label_00.setGeometry(QtCore.QRect(22, 261, 291, 16))
        self.label_00.setFont(self.fontGlobal_08)       # 
        self.label_00.setStyleSheet("color : #ffffff; background-color: red; font: bold 10px;")   # white red bold
        #self.label_00.setToolTip("Display the modification Axis and Rotation or Position")
        self.label_00.setObjectName(_fromUtf8("label_00"))

        self.PB_Quit = QtGui.QPushButton(self.centralwidget)
        self.PB_Quit.setGeometry(QtCore.QRect(20, 280, 65, 23))
        self.PB_Quit.setFont(self.fontGlobal_08)       # 
        self.PB_Quit.setObjectName(_fromUtf8("PB_Quit"))
        self.PB_Quit.setToolTip("Quite the macro")
        self.PB_Quit.clicked.connect(self.on_PB_Quit_clicked)

        self.PB_Original = QtGui.QPushButton(self.centralwidget)
        self.PB_Original.setGeometry(QtCore.QRect(95, 280, 65, 23))
        self.PB_Original.setFont(self.fontGlobal_08)       # 
        self.PB_Original.setObjectName(_fromUtf8("PB_Original"))
        self.PB_Original.setToolTip("Move the object to the original position")
        self.PB_Original.clicked.connect(self.on_PB_Original_clicked)

        self.PB_Zero = QtGui.QPushButton(self.centralwidget)
        self.PB_Zero.setGeometry(QtCore.QRect(171, 280, 65, 23))
        self.PB_Zero.setFont(self.fontGlobal_08)       # 
        self.PB_Zero.setObjectName(_fromUtf8("PB_Zero"))
        self.PB_Zero.setToolTip("Move the object to the base coordinates 0, 0, 0")
        self.PB_Zero.clicked.connect(self.on_PB_Zero_clicked)

        self.PB_Reset = QtGui.QPushButton(self.centralwidget)
        self.PB_Reset.setGeometry(QtCore.QRect(247, 280, 65, 23))
        self.PB_Reset.setFont(self.fontGlobal_08)       # 
        self.PB_Reset.setObjectName(_fromUtf8("PB_Reset"))
        self.PB_Reset.setToolTip("Reset the complete data macro")
        self.PB_Reset.clicked.connect(self.on_PB_Reset_clicked)

        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint)                   # this function turns the front window (stay to hint)
        MainWindow.setWindowTitle("Macro_Rotate_To_Point")
        self.groupBox_Axis.setTitle("Axis Rotation")
        self.RB_Rotation_Z.setText("Rotation(X) Roll")
        self.RB_Rotation_Y.setText("Rotation(Y) Pitch")
        self.RB_Rotation_X.setText("Rotation(Z) Yaw")
        self.groupBox_Rotation.setTitle("Point Rotation")
        self.groupBox_Pos_Mouse.setTitle("Coordinates Point clicked")
        self.RB_Center_Mass.setText("Center of Mass")
        self.RB_Point_Clicked.setText("Point clicked")
        self.RB_Bond_Box_Center.setText("Bounbox Center")
        self.CB_Position.setText("Position")
        self.CB_Point.setText("Point")
        self.CB_Free.setText("Free")
        self.PB_Apply.setText("Apply")
        self.PB_Original.setText("Original")
        self.PB_Reset.setText("Reset")
        self.PB_Quit.setText("Quit")
        self.PB_Zero.setText("0,0,0")
        self.label_00.setText(" Select one Object")

    def on_DS_Pos_Mouse_X(self,val):
        global positionMouse
        global axisX
        positionMouse = [val, positionMouse[1], positionMouse[2]]
        axisX = positionMouse[0]
#        print("on_DS_Pos_Mouse_X ", val)

    def on_DS_Pos_Mouse_Y(self,val):
        global positionMouse
        global axisY
        positionMouse = [positionMouse[0], val, positionMouse[2]]
        axisY = positionMouse[1]
#        print("on_DS_Pos_Mouse_Y ", val)

    def on_DS_Pos_Mouse_Z(self,val):
        global positionMouse
        global axisZ
        positionMouse = [positionMouse[0], positionMouse[1], val]
        axisZ = positionMouse[2]
#        print("on_DS_Pos_Mouse_Z ", val)

    def on_SC_Slider_Bar(self,val):
        global ui
        global valeur
        global myObject

        if myObject != "":
            valeur = val
            self.DS_Scroll_Bar.setValue(valeur)
            self.SC_Slider_Bar.setValue(valeur)

            if self.CB_Free.isChecked():
                ff = ui
                ff.on_PB_Apply_clicked()
        else:
            self.DS_Scroll_Bar.setValue(0.0)
            self.SC_Slider_Bar.setValue(0.0)
#        print("on_SC_Scroll_Bar ", valeur)

    def on_DS_Scroll_Bar(self,val):
        global valeur
        global myObject
        global axisX, axisY, axisZ
        global posX, posY, posZ
        global rotAngleX, rotAngleY, rotAngleZ

        if myObject == "":
            self.DS_Scroll_Bar.setValue(0.0)
            self.SC_Slider_Bar.setValue(0.0)
            None
        else:
            valeur = val
            self.SC_Slider_Bar.setValue(valeur)
            if self.CB_Position.isChecked():                 # translate

                if self.RB_Rotation_X.isChecked():
                    posX = valeur
                    posY = posZ = 0.0
                    self.LE_Increment.setText(str(round(myObject.Placement.Base[0],4) + valeur))
                elif self.RB_Rotation_Y.isChecked():
                    posY = valeur
                    posX = posZ = 0.0
                    self.LE_Increment.setText(str(round(myObject.Placement.Base[1],4) + valeur))
                elif self.RB_Rotation_Z.isChecked():
                    posZ = valeur
                    posX = posY = 0.0
                    self.LE_Increment.setText(str(round(myObject.Placement.Base[2],4) + valeur))

                self.label_00.setText("[Pos=(" + str(round(myObject.Placement.Base[0],2))+" , " + 
                                                 str(round(myObject.Placement.Base[1],2))+" , " + 
                                                 str(round(myObject.Placement.Base[2],2))+")] " +
                                      "[Axis=("+ str(round(axisX,2)) + " , " + str(round(axisY,2)) + " , " + str(round(axisZ,2)) + ")]")

            else:                                            # rotation

                if self.RB_Rotation_X.isChecked():
                    rotAngleX = valeur
                    rotAngleY = rotAngleZ = 0.0
                    self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[0],4) + valeur))
                elif self.RB_Rotation_Y.isChecked():
                    rotAngleY = valeur
                    rotAngleZ = rotAngleX = 0.0
                    self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[1],4) + valeur))
                elif self.RB_Rotation_Z.isChecked():
                    rotAngleZ = valeur
                    rotAngleX = rotAngleY = 0.0
                    self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[2],4) + valeur))

#                self.label_00.setText("[Rot=(" + str(round(rotAngleX,2)) + " , " + str(round(rotAngleY,2)) + " , " + str(round(rotAngleZ,2)) + ")] " +
#                                      "[Axis=("+ str(round(axisX,2)) + " , " + str(round(axisY,2)) + " , " + str(round(axisZ,2)) + ")]")
#        print("on_DS_Scroll_Bar ", valeur)

    def on_LE_Increment_Pressed(self,text):
        None
#        print("on_lineEdit_1_Pressed")

    def on_PB_Apply_clicked(self):
        global valeur
        global myObject
        global positionMouse
        global originalPlacement
        global originalObject

        global axisX, axisY, axisZ
        global posX, posY, posZ
        global rotAngleX, rotAngleY, rotAngleZ

        if (myObject == "") :
            self.label_00.setStyleSheet("color : #ffffff; background-color: red; font: bold 10px;")   # white red bold
            self.label_00.setText(" Select one Object")
            FreeCAD.Console.PrintError("Select one Object" + "\n")
        else:
            if self.CB_Position.isChecked():                 # translate

                myObject.Placement = App.Placement(App.Vector(posX, posY, posZ), App.Rotation(0.0,0.0,0.0), App.Vector(0.0,0.0,0.0)).multiply(App.ActiveDocument.getObject(myObject.Name).Placement)

                if self.RB_Rotation_X.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Base[0],4)))
                elif self.RB_Rotation_Y.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Base[1],4)))
                elif self.RB_Rotation_Z.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Base[2],4)))

                self.label_00.setText("[Pos=(" + str(round(myObject.Placement.Base[0],2))+" , " + 
                                                 str(round(myObject.Placement.Base[1],2))+" , " + 
                                                 str(round(myObject.Placement.Base[2],2))+")] " +
                                      "[Axis=("+ str(round(axisX,2)) + " , " + str(round(axisY,2)) + " , " + str(round(axisZ,2)) + ")]")

            else:                                            # rotation

                myObject.Placement = App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(rotAngleX, rotAngleY, rotAngleZ), App.Vector(axisX, axisY, axisZ)).multiply(App.ActiveDocument.getObject(myObject.Name).Placement)

                if self.RB_Rotation_X.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[0],4)))
                elif self.RB_Rotation_Y.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[1],4)))
                elif self.RB_Rotation_Z.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[2],4)))

                self.label_00.setText("[Rot=(" + str(round(myObject.Placement.Rotation.toEuler()[0],2)) + " , " +
                                                 str(round(myObject.Placement.Rotation.toEuler()[1],2)) + " , " + 
                                                 str(round(myObject.Placement.Rotation.toEuler()[2],2)) + ")] " +
                                      "[Axis=("+ str(round(axisX,2))+" , "+ str(round(axisY,2))+" , "+ str(round(axisZ,2))+")]")
       
#            FreeCAD.ActiveDocument.recompute()
#        print("on_PB_Apply_clicked")

    def on_RB_Rotation_0(self):
        None
#        print("on_RB_Rotation_0")

    def on_RB_Rotation_X(self):
        global myObject
        if self.CB_Position.isChecked():              
            self.LE_Increment.setText(str(round(myObject.Placement.Base[0],4)))                  # pos X
        else:
            self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[0],4)))    # yaw = Z
        self.DS_Scroll_Bar.setValue(0.0)
#        print("on_RB_Rotation_X")

    def on_RB_Rotation_Y(self):
        global myObject
        if self.CB_Position.isChecked():              
            self.LE_Increment.setText(str(round(myObject.Placement.Base[1],4)))                  # pos Y
        else:
            self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[1],4)))    # pitch= Y
        self.DS_Scroll_Bar.setValue(0.0)
#        print("on_RB_Rotation_Y")

    def on_RB_Rotation_Z(self):
        global myObject
        if self.CB_Position.isChecked():              
            self.LE_Increment.setText(str(round(myObject.Placement.Base[2],4)))                  #  pos Z
        else:
            self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[2],4)))    # roll = X
        self.DS_Scroll_Bar.setValue(0.0)
#        print("on_RB_Rotation_Z")

    def on_RB_CenterRot(self):                                # zero
        global myObject
        global positionMouse
        global axisX, axisY, axisZ
        
        try:
            self.groupBox_Pos_Mouse.setEnabled(False)
            if self.RB_Bond_Box_Center.isChecked():           # axis
                axisX = myObject.Shape.BoundBox.Center.x 
                axisY = myObject.Shape.BoundBox.Center.y
                axisZ = myObject.Shape.BoundBox.Center.z
                if self.CB_Point.isChecked():
                    point = Draft.makePoint(myObject.Shape.BoundBox.Center.x, myObject.Shape.BoundBox.Center.y, myObject.Shape.BoundBox.Center.z)
                    point.ViewObject.PointColor = (1.0,0.0,0.0)
                    point.Label = "Point_BoundBox_Center"

            elif self.RB_Center_Mass.isChecked():
                axisX = myObject.Shape.CenterOfMass.x
                axisY = myObject.Shape.CenterOfMass.y
                axisZ = myObject.Shape.CenterOfMass.z
                if self.CB_Point.isChecked():
                    point = Draft.makePoint(myObject.Shape.CenterOfMass.x, myObject.Shape.CenterOfMass.y, myObject.Shape.CenterOfMass.z)
                    point.ViewObject.PointColor = (0.0,1.0,0.0)
                    point.Label = "Point_CenterOfMass"
    
            elif self.RB_Point_Clicked.isChecked():
                axisX = positionMouse[0]
                axisY = positionMouse[1]
                axisZ = positionMouse[2]
                self.groupBox_Pos_Mouse.setEnabled(True)

                if self.CB_Point.isChecked():
                    point = Draft.makePoint(positionMouse[0], positionMouse[1], positionMouse[2])
                    point.ViewObject.PointColor = (0.0,0.0,1.0)
                    point.Label = "Point_positionMouse"

        except Exception:
            self.label_00.setText("Error CenterRot_0")
            FreeCAD.Console.PrintError("Error CenterRot_0" + "\n" + "or Bad selection" + "\n")
#        print("on_RB_CenterRot")

    def on_CB_Position(self):
        global myObject
        global posX, posY, posZ
        global axisX, axisY, axisZ

        if self.CB_Position.isChecked():              
            self.groupBox_Rotation.setEnabled(False)
            self.RB_Bond_Box_Center.setChecked(True)
            self.SC_Slider_Bar.setMinimum(-1000)
            self.SC_Slider_Bar.setMaximum(1000)
            self.DS_Scroll_Bar.setMinimum(-1000)
            self.DS_Scroll_Bar.setMaximum(1000)

            self.groupBox_Axis.setTitle("Axis Direction")
            self.RB_Rotation_Z.setText("Direction Z ")          # translate
            self.RB_Rotation_Y.setText("Direction Y ")
            self.RB_Rotation_X.setText("Direction X ")

            try:
                self.label_00.setText("[Pos=(" + str(round(myObject.Placement.Base[0],2)) + " , " + 
                                                 str(round(myObject.Placement.Base[1],2)) + " , " + 
                                                 str(round(myObject.Placement.Base[2],2)) + ")] " +
                                      "[Axis=("+ str(round(axisX,2)) + " , " + str(round(axisY,2)) + " , " + str(round(axisZ,2)) + ")]")
                if self.RB_Rotation_X.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Base[0],4)))
                elif self.RB_Rotation_Y.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Base[1],4)))
                elif self.RB_Rotation_Z.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Base[2],4)))
            except Exception:
                self.label_00.setText("Error Position_0")
                FreeCAD.Console.PrintError("Error Position_0" + "\n" + "or Bad selection" + "\n")
        else:
            self.groupBox_Rotation.setEnabled(True)
            self.SC_Slider_Bar.setMinimum(-360)
            self.SC_Slider_Bar.setMaximum(360)
            self.DS_Scroll_Bar.setMinimum(-360)
            self.DS_Scroll_Bar.setMaximum(360)

            self.groupBox_Axis.setTitle("Axis Rotation")
            self.RB_Rotation_Z.setText("Rotation(X) Roll")      # rotation
            self.RB_Rotation_Y.setText("Rotation(Y) Pitch")
            self.RB_Rotation_X.setText("Rotation(Z) Yaw")

            try:
                self.label_00.setText("[Rot=(" + str(round(myObject.Placement.Rotation.toEuler()[0],2)) + " , " +
                                                 str(round(myObject.Placement.Rotation.toEuler()[1],2)) + " , " + 
                                                 str(round(myObject.Placement.Rotation.toEuler()[2],2)) + ")] " +
                                      "[Axis=("+str(round(axisX,2))+" , "+ str(round(axisY,2))+" , "+ str(round(axisZ,2))+")]")
                if self.RB_Rotation_X.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[0],4)))
                elif self.RB_Rotation_Y.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[1],4)))
                elif self.RB_Rotation_Z.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[2],4)))
            except Exception:
                self.label_00.setText("Error Position_1")
                FreeCAD.Console.PrintError("Error Position_0" + "\n" + "or Bad selection" + "\n")

        self.DS_Scroll_Bar.setValue(0.0)
#        print("on_CB_Position")

    def on_CB_Point(self):
        global ui
        ff = ui
        ff.on_RB_CenterRot()
#        print("on_CB_Point")

    def on_PB_Zero_clicked(self):
        global myObject

        if (myObject != ""):
            try:
               # pl = App.Placement(App.Vector(10.0,10.0,10.0), App.Rotation(0.0, 0.0, 0.0), App.Vector(0.0, 0.0, 0.0))
                pl = App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(0.0, 0.0, 0.0), App.Vector(0.0, 0.0, 0.0))
    
                myObject.Placement = pl
#                FreeCAD.ActiveDocument.recompute()
            
                if self.RB_Rotation_X.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[0],4)))
                elif self.RB_Rotation_Y.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[1],4)))
                elif self.RB_Rotation_Z.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[2],4)))
            
                self.label_00.setText("[Rot=(" +str(round(myObject.Placement.Rotation.toEuler()[0],2))+" , "+str(round(myObject.Placement.Rotation.toEuler()[1],2))+" , "+ str(round(myObject.Placement.Rotation.toEuler()[2],2))+")] "+
                                      "[Axis=("+str(round(myObject.Placement.Base.x,2))+" , "+ str(round(myObject.Placement.Base.y,2))+" , "+ str(round(myObject.Placement.Base.z,2))+")]")
                
                self.DS_Scroll_Bar.setValue(0.0)
                self.LE_Increment.setText(str(0.0))
            
#                FreeCAD.ActiveDocument.recompute()
                Gui.activeDocument().activeView().viewTop()
                Gui.SendMsgToActiveView("ViewFit")
    
            except Exception:
                self.label_00.setText("Error Zero_0")
                FreeCAD.Console.PrintError("Error Zero_0" + "\n" + "or Bad selection" + "\n")
        else:
            self.label_00.setStyleSheet("color : #ffffff; background-color: red; font: bold 10px;")   # white red bold
            self.label_00.setText(" Select one Object")
            FreeCAD.Console.PrintError("Select one Object" + "\n")
#        print("on_PB_Zero_clicked")

    def on_PB_Original_clicked(self):
        global ui
        global myObject
        global originalPlacement
        global axisX, axisY, axisZ
        global rotAngleX, rotAngleY, rotAngleZ

        if (myObject != ""):
            try:
                rotAngleX  = rotAngleY = rotAngleZ = 0.0
                myObject.Placement     = originalPlacement
                self.DS_Scroll_Bar.setValue(0.0)
            
                if self.RB_Rotation_X.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[0],4)))    # yaw Z
                elif self.RB_Rotation_Y.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[1],4)))    # pitch Y
                elif self.RB_Rotation_Z.isChecked():
                    self.LE_Increment.setText(str(round(myObject.Placement.Rotation.toEuler()[2],4)))    # roll Z
            
                ff = ui
                ff.on_RB_CenterRot()
            
                self.label_00.setText("[Rot=(" +str(round(myObject.Placement.Rotation.toEuler()[0],2))+" , "+str(round(myObject.Placement.Rotation.toEuler()[1],2))+" , "+ str(round(myObject.Placement.Rotation.toEuler()[2],2))+")] "+
                                      "[Axis=("+str(round(axisX,2))+" , "+ str(round(axisY,2))+" , "+ str(round(axisZ,2))+")]")
#                FreeCAD.ActiveDocument.recompute()
            except Exception:
                self.label_00.setText("Error Original_0")
                FreeCAD.Console.PrintError("Error Original_0" + "\n" + "or Bad selection" + "\n")
        else:
            self.label_00.setStyleSheet("color : #ffffff; background-color: red; font: bold 10px;")   # white red bold
            self.label_00.setText(" Select one Object")
            FreeCAD.Console.PrintError("Select one Object" + "\n")

#        print("on_PB_Original_clicked")

    def on_PB_Reset_clicked(self):
        global originalObject
        global myObject
        
        global valeur
        global posX, posY, posZ
        global rotAngleX, rotAngleY, rotAngleZ
        global axisX, axisY, axisZ

        try:
            for obj in FreeCAD.ActiveDocument.Objects:         # deslectionne
                FreeCADGui.Selection.removeSelection(obj)
        except Exception:
            None

        originalObject = myObject = ""
        posX = posY = posZ = rotAngleX = rotAngleY = rotAngleZ = 0.0
        axisX = axisY = axisZ = 0.0
        valeur  = 0.0

        self.DS_Scroll_Bar.setValue(0.0)
        self.LE_Increment.setText(str(0.0))

        self.groupBox_Axis.setTitle("Axis Rotation")
        self.RB_Rotation_Z.setText("Rotation(X) Roll")
        self.RB_Rotation_Y.setText("Rotation(Y) Pitch")
        self.RB_Rotation_X.setText("Rotation(Z) Yaw")

        self.groupBox_Rotation.setEnabled(False)
        self.groupBox_Axis.setEnabled(False)
        self.groupBox_Pos_Mouse.setEnabled(False)

        self.DS_Pos_Mouse_X.setValue(0.0)
        self.DS_Pos_Mouse_Y.setValue(0.0)
        self.DS_Pos_Mouse_Z.setValue(0.0)

        self.CB_Position.setEnabled(False)
        self.CB_Position.setChecked(False)
        self.CB_Point.setEnabled(False)
        self.CB_Point.setChecked(False)
        self.CB_Free.setEnabled(False)
        self.CB_Free.setChecked(False)

        self.label_00.setStyleSheet("color : #ffffff; background-color: red; font: bold 10px;")   # white red bold
        self.label_00.setText(" Select one Object")
        FreeCAD.Console.PrintError("Select one Object" + "\n")
        FreeCAD.Console.PrintMessage("Reset" + "\n")

    def on_PB_Quit_clicked(self):
        self.vueActive.removeEventCallback("SoMouseButtonEvent",self.click) # desinstalle la fonction souris
        FreeCADGui.Selection.removeObserver(s)                              # desinstalle la fonction residente
        self.window.hide()                                                  # hide the window and close the macro
        FreeCAD.Console.PrintMessage("Quit Rotate_To_Point" + "\n")

###################################################################################################
class SelObserver:
    def addSelection(self, document, object, element, position):  # Selection
        global ui
        global sourisPass
        
        global positionMouse
        global originalObject
        global myObject
        global originalPlacement

        global posX, posY, posZ
        global rotAngleX, rotAngleY, rotAngleZ
        global axisX, axisY, axisZ

        if sourisPass == 0:                                                                  # pour un seul passage
            sourisPass == 1

            sel = FreeCADGui.Selection.getSelection()[0]                                     # select object with getSelection()
            
            positionMouse     = position
            originalObject    = myObject = sel   
            originalPlacement = sel.Shape.Placement

            #longueur = (myObject.Shape.BoundBox.XLength * 0.5)                              # pour Axis
            positionBase = originalObject.Shape.Placement.Base                               # Placement Vector XYZ
    
            posX = positionBase.x
            posY = positionBase.y
            posZ = positionBase.z
    
            Yaw   = originalObject.Shape.Placement.Rotation.toEuler()[0]                     # decode angle Euler Yaw
            Pitch = originalObject.Shape.Placement.Rotation.toEuler()[1]                     # decode angle Euler Pitch
            Roll  = originalObject.Shape.Placement.Rotation.toEuler()[2]                     # decode angle Euler Roll
            
            rotAngleX = Yaw
            rotAngleY = Pitch
            rotAngleZ = Roll
            axisX = axisY = axisZ = 0.0

            ff = ui
            ff.DS_Pos_Mouse_X.setValue(positionMouse[0])
            ff.DS_Pos_Mouse_Y.setValue(positionMouse[1])
            ff.DS_Pos_Mouse_Z.setValue(positionMouse[2])

            ff.on_RB_CenterRot()
            ff.groupBox_Rotation.setEnabled(True)
            ff.groupBox_Axis.setEnabled(True)
            #ff.groupBox_Pos_Mouse.setEnabled(True)
            ff.CB_Position.setEnabled(True)
            ff.CB_Point.setEnabled(True)
            ff.CB_Free.setEnabled(True)
            ff.label_00.setStyleSheet("Base")                                                # origin system
            ff.label_00.setText("[Rot =(" + str(round(rotAngleX,2))+ " , " + str(round(rotAngleY,2)) + " , " + str(round(rotAngleZ,2)) + ")] " +
                                "[Axis=("+ str(round(axisX,2)) + " , " + str(round(axisY,2)) + " , " + str(round(axisZ,2)) + ")]")

    def clearSelection(self,doc):                                                            # Si clic sur l'ecran, effacer la selection
        global ui
        ff = ui
        ff.on_PB_Reset_clicked()

###################################################################################################

doc = FreeCAD.ActiveDocument
if doc == None:
    doc = FreeCAD.newDocument()

try:
    for obj in FreeCAD.ActiveDocument.Objects:         # deslectionne
        FreeCADGui.Selection.removeSelection(obj)
except Exception:
    None

s=SelObserver()
FreeCADGui.Selection.addObserver(s)                    # installe la fonction en mode resident

MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()

Example:

Links

The forum feature req: placement - rotate part around its midpoint My macro to Gist mario52a

Version

06/04/2019 ver 00.04 : Python 3

29/03/2018 ver 00.03 : comment the "FreeCAD.ActiveDocument.recompute()" the change value are too slow with complex element in FreeCAD 0.17.... see FC0.17 recompute strange behaviour (regression)

27/03/2017 ver 00.02 : modify the spinbox "Pos" now accept the negative values

05/03/2017 ver 00.01 : add 3 spinbox for displayed the coordinates X Y Z on click mouse

04/03/2017 ver 00.00