finish move tool
This commit is contained in:
parent
fbdbb8b4ab
commit
a7fbc02e6d
|
@ -6,14 +6,14 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>136</width>
|
||||
<height>223</height>
|
||||
<width>150</width>
|
||||
<height>297</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_FlipX">
|
||||
<property name="font">
|
||||
|
@ -63,13 +63,29 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_Minimize">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>30</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Minimize</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Volume</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="font">
|
||||
<font>
|
||||
|
@ -78,11 +94,18 @@
|
|||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>X-Size: 0mm</string>
|
||||
<string>X-Size:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_XS">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="font">
|
||||
<font>
|
||||
|
@ -91,11 +114,18 @@
|
|||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Y-Size: 0mm</string>
|
||||
<string>Y-Size:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_YS">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="font">
|
||||
<font>
|
||||
|
@ -104,7 +134,34 @@
|
|||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Z-Size: 0mm </string>
|
||||
<string>Z-Size:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_ZS">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Volume:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_VS">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -20,6 +20,7 @@ SET(MachDist_SRCS
|
|||
MachDistAnalysis.py
|
||||
MachDistIsostatic.py
|
||||
MachDistAlignment.py
|
||||
MachDistMoveTools.py
|
||||
Parameter.ui
|
||||
Material.ui
|
||||
Aligment.ui
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
import FreeCAD, Fem
|
||||
import FreeCAD, Fem, MachDistMoveTools
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
import FreeCADGui, FemGui
|
||||
|
@ -45,7 +45,7 @@ class _CommandAlignment:
|
|||
|
||||
def Activated(self):
|
||||
FemMeshObject = None
|
||||
import FemGui, Mesh
|
||||
import FemGui
|
||||
# check if a active analysis is present and no Mesh in it
|
||||
if FemGui.getActiveAnalysis() != None:
|
||||
for i in FemGui.getActiveAnalysis().Member:
|
||||
|
@ -56,18 +56,6 @@ class _CommandAlignment:
|
|||
return
|
||||
FreeCAD.ActiveDocument.openTransaction("Alignment")
|
||||
|
||||
# switch on Bound Box
|
||||
FemMeshObject.ViewObject.BoundingBox = True
|
||||
QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)
|
||||
n = FemMeshObject.FemMesh.Nodes
|
||||
p = Mesh.calculateEigenTransform(n)
|
||||
#FemMeshObject.Placement = p
|
||||
m = Fem.FemMesh(FemMeshObject.FemMesh)
|
||||
m.setTransform(p)
|
||||
FemMeshObject.FemMesh = m
|
||||
FemMeshObject.Placement = FreeCAD.Placement()
|
||||
|
||||
QtGui.qApp.restoreOverrideCursor()
|
||||
|
||||
taskd = _AlignTaskPanel(FemMeshObject)
|
||||
FreeCADGui.Control.showDialog(taskd)
|
||||
|
@ -98,9 +86,36 @@ class _AlignTaskPanel:
|
|||
QtCore.QObject.connect(self.formUi.pushButton_FlipX, QtCore.SIGNAL("clicked()"), self.flipX)
|
||||
QtCore.QObject.connect(self.formUi.pushButton_FlipY, QtCore.SIGNAL("clicked()"), self.flipY)
|
||||
QtCore.QObject.connect(self.formUi.pushButton_FlipZ, QtCore.SIGNAL("clicked()"), self.flipZ)
|
||||
QtCore.QObject.connect(self.formUi.checkBox_AutoMinimize, QtCore.SIGNAL("stateChanged(int)"), self.autoMinToogle)
|
||||
QtCore.QObject.connect(self.formUi.pushButton_Minimize, QtCore.SIGNAL("clicked()"), self.minimize)
|
||||
|
||||
self.update()
|
||||
|
||||
# switch on Bound Box
|
||||
#self.obj.ViewObject.BoundingBox = True
|
||||
|
||||
# calculate eigen transformation and transform the mesh
|
||||
QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)
|
||||
import Mesh
|
||||
n = self.obj.FemMesh.Nodes
|
||||
p = Mesh.calculateEigenTransform(n)
|
||||
|
||||
# move in the first quandrant and minimize bound box
|
||||
MachDistMoveTools.moveHome(self.obj)
|
||||
MachDistMoveTools.minimizeBoundVolume(self.obj)
|
||||
MachDistMoveTools.moveHome(self.obj)
|
||||
self.showData()
|
||||
|
||||
#self.obj.Placement = p
|
||||
m = Fem.FemMesh(self.obj.FemMesh)
|
||||
m.setTransform(self.obj.Placement)
|
||||
|
||||
self.obj.FemMesh = m
|
||||
self.obj.Placement = FreeCAD.Placement()
|
||||
|
||||
QtGui.qApp.restoreOverrideCursor()
|
||||
|
||||
|
||||
|
||||
def getStandardButtons(self):
|
||||
return int(QtGui.QDialogButtonBox.Ok) | int(QtGui.QDialogButtonBox.Cancel)
|
||||
|
@ -111,30 +126,70 @@ class _AlignTaskPanel:
|
|||
|
||||
def accept(self):
|
||||
FreeCADGui.Control.closeDialog()
|
||||
self.obj.ViewObject.BoundingBox = False
|
||||
#self.obj.ViewObject.BoundingBox = False
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
|
||||
|
||||
def reject(self):
|
||||
FreeCADGui.Control.closeDialog()
|
||||
self.obj.ViewObject.BoundingBox = False
|
||||
#self.obj.ViewObject.BoundingBox = False
|
||||
FreeCAD.ActiveDocument.abortTransaction()
|
||||
|
||||
def autoMinToogle(self,state):
|
||||
if state == 0: self.formUi.pushButton_Minimize.setEnabled(True)
|
||||
if state == 2: self.formUi.pushButton_Minimize.setEnabled(False)
|
||||
|
||||
def minimize(self):
|
||||
QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)
|
||||
MachDistMoveTools.minimizeBoundVolume(self.obj)
|
||||
self.showData()
|
||||
QtGui.qApp.restoreOverrideCursor()
|
||||
|
||||
|
||||
def showData(self):
|
||||
b = self.obj.FemMesh.BoundBox
|
||||
self.formUi.lineEdit_XS.setText("%f"%b.XLength)
|
||||
self.formUi.lineEdit_YS.setText("%f"%b.YLength)
|
||||
self.formUi.lineEdit_ZS.setText("%f"%b.ZLength)
|
||||
self.formUi.lineEdit_VS.setText("%f"% float(b.XLength*b.YLength*b.ZLength))
|
||||
|
||||
def afterFlip(self):
|
||||
QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)
|
||||
MachDistMoveTools.minimizeBoundVolume(self.obj)
|
||||
MachDistMoveTools.moveHome(self.obj)
|
||||
QtGui.qApp.restoreOverrideCursor()
|
||||
|
||||
def flipX(self):
|
||||
QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)
|
||||
p = self.obj.Placement
|
||||
r2 = p.Rotation.multiply(FreeCAD.Rotation(FreeCAD.Vector(1,0,0),180))
|
||||
p.Rotation = r2
|
||||
return
|
||||
p.Rotation = p.Rotation.multiply(FreeCAD.Rotation(FreeCAD.Vector(1,0,0),90))
|
||||
MachDistMoveTools.moveHome(self.obj)
|
||||
if(self.formUi.checkBox_AutoMinimize.isChecked()):
|
||||
MachDistMoveTools.minimizeBoundVolume(self.obj)
|
||||
self.showData()
|
||||
QtGui.qApp.restoreOverrideCursor()
|
||||
|
||||
def flipY(self):
|
||||
QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)
|
||||
p = self.obj.Placement
|
||||
r2 = p.Rotation.multiply(FreeCAD.Rotation(FreeCAD.Vector(0,1,0),180))
|
||||
p.Rotation = r2
|
||||
return
|
||||
p.Rotation = p.Rotation.multiply(FreeCAD.Rotation(FreeCAD.Vector(0,1,0),90))
|
||||
|
||||
MachDistMoveTools.moveHome(self.obj)
|
||||
if(self.formUi.checkBox_AutoMinimize.isChecked()):
|
||||
MachDistMoveTools.minimizeBoundVolume(self.obj)
|
||||
self.showData()
|
||||
QtGui.qApp.restoreOverrideCursor()
|
||||
|
||||
def flipZ(self):
|
||||
QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)
|
||||
p = self.obj.Placement
|
||||
r2 = p.Rotation.multiply(FreeCAD.Rotation(FreeCAD.Vector(0,0,1),180))
|
||||
zl = self.obj.FemMesh.BoundBox.ZLength
|
||||
p.Rotation = r2
|
||||
return
|
||||
p.Rotation = p.Rotation.multiply(FreeCAD.Rotation(FreeCAD.Vector(0,0,1),90))
|
||||
|
||||
MachDistMoveTools.moveHome(self.obj)
|
||||
if(self.formUi.checkBox_AutoMinimize.isChecked()):
|
||||
MachDistMoveTools.minimizeBoundVolume(self.obj)
|
||||
self.showData()
|
||||
QtGui.qApp.restoreOverrideCursor()
|
||||
|
||||
|
||||
FreeCADGui.addCommand('MachDist_Alignment',_CommandAlignment())
|
||||
|
|
|
@ -30,4 +30,34 @@ __url__ = "http://free-cad.sourceforge.net"
|
|||
|
||||
|
||||
def moveHome(obj):
|
||||
b = obj.FemMesh.BoundBox
|
||||
m = FreeCAD.Vector(-(b.XMin),-(b.YMin),-(b.ZMin))
|
||||
p = obj.Placement
|
||||
p2 = FreeCAD.Placement(p.Base + m,p.Rotation)
|
||||
obj.Placement = p2
|
||||
return
|
||||
|
||||
def getBoundBoxVolume(obj):
|
||||
b = obj.FemMesh.BoundBox
|
||||
return b.XLength * b.YLength * b.ZLength
|
||||
|
||||
def minimizeBoundVolume(obj):
|
||||
p = obj.Placement
|
||||
VolOld = getBoundBoxVolume(obj)
|
||||
OverallSteps = 0
|
||||
# rotate a fraction and test if it get better
|
||||
for a in (3.0,1.0,0.5,0.1,0.05,0.01,0.005,0.001):
|
||||
for v in ( (0.0, 0.0, 1.0),(0.0, 1.0, 0.0),(1.0, 0.0, 0.0) ):
|
||||
for dir in (-1.0,1.0):
|
||||
Better = True
|
||||
i = 0
|
||||
while(Better):
|
||||
p.Rotation = p.Rotation.multiply(FreeCAD.Rotation(FreeCAD.Vector(v[0],v[1],v[2]),a*dir))
|
||||
NewVol = getBoundBoxVolume(obj)
|
||||
i = i+1
|
||||
if(NewVol>VolOld):
|
||||
Better = False
|
||||
print "Axis: (",v[0],v[1],v[2],") Angle: ",a*dir," -> End with after ",i," Steps with V=",NewVol
|
||||
VolOld = NewVol
|
||||
OverallSteps = OverallSteps + i
|
||||
print "OverallSteps: ",OverallSteps
|
Loading…
Reference in New Issue
Block a user