示例#1
0
 def candidates(self, obj):
     solids = [o for o in obj.Document.Objects if PathUtil.isSolid(o)]
     if obj.Base in solids and PathJob.isResourceClone(obj, 'Base'):
         solids.remove(obj.Base)
     if obj.Stock in solids:
         # regardless, what stock is/was, it's not a valid choice
         solids.remove(obj.Stock)
     return sorted(solids, key=lambda c: c.Label)
示例#2
0
 def candidates(self, obj):
     solids = [o for o in obj.Document.Objects if PathUtil.isSolid(o)]
     if obj.Base in solids and PathJob.isResourceClone(obj, 'Base'):
         solids.remove(obj.Base)
     if obj.Stock in solids:
         # regardless, what stock is/was, it's not a valid choice
         solids.remove(obj.Stock)
     return sorted(solids, key=lambda c: c.Label)
示例#3
0
    def setupModel(self, job=None):

        if job:
            preSelected = Counter([
                PathUtil.getPublicObject(job.Proxy.baseObject(job, obj)).Label
                for obj in job.Model.Group
            ])
            jobResources = job.Model.Group + [job.Stock]
        else:
            preSelected = Counter(
                [obj.Label for obj in FreeCADGui.Selection.getSelection()])
            jobResources = []

        self.candidates = sorted(PathJob.ObjectJob.baseCandidates(),
                                 key=lambda o: o.Label)

        # If there is only one possibility we might as well make sure it's selected
        if not preSelected and 1 == len(self.candidates):
            preSelected = Counter([self.candidates[0].Label])

        expandSolids = False
        expand2Ds = False
        expandJobs = False

        for base in self.candidates:
            if (not base in jobResources
                    and not PathJob.isResourceClone(job, base, None)
                    and not hasattr(base, "StockType")):
                item0 = QtGui.QStandardItem()
                item1 = QtGui.QStandardItem()

                item0.setData(base.Label, QtCore.Qt.EditRole)
                item0.setData(base, self.DataObject)
                item0.setCheckable(True)
                item0.setEditable(False)

                item1.setEnabled(True)
                item1.setEditable(True)

                if base.Label in preSelected:
                    itemSelected = True
                    item0.setCheckState(QtCore.Qt.CheckState.Checked)
                    item1.setData(preSelected[base.Label], QtCore.Qt.EditRole)
                else:
                    itemSelected = False
                    item0.setCheckState(QtCore.Qt.CheckState.Unchecked)
                    item1.setData(0, QtCore.Qt.EditRole)

                if PathUtil.isSolid(base):
                    self.itemsSolid.appendRow([item0, item1])
                    if itemSelected:
                        expandSolids = True
                else:
                    self.items2D.appendRow([item0, item1])
                    if itemSelected:
                        expand2Ds = True

        for j in sorted(PathJob.Instances(), key=lambda x: x.Label):
            if j != job:
                item0 = QtGui.QStandardItem()
                item1 = QtGui.QStandardItem()

                item0.setData(j.Label, QtCore.Qt.EditRole)
                item0.setData(j, self.DataObject)
                item0.setCheckable(True)
                item0.setEditable(False)

                item1.setEnabled(True)
                item1.setEditable(True)

                if j.Label in preSelected:
                    expandJobs = True
                    item0.setCheckState(QtCore.Qt.CheckState.Checked)
                    item1.setData(preSelected[j.Label], QtCore.Qt.EditRole)
                else:
                    item0.setCheckState(QtCore.Qt.CheckState.Unchecked)
                    item1.setData(0, QtCore.Qt.EditRole)

                self.itemsJob.appendRow([item0, item1])

        self.delegate = _ItemDelegate(self, self.dialog.modelTree)
        self.model = QtGui.QStandardItemModel(self.dialog)
        self.model.setHorizontalHeaderLabels(["Model", "Count"])

        if self.itemsSolid.hasChildren():
            self.model.appendRow(self.itemsSolid)
            if expandSolids or not (expand2Ds or expandJobs):
                expandSolids = True
        if self.items2D.hasChildren():
            self.model.appendRow(self.items2D)
        if self.itemsJob.hasChildren():
            self.model.appendRow(self.itemsJob)

        self.dialog.modelTree.setModel(self.model)
        self.dialog.modelTree.setItemDelegateForColumn(1, self.delegate)
        self.dialog.modelTree.expandAll()
        self.dialog.modelTree.resizeColumnToContents(0)
        self.dialog.modelTree.resizeColumnToContents(1)
        self.dialog.modelTree.collapseAll()

        if expandSolids:
            self.dialog.modelTree.setExpanded(self.itemsSolid.index(), True)
        if expand2Ds:
            self.dialog.modelTree.setExpanded(self.items2D.index(), True)
        if expandJobs:
            self.dialog.modelTree.setExpanded(self.itemsJob.index(), True)

        self.dialog.modelTree.setEditTriggers(
            QtGui.QAbstractItemView.AllEditTriggers)
        self.dialog.modelTree.setSelectionBehavior(
            QtGui.QAbstractItemView.SelectItems)

        self.dialog.modelGroup.show()
示例#4
0
    def setupModel(self, job = None):

        if job:
            preSelected = Counter([PathUtil.getPublicObject(job.Proxy.baseObject(job, obj)).Label for obj in job.Model.Group])
            jobResources = job.Model.Group + [job.Stock]
        else:
            preSelected = Counter([obj.Label for obj in FreeCADGui.Selection.getSelection()])
            jobResources = []

        self.candidates = sorted(PathJob.ObjectJob.baseCandidates(), key=lambda o: o.Label)

        # If there is only one possibility we might as well make sure it's selected
        if not preSelected and 1 == len(self.candidates):
            preSelected = Counter([self.candidates[0].Label])

        expandSolids = False
        expand2Ds    = False
        expandJobs   = False

        for i, base in enumerate(self.candidates):
            if not base in jobResources and not PathJob.isResourceClone(job, base, None) and not hasattr(base, 'StockType'):
                item0 = QtGui.QStandardItem()
                item1 = QtGui.QStandardItem()

                item0.setData(base.Label, QtCore.Qt.EditRole)
                item0.setData(base, self.DataObject)
                item0.setCheckable(True)
                item0.setEditable(False)

                item1.setEnabled(True)
                item1.setEditable(True)

                if base.Label in preSelected:
                    itemSelected = True
                    item0.setCheckState(QtCore.Qt.CheckState.Checked)
                    item1.setData(preSelected[base.Label], QtCore.Qt.EditRole)
                else:
                    itemSelected = False
                    item0.setCheckState(QtCore.Qt.CheckState.Unchecked)
                    item1.setData(0, QtCore.Qt.EditRole)

                if PathUtil.isSolid(base):
                    self.itemsSolid.appendRow([item0, item1])
                    if itemSelected:
                        expandSolids = True
                else:
                    self.items2D.appendRow([item0, item1])
                    if itemSelected:
                        expand2Ds = True

        for j in sorted(PathJob.Instances(), key=lambda x: x.Label):
            if j != job:
                item0 = QtGui.QStandardItem()
                item1 = QtGui.QStandardItem()

                item0.setData(j.Label, QtCore.Qt.EditRole)
                item0.setData(j, self.DataObject)
                item0.setCheckable(True)
                item0.setEditable(False)

                item1.setEnabled(True)
                item1.setEditable(True)

                if j.Label in preSelected:
                    expandJobs = True
                    item0.setCheckState(QtCore.Qt.CheckState.Checked)
                    item1.setData(preSelected[j.Label], QtCore.Qt.EditRole)
                else:
                    item0.setCheckState(QtCore.Qt.CheckState.Unchecked)
                    item1.setData(0, QtCore.Qt.EditRole)

                self.itemsJob.appendRow([item0, item1])

        self.delegate = _ItemDelegate(self, self.dialog.modelTree)
        self.model = QtGui.QStandardItemModel(self.dialog)
        self.model.setHorizontalHeaderLabels(['Model', 'Count'])


        if self.itemsSolid.hasChildren():
            self.model.appendRow(self.itemsSolid)
            if expandSolids or not (expand2Ds or expandJobs):
                expandSolids = True
        if self.items2D.hasChildren():
            self.model.appendRow(self.items2D)
        if self.itemsJob.hasChildren():
            self.model.appendRow(self.itemsJob)

        self.dialog.modelTree.setModel(self.model)
        self.dialog.modelTree.setItemDelegateForColumn(1, self.delegate)
        self.dialog.modelTree.expandAll()
        self.dialog.modelTree.resizeColumnToContents(0)
        self.dialog.modelTree.resizeColumnToContents(1)
        self.dialog.modelTree.collapseAll()

        if expandSolids:
            self.dialog.modelTree.setExpanded(self.itemsSolid.index(), True)
        if expand2Ds:
            self.dialog.modelTree.setExpanded(self.items2D.index(), True)
        if expandJobs:
            self.dialog.modelTree.setExpanded(self.itemsJob.index(), True)

        self.dialog.modelTree.setEditTriggers(QtGui.QAbstractItemView.AllEditTriggers)
        self.dialog.modelTree.setSelectionBehavior(QtGui.QAbstractItemView.SelectItems)

        self.dialog.modelGroup.show()
示例#5
0
    def setupModel(self, job=None):
        if job:
            sel = [
                PathUtil.getPublicObject(job.Proxy.baseObject(job, obj))
                for obj in job.Model.Group
            ]
            xxx = job.Model.Group + [job.Stock]
        else:
            sel = FreeCADGui.Selection.getSelection()
            xxx = []

        if sel:
            selected = [s.Label for s in sel]
        else:
            selected = []

        PathLog.track('selected', selected)

        expandSolids = False
        expandTwoDs = False
        expandJobs = False
        index = 0
        candidates = sorted(PathJob.ObjectJob.baseCandidates(),
                            key=lambda o: o.Label)
        for base in candidates:
            PathLog.track(base.Label)
            if not base in xxx and not PathJob.isResourceClone(
                    job, base, None) and not hasattr(base, 'StockType'):
                PathLog.track('base', base.Label)
                item = QtGui.QTreeWidgetItem([base.Label])
                item.setData(0, self.DataObject, base)
                sel = base.Label in selected
                if sel or (1 == len(candidates) and not selected):
                    item.setCheckState(0, QtCore.Qt.CheckState.Checked)
                else:
                    item.setCheckState(0, QtCore.Qt.CheckState.Unchecked)
                if PathUtil.isSolid(base):
                    self.itemsSolid.addChild(item)
                    if sel:
                        expandSolids = True
                else:
                    self.itemsTwoD.addChild(item)
                    if sel:
                        expandTwoDs = True

        for j in sorted(PathJob.Instances(), key=lambda x: x.Label):
            if j != job:
                item = QtGui.QTreeWidgetItem([j.Label])
                item.setData(0, self.DataObject, j)
                if j.Label in selected:
                    expandJobs = True
                    item.setCheckState(0, QtCore.Qt.CheckState.Checked)
                else:
                    item.setCheckState(0, QtCore.Qt.CheckState.Unchecked)
                self.itemsJob.addChild(item)

        if self.itemsSolid.childCount() > 0:
            self.dialog.modelTree.addTopLevelItem(self.itemsSolid)
            if expandSolids or not (expandTwoDs or expandJobs):
                PathLog.track()
                self.itemsSolid.setExpanded(True)
                expandSolids = True
        if self.itemsTwoD.childCount() > 0:
            self.dialog.modelTree.addTopLevelItem(self.itemsTwoD)
            if expandTwoDs:
                self.itemsTwoD.setExpanded(True)
        if self.itemsJob.childCount() > 0:
            self.dialog.modelTree.addTopLevelItem(self.itemsJob)
            if expandJobs:
                self.itemsJob.setExpanded(True)
        self.dialog.modelGroup.show()
示例#6
0
    def setupModel(self, job = None):
        if job:
            sel = [PathUtil.getPublicObject(job.Proxy.baseObject(job, obj)) for obj in job.Model.Group]
            xxx = job.Model.Group + [job.Stock]
        else:
            sel = FreeCADGui.Selection.getSelection()
            xxx = []

        if sel:
            selected = [s.Label for s in sel]
        else:
            selected = []

        PathLog.track('selected', selected)

        expandSolids = False
        expandTwoDs  = False
        expandJobs   = False
        index = 0
        candidates = sorted(PathJob.ObjectJob.baseCandidates(), key=lambda o: o.Label)
        for base in candidates:
            PathLog.track(base.Label)
            if not base in xxx and not PathJob.isResourceClone(job, base, None) and not hasattr(base, 'StockType'):
                PathLog.track('base', base.Label)
                item = QtGui.QTreeWidgetItem([base.Label])
                item.setData(0, self.DataObject, base)
                sel = base.Label in selected
                if sel or (1 == len(candidates) and not selected):
                    item.setCheckState(0, QtCore.Qt.CheckState.Checked)
                else:
                    item.setCheckState(0, QtCore.Qt.CheckState.Unchecked)
                if PathUtil.isSolid(base):
                    self.itemsSolid.addChild(item)
                    if sel:
                        expandSolids = True
                else:
                    self.itemsTwoD.addChild(item)
                    if sel:
                        expandTwoDs = True

        for j in sorted(PathJob.Instances(), key=lambda x: x.Label):
            if j != job:
                item = QtGui.QTreeWidgetItem([j.Label])
                item.setData(0, self.DataObject, j)
                if j.Label in selected:
                    expandJobs = True
                    item.setCheckState(0, QtCore.Qt.CheckState.Checked)
                else:
                    item.setCheckState(0, QtCore.Qt.CheckState.Unchecked)
                self.itemsJob.addChild(item)

        if self.itemsSolid.childCount() > 0:
            self.dialog.modelTree.addTopLevelItem(self.itemsSolid)
            if expandSolids or not (expandTwoDs or expandJobs):
                PathLog.track()
                self.itemsSolid.setExpanded(True)
                expandSolids = True
        if self.itemsTwoD.childCount() > 0:
            self.dialog.modelTree.addTopLevelItem(self.itemsTwoD)
            if expandTwoDs:
                self.itemsTwoD.setExpanded(True)
        if self.itemsJob.childCount() > 0:
            self.dialog.modelTree.addTopLevelItem(self.itemsJob)
            if expandJobs:
                self.itemsJob.setExpanded(True)
        self.dialog.modelGroup.show()