Beispiel #1
0
    def bulge2arc(self, Ps, Pe, bulge):
        """
        bulge2arc()
        """
        c = (1 / bulge - bulge) / 2

        #Berechnung des Mittelpunkts (Formel von Mickes!)
        #Calculation of the center (Micke's formula)
        O = Point(x=(Ps.x + Pe.x - (Pe.y - Ps.y) * c) / 2, \
                  y=(Ps.y + Pe.y + (Pe.x - Ps.x) * c) / 2)

        #Radius = Distance between the centre and Ps
        r = O.distance(Ps)
        #Kontrolle ob beide gleich sind (passt ...)
        #Check if they are equal (fits ...)
        #r=O.distance(Pe)

        #Unterscheidung f�r den �ffnungswinkel.
        #Distinction for the opening angle. ???
        if bulge > 0:
            return ArcGeo(Ps=Ps, Pe=Pe, O=O, r=r)
        else:
            arc = ArcGeo(Ps=Pe, Pe=Ps, O=O, r=r)
            arc.reverse()
            return arc
Beispiel #2
0
    def initialize_export_vars(self):
        """
        This function is called to initialize all export variables. This will
        be done directly before the export starts.
        """

        #Initialization of the General Postprocessor parameters
        self.feed = 0
        self.speed = 0
        self.tool_nr = 1
        self.comment = ""

        self.abs_export = self.vars.General["abs_export"]

        self.Pe = Point(x=g.config.vars.Plane_Coordinates['axis1_start_end'],
                        y=g.config.vars.Plane_Coordinates['axis2_start_end'])

        self.Ps = Point(x=g.config.vars.Plane_Coordinates['axis1_start_end'],
                        y=g.config.vars.Plane_Coordinates['axis2_start_end'])

        self.lPe = Point(x=g.config.vars.Plane_Coordinates['axis1_start_end'],
                         y=g.config.vars.Plane_Coordinates['axis2_start_end'])

        self.IJ = Point(x=0.0, y=0.0)
        self.O = Point(x=0.0, y=0.0)
        self.r = 0.0
        self.s_ang = 0.0
        self.e_ang = 0.0

        self.ze = g.config.vars.Depth_Coordinates['axis3_retract']
        self.lz = self.ze

        self.keyvars = {"%feed":'self.iprint(self.feed)', \
                        "%speed":'self.iprint(self.speed)', \
                        "%tool_nr":'self.iprint(self.tool_nr)', \
                        "%nl":'self.nlprint()', \
                        "%XE":'self.fnprint(self.Pe.x)', \
                        "%-XE":'self.fnprint(-self.Pe.x)', \
                        "%XS":'self.fnprint(self.Ps.x)', \
                        "%-XS":'self.fnprint(-self.Ps.x)', \
                        "%YE":'self.fnprint(self.Pe.y*fac)', \
                        "%-YE":'self.fnprint(-self.Pe.y*fac)', \
                        "%YS":'self.fnprint(self.Ps.y*fac)', \
                        "%-YS":'self.fnprint(-self.Ps.y*fac)', \
                        "%ZE":'self.fnprint(self.ze)', \
                        "%-ZE":'self.fnprint(-self.ze)', \
                        "%I":'self.fnprint(self.IJ.x)', \
                        "%-I":'self.fnprint(-self.IJ.x)', \
                        "%J":'self.fnprint(self.IJ.y*fac)', \
                        "%-J":'self.fnprint(-self.IJ.y*fac)', \
                        "%XO":'self.fnprint(self.O.x)', \
                        "%-XO":'self.fnprint(-self.O.x)', \
                        "%YO":'self.fnprint(self.O.y*fac)', \
                        "%-YO":'self.fnprint(-self.O.y*fac)', \
                        "%R":'self.fnprint(self.r)', \
                        "%AngS":'self.fnprint(degrees(self.s_ang))', \
                        "%-AngS":'self.fnprint(degrees(-self.s_ang))', \
                        "%AngE":'self.fnprint(degrees(self.e_ang))', \
                        "%-AngE":'self.fnprint(degrees(-self.e_ang))', \
                        "%comment":'self.sprint(self.comment)'}
Beispiel #3
0
    def __init__(self, Nr=0, caller=None):
        self.Typ = 'Ellipse'
        self.Nr = Nr
        #Initialisieren der Werte
        #Initialise the values
        self.Layer_Nr = 0
        self.center = Point(0, 0) #Centre of the geometry
        self.vector = Point(1, 0) # Vector A = semi-major axis.
                                  # a = rotation of the ellipse
                                  # http://de.wikipedia.org/wiki/Gro%C3%9Fe_Halbachse
        self.ratio = 1            #Verh�ltnis der kleinen zur gro�en Halbachse (b/a)
                                  #Ratio of the minor to major axis (b/a)
        #self.AngS = 0            #Startwinkel beim zeichnen eines Ellipsensegments
                                  #Starting angle when drawing an ellipse segment
        #self.AngE = radians(360) #Endwinkel (Winkel im DXF als Radians!)
                                  #End angle (angle in radians as DXF!)
        #Die folgenden Grundwerte werden sp�ter ein mal berechnet
        #The following limits are calculated later

        self.length = 0
        self.Points = []
        self.Points.append(self.center)
        #Lesen der Geometrie / Read the geometry
        self.Read(caller)

        #Zuweisen der Toleranz f�rs Fitting / Assign the tolerance for fitting
        tol = g.config.fitting_tolerance

        #Errechnen der Ellipse / Calculate the ellipse
        self.Ellipse_Grundwerte()
        self.Ellipse_2_Arcs(tol)
Beispiel #4
0
    def Read(self, caller):
        """
        This function does read the geometry.
        @param caller: The instance which is calling the function
        """
        #Assign short name
        lp = caller.line_pairs
        e = lp.index_code(0, caller.start + 1)

        #Assign layer
        s = lp.index_code(8, caller.start + 1)
        self.Layer_Nr = caller.Get_Layer_Nr(lp.line_pair[s].value)

        #X Value
        sl = lp.index_code(10, s + 1)
        x0 = float(lp.line_pair[sl].value)

        #Y Value
        s = lp.index_code(20, sl + 1)
        y0 = float(lp.line_pair[s].value)

        #X Value 2
        s = lp.index_code(11, sl + 1)
        x1 = float(lp.line_pair[s].value)

        #Y Value 2
        s = lp.index_code(21, s + 1)
        y1 = float(lp.line_pair[s].value)

        #Searching for an extrusion direction
        s_nxt_xt = lp.index_code(230, s + 1, e)
        #If there is a extrusion direction given flip around x-Axis
        if s_nxt_xt != None:
            extrusion_dir = float(lp.line_pair[s_nxt_xt].value)
            logger.debug(
                self.tr('Found extrusion direction: %s') % extrusion_dir)
            if extrusion_dir == -1:
                x0 = -x0
                x1 = -x1

        Ps = Point(x0, y0)
        Pe = Point(x1, y1)

        #Anhängen der LineGeo Klasse für die Geometrie
        #Annexes to LineGeo class for geometry ???
        self.geo.append(LineGeo(Ps=Ps, Pe=Pe))

        #Länge entspricht der Länge des Kreises
        #Length corresponding to the length (circumference?) of the circle
        self.length = self.geo[-1].length

        #Neuen Startwert für die nächste Geometrie zurückgeben
        #New starting value for the next geometry
        caller.start = s
Beispiel #5
0
    def makeShapesAndPlot(self, values):
        """
        Plots all data stored in the values parameter to the Canvas
        @param values: Includes all values loaded from the dxf file
        """

        #Generate the Shapes
        self.makeShapes(values,
                        p0 = Point(x = self.cont_dx, y = self.cont_dy),
                        pb = Point(x = 0.0, y = 0.0),
                        sca = [self.cont_scale, self.cont_scale, self.cont_scale],
                        rot = self.rotate)
Beispiel #6
0
    def __init__(self, Nr=None, Name='', parent=None,
                children=[], p0=Point(), pb=Point(),
                sca=[1, 1, 1], rot=0.0):

        self.type = "Entity"
        self.Nr = Nr
        self.Name = Name
        self.children = children
        self.p0 = p0
        self.pb = pb
        self.sca = sca
        self.rot = rot
        self.parent = parent
Beispiel #7
0
    def calc_O1_O2_k(self, r1, r2, tan_a, teta):
        """
        calc_O1_O2_k()
        """
        #print("r1: %0.3f, r2: %0.3f, tan_a: %0.3f, teta: %0.3f" %(r1,r2,tan_a,teta))
        #print("N1: x: %0.3f, y: %0.3f" %(-sin(tan_a), cos(tan_a)))
        #print("V: x: %0.3f, y: %0.3f" %(-sin(teta+tan_a),cos(teta+tan_a)))

        O1 = Point(x=self.Ps.x - r1 * sin(tan_a), \
                      y=self.Ps.y + r1 * cos(tan_a))
        k = Point(x=self.Ps.x + r1 * (-sin(tan_a) + sin(teta + tan_a)), \
                     y=self.Ps.y + r1 * (cos(tan_a) - cos(tan_a + teta)))
        O2 = Point(x=k.x + r2 * (-sin(teta + tan_a)), \
                      y=k.y + r2 * (cos(teta + tan_a)))
        return O1, O2, k
Beispiel #8
0
    def AnalyseAndOptimize(self):
        """
        This method is called after the shape has been generated before it gets
        plotted to change all shape direction to a CW shape.
        """
        logger.debug(
            self.tr("Analysing the shape for CW direction Nr: %s") % self.nr)
        # Optimization for closed shapes
        if self.closed:
            # Start value for the first sum
            start = self.geos[0].get_start_end_points(0)[0]
            summe = 0.0
            for geo in self.geos:
                if geo.type == 'LineGeo':
                    ende = geo.get_start_end_points(1)[0]
                    summe += (start.x + ende.x) * (ende.y - start.y) / 2
                    start = ende
                elif geo.type == 'ArcGeo':
                    segments = int(abs(degrees(geo.ext)) // 90 + 1)
                    for i in range(segments):
                        ang = geo.s_ang + (i + 1) * geo.ext / segments
                        ende = Point(geo.O.x + cos(ang) * geo.r,
                                     geo.O.y + sin(ang) * geo.r)
                        summe += (start.x + ende.x) * (ende.y - start.y) / 2
                        start = ende

            if summe > 0.0:
                self.reverse()
                logger.debug(self.tr("Had to reverse the shape to be cw"))
Beispiel #9
0
    def FindNearestStPoint(self, StPoint=Point()):
        """
        Find Nearest Point to given StartPoint. This is used to change the
        start of closed contours
        @param StPoint: This is the point for which the nearest point shall
        be searched.
        """
        if self.closed:
            logger.debug(self.tr("Clicked Point: %s") % StPoint)
            start = self.geos[0].get_start_end_points(0, self.parent)[0]
            min_distance = start.distance(StPoint)

            logger.debug(self.tr("Old Start Point: %s") % start)

            min_geo_nr = 0
            for geo_nr in range(1, len(self.geos)):
                start = self.geos[geo_nr].get_start_end_points(0,
                                                               self.parent)[0]

                if start.distance(StPoint) < min_distance:
                    min_distance = start.distance(StPoint)
                    min_geo_nr = geo_nr

            # Overwrite the geometries in changed order.
            self.geos = self.geos[min_geo_nr:] + self.geos[:min_geo_nr]

            start = self.geos[0].get_start_end_points(0, self.parent)[0]
            logger.debug(self.tr("New Start Point: %s") % start)
Beispiel #10
0
    def __init__(
            self,
            text='S',
            startp=Point(x=0.0, y=0.0),
    ):
        """
        Initialisation of the class.
        """
        QtGui.QGraphicsItem.__init__(self)

        self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable, False)

        self.text = text
        self.sc = 1.0
        self.startp = QtCore.QPointF(startp.x, -startp.y)

        pencolor = QtGui.QColor(0, 200, 255)
        self.brush = QtGui.QColor(0, 100, 255)

        self.pen = QtGui.QPen(pencolor, 1, QtCore.Qt.SolidLine,
                              QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)
        self.pen.setCosmetic(True)

        self.path = QtGui.QPainterPath()
        self.path.addText(QtCore.QPointF(0, 0),
                          QtGui.QFont("Arial", 10 / self.sc), self.text)
Beispiel #11
0
    def calc_curve(self, n=0, cpts_nr=20):
        """
        Berechnen von eine Anzahl gleichm�ssig verteilter Punkte bis zur n-ten Ableitung
        """

        #Anfangswerte f�r Step und u
        u = 0
        step = float(self.Knots[-1]) / (cpts_nr - 1)
        Points = []

        #Wenn die erste Ableitung oder h�her errechnet wird die ersten
        #Ableitung in dem tan als Winkel in rad gespeichert
        tang = []

        while u <= self.Knots[-1]:
            CK = self.bspline_ders_evaluate(n=n, u=u)

            #Den Punkt in einem Punkt List abspeichern
            Points.append(Point(x=CK[0][0], y=CK[0][1]))

            #F�r die erste Ableitung wird den Winkel der tangente errechnet
            if n >= 1:
                tang.append(atan2(CK[1][1], CK[1][0]))
            u += step

        return Points, tang
Beispiel #12
0
    def Read(self, caller):
        """
        Read()
        """
        #Assign short name
        lp = caller.line_pairs
        e = lp.index_code(0, caller.start + 1)

        #Assign layer
        s = lp.index_code(8, caller.start + 1)
        self.Layer_Nr = caller.Get_Layer_Nr(lp.line_pair[s].value)

        #X Value
        s = lp.index_code(10, s + 1)
        x0 = float(lp.line_pair[s].value)

        #Y Value
        s = lp.index_code(20, s + 1)
        y0 = float(lp.line_pair[s].value)

        Ps = Point(x0, y0)

        self.geo.append(HoleGeo(Ps))
        #self.geo.append(LineGeo(Ps=Point(0,0), Pe=P))

        #Neuen Startwert für die nächste Geometrie zurückgeben
        #New starting value for the next geometry
        caller.start = s
Beispiel #13
0
    def analyse_and_opt(self):
        """
        analyse_and_opt()
        """
        summe = 0

        #Richtung in welcher der Anfang liegen soll (unten links)
        #Direction of the top (lower left) ???
        Popt = Point(x= -1e3, y= -1e6)

        #Calculation of the alignment after Gaussian-Elling
        #Positive value means CW, negative value indicates CCW
        #closed polygon
        for Line in self.geo:
            summe += (Line.Ps.x * Line.Pe.y - Line.Pe.x * Line.Ps.y) / 2

        if summe > 0.0:
            self.reverse()

        #Find the smallest starting point from bottom left X (Must be new loop!)
        #logger.debug(self.geo)

        min_distance = self.geo[0].Ps.distance(Popt)
        min_geo_nr = 0
        for geo_nr in range(1, len(self.geo)):
            if (self.geo[geo_nr].Ps.distance(Popt) < min_distance):
                min_distance = self.geo[geo_nr].Ps.distance(Popt)
                min_geo_nr = geo_nr

        #Order contour so the new starting point is at the beginning
        self.geo = self.geo[min_geo_nr:len(self.geo)] + self.geo[0:min_geo_nr]
Beispiel #14
0
    def __init__(self, MyGraphicsView, MyGraphicsScene, position):

        QtGui.QMenu.__init__(self)

        self.position = MyGraphicsView.mapToGlobal(position)
        GVPos = MyGraphicsView.mapToScene(position)
        self.PlotPos = Point(x=GVPos.x(), y=-GVPos.y())

        self.MyGraphicsScene = MyGraphicsScene
        self.MyGraphicsView = MyGraphicsView

        if len(self.MyGraphicsScene.selectedItems()) == 0:
            return

        invertAction = self.addAction(self.tr("Invert Selection"))
        disableAction = self.addAction(self.tr("Disable Selection"))
        enableAction = self.addAction(self.tr("Enable Selection"))

        self.addSeparator()

        swdirectionAction = self.addAction(self.tr("Switch Direction"))
        SetNxtStPAction = self.addAction(self.tr("Set Nearest StartPoint"))

        if g.config.machine_type == 'drag_knife':
            pass
        else:
            self.addSeparator()
            submenu1 = QtGui.QMenu(self.tr('Cutter Compensation'), self)
            self.noCompAction = submenu1.addAction(
                self.tr("G40 No Compensation"))
            self.noCompAction.setCheckable(True)
            self.leCompAction = submenu1.addAction(
                self.tr("G41 Left Compensation"))
            self.leCompAction.setCheckable(True)
            self.reCompAction = submenu1.addAction(
                self.tr("G42 Right Compensation"))
            self.reCompAction.setCheckable(True)

            logger.debug(
                self.tr("The selected shapes have the following direction: %i")
                % (self.calcMenuDir()))
            self.checkMenuDir(self.calcMenuDir())

            self.addMenu(submenu1)

        invertAction.triggered.connect(self.invertSelection)
        disableAction.triggered.connect(self.disableSelection)
        enableAction.triggered.connect(self.enableSelection)

        swdirectionAction.triggered.connect(self.switchDirection)
        SetNxtStPAction.triggered.connect(self.setNearestStP)

        if g.config.machine_type == 'drag_knife':
            pass
        else:
            self.noCompAction.triggered.connect(self.setNoComp)
            self.leCompAction.triggered.connect(self.setLeftComp)
            self.reCompAction.triggered.connect(self.setRightComp)

        self.exec_(self.position)
Beispiel #15
0
    def analyse_and_opt(self):
        """
        analyse_and_opt()
        """
        summe = 0

        #Richtung in welcher der Anfang liegen soll (unten links)
        #Direction of the top (lower left) ????
        Popt = Point(x=-1e3, y=-1e6)

        #Calculation of the alignment after Gaussian-Elling
        #Positive value means CW, negative value indicates CCW
        #closed polygon
        for Line in self.geo:
            summe += (Line.Pa.x * Line.Pe.y - Line.Pe.x * Line.Pa.y) / 2

        if summe > 0.0:
            self.reverse()

        #Suchen des kleinsten Startpunkts von unten Links X zuerst (Muss neue Schleife sein!)
        #Find the smallest starting point from bottom left X (Must be new loop!)
        min_distance = self.geo[0].Pa.distance(Popt)
        min_geo_nr = 0
        for geo_nr in range(1, len(self.geo)):
            if (self.geo[geo_nr].Pa.distance(Popt) < min_distance):
                min_distance = self.geo[geo_nr].Pa.distance(Popt)
                min_geo_nr = geo_nr

        #Kontur so anordnen das neuer Startpunkt am Anfang liegt
        #Order Contour so new starting point is at the beginning
        self.geo = self.geo[min_geo_nr:len(self.geo)] + self.geo[0:min_geo_nr]
Beispiel #16
0
    def __init__(self,
                 startp=Point(x=0.0, y=0.0),
                 endp=None,
                 length=60.0,
                 angle=50.0,
                 color=QtCore.Qt.red,
                 pencolor=QtCore.Qt.green,
                 dir=0):
        """
        Initialisation of the class.
        """
        self.sc = 1
        super(Arrow, self).__init__()

        self.startp = QtCore.QPointF(startp.x, -startp.y)
        self.endp = endp

        self.length = length
        self.angle = angle
        self.dir = dir
        self.allwaysshow = False

        self.arrowHead = QtGui.QPolygonF()
        self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable, False)
        self.myColor = color
        self.pen = QtGui.QPen(pencolor, 1, QtCore.Qt.SolidLine,
                              QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)
        self.arrowSize = 8.0

        self.pen.setCosmetic(True)
Beispiel #17
0
 def contains_point(self, point):
     """
     Method to determine the minimal distance from the point to the shape
     @param point: a QPointF
     @return: minimal distance
     """
     min_distance = float(0x7fffffff)
     ref_point = Point(point.x(), point.y())
     t = 0.0
     while t < 1.0:
         per_point = self.path.pointAtPercent(t)
         spline_point = Point(per_point.x(), per_point.y())
         distance = ref_point.distance(spline_point)
         if distance < min_distance:
             min_distance = distance
         t += 0.01
     return min_distance
Beispiel #18
0
 def contains_point(self, point):
     """
     Method to determine the minimal distance from the point to the shape
     @param point: a QPointF
     @return: minimal distance
     """
     min_distance = float(0x7fffffff)
     ref_point = Point(point.x(), point.y())
     t = 0.0
     while t < 1.0:
         per_point = self.path.pointAtPercent(t)
         spline_point = Point(per_point.x(), per_point.y())
         distance = ref_point.distance(spline_point)
         if distance < min_distance:
             min_distance = distance
         t += 0.01
     return min_distance
Beispiel #19
0
 def Ellipse_Point(self, alpha=0):#Point(0,0)
     """
     Ellipse_Point()
     """
     #gro�e Halbachse, kleine Halbachse, rotation der Ellipse (rad), Winkel des Punkts in der Ellipse (rad)
     #Semi-major axis, minor axis, rotation of the ellipse (rad), the point in the ellipse angle (rad) ???
     Ex = self.a * cos(alpha) * cos(self.rotation) - self.b * sin(alpha) * sin(self.rotation)
     Ey = self.a * cos(alpha) * sin(self.rotation) + self.b * sin(alpha) * cos(self.rotation)
     return Point(self.center.x + Ex, self.center.y + Ey)
Beispiel #20
0
    def addexproutest(self):
        """
        This function initialises the Arrows of the export route order and
        its numbers.
        @param shapes_st_en_points: The start and end points of the shapes.
        @param route: The order of the shapes to be plotted.
        """

        x_st = g.config.vars.Plane_Coordinates['axis1_start_end']
        y_st = g.config.vars.Plane_Coordinates['axis2_start_end']
        self.expprv = Point(x=x_st, y=y_st)
        self.expcol = QtCore.Qt.darkRed
Beispiel #21
0
    def addexproute(self, exp_order, layer_nr):
        """
        This function initialises the Arrows of the export route order and 
        its numbers. 
        @param shapes_st_en_points: The start and end points of the shapes.
        @param route: The order of the shapes to be plotted. 
        """

        x_st = g.config.vars.Plane_Coordinates['axis1_start_end']
        y_st = g.config.vars.Plane_Coordinates['axis2_start_end']
        start = Point(x=x_st, y=y_st)
        ende = Point(x=x_st, y=y_st)

        #shapes_st_en_points.append([start,ende])

        #Print the optimised route
        for shape_nr in range(len(exp_order)):
            st = self.expprv
            [en, dummy] = self.shapes[exp_order[shape_nr]].get_st_en_points(0)
            [self.expprv,
             dummy] = self.shapes[exp_order[shape_nr]].get_st_en_points(1)
            #            st=shapes_st_en_points[route[st_nr]][1]
            #            en=shapes_st_en_points[route[en_nr]][0]

            self.routearrows.append(
                Arrow(startp=st,
                      endp=en,
                      color=self.expcol,
                      pencolor=self.expcol))

            self.expcol = QtCore.Qt.darkGray

            self.routetext.append(
                RouteText(text=("%s,%s" % (layer_nr, shape_nr + 1)),
                          startp=en))

            #self.routetext[-1].ItemIgnoresTransformations

            self.addItem(self.routetext[-1])
            self.addItem(self.routearrows[-1])
Beispiel #22
0
    def Read(self, caller):
        """
        Read()
        """
        #Assign short name
        lp = caller.line_pairs
        e = lp.index_code(0, caller.start + 1)

        #Assign Layer
        s = lp.index_code(8, caller.start + 1)
        self.Layer_Nr = caller.Get_Layer_Nr(lp.line_pair[s].value)

        #Centre X value, Y value
        s = lp.index_code(10, s + 1)
        x0 = float(lp.line_pair[s].value)
        s = lp.index_code(20, s + 1)
        y0 = float(lp.line_pair[s].value)
        self.center = Point(x0, y0)
        #XWert, YWert. Vektor, relativ zum Zentrum, Gro�e Halbachse
        #X value, Y value. Vector relative to the center, Semi-major axis
        s = lp.index_code(11, s + 1)
        x1 = float(lp.line_pair[s].value)
        s = lp.index_code(21, s + 1)
        y1 = float(lp.line_pair[s].value)
        self.vector = Point(x1, y1)
        #Ratio minor to major axis
        s = lp.index_code(40, s + 1)
        self.ratio = float(lp.line_pair[s].value)
        #Start Winkel - Achtung, ist als rad (0-2pi) im dxf
        #Start angle - Note in radian (0-2pi) per dxf
        s = lp.index_code(41, s + 1)
        self.AngS = float(lp.line_pair[s].value)
        #End Winkel - Achtung, ist als rad (0-2pi) im dxf
        #End angle - Note in radian (0-2pi) per dxf
        s = lp.index_code(42, s + 1)
        self.AngE = float(lp.line_pair[s].value)
        #Neuen Startwert f�r die n�chste Geometrie zur�ckgeben
        #New starting value for the next geometry return
        caller.start = e
Beispiel #23
0
    def makeShapesAndPlot(self, values):
        """
        Plots all data stored in the values parameter to the Canvas
        @param values: Includes all values loaded from the dxf file
        """

        #Generate the Shapes
        self.makeShapes(
            values,
            p0=Point(x=self.cont_dx, y=self.cont_dy),
            pb=Point(x=0.0, y=0.0),
            sca=[self.cont_scale, self.cont_scale, self.cont_scale],
            rot=self.rotate)

        # Automatic cutter compensation
        self.automaticCutterCompensation()

        # Break insertion
        Breaks(self.LayerContents).process()

        #Populate the treeViews
        self.TreeHandler.buildEntitiesTree(self.EntitiesRoot)
        self.TreeHandler.buildLayerTree(self.LayerContents)

        #Print the values
        self.MyGraphicsView.clearScene()
        self.MyGraphicsScene = MyGraphicsScene()

        self.MyGraphicsScene.plotAll(self.shapes, self.EntitiesRoot)
        self.MyGraphicsView.setScene(self.MyGraphicsScene)
        self.setShow_wp_zero()
        self.setShow_path_directions()
        self.setShow_disabled_paths()
        self.setUpdate_export_route()
        self.MyGraphicsView.show()
        self.MyGraphicsView.setFocus()

        #Autoscale the Canvas
        self.MyGraphicsView.autoscale()
Beispiel #24
0
    def bulge2arc(self, Ps, Pe, bulge):
        """
        bulge2arc()
        """
        c = (1 / bulge - bulge) / 2

        #Calculate the centre point (Micke's formula!)
        O = Point(x=(Ps.x + Pe.x - (Pe.y - Ps.y) * c) / 2, \
                  y=(Ps.y + Pe.y + (Pe.x - Ps.x) * c) / 2)

        #Radius = Distance between the centre and Ps
        r = O.distance(Ps)

        #Check if they are equal (fits ...)
        #r=O.distance(Pe)

        #Unterscheidung f�r den �ffnungswinkel.
        #Distinction for the opening angle. ???
        if bulge > 0:
            return ArcGeo(Ps=Ps, Pe=Pe, O=O, r=r)
        else:
            arc = ArcGeo(Ps=Pe, Pe=Ps, O=O, r=r)
            arc.reverse()
            return arc
Beispiel #25
0
    def bulge2arc(self, Pa, Pe, bulge):
        """
        bulge2arc()
        """
        c = (1 / bulge - bulge) / 2

        #Calculate the centre point (Micke's formula!)
        O = Point(x=(Pa.x + Pe.x - (Pe.y - Pa.y) * c) / 2, \
                  y=(Pa.y + Pe.y + (Pe.x - Pa.x) * c) / 2)

        #Radius = Distance between the centre and Pa
        r = O.distance(Pa)

        #Check if they are equal (fits ...)
        #r=O.distance(Pe)

        #Unterscheidung für den Öffnungswinkel.
        #Distinction for the opening angle. ???
        if bulge > 0:
            return ArcGeo(Pa=Pa, Pe=Pe, O=O, r=r)
        else:
            arc = ArcGeo(Pa=Pe, Pe=Pa, O=O, r=r)
            arc.reverse()
            return arc
Beispiel #26
0
    def Read(self, caller):
        """
        Read()
        """
        #Assign short name
        lp = caller.line_pairs
        e = lp.index_code(0, caller.start + 1)

        #Block Name
        ind = lp.index_code(2, caller.start + 1, e)
        #print lp.line_pair[ind].value ########################################
        self.BlockName = lp.line_pair[ind].value

        #Assign layer
        s = lp.index_code(8, caller.start + 1, e)
        self.Layer_Nr = caller.Get_Layer_Nr(lp.line_pair[s].value)

        #X Value
        s = lp.index_code(10, s + 1, e)
        x0 = float(lp.line_pair[s].value)

        #Y Value
        s = lp.index_code(20, s + 1, e)
        y0 = float(lp.line_pair[s].value)
        self.Point = Point(x0, y0)

        #XScale
        s_temp = lp.index_code(41, s + 1, e)
        if s_temp != None:
            self.Scale[0] = float(lp.line_pair[s_temp].value)

        #YScale
        s_temp = lp.index_code(42, s + 1, e)
        if s_temp != None:
            self.Scale[1] = float(lp.line_pair[s_temp].value)

        #ZScale
        s_temp = lp.index_code(43, s + 1, e)
        if s_temp != None:
            self.Scale[2] = float(lp.line_pair[s_temp].value)

        #Rotation
        s_temp = lp.index_code(50, s + 1, e)
        if s_temp != None:
            self.rot = radians(float(lp.line_pair[s_temp].value))

        #New starting value for the next geometry
        caller.start = e
Beispiel #27
0
 def intersectGeometry(self, lineGeo, breakShape):
     """
     Try to break lineGeo with the given breakShape. Will return the intersection points of lineGeo with breakShape.
     """
     intersections = []
     line = QtCore.QLineF(lineGeo.Pa.x, lineGeo.Pa.y, lineGeo.Pe.x,
                          lineGeo.Pe.y)
     for breakGeo in breakShape.geos:
         if isinstance(breakGeo, LineGeo):
             breakLine = QtCore.QLineF(breakGeo.Pa.x, breakGeo.Pa.y,
                                       breakGeo.Pe.x, breakGeo.Pe.y)
             intersection = QtCore.QPointF(5, 5)
             res = line.intersect(breakLine, intersection)
             if (res == QtCore.QLineF.BoundedIntersection):
                 intersections.append(
                     Point(intersection.x(), intersection.y()))
     return intersections
Beispiel #28
0
 def intersectLineGeometry(self, lineGeo, breakShape):
     """
     Try to break lineGeo with the given breakShape. Will return the intersection points of lineGeo with breakShape.
     """
     # TODO geos should be abs
     intersections = []
     line = QtCore.QLineF(lineGeo.Ps.x, lineGeo.Ps.y, lineGeo.Pe.x,
                          lineGeo.Pe.y)
     for breakGeo in breakShape.geos:
         if isinstance(breakGeo, LineGeo):
             breakLine = QtCore.QLineF(breakGeo.Ps.x, breakGeo.Ps.y,
                                       breakGeo.Pe.x, breakGeo.Pe.y)
             intersection = QtCore.QPointF(0, 0)  # values do not matter
             res = line.intersect(breakLine, intersection)
             if res == QtCore.QLineF.BoundedIntersection:
                 intersections.append(
                     Point(intersection.x(), intersection.y()))
     return intersections
Beispiel #29
0
    def addexprouteen(self):
        """
        This function initialises the Arrows of the export route order and 
        its numbers. 
        @param shapes_st_en_points: The start and end points of the shapes.
        @param route: The order of the shapes to be plotted. 
        """

        x_st = g.config.vars.Plane_Coordinates['axis1_start_end']
        y_st = g.config.vars.Plane_Coordinates['axis2_start_end']
        st = self.expprv
        en = Point(x=x_st, y=y_st)
        self.expcol = QtCore.Qt.darkRed

        self.routearrows.append(
            Arrow(startp=st, endp=en, color=self.expcol, pencolor=self.expcol))

        self.addItem(self.routearrows[-1])
Beispiel #30
0
    def add2path(self, papath=None, parent=None, layerContent=None):
        """
        Plots the geometry of self into defined path for hit testing. Refer
        to http://stackoverflow.com/questions/11734618/check-if-point-exists-in-qpainterpath
        for description
        @param papath: The hitpath to add the geometrie
        @param parent: The parent of the shape
        """
        abs_geo = self.make_abs_geo(parent)

        segments = int(abs(degrees(abs_geo.ext) // 3) + 1)

        for i in range(segments + 1):

            ang = abs_geo.s_ang + i * abs_geo.ext / segments
            p_cur = Point(abs_geo.O.x + cos(ang) * abs(abs_geo.r),
                          abs_geo.O.y + sin(ang) * abs(abs_geo.r))

            if i >= 1:
                papath.lineTo(p_cur.x, -p_cur.y)
Beispiel #31
0
    def analyse_and_opt(self):
        """
        analyse_and_opt()
        """
        #Richtung in welcher der Anfang liegen soll (unten links)
        #Direction of top (lower left) ???
        Popt = Point(x= -1e3, y= -1e6)

        #Suchen des kleinsten Startpunkts von unten Links X zuerst (Muss neue Schleife sein!)
        #Find the smallest starting point from bottom left X (Must be new loop!)
        min_distance = self.geo[0].Ps.distance(Popt)
        min_geo_nr = 0
        for geo_nr in range(1, len(self.geo)):
            if (self.geo[geo_nr].Ps.distance(Popt) < min_distance):
                min_distance = self.geo[geo_nr].Ps.distance(Popt)
                min_geo_nr = geo_nr

        #Kontur so anordnen das neuer Startpunkt am Anfang liegt
        #Contour so the new starting point is at the start order
        self.geo = self.geo[min_geo_nr:len(self.geo)] + self.geo[0:min_geo_nr]
Beispiel #32
0
    def mouseMoveEvent(self, event):
        """
        MouseMoveEvent of the Graphiscview. May also be used for the Statusbar.
        @purpose: Get the MouseMoveEvent and use it for the Rubberband Selection
        @param event: Event Parameters passed to function
        """
        if not(self.mppos is None):
            Point = event.pos() - self.mppos
            if (Point.manhattanLength() > 3):
                #print 'the mouse has moved more than 3 pixels since the oldPosition'
                #print "Mouse Pointer is currently hovering at: ", event.pos()
                self.rubberBand.show()
                self.rubberBand.setGeometry(QtCore.QRect(self.mppos, event.pos()).normalized())

        scpoint = self.mapToScene(event.pos())

        #self.setStatusTip('X: %3.1f; Y: %3.1f' %(scpoint.x(), -scpoint.y()))
        #works not as supposed to
        self.setToolTip('X: %3.1f; Y: %3.1f' %(scpoint.x(), -scpoint.y()))

        super(MyGraphicsView, self).mouseMoveEvent(event)