コード例 #1
0
ファイル: car_controller.py プロジェクト: fpeterek/car-client
 def add_waypoint(self, waypoint: Waypoint) -> None:
     with self.waypoints_lock:
         orig_pos = Position(lat=waypoint.lat, lon=waypoint.lon)
         adjusted_position, path = self.map.closest_point(orig_pos)
         waypoint.path = path
         waypoint.lat = adjusted_position.lat
         waypoint.lon = adjusted_position.lon
         self.waypoints.append(waypoint)
         self.on_waypoint_change()
コード例 #2
0
ファイル: __init__.py プロジェクト: konne88/Lotse
    def load_persistent(self):
        try:

            file = open(os.path.join(self.settingsdir,'persist.xml'), 'r')
        
            doc = xml.parse(file)
            if doc.documentElement.tagName == 'session':
                waypoint_list = doc.getElementsByTagName('waypoints')[0]
                sources = waypoint_list.getElementsByTagName('source')
                for source in sources:
                    currentSource = Source(source.getAttribute('type'))
                    if currentSource.name == "Manual Waypoints":
                        self.manualSource = currentSource
                        
                    sourceIter = self.wpList.append(None,(currentSource,))                                   

                    waypoints=source.getElementsByTagName('wp')                    
                    for waypoint in waypoints:
                        wp=Waypoint()
                        name_element = \
                            waypoint.getElementsByTagName('name')[0]
                        lat_element = \
                            waypoint.getElementsByTagName('latitude')[0]
                        lon_element = \
                            waypoint.getElementsByTagName('longitude')[0]
                        alt_element = \
                            waypoint.getElementsByTagName('altitude')[0]
                        
                        wp.name = string.strip(name_element.firstChild.data)
                        wp.lat=float(lat_element.firstChild.data)
                        wp.lon=float(lon_element.firstChild.data)                        
                        wp.alt=float(alt_element.firstChild.data)
                        #print '---'+wp.name
                        #Append Waypoint to correct Source Object
                        self.wpList.append(sourceIter,(wp,))
                        
            #if document is empty or contains garbage raise IOError   after cleaning up                    
            else:
                doc.unlink()
                file.close()
                raise IOError
                
            doc.unlink()
            file.close()
            return True
        except(IOError):
            #The File is not available for reading so insert standard Source into the list
            currentSource = Source('Manual Waypoints')
            self.manualSource = currentSource
            self.wpList.append(None,(currentSource,))
            return False
コード例 #3
0
ファイル: waypointloader.py プロジェクト: konne88/Lotse
    def load_from_file(self, filename):
        try:
            file = open(filename, 'r')
        
            doc = xml.parse(file)
            currentSource = Source(os.path.basename(filename))
            sourceIter = self.wpList.append(None,(currentSource,))       
            
            if doc.documentElement.tagName == 'gpx':
                waypoints = doc.getElementsByTagName('wpt')                
                for waypoint in waypoints:                    

                        wp=Waypoint()
                        wp.lat=float(waypoint.getAttribute('lat'))
                        wp.lon=float(waypoint.getAttribute('lon'))  
                        
                        alt_element = \
                            waypoint.getElementsByTagName('ele')
                        if alt_element.length > 0:
                            wp.alt=float(alt_element[0].firstChild.data)

                        name_element = \
                            waypoint.getElementsByTagName('name')
                        if name_element.length > 0:
                            wp.name = string.strip(name_element[0].firstChild.data)
                        
                        
                        #Append Waypoint to correct Source Object
                        self.wpList.append(sourceIter,(wp,))
                        
            #if document is empty or contains garbage raise IOError   after cleaning up                    
            else:
                doc.unlink()
                file.close()
                raise IOError
                
            doc.unlink()
            file.close()
            return True
        except(IOError):

            return False