コード例 #1
0
ファイル: genericshapebase.py プロジェクト: apullin/popupcad
 def buildvertexlist(points):
     exterior = []
     for point in points:
         v=ShapeVertex()
         v.setpos(point)
         exterior.append(v)
     return exterior
コード例 #2
0
ファイル: proto.py プロジェクト: heiko114514/popupcad
    def mousepress(self, point):
        import numpy
        point = tuple(numpy.array(qh.to_tuple(point)) / popupcad.view_scaling)

        if not self.temphandle:
            a = ShapeVertex(point)
            self.temphandle = a.gen_interactive()
            self.temphandle.setParentItem(self)
            self.temphandle.updatescale()

        if self.generic.len_exterior() == 0:
            self.addhandle(self.temphandle)
            a = ShapeVertex(point)
            self.temphandle = a.gen_interactive()
            self.temphandle.setParentItem(self)
            self.temphandle.updatescale()
            self.updateshape()
            return

        elif self.generic.len_exterior() == 1:
            if self.addhandle(self.temphandle):
                self.finish_definition()
                self.updateshape()
                return

            else:
                return
        else:
            raise Exception
            self.finish_definition()
            self.updateshape()
            return
        self.updateshape()
コード例 #3
0
ファイル: interactive.py プロジェクト: apullin/popupcad
 def addvertex(self,qpoint):
     from popupcad.geometry.vertex import ShapeVertex
     v = ShapeVertex()
     v.setpos(qpoint.toTuple())
     self.generic.addvertex_exterior(v,special = True)
     self.updatehandles()
     self.refreshview()        
コード例 #4
0
    def gen_from_point_lists(cls, exterior_p, interiors_p, **kwargs):

        exterior = [ShapeVertex(point) for point in exterior_p]
        interiors = [[ShapeVertex(point) for point in interior]
                     for interior in interiors_p]

        return cls(exterior, interiors, **kwargs)
コード例 #5
0
ファイル: proto.py プロジェクト: apullin/popupcad
    def mousepress(self,point):
        if not self.temphandle:
            a = ShapeVertex()
            a.setpos(point.toTuple())
            self.temphandle = a.gen_interactive()
            self.temphandle.setParentItem(self)
            self.temphandle.updatescale()
            
        if len(self.generic.get_exterior())==0:
            self.addhandle(self.temphandle)
            a = ShapeVertex()
            a.setpos(point.toTuple())
            self.temphandle = a.gen_interactive()
            self.temphandle.setParentItem(self)
            self.temphandle.updatescale()
            self.updateshape()
            return
            
        elif len(self.generic.get_exterior())==1:
            if self.addhandle(self.temphandle):
                self.finish_definition()
                self.updateshape()
                return

            else:
                return
        else:
            raise(Exception('should never get here'))
            self.finish_definition()
            self.updateshape()
            return
        self.updateshape()
コード例 #6
0
def getjoints(geoms,roundvalue):
    from popupcad.geometry.vertex import ShapeVertex
    from popupcad.filetypes.genericshapes import GenericLine
    
    tolerance = 10**(-roundvalue)

    lines = []

    for geom in geoms:
        p = geom.exteriorpoints()
        lines.extend(zip(p, p[1:] + p[:1]))
        for interior in geom.interiorpoints():
            lines.extend(zip(interior, interior[1:] + interior[:1]))

    l3 = popupcad.algorithms.points.distance_of_lines(lines, [0, 0])
    l4 = popupcad.algorithms.points.distance_of_lines(lines, [10 * tolerance, 0])
    l5 = popupcad.algorithms.points.distance_of_lines(lines, [10 * tolerance, 10 * tolerance])
    l6 = popupcad.algorithms.points.distance_of_lines(lines, [0, 10 * tolerance])
    l7 = popupcad.algorithms.points.distance_of_lines(lines, [10 * tolerance, 20 * tolerance])
    
    m = numpy.c_[l3, l4, l5, l6, l7]
    m = m.round(roundvalue)
    m2 = [tuple(items) for items in m.tolist()]
    m3 = list(set(m2))
#    jj = numpy.searchsorted(m3,m2)
    index_to_unique = [m3.index(item) for item in m2]
    indeces_to_orig = [[] for item in m3]
    [indeces_to_orig[item].append(ii) for ii, item in enumerate(index_to_unique)]

    newsegments = []
    for segments in indeces_to_orig:
        if len(segments) > 1:
            a = [lines[ii] for ii in segments]
            vertices = []
            [vertices.extend(item) for item in a[1:]]
            ordered_vertices = popupcad.algorithms.points.order_vertices(vertices,a[0],tolerance=tolerance)
            segs = list(zip(ordered_vertices[:-1], ordered_vertices[1:]))
            midpoints = popupcad.algorithms.points.segment_midpoints(segs)
            count = [0 for item in midpoints]
            for ii in segments:
                for jj, point in enumerate(midpoints):
                    if popupcad.algorithms.points.point_within_line(point,lines[ii],tolerance=tolerance):
                        count[jj] += 1
            newsegments.extend([seg for count_ii, seg in zip(count, segs) if count_ii > 1])

    generic_lines = [GenericLine([ShapeVertex(v1), ShapeVertex(v2)], []) for v1, v2 in newsegments]
    generic_lines = [item for item in generic_lines if len(item.get_exterior()) == 2]
    return generic_lines
コード例 #7
0
 def addvertex(self, qpoint):
     from popupcad.geometry.vertex import ShapeVertex
     import numpy
     v = ShapeVertex(numpy.array(qh.to_tuple(qpoint))/popupcad.view_scaling)
     self.generic.addvertex_exterior(v, special=True)
     self.updatehandles()
     self.refreshview()
コード例 #8
0
ファイル: sketcher.py プロジェクト: yushuiqiang/popupcad
    def add_constraint(self, constraintclass):
        from popupcad.filetypes.genericshapes import GenericLine
        self.undoredo.savesnapshot()
        items = []
        new_constraints = []

        for item in self.scene.selectedItems():
            if isinstance(item, ReferenceInteractiveVertex):
                generic = item.get_generic()
                newgeneric = DrawnPoint(generic.getpos(), construction=True)
                newitem = newgeneric.gen_interactive()
                self.scene.addItem(newitem)
                items.append(newgeneric)
                item.setSelected(False)
                newitem.setSelected(True)
                new_constraints.append(
                    constraints.FixedConstraint.new(newgeneric))

            elif isinstance(item, ReferenceInteractiveEdge):
                generic = item.get_generic()
                v1 = ShapeVertex(generic.vertex1.getpos())
                v2 = ShapeVertex(generic.vertex2.getpos())
                new_constraints.append(constraints.FixedConstraint.new(v1, v2))

                l = GenericLine([v1, v2], [], construction=True)

                a = l.outputinteractive()
                self.scene.addItem(a)

                item.setSelected(False)
                a.setSelected(True)
                items.append(a.selectableedges[0].get_generic())

            elif isinstance(item, InteractiveVertex):
                items.append(item.get_generic())
            elif isinstance(item, InteractiveEdge):
                items.append(item.get_generic())
            elif isinstance(item, DrawingPoint):
                items.append(item.get_generic())

        new_constraint = constraintclass.new(*items)
        if new_constraint is not None:
            new_constraints.append(new_constraint)
            for constraint in new_constraints:
                self.sketch.constraintsystem.add_constraint(constraint)
            self.refreshconstraints()
コード例 #9
0
ファイル: proto.py プロジェクト: heiko114514/popupcad
    def mousepress(self, point):
        import numpy
        point = tuple(numpy.array(qh.to_tuple(point)) / popupcad.view_scaling)

        if not self.temphandle:
            a = ShapeVertex(point)
            self.temphandle = a.gen_interactive()
            self.temphandle.setParentItem(self)
            self.temphandle.updatescale()
            self.addhandle(self.temphandle)
        else:
            self.addhandle(self.temphandle)
        if not self.temphandle:
            a = ShapeVertex(point)
            self.temphandle = a.gen_interactive()
            self.temphandle.setParentItem(self)
            self.temphandle.updatescale()

        self.updateshape()
コード例 #10
0
    def mousepress(self, point):
        import numpy
        point = tuple(numpy.array(qh.to_tuple(point)) / popupcad.view_scaling)

        if not self.temphandle:
            a = ShapeVertex(point)
            self.temphandle = a.gen_interactive()
            self.temphandle.setParentItem(self)
            self.temphandle.updatescale()

        if self.generic.len_exterior() == 0:
            self.addhandle(self.temphandle)
            a = ShapeVertex(point)
            self.temphandle = a.gen_interactive()
            self.temphandle.setParentItem(self)
            self.temphandle.updatescale()
            self.updateshape()
            return

        elif self.generic.len_exterior() == 1:
            if self.addhandle(self.temphandle):
                self.finish_definition()
                self.updateshape()
                return

            else:
                return
        else:
            raise Exception
            self.finish_definition()
            self.updateshape()
            return
        self.updateshape()
コード例 #11
0
def to_generic(entity):
    import shapely.geometry as sg
    from popupcad.filetypes.genericshapes import GenericPoly, GenericPolyline
    from popupcad.geometry.vertex import DrawnPoint
    from popupcad.geometry.vertex import ShapeVertex

    exterior_p, interiors_p = get_shapely_vertices(
        entity, 1 / popupcad.csg_processing_scaling)
    exterior = [ShapeVertex(point) for point in exterior_p]
    interiors = [[ShapeVertex(point) for point in interior]
                 for interior in interiors_p]

    if isinstance(entity, sg.Polygon):
        subclass = GenericPoly
    elif isinstance(entity, sg.LineString):
        subclass = GenericPolyline
    elif isinstance(entity, sg.Point):
        s = DrawnPoint(exterior_p[0])
        return s
    else:
        raise GeometryNotHandled()
    return subclass(exterior, interiors)
コード例 #12
0
ファイル: proto.py プロジェクト: apullin/popupcad
    def mousepress(self,point):
        if not self.temphandle:
            a = ShapeVertex()
            a.setpos(point.toTuple())
            self.temphandle = a.gen_interactive()
            self.temphandle.setParentItem(self)
            self.temphandle.updatescale()
            self.addhandle(self.temphandle)
        else:
            self.addhandle(self.temphandle)
        if not self.temphandle:
            a = ShapeVertex()
            a.setpos(point.toTuple())
            self.temphandle = a.gen_interactive()
            self.temphandle.setParentItem(self)
            self.temphandle.updatescale()

        self.updateshape()
コード例 #13
0
    def mousePressEvent(self, event):
        pos = event.scenePos()

        if self.temp is not None:
            if event.button() == qc.Qt.LeftButton:
                self.temp.mousepress(pos)

        elif self.nextgeometry is not None:
            if event.button() == qc.Qt.LeftButton:
                if self.temp is None:
                    if self.nextgeometry == TextParent:
                        textpos = ShapeVertex(qh.to_tuple(pos),
                                              scaling=1 /
                                              popupcad.view_scaling)
                        text = GenericText('',
                                           textpos,
                                           font='Courier New',
                                           fontsize=1)
                        temp = self.nextgeometry(text)
                        self.addItem(temp)
                        temp.editmode()

                    elif self.nextgeometry == DrawingPoint:
                        temp = self.nextgeometry(
                            DrawnPoint(qh.to_tuple(pos),
                                       scaling=1 / popupcad.view_scaling))
                        self.addItem(temp)
                        self.setFocusItem(temp)
                        temp.updatescale()
                        self.childfinished()
                    else:
                        self.temp = self.nextgeometry()
                        self.addItem(self.temp)
                        self.setFocusItem(self.temp)
                        self.temp.mousepress(pos)
        else:
            qg.QGraphicsScene.mousePressEvent(self, event)
            self.leavingeditmode.emit()
コード例 #14
0
    def mousepress(self, point):
        import numpy
        point = tuple(numpy.array(qh.to_tuple(point)) / popupcad.view_scaling)

        if not self.temphandle:
            a = ShapeVertex(point)
            self.temphandle = a.gen_interactive()
            self.temphandle.setParentItem(self)
            self.temphandle.updatescale()
            self.addhandle(self.temphandle)
        else:
            self.addhandle(self.temphandle)
        if not self.temphandle:
            a = ShapeVertex(point)
            self.temphandle = a.gen_interactive()
            self.temphandle.setParentItem(self)
            self.temphandle.updatescale()

        self.updateshape()