Esempio n. 1
0
def TransformationParameter(restriction=None, preprocess=None, **kwargs):
    from spira.core.transformation import Transform
    if 'default' in kwargs:
        default = kwargs['default']
    else:
        default = None
    R = RestrictType(Transform) & restriction
    P = ProcessoTransformation() + preprocess
    return ParameterDescriptor(default=default, restrictions=R, preprocess=P, **kwargs)
Esempio n. 2
0
def DisplayStyleParameter(local_name=None,
                          restriction=None,
                          preprocess=None,
                          **kwargs):
    if not 'default' in kwargs:
        kwargs['default'] = None
    R = RestrictType(DisplayStyle) & restriction
    P = ProcessorDisplayStyle() + preprocess
    return RestrictedProperty(local_name,
                              restriction=R,
                              preprocess=P,
                              **kwargs)
Esempio n. 3
0
def ColorParameter(red=0, green=0, blue=0, **kwargs):
    from spira.yevon.visualization.color import Color
    if 'default' not in kwargs:
        kwargs['default'] = Color(red=0, green=0, blue=0, **kwargs)
    R = RestrictType(Color)
    return ParameterDescriptor(restrictions=R, **kwargs)
Esempio n. 4
0
import numpy as np
import networkx as nx
from spira.core.parameters.restrictions import RestrictType, RestrictRange
from spira.core.parameters.descriptor import RestrictedParameter

NUMBER = RestrictType((int, float, np.int32, np.int64, np.float))
FLOAT = RestrictType(float)
INTEGER = RestrictType(int)
COMPLEX = RestrictType((int, float, complex))
STRING = RestrictType(str)
BOOL = RestrictType(bool)
DICTIONARY = RestrictType(dict)
LIST = RestrictType(list)
TUPLE = RestrictType(tuple)
NUMPY_ARRAY = RestrictType(np.ndarray)
GRAPH = RestrictType(nx.Graph)


def NumberParameter(restriction=None, **kwargs):
    if 'default' not in kwargs:
        kwargs['default'] = 0
    R = NUMBER & restriction
    return RestrictedParameter(restriction=R, **kwargs)


def ComplexParameter(restriction=None, **kwargs):
    from .variables import COMPLEX
    if 'default' not in kwargs:
        kwargs['default'] = 0
    return RestrictedParameter(restriction=COMPLEX, **kwargs)
Esempio n. 5
0
 def __init__(self, default=[], **kwargs):
     kwargs['default'] = self.__type__(default)
     kwargs['restrictions'] = RestrictType([self.__type__])
     super().__init__(**kwargs)
Esempio n. 6
0
class Magnification(__ConvertableTransform__):
    """ Scaling transformation with respect to a given point. """

    def __init__(self, magnification=1.0, magnification_center=(0.0, 0.0), **kwargs):
        super().__init__(magnification=magnification, magnification_center=magnification_center, **kwargs)

    def set_magnification(self, value):
        self.__magnification__ = value
        if hasattr(self, '__magnification_center__'):
            center = self.__magnification_center__
            self.translation = Coord((1 - self.__magnification__) * center.x, (1 - self.__magnification__) * center.y)
            

    magnification = SetFunctionParameter('__magnification__', set_magnification, default=1.0)
    
    def set_magnification_center(self, center):
        if not isinstance(center, Coord):
            center = Coord(center[0], center[1])
        self.__magnification_center__ = center
        if hasattr(self, '__magnification__'):
            self.translation = Coord((1 - self.__magnification__) * center.x, (1 - self.__magnification__) * center.y)

    magnification_center = SetFunctionParameter(
        local_name='__magnification_center__', 
        fset=set_magnification_center, 
        restriction=RestrictType(Coord), 
        preprocess=ProcessorTypeCast(Coord), 
        default=(0.0, 0.0)
    )
    
    def apply_to_coord(self, coord):      
        coord = self.__magnify__(coord)
        coord = self.__translate__(coord)
        return coord

    def reverse_on_coord(self, coord):      
        coord = self.__inv_translate__(coord)
        coord = self.__inv_magnify__(coord)
        return coord

    def apply_to_array(self, coords):      
        coords = self.__magnify_array__(coords)
        coords = self.__translate_array__(coords)
        return coords

    def reverse_on_array(self, coords):      
        coords = self.__inv_translate_array__(coords)
        coords = self.__inv_magnify__array__(coords)
        return coords

    def apply_to_length(self, length):
        return length * self.magnification
    
    def reverse_on_length(self, length):
        return length / self.magnification
    
    def __neg__(self):
        """ Returns reverse transformation """
        return Magnification(self.magnification_center, 1.0 / self.magnification)    

    def is_identity(self):
        return (self.magnification == 1.0)
Esempio n. 7
0
class Rotation(__ConvertableTransform__):
    def __init__(self,
                 rotation=0,
                 rotation_center=(0, 0),
                 absolute_rotation=False,
                 **kwargs):
        if not 'translation' in kwargs:
            kwargs['translation'] = SUPPRESSED
        super().__init__(rotation=rotation,
                         rotation_center=rotation_center,
                         absolute_rotation=absolute_rotation,
                         **kwargs)

    absolute_rotation = getattr(GenericTransform, 'absolute_rotation')

    def set_rotation(self, value):
        self.__rotation__ = value % 360.0
        if value % 90.0 == 0.0:
            if self.__rotation__ == 0.0:
                self.__ca__ = 1.0
                self.__sa__ = 0.0
            elif self.__rotation__ == 90.0:
                self.__ca__ = 0.0
                self.__sa__ = 1.0
            elif self.__rotation__ == 180.0:
                self.__ca__ = -1.0
                self.__sa__ = 0.0
            elif self.__rotation__ == 270.0:
                self.__ca__ = 0.0
                self.__sa__ = -1.
        else:
            self.__ca__ = np.cos(value * constants.DEG2RAD)
            self.__sa__ = np.sin(value * constants.DEG2RAD)
        if hasattr(self, '__rotation_center__'):
            rotation_center = self.__rotation_center__
            self.translation = Coord(
                rotation_center.x * (1 - self.__ca__) +
                rotation_center.y * self.__sa__,
                rotation_center.y * (1 - self.__ca__) -
                rotation_center.x * self.__sa__)

    rotation = SetFunctionParameter('__rotation__', set_rotation, default=0.0)

    def set_rotation_center(self, rotation_center):
        if not isinstance(rotation_center, Coord):
            rotation_center = Coord(rotation_center[0], rotation_center[1])
        self.__rotation_center__ = rotation_center
        if hasattr(self, '__ca__'):
            self.translation = Coord(
                rotation_center.x * (1 - self.__ca__) +
                rotation_center.y * self.__sa__,
                -rotation_center.x * self.__sa__ + rotation_center.y *
                (1 - self.__ca__))

    rotation_center = SetFunctionParameter(local_name='__rotation_center__',
                                           fset=set_rotation_center,
                                           restriction=RestrictType(Coord),
                                           preprocess=ProcessorTypeCast(Coord),
                                           default=(0.0, 0.0))

    def __neg__(self):
        return Rotation(-self.rotation, self.rotation_center)

    def apply_to_coord(self, coord):
        coord = self.__rotate__(coord)
        coord = self.__translate__(coord)
        return coord

    def reverse_on_coord(self, coord):
        coord = self.__inv_translate__(coord)
        coord = self.__inv_rotate__(coord)
        return coord

    def apply_to_array(self, coords):
        coords = self.__rotate_array__(coords)
        coords = self.__translate_array__(coords)
        return coords

    def apply_to_angle(self, angle):
        a = angle
        a += self.rotation
        return a % 360.0

    def is_identity(self):
        return (self.rotation == 0.0)
Esempio n. 8
0
def NetParameter(local_name=None, restriction=None, **kwargs):
    R = RestrictType(Net) & restriction
    return RestrictedParameter(local_name, restriction=R, **kwargs)
Esempio n. 9
0
def StippleParameter(local_name=None, restriction=None, preprocess=None,**kwargs):
    R = RestrictType(StipplePattern) & restriction
    P = ProcessorStipplePattern() + preprocess
    return RestrictedParameter(local_name,  restriction=R, preprocess=P, **kwargs)
Esempio n. 10
0
def CellParameter(local_name=None, restriction=None, **kwargs):
    R = RestrictType(Cell) & restriction
    return ParameterDescriptor(local_name, restriction=R, **kwargs)
Esempio n. 11
0
        return 180.0 / math.pi * self.angle_rad(other)

    def angle_rad(self, other=(0.0, 0.0)):
        """ the angle with respect to another coordinate, in radians """
        return math.atan2(self.y - other[1], self.x - other[0])

    def dot(self, other):
        return np.conj(self.x) * other[0] + np.conj(self.y) * other[1]

    def id_string(self):
        return "%d_%d" % (self.x * 1000, self.y * 1000)

    def to_numpy_array(self):
        return np.array([self.x, self.y])

    def to_list(self):
        return [self.x, self.y]


RESTRICT_COORD = RestrictType(Coord)


def CoordParameter(local_name=None, restriction=None, preprocess=None, **kwargs):
    if 'default' not in kwargs:
        kwargs['default'] = Coord(0,0)
    R = RESTRICT_COORD & restriction
    P = ProcessorTypeCast(Coord) + preprocess
    return RestrictedParameter(local_name, restriction=R, preprocess=P, **kwargs)


Esempio n. 12
0
def VModelProcessFlowParameter(local_name=None, restriction=None, **kwargs):
    R = RestrictType(VModelProcessFlow) & restriction
    return RestrictedParameter(local_name, restriction=R, **kwargs)
Esempio n. 13
0
def LayerParameter(local_name=None, restriction=None, **kwargs):
    R = RestrictType(__Layer__) & restriction
    return RestrictedParameter(local_name, restriction=R, **kwargs)
Esempio n. 14
0
def ProcessParameter(local_name=None, restriction=None, **kwargs):
    R = RestrictType(ProcessLayer) & restriction
    return RestrictedParameter(local_name, restriction=R, **kwargs)
Esempio n. 15
0
def PurposeLayerParameter(local_name=None, restriction=None, **kwargs):
    R = RestrictType(PurposeLayer) & restriction
    return RestrictedParameter(local_name, restrictions=R, **kwargs)