finish move tool
This commit is contained in:
parent
fbdbb8b4ab
commit
a7fbc02e6d
|
@ -6,14 +6,14 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>136</width>
|
<width>150</width>
|
||||||
<height>223</height>
|
<height>297</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_FlipX">
|
<widget class="QPushButton" name="pushButton_FlipX">
|
||||||
<property name="font">
|
<property name="font">
|
||||||
|
@ -63,13 +63,29 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="groupBox">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Volume</string>
|
<string>Volume</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
<item>
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
|
@ -78,11 +94,18 @@
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>X-Size: 0mm</string>
|
<string>X-Size:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
|
@ -91,11 +114,18 @@
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Y-Size: 0mm</string>
|
<string>Y-Size:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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">
|
<widget class="QLabel" name="label_3">
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
|
@ -104,7 +134,34 @@
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<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>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -20,6 +20,7 @@ SET(MachDist_SRCS
|
||||||
MachDistAnalysis.py
|
MachDistAnalysis.py
|
||||||
MachDistIsostatic.py
|
MachDistIsostatic.py
|
||||||
MachDistAlignment.py
|
MachDistAlignment.py
|
||||||
|
MachDistMoveTools.py
|
||||||
Parameter.ui
|
Parameter.ui
|
||||||
Material.ui
|
Material.ui
|
||||||
Aligment.ui
|
Aligment.ui
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
import FreeCAD, Fem
|
import FreeCAD, Fem, MachDistMoveTools
|
||||||
|
|
||||||
if FreeCAD.GuiUp:
|
if FreeCAD.GuiUp:
|
||||||
import FreeCADGui, FemGui
|
import FreeCADGui, FemGui
|
||||||
|
@ -45,7 +45,7 @@ class _CommandAlignment:
|
||||||
|
|
||||||
def Activated(self):
|
def Activated(self):
|
||||||
FemMeshObject = None
|
FemMeshObject = None
|
||||||
import FemGui, Mesh
|
import FemGui
|
||||||
# check if a active analysis is present and no Mesh in it
|
# check if a active analysis is present and no Mesh in it
|
||||||
if FemGui.getActiveAnalysis() != None:
|
if FemGui.getActiveAnalysis() != None:
|
||||||
for i in FemGui.getActiveAnalysis().Member:
|
for i in FemGui.getActiveAnalysis().Member:
|
||||||
|
@ -56,18 +56,6 @@ class _CommandAlignment:
|
||||||
return
|
return
|
||||||
FreeCAD.ActiveDocument.openTransaction("Alignment")
|
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)
|
taskd = _AlignTaskPanel(FemMeshObject)
|
||||||
FreeCADGui.Control.showDialog(taskd)
|
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_FlipX, QtCore.SIGNAL("clicked()"), self.flipX)
|
||||||
QtCore.QObject.connect(self.formUi.pushButton_FlipY, QtCore.SIGNAL("clicked()"), self.flipY)
|
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.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()
|
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):
|
def getStandardButtons(self):
|
||||||
return int(QtGui.QDialogButtonBox.Ok) | int(QtGui.QDialogButtonBox.Cancel)
|
return int(QtGui.QDialogButtonBox.Ok) | int(QtGui.QDialogButtonBox.Cancel)
|
||||||
|
@ -111,30 +126,70 @@ class _AlignTaskPanel:
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
FreeCADGui.Control.closeDialog()
|
FreeCADGui.Control.closeDialog()
|
||||||
self.obj.ViewObject.BoundingBox = False
|
#self.obj.ViewObject.BoundingBox = False
|
||||||
FreeCAD.ActiveDocument.commitTransaction()
|
FreeCAD.ActiveDocument.commitTransaction()
|
||||||
|
|
||||||
|
|
||||||
def reject(self):
|
def reject(self):
|
||||||
FreeCADGui.Control.closeDialog()
|
FreeCADGui.Control.closeDialog()
|
||||||
self.obj.ViewObject.BoundingBox = False
|
#self.obj.ViewObject.BoundingBox = False
|
||||||
FreeCAD.ActiveDocument.abortTransaction()
|
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):
|
def flipX(self):
|
||||||
|
QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)
|
||||||
p = self.obj.Placement
|
p = self.obj.Placement
|
||||||
r2 = p.Rotation.multiply(FreeCAD.Rotation(FreeCAD.Vector(1,0,0),180))
|
p.Rotation = p.Rotation.multiply(FreeCAD.Rotation(FreeCAD.Vector(1,0,0),90))
|
||||||
p.Rotation = r2
|
MachDistMoveTools.moveHome(self.obj)
|
||||||
return
|
if(self.formUi.checkBox_AutoMinimize.isChecked()):
|
||||||
|
MachDistMoveTools.minimizeBoundVolume(self.obj)
|
||||||
|
self.showData()
|
||||||
|
QtGui.qApp.restoreOverrideCursor()
|
||||||
|
|
||||||
def flipY(self):
|
def flipY(self):
|
||||||
|
QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)
|
||||||
p = self.obj.Placement
|
p = self.obj.Placement
|
||||||
r2 = p.Rotation.multiply(FreeCAD.Rotation(FreeCAD.Vector(0,1,0),180))
|
p.Rotation = p.Rotation.multiply(FreeCAD.Rotation(FreeCAD.Vector(0,1,0),90))
|
||||||
p.Rotation = r2
|
|
||||||
return
|
MachDistMoveTools.moveHome(self.obj)
|
||||||
|
if(self.formUi.checkBox_AutoMinimize.isChecked()):
|
||||||
|
MachDistMoveTools.minimizeBoundVolume(self.obj)
|
||||||
|
self.showData()
|
||||||
|
QtGui.qApp.restoreOverrideCursor()
|
||||||
|
|
||||||
def flipZ(self):
|
def flipZ(self):
|
||||||
|
QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)
|
||||||
p = self.obj.Placement
|
p = self.obj.Placement
|
||||||
r2 = p.Rotation.multiply(FreeCAD.Rotation(FreeCAD.Vector(0,0,1),180))
|
p.Rotation = p.Rotation.multiply(FreeCAD.Rotation(FreeCAD.Vector(0,0,1),90))
|
||||||
zl = self.obj.FemMesh.BoundBox.ZLength
|
|
||||||
p.Rotation = r2
|
MachDistMoveTools.moveHome(self.obj)
|
||||||
return
|
if(self.formUi.checkBox_AutoMinimize.isChecked()):
|
||||||
|
MachDistMoveTools.minimizeBoundVolume(self.obj)
|
||||||
|
self.showData()
|
||||||
|
QtGui.qApp.restoreOverrideCursor()
|
||||||
|
|
||||||
|
|
||||||
FreeCADGui.addCommand('MachDist_Alignment',_CommandAlignment())
|
FreeCADGui.addCommand('MachDist_Alignment',_CommandAlignment())
|
||||||
|
|
|
@ -30,4 +30,34 @@ __url__ = "http://free-cad.sourceforge.net"
|
||||||
|
|
||||||
|
|
||||||
def moveHome(obj):
|
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
|
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