def updatePosition_Z(self, fp, dummy=None):
     if 'topSide' in self.Type:
         self.z = getPCBheight()[1]
     elif 'bothSide' in self.Type:  # gorna oraz dolna warstwa
         self.z = -0.5
         self.layerHeight = getPCBheight()[1] + 1.0
     else:  # bottomSide
         self.z = 0.0
     
     fp.Base.Placement.Base.z = self.z
     self.createGeometry(fp)
 def setLayerSide(self):
     if 'topSide' in self.Type:
         self.layerReversed = False
         self.layerHeight = 0.5
         self.z = getPCBheight()[1]
     elif 'bothSide' in self.Type:  # gorna oraz dolna warstwa
         self.layerReversed = False
         self.layerHeight = getPCBheight()[1] + 1.0
         self.z = -0.5
     else:  # bottomSide
         self.layerReversed = True
         self.layerHeight = 0.5
         self.z = 0.0
def createConstraintArea(obj, typeCA):
    try:
        if not FreeCAD.activeDocument() or getPCBheight()[0]:
            return
        #
        grp = createGroup_Areas()
        
        if obj.isDerivedFrom("Sketcher::SketchObject"):
            if not obj.Shape.isClosed():
                FreeCAD.Console.PrintWarning("Sketcher is not closed!\n")
                return
            #
            obj.ViewObject.Visibility = False
            
            #layerName = PCBconstraintAreas[typeCA][0]
            layerColor = (PCBconstraintAreas[typeCA][3][0] / 255., PCBconstraintAreas[typeCA][3][1] / 255., PCBconstraintAreas[typeCA][3][2] / 255.)
            layerTransparent = PCBconstraintAreas[typeCA][2]
            typeL = PCBconstraintAreas[typeCA][1]
            #numLayer = 0
            #
            a = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", typeCA + "_{0}".format(0))
            constraintAreaObject(a, typeL)
            a.Base = obj
            viewProviderConstraintAreaObject(a.ViewObject)
            
            grp.addObject(a)
            FreeCADGui.activeDocument().getObject(a.Name).ShapeColor = layerColor
            FreeCADGui.activeDocument().getObject(a.Name).Transparency = layerTransparent
            FreeCADGui.activeDocument().getObject(a.Name).DisplayMode = 1
            #grp.Proxy.Object.Group.append(a)
            #grp.Object.Group.append(a)
            
            return a
    except Exception ,e:
        FreeCAD.Console.PrintWarning("{0} \n".format(e))
示例#4
0
    def execute(self, obj):
        if 'tGlue' in self.Type:
            z = getPCBheight()[1] + 0.04
            h = obj.Height.Value

            if h <= 0:
                h = 0.01
        else:  # bottomSide
            z = -0.04
            h = -obj.Height.Value

            if h >= 0:
                h = -0.01
        #
        obiekty = []
        #
        for i in obj.Base.Geometry:
            if i.__class__.__name__ == 'GeomLineSegment':
                x1 = i.StartPoint.x
                y1 = i.StartPoint.y
                x2 = i.EndPoint.x
                y2 = i.EndPoint.y
                #
                obiekty.append(self.createLine(x1, y1, x2, y2,
                                               obj.Width.Value))
            elif i.__class__.__name__ == 'GeomCircle':
                x = i.Center.x
                y = i.Center.y
                r = i.Radius
                #
                obiekty.append(self.createCircle(x, y, r, obj.Width.Value))
            elif i.__class__.__name__ == 'GeomArcOfCircle':
                curve = degrees(i.LastParameter - i.FirstParameter)
                xs = i.Center.x
                ys = i.Center.y
                r = i.Radius

                math = mathFunctions()
                p1 = [
                    math.cosinus(degrees(i.FirstParameter)) * r,
                    math.sinus(degrees(i.FirstParameter)) * r
                ]
                p1 = [p1[0] + xs, p1[1] + ys]
                p2 = math.obrocPunkt2(p1, [xs, ys], curve)
                #
                obiekty.append(self.createArc(p1, p2, curve, obj.Width.Value))
        #
        #path = obiekty[0]
        #for i in range(1, len(obiekty)):
        #path = path.fuse(obiekty[i])
        #path = path.removeSplitter()
        path = Part.makeCompound(obiekty)
        # cut to board shape
        if self.cutToBoard:
            path = cutToBoardShape(path)
        ###################################################
        if obj.Flat == False:
            path = path.extrude(FreeCAD.Base.Vector(0, 0, h))
        path.Placement.Base.z = z
        obj.Shape = path
示例#5
0
 def generate(self):
     if self.base == None:
         FreeCAD.Console.PrintWarning("Mandatory field is empty!\n")
     elif not self.base.isDerivedFrom("Sketcher::SketchObject"):
         FreeCAD.Console.PrintWarning("Wrong object!\n")
     #
     pcb = getPCBheight()
     grp = createGroup_Glue()
     #
     if self.side == 1:  # top
         typeL = 'glueT'
     else:
         typeL  = 'glueB'
     
     a = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "Glue_{0}".format(0))
     PCBgluePath(a, typeL)
     a.Base = self.base
     if self.width == 0:
         a.Width = 1
     else:
         a.Width = self.width
     a.Height = self.height
     a.Flat = self.flat
     a.Proxy.Side = self.side
     a.Proxy.updatePosition_Z(a, pcb[1])
     
     viewProviderPCBgluePath(a.ViewObject)
     #
     grp.addObject(a)
     FreeCADGui.activeDocument().getObject(a.Name).ShapeColor = self.color
     FreeCADGui.activeDocument().getObject(a.Name).Transparency = self.transparent
     # #
     self.base.ViewObject.Visibility = False
     # #
     pcb[2].Proxy.addObject(pcb[2], a)
示例#6
0
 def createCenteDrill(self):
     if FreeCAD.activeDocument() and getPCBheight()[0]:
         try:
             form = createDrillcenter_Gui()
             FreeCADGui.Control.showDialog(form)
         except Exception ,e:
             FreeCAD.Console.PrintWarning("{0} \n".format(e))
示例#7
0
    def getParts(self):
        ''' get param from all packages from current document '''
        parts = {}
        #
        pcb = getPCBheight()
        if pcb[0]:
            for i in pcb[2].Group:
                if hasattr(i, "Proxy") and hasattr(
                        i.Proxy,
                        "Type") and i.Proxy.Type in ["PCBpart", "PCBpart_E"]:
                    partValue = ""
                    if i.PartValue:
                        partValue = i.PartValue.String
                    partName = ""
                    if i.PartName:
                        partName = i.PartName.String

                    if not i.Package in parts.keys():
                        parts[i.Package] = {}
                    if not partValue in parts[i.Package].keys():
                        parts[i.Package][partValue] = {}

                    x = self.prepareX(i.X.Value)
                    y = self.prepareY(i.Y.Value)

                    parts[i.Package][partValue][partName] = {
                        'side': i.Side,
                        'x': x,
                        'y': y,
                        'z': self.prepareZ(i.Socket.Value),
                        'rot': i.Rot.Value
                    }
        #
        return parts
示例#8
0
    def constraintAreaF(self, typeCA):
        ''' create constraint area '''
        zaznaczoneObiekty = FreeCADGui.Selection.getSelection()

        if len(zaznaczoneObiekty) and getPCBheight()[0]:
            grp = createGroup_Areas()
            for i in zaznaczoneObiekty:
                if i.isDerivedFrom("Sketcher::SketchObject") and i.Shape.isClosed():
                    i.ViewObject.Visibility = False
                    
                    #layerName = PCBconstraintAreas[typeCA][0]
                    layerColor = (PCBconstraintAreas[typeCA][3][0] / 255., PCBconstraintAreas[typeCA][3][1] / 255., PCBconstraintAreas[typeCA][3][2] / 255.)
                    layerTransparent = PCBconstraintAreas[typeCA][2]
                    typeL = PCBconstraintAreas[typeCA][1]
                    #numLayer = 0
                    #
                    a = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", typeCA + "_{0}".format(0))
                    constraintAreaObject(a, typeL)
                    a.Base = i
                    viewProviderConstraintAreaObject(a.ViewObject)
                    
                    grp.addObject(a)
                    FreeCADGui.activeDocument().getObject(a.Name).ShapeColor = layerColor
                    FreeCADGui.activeDocument().getObject(a.Name).Transparency = layerTransparent
                    FreeCADGui.activeDocument().getObject(a.Name).DisplayMode = 1
                    #grp.Proxy.Object.Group.append(a)
                    #grp.Object.Group.append(a)
        elif not pcb[0]:
            FreeCAD.Console.PrintWarning("No PCB found\n")
示例#9
0
    def open(self):
        ''' load all packages types to list '''
        pcb = getPCBheight()
        if pcb[0]:  # board is available
            for j in pcb[2].Group:
                if hasattr(j, "Proxy") and hasattr(
                        j.Proxy,
                        "Type") and j.Proxy.Type in ["PCBpart", "PCBpart_E"]:
                    if not j.Package in self.listOfModels.keys():
                        self.listOfModels[j.Package] = []
                        ####
                        a = QtGui.QListWidgetItem(j.Package)
                        #a.setData(QtCore.Qt.UserRole, j.Package)
                        a.setFlags(QtCore.Qt.ItemIsEnabled
                                   | QtCore.Qt.ItemIsUserCheckable)

                        try:
                            a.setIcon(j.ViewObject.Icon)
                        except AttributeError:
                            pass

                        if self.updateModel:
                            if self.updateModel == j.Package:
                                a.setCheckState(QtCore.Qt.Checked)
                            else:
                                a.setCheckState(QtCore.Qt.Unchecked)
                        else:
                            a.setCheckState(QtCore.Qt.Checked)

                        self.form.listaElementow.addItem(a)
                    ####
                    self.listOfModels[j.Package].append(j)
示例#10
0
    def updatePosition_Z(self, fp, dummy=None):
        thickness = getPCBheight()[1]

        if fp.Side == objectSides[0]:  # TOP
            fp.Placement.Base.z = thickness + 0.001 + fp.Z.Value
        else:
            fp.Placement.Base.z = -0.001 - fp.Z.Value
示例#11
0
def exportAssemblyPCB():
    pcb = getPCBheight()
    
    if FreeCAD.activeDocument() and pcb[0]:
        exportAssembly(pcb[2].Group + [pcb[2]])
    else:
        FreeCAD.Console.PrintWarning("File does not exist or is empty\n")
示例#12
0
 def updatePosition_Z(self, fp, dummy=None):
     thickness = getPCBheight()[1]
     
     if fp.Side == objectSides[0]:  # TOP
         fp.Placement.Base.z = thickness + 0.001 + fp.Z.Value
     else:
         fp.Placement.Base.z = -0.001 - fp.Z.Value
示例#13
0
def getBoardOutline():
    pcb = getPCBheight()
    if pcb[0]:  # board is available
        board = sketcherGetGeometry(pcb[2].Border)
        if board[0]:
            return board[1]

    return []
示例#14
0
 def execute(self, obj):
     if 'tGlue' in self.Type:
         z = getPCBheight()[1] + 0.04
         h = obj.Height.Value
         
         if h <= 0:
             h = 0.01
     else:  # bottomSide
         z = -0.04
         h = -obj.Height.Value
         
         if h >= 0:
             h = -0.01
     #
     obiekty = []
     #
     for i in obj.Base.Geometry:
         if i.__class__.__name__ == 'GeomLineSegment':
             x1 = i.StartPoint.x
             y1 = i.StartPoint.y
             x2 = i.EndPoint.x
             y2 = i.EndPoint.y
             #
             obiekty.append(self.createLine(x1, y1, x2, y2, obj.Width.Value))
         elif i.__class__.__name__ == 'GeomCircle':
             x = i.Center.x
             y = i.Center.y
             r = i.Radius
             #
             obiekty.append(self.createCircle(x, y, r, obj.Width.Value))
         elif i.__class__.__name__ == 'GeomArcOfCircle':
             curve = degrees(i.LastParameter - i.FirstParameter)
             xs = i.Center.x
             ys = i.Center.y
             r = i.Radius
             
             math = mathFunctions()
             p1 = [math.cosinus(degrees(i.FirstParameter)) * r, math.sinus(degrees(i.FirstParameter)) * r]
             p1 = [p1[0] + xs, p1[1] + ys]
             p2 = math.obrocPunkt2(p1, [xs, ys], curve)
             #
             obiekty.append(self.createArc(p1, p2, curve, obj.Width.Value))
     #
     #path = obiekty[0]
     #for i in range(1, len(obiekty)):
         #path = path.fuse(obiekty[i])
     #path = path.removeSplitter()
     path = Part.makeCompound(obiekty)
     # cut to board shape
     if self.cutToBoard:
         path = cutToBoardShape(path)
     ###################################################
     if obj.Flat == False:
         path = path.extrude(FreeCAD.Base.Vector(0, 0, h))
     path.Placement.Base.z = z
     obj.Shape = path
示例#15
0
    def changePos(self, val):
        #################################################################
        #        polaczyc z innymi podobnymi czesciami kodu !!!!!       #
        #################################################################
        gruboscPlytki = getPCBheight()[1]
        
        for i in self.elemPackage:
            # rotate object according to (RX, RY, RZ) set by user
            sX = i[0].Shape.BoundBox.Center.x * (-1) + i[0].Placement.Base.x
            sY = i[0].Shape.BoundBox.Center.y * (-1) + i[0].Placement.Base.y
            sZ = i[0].Shape.BoundBox.Center.z * (-1) + i[0].Placement.Base.z + gruboscPlytki / 2.
            
            rotateY = self.form.rotationRY.value()
            rotateX = self.form.rotationRX.value()
            rotateZ = self.form.rotationRZ.value()
            pla = FreeCAD.Placement(i[0].Placement.Base, FreeCAD.Rotation(rotateX, rotateY, rotateZ), FreeCAD.Base.Vector(sX, sY, sZ))
            i[0].Placement = pla
            
            ## placement object to 0, 0, PCB_size / 2. (X, Y, Z)
            sX = i[0].Shape.BoundBox.Center.x * (-1) + i[0].Placement.Base.x
            sY = i[0].Shape.BoundBox.Center.y * (-1) + i[0].Placement.Base.y
            sZ = i[0].Shape.BoundBox.Center.z * (-1) + i[0].Placement.Base.z + gruboscPlytki / 2.

            i[0].Placement.Base.x = sX + self.form.positionX.value() - i[0].Proxy.offsetX
            i[0].Placement.Base.y = sY + self.form.positionY.value() - i[0].Proxy.offsetY
            i[0].Placement.Base.z = sZ
            
            # move object to correct Z
            i[0].Placement.Base.z = i[0].Placement.Base.z + (gruboscPlytki - i[0].Shape.BoundBox.Center.z) + self.form.positionZ.value() 
            
            #
            if i[0].Side == "BOTTOM":
                # ROT Y - MIRROR
                shape = i[0].Shape.copy()
                shape.Placement = i[0].Placement
                shape.rotate((0, 0, gruboscPlytki / 2.), (0.0, 1.0, 0.0), 180)
                i[0].Placement = shape.Placement
                
                # ROT Z - VALUE FROM EAGLE
                shape = i[0].Shape.copy()
                shape.Placement = i[0].Placement
                shape.rotate((0, 0, 0), (0.0, 0.0, 1.0), -i[0].Rot)
                i[0].Placement = shape.Placement
            else:
                # ROT Z - VALUE FROM EAGLE
                shape = i[0].Shape.copy()
                shape.Placement = i[0].Placement
                shape.rotate((0, 0, 0), (0.0, 0.0, 1.0), i[0].Rot)
                i[0].Placement = shape.Placement
            
            # placement object to X, Y set in eagle
            i[0].Placement.Base.x = i[0].Placement.Base.x + i[0].X.Value
            i[0].Placement.Base.y = i[0].Placement.Base.y + i[0].Y.Value
            
        FreeCAD.ActiveDocument.recompute()
示例#16
0
 def createPCB_F(self):
     if FreeCAD.activeDocument():
         if getPCBheight()[0]:
             FreeCAD.Console.PrintWarning("One board per project.\n")
             return
         #
         form = createPCB()
         if len(FreeCADGui.Selection.getSelection()):
             if FreeCADGui.Selection.getSelection()[0].isDerivedFrom("Sketcher::SketchObject"):
                 form.pcbBorder.setText(FreeCADGui.Selection.getSelection()[0].Name)
                 if len(FreeCADGui.Selection.getSelection()) > 1 and FreeCADGui.Selection.getSelection()[1].isDerivedFrom("Sketcher::SketchObject"):
                     form.pcbHoles.setText(FreeCADGui.Selection.getSelection()[1].Name)
         FreeCADGui.Control.showDialog(form)
示例#17
0
 def zaznaczSketcher(self):
     pcb = getPCBheight()
     zaznaczoneObiekty = FreeCADGui.Selection.getSelection()
     
     if len(zaznaczoneObiekty):
         for i in zaznaczoneObiekty:
             try:
                 if i.isDerivedFrom("Sketcher::SketchObject") and i.Shape.isClosed() and pcb[0]:
                     FreeCADGui.pcbToolBar.scriptCmd_constraintsAreas.setDisabled(False)
                     break
             except:
                 pass
             FreeCADGui.pcbToolBar.scriptCmd_constraintsAreas.setDisabled(True)
     else:
         FreeCADGui.pcbToolBar.scriptCmd_constraintsAreas.setDisabled(True)
def createConstraintArea(obj, typeCA, height=0):
    try:
        pcb = getPCBheight()

        if not pcb[0]:
            return
        #
        grp = createGroup_Areas()

        if obj.isDerivedFrom("Sketcher::SketchObject"):
            if not obj.Shape.isClosed():
                FreeCAD.Console.PrintWarning("Sketcher is not closed!\n")
                return
            #
            obj.ViewObject.Visibility = False

            layerColor = (PCBconstraintAreas[typeCA][3][0] / 255.,
                          PCBconstraintAreas[typeCA][3][1] / 255.,
                          PCBconstraintAreas[typeCA][3][2] / 255.)
            layerTransparent = PCBconstraintAreas[typeCA][2][2]
            typeL = PCBconstraintAreas[typeCA][1][0]
            #
            a = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",
                                                 typeCA + "_{0}".format(0))
            layerObj = constraintAreaObject(a, typeL)
            a.Base = obj
            if height != 0:
                a.Height = height
            viewProviderConstraintAreaObject(a.ViewObject)
            layerObj.updatePosition_Z(a, pcb[1])

            grp.addObject(a)
            FreeCADGui.activeDocument().getObject(
                a.Name).ShapeColor = layerColor
            FreeCADGui.activeDocument().getObject(
                a.Name).Transparency = layerTransparent
            FreeCADGui.activeDocument().getObject(a.Name).DisplayMode = 1

            a.recompute()
            a.Base.recompute()
            a.purgeTouched()
            a.Base.purgeTouched()

            pcb[2].Proxy.addObject(pcb[2], a)

            return a
    except Exception as e:
        FreeCAD.Console.PrintWarning("Error CCA: {0} \n".format(e))
示例#19
0
    def generate(self, addToGroup=True):
        pcb = getPCBheight()

        if pcb[0]:
            text = self.Text
            if self.mode == 'anno':
                if not type(text) == list:
                    text = text.split('\n')
            else:
                if type(text) == list:
                    text = '_'.join(text)
            #
            self.setName(self.defaultName)
            #
            self.Annotation = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython", 'PCBannotation_0000')
            self.Annotation.Label = 'PCBannotation_0000'
            PCBannotation(self.Annotation, self.mode)
            self.Annotation.Placement.Base = FreeCAD.Vector(0, 0, 0)
            #self.Annotation.Proxy.mode = self.mode
            self.Annotation.Justification = self.Align
            self.Annotation.X = self.X
            self.Annotation.Y = self.Y
            self.Annotation.Z = self.Z
            self.Annotation.Side = self.Side.upper()
            self.Annotation.Rot = self.Rot
            self.Annotation.Size = self.Size
            self.Annotation.Spin = self.Spin
            self.Annotation.LineDistance = self.lineDistance
            self.Annotation.Tracking = self.tracking
            self.Annotation.Font = self.Font
            self.Annotation.Proxy.block = False
            self.Annotation.String = text
            viewProviderPCBannotation(self.Annotation.ViewObject)
            
            try:
                self.Annotation.ViewObject.ShapeColor = self.Color
            except:
                self.Annotation.ViewObject.ShapeColor = (1.0, 1.0, 1.0)
            self.Annotation.ViewObject.Visibility = self.Visibility
            
            self.Annotation.Proxy.updatePosition_Z(self.Annotation, pcb[1])
            #Draft.formatObject(obj)
            #obj.recompute()
            #
            if addToGroup:
                grp = createGroup_Annotations()
                grp.addObject(self.Annotation)
            pcb[2].Proxy.addObject(pcb[2], self.Annotation)
示例#20
0
def createDrillcenter(size, color):
    if not FreeCAD.activeDocument() or not getPCBheight()[0]:
        return False
    else:
        doc = FreeCAD.activeDocument()
    
    if size == 0:
        return False
    #
    try:
        obj = None
        for i in FreeCAD.activeDocument().Objects:
            if hasattr(i, "Proxy") and hasattr(i.Proxy, "Type") and 'PCBcenterDrill' in i.Proxy.Type:
                obj = i
                break
    except Exception, e:
        FreeCAD.Console.PrintWarning(str(e) + "\n")
示例#21
0
    def changePos(self, val):
        gruboscPlytki = getPCBheight()[1]

        for i in self.elemPackage:
            step_model = i[0]
            #
            self.partPlacement(step_model, self.form.positionX.value(),
                               self.form.positionY.value(),
                               self.form.positionZ.value(),
                               self.form.rotationRX.value(),
                               self.form.rotationRY.value(),
                               self.form.rotationRZ.value(),
                               step_model.X.Value, step_model.Y.Value)
            if step_model.Side == "BOTTOM":
                step_model.Proxy.changeSide(step_model)
            step_model.Proxy.oldROT = 0
            step_model.Rot = step_model.Rot.Value  # rot around Z
            step_model.Proxy.updatePosition_Z(step_model, gruboscPlytki, True)
示例#22
0
    def __init__(self, updateModel, parent=None):
        self.form = moveWizardWidget()
        self.form.setWindowIcon(QtGui.QIcon(":/data/img/centroid.svg"))
        self.form.setWindowTitle('Placement model')
        self.updateModel = updateModel

        self.setDatabase()

        self.elemPackage = []
        pcb = getPCBheight()
        if pcb[0]:  # board is available
            for i in pcb[2].Group:
                if hasattr(i, "Proxy") and hasattr(
                        i.Proxy, "Type"
                ) and i.Proxy.Type == "PCBpart" and not i.KeepPosition and i.Package == updateModel:
                    self.elemPackage.append([
                        i, i.Placement, i.Proxy.oldX, i.Proxy.oldY,
                        i.Proxy.oldROT, i.Proxy.offsetZ
                    ])
示例#23
0
def generateCentroidReport():
    txt = '''Report Origin = (0.0, 0.0)
Units used = "mm"

'''
    txt += '{0}{1}{2}{3}{4}\n'.format(lJ("RefDes"), lJ("Layer"), lJ("X"),
                                      lJ("Y"), lJ("Rotation"))
    pcb = getPCBheight()
    if pcb[0]:
        for i in pcb[2].Group:
            if hasattr(i, "Proxy") and hasattr(
                    i.Proxy,
                    "Type") and i.Proxy.Type in ["PCBpart", "PCBpart_E"]:
                try:
                    partName = i.PartName.String
                except:
                    partName = ""
                txt += '{0}{1}{2}{3}{4}\n'.format(lJ(partName), lJ(i.Side),
                                                  lJ(i.X), lJ(i.Y),
                                                  lJ(i.Rot % 360))
    return txt
示例#24
0
 def exportCentroid(self):
     ''' also known as Insertion or pick-and-place or XY data '''
     if FreeCAD.activeDocument() and getPCBheight()[0]:
         createCentroid_Gui().exec_()
示例#25
0
 def exportPCB(self):
     ''' export project to one supported file format '''
     if FreeCAD.activeDocument() and getPCBheight()[0]:
         exportPCB_Gui().exec_()
示例#26
0
 def exportDrillingMap(self):
     if FreeCAD.activeDocument() and getPCBheight()[0]:
         exportDrillingMap_Gui().exec_()
示例#27
0
 def exportBOM(self):
     ''' load export bom to file '''
     if FreeCAD.activeDocument() and getPCBheight()[0]:
         exportBOM_Gui().exec_()
示例#28
0
 def exportHoleLocationsReport(self):
     if FreeCAD.activeDocument() and getPCBheight()[0]:
         exportHolesReport_Gui().exec_()
示例#29
0
    def __init__(self, searchPhrase=None, parent=None):
        partsManaging.__init__(self)
        QtGui.QWidget.__init__(self, parent)

        self.setDatabase()
        freecadSettings = FreeCAD.ParamGet(
            "User parameter:BaseApp/Preferences/Mod/PCB")
        #

        self.gruboscPlytki = getPCBheight()[1]
        self.root = None
        self.packageData = {}
        #
        self.form = self
        self.form.setWindowTitle("Add model")
        self.form.setWindowIcon(QtGui.QIcon(":/data/img/addModel.png"))
        #
        self.listaBibliotek = QtGui.QComboBox()

        #self.package = QtGui.QComboBox()
        #self.package.setInsertPolicy(QtGui.QComboBox.InsertAlphabetically)
        self.package = modelsList()
        self.package.checkItems = False
        self.package.sql = self.__SQL__

        self.side = QtGui.QComboBox()
        self.side.addItems(['TOP', 'BOTTOM'])

        self.value = QtGui.QLineEdit('')

        self.label = QtGui.QLineEdit('')

        self.rotation = QtGui.QDoubleSpinBox()
        self.rotation.setSingleStep(1)
        self.rotation.setSuffix(' deg')
        self.rotation.setRange(-360, 360)

        self.val_x = QtGui.QDoubleSpinBox()
        self.val_x.setSingleStep(0.5)
        self.val_x.setRange(-1000, 1000)
        self.val_x.setSuffix(' mm')

        self.val_y = QtGui.QDoubleSpinBox()
        self.val_y.setSingleStep(0.5)
        self.val_y.setRange(-1000, 1000)
        self.val_y.setSuffix(' mm')

        self.error = QtGui.QLabel(u'')

        self.updateView = QtGui.QCheckBox(u'Update active view')

        self.loadModelColors = QtGui.QCheckBox(u'Colorize elements')
        self.loadModelColors.setChecked(
            freecadSettings.GetBool("partsColorize", True))

        self.adjustParts = QtGui.QCheckBox(u'Adjust part name/value')
        self.adjustParts.setChecked(
            freecadSettings.GetBool("adjustNameValue", False))

        self.continueCheckBox = QtGui.QCheckBox(u'Continue')

        self.groupParts = QtGui.QCheckBox(u'Group parts')
        self.groupParts.setChecked(freecadSettings.GetBool(
            "groupParts", False))
        #
        lay = QtGui.QGridLayout()
        lay.addWidget(self.package, 0, 0, 14, 1)
        lay.addWidget(QtGui.QLabel(u'Library:'), 0, 1, 1, 1)
        lay.addWidget(self.listaBibliotek, 1, 1, 1, 1)
        lay.addWidget(QtGui.QLabel(u'Label:*'), 2, 1, 1, 1)
        lay.addWidget(self.label, 3, 1, 1, 1)
        lay.addWidget(QtGui.QLabel(u'Value:'), 4, 1, 1, 1)
        lay.addWidget(self.value, 5, 1, 1, 1)
        lay.addWidget(QtGui.QLabel(u'Side:'), 6, 1, 1, 1)
        lay.addWidget(self.side, 7, 1, 1, 1)
        lay.addWidget(QtGui.QLabel(u'Rotation:'), 8, 1, 1, 1)
        lay.addWidget(self.rotation, 9, 1, 1, 1)
        lay.addWidget(QtGui.QLabel(u'X:'), 10, 1, 1, 1)
        lay.addWidget(self.val_x, 11, 1, 1, 1)
        lay.addWidget(QtGui.QLabel(u'Y:'), 12, 1, 1, 1)
        lay.addWidget(self.val_y, 13, 1, 1, 1)

        lay_1 = QtGui.QHBoxLayout()
        lay_1.addWidget(self.loadModelColors)
        lay_1.addWidget(self.adjustParts)
        lay_1.setContentsMargins(0, 0, 0, 0)
        lay.addLayout(lay_1, 15, 0, 1, 2)

        #lay.addItem(QtGui.QSpacerItem(1, 5), 16, 0, 1, 2)

        lay_2 = QtGui.QHBoxLayout()
        lay_2.addWidget(self.groupParts)
        lay_2.addWidget(self.updateView)
        lay_2.setContentsMargins(0, 0, 0, 0)
        lay.addLayout(lay_2, 17, 0, 1, 2)

        lay_3 = QtGui.QHBoxLayout()
        lay_3.addWidget(self.continueCheckBox)
        lay_3.setContentsMargins(0, 0, 0, 0)
        lay.addLayout(lay_3, 18, 0, 1, 2)

        #lay.addItem(QtGui.QSpacerItem(1, 10), 18, 0, 1, 2)
        #lay.addWidget(self.error, 19, 0, 1, 2)
        lay.setRowStretch(14, 10)
        self.setLayout(lay)
        #
        self.connect(self.package,
                     QtCore.SIGNAL("itemPressed (QTreeWidgetItem *,int)"),
                     self.reloadList)
        #self.connect(self.package, QtCore.SIGNAL('currentIndexChanged (int)'), self.reloadList)
        self.connect(self.val_x, QtCore.SIGNAL('valueChanged (double)'),
                     self.addArrow)
        self.connect(self.val_y, QtCore.SIGNAL('valueChanged (double)'),
                     self.addArrow)
        self.connect(self.side, QtCore.SIGNAL('currentIndexChanged (int)'),
                     self.addArrow)
        self.connect(self.updateView, QtCore.SIGNAL('stateChanged (int)'),
                     self.changeView)

        self.readLibs()
        self.addArrow()
示例#30
0
def exportAssembly(objectsToExport):
    doc = FreeCAD.ActiveDocument
    pcb = getPCBheight()

    tmpobjs = []
    objs = []
    #
    for i in getObjFromGroup(objectsToExport, []):
        #if not i.ViewObject.Visibility or not hasattr(i,'Shape') or not hasattr(i,'Proxy'):
        #    continue
        #if not i.ViewObject.Visibility or not hasattr(i,'Shape'):
        #    continue
        #if hasattr(i, "Proxy") and hasattr(i.Proxy, "Type") and i.Proxy.Type in [['PCBannotation'], 'PCBpart_E']:
        #    continue
        #if i.isDerivedFrom("App::DocumentObjectGroup") or i.TypeId == 'App::Part':
        #    objectsToExport += getObjFromGroup(i.Group)
        #    continue
        #if not i.isDerivedFrom("Sketcher::SketchObject") and len(i.Shape.Solids):
            ## We are trying to combining all objects into one single compound object. However,
            ## FreeCAD has a bug such that after compound, it will sometimes refuse to display
            ## any color if the compound contain some overlapped pads with holes, even though
            ## the color of all faces stored in DiffuseColor is still intact. 
            ## 
            ## The walkaround is to explode the pad object, and recombine all the solid inside
            ## using 'Part::Compound'. 
            ##
            ## Only apply this trick to layerSilkObject(pads) and layerPathObject(path) and 
            ## having holes.
        
        if (pcb[0] and not doc.Board.Display) or len(i.Shape.Solids)==1 or (hasattr(i, "Proxy") and not i.Proxy.__class__.__name__ in ['layerSilkObject', 'layerPathObject']) :
            objs.append(i)
            continue
        subobjs = []
        for j in i.Shape.Solids:
            tmpobj = doc.addObject('Part::Feature','obj')
            tmpobj.Shape = j
            #tmpobj.ViewObject.ShapeColor = i.ViewObject.ShapeColor
            tmpobjs.append(tmpobj)
            subobjs.append(tmpobj)
        subobj = doc.addObject('Part::Compound','obj')
        subobj.Links = subobjs
        objs.append(subobj)
        tmpobjs.append(subobj)

    if not len(objs):
        FreeCAD.Console.PrintWarning('No parts found\n')
        return
    obj = doc.addObject('Part::Compound','Compound')
    obj.Links = objs
    doc.recompute()
    tmpobjs.append(obj)

    import random
    newDoc = FreeCAD.newDocument(doc.Name+'_'+str(random.randrange(10000,99999)))

    copy = newDoc.addObject('Part::Feature','Compound')
    copy.Shape = obj.Shape
    copy.ViewObject.DiffuseColor = obj.ViewObject.DiffuseColor
    copy.ViewObject.DisplayMode = 'Shaded'
    newDoc.recompute()

    for i in objs:
        i.ViewObject.Visibility = True
    for i in reversed(tmpobjs):
        doc.removeObject(i.Name)

    view = FreeCADGui.getDocument(newDoc.Name).activeView()
    view.viewAxometric()
    view.fitAll()
示例#31
0
    def __init__(self, searchPhrase=None, parent=None):
        QtGui.QWidget.__init__(self, parent)
        #partsManaging.__init__(self, parent)
        
        self.gruboscPlytki = getPCBheight()[1]
        self.root = None
        self.packageData = {}
        
        self.form = self
        self.form.setWindowTitle("Add annotation")
        self.form.setWindowIcon(QtGui.QIcon(":/data/img/addAnnotation.svg"))
        #
        self.text = QtGui.QTextEdit('')
        self.text.setFixedHeight(100)
        
        self.align = QtGui.QComboBox()
        self.align.addItems(alignParam)
        
        self.spin = QtGui.QComboBox()
        self.spin.addItems(['True', 'False'])
        self.spin.setCurrentIndex(1)
        
        self.fontSize = QtGui.QDoubleSpinBox()
        self.fontSize.setValue(1.27)
        self.fontSize.setSuffix(' mm')
        
        self.fontName = QtGui.QComboBox()
        self.fontName.addItems(fonts)
        self.fontName.setCurrentIndex(self.fontName.findText("Fixed"))
        
        self.tracking = QtGui.QDoubleSpinBox()
        self.tracking.setSingleStep(0.5)
        self.tracking.setRange(-1000, 1000)
        self.tracking.setSuffix(' mm')
        
        self.lineDistance = QtGui.QSpinBox()
        self.lineDistance.setValue(50)
        self.lineDistance.setSingleStep(1)
        self.lineDistance.setRange(-1000, 1000)
        self.lineDistance.setSuffix(' %')
        
        self.val_x = QtGui.QDoubleSpinBox()
        self.val_x.setSingleStep(0.5)
        self.val_x.setRange(-1000, 1000)
        self.val_x.setSuffix(' mm')
        
        self.val_y = QtGui.QDoubleSpinBox()
        self.val_y.setSingleStep(0.5)
        self.val_y.setRange(-1000, 1000)
        self.val_y.setSuffix(' mm')
        
        self.val_z = QtGui.QDoubleSpinBox()
        self.val_z.setSingleStep(0.5)
        self.val_z.setRange(-1000, 1000)
        self.val_z.setSuffix(' mm')
        
        self.rotation = QtGui.QDoubleSpinBox()
        self.rotation.setSingleStep(1)
        self.rotation.setSuffix(' deg')
        self.rotation.setRange(-360, 360)
        
        self.side = QtGui.QComboBox()
        self.side.addItems(objectSides)
        
        self.error = QtGui.QLabel(u'')
        
        self.continueCheckBox = QtGui.QCheckBox(u'Continue')
        
        self.fontColor = kolorWarstwy()
        self.fontColor.setColor(getFromSettings_Color_1('AnnotationsColor', 4294967295))
        self.fontColor.setToolTip(u"Click to change color")
        #
        lay = QtGui.QGridLayout()
        lay.addWidget(QtGui.QLabel(u'Text:'), 0, 0, 1, 1)
        lay.addWidget(self.text, 0, 1, 1, 2)
        
        lay.addWidget(QtGui.QLabel(u'Font:'), 1, 0, 1, 1)
        lay.addWidget(self.fontName, 1, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'FontFile:'), 2, 0, 1, 1)
        
        lay.addWidget(QtGui.QLabel(u'Font size:'), 3, 0, 1, 1)
        lay.addWidget(self.fontSize, 3, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Tracking:'), 4, 0, 1, 1)
        lay.addWidget(self.tracking, 4, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Line Distance:'), 5, 0, 1, 1)
        lay.addWidget(self.lineDistance, 5, 1, 1, 2)
        
        lay.addWidget(QtGui.QLabel(u'Font color:'), 6, 0, 1, 1)
        lay.addWidget(self.fontColor, 6, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Align:'), 7, 0, 1, 1)
        lay.addWidget(self.align, 7, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Side:'), 8, 0, 1, 1)
        lay.addWidget(self.side, 8, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Spin:'), 9, 0, 1, 1)
        lay.addWidget(self.spin, 9, 1, 1, 2)
        
        lay.addWidget(QtGui.QLabel(u'X:'), 10, 0, 1, 1)
        lay.addWidget(self.val_x, 10, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Y:'), 11, 0, 1, 1)
        lay.addWidget(self.val_y, 11, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Z:'), 12, 0, 1, 1)
        lay.addWidget(self.val_z, 12, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Rotation:'), 13, 0, 1, 1)
        lay.addWidget(self.rotation, 13, 1, 1, 2)
        
        lay.addItem(QtGui.QSpacerItem(1, 10), 14, 0, 1, 3)
        lay.addWidget(self.continueCheckBox, 15, 0, 1, 3)
        lay.addItem(QtGui.QSpacerItem(1, 10), 16, 0, 1, 3)
        lay.addWidget(self.error, 17, 0, 1, 3)
        lay.setRowStretch(18, 10)
        self.setLayout(lay)
        #
        self.connect(self.val_x, QtCore.SIGNAL('valueChanged (double)'), self.addArrow)
        self.connect(self.val_y, QtCore.SIGNAL('valueChanged (double)'), self.addArrow)
        #self.connect(self.side, QtCore.SIGNAL('currentIndexChanged (int)'), self.addArrow)

        self.addArrow()
示例#32
0
def createDrillcenter(size, color):
    pcb = getPCBheight()
    #
    if not FreeCAD.activeDocument() or not pcb[0]:
        return False
    else:
        doc = FreeCAD.activeDocument()
    
    if size == 0:
        return False
    #
    try:
        obj = None
        for i in FreeCAD.activeDocument().Objects:
            if hasattr(i, "Proxy") and hasattr(i.Proxy, "Type") and 'PCBcenterDrill' in i.Proxy.Type:
                obj = i
                break
    except Exception as e:
        FreeCAD.Console.PrintWarning(str(e) + "\n")
    #
    try:
        if not obj:
            layerS = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", 'centerDrill')
            layerNew = layerSilkObject(layerS, ['PCBcenterDrill'])
            layerNew.defHeight = pcb[1] + 0.000001
            layerNew.side = 2
        else:
            layerS = obj
            layerNew = obj.Proxy
            #
            layerNew.spisObiektowTXT = []
    except:
        FreeCAD.Console.PrintWarning(str(e) + "\n")
        return False
    else:
        for j in doc.Objects:
            if hasattr(j, "Proxy") and hasattr(j.Proxy, "Type") and j.Proxy.Type == "PCBboard":
                try:
                    for k in range(len(j.Holes.Geometry)):
                        if j.Holes.Geometry[k].Construction or str(j.Holes.Geometry[k].__class__) != "<class 'Part.Circle'>":
                            continue
                        
                        x = j.Holes.Geometry[k].Center.x
                        y = j.Holes.Geometry[k].Center.y
                        r1 = j.Holes.Geometry[k].Radius
                        r2 = size / 2.
                        
                        if r1 > r2:
                            layerNew.addCircle(x, y, r1)
                            layerNew.setFace()
                            layerNew.circleCutHole(x, y, r2)
                    break
                except Exception as e:
                    FreeCAD.Console.PrintWarning(str(e) + "\n")
        #######
        layerNew.generuj(layerS)
        #layerNew.updatePosition_Z(layerS, pcb[1])
        viewProviderLayerSilkObject(layerS.ViewObject)
        layerS.ViewObject.ShapeColor = color
        
        grp = createGroup_Layers()
        grp.addObject(layerS)
        pcb[2].addObject(layerS)
        #
        return True
示例#33
0
 def __init__(self, searchPhrase=None, parent=None):
     partsManaging.__init__(self)
     QtGui.QWidget.__init__(self, parent)
     
     self.setDatabase()
     freecadSettings = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/PCB")
     #
     
     self.gruboscPlytki = getPCBheight()[1]
     self.root = None
     self.packageData = {}
     #
     self.form = self
     self.form.setWindowTitle("Add model")
     self.form.setWindowIcon(QtGui.QIcon(":/data/img/addModel.png"))
     #
     self.listaBibliotek = QtGui.QComboBox()
     
     #self.package = QtGui.QComboBox()
     #self.package.setInsertPolicy(QtGui.QComboBox.InsertAlphabetically)
     self.package = modelsList()
     self.package.checkItems = False
     self.package.sql = self.__SQL__
     
     self.side = QtGui.QComboBox()
     self.side.addItems(['TOP', 'BOTTOM'])
     
     self.value = QtGui.QLineEdit('')
     
     self.label = QtGui.QLineEdit('')
     
     self.rotation = QtGui.QDoubleSpinBox()
     self.rotation.setSingleStep(1)
     self.rotation.setSuffix(' deg')
     self.rotation.setRange(-360, 360)
     
     self.val_x = QtGui.QDoubleSpinBox()
     self.val_x.setSingleStep(0.5)
     self.val_x.setRange(-1000, 1000)
     self.val_x.setSuffix(' mm')
     
     self.val_y = QtGui.QDoubleSpinBox()
     self.val_y.setSingleStep(0.5)
     self.val_y.setRange(-1000, 1000)
     self.val_y.setSuffix(' mm')
     
     self.error = QtGui.QLabel(u'')
     
     self.updateView = QtGui.QCheckBox(u'Update active view')
     
     self.loadModelColors = QtGui.QCheckBox(u'Colorize elements')
     self.loadModelColors.setChecked(freecadSettings.GetBool("partsColorize", True))
     
     self.adjustParts = QtGui.QCheckBox(u'Adjust part name/value')
     self.adjustParts.setChecked(freecadSettings.GetBool("adjustNameValue", False))
     
     self.continueCheckBox = QtGui.QCheckBox(u'Continue')
     
     self.groupParts = QtGui.QCheckBox(u'Group parts')
     self.groupParts.setChecked(freecadSettings.GetBool("groupParts", False))
     #
     lay = QtGui.QGridLayout()
     lay.addWidget(self.package, 0, 0, 14, 1)
     lay.addWidget(QtGui.QLabel(u'Library:'), 0, 1, 1, 1)
     lay.addWidget(self.listaBibliotek, 1, 1, 1, 1)
     lay.addWidget(QtGui.QLabel(u'Label:*'), 2, 1, 1, 1)
     lay.addWidget(self.label, 3, 1, 1, 1)
     lay.addWidget(QtGui.QLabel(u'Value:'), 4, 1, 1, 1)
     lay.addWidget(self.value, 5, 1, 1, 1)
     lay.addWidget(QtGui.QLabel(u'Side:'), 6, 1, 1, 1)
     lay.addWidget(self.side, 7, 1, 1, 1)
     lay.addWidget(QtGui.QLabel(u'Rotation:'), 8, 1, 1, 1)
     lay.addWidget(self.rotation, 9, 1, 1, 1)
     lay.addWidget(QtGui.QLabel(u'X:'), 10, 1, 1, 1)
     lay.addWidget(self.val_x, 11, 1, 1, 1)
     lay.addWidget(QtGui.QLabel(u'Y:'), 12, 1, 1, 1)
     lay.addWidget(self.val_y, 13, 1, 1, 1)
     
     lay_1 = QtGui.QHBoxLayout()
     lay_1.addWidget(self.loadModelColors)
     lay_1.addWidget(self.adjustParts)
     lay_1.setContentsMargins(0, 0, 0, 0)
     lay.addLayout(lay_1, 15, 0, 1, 2)
     
     #lay.addItem(QtGui.QSpacerItem(1, 5), 16, 0, 1, 2)
     
     lay_2 = QtGui.QHBoxLayout()
     lay_2.addWidget(self.groupParts)
     lay_2.addWidget(self.updateView)
     lay_2.setContentsMargins(0, 0, 0, 0)
     lay.addLayout(lay_2, 17, 0, 1, 2)
     
     lay_3 = QtGui.QHBoxLayout()
     lay_3.addWidget(self.continueCheckBox)
     lay_3.setContentsMargins(0, 0, 0, 0)
     lay.addLayout(lay_3, 18, 0, 1, 2)
     
     #lay.addItem(QtGui.QSpacerItem(1, 10), 18, 0, 1, 2)
     #lay.addWidget(self.error, 19, 0, 1, 2)
     lay.setRowStretch(14, 10)
     self.setLayout(lay)
     #
     self.connect(self.package, QtCore.SIGNAL("itemPressed (QTreeWidgetItem *,int)"), self.reloadList)
     #self.connect(self.package, QtCore.SIGNAL('currentIndexChanged (int)'), self.reloadList)
     self.connect(self.val_x, QtCore.SIGNAL('valueChanged (double)'), self.addArrow)
     self.connect(self.val_y, QtCore.SIGNAL('valueChanged (double)'), self.addArrow)
     self.connect(self.side, QtCore.SIGNAL('currentIndexChanged (int)'), self.addArrow)
     self.connect(self.updateView, QtCore.SIGNAL('stateChanged (int)'), self.changeView)
     
     self.readLibs()
     self.addArrow()
示例#34
0
    def __init__(self, searchPhrase=None, parent=None):
        QtGui.QWidget.__init__(self, parent)
        #partsManaging.__init__(self, parent)
        
        self.gruboscPlytki = getPCBheight()[1]
        self.root = None
        self.packageData = {}
        
        self.form = self
        self.form.setWindowTitle("Add annotation")
        self.form.setWindowIcon(QtGui.QIcon(":/data/img/annotation.png"))
        #
        self.text = QtGui.QLineEdit('')
        
        self.align = QtGui.QComboBox()
        self.align.addItems(alignParam)
        
        self.mirror = QtGui.QComboBox()
        self.mirror.addItems(mirror)
        
        self.spin = QtGui.QComboBox()
        self.spin.addItems(['True', 'False'])
        
        self.fontSize = QtGui.QDoubleSpinBox()
        self.fontSize.setValue(1.27)
        self.fontSize.setSuffix(' mm')
        
        self.fontName = QtGui.QComboBox()
        self.fontName.setDisabled(True)
        
        self.val_x = QtGui.QDoubleSpinBox()
        self.val_x.setSingleStep(0.5)
        self.val_x.setRange(-1000, 1000)
        self.val_x.setSuffix(' mm')
        
        self.val_y = QtGui.QDoubleSpinBox()
        self.val_y.setSingleStep(0.5)
        self.val_y.setRange(-1000, 1000)
        self.val_y.setSuffix(' mm')
        
        self.rotation = QtGui.QDoubleSpinBox()
        self.rotation.setSingleStep(1)
        self.rotation.setSuffix(' deg')
        self.rotation.setRange(-360, 360)
        
        self.side = QtGui.QComboBox()
        self.side.addItems(objectSides)
        
        self.error = QtGui.QLabel(u'')
        
        self.continueCheckBox = QtGui.QCheckBox(u'Continue')
        
        self.fontColor = kolorWarstwy()
        self.fontColor.setColor((0, 0, 0))
        self.fontColor.setToolTip(u"Click to change color")
        #
        lay = QtGui.QGridLayout()
        lay.addWidget(QtGui.QLabel(u'Text:'), 0, 0, 1, 1)
        lay.addWidget(self.text, 0, 1, 1, 2)
        
        lay.addWidget(QtGui.QLabel(u'Font name:'), 1, 0, 1, 1)
        lay.addWidget(self.fontName, 1, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Font size:'), 2, 0, 1, 1)
        lay.addWidget(self.fontSize, 2, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Font color:'), 3, 0, 1, 1)
        lay.addWidget(self.fontColor, 3, 1, 1, 2)
        
        lay.addWidget(QtGui.QLabel(u'Align:'), 4, 0, 1, 1)
        lay.addWidget(self.align, 4, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Mirror:'), 5, 0, 1, 1)
        lay.addWidget(self.mirror, 5, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Spin:'), 6, 0, 1, 1)
        lay.addWidget(self.spin, 6, 1, 1, 2)
        
        lay.addWidget(QtGui.QLabel(u'X:'), 7, 0, 1, 1)
        lay.addWidget(self.val_x, 7, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Y:'), 8, 0, 1, 1)
        lay.addWidget(self.val_y, 8, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Rotation:'), 9, 0, 1, 1)
        lay.addWidget(self.rotation, 9, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Side:'), 10, 0, 1, 1)
        lay.addWidget(self.side, 10, 1, 1, 2)
        
        lay.addItem(QtGui.QSpacerItem(1, 10), 11, 0, 1, 3)
        lay.addWidget(self.continueCheckBox, 12, 0, 1, 3)
        lay.addItem(QtGui.QSpacerItem(1, 10), 13, 0, 1, 3)
        lay.addWidget(self.error, 14, 0, 1, 3)
        lay.setRowStretch(15, 10)
        self.setLayout(lay)
        #
        self.connect(self.val_x, QtCore.SIGNAL('valueChanged (double)'), self.addArrow)
        self.connect(self.val_y, QtCore.SIGNAL('valueChanged (double)'), self.addArrow)
        #self.connect(self.side, QtCore.SIGNAL('currentIndexChanged (int)'), self.addArrow)

        self.addArrow()
示例#35
0
    def addPart(self, newPart, koloroweElemnty=True, adjustParts=False, groupParts=True, partMinX=0, partMinY=0, partMinZ=0):
        doc = FreeCAD.activeDocument()
        gruboscPlytki = getPCBheight()[1]
        result = ['OK']
        
        #grp = doc.addObject("App::DocumentObjectGroup", "Parts")
        
        # basic data
        partNameTXT = partNameTXT_label = self.generateNewLabel(newPart[0][0])
        if isinstance(partNameTXT, unicode):
            partNameTXT = unicodedata.normalize('NFKD', partNameTXT).encode('ascii', 'ignore')
        #
        partValueTXT = newPart[0][2]
        #if isinstance(partValueTXT, unicode):
            #partValueTXT = unicodedata.normalize('NFKD', partValueTXT).encode('ascii', 'ignore')
        partRotation = self.adjustRotation(newPart[0][5])  # rotation around Z
        # check if 3D model exist
        #################################################################
        #################################################################
        fileData = self.partExist(newPart[0][1], "{0} {1} ({2})".format(partNameTXT_label, partValueTXT, newPart[0][1]))
        
        if fileData[0]:
            packageData = self.__SQL__.getValues(fileData[2])
            filePath = fileData[1]
            
            correctingValue_X = fileData[3][2]  # pos_X
            correctingValue_Y = fileData[3][3]  # pos_Y
            correctingValue_Z = fileData[3][4]  # pos_Z
            correctingValue_RX = fileData[3][5]  # pos_RX
            correctingValue_RY = fileData[3][6]  # pos_RY
            correctingValue_RZ = fileData[3][7]  # pos_RZ
            ################################################################
            # DODANIE OBIEKTU NA PLANSZE
            ################################################################
            step_model = doc.addObject("Part::FeaturePython", "{0} ({1})".format(partNameTXT, fileData[3][0]))
            step_model.Label = partNameTXT_label
            
            if not koloroweElemnty:
                step_model.Shape = Part.read(filePath)
            else:
                active = FreeCAD.ActiveDocument.Name
                step_model = self.getPartShape(filePath, step_model, koloroweElemnty)
                FreeCAD.setActiveDocument(active)
                FreeCAD.ActiveDocument=FreeCAD.getDocument(active)
                FreeCADGui.ActiveDocument=FreeCADGui.getDocument(active)
            
            obj = partObject(step_model)
            step_model.Package = u"{0}".format(fileData[3][0])
            step_model.Side = "{0}".format(newPart[0][6])
            ################################################################
            # PUTTING OBJECT IN CORRECT POSITION/ORIENTATION
            ################################################################
            # rotate object according to (RX, RY, RZ) set by user
            sX = step_model.Shape.BoundBox.Center.x * (-1) + step_model.Placement.Base.x
            sY = step_model.Shape.BoundBox.Center.y * (-1) + step_model.Placement.Base.y
            sZ = step_model.Shape.BoundBox.Center.z * (-1) + step_model.Placement.Base.z + gruboscPlytki / 2.
            
            rotateX = correctingValue_RX
            rotateY = correctingValue_RY
            rotateZ = correctingValue_RZ
            
            pla = FreeCAD.Placement(step_model.Placement.Base, FreeCAD.Rotation(rotateX, rotateY, rotateZ), FreeCAD.Base.Vector(sX, sY, sZ))
            step_model.Placement = pla
            
            ## placement object to 0, 0, PCB_size / 2. (X, Y, Z)
            sX = step_model.Shape.BoundBox.Center.x * (-1) + step_model.Placement.Base.x
            sY = step_model.Shape.BoundBox.Center.y * (-1) + step_model.Placement.Base.y
            sZ = step_model.Shape.BoundBox.Center.z * (-1) + step_model.Placement.Base.z + gruboscPlytki / 2.

            step_model.Placement.Base.x = sX + correctingValue_X
            step_model.Placement.Base.y = sY + correctingValue_Y
            step_model.Placement.Base.z = sZ
            
            # move object to correct Z
            step_model.Placement.Base.z = step_model.Placement.Base.z + (gruboscPlytki - step_model.Shape.BoundBox.Center.z) + correctingValue_Z
            #################################################################
            # FILTERING OBJECTS BY SIZE L/W/H
            #################################################################
            if partMinX != 0:
                minValue = partMinX
                if step_model.Side == 'TOP':
                    minValue += gruboscPlytki
                
                if step_model.Shape.BoundBox.XLength < minValue:
                    doc.removeObject(step_model.Name)
                    return
            elif partMinY != 0:
                minValue = partMinY
                if step_model.Side == 'TOP':
                    minValue += gruboscPlytki
                
                if step_model.Shape.BoundBox.YLength < minValue:
                    doc.removeObject(step_model.Name)
                    return
            elif partMinZ != 0:
                minValue = partMinZ
                if step_model.Side == 'TOP':
                    minValue += gruboscPlytki
                
                if step_model.Shape.BoundBox.ZLength < minValue:
                    doc.removeObject(step_model.Name)
                    return
            #################################################################
            # SETTTING OBJECT SIDE ON THE PCB
            #################################################################
            if newPart[0][6] == 'BOTTOM':
                # ROT Y - MIRROR
                shape = step_model.Shape.copy()
                shape.Placement = step_model.Placement
                shape.rotate((0, 0, gruboscPlytki / 2.), (0.0, 1.0, 0.0), 180)
                step_model.Placement = shape.Placement
                
                # ROT Z - VALUE FROM EAGLE
                shape = step_model.Shape.copy()
                shape.Placement = step_model.Placement
                shape.rotate((0, 0, 0), (0.0, 0.0, 1.0), -partRotation)
                step_model.Placement = shape.Placement
            else:
                # ROT Z - VALUE FROM EAGLE
                shape = step_model.Shape.copy()
                shape.Placement = step_model.Placement
                shape.rotate((0, 0, 0), (0.0, 0.0, 1.0), partRotation)
                step_model.Placement = shape.Placement
            #################################################################
            # placement object to X, Y set in eagle
            #################################################################
            step_model.Placement.Base.x = step_model.Placement.Base.x + newPart[0][3]
            step_model.Placement.Base.y = step_model.Placement.Base.y + newPart[0][4]
            #################################################################
            # 
            #################################################################
            step_model.X = step_model.Shape.BoundBox.Center.x
            step_model.Y = step_model.Shape.BoundBox.Center.y
            step_model.Proxy.oldX = step_model.Shape.BoundBox.Center.x
            step_model.Proxy.oldY = step_model.Shape.BoundBox.Center.y
            step_model.Proxy.offsetX = correctingValue_X
            step_model.Proxy.offsetY = correctingValue_Y
            step_model.Proxy.oldROT = partRotation
            step_model.Rot = partRotation
            step_model.Proxy.update_Z = step_model.Placement.Base.z
            #################################################################
            # DODANIE PODSTAWKI
            #   dodajPodstawke - definicja zachowania dla danego obiektu
            #     0 - brak podstawki
            #     1 - dodanie podstawki
            #################################################################
            dodajPodstawke = False
            
            if eval(packageData["add_socket"])[0] and self.allSocked == 0 and eval(packageData["add_socket"])[1] != fileData[2]:
                socketData = self.__SQL__.getValues(eval(packageData["add_socket"])[1])
                
                if eval(socketData["socket"])[0]:
                    dial = QtGui.QMessageBox()
                    dial.setText(u"Add socket to part {0} (Package: {1}, Library: {2})?".format(partNameTXT, newPart[0][1], newPart[0][7]))
                    dial.setWindowTitle("Socket")
                    dial.setIcon(QtGui.QMessageBox.Question)
                    dial.addButton('No', QtGui.QMessageBox.RejectRole)
                    podstawkaTAK = dial.addButton('Yes', QtGui.QMessageBox.YesRole)
                    zawszePodstawki = dial.addButton('Yes for all', QtGui.QMessageBox.YesRole)
                    nigdyPodstawki = dial.addButton('No for all', QtGui.QMessageBox.RejectRole)
                    dial.exec_()
                    
                    if dial.clickedButton() == nigdyPodstawki:
                        self.allSocked = -1
                    elif dial.clickedButton() == zawszePodstawki:
                        self.allSocked = 1
                    elif dial.clickedButton() == podstawkaTAK:
                        dodajPodstawke = True
                    else:
                        dodajPodstawke = False
            #
            if (dodajPodstawke or self.allSocked == 1) and eval(packageData["add_socket"])[0]:
                socketData = self.__SQL__.getValues(eval(packageData["add_socket"])[1])
                
                if self.__SQL__.has_section(eval(packageData["add_socket"])[1]):  # sprawdzamy czy podana podstawka istnieje
                    step_model.Socket = float(eval(socketData["socket"])[1])  # ustawienie wysokosci podstawki
                    package = eval(socketData["soft"])[0][0]
                    
                    EL_Name = [socketData["name"], newPart[0][3], newPart[0][4], 1.27, newPart[0][5], newPart[0][6], "bottom-left", False, 'None', '', True]
                    EL_Value = ["", newPart[0][3], newPart[0][4], 1.27, newPart[0][5], newPart[0][6], "bottom-left", False, 'None', '', True]
                    PCB_EL = [[socketData["name"], package, "", newPart[0][3], newPart[0][4], newPart[0][5], newPart[0][6], ""], EL_Name, EL_Value]
                else:
                    PCB_EL = [socketData["name"], socketData["name"], "", ""]
                    
                self.addPart(PCB_EL, koloroweElemnty, adjustParts, groupParts, partMinX, partMinY, partMinZ)
            ##################################################################
            ## part name object
            ## [txt, x, y, size, rot, side, align, spin, mirror, font]
            ##################################################################
            annotationName = createAnnotation()
            annotationName.defaultName = '{0}_Name'.format(partNameTXT_label)
            annotationName.mode = 'anno_name'
            annotationName.Side = newPart[1][5]
            annotationName.Rot = self.adjustRotation(newPart[1][4])
            annotationName.Text = partNameTXT_label
            annotationName.Spin = newPart[1][7]
            
            if adjustParts and "adjust" in packageData.keys() and "Name" in eval(packageData["adjust"]).keys() and eval(str(eval(packageData["adjust"])["Name"][0])):
                values = eval(packageData["adjust"])["Name"]
                
                if step_model.Side == "BOTTOM":
                    x1 = self.odbijWspolrzedne(newPart[0][3] + values[2], step_model.X.Value)
                    annotationName.Mirror = True
                    
                    [xR, yR] = self.obrocPunkt2([x1, newPart[0][4] + values[3]], [step_model.X.Value, step_model.Y.Value], -step_model.Rot.Value)
                else:
                    annotationName.Mirror = False
                    
                    [xR, yR] = self.obrocPunkt2([newPart[0][3] + values[2], newPart[0][4] + values[3]], [step_model.X.Value, step_model.Y.Value], step_model.Rot.Value)
                
                annotationName.X = xR
                annotationName.Y = yR
                annotationName.Z = values[4]
                annotationName.Align = str(values[7])
                annotationName.Size = values[5]
                annotationName.Color = values[6]
                annotationName.Visibility = eval(values[1])
            else:
                annotationName.X = newPart[1][1]
                annotationName.Y = newPart[1][2]
                annotationName.Z = 0
                annotationName.Align = newPart[1][6]
                annotationName.Size = newPart[1][3]
                annotationName.Mirror = newPart[1][8]
                annotationName.Color = (1., 1., 1.)
                annotationName.Visibility = newPart[1][10]
            
            annotationName.generate()
            #################################################################
            # part value
            # [txt, x, y, size, rot, side, align, spin, mirror, font]
            #################################################################
            annotationValue = createAnnotation()
            annotationValue.defaultName = '{0}_Value'.format(partNameTXT_label)
            annotationValue.mode = 'anno_value'
            annotationValue.Side = newPart[2][5]
            annotationValue.Rot = self.adjustRotation(newPart[2][4])
            annotationValue.Text = partValueTXT
            annotationValue.Spin = newPart[2][7]
            
            if adjustParts and "adjust" in packageData.keys() and "Value" in eval(packageData["adjust"]).keys() and eval(str(eval(packageData["adjust"])["Value"][0])):
                values = eval(packageData["adjust"])["Value"]
                
                if step_model.Side == "BOTTOM":
                    x1 = self.odbijWspolrzedne(newPart[0][3] + values[2], step_model.X.Value)
                    annotationValue.Mirror = True
                    
                    [xR, yR] = self.obrocPunkt2([x1, newPart[0][4] + values[3]], [step_model.X.Value, step_model.Y.Value], -step_model.Rot.Value)
                else:
                    annotationValue.Mirror = False
                    
                    [xR, yR] = self.obrocPunkt2([newPart[0][3] + values[2], newPart[0][4] + values[3]], [step_model.X.Value, step_model.Y.Value], step_model.Rot.Value)
                
                annotationValue.X = xR
                annotationValue.Y = yR
                annotationValue.Z = values[4]
                annotationValue.Align = str(values[7])
                annotationValue.Size = values[5]
                annotationValue.Color = values[6]
                annotationValue.Visibility = eval(values[1])
            else:
                annotationValue.X = newPart[2][1]
                annotationValue.Y = newPart[2][2]
                annotationValue.Z = 0
                annotationValue.Align = newPart[2][6]
                annotationValue.Size = newPart[2][3]
                annotationValue.Mirror = newPart[2][8]
                annotationValue.Color = (1., 1., 1.)
                annotationValue.Visibility = newPart[2][10]
            
            annotationValue.generate()
            #
            step_model.PartName = annotationName.Annotation
            step_model.PartValue = annotationValue.Annotation
            ################
            viewProviderPartObject(step_model.ViewObject)
            #################################################################
            # KOLORY DLA ELEMENTOW
            #################################################################
            #if koloroweElemnty:
                #if filePath.upper().endswith('.IGS') or filePath.upper().endswith('IGES'):
                    #step_model = self.getColorFromIGS(filePath, step_model)
                #elif filePath.upper().endswith('.STP') or filePath.upper().endswith('STEP'):
                    #step_model = self.getColorFromSTP(filePath, step_model)
        else:
            #################################################################
            # FILTERING OBJECTS BY SIZE L/W/H
            #################################################################
            if partMinX != 0 or partMinY or partMinZ:
                return
            #################################################################
            #################################################################
            ## DODANIE OBIEKTU NA PLANSZE
            step_model = doc.addObject("Part::FeaturePython", "{0} ({1})".format(partNameTXT, newPart[0][1]))
            step_model.Label = partNameTXT_label
            obj = partObject_E(step_model)
            #step_model.Label = partNameTXT
            step_model.Package = "{0}".format(newPart[0][1])
            #step_model.Value = "{0}".format(i[0][2])
            #####
            # placement object to X, Y set in eagle
            step_model.Placement.Base.x = step_model.Placement.Base.x + newPart[0][3]
            step_model.Placement.Base.y = step_model.Placement.Base.y + newPart[0][4]
            
            # move object to correct Z
            step_model.Placement.Base.z = step_model.Placement.Base.z + gruboscPlytki
            #####
            step_model.Side = "{0}".format(newPart[0][6])
            step_model.X = newPart[0][3]
            step_model.Y = newPart[0][4]
            step_model.Rot = partRotation
            step_model.Proxy.update_Z = 0
            ######
            ######
            # part name object
            # [txt, x, y, size, rot, side, align, spin, mirror, font]
            annotationName = createAnnotation()
            annotationName.defaultName = u'{0}_Name'.format(partNameTXT_label)
            annotationName.mode = 'anno_name'
            annotationName.X = newPart[1][1]
            annotationName.Y = newPart[1][2]
            annotationName.Z = 0
            annotationName.Side = newPart[1][5]
            annotationName.Rot = self.adjustRotation(newPart[1][4])
            annotationName.Text = partNameTXT_label
            annotationName.Align = newPart[1][6]
            annotationName.Size = newPart[1][3]
            annotationName.Spin = newPart[1][7]
            annotationName.Mirror = newPart[1][8]
            annotationName.Visibility = newPart[1][10]
            annotationName.Color = (1., 1., 1.)
            annotationName.generate()
            # part value
            # [txt, x, y, size, rot, side, align, spin, mirror, font]
            annotationValue = createAnnotation()
            annotationValue.defaultName = u'{0}_Value'.format(partNameTXT_label)
            annotationValue.mode = 'anno_value'
            annotationValue.X = newPart[2][1]
            annotationValue.Y = newPart[2][2]
            annotationValue.Z = 0
            annotationValue.Side = newPart[2][5]
            annotationValue.Rot = self.adjustRotation(newPart[2][4])
            annotationValue.Text = partValueTXT
            annotationValue.Align = newPart[2][6]
            annotationValue.Size = newPart[2][3]
            annotationValue.Spin = newPart[2][7]
            annotationValue.Mirror = newPart[2][8]
            annotationValue.Visibility = newPart[2][10]
            annotationValue.Color = (1., 1., 1.)
            annotationValue.generate()
            #
            step_model.PartName = annotationName.Annotation
            step_model.PartValue = annotationValue.Annotation
            ######
            ######
            viewProviderPartObject_E(step_model.ViewObject)
            #################################################################
            result = ['Error']
        ######
        result.append(step_model)
        self.addPartToGroup(groupParts, fileData, step_model)
        self.updateView()
        return result
示例#36
0
    def accept(self):
        ''' update 3d models '''
        if FreeCAD.activeDocument():
            self.databaseType = self.form.listaBibliotek.itemData(
                self.form.listaBibliotek.currentIndex(), QtCore.Qt.UserRole)
            koloroweElemnty = self.form.plytkaPCB_elementyKolory.isChecked()
            adjustParts = self.form.adjustParts.isChecked()
            groupParts = self.form.groupParts.isChecked()
            pcb = getPCBheight()
            ####
            for j in range(self.form.listaElementow.count()):
                if self.form.listaElementow.item(j).checkState() == 2:
                    package = self.form.listaElementow.item(j).text()

                    fileData = self.partExist(package, u"")
                    ####
                    for i in self.listOfModels[package]:
                        if i.Proxy.Type == "PCBpart" and fileData[0]:
                            if fileData[2] > 0:
                                modelData = self.__SQL__.getModelByID(
                                    fileData[2])

                                if modelData[0]:
                                    modelData = self.__SQL__.convertToTable(
                                        modelData[1])
                                else:
                                    modelData = {
                                        'sockedID': 0,
                                        'socketIDSocket': False
                                    }
                            else:
                                modelData = {'add_socket': '[False,None]'}

                            filePath = fileData[1]
                            correctingValue_X = fileData[3]['x']  # pos_X
                            correctingValue_Y = fileData[3]['y']  # pos_Y
                            correctingValue_Z = fileData[3]['z']  # pos_Z
                            correctingValue_RX = fileData[3]['rx']  # pos_RX
                            correctingValue_RY = fileData[3]['ry']  # pos_RY
                            correctingValue_RZ = fileData[3]['rz']  # pos_RZ

                            #### NEW MODEL SHAPE
                            i = self.getPartShape(filePath, i, koloroweElemnty)
                            ################################################################
                            # PUTTING OBJECT IN CORRECT POSITION/ORIENTATION
                            ################################################################
                            self.partPlacement(
                                i, correctingValue_X, correctingValue_Y,
                                correctingValue_Z, correctingValue_RX,
                                correctingValue_RY, correctingValue_RZ,
                                i.X.Value, i.Y.Value)
                            if i.Side == "BOTTOM":
                                i.Proxy.changeSide(i)
                            i.Proxy.oldROT = 0
                            i.Rot = i.Rot.Value  # rot around Z
                            i.Proxy.updatePosition_Z(i, pcb[1], True)
                            self.addPartToGroup(groupParts, i)
                        elif i.Proxy.Type == "PCBpart_E" and fileData[0]:
                            newPart = self.partStandardDictionary()
                            newPart['name'] = i.Label
                            newPart['library'] = i.Package
                            newPart['package'] = package
                            newPart['value'] = i.Rot.Value
                            newPart['x'] = i.X.Value
                            newPart['y'] = i.Y.Value
                            newPart['rot'] = i.Rot.Value
                            newPart['side'] = i.Side

                            newPart['EL_Name']["x"] = i.X.Value
                            newPart['EL_Name']["y"] = i.Y.Value
                            newPart['EL_Name']["rot"] = i.Rot.Value
                            newPart['EL_Name']["side"] = i.Side

                            newPart['EL_Value']["x"] = i.X.Value
                            newPart['EL_Value']["y"] = i.Y.Value
                            newPart['EL_Value']["rot"] = i.Rot.Value
                            newPart['EL_Value']["side"] = i.Side

                            result = self.addPart(newPart, koloroweElemnty,
                                                  adjustParts, groupParts)
                            if result[0] == 'OK':
                                try:
                                    FreeCAD.activeDocument().removeObject(
                                        i.Name)
                                except:
                                    pass
                        else:
                            self.addPartToGroup(groupParts, i)
        # packages = []
        # for i in range(self.form.listaElementow.count()):
        # if self.form.listaElementow.item(i).checkState() == 2:
        # packages.append(str(self.form.listaElementow.item(i).data(QtCore.Qt.UserRole)))
        # #################################################################
        # if FreeCAD.activeDocument():
        # doc = FreeCAD.activeDocument()
        # if len(doc.Objects):
        # self.databaseType = self.form.listaBibliotek.itemData(self.form.listaBibliotek.currentIndex(), QtCore.Qt.UserRole)
        # for j in doc.Objects:
        # if hasattr(j, "Proxy") and hasattr(j.Proxy, "Type") and j.Proxy.Type in ["PCBpart", "PCBpart_E"] and not j.KeepPosition  and j.Package in packages:
        # koloroweElemnty = self.form.plytkaPCB_elementyKolory.isChecked()
        # adjustParts = self.form.adjustParts.isChecked()
        # groupParts = self.form.groupParts.isChecked()

        # name = j.Label
        # package = j.Package
        # try:
        # value = j.PartValue.ViewObject.Text
        # except:
        # value = ""
        # x = j.X.Value - j.Proxy.offsetX
        # y = j.Y.Value - j.Proxy.offsetY
        # rot = j.Rot.Value
        # side = j.Side
        # library = j.Package

        # ##################################################################
        # ## part name object
        # ## [txt, x, y, size, rot, side, align, spin, mirror, font]
        # ##################################################################
        # if j.PartName:
        # PartName_text = j.PartName.ViewObject.Text
        # PartName_x = j.PartName.X
        # PartName_y = j.PartName.Y
        # PartName_size = j.PartName.ViewObject.Size
        # PartName_rot = j.PartName.Rot
        # PartName_side = j.PartName.Side
        # PartName_align = j.PartName.ViewObject.Align
        # PartName_mirror = j.PartName.ViewObject.Mirror
        # PartName_spin = j.PartName.ViewObject.Spin
        # PartName_Visibility = j.PartName.ViewObject.Visibility
        # PartName_Color = j.PartName.ViewObject.Color
        # else:
        # PartName_text = name
        # PartName_x = x
        # PartName_y = y
        # PartName_size = 1.27
        # PartName_rot = rot
        # PartName_side = side
        # PartName_align = "bottom-left"
        # PartName_mirror = 'None'
        # PartName_spin = False
        # PartName_Visibility = True
        # PartName_Color = (1., 1., 1.)

        # EL_Name = [PartName_text, PartName_x, PartName_y, PartName_size, PartName_rot, PartName_side, PartName_align, PartName_spin, PartName_mirror, '', PartName_Visibility]
        # ##################################################################
        # ## part value
        # ## [txt, x, y, size, rot, side, align, spin, mirror, font]
        # ##################################################################
        # if j.PartValue:
        # PartValue_text = j.PartValue.ViewObject.Text
        # PartValue_x = j.PartValue.X
        # PartValue_y = j.PartValue.Y
        # PartValue_size = j.PartValue.ViewObject.Size
        # PartValue_rot = j.PartValue.Rot
        # PartValue_side = j.PartValue.Side
        # PartValue_align = j.PartValue.ViewObject.Align
        # PartValue_mirror = j.PartValue.ViewObject.Mirror
        # PartValue_spin = j.PartValue.ViewObject.Spin
        # PartValue_Visibility = j.PartValue.ViewObject.Visibility
        # PartValue_Color = j.PartValue.ViewObject.Color
        # else:
        # PartValue_text = name
        # PartValue_x = x
        # PartValue_y = y
        # PartValue_size = 1.27
        # PartValue_rot = rot
        # PartValue_side = side
        # PartValue_align = "bottom-left"
        # PartValue_mirror = 'None'
        # PartValue_spin = False
        # PartValue_Visibility = True
        # PartValue_Color = (1., 1., 1.)

        # EL_Value = [PartValue_text, PartValue_x, PartValue_y, PartValue_size, PartValue_rot, PartValue_side, PartValue_align, PartValue_spin, PartValue_mirror, '', PartValue_Visibility]
        # ##################################################################
        # ##
        # ##################################################################
        # newPart = [[name, library, value, x, y, rot, side, package], EL_Name, EL_Value]
        # result = self.addPart(newPart, koloroweElemnty, adjustParts, groupParts)

        # # if result[0] == 'OK':
        # # oldValueLabel = j.PartValue.Label
        # # oldNameLabel = j.PartName.Label
        # # # del old object
        # # doc.removeObject(j.PartValue.Name)
        # # doc.removeObject(j.PartName.Name)
        # # doc.removeObject(j.Name)
        # # # rename new object name
        # # result[1].Label = name
        # # result[1].PartValue.Label = oldValueLabel
        # # result[1].PartName.Label = oldNameLabel
        # # # set text color
        # # result[1].PartName.ViewObject.Color = PartName_Color
        # # result[1].PartValue.ViewObject.Color = PartValue_Color
        # # else:
        # # doc.removeObject(result[1].PartValue.Name)
        # # doc.removeObject(result[1].PartName.Name)
        # # doc.removeObject(result[1].Name)
        return True
示例#37
0
    def __init__(self, searchPhrase=None, parent=None):
        QtGui.QWidget.__init__(self, parent)
        #partsManaging.__init__(self, parent)

        self.gruboscPlytki = getPCBheight()[1]
        self.root = None
        self.packageData = {}

        self.form = self
        self.form.setWindowTitle("Add annotation")
        self.form.setWindowIcon(QtGui.QIcon(":/data/img/annotation.png"))
        #
        self.text = QtGui.QLineEdit('')

        self.align = QtGui.QComboBox()
        self.align.addItems(alignParam)

        self.mirror = QtGui.QComboBox()
        self.mirror.addItems(mirror)

        self.spin = QtGui.QComboBox()
        self.spin.addItems(['True', 'False'])

        self.fontSize = QtGui.QDoubleSpinBox()
        self.fontSize.setValue(1.27)
        self.fontSize.setSuffix(' mm')

        self.fontName = QtGui.QComboBox()
        self.fontName.setDisabled(True)

        self.val_x = QtGui.QDoubleSpinBox()
        self.val_x.setSingleStep(0.5)
        self.val_x.setRange(-1000, 1000)
        self.val_x.setSuffix(' mm')

        self.val_y = QtGui.QDoubleSpinBox()
        self.val_y.setSingleStep(0.5)
        self.val_y.setRange(-1000, 1000)
        self.val_y.setSuffix(' mm')

        self.rotation = QtGui.QDoubleSpinBox()
        self.rotation.setSingleStep(1)
        self.rotation.setSuffix(' deg')
        self.rotation.setRange(-360, 360)

        self.side = QtGui.QComboBox()
        self.side.addItems(objectSides)

        self.error = QtGui.QLabel(u'')

        self.continueCheckBox = QtGui.QCheckBox(u'Continue')

        self.fontColor = kolorWarstwy()
        self.fontColor.setColor((0, 0, 0))
        self.fontColor.setToolTip(u"Click to change color")
        #
        lay = QtGui.QGridLayout()
        lay.addWidget(QtGui.QLabel(u'Text:'), 0, 0, 1, 1)
        lay.addWidget(self.text, 0, 1, 1, 2)

        lay.addWidget(QtGui.QLabel(u'Font name:'), 1, 0, 1, 1)
        lay.addWidget(self.fontName, 1, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Font size:'), 2, 0, 1, 1)
        lay.addWidget(self.fontSize, 2, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Font color:'), 3, 0, 1, 1)
        lay.addWidget(self.fontColor, 3, 1, 1, 2)

        lay.addWidget(QtGui.QLabel(u'Align:'), 4, 0, 1, 1)
        lay.addWidget(self.align, 4, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Mirror:'), 5, 0, 1, 1)
        lay.addWidget(self.mirror, 5, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Spin:'), 6, 0, 1, 1)
        lay.addWidget(self.spin, 6, 1, 1, 2)

        lay.addWidget(QtGui.QLabel(u'X:'), 7, 0, 1, 1)
        lay.addWidget(self.val_x, 7, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Y:'), 8, 0, 1, 1)
        lay.addWidget(self.val_y, 8, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Rotation:'), 9, 0, 1, 1)
        lay.addWidget(self.rotation, 9, 1, 1, 2)
        lay.addWidget(QtGui.QLabel(u'Side:'), 10, 0, 1, 1)
        lay.addWidget(self.side, 10, 1, 1, 2)

        lay.addItem(QtGui.QSpacerItem(1, 10), 11, 0, 1, 3)
        lay.addWidget(self.continueCheckBox, 12, 0, 1, 3)
        lay.addItem(QtGui.QSpacerItem(1, 10), 13, 0, 1, 3)
        lay.addWidget(self.error, 14, 0, 1, 3)
        lay.setRowStretch(15, 10)
        self.setLayout(lay)
        #
        self.connect(self.val_x, QtCore.SIGNAL('valueChanged (double)'),
                     self.addArrow)
        self.connect(self.val_y, QtCore.SIGNAL('valueChanged (double)'),
                     self.addArrow)
        #self.connect(self.side, QtCore.SIGNAL('currentIndexChanged (int)'), self.addArrow)

        self.addArrow()
示例#38
0
 def changeJustification(self, fp):
     try:
         fp.Placement = FreeCAD.Placement(fp.Placement.Base, FreeCAD.Rotation(FreeCAD.Vector(0,0,1),0))
         
         if fp.Spin == False and 90 < abs(fp.Rot.Value) < 271: # SPIN IS OFF
             if fp.Justification == "bottom-left":
                 fp.Placement.Base.x = fp.X.Value - fp.Shape.BoundBox.XLength
                 fp.Placement.Base.y = fp.Y.Value - fp.Shape.BoundBox.YLength
                 
                 self.przX = fp.Shape.BoundBox.XLength
                 self.przY = fp.Shape.BoundBox.YLength
             elif fp.Justification == "bottom-right":
                 fp.Placement.Base.x = fp.X.Value
                 fp.Placement.Base.y = fp.Y.Value - fp.Shape.BoundBox.YLength
                 
                 self.przX = 0
                 self.przY = fp.Shape.BoundBox.YLength
             elif fp.Justification == "bottom-center":
                 fp.Placement.Base.x = fp.X.Value - fp.Shape.BoundBox.XLength / 2.
                 fp.Placement.Base.y = fp.Y.Value - fp.Shape.BoundBox.YLength
                 
                 self.przX = fp.Shape.BoundBox.XLength / 2.
                 self.przY = fp.Shape.BoundBox.YLength
             
             
             elif fp.Justification == "center-left":
                 fp.Placement.Base.x = fp.X.Value - fp.Shape.BoundBox.XLength
                 fp.Placement.Base.y = fp.Y.Value - fp.Shape.BoundBox.YLength / 2.
                 
                 self.przX = fp.Shape.BoundBox.XLength
                 self.przY = fp.Shape.BoundBox.YLength / 2.
             elif fp.Justification == "center":
                 fp.Placement.Base.x = fp.X.Value - fp.Shape.BoundBox.XLength / 2.
                 fp.Placement.Base.y = fp.Y.Value - fp.Shape.BoundBox.YLength / 2.
                 
                 self.przX = fp.Shape.BoundBox.XLength / 2.
                 self.przY = fp.Shape.BoundBox.YLength / 2.
             elif fp.Justification == "center-right":
                 fp.Placement.Base.x = fp.X.Value
                 fp.Placement.Base.y = fp.Y.Value - fp.Shape.BoundBox.YLength / 2.
                 
                 self.przX = 0
                 self.przY = fp.Shape.BoundBox.YLength / 2.
             
             
             elif fp.Justification == "top-right":
                 fp.Placement.Base.x = fp.X.Value
                 fp.Placement.Base.y = fp.Y.Value
                 
                 self.przX = 0
                 self.przY = 0
             elif fp.Justification == "top-left":
                 fp.Placement.Base.x = fp.X.Value - fp.Shape.BoundBox.XLength
                 fp.Placement.Base.y = fp.Y.Value
                 
                 self.przX = fp.Shape.BoundBox.XLength
                 self.przY = 0
             elif fp.Justification == "top-center":
                 fp.Placement.Base.x = fp.X.Value - fp.Shape.BoundBox.XLength / 2.
                 fp.Placement.Base.y = fp.Y.Value
                 
                 self.przX = fp.Shape.BoundBox.XLength / 2.
                 self.przY = 0
             
         else:
             if fp.Justification == "bottom-left":
                 fp.Placement.Base.x = fp.X.Value
                 fp.Placement.Base.y = fp.Y.Value
                 
                 self.przX = 0
                 self.przY = 0
             elif fp.Justification == "bottom-center":
                 fp.Placement.Base.x = fp.X.Value - fp.Shape.BoundBox.XLength / 2.
                 fp.Placement.Base.y = fp.Y.Value
                 
                 self.przX = fp.Shape.BoundBox.XLength / 2.
                 self.przY = 0
             elif fp.Justification == "bottom-right":
                 fp.Placement.Base.x = fp.X.Value - fp.Shape.BoundBox.XLength
                 fp.Placement.Base.y = fp.Y.Value
                 
                 self.przX = fp.Shape.BoundBox.XLength
                 self.przY = 0
                 
                 
             elif fp.Justification == "center-left":
                 fp.Placement.Base.x = fp.X.Value
                 fp.Placement.Base.y = fp.Y.Value - fp.Shape.BoundBox.YLength / 2.
                 
                 self.przX = 0
                 self.przY = fp.Shape.BoundBox.YLength / 2.
             elif fp.Justification == "center":
                 fp.Placement.Base.x = fp.X.Value - fp.Shape.BoundBox.XLength / 2.
                 fp.Placement.Base.y = fp.Y.Value - fp.Shape.BoundBox.YLength / 2.
                 
                 self.przX = fp.Shape.BoundBox.XLength / 2.
                 self.przY = fp.Shape.BoundBox.YLength / 2.
             elif fp.Justification == "center-right":
                 fp.Placement.Base.x = fp.X.Value - fp.Shape.BoundBox.XLength
                 fp.Placement.Base.y = fp.Y.Value - fp.Shape.BoundBox.YLength / 2.
                 
                 self.przX = fp.Shape.BoundBox.XLength
                 self.przY = fp.Shape.BoundBox.YLength / 2.
             
             
             elif fp.Justification == "top-left":
                 fp.Placement.Base.x = fp.X.Value
                 fp.Placement.Base.y = fp.Y.Value - fp.Shape.BoundBox.YLength
                 
                 self.przX = 0
                 self.przY = fp.Shape.BoundBox.YLength
             elif fp.Justification == "top-center":
                 fp.Placement.Base.x = fp.X.Value - fp.Shape.BoundBox.XLength / 2.
                 fp.Placement.Base.y = fp.Y.Value - fp.Shape.BoundBox.YLength
                 
                 self.przX = fp.Shape.BoundBox.XLength / 2.
                 self.przY = fp.Shape.BoundBox.YLength
             elif fp.Justification == "top-right":
                 fp.Placement.Base.x = fp.X.Value - fp.Shape.BoundBox.XLength
                 fp.Placement.Base.y = fp.Y.Value - fp.Shape.BoundBox.YLength
                 
                 self.przX = fp.Shape.BoundBox.XLength
                 self.przY = fp.Shape.BoundBox.YLength
         
         if fp.Side == "TOP":
             rotY = 0
             rotZ = fp.Rot.Value
         else:
             rotY = 180
             rotZ = -fp.Rot.Value
         
         if fp.Spin == False and 90 < abs(fp.Rot.Value) < 271:
             fp.Placement = FreeCAD.Placement(fp.Placement.Base, FreeCAD.Rotation(rotZ - 180, rotY ,0), FreeCAD.Vector(self.przX, self.przY, fp.Z.Value))
         else:
             fp.Placement = FreeCAD.Placement(fp.Placement.Base, FreeCAD.Rotation(rotZ, rotY, 0), FreeCAD.Vector(self.przX, self.przY, fp.Z.Value))
         
         if str(fp.Placement.Base.z) == "nan":
             fp.Placement.Base.z = 0
         #
         thickness = getPCBheight()
         if thickness[0]:
             self.updatePosition_Z(fp, thickness[1])
         else:
             self.updatePosition_Z(fp, 0)
         
     except Exception as e:
         #FreeCAD.Console.PrintWarning("3. {0}\n".format(e))
         pass
示例#39
0
 def createGluePath(self):
     if FreeCAD.activeDocument() and getPCBheight()[0]:
         FreeCADGui.Control.showDialog(createGlueGui())
示例#40
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.form = self
        self.form.setWindowTitle(u"Layers settings")
        self.form.setWindowIcon(QtGui.QIcon(":/data/img/layers_TI.svg"))
        #
        self.layerslist = {}
        #
        self.mainLay = QtGui.QGridLayout()
        pcb = getPCBheight()
        try:
            if FreeCAD.activeDocument() and pcb[0]:
                for i in pcb[2].Group:
                    if hasattr(i, "Proxy") and hasattr(i.Proxy, "Type"):
                        if isinstance(i.Proxy.Type, str):
                            if i.Proxy.Type in ["PCBpart", "PCBpart_E"]:
                                if i.Proxy.Type == "PCBpart":
                                    if not "Parts" in self.layerslist.keys():
                                        self.layerslist["Parts"] = []

                                    self.layerslist["Parts"].append(i)
                                #
                                if not "Parts Name" in self.layerslist.keys():
                                    self.layerslist["Parts Name"] = []

                                if i.PartName:
                                    self.layerslist["Parts Name"].append(
                                        i.PartName)
                                #
                                if not "Parts Value" in self.layerslist.keys():
                                    self.layerslist["Parts Value"] = []

                                if i.PartValue:
                                    self.layerslist["Parts Value"].append(
                                        i.PartValue)
                            elif i.Proxy.Type == "ShapeString" and i.Proxy.mode == "anno":
                                if not "Annotations" in self.layerslist.keys():
                                    self.layerslist["Annotations"] = []

                                self.layerslist["Annotations"].append(i)
                        elif isinstance(i.Proxy.Type, list):
                            if "layer" in i.Proxy.Type:
                                if not "All layers" in self.layerslist.keys():
                                    self.layerslist["All layers"] = []

                                self.layerslist["All layers"].append(i)
                                #
                                if not i.Proxy.Type[
                                        -1] in self.layerslist.keys():
                                    self.layerslist[i.Label] = []

                                self.layerslist[i.Label].append(i)
                ####
                nr = 0
                for i in self.layerslist.keys():
                    self.addRow(i, nr)
                    nr += 1
        except Exception as e:
            print(e)

        self.mainLay.setColumnStretch(0, 10)
        self.setLayout(self.mainLay)
示例#41
0
 def addModel(self):
     ''' add model from library to project '''
     if FreeCAD.activeDocument() and getPCBheight()[0]:
         FreeCADGui.Control.showDialog(addModel())
示例#42
0
 def Flayers(self):
     if FreeCAD.activeDocument() and getPCBheight()[0]:
         FreeCADGui.Control.showDialog(layersSettings())
示例#43
0
 def addAnnotation(self):
     if FreeCAD.activeDocument() and getPCBheight()[0]:
         FreeCADGui.Control.showDialog(createAnnotation_Gui())
示例#44
0
    def changePos(self, val):
        #################################################################
        #        polaczyc z innymi podobnymi czesciami kodu !!!!!       #
        #################################################################
        gruboscPlytki = getPCBheight()[1]

        for i in self.elemPackage:
            # rotate object according to (RX, RY, RZ) set by user
            sX = i[0].Shape.BoundBox.Center.x * (-1) + i[0].Placement.Base.x
            sY = i[0].Shape.BoundBox.Center.y * (-1) + i[0].Placement.Base.y
            sZ = i[0].Shape.BoundBox.Center.z * (
                -1) + i[0].Placement.Base.z + gruboscPlytki / 2.

            rotateY = self.form.rotationRY.value()
            rotateX = self.form.rotationRX.value()
            rotateZ = self.form.rotationRZ.value()
            pla = FreeCAD.Placement(
                i[0].Placement.Base, FreeCAD.Rotation(rotateX, rotateY,
                                                      rotateZ),
                FreeCAD.Base.Vector(sX, sY, sZ))
            i[0].Placement = pla

            ## placement object to 0, 0, PCB_size / 2. (X, Y, Z)
            sX = i[0].Shape.BoundBox.Center.x * (-1) + i[0].Placement.Base.x
            sY = i[0].Shape.BoundBox.Center.y * (-1) + i[0].Placement.Base.y
            sZ = i[0].Shape.BoundBox.Center.z * (
                -1) + i[0].Placement.Base.z + gruboscPlytki / 2.

            i[0].Placement.Base.x = sX + self.form.positionX.value(
            ) - i[0].Proxy.offsetX
            i[0].Placement.Base.y = sY + self.form.positionY.value(
            ) - i[0].Proxy.offsetY
            i[0].Placement.Base.z = sZ

            # move object to correct Z
            i[0].Placement.Base.z = i[0].Placement.Base.z + (
                gruboscPlytki -
                i[0].Shape.BoundBox.Center.z) + self.form.positionZ.value()

            #
            if i[0].Side == "BOTTOM":
                # ROT Y - MIRROR
                shape = i[0].Shape.copy()
                shape.Placement = i[0].Placement
                shape.rotate((0, 0, gruboscPlytki / 2.), (0.0, 1.0, 0.0), 180)
                i[0].Placement = shape.Placement

                # ROT Z - VALUE FROM EAGLE
                shape = i[0].Shape.copy()
                shape.Placement = i[0].Placement
                shape.rotate((0, 0, 0), (0.0, 0.0, 1.0), -i[0].Rot)
                i[0].Placement = shape.Placement
            else:
                # ROT Z - VALUE FROM EAGLE
                shape = i[0].Shape.copy()
                shape.Placement = i[0].Placement
                shape.rotate((0, 0, 0), (0.0, 0.0, 1.0), i[0].Rot)
                i[0].Placement = shape.Placement

            # placement object to X, Y set in eagle
            i[0].Placement.Base.x = i[0].Placement.Base.x + i[0].X.Value
            i[0].Placement.Base.y = i[0].Placement.Base.y + i[0].Y.Value

        FreeCAD.ActiveDocument.recompute()