def clicked(self, bt):
     if bt == QtGui.QDialogButtonBox.Ignore:
         # ask for confirmation before resetting everything
         msgName = Asm4.nameLabel(self.selectedFastener)
         # see whether the ExpressionEngine field is filled
         if self.old_EE :
             # 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.')
         else:
             # if not, then it's useless to bother the user
             confirmed = True
         if confirmed:
             # unset the ExpressionEngine in the Placement
             self.selectedFastener.setExpression('Placement', None)
             # reset Asm4 properties
             Asm4.makeAsmProperties( self.selectedFastener, reset=True )
         self.finish()
Example #2
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()
 def addSelection(self, doc, obj, sub, pnt):
     selPath = Asm4.getSelectionPath(doc, obj, sub)
     selObj = Gui.Selection.getSelection()[0]
     if selObj and len(selPath) > 2:
         selLinkName = selPath[2]
         idx = self.parentList.findText(selLinkName)
         if idx >= 0:
             self.parentList.setCurrentIndex(idx)
             #selObj = Gui.Selection.getSelection()[0]
             #if selObj:
             found = self.attLCSlist.findItems(Asm4.nameLabel(selObj),
                                               QtCore.Qt.MatchExactly)
             if len(found) > 0:
                 self.attLCSlist.clearSelection()
                 found[0].setSelected(True)
                 self.attLCSlist.scrollToItem(found[0])
                 self.attLCSlist.setCurrentRow(self.attLCSlist.row(
                     found[0]))
                 self.onApply()
Example #4
0
 def clicked(self, button):
     if button == QtGui.QDialogButtonBox.Ignore:
         # ask for confirmation before resetting everything
         msgName = Asm4.nameLabel(self.selectedLink)
         # see whether the ExpressionEngine field is filled
         if self.selectedLink.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:
             # unset the ExpressionEngine for the Placement
             self.selectedLink.setExpression('Placement', None)
             # reset the assembly properties
             Asm4.makeAsmProperties( self.selectedLink, reset=True )
             # finish
             FCC.PrintWarning("Part is now manually placed\n")
             self.finish()
         else:
             FCC.PrintWarning("Part untouched\n")
             self.finish()
Example #5
0
    def __init__(self):
        self.base = QtGui.QWidget()
        self.form = self.base
        iconFile = os.path.join(Asm4.iconPath, 'Place_Link.svg')
        self.form.setWindowIcon(QtGui.QIcon(iconFile))
        self.form.setWindowTitle('Place linked Part')

        # check that we have selected two LCS or an App::Link object
        self.selectedLink = []
        self.selectedLCSA = None
        self.selectedLinkB = None
        self.selectedLCSB = None
        selection = Asm4.getSelectedLink()
        #selectedLCSPair = Asm4.getLinkAndDatum2()
        self.Xtranslation = 0.00
        self.Ytranslation = 0.00
        self.Ztranslation = 0.00
        self.XrotationAngle = 0.00
        self.YrotationAngle = 0.00
        self.ZrotationAngle = 0.00

        # draw the GUI, objects are defined later down
        self.drawUI()
        global taskUI
        taskUI = self

        #Handle single selected App::Link
        if not selection:
            # This shouldn't happen
            FCC.PrintWarning(
                "This is not an error message you are supposed to see, something went wrong\n"
            )
            Gui.Control.closeDialog()
        else:
            self.selectedLink = selection
            Asm4.makeAsmProperties(self.selectedLink)

        #save original AttachmentOffset of linked part
        self.old_LinkAttachmentOffset = self.selectedLink.AttachmentOffset
        self.old_LinkRotation = self.selectedLink.AttachmentOffset.Rotation
        self.old_LinkPosition = self.selectedLink.AttachmentOffset.Base
        # default values correspond to original AttachmentOffset of linked part
        self.Xtranslation = self.old_LinkPosition[0]
        self.Ytranslation = self.old_LinkPosition[1]
        self.Ztranslation = self.old_LinkPosition[2]
        self.XrotationAngle = self.old_LinkRotation.toEuler()[0]
        self.YrotationAngle = self.old_LinkRotation.toEuler()[1]
        self.ZrotationAngle = self.old_LinkRotation.toEuler()[2]

        # save previous view properties
        self.old_OverrideMaterial = self.selectedLink.ViewObject.OverrideMaterial
        self.old_DrawStyle = self.selectedLink.ViewObject.DrawStyle
        self.old_LineWidth = self.selectedLink.ViewObject.LineWidth
        self.old_DiffuseColor = self.selectedLink.ViewObject.ShapeMaterial.DiffuseColor
        self.old_Transparency = self.selectedLink.ViewObject.ShapeMaterial.Transparency
        # set new view properties
        self.selectedLink.ViewObject.OverrideMaterial = True
        self.selectedLink.ViewObject.DrawStyle = DrawStyle
        self.selectedLink.ViewObject.LineWidth = LineWidth
        self.selectedLink.ViewObject.ShapeMaterial.DiffuseColor = DiffuseColor
        self.selectedLink.ViewObject.ShapeMaterial.Transparency = Transparency

        # 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 the link is an Asm4 link:
        self.isAsm4EE = False
        if hasattr(self.selectedLink, 'AssemblyType'):
            if self.selectedLink.AssemblyType == 'Asm4EE' or self.selectedLink.AssemblyType == '':
                self.isAsm4EE = True
            else:
                Asm4.warningBox(
                    "This Link's assembly type doesn't correspond to this WorkBench"
                )
                return

        # initialize the UI with the current data
        self.attLCStable = []
        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' and hasattr(obj.LinkedObject,
                                                     'isDerivedFrom'):
                if obj.LinkedObject.isDerivedFrom(
                        'App::Part') or obj.LinkedObject.isDerivedFrom(
                            'PartDesign::Body'):
                    # ... except if it's the selected link itself
                    if obj != self.selectedLink:
                        self.parentTable.append(obj)
                        # 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)

        # find all the LCS in the selected link
        self.partLCStable = Asm4.getPartLCS(self.selectedLink.LinkedObject)
        # build the list
        self.partLCSlist.clear()
        for lcs in self.partLCStable:
            newItem = QtGui.QListWidgetItem()
            newItem.setText(Asm4.nameLabel(lcs))
            newItem.setIcon(lcs.ViewObject.Icon)
            self.partLCSlist.addItem(newItem)

        # get the old values
        if self.isAsm4EE:
            self.old_AO = self.selectedLink.AttachmentOffset
            self.old_linkLCS = self.selectedLink.AttachedBy[1:]
            (self.old_Parent, separator,
             self.old_parentLCS) = self.selectedLink.AttachedTo.partition('#')
        else:
            self.old_AO = []
            self.old_Parent = ''

        self.old_EE = ''
        # get and store the current expression engine:
        self.old_EE = Asm4.placementEE(self.selectedLink.ExpressionEngine)

        # decode the old ExpressionEngine
        old_Parent = ''
        old_ParentPart = ''
        old_attLCS = ''
        constrName = ''
        linkedDoc = ''
        old_linkLCS = ''
        # if the decode is unsuccessful, old_Expression is set to False and the other things are set to 'None'
        (old_Parent, old_attLCS,
         old_linkLCS) = Asm4.splitExpressionLink(self.old_EE, self.old_Parent)

        # find the old LCS in the list of LCS of the linked part...
        # MatchExactly, MatchContains, MatchEndsWith ...
        lcs_found = self.partLCSlist.findItems(old_linkLCS,
                                               QtCore.Qt.MatchExactly)
        if not lcs_found:
            lcs_found = self.partLCSlist.findItems(old_linkLCS + ' (',
                                                   QtCore.Qt.MatchStartsWith)
        if lcs_found:
            # ... and select it
            self.partLCSlist.setCurrentItem(lcs_found[0])

        # find the oldPart in the part list...
        if old_Parent == 'Parent Assembly':
            parent_found = True
            parent_index = 1
        else:
            parent_found = False
            parent_index = 1
            for item in self.parentTable[1:]:
                if item.Name == old_Parent:
                    parent_found = True
                    break
                else:
                    parent_index = 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 = self.attLCSlist.findItems(old_attLCS,
                                              QtCore.Qt.MatchExactly)
        if not lcs_found:
            lcs_found = self.attLCSlist.findItems(old_attLCS + ' (',
                                                  QtCore.Qt.MatchStartsWith)
        if lcs_found:
            # ... and select it
            self.attLCSlist.setCurrentItem(lcs_found[0])
    def Activated(self):

        # 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 = []
        selection = self.checkSelectionDatum()
        if not selection:
            self.close()
        else:
            self.selectedDatum = selection

        # check if the datum object is already mapped to something
        if self.selectedDatum.MapMode != 'Deactivated':
            message = 'This datum object \"'+self.selectedDatum.Label+'\" is mapped to some geometry. Attaching-it with Assembly4 will loose this mapping.'
            if Asm4.confirmBox(message):
                # unset MappingMode
                self.selectedDatum.MapMode = 'Deactivated'
            else:
                # don't do anything and ...
                return

        # Now we can draw the UI
        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') and obj.LinkedObject.isDerivedFrom('App::Part'):
                    self.parentTable.append( obj )
                    # 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)

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

        # 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 ) = Asm4.splitExpressionDatum( self.old_EE )
        self.expression.setText( self.old_EE + ' => old_Parent = '+ old_Parent )


        # 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] )
    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) = Asm4.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])
Example #8
0
    def Activated(self):
        # 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

        self.attLCStable = []

        # check that we have selected an App::Link object
        self.selectedLink = []
        selection = self.GetSelection()
        if not selection:
            self.close()
        else:
            self.selectedLink = selection

        # check that the link is an Asm4 link:
        self.isAsm4EE = False
        if hasattr(self.selectedLink, 'AssemblyType'):
            if self.selectedLink.AssemblyType == 'Asm4EE' or self.selectedLink.AssemblyType == '':
                self.isAsm4EE = True
            else:
                Asm4.warningBox(
                    "This Link's assembly type doesn't correspond to this WorkBench"
                )
                return

        # initialize the UI with the current data
        self.initUI()
        # now self.parentList and self.parentTable are available

        # find all the linked parts in the assembly
        # for obj in self.activeDoc.findObjects("App::Link"):
        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'
                           ) and obj.LinkedObject.isDerivedFrom('App::Part'):
                    # ... except if it's the selected link itself
                    if obj != self.selectedLink:
                        self.parentTable.append(obj)
                        # 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)

        # find all the LCS in the selected link
        self.partLCStable = self.getPartLCS(self.selectedLink.LinkedObject)
        # build the list
        self.partLCSlist.clear()
        for lcs in self.partLCStable:
            newItem = QtGui.QListWidgetItem()
            newItem.setText(Asm4.nameLabel(lcs))
            newItem.setIcon(lcs.ViewObject.Icon)
            self.partLCSlist.addItem(newItem)

        # get the old values
        if self.isAsm4EE:
            self.old_AO = self.selectedLink.AttachmentOffset
            self.old_linkLCS = self.selectedLink.AttachedBy[1:]
            (self.old_Parent, separator,
             self.old_parentLCS) = self.selectedLink.AttachedTo.partition('#')
        else:
            self.old_AO = []
            self.old_Parent = ''

        self.old_EE = ''
        # get and store the current expression engine:
        self.old_EE = Asm4.placementEE(self.selectedLink.ExpressionEngine)
        # for debugging, use this field to print text
        #self.expression.setText( self.old_EE )

        # decode the old ExpressionEngine
        old_Parent = ''
        old_ParentPart = ''
        old_attLCS = ''
        constrName = ''
        linkedDoc = ''
        old_linkLCS = ''
        # if the decode is unsuccessful, old_Expression is set to False and the other things are set to 'None'
        (old_Parent, old_attLCS,
         old_linkLCS) = Asm4.splitExpressionLink(self.old_EE, self.old_Parent)
        #self.expression.setText( old_Parent +'***'+ self.old_Parent )

        # find the old LCS in the list of LCS of the linked part...
        # MatchExactly, MatchContains, MatchEndsWith ...
        lcs_found = self.partLCSlist.findItems(old_linkLCS,
                                               QtCore.Qt.MatchExactly)
        if not lcs_found:
            lcs_found = self.partLCSlist.findItems(old_linkLCS + ' (',
                                                   QtCore.Qt.MatchStartsWith)
        if lcs_found:
            # ... and select it
            self.partLCSlist.setCurrentItem(lcs_found[0])

        # find the oldPart in the part list...
        if old_Parent == 'Parent Assembly':
            parent_found = True
            parent_index = 1
        else:
            parent_found = False
            parent_index = 1
            for item in self.parentTable[1:]:
                if item.Name == old_Parent:
                    parent_found = True
                    break
                else:
                    parent_index = 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 = self.attLCSlist.findItems(old_attLCS,
                                              QtCore.Qt.MatchExactly)
        if not lcs_found:
            lcs_found = self.attLCSlist.findItems(old_attLCS + ' (',
                                                  QtCore.Qt.MatchStartsWith)
        if lcs_found:
            # ... and select it
            self.attLCSlist.setCurrentItem(lcs_found[0])

        # the widget is shown and not executed to allow it to stay on top
        self.show()
    def __init__(self):
        self.base = QtGui.QWidget()
        self.form = self.base        
        self.form.setWindowIcon(QtGui.QIcon( iconFile ))
        self.form.setWindowTitle('Attach a Fastener 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
        # has been checked before calling
        self.selectedFastener = getSelectionFS()

        # 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' and 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)

        # check where the fastener was attached to
        (self.old_Parent, separator, self.old_parentLCS) = self.selectedFastener.AttachedTo.partition('#')
        # get and store the Placement's current ExpressionEngine:
        self.old_EE = Asm4.placementEE( self.selectedFastener.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_parentLCS = ''
        if  self.old_EE and self.old_Parent:
            ( old_Parent, old_parentPart, old_parentLCS ) = self.splitExpressionFastener( self.old_EE, self.old_Parent )

        # find the oldPart in the part list...
        parent_index = 1
        if old_Parent == 'Parent Assembly':
            parent_found = True
        else:
            parent_found = False
            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 oldLCS in the list of LCS of the linked part...
        lcs_found = []
        lcs_found = self.attLCSlist.findItems( old_parentLCS, QtCore.Qt.MatchExactly )
        if lcs_found:
            # ... and select it
            self.attLCSlist.setCurrentItem( lcs_found[0] )
        else:
            # may-be it was renamed, see if we can find it as (name)
            lcs_found = self.attLCSlist.findItems( '('+old_parentLCS+')', QtCore.Qt.MatchContains )
            if lcs_found:
                self.attLCSlist.setCurrentItem( lcs_found[0] )