Macro FCCamera: Difference between revisions
mNo edit summary |
m (create the link to Gist cause indentation inappropriate created) |
||
Line 105: | Line 105: | ||
==Script== <!--T:22--> |
==Script== <!--T:22--> |
||
</translate> |
|||
'''Macro FCCamera.FCMacro''' |
Download the macro to Gist [https://gist.github.com/mario52a/4aa545c23b323cf68824 '''Macro FCCamera.FCMacro'''] |
||
{{Code|code= |
|||
# -*- coding: utf-8 -*- |
|||
""" |
|||
*************************************************************************** |
|||
* Copyright (c) 2015 2016 <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 * |
|||
*************************************************************************** |
|||
""" |
|||
# FCCamera 0.5 18/03/2015 28/02/2016 06/09/2016 |
|||
# |
|||
#OS: Windows Vista #OS: Windows Vista |
|||
#Word size of OS: 32-bit #Word size of OS: 32-bit |
|||
#Word size of FreeCAD: 32-bit #Word size of FreeCAD: 32-bit |
|||
#Version: 0.15.4502 (Git) #Version: 0.15.4655 (Git) |
|||
#Branch: master #Branch: master |
|||
#Hash: 3c754da0cbc86e06ade2543baecbca25701b7160 #Hash: 5d159f5cf352a93b1aff4fb7b82e8b747ee4f35b |
|||
#Python version: 2.7.8 #Python version: 2.7.8 |
|||
#Qt version: 4.8.6 #Qt version: 4.8.6 |
|||
#Coin version: 4.0.0a #Coin version: 4.0.0a |
|||
#OCC version: 6.7.1 #OCC version: 6.7.1 |
|||
# |
|||
__title__ ="FCCamera" |
|||
__author__ = "Mario52" |
|||
__url__ = "http://www.freecadweb.org/wiki/index.php?title=Macro_FCCamera" |
|||
__version__ = "00.05" |
|||
__date__ = "06/09/2016" |
|||
import Draft, Part, FreeCAD, math, PartGui, FreeCADGui, DraftVecUtils |
|||
#import os, WorkingPlane |
|||
App = FreeCAD |
|||
try: |
|||
import PyQt4 # PyQt4 |
|||
from PyQt4 import QtCore, QtGui # PyQt4 |
|||
App.Console.PrintMessage("PyQt4"+"\n") |
|||
except Exception: |
|||
import PySide # PySide |
|||
from PySide import QtCore, QtGui # PySide |
|||
App.Console.PrintMessage("PySide"+"\n") |
|||
from math import radians, degrees, sqrt, pi, sin, cos, asin |
|||
from FreeCAD import Base |
|||
from FreeCAD import Vector |
|||
import pivy |
|||
from pivy import coin |
|||
global path ; path = "" |
|||
global valeur ; valeur = 0.0 |
|||
global valeurV ; valeurV = 0.0 |
|||
global Rname ; Rname = ["","",""] |
|||
global RnameCube; RnameCube = "" |
|||
global RnameCompound; RnameCompound = "" |
|||
global datExtract; datExtract = "" |
|||
global positionX ; positionX = 0.0 |
|||
global positionY ; positionY = 0.0 |
|||
global positionZ ; positionZ = 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) |
|||
class SelObserver: # SelObserver |
|||
def addSelection(self,document, object, element, position): # Selection SelObserver |
|||
global positionX |
|||
global positionY |
|||
global positionZ |
|||
positionX = position[0] |
|||
positionY = position[1] |
|||
positionZ = position[2] |
|||
def datExtract(data): |
|||
# return a string |
|||
data = str(data) |
|||
a = "" |
|||
for i in data: |
|||
if i in ("0123456789e.- "): |
|||
a+=i |
|||
a = a.strip(" ") |
|||
a = a.split(" ") |
|||
return a |
|||
global Nameelement2; Nameelement2 = "" # new selection |
|||
global vueView ; vueView = 0 # passe vue |
|||
def To_Face_Or_To_Axis(ToFace): # 1=NormalAt 0=Axis #Align Face selected to Face or to Axis |
|||
global vueView |
|||
global Nameelement2 |
|||
try: |
|||
SubElement = FreeCADGui.Selection.getSelectionEx() |
|||
Nameelement = SubElement[0].SubElementNames[0] |
|||
if Nameelement != Nameelement2: |
|||
vueView = 0 |
|||
Nameelement2 = Nameelement |
|||
if ToFace == 1: |
|||
v = Gui.Selection.getSelectionEx()[0].SubObjects[0].normalAt(0,0) # NormalAt |
|||
App.Console.PrintMessage("Nor At ") |
|||
else: |
|||
v=Gui.Selection.getSelectionEx()[0].SubObjects[0].Surface.Axis # Axis |
|||
App.Console.PrintMessage("S Axis ") |
|||
if vueView == 0: |
|||
r=App.Rotation(App.Vector(0,0,1),v) |
|||
App.Console.PrintMessage("0,0,1"+"\n") |
|||
elif vueView == 1: |
|||
r=App.Rotation(App.Vector(0,0,-1),v) |
|||
App.Console.PrintMessage("0,0,-1"+"\n") |
|||
elif vueView == 2: |
|||
r=App.Rotation(App.Vector(0,1,0),v) |
|||
App.Console.PrintMessage("0,1,0"+"\n") |
|||
elif vueView == 3: |
|||
r=App.Rotation(App.Vector(0,-1,0),v) |
|||
App.Console.PrintMessage("0,-1,0"+"\n") |
|||
elif vueView == 4: |
|||
r=App.Rotation(App.Vector(1,0,0),v) |
|||
App.Console.PrintMessage("1,0,0"+"\n") |
|||
elif vueView == 5: |
|||
r=App.Rotation(App.Vector(-1,0,0),v) |
|||
App.Console.PrintMessage("-1,0,0"+"\n") |
|||
vueView = -1 |
|||
Gui.ActiveDocument.ActiveView.setCameraOrientation(r.Q)# |
|||
vueView += 1 |
|||
except: |
|||
App.Console.PrintError("Select a face"+"\n") |
|||
class Ui_MainWindow(object): |
|||
def setupUi(self, MainWindow): |
|||
global path |
|||
self.window = MainWindow |
|||
#path = FreeCAD.ConfigGet("AppHomePath") |
|||
path = FreeCAD.ConfigGet("UserAppData") # |
|||
# path = "Yout path" # |
|||
App.Console.PrintMessage("Path locality to FCCamera.....images.png [ " + path + " ]"+"\n") |
|||
# print "Path locality ( ",path," )" |
|||
MainWindow.setObjectName(_fromUtf8("MainWindow")) |
|||
MainWindow.resize(209, 500) |
|||
MainWindow.setMaximumSize(QtCore.QSize(209, 500)) |
|||
self.centralWidget = QtGui.QWidget(MainWindow) |
|||
self.centralWidget.setObjectName(_fromUtf8("centralWidget")) |
|||
### ---graphicsView--- |
|||
self.graphicsView = QtGui.QGraphicsView(self.centralWidget) |
|||
self.graphicsView.setGeometry(QtCore.QRect(20, 10, 171, 101)) |
|||
self.graphicsView.setFrameShape(QtGui.QFrame.StyledPanel) |
|||
self.graphicsView.setObjectName(_fromUtf8("graphicsView")) |
|||
pic = QtGui.QPixmap(path+"FCCamera_Axis_rotation_X.png") |
|||
self.scene = QtGui.QGraphicsScene() |
|||
self.scene.addPixmap(QtGui.QPixmap(pic)) |
|||
self.graphicsView.setScene(ui.scene) |
|||
### ---graphicsView--- |
|||
self.groupBox_01 = QtGui.QGroupBox(self.centralWidget) |
|||
self.groupBox_01.setGeometry(QtCore.QRect(10, 120, 191, 151)) |
|||
self.groupBox_01.setObjectName(_fromUtf8("groupBox_01")) |
|||
self.label_02 = QtGui.QLabel(self.groupBox_01) |
|||
self.label_02.setGeometry(QtCore.QRect(10, 20, 181, 16)) |
|||
self.label_02.setObjectName(_fromUtf8("label_02")) |
|||
self.RB_Angle_X = QtGui.QRadioButton(self.groupBox_01) |
|||
self.RB_Angle_X.setGeometry(QtCore.QRect(10, 90, 51, 20)) |
|||
palette = QtGui.QPalette() |
|||
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) |
|||
brush.setStyle(QtCore.Qt.SolidPattern) |
|||
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush) |
|||
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) |
|||
brush.setStyle(QtCore.Qt.SolidPattern) |
|||
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush) |
|||
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120)) |
|||
brush.setStyle(QtCore.Qt.SolidPattern) |
|||
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush) |
|||
self.RB_Angle_X.setPalette(palette) |
|||
font = QtGui.QFont() |
|||
font.setBold(True) |
|||
font.setWeight(75) |
|||
self.RB_Angle_X.setFont(font) |
|||
self.RB_Angle_X.setMouseTracking(True) |
|||
self.RB_Angle_X.setChecked(True) |
|||
self.RB_Angle_X.setObjectName(_fromUtf8("RB_Angle_X")) |
|||
self.RB_Angle_X.setToolTip(u"Rotation of the camera on the X axis") |
|||
self.RB_Angle_X.clicked.connect(self.on_RB_Angle_X_clicked) |
|||
self.label_03 = QtGui.QLabel(self.groupBox_01) |
|||
self.label_03.setGeometry(QtCore.QRect(10, 70, 161, 16)) |
|||
self.label_03.setObjectName(_fromUtf8("label_03")) |
|||
self.RB_Angle_Y = QtGui.QRadioButton(self.groupBox_01) |
|||
self.RB_Angle_Y.setGeometry(QtCore.QRect(80, 90, 41, 20)) |
|||
palette = QtGui.QPalette() |
|||
brush = QtGui.QBrush(QtGui.QColor(0, 170, 0)) |
|||
brush.setStyle(QtCore.Qt.SolidPattern) |
|||
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush) |
|||
brush = QtGui.QBrush(QtGui.QColor(0, 170, 0)) |
|||
brush.setStyle(QtCore.Qt.SolidPattern) |
|||
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush) |
|||
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120)) |
|||
brush.setStyle(QtCore.Qt.SolidPattern) |
|||
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush) |
|||
self.RB_Angle_Y.setPalette(palette) |
|||
font = QtGui.QFont() |
|||
font.setBold(True) |
|||
font.setWeight(75) |
|||
self.RB_Angle_Y.setFont(font) |
|||
self.RB_Angle_Y.setObjectName(_fromUtf8("RB_Angle_Y")) |
|||
self.RB_Angle_Y.setToolTip(u"Rotation of the camera on the Y axis") |
|||
self.RB_Angle_Y.clicked.connect(self.on_RB_Angle_Y_clicked) |
|||
self.RB_Angle_Z = QtGui.QRadioButton(self.groupBox_01) |
|||
self.RB_Angle_Z.setGeometry(QtCore.QRect(150, 90, 41, 20)) |
|||
palette = QtGui.QPalette() |
|||
brush = QtGui.QBrush(QtGui.QColor(0, 0, 255)) |
|||
brush.setStyle(QtCore.Qt.SolidPattern) |
|||
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush) |
|||
brush = QtGui.QBrush(QtGui.QColor(0, 0, 255)) |
|||
brush.setStyle(QtCore.Qt.SolidPattern) |
|||
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush) |
|||
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120)) |
|||
brush.setStyle(QtCore.Qt.SolidPattern) |
|||
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush) |
|||
self.RB_Angle_Z.setPalette(palette) |
|||
font = QtGui.QFont() |
|||
font.setBold(True) |
|||
font.setWeight(75) |
|||
self.RB_Angle_Z.setFont(font) |
|||
self.RB_Angle_Z.setObjectName(_fromUtf8("RB_Angle_Z")) |
|||
self.RB_Angle_Z.setToolTip(u"Rotation of the camera on the Z axis") |
|||
self.RB_Angle_Z.clicked.connect(self.on_RB_Angle_Z_clicked) |
|||
self.DS_Angle = QtGui.QDoubleSpinBox(self.groupBox_01) |
|||
self.DS_Angle.setGeometry(QtCore.QRect(8, 40, 171, 22)) |
|||
self.DS_Angle.setAlignment(QtCore.Qt.AlignCenter) |
|||
self.DS_Angle.setDecimals(10) |
|||
self.DS_Angle.setMinimum(-359.0) |
|||
self.DS_Angle.setMaximum(359.0) |
|||
self.DS_Angle.setSingleStep(1.0) |
|||
self.DS_Angle.setObjectName(_fromUtf8("DS_Angle")) |
|||
self.DS_Angle.setToolTip(u"Enter the angle of rotation in degrees.\n" |
|||
" The given angle is added to the angle of the current view") |
|||
self.DS_Angle.valueChanged.connect(self.on_DS_Angle_valueChanged) #connection DS_Angle |
|||
self.PB_Accept_View = QtGui.QPushButton(self.groupBox_01) |
|||
self.PB_Accept_View.setGeometry(QtCore.QRect(10, 110, 171, 28)) |
|||
icon1 = QtGui.QIcon() |
|||
icon1.addPixmap(QtGui.QPixmap(_fromUtf8(path+"FCCamera_01.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) |
|||
self.PB_Accept_View.setIcon(icon1) |
|||
self.PB_Accept_View.setToolTip(u"Accept the view given") |
|||
self.PB_Accept_View.setObjectName(_fromUtf8("PB_Accept_View")) |
|||
self.PB_Accept_View.clicked.connect(self.on_PB_Accept_View_clicked) |
|||
self.groupBox_02 = QtGui.QGroupBox(self.centralWidget) |
|||
self.groupBox_02.setGeometry(QtCore.QRect(10, 280, 191, 181)) |
|||
self.groupBox_02.setObjectName(_fromUtf8("groupBox_02")) |
|||
self.PB_Detect_Camera = QtGui.QPushButton(self.groupBox_02) |
|||
self.PB_Detect_Camera.setGeometry(QtCore.QRect(10, 20, 171, 28)) |
|||
icon2 = QtGui.QIcon() |
|||
icon2.addPixmap(QtGui.QPixmap(_fromUtf8(path+"FCCamera_02.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) |
|||
self.PB_Detect_Camera.setIcon(icon2) |
|||
self.PB_Detect_Camera.setObjectName(_fromUtf8("PB_Detect_Camera")) |
|||
self.PB_Detect_Camera.setToolTip(u"Detect the position of the camera\n" |
|||
" The returned value is the value provided by the function getCameraOrientation()") |
|||
self.PB_Detect_Camera.clicked.connect(self.on_PB_Detect_Camera_clicked) |
|||
self.PB_To_Face = QtGui.QPushButton(self.groupBox_02) |
|||
self.PB_To_Face.setGeometry(QtCore.QRect(10, 70, 81, 28)) |
|||
icon3 = QtGui.QIcon() |
|||
icon3.addPixmap(QtGui.QPixmap(_fromUtf8(path+"FCCamera_03.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) |
|||
self.PB_To_Face.setIcon(icon3) |
|||
self.PB_To_Face.setObjectName(_fromUtf8("PB_To_Face")) |
|||
self.PB_To_Face.setToolTip("Align the view to the selected face \n" |
|||
"Click and repeat the click for NormalAt : \n" |
|||
"(0,0,1) (0,0,-1) (0,1,0) (0,-1,0) (1,0,0) (-1,0,0)") |
|||
self.PB_To_Face.clicked.connect(self.on_PB_To_Face_clicked) # align view to face Face |
|||
self.label_04 = QtGui.QLabel(self.groupBox_02) |
|||
self.label_04.setGeometry(QtCore.QRect(10, 50, 161, 20)) |
|||
self.label_04.setObjectName(_fromUtf8("label_04")) |
|||
self.PB_To_Axis = QtGui.QPushButton(self.groupBox_02) |
|||
self.PB_To_Axis.setGeometry(QtCore.QRect(100, 70, 81, 28)) |
|||
icon4 = QtGui.QIcon() |
|||
icon4.addPixmap(QtGui.QPixmap(_fromUtf8(path+"FCCamera_04.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) |
|||
self.PB_To_Axis.setIcon(icon4) |
|||
self.PB_To_Axis.setObjectName(_fromUtf8("PB_To_Axis")) |
|||
self.PB_To_Axis.setToolTip("Align the view to Axis face selected \n" |
|||
"Click and repeat the click for Surface Axis : \n" |
|||
"(0,0,1) (0,0,-1) (0,1,0) (0,-1,0) (1,0,0) (-1,0,0)") |
|||
self.PB_To_Axis.clicked.connect(self.on_PB_To_Axis_clicked) # Align view to face Axis |
|||
self.PB_Align_O_To_View = QtGui.QPushButton(self.groupBox_02) |
|||
self.PB_Align_O_To_View.setGeometry(QtCore.QRect(10, 105, 171, 28)) |
|||
icon5 = QtGui.QIcon() |
|||
icon5.addPixmap(QtGui.QPixmap(_fromUtf8(path+"FCCamera_05.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) |
|||
self.PB_Align_O_To_View.setIcon(icon5) |
|||
self.PB_Align_O_To_View.setObjectName(_fromUtf8("PB_Align_O_To_View")) |
|||
self.PB_Align_O_To_View.setToolTip("Align the object selected to the actual view \n" |
|||
"The changed values are : Rotation Axis((X, Y, Z), Angle) \n" |
|||
"Same Euler angles : Yaw, Pitch, Roll \n The Translation is not modify") |
|||
self.PB_Align_O_To_View.clicked.connect(self.on_PB_Align_O_To_View_clicked) # Align object to view |
|||
self.PB_Create_Plane = QtGui.QPushButton(self.groupBox_02) |
|||
self.PB_Create_Plane.setGeometry(QtCore.QRect(10, 140, 171, 28)) |
|||
icon6 = QtGui.QIcon() |
|||
icon6.addPixmap(QtGui.QPixmap(_fromUtf8(path+"FCCamera_06.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) |
|||
self.PB_Create_Plane.setIcon(icon6) |
|||
self.PB_Create_Plane.setObjectName(_fromUtf8("PB_Create_Plane")) |
|||
self.PB_Create_Plane.setToolTip("A circular plane is created facing the screen to mouse click coordinates on an object \n" |
|||
"The radius of the plane is equal to the maximum dimension of BoundBox \n" |
|||
"If no object is selected, the plane is created to 0, 0, 0 coordinates with a radius of 20 mm") |
|||
self.PB_Create_Plane.clicked.connect(self.on_PB_Create_Plane_clicked) # create plane |
|||
self.PB_Reset = QtGui.QPushButton(self.centralWidget) |
|||
self.PB_Reset.setGeometry(QtCore.QRect(10, 465, 91, 28)) |
|||
icon7 = QtGui.QIcon() |
|||
icon7.addPixmap(QtGui.QPixmap(_fromUtf8(path+"FCCamera_07.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) |
|||
self.PB_Reset.setIcon(icon7) |
|||
self.PB_Reset.setObjectName(_fromUtf8("PB_Reset")) |
|||
self.PB_Reset.setToolTip("Refresh alls") |
|||
self.PB_Reset.clicked.connect(self.on_PB_Reset_clicked) # refresh |
|||
self.PB_Quit = QtGui.QPushButton(self.centralWidget) |
|||
self.PB_Quit.setGeometry(QtCore.QRect(110, 465, 91, 28)) |
|||
icon8 = QtGui.QIcon() |
|||
icon8.addPixmap(QtGui.QPixmap(_fromUtf8(path+"FCCamera_08.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) |
|||
self.PB_Quit.setIcon(icon8) |
|||
self.PB_Quit.setObjectName(_fromUtf8("PB_Quit")) |
|||
self.PB_Quit.setToolTip("Quit FCCamera") |
|||
self.PB_Quit.clicked.connect(self.on_PB_Quit_clicked) # quit |
|||
MainWindow.setCentralWidget(self.centralWidget) |
|||
self.retranslateUi(MainWindow) |
|||
QtCore.QMetaObject.connectSlotsByName(MainWindow) |
|||
def retranslateUi(self, MainWindow): |
|||
MainWindow.setWindowTitle("FCCamera") |
|||
MainWindow.setWindowIcon(QtGui.QIcon(path+'FCCamera_00.png')) # change l'icône de la fenêtre principale |
|||
try: |
|||
MainWindow.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint) # PyQt4 cette fonction met la fenêtre en avant |
|||
except Exception: |
|||
MainWindow.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide cette fonction met la fenêtre en avant |
|||
self.groupBox_01.setTitle("Camera of Axis") |
|||
self.label_02.setText("Angle rotation Axis in degrees") |
|||
self.label_03.setText("Axe of rotation") |
|||
self.RB_Angle_X.setText("X") |
|||
self.RB_Angle_Y.setText("Y") |
|||
self.RB_Angle_Z.setText("Z") |
|||
self.PB_Accept_View.setText("Accept the rotation") |
|||
self.groupBox_02.setTitle("Virtual") |
|||
self.PB_Detect_Camera.setText("Detect camera orientation") |
|||
self.PB_To_Face.setText("To Face.") |
|||
self.label_04.setText("Align view to face selected.") |
|||
self.PB_To_Axis.setText("To Axis.") |
|||
self.PB_Align_O_To_View.setText("Align Object to View") |
|||
self.PB_Create_Plane.setText("Create plane of view.") |
|||
self.PB_Reset.setText("Reset") |
|||
self.PB_Quit.setText("Quit") |
|||
def on_RB_Angle_X_clicked(self): # X |
|||
global path |
|||
App.Console.PrintMessage("X"+"\n") |
|||
pic = QtGui.QPixmap(path+"FCCamera_Axis_rotation_X.png") |
|||
self.scene = QtGui.QGraphicsScene() |
|||
self.scene.addPixmap(QtGui.QPixmap(pic)) |
|||
self.graphicsView.setScene(ui.scene) |
|||
def on_RB_Angle_Y_clicked(self): # Y |
|||
global path |
|||
App.Console.PrintMessage("Y"+"\n") |
|||
pic = QtGui.QPixmap(path+"FCCamera_Axis_rotation_Y.png") |
|||
self.scene = QtGui.QGraphicsScene() |
|||
self.scene.addPixmap(QtGui.QPixmap(pic)) |
|||
self.graphicsView.setScene(ui.scene) |
|||
def on_RB_Angle_Z_clicked(self): # Z |
|||
global path |
|||
App.Console.PrintMessage("Z"+"\n") |
|||
pic = QtGui.QPixmap(path+"FCCamera_Axis_rotation_Z.png") |
|||
self.scene = QtGui.QGraphicsScene() |
|||
self.scene.addPixmap(QtGui.QPixmap(pic)) |
|||
self.graphicsView.setScene(ui.scene) |
|||
def on_DS_Angle_valueChanged(self,value): # connection DS_Angle value donnee en degres |
|||
global valeur |
|||
valeur = 0.0 |
|||
valeur = math.radians(value) # valeur en degres convertie en radian |
|||
def on_PB_Detect_Camera_clicked(self): # detection Orientation camera |
|||
plan = FreeCADGui.ActiveDocument.ActiveView.getCameraOrientation() |
|||
cam=Gui.ActiveDocument.ActiveView.getCameraNode() |
|||
App.Console.PrintMessage("___Camera_Detection_____________________"+"\n") |
|||
App.Console.PrintMessage("position : " + str(cam.position.getValue().getValue()) + "\n") |
|||
App.Console.PrintMessage("orientation : " + str(FreeCADGui.ActiveDocument.ActiveView.getCameraOrientation().Axis)+" , "+str(FreeCADGui.ActiveDocument.ActiveView.getCameraOrientation().Angle) + "\n") |
|||
App.Console.PrintMessage("nearDistance : " + str(cam.nearDistance.getValue()) + "\n") |
|||
App.Console.PrintMessage("farDistance : " + str(cam.farDistance.getValue()) + "\n") |
|||
App.Console.PrintMessage("aspectRatio : " + str(cam.aspectRatio.getValue()) + "\n") |
|||
App.Console.PrintMessage("focalDistance : " + str(cam.focalDistance.getValue()) + "\n") |
|||
App.Console.PrintMessage("height : " + str(cam.height.getValue()) + "\n" + "\n") |
|||
App.Console.PrintMessage("___Camera_Orientation____________________"+"\n") |
|||
App.Console.PrintMessage("Radians XYZ Q : " + str(plan)+"\n") |
|||
xP = float(datExtract(plan)[0]) |
|||
yP = float(datExtract(plan)[1]) |
|||
zP = float(datExtract(plan)[2]) |
|||
qP = float(datExtract(plan)[3]) |
|||
App.Console.PrintMessage("Degrees XYZ : " + str(degrees(xP)) + " , " +str(degrees(yP)) + " , " + str(degrees(zP)) +"\n") |
|||
App.Console.PrintMessage("Degrees Q : " + str(degrees(qP)) +"\n"+"\n") |
|||
App.Console.PrintMessage("Radians Axis.xyz A : " + str(plan.Axis) + " , " + str(plan.Angle) +"\n") |
|||
App.Console.PrintMessage("Degrees Axis.x : " + str(degrees(plan.Axis.x)) +"\n") |
|||
App.Console.PrintMessage("Degrees Axis.y : " + str(degrees(plan.Axis.y)) +"\n") |
|||
App.Console.PrintMessage("Degrees Axis.z : " + str(degrees(plan.Axis.z)) +"\n") |
|||
App.Console.PrintMessage("Degrees Angle : " + str(degrees(plan.Angle)) +"\n") |
|||
#http://forum.freecadweb.org/viewtopic.php?f=13&t=14213 |
|||
App.Console.PrintMessage("Direction : " + str(cam.orientation.getValue().multVec(coin.SbVec3f(0,0,-1)).getValue()) + "\n") |
|||
App.Console.PrintMessage("___FCCamera______________________________"+"\n\n") |
|||
App.ActiveDocument.recompute() |
|||
def on_PB_Accept_View_clicked(self): # Accept Rotation Camera to Axis |
|||
global valeur |
|||
if (valeur != 0): |
|||
Xv = 0.0;Yv = 0.0;Zv = 0.0 |
|||
cam = Gui.ActiveDocument.ActiveView.getCameraNode() |
|||
rot = coin.SbRotation() |
|||
##### |
|||
if self.RB_Angle_X.isChecked(): |
|||
Xv = 1.0 |
|||
App.Console.PrintMessage("(X ") |
|||
else: |
|||
App.Console.PrintMessage("(- ") |
|||
if self.RB_Angle_Y.isChecked(): |
|||
Yv = 1.0 |
|||
App.Console.PrintMessage("Y ") |
|||
else: |
|||
App.Console.PrintMessage("- ") |
|||
if self.RB_Angle_Z.isChecked(): |
|||
Zv = 1.0 |
|||
App.Console.PrintMessage("Z) ") |
|||
else: |
|||
App.Console.PrintMessage("-) "+"\n") |
|||
##### |
|||
rot.setValue(coin.SbVec3f(Xv,Yv,Zv),valeur) |
|||
nrot = cam.orientation.getValue() * rot |
|||
cam.orientation = nrot |
|||
App.Console.PrintMessage(str(valeur)+" rad. , "+str(math.degrees(valeur))+" deg."+"\n") |
|||
App.Console.PrintMessage("FCCamera_________________________________"+"\n\n") |
|||
if valeur == 0: |
|||
App.Console.PrintError("Value egal zero select one Value"+"\n") |
|||
def on_PB_Align_O_To_View_clicked(self): #Align and Fix Object to View |
|||
sel = FreeCADGui.Selection.getSelection() |
|||
if (len(sel)==0): |
|||
App.Console.PrintError("Select one object"+"\n") |
|||
else: |
|||
Nameelement = sel[0].Name |
|||
print sel[0].Placement.Base |
|||
App.Console.PrintMessage(str(Nameelement)+"\n") |
|||
pl = FreeCAD.Placement() |
|||
pl.Rotation = FreeCADGui.ActiveDocument.ActiveView.getCameraOrientation() |
|||
pl.Base = sel[0].Placement.Base |
|||
App.ActiveDocument.getObject(Nameelement).Placement=pl |
|||
def on_PB_Create_Plane_clicked(self): # Create plane |
|||
global positionX # create plans coordinate mouse |
|||
global positionY |
|||
global positionZ |
|||
rayon = 20 # Radius of plane |
|||
selEx = FreeCADGui.Selection.getSelectionEx() |
|||
objs = [selobj.Object for selobj in selEx] |
|||
if len(objs) >= 1: # radius = > BounBox length |
|||
s = objs[0].Shape |
|||
boundBox_ = s.BoundBox |
|||
boundBoxLX = boundBox_.XLength |
|||
boundBoxLY = boundBox_.YLength |
|||
boundBoxLZ = boundBox_.ZLength |
|||
rayon = boundBoxLX |
|||
if rayon < boundBoxLY: |
|||
rayon = boundBoxLY |
|||
elif rayon < boundBoxLZ: |
|||
rayon = boundBoxLZ |
|||
radiusP = rayon # Radius of plane |
|||
App.Console.PrintMessage("Create plane ("+str(radiusP)+" mm)"+"\n") |
|||
FcPlane = doc.addObject("App::DocumentObjectGroup","FcPlane") |
|||
plan = FreeCADGui.ActiveDocument.ActiveView.getCameraOrientation() |
|||
# App.Console.PrintMessage(str(plan)+"\n") |
|||
# App.Console.PrintMessage(str(positionX)+" "+str(positionY)+" "+str(positionZ)+"\n") |
|||
xP = float(datExtract(plan)[0]) |
|||
yP = float(datExtract(plan)[1]) |
|||
zP = float(datExtract(plan)[2]) |
|||
qP = float(datExtract(plan)[3]) |
|||
pl = FreeCAD.Placement() |
|||
pl.Rotation.Q = (xP,yP,zP,qP) # rotation of object |
|||
pl.Base = FreeCAD.Vector(positionX,positionY,positionZ) # here coordinates XYZ of plan |
|||
# Draft.makeRectangle(length=radiusP,height=radiusP,placement=pl,face=False,support=None) |
|||
points=[FreeCAD.Vector(-(radiusP*1.5),0,0),FreeCAD.Vector((radiusP*1.5),0,0)] |
|||
mire01 = Draft.makeWire(points,closed=False,placement=pl,face=False,support=None) |
|||
FreeCADGui.ActiveDocument.getObject(App.ActiveDocument.ActiveObject.Name).LineColor = (1.0,0.0,0.0) |
|||
FcPlane.addObject(mire01) # contener character |
|||
points=[FreeCAD.Vector(0,-(radiusP*1.5),0),FreeCAD.Vector(0,(radiusP*1.5),0)] |
|||
mire02 = Draft.makeWire(points,closed=False,placement=pl,face=False,support=None) |
|||
FreeCADGui.ActiveDocument.getObject(App.ActiveDocument.ActiveObject.Name).LineColor = (1.0,0.0,0.0) |
|||
FcPlane.addObject(mire02) # contener character |
|||
cercle = Draft.makeCircle(radius=radiusP,placement=pl,face=False,support=None) |
|||
Rnameplane = App.ActiveDocument.ActiveObject.Name |
|||
App.ActiveDocument.ActiveObject.Label = "PlaneC" |
|||
FreeCAD.ActiveDocument.getObject(Rnameplane).MakeFace = True |
|||
FreeCADGui.ActiveDocument.getObject(Rnameplane).LineColor = (1.0,0.0,0.0) |
|||
FreeCADGui.ActiveDocument.getObject(Rnameplane).ShapeColor = (0.0,0.66666669,1.0) |
|||
FreeCADGui.ActiveDocument.getObject(Rnameplane).Transparency = 80 |
|||
FreeCADGui.ActiveDocument.getObject(Rnameplane).GridSize = '10 mm' |
|||
# FreeCADGui.ActiveDocument.getObject(Rnameplane).GridSnap = True |
|||
FreeCADGui.ActiveDocument.getObject(Rnameplane).ShowGrid = True |
|||
FcPlane.addObject(cercle) # contener character |
|||
FreeCAD.ActiveDocument.recompute() |
|||
positionX = 0.0 |
|||
positionY = 0.0 |
|||
positionZ = 0.0 |
|||
def on_PB_To_Face_clicked(self): # view to face selected Face |
|||
To_Face_Or_To_Axis(1) |
|||
def on_PB_To_Axis_clicked(self): # view to face selected Axis |
|||
To_Face_Or_To_Axis(0) |
|||
def on_PB_Reset_clicked(self): # Refresh |
|||
global valeur |
|||
global positionX |
|||
global positionY |
|||
global positionZ |
|||
global vueView |
|||
global path |
|||
App.Console.PrintMessage("Refresh"+"\n") |
|||
Gui.activeDocument().activeView().viewTop() |
|||
Gui.SendMsgToActiveView("ViewFit") |
|||
valeur = 0.0 |
|||
self.DS_Angle.setProperty("value", 0.0) |
|||
positionX = 0.0 |
|||
positionY = 0.0 |
|||
positionZ = 0.0 |
|||
vueView = 0 |
|||
self.groupBox_01.setTitle("Camera of Axis") |
|||
self.label_02.setText("Angle rotation Axis in degrees") |
|||
self.label_03.setText("Axe of rotation") |
|||
self.RB_Angle_X.setText("X") |
|||
self.RB_Angle_Y.setText("Y") |
|||
self.RB_Angle_Z.setText("Z") |
|||
self.RB_Angle_X.setChecked(True) |
|||
pic = QtGui.QPixmap(path+"FCCamera_Axis_rotation_X.png") |
|||
self.scene = QtGui.QGraphicsScene() |
|||
self.scene.addPixmap(QtGui.QPixmap(pic)) |
|||
self.graphicsView.setScene(ui.scene) |
|||
def on_PB_Quit_clicked(self): # quit |
|||
App.Console.PrintMessage("Fin FCCamera"+"\n") |
|||
FreeCADGui.Selection.removeObserver(s) # desinstalle la fonction residente |
|||
self.window.hide() |
|||
##Start##### |
|||
doc = FreeCAD.ActiveDocument # create one document |
|||
if doc == None: |
|||
doc = FreeCAD.newDocument() |
|||
#Gui.ActiveDocument.ActiveView.setAxisCross(True) # GuiAxis true |
|||
s=SelObserver() # installe the function in resident mode SelObserver |
|||
FreeCADGui.Selection.addObserver(s) # installe the function in resident mode SelObserver |
|||
MainWindow = QtGui.QMainWindow() |
|||
ui = Ui_MainWindow() |
|||
ui.setupUi(MainWindow) |
|||
MainWindow.show() |
|||
}} |
|||
<translate> |
|||
==Examples== <!--T:31--> |
==Examples== <!--T:31--> |
||
Revision as of 18:08, 20 September 2016
File:FCCamera 00 Macro FCCamera |
Description |
---|
This macro can rotate the screen in a defined angle and the defined axis and creates a plan to face the screen. Macro version: 0.5 (06/09/2016) Author: Mario52 |
Author |
Mario52 |
Download |
None |
Links |
Macros recipes How to install macros How to customize toolbars |
Macro Version |
0.5 (06/09/2016) |
Date last modified |
None |
FreeCAD Version(s) |
None |
Default shortcut |
None |
See also |
None |
Description
This macro can rotate the screen in a defined angle and the defined axis and creates a plan to face the screen to create a form in the specified plan positions the selected face facing the screen, to detect the position of the camera, align view to face or to axis, align the object to view.
How to use
Use is easy,
Camera of Axis: The dialog box to enter the rotation value angle in degrees.
Angle rotation Axis in degrees: Select the rotation axis X Y or Z.
Axe of rotation
Virtual
- Detect camera orientation : Detect the camera orientation and print in report view. The returned value is the value provided by the function getCameraOrientation().
Align view to face selected
- To Face. : Align the view to the selected face. Click and repeat the click for NormalAt : "(0,0,1) (0,0,-1) (0,1,0) (0,-1,0) (1,0,0) (-1,0,0)"
- To Axis. : Align the view to Axis face selected. Click and repeat the click for Surface Axis : "(0,0,1) (0,0,-1) (0,1,0) (0,-1,0) (1,0,0) (-1,0,0)"
- Align object to view. : Align the object selected to the actual view. The changed values are : Rotation Axis((X, Y, Z), Angle) Same Euler angles : Yaw, Pitch, Roll, The Translation is not modify.
- Create plane of view. : A circular plane is created facing the screen to mouse click coordinates on an object. The radius of the plane is equal to the maximum dimension of BoundBox. If no object is selected, the plane is created to 0, 0, 0 coordinates with a radius of 20 mm. The radius is modifiable to line 515:
rayon = 20 # Radius of plane
Icons
Download the file image and copy in your macro repertory.
Click the image, in the new window position the mouse over the image, click the right mouse and do "Save target as ..."
The path of icons is displayed in the View report
ex: Path locality to FCCamera.....images.png [ C:\Users\xx\AppData\Roaming\FreeCAD\ ]
You can change the path by changing the path in the line 165
Icons program :
Icons tableau : Axis X Axis Y Axis Z
Examples
to do ...
Links
Related Links with FCCamera
Macro Rotate View, Macro Align Object to View, Macro Align Face Object to View, Macro WorkFeatures
Discussion Forum MACRO:Work Feature 2014_12
Script
Download the macro to Gist Macro FCCamera.FCMacro
Examples
How to place an angle hole
-
Create your object
-
Select your cylinder for create your hole
-
The cylinder moves to 15 degrees (take the camera position)
do your Boolean operation -
Your hole 15 degrees
The same result can be achieved by creating a plan in the corner gave the mouse click position and a sketch.
Version
- ver 0.5 06/09/2016: correct name "FCCamera_Axis_rotation_X.png" in reset block
- ver 0.4 28/02/2016 : add display all camera detection and the Direction
- ver 0.3 18/03/2015 : modify line 492 replace "pl.Base = App.Vector(0,0,0)" to "pl.Base = sel[0].Placement.Base" now no longer moves the form at point (0,0,0) and leaves has the coordinates
- ver 0.2 25/02/2015 : correct names files in for compatibility Linux (case sensitive) thanks microelly2