Added annotations to ship weights definition tool
This commit is contained in:
parent
1183b468bd
commit
0a3a2b1de0
|
@ -101,6 +101,7 @@ SOURCE_GROUP("shiputils" FILES ${ShipUtils_SRCS})
|
||||||
|
|
||||||
SET(ShipWeights_SRCS
|
SET(ShipWeights_SRCS
|
||||||
tankWeights/__init__.py
|
tankWeights/__init__.py
|
||||||
|
tankWeights/Preview.py
|
||||||
tankWeights/TaskPanel.py
|
tankWeights/TaskPanel.py
|
||||||
tankWeights/TaskPanel.ui
|
tankWeights/TaskPanel.ui
|
||||||
)
|
)
|
||||||
|
|
|
@ -70,6 +70,7 @@ nobase_data_DATA = \
|
||||||
shipUtils/Paths.py \
|
shipUtils/Paths.py \
|
||||||
shipUtils/Translator.py \
|
shipUtils/Translator.py \
|
||||||
tankWeights/__init__.py \
|
tankWeights/__init__.py \
|
||||||
|
tankWeights/Preview.py \
|
||||||
tankWeights/TaskPanel.py \
|
tankWeights/TaskPanel.py \
|
||||||
tankWeights/TaskPanel.ui \
|
tankWeights/TaskPanel.ui \
|
||||||
tankCreateTank/__init__.py \
|
tankCreateTank/__init__.py \
|
||||||
|
|
106
src/Mod/Ship/tankWeights/Preview.py
Normal file
106
src/Mod/Ship/tankWeights/Preview.py
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
#***************************************************************************
|
||||||
|
#* *
|
||||||
|
#* Copyright (c) 2011, 2012 *
|
||||||
|
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
||||||
|
#* *
|
||||||
|
#* This program is free software; you can redistribute it and/or modify *
|
||||||
|
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||||
|
#* as published by the Free Software Foundation; either version 2 of *
|
||||||
|
#* the License, or (at your option) any later version. *
|
||||||
|
#* for detail see the LICENCE text file. *
|
||||||
|
#* *
|
||||||
|
#* This program is distributed in the hope that it will be useful, *
|
||||||
|
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
#* GNU Library General Public License for more details. *
|
||||||
|
#* *
|
||||||
|
#* You should have received a copy of the GNU Library General Public *
|
||||||
|
#* License along with this program; if not, write to the Free Software *
|
||||||
|
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||||
|
#* USA *
|
||||||
|
#* *
|
||||||
|
#***************************************************************************
|
||||||
|
|
||||||
|
# FreeCAD modules
|
||||||
|
import FreeCAD,FreeCADGui
|
||||||
|
from FreeCAD import Base
|
||||||
|
from FreeCAD import Part
|
||||||
|
# FreeCADShip modules
|
||||||
|
from shipUtils import Paths, Translator
|
||||||
|
|
||||||
|
class Preview(object):
|
||||||
|
def __init__(self):
|
||||||
|
""" Constructor.
|
||||||
|
"""
|
||||||
|
self.objects = []
|
||||||
|
|
||||||
|
def reinit(self):
|
||||||
|
""" Reinitializate drawer.
|
||||||
|
"""
|
||||||
|
self.clean()
|
||||||
|
|
||||||
|
def update(self, names, pos):
|
||||||
|
""" Update the 3D view printing annotations.
|
||||||
|
@param names Weight names.
|
||||||
|
@param pos Weight positions (FreeCAD::Base::Vector).
|
||||||
|
"""
|
||||||
|
# Destroy all previous entities
|
||||||
|
self.clean()
|
||||||
|
for i in range(0, len(names)):
|
||||||
|
# Draw gravity line
|
||||||
|
line = Part.makeLine((pos[i].x,pos[i].y,pos[i].z),(pos[i].x,pos[i].y,pos[i].z - 9.81))
|
||||||
|
Part.show(line)
|
||||||
|
objs = FreeCAD.ActiveDocument.Objects
|
||||||
|
self.objects.append(objs[-1])
|
||||||
|
objs[-1].Label = names[i] + 'Line'
|
||||||
|
# Draw circles
|
||||||
|
circle = Part.makeCircle(0.5, pos[i], Base.Vector(1.0,0.0,0.0))
|
||||||
|
Part.show(circle)
|
||||||
|
objs = FreeCAD.ActiveDocument.Objects
|
||||||
|
self.objects.append(objs[-1])
|
||||||
|
objs[-1].Label = names[i] + 'CircleX'
|
||||||
|
circle = Part.makeCircle(0.5, pos[i], Base.Vector(0.0,1.0,0.0))
|
||||||
|
Part.show(circle)
|
||||||
|
objs = FreeCAD.ActiveDocument.Objects
|
||||||
|
self.objects.append(objs[-1])
|
||||||
|
objs[-1].Label = names[i] + 'CircleY'
|
||||||
|
circle = Part.makeCircle(0.5, pos[i], Base.Vector(0.0,0.0,1.0))
|
||||||
|
Part.show(circle)
|
||||||
|
objs = FreeCAD.ActiveDocument.Objects
|
||||||
|
self.objects.append(objs[-1])
|
||||||
|
objs[-1].Label = names[i] + 'CircleZ'
|
||||||
|
# Draw annotation
|
||||||
|
self.objects.append(DrawText(names[i] + 'Text', names[i], Base.Vector(pos[i].x+1.0,pos[i].y,pos[i].z)))
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
""" Erase all annotations from screen.
|
||||||
|
"""
|
||||||
|
for i in range(0,len(self.objects)):
|
||||||
|
if not FreeCAD.ActiveDocument.getObject(self.objects[i].Name):
|
||||||
|
continue
|
||||||
|
FreeCAD.ActiveDocument.removeObject(self.objects[i].Name)
|
||||||
|
self.objects = []
|
||||||
|
|
||||||
|
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)
|
|
@ -27,6 +27,7 @@ import FreeCADGui as Gui
|
||||||
# Qt library
|
# Qt library
|
||||||
from PyQt4 import QtGui,QtCore
|
from PyQt4 import QtGui,QtCore
|
||||||
# Module
|
# Module
|
||||||
|
import Preview
|
||||||
from Instance import *
|
from Instance import *
|
||||||
from shipUtils import Paths, Translator
|
from shipUtils import Paths, Translator
|
||||||
|
|
||||||
|
@ -34,8 +35,10 @@ class TaskPanel:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ui = Paths.modulePath() + "/tankWeights/TaskPanel.ui"
|
self.ui = Paths.modulePath() + "/tankWeights/TaskPanel.ui"
|
||||||
self.ship = None
|
self.ship = None
|
||||||
|
self.preview = Preview.Preview()
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
|
self.preview.clean()
|
||||||
if not self.ship:
|
if not self.ship:
|
||||||
return False
|
return False
|
||||||
# Setup lists
|
# Setup lists
|
||||||
|
@ -62,6 +65,7 @@ class TaskPanel:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def reject(self):
|
def reject(self):
|
||||||
|
self.preview.clean()
|
||||||
if not self.ship:
|
if not self.ship:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
@ -98,6 +102,21 @@ class TaskPanel:
|
||||||
self.retranslateUi()
|
self.retranslateUi()
|
||||||
# Connect Signals and Slots
|
# Connect Signals and Slots
|
||||||
QtCore.QObject.connect(form.weights,QtCore.SIGNAL("cellChanged(int,int)"),self.onTableItem);
|
QtCore.QObject.connect(form.weights,QtCore.SIGNAL("cellChanged(int,int)"),self.onTableItem);
|
||||||
|
# Update screen
|
||||||
|
name = []
|
||||||
|
pos = []
|
||||||
|
for i in range(0,self.form.weights.rowCount() - 1):
|
||||||
|
item = self.form.weights.item(i,0)
|
||||||
|
name.append(item.text().__str__())
|
||||||
|
vec = []
|
||||||
|
item = self.form.weights.item(i,2)
|
||||||
|
vec.append(item.text().toFloat()[0])
|
||||||
|
item = self.form.weights.item(i,3)
|
||||||
|
vec.append(item.text().toFloat()[0])
|
||||||
|
item = self.form.weights.item(i,4)
|
||||||
|
vec.append(item.text().toFloat()[0])
|
||||||
|
pos.append(App.Base.Vector(vec[0],vec[1],vec[2]))
|
||||||
|
self.preview.update(name, pos)
|
||||||
|
|
||||||
def getMainWindow(self):
|
def getMainWindow(self):
|
||||||
"returns the main window"
|
"returns the main window"
|
||||||
|
@ -202,6 +221,21 @@ class TaskPanel:
|
||||||
(number,flag) = item.text().toFloat()
|
(number,flag) = item.text().toFloat()
|
||||||
if not flag:
|
if not flag:
|
||||||
item.setText('0.0')
|
item.setText('0.0')
|
||||||
|
# Update screen annotations
|
||||||
|
name = []
|
||||||
|
pos = []
|
||||||
|
for i in range(0,self.form.weights.rowCount() - 1):
|
||||||
|
item = self.form.weights.item(i,0)
|
||||||
|
name.append(item.text().__str__())
|
||||||
|
vec = []
|
||||||
|
item = self.form.weights.item(i,2)
|
||||||
|
vec.append(item.text().toFloat()[0])
|
||||||
|
item = self.form.weights.item(i,3)
|
||||||
|
vec.append(item.text().toFloat()[0])
|
||||||
|
item = self.form.weights.item(i,4)
|
||||||
|
vec.append(item.text().toFloat()[0])
|
||||||
|
pos.append(App.Base.Vector(vec[0],vec[1],vec[2]))
|
||||||
|
self.preview.update(name, pos)
|
||||||
|
|
||||||
def createTask():
|
def createTask():
|
||||||
panel = TaskPanel()
|
panel = TaskPanel()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user