Exemple #1
0
 def Activated(self):
     #Handle single selected App::Link
     selectedLink = None
     parentAssembly = None
     selection = Asm4.getSelectedLink()
     if not selection:
         # This shouldn't happen
         FCC.PrintWarning(
             "This is not an error message you are supposed to see, something went wrong\n"
         )
         return
     else:
         parent = selection.getParentGeoFeatureGroup()
         # only handle if the parent is at the root of the document:
         if parent and parent.TypeId == 'App::Part' and parent.getParentGeoFeatureGroup(
         ) is None:
             # only accept Asm4 Models as assemblies
             # this is self-imposed, works also without an Asm4 Model
             if parent.Name == 'Model':
                 # launch the UI in the task panel
                 Gui.Control.showDialog(placeLinkUI())
             else:
                 Asm4.warningBox(
                     'Please select a link in the assembly Model')
         else:
             Asm4.warningBox('Please select a link in the assembly Model.')
     return
Exemple #2
0
    def __init__(self):
        ( link, datum ) = Asm4.getLinkAndDatum()
        if not link is None:
            self.targetDatum = datum
            self.targetLink  = link
            
            self.base = QtGui.QWidget()
            self.form = self.base        
            self.form.setWindowIcon(QtGui.QIcon( iconFile ))
            self.form.setWindowTitle('Import a Datum object into the Assembly')

            # get the current active document to avoid errors if user changes tab
            self.activeDoc = App.ActiveDocument
            self.parentAssembly = self.activeDoc.Model

            '''
            # this has been checked before calling
            self.targetDatum = getSelection()
            selectionTree = Gui.Selection.getSelectionEx("", 0)[0].SubElementNames[0]
            (targetLinkName, sel, dot) = selectionTree.partition('.'+self.targetDatum.Name)
            self.targetLink = self.activeDoc.getObject( targetLinkName )
            '''

            # make and initialize UI
            self.drawUI()
            self.initUI()
        else:
            Asm4.warningBox( 'The selected datum object cannot be imported into this assembly' )
 def accept(self):
     selectedItems = self.configurationList.selectedItems()
     if len(selectedItems) == 0:
         Asm4.warningBox('Please select a configuration in the list')
         return
     config = selectedItems[0]
     RestoreConfiguration(config.name)
     Gui.Control.closeDialog()
Exemple #4
0
 def Activated(self):
     # check that our selection is correct
     (link, datum) = Asm4.getLinkAndDatum()
     if not link:
         Asm4.warningBox(
             'The selected datum object cannot be imported into this assembly'
         )
     else:
         Gui.Control.showDialog(importDatumUI())
Exemple #5
0
    def accept(self):
        selectedItems = self.configurationList.selectedItems()
        if len(selectedItems) == 0:
            Asm4.warningBox('No cofiguration selected!')
            return

        item = selectedItems[0]
        RestoreConfiguration(item.name)
        Gui.Control.closeDialog()
Exemple #6
0
 def checkModel(self):
     # check wheter there is already a Model in the document
     # we don't check whether it's an App::Part or not
     # Returns True if there is an object called 'Model'
     if self.activeDoc.getObject('Model'):
         Asm4.warningBox(
             "There is already an Assembly4 Model in this document.")
         return (True)
     else:
         return (False)
Exemple #7
0
 def checkModel(self):
     if self.activeDoc.getObject('Model'):
         if self.activeDoc.Model.TypeId == 'App::Part' and self.activeDoc.Model.Type == 'Assembly4 Model':
             Asm4.warningBox(
                 "This document already contains an Assembly4 Model.")
         else:
             Asm4.warningBox(
                 "This document already contains another FreeCAD object called \"Model\". I cannot create an Assembly4 Model."
             )
         return (True)
     else:
         return (False)
    def accept(self):
        confName = self.configurationName.text().strip()
        confDescr = self.configurationDescription.text().strip()
        if confName == '':
            Asm4.warningBox('Please specify configuration name!')
            self.configurationName.setFocus()
            return
        # if no description provided, set the name as description
        if confDescr == '':
            confDescr = ' '

        self.SaveConfiguration(confName, confDescr)
        Gui.Control.closeDialog()
Exemple #9
0
    def Activated(self):
        # check that we have somewhere to put our stuff
        selectedObj = self.checkSelection()

        # check whether we have selected a container
        if selectedObj.TypeId in self.containers:
            parentContainer = selectedObj
        # if a datum object is selected we try to find the parent container
        elif selectedObj.TypeId in Asm4.datumTypes:
            parent = selectedObj.getParentGeoFeatureGroup()
            if parent.TypeId in self.containers:
                parentContainer = parent
        # something went wrong
        else:
            Asm4.warningBox("I can't create a " + self.datumType +
                            " with the current selections")

        # check whether there is already a similar datum, and increment the instance number
        # instanceNum = 1
        #while App.ActiveDocument.getObject( self.datumName+'_'+str(instanceNum) ):
        #    instanceNum += 1
        #datumName = self.datumName+'_'+str(instanceNum)
        if parentContainer:
            # input dialog to ask the user the name of the Sketch:
            proposedName = Asm4.nextInstance(self.datumName, startAtOne=True)
            text, ok = QtGui.QInputDialog.getText(
                None,
                'Create new ' + self.datumName,
                'Enter ' + self.datumName + ' name :' + ' ' * 40,
                text=proposedName)
            if ok and text:
                # App.activeDocument().getObject('Model').newObject( 'Sketcher::SketchObject', text )
                createdDatum = parentContainer.newObject(self.datumType, text)
                # automatic resizing of datum Plane sucks, so we set it to manual
                if self.datumType == 'PartDesign::Plane':
                    createdDatum.ResizeMode = 'Manual'
                    createdDatum.Length = 100
                    createdDatum.Width = 100
                # if color or transparency is specified for this datum type
                if self.datumColor:
                    Gui.ActiveDocument.getObject(
                        createdDatum.Name).ShapeColor = self.datumColor
                if self.datumAlpha:
                    Gui.ActiveDocument.getObject(
                        createdDatum.Name).Transparency = self.datumAlpha
                # highlight the created datum object
                Gui.Selection.clearSelection()
                Gui.Selection.addSelection(App.ActiveDocument.Name,
                                           parentContainer.Name,
                                           createdDatum.Name + '.')
                Gui.runCommand('Part_EditAttachment')
Exemple #10
0
    def accept(self):
        if self.configurationName.text().strip() == '':
            Asm4.warningBox('Please specify configuration name!')
            self.configurationName.setFocus()
            return

        if self.configurationDescription.text().strip() == '':
            Asm4.warningBox('Please specify configuration description!')
            self.configurationDescription.setFocus()
            return

        SaveConfiguration(self.configurationName.text().strip(),
                          self.configurationDescription.text().strip())
        Gui.Control.closeDialog()
Exemple #11
0
    def Activated(self):
        # get the current active document to avoid errors if user changes tab
        self.activeDoc = App.activeDocument()
        # check whether there is already Model in the document
        if not self.checkModel():
            # create a group 'Parts' to hold all parts in the assembly document (if any)
            # must be done before creating the Asm4 Model
            partsGroup = self.activeDoc.getObject('Parts')
            if partsGroup is None:
                partsGroup = self.activeDoc.addObject(
                    'App::DocumentObjectGroup', 'Parts')

            # create a new App::Part called 'Model'
            model = self.activeDoc.addObject('App::Part', 'Model')
            # set the type as a "proof" that it's an Assembly4 Model
            model.Type = 'Assembly4 Model'
            # add an LCS at the root of the Model, and attach it to the 'Origin'
            lcs0 = model.newObject('PartDesign::CoordinateSystem',
                                   'LCS_Origin')
            lcs0.Support = [(model.Origin.OriginFeatures[0], '')]
            lcs0.MapMode = 'ObjectXY'
            lcs0.MapReversed = False
            # create a group Constraints to store future solver constraints there
            model.newObject('App::DocumentObjectGroup', 'Constraints')
            # create an object Variables to hold variables to be used in this document
            model.addObject(Asm4.createVariables())
            # create a Configuration property
            model.addProperty('App::PropertyEnumeration', 'Configuration',
                              'Parameters')
            model.Configuration = ['Default']

            # move existing parts and bodies at the document root to the Parts group
            # not nested inside other parts, to keep hierarchy
            if partsGroup.TypeId == 'App::DocumentObjectGroup':
                for obj in self.activeDoc.Objects:
                    if obj.TypeId in Asm4.containerTypes and obj.Name != 'Model' and obj.getParentGeoFeatureGroup(
                    ) is None:
                        partsGroup.addObject(obj)
            else:
                Asm4.warningBox(
                    'There seems to already be a Parts object, you might get unexpected behaviour'
                )

            # recompute to get rid of the small overlays
            model.recompute()
            self.activeDoc.recompute()
Exemple #12
0
    def __init__(self):
        (link, datum) = Asm4.getLinkAndDatum()
        if link:
            self.targetDatum = datum
            self.targetLink = link

            self.base = QtGui.QWidget()
            self.form = self.base
            self.form.setWindowIcon(QtGui.QIcon(iconFile))
            self.form.setWindowTitle('Import a Datum object into the Assembly')

            # get the current active document to avoid errors if user changes tab
            self.activeDoc = App.ActiveDocument
            self.parentAssembly = self.activeDoc.Model

            # make and initialize UI
            self.drawUI()
            self.initUI()
        else:
            Asm4.warningBox(
                'The selected datum object cannot be imported into this assembly'
            )
Exemple #13
0
 def Activated(self):
     # get the selected object
     selObj, selAxis = self.checkObjAndAxis()
     #FCC.PrintMessage('Selected '+selObj.Name+' of '+selObj.TypeId+' TypeId' )
     # check that object and axis belong to the same parent
     objParent = selObj.getParentGeoFeatureGroup()
     axisParent = selAxis.getParentGeoFeatureGroup()
     if not objParent == axisParent:
         msg = 'Please select an object and an axis belonging to the same part'
         Asm4.warningBox(msg)
     # if something valid has been returned:
     else:
         # create the array
         array = selObj.Document.addObject("App::FeaturePython",
                                           'Array_' + selObj.Label,
                                           CircularArray(), None, True)
         # set array parameters
         array.setLink(selObj)
         array.Axis = selAxis
         array.ArraySteps = "Full Circle"
         array.ElementCount = 5
         # set the viewprovider
         ViewProviderLink(array.ViewObject, self.iconFile)
         # move array into common parent (if any)
         if objParent:
             objParent.addObject(array)
         # hide original object
         #array.SourceObject.ViewObject.hide()
         selObj.Visibility = False
         # update
         array.recompute()
         objParent.recompute()
         App.ActiveDocument.recompute()
         Gui.Selection.clearSelection()
         Gui.Selection.addSelection(objParent.Document.Name, objParent.Name,
                                    array.Name + '.')
    def Activated(self):
        # This function is executed when the command is activated

        # initialise stuff
        # this is the App::Part where we'll put our App::Link
        self.asmPart = None
        self.origLink = None
        self.allParts = []
        self.partsDoc = []
        self.filterPartList.clear()
        self.partList.clear()
        self.linkNameInput.clear()

        # get the current active document to avoid errors if user changes tab
        self.activeDoc = App.ActiveDocument

        # an App::Part at the root of the document is selected, we insert the link there
        if Asm4.getSelectedRootPart():
            self.asmPart = Asm4.getSelectedRootPart()
        # a link is selected, let's see if we can duplicate it
        elif Asm4.getSelectedLink():
            selObj = Asm4.getSelectedLink()
            parent = selObj.getParentGeoFeatureGroup()
            # if the selectd link is in a root App::Part
            if parent.TypeId == 'App::Part' and parent.getParentGeoFeatureGroup(
            ) is None:
                self.asmPart = parent
                self.origLink = selObj
        elif Asm4.checkModel():
            self.asmPart = self.activeDoc.getObject('Model')

        if self.asmPart is None:
            Asm4.warningBox('Please create an Assembly Model')
            return

        # Search for all App::Parts and PartDesign::Body in all open documents
        # Also store the document of the part
        for doc in App.listDocuments().values():
            for obj in doc.findObjects("App::Part"):
                # we don't want to link to itself to the 'Model' object
                # other App::Part in the same document are OK
                # but only those at top level (not nested inside other containers)
                if obj != self.asmPart and obj.getParentGeoFeatureGroup(
                ) is None:
                    self.allParts.append(obj)
                    self.partsDoc.append(doc)
            for obj in doc.findObjects("PartDesign::Body"):
                # but only those at top level (not nested inside other containers)
                if obj.getParentGeoFeatureGroup() is None:
                    self.allParts.append(obj)
                    self.partsDoc.append(doc)

        # build the list
        for part in self.allParts:
            newItem = QtGui.QListWidgetItem()
            if part.Name == part.Label:
                partText = part.Name
            else:
                partText = part.Label + ' (' + part.Name + ')'
            newItem.setText(part.Document.Name + "#" + partText)
            newItem.setIcon(part.ViewObject.Icon)
            self.partList.addItem(newItem)

        # if an existing App::Link was selected
        if self.origLink:
            origPart = self.origLink.LinkedObject
            # try to find the original part of the selected link
            # MatchExactly, MatchContains, MatchEndsWith, MatchStartsWith ...
            origPartText = origPart.Document.Name + "#" + origPart.Label
            # if Label!=Name then the string still starts with Label
            partFound = self.partList.findItems(origPartText,
                                                QtCore.Qt.MatchStartsWith)
            if partFound:
                self.partList.setCurrentItem(partFound[0])
                # set the proposed name to a duplicate of the original link name
                origName = self.origLink.Label
                # if the last character is a number, we increment this number
                lastChar = origName[-1]
                if lastChar.isnumeric():
                    rootName = origName[:-1]
                    instanceNum = int(lastChar)
                    while App.ActiveDocument.getObject(rootName +
                                                       str(instanceNum)):
                        instanceNum += 1
                    proposedLinkName = rootName + str(instanceNum)
                # else we append a _2 to the original name (Label)
                else:
                    proposedLinkName = origName + '_2'
                self.linkNameInput.setText(proposedLinkName)

        # show the UI
        self.show()
Exemple #15
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()
Exemple #16
0
    def Activated(self):
        # get the current active document to avoid errors if user changes tab
        self.activeDoc = App.activeDocument()

        # check that we have selected an App::Link object
        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':
                self.isAsm4EE = True
            else:
                Asm4.warningBox(
                    "This Link's assembly type doesn't correspond to this WorkBench"
                )
                return

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

        # the parent (top-level) assembly is the App::Part called Model (hard-coded)
        # What would happen if there are 2 App::Part ?
        self.parentAssembly = self.activeDoc.Model
        # Initialize the assembly tree with the Parrent Assembly as first element
        # all the parts in the assembly, except the selected link
        self.asmParts = []
        # the first item is "Select attachment Parent" therefore we add an empty object
        self.asmParts.append([])
        self.asmParts.append(self.parentAssembly)
        # Add it as first element to the drop-down combo-box
        parentIcon = self.parentAssembly.ViewObject.Icon
        self.parentList.addItem(parentIcon, 'Parent Assembly',
                                self.parentAssembly)

        # find all the linked parts in the assembly
        for obj in self.activeDoc.findObjects("App::Link"):
            # add it to our list if it's a link to an App::Part ...
            if hasattr(obj, 'LinkedObject') and obj.LinkedObject.isDerivedFrom(
                    'App::Part'):
                # ... except if it's the selected link itself
                if obj != self.selectedLink:
                    self.asmParts.append(obj)
                    # add to the drop-down combo box with the assembly tree's parts
                    objIcon = obj.LinkedObject.ViewObject.Icon
                    if obj.Name == obj.Label:
                        objText = obj.Name
                    else:
                        objText = obj.Label + ' (' + obj.Name + ')'
                    self.parentList.addItem(objIcon, objText, obj)

        # find all the LCS in the selected link
        self.partLCStable = self.getPartLCS(self.selectedLink.LinkedObject)
        # build the list
        for lcs in self.partLCStable:
            newItem = QtGui.QListWidgetItem()
            if lcs.Name == lcs.Label:
                newItem.setText(lcs.Name)
            else:
                newItem.setText(lcs.Label + ' (' + lcs.Name + ')')
            #newItem.setIcon( lcs.ViewObject.Icon )
            #self.lcsIcon = 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:
        old_EE = self.selectedLink.ExpressionEngine
        if old_EE:
            (pla, self.old_EE) = old_EE[0]

        # for debugging, use this field to print text
        #self.expression.setText( self.old_attPart )

        # decode the old ExpressionEngine
        old_Parent = ''
        old_ParentPart = ''
        old_attLCS = ''
        constrName = ''
        linkedDoc = ''
        old_linkLCS = ''
        # if the linked part is in the same document as the assembly:
        if self.parentAssembly.Document.Name == self.selectedLink.LinkedObject.Document.Name:
            (old_Parent, old_attLCS,
             old_linkLCS) = Asm4.splitExpressionDoc(self.old_EE,
                                                    self.old_Parent)
        # if the linked part comes from another document:
        else:
            # 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 = []
        lcs_found = self.partLCSlist.findItems(old_linkLCS,
                                               QtCore.Qt.MatchExactly)
        if lcs_found:
            # ... and select it
            self.partLCSlist.setCurrentItem(lcs_found[0])
        else:
            # may-be it was renamed, see if we can find it as (name)
            lcs_found = self.partLCSlist.findItems('(' + old_linkLCS + ')',
                                                   QtCore.Qt.MatchContains)
            if lcs_found:
                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.asmParts[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 oldLCS in the old parent Part (actually the App::Link)...
        #self.oldLCS = self.attLCSlist.findItems( self.old_attLCS, QtCore.Qt.CaseSensitive )
        lcs_found = []
        lcs_found = self.attLCSlist.findItems(old_attLCS,
                                              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_attLCS + ')',
                                                  QtCore.Qt.MatchContains)
            if lcs_found:
                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
        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])
Exemple #18
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.selectedFastener = []
        selection = self.GetSelection()
        if selection == None:
            self.close()
        else:
            self.selectedFastener = selection

        # check that the fastener is an Asm4 fastener
        if not hasattr(self.selectedFastener,'AssemblyType'):
            Asm4.makeAsmProperties(self.selectedFastener)
        asmType = self.selectedFastener.AssemblyType
        # we only deal with Asm4 or empty types
        if asmType!='Asm4EE' and asmType!='':
            Asm4.warningBox("This doesn't seem to be an Assembly4 Fastener")
            return(False)

        # check where the fastener was attached to
        (self.old_Parent, separator, self.old_parentLCS) = self.selectedFastener.AttachedTo.partition('#')

        # get and store the current expression engine:
        self.old_EE = ''
        old_EE = self.selectedFastener.ExpressionEngine
        if old_EE:
            for ( key, expr ) in old_EE:
                #( key, expr ) = ee
                if key=='Placement':
                    self.old_EE = expr

        # Now we can draw the UI
        self.initUI()
        self.show()

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

        # We get all the App::Link parts in the assembly 
        self.asmParts = []
        # the first item is "Select linked Part" therefore we add an empty object
        self.asmParts.append( [] )
        # We also add the parent assembly
        self.asmParts.append( self.parentAssembly )
        # Add it as first element to the drop-down combo-box
        parentIcon = self.parentAssembly.ViewObject.Icon
        self.parentList.addItem( parentIcon, 'Parent Assembly', self.parentAssembly )
        # find all the linked parts in the assembly
        for obj in self.activeDoc.findObjects("App::Link"):
            if obj.LinkedObject.isDerivedFrom('App::Part'):
                # add it to our tree table if it's a link to an App::Part ...
                self.asmParts.append( obj )
                # ... and add to the drop-down combo box with the assembly tree's parts
                objIcon = obj.LinkedObject.ViewObject.Icon
                self.parentList.addItem( objIcon, obj.Name, obj)

        # 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.asmParts[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 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] )