Example #1
0
class RendererObjectManager(object):
    '''
    ABSTRACT CLASS DO NOT DIRECTLY INSTANTIATE
    Abstracts the commonality between all the 
    object managers. Chiefly important attributes.
    '''
    lock = threading.RLock()
    max_radius_of_view = 360  # in degrees
    # Used to distinguish between different renderers, so we can have sets of them.
    s_index = 0

    update_type = enum(Reset=0, UpdatePositions=1, UpdateImages=2)

    def compare_to(self, render_object_manager):
        raise NotImplementedError("Not implemented")

    def draw(self, gl):
        if self.enabled and self.render_state.radius_of_view <= self.max_radius_of_view:
            self.draw_internal(gl)

    def queue_for_reload(self, bool_full_reload):
        self.listener(self, bool_full_reload)

    def __init__(self, new_layer, new_texture_manager):
        '''
        Constructor
        '''
        self.layer = new_layer
        self.texture_manager = new_texture_manager
        self.enabled = True
        self.render_state = None
        self.listener = None
        with self.lock:
            self.index = self.s_index + 1
Example #2
0
class DragRotateZoomGestureDetector(object):
    '''
    Handles events such as key presses and mouse button
    presses, which allows for dragging and zooming
    '''
    STATES = enum(READY=0, DRAGGING=1, DRAGGING2=2)
    
    def on_motion_event(self, event):
        '''
        The state changes are as follows.
        READY -> DRAGGING -> DRAGGING2 -> READY
        
        ACTION_DOWN: READY->DRAGGING
           last position = current position
        
        ACTION_MOVE: no state change
           calculate move = current position - last position
           last position = current position
        
        ACTION_UP: DRAGGING->READY
           last position = null
           ...or...from DRAGGING
        
        ACTION_POINTER_DOWN: DRAGGING->DRAGGING2
           we're in multitouch mode
           last position1 = current position1
           last poisiton2 = current position2
        
         ACTION_MOVE:
           calculate move
           last position1 = current position1
           
        NOTE: MULTITOUCH (DRAGGING2) IS NOT IMPLEMENTED YET
        '''
        ACTION_DOWN = QtCore.QEvent.MouseButtonPress
        ACTION_UP = QtCore.QEvent.MouseButtonRelease
        ACTION_MOVE = QtCore.QEvent.MouseMove
        
        if event.type() == QtCore.QEvent.KeyPress:
            self.key_press_event(event)
            return True
        
        if event.type() == ACTION_DOWN and self.state == self.STATES.READY:
            self.show_menu_bool = True
            self.state = self.STATES.DRAGGING
            self.last_x1, self.last_y1 = event.x(), event.y()
            return True
        
        if event.type() == ACTION_MOVE and self.state == self.STATES.DRAGGING:
            self.show_menu_bool = False
            current_x, current_y = event.x(), event.y()
            self.map_mover.on_drag(current_x - self.last_x1, current_y - self.last_y1)
            self.last_x1, self.last_y1 = current_x, current_y
            return True
        
        if event.type() == ACTION_UP and self.state != self.STATES.READY:
            
            if self.show_menu_bool:
                self.show_menus()
                self.show_menu_bool = False
                
            self.state = self.STATES.READY
            return True
                
        return False
        
    def key_press_event(self, event):
        if event.key() == 16777235: # up key, zoom in
            self.map_mover.control_group.zoom_in()
        elif event.key() == 16777237: # down key, zoom out
            self.map_mover.control_group.zoom_out()
        elif event.key() == 65: # "a" key, rotate left
            self.map_mover.control_group.change_right_left(-math.pi/64.0)
        elif event.key() == 68: # "d" key, rotate right
            self.map_mover.control_group.change_right_left(math.pi/64.0)
        elif event.key() == 87: # "w" key, rotate up
            self.map_mover.control_group.change_up_down(-math.pi/64.0)
        elif event.key() == 83: # "s" key, rotate down
            self.map_mover.control_group.change_up_down(math.pi/64.0)
    
    def norm_squared(self, x, y):
        return (x*x + y*y)

    def show_menus(self):
        # This function should be assigned upon instantiation
        raise Exception

    def __init__(self, map_mover, show_menus_func):
        '''
        Constructor
        '''
        self.map_mover = map_mover
        self.state = self.STATES.READY
        self.last_x1, self.last_y1 = 0, 0
        self.last_x2, self.last_y2 = 0, 0
        
        self.show_menu_bool = False
        self.show_menus = show_menus_func
        
Example #3
0
@author: Neil Borle
'''

import time
import math
from OrbitalElements import OrbitalElements
from src.base.TimeConstants import MILLISECONDS_PER_DAY, MILLISECONDS_PER_WEEK, MILLISECONDS_PER_HOUR
from src.units.RaDec import RaDec, calculate_ra_dec_dist
from src.units.GeocentricCoordinates import get_instance as gc_get_instance
from src.units.HeliocentricCoordinates import get_instance as hc_get_instance
from src.utils import Geometry as Geometry
from src.utils.Enumeration import enum
from src.utils.TimeUtil import julian_centuries, calculate_julian_day

#Enum that identifies whether we are interested in rise or set time.
rise_set_indicator = enum(RISE=0, SET=1)
    
planet_enum = enum(MERCURY=0, VENUS=1, SUN=2, MARS=3, 
              JUPITER=4, SATURN=5, URANUS=6, 
              NEPTUNE=7, PLUTO=8, MOON=9)

res = {0 : ["mercury", "Mercury", 1 * MILLISECONDS_PER_DAY],
       1 : ["venus", "Venus", 1 * MILLISECONDS_PER_DAY],
       2 : ["sun", "Sun", 1 * MILLISECONDS_PER_DAY],
       3 : ["mars", "Mars", 1 * MILLISECONDS_PER_DAY],
       4 : ["jupiter", "Jupiter", 1 * MILLISECONDS_PER_WEEK],
       5 : ["saturn", "Saturn", 1 * MILLISECONDS_PER_WEEK],
       6 : ["uranus", "Uranus", 1 * MILLISECONDS_PER_WEEK],
       7 : ["neptune", "Neptune", 1 * MILLISECONDS_PER_WEEK],
       8 : ["pluto", "Pluto", 1 * MILLISECONDS_PER_WEEK],
       9 : ["moon4", "Moon", 1 * MILLISECONDS_PER_HOUR]}
Example #4
0
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.


Created on 2013-05-16

@author: Neil Borle
'''

from Source import Source
from src.utils.Enumeration import enum
from src.units.GeocentricCoordinates import get_instance

shape_enum = enum(CIRCLE=0, STAR=1, ELLIPTICAL_GALAXY=2, \
                      SPIRAL_GALAXY=3, IRREGULAR_GALAXY=4, \
                      LENTICULAR_GALAXY=3, GLOBULAR_CLUSTER=5, \
                      OPEN_CLUSTER=6, NEBULA=7, HUBBLE_DEEP_FIELD=8)


class PointSource(Source):
    '''
    This class represents a astronomical point source, 
    such as a star, or a distant galaxy.
    '''

    def __init__(self, new_color, new_size, geo_coords=get_instance(0.0, 0.0), \
                 new_shape=shape_enum.CIRCLE):
        '''
        Constructor
        '''
        Source.__init__(self, new_color, geo_coords)
Example #5
0
        
    def queue_objects(self, sources, update_type, controller):
        def run_method():
            self.manager.update_objects(sources, update_type)
        
        msg = "Setting source objects"
        controller.queue_runnable(msg, command_type.DATA, Runnable(run_method))
    
    def __init__(self, mgr):
        '''
        constructor
        '''
        # Render Object Manager
        self.manager = mgr
        
command_type = enum(VIEW=0, DATA=1, SYNCHRONIZATION=3)

class RendererControllerBase(object):
    '''
    Base class in that it provides the basic functions
    for dealing with object managers.
    '''
    
    def create_point_manager(self, layer_id):
        manager = RenderManager(self.renderer.create_point_manager(layer_id))
        self.queue_add_manager(manager)
        return manager
        
    def create_line_manager(self, layer_id):
        manager = RenderManager(self.renderer.create_line_manager(layer_id))
        self.queue_add_manager(manager)
Example #6
0
Created on 2013-05-17

@author: Neil Borle
'''

import math
from src.units.HeliocentricCoordinates import HeliocentricCoordinates, get_instance as hc_get_instance
from src.utils.Geometry import mod_2_pi, radians_to_degrees
from src.utils.Enumeration import enum

planet_enum = enum(MERCURY=0,
                   VENUS=1,
                   SUN=2,
                   MARS=3,
                   JUPITER=4,
                   SATURN=5,
                   URANUS=6,
                   NEPTUNE=7,
                   PLUTO=8,
                   MOON=9)


def get_instance(geo_coord=None, earth_coord=None, planet=None, time=None):
    '''
    Returns a RaDec instance given either geocentric coordinates
    or heliocentric coordinates with a planet and the time.
    '''

    if geo_coord == None and earth_coord == None:
        raise Exception("must provide geo_coords or helio_coords")
    if geo_coord != None:
Example #7
0
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.


Created on 2013-05-16

@author: Neil Borle
'''

from src.units.GeocentricCoordinates import get_instance
from src.utils.Enumeration import enum

update_granularity = enum(Second=0, Minute=1, Hour=2, Day=3, Month=4, Year=5)

class Source(object):
    '''
    Base class for all sources since every source has features such
    as position, color and granularity
    '''

    def __init__(self, new_color, geo_coords=get_instance(0.0, 0.0)):
        '''
        Constructor
        '''
        self.color = new_color
        self.geocentric_coords = geo_coords
        self.granulatriy = None
        self.name_list = []
Example #8
0
   See the License for the specific language governing permissions and
   limitations under the License.


Created on 2013-05-17

@author: Neil Borle
'''

import math
from src.units.HeliocentricCoordinates import HeliocentricCoordinates, get_instance as hc_get_instance
from src.utils.Geometry import mod_2_pi, radians_to_degrees
from src.utils.Enumeration import enum

planet_enum = enum(MERCURY=0, VENUS=1, SUN=2, MARS=3, 
              JUPITER=4, SATURN=5, URANUS=6, 
              NEPTUNE=7, PLUTO=8, MOON=9)

def get_instance(geo_coord=None, earth_coord=None,
                 planet=None, time=None):
    '''
    Returns a RaDec instance given either geocentric coordinates
    or heliocentric coordinates with a planet and the time.
    '''
    
    if geo_coord == None and earth_coord == None: 
        raise Exception("must provide geo_coords or helio_coords")
    if geo_coord != None:
        raRad = math.atan2(geo_coord.y, geo_coord.x)
        if (raRad < 0): raRad += math.pi * 2.0
        decRad = math.atan2(geo_coord.z,
Example #9
0
Created on 2013-05-16

@author: Neil Borle
"""

from Source import Source
from src.utils.Enumeration import enum
from src.units.GeocentricCoordinates import get_instance

shape_enum = enum(
    CIRCLE=0,
    STAR=1,
    ELLIPTICAL_GALAXY=2,
    SPIRAL_GALAXY=3,
    IRREGULAR_GALAXY=4,
    LENTICULAR_GALAXY=3,
    GLOBULAR_CLUSTER=5,
    OPEN_CLUSTER=6,
    NEBULA=7,
    HUBBLE_DEEP_FIELD=8,
)


class PointSource(Source):
    """
    This class represents a astronomical point source, 
    such as a star, or a distant galaxy.
    """

    def __init__(self, new_color, new_size, geo_coords=get_instance(0.0, 0.0), new_shape=shape_enum.CIRCLE):
        """
Example #10
0
@author: Neil Borle
"""

import time
import math
from OrbitalElements import OrbitalElements
from src.base.TimeConstants import MILLISECONDS_PER_DAY, MILLISECONDS_PER_WEEK, MILLISECONDS_PER_HOUR
from src.units.RaDec import RaDec, calculate_ra_dec_dist
from src.units.GeocentricCoordinates import get_instance as gc_get_instance
from src.units.HeliocentricCoordinates import get_instance as hc_get_instance
from src.utils import Geometry as Geometry
from src.utils.Enumeration import enum
from src.utils.TimeUtil import julian_centuries, calculate_julian_day

# Enum that identifies whether we are interested in rise or set time.
rise_set_indicator = enum(RISE=0, SET=1)

planet_enum = enum(MERCURY=0, VENUS=1, SUN=2, MARS=3, JUPITER=4, SATURN=5, URANUS=6, NEPTUNE=7, PLUTO=8, MOON=9)

res = {
    0: ["mercury", "Mercury", 1 * MILLISECONDS_PER_DAY],
    1: ["venus", "Venus", 1 * MILLISECONDS_PER_DAY],
    2: ["sun", "Sun", 1 * MILLISECONDS_PER_DAY],
    3: ["mars", "Mars", 1 * MILLISECONDS_PER_DAY],
    4: ["jupiter", "Jupiter", 1 * MILLISECONDS_PER_WEEK],
    5: ["saturn", "Saturn", 1 * MILLISECONDS_PER_WEEK],
    6: ["uranus", "Uranus", 1 * MILLISECONDS_PER_WEEK],
    7: ["neptune", "Neptune", 1 * MILLISECONDS_PER_WEEK],
    8: ["pluto", "Pluto", 1 * MILLISECONDS_PER_WEEK],
    9: ["moon4", "Moon", 1 * MILLISECONDS_PER_HOUR],
}
Example #11
0
    def queue_objects(self, sources, update_type, controller):
        def run_method():
            self.manager.update_objects(sources, update_type)

        msg = "Setting source objects"
        controller.queue_runnable(msg, command_type.DATA, Runnable(run_method))

    def __init__(self, mgr):
        '''
        constructor
        '''
        # Render Object Manager
        self.manager = mgr


command_type = enum(VIEW=0, DATA=1, SYNCHRONIZATION=3)


class RendererControllerBase(object):
    '''
    Base class in that it provides the basic functions
    for dealing with object managers.
    '''
    def create_point_manager(self, layer_id):
        manager = RenderManager(self.renderer.create_point_manager(layer_id))
        self.queue_add_manager(manager)
        return manager

    def create_line_manager(self, layer_id):
        manager = RenderManager(self.renderer.create_line_manager(layer_id))
        self.queue_add_manager(manager)