Exemplo n.º 1
0
    def paint_buffer(self, zoom=0):
        """zoom:0, tai atliekam iprasta perpaisyma (zoom nebuvo paspaustas)
            zoom:1 - pradinis perpaisymas po zoom paspaudimo, nupaisome tik vartotojui matoma dali
            zoom:2 - perpaisymas po expose ivykdymo, dapaisome likusia buferio dali
        """
        #print "paint_buffer :", zoom
        self.ui_set_cursor("wait_arrow")
        area = self._device_area
        self._canvas.drag2(Point(area.width, area.height)) #pastumiam canvas, kuri paskui atstumsime atgal
        if not zoom:
            #timer.start("update 3x3")
            #self._surface_buffer = None - pilnai perpiesti draginimo metu apsimoka tik kartais, kai zoomlevelis pats maziausias - nes tada
            # ta pati figura patenka tiek i kaire tiek ir i desine drago puse ir yra perpaisoma du kartus
            self.update_surface_buffer(Area(0, 0, area.width*3, area.height*3),  self._buffer_offset)
            #timer.end("update 3x3")
        elif zoom == 1: # perpaisome po zoom paspaudimo virsutine kaire dali
            #self._surface_buffer = None
            timer.start("update 2x2")
            self.update_surface_buffer(Area(0, 0, area.width*2, area.height*2)) 
            timer.end("update 2x2")
            self._zoom = True # po expose 
        elif zoom == 2: # perpaisysime likusia dali
            timer.start("update invalid")
            self.invalidate(Area(area.width*2, 0, area.width, area.height*2)) # invaliduojame buferio desini sona
            self.invalidate(Area(0, area.height*2, area.width*3, area.height)) # invaliduojame buferio apacia
            self.update_surface_buffer(Area(0, 0, area.width*3, area.height*3))
            timer.end("update invalid")
            self._zoom = False

        self._canvas.drag2(Point(-area.width, -area.height))
        self.ui_reset_cursor()
Exemplo n.º 2
0
        def test(obj, tool):
            if obj[0] == 4:
                #data = Shape.decompress(obj).get_data()
                #data1 = geometry.curve2ocad(data)
                #data2 = geometry.triplets2bezier(data)
                
                geometry.bezier_points = []
                
                timer.start("BezierLength") # praleidziama pirma ir paskutines koordinates
                length = geometry.bezier_length(obj[3:], maxdepth=4, distance_tolerance=0.25)
                # bent dvigubai greiciau nei, kai distance_tolerance=None, panasu kai maxdepth=3
                # reikia apsispresti kas geriau (maxdepth=4, distance_tolerance=0.25), ar (maxdepth=3, distance_tolerance=None)
                # panasu, kad maxdepth=3 - duoda daugiau tasku
                # maxdepth=3 - rezultatas mane tenkina, ar galima pagreitinti pridejus distance_tolerance?
                timer.end("BezierLength")
                print "bezier length: ", length
                
                timer.start("CairoLength")
                length2 = geometry.cairo_curve_length(obj[3:])
                timer.end("CairoLength")
                print "cairo length: ", length2
                
                
                if tool._curve_id:
                    screen.replace(tool._curve_id, ScreenLine(geometry.bezier_points))
                else:
                    tool._curve_id = screen.add(ScreenLine(geometry.bezier_points))

                #timer.start("BezierLength22")
                #print "lnegth: ", geometry.bezier_length(data2, maxdepth=4, distance_tolerance=None)
                #timer.end("BezierLength22")
                
                return "Length: " + str(length)
            else:
                return str(obj[1]) + " - z-index: " + str(screen.get_canvas().get_styler().get_style(obj).get("z-index", "?")) #obj[1]
Exemplo n.º 3
0
 def draw(self, ctx, area, fill_or_stroke=True):
     """Draw the complete drawing by drawing each object in turn."""
     
     self._painter.background(ctx, area, color=(1,1,1), clip=True) # paint white background
     self._painter.setup(ctx, transform={"translate":self.get_offset(), "scale": self.get_ratio()})
     
     # paishysime tik tuos tashkus kurie pakliuna i vartotojo langa
     # reikia device_area konvertuoti i user koordinates
     x, y = self.device_to_user(Point(area.x, area.y))
     x2, y2 = self.device_to_user(Point(area.x + area.width, area.y + area.height))
     
     radius = 0 #self.pixel_radius + self.line_width # ne cia reikia prideti radiusa, o ten kur dedame i cavas'a shape'us
     # geriau cia, nes paprasciau yra iskviesti nupaisyti didesni gabala nei paskaiciuoti tikslu pvz linijo simboliu dydi...
     
     elements = self._index_rtree.intersection((x-radius, y-radius, x2+radius, y2+radius))
     elements_zindex = self._styler.create_zindex(elements) # jis yra pilnas visu galimu zindex'u sarasas - pradzioje dalis ju gali buti ir tusti []
     
     timer.start("draw")
     for zindex in sorted(elements_zindex.keys()):
         for element in elements_zindex[zindex]:
             #print "element: ", element[0][0]
             self._painter.draw(element, update=elements_zindex, fill_or_stroke=fill_or_stroke) # kazka visada nupaiso - bet dar papildomai gali iterpti elementu su didesniu zindex'u
             # tie elementai bus nupaisomi veliau.
         
     timer.end("draw")
Exemplo n.º 4
0
    def update_surface_buffer(self, area, offset=Point(0, 0)):
        """update self._surface_buffer"""
        #self._surface_buffer = None
        if not self._surface_buffer:
            self._surface_buffer = cairo.ImageSurface(cairo.FORMAT_ARGB32, area.width,  area.height)
            #self._surface_buffer = cairo.RecordingSurface(cairo.CONTENT_COLOR_ALPHA, (0,0, area.width, area.height))

            context = cairo.Context(self._surface_buffer)
            timer.start("expose full redraw")
            self._canvas.draw(context, area)
            timer.end("expose full redraw")
        else: # reikia paslinkti arba tiesiog perpaisyti is buferio
            #print "expose buffer"
            # nupaisome buferi (jeigu reikia su postumiu)
            merged_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, area.width, area.height)
            #merged_surface = cairo.RecordingSurface(cairo.CONTENT_COLOR_ALPHA, (0,0, area.width, area.height))
            merged_ctx = cairo.Context(merged_surface)

            merged_ctx.set_source_surface(self._surface_buffer, offset.x, offset.y)
            merged_ctx.paint()
            # pridejome sena padraginta gabala
            
            # dabar pridesime papildomus gabalus, jeigu atliktas dragas
            self.invalidate_drag_regions(area, offset) # paskaiciuojame ka reikia perpaisyti po draginimo virsuje/apacioje/sonuose
            self.draw_invalid_regions(merged_surface) # perpaisome viska, kas buvo irasyra i self._redraw_regions = []
            self._surface_buffer = merged_surface
Exemplo n.º 5
0
 def press(self, screen, point):
     timer.start("press")
     if self._object_index != None:
         id = self._selected_objects[self._object_index]
         found = list(reversed(screen.get_canvas().find_objects_at_position(point))) # apverciame kad pirmi eitu tie kuriuos nupaiseme veliausiai
         if id in found:
             self._drag_object_id = id # start dragging object
             self._drag_object_point = point # start of the dragging
         else:
             self._drag_object_id = None
     timer.end("press")
Exemplo n.º 6
0
 def load_fcad_file(self, file_path):
     timer.start("loading shapes.fcad")
     self._shapes = ShapeFile.read_fcad_file(file_path)
 
     if len(self._shapes):
         def generator_function(points):
             for i, obj in enumerate(points):
                 if obj == None: continue
                 yield (i, self._styler.get_bbox(fshape.Shape.decompress(obj)), obj)
         self._index_rtree = Rtree(generator_function(self._shapes))
     timer.end("loading shapes.fcad")
Exemplo n.º 7
0
 def load_pickle(self, file_path):
     timer.start("loading shapes.p")
     if os.path.exists(file_path):
         self._shapes = pickle.load(open(file_path, "rb"))
         
         if len(self._shapes):
             def generator_function(points):
                 for i, obj in enumerate(points):
                     if obj == None: continue
                     yield (i, self._styler.get_bbox(fshape.Shape.decompress(obj)), obj)
             self._index_rtree = Rtree(generator_function(self._shapes))
     timer.end("loading shapes.p")
Exemplo n.º 8
0
 def draw_object(self, ctx, id, fill_or_stroke=True):
     #self.apply_transforms(ctx) # drag and scale
     self._painter.setup(ctx, transform={"translate":self.get_offset(), "scale": self.get_ratio()})
     
     elements_zindex = self._styler.create_zindex([id])
     
     timer.start("draw single object")
     for zindex in sorted(elements_zindex.keys()):
         for element in elements_zindex[zindex]:
             self._painter.draw(element, update=elements_zindex, fill_or_stroke=fill_or_stroke) # kazka visada nupaiso - bet dar papildomai gali iterpti elementu su didesniu zindex'u
         
     timer.end("draw single object")
Exemplo n.º 9
0
    def release(self, screen, point):
        timer.start("release")
        if self._drag_object_id != None: # object drag end
            offset = (point.x - self._drag_object_point.x, point.y - self._drag_object_point.y)
            if offset != (0,0):
                Invoker.execute(MoveShapeCommand(self, screen, self._drag_object_id, offset))
                text = "Object %i was moved." % self._drag_object_id
                self._drag_object_id = None
                return text

        shape_id = self.get_next(screen, point)
        
        if shape_id != None:
            self.show_handlers(screen, ScreenSelectedObject(shape_id))
            timer.end("release")
            return "%i:%i of %i" % (self._object_index, shape_id, len(self._selected_objects))
        else: 
            timer.end("release")
            return "No objects found"
Exemplo n.º 10
0
    def draw_100(self, ctx, area):
        """100% draw for printing, no scale, area in user coordinates"""
        page_area = Area(0, 0, area.width, area.height)
        #ctx.rectangle(0, 0, area.width, area.height) 
        #ctx.clip() # tam kad nepaisytu uzh sito staciakampio ribu (tada gaunasi dubliuotos linijos)
        #self.background(ctx, page_area) # paint white background
        
        self._painter.background(ctx, page_area, color=(1,1,1), clip=True) # paint white background
        self._painter.setup(ctx, transform={"translate":(-area.x, -area.y)})

        radius = 0 #self.pixel_radius + self.line_width # ne cia reikia prideti radiusa, o ten kur dedame i cavas'a shape'us
        
        elements = self._index_rtree.intersection((area.x-radius, area.y-radius, area.x+area.width+radius, area.y+area.height+radius))
        elements_zindex = self._styler.create_zindex(elements) # jis yra pilnas visu galimu zindex'u sarasas - pradzioje dalis ju gali buti ir tusti []
        
        timer.start("draw100")
        for zindex in sorted(elements_zindex.keys()):
            for element in elements_zindex[zindex]:
                self._painter.draw(element, update=elements_zindex) # kazka visada nupaiso - bet dar papildomai gali iterpti elementu su didesniu zindex'u
                # tie elementai bus nupaisomi veliau.
            
        timer.end("draw100")
Exemplo n.º 11
0
    def add_random_points(self, number, area, generator=True):
        """Kai generator=False - sunaudoja maziau atminties ikrovimo metu, bet trunka gerokai leciau
        """
        self._shapes = []
        timer.start("Adding random data")

        from random import randint
        for x in range(0, number):
            color = 65536 * randint(0,255) + 256 * randint(0,255) + randint(0,255) # RGBint
            x, y = randint(2, area.width), randint(2, area.height)

            if not generator: # darysime rtree.add kiekvienam taskui atskirai
                self.add(fshape.Shape(1, Point(x, y), color=color))
            else:
                self._shapes.append((1, color, x, y))
        
        if generator:
            def generator_function(points):
                for i, obj in enumerate(points):
                    yield (i, (obj[2], obj[3], obj[2], obj[3]), obj)
            self._index_rtree = Rtree(generator_function(self._shapes))
        
        timer.end("Adding random data")
Exemplo n.º 12
0
    def load_shape_file(self, file_path, generator=True):
        import shapefile
        from random import randint

        sf = shapefile.Reader(file_path)
        print "Number of shapes: ", sf.numRecords
        
        self.add(fshape.Shape(1, Point(0, 0), style={"z-index":99})) # koordinaciu centras
        
        if self.prj.scale == 1: # pirmas kartas
            prj = GisProjection(self, sf.bbox)
            #po sito ciklo jau turesime zemelapio ribas
            center = prj.map_to_user(prj.get_center())
            self.center(center)
            self.prj = prj
                    
        timer.start("Adding shapes")
        symbol = sf.shapeName.split("/")[-1]
        self._styler.set_symbol_style(symbol, {"color": (randint(0,255),randint(0,255),randint(0,255))})
        
        for shape in sf.ogis_shapes(self.prj):
            self.add(fshape.Shape(shape.shapeType, shape.points, symbol=symbol))
        timer.end("Adding shapes")
Exemplo n.º 13
0
    def load_ocad_file(self, file_path, generator=True):
        #import ocadfile
        #self.add(Shape(1, Point(0, 0), symbol="graphics")) # koordinaciu centras

        self._prj = GisProjection()
        self._zoom_level = self._ratio_index.index(4)
        
        of = OcadFile(file_path, self._prj)
        #self._styler.load_ocad_symbols(of, prj)

        timer.start("Adding ocad symbols")
        self._styler.set_symbols_style(of.get_symbols_style())
        timer.end("Adding ocad symbols")
        
        
        timer.start("Adding ocad elements")
        shapes = of.get_shapes()
        print "Shapes: ", len(shapes)
        for shape in shapes:
            self.add(shape)
        timer.end("Adding ocad elements")
        
        self.center()