Macro Rotate To Point
Description |
---|
La version mise à jour de la macro a modifié l'interface graphique pour améliorer la prise en charge HiDPI (QGridLayout). Exécutez uniquement FC v0.18 ou supérieur (prenant en charge Qt5 et PySide2) Macro pour faire tourner un objet sur lui-même avec l'axe de rotation: centre de la boîte, centre de masse, direction du fil, ou dernier point cliqué. Pour la version précédente (Qt4) voir Macro_Rotate_To_Point Macro_Rotate_To_Point et installez la manuellement. |
Auteur |
Mario52 |
Téléchargement |
ToolBar Icon |
Liens |
Page des macros Comment installer une macro Comment créer une barre d'outils |
Version Macro |
00.05.2 |
Dernière modification |
2020/03/07 |
Version(s) FreeCAD |
0.18+ |
Raccourci clavier |
None |
Voir aussi |
None |
Description
Macro pour faire pivoter un objet sur lui-même, l'axe de rotation étant soit:
- centre boundbox
- le centre de masse
- direction du fil
- dernier point cliqué
Utilisation
- Téléchargez la macro depuis le gestionnaire d'extensions
- Exécuter la macro
- Sélectionnez un objet
- Choisissez l'une des orientations suivantes:
- Rotation des points
- Boundbox Center: Sélectionnez la rotation du centre BoundBox à l'axe
- Center of Mass: sélectionnez la rotation du centre de masse à l'axe
- Point Clicked: Sélectionnez le dernier clic de souris comme point de rotation de l'axe
- 1: sélectionnez l'objet
- 2: utilisez la touche CTRL pour choisir un objet supplémentaire
- Rotation de l'axe
- Rotation (Z) Lacet: axe de lacet
- Rotation (Y) Pas: Axe de pas
- Rotation (X) Roll: Axe de roulis
- Point de coordonnées cliqué
- DoubleSpinBox: Coordonnez X au clic de la souris (modifiable uniquement avec le mode "Point Clicked")
- DoubleSpinBox: Coordonnez Y au clic de la souris (modifiable uniquement avec le mode "Point Clicked")
- DoubleSpinBox: Coordonner Z au clic de souris (modifiable uniquement avec le mode "Point Clicked")
- Position: Si cette case à cocher est cochée, la rotation est désactivée, le placement de l'objet se fait sur l'axe sélectionné.
- Point: Si cette case à cocher est cochée, un point est créé pour visualiser l'axe de rotation des points: rouge X, vert Y, bleu Z
- Line edit: L'édition de ligne affiche les coordonnées d'origine de l'axe sélectionné + les données d'entrée données dans la spinBox
- Free: Si cette case à cocher est cochée, la Apply est commutée et la rotation ou la traduction est exécutée en temps réel
- DoubleSpinBox: entrez la modification
- Apply: Appliquer la modification à l'objet
- Quit: quitter la macro
- Original: Après avoir modifié les données de l'objet, vous pouvez revenir à l'emplacement d'origine, si vous n'avez pas désélectionné l'objet actuel.
- 0,0,0: cette option place l'objet en coordonnées de base
0,0,0
- Reset: Réinitialisez les données dans la macro et désélectionnez l'objet actuel (même clic de souris dans la vue 3D)
Script
Macro_Rotate_To_Point.FCMacro
# -*- coding: utf-8 -*- from __future__ import unicode_literals """ *************************************************************************** * Copyright (c) 2017 2018 2019 2020 <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. * ** ** * Use at your own risk. The author assumes no liability for data loss. * * It is advised to backup your data frequently. * * If you do not trust the software do not use it. * ** ** * * * 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 (10.0) #Word size of OS: 64-bit #Word size of FreeCAD: 64-bit #Version: 0.19.19697 (Git) #Build type: Release #Branch: master #Hash: 8832356802011bf5d70e9d6f0efa89c47bc70a91 #Python version: 3.6.8 #Qt version: 5.12.1 #Coin version: 4.0.0a #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.05.2" __date__ = "2020/03/07" #YYYY/MM/DD # #### Test FreeCAD.Version above 0.17 BEGIN ########################################################################################################## import WebGui #WebGui.openBrowser("http://www.freecadweb.org/") try: import PySide from PySide import QtGui import sys, os def errorDialog(msg): diag = QtGui.QMessageBox(QtGui.QMessageBox.Critical,u"Error FreeCAD Version",msg ) diag.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide #cette fonction met la fenetre en avant diag.setStyleSheet("QLabel {color : #ffffff; background-color : #FF3300; font: bold}") FreeCAD.Console.PrintMessage("If you have not redirect to the FreeCAD Web page (with header):" + "\n\n") FreeCAD.Console.PrintError("* Copyright (c) 2017 2018 2019 <mario52> *" + "\n\n") FreeCAD.Console.PrintMessage("Copy and paste this link in your Browser:" + "\n\n") FreeCAD.Console.PrintMessage("https://gist.githubusercontent.com/mario52a/2fc48333deca5a31e6232c29a9db5e4c/raw/9231d5b1d218357305cc0404e46bf6c107509a0e/Macro%2520Rotate%2520To%2520Point.FCMacro" + "\n\n") #WebGui.openBrowser("https://www.freecadweb.org/wiki/How_to_install_macros") WebGui.openBrowser("https://gist.githubusercontent.com/mario52a/2fc48333deca5a31e6232c29a9db5e4c/raw/9231d5b1d218357305cc0404e46bf6c107509a0e/Macro%2520Rotate%2520To%2520Point.FCMacro" + "\n\n") diag.exec_() diag.setStyleSheet("Base") Gui.runCommand('Std_DlgMacroExecute',0) quit("None") if int(FreeCAD.Version()[1]) < 18: # Version de FreeCAD memo = PySide.QtGui.QClipboard() memo.setText(__title__) errorDialog("This version " + __title__ + " rmu work with the FreeCAD 0.18 or higher. " + "\n" "PySide2 Qt version: 5" + "\n\n" "This title name " + __title__ + " is copied in memory" + "\n" "Quit this window, the macro editor is open automatically." + "\n\n" "Click the Create button and paste the title name memorized in the dialog window." + "\n\n" "Copy the code of the page in your FreeCAD browser open and paste it in the macro page." + "\n\n" "or see the page:" + "\n\n" "[https://gist.githubusercontent.com/mario52a/2fc48333deca5a31e6232c29a9db5e4c/raw/9231d5b1d218357305cc0404e46bf6c107509a0e/Macro%2520Rotate%2520To%2520Point.FCMacro]" + "\n") except Exception: None #### Test FreeCAD.Version above 0.17 END ############################################################################################################ import PySide2 from PySide2 import (QtWidgets, QtCore, QtGui) from PySide2.QtWidgets import (QWidget, QApplication, QSlider, QGraphicsView, QGraphicsScene, QVBoxLayout, QStyle) from PySide2.QtGui import (QPainter, QColor, QIcon) from PySide2.QtSvg 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 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(360, 300) # MainWindow.setMinimumSize(QtCore.QSize(330, 10)) # MainWindow.setMaximumSize(QtCore.QSize(330, 330)) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName(_fromUtf8("centralwidget")) #### self.groupBox_Rotation = QtWidgets.QGroupBox(self.centralwidget) self.groupBox_Rotation.setEnabled(False) self.RB_Bond_Box_Center = QtWidgets.QRadioButton() self.RB_Bond_Box_Center.setChecked(True) self.RB_Bond_Box_Center.clicked.connect(self.on_RB_CenterRot) self.RB_Center_Mass = QtWidgets.QRadioButton() self.RB_Center_Mass.clicked.connect(self.on_RB_CenterRot) self.RB_Point_Clicked = QtWidgets.QRadioButton() self.RB_Point_Clicked.clicked.connect(self.on_RB_CenterRot) #### self.groupBox_Axis = QtWidgets.QGroupBox() self.groupBox_Axis.setEnabled(False) self.RB_Rotation_0 = QtWidgets.QRadioButton() self.RB_Rotation_0.setVisible(False) # self.RB_Rotation_0.clicked.connect(self.on_RB_Rotation_0) self.RB_Rotation_X = QtWidgets.QRadioButton() self.RB_Rotation_X.setChecked(True) self.RB_Rotation_X.clicked.connect(self.on_RB_Rotation_X) self.RB_Rotation_Y = QtWidgets.QRadioButton() self.RB_Rotation_Y.clicked.connect(self.on_RB_Rotation_Y) self.RB_Rotation_Z = QtWidgets.QRadioButton() self.RB_Rotation_Z.clicked.connect(self.on_RB_Rotation_Z) self.RB_Direction_D = QtWidgets.QRadioButton() self.RB_Direction_D.clicked.connect(self.on_RB_Direction_D) #### self.groupBox_Pos_Mouse = QtWidgets.QGroupBox() self.groupBox_Pos_Mouse.setEnabled(False) self.DS_Pos_Mouse_X = QtWidgets.QDoubleSpinBox() self.DS_Pos_Mouse_X.setDecimals(6) self.DS_Pos_Mouse_X.setSuffix(" X") self.DS_Pos_Mouse_X.valueChanged.connect(self.on_DS_Pos_Mouse_X) self.DS_Pos_Mouse_Y = QtWidgets.QDoubleSpinBox() self.DS_Pos_Mouse_Y.setDecimals(6) self.DS_Pos_Mouse_Y.setSuffix(" Y") self.DS_Pos_Mouse_Y.valueChanged.connect(self.on_DS_Pos_Mouse_Y) self.DS_Pos_Mouse_Z = QtWidgets.QDoubleSpinBox() self.DS_Pos_Mouse_Z.setDecimals(6) self.DS_Pos_Mouse_Z.setSuffix(" Z") self.DS_Pos_Mouse_Z.valueChanged.connect(self.on_DS_Pos_Mouse_Z) #### self.SC_Slider_Bar = QtWidgets.QSlider() 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.valueChanged.connect(self.on_SC_Slider_Bar) self.LE_Increment = QtWidgets.QLineEdit() 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 = QtWidgets.QDoubleSpinBox() self.DS_Scroll_Bar.setMinimum(-360.0) self.DS_Scroll_Bar.setMaximum(360.0) self.DS_Scroll_Bar.setDecimals(4) self.DS_Scroll_Bar.valueChanged.connect(self.on_DS_Scroll_Bar) self.PB_Apply = QtWidgets.QPushButton() self.PB_Apply.clicked.connect(self.on_PB_Apply_clicked) self.CB_Position = QtWidgets.QCheckBox() self.CB_Position.setEnabled(False) self.CB_Position.clicked.connect(self.on_CB_Position) # self.CB_Point = QtWidgets.QCheckBox() # self.CB_Point.setEnabled(False) # self.CB_Point.clicked.connect(self.on_CB_Point) self.PB_Point = QtWidgets.QPushButton() self.PB_Point.setEnabled(False) self.PB_Point.clicked.connect(self.on_CB_Point) self.CB_Free = QtWidgets.QCheckBox() self.CB_Free.setEnabled(False) # self.CB_Free.clicked.connect(self.on_CB_Free) self.label_00 = QtWidgets.QLabel() 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.PB_Quit = QtWidgets.QPushButton() self.PB_Quit.clicked.connect(self.on_PB_Quit_clicked) self.PB_Original = QtWidgets.QPushButton() self.PB_Original.clicked.connect(self.on_PB_Original_clicked) self.PB_Zero = QtWidgets.QPushButton() self.PB_Zero.clicked.connect(self.on_PB_Zero_clicked) self.PB_Reset = QtWidgets.QPushButton() self.PB_Reset.clicked.connect(self.on_PB_Reset_clicked) #### Gridlayout Header self.gridLayoutWidget = QtWidgets.QWidget(self.centralwidget) self.gridLayout_00_00 = QtWidgets.QGridLayout(self.centralwidget) self.gridLayout_00_00.setContentsMargins(10, 10, 10, 10)#Gauche Haut Droit Bas #### Gridlayout Header #### Gridlayout BEGIN self.grid_00_01 = QtWidgets.QGridLayout() # self.gridLayoutWidget_3 = QtWidgets.QWidget(self.groupBox_Rotation) self.grid_00_01.addWidget(self.groupBox_Rotation, 0, 0, 1, 1) self.grid_00_01.setContentsMargins(0, 0, 0, 0) #Gauche Haut Droite Bas self.grid_00_01_00 = QtWidgets.QGridLayout(self.groupBox_Rotation) self.grid_00_01_00.setContentsMargins(10, 10, 0, 10) self.grid_00_01_00.addWidget(self.RB_Bond_Box_Center, 0, 0, 1, 1) self.grid_00_01_00.addWidget(self.RB_Center_Mass, 1, 0, 1, 1) self.grid_00_01_00.addWidget(self.RB_Point_Clicked, 2, 0, 1, 1) self.gridLayout_00_00.addLayout(self.grid_00_01, 0, 0, 1, 1) #### self.grid_00_02 = QtWidgets.QGridLayout() self.grid_00_02.addWidget(self.groupBox_Axis, 0, 0, 1, 1) self.grid_00_02.setContentsMargins(0, 0, 0, 0) self.grid_00_02_00 = QtWidgets.QGridLayout(self.groupBox_Axis) self.grid_00_02_00.setContentsMargins(10, 10, 0, 10) self.grid_00_02_00.addWidget(self.RB_Rotation_X, 0, 0, 1, 1) self.grid_00_02_00.addWidget(self.RB_Rotation_Y, 1, 0, 1, 1) self.grid_00_02_00.addWidget(self.RB_Rotation_Z, 2, 0, 1, 1) self.grid_00_02_00.addWidget(self.RB_Direction_D, 3, 0, 1, 1) self.gridLayout_00_00.addLayout(self.grid_00_02, 0, 1, 1, 1) #### self.grid_00_03 = QtWidgets.QGridLayout() self.grid_00_03.addWidget(self.groupBox_Pos_Mouse, 2, 0, 1, 1) self.grid_00_03.setContentsMargins(0, 0, 0, 0) self.grid_00_03_00 = QtWidgets.QGridLayout(self.groupBox_Pos_Mouse) self.grid_00_03_00.setContentsMargins(10, 10, 10, 10) self.grid_00_03_00.addWidget(self.DS_Pos_Mouse_X, 0, 0, 1, 1) self.grid_00_03_00.addWidget(self.DS_Pos_Mouse_Y, 0, 1, 1, 1) self.grid_00_03_00.addWidget(self.DS_Pos_Mouse_Z, 0, 2, 1, 1) self.gridLayout_00_00.addLayout(self.grid_00_03, 1, 0, 1, 2) #### self.grid_00_04 = QtWidgets.QGridLayout() self.grid_00_04.setContentsMargins(0, 10, 0, 0) self.grid_00_04.addWidget(self.CB_Position, 0, 0, 1, 1) # self.grid_00_04.addWidget(self.CB_Point, 0, 1, 1, 1) self.grid_00_04.addWidget(self.PB_Point, 0, 1, 1, 1) self.grid_00_04.addWidget(self.CB_Free, 0, 2, 1, 1) self.gridLayout_00_00.addLayout(self.grid_00_04, 2, 0, 1, 2) #### self.grid_00_05 = QtWidgets.QGridLayout() self.grid_00_05.setContentsMargins(0, 10, 0, 0) self.grid_00_05.addWidget(self.LE_Increment, 0, 0, 1, 1) self.grid_00_05.addWidget(self.DS_Scroll_Bar, 0, 1, 1, 1) self.grid_00_05.addWidget(self.PB_Apply, 0, 2, 1, 1) self.gridLayout_00_00.addLayout(self.grid_00_05, 3, 0, 1, 2) #### self.grid_00_06 = QtWidgets.QGridLayout() self.grid_00_06.setContentsMargins(0, 0, 0, 0) self.grid_00_06.addWidget(self.SC_Slider_Bar, 0, 0, 1, 1) self.gridLayout_00_00.addLayout(self.grid_00_06, 4, 0, 1, 2) #### self.grid_00_07 = QtWidgets.QGridLayout() self.grid_00_07.setContentsMargins(0, 0, 0, 0) self.grid_00_07.addWidget(self.label_00, 0, 0, 1, 1) self.gridLayout_00_00.addLayout(self.grid_00_07, 5, 0, 1, 2) #### self.grid_00_08 = QtWidgets.QGridLayout() self.grid_00_08.setContentsMargins(0, 0, 0, 0) self.grid_00_08.addWidget(self.PB_Quit, 0, 0, 1, 1) self.grid_00_08.addWidget(self.PB_Original, 0, 1, 1, 1) self.grid_00_08.addWidget(self.PB_Zero, 0, 2, 1, 1) self.grid_00_08.addWidget(self.PB_Reset, 0, 3, 1, 1) self.gridLayout_00_00.addLayout(self.grid_00_08, 6, 0, 1, 2) #### Gridlayout END MainWindow.setCentralWidget(self.centralwidget) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): MainWindow.setWindowFlags(PySide2.QtCore.Qt.WindowStaysOnTopHint) # this function turns the front window (stay to hint) MainWindow.setWindowTitle(__title__ + " rmu (" + __version__ + ")") _translate = QtCore.QCoreApplication.translate self.groupBox_Rotation.setTitle(_translate("MainWindow", "Point Rotation")) self.RB_Bond_Box_Center.setText(_translate("MainWindow", "Boundbox Center")) self.RB_Bond_Box_Center.setToolTip(_translate("MainWindow", "Point rotation on BoundBox Center")) self.RB_Center_Mass.setText(_translate("MainWindow", "Center of Mass")) self.RB_Center_Mass.setToolTip(_translate("MainWindow", "Point rotation on Center Mass")) self.RB_Point_Clicked.setText(_translate("MainWindow", "Point clicked")) self.RB_Point_Clicked.setToolTip(_translate("MainWindow", "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.groupBox_Axis.setTitle(_translate("MainWindow", "Axis Rotation")) self.RB_Rotation_X.setText(_translate("MainWindow", "Rotation(Z) Yaw")) self.RB_Rotation_X.setToolTip(_translate("MainWindow", "Rotation on Axis Yaw (Z)")) self.RB_Rotation_Y.setText(_translate("MainWindow", "Rotation(Y) Pitch")) self.RB_Rotation_Y.setToolTip(_translate("MainWindow", "Rotation on Axis Pitch (Y)")) self.RB_Rotation_Z.setText(_translate("MainWindow", "Rotation(X) Roll")) self.RB_Rotation_Z.setToolTip(_translate("MainWindow", "Rotation on Axis Roll (X)")) self.RB_Direction_D.setText(_translate("MainWindow", "Direction")) self.RB_Direction_D.setToolTip(_translate("MainWindow", "Rotation or Translation on Direction" + "\n" "For use the Direction option:" + "\n" "Select First: the object to Rotate/Translate" + "\n" "Second: the path: Line, Wire or Edge")) self.groupBox_Pos_Mouse.setTitle(_translate("MainWindow", "Coordinates Point clicked")) self.groupBox_Pos_Mouse.setToolTip(_translate("MainWindow", "Position click mouse modification possible only with mode Point clicked")) self.DS_Pos_Mouse_X.setToolTip(_translate("MainWindow", "Position click mouse X" + "\n" + "modification only with mode Point clicked")) self.DS_Pos_Mouse_Y.setToolTip(_translate("MainWindow", "Position click mouse Y" + "\n" + "modification only with mode Point clicked")) self.DS_Pos_Mouse_Z.setToolTip(_translate("MainWindow", "Position click mouse Z" + "\n" + "modification only with mode Point clicked")) self.CB_Position.setText(_translate("MainWindow", "Translation")) self.CB_Position.setToolTip(_translate("MainWindow", "Move the object to axis choice X, Y or Z")) # self.CB_Point.setText(_translate("MainWindow", "Point")) # self.CB_Point.setToolTip(_translate("MainWindow", "If checked, create one point to visualise the point rotation")) self.PB_Point.setText(_translate("MainWindow", "Point")) self.PB_Point.setToolTip(_translate("MainWindow", "Create one point to visualise the point rotation")) self.CB_Free.setText(_translate("MainWindow", "Free")) self.CB_Free.setToolTip(_translate("MainWindow", "This checkBox switch the Application button")) self.LE_Increment.setToolTip(_translate("MainWindow", "Display the original Data + the modification")) self.DS_Scroll_Bar.setToolTip(_translate("MainWindow", "Enter the modification")) self.PB_Apply.setToolTip(_translate("MainWindow", "Apply the modification")) self.PB_Apply.setText(_translate("MainWindow", "Apply")) self.label_00.setText(_translate("MainWindow", " Select one Object")) self.PB_Quit.setText(_translate("MainWindow", "Quit")) self.PB_Quit.setToolTip(_translate("MainWindow", "Quite the macro")) self.PB_Original.setText(_translate("MainWindow", "Original")) self.PB_Original.setToolTip(_translate("MainWindow", "Move the object to the original position")) self.PB_Reset.setText(_translate("MainWindow", "Reset")) self.PB_Reset.setToolTip(_translate("MainWindow", "Reset the complete data macro")) self.PB_Zero.setText(_translate("MainWindow", "0,0,0")) self.PB_Zero.setToolTip(_translate("MainWindow", "Move the object to the base coordinates 0, 0, 0")) 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)) elif self.RB_Direction_D.isChecked(): posZ = valeur posX = posY = 0.0 xD = str(round(myObject.Placement.Base[0],4)) yD = str(round(myObject.Placement.Base[1],4)) zD = str(round(myObject.Placement.Base[2],4)) self.LE_Increment.setText("(" + xD + ", " + yD + ", " + zD + ")") 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)) elif self.RB_Direction_D.isChecked(): rotAngleZ = valeur rotAngleX = rotAngleY = 0.0 xD = str(round(myObject.Placement.Rotation.toEuler()[0],4)) yD = str(round(myObject.Placement.Rotation.toEuler()[1],4)) zD = str(round(myObject.Placement.Rotation.toEuler()[2],4)) self.LE_Increment.setText("(" + xD + ", " + yD + ", " + zD + ")") 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 if self.RB_Direction_D.isChecked(): # direction try: selectedEdge = FreeCADGui.Selection.getSelectionEx()[1].SubObjects[0] # select one element and axis second object (2 selections) except Exception: try: selectedEdge = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[1] # select one element and axis same object (2 selections) except Exception: try: selectedEdge = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0] # select one element and axis same object (1 selection) except Exception: None pointsTrajet = [] try: pointsTrajet = selectedEdge.discretize(Distance = 1.0) # discretize the element except Exception: direction = myObject.Shape.Vertexes[0].Point pointsTrajet = direction None try: direction = pointsTrajet[1].sub(pointsTrajet[0]) # search the direction line or sub except Exception: try: direction = myObject.Shape.Vertexes[0].Point # direction point except Exception: direction = App.Vector(0.0,0.0,0.0) myObject.Placement.Base = myObject.Placement.Base + App.Vector(direction).scale(valeur, valeur, valeur) else: 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))) elif self.RB_Direction_D.isChecked(): xD = str(round(myObject.Placement.Base[0],4)) yD = str(round(myObject.Placement.Base[1],4)) zD = str(round(myObject.Placement.Base[2],4)) self.LE_Increment.setText("(" + xD + ", " + yD + ", " + zD + ")") 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_Direction_D.isChecked(): # direction try: selectedEdge = FreeCADGui.Selection.getSelectionEx()[1].SubObjects[0] # select one element and axis second object (2 selections) except Exception: try: selectedEdge = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[1] # select one element and axis same object (2 selections) except Exception: try: selectedEdge = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0] # select one element and axis same object (1 selection) except Exception: None try: direction = selectedEdge.Vertexes[1].Point.sub(selectedEdge.Vertexes[0].Point)# search the direction line or sub except Exception: try: direction = objectRotation.Vertexes[0].Point except Exception: direction = App.Vector(0.0,0.0,0.0) myObject.Placement = App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(App.Vector(direction), valeur), App.Vector(axisX, axisY, axisZ)).multiply(App.ActiveDocument.getObject(myObject.Name).Placement) else: 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) # other method 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))) elif self.RB_Direction_D.isChecked(): xD = str(round(myObject.Placement.Rotation.toEuler()[0],4)) yD = str(round(myObject.Placement.Rotation.toEuler()[1],4)) zD = str(round(myObject.Placement.Rotation.toEuler()[2],4)) self.LE_Increment.setText("(" + xD + ", " + yD + ", " + zD + ")") 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_Direction_D(self): global myObject if self.CB_Position.isChecked(): xD = str(round(myObject.Placement.Base[0],4)) yD = str(round(myObject.Placement.Base[1],4)) zD = str(round(myObject.Placement.Base[2],4)) else: xD = str(round(myObject.Placement.Rotation.toEuler()[0],4)) yD = str(round(myObject.Placement.Rotation.toEuler()[1],4)) zD = str(round(myObject.Placement.Rotation.toEuler()[2],4)) self.LE_Increment.setText("(" + xD + ", " + yD + ", " + zD + ")") self.DS_Scroll_Bar.setValue(0.0) # print("on_RB_Direction_D") 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 self.label_00.setToolTip("Axis BoundBox.Center") elif self.RB_Center_Mass.isChecked(): axisX = myObject.Shape.CenterOfMass.x axisY = myObject.Shape.CenterOfMass.y axisZ = myObject.Shape.CenterOfMass.z self.label_00.setToolTip("Axis Center Of Mass") elif self.RB_Point_Clicked.isChecked(): axisX = positionMouse[0] axisY = positionMouse[1] axisZ = positionMouse[2] self.groupBox_Pos_Mouse.setEnabled(True) self.label_00.setToolTip("Point Mouse") 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 Translation") self.RB_Rotation_Z.setText("Translation Z ") # translate self.RB_Rotation_Y.setText("Translation Y ") self.RB_Rotation_X.setText("Translation X ") self.RB_Direction_D.setText("Translation D ") try: self.label_00.setText("[Pl.Base=(" + 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))) elif self.RB_Direction_D.isChecked(): xD = str(round(myObject.Placement.Base[0],4)) yD = str(round(myObject.Placement.Base[1],4)) zD = str(round(myObject.Placement.Base[2],4)) self.LE_Increment.setText("(" + xD + ", " + yD + ", " + zD + ")") 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") self.RB_Direction_D.setText("Rotation(D)") 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))) elif self.RB_Direction_D.isChecked(): xD = str(round(myObject.Placement.Rotation.toEuler()[0],4)) yD = str(round(myObject.Placement.Rotation.toEuler()[1],4)) zD = str(round(myObject.Placement.Rotation.toEuler()[2],4)) self.LE_Increment.setText("(" + xD + ", " + yD + ", " + zD + ")") 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 global myObject global positionMouse if self.RB_Bond_Box_Center.isChecked(): # axis # 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(): # 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(): # 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" Gui.Selection.addSelection(App.ActiveDocument.getObject(myObject.Name)) FreeCAD.ActiveDocument.recompute() # 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(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))) elif self.RB_Direction_D.isChecked(): xD = str(round(myObject.Placement.Rotation.toEuler()[0],4)) yD = str(round(myObject.Placement.Rotation.toEuler()[1],4)) zD = str(round(myObject.Placement.Rotation.toEuler()[2],4)) self.LE_Increment.setText("(" + xD + ", " + yD + ", " + zD + ")") 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 elif self.RB_Direction_D.isChecked(): xD = str(round(myObject.Placement.Rotation.toEuler()[0],4)) yD = str(round(myObject.Placement.Rotation.toEuler()[1],4)) zD = str(round(myObject.Placement.Rotation.toEuler()[2],4)) self.LE_Increment.setText("(" + xD + ", " + yD + ", " + zD + ")") 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.RB_Direction_D.setText("Rotation(D) Direction") 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.PB_Point.setEnabled(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() if ff.CB_Position.isChecked(): ff.groupBox_Rotation.setEnabled(False) else: 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.PB_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: # deselectionne FreeCADGui.Selection.removeSelection(obj) except Exception: None s=SelObserver() FreeCADGui.Selection.addObserver(s) # installe la fonction en mode resident if __name__ == "__main__": MainWindow = QtWidgets.QMainWindow() MainWindow.setObjectName("__title__") # macro internal Name ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show()
Exemple
Liens
The forum feature req: placement - rotate part around its midpoint Mes macro sur Gist mario52a
Version
2020/03/07 ver 00.05.2 : correction du bug translation éffacée "direction = myObject.Placement.Rotation.multVec(direction)"
2020/03/01 ver 00.05.1 : correction de la position du test "FreeCAD version"
2020/02/29 ver 00.05 : conversion pour Hdpi (Layout) et ajout fonction Direction
06/04/2019 ver 00.04 : Python 3
29/03/2018 ver 00.03 : commenter les lignes "FreeCAD.ActiveDocument.recompute()" le changement de valeur est trop lente dans FreeCAD 0.17.... voir FC0.17 recompute strange behaviour (regression)
27/03/2017 ver 00.02 : modification du spinbox "Pos" maintenant accepte les valeurs négatives
05/03/2017 ver 00.01 : ajout de 3 boîtes de dialogue pour afficher les coordonnées X Y Z au clic de souris
04/03/2017 ver 00.00