├── .gitignore ├── AUTHORS ├── LICENSE ├── README.rst ├── config └── main.yaml ├── doc ├── IFRExample.jpg ├── Makefile ├── SectionalExample.jpg ├── conf.py └── toc.rst ├── gui └── __init__.py ├── hmi ├── __init__.py ├── actions.py ├── data.py ├── functions.py ├── keys.py └── menu.py ├── make_tiles └── make_tiles.py ├── pyAvMap.py ├── pyavmap ├── __init__.py └── avchart_proj.py ├── setup.py └── tests └── __init__.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.py~ 3 | config.py 4 | .DS_Store 5 | *.log 6 | .directory 7 | charts 8 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Garrett Herschleb 2 | Phil Birkelbach 3 | 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) year name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Lesser General Public 340 | License instead of this License. 341 | 342 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | MakerPlane Aviation Moving Map Package 2 | ====================================== 3 | 4 | Copyright (c) 2018-2019 MakerPlane 5 | 6 | pyAvMap is an open source moving map package for aviation. 7 | 8 | Example screen showing a Sectional type chart: |SecSample| 9 | 10 | Example screen showing an low enroute IFR type chart: |IFRSample| 11 | 12 | Installation 13 | ------------ 14 | 15 | Begin by cloning the Git repository 16 | 17 | git clone git@github.com:makerplane/pyAvMap.git 18 | 19 | .. 20 | 21 | git clone https://github.com/makerplane/pyAvMap.git 22 | 23 | If you’d like to install the program permanently to your system or into 24 | a virtualenv you can issue the command… 25 | 26 | sudo pip3 install . 27 | 28 | from the root directory of the source repository. **Caution** This 29 | feature is still in development and may not work consistently. 30 | 31 | Requirements 32 | ------------ 33 | 34 | Download chart(s) from FAA website. 35 | ``https://www.faa.gov/air_traffic/flight_info/aeronav/digital_products/`` 36 | 37 | :: 38 | 39 | Unzip them into pyAvMap/charts/Sectional/ # Should include *.tif and *.htm and *.tfw(x) 40 | cd pyAvMap/charts/Sectional/ 41 | pyAvMap/make_tiles/make_tiles.py # e.g. "Albuquerque SEC 101" 42 | rm pyAvMap/charts/Sectional//*.tif # after the tiles are created, you don't need the humongo tiff anymore 43 | 44 | The above example is for sectional charts. Other directory names for 45 | other chart types are: 1. IFR 1. Jet 1. Terminal 46 | 47 | Some IFR charts are laid out so that North is approximately in the width 48 | direction rather than the height direction. L-01 and L-02 are examples 49 | of this. In this case, add a second argument of “1” (the number without 50 | quotes) to the ``make_tiles.py`` command line, and that will rotate the 51 | chart so it’s oriented correctly. 52 | 53 | Dependencies 54 | ------------ 55 | 56 | The pyAvTools repo should be cloned adjacent to pyAvMap. You should use 57 | makerplane/pyAvTools. 58 | 59 | .. |SecSample| image:: https://raw.githubusercontent.com/Maker42/pyAvMap/master/doc/SectionalExample.jpg 60 | .. |IFRSample| image:: https://raw.githubusercontent.com/Maker42/pyAvMap/master/doc/IFRExample.jpg 61 | -------------------------------------------------------------------------------- /config/main.yaml: -------------------------------------------------------------------------------- 1 | main: 2 | # IP information for network adapter 3 | FixServer: 127.0.0.1 4 | FixPort: 3490 5 | screenWidth: 1000 6 | screenHeight: 700 7 | 8 | charts_dir: charts 9 | 10 | icon_scale: 0.5 11 | icon_fill: mediumorchid 12 | icon_outline: white 13 | icon_opacity: .9 14 | zoom: 1.0 15 | show_path: True 16 | chart_type: Sectional 17 | north_is_up: True 18 | extended_track_length: 200 19 | el_color: black 20 | 21 | displays: 22 | GPS: 23 | columns: 2 24 | keys: 25 | - TRACKM 26 | - GS 27 | description_overrides: 28 | - Mag Track 29 | - GS 30 | position: [-20, 20] 31 | css_styles: "background-color: gray;border-style: solid ;border-width: 2 ;border-color: black; color: darkblue" 32 | item_css_styles: "border-style: none" 33 | 34 | menu: 35 | menus: 36 | MainMenu: 37 | - ['Zoom', 'set menu focus', "ZOOM"] 38 | - ['Chart Type', 'set menu focus', "Chart Type"] 39 | - ['Debug', 'logging.getLogger().setLevel(1 if logging.getLogger().getEffectiveLevel() > 1 else logging.INFO)', None] 40 | start_menu: MainMenu 41 | number_of_buttons: 3 42 | buttons_spacing: 120 43 | left_margin: 100 44 | top_margin: 5 45 | 46 | # The keybindings are used to attach keystrokes to actions. The key can be 47 | # a string that represents a key Sequence. See the documentation for more 48 | # information about key sequences and actions. 49 | keybindings: 50 | - key: F1 51 | action: Activate Menu Item 52 | args: 1 53 | - key: F2 54 | action: Activate Menu Item 55 | args: 2 56 | - key: F3 57 | action: Activate Menu Item 58 | args: 3 59 | - key: F4 60 | action: Activate Menu Item 61 | args: 4 62 | - key: F5 63 | action: Activate Menu Item 64 | args: 5 65 | - key: F6 66 | action: Activate Menu Item 67 | args: 6 68 | 69 | # Data bindings tie actions to values in the database 70 | # key is the database key and should match the FIX Gateway key 71 | databindings: 72 | - key: BTN1 73 | condition: True 74 | action: Activate Menu Item 75 | args: 1 76 | - key: BTN2 77 | condition: True 78 | action: Activate Menu Item 79 | args: 2 80 | - key: BTN3 81 | condition: True 82 | action: Activate Menu Item 83 | args: 3 84 | - key: BTN4 85 | condition: True 86 | action: Activate Menu Item 87 | args: 4 88 | - key: BTN5 89 | condition: True 90 | action: Activate Menu Item 91 | args: 5 92 | - key: BTN6 93 | condition: True 94 | action: Activate Menu Item 95 | args: 6 96 | -------------------------------------------------------------------------------- /doc/IFRExample.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makerplane/pyAvMap/70fb9d700e2f6c313d010838eb142973b6d78100/doc/IFRExample.jpg -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = pyAvMap 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /doc/SectionalExample.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makerplane/pyAvMap/70fb9d700e2f6c313d010838eb142973b6d78100/doc/SectionalExample.jpg -------------------------------------------------------------------------------- /doc/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Configuration file for the Sphinx documentation builder. 4 | # 5 | # This file does only contain a selection of the most common options. For a 6 | # full list see the documentation: 7 | # http://www.sphinx-doc.org/en/master/config 8 | 9 | # -- Path setup -------------------------------------------------------------- 10 | 11 | # If extensions (or modules to document with autodoc) are in another directory, 12 | # add these directories to sys.path here. If the directory is relative to the 13 | # documentation root, use os.path.abspath to make it absolute, like shown here. 14 | # 15 | # import os 16 | # import sys 17 | # sys.path.insert(0, os.path.abspath('.')) 18 | 19 | 20 | # -- Project information ----------------------------------------------------- 21 | 22 | project = u'pyAvMap' 23 | copyright = u'2019, Garrett Herschleb, Phil Birkelbach' 24 | author = u'Garrett Herschleb, Phil Birkelbach' 25 | 26 | # The short X.Y version 27 | version = u'' 28 | # The full version, including alpha/beta/rc tags 29 | release = u'' 30 | 31 | 32 | # -- General configuration --------------------------------------------------- 33 | 34 | # If your documentation needs a minimal Sphinx version, state it here. 35 | # 36 | # needs_sphinx = '1.0' 37 | 38 | # Add any Sphinx extension module names here, as strings. They can be 39 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 40 | # ones. 41 | extensions = [ 42 | 'sphinx.ext.autodoc', 43 | ] 44 | 45 | # Add any paths that contain templates here, relative to this directory. 46 | templates_path = ['_templates'] 47 | 48 | # The suffix(es) of source filenames. 49 | # You can specify multiple suffix as a list of string: 50 | # 51 | # source_suffix = ['.rst', '.md'] 52 | source_suffix = '.rst' 53 | 54 | # The master toctree document. 55 | master_doc = 'toc' 56 | 57 | # The language for content autogenerated by Sphinx. Refer to documentation 58 | # for a list of supported languages. 59 | # 60 | # This is also used if you do content translation via gettext catalogs. 61 | # Usually you set "language" from the command line for these cases. 62 | language = None 63 | 64 | # List of patterns, relative to source directory, that match files and 65 | # directories to ignore when looking for source files. 66 | # This pattern also affects html_static_path and html_extra_path . 67 | exclude_patterns = [u'_build', 'Thumbs.db', '.DS_Store'] 68 | 69 | # The name of the Pygments (syntax highlighting) style to use. 70 | pygments_style = 'sphinx' 71 | 72 | 73 | # -- Options for HTML output ------------------------------------------------- 74 | 75 | # The theme to use for HTML and HTML Help pages. See the documentation for 76 | # a list of builtin themes. 77 | # 78 | html_theme = 'alabaster' 79 | 80 | # Theme options are theme-specific and customize the look and feel of a theme 81 | # further. For a list of options available for each theme, see the 82 | # documentation. 83 | # 84 | # html_theme_options = {} 85 | 86 | # Add any paths that contain custom static files (such as style sheets) here, 87 | # relative to this directory. They are copied after the builtin static files, 88 | # so a file named "default.css" will overwrite the builtin "default.css". 89 | html_static_path = ['_static'] 90 | 91 | # Custom sidebar templates, must be a dictionary that maps document names 92 | # to template names. 93 | # 94 | # The default sidebars (for documents that don't match any pattern) are 95 | # defined by theme itself. Builtin themes are using these templates by 96 | # default: ``['localtoc.html', 'relations.html', 'sourcelink.html', 97 | # 'searchbox.html']``. 98 | # 99 | # html_sidebars = {} 100 | 101 | 102 | # -- Options for HTMLHelp output --------------------------------------------- 103 | 104 | # Output file base name for HTML help builder. 105 | htmlhelp_basename = 'pyAvMapdoc' 106 | 107 | 108 | # -- Options for LaTeX output ------------------------------------------------ 109 | 110 | latex_elements = { 111 | # The paper size ('letterpaper' or 'a4paper'). 112 | # 113 | # 'papersize': 'letterpaper', 114 | 115 | # The font size ('10pt', '11pt' or '12pt'). 116 | # 117 | # 'pointsize': '10pt', 118 | 119 | # Additional stuff for the LaTeX preamble. 120 | # 121 | # 'preamble': '', 122 | 123 | # Latex figure (float) alignment 124 | # 125 | # 'figure_align': 'htbp', 126 | } 127 | 128 | # Grouping the document tree into LaTeX files. List of tuples 129 | # (source start file, target name, title, 130 | # author, documentclass [howto, manual, or own class]). 131 | latex_documents = [ 132 | (master_doc, 'pyAvMap.tex', u'pyAvMap Documentation', 133 | u'Garrett Herschleb, Phil Birkelbach', 'manual'), 134 | ] 135 | 136 | 137 | # -- Options for manual page output ------------------------------------------ 138 | 139 | # One entry per manual page. List of tuples 140 | # (source start file, name, description, authors, manual section). 141 | man_pages = [ 142 | (master_doc, 'pyavmap', u'pyAvMap Documentation', 143 | [author], 1) 144 | ] 145 | 146 | 147 | # -- Options for Texinfo output ---------------------------------------------- 148 | 149 | # Grouping the document tree into Texinfo files. List of tuples 150 | # (source start file, target name, title, author, 151 | # dir menu entry, description, category) 152 | texinfo_documents = [ 153 | (master_doc, 'pyAvMap', u'pyAvMap Documentation', 154 | author, 'pyAvMap', 'One line description of project.', 155 | 'Miscellaneous'), 156 | ] 157 | 158 | 159 | # -- Extension configuration ------------------------------------------------- -------------------------------------------------------------------------------- /doc/toc.rst: -------------------------------------------------------------------------------- 1 | .. pyAvMap documentation master file, created by 2 | sphinx-quickstart on Wed Feb 6 13:58:50 2019. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to pyAvMap's documentation! 7 | =================================== 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | :caption: Contents: 12 | 13 | 14 | 15 | Indices and tables 16 | ================== 17 | 18 | * :ref:`genindex` 19 | * :ref:`modindex` 20 | * :ref:`search` 21 | -------------------------------------------------------------------------------- /gui/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2019 Garrett Herschleb 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation; either version 2 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; if not, write to the Free Software 15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 | 17 | try: 18 | from PyQt5.QtGui import * 19 | from PyQt5.QtCore import * 20 | from PyQt5.QtWidgets import * 21 | except: 22 | from PyQt4.QtGui import * 23 | from PyQt4.QtCore import * 24 | 25 | import logging 26 | log = logging.getLogger(__name__) 27 | import sys, os 28 | 29 | if "pyAvTools" not in ''.join(sys.path): 30 | neighbor_tools = os.path.join ('..', 'pyAvTools') 31 | if os.path.isdir (neighbor_tools): 32 | sys.path.append (neighbor_tools) 33 | elif 'TOOLS_PATH' in os.environ: 34 | sys.path.append (os.environ['TOOLS_PATH']) 35 | 36 | try: 37 | import pyavui 38 | except: 39 | print ("You need to have pyAvTools installed, or in an adjacent directory to pyAvMap.") 40 | print ("Or set the environment variable 'TOOLS_PATH' to point to the location of pyAvTools.") 41 | sys.exit(-1) 42 | 43 | class ChartTypeSel(pyavui.AVUI): 44 | def __init__(self, enc_key, enc_sel_key, chart_types, callback, parent=None, config=None): 45 | super(ChartTypeSel,self).__init__ (enc_key, enc_sel_key, parent) 46 | self.chart_types = chart_types 47 | self.callback = callback 48 | 49 | def resizeEvent(self, event): 50 | title = "Chart Type" 51 | self.ctsel_widget = pyavui.SelectMenuWidget(title, self.chart_types, self.change_chart_type, 52 | pyavui.SelectMenuWidget.MENU_ACTION_TYPE_FUNCTION, self.width(), self.height()) 53 | super(ChartTypeSel,self).resizeEvent (event) 54 | super(ChartTypeSel,self).set_widgets ([self.ctsel_widget]) 55 | 56 | def change_chart_type(self, i, ct_string): 57 | self.callback (ct_string) 58 | -------------------------------------------------------------------------------- /hmi/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018 Phil Birkelbach 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation; either version 2 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; if not, write to the Free Software 15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 | 17 | import logging 18 | 19 | from .actions import ActionClass 20 | from .menu import Menu 21 | from . import keys 22 | from . import data 23 | 24 | actions = None 25 | 26 | def initialize(config): 27 | global actions 28 | log = logging.getLogger(__name__) 29 | log.info("Initializing Actions") 30 | actions = ActionClass() 31 | 32 | if "databindings" in config: 33 | data.initialize(config["databindings"]) 34 | -------------------------------------------------------------------------------- /hmi/actions.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018 Phil Birkelbach; 2019 Garrett Herschleb 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation; either version 2 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; if not, write to the Free Software 15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 | 17 | try: 18 | from PyQt5.QtCore import * 19 | from PyQt5.QtGui import * 20 | from PyQt5.QtWidgets import * 21 | 22 | except: 23 | from PyQt4.QtCore import * 24 | from PyQt4.QtGui import * 25 | 26 | import hmi.functions 27 | 28 | class ActionClass(QWidget): 29 | activateMenuItem = pyqtSignal(object) 30 | setMenuFocus = pyqtSignal(object) 31 | evalExpression = pyqtSignal(object) 32 | 33 | def __init__(self): 34 | super(ActionClass, self).__init__() 35 | self.signalMap = {"activate menu item":self.activateMenuItem 36 | ,"set menu focus":self.setMenuFocus 37 | } 38 | 39 | 40 | def trigger(self, action, argument=""): 41 | a = self.signalMap[action.lower()] 42 | if isinstance(a, pyqtBoundSignal): 43 | a.emit(argument) 44 | else: # It's not a signal so assume it's a function 45 | a(argument) 46 | 47 | 48 | def findAction(self, action): 49 | a = action.lower() 50 | if a in self.signalMap: 51 | return self.signalMap[a] 52 | else: 53 | return None 54 | -------------------------------------------------------------------------------- /hmi/data.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018 Phil Birkelbach 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation; either version 2 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; if not, write to the Free Software 15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 | 17 | try: 18 | from PyQt5.QtCore import * 19 | from PyQt5.QtGui import * 20 | except: 21 | from PyQt4.QtCore import * 22 | from PyQt4.QtGui import * 23 | 24 | import logging 25 | log = logging.getLogger(__name__) 26 | 27 | 28 | import hmi 29 | 30 | __bindings = [] 31 | 32 | class DataBinding(object): 33 | def __init__(self, config): 34 | self.key = config['key'] 35 | self.condition = None 36 | self.args = "" 37 | self.__value = None 38 | 39 | a = config['action'] 40 | if hmi.actions.findAction(a): 41 | self.action = a 42 | else: 43 | log.error("Action Not Found - {}".format(a)) 44 | return None 45 | 46 | if 'args' in config: 47 | self.args = config['args'] 48 | if self.args == None: self.args = "" 49 | 50 | 51 | def __str__(self): 52 | s = "Data Binding: {} - {}({})".format(self.key, self.action, self.args) 53 | return(s) 54 | 55 | def initialize(config): 56 | for x in config: 57 | try: 58 | d = DataBinding(x) 59 | print(d) 60 | except: 61 | log.error("Unable to load Data Binding {}".format(x)) 62 | raise 63 | -------------------------------------------------------------------------------- /hmi/functions.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018 Phil Birkelbach 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation; either version 2 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; if not, write to the Free Software 15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 | 17 | import pyavtools.fix as fix 18 | 19 | # Set a value in the FIX database. arg should be "key,value" 20 | def setValue(arg): 21 | args = arg.split(',') 22 | fix.db.set_value(args[0].strip(), args[1].strip()) 23 | -------------------------------------------------------------------------------- /hmi/keys.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018 Phil Birkelbach 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation; either version 2 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; if not, write to the Free Software 15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 | 17 | try: 18 | from PyQt5.QtCore import * 19 | from PyQt5.QtGui import * 20 | except: 21 | from PyQt4.QtCore import * 22 | from PyQt4.QtGui import * 23 | 24 | import logging 25 | log = logging.getLogger(__name__) 26 | 27 | 28 | import hmi 29 | 30 | __keypress = [] 31 | __keyrelease = [] 32 | 33 | class KeyBinding(object): 34 | def __init__(self, config): 35 | self.key = QKeySequence(config['key']) 36 | self.args = "" 37 | self.direction = 'DN' 38 | 39 | if self.key.toString() == '': 40 | log.error("Invalid Key {}".format(config['key'])) 41 | return None 42 | a = config['action'] 43 | if hmi.actions.findAction(a): 44 | self.action = a 45 | else: 46 | log.error("Action Not Found - {}".format(a)) 47 | return None 48 | if 'args' in config: 49 | self.args = config['args'] 50 | if self.args == None: self.args = "" 51 | if 'direction' in config: 52 | d = config['direction'].lower() 53 | if d == 'up': 54 | self.direction = "UP" 55 | 56 | def __str__(self): 57 | s = "Key Binding: {} - {}({})".format(self.key.toString(), self.action, self.args) 58 | return(s) 59 | 60 | 61 | def keyPress(event): 62 | for each in __keypress: 63 | if event.key() == each.key and not event.isAutoRepeat(): 64 | hmi.actions.trigger(each.action, each.args) 65 | 66 | 67 | def keyRelease(event): 68 | for each in __keyrelease: 69 | if event.key() == each.key and not event.isAutoRepeat(): 70 | hmi.actions.trigger(each.action, each.args) 71 | 72 | 73 | def initialize(window, config): 74 | for x in config: 75 | try: 76 | k = KeyBinding(x) 77 | except: 78 | log.error("Unable to load Key Binding {}".format(x)) 79 | if k: 80 | if k.direction == 'DN': 81 | __keypress.append(k) 82 | else: 83 | __keyrelease.append(k) 84 | 85 | 86 | window.keyPress.connect(keyPress) 87 | window.keyRelease.connect(keyRelease) 88 | -------------------------------------------------------------------------------- /hmi/menu.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018-2019 Garrett Herschleb 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation; either version 2 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; if not, write to the Free Software 15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 | 17 | try: 18 | from PyQt5.QtGui import * 19 | from PyQt5.QtCore import * 20 | from PyQt5.QtWidgets import * 21 | except: 22 | from PyQt4.QtGui import * 23 | from PyQt4.QtCore import * 24 | 25 | import logging 26 | 27 | #import hooks 28 | import pyavtools.fix as fix 29 | import hmi 30 | 31 | logger=logging.getLogger(__name__) 32 | 33 | # TheMenuObject=None 34 | 35 | class Menu(QWidget): 36 | def __init__(self, parent, config): 37 | global TheMenuObject 38 | super(Menu, self).__init__(parent) 39 | self.config = config 40 | self.myparent = parent 41 | self.registered_targets = dict() 42 | self.buttons = list() 43 | self.button_actions = list() 44 | self.button_args = list() 45 | self.focused_object = None 46 | self.focus_button = -1 47 | self.last_button_clicked = -1 48 | last_x = self.config['left_margin'] 49 | self.avmap = None 50 | for b in range(self.config['number_of_buttons']): 51 | self.buttons.append(QPushButton("", self)) 52 | self.button_actions.append(None) 53 | self.button_args.append(None) 54 | button_function = eval("self.button_clicked" + str(b+1)) 55 | self.buttons[-1].clicked.connect(button_function) 56 | self.buttons[-1].move (last_x, self.config['top_margin']) 57 | last_x += self.config['buttons_spacing'] 58 | 59 | #button_function = buttonFactory(b) 60 | #button_function = eval("button" + str(b+1)) 61 | #fix.db.get_item("BTN" + str(b+1), True).valueChanged[bool].connect(buttonFactory(b)) 62 | self.adjustSize() 63 | self.register_target("ZOOM", ZoomProxy()) 64 | # TheMenuObject = self 65 | hmi.actions.activateMenuItem.connect(self.activateMenuItem) 66 | hmi.actions.setMenuFocus.connect(self.focus) 67 | 68 | def start(self): 69 | start_menu = self.config['start_menu'] 70 | self.activate_menu (start_menu) 71 | 72 | def activate_menu(self, menu_name): 73 | logger.debug ("Menu.activate_menu (%s)", menu_name) 74 | self.current_menu = self.config['menus'][menu_name] 75 | for i,(label,actions,args) in enumerate(self.current_menu): 76 | self.set_button (i, label, actions, args) 77 | self.buttons[i].show() 78 | last_i = i 79 | last_i += 1 80 | while last_i < len(self.buttons): 81 | self.buttons[last_i].hide() 82 | last_i += 1 83 | 84 | def register_target(self, key, obj): 85 | self.registered_targets[key] = obj 86 | 87 | def focus(self, target): 88 | former_focus = None 89 | if self.focused_object is not None: 90 | self.focused_object.defocus() 91 | self.buttons[self.focus_button].setText(self.current_menu[self.focus_button][0]) 92 | former_focus = self.focused_object 93 | self.focused_object = None 94 | if target is not None and ((former_focus is None) or (former_focus != self.registered_targets[target])): 95 | self.focused_object = self.registered_targets[target] 96 | self.focused_object.focus() 97 | self.focus_button = self.last_button_clicked 98 | self.buttons[self.focus_button].setText(self.current_menu[self.focus_button][0] + " Done") 99 | self.buttons[self.focus_button].adjustSize() 100 | else: 101 | self.focused_object = None 102 | 103 | def set_button(self, i, label, actions, args): 104 | self.buttons[i].setText(label) 105 | self.button_actions[i] = actions 106 | self.button_args[i] = args 107 | 108 | def perform_action(self, actions, args): 109 | logger.debug ("perform_action: %s", str(actions)) 110 | if actions is None: 111 | return 112 | if isinstance(actions,int): 113 | self.perform_action (self.button_actions[actions], self.button_args[actions]) 114 | elif isinstance(actions,list): 115 | for a in actions: 116 | self.perform_action(a) 117 | elif isinstance(actions,str): 118 | try: 119 | hmi.actions.trigger(actions, args) 120 | except: 121 | eval(actions) 122 | else: 123 | actions() 124 | 125 | def toggle_db_bool(self, key): 126 | db = fix.db.get_item(key) 127 | db.value = not db.value 128 | if db.value and self.last_button_clicked >= 0: 129 | self.buttons[self.last_button_clicked].setStyleSheet ("color: green") 130 | else: 131 | self.buttons[self.last_button_clicked].setStyleSheet ("color: black") 132 | 133 | 134 | def button_clicked(self, btn_num): 135 | if btn_num >= 0: 136 | self.last_button_clicked = btn_num 137 | self.perform_action(self.button_actions[btn_num], self.button_args[btn_num]) 138 | 139 | def button_clicked1(self, _): 140 | self.button_clicked(0) 141 | 142 | def button_clicked2(self, _): 143 | self.button_clicked(1) 144 | 145 | def button_clicked3(self, _): 146 | self.button_clicked(2) 147 | 148 | def button_clicked4(self, _): 149 | self.button_clicked(3) 150 | 151 | def button_clicked5(self, _): 152 | self.button_clicked(4) 153 | 154 | def button_clicked6(self, _): 155 | self.button_clicked(5) 156 | 157 | def activateMenuItem(self, val): 158 | self.button_clicked(int(val)-1) 159 | 160 | def register_map(self, m): 161 | self.avmap = m 162 | self.registered_targets['ZOOM'].register_map (m) 163 | 164 | class ZoomProxy: 165 | def __init__(self): 166 | self.enc = fix.db.get_item("ENC1", True) 167 | self.avmap = None 168 | 169 | def register_map(self, m): 170 | self.avmap = m 171 | 172 | def focus(self): 173 | self.last_value = self.enc.value 174 | self.enc.valueChanged[int].connect(self.change) 175 | 176 | def defocus(self): 177 | self.enc.valueChanged[int].disconnect(self.change) 178 | 179 | def change(self, _): 180 | val = self.enc.value 181 | diff = val - self.last_value 182 | if self.avmap is not None: 183 | self.avmap.incZoom (diff * 0.1) 184 | self.last_value = val 185 | -------------------------------------------------------------------------------- /make_tiles/make_tiles.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (c) 2019 Garrett Herschleb 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program; if not, write to the Free Software 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | 18 | import sys, os 19 | from PIL import Image 20 | 21 | Image.MAX_IMAGE_PIXELS=225000000 22 | print ("Reading Image...") 23 | i=Image.open(sys.argv[1] + '.tif') 24 | if len(sys.argv) > 2: 25 | rotate = bool(sys.argv[2]) 26 | else: 27 | rotate = False 28 | ncuts = 10 29 | cut_width = int(round(float(i.width) / float(ncuts))) 30 | cut_height = int(round(float(i.height) / float(ncuts))) 31 | xoff = 0 32 | for x in range(ncuts): 33 | yoff = 0 34 | for y in range(ncuts): 35 | print ("Cropping tile %dx%d..."%(x,y)) 36 | ci = i.crop((xoff,yoff,xoff+cut_width,yoff+cut_height)) 37 | if rotate: 38 | ci = ci.transpose (Image.ROTATE_90) 39 | ci.save(sys.argv[1] + str(y) + str(ncuts-x-1) + ".png") 40 | else: 41 | ci.save(sys.argv[1] + str(x) + str(y) + ".png") 42 | yoff += cut_height 43 | xoff += cut_width 44 | if rotate: 45 | f = open ('rotated', 'w') 46 | f.close() 47 | -------------------------------------------------------------------------------- /pyAvMap.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Copyright (c) 2019 Garrett Herschleb 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program; if not, write to the Free Software 17 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | 19 | import sys, os, time 20 | 21 | import logging 22 | import logging.config 23 | import argparse 24 | try: 25 | from PyQt5.QtGui import * 26 | from PyQt5.QtWidgets import * 27 | from PyQt5.QtCore import * 28 | PYQT = 5 29 | except: 30 | from PyQt4.QtGui import * 31 | from PyQt4.QtCore import * 32 | PYQT = 4 33 | import yaml 34 | import gui 35 | import hmi 36 | from hmi import Menu 37 | 38 | if "pyAvTools" not in ''.join(sys.path): 39 | neighbor_tools = os.path.join ('..', 'pyAvTools') 40 | if os.path.isdir (neighbor_tools): 41 | sys.path.append (neighbor_tools) 42 | elif 'TOOLS_PATH' in os.environ: 43 | sys.path.append (os.environ['TOOLS_PATH']) 44 | 45 | try: 46 | import pyavui 47 | import pyavtools.fix as fix 48 | except: 49 | print ("You need to have pyAvTools installed, or in an adjacent directory to pyAvMap.") 50 | print ("Or set the environment variable 'TOOLS_PATH' to point to the location of pyAvTools.") 51 | sys.exit(-1) 52 | 53 | import pyavmap 54 | 55 | class Main(QMainWindow): 56 | keyPress = pyqtSignal(QEvent) 57 | keyRelease = pyqtSignal(QEvent) 58 | def keyPressEvent(self, event): 59 | self.keyPress.emit(event) 60 | def keyReleaseEvent(self, event): 61 | self.keyRelease.emit(event) 62 | 63 | 64 | if __name__ == "__main__": 65 | app = QApplication(sys.argv) 66 | parser = argparse.ArgumentParser(description='pyAvMap') 67 | parser.add_argument('--debug', action='store_true', 68 | help='Run in debug mode') 69 | parser.add_argument('--verbose', '-v', action='store_true', 70 | help='Run in verbose mode') 71 | parser.add_argument('--config-file', default='config/main.yaml', type=argparse.FileType('r'), 72 | help='Alternate configuration file') 73 | 74 | args = parser.parse_args() 75 | 76 | # if we passed in a configuration file on the command line... 77 | config = yaml.load(args.config_file) 78 | 79 | if 'logging' in config: 80 | logging.config.dictConfig(config['logging']) 81 | else: 82 | logging.basicConfig() 83 | 84 | log = logging.getLogger() 85 | if args.verbose: 86 | log.setLevel(logging.INFO) 87 | if args.debug: 88 | log.setLevel(logging.DEBUG) 89 | log.info("Starting pyAvMap") 90 | 91 | log.debug("PyQT Version = %d" % PYQT) 92 | 93 | fix.initialize(config) 94 | 95 | pyavmap.configure_charts (config['charts_dir']) 96 | 97 | main_window = Main() 98 | screenWidth = int(config["main"]["screenWidth"]) 99 | screenHeight = int(config["main"]["screenHeight"]) 100 | main_window.resize(screenWidth, screenHeight) 101 | avmap = pyavmap.AvMap (config, main_window) 102 | avmap.resize(screenWidth, screenHeight) 103 | 104 | hmi.initialize(config) 105 | hmi.keys.initialize(main_window, config["keybindings"]) 106 | if 'menu' in config: 107 | menu = Menu(main_window, config["menu"]) 108 | menu.start() 109 | menu.register_map(avmap) 110 | enc = "ENC1" if "rotary_encoder" not in config else config["rotary_encoder"] 111 | enc_sel = "BTN6" if "rotary_select" not in config else config["rotary_select"] 112 | ctsel_widget = gui.ChartTypeSel(enc, enc_sel, pyavmap.chart_types(), 113 | avmap.set_chart_type, main_window) 114 | ctsel_widget.resize (100, 65) 115 | ctsel_widget.move (30, 32) 116 | menu.register_target ("Chart Type", ctsel_widget) 117 | 118 | 119 | if 'displays' in config: 120 | for title,contents in config['displays'].items(): 121 | position = [0,0] 122 | kwargs = {'parent': main_window} 123 | dbitems = list() 124 | for k,v in contents.items(): 125 | if k == 'keys': 126 | for key in v: 127 | item = fix.db.get_item(key) 128 | dbitems.append(item) 129 | elif k == 'position': 130 | position = v 131 | else: 132 | kwargs[k] = v 133 | d = pyavui.FIXDisplay(title, dbitems, **kwargs) 134 | if position[0] < 0: 135 | position[0] = screenWidth+position[0]-d.width() 136 | if position[1] < 0: 137 | position[1] = screenHeight+position[1]-d.height() 138 | d.move (*tuple(position)) 139 | 140 | main_window.show() 141 | track = fix.db.get_item("TRACK") 142 | avmap.setTrack(track.value) 143 | lat = fix.db.get_item("LAT") 144 | avmap.setLat(lat.value) 145 | lon = fix.db.get_item("LONG") 146 | avmap.setLon (lon.value) 147 | lat.valueChanged[float].connect(avmap.setLat) 148 | lon.valueChanged[float].connect(avmap.setLon) 149 | track.valueChanged[float].connect(avmap.setTrack) 150 | 151 | # Main program loop 152 | result = app.exec_() 153 | 154 | # Clean up and get out 155 | fix.stop() 156 | log.info("PyAvMap Exiting Normally") 157 | sys.exit(result) 158 | -------------------------------------------------------------------------------- /pyavmap/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2019 Garrett Herschleb 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation; either version 2 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; if not, write to the Free Software 15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 | 17 | import math 18 | import logging 19 | import time 20 | import threading 21 | import os 22 | from glob import glob 23 | 24 | try: 25 | from PyQt5.QtGui import * 26 | from PyQt5.QtCore import * 27 | from PyQt5.QtWidgets import * 28 | except: 29 | from PyQt4.QtGui import * 30 | from PyQt4.QtCore import * 31 | 32 | import pyavmap.avchart_proj as proj 33 | 34 | log = logging.getLogger(__name__) 35 | 36 | class AvMap(QGraphicsView): 37 | icon_poly_points = [ 38 | QPointF (0,0) 39 | ,QPointF (5,5) 40 | ,QPointF (20,5) 41 | 42 | ,QPointF (30,25) 43 | ,QPointF (40,25) 44 | ,QPointF (35,5) 45 | 46 | ,QPointF (50,5) 47 | ,QPointF (55,10) 48 | ,QPointF (65,10) 49 | ,QPointF (60,0) 50 | ,QPointF (65,-10) 51 | ,QPointF (55,-10) 52 | ,QPointF (50,-5) 53 | 54 | ,QPointF (35,-5) 55 | ,QPointF (40,-25) 56 | ,QPointF (30,-25) 57 | 58 | ,QPointF (20,-5) 59 | ,QPointF (5,-5) 60 | ] 61 | icon_center = QPointF(25,0) 62 | scene_size_multiplier=4 63 | def __init__(self, config, parent=None): 64 | super(AvMap, self).__init__(parent) 65 | self.config = config 66 | 67 | self.setStyleSheet("border: 0px") 68 | self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) 69 | self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) 70 | self.setRenderHint(QPainter.Antialiasing) 71 | self.setFocusPolicy(Qt.NoFocus) 72 | self.fontSize = 30 73 | self._lat = 0 74 | self._lon = 0 75 | self._track_direction = 0 76 | 77 | self.chart_type = proj.CT_SECTIONAL if 'chart_type' not in self.config else self.config ['chart_type'] 78 | 79 | self.zoom = 1.0 if 'zoom' not in self.config else self.config['zoom'] 80 | self.xoff = 0 if 'xoff' not in self.config else self.config['xoff'] 81 | self.yoff = 0 if 'yoff' not in self.config else self.config['yoff'] 82 | self.pxmap_update_period = 1.0 if 'pxmap_update_period' not in self.config \ 83 | else self.config['pxmap_update_period'] 84 | self.icon_opacity = .8 if 'icon_opacity' not in self.config else self.config['icon_opacity'] 85 | self.icon_scale = 1.0 if 'icon_scale' not in self.config else self.config['icon_scale'] 86 | self.icon_fill = Qt.white if 'icon_fill' not in self.config \ 87 | else self.config['icon_fill'] 88 | self.icon_outline = Qt.black if 'icon_outline' not in self.config \ 89 | else self.config['icon_outline'] 90 | self.show_path = False if 'show_path' not in self.config else self.config['show_path'] 91 | self.path_color = Qt.green if 'path_color' not in self.config else self.config['path_color'] 92 | self.path_history = list() 93 | self.last_path_time = 0 94 | self.max_path_len = 1000 if 'path_length' not in self.config else self.config['path_length'] 95 | self.north_is_up = True if 'north_is_up' not in self.config else self.config['north_is_up'] 96 | self.extended_track_length = 100 if 'extended_track_length' not in self.config \ 97 | else self.config['extended_track_length'] 98 | self.el_color = Qt.yellow if 'el_color' not in self.config else self.config['el_color'] 99 | self.last_rotation_val = 0.0 100 | self.chart = None 101 | self.map_pixmap = None 102 | self.new_map_pixmap = None 103 | self.map_pixmap_lon = None 104 | self.map_pixmap_lat = None 105 | self.pmi = None 106 | # Data from pixmap construction 107 | # The offset of the upper left corner of the constructed pixmap in over-all chart x-y coordinates, 108 | # adjusted for zoom level 109 | self.corner_x = None 110 | self.corner_y = None 111 | # The position of the given lat,lon in the over-all chart x-y coordinates, 112 | # adjusted for zoom level 113 | self.xzoom = None 114 | self.yzoom = None 115 | self.chart_image_time = 0 116 | self.pxmap_update_pending = False 117 | self.pxmap_update = None 118 | self.pxmap_lock = threading.RLock() 119 | 120 | def resizeEvent(self, event): 121 | log.debug("resizeEvent") 122 | #Setup the scene that we use for the background of the AI 123 | self.pxmpHeight = self.height() * self.scene_size_multiplier 124 | self.pxmpWidth = self.width() * self.scene_size_multiplier 125 | self.scene = QGraphicsScene(0, 0, self.pxmpWidth+self.width(), self.pxmpHeight+self.height()) 126 | self.setScene(self.scene) 127 | self.init_chart() 128 | 129 | def find_best_chart(self): 130 | cd = None if 'charts_dir' not in self.config else self.config['charts_dir'] 131 | candidates = proj.find_charts (self.chart_type, self._lon, self._lat, cd, 132 | self.pxmpWidth, self.pxmpHeight, self.zoom) 133 | if len(candidates) == 0: 134 | return None 135 | best_chart = candidates[0] 136 | if len(candidates) > 1: 137 | best_dir = abs(Heading (((self._lon,self._lat), (candidates[0].center_lat, candidates[0].center_lon))) - 138 | self._track_direction) 139 | if best_dir > 180: 140 | best_dir -= 180 141 | for ch in candidates[1:]: 142 | d = abs(Heading (((self._lon,self._lat), (ch.center_lat, ch.center_lon))) - self._track_direction) 143 | if d > 180: 144 | d = abs(d-360) 145 | if d < best_dir: 146 | best_dir = d 147 | best_chart = ch 148 | return best_chart 149 | 150 | def init_chart(self): 151 | log.debug("init_chart") 152 | self.chart = self.find_best_chart() 153 | if self.chart is None: 154 | log.error ("No chart found for %g,%g", self._lon, self._lat) 155 | return 156 | self.map_pixmap_lon = self._lon 157 | self.map_pixmap_lat = self._lat 158 | try: 159 | self.map_pixmap,self.corner_x,self.corner_y,self.xzoom,self.yzoom = \ 160 | self.chart.construct_pixmap(self._lon, self._lat, 161 | self.pxmpWidth, self.pxmpHeight, self.zoom) 162 | self.chart_image_time = time.time() 163 | good = True 164 | except RuntimeError: 165 | good = False 166 | log.error ("Chart set failure: %s %g,%g", self.chart.name, self._lon, self._lat) 167 | if good: 168 | if self.pmi is None: 169 | self.pmi = self.scene.addPixmap (self.map_pixmap) 170 | self.pmi.setOffset(self.width()/2,self.height()/2) 171 | else: 172 | self.pmi.setPixmap (self.map_pixmap) 173 | self.redraw() 174 | 175 | def redraw(self): 176 | self.resetTransform() 177 | self.pxmap_lock.acquire() 178 | if self.pxmap_update_pending and (self.new_map_pixmap is not None): 179 | self.map_pixmap = self.new_map_pixmap 180 | self.pmi.setPixmap (self.map_pixmap) 181 | self.new_map_pixmap = None 182 | self.pxmap_update_pending = False 183 | cx = self.xzoom-self.corner_x + self.width()/2 184 | cy = self.yzoom-self.corner_y + self.height()/2 185 | self.pxmap_lock.release() 186 | log.log (2, "redraw center on %g,%g - %g,%g - %d,%d = %g,%g", self.xzoom, self.yzoom, 187 | self.corner_x, self.corner_y, 188 | self.width()/2, self.height()/2, 189 | cx,cy) 190 | if cy < self.height()/2: 191 | log.error ("Image spill to the top") 192 | if self.scene.height()-cy < self.height()/2: 193 | log.error ("Image spill to the bottom") 194 | if cx < self.width()/2: 195 | log.error ("Image spill to the left") 196 | if self.scene.width()-cx < self.width()/2: 197 | log.error ("Image spill to the right") 198 | if (not self.north_is_up) and (self.chart is not None): # Track is up 199 | cna = self.chart.north_angle * 180 / math.pi 200 | rotate_angle = -self._track_direction - (cna - 90) 201 | if rotate_angle != self.last_rotation_val: 202 | increment_angle = rotate_angle - self.last_rotation_val 203 | self.rotate(increment_angle) 204 | self.last_rotation_angle = rotate_angle 205 | if self.yoff != 0 or self.xoff != 0: 206 | rotate_angle *= math.pi / 180 207 | cosa = math.cos(rotate_angle) 208 | sina = math.sin(rotate_angle) 209 | yoff = (self.yoff*cosa - self.xoff*sina) 210 | xoff = (self.xoff*cosa + self.yoff*sina) 211 | cy -= yoff 212 | cx -= xoff 213 | else: 214 | cx -= self.xoff 215 | cy -= self.yoff 216 | self.centerOn(cx, cy) 217 | 218 | def setLat(self, val): 219 | if val != self._lat and self.isVisible(): 220 | self._lat = val 221 | if self.chart is None or self.map_pixmap is None: 222 | self.init_chart() 223 | else: 224 | self.xzoom,self.yzoom = self.chart.get_zoom_pos (self._lon, self._lat, self.zoom) 225 | self.redraw() 226 | self.check_pxmap_update() 227 | self.record_track() 228 | 229 | def setLon(self, val): 230 | if val != self._lon and self.isVisible(): 231 | self._lon = val 232 | if self.chart is None or self.map_pixmap is None: 233 | self.init_chart() 234 | else: 235 | self.xzoom,self.yzoom = self.chart.get_zoom_pos (self._lon, self._lat, self.zoom) 236 | self.redraw() 237 | self.check_pxmap_update() 238 | self.record_track() 239 | 240 | def record_track(self): 241 | add = False 242 | now = time.time() 243 | if len(self.path_history) > 0: 244 | dist = Distance (((self._lon,self._lat), self.path_history[-1])) 245 | if dist > 10 and now - self.last_path_time > 1: 246 | add = True 247 | else: 248 | add = True 249 | if add: 250 | self.path_history.append ((self._lon,self._lat)) 251 | self.last_path_time = now 252 | if len(self.path_history) > self.max_path_len: 253 | del self.path_history[0] 254 | 255 | def incZoom(self, diff): 256 | log.debug("incZoom") 257 | if diff != 0 and self.isVisible(): 258 | newzoom = self.zoom + diff 259 | if newzoom <= .2: 260 | newzoom = .2 261 | if newzoom > 2: 262 | newzoom = 2 263 | if self.zoom != newzoom: 264 | self.zoom = newzoom 265 | if self.chart is None or self.map_pixmap is None: 266 | self.init_chart() 267 | else: 268 | self.map_pixmap_lon = self._lon 269 | self.map_pixmap_lat = self._lat 270 | try: 271 | self.map_pixmap,self.corner_x,self.corner_y,self.xzoom,self.yzoom = \ 272 | self.chart.construct_pixmap(self._lon, self._lat, 273 | self.pxmpWidth, self.pxmpHeight, self.zoom) 274 | self.chart_image_time = time.time() 275 | good = True 276 | except RuntimeError: 277 | good = False 278 | log.error ("Chart set failure: %s %g,%g", chart_name, self._lon, self._lat) 279 | if good: 280 | self.pmi.setPixmap (self.map_pixmap) 281 | self.redraw() 282 | 283 | def setTrack(self, val): 284 | if val != self._track_direction and self.isVisible(): 285 | self._track_direction = val 286 | 287 | def set_chart_type(self, ct): 288 | self.chart_type = ct 289 | self.init_chart() 290 | 291 | def set_north_up(self, nu): 292 | self.north_is_up = nu 293 | 294 | # We use the paintEvent to draw on the viewport the parts that aren't moving. 295 | def paintEvent(self, event): 296 | super(AvMap, self).paintEvent(event) 297 | w = self.width() 298 | h = self.height() 299 | p = QPainter(self.viewport()) 300 | p.setRenderHint(QPainter.Antialiasing) 301 | 302 | p.setPen(QColor(self.icon_outline)) 303 | p.setBrush(QColor(self.icon_fill)) 304 | p.setOpacity (self.icon_opacity) 305 | ix = self.icon_center.x()*self.icon_scale 306 | iy = self.icon_center.y()*self.icon_scale 307 | if (self.chart is not None) and self.north_is_up: 308 | angle = self._track_direction * math.pi/180 309 | angle += self.chart.north_angle 310 | else: 311 | angle = math.pi/2 312 | cosa = math.cos(angle) 313 | sina = math.sin(angle) 314 | offset_x = self.width()/2 + self.xoff - (ix*cosa - iy*sina) 315 | offset_y = self.height()/2 + self.yoff - (iy*cosa + ix*sina) 316 | pp = [QPointF ((p.x()*cosa - p.y()*sina)*self.icon_scale + offset_x, 317 | (p.y()*cosa + p.x()*sina)*self.icon_scale + offset_y) 318 | for p in self.icon_poly_points] 319 | p.drawPolygon(QPolygonF(pp)) 320 | 321 | if self.north_is_up and self.show_path and len(self.path_history) >= 2: 322 | p.setPen(QColor(self.path_color)) 323 | p.setOpacity(1.0) 324 | cx = self.xzoom-self.corner_x-self.xoff # Where in the pixmap is the center of the display 325 | cy = self.yzoom-self.corner_y-self.yoff 326 | cx -= self.width()/2 # Where in the pixmap is the ul corner of display 327 | cy -= self.height()/2 328 | last_coord_x,last_coord_y = self.screen_coord (self.path_history[0][0], self.path_history[0][1], cx, cy) 329 | for i in range(1,len(self.path_history)): 330 | icoord_x,icoord_y = self.screen_coord (self.path_history[i][0], self.path_history[i][1], cx,cy) 331 | p.drawLine(QPointF(last_coord_x,last_coord_y), QPointF(icoord_x,icoord_y)) 332 | log.debug("path_history %.1f,%.1f -> %.1f,%.1f", last_coord_x, last_coord_y, icoord_x, icoord_y) 333 | last_coord_x = icoord_x 334 | last_coord_y = icoord_y 335 | if self.north_is_up and self.extended_track_length > 0: 336 | ix = 0 337 | iy = -self.extended_track_length 338 | ext_dx = (ix*cosa - iy*sina) 339 | ext_dy = (iy*cosa + ix*sina) 340 | pen = QPen(QColor(self.el_color)) 341 | pen.setStyle(Qt.DotLine) 342 | p.setPen(pen) 343 | bx = self.width()/2 + self.xoff 344 | by = self.height()/2 + self.yoff 345 | ex = bx + ext_dy 346 | ey = by - ext_dx 347 | p.drawLine (QPointF(bx,by), QPointF(ex,ey)) 348 | 349 | def screen_coord(self, lon, lat, cx, cy): 350 | coord_x,coord_y = self.chart.proj (lon,lat) 351 | coord_x *= self.zoom 352 | coord_y *= self.zoom 353 | coord_x -= self.corner_x # Where is the track in the pixmap 354 | coord_y -= self.corner_y 355 | coord_x -= cx 356 | coord_y -= cy 357 | return coord_x,coord_y 358 | 359 | def update_chart_pixmap(self, chart): 360 | try: 361 | map_pixmap,corner_x,corner_y,xzoom,yzoom = \ 362 | chart.construct_pixmap(self._lon, self._lat, 363 | self.pxmpWidth, self.pxmpHeight, self.zoom) 364 | good = True 365 | except RuntimeError: 366 | good = False 367 | self.pxmap_update_pending = False 368 | log.error ("update pixmap set failure: %s %g,%g", chart.name, self._lon, self._lat) 369 | if good: 370 | self.pxmap_lock.acquire() 371 | self.new_map_pixmap,self.corner_x,self.corner_y,self.xzoom,self.yzoom = \ 372 | map_pixmap,corner_x,corner_y,xzoom,yzoom 373 | self.chart = chart 374 | self.pxmap_lock.release() 375 | self.chart_image_time = time.time() 376 | 377 | def check_pxmap_update(self): 378 | if (self.chart is not None) and (not self.pxmap_update_pending): 379 | if time.time() - self.chart_image_time > self.pxmap_update_period: 380 | cx,cy,oob = self.chart.compute_ul_corner(self._lon, self._lat, 381 | self.pxmpWidth, self.pxmpHeight, self.zoom) 382 | chart = self.chart 383 | if oob: # out of bounds 384 | chart = self.find_best_chart() 385 | if chart is None or chart.name == self.chart.name: 386 | log.debug ("Out of bounds, but no better chart available") 387 | chart = self.chart 388 | else: 389 | log.debug ("Out of bounds. change chart to %s"%chart.name) 390 | self.chart_image_time = time.time() 391 | if cx != self.corner_x or cy != self.corner_y or chart != self.chart: 392 | self.pxmap_update_pending = True 393 | th = threading.Thread (target=self.update_chart_pixmap, args=(chart,)) 394 | th.start() 395 | 396 | def get_polar_deltas(course): 397 | lng1,lat1 = course[0] 398 | lng2,lat2 = course[1] 399 | dlng = lng2 - lng1 400 | dlat = lat2 - lat1 401 | return (dlng,dlat) 402 | 403 | def GetRelLng(lat1): 404 | return math.cos(lat1) 405 | 406 | def adjusted_polar_deltas(course, rel_lng=0): 407 | dlng,dlat = get_polar_deltas(course) 408 | 409 | # Determine how far is a longitude increment relative to latitude at this latitude 410 | if rel_lng == 0: 411 | lat1 = course[0][1] * math.pi / 180.0 412 | relative_lng_length = GetRelLng(lat1) 413 | else: 414 | relative_lng_length = rel_lng 415 | dlng *= relative_lng_length 416 | return dlng,dlat 417 | 418 | METERS_PER_NM = 1852 419 | # Computes distance in meters between 2 long/lat points 420 | def Distance(course, rel_lng=0): 421 | dlng,dlat = adjusted_polar_deltas(course, rel_lng) 422 | # Multiply by 60 to convert from degrees to nautical miles. 423 | distance = math.sqrt(dlng * dlng + dlat * dlat) * 60.0 424 | return distance * METERS_PER_NM 425 | 426 | def Heading(course, rel_lng=0): 427 | dlng,dlat = adjusted_polar_deltas(course, rel_lng) 428 | heading = math.atan2(dlng, dlat) * 180 / math.pi 429 | return heading 430 | 431 | def configure_charts (directory): 432 | chart_types = glob(os.path.join (directory, '*')) 433 | chart_types = [os.path.basename(ct) for ct in chart_types] 434 | log.debug ("Found chart types: %s", str(chart_types)) 435 | for ct in chart_types: 436 | proj.charts[ct] = dict() 437 | chart_names = glob(os.path.join (directory, ct, '*')) 438 | chart_names = [os.path.basename(cn) for cn in chart_names] 439 | log.debug ("Found chart in %s: %s", ct, str(chart_names)) 440 | for cn in chart_names: 441 | base_name = glob(os.path.join (directory, ct, cn, '*.tfw')) 442 | if len(base_name) == 0: 443 | base_name = glob(os.path.join (directory, ct, cn, '*.tfwx')) 444 | if len(base_name) == 0: 445 | log.error ("Invalid chart found: %s", os.path.join (directory, ct, cn)) 446 | continue 447 | base = os.path.basename(base_name[0]) 448 | base = os.path.splitext(base)[0] 449 | proj.charts[ct][cn] = [base] 450 | if os.path.exists (os.path.join (directory, ct, cn, 'rotated')): 451 | proj.charts[ct][cn].append(True) 452 | log.debug ("chart %s of type %s is defined: %s", cn, ct, str(proj.charts[ct][cn])) 453 | 454 | def chart_types(): 455 | return (list(proj.charts.keys())) 456 | -------------------------------------------------------------------------------- /pyavmap/avchart_proj.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2019 Garrett Herschleb 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation; either version 2 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; if not, write to the Free Software 15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 | 17 | import os, math 18 | 19 | try: 20 | from PyQt5.QtGui import * 21 | from PyQt5.QtCore import * 22 | from PyQt5.QtWidgets import * 23 | except: 24 | from PyQt4.QtGui import * 25 | from PyQt4.QtCore import * 26 | 27 | from pyproj import Proj 28 | 29 | import logging 30 | log = logging.getLogger(__name__) 31 | 32 | CT_SECTIONAL = 'Sectional' 33 | CT_IFR = 'IFR' 34 | CT_JET = 'Jet' 35 | CT_TAC = 'Terminal' 36 | 37 | charts = dict() 38 | 39 | class AvChart: 40 | def __init__(self, name, base_name, rotated): 41 | self.name = name 42 | self.base_name = base_name 43 | self.rotated = rotated 44 | self.lat_0=None 45 | self.lon_0=None 46 | lat1=None 47 | lat2=None 48 | proj='lcc' 49 | datum='WGS84' 50 | self.llon = None 51 | self.rlon = None 52 | self.ulat = None 53 | self.llat = None 54 | self.column_count = None 55 | htm_name = base_name + '.htm' 56 | if not os.path.exists (htm_name): 57 | htm_name = base_name + '_tif.htm' 58 | with open(htm_name, 'r') as htm: 59 | while True: 60 | line = htm.readline() 61 | if line is None or len(line) == 0: 62 | htm.close() 63 | break 64 | if 'Map_Projection_Name' in line: 65 | if not 'Lambert' in line: 66 | raise RuntimeError("Unrecognized map projection") 67 | if 'Standard_Parallel' in line: 68 | i = line.index('Standard_Parallel') 69 | n = line.index('>', i) + 1 70 | e = line.index('<', n) 71 | p = float(line[n:e]) 72 | if lat1 is not None: 73 | lat2 = p 74 | log.debug ("%s: lat2 = %g"%(base_name, lat2)) 75 | else: 76 | lat1 = p 77 | log.debug ("%s: lat1 = %g"%(base_name, lat1)) 78 | if 'Longitude_of_Central_Meridian' in line: 79 | i = line.index('Central_Meridian') 80 | n = line.index('>', i) + 1 81 | e = line.index('<', n) 82 | self.lon_0 = float(line[n:e]) 83 | if 'Latitude_of_Projection_Origin' in line: 84 | i = line.index('Projection_Origin') 85 | n = line.index('>', i) + 1 86 | e = line.index('<', n) 87 | self.lat_0 = float(line[n:e]) 88 | if 'Column_Count' in line: 89 | i = line.index('Column_Count') 90 | n = line.index('>', i) + 1 91 | e = line.index('<', n) 92 | self.column_count = int(line[n:e]) 93 | if '_Bounding_Coordinate' in line: 94 | i = line.index('Coordinate') 95 | n = line.index('>', i) + 1 96 | e = line.index('<', n) 97 | coord = float(line[n:e]) 98 | if 'West' in line: 99 | self.llon = coord 100 | log.debug ("West boundary of %s is %g"%(self.name, coord)) 101 | elif 'East' in line: 102 | self.rlon = coord 103 | log.debug ("East boundary of %s is %g"%(self.name, coord)) 104 | elif 'North' in line: 105 | self.ulat = coord 106 | log.debug ("North boundary of %s is %g"%(self.name, coord)) 107 | elif 'South' in line: 108 | self.llat = coord 109 | log.debug ("South boundary of %s is %g"%(self.name, coord)) 110 | else: 111 | raise RuntimeError ("%s: Unknown bounding coordinate type: %s"%(base_name, line)) 112 | 113 | wfname = base_name + '.tfw' 114 | if not os.path.exists (wfname): 115 | wfname = base_name + '.tfwx' 116 | with open(wfname, 'r') as wf: 117 | constants = wf.readlines() 118 | wf.close() 119 | self.A,self.D, self.B,self.E, self.C,self.F = [float(c) for c in constants] 120 | 121 | self.divisor = (self.E*self.A) - (self.B*self.D) 122 | self.xconst = self.B*self.F - self.C*self.E 123 | self.yconst = self.D*self.C - self.A*self.F 124 | self.center_lat = (self.ulat + self.llat) / 2.0 125 | self.center_lon = (self.llon + self.rlon) / 2.0 126 | self.p = Proj(proj=proj, lat_0=self.lat_0, lon_0=self.lon_0, units='meters', 127 | datum=datum, lat_1=lat1, lat_2=lat2) 128 | 129 | cx,cy = self.proj (self.center_lon, self.center_lat) 130 | ux,uy = self.proj (self.center_lon, self.ulat) 131 | dx = ux-cx 132 | dy = uy-cy 133 | self.north_angle = math.atan2(dy, dx) + math.pi # 180 degree flip because positive y is down 134 | 135 | pxmp0 = QPixmap(base_name + '00.png') 136 | self.tile_width = pxmp0.width() 137 | self.tile_height = pxmp0.height() 138 | 139 | def is_valid(self): 140 | return not (self.llon is None or self.rlon is None or 141 | self.ulat is None or self.llat is None) 142 | 143 | def proj(self, lon,lat): 144 | x1,y1 = self.p(lon,lat) 145 | x = (self.E*x1 - self.B*y1 + self.xconst) / self.divisor 146 | y = ((self.A*y1 - self.D*x1 + self.yconst) / self.divisor) 147 | if self.rotated: 148 | temp = x 149 | x = y 150 | y = self.column_count - temp - 1 151 | return (x,y) 152 | 153 | def get_tile_coord(self, lon, lat): 154 | x,y = self.proj(lon,lat) 155 | x /= self.tile_width 156 | y /= self.tile_height 157 | x = int(x) 158 | y = int(y) 159 | return x,y 160 | 161 | def get_tile_pixmap_pos (self, lon, lat, just_check=False): 162 | x,y = self.get_tile_coord(lon, lat) 163 | if x < 0: 164 | log.debug ("%g,%g is out of longitude bounds: %g,%g", lon, lat, x,y) 165 | return (x,y,None) 166 | elif y < 0: 167 | log.debug ("%g,%g is out of latitude bounds: %g,%g", lon, lat, x,y) 168 | return (x,y,None) 169 | return self.get_tile_pixmap(x,y, just_check) 170 | 171 | def get_tile_pixmap (self, x,y, just_check=False): 172 | fname = self.base_name + str(x) + str(y) + '.png' 173 | if not os.path.exists (fname): 174 | log.debug ("No tile %s", fname) 175 | return (x,y,None) 176 | if just_check: 177 | return (x,y,True) 178 | else: 179 | return (x,y,QPixmap(fname)) 180 | 181 | def compute_tile_bounds(self, lon, lat, width, height, zoom_width, zoom_height): 182 | imcenterx = width/2 183 | imcentery = height/2 184 | cx,cy = self.get_tile_coord(lon, lat) 185 | begin_xindex = cx - int(imcenterx / zoom_width) 186 | begin_yindex = cy - int(imcentery / zoom_height) 187 | log.debug ("begin_xindex = %d-int(round(%g/%g))(%d) = %d", 188 | cx, imcenterx, zoom_width, int(imcenterx / zoom_width), begin_xindex) 189 | log.debug ("begin_yindex = %d-int(round(%g/%g))(%d) = %d", 190 | cy, imcentery, zoom_height, int(imcentery / zoom_height), begin_yindex) 191 | out_of_bounds = False 192 | if begin_xindex < 0: 193 | begin_xindex = 0 194 | out_of_bounds = True 195 | if begin_yindex < 0: 196 | begin_yindex = 0 197 | out_of_bounds = True 198 | end_xindex = begin_xindex + int(width / zoom_width)+1 199 | end_yindex = begin_yindex + int(height / zoom_height)+1 200 | log.debug ("end_*index = %d,%d", end_xindex,end_yindex) 201 | fname = self.base_name + str(end_xindex) + str(end_yindex) + '.png' 202 | if not os.path.exists (fname): 203 | out_of_bounds = True 204 | return begin_xindex,begin_yindex, end_xindex,end_yindex, out_of_bounds 205 | 206 | def construct_pixmap(self, lon, lat, width, height, zoom): 207 | ret = QPixmap(width, height) 208 | ret.fill (QColor(Qt.black)) 209 | cx,cy,ci = self.get_tile_pixmap_pos (lon, lat) 210 | if ci is None: 211 | raise RuntimeError ("longitude %g, latitude %g is not contained in map %s (tile %d,%d)"%( 212 | lon,lat,self.name,cx,cy)) 213 | 214 | zoom_width = self.tile_width * zoom 215 | zoom_height = self.tile_height * zoom 216 | begin_xindex,begin_yindex,end_xindex,end_yindex,oob = self.compute_tile_bounds (lon, lat, 217 | width, height, zoom_width, zoom_height) 218 | 219 | painter = QPainter(ret) 220 | tile_place_x = 0 221 | log.debug ("const_pmp: zoom w,h = %g,%g", zoom_width, zoom_height) 222 | for i in range(begin_xindex,end_xindex): 223 | if tile_place_x > width: 224 | break 225 | tile_place_y = 0 226 | for j in range(begin_yindex,end_yindex): 227 | if tile_place_y > height: 228 | break 229 | tx,ty,tp = self.get_tile_pixmap(i,j) 230 | if tp is not None: 231 | tp = tp.scaled (int(round(tp.width()*zoom)), int(round(tp.height()*zoom)), 232 | transformMode=Qt.SmoothTransformation) 233 | painter.drawPixmap(QPoint(int(round(tile_place_x)),int(round(tile_place_y))), tp) 234 | log.debug ("const_pmp: tile %d,%d drawn at %d,%d", i,j, 235 | int(round(tile_place_x)),int(round(tile_place_y))) 236 | tile_place_y += zoom_height 237 | tile_place_x += zoom_width 238 | 239 | corner_x = begin_xindex * zoom_width 240 | corner_y = begin_yindex * zoom_height 241 | xzoom,yzoom = self.get_zoom_pos(lon,lat,zoom) 242 | return ret,corner_x,corner_y,xzoom,yzoom 243 | 244 | def compute_ul_corner(self, lon, lat, width, height, zoom): 245 | zoom_width = self.tile_width * zoom 246 | zoom_height = self.tile_height * zoom 247 | begin_xindex,begin_yindex,end_xindex,end_yindex,oob = self.compute_tile_bounds (lon, lat, 248 | width, height, zoom_width, zoom_height) 249 | corner_x = begin_xindex * zoom_width 250 | corner_y = begin_yindex * zoom_height 251 | return corner_x, corner_y, oob 252 | 253 | def check_boundaries (self, lon, lat, width, height, zoom): 254 | cx,cy,ci = self.get_tile_pixmap_pos (lon, lat, just_check=True) 255 | if ci is None or ci is False: 256 | return False, True 257 | zoom_width = self.tile_width * zoom 258 | zoom_height = self.tile_height * zoom 259 | begin_xindex,begin_yindex,end_xindex,end_yindex,boundary_spill = \ 260 | self.compute_tile_bounds (lon, lat, 261 | width, height, zoom_width, zoom_height) 262 | return True,boundary_spill 263 | 264 | def get_zoom_pos(self, lon, lat, zoom): 265 | chart_x,chart_y = self.proj(lon,lat) 266 | xzoom = chart_x * zoom 267 | yzoom = chart_y * zoom 268 | return xzoom,yzoom 269 | 270 | 271 | def load_chart(name, chtype, directory=None): 272 | if name in charts[chtype]: 273 | rotated = False 274 | base_name = charts[chtype][name][0] 275 | if len(charts[chtype][name]) > 1 and bool(charts[chtype][name][1]): 276 | rotated = True 277 | if directory is not None: 278 | base_name = os.path.join (directory, chtype, name, base_name) 279 | else: 280 | base_name = os.path.join (chtype, name, base_name) 281 | ret = AvChart (name, base_name, rotated) 282 | return ret 283 | else: 284 | log.error ("chart %s not found", name) 285 | return None 286 | 287 | def find_chart (chart_type, lon, lat, directory): 288 | ch = list(charts[chart_type].keys())[0] 289 | tried = set() 290 | while True: 291 | in_bounds = False 292 | chart = load_chart(ch, chart_type, directory) 293 | if chart is not None and chart.is_valid(): 294 | in_bounds = True 295 | tried.add (ch) 296 | if lon < chart.llon: 297 | in_bounds = False 298 | newch = charts[chart_type][ch][4] 299 | if newch is not None and (newch not in tried): 300 | ch = newch 301 | continue 302 | if lon > chart.rlon: 303 | in_bounds = False 304 | newch = charts[chart_type][ch][3] 305 | if newch is not None and (newch not in tried): 306 | ch = newch 307 | continue 308 | if lat > chart.ulat: 309 | in_bounds = False 310 | newch = charts[chart_type][ch][1] 311 | if newch is not None and (newch not in tried): 312 | ch = newch 313 | continue 314 | if lat < chart.llat: 315 | in_bounds = False 316 | newch = charts[chart_type][ch][2] 317 | if newch is not None and (newch not in tried): 318 | ch = newch 319 | continue 320 | if in_bounds: 321 | return chart 322 | else: 323 | # No chart found 324 | return None 325 | 326 | def find_charts (chart_type, lon, lat, directory, width, height, zoom): 327 | ret = list() 328 | for ch,chinfo in charts[chart_type].items(): 329 | chart = load_chart(ch, chart_type, directory) 330 | if chart is not None and chart.is_valid(): 331 | in_bounds = True 332 | if lon < chart.llon: 333 | in_bounds = False 334 | if lon > chart.rlon: 335 | in_bounds = False 336 | if lat > chart.ulat: 337 | in_bounds = False 338 | if lat < chart.llat: 339 | in_bounds = False 340 | if in_bounds: 341 | valid,boundary_spill = chart.check_boundaries(lon, lat, 342 | width, height, zoom) 343 | if valid: 344 | ret.append(chart) 345 | return ret 346 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | import glob 3 | import os 4 | 5 | with open("README.rst", "r") as fh: 6 | long_description = fh.read() 7 | 8 | datafiles = [('etc/fixgw', ['config/default.yaml', 'config/default.db', 'config/c170b.ini','config/fg_172.ini']), 9 | ('etc/fixgw/canfix', ['config/canfix/default.map']), 10 | # ('share/fixgw/doc', ['doc/_build/FIXGateway-html.tar.gz', 'doc/_build/latex/FIXGateway.pdf']), 11 | ('share/fixgw', ['fixgw/plugins/fgfs/fix_fgfs.xml']), 12 | ] 13 | 14 | setuptools.setup( 15 | name="fixgw", 16 | version="0.1.0", 17 | author="Phil Birkelbach", 18 | author_email="phil@petrasoft.net", 19 | description="FIX-Gateway: Gateway software for the Flight Information eXchange protocols", 20 | long_description=long_description, 21 | #long_description_content_type="text/x-rst", 22 | url="https://github.com/makerplane/FIX-Gateway", 23 | packages=setuptools.find_packages(), 24 | #packages=['canfix'], 25 | #package_data = {'fixgw':['config/*']}, 26 | install_requires = ['pyyaml',], 27 | data_files = datafiles, 28 | #test_suite = 'tests', 29 | #scripts = ['bin/fixgw', 'bin/fixgwc'], 30 | entry_points = { 31 | 'console_scripts': ['fixgw=fixgw.server:main', 'fixgwc=fixgw.client:main'], 32 | }, 33 | classifiers=[ 34 | "Programming Language :: Python :: 3", 35 | "License :: OSI Approved :: GNU General Public License v2 (GPLv2)" 36 | "Operating System :: POSIX :: Linux", 37 | ], 38 | test_suite = 'tests', 39 | ) 40 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makerplane/pyAvMap/70fb9d700e2f6c313d010838eb142973b6d78100/tests/__init__.py --------------------------------------------------------------------------------