Skip to content

Commit

Permalink
Added units mangement to the outline drawing tool
Browse files Browse the repository at this point in the history
  • Loading branch information
sanguinariojoe authored and wwmayer committed Jul 13, 2014
1 parent 978030a commit 1ce24c8
Showing 1 changed file with 34 additions and 33 deletions.
67 changes: 34 additions & 33 deletions src/Mod/Ship/shipOutlineDraw/TaskPanel.py
Expand Up @@ -24,6 +24,7 @@
import FreeCAD as App
from FreeCAD import Base, Vector
import FreeCADGui as Gui
import Units
import Part
from PySide import QtGui, QtCore
import Preview
Expand Down Expand Up @@ -301,7 +302,7 @@ def setSectionType(self, ID):
form.sections.setRowCount(nRow + 1)
self.skip = True
for i in range(0, nRow):
string = '{0}'.format(SectionList[i])
string = '{} m'.format(SectionList[i])
item = QtGui.QTableWidgetItem(string)
form.sections.setItem(i, 0, item)
self.skip = False
Expand All @@ -327,55 +328,55 @@ def onTableItem(self, row, column):
form.sections = self.widget(QtGui.QTableWidget, "Sections")
form.sectionType = self.widget(QtGui.QComboBox, "SectionType")

# Add an empty item at the end of the list
nRow = form.sections.rowCount()
item = form.sections.item(nRow - 1, 0)
if item:
if(item.text() != ''):
form.sections.setRowCount(nRow + 1)
# Ensure that the new introduced item is a number

ID = form.sectionType.currentIndex()
if ID == 0:
SectionList = self.LSections[:]
SectionList = self.LSections
elif ID == 1:
SectionList = self.BSections[:]
SectionList = self.BSections
elif ID == 2:
SectionList = self.TSections[:]
SectionList = self.TSections

item = form.sections.item(row, column)
# Look for deleted row (empty string)
if not item.text():
del SectionList[row]
form.sections.removeRow(row)
self.obj = self.preview.update(self.ship.Length.getValueAs('m').Value,
self.ship.Breadth.getValueAs('m').Value,
self.ship.Draft.getValueAs('m').Value,
self.LSections,
self.BSections,
self.TSections,
self.ship.Shape)
return

# Get the new section value
try:
if 'toFloat' in dir(item.text()):
(number, flag) = item.text().toFloat()
if not flag:
raise ValueError('The string cannot be converted into a'
' number')
else:
number = float(item.text())
qty = Units.Quantity(item.text())
number = qty.getValueAs('m').Value
except:
number = 0.0
string = '{}'.format(number)

string = '{} m'.format(number)
item.setText(string)
# Regenerate the list
SectionList = []
del SectionList[:]
for i in range(0, nRow):
item = form.sections.item(i, 0)
try:
if 'toFloat' in dir(item.text()):
(number, flag) = item.text().toFloat()
if not flag:
raise ValueError('The string cannot be converted into a'
' number')
else:
number = float(item.text())
qty = Units.Quantity(item.text())
number = qty.getValueAs('m').Value
except:
continue
number = 0.0
SectionList.append(number)
# Paste it into the section type list
ID = form.sectionType.currentIndex()
if ID == 0:
self.LSections = SectionList[:]
elif ID == 1:
self.BSections = SectionList[:]
elif ID == 2:
self.TSections = SectionList[:]

self.obj = self.preview.update(self.ship.Length.getValueAs('m').Value,
self.ship.Breadth.getValueAs('m').Value,
self.ship.Draft.getValueAs('m').Value,
Expand All @@ -397,11 +398,11 @@ def onDeleteButton(self):
form.sections.setRowCount(1)
ID = form.sectionType.currentIndex()
if ID == 0:
self.LSections = []
del self.LSections[:]
elif ID == 1:
self.BSections = []
del self.BSections[:]
elif ID == 2:
self.TSections = []
del self.TSections[:]
self.setSectionType(ID)

def onCreateButton(self):
Expand Down

0 comments on commit 1ce24c8

Please sign in to comment.