0001"""
0002**points** pickable and movable constrained to the Riemann sphere or an object
0003on the sphere
0004"""
0005
0006__Def__ = ['uSlider']
0007
0008__Classes__ = ['uSphereSlider', 'uCircleSlider']
0009
0010
0011__all__ = __Classes__ + __Def__
0012
0013__doc_hints__={'m_type':'factory'}
0014
0015import pygeo.base.abstracts._usphere as USphere
0016from pygeo.base.abstracts._element import Element
0017
0018from pygeo.base.analytics.pygeomath import sin, cos, PI, vector
0019
0020
0021class uSphereSlider(USphere._uFreePosition):
0022    """
0023*point* of the Riemann sphere that can be picked and moved
0024constrained to the sphere and with initial position at the given 
0025**spherical coordinates**, in radians 
0026    
0027    
0028    inherits
0029    
0030        `_uPoint`__
0031
0032__ class-base.abstracts._usphere._uPoint.html        
0033    
0034    """
0035
0036    __doc_hints__=  {'factory':'uSlider',
0037                    'args':['float,<float>', '<theta = float> <,phi= float>']}
0038
0039    __opts__= USphere._uFreePosition.__opts__[:] + ["theta","phi"]
0040
0041    def __init__(self,theta=PI/2,phi=PI/2,**kws):
0042        self.theta=theta
0043        self.phi=phi
0044        USphere._uFreePosition.__init__(self,**kws)
0045        self.init()
0046
0047    def findSelf(self):
0048        try:
0049            factor=1.0/self.mag
0050            self.set(self*factor)
0051        except ZeroDivisionError:
0052            self.set(vector(0,0,1))
0053        return True
0054
0055    def init(self):
0056        x=sin(self.theta)*cos(self.phi)
0057        y=sin(self.theta)*sin(self.phi)
0058        z=cos(self.theta)
0059        self.set(vector(x,y,z))
0060        Element.init(self)
0061
0062class uCircleSlider(USphere._uFreePosition):
0063    """
0064*point* of the given spheric section of the Riemann sphere that can
0065be picked and moved constrained to the **spheric section** , with its initial position
0066determined by optinal **float** argument, in radians
0067    
0068    
0069    inherits
0070    
0071        `_uPoint`__
0072
0073__ class-base.abstracts._usphere._uPoint.html        
0074    
0075    """
0076
0077    __doc_hints__=  {'factory':'uSlider',
0078                    'args':['zcircle <,float>']}
0079
0080    __opts__= USphere._uFreePosition.__opts__[:] + ["angle"]
0081
0082    def __init__(self,ucircle,angle=PI,**kws):
0083        self.ucircle=ucircle
0084        self.angle=angle
0085        USphere._uFreePosition.__init__(self,*[ucircle],**kws)
0086        self.init()
0087
0088    def init(self):
0089        self.set(self.ucircle._cpoint)
0090        self.toCircumPoint(self.ucircle,self.angle)
0091        Element.init(self)
0092
0093    def findSelf(self):
0094       self.toCircle(self.ucircle)
0095       return True
0096
0097def uSlider(*args,**kws):
0098    """
0099'class factory' function returns instance of object derived from the 
0100_uPoint abstract class representing points of the Riemann sphere that can
0101be picked and moved on the sphere or constrained to an object on the sphere.
0102    
0103    """
0104
0105    from pygeo.base.abstracts._element import method_get
0106    from pygeo.base.support.pygeoexceptions import Argument_Type_Error
0107
0108    __sigs__=[[],[float],[float,float],
0109              [USphere._uCircle],[USphere._uCircle,float]]
0110
0111    t,i = method_get(__sigs__,args)
0112
0113    if t is None:
0114        raise Argument_Type_Error(__sigs__,args)
0115    else:
0116        if i==0:
0117            return uSphereSlider(**kws)
0118        elif i==1:
0119            return uSphereSlider(t[0],**kws)
0120        elif i==2:
0121            return uSphereSlider(t[0],t[1],**kws)
0122        elif i==3:
0123            return uCircleSlider(t[0],**kws)
0124        elif i==4:
0125            return uCircleSlider(t[0],t[1],**kws)
0126        else:
0127            raise Argument_Type_Error(__sigs__,args)