Merge branch 'master' of ssh://free-cad.git.sourceforge.net/gitroot/free-cad/free-cad
This commit is contained in:
commit
bc34ac1943
|
@ -27,11 +27,8 @@ import math
|
||||||
from PyQt4 import QtGui,QtCore
|
from PyQt4 import QtGui,QtCore
|
||||||
# FreeCAD modules
|
# FreeCAD modules
|
||||||
import FreeCAD,FreeCADGui
|
import FreeCAD,FreeCADGui
|
||||||
from FreeCAD import Base, Vector
|
|
||||||
import Part, Image, ImageGui
|
|
||||||
# FreeCADShip modules
|
# FreeCADShip modules
|
||||||
from shipUtils import Paths
|
from shipUtils import Paths
|
||||||
import Tools
|
|
||||||
|
|
||||||
header = """ #################################################################
|
header = """ #################################################################
|
||||||
|
|
||||||
|
@ -47,32 +44,13 @@ header = """ #################################################################
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Plot(object):
|
class Plot(object):
|
||||||
def __init__(self, ship, trim, drafts):
|
def __init__(self, ship, trim, points):
|
||||||
""" Constructor. performs plot and show it (Using pyxplot).
|
""" Constructor. performs plot and show it (Using pyxplot).
|
||||||
@param ship Selected ship instance
|
@param ship Selected ship instance
|
||||||
@param trim Trim in degrees.
|
@param trim Trim in degrees.
|
||||||
@param drafts List of drafts to be performed.
|
@param points List of computed hydrostatics.
|
||||||
"""
|
"""
|
||||||
# Compute data
|
self.points = points[:]
|
||||||
# Get external faces
|
|
||||||
faces = self.externalFaces(ship.Shape)
|
|
||||||
if len(faces) == 0:
|
|
||||||
msg = QtGui.QApplication.translate("ship_console", "Can't detect external faces from ship object",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8)
|
|
||||||
FreeCAD.Console.PrintError(msg + '\n')
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
faces = Part.makeShell(faces)
|
|
||||||
# Print data
|
|
||||||
msg = QtGui.QApplication.translate("ship_console", "Computing hydrostatics",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8)
|
|
||||||
FreeCAD.Console.PrintMessage(msg + '...\n')
|
|
||||||
self.points = []
|
|
||||||
for i in range(0,len(drafts)):
|
|
||||||
FreeCAD.Console.PrintMessage("\t%d / %d\n" % (i+1, len(drafts)))
|
|
||||||
draft = drafts[i]
|
|
||||||
point = Tools.Point(ship,faces,draft,trim)
|
|
||||||
self.points.append(point)
|
|
||||||
# Try to plot
|
# Try to plot
|
||||||
self.plotVolume()
|
self.plotVolume()
|
||||||
self.plotStability()
|
self.plotStability()
|
||||||
|
@ -80,7 +58,7 @@ class Plot(object):
|
||||||
# Save data
|
# Save data
|
||||||
if self.createDirectory():
|
if self.createDirectory():
|
||||||
return
|
return
|
||||||
if self.saveData(ship, trim, drafts):
|
if self.saveData(ship, trim):
|
||||||
return
|
return
|
||||||
|
|
||||||
def plotVolume(self):
|
def plotVolume(self):
|
||||||
|
@ -345,11 +323,10 @@ class Plot(object):
|
||||||
FreeCAD.Console.PrintError(msg + ':\n\t' + "\'"+ self.path + "\'\n")
|
FreeCAD.Console.PrintError(msg + ':\n\t' + "\'"+ self.path + "\'\n")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def saveData(self, ship, trim, drafts):
|
def saveData(self, ship, trim):
|
||||||
""" Write data file.
|
""" Write data file.
|
||||||
@param ship Selected ship instance
|
@param ship Selected ship instance
|
||||||
@param trim Trim in degrees.
|
@param trim Trim in degrees.
|
||||||
@param drafts List of drafts to be performed.
|
|
||||||
@return True if error happens.
|
@return True if error happens.
|
||||||
"""
|
"""
|
||||||
# Open the file
|
# Open the file
|
||||||
|
@ -380,7 +357,7 @@ class Plot(object):
|
||||||
Output.write(" #\n")
|
Output.write(" #\n")
|
||||||
Output.write(" #################################################################\n")
|
Output.write(" #################################################################\n")
|
||||||
# Print data
|
# Print data
|
||||||
for i in range(0,len(drafts)):
|
for i in range(0,len(self.points)):
|
||||||
point = self.points[i]
|
point = self.points[i]
|
||||||
string = "%f %f %f %f %f %f %f %f %f %f %f\n" % (point.disp, point.draft, point.wet, point.mom, point.xcb, point.farea, point.KBt, point.BMt, point.Cb, point.Cf, point.Cm)
|
string = "%f %f %f %f %f %f %f %f %f %f %f\n" % (point.disp, point.draft, point.wet, point.mom, point.xcb, point.farea, point.KBt, point.BMt, point.Cb, point.Cf, point.Cm)
|
||||||
Output.write(string)
|
Output.write(string)
|
||||||
|
@ -392,87 +369,3 @@ class Plot(object):
|
||||||
FreeCAD.Console.PrintMessage(msg + ':\n\t' + "\'"+ self.dataFile + "\'\n")
|
FreeCAD.Console.PrintMessage(msg + ':\n\t' + "\'"+ self.dataFile + "\'\n")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def lineFaceSection(self,line,surface):
|
|
||||||
""" Returns the point of section of a line with a face
|
|
||||||
@param line Line object, that can be a curve.
|
|
||||||
@param surface Surface object (must be a Part::Shape)
|
|
||||||
@return Section points array, [] if line don't cut surface
|
|
||||||
"""
|
|
||||||
# Get initial data
|
|
||||||
result = []
|
|
||||||
vertexes = line.Vertexes
|
|
||||||
nVertex = len(vertexes)
|
|
||||||
# Perform the cut
|
|
||||||
section = line.cut(surface)
|
|
||||||
# Filter all old points
|
|
||||||
points = section.Vertexes
|
|
||||||
return points
|
|
||||||
|
|
||||||
def externalFaces(self, shape):
|
|
||||||
""" Returns detected external faces.
|
|
||||||
@param shape Shape where external faces wanted.
|
|
||||||
@return List of external faces detected.
|
|
||||||
"""
|
|
||||||
result = []
|
|
||||||
faces = shape.Faces
|
|
||||||
bbox = shape.BoundBox
|
|
||||||
L = bbox.XMax - bbox.XMin
|
|
||||||
B = bbox.YMax - bbox.YMin
|
|
||||||
T = bbox.ZMax - bbox.ZMin
|
|
||||||
dist = math.sqrt(L*L + B*B + T*T)
|
|
||||||
msg = QtGui.QApplication.translate("ship_console", "Computing external faces",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8)
|
|
||||||
FreeCAD.Console.PrintMessage(msg + '...\n')
|
|
||||||
# Valid/unvalid faces detection loop
|
|
||||||
for i in range(0,len(faces)):
|
|
||||||
FreeCAD.Console.PrintMessage("\t%d / %d\n" % (i+1, len(faces)))
|
|
||||||
f = faces[i]
|
|
||||||
# Create a line normal to surface at middle point
|
|
||||||
u = 0.0
|
|
||||||
v = 0.0
|
|
||||||
try:
|
|
||||||
surf = f.Surface
|
|
||||||
u = 0.5*(surf.getUKnots()[0]+surf.getUKnots()[-1])
|
|
||||||
v = 0.5*(surf.getVKnots()[0]+surf.getVKnots()[-1])
|
|
||||||
except:
|
|
||||||
cog = f.CenterOfMass
|
|
||||||
[u,v] = f.Surface.parameter(cog)
|
|
||||||
p0 = f.valueAt(u,v)
|
|
||||||
try:
|
|
||||||
n = f.normalAt(u,v).normalize()
|
|
||||||
except:
|
|
||||||
continue
|
|
||||||
p1 = p0 + n.multiply(1.5*dist)
|
|
||||||
line = Part.makeLine(p0, p1)
|
|
||||||
# Look for faces in front of this
|
|
||||||
nPoints = 0
|
|
||||||
for j in range(0,len(faces)):
|
|
||||||
f2 = faces[j]
|
|
||||||
section = self.lineFaceSection(line, f2)
|
|
||||||
if len(section) <= 2:
|
|
||||||
continue
|
|
||||||
# Add points discarding start and end
|
|
||||||
nPoints = nPoints + len(section) - 2
|
|
||||||
# In order to avoid special directions we can modify line
|
|
||||||
# normal a little bit.
|
|
||||||
angle = 5
|
|
||||||
line.rotate(p0,Vector(1,0,0),angle)
|
|
||||||
line.rotate(p0,Vector(0,1,0),angle)
|
|
||||||
line.rotate(p0,Vector(0,0,1),angle)
|
|
||||||
nPoints2 = 0
|
|
||||||
for j in range(0,len(faces)):
|
|
||||||
if i == j:
|
|
||||||
continue
|
|
||||||
f2 = faces[j]
|
|
||||||
section = self.lineFaceSection(line, f2)
|
|
||||||
if len(section) <= 2:
|
|
||||||
continue
|
|
||||||
# Add points discarding start and end
|
|
||||||
nPoints2 = nPoints + len(section) - 2
|
|
||||||
# If the number of intersection points is pair, is a
|
|
||||||
# external face. So if we found an odd points intersection,
|
|
||||||
# face must be discarded.
|
|
||||||
if (nPoints % 2) or (nPoints2 % 2):
|
|
||||||
continue
|
|
||||||
result.append(f)
|
|
||||||
return result
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ import math
|
||||||
# FreeCAD modules
|
# FreeCAD modules
|
||||||
import FreeCAD as App
|
import FreeCAD as App
|
||||||
import FreeCADGui as Gui
|
import FreeCADGui as Gui
|
||||||
|
from FreeCAD import Base, Vector
|
||||||
|
import Part
|
||||||
# Qt library
|
# Qt library
|
||||||
from PyQt4 import QtGui,QtCore
|
from PyQt4 import QtGui,QtCore
|
||||||
# Module
|
# Module
|
||||||
|
@ -37,10 +39,13 @@ class TaskPanel:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ui = Paths.modulePath() + "/shipHydrostatics/TaskPanel.ui"
|
self.ui = Paths.modulePath() + "/shipHydrostatics/TaskPanel.ui"
|
||||||
self.ship = None
|
self.ship = None
|
||||||
|
self.running = False
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
if not self.ship:
|
if not self.ship:
|
||||||
return False
|
return False
|
||||||
|
if self.running:
|
||||||
|
return
|
||||||
self.save()
|
self.save()
|
||||||
draft = self.form.minDraft.value()
|
draft = self.form.minDraft.value()
|
||||||
drafts = [draft]
|
drafts = [draft]
|
||||||
|
@ -48,10 +53,45 @@ class TaskPanel:
|
||||||
for i in range(1,self.form.nDraft.value()):
|
for i in range(1,self.form.nDraft.value()):
|
||||||
draft = draft + dDraft
|
draft = draft + dDraft
|
||||||
drafts.append(draft)
|
drafts.append(draft)
|
||||||
PlotAux.Plot(self.ship, self.form.trim.value(), drafts)
|
# Compute data
|
||||||
|
# Get external faces
|
||||||
|
self.loop=QtCore.QEventLoop()
|
||||||
|
self.timer=QtCore.QTimer()
|
||||||
|
self.timer.setSingleShot(True)
|
||||||
|
QtCore.QObject.connect(self.timer,QtCore.SIGNAL("timeout()"),self.loop,QtCore.SLOT("quit()"))
|
||||||
|
self.running = True
|
||||||
|
faces = self.externalFaces(self.ship.Shape)
|
||||||
|
if not self.running:
|
||||||
|
return False
|
||||||
|
if len(faces) == 0:
|
||||||
|
msg = QtGui.QApplication.translate("ship_console", "Can't detect external faces from ship object",
|
||||||
|
None,QtGui.QApplication.UnicodeUTF8)
|
||||||
|
App.Console.PrintError(msg + '\n')
|
||||||
|
return False
|
||||||
|
faces = Part.makeShell(faces)
|
||||||
|
# Get hydrostatics
|
||||||
|
msg = QtGui.QApplication.translate("ship_console", "Computing hydrostatics",
|
||||||
|
None,QtGui.QApplication.UnicodeUTF8)
|
||||||
|
App.Console.PrintMessage(msg + '...\n')
|
||||||
|
points = []
|
||||||
|
for i in range(0,len(drafts)):
|
||||||
|
App.Console.PrintMessage("\t%d / %d\n" % (i+1, len(drafts)))
|
||||||
|
draft = drafts[i]
|
||||||
|
point = Tools.Point(self.ship,faces,draft,self.form.trim.value())
|
||||||
|
points.append(point)
|
||||||
|
self.timer.start(0.0)
|
||||||
|
self.loop.exec_()
|
||||||
|
if(not self.running):
|
||||||
|
break
|
||||||
|
PlotAux.Plot(self.ship, self.form.trim.value(), points)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def reject(self):
|
def reject(self):
|
||||||
|
if not self.ship:
|
||||||
|
return False
|
||||||
|
if self.running:
|
||||||
|
self.running = False
|
||||||
|
return
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def clicked(self, index):
|
def clicked(self, index):
|
||||||
|
@ -235,6 +275,95 @@ class TaskPanel:
|
||||||
self.ship.addProperty("App::PropertyInteger","HydrostaticsNDraft","Ship", tooltip)
|
self.ship.addProperty("App::PropertyInteger","HydrostaticsNDraft","Ship", tooltip)
|
||||||
self.ship.HydrostaticsNDraft = self.form.nDraft.value()
|
self.ship.HydrostaticsNDraft = self.form.nDraft.value()
|
||||||
|
|
||||||
|
def lineFaceSection(self,line,surface):
|
||||||
|
""" Returns the point of section of a line with a face
|
||||||
|
@param line Line object, that can be a curve.
|
||||||
|
@param surface Surface object (must be a Part::Shape)
|
||||||
|
@return Section points array, [] if line don't cut surface
|
||||||
|
"""
|
||||||
|
# Get initial data
|
||||||
|
result = []
|
||||||
|
vertexes = line.Vertexes
|
||||||
|
nVertex = len(vertexes)
|
||||||
|
# Perform the cut
|
||||||
|
section = line.cut(surface)
|
||||||
|
# Filter all old points
|
||||||
|
points = section.Vertexes
|
||||||
|
return points
|
||||||
|
|
||||||
|
def externalFaces(self, shape):
|
||||||
|
""" Returns detected external faces.
|
||||||
|
@param shape Shape where external faces wanted.
|
||||||
|
@return List of external faces detected.
|
||||||
|
"""
|
||||||
|
result = []
|
||||||
|
faces = shape.Faces
|
||||||
|
bbox = shape.BoundBox
|
||||||
|
L = bbox.XMax - bbox.XMin
|
||||||
|
B = bbox.YMax - bbox.YMin
|
||||||
|
T = bbox.ZMax - bbox.ZMin
|
||||||
|
dist = math.sqrt(L*L + B*B + T*T)
|
||||||
|
msg = QtGui.QApplication.translate("ship_console", "Computing external faces",
|
||||||
|
None,QtGui.QApplication.UnicodeUTF8)
|
||||||
|
App.Console.PrintMessage(msg + '...\n')
|
||||||
|
# Valid/unvalid faces detection loop
|
||||||
|
for i in range(0,len(faces)):
|
||||||
|
App.Console.PrintMessage("\t%d / %d\n" % (i+1, len(faces)))
|
||||||
|
f = faces[i]
|
||||||
|
# Create a line normal to surface at middle point
|
||||||
|
u = 0.0
|
||||||
|
v = 0.0
|
||||||
|
try:
|
||||||
|
surf = f.Surface
|
||||||
|
u = 0.5*(surf.getUKnots()[0]+surf.getUKnots()[-1])
|
||||||
|
v = 0.5*(surf.getVKnots()[0]+surf.getVKnots()[-1])
|
||||||
|
except:
|
||||||
|
cog = f.CenterOfMass
|
||||||
|
[u,v] = f.Surface.parameter(cog)
|
||||||
|
p0 = f.valueAt(u,v)
|
||||||
|
try:
|
||||||
|
n = f.normalAt(u,v).normalize()
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
p1 = p0 + n.multiply(1.5*dist)
|
||||||
|
line = Part.makeLine(p0, p1)
|
||||||
|
# Look for faces in front of this
|
||||||
|
nPoints = 0
|
||||||
|
for j in range(0,len(faces)):
|
||||||
|
f2 = faces[j]
|
||||||
|
section = self.lineFaceSection(line, f2)
|
||||||
|
if len(section) <= 2:
|
||||||
|
continue
|
||||||
|
# Add points discarding start and end
|
||||||
|
nPoints = nPoints + len(section) - 2
|
||||||
|
# In order to avoid special directions we can modify line
|
||||||
|
# normal a little bit.
|
||||||
|
angle = 5
|
||||||
|
line.rotate(p0,Vector(1,0,0),angle)
|
||||||
|
line.rotate(p0,Vector(0,1,0),angle)
|
||||||
|
line.rotate(p0,Vector(0,0,1),angle)
|
||||||
|
nPoints2 = 0
|
||||||
|
for j in range(0,len(faces)):
|
||||||
|
if i == j:
|
||||||
|
continue
|
||||||
|
f2 = faces[j]
|
||||||
|
section = self.lineFaceSection(line, f2)
|
||||||
|
if len(section) <= 2:
|
||||||
|
continue
|
||||||
|
# Add points discarding start and end
|
||||||
|
nPoints2 = nPoints + len(section) - 2
|
||||||
|
# If the number of intersection points is pair, is a
|
||||||
|
# external face. So if we found an odd points intersection,
|
||||||
|
# face must be discarded.
|
||||||
|
if (nPoints % 2) or (nPoints2 % 2):
|
||||||
|
continue
|
||||||
|
result.append(f)
|
||||||
|
self.timer.start(0.0)
|
||||||
|
self.loop.exec_()
|
||||||
|
if(not self.running):
|
||||||
|
break
|
||||||
|
return result
|
||||||
|
|
||||||
def createTask():
|
def createTask():
|
||||||
panel = TaskPanel()
|
panel = TaskPanel()
|
||||||
Gui.Control.showDialog(panel)
|
Gui.Control.showDialog(panel)
|
||||||
|
|
|
@ -39,10 +39,13 @@ class TaskPanel:
|
||||||
self.ui = Paths.modulePath() + "/tankGZ/TaskPanel.ui"
|
self.ui = Paths.modulePath() + "/tankGZ/TaskPanel.ui"
|
||||||
self.ship = None
|
self.ship = None
|
||||||
self.tanks = {}
|
self.tanks = {}
|
||||||
|
self.running = False
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
if not self.ship:
|
if not self.ship:
|
||||||
return False
|
return False
|
||||||
|
if self.running:
|
||||||
|
return
|
||||||
# Get general data
|
# Get general data
|
||||||
disp = self.computeDisplacement()
|
disp = self.computeDisplacement()
|
||||||
draft = self.computeDraft(disp[0], self.form.trim.value())
|
draft = self.computeDraft(disp[0], self.form.trim.value())
|
||||||
|
@ -57,16 +60,28 @@ class TaskPanel:
|
||||||
msg = QtGui.QApplication.translate("ship_console","Computing GZ",
|
msg = QtGui.QApplication.translate("ship_console","Computing GZ",
|
||||||
None,QtGui.QApplication.UnicodeUTF8)
|
None,QtGui.QApplication.UnicodeUTF8)
|
||||||
App.Console.PrintMessage(msg + "...\n")
|
App.Console.PrintMessage(msg + "...\n")
|
||||||
|
loop=QtCore.QEventLoop()
|
||||||
|
timer=QtCore.QTimer()
|
||||||
|
timer.setSingleShot(True)
|
||||||
|
QtCore.QObject.connect(timer,QtCore.SIGNAL("timeout()"),loop,QtCore.SLOT("quit()"))
|
||||||
|
self.running = True
|
||||||
for i in range(0, nRoll):
|
for i in range(0, nRoll):
|
||||||
App.Console.PrintMessage("\t%d/%d\n" % (i+1,nRoll))
|
App.Console.PrintMessage("\t%d/%d\n" % (i+1,nRoll))
|
||||||
roll.append(i*dRoll)
|
roll.append(i*dRoll)
|
||||||
GZ.append(self.computeGZ(draft[0], trim, roll[-1]))
|
GZ.append(self.computeGZ(draft[0], trim, roll[-1]))
|
||||||
|
timer.start(0.0)
|
||||||
|
loop.exec_()
|
||||||
|
if(not self.running):
|
||||||
|
break
|
||||||
PlotAux.Plot(roll, GZ, disp[0]/1000.0, draft[0], trim)
|
PlotAux.Plot(roll, GZ, disp[0]/1000.0, draft[0], trim)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def reject(self):
|
def reject(self):
|
||||||
if not self.ship:
|
if not self.ship:
|
||||||
return False
|
return False
|
||||||
|
if self.running:
|
||||||
|
self.running = False
|
||||||
|
return
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def clicked(self, index):
|
def clicked(self, index):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user