コード例 #1
0
    def onParentSelected(self):
        # clear the selection in the GUI window
        Gui.Selection.clearSelection()
        # build the LCS table
        self.attLCStable = []
        # the current text in the combo-box is the link's name...
        if self.parentList.currentIndex() > 0:
            parentName = self.parentTable[self.parentList.currentIndex()].Name
            parentPart = self.activeDoc.getObject(parentName)
            if parentPart:
                # we get the LCS from the linked part
                self.attLCStable = Asm4.getPartLCS(parentPart.LinkedObject)
                # linked part & doc
                dText = parentPart.LinkedObject.Document.Name + '#'
                # if the linked part has been renamed by the user
                pText = Asm4.nameLabel(parentPart.LinkedObject)
                self.parentDoc.setText(dText + pText)
                # highlight the selected part:
                Gui.Selection.addSelection(parentPart.Document.Name, 'Model',
                                           parentPart.Name + '.')
        # something wrong
        else:
            return

        # build the list
        self.attLCSlist.clear()
        for lcs in self.attLCStable:
            newItem = QtGui.QListWidgetItem()
            newItem.setText(Asm4.nameLabel(lcs))
            newItem.setIcon(lcs.ViewObject.Icon)
            self.attLCSlist.addItem(newItem)
            #self.attLCStable.append(lcs)
        return
コード例 #2
0
 def initUI(self):
     self.lscName.setText(Asm4.nameLabel(self.selectedDatum))
     self.parentDoc.clear()
     self.attLCSlist.clear()
     # list and table containing the available parents in the assembly to choose from
     self.parentList.clear()
     self.parentTable = []
     self.parentList.addItem('Please select')
     self.parentTable.append([])
コード例 #3
0
 def clicked(self, bt):
     if bt == QtGui.QDialogButtonBox.Ignore:
         # ask for confirmation before resetting everything
         msgName = Asm4.nameLabel(self.selectedDatum)
         # see whether the ExpressionEngine field is filled
         if self.selectedDatum.ExpressionEngine:
             # if yes, then ask for confirmation
             confirmed = Asm4.confirmBox(
                 'This command will release all attachments on ' + msgName +
                 ' and set it to manual positioning in its current location.'
             )
             # if not, then it's useless to bother the user
         else:
             confirmed = True
         if confirmed:
             self.selectedDatum.setExpression('Placement', None)
         self.finish()
コード例 #4
0
    def __init__(self):
        self.base = QtGui.QWidget()
        self.form = self.base
        self.form.setWindowIcon(QtGui.QIcon(iconFile))
        self.form.setWindowTitle('Place a Datum object in the assembly')

        # get the current active document to avoid errors if user changes tab
        self.activeDoc = App.activeDocument()
        # the parent (top-level) assembly is the App::Part called Model (hard-coded)
        self.parentAssembly = self.activeDoc.Model

        # check that we have selected a PartDesign::CoordinateSystem
        self.selectedDatum = Asm4.getSelectedDatum()

        # Now we can draw the UI
        self.drawUI()
        self.initUI()
        # now self.parentList and self.parentTable are available

        # find all the linked parts in the assembly
        for objName in self.parentAssembly.getSubObjects():
            # remove the trailing .
            obj = self.activeDoc.getObject(objName[0:-1])
            if obj.TypeId == 'App::Link':
                # add it to our list if it's a link to an App::Part ...
                if hasattr(obj.LinkedObject, 'isDerivedFrom'):
                    linkedObj = obj.LinkedObject
                    if linkedObj.isDerivedFrom(
                            'App::Part') or linkedObj.isDerivedFrom(
                                'PartDesign::Body'):
                        # add to the object table holding the objects ...
                        self.parentTable.append(obj)
                        # ... and add to the drop-down combo box with the assembly tree's parts
                        objIcon = obj.LinkedObject.ViewObject.Icon
                        objText = Asm4.nameLabel(obj)
                        self.parentList.addItem(objIcon, objText, obj)

        self.old_EE = ' '
        # get and store the Placement's current ExpressionEngine:
        self.old_EE = Asm4.placementEE(self.selectedDatum.ExpressionEngine)

        # decode the old ExpressionEngine
        # if the decode is unsuccessful, old_Expression is set to False
        # and old_attPart and old_attLCS are set to 'None'
        old_Parent = ''
        old_ParentPart = ''
        old_attLCS = ''
        (old_Parent, old_ParentPart,
         old_attLCS) = self.splitExpressionDatum(self.old_EE)

        # find the oldPart in the current part list...
        oldPart = self.parentList.findText(old_Parent)
        # if not found
        if oldPart == -1:
            # set to initial "Select linked Part" entry
            self.parentList.setCurrentIndex(0)
        else:
            self.parentList.setCurrentIndex(oldPart)

        parent_found = False
        parent_index = 1
        for item in self.parentTable[1:]:
            if item.Name == old_Parent:
                parent_found = True
                break
            else:
                parent_index += 1
        if not parent_found:
            parent_index = 0
        self.parentList.setCurrentIndex(parent_index)
        # this should have triggered self.getPartLCS() to fill the LCS list

        # find the old attachment Datum in the list of the Datums in the linked part...
        # lcs_found = []
        lcs_found = self.attLCSlist.findItems(old_attLCS,
                                              QtCore.Qt.MatchExactly)
        if not lcs_found:
            lcs_found = self.attLCSlist.findItems(old_attLCS + ' (',
                                                  QtCore.Qt.MatchContains)
        if lcs_found:
            # ... and select it
            self.attLCSlist.setCurrentItem(lcs_found[0])