Esempio n. 1
0
 def execute(self, undo, *args):
     util.test_boolean(undo)
     _alen = len(args)
     if _alen == 0:
         raise ValueError, "No arguments to execute()"
     _f = self.getObject()
     _op = args[0]
     if _op == 'radius_changed':
         if len(args) < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _r = args[1]
         if not isinstance(_r, float):
             raise TypeError, "Unexpected type for radius: " + `type(_r)`
         _sdata = _f.getRadius()
         self.ignore(_op)
         try:
             if undo:
                 _f.startUndo()
                 try:
                     _f.setRadius(_r)
                 finally:
                     _f.endUndo()
             else:
                 _f.startRedo()
                 try:
                     _f.setRadius(_r)
                 finally:
                     _f.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     else:
         super(FilletLog, self).execute(undo, *args)
Esempio n. 2
0
 def execute(self, undo, *args):
     util.test_boolean(undo)
     _alen = len(args)
     if _alen == 0:
         raise ValueError, "No arguments to execute()"
     _c = self.getObject()
     _op = args[0]
     if _op == 'length_changed':
         if len(args) < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _l = args[1]
         if not isinstance(_l, float):
             raise TypeError, "Unexpected type for length: " + `type(_l)`
         _sdata = _c.getLength()
         self.ignore(_op)
         try:
             if undo:
                 _c.startUndo()
                 try:
                     _c.setLength(_l)
                 finally:
                     _c.endUndo()
             else:
                 _c.startRedo()
                 try:
                     _c.setLength(_l)
                 finally:
                     _c.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     else:
         super(ChamferLog, self).execute(undo, *args)
 def __visibilityChanged(self, obj, *args):
     _alen = len(args)
     if _alen < 1:
         raise ValueError, "Invalid argument count: %d" % _alen
     _vis = args[0]
     util.test_boolean(_vis)
     self.saveUndoData('visibilty_changed', _vis)
 def __lockChanged(self, obj, *args):
     _alen = len(args)
     if _alen < 1:
         raise ValueError, "Invalid argument count: %d" % _alen
     _lock = args[0]
     util.test_boolean(_lock)
     self.saveUndoData('lock_changed', _lock)
Esempio n. 5
0
    def __init__(self, objs, external=True):
        """Initialize a Path.

p = Path(objs[, external])

The required argument 'objs' is a list of objects defining
the path. The valid objects are circles, arcs, segments,
chamfers and fillets.

The optional argument 'external' is by default True, meaning
that this Path is an outer boundary. If the argument is False,
then the Path represents an internal non-hatched area inside
another Path.
        """
        if not isinstance(objs, list):
            raise TypeError, "Unexpected list type: " + ` type(objs) `
        if not len(objs):
            raise ValueError, "Invalid empty object list"
        for _obj in objs:
            _valid = False
            if (isinstance(_obj, segment.Segment) or isinstance(_obj, arc.Arc)
                    or isinstance(_obj, circle.Circle)
                    or isinstance(_obj, segjoint.Chamfer)
                    or isinstance(_obj, segjoint.Fillet)):
                _valid = True
            if not _valid:
                raise TypeError, "Invalid object type in list: " + ` type(
                    _obj) `
        _circular = False
        if len(objs) == 1:
            _circular = True
            _obj = objs[0]
            _valid = False
            if isinstance(_obj, arc.Arc):
                _sa = _obj.getStartAngle()
                _ea = _obj.getEndAngle()
                if abs(_sa - _ea) < 1e-10:
                    _valid = True
                if not _valid:
                    raise ValueError, "Invalid single Arc path: " + str(_obj)
            elif isinstance(_obj, circle.Circle):
                pass
            else:
                raise TypeError, "Invalid single entity path: " + str(_obj)
        else:
            _valid = True
            for _obj in objs:
                if isinstance(_obj, circle.Circle):
                    if not isinstance(_obj, arc.Arc):
                        _valid = False
                        break
            if not _valid:
                raise TypeError, "Circle found in multi-object path"
            _valid = True  # _validate_path(objlist)
            if not _valid:
                raise ValueError, "Objlist objects do not make a closed path."
        util.test_boolean(external)
        self.__objs = objs[:]
        self.__circular = _circular
        self.__external = external
 def execute(self, undo, *args):
     # print "EntityLog::execute() ..."
     # print args
     util.test_boolean(undo)
     _alen = len(args)
     if len(args) == 0:
         raise ValueError, "No arguments to execute()"
     _obj = self.__obj
     _op = args[0]
     if _op == 'visibility_changed':
         if len(args) < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _sdata = _obj.getVisibility()
         self.ignore(_op)
         try:
             _vis = args[1]
             if undo:
                 _obj.startUndo()
                 try:
                     _obj.setVisibility(_vis)
                 finally:
                     _obj.endUndo()
             else:
                 _obj.startRedo()
                 try:
                     _obj.setVisibility(_vis)
                 finally:
                     _obj.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     elif _op == 'lock_changed':
         if len(args) < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _sdata = _obj.isLocked()
         self.ignore(_op)
         try:
             _lock = args[1]
             if undo:
                 _obj.startUndo()
                 try:
                     _obj.setLock(_lock)
                 finally:
                     _obj.endUndo()
             else:
                 _obj.startRedo()
                 try:
                     _obj.setLock(_lock)
                 finally:
                     _obj.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     else:
         raise ValueError, "Unexpected operation: %s" % _op
    def setLock(self, lock):
        """Set the locked status on an entity.

setLock(lock)

Argument 'lock' can be True or False.
        """
        util.test_boolean(lock)
        _l = self.__locked
        if _l is not lock:
            self.__locked = lock
            self.sendMessage('lock_changed', _l)
            self.modified()
 def execute(self, undo, *args):
     util.test_boolean(undo)
     _alen = len(args)
     if len(args) == 0:
         raise ValueError, "No arguments to execute()"
     _c = self.getObject()
     _p1, _p2 = _c.getKeypoints()
     _op = args[0]
     if _op == 'keypoint_changed':
         if _alen < 3:
             raise ValueError, "Invalid argument count: %d" % _alen
         _oid = args[1]
         _nid = args[2]
         _parent = _c.getParent()
         if _parent is None:
             raise ValueError, "CLine has no parent - cannot undo"
         self.ignore(_op)
         try:
             if undo:
                 _pt = _parent.getObject(_oid)
                 if _pt is None or not isinstance(_pt, point.Point):
                     raise ValueError, "Old keypoint missing: id=%d" % _oid
                 _c.startUndo()
                 try:
                     if _p1.getID() == _nid:
                         _c.setP1(_pt)
                     elif _p2.getID() == _nid:
                         _c.setP2(_pt)
                     else:
                         raise ValueError, "Unexpected keypoint ID: %d" % _nid
                 finally:
                     _c.endUndo()
             else:
                 _pt = _parent.getObject(_nid)
                 if _pt is None or not isinstance(_pt, point.Point):
                     raise ValueError, "New keypoint missing: id=%d" % _nid
                 _c.startRedo()
                 try:
                     if _p1.getID() == _oid:
                         _c.setP1(_pt)
                     elif _p2.getID() == _oid:
                         _c.setP2(_pt)
                     else:
                         raise ValueError, "Unexpected keypoint ID: %d" % _oid
                 finally:
                     _c.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _oid, _nid)
     else:
         super(CLineLog, self).execute(undo, *args)
    def setVisibility(self, vis):
        """Set the visibility of the entity.

setVisibility(vis)

Argument 'vis' must be either True or False.
        """
        util.test_boolean(vis)
        _v = self.__visible
        if _v is not vis:
            self.startChange('visibility_changed')
            self.__visible = vis
            self.endChange('visibility_changed')
            self.sendMessage('visibility_changed', _v)
            self.modified()
    def inRegion(self, xmin, ymin, xmax, ymax, fully=False):
        """Return whether or not a CLine passes through a region.

isRegion(xmin, ymin, xmax, ymax)

The four arguments define the boundary of an area, and the
function returns True if the CLine passes within the area.
Otherwise, the function returns False.
        """
        _xmin = util.get_float(xmin)
        _ymin = util.get_float(ymin)
        _xmax = util.get_float(xmax)
        if _xmax < _xmin:
            raise ValueError, "Illegal values: xmax < xmin"
        _ymax = util.get_float(ymax)
        if _ymax < _ymin:
            raise ValueError, "Illegal values: ymax < ymin"
        util.test_boolean(fully)
        if fully:
            return False
        _x1, _y1 = self.__p1.getCoords()
        _x2, _y2 = self.__p2.getCoords()
        _xdiff = _x2 - _x1
        _ydiff = _y2 - _y1
        _val = False
        if _xmin < _x1 < _xmax and _ymin < _y1 < _ymax:
            _val = True
        elif _xmin < _x2 < _xmax and _ymin < _y2 < _ymax:
            _val = True
        elif abs(_xdiff) < 1e-10:  # vertical line
            if _xmin < _x1 < _xmax:
                _val = True
        elif abs(_ydiff) < 1e-10:  # horizontal line
            if _ymin < _y1 < _ymax:
                _val = True
        else:
            _slope = _ydiff / _xdiff
            _yint = _y1 - _slope * _x1
            if _ymin < (_slope * _xmin + _yint) < _ymax:  # hits left side
                _val = True
            elif _ymin < (_slope * _xmax + _yint) < _ymax:  # hits right side
                _val = True
            else:  # hits bottom - no need to check top ...
                _xymin = (_ymin - _yint) / _slope
                if _xmin < _xymin < _xmax:
                    _val = True
        return _val
    def inRegion(self, xmin, ymin, xmax, ymax, fully=False):
        """Return whether or not a Leader exists within a region.

isRegion(xmin, ymin, xmax, ymax[, fully])

The four arguments define the boundary of an area, and the
method returns True if the Leader lies within that area. If
the optional argument fully is used and is True, then all
the Leader points must lie within the boundary. Otherwise,
the method returns False.
        """
        _xmin = util.get_float(xmin)
        _ymin = util.get_float(ymin)
        _xmax = util.get_float(xmax)
        if _xmax < _xmin:
            raise ValueError, "Illegal values: xmax < xmin"
        _ymax = util.get_float(ymax)
        if _ymax < _ymin:
            raise ValueError, "Illegal values: ymax < ymin"
        util.test_boolean(fully)
        _x1, _y1 = self.__p1.getCoords()
        _x2, _y2 = self.__p2.getCoords()
        _x3, _y3 = self.__p3.getCoords()
        _pxmin = min(_x1, _x2, _x3)
        _pymin = min(_y1, _y2, _y3)
        _pxmax = max(_x1, _x2, _x3)
        _pymax = max(_y1, _y2, _y3)
        if ((_pxmax < _xmin) or
            (_pymax < _ymin) or
            (_pxmin > _xmax) or
            (_pymin > _ymax)):
            return False
        if fully:
            if ((_pxmin > _xmin) and
                (_pymin > _ymin) and
                (_pxmax < _xmax) and
                (_pymax < _ymax)):
                return True
            return False
        if util.in_region(_x1, _y1, _x2, _y2, _xmin, _ymin, _xmax, _ymax):
            return True
        return util.in_region(_x2, _y2, _x3, _y3, _xmin, _ymin, _xmax, _ymax)
    def inRegion(self, xmin, ymin, xmax, ymax, fully=False):
        """Return whether or not a Polyline exists within a region.

isRegion(xmin, ymin, xmax, ymax[, fully])

The four arguments define the boundary of an area, and the
method returns True if the Polyline lies within that area. If
the optional argument 'fully' is used and is True, then both
endpoints of the Polyline must lie within the boundary.
Otherwise, the method returns False.
        """
        _xmin = util.get_float(xmin)
        _ymin = util.get_float(ymin)
        _xmax = util.get_float(xmax)
        if _xmax < _xmin:
            raise ValueError, "Illegal values: xmax < xmin"
        _ymax = util.get_float(ymax)
        if _ymax < _ymin:
            raise ValueError, "Illegal values: ymax < ymin"
        util.test_boolean(fully)
        _pxmin, _pymin, _pxmax, _pymax = self.getBounds()
        if ((_pxmax < _xmin) or
            (_pxmin > _xmax) or
            (_pymax < _ymin) or
            (_pymin > _ymax)):
            return False
        if fully:
            if ((_pxmin > _xmin) and
                (_pymin > _ymin) and
                (_pxmax < _xmax) and
                (_pymax < _ymax)):
                return True
            return False
        _pts = self.__pts
        for _i in range(len(_pts) - 1):
            _x1, _y1 = _pts[_i].getCoords()
            _x2, _y2 = _pts[_i + 1].getCoords()
            if util.in_region(_x1, _y1, _x2, _y2, _xmin, _ymin, _xmax, _ymax):
                return True
        return False
Esempio n. 13
0
    def inRegion(self, xmin, ymin, xmax, ymax, fully=False):
        """Return whether or not an HCLine passes through a region.

inRegion(xmin, ymin, xmax, ymax)

The first four arguments define the boundary. The method
will return True if the HCLine falls between ymin and ymax.
Otherwise the function will return False.
        """
        _xmin = util.get_float(xmin)
        _ymin = util.get_float(ymin)
        _xmax = util.get_float(xmax)
        if _xmax < _xmin:
            raise ValueError, "Illegal values: xmax < xmin"
        _ymax = util.get_float(ymax)
        if _ymax < _ymin:
            raise ValueError, "Illegal values: ymax < ymin"
        util.test_boolean(fully)
        if fully:
            return False
        _y = self.__keypoint.y
        return not (_y < _ymin or _y > _ymax)
    def inRegion(self, xmin, ymin, xmax, ymax, fully=False):
        """Return whether or not an VCLine passes through a region.

inRegion(xmin, ymin, xmax, ymax)

The first four arguments define the boundary. The method
will return True if the VCLine falls between xmin and xmax.
Otherwise the function will return False.
        """
        _xmin = util.get_float(xmin)
        _ymin = util.get_float(ymin)
        _xmax = util.get_float(xmax)
        if _xmax < _xmin:
            raise ValueError, "Illegal values: xmax < xmin"
        _ymax = util.get_float(ymax)
        if _ymax < _ymin:
            raise ValueError, "Illegal values: ymax < ymin"
        util.test_boolean(fully)
        if fully:
            return False
        _x = self.__keypoint.x
        return not (_x < _xmin or _x > _xmax)
Esempio n. 15
0
    def inRegion(self, xmin, ymin, xmax, ymax, fully=False):
        """Return whether or not a fillet exists with a region.

isRegion(xmin, ymin, xmax, ymax)

The four arguments define the boundary of an area, and the
function returns True if the joint lies within that area.
Otherwise, the function returns False.
        """
        _xmin = util.get_float(xmin)
        _ymin = util.get_float(ymin)
        _xmax = util.get_float(xmax)
        if _xmax < _xmin:
            raise ValueError, "Illegal values: xmax < xmin"
        _ymax = util.get_float(ymax)
        if _ymax < _ymin:
            raise ValueError, "Illegal values: ymax < ymin"
        util.test_boolean(fully)
        _mp1, _mp2 = self.getMovingPoints()
        _mx1, _my1 = _mp1.getCoords()
        _mx2, _my2 = _mp2.getCoords()
        _r = self.__radius
        _xc, _yc = self.__center
        _a1, _a2 = self.getAngles()
        _xl = [_mx1, _mx2, _xc]
        _yl = [_my1, _my2, _yc]
        if fully:
            if ((min(_xl) > _xmin) and
                (min(_yl) > _ymin) and
                (max(_xl) < _xmax) and
                (max(_yl) < _ymax)):
                return True
            return False
        #
        # fixme - need to use the arc and endpoints and not
        # a line connecting the endpoints ...
        #
        return util.in_region(_mx1, _my1, _mx2, _my2,
                              _xmin, _ymin, _xmax, _ymax)
Esempio n. 16
0
    def inRegion(self, xmin, ymin, xmax, ymax, fully=True):
        """Returns True if the Point is within the bounding values.

inRegion(xmin, ymin, xmax, ymax)

The four arguments define the boundary of an area, and the
function returns True if the Point lies within that area.
Otherwise, the function returns False.
        """
        _xmin = util.get_float(xmin)
        _ymin = util.get_float(ymin)
        _xmax = util.get_float(xmax)
        if _xmax < _xmin:
            raise ValueError, "Illegal values: xmax < xmin"
        _ymax = util.get_float(ymax)
        if _ymax < _ymin:
            raise ValueError, "Illegal values: ymax < ymin"
        util.test_boolean(fully)
        _x = self.__x
        _y = self.__y
        return not ((_x < _xmin) or (_x > _xmax) or (_y < _ymin) or
                    (_y > _ymax))
Esempio n. 17
0
    def inRegion(self, xmin, ymin, xmax, ymax, fully=False):
        """Return whether or not a segjoint exists with a region.

isRegion(xmin, ymin, xmax, ymax)

The four arguments define the boundary of an area, and the
function returns True if the joint lies within that area.
Otherwise, the function returns False.
        """
        _xmin = util.get_float(xmin)
        _ymin = util.get_float(ymin)
        _xmax = util.get_float(xmax)
        if _xmax < _xmin:
            raise ValueError, "Illegal values: xmax < xmin"
        _ymax = util.get_float(ymax)
        if _ymax < _ymin:
            raise ValueError, "Illegal values: ymax < ymin"
        util.test_boolean(fully)
        _mp1, _mp2 = self.getMovingPoints()
        _mx1, _my1 = _mp1.getCoords()
        _mx2, _my2 = _mp2.getCoords()
        _fxmin = min(_mx1, _mx2)
        _fymin = min(_my1, _my2)
        _fxmax = max(_mx1, _mx2)
        _fymax = max(_my1, _my2)
        if ((_fxmax < _xmin) or
            (_fymax < _ymin) or
            (_fxmin > _xmax) or
            (_fymin > _ymax)):
            return False
        if fully:
            if ((_fxmin > _xmin) and
                (_fymin > _ymin) and
                (_fxmax < _xmax) and
                (_fymax < _ymax)):
                return True
            return False
        return util.in_region(_mx1, _my1, _mx2, _my2,
                              _xmin, _ymin, _xmax, _ymax)
Esempio n. 18
0
 def execute(self, undo, *args):
     util.test_boolean(undo)
     _alen = len(args)
     if _alen == 0:
         raise ValueError, "No arguments to execute()"
     _h = self.getObject()
     _p = _h.getLocation()
     _op = args[0]
     if _op == "keypoint_changed":
         if _alen < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _oid = args[1]
         _parent = _h.getParent()
         if _parent is None:
             raise ValueError, "HCLine has no parent - cannot undo"
         _pt = _parent.getObject(_oid)
         if _pt is None or not isinstance(_pt, point.Point):
             raise ValueError, "Keypoint missing: id=%d" % _oid
         _sdata = _p.getID()
         self.ignore(_op)
         try:
             if undo:
                 _h.startUndo()
                 try:
                     _h.setLocation(_pt)
                 finally:
                     _h.endUndo()
             else:
                 _h.startRedo()
                 try:
                     _h.setLocation(_pt)
                 finally:
                     _h.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     else:
         super(HCLineLog, self).execute(undo, *args)
 def execute(self, undo, *args):
     util.test_boolean(undo)
     _alen = len(args)
     if _alen == 0:
         raise ValueError, "No arguments to execute()"
     _v = self.getObject()
     _p = _v.getLocation()
     _op = args[0]
     if _op == 'keypoint_changed':
         if _alen < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _oid = args[1]
         _parent = _v.getParent()
         if _parent is None:
             raise ValueError, "VCLine has no parent - cannot undo"
         _pt = _parent.getObject(_oid)
         if _pt is None or not isinstance(_pt, point.Point):
             raise ValueError, "Keypoint missing: id=%d" % _oid
         _sdata = _p.getID()
         self.ignore(_op)
         try:
             if undo:
                 _v.startUndo()
                 try:
                     _v.setLocation(_pt)
                 finally:
                     _v.endUndo()
             else:
                 _v.startRedo()
                 try:
                     _v.setLocation(_pt)
                 finally:
                     _v.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     else:
         super(VCLineLog, self).execute(undo, *args)
    def inRegion(self, xmin, ymin, xmax, ymax, fully=True):
        """Returns True if the Point is within the bounding values.

inRegion(xmin, ymin, xmax, ymax)

The four arguments define the boundary of an area, and the
function returns True if the Point lies within that area.
Otherwise, the function returns False.
        """
        _xmin = util.get_float(xmin)
        _ymin = util.get_float(ymin)
        _xmax = util.get_float(xmax)
        if _xmax < _xmin:
            raise ValueError, "Illegal values: xmax < xmin"
        _ymax = util.get_float(ymax)
        if _ymax < _ymin:
            raise ValueError, "Illegal values: ymax < ymin"
        util.test_boolean(fully)
        _x = self.__x
        _y = self.__y
        return not ((_x < _xmin) or
                    (_x > _xmax) or
                    (_y < _ymin) or
                    (_y > _ymax))
 def execute(self, undo, *args):
     util.test_boolean(undo)
     _alen = len(args)
     if _alen == 0:
         raise ValueError, "No arguments to execute()"
     _p = self.getObject()
     _op = args[0]
     if _op == 'moved':
         if _alen < 3:
             raise ValueError, "Invalid argument count: %d" % _alen
         _x = args[1]
         if not isinstance(_x, float):
             raise TypeError, "Unexpected type for 'x': " + `type(_x)`
         _y = args[2]
         if not isinstance(_y, float):
             raise TypeError, "Unexpected type for 'y': " + `type(_y)`
         _px, _py = _p.getCoords()
         self.ignore(_op)
         try:
             if undo:
                 _p.startUndo()
                 try:
                     _p.setCoords(_x, _y)
                 finally:
                     _p.endUndo()
             else:
                 _p.startRedo()
                 try:
                     _p.setCoords(_x, _y)
                 finally:
                     _p.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _px, _py)
     else:
         super(PointLog, self).execute(undo, *args)
Esempio n. 22
0
 def execute(self, undo, *args):
     util.test_boolean(undo)
     _alen = len(args)
     if _alen == 0:
         raise ValueError, "No arguments to execute()"
     _p = self.getObject()
     _op = args[0]
     if _op == 'moved':
         if _alen < 3:
             raise ValueError, "Invalid argument count: %d" % _alen
         _x = args[1]
         if not isinstance(_x, float):
             raise TypeError, "Unexpected type for 'x': " + ` type(_x) `
         _y = args[2]
         if not isinstance(_y, float):
             raise TypeError, "Unexpected type for 'y': " + ` type(_y) `
         _px, _py = _p.getCoords()
         self.ignore(_op)
         try:
             if undo:
                 _p.startUndo()
                 try:
                     _p.setCoords(_x, _y)
                 finally:
                     _p.endUndo()
             else:
                 _p.startRedo()
                 try:
                     _p.setCoords(_x, _y)
                 finally:
                     _p.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _px, _py)
     else:
         super(PointLog, self).execute(undo, *args)
Esempio n. 23
0
    def inRegion(self, xmin, ymin, xmax, ymax, fully=False):
        """Return whether or not a Polyline exists within a region.

isRegion(xmin, ymin, xmax, ymax[, fully])

The four arguments define the boundary of an area, and the
method returns True if the Polyline lies within that area. If
the optional argument 'fully' is used and is True, then both
endpoints of the Polyline must lie within the boundary.
Otherwise, the method returns False.
        """
        _xmin = util.get_float(xmin)
        _ymin = util.get_float(ymin)
        _xmax = util.get_float(xmax)
        if _xmax < _xmin:
            raise ValueError, "Illegal values: xmax < xmin"
        _ymax = util.get_float(ymax)
        if _ymax < _ymin:
            raise ValueError, "Illegal values: ymax < ymin"
        util.test_boolean(fully)
        _pxmin, _pymin, _pxmax, _pymax = self.getBounds()
        if ((_pxmax < _xmin) or (_pxmin > _xmax) or (_pymax < _ymin)
                or (_pymin > _ymax)):
            return False
        if fully:
            if ((_pxmin > _xmin) and (_pymin > _ymin) and (_pxmax < _xmax)
                    and (_pymax < _ymax)):
                return True
            return False
        _pts = self.__pts
        for _i in range(len(_pts) - 1):
            _x1, _y1 = _pts[_i].getCoords()
            _x2, _y2 = _pts[_i + 1].getCoords()
            if util.in_region(_x1, _y1, _x2, _y2, _xmin, _ymin, _xmax, _ymax):
                return True
        return False
 def saveData(self, undo, op, *args):
     util.test_boolean(undo)
     if undo:
         self.saveRedoData(op, *args)
     else:
         self.saveUndoData(op, *args)
Esempio n. 25
0
 def execute(self, undo, *args):
     util.test_boolean(undo)
     _alen = len(args)
     if len(args) == 0:
         raise ValueError, "No arguments to execute()"
     _obj = self.getObject()
     _op = args[0]
     _image = None
     _layer = _obj.getParent()
     if _layer is not None:
         _image = _layer.getParent()
     if _op == 'style_changed':
         if _image is None:
             raise RuntimeError, "Object not stored in an Image"
         if _alen < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _style = None
         _sv, _olt, _oc, _ot = args[1]
         _name, _ltdata, _col, _th = _sv
         for _s in _image.getImageEntities('style'):
             if _s.getName() != _name:
                 continue
             _lt = _s.getLinetype()
             if (_lt.getName() != _ltdata[0]
                     or _lt.getList() != _ltdata[1]):
                 continue
             if _s.getColor().getColors() != _col:
                 continue
             if abs(_s.getThickness() - _th) > 1e-10:
                 continue
             _style = _s
             break
         _sdata = _obj.getGraphicValues()
         if _style is not None:
             self.ignore(_op)
             try:
                 if undo:
                     _obj.startUndo()
                     try:
                         _obj.setStyle(_style)
                     finally:
                         _obj.endUndo()
                 else:
                     _obj.startRedo()
                     try:
                         _obj.setStyle(_style)
                     finally:
                         _obj.endRedo()
             finally:
                 self.receive(_op)
             #
             # restore values differing from the Style
             #
             if _olt is not None:
                 _name, _list = _olt
                 _lt = None
                 for _l in _image.getImageEntities('linetype'):
                     if (_l.getName() == _name and _l.getList() == _list):
                         _lt = _l
                         break
                 _obj.mute()
                 try:
                     _obj.setLinetype(_lt)
                 finally:
                     _obj.unmute()
             if _oc is not None:
                 _col = None
                 for _c in _image.getImageEntities('color'):
                     if _c.getColors() == _oc:
                         _col = _c
                         break
                 _obj.mute()
                 try:
                     _obj.setColor(_col)
                 finally:
                     _obj.unmute()
             if _ot is not None:
                 _obj.mute()
                 try:
                     _obj.setThickness(_ot)
                 finally:
                     _obj.unmute()
         self.saveData(undo, _op, _sdata)
     elif _op == 'linetype_changed':
         if _image is None:
             raise RuntimeError, "Object not stored in an Image"
         if _alen < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _lt = _obj.getLinetype()
         _sdata = (_lt.getName(), _lt.getList())
         self.ignore(_op)
         try:
             _name, _list = args[1]
             _lt = None
             for _l in _image.getImageEntities('linetype'):
                 if (_l.getName() == _name and _l.getList() == _list):
                     _lt = _l
                     break
             if undo:
                 _obj.startUndo()
                 try:
                     _obj.setLinetype(_lt)
                 finally:
                     _obj.endUndo()
             else:
                 _obj.startRedo()
                 try:
                     _obj.setLinetype(_lt)
                 finally:
                     _obj.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     elif _op == 'color_changed':
         if _image is None:
             raise RuntimeError, "Object not stored in an Image"
         if _alen < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _sdata = _obj.getColor().getColors()
         self.ignore(_op)
         try:
             _col = None
             for _c in _image.getImageEntities('color'):
                 if _c.getColors() == args[1]:
                     _col = _c
                     break
             if undo:
                 _obj.startUndo()
                 try:
                     _obj.setColor(_col)
                 finally:
                     _obj.endUndo()
             else:
                 _obj.startRedo()
                 try:
                     _obj.setColor(_col)
                 finally:
                     _obj.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     elif _op == 'thickness_changed':
         if _alen < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _sdata = _obj.getThickness()
         self.ignore(_op)
         try:
             _t = args[1]
             if undo:
                 _obj.startUndo()
                 try:
                     _obj.setThickness(_t)
                 finally:
                     _obj.endUndo()
             else:
                 _obj.startRedo()
                 try:
                     _obj.setThickness(_t)
                 finally:
                     _obj.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     else:
         super(GraphicObjectLog, self).execute(undo, *args)
Esempio n. 26
0
    def __init__(self, objs, external=True):
        """Initialize a Path.

p = Path(objs[, external])

The required argument 'objs' is a list of objects defining
the path. The valid objects are circles, arcs, segments,
chamfers and fillets.

The optional argument 'external' is by default True, meaning
that this Path is an outer boundary. If the argument is False,
then the Path represents an internal non-hatched area inside
another Path.
        """
        if not isinstance(objs, list):
            raise TypeError, "Unexpected list type: " + ` type(objs) `
        if not len(objs):
            raise ValueError, "Invalid empty object list"
        for _obj in objs:
            _valid = False
            if (
                isinstance(_obj, segment.Segment)
                or isinstance(_obj, arc.Arc)
                or isinstance(_obj, circle.Circle)
                or isinstance(_obj, segjoint.Chamfer)
                or isinstance(_obj, segjoint.Fillet)
            ):
                _valid = True
            if not _valid:
                raise TypeError, "Invalid object type in list: " + ` type(_obj) `
        _circular = False
        if len(objs) == 1:
            _circular = True
            _obj = objs[0]
            _valid = False
            if isinstance(_obj, arc.Arc):
                _sa = _obj.getStartAngle()
                _ea = _obj.getEndAngle()
                if abs(_sa - _ea) < 1e-10:
                    _valid = True
                if not _valid:
                    raise ValueError, "Invalid single Arc path: " + str(_obj)
            elif isinstance(_obj, circle.Circle):
                pass
            else:
                raise TypeError, "Invalid single entity path: " + str(_obj)
        else:
            _valid = True
            for _obj in objs:
                if isinstance(_obj, circle.Circle):
                    if not isinstance(_obj, arc.Arc):
                        _valid = False
                        break
            if not _valid:
                raise TypeError, "Circle found in multi-object path"
            _valid = True  # _validate_path(objlist)
            if not _valid:
                raise ValueError, "Objlist objects do not make a closed path."
        util.test_boolean(external)
        self.__objs = objs[:]
        self.__circular = _circular
        self.__external = external
Esempio n. 27
0
    def execute(self, undo, *args):
        #
        # fixme - deal with the endpoints ...
        #
        def _used_by(obj, plist):
            _objpt = None
            for _pt in plist:
                for _user in _pt.getUsers():
                    if _user is obj:
                        _objpt = _pt
                        break
                if _objpt is not None:
                    break
            return _objpt

        def _most_used(plist):
            _pmax = plist.pop()
            _max = _pmax.countUsers()
            for _pt in plist:
                _count = _pt.countUsers()
                if _count > _max:
                    _max = _count
                    _pmax = _pt
            return _pmax

        util.test_boolean(undo)
        _alen = len(args)
        if _alen == 0:
            raise ValueError, "No arguments to execute()"
        _a = self.getObject()
        _cp = _a.getCenter()
        _op = args[0]
        if _op == 'center_changed':
            if _alen < 2:
                raise ValueError, "Invalid argument count: %d" % _alen
            _oid = args[1]
            _parent = _a.getParent()
            if _parent is None:
                raise ValueError, "Arc has no parent - cannot undo"
            _pt = _parent.getObject(_oid)
            if _pt is None or not isinstance(_pt, point.Point):
                raise ValueError, "Center point missing: id=%d" % _oid
            _ep1, _ep2 = _a.getEndpoints()
            _pts = _parent.find('point', _ep1[0], _ep1[1])
            _ep = _used_by(_a, _pts)
            assert _ep is not None, "Arc endpoint not found in layer"
            _ep.freeUser(_a)
            _pts = _parent.find('point', _ep2[0], _ep2[1])
            _ep = _used_by(_a, _pts)
            assert _ep is not None, "Arc endpoint not found in layer"
            _ep.freeUser(_a)
            _sdata = _cp.getID()
            self.ignore(_op)
            try:
                if undo:
                    _a.startUndo()
                    try:
                        _a.setCenter(_pt)
                    finally:
                        _a.endUndo()
                else:
                    _a.startRedo()
                    try:
                        _a.setCenter(_pt)
                    finally:
                        _a.endRedo()
            finally:
                self.receive(_op)
            _ep1, _ep2 = _a.getEndpoints()
            _pts = _parent.find('point', _ep1[0], _ep1[1])
            _ep = _most_used(_pts)
            _ep.storeUser(_a)
            _pts = _parent.find('point', _ep2[0], _ep2[1])
            _ep = _most_used(_pts)
            _ep.storeUser(_a)
            self.saveData(undo, _op, _sdata)
        elif _op == 'radius_changed':
            if len(args) < 2:
                raise ValueError, "Invalid argument count: %d" % _alen
            _r = args[1]
            if not isinstance(_r, float):
                raise TypeError, "Unexpected type for radius: " + ` type(_r) `
            _sdata = _a.getRadius()
            self.ignore(_op)
            try:
                if undo:
                    _a.startUndo()
                    try:
                        _a.setRadius(_r)
                    finally:
                        _a.endUndo()
                else:
                    _a.startRedo()
                    try:
                        _a.setRadius(_r)
                    finally:
                        _a.endRedo()
            finally:
                self.receive(_op)
            self.saveData(undo, _op, _sdata)
        elif _op == 'start_angle_changed':
            if len(args) < 2:
                raise ValueError, "Invalid argument count: %d" % _alen
            _sa = args[1]
            if not isinstance(_sa, float):
                raise TypeError, "Unexpected type for angle: " + ` type(_sa) `
            _sdata = _a.getStartAngle()
            self.ignore(_op)
            try:
                if undo:
                    _a.startUndo()
                    try:
                        _a.setStartAngle(_sa)
                    finally:
                        _a.endUndo()
                else:
                    _a.startRedo()
                    try:
                        _a.setStartAngle(_sa)
                    finally:
                        _a.endRedo()
            finally:
                self.receive(_op)
            self.saveData(undo, _op, _sdata)
        elif _op == 'end_angle_changed':
            if len(args) < 2:
                raise ValueError, "Invalid argument count: %d" % _alen
            _ea = args[1]
            if not isinstance(_ea, float):
                raise TypeError, "Unexpected type for angle: " + ` type(_ea) `
            _sdata = _a.getEndAngle()
            self.ignore(_op)
            try:
                if undo:
                    _a.startUndo()
                    try:
                        _a.setEndAngle(_ea)
                    finally:
                        _a.endUndo()
                else:
                    _a.startRedo()
                    try:
                        _a.setEndAngle(_ea)
                    finally:
                        _a.endRedo()
            finally:
                self.receive(_op)
            self.saveData(undo, _op, _sdata)
        else:
            super(ArcLog, self).execute(undo, *args)
    def inRegion(self, xmin, ymin, xmax, ymax, fully=False):
        """Return whether or not an CCircle exists within a region.

inRegion(xmin, ymin, xmax, ymax[, fully])

The first four arguments define the boundary. The optional
fifth argument 'fully' indicates whether or not the CCircle
must be completely contained within the region or just pass
through it.
        """
        _xmin = util.get_float(xmin)
        _ymin = util.get_float(ymin)
        _xmax = util.get_float(xmax)
        if _xmax < _xmin:
            raise ValueError, "Illegal values: xmax < xmin"
        _ymax = util.get_float(ymax)
        if _ymax < _ymin:
            raise ValueError, "Illegal values: ymax < ymin"
        util.test_boolean(fully)
        _xc, _yc = self.__center.getCoords()
        _r = self.__radius
        #
        # cheap test to see if ccircle cannot be in region
        #
        if (((_xc - _r) > _xmax) or
            ((_yc - _r) > _ymax) or
            ((_xc + _r) < _xmin) or
            ((_yc + _r) < _ymin)):
            return False
        _val = False
        _bits = 0        
        #
        # calculate distances from center to region boundary
        #
        if abs(_xc - _xmin) < _r: _bits = _bits | 1 # left edge
        if abs(_xc - _xmax) < _r: _bits = _bits | 2 # right edge
        if abs(_yc - _ymin) < _r: _bits = _bits | 4 # bottom edge
        if abs(_yc - _ymax) < _r: _bits = _bits | 8 # top edge
        if _bits == 0:
            #
            # if the ccircle center is in region then the entire
            # ccircle is visible since the distance from the center
            # to any edge is greater than the radius. If the center
            # is not in the region then the ccircle is not visible in
            # the region because the distance to any edge is greater
            # than the radius, and so one of the bits should have been
            # set ...
            #
            if ((_xmin < _xc < _xmax) and (_ymin < _yc < _ymax)):
                _val = True
        else:
            _val = True
            #
            # calculate distance to corners of region
            #
            if math.hypot((_xc - _xmin), (_yc - _ymax)) < _r:
                _bits = _bits | 0x10 # upper left
            if math.hypot((_xc - _xmax), (_yc - _ymin)) < _r:
                _bits = _bits | 0x20 # lower right
            if math.hypot((_xc - _xmin), (_yc - _ymin)) < _r:
                _bits = _bits | 0x40 # lower left
            if math.hypot((_xc - _xmax), (_yc - _ymax)) < _r:
                _bits = _bits | 0x80 # upper right
            #
            # if all bits are set then distance from ccircle center
            # to region endpoints is less than radius - ccircle
            # entirely outside the region
            #
            if _bits == 0xff or fully:
                _val = False
        return _val
 def setLandscapeMode(self, flag):
     util.test_boolean(flag)
     self.__landscape = flag
 def execute(self, undo, *args):
     util.test_boolean(undo)
     _alen = len(args)
     if _alen == 0:
         raise ValueError, "No arguments to execute()"
     _l = self.getObject()
     _op = args[0]
     if _op == 'point_changed':
         if _alen < 3:
             raise ValueError, "Invalid argument count: %d" % _alen
         _oid = args[1]
         _nid = args[2]
         _p1, _p2, _p3 = _l.getPoints()
         _parent = _l.getParent()
         if _parent is None:
             raise ValueError, "Leader has no parent - cannot undo"
         self.ignore(_op)
         try:
             if undo:
                 _pt = _parent.getObject(_oid)
                 if _pt is None or not isinstance(_pt, point.Point):
                     raise ValueError, "Old point missing: id=%d" % _oid
                 _l.startUndo()
                 try:
                     if _p1.getID() == _nid:
                         _l.setP1(_pt)
                     elif _p2.getID() == _nid:
                         _l.setP2(_pt)
                     elif _p3.getID() == _nid:
                         _l.setP3(_pt)
                     else:
                         raise ValueError, "Unexpected point ID: %d" % _nid
                 finally:
                     _l.endUndo()
             else:
                 _pt = _parent.getObject(_nid)
                 if _pt is None or not isinstance(_pt, point.Point):
                     raise ValueError, "New point missing: id=%d" % _nid
                 _l.startRedo()
                 try:
                     if _p1.getID() == _oid:
                         _l.setP1(_pt)
                     elif _p2.getID() == _oid:
                         _l.setP2(_pt)
                     elif _p3.getID() == _oid:
                         _l.setP3(_pt)
                     else:
                         raise ValueError, "Unexpected point ID: %d" % _oid
                 finally:
                     _l.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _oid, _nid)
     elif _op == 'size_changed':
         if len(args) < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _size = args[1]
         if not isinstance(_size, float):
             raise TypeError, "Unexpected type for size: " + `type(_size)`
         _sdata = _l.getArrowSize()
         self.ignore(_op)
         try:
             if undo:
                 _l.startUndo()
                 try:
                     _l.setArrowSize(_size)
                 finally:
                     _l.endUndo()
             else:
                 _l.startRedo()
                 try:
                     _l.setArrowSize(_size)
                 finally:
                     _l.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     else:
         super(LeaderLog, self).execute(undo, *args)
    def inRegion(self, xmin, ymin, xmax, ymax, fully=False):
        """Return whether or not an ACLine passes through a region.

inRegion(xmin, ymin, xmax, ymax)

The first four arguments define the boundary. The method
will return True if the ACLine passes through the boundary.
Otherwise the function will return False.
        """
        _xmin = util.get_float(xmin)
        _ymin = util.get_float(ymin)
        _xmax = util.get_float(xmax)
        if _xmax < _xmin:
            raise ValueError, "Illegal values: xmax < xmin"
        _ymax = util.get_float(ymax)
        if _ymax < _ymin:
            raise ValueError, "Illegal values: ymax < ymin"
        util.test_boolean(fully)
        if fully:
            return False
        _x, _y = self.getLocation().getCoords()
        _angle = self.__angle
        _val = False
        if _xmin < _x < _xmax and _ymin < _y < _ymax:
            _val = True
        elif self.isHorizontal() and _ymin < _y < _ymax:
            _val = True
        elif self.isVertical() and _xmin < _x < _xmax:
            _val = True
        else:
            #
            # the ACLine can be parameterized as
            #
            # x = u * (x2 - x1) + x1
            # y = u * (y2 - y1) + y1
            #
            # for u = 0, x => x1, y => y1
            # for u = 1, x => x2, y => y2
            #
            # if the ACLine passes through the region then there
            # will be valid u occuring at the region boundary
            #
            _rangle = _angle * _dtr
            _dx = math.cos(_rangle)
            _dy = math.sin(_rangle)
            #
            # x = xmin
            #
            _u = (_xmin - _x)/_dx
            _yt = (_u * _dy) + _y
            if (_ymin - 1e-10) < _yt < (_ymax + 1e-10): # catch endpoints
                _val = True
            if not _val:
                #
                # x = xmax
                #
                _u = (_xmax - _x)/_dx
                _yt = (_u * _dy) + _y
                if (_ymin - 1e-10) < _yt < (_ymax + 1e-10): # catch endpoints
                    _val = True
                if not _val:
                    #
                    # y = ymin
                    #
                    # if this fails there is no way the ACLine can be in
                    # region because it cannot pass through only one side
                    #
                    _u = (_ymin - _y)/_dy
                    _xt = (_u * _dx) + _x
                    if _xmin < _xt < _xmax:
                        _val = True
        return _val
Esempio n. 32
0
 def execute(self, undo, *args):
     #
     # fixme - deal with the endpoints ...
     #
     def _used_by(obj, plist):
         _objpt = None
         for _pt in plist:
             for _user in _pt.getUsers():
                 if _user is obj:
                     _objpt = _pt
                     break
             if _objpt is not None:
                 break
         return _objpt
     def _most_used(plist):
         _pmax = plist.pop()
         _max = _pmax.countUsers()
         for _pt in plist:
             _count = _pt.countUsers()
             if _count > _max:
                 _max = _count
                 _pmax = _pt
         return _pmax
     util.test_boolean(undo)
     _alen = len(args)
     if _alen == 0:
         raise ValueError, "No arguments to execute()"
     _a = self.getObject()
     _cp = _a.getCenter()
     _op = args[0]
     if _op == 'center_changed':
         if _alen < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _oid = args[1]
         _parent = _a.getParent()
         if _parent is None:
             raise ValueError, "Arc has no parent - cannot undo"
         _pt = _parent.getObject(_oid)
         if _pt is None or not isinstance(_pt, point.Point):
             raise ValueError, "Center point missing: id=%d" % _oid
         _ep1, _ep2 = _a.getEndpoints()
         _pts = _parent.find('point', _ep1[0], _ep1[1])
         _ep = _used_by(_a, _pts)
         assert _ep is not None, "Arc endpoint not found in layer"
         _ep.freeUser(_a)
         _pts = _parent.find('point', _ep2[0], _ep2[1])
         _ep = _used_by(_a, _pts)
         assert _ep is not None, "Arc endpoint not found in layer"
         _ep.freeUser(_a)
         _sdata = _cp.getID()
         self.ignore(_op)
         try:
             if undo:
                 _a.startUndo()
                 try:
                     _a.setCenter(_pt)
                 finally:
                     _a.endUndo()
             else:
                 _a.startRedo()
                 try:
                     _a.setCenter(_pt)
                 finally:
                     _a.endRedo()
         finally:
             self.receive(_op)
         _ep1, _ep2 = _a.getEndpoints()
         _pts = _parent.find('point', _ep1[0], _ep1[1])
         _ep = _most_used(_pts)
         _ep.storeUser(_a)
         _pts = _parent.find('point', _ep2[0], _ep2[1])
         _ep = _most_used(_pts)
         _ep.storeUser(_a)
         self.saveData(undo, _op, _sdata)
     elif _op == 'radius_changed':
         if len(args) < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _r = args[1]
         if not isinstance(_r, float):
             raise TypeError, "Unexpected type for radius: " + `type(_r)`
         _sdata = _a.getRadius()
         self.ignore(_op)
         try:
             if undo:
                 _a.startUndo()
                 try:
                     _a.setRadius(_r)
                 finally:
                     _a.endUndo()
             else:
                 _a.startRedo()
                 try:
                     _a.setRadius(_r)
                 finally:
                     _a.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     elif _op == 'start_angle_changed':
         if len(args) < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _sa = args[1]
         if not isinstance(_sa, float):
             raise TypeError, "Unexpected type for angle: " + `type(_sa)`
         _sdata = _a.getStartAngle()
         self.ignore(_op)
         try:
             if undo:
                 _a.startUndo()
                 try:
                     _a.setStartAngle(_sa)
                 finally:
                     _a.endUndo()
             else:
                 _a.startRedo()
                 try:
                     _a.setStartAngle(_sa)
                 finally:
                     _a.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     elif _op == 'end_angle_changed':
         if len(args) < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _ea = args[1]
         if not isinstance(_ea, float):
             raise TypeError, "Unexpected type for angle: " + `type(_ea)`
         _sdata = _a.getEndAngle()
         self.ignore(_op)
         try:
             if undo:
                 _a.startUndo()
                 try:
                     _a.setEndAngle(_ea)
                 finally:
                     _a.endUndo()
             else:
                 _a.startRedo()
                 try:
                     _a.setEndAngle(_ea)
                 finally:
                     _a.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     else:
         super(ArcLog, self).execute(undo, *args)
 def execute(self, undo, *args):
     util.test_boolean(undo)
     _alen = len(args)
     if _alen == 0:
         raise ValueError, "No arguments to execute()"
     _c = self.getObject()
     _cp = _c.getCenter()
     _op = args[0]
     if _op == 'radius_changed':
         if len(args) < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _r = args[1]
         if not isinstance(_r, float):
             raise TypeError, "Unexpected type for radius: " + `type(_r)`
         _sdata = _c.getRadius()
         self.ignore(_op)
         try:
             if undo:
                 _c.startUndo()
                 try:
                     _c.setRadius(_r)
                 finally:
                     _c.endUndo()
             else:
                 _c.startRedo()
                 try:
                     _c.setRadius(_r)
                 finally:
                     _c.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     elif _op == 'center_changed':
         if _alen < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _oid = args[1]
         _parent = _c.getParent()
         if _parent is None:
             raise ValueError, "CCircle has no parent - cannot undo"
         _pt = _parent.getObject(_oid)
         if _pt is None or not isinstance(_pt, point.Point):
             raise ValueError, "Center point missing: id=%d" % _oid
         _sdata = _cp.getID()
         self.ignore(_op)
         try:
             if undo:
                 _c.startUndo()
                 try:
                     _c.setCenter(_pt)
                 finally:
                     _c.endUndo()
             else:
                 _c.startRedo()
                 try:
                     _c.setCenter(_pt)
                 finally:
                     _c.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     else:
         super(CCircleLog, self).execute(undo, *args)
Esempio n. 34
0
    def inRegion(self, xmin, ymin, xmax, ymax, fully=False):
        """Return whether or not an Arc exists within a region.

inRegion(xmin, ymin, xmax, ymax[, fully])

The first four arguments define the boundary. The optional
fifth argument fully indicates whether or not the Arc
must be completely contained within the region or just pass
through it.
        """
        _xmin = util.get_float(xmin)
        _ymin = util.get_float(ymin)
        _xmax = util.get_float(xmax)
        if _xmax < _xmin:
            raise ValueError, "Illegal values: xmax < xmin"
        _ymax = util.get_float(ymax)
        if _ymax < _ymin:
            raise ValueError, "Illegal values: ymax < ymin"
        util.test_boolean(fully)
        _xc, _yc = self.__center.getCoords()
        _r = self.__radius
        #
        # cheap test to see if arc cannot be in region
        #
        _axmin, _aymin, _axmax, _aymax = self.getBounds()
        if ((_axmin > _xmax) or (_aymin > _ymax) or (_axmax < _xmin)
                or (_aymax < _ymin)):
            return False
        _val = False
        _bits = 0
        #
        # calculate distances from center to region boundary
        #
        if abs(_xc - _xmin) < _r: _bits = _bits | 1  # left edge
        if abs(_xc - _xmax) < _r: _bits = _bits | 2  # right edge
        if abs(_yc - _ymin) < _r: _bits = _bits | 4  # bottom edge
        if abs(_yc - _ymax) < _r: _bits = _bits | 8  # top edge
        if _bits == 0:
            #
            # arc must be visible - the center is in
            # the region and is more than the radius from
            # each edge
            #
            _val = True
        else:
            #
            # calculate distance to corners of region
            #
            if math.hypot((_xc - _xmin), (_yc - _ymax)) < _r:
                _bits = _bits | 0x10  # upper left
            if math.hypot((_xc - _xmax), (_yc - _ymin)) < _r:
                _bits = _bits | 0x20  # lower right
            if math.hypot((_xc - _xmin), (_yc - _ymin)) < _r:
                _bits = _bits | 0x40  # lower left
            if math.hypot((_xc - _xmax), (_yc - _ymax)) < _r:
                _bits = _bits | 0x80  # upper right
            #
            # if all bits are set then distance from arc center
            # to region endpoints is less than radius - arc
            # entirely outside the region
            #
            _val = not ((_bits == 0xff) or fully)
            #
            # if the test value is still true, check that the
            # arc boundary can overlap with the region
            #
            if _val:
                _ep1, _ep2 = self.getEndpoints()
                _axmin = min(_xc, _ep1[0], _ep2[0])
                if self.throughAngle(180.0):
                    _axmin = _xc - _r
                if _axmin > _xmax:
                    return False
                _aymin = min(_yc, _ep1[1], _ep2[1])
                if self.throughAngle(270.0):
                    _aymin = _yc - _r
                if _aymin > _ymax:
                    return False
                _axmax = max(_xc, _ep1[0], _ep2[0])
                if self.throughAngle(0.0):
                    _axmax = _xc + _r
                if _axmax < _xmin:
                    return False
                _aymax = max(_yc, _ep1[1], _ep2[1])
                if self.throughAngle(90.0):
                    _aymax = _yc + _r
                if _aymax < _ymin:
                    return False
        return _val
 def setColorMode(self, flag):
     util.test_boolean(flag)
     self.__color = flag
 def invertWhite(self, flag):
     util.test_boolean(flag)
     self.__invert = flag
 def execute(self, undo, *args):
     util.test_boolean(undo)
     _alen = len(args)
     if _alen == 0:
         raise ValueError, "No arguments to execute()"
     _a = self.getObject()
     _p = _a.getLocation()
     _op = args[0]
     if _op == 'rotated':
         if len(args) < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _angle = args[1]
         if not isinstance(_angle, float):
             raise TypeError, "Unexpected type for angle: " + `type(_angle)`
         _sdata = _a.getAngle()
         self.ignore(_op)
         try:
             if undo:
                 _a.startUndo()
                 try:
                     _a.setAngle(_angle)
                 finally:
                     _a.endUndo()
             else:
                 _a.startRedo()
                 try:
                     _a.setAngle(_angle)
                 finally:
                     _a.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     elif _op == 'keypoint_changed':
         if _alen < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _oid = args[1]
         _parent = _a.getParent()
         if _parent is None:
             raise ValueError, "ACLine has no parent - cannot undo"
         _pt = _parent.getObject(_oid)
         if _pt is None or not isinstance(_pt, point.Point):
             raise ValueError, "Keypoint missing: id=%d" % _oid
         _sdata = _p.getID()
         self.ignore(_op)
         try:
             if undo:
                 _a.startUndo()
                 try:
                     _a.setLocation(_pt)
                 finally:
                     _a.endUndo()
             else:
                 _a.startRedo()
                 try:
                     _a.setLocation(_pt)
                 finally:
                     _a.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     else:
         super(ACLineLog, self).execute(undo, *args)
 def execute(self, undo, *args):
     util.test_boolean(undo)
     _alen = len(args)
     if _alen == 0:
         raise ValueError, "No arguments to execute()"
     _p = self.getObject()
     _op = args[0]
     _pts = _p.getPoints()
     if _op == 'point_changed':
         if _alen < 3:
             raise ValueError, "Invalid argument count: %d" % _alen
         _oid = args[1]
         _nid = args[2]
         _parent = _p.getParent()
         if _parent is None:
             raise ValueError, "Polyline has no parent - cannot undo"
         self.ignore(_op)
         try:
             if undo:
                 _setpt = _parent.getObject(_oid)
                 if _setpt is None or not isinstance(_setpt, point.Point):
                     raise ValueError, "Old endpoint missing: id=%d" % _oid
                 _p.startUndo()
                 try:
                     _seen = False
                     for _i in range(len(_pts)):
                         _pt = _pts[_i]
                         if _pt.getID() == _nid:
                             _p.setPoint(_i, _setpt)
                             _seen = True
                             break
                     if not _seen:
                         raise ValueError, "Unexpected point ID: %d" % _nid
                 finally:
                     _p.endUndo()
             else:
                 _setpt = _parent.getObject(_nid)
                 if _setpt is None or not isinstance(_setpt, point.Point):
                     raise ValueError, "New point missing: id=%d" % _nid
                 _pts = _p.getPoints()
                 _p.startRedo()
                 try:
                     _seen = False
                     for _i in range(len(_pts)):
                         _pt = _pts[_i]
                         if _pt.getID() == _oid:
                             _p.setPoint(_i, _setpt)
                             _seen = True
                             break
                     if not _seen:
                         raise ValueError, "Unexpected point ID: %d" % _nid
                 finally:
                     _p.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _oid, _nid)
     elif _op == 'added_point':
         if _alen < 3:
             raise ValueError, "Invalid argument count: %d" % _alen
         _idx = args[1]
         _pid = args[2]
         self.ignore(_op)
         try:
             if undo:
                 self.ignore('deleted_point')
                 try:
                     _p.startUndo()
                     try:
                         _p.delPoint(_idx)
                     finally:
                         _p.endUndo()
                 finally:
                     self.receive('deleted_point')
             else:
                 _parent = _p.getParent()
                 if _parent is None:
                     raise ValueError, "Polyline has no parent - cannot undo"
                 _pt = _parent.getObject(_pid)
                 if _pt is None or not isinstance(_pt, point.Point):
                     raise ValueError, "Point missing: id=%d" % _pid
                 _p.startRedo()
                 try:
                     _p.addPoint(_idx, _pt)
                 finally:
                     _p.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _idx, _pid)
     elif _op == 'deleted_point':
         if _alen < 3:
             raise ValueError, "Invalid argument count: %d" % _alen
         _idx = args[1]
         _pid = args[2]
         self.ignore(_op)
         try:
             if undo:
                 _parent = _p.getParent()
                 if _parent is None:
                     raise ValueError, "Polyline has no parent - cannot undo"
                 _pt = _parent.getObject(_pid)
                 if _pt is None or not isinstance(_pt, point.Point):
                     raise ValueError, "Point missing: id=%d" % _pid
                 self.ignore('added_point')
                 try:
                     _p.startUndo()
                     try:
                         _p.addPoint(_idx, _pt)
                     finally:
                         _p.endUndo()
                 finally:
                     self.receive('added_point')
             else:
                 _p.startRedo()
                 try:
                     _p.delPoint(_idx)
                 finally:
                     _p.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _idx, _pid)
     else:
         super(PolylineLog, self).execute(undo, *args)
 def execute(self, undo, *args):
     util.test_boolean(undo)
     _alen = len(args)
     if len(args) == 0:
         raise ValueError, "No arguments to execute()"
     _obj = self.getObject()
     _op = args[0]
     _image = None
     _layer = _obj.getParent()
     if _layer is not None:
         _image = _layer.getParent()
     if _op == 'style_changed':
         if _image is None:
             raise RuntimeError, "Object not stored in an Image"
         if _alen < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _style = None
         _sv, _olt, _oc, _ot = args[1]
         _name, _ltdata, _col, _th = _sv
         for _s in _image.getImageEntities('style'):
             if _s.getName() != _name:
                 continue
             _lt = _s.getLinetype()
             if (_lt.getName() != _ltdata[0] or
                 _lt.getList() != _ltdata[1]):
                 continue
             if _s.getColor().getColors() != _col:
                 continue
             if abs(_s.getThickness() - _th) > 1e-10:
                 continue
             _style = _s
             break
         _sdata = _obj.getGraphicValues()
         if _style is not None:
             self.ignore(_op)
             try:
                 if undo:
                     _obj.startUndo()
                     try:
                         _obj.setStyle(_style)
                     finally:
                         _obj.endUndo()
                 else:
                     _obj.startRedo()
                     try:
                         _obj.setStyle(_style)
                     finally:
                         _obj.endRedo()
             finally:
                 self.receive(_op)
             #
             # restore values differing from the Style
             #
             if _olt is not None:
                 _name, _list = _olt
                 _lt = None
                 for _l in _image.getImageEntities('linetype'):
                     if (_l.getName() == _name and _l.getList() == _list):
                         _lt = _l
                         break
                 _obj.mute()
                 try:
                     _obj.setLinetype(_lt)
                 finally:
                     _obj.unmute()
             if _oc is not None:
                 _col = None
                 for _c in _image.getImageEntities('color'):
                     if _c.getColors() == _oc:
                         _col = _c
                         break
                 _obj.mute()
                 try:
                     _obj.setColor(_col)
                 finally:
                     _obj.unmute()
             if _ot is not None:
                 _obj.mute()
                 try:
                     _obj.setThickness(_ot)
                 finally:
                     _obj.unmute()
         self.saveData(undo, _op, _sdata)
     elif _op == 'linetype_changed':
         if _image is None:
             raise RuntimeError, "Object not stored in an Image"
         if _alen < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _lt = _obj.getLinetype()
         _sdata = (_lt.getName(), _lt.getList())
         self.ignore(_op)
         try:
             _name, _list = args[1]
             _lt = None
             for _l in _image.getImageEntities('linetype'):
                 if (_l.getName() == _name and _l.getList() == _list):
                     _lt = _l
                     break
             if undo:
                 _obj.startUndo()
                 try:
                     _obj.setLinetype(_lt)
                 finally:
                     _obj.endUndo()
             else:
                 _obj.startRedo()
                 try:
                     _obj.setLinetype(_lt)
                 finally:
                     _obj.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     elif _op == 'color_changed':
         if _image is None:
             raise RuntimeError, "Object not stored in an Image"
         if _alen < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _sdata = _obj.getColor().getColors()
         self.ignore(_op)
         try:
             _col = None
             for _c in _image.getImageEntities('color'):
                 if _c.getColors() == args[1]:
                     _col = _c
                     break
             if undo:
                 _obj.startUndo()
                 try:
                     _obj.setColor(_col)
                 finally:
                     _obj.endUndo()
             else:
                 _obj.startRedo()
                 try:
                     _obj.setColor(_col)
                 finally:
                     _obj.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     elif _op == 'thickness_changed':
         if _alen < 2:
             raise ValueError, "Invalid argument count: %d" % _alen
         _sdata = _obj.getThickness()
         self.ignore(_op)
         try:
             _t = args[1]
             if undo:
                 _obj.startUndo()
                 try:
                     _obj.setThickness(_t)
                 finally:
                     _obj.endUndo()
             else:
                 _obj.startRedo()
                 try:
                     _obj.setThickness(_t)
                 finally:
                     _obj.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _sdata)
     else:
         super(GraphicObjectLog, self).execute(undo, *args)
Esempio n. 40
0
 def execute(self, undo, *args):
     util.test_boolean(undo)
     _alen = len(args)
     if _alen == 0:
         raise ValueError, "No arguments to execute()"
     _p = self.getObject()
     _op = args[0]
     _pts = _p.getPoints()
     if _op == 'point_changed':
         if _alen < 3:
             raise ValueError, "Invalid argument count: %d" % _alen
         _oid = args[1]
         _nid = args[2]
         _parent = _p.getParent()
         if _parent is None:
             raise ValueError, "Polyline has no parent - cannot undo"
         self.ignore(_op)
         try:
             if undo:
                 _setpt = _parent.getObject(_oid)
                 if _setpt is None or not isinstance(_setpt, point.Point):
                     raise ValueError, "Old endpoint missing: id=%d" % _oid
                 _p.startUndo()
                 try:
                     _seen = False
                     for _i in range(len(_pts)):
                         _pt = _pts[_i]
                         if _pt.getID() == _nid:
                             _p.setPoint(_i, _setpt)
                             _seen = True
                             break
                     if not _seen:
                         raise ValueError, "Unexpected point ID: %d" % _nid
                 finally:
                     _p.endUndo()
             else:
                 _setpt = _parent.getObject(_nid)
                 if _setpt is None or not isinstance(_setpt, point.Point):
                     raise ValueError, "New point missing: id=%d" % _nid
                 _pts = _p.getPoints()
                 _p.startRedo()
                 try:
                     _seen = False
                     for _i in range(len(_pts)):
                         _pt = _pts[_i]
                         if _pt.getID() == _oid:
                             _p.setPoint(_i, _setpt)
                             _seen = True
                             break
                     if not _seen:
                         raise ValueError, "Unexpected point ID: %d" % _nid
                 finally:
                     _p.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _oid, _nid)
     elif _op == 'added_point':
         if _alen < 3:
             raise ValueError, "Invalid argument count: %d" % _alen
         _idx = args[1]
         _pid = args[2]
         self.ignore(_op)
         try:
             if undo:
                 self.ignore('deleted_point')
                 try:
                     _p.startUndo()
                     try:
                         _p.delPoint(_idx)
                     finally:
                         _p.endUndo()
                 finally:
                     self.receive('deleted_point')
             else:
                 _parent = _p.getParent()
                 if _parent is None:
                     raise ValueError, "Polyline has no parent - cannot undo"
                 _pt = _parent.getObject(_pid)
                 if _pt is None or not isinstance(_pt, point.Point):
                     raise ValueError, "Point missing: id=%d" % _pid
                 _p.startRedo()
                 try:
                     _p.addPoint(_idx, _pt)
                 finally:
                     _p.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _idx, _pid)
     elif _op == 'deleted_point':
         if _alen < 3:
             raise ValueError, "Invalid argument count: %d" % _alen
         _idx = args[1]
         _pid = args[2]
         self.ignore(_op)
         try:
             if undo:
                 _parent = _p.getParent()
                 if _parent is None:
                     raise ValueError, "Polyline has no parent - cannot undo"
                 _pt = _parent.getObject(_pid)
                 if _pt is None or not isinstance(_pt, point.Point):
                     raise ValueError, "Point missing: id=%d" % _pid
                 self.ignore('added_point')
                 try:
                     _p.startUndo()
                     try:
                         _p.addPoint(_idx, _pt)
                     finally:
                         _p.endUndo()
                 finally:
                     self.receive('added_point')
             else:
                 _p.startRedo()
                 try:
                     _p.delPoint(_idx)
                 finally:
                     _p.endRedo()
         finally:
             self.receive(_op)
         self.saveData(undo, _op, _idx, _pid)
     else:
         super(PolylineLog, self).execute(undo, *args)
Esempio n. 41
0
    def inRegion(self, xmin, ymin, xmax, ymax, fully=False):
        """Return whether or not an Arc exists within a region.

inRegion(xmin, ymin, xmax, ymax[, fully])

The first four arguments define the boundary. The optional
fifth argument fully indicates whether or not the Arc
must be completely contained within the region or just pass
through it.
        """
        _xmin = util.get_float(xmin)
        _ymin = util.get_float(ymin)
        _xmax = util.get_float(xmax)
        if _xmax < _xmin:
            raise ValueError, "Illegal values: xmax < xmin"
        _ymax = util.get_float(ymax)
        if _ymax < _ymin:
            raise ValueError, "Illegal values: ymax < ymin"
        util.test_boolean(fully)
        _xc, _yc = self.__center.getCoords()
        _r = self.__radius
        #
        # cheap test to see if arc cannot be in region
        #
        _axmin, _aymin, _axmax, _aymax = self.getBounds()
        if ((_axmin > _xmax) or
            (_aymin > _ymax) or
            (_axmax < _xmin) or
            (_aymax < _ymin)):
            return False
        _val = False
        _bits = 0
        #
        # calculate distances from center to region boundary
        #
        if abs(_xc - _xmin) < _r: _bits = _bits | 1 # left edge
        if abs(_xc - _xmax) < _r: _bits = _bits | 2 # right edge
        if abs(_yc - _ymin) < _r: _bits = _bits | 4 # bottom edge
        if abs(_yc - _ymax) < _r: _bits = _bits | 8 # top edge
        if _bits == 0:
            #
            # arc must be visible - the center is in
            # the region and is more than the radius from
            # each edge
            #
            _val = True
        else:
            #
            # calculate distance to corners of region
            #
            if math.hypot((_xc - _xmin), (_yc - _ymax)) < _r:
                _bits = _bits | 0x10 # upper left
            if math.hypot((_xc - _xmax), (_yc - _ymin)) < _r:
                _bits = _bits | 0x20 # lower right
            if math.hypot((_xc - _xmin), (_yc - _ymin)) < _r:
                _bits = _bits | 0x40 # lower left
            if math.hypot((_xc - _xmax), (_yc - _ymax)) < _r:
                _bits = _bits | 0x80 # upper right
            #
            # if all bits are set then distance from arc center
            # to region endpoints is less than radius - arc
            # entirely outside the region
            #
            _val = not ((_bits == 0xff) or fully)
            #
            # if the test value is still true, check that the
            # arc boundary can overlap with the region
            #
            if _val:
                _ep1, _ep2 = self.getEndpoints()
                _axmin = min(_xc, _ep1[0], _ep2[0])
                if self.throughAngle(180.0):
                    _axmin = _xc - _r
                if _axmin > _xmax:
                    return False
                _aymin = min(_yc, _ep1[1], _ep2[1])
                if self.throughAngle(270.0):
                    _aymin = _yc - _r
                if _aymin > _ymax:
                    return False
                _axmax = max(_xc, _ep1[0], _ep2[0])
                if self.throughAngle(0.0):
                    _axmax = _xc + _r
                if _axmax < _xmin:
                    return False
                _aymax = max(_yc, _ep1[1], _ep2[1])
                if self.throughAngle(90.0):
                    _aymax = _yc + _r
                if _aymax < _ymin:
                    return False
        return _val