0001"""
0002**point** which can be picked and moved, with movement constrained 
0003to a given geometric object
0004
0005"""
0006__Def__ =          ['Slider']
0007
0008__Classes__ =      [ 'LineSlider', 'PlaneSlider','CircleSlider',
0009                    'SphereSlider']
0010
0011__all__= __Classes__ + __Def__
0012
0013__doc_hints__=  {'m_type':'factory'}
0014
0015import pygeo.base.abstracts._real as Real
0016
0017from pygeo.base.analytics.pygeomath import vector, sin, cos, PI
0018from pygeo.base.abstracts._element import Element
0019
0020
0021class LineSlider(Real._FreePosition):
0022    """
0023*point* that can be picked and moved, with movement constrained 
0024to given **line**
0025    
0026    inherits
0027    
0028        `_Point`__
0029
0030__ base.abstracts._real._Point.html        
0031    
0032    """
0033    __doc_hints__=  {'factory':'Slider',
0034                    'args':['line <ratio=numeric>'],
0035                    'default': 'midpoint (i.e. ratio=.5)'}
0036
0037    __opts__= Real._FreePosition.__opts__[:] + ["ratio"]
0038
0039    def __init__(self,line,**kws):
0040        self.line=line
0041        self.t=kws.get('ratio',.5)
0042        Real._FreePosition.__init__(self,*[line],**kws)
0043        self.extend=kws.get("extend",True)
0044        self.lines=[line]
0045        self.init()
0046
0047    def init(self):
0048        self.toInterpolated(self.line.p1,self.line.p2,self.t)
0049        Element.init(self)
0050
0051    def setext(self):
0052        self.line.get_extension(self)
0053        self.line._redraw()
0054
0055    def findSelf(self):
0056        self.toLine(self.line.p1,self.line.p2)
0057        self.line._redraw()
0058        return True
0059
0060    def reset(self):
0061        self.init()
0062        Real._Point.update(self)
0063
0064
0065class PlaneSlider(Real._FreePosition):
0066    """
0067*point* which can be picked and moved,  with movement constrained 
0068to given **plane**
0069
0070    inherits
0071    
0072        `_Point`__
0073
0074__ base.abstracts._real._Point.html        
0075
0076    """
0077
0078    __doc_hints__=  {'factory':'Slider',
0079                    'args':['plane <,[numeric,numeric,numeric]>'],
0080                    'default': 'point on plane closest to the origin'}
0081
0082    def __init__(self,plane,*args,**kws):
0083        self.plane=plane
0084        args=[plane]+list(args)
0085        Real._FreePosition.__init__(self,*args,**kws)
0086        self.init()
0087
0088    def findSelf(self):
0089        return self.toPlane(self.plane)
0090
0091
0092class CircleSlider(Real._FreePosition):
0093    """
0094*point* which can be picked and moved, with movement constrained to 
0095given **circle**
0096
0097    inherits
0098    
0099        `_Point`__
0100
0101__ base.abstracts._real._Point.html        
0102
0103    """
0104
0105    __doc_hints__=  {'factory':'Slider',
0106                    'args':['circle <,angle=numeric>'],
0107                    'default': "point on circle rotated PI from circle's cpoint"}
0108
0109    __opts__= Real._FreePosition.__opts__[:] + ["angle"]
0110
0111    def __init__(self,circle,**kws):
0112        self.circle=circle
0113        self.angle=kws.get('angle',PI)
0114        Real._FreePosition.__init__(self,*[circle],**kws)
0115        self.init()
0116
0117    def findSelf(self):
0118        return self.toCircle(self.circle)
0119
0120    def init(self):
0121        self.set(self.circle._cpoint)
0122        self.toCircumPoint(self.circle,self.angle)
0123        Element.init(self)
0124
0125    def reset(self):
0126        self.init()
0127        Real._Point.update(self)
0128
0129
0130class SphereSlider(Real._FreePosition):
0131    """
0132point which can be picked and moved, with movement constrained to 
0133given sphere
0134
0135    inherits
0136    
0137        `_Point`__
0138
0139__ base.abstracts._real._Point.html        
0140
0141    """
0142
0143    __doc_hints__=  {'factory':'Slider',
0144                    'args':['sphere <,theta=numeric><,phi=numeric>'],
0145                    'default': 'theta = PI, phi = PI'}
0146    __opts__= Real._FreePosition.__opts__[:] + ["theta","phi"]
0147
0148    def __init__(self,sphere,**kws):
0149        self.sphere=sphere
0150        self.theta=kws.get('theta',PI)
0151        self.phi=kws.get('phi',PI)
0152        Real._FreePosition.__init__(self,*[sphere],**kws)
0153        self.init()
0154
0155    def findSelf(self):
0156        return self.toSphere(self.sphere)
0157
0158    def reset(self):
0159        self.init()
0160        Real._Point.update(self)
0161
0162    def init(self):
0163        x=sin(self.theta)*cos(self.phi)
0164        y=sin(self.theta)*sin(self.phi)
0165        z=cos(self.theta)
0166        self.set(vector(x,y,z)*self.sphere._radius+self.sphere._center)
0167        Element.init(self)
0168
0169def  Slider(*args,**kws):
0170    """
0171'class factory' function returns instance of object derived from the _Point 
0172abstract class which can be picked, with movement constrained to a given 
0173geometric object
0174    """
0175
0176    from pygeo.base.abstracts._element import method_get
0177    from pygeo.base.support.pygeoexceptions import Argument_Type_Error
0178
0179    __sigs__ = [[Real._Line],[Real._Plane],
0180               [Real._Plane,float,float,float],
0181               [Real._Circle,float,float,float],
0182               [Real._Plane,list],[Real._Plane,tuple],
0183               [Real._Circle,list],[Real._Circle,tuple],
0184               [Real._Circle],[Real._Sphere]]
0185    t,i = method_get(__sigs__,args)
0186
0187    if t is None:
0188        raise Argument_Type_Error(__sigs__,args)
0189    else:
0190        if i == 0:
0191            return LineSlider(t[0],**kws)
0192        elif i==1:
0193            return PlaneSlider(t[0],**kws)
0194        elif i==2 or i==3:
0195            return PlaneSlider(t[0],t[1],t[2],t[3],**kws)
0196        elif i==4 or i==5 or i==6 or i==7:
0197            return PlaneSlider(t[0],t[1][0],t[1][1],t[1][1],**kws)
0198        elif i==8:
0199            return CircleSlider(t[0],**kws)
0200        elif i==9:
0201            return SphereSlider(t[0],**kws)
0202        else:
0203            raise Argument_Type_Error(__sigs__,args)