Added Free surface 3D view update

This commit is contained in:
Jose Luis Cercós pita
2012-01-20 14:36:22 +01:00
committed by Yorik van Havre
parent b11ff9b940
commit b7ea4242bd
2 changed files with 37 additions and 84 deletions

View File

@@ -32,99 +32,47 @@ class Preview(object):
def __init__(self):
""" Constructor.
"""
self.baseLine = None
self.baseLineLabel = None
self.reinit()
def reinit(self):
""" Reinitializate drawer.
"""
self.obj = None
self.clean()
def update(self, L, B, T):
""" Update the 3D view printing annotations.
@param L Ship length.
@param B Ship beam.
@param T Ship draft.
def update(self, draft, trim, ship):
""" Update free surface 3D view
@param traft Draft.
@param trim Trim in degrees.
"""
# Destroy all previous entities
# Destroy old object if exist
self.clean()
# Draw base line
xStart = -0.6*L;
xEnd = 0.6*L;
baseLine = Part.makeLine((xStart,0,0),(xEnd,0,0))
Part.show(baseLine)
# Set free surface bounds
bbox = ship.Shape.BoundBox
L = 1.5 * bbox.XLength
B = 3.0 * bbox.YLength
# Create plane
x = - 0.5 * L
y = - 0.5 * B
point = Base.Vector(x,y,0.0)
plane = Part.makePlane(L,B, point, Base.Vector(0,0,1))
# Set position
plane.rotate(Base.Vector(0,0,0), Base.Vector(0,1,0), trim)
plane.translate(Base.Vector(0,0,draft))
# Create the FreeCAD object
Part.show(plane)
objs = FreeCAD.ActiveDocument.Objects
self.baseLine = objs[len(objs)-1]
self.baseLine.Label = 'BaseLine'
self.baseLineLabel = DrawText('BaseLineText', str(Translator.translate('Base line')), Base.Vector(xEnd,0,0))
# Draw free surface
fsLine = Part.makeLine((xStart,0,T),(xEnd,0,T))
Part.show(fsLine)
objs = FreeCAD.ActiveDocument.Objects
self.fsLine = objs[len(objs)-1]
self.fsLine.Label = 'FreeSurface'
self.fsLineLabel = DrawText('FSText', str(Translator.translate('Free surface')), Base.Vector(xEnd,0,T))
# Draw forward perpendicular
zStart = -0.1*T
zEnd = 1.1*T
fpLine = Part.makeLine((0.5*L,0,zStart),(0.5*L,0,zEnd))
Part.show(fpLine)
objs = FreeCAD.ActiveDocument.Objects
self.fpLine = objs[len(objs)-1]
self.fpLine.Label = 'ForwardPerpendicular'
self.fpLineLabel = DrawText('FPText', str(Translator.translate('Forward perpendicular')), Base.Vector(0.5*L,0,zEnd))
# Draw after perpendicular
apLine = Part.makeLine((-0.5*L,0,zStart),(-0.5*L,0,zEnd))
Part.show(apLine)
objs = FreeCAD.ActiveDocument.Objects
self.apLine = objs[len(objs)-1]
self.apLine.Label = 'AfterPerpendicular'
self.apLineLabel = DrawText('APText', str(Translator.translate('After perpendicular')), Base.Vector(-0.5*L,0,zEnd))
# Draw amin frame
amLine = Part.makeLine((0,-0.5*B,zStart),(0,-0.5*B,zEnd))
Part.show(amLine)
objs = FreeCAD.ActiveDocument.Objects
self.amLine = objs[len(objs)-1]
self.amLine.Label = 'AminFrame'
self.amLineLabel = DrawText('AMText', str(Translator.translate('Amin frame')), Base.Vector(0,-0.5*B,zEnd))
self.obj = objs[len(objs)-1]
self.obj.Label = 'FreeSurface'
# Set properties of object
guiObj = FreeCADGui.ActiveDocument.getObject(self.obj.Name)
guiObj.ShapeColor = (0.4,0.8,0.85)
guiObj.Transparency = 50
def clean(self):
""" Erase all annotations from screen.
"""
if not self.baseLine:
if not self.obj:
return
FreeCAD.ActiveDocument.removeObject(self.baseLine.Name)
FreeCAD.ActiveDocument.removeObject(self.baseLineLabel.Name)
FreeCAD.ActiveDocument.removeObject(self.fsLine.Name)
FreeCAD.ActiveDocument.removeObject(self.fsLineLabel.Name)
FreeCAD.ActiveDocument.removeObject(self.fpLine.Name)
FreeCAD.ActiveDocument.removeObject(self.fpLineLabel.Name)
FreeCAD.ActiveDocument.removeObject(self.apLine.Name)
FreeCAD.ActiveDocument.removeObject(self.apLineLabel.Name)
FreeCAD.ActiveDocument.removeObject(self.amLine.Name)
FreeCAD.ActiveDocument.removeObject(self.amLineLabel.Name)
def DrawText(name, string, position, displayMode="Screen", angle=0.0, justification="Left", colour=(0.00,0.00,0.00), size=12):
""" Draws a text in a desired position.
@param name Name of the object
@param string Text to draw (recommended format u'')
@param position Point to draw the text
@param angle Counter clockwise rotation of text
@param justification Alignement of the text ("Left", "Right" or "Center")
@param colour Colour of the text
@param size Font size
@return FreeCAD annotation object
"""
# Create the object
text = FreeCAD.ActiveDocument.addObject("App::Annotation",name)
# Set the text
text.LabelText = [string, u'']
# Set the options
text.Position = position
FreeCADGui.ActiveDocument.getObject(text.Name).Rotation = angle
FreeCADGui.ActiveDocument.getObject(text.Name).Justification = justification
FreeCADGui.ActiveDocument.getObject(text.Name).FontSize = size
FreeCADGui.ActiveDocument.getObject(text.Name).TextColor = colour
FreeCADGui.ActiveDocument.getObject(text.Name).DisplayMode = displayMode
return FreeCAD.ActiveDocument.getObject(text.Name)
FreeCAD.ActiveDocument.removeObject(self.obj.Name)
self.obj=None

View File

@@ -146,6 +146,8 @@ class TaskPanel:
flag = False
if flag:
self.form.trim.setValue(self.ship.AreaCurveTrim)
# Update GUI
self.preview.update(self.form.draft.value(), self.form.trim.value(), self.ship)
msg = Translator.translate("Ready to work\n")
App.Console.PrintMessage(msg)
return False
@@ -162,12 +164,15 @@ class TaskPanel:
""" Method called when input data is changed.
@param value Changed value.
"""
pass
if not self.ship:
return
self.preview.update(self.form.draft.value(), self.form.trim.value(), self.ship)
def onUpdate(self):
""" Method called when update data request.
"""
pass
if not self.ship:
return
def save(self):
""" Saves data into ship instance.