<commit_before>#***************************************************************************
#*                                                                         *
#*   Copyright (c) 2016 <NAME> <<EMAIL>>             *
#*                                                                         *
#*   This program is free software; you can redistribute it and/or modify  *
#*   it under the terms of the GNU Lesser General Public License (LGPL)    *
#*   as published by the Free Software Foundation; either version 2 of     *
#*   the License, or (at your option) any later version.                   *
#*   for detail see the LICENCE text file.                                 *
#*                                                                         *
#*   This program is distributed in the hope that it will be useful,       *
#*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
#*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
#*   GNU Library General Public License for more details.                  *
#*                                                                         *
#*   You should have received a copy of the GNU Library General Public     *
#*   License along with this program; if not, write to the Free Software   *
#*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
#*   USA                                                                   *
#*                                                                         *
#***************************************************************************
import FreeCAD as App
import FreeCADGui as Gui

from GDT import *

class InventoryCommand:
    def __init__(self):
        self.iconPath = ':/dd/icons/inventory.svg'
        self.toolTip = 'Inventory of the elements of GD&T'

    def Activated(self):
        Gui.Control.showDialog( GDTGuiClass() )

    def GetResources(self):
        return {
            'Pixmap' : self.iconPath,
            'MenuText': self.toolTip,
            'ToolTip':  self.toolTip
            }

    def IsActive(self):
        if FreeCADGui.ActiveDocument:
            return True
        else:
            return False

class GDTGuiClass:
    def __init__(self):
        self.widgetsGDT = []
        inventory = getAllAnnotationPlaneObjects() + getAllDatumSystemObjects() + getAllDatumFeatureObjects() + getAllGeometricToleranceObjects()
        for obj in inventory:
            self.widget = QtGui.QWidget()
            self.widget.setWindowTitle( obj.Label )
            self.widget.setWindowIcon( obj.ViewObject.Icon )
            self.widgetsGDT.append(self.widget)
            self.dialogWidgets = []
            vbox = QtGui.QVBoxLayout()
            hbox = QtGui.QHBoxLayout()
            self.data = ContainerOfData()
            self.data.textName = obj.Label
            if "AnnotationPlane" == getType(obj):
                self.dialogWidgets.append(textLabelWidget_inv(Text = 'Name:', Mask = 'NNNn', Data = self.data, Obj = obj))
                self.dialogWidgets.append(fieldLabelButtonWidget_inv(Text = 'Offset:', Data = self.data, Obj = obj))

            if "DatumSystem" == getType(obj):
                self.dialogWidgets.append(textLabelWidget_inv(Text = 'Name:', Mask='NNNn', Data = self.data, Obj = obj))
                listDF = [None] + [l for l in getAllDatumFeatureObjects()]
                self.dialogWidgets.append( groupBoxWidget_inv(Text='Constituents', List=[comboLabelWidget_inv(Text='Primary:',List=listDF, Data = self.data, Obj = obj),comboLabelWidget_inv(Text='Secondary:',List=listDF, Data = self.data, Obj = obj), comboLabelWidget_inv(Text='Tertiary:',List=listDF, Data = self.data, Obj = obj)], Data = self.data, Obj = obj) )

            if "DatumFeature" == getType(obj):
                self.dialogWidgets.append(textLabelWidget_inv(Text = 'Datum feature:', Mask='>A', Data = self.data, Obj = obj))
                self.dialogWidgets.append( comboLabelWidget_inv(Text='In annotation:', List = [l for l in getAllAnnotationObjects()], Data = self.data, Obj = obj) )

            if "GeometricTolerance" == getType(obj):
                self.dialogWidgets.append(textLabelWidget_inv(Text = 'Name:', Mask='NNNn', Data = self.data, Obj = obj))
                characteristics = makeCharacteristics()
                self.dialogWidgets.append( comboLabelWidget_inv(Text='Characteristic:', List=characteristics.Label, Icons=characteristics.Icon, Data = self.data, Obj = obj) )
                featureControlFrame = makeFeatureControlFrame()
                self.dialogWidgets.append( fieldLabeCombolWidget_inv(Text='Tolerance value:', List=featureControlFrame.Label, Icons=featureControlFrame.Icon, ToolTip=featureControlFrame.toolTip, Data = self.data, Obj = obj) ) #http://doc.qt.io/qt-5/qlineedit.html#inputMask-prop
                self.dialogWidgets.append( comboLabelWidget_inv(Text='Datum system:', List=[None] + [l for l in getAllDatumSystemObjects()], Data = self.data, Obj = obj) )
                self.dialogWidgets.append( comboLabelWidget_inv(Text='In annotation:', List=[l for l in getAllAnnotationObjects()], Data = self.data, Obj = obj) )

            for widg in self.dialogWidgets:
                w = widg.generateWidget()
                if isinstance(w, QtGui.QLayout):
                    vbox.addLayout( w )
                else:
                    vbox.addWidget( w )

            buttonModify = QtGui.QPushButton('Modify')
            buttonModify.clicked.connect(lambda obj = obj, data = self.data: self.modifyFunc(obj, data))
            buttonDelate = QtGui.QPushButton('Delete')
            buttonDelate.clicked.connect(lambda obj = obj: self.deleteFunc(obj))
            hbox.addStretch(1)
            hbox.addWidget( buttonModify )
            hbox.addWidget( buttonDelate )
            hbox.addStretch(1)
            vbox.addLayout(hbox)
            self.widget.setLayout(vbox)

        self.form = self.widgetsGDT

    def modifyFunc(self, obj, data):
        if "AnnotationPlane" == getType(obj):
            obj.Label = data.textName
            obj.Offset = data.OffsetValue

        if "DatumSystem" == getType(obj):
            obj.Primary = data.primary
            obj.Secondary = data.secondary
            obj.Tertiary = data.tertiary
            textName = data.textName.split(":")[0]
            if data.primary <> None:
                textName+=': '+obj.Primary.Label
                if data.secondary <> None:
                    textName+=' | '+obj.Secondary.Label
                    if data.tertiary <> None:
                        textName+=' | '+obj.Tertiary.Label
            obj.Label = textName

        if "DatumFeature" == getType(obj):
            if data.annotation.DF <> None:
                QtGui.QMessageBox.critical(
                    QtGui.qApp.activeWindow(),
                    'ERROR',
                    'You can not change the DF to an annotation where one already exists',
                    QtGui.QMessageBox.StandardButton.Abort )
            else:
                annotationObj = getAnnotationWithDF(obj)
                if annotationObj.Label <> data.annotation.Label:
                    annotationObj.removeObject(obj)
                    annotationObj.DF = None
                    data.annotation.addObject(obj)
                    data.annotation.DF = obj
                obj.Label = data.textName

        if "GeometricTolerance" == getType(obj):
            annotationObj = getAnnotationWithGT(obj)
            if annotationObj.Label <> data.annotation.Label:
                annotationObj.removeObject(obj)
                gt = annotationObj.GT
                gt.remove(obj)
                annotationObj.GT = gt
                data.annotation.addObject(obj)
                gt = data.annotation.GT
                gt.append(obj)
                data.annotation.GT = gt
            obj.Label = data.textName
            obj.Characteristic = data.characteristic.Label
            obj.CharacteristicIcon = data.characteristic.Icon
            obj.CharacteristicIconText = data.characteristic.IconText
            obj.ToleranceValue = data.toleranceValue
            obj.FeatureControlFrame = data.featureControlFrame
            obj.DS = data.datumSystem

        FreeCADGui.Control.closeDialog()
        hideGrid()
        for l in getAllAnnotationObjects():
            l.touch()
        FreeCAD.ActiveDocument.recompute()
        Gui.Control.showDialog( GDTGuiClass() )

    def deleteFunc(self, obj):
        FreeCAD.ActiveDocument.removeObject(obj.Name)
        FreeCADGui.Control.closeDialog()
        hideGrid()
        for l in getAllAnnotationObjects():
            l.touch()
        FreeCAD.ActiveDocument.recompute()
        Gui.Control.showDialog( GDTGuiClass() )

    def getPos(self, actualValue, List):
        for i in range(len(List)):
            if List[i][0] == actualValue:
                return i
<commit_msg>Fully implemented deletions in inventory widget<commit_after>#***************************************************************************
#*                                                                         *
#*   Copyright (c) 2016 <NAME> <<EMAIL>>             *
#*                                                                         *
#*   This program is free software; you can redistribute it and/or modify  *
#*   it under the terms of the GNU Lesser General Public License (LGPL)    *
#*   as published by the Free Software Foundation; either version 2 of     *
#*   the License, or (at your option) any later version.                   *
#*   for detail see the LICENCE text file.                                 *
#*                                                                         *
#*   This program is distributed in the hope that it will be useful,       *
#*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
#*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
#*   GNU Library General Public License for more details.                  *
#*                                                                         *
#*   You should have received a copy of the GNU Library General Public     *
#*   License along with this program; if not, write to the Free Software   *
#*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
#*   USA                                                                   *
#*                                                                         *
#***************************************************************************
import FreeCAD as App
import FreeCADGui as Gui

from GDT import *

class InventoryCommand:
    def __init__(self):
        self.iconPath = ':/dd/icons/inventory.svg'
        self.toolTip = 'Inventory of the elements of GD&T'

    def Activated(self):
        Gui.Control.showDialog( GDTGuiClass() )

    def GetResources(self):
        return {
            'Pixmap' : self.iconPath,
            'MenuText': self.toolTip,
            'ToolTip':  self.toolTip
            }

    def IsActive(self):
        if FreeCADGui.ActiveDocument:
            return True
        else:
            return False

class GDTGuiClass:
    def __init__(self):
        self.widgetsGDT = []
        inventory = getAllAnnotationPlaneObjects() + getAllDatumSystemObjects() + getAllDatumFeatureObjects() + getAllGeometricToleranceObjects()
        for obj in inventory:
            self.widget = QtGui.QWidget()
            self.widget.setWindowTitle( obj.Label )
            self.widget.setWindowIcon( obj.ViewObject.Icon )
            self.widgetsGDT.append(self.widget)
            self.dialogWidgets = []
            vbox = QtGui.QVBoxLayout()
            hbox = QtGui.QHBoxLayout()
            self.data = ContainerOfData()
            self.data.textName = obj.Label
            if "AnnotationPlane" == getType(obj):
                self.dialogWidgets.append(textLabelWidget_inv(Text = 'Name:', Mask = 'NNNn', Data = self.data, Obj = obj))
                self.dialogWidgets.append(fieldLabelButtonWidget_inv(Text = 'Offset:', Data = self.data, Obj = obj))

            elif "DatumSystem" == getType(obj):
                self.dialogWidgets.append(textLabelWidget_inv(Text = 'Name:', Mask='NNNn', Data = self.data, Obj = obj))
                listDF = [None] + [l for l in getAllDatumFeatureObjects()]
                self.dialogWidgets.append( groupBoxWidget_inv(Text='Constituents', List=[comboLabelWidget_inv(Text='Primary:',List=listDF, Data = self.data, Obj = obj),comboLabelWidget_inv(Text='Secondary:',List=listDF, Data = self.data, Obj = obj), comboLabelWidget_inv(Text='Tertiary:',List=listDF, Data = self.data, Obj = obj)], Data = self.data, Obj = obj) )

            elif "DatumFeature" == getType(obj):
                self.dialogWidgets.append(textLabelWidget_inv(Text = 'Datum feature:', Mask='>A', Data = self.data, Obj = obj))
                self.dialogWidgets.append( comboLabelWidget_inv(Text='In annotation:', List = [l for l in getAllAnnotationObjects()], Data = self.data, Obj = obj) )

            elif "GeometricTolerance" == getType(obj):
                self.dialogWidgets.append(textLabelWidget_inv(Text = 'Name:', Mask='NNNn', Data = self.data, Obj = obj))
                characteristics = makeCharacteristics()
                self.dialogWidgets.append( comboLabelWidget_inv(Text='Characteristic:', List=characteristics.Label, Icons=characteristics.Icon, Data = self.data, Obj = obj) )
                featureControlFrame = makeFeatureControlFrame()
                self.dialogWidgets.append( fieldLabeCombolWidget_inv(Text='Tolerance value:', List=featureControlFrame.Label, Icons=featureControlFrame.Icon, ToolTip=featureControlFrame.toolTip, Data = self.data, Obj = obj) ) #http://doc.qt.io/qt-5/qlineedit.html#inputMask-prop
                self.dialogWidgets.append( comboLabelWidget_inv(Text='Datum system:', List=[None] + [l for l in getAllDatumSystemObjects()], Data = self.data, Obj = obj) )
                self.dialogWidgets.append( comboLabelWidget_inv(Text='In annotation:', List=[l for l in getAllAnnotationObjects()], Data = self.data, Obj = obj) )

            for widg in self.dialogWidgets:
                w = widg.generateWidget()
                if isinstance(w, QtGui.QLayout):
                    vbox.addLayout( w )
                else:
                    vbox.addWidget( w )

            buttonModify = QtGui.QPushButton('Modify')
            buttonModify.clicked.connect(lambda obj = obj, data = self.data: self.modifyFunc(obj, data))
            buttonDelate = QtGui.QPushButton('Delete')
            buttonDelate.clicked.connect(lambda obj = obj: self.deleteFunc(obj))
            hbox.addStretch(1)
            hbox.addWidget( buttonModify )
            hbox.addWidget( buttonDelate )
            hbox.addStretch(1)
            vbox.addLayout(hbox)
            self.widget.setLayout(vbox)

        self.form = self.widgetsGDT

    def modifyFunc(self, obj, data):
        if "AnnotationPlane" == getType(obj):
            obj.Label = data.textName
            obj.Offset = data.OffsetValue

        elif "DatumSystem" == getType(obj):
            obj.Primary = data.primary
            obj.Secondary = data.secondary
            obj.Tertiary = data.tertiary
            textName = data.textName.split(":")[0]
            if data.primary <> None:
                textName+=': '+obj.Primary.Label
                if data.secondary <> None:
                    textName+=' | '+obj.Secondary.Label
                    if data.tertiary <> None:
                        textName+=' | '+obj.Tertiary.Label
            obj.Label = textName

        elif "DatumFeature" == getType(obj):
            if data.annotation.DF <> None:
                QtGui.QMessageBox.critical(
                    QtGui.qApp.activeWindow(),
                    'ERROR',
                    'You can not change the DF to an annotation where one already exists',
                    QtGui.QMessageBox.StandardButton.Abort )
            else:
                annotationObj = getAnnotationWithDF(obj)
                if annotationObj.Label <> data.annotation.Label:
                    annotationObj.removeObject(obj)
                    annotationObj.DF = None
                    data.annotation.addObject(obj)
                    data.annotation.DF = obj
                obj.Label = data.textName

        elif "GeometricTolerance" == getType(obj):
            annotationObj = getAnnotationWithGT(obj)
            if annotationObj.Label <> data.annotation.Label:
                annotationObj.removeObject(obj)
                gt = annotationObj.GT
                gt.remove(obj)
                annotationObj.GT = gt
                data.annotation.addObject(obj)
                gt = data.annotation.GT
                gt.append(obj)
                data.annotation.GT = gt
            obj.Label = data.textName
            obj.Characteristic = data.characteristic.Label
            obj.CharacteristicIcon = data.characteristic.Icon
            obj.CharacteristicIconText = data.characteristic.IconText
            obj.ToleranceValue = data.toleranceValue
            obj.FeatureControlFrame = data.featureControlFrame
            obj.DS = data.datumSystem

        FreeCADGui.Control.closeDialog()
        hideGrid()
        for l in getAllAnnotationObjects():
            l.touch()
        FreeCAD.ActiveDocument.recompute()
        Gui.Control.showDialog( GDTGuiClass() )

    def deleteFunc(self, obj):
        if "AnnotationPlane" == getType(obj):
            ok = True
            for l in getAllAnnotationObjects():
                if l.AP == obj:
                    ok = False
                    break
            if ok:
                FreeCAD.ActiveDocument.removeObject(obj.Name)
            else:
                QtGui.QMessageBox.critical(
                    QtGui.qApp.activeWindow(),
                    'ERROR',
                    'You can not delete AP in use',
                    QtGui.QMessageBox.StandardButton.Abort )

        elif "DatumSystem" == getType(obj):
            FreeCAD.ActiveDocument.removeObject(obj.Name)

        elif "DatumFeature" == getType(obj):
            for l in getAllDatumSystemObjects():
                if l.Primary == obj:
                    l.Primary = l.Secondary
                    l.Secondary = l.Tertiary
                    l.Tertiary = None
                elif l.Secondary == obj:
                    l.Secondary = l.Tertiary
                    l.Tertiary = None
            for l in getAllAnnotationObjects():
                if l.DF == obj:
                    l.DF = None
                    break
            FreeCAD.ActiveDocument.removeObject(obj.Name)

        elif "GeometricTolerance" == getType(obj):
            for l in getAllAnnotationObjects():
                for gt in l.GT:
                    if gt == obj:
                        gtAux = l.GT
                        gtAux.remove(obj)
                        l.GT = gtAux
                        break
            FreeCAD.ActiveDocument.removeObject(obj.Name)

        FreeCADGui.Control.closeDialog()
        hideGrid()
        for l in getAllAnnotationObjects():
            l.touch()
        FreeCAD.ActiveDocument.recompute()
        Gui.Control.showDialog( GDTGuiClass() )

    def getPos(self, actualValue, List):
        for i in range(len(List)):
            if List[i][0] == actualValue:
                return i

{'fraction_non_alphanumeric': 0.11070034914766892, 'fraction_numerical': 0.0024645717806531116, 'mean_word_length': 1.7717375836060907, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3770458', 'n_tokens_mistral': 5300, 'n_tokens_neox': 4950, 'n_words': 1149}