示例#1
0
class TaskWizardShaft:
    "Shaft Wizard"
    App = FreeCAD
    Gui = FreeCADGui
    
    def __init__(self, doc):
        mw = QtGui.qApp.activeWindow()
        cw = mw.centralWidget() # This is a qmdiarea widget
        self.doc = doc

        # Get active document or create a new one
        # Important because when setting the default data in WizardShaftTable() the
        # updateSketch() slot will be activated and it relies on finding a valid document
        if self.doc == None:
            self.Gui.activateWorkbench("PartDesignWorkbench")
            self.doc = self.App.newDocument()
            # Grab the newly created feature window
            featureWindow = cw.subWindowList()[-1]
        else:
            featureWindow = cw.activeSubWindow()
        
        # Buttons for diagram display
        buttonLayout = QtGui.QGridLayout() 
        bnames = [["All [x]", "All [y]", "All [z]" ], 
                           ["N [x]", "Q [y]", "Q [z]"], 
                           ["Mt [x]",  "Mb [z]", "Mb [y]"], 
                           ["",  "w [y]",  "w [z]"], 
                           ["sigma [x]", "sigma [y]", "sigma [z]"], 
                           ["tau [x]",  "sigmab [z]", "sigmab [y]"]]
        slots = [[self.slotAllx,  self.slotAlly,  self.slotAllz], 
                      [self.slotFx,  self.slotQy,  self.slotQz], 
                      [self.slotMx,  self.slotMz,  self.slotMy], 
                      [self.slotNone,  self.slotWy, self.slotWz], 
                      [self.slotSigmax,  self.slotSigmay,  self.slotSigmaz], 
                      [self.slotTaut,  self.slotSigmabz,  self.slotSigmaby]]
        self.buttons = [[None,  None,  None],  [None,  None,  None],  [None,  None,  None],  [None,  None,  None],  [None,  None,  None],  [None,  None,  None]]

        for col in range(3):
            for row in range(6):
                button = QtGui.QPushButton(bnames[row][col])
                buttonLayout.addWidget(button,  row,  col)
                self.buttons[row][col] = button
                button.clicked.connect(slots[row][col])
                
        # Create Shaft object
        self.shaft = Shaft(self)
        # Create table widget
        self.form = QtGui.QWidget()
        self.table = WizardShaftTable(self, self.shaft)        
        
        # The top layout will contain the Shaft Wizard layout plus the elements of the FEM constraints dialog
        layout = QtGui.QVBoxLayout()
        layout.setObjectName("ShaftWizard") # Do not change or translate: Required to detect whether Shaft Wizard is running in FemGui::ViewProviderFemConstraintXXX
        sublayout = QtGui.QVBoxLayout()
        sublayout.setObjectName("ShaftWizardLayout") # Do not change or translate        
        sublayout.addWidget(self.table.widget)
        sublayout.addLayout(buttonLayout)
        layout.addLayout(sublayout)
        self.form.setLayout(layout)
        
        # Switch to feature window
        mdi=QtGui.qApp.activeWindow().findChild(QtGui.QMdiArea)
        cw.setActiveSubWindow(featureWindow)
        
    def slotAllx(self):
        self.shaft.showDiagram("Allx")
    def slotAlly(self):
        self.shaft.showDiagram("Ally")
    def slotAllz(self):
        self.shaft.showDiagram("Allz")
        
    def slotFx(self):
        self.shaft.showDiagram("Nx")        
    def slotQy(self):
        self.shaft.showDiagram("Qy")        
    def slotQz(self):
        self.shaft.showDiagram("Qz")
    
    def slotMx(self):
        self.shaft.showDiagram("Mx")
    def slotMz(self):
        self.shaft.showDiagram("Mz")        
    def slotMy(self):
        self.shaft.showDiagram("My")
        
    def slotNone(self):
        pass
    def slotWy(self):
        self.shaft.showDiagram("wy")
    def slotWz(self):
        self.shaft.showDiagram("wz")
        
    def slotSigmax(self):
        self.shaft.showDiagram("sigmax")
    def slotSigmay(self):
        self.shaft.showDiagram("sigmay")        
    def slotSigmaz(self):
        self.shaft.showDiagram("sigmaz")
        
    def slotTaut(self):
        self.shaft.showDiagram("taut")
    def slotSigmabz(self):
        self.shaft.showDiagram("sigmabz")        
    def slotSigmaby(self):
        self.shaft.showDiagram("sigmaby")
        
    def updateButton(self,  row,  col,  flag):
        self.buttons[row][col].setEnabled(flag)
        
    def updateButtons(self,  col,  flag):
        for row in range(len(self.buttons)):
            self.updateButton(row,  col,  flag)
        
    def getStandardButtons(self):
        return int(QtGui.QDialogButtonBox.Ok)

    def accept(self):
        if self.table:
            del self.table
        if self.shaft:
            del self.shaft
        if self.form:
            del self.form
        return True
        
    def isAllowedAlterDocument(self):
        return False