Macro FCCamera: Difference between revisions

From FreeCAD Documentation
(Marked this version for translation)
m (Tweeks)
(47 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<translate>
<!--T:1-->
<!--T:1-->
{{Macro
{{Macro|Icon=FCCamera_00|Name=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.|Author=Mario52}}
|Name=Macro FCCamera

|Icon=FCCamera_00.png
|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.
|Author=Mario52
|Version=0.12.1
|Date=2020/02/12
|FCVersion=All
|Download=[https://forum.freecadweb.org/download/file.php?id=79288 FCCamera_Icones.zip]. Unziped the package and paste the total icon in the same directory as the macro.
}}


==Description== <!--T:2-->
==Description== <!--T:2-->
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.
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.


</translate>
==How to use== <!--T:3-->
{{Codeextralink|https://gist.githubusercontent.com/mario52a/4aa545c23b323cf68824/raw/42dc3ef73dc8db463a03b175f5a7f1f6978e3293/Macro%2520FCCamera.FCMacro}}
<translate>


<!--T:4-->
==Usage== <!--T:3-->
Uses aesy,


<!--T:5-->
<!--T:5-->
Line 19: Line 29:


<!--T:7-->
<!--T:7-->
'''Angle rotation Axis in degrees''': Select the rotation axis '''X Y''' or '''Z'''.
'''Angle rotation Axis in degrees''': Select the rotation axis '''X, Y,''' or '''Z'''.


<!--T:8-->
<!--T:8-->
Line 46: Line 56:


<!--T:16-->
<!--T:16-->
* [[File:FCCamera_06.png|24px]] {{KEY|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 494:
* [[File:FCCamera_06.png|24px]] {{KEY|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:
</translate>
</translate>
{{Code|code=
{{Code|code=
Line 53: Line 63:
<translate>
<translate>
<!--T:17-->
<!--T:17-->
* [[File:FCCamera_07.png|24px]] {{KEY|Reset.}} : Reset all values.
*{{KEY|[[File:FCCamera_07.png|24px]] Reset.}} : Reset all values.
* [[File:FCCamera_08.png|24px]] {{KEY|Quit.}} : Quit FCCamera.
*{{KEY| [[File:FCCamera_00.png|24px]] Photo.}} : Section save the screen rotation an image in angle value
*{{KEY| [[File:FCCamera_08.png|24px]] Quit.}} : Quit FCCamera.


<!--T:18-->
==Section Photo== <!--T:44-->

<!--T:45-->
[[File:Macro FCCamera 00b.png|left|FCCamera]]
{{clear}}
{{clear}}

<!--T:46-->
*{{KEY|ComboBox Actual }} : choice your screen definition for the image format
**Available (pre-defined):
***"Actual" (definition actual of screen)
***"Icon 16 x 16"
***"Icon 32 x 32"
***"Icon 64 x 64"
***"Icon 128 x 128"
***"CGA 320 x 200"
***"QVGA 320 x 240"
***"VGA 640 x 480"
***"SVGA 800 x 600"
***"XGA 1024 x 768"
***"XGA+ 1152 x 864"
***"SXGA 1280 x 1024"
***"SXGA+ 1400 x 1050"
***"UXGA 1600 x 1200"
***"QXGA 2048 x 1536"
***"Free"

<!--T:47-->
*{{KEY|SpinBox X and Y }}

<!--T:48-->
*{{KEY|ComboBox Format image}}
**Available :
***"BMP *.bmp"
***"ICO *.ico"
***"JPEG *.jpeg"
***"JPG *.jpg"
***"PNG *.png" (by default)
***"PPM *.ppm"
***"TIF *.tif"
***"TIFF *.tiff"
***"XBM *.xbm"
***"XPM *.xpm"

<!--T:18-->
*Line 1 : Number image calculated by the angle give (ex: angle 60 degrees = 360 (complete rotation) / 60 (angle) = 6 images

<!--T:49-->
*Line 2 : The definition of screen used

<!--T:50-->
*Background image :
** Actual : save image with the screen colour actual
** White : save image with the screen colour white
** Black : save image with the screen colour black

<!--T:51-->
*{{KEY|[[File:FCCamera_00.png|24px]] Launch}} : Open the file window , give the name and the path
*{{KEY|[[File:FCCamera_07.png|24px]] Reset}} : Reset the default value
*{{KEY|[[File:FCCamera_00.png|24px]] Return}} : Quit the photo panel and return to FCCamera panel


==Icons== <!--T:19-->
==Icons== <!--T:19-->
Line 63: Line 131:


<!--T:20-->
<!--T:20-->
Click the image, in the new window position the mouse over the image, click the right mouse and do "Save target as ..."
Click the image, in the new window position the mouse over the image, click the right mouse and choose "Save target as ..."


<!--T:28-->
The path of icons is displayed in the View report

<!--T:29-->
'''ex:''' Path locality to FCCamera.....images.png [ C:\Users\xx\AppData\Roaming\FreeCAD\ ]

<!--T:30-->
You can change the path by changing the path in the line 165


<!--T:21-->
<!--T:21-->
'''Icons program :'''
'''Icons program :'''

</translate>
</translate>

<center>
<gallery widths="500" heights="300">
File:FCCamera 15.png|How copy the icons in your macros directory.


</gallery>
</center>

Download the package with the icon files [https://forum.freecadweb.org/download/file.php?id=79288 FCCamera_Icones.zip]. Unziped the package and paste the total icon in the same directory as the macro.


[[File:FCCamera_00.png|Logo FCCamera]] [[File:FCCamera_01.png|Accept]] [[File:FCCamera_02.png|Detect]] [[File:FCCamera_03.png|To Face]]
[[File:FCCamera_00.png|Logo FCCamera]] [[File:FCCamera_01.png|Accept]] [[File:FCCamera_02.png|Detect]] [[File:FCCamera_03.png|To Face]]
[[File:FCCamera_04.png|To Axis]] [[File:FCCamera_05.png|Align Object to View]] [[File:FCCamera_06.png|Create plane]] [[File:FCCamera_07.png|Reset]]
[[File:FCCamera_04.png|To Axis]] [[File:FCCamera_05.png|Align Object to View]] [[File:FCCamera_06.png|Create plane]] [[File:FCCamera_07.png|Reset]]
Line 81: Line 170:
[[File:FCCamera Axis rotation Y.png|Axis Y]]
[[File:FCCamera Axis rotation Y.png|Axis Y]]
[[File:FCCamera Axis rotation Z.png|Axis Z]]
[[File:FCCamera Axis rotation Z.png|Axis Z]]
[[File:FCCamera Axis rotation D.png|Direction Axis]]


<translate>
<translate>
==Examples== <!--T:24-->



==Links== <!--T:25-->
==Links== <!--T:25-->
Line 96: Line 184:


==Script== <!--T:22-->
==Script== <!--T:22-->
</translate>


<!--T:58-->
'''Macro FCCamera.FCMacro'''
Download the icon files [https://forum.freecadweb.org/download/file.php?id=79288 FCCamera_Icones.zip]


<!--T:42-->
{{Code|code=
Download the macro to Gist [https://gist.github.com/mario52a/4aa545c23b323cf68824 '''Macro FCCamera.FCMacro''']
# -*- coding: utf-8 -*-
"""
***************************************************************************
* Copyright (c) 2015 <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.1 26/01/2015
#
#OS: Windows Vista
#Word size of OS: 32-bit
#Word size of FreeCAD: 32-bit
#Version: 0.15.4502 (Git)
#Branch: master
#Hash: 3c754da0cbc86e06ade2543baecbca25701b7160
#Python version: 2.7.8
#Qt version: 4.8.6
#Coin version: 4.0.0a
#OCC version: 6.7.1
#
__title__="FCCamera"
__author__ = "Mario52"


==Examples== <!--T:31-->
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")


===How to place an angle hole=== <!--T:32-->
import Draft, Part, FreeCAD, math, PartGui, FreeCADGui, DraftVecUtils
#import os, WorkingPlane


<!--T:33-->
from math import radians, degrees, sqrt, pi, sin, cos, asin
<center>
from FreeCAD import Base
<gallery widths="300" heights="280">
from FreeCAD import Vector
File:FCCamera 09.png|Create your object
import pivy
File:FCCamera 10.png|Create one cylinder and positionning this <br />Give your axis, angle inclination and click the button [[File:FCCamera_01.png|24px]] {{KEY|Accept the rotation}}
from pivy import coin
</gallery>
</center>


<!--T:34-->
global path ; path = ""
<center>
global valeur ; valeur = 0.0
<gallery widths="300" heights="280">
global valeurV ; valeurV = 0.0
File:FCCamera 11.png|Select your cylinder for create your hole
global Rname ; Rname = ["","",""]
File:FCCamera 12.png|In FCCamera click the button [[File:FCCamera_05.png|24px]] {{KEY|Align Object to View}}
global RnameCube; RnameCube = ""
</gallery>
global RnameCompound; RnameCompound = ""
</center>
global datExtract; datExtract = ""


<!--T:35-->
global positionX ; positionX = 0.0
<center>
global positionY ; positionY = 0.0
<gallery widths="300" heights="280">
global positionZ ; positionZ = 0.0
File:FCCamera 13.png|The cylinder moves to 15 degrees (take the camera position)<br />do your Boolean operation
File:FCCamera 14.png|Your hole 15 degrees
</gallery>
</center>


<!--T:36-->
try:
The same result can be achieved by creating a plan in the corner gave the mouse click position and a sketch.
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s


<!--T:53-->
try:
<center>
_encoding = QtGui.QApplication.UnicodeUTF8
<gallery widths="750" heights="700">
def _translate(context, text, disambig):
File:Macro_FCCamera_Align_To_Face.gif|Example placement spring to face axis
return QtGui.QApplication.translate(context, text, disambig, _encoding)
</gallery>
except AttributeError:
</center>
def _translate(context, text, disambig):
<center>
return QtGui.QApplication.translate(context, text, disambig)
<gallery widths="850" heights="550">
File:Test_FCCamera_Photo_01.gif|Example photo rotation and save images (you must create one animate Gif [https://www.gimp.org/ with GIMP])
</gallery>
</center>
</translate>
<translate>
==Version== <!--T:37-->
</translate>
<translate>


<!--T:60-->
class SelObserver: # SelObserver
*'''ver 00.12.1 (12/02/2020):''' suppress the bad character lines 674 and 675 (accent...) again
def addSelection(self,document, object, element, position): # Selection SelObserver
global positionX
global positionY
global positionZ
positionX = position[0]
positionY = position[1]
positionZ = position[2]


<!--T:59-->
def datExtract(data):
*'''ver 12 (01/08/2019):''' compatible Python 3 ( print to print() )
# 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


<!--T:55-->
global Nameelement2; Nameelement2 = "" # new selection
*'''ver 11 (13/01/2018):''' minor
global vueView ; vueView = 0 # passe vue


<!--T:56-->
def To_Face_Or_To_Axis(ToFace): # 1=NormalAt 0=Axis #Align Face selected to Face or to Axis
*'''ver 10 (13/01/2018):''' add "def centerBoundBoxGlobal():"
global vueView
global Nameelement2


<!--T:57-->
try:
*'''ver 09 (08/01/2018):''' minor
SubElement = FreeCADGui.Selection.getSelectionEx()
Nameelement = SubElement[0].SubElementNames[0]
if Nameelement != Nameelement2:
vueView = 0
Nameelement2 = Nameelement


<!--T:52-->
if ToFace == 1:
*'''ver 08 (08/01/2018):''' supp "Pyqt4" and adjust number image
v = Gui.Selection.getSelectionEx()[0].SubObjects[0].normalAt(0,0) # NormalAt
*'''ver 07 (03/01/2018):''' add photo panel and rotation to axis selected (wire, edge, line )
App.Console.PrintMessage("Nor At ")
else:
v=Gui.Selection.getSelectionEx()[0].SubObjects[0].Surface.Axis # Axis
App.Console.PrintMessage("S Axis ")


<!--T:43-->
if vueView == 0:
*'''ver 0.6 (13/12/2016):''' new system for search the macro path directly in the preferences
r=App.Rotation(App.Vector(0,0,1),v)
</translate>
App.Console.PrintMessage("0,0,1"+"\n")
#path = FreeCAD.ConfigGet("AppHomePath")
elif vueView == 1:
#path = FreeCAD.ConfigGet("UserAppData")
r=App.Rotation(App.Vector(0,0,-1),v)
#path = "your path"
App.Console.PrintMessage("0,0,-1"+"\n")
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro")# macro path
elif vueView == 2:
path = param.GetString("MacroPath","") + "/" # macro path
r=App.Rotation(App.Vector(0,1,0),v)
path = path.replace("\\","/")
App.Console.PrintMessage("0,1,0"+"\n")
App.Console.PrintMessage("Path locality to FCCamera.....images.png [ " + path + " ]"+"\n")
elif vueView == 3:
<translate>
r=App.Rotation(App.Vector(0,-1,0),v)
<!--T:38-->
App.Console.PrintMessage("0,-1,0"+"\n")
*'''ver 0.5 06/09/2016:''' correct name "FCCamera_Axis_rotation_X.png" in reset block
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


<!--T:41-->
Gui.ActiveDocument.ActiveView.setCameraOrientation(r.Q)#
*'''ver 0.4 28/02/2016 :''' add display all camera detection and the [http://forum.freecadweb.org/viewtopic.php?f=13&t=14213#p114667 Direction]
vueView += 1
except:
App.Console.PrintError("Select a face"+"\n")


<!--T:40-->
class Ui_MainWindow(object):
*'''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
def setupUi(self, MainWindow):
global path
self.window = MainWindow
path = FreeCAD.ConfigGet("AppHomePath")
#path = FreeCAD.ConfigGet("UserAppData")
#App.Console.PrintMessage(str(path)+"\n")


<!--T:39-->
MainWindow.setObjectName(_fromUtf8("MainWindow"))
*'''ver 0.2 25/02/2015 :''' correct names files in for compatibility Linux (case sensitive) thanks microelly2
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"))


</translate>
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()
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")
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
App.Console.PrintMessage(str(Nameelement)+"\n")
pl = FreeCAD.Placement()
pl.Rotation = FreeCADGui.ActiveDocument.ActiveView.getCameraOrientation()
pl.Base = FreeCAD.Vector(0.0,0.0,0.0)
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

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+"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()


}}


<languages/>

Revision as of 14:14, 12 February 2020

Other languages:

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 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.

Macro version: 0.12.1
Last modified: 2020/02/12
FreeCAD version: All
Download: FCCamera_Icones.zip. Unziped the package and paste the total icon in the same directory as the macro.
Author: Mario52
Author
Mario52
Download
FCCamera_Icones.zip. Unziped the package and paste the total icon in the same directory as the macro.
Links
Macro Version
0.12.1
Date last modified
2020/02/12
FreeCAD Version(s)
All
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.

Temporary code for external macro link. Do not use this code. This code is used exclusively by Addon Manager. Link for optional manual installation: Macro


# This code is copied instead of the original macro code
# to guide the user to the online download page.
# Use it if the code of the macro is larger than 64 KB and cannot be included in the wiki
# or if the RAW code URL is somewhere else in the wiki.

from PySide import QtGui, QtCore

diag = QtGui.QMessageBox(QtGui.QMessageBox.Information,
    "Information",
    "This macro must be downloaded from this link\n"
    "\n"
    "https://gist.githubusercontent.com/mario52a/4aa545c23b323cf68824/raw/42dc3ef73dc8db463a03b175f5a7f1f6978e3293/Macro%2520FCCamera.FCMacro" + "\n"
    "\n"
    "Quit this window to access the download page")

diag.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
diag.setWindowModality(QtCore.Qt.ApplicationModal)
diag.exec_()

import webbrowser 
webbrowser.open("https://gist.githubusercontent.com/mario52a/4aa545c23b323cf68824/raw/42dc3ef73dc8db463a03b175f5a7f1f6978e3293/Macro%2520FCCamera.FCMacro")


Usage

FCCamera
FCCamera

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

  • Accept the rotation : Accept the rotation give to angle selected

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
  • Reset. : Reset all values.
  • Photo. : Section save the screen rotation an image in angle value
  • Quit. : Quit FCCamera.

Section Photo

FCCamera
FCCamera
  • ComboBox Actual  : choice your screen definition for the image format
    • Available (pre-defined):
      • "Actual" (definition actual of screen)
      • "Icon 16 x 16"
      • "Icon 32 x 32"
      • "Icon 64 x 64"
      • "Icon 128 x 128"
      • "CGA 320 x 200"
      • "QVGA 320 x 240"
      • "VGA 640 x 480"
      • "SVGA 800 x 600"
      • "XGA 1024 x 768"
      • "XGA+ 1152 x 864"
      • "SXGA 1280 x 1024"
      • "SXGA+ 1400 x 1050"
      • "UXGA 1600 x 1200"
      • "QXGA 2048 x 1536"
      • "Free"
  • SpinBox X and Y
  • ComboBox Format image
    • Available :
      • "BMP *.bmp"
      • "ICO *.ico"
      • "JPEG *.jpeg"
      • "JPG *.jpg"
      • "PNG *.png" (by default)
      • "PPM *.ppm"
      • "TIF *.tif"
      • "TIFF *.tiff"
      • "XBM *.xbm"
      • "XPM *.xpm"
  • Line 1 : Number image calculated by the angle give (ex: angle 60 degrees = 360 (complete rotation) / 60 (angle) = 6 images
  • Line 2 : The definition of screen used
  • Background image :
    • Actual : save image with the screen colour actual
    • White : save image with the screen colour white
    • Black : save image with the screen colour black
  • Launch : Open the file window , give the name and the path
  • Reset : Reset the default value
  • Return : Quit the photo panel and return to FCCamera panel

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 choose "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 :


Download the package with the icon files FCCamera_Icones.zip. Unziped the package and paste the total icon in the same directory as the macro.


Logo FCCamera Accept Detect To Face To Axis Align Object to View Create plane Reset Quit

Icons tableau : Axis X Axis Y Axis Z Direction Axis


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 icon files FCCamera_Icones.zip

Download the macro to Gist Macro FCCamera.FCMacro

Examples

How to place an angle hole

The same result can be achieved by creating a plan in the corner gave the mouse click position and a sketch.

Version

  • ver 00.12.1 (12/02/2020): suppress the bad character lines 674 and 675 (accent...) again
  • ver 12 (01/08/2019): compatible Python 3 ( print to print() )
  • ver 11 (13/01/2018): minor
  • ver 10 (13/01/2018): add "def centerBoundBoxGlobal():"
  • ver 09 (08/01/2018): minor
  • ver 08 (08/01/2018): supp "Pyqt4" and adjust number image
  • ver 07 (03/01/2018): add photo panel and rotation to axis selected (wire, edge, line )
  • ver 0.6 (13/12/2016): new system for search the macro path directly in the preferences
#path = FreeCAD.ConfigGet("AppHomePath")
#path = FreeCAD.ConfigGet("UserAppData")
#path = "your path"
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro")# macro path
path = param.GetString("MacroPath","") + "/"                        # macro path
path = path.replace("\\","/")
App.Console.PrintMessage("Path locality to FCCamera.....images.png [ " + path + " ]"+"\n")
  • 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