コード例 #1
0
    def DuplicateObjects(self, infolist, offset):
        infolist = list_to_tree2(infolist)

        objects = self.objects
        undo = [self.begin_change_children()]
        selection = []
        added = 0
        try:
            for idx, obj in infolist:
                idx = idx + added
                if type(obj) == ListType:
                    # duplicate in subobj
                    sel, undoinfo = objects[idx].DuplicateObjects(obj, offset)
                    undo.append(undoinfo)
                    selection = selection + prepend_idx(idx, sel)
                else:
                    obj = obj.Duplicate()
                    obj.Translate(offset)
                    sel, undoinfo = self.Insert(obj, idx + 1)
                    undo.append(undoinfo)
                    selection.append(sel)
                    added = added + 1
            undo.append(self.end_change_children())
            return (selection, CreateListUndo(undo))
        except:
            Undo(CreateListUndo(undo))
            raise
コード例 #2
0
ファイル: compound.py プロジェクト: shumik/skencil-c
    def DuplicateObjects(self, infolist, offset):
	infolist = list_to_tree2(infolist)

	objects = self.objects
	undo = [self.begin_change_children()]
	selection = []
	added = 0
	try:
	    for idx, obj in infolist:
		idx = idx + added
		if type(obj) == ListType:
		    # duplicate in subobj
		    sel, undoinfo = objects[idx].DuplicateObjects(obj, offset)
		    undo.append(undoinfo)
		    selection = selection + prepend_idx(idx, sel)
		else:
		    obj = obj.Duplicate()
		    obj.Translate(offset)
		    sel, undoinfo = self.Insert(obj, idx + 1)
		    undo.append(undoinfo)
		    selection.append(sel)
		    added = added + 1
	    undo.append(self.end_change_children())
	    return (selection, CreateListUndo(undo))
	except:
	    Undo(CreateListUndo(undo))
	    raise
コード例 #3
0
 def SelectSubobject(self, p, rect, device, path=None, *rest):
     idx = self.Hit(p, rect, device) - 1
     obj = self.objects[idx]
     if idx % 2 == 0:
         # a control object
         if path:
             path_idx = path[0]
             path = path[1:]
             obj = obj.SelectSubobject(p, rect, device, path)
         elif path == ():
             obj = obj.SelectSubobject(p, rect, device)
         info = selinfo.prepend_idx(idx, obj)
     else:
         # an interpolation object
         if path is None:
             info = self
         else:
             info = selinfo.prepend_idx(idx, obj)
     return info
コード例 #4
0
ファイル: blendgroup.py プロジェクト: shumik/skencil-c
    def SelectSubobject(self, p, rect, device, path = None, *rest):
	idx = self.Hit(p, rect, device) - 1
	obj = self.objects[idx]
	if idx % 2 == 0:
	    # a control object
	    if path:
		path_idx = path[0]
		path = path[1:]
		obj = obj.SelectSubobject(p, rect, device, path)
	    elif path == ():
		obj = obj.SelectSubobject(p, rect, device)
            info = selinfo.prepend_idx(idx, obj)
        else:
            # an interpolation object
            if path is None:
                info = self
            else:
                info = selinfo.prepend_idx(idx, obj)
	return info
コード例 #5
0
ファイル: text.py プロジェクト: shumik/skencil-c
    def SelectSubobject(self, p, rect, device, path = None, *rest):
	idx = self.Hit(p, rect, device) - 1
	obj = self.objects[idx]
	if path:
	    path_idx = path[0]
	    path = path[1:]
	    if path_idx == idx:
		obj = obj.SelectSubobject(p, rect, device, path)
	elif path == ():
	    obj = obj.SelectSubobject(p, rect, device)
	else:
	    return  self
	return selinfo.prepend_idx(idx, obj)
コード例 #6
0
 def SelectSubobject(self, p, rect, device, path=None, *rest):
     idx = self.Hit(p, rect, device) - 1
     obj = self.objects[idx]
     if path:
         path_idx = path[0]
         path = path[1:]
         if path_idx == idx:
             obj = obj.SelectSubobject(p, rect, device, path)
     elif path == ():
         obj = obj.SelectSubobject(p, rect, device)
     else:
         return self
     return selinfo.prepend_idx(idx, obj)
コード例 #7
0
 def SelectSubobject(self, p, rect, device, path=(), *rest):
     if not self.CanSelect():
         return None
     device.StartOutlineMode()
     try:
         objects = self.objects
         for obj_idx in range(len(objects) - 1, -1, -1):
             obj = objects[obj_idx]
             if obj.Hit(p, rect, device):
                 result = obj.SelectSubobject(p, rect, device)
                 return selinfo.prepend_idx(obj_idx, result)
         return None
     finally:
         device.EndOutlineMode()
コード例 #8
0
ファイル: layer.py プロジェクト: htgoebel/uniconvertor
 def SelectSubobject(self, p, rect, device, path=(), *rest):
     if not self.CanSelect():
         return None
     device.StartOutlineMode()
     try:
         objects = self.objects
         for obj_idx in range(len(objects) - 1, -1, -1):
             obj = objects[obj_idx]
             if obj.Hit(p, rect, device):
                 result = obj.SelectSubobject(p, rect, device)
                 return selinfo.prepend_idx(obj_idx, result)
         return None
     finally:
         device.EndOutlineMode()
コード例 #9
0
    def MoveObjectsUp(self, infolist):
        sliced = list_to_tree_sliced(infolist)
        sliced.reverse()
        undo = [self.begin_change_children()]
        selection = []
        permutation = range(len(self.objects))
        objects = self.objects
        max = len(objects)
        try:
            for start, end in sliced:
                if type(end) == IntType:
                    if end < max:
                        temp = permutation[start:end]
                        del permutation[start:end]
                        permutation[start + 1:start + 1] = temp
                        selection = selection + select_range(
                            start + 1, objects[start:end])
                    else:
                        selection = selection + select_range(
                            start, objects[start:end])

                elif type(end) == ListType:
                    sel, undo_info = objects[start].MoveObjectsUp(end)
                    if undo_info is not NullUndo:
                        undo.append(undo_info)
                    selection = selection + prepend_idx(start, sel)
                else:
                    if start < max - 1:
                        del permutation[start]
                        permutation.insert(start + 1, start)
                        selection.append(build_info(start + 1, objects[start]))
                    else:
                        selection.append(build_info(start, objects[start]))

            undo_info = self.permute_objects(permutation)
            if undo_info is not NullUndo:
                undo.append(undo_info)
            undo.append(self.end_change_children())
            if len(undo) <= 2:
                undo = NullUndo
                selection = infolist
            else:
                undo = CreateListUndo(undo)
            return (selection, undo)
        except:
            Undo(CreateListUndo(undo))
            raise
コード例 #10
0
ファイル: compound.py プロジェクト: shumik/skencil-c
    def MoveObjectsUp(self, infolist):
	sliced = list_to_tree_sliced(infolist)
	sliced.reverse()
	undo = [self.begin_change_children()]
	selection = []
	permutation = range(len(self.objects))
	objects = self.objects
	max = len(objects)
	try:
	    for start, end in sliced:
		if type(end) == IntType:
		    if end < max:
			temp = permutation[start:end]
			del permutation[start:end]
			permutation[start + 1:start + 1] = temp
			selection = selection + select_range(start + 1,
							   objects[start:end])
		    else:
			selection = selection + select_range(start,
							   objects[start:end])

		elif type(end) == ListType:
		    sel, undo_info = objects[start].MoveObjectsUp(end)
		    if undo_info is not NullUndo:
			undo.append(undo_info)
		    selection = selection + prepend_idx(start, sel)
		else:
		    if start < max - 1:
			del permutation[start]
			permutation.insert(start + 1, start)
			selection.append(build_info(start + 1, objects[start]))
		    else:
			selection.append(build_info(start, objects[start]))

	    undo_info = self.permute_objects(permutation)
	    if undo_info is not NullUndo:
		undo.append(undo_info)
	    undo.append(self.end_change_children())
	    if len(undo) <= 2:
		undo = NullUndo
		selection = infolist
	    else:
		undo = CreateListUndo(undo)
	    return (selection, undo)
	except:
	    Undo(CreateListUndo(undo))
	    raise
コード例 #11
0
 def SelectSubobject(self, p, rect, device, path=None, *rest):
     test = rect.overlaps
     if path is None:
         return self
     if path:
         path_idx = path[0]
         path = path[1:]
     else:
         path_idx = -1
         path = None
     objects = self.objects
     for obj_idx in range(len(objects) - 1, -1, -1):
         obj = objects[obj_idx]
         if test(obj.bounding_rect) and obj.Hit(p, rect, device):
             if obj_idx == path_idx:
                 result = obj.SelectSubobject(p, rect, device, path)
             else:
                 result = obj.SelectSubobject(p, rect, device)
             return prepend_idx(obj_idx, result)
     return None
コード例 #12
0
ファイル: compound.py プロジェクト: shumik/skencil-c
    def SelectSubobject(self, p, rect, device, path = None, *rest):
	test = rect.overlaps
	if path is None:
	    return self
	if path:
	    path_idx = path[0]
	    path = path[1:]
	else:
	    path_idx = -1
	    path = None
	objects = self.objects
	for obj_idx in range(len(objects) - 1, -1, -1):
	    obj = objects[obj_idx]
	    if test(obj.bounding_rect) and obj.Hit(p, rect, device):
		if obj_idx == path_idx:
		    result = obj.SelectSubobject(p, rect, device, path)
		else:
		    result = obj.SelectSubobject(p, rect, device)
		return prepend_idx(obj_idx, result)
	return None
コード例 #13
0
ファイル: layer.py プロジェクト: htgoebel/uniconvertor
 def SelectionInfo(self, child, cache=None):
     info = selinfo.build_info(_sketch.IdIndex(self.objects, child), child)
     return selinfo.prepend_idx(self.document.LayerIndex(self), info)
コード例 #14
0
 def SelectionInfo(self, child, cache=None):
     info = selinfo.build_info(_sketch.IdIndex(self.objects, child), child)
     return selinfo.prepend_idx(self.document.LayerIndex(self), info)
コード例 #15
0
    def move_objects_to_top(self, infolist, to_bottom=0):
        # Implement the public methods MoveToTop (if to_bottom is false)
        # and MoveToBottom (if to_bottom is true).
        sliced = list_to_tree_sliced(infolist)
        sliced.reverse()

        undo = [self.begin_change_children()]
        selection = []
        idxs = []
        permutation = range(len(self.objects))
        try:
            for start, end in sliced:
                if type(end) == IntType:
                    # a contiguous range of self's children (start:end)
                    idxs[:0] = permutation[start:end]
                    del permutation[start:end]
                elif type(end) == ListType:
                    # children of self.objects[start]
                    child = self.objects[start]
                    sel, undo_info = child.move_objects_to_top(end, to_bottom)
                    if undo_info is not NullUndo:
                        undo.append(undo_info)
                    selection = selection + prepend_idx(start, sel)
                else:
                    # a single object (self.object[start])
                    idxs.insert(0, start)
                    del permutation[start]

            if idxs:
                # direct children of self are involved: apply the
                # permutation
                if to_bottom:
                    permutation = idxs + permutation
                else:
                    permutation = permutation + idxs
                undo_info = self.permute_objects(permutation)
                if undo_info is not NullUndo:
                    undo.append(undo_info)
            # finished:
            undo.append(self.end_change_children())
            if len(undo) <= 2:
                # We haven't really done anything (undo has length 2),
                # so we just pass the selection info back unchanged
                selection = infolist
                undo = NullUndo
            else:
                # We have done something, so figure out the new
                # selection info
                undo = CreateListUndo(undo)

                if to_bottom:
                    selection = selection \
                       + select_range(0, self.objects[:len(idxs)])
                else:
                    min = len(self.objects) - len(idxs)
                    selection = selection \
                       + select_range(min, self.objects[min:])
            return (selection, undo)
        except:
            # Ooops, something's gone wrong. Undo everything we've done
            # so far... (hmm, this currently fails to undo everything if
            # undo.append(undo_info) fails... (the undo_info involved
            # would be lost))
            Undo(CreateListUndo(undo))
            raise
コード例 #16
0
 def Insert(self, obj, at):
     # Insert OBJ into the object hierarchy at the position described
     # by AT. AT should be either an integer or a tuple of integers.
     # OBJ can be a graphics object of a list of such objects.
     #
     # If AT is a tuple of 2 or more ints, self's child at AT[0] has
     # to be a compound object and its Insert method is called with
     # OBJ and AT[1:] as arguments.
     #
     # If AT is an int or a singleton of one int, insert OBJ at that
     # position in self's children. If OBJ is a graphics object, this
     # works just like a list objects insert method (insert(AT,
     # OBJ)). If its a list of graphics objects this method
     # effectively assigns that list to the slice AT:AT.
     #
     # As a side effect, this method calls the following methods of
     # the inserted objects:
     #
     #	    obj.SetDocument(self.document)
     #	    obj.SetParent(self)
     #	    obj.Connect()
     #
     # Return a tuple (SELINFO, UNDO), where SELINFO is selection
     # info for the inserted objects at their new positions, and UNDO
     # is the appropriate undo info.
     #
     # If self is modified directly, issue a CHANGED message.
     undo_info = None
     try:
         if type(at) == TupleType and at:
             if len(at) == 1:
                 at = at[0]
             else:
                 child = at[0]
                 at = at[1:]
                 sel_info, undo_info = self.objects[child].Insert(obj, at)
                 sel_info = prepend_idx(child, sel_info)
                 return (sel_info, undo_info)
         if type(at) != IntType or at > len(self.objects):
             at = len(self.objects)
         if type(obj) == InstanceType:
             self.objects.insert(at, obj)
             obj.SetDocument(self.document)
             obj.SetParent(self)
             obj.Connect()
             sel_info = build_info(at, obj)
             undo_info = (self.Remove, obj, at)
         else:
             self.objects[at:at] = obj
             for o in obj:
                 # XXX: should we have undo info for these:
                 o.SetDocument(self.document)
                 o.SetParent(self)
                 o.Connect()
             sel_info = select_range(at, obj)
             undo_info = (self.RemoveSlice, at, at + len(obj))
         self._changed()
         return (sel_info, undo_info)
     except:
         if undo_info is not None:
             Undo(undo_info)
         raise
コード例 #17
0
ファイル: compound.py プロジェクト: shumik/skencil-c
    def move_objects_to_top(self, infolist, to_bottom = 0):
	# Implement the public methods MoveToTop (if to_bottom is false)
	# and MoveToBottom (if to_bottom is true).
	sliced = list_to_tree_sliced(infolist)
	sliced.reverse()

	undo = [self.begin_change_children()]
	selection = []
	idxs = []
	permutation = range(len(self.objects))
	try:
	    for start, end in sliced:
		if type(end) == IntType:
		    # a contiguous range of self's children (start:end)
		    idxs[:0] = permutation[start:end]
		    del permutation[start:end]
		elif type(end) == ListType:
		    # children of self.objects[start]
		    child = self.objects[start]
		    sel, undo_info = child.move_objects_to_top(end, to_bottom)
		    if undo_info is not NullUndo:
			undo.append(undo_info)
		    selection = selection + prepend_idx(start, sel)
		else:
		    # a single object (self.object[start])
		    idxs.insert(0, start)
		    del permutation[start]

	    if idxs:
		# direct children of self are involved: apply the
		# permutation
		if to_bottom:
		    permutation = idxs + permutation
		else:
		    permutation = permutation + idxs
		undo_info = self.permute_objects(permutation)
		if undo_info is not NullUndo:
		    undo.append(undo_info)
	    # finished:
	    undo.append(self.end_change_children())
	    if len(undo) <= 2:
		# We haven't really done anything (undo has length 2),
		# so we just pass the selection info back unchanged
		selection = infolist
		undo = NullUndo
	    else:
		# We have done something, so figure out the new
		# selection info
		undo = CreateListUndo(undo)

		if to_bottom:
		    selection = selection \
				+ select_range(0, self.objects[:len(idxs)])
		else:
		    min = len(self.objects) - len(idxs)
		    selection = selection \
				+ select_range(min, self.objects[min:])
	    return (selection, undo)
	except:
	    # Ooops, something's gone wrong. Undo everything we've done
	    # so far... (hmm, this currently fails to undo everything if
	    # undo.append(undo_info) fails... (the undo_info involved
	    # would be lost))
	    Undo(CreateListUndo(undo))
	    raise
コード例 #18
0
ファイル: compound.py プロジェクト: shumik/skencil-c
    def Insert(self, obj, at):
	# Insert OBJ into the object hierarchy at the position described
	# by AT. AT should be either an integer or a tuple of integers.
	# OBJ can be a graphics object of a list of such objects.
	#
	# If AT is a tuple of 2 or more ints, self's child at AT[0] has
	# to be a compound object and its Insert method is called with
	# OBJ and AT[1:] as arguments.
	#
	# If AT is an int or a singleton of one int, insert OBJ at that
	# position in self's children. If OBJ is a graphics object, this
	# works just like a list objects insert method (insert(AT,
	# OBJ)). If its a list of graphics objects this method
	# effectively assigns that list to the slice AT:AT.
	#
	# As a side effect, this method calls the following methods of
	# the inserted objects:
	#
	#	    obj.SetDocument(self.document)
	#	    obj.SetParent(self)
	#	    obj.Connect()
	#
	# Return a tuple (SELINFO, UNDO), where SELINFO is selection
	# info for the inserted objects at their new positions, and UNDO
	# is the appropriate undo info.
	#
	# If self is modified directly, issue a CHANGED message.
	undo_info = None
	try:
	    if type(at) == TupleType and at:
		if len(at) == 1:
		    at = at[0]
		else:
		    child = at[0]
		    at = at[1:]
		    sel_info, undo_info = self.objects[child].Insert(obj, at)
		    sel_info = prepend_idx(child, sel_info)
		    return (sel_info, undo_info)
	    if type(at) != IntType or at > len(self.objects):
		at = len(self.objects)
	    if type(obj) == InstanceType:
		self.objects.insert(at, obj)
		obj.SetDocument(self.document)
		obj.SetParent(self)
		obj.Connect()
		sel_info = build_info(at, obj)
		undo_info = (self.Remove, obj, at)
	    else:
		self.objects[at:at] = obj
		for o in obj:
		    # XXX: should we have undo info for these:
		    o.SetDocument(self.document)
		    o.SetParent(self)
		    o.Connect()
		sel_info = select_range(at, obj)
		undo_info = (self.RemoveSlice, at, at + len(obj))
	    self._changed()
	    return (sel_info, undo_info)
	except:
	    if undo_info is not None:
		Undo(undo_info)
	    raise