forked from FreeCAD/FreeCAD-macros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FCRotateViewAbsolute.FCMacro
193 lines (146 loc) · 4.62 KB
/
FCRotateViewAbsolute.FCMacro
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
__Name__ = 'FCRotateViewAbsolute'
__Comment__ = ''
__License__ = ''
__Web__ = ''
__Wiki__ = ''
__Icon__ = ''
__Help__ = ''
__Author__ = ''
__Version__ = ''
__Status__ = ''
__Requires__ = ''
__Files__ = ''
from FreeCAD import Base
import FreeCADGui as Gui
from math import cos,sin,pi
import sys
from PySide.QtCore import *
from PySide.QtGui import *
from pivy import coin
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.alpha=00
self.beta=180
self.setWindowFlags(Qt.WindowStaysOnTopHint)
dial = QDial()
dial.setNotchesVisible(True)
self.dial=dial
dial.setMaximum(360)
dial.setValue(self.alpha)
dial2 = QDial()
dial2.setNotchesVisible(True)
self.dial2=dial2
dial2.setMaximum(360)
dial2.setValue(self.beta)
spinbox = QSpinBox()
spinbox.setMaximum(360)
layout = QHBoxLayout()
self.pushButton00 = QPushButton(QIcon('icons:freecad.svg'),"Dimetric")
self.pushButton01 = QPushButton(QIcon('icons:freecad.svg'),"Trimetric")
self.pushButton02 = QPushButton(QIcon('icons:freecad.svg'),"Isometric")
self.pushButton03 = QPushButton(QIcon('icons:freecad.svg'),"Front")
self.pushButton00.clicked.connect(self.dimetric)
self.pushButton01.clicked.connect(self.trimetric)
self.pushButton02.clicked.connect(self.isometric)
self.pushButton03.clicked.connect(self.front)
layout.addWidget(self.pushButton03)
layout.addWidget(self.pushButton00)
layout.addWidget(self.pushButton01)
layout.addWidget(self.pushButton02)
layout.addWidget(dial)
layout.addWidget(dial2)
# layout.addWidget(spinbox)
self.setLayout(layout)
#self.connect(dial, SIGNAL("valueChanged(int)"), spinbox.setValue)
#self.connect(spinbox, SIGNAL("valueChanged(int)"), dial.setValue)
dial.valueChanged.connect(spinbox.setValue);
dial.valueChanged.connect(self.dreher);
dial2.valueChanged.connect(self.heber);
self.cami()
self.setWindowTitle("Camera position")
Gui.SendMsgToActiveView("ViewFit")
def dreher(self):
self.alpha=self.dial.value()
self.cami()
def heber(self):
self.beta=self.dial2.value()
self.cami()
def rotY(self,delta=10):
if self.beta==1:
self.beta=0
self.beta += delta
if self.beta >360:
self.beta -= 360
if self.beta <0:
self.beta += 360
if self.beta==0:
self.beta=1
FreeCAD.Console.PrintMessage(str(self.beta)+" # ");
self.dial2.setValue(self.beta)
def rotZ(self,delta=10):
self.alpha += delta
if self.alpha >360:
self.alpha -= 360
if self.alpha <0:
self.alpha += 360
self.dial.setValue(self.alpha)
def cami(self):
from pivy import coin
alpha=self.alpha
beta=self.beta
camera = FreeCADGui.ActiveDocument.ActiveView.getCameraNode()
Gui=FreeCADGui
if False:
typeCamera="Orthographic"
if typeCamera=="Orthographic":
Gui.activeDocument().activeView().setCameraType("Orthographic")
else:
Gui.activeDocument().activeView().setCameraType("Perspective")
campos=Base.Vector( 1000 * cos (pi*alpha/360*2)*sin(pi*beta/360*1), 1000*sin(pi*alpha/360*2)*sin(pi*beta/360*1), 1000*cos(pi*beta/360*1))
camera.position.setValue( campos)
pos3=FreeCAD.Vector(0,0,0)
pos3.sub(campos)
#if False:
camera.pointAt(coin.SbVec3f(pos3),coin.SbVec3f(0,0,1))
App.ActiveDocument.recompute()
FreeCADGui.updateGui()
def front(self):
from pivy import coin
pos3=FreeCAD.Vector(0,0,0)
campos=FreeCAD.Vector(0,-10,0)
camera = FreeCADGui.ActiveDocument.ActiveView.getCameraNode()
camera.position.setValue( campos)
camera.pointAt(coin.SbVec3f(pos3),coin.SbVec3f(0,0,1))
def isometric(self):
pos3=FreeCAD.Vector(0,0,0)
campos=FreeCAD.Vector(100,-100,100)
camera = FreeCADGui.ActiveDocument.ActiveView.getCameraNode()
camera.position.setValue( campos)
pos3.sub(campos)
camera.pointAt(coin.SbVec3f(pos3),coin.SbVec3f(0,0,1))
def dimetric(self):
pos3=FreeCAD.Vector(0,0,0)
campos=FreeCAD.Vector(68,-68,27)
camera = FreeCADGui.ActiveDocument.ActiveView.getCameraNode()
camera.position.setValue( campos)
pos3.sub(campos)
camera.pointAt(coin.SbVec3f(pos3),coin.SbVec3f(0,0,1))
App.ActiveDocument.recompute()
FreeCADGui.updateGui()
def trimetric(self):
pos3=FreeCAD.Vector(0,0,0)
campos=FreeCAD.Vector(210,-790,580)
camera = FreeCADGui.ActiveDocument.ActiveView.getCameraNode()
camera.position.setValue( campos)
pos3.sub(campos)
camera.pointAt(coin.SbVec3f(pos3),coin.SbVec3f(0,0,1))
if hasattr(FreeCAD,"ViewMgr")and FreeCAD.ViewMgr:
FreeCAD.ViewMgr.show()
FreeCAD.Console.PrintMessage("neu gestrte")
else:
FreeCAD.ViewMgr=Form()
FreeCAD.ViewMgr.show()
FreeCAD.Console.PrintMessage(" war schon da")
t=FreeCADGui.getMainWindow()
t.activateWindow()