Exemple #1
0
 def __init__(self, mode, *args, **kwargs):
     Usb.__init__(self, *args, **kwargs)
     self.cutter = Cutter()
     if mode == 'rpi':
         self.cut = self._cut_rpi
     else:
         self.cut = Usb.cut
Exemple #2
0
def izvadi( fime, srezove, dirime, nomer =None, ime ='', opfx =''):
    log()
    c = Cutter()
    if isinstance( srezove, str):
        srezove = [s.split('#',1)[0] for s in srezove.split('\n')]
        v = ' '.join( s for s in srezove if s.strip())
        v = rec2dir.opravi_tireta( v, spc=' ')
        c.readcuts( v)
    elif isinstance( srezove, dict):
        for k,v in srezove.items():
            c.name = str(k)
            v = rec2dir.opravi_tireta( v, spc=' ')
            c.readcuts( v)
            c.add()
    else:
        assert 0, (srezove, fime)

    c.save( infile= fime, path= dirime,
        ofile_as_sfx = ''.join( '-'+str(f) for f in [
            #opfx or dirime.rstrip('/'),
            #fime,
            ime, nomer]
            if f),
        do_nothing= not optz.zapis,
        #verbose= True
        )
Exemple #3
0
    def __drawCutter(self, c: Cutter):
        tl = c.topLeft()
        br = c.bottomRight()

        c.setSceneItem(
            self.scene.addRect(tl.x(), tl.y(),
                               br.x() - tl.x(),
                               br.y() - tl.y(), self.CUTTER_COLOR))
Exemple #4
0
class KXKMPrinter(Usb):
    def __init__(self, mode, *args, **kwargs):
        Usb.__init__(self, *args, **kwargs)
        self.cutter = Cutter()
        if mode == 'rpi':
            self.cut = self._cut_rpi
        else:
            self.cut = Usb.cut

    def _cut_rpi(self, mode='PART', feed=True):
        """ Cut paper.
        Without any arguments the paper will be cut completely. With 'mode=PART' a partial cut will
        be attempted. Note however, that not all models can do a partial cut. See the documentation of
        your printer for details.
        .. todo:: Check this function on TM-T88II.
        :param mode: set to 'PART' for a partial cut. default: 'FULL'
        :param feed: print and feed before cutting. default: true
        :raises ValueError: if mode not in ('FULL', 'PART')
        """

        if feed:
            self._raw(ESC + b"d" + six.int2byte(4))
            time.sleep(0.15)
            time.sleep(0.10)

        mode = mode.upper()
        if mode not in ('FULL', 'PART'):
            raise ValueError("Mode must be one of ('FULL', 'PART')")

        try:
            if mode == "PART":
                self.cutter.cut(CUT_HALF)
            elif mode == "FULL":
                self.cutter.cut(CUT_FULL)
        except Exception as e:
            self.cutter.stop()
            raise e

        time.sleep(0.15)
        time.sleep(0.15)

        if feed:
            self._raw(ESC + b"d" + six.int2byte(3))
            #time.sleep(0.00)

    def _test(self):
        self.cut()
        time.sleep(0.5)
        self.cut()
        time.sleep(0.5)
        self.cut(mode='FULL')
        time.sleep(0.5)
        self.cutter._test()
        time.sleep(0.1)
        self.cutter._repos()
Exemple #5
0
    def __init__(self):
        Node.__init__(self)

        self.bz_points = True
        self.bz_curves = True
        self.bz_polygons = False

        self.bs_points = True
        self.bs_curves = False
        self.bs_polygons = False

        self.selected = None

        self.cutter = Cutter()

        self.w = 0
        self.h = 0
Exemple #6
0
	def __init__( self ) :
		Node.__init__( self )

		self.bz_points   = True
		self.bz_curves   = True
		self.bz_polygons = False

		self.bs_points   = True
		self.bs_curves   = False
		self.bs_polygons = False

		self.selected = None

		self.cutter = Cutter()

		self.w = 0
		self.h = 0
Exemple #7
0
class Curves( Node ) :
	BEZIER_C0 , BEZIER_C2 , INTERPOLATION , SURFACE_C0 , SURFACE_C2 , SURFACE_PIPE , SURFACE_GREGORY = range(7)
	C0 , C1 , C2 = range(3)

	def __init__( self ) :
		Node.__init__( self )

		self.bz_points   = True
		self.bz_curves   = True
		self.bz_polygons = False

		self.bs_points   = True
		self.bs_curves   = False
		self.bs_polygons = False

		self.selected = None

		self.cutter = Cutter()

		self.w = 0
		self.h = 0

	def clear( self ) :
		self.del_all()
		self.selected = None
		self.cutter.clear()

	def set_screen_size( self , w , h ) :
		self.w = w
		self.h = h
		for b in self :
			b.set_screen_size( w , h )

	def set_editmode( self , mode ) :
		for b in self :
			b.set_editmode( mode )

	def new( self , pos , which_cur , pre_data = None , post_data = None ) :
		if which_cur == Curves.BEZIER_C0 :
			self.selected = BezierC0( self.bz_points , self.bz_curves , self.bz_polygons )
		elif which_cur == Curves.BEZIER_C2 :
			self.selected = BezierC2(
								self.bz_points , self.bz_curves , self.bz_polygons ,
								self.bs_points , self.bs_curves , self.bs_polygons )
		elif which_cur == Curves.INTERPOLATION :
			self.selected = Interpolation( )
		elif which_cur == Curves.SURFACE_C0 :
			self.selected = SurfaceC0( pre_data , self.bz_points , self.bz_curves , self.bz_polygons )
		elif which_cur == Curves.SURFACE_C2 :
			self.selected = SurfaceC2( pre_data , self.bz_points , self.bz_curves , self.bz_polygons )
		elif which_cur == Curves.SURFACE_PIPE :
			self.selected = Pipe( pre_data , self.bz_points , self.bz_curves , self.bz_polygons )
		elif which_cur == Curves.SURFACE_GREGORY :
			self.selected = GregoryGap( pre_data , self.bz_points , self.bz_curves , self.bz_polygons )

		self.selected.new( pos , post_data )
		self.add_child( self.selected )

		self.selected.set_screen_size( self.w , self.h )

	def delete( self , pos , dist = .05 ) :
		s = self.find_near( pos , dist )
		if not s[1] :
			return
		if self.selected == s[1] :
			self.selected = None
		self.del_child( s[1] )

	def select( self , pos , dist = .05 ) :
		v , self.selected = self.find_near( pos , dist )

	def find_near( self , pos , dist ) :
		minv = None
		for pts in self :
			v , p = pts.find_nearest( pos , dist )
			if minv == None or minv > v :
				out = pts
				minv = v

		if not minv :
			return float('inf') , None
		else :
			return minv , out

	def point_new( self , which , pos ) :
		if self.selected :
			self.selected.new( pos , which )
			self.selected.get_geom().refresh()

	def point_delete( self , pos , dist ) :
		if self.selected :
			self.selected.delete( pos , dist )
			self.selected.get_geom().refresh()

	def point_select( self , pos , dist ) :
		if self.selected :
			self.selected.select( pos , dist )
			self.selected.get_geom().refresh()

	def point_move( self , v ) :
		if self.selected :
			self.selected.move_current( v )
			if self.cutter.cuts( self.selected ) :
				self.cutter.reset_trimms()

	def toggle( self , which , what ) :
		if which == Curve.BEZIER :
			if what == Curve.POINTS :
				self.bz_points = not self.bz_points
			elif what == Bezier.CURVE :
				self.bz_curves = not self.bz_curves
			elif what == Bezier.POLYGON :
				self.bz_polygons = not self.bz_polygons
		elif which == Curve.BSPLINE :
			if what == Curve.POINTS :
				self.bs_points = not self.bs_points
			elif what == Bezier.CURVE :
				self.bs_curves = not self.bs_curves
			elif what == Bezier.POLYGON :
				self.bs_polygons = not self.bs_polygons

		for b in self :
			b.set_visibility( Curve.BEZIER , self.bz_points , self.bz_curves , self.bz_polygons )
			b.set_visibility( Curve.BSPLINE, self.bs_points , self.bs_curves , self.bs_polygons )
			b.get_geom().refresh()

	def set_surf_density( self , dens ) :
		for b in self :
			if isinstance(b,SurfaceC0) or isinstance(b,SurfaceC2) or isinstance(b,GregoryGap) :
				b.set_density( dens )

	def fill_gap( self , c ) :
		if isinstance(self.selected,GregoryGap) :
			if c == None :
				self.selected.fill_gap_none()
			if c == Curves.C0 :
				self.selected.fill_gap_c0()
			elif c == Curves.C1 :
				self.selected.fill_gap_c1()
			elif c == Curves.C2 :
				self.selected.fill_gap_c2()

	def select_to_cut( self , pos , dist = .05 ) :
		v , c = self.find_near( pos , dist )
		if c != None and isinstance(c,SurfaceC2) :
			self.cutter.add( c )

	def cut( self , pos , delta ) :
		return self.cutter.cut( pos , delta )

	def clear_cut( self ) :
		self.cutter.reset_trimms()
		self.cutter.reset_ind()

	def cut_select( self , i , k ) :
		self.cutter.cut_select( i , k )

	def load( self , path ) :
		with open(path,"r+") as f :
			for k in xrange(int(f.readline())) :
				u , v , t = map( int , f.readline().split(' ') )
				pts = []
				for i in xrange(u*(v+3) if t != 0 else (u+3)*(v+3)) :
					pts.append( np.array( f.readline().split(' ') , np.float32 ) )
				if t == 0 :
					self.add_child( SurfaceC2( ( (u,v) , (1,1) ) ,
						self.bz_points , self.bz_curves , self.bz_polygons , pts ) )
				else : 
					self.add_child( Pipe(( (u,v) , (1,1) ) ,
						self.bz_points , self.bz_curves , self.bz_polygons , pts ) )

	def dump( self , path ) :
		with open(path,"w+") as f :
			count = 0
			for s in self : 
				if not isinstance(s,SurfaceC2) : continue
				count += 1
			f.write(str(count)+"\n")
			for s in self :
				if not isinstance(s,SurfaceC2) : continue
				f.write("{1} {2} {0}\n".format(int(isinstance(s,Pipe)),*s.get_uv()))
				for p in s.iter_pts() :
					f.write("{0} {1} {2}\n".format(*p))
from pizza import Pizza
from cutter import Cutter

pizza = Pizza()
pizza.read('small')
pizza.slice((0, 0), (0, 2))
pizza.slice((0, 0), (3, 6))

for i in range(1, 7):
    pizza.slice((1, 5), (i, i))

pizza.parse_to_file()

pizza = Pizza()
pizza.read('medium')
Cutter(pizza).solve(4, 3)

pizza = Pizza()
pizza.read('big')
Cutter(pizza).solve(2, 6)
Exemple #9
0
class Curves(Node):
    BEZIER_C0, BEZIER_C2, INTERPOLATION, SURFACE_C0, SURFACE_C2, SURFACE_PIPE, SURFACE_GREGORY = range(
        7)
    C0, C1, C2 = range(3)

    def __init__(self):
        Node.__init__(self)

        self.bz_points = True
        self.bz_curves = True
        self.bz_polygons = False

        self.bs_points = True
        self.bs_curves = False
        self.bs_polygons = False

        self.selected = None

        self.cutter = Cutter()

        self.w = 0
        self.h = 0

    def clear(self):
        self.del_all()
        self.selected = None
        self.cutter.clear()

    def set_screen_size(self, w, h):
        self.w = w
        self.h = h
        for b in self:
            b.set_screen_size(w, h)

    def set_editmode(self, mode):
        for b in self:
            b.set_editmode(mode)

    def new(self, pos, which_cur, pre_data=None, post_data=None):
        if which_cur == Curves.BEZIER_C0:
            self.selected = BezierC0(self.bz_points, self.bz_curves,
                                     self.bz_polygons)
        elif which_cur == Curves.BEZIER_C2:
            self.selected = BezierC2(self.bz_points, self.bz_curves,
                                     self.bz_polygons, self.bs_points,
                                     self.bs_curves, self.bs_polygons)
        elif which_cur == Curves.INTERPOLATION:
            self.selected = Interpolation()
        elif which_cur == Curves.SURFACE_C0:
            self.selected = SurfaceC0(pre_data, self.bz_points, self.bz_curves,
                                      self.bz_polygons)
        elif which_cur == Curves.SURFACE_C2:
            self.selected = SurfaceC2(pre_data, self.bz_points, self.bz_curves,
                                      self.bz_polygons)
        elif which_cur == Curves.SURFACE_PIPE:
            self.selected = Pipe(pre_data, self.bz_points, self.bz_curves,
                                 self.bz_polygons)
        elif which_cur == Curves.SURFACE_GREGORY:
            self.selected = GregoryGap(pre_data, self.bz_points,
                                       self.bz_curves, self.bz_polygons)

        self.selected.new(pos, post_data)
        self.add_child(self.selected)

        self.selected.set_screen_size(self.w, self.h)

    def delete(self, pos, dist=.05):
        s = self.find_near(pos, dist)
        if not s[1]:
            return
        if self.selected == s[1]:
            self.selected = None
        self.del_child(s[1])

    def select(self, pos, dist=.05):
        v, self.selected = self.find_near(pos, dist)

    def find_near(self, pos, dist):
        minv = None
        for pts in self:
            v, p = pts.find_nearest(pos, dist)
            if minv == None or minv > v:
                out = pts
                minv = v

        if not minv:
            return float('inf'), None
        else:
            return minv, out

    def point_new(self, which, pos):
        if self.selected:
            self.selected.new(pos, which)
            self.selected.get_geom().refresh()

    def point_delete(self, pos, dist):
        if self.selected:
            self.selected.delete(pos, dist)
            self.selected.get_geom().refresh()

    def point_select(self, pos, dist):
        if self.selected:
            self.selected.select(pos, dist)
            self.selected.get_geom().refresh()

    def point_move(self, v):
        if self.selected:
            self.selected.move_current(v)
            if self.cutter.cuts(self.selected):
                self.cutter.reset_trimms()

    def toggle(self, which, what):
        if which == Curve.BEZIER:
            if what == Curve.POINTS:
                self.bz_points = not self.bz_points
            elif what == Bezier.CURVE:
                self.bz_curves = not self.bz_curves
            elif what == Bezier.POLYGON:
                self.bz_polygons = not self.bz_polygons
        elif which == Curve.BSPLINE:
            if what == Curve.POINTS:
                self.bs_points = not self.bs_points
            elif what == Bezier.CURVE:
                self.bs_curves = not self.bs_curves
            elif what == Bezier.POLYGON:
                self.bs_polygons = not self.bs_polygons

        for b in self:
            b.set_visibility(Curve.BEZIER, self.bz_points, self.bz_curves,
                             self.bz_polygons)
            b.set_visibility(Curve.BSPLINE, self.bs_points, self.bs_curves,
                             self.bs_polygons)
            b.get_geom().refresh()

    def set_surf_density(self, dens):
        for b in self:
            if isinstance(b, SurfaceC0) or isinstance(
                    b, SurfaceC2) or isinstance(b, GregoryGap):
                b.set_density(dens)

    def fill_gap(self, c):
        if isinstance(self.selected, GregoryGap):
            if c == None:
                self.selected.fill_gap_none()
            if c == Curves.C0:
                self.selected.fill_gap_c0()
            elif c == Curves.C1:
                self.selected.fill_gap_c1()
            elif c == Curves.C2:
                self.selected.fill_gap_c2()

    def select_to_cut(self, pos, dist=.05):
        v, c = self.find_near(pos, dist)
        if c != None and isinstance(c, SurfaceC2):
            self.cutter.add(c)

    def cut(self, pos, delta):
        return self.cutter.cut(pos, delta)

    def clear_cut(self):
        self.cutter.reset_trimms()
        self.cutter.reset_ind()

    def cut_select(self, i, k):
        self.cutter.cut_select(i, k)

    def load(self, path):
        with open(path, "r+") as f:
            for k in xrange(int(f.readline())):
                u, v, t = map(int, f.readline().split(' '))
                pts = []
                for i in xrange(u * (v + 3) if t != 0 else (u + 3) * (v + 3)):
                    pts.append(np.array(f.readline().split(' '), np.float32))
                if t == 0:
                    self.add_child(
                        SurfaceC2(((u, v), (1, 1)), self.bz_points,
                                  self.bz_curves, self.bz_polygons, pts))
                else:
                    self.add_child(
                        Pipe(((u, v), (1, 1)), self.bz_points, self.bz_curves,
                             self.bz_polygons, pts))

    def dump(self, path):
        with open(path, "w+") as f:
            count = 0
            for s in self:
                if not isinstance(s, SurfaceC2): continue
                count += 1
            f.write(str(count) + "\n")
            for s in self:
                if not isinstance(s, SurfaceC2): continue
                f.write("{1} {2} {0}\n".format(int(isinstance(s, Pipe)),
                                               *s.get_uv()))
                for p in s.iter_pts():
                    f.write("{0} {1} {2}\n".format(*p))
Exemple #10
0
add_plot_verbose(argument_parser)
add_range_list_subparser(argument_parser)


def normal_clamped(mean, stddev):
    d = np.random.normal(0, stddev)
    d = min(3 * stddev, max(-3 * stddev, d))
    return mean + d


if __name__ == "__main__":
    from cutter import Cutter

    args = argument_parser.parse_args()

    cut = Cutter()

    instrument = args.instrument if hasattr(args, 'instrument') else 'unknown'
    # centerOffset (this is the position the object is placed at in ideal
    # cases, it should be dependent on the object geometry)
    # screw: (-10, 0) depending on image size
    if instrument in ['robot', 'drill']:
        cut['CenterOffset'] = (10, 0)
    else:
        cut['CenterOffset'] = args.center_offset

    # maximal displacement of the headPoint in millimeters

    with open(os.path.join(folder, '../data/config.json'), 'r') as fp:
        config = json.load(fp)
Exemple #11
0
        options.inpath = dirname( cutfile)
        cutfile = open( cutfile)

    for c in eutf.readlines( cutfile):
        c = c.strip()
        if not c or c.startswith( '#'): continue
        if assign_params( c): continue
        if not c.replace( '=',''):  #only ===== ; force filename follows
            if cutter:
                cutter.save()
                cutter = None
            #print '======'
            options.infile = None
            continue
        if sum( c.endswith( '.'+ext) for ext in 'flac wav mp3'.split()):
            if cutter:
                cutter.save()
                cutter = None
            print( 'new-infile=', c)
            options.infile = c
            continue
        if not cutter: cutter = Cutter()
        if options.verbose: print( '<', c)
        cutter.readline( c)

    if cutter:
        cutter.save()
        cutter = None

# vim:ts=4:sw=4:expandtab
Exemple #12
0
    required=True,
    help="The full output filename to use for results (json).")

add_plot_verbose(argument_parser)

add_range_list_subparser(argument_parser)

if __main__ == "__name__":

    # set the rng to defined settings
    # from keras_impl import seedsettings
    from predictorkeras import PredictorKeras as PredictorLib

    from cutter import Cutter

    cut = Cutter()

    # width and height of Large and Final images
    cut["Large"] = {"Width": 270, "Height": 270}

    instument = args.instrument if hasattr(args, 'instrument') else 'unknown'
    # centerOffset (this is the position the object is placed at in ideal cases, it should be dependent on the object geometry)
    # screw: (-10, 0) depending on image size
    if instrument in ['robot', 'drill']:
        cut["CenterOffset"] = (10, 0)
    else:
        cut["CenterOffset"] = args.center_offset

    # maximal displacement of the headPoint in millimeters

    with open(folder + '/data/config.json') as fp:
Exemple #13
0
 def addCutter(self, p1: QPoint, p2: QPoint):
     c = Cutter(p1, p2)
     self.cutter = c
     self.__drawCutter(c)