forked from PrinceofOrange/FreeCAD-macros
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFCCamera.FCMacro
More file actions
663 lines (567 loc) · 29 KB
/
Copy pathFCCamera.FCMacro
File metadata and controls
663 lines (567 loc) · 29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
# -*- 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.3 18/03/2015
#
#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.03"
__date__ = "18/03/2015"
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")
#import PySide # PySide
#from PySide import QtCore, QtGui # PySide
#App.Console.PrintMessage("PySide"+"\n")
###########
import sys, traceback
def saye(s):
FreeCAD.Console.PrintError(str(s)+"\n")
def dlgexc(mess=''):
exc_type, exc_value, exc_traceback = sys.exc_info()
ttt=repr(traceback.format_exception(exc_type, exc_value,exc_traceback))
lls=eval(ttt)
lls2=eval(ttt)
l=len(lls)
l2=lls[(l-1):]
FreeCAD.Console.PrintError(mess + "\n" +"--> ".join(lls2))
msg=mess + "\n\n" +"--> ".join(l2)
diag = QtGui.QMessageBox(QtGui.QMessageBox.Critical,u"Plugin Loader Error",msg )
diag.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint)
diag.exec_()
def sayexc(mess=''):
exc_type, exc_value, exc_traceback = sys.exc_info()
ttt=repr(traceback.format_exception(exc_type, exc_value,exc_traceback))
lls=eval(ttt)
saye(mess + "\n" +"--> ".join(lls))
###########
import Draft, Part, FreeCAD, math, PartGui, FreeCADGui, DraftVecUtils
#import os, WorkingPlane
from math import radians, degrees, sqrt, pi, sin, cos, asin
from FreeCAD import Base
from FreeCAD import Vector
import pivy
from pivy import coin
import FreeCADGui
App=FreeCAD
Gui=FreeCADGui
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:
sayexc()
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" #
path="/usr/lib/freecad/Mod/plugins/FreeCAD-macros-git/icons/Camera/"
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()
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
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
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()
t=FreeCADGui.getMainWindow()
t.activateWindow()