From 1ce24c879f0a41f9a74342494aea2ce7bb0012a6 Mon Sep 17 00:00:00 2001 From: Jose Luis Cercos-Pita Date: Fri, 11 Jul 2014 13:57:44 +0200 Subject: [PATCH] Added units mangement to the outline drawing tool --- src/Mod/Ship/shipOutlineDraw/TaskPanel.py | 67 ++++++++++++----------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/src/Mod/Ship/shipOutlineDraw/TaskPanel.py b/src/Mod/Ship/shipOutlineDraw/TaskPanel.py index 73a1dc375..665bd90d7 100644 --- a/src/Mod/Ship/shipOutlineDraw/TaskPanel.py +++ b/src/Mod/Ship/shipOutlineDraw/TaskPanel.py @@ -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 @@ -301,7 +302,7 @@ class TaskPanel: 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 @@ -327,55 +328,55 @@ class TaskPanel: 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, @@ -397,11 +398,11 @@ class TaskPanel: 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):