Skip to content

Commit

Permalink
Modify section Spref #81
Browse files Browse the repository at this point in the history
  • Loading branch information
eryar committed Jul 16, 2022
1 parent 62d35d8 commit 90c4f08
Showing 1 changed file with 127 additions and 1 deletion.
128 changes: 127 additions & 1 deletion Python/Structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,45 @@ def profileChanged(self, theCurrentRow, theCurrentColumn, thePreviousRow, thePre

# profileChanged

def setSpcoItem(self, theSpcoItem):
if theSpcoItem == None:
return
# if

aSeleItem = theSpcoItem.Owner
aSpecItem = aSeleItem.Owner

for i in range(self.comboSpec.count):
if self.comboSpec.itemData(i) == aSpecItem:
self.comboSpec.setCurrentIndex(i)
break
# if
# for

for i in range(self.comboType.count):
if self.comboType.itemData(i) == aSeleItem:
self.comboType.setCurrentIndex(i)
break
# if
# for

for r in range(self.tableWidget.rowCount):
aTableItem = self.tableWidget.item(r, 0)
if aTableItem.data(Qt.UserRole) == theSpcoItem:
self.tableWidget.setCurrentItem(aTableItem)
break
# if
# for
# setSpcoItem

# SectionSpecDialog

class SectionDialog(QDialog):
def __init__(self, theParent = None):
QDialog.__init__(self, theParent)

self.spcoItem = None
self.sctnItem = None

self.setupUi()
# __init__
Expand All @@ -476,6 +508,21 @@ def setupUi(self):

self.verticalLayout = QVBoxLayout(self)

# Create
self.formLayout = QFormLayout()

self.comboName = QComboBox()
self.comboName.addItem(QT_TRANSLATE_NOOP("Structure", "Create"))
self.comboName.addItem(QT_TRANSLATE_NOOP("Structure", "Modify"))
self.comboName.activated.connect(self.activateName)

self.textName = QLineEdit()

self.formLayout.setWidget(0, QFormLayout.LabelRole, self.comboName)
self.formLayout.setWidget(0, QFormLayout.FieldRole, self.textName)

self.verticalLayout.addLayout(self.formLayout)

self.groupBox = QGroupBox(QT_TRANSLATE_NOOP("Structure", "Specification"))

self.formLayout = QFormLayout(self.groupBox)
Expand Down Expand Up @@ -603,8 +650,56 @@ def setupUi(self):

# setupUi

def activateName(self):
aIndex = self.comboName.currentIndex
if aIndex == 0:
self.setWindowTitle(QT_TRANSLATE_NOOP("Structure", "Create Section"))
self.tabWidget.addTab(self.tabPointVector, QT_TRANSLATE_NOOP("Structure", "Point and Vector"))
self.sctnItem = None

self.textX1.setText("0")
self.textY1.setText("0")
self.textZ1.setText("0")

self.textX2.setText("0")
self.textY2.setText("0")
self.textZ2.setText("0")
else:
self.setWindowTitle(QT_TRANSLATE_NOOP("Structure", "Modify Section"))
self.tabWidget.removeTab(1)

aTreeItem = PipeCad.CurrentItem()
if aTreeItem.Type == "SCTN":
self.sctnItem = aTreeItem
self.spcoItem = aTreeItem.Spref

aPs = aTreeItem.StartPosition
aPe = aTreeItem.EndPosition

self.textName.setText(aTreeItem.Name)

if aTreeItem.Spref != None and self.spcoItem.Catref != None:
self.textSpec.setText(aTreeItem.Spref.Catref.Name)
# if

self.textX1.setText(str(aPs.X))
self.textY1.setText(str(aPs.Y))
self.textZ1.setText(str(aPs.Z))

self.textX2.setText(str(aPe.X))
self.textY2.setText(str(aPe.Y))
self.textZ2.setText(str(aPe.Z))
else:
self.sctnItem = None

QMessageBox.warning(self, "", QT_TRANSLATE_NOOP("Structure", "Please select SCTN to modify!"))
# if
# if
# activateName

def selectSpec(self):
aSpecDlg = SectionSpecDialog(self)
aSpecDlg.setSpcoItem(self.spcoItem)
if aSpecDlg.exec() != QDialog.Accepted:
return
# if
Expand Down Expand Up @@ -633,7 +728,29 @@ def selectSpec(self):
self.textJline.setText(aSpecDlg.comboJline.currentText)
# selectSpec

def accept(self):
def modifySection(self):
aX = float(self.textX1.text)
aY = float(self.textY1.text)
aZ = float(self.textZ1.text)

aPs = Position(aX, aY, aZ)

aX = float(self.textX2.text)
aY = float(self.textY2.text)
aZ = float(self.textZ2.text)

aPe = Position(aX, aY, aZ)

PipeCad.StartTransaction("Modify Section")
aSctnItem = self.sctnItem
aSctnItem.StartPosition = aPs
aSctnItem.EndPosition = aPe
aSctnItem.Spref = self.spcoItem

PipeCad.CommitTransaction()
# modifySection

def createSection(self):
aIndex = self.tabWidget.currentIndex
if aIndex == 0:
# 2 Points
Expand Down Expand Up @@ -677,6 +794,15 @@ def accept(self):

PipeCad.CommitTransaction()
# if
# createSection

def accept(self):

if self.sctnItem == None:
self.createSection()
else:
self.modifySection()
# if

QDialog.accept(self)
# accept
Expand Down

0 comments on commit 90c4f08

Please sign in to comment.