Archived
Private
Public Access
1
0

Initial commit

This commit is contained in:
2022-09-04 12:45:01 +02:00
commit f4a01d6a69
11601 changed files with 4206660 additions and 0 deletions

9
Java/BowlerStudio/.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,9 @@
# These are supported funding model platforms
github: madhephaestus
#github: madhephaestus
patreon: madhephaestus
#community_bridge: BowlerStudio
issuehunt: CommonWealthRobotics/BowlerStudio
#ko-fi: bowlerstudio
liberapay: madhephaestus
#open_collective: kevin-harrington

View File

@@ -0,0 +1,10 @@
name: "Validate Gradle Wrapper"
on: [push]
jobs:
validation:
name: "Validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1

27
Java/BowlerStudio/.gitignore vendored Normal file
View File

@@ -0,0 +1,27 @@
/build/
/.nb-gradle/private/
/bin/
/JFXScad.jar
/servoTest.jfxscad
/wheel.stl
/.gradle*
/.gradle*
/.project
/.classpath
/.settings*
/.idea*
/build/
/whitecylinder/
*.iml
/CSGdatabase.json
/jbullet-20101010/
/.DS_Store
*hs_err_pid*.log*
*.debuggerDefaults*
/*.svg
/*.svg.png
/.combined.png-autosave.kra
/combined.png
/Oracle_VM_VirtualBox_Extension_Pack-5.2.20.vbox-extpack
/chdk-ptp-java.log

3
Java/BowlerStudio/.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "libraries/bowler-script-kernel"]
path = libraries/bowler-script-kernel
url = https://github.com/CommonWealthRobotics/bowler-script-kernel.git

View File

@@ -0,0 +1,20 @@
language: java
before_install:
- "export DISPLAY=:99.0"
- "export TERM=dumb"
- "sh -e /etc/init.d/xvfb start"
script:
- TERM=dumb ./gradlew compileJava javadoc
cache:
directories:
- $HOME/.m2
jdk:
- oraclejdk8
# for running tests on Travis CI container infrastructure for faster builds
sudo: true
dist: trusty

76
Java/BowlerStudio/COC.md Normal file
View File

@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies within all project spaces, and it also applies when
an individual is representing the project or its community in public spaces.
Examples of representing a project or community include using an official
project e-mail address, posting via an official social media account, or acting
as an appointed representative at an online or offline event. Representation of
a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

View File

@@ -0,0 +1,9 @@
### Installed Version
### OS type and version number
### Expected behavior
### Actual Behavior
### Steps to reproduce the behavior

674
Java/BowlerStudio/LICENSE Normal file
View File

@@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

192
Java/BowlerStudio/README.md Normal file
View File

@@ -0,0 +1,192 @@
BowlerStudio
==========
[![Join the chat at https://gitter.im/CommonWealthRobotics/BowlerStudio](https://badges.gitter.im/CommonWealthRobotics/BowlerStudio.svg)](https://gitter.im/CommonWealthRobotics/BowlerStudioDevelopment?utm_source=share-link&utm_medium=link&utm_campaign=share-link)
[![Build Status](https://travis-ci.org/CommonWealthRobotics/BowlerStudio.svg?branch=development)](https://travis-ci.org/CommonWealthRobotics/BowlerStudio)
[![Github All Releases](https://img.shields.io/github/downloads/CommonWealthRobotics/BowlerStudio/total.svg)](https://github.com/CommonWealthRobotics/BowlerStudio/releases)
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/2904/badge)](https://bestpractices.coreinfrastructure.org/projects/2904)
# [Download Latest](https://github.com/CommonWealthRobotics/BowlerStudio/releases)
## Ubuntu 18.04
sudo add-apt-repository ppa:mad-hephaestus/commonwealthrobotics -y
sudo apt-get update
sudo apt-get install bowlerstudio
bowlerstudio
## Debian
sudo apt-get install software-properties-common python-software-properties
sudo add-apt-repository "deb http://ppa.launchpad.net/mad-hephaestus/commonwealthrobotics/ubuntu xenial main" -y
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 71EA898B
sudo add-apt-repository "deb http://ppa.launchpad.net/mad-hephaestus/commonwealthrobotics/ubuntu bionic main" -y
sudo apt-get update
sudo apt-get install bowlerstudio
# What is BowlerStudio?
BowlerStudio assists you in every step of a robotics project from concept to completion. Tools enable users to:
* Interface with motors, sensors, and other electronics hardware.
* Create 3d models for fabrication, and for simulating the motions of your project.
* Give your robot sight with image processing on camera feeds and Kinect data.
* Operate 3d printers and other CNC machines.
* Create custom graphical user interfaces to control yours robots.
* Create and control animations.
==========
## The Nitty-Gritty Version
BowlerStudio Robotics development IDE is based on
* [JCSG](https://github.com/miho/JCSG)
* [Java-Bowler](https://github.com/NeuronRobotics/java-bowler)
* [Jinput](https://github.com/jinput/jinput)
* [motej](http://motej.sourceforge.net/)
* [Usb4Java](https://github.com/usb4java/usb4java)
* [NrJavaSerial](https://github.com/NeuronRobotics/nrjavaserial)
* [BlueCove](https://github.com/hcarver/bluecove)
* JavaFX 8 3d engine.
* [JBullet](http://jbullet.advel.cz/) physics engine ported from the popular Bullet C++ framework.
* [Jetty](http://www.eclipse.org/jetty/) Web Framework
BowlerStudio is a device manager, scripting engine, CAD package, and simulation tool all in one application. A user can develop the kinematic of an robot arm using the D-H parameters-based automatic kinematics engine. With this kinematics model, the user can then generate the CAD for new unique parts to match the kinematic model. The user can then export the model to an STL, and connect a Bowler 3d printer to BowlerStudio. The printer can print out the part (using the newly generated STL) while the user connects a DyIO and begins testing the servos with the kinematics model. When the print is done, the user can assemble the arm with the tested servos and run the model again to control the arm with Cartesian instructions. Once this is complete, the user can then attach a wiimote to train the robot arm through a set of tasks, recording them with the animation framework built into BowlerStudio. To be sure the arm is moving to the right place, the user can attach a webcam to the end and use OpenCV to verify the arm's position, or use the arm (in conjunction with the webcam with OpenCV enabled) to track and grab objects (IE "eye-in-hand" tracking).
Every step of this task can be performed from within BowlerStudio!
Let's go through the main features:
# Scripting With Gist
### About scripts and Gist
Scripts are bits of code that BowlerStudio can load and run. BowlerStudio allows you to open a local file and run it, but BowlerStudio is most powerful when the code lives on Github Gist (a code snippet hosting service from Github). Simply give BowlerStudio the URL for a Gist you want to load and execute. Gists can be selected and edited using the built in browser, or inline in another script using the Gist ID.
### Java and Groovy
BowlerStudio can load and run scripts written in Java, Groovy, and Python. Which parser is used is determined by the file extension. Files that end in .java or .groovy will be run through the Groovy compiler. These Groovy scripts are compiled fully and run directly in the JVM. This means they will execute at full speed, just like a regular application.
### Python
Python, on the other hand, by virtue of its structure, will generally execute much slower then Java. With the reduction in speed you get lots of flexibility and a clean and easy to understand syntax. The python code can also create and return objects to BowlerStudio (such as CAD CSG objects, or UI Tabs).
### Return Objects
A script can return a few object types that will be handled by BowlerStudio:
Objects of type "CSG" and "MeshView" will be added to the 3d display. If a transform is added to either of these and updated by a script the user can move an object in the 3d view.
Objects of type "Tab" will be added to the Tabmanager and displayed in BowlerStudio. This is an easy way to make control panels or state displays and monitors.
Objects of type "BowlerAbstractDevice" (or any subclass) will be added to the connections manager and made available to all other scripts. These can be external devices or virtual communication bus devices. A bowler Server/Client pair is the preferred mechanism for communication between scripts.
### Device Access
All scripts are passed all connected devices by name when the script is run. The name associated with the device in the connections tab is the name to use in the script to access that device. A script can also create and return a device (EG to connect to a specific device in order to give that device a specific name). The device returned will be added to the list of available devices and be available to other scripts. A user can define their own devices to facilitate communication between scripts.
# Bowler Devices
BowlerDevices (such as the Neuron Robotics DyIO) are devices that implement the Bowler Communication System. BowlerDevices are servers of features to applications. The DyIO, for example, is a server of microcontroller features. These devices implement a micro domain-specific language as a protocol. This language synchronizes the device with the application by building the communication system at runtime using a namespace/RPC system.
As such, the device is treated as a collection of namespaces. Each namespace has a set of RPCs for communication, some synchronous (IE they are application initiated) and some asynchronous (IE device initiated). In addition, each RPC has full method introspection. This means that all parameters and datatypes (including how to pack and interpret all packets) are able to be queried over the communication system. A Library need only implement the core packet parser and every device will assemble its own communication layer live.
# Cameras
Cameras can be connected to Bowler Studio using one of 3 supported drivers:
OpenCV's native Java bindings are provided by installing OpenCV using your OS specific installer (unfortunately not available for Mac at this time).
JavaCV is a meta-library that adds support for a wide range of camera device integrations and image processing options. This is a big project and integrated now with a full scripting system.
CHDK-PTP-Java is a Java library that adds support for SLR Cannon cameras. CHDK is a camera OS that makes the cameras features available over USB, and the Java library makes those images and controls available to Java and or scripting engine.
# Image processing
Image processing is provided be a variety of libraries included in this application. OpenCV and ARToolkit are some of the most widely used image recognition libraries available, and now you can use them directly from our scripting environment!
# Kinematics Engine
The Bowler Kinematics engine is based on [D-H parameters](https://www.youtube.com/embed/rA9tm0gTln8)- the standard mathematical definition of kinematics chains. This standard simplifies the calculation process and allows us to run forward kinematics equations for arbitrary defined chains in real time. For inverse kinematics, a collection of kinematic engines are available for optimizing for speed and accuracy.
# Real-Time validated
For applications where real time is required, there is no need to leave the Bowler OS. The Bowler Java stack has been validated as real-time capable when run on JamaicaVM (the real-time Java implementation). The Bowler Kinematics engine is run in a real-time loop for neurosurgery applications (Bowler and Java are fast and reliable enough for brain surgery!)
# 3D CAD
Users can write scripts using Java, Groovy or Python to generate CSG style CAD. This programmatic CAD engine JCSG was inspired by OpenSCAD, but implemented in pure Java with JavaFX visualizations. JCSG implements all basic shape generation and manipulation, using Java's library packaging and distribution for libraries of parts. Gist hosting of parts can also simplify sharing and loading of dependent libraries.
# Virtualization
### Virtual links
Virtual PID devices allow users to make applications that can be simulated with virtual links before ever connecting a real device.
Users can also use the PIDLab to learn about designing and implementing PID controllers with a built in motor physics simulation.
### Virtual Camera
Coming soon! Soon users will be able to interact with the 3D environment camera from their code just like a real camera. Users will be able to manipulate it just like it was another 3d object.
### Virtual Sensors
Coming soon! Soon we will be able to provide virtual sensor devices, simulating real world sensors within the 3d environment.
# Make A Contribution
BowlerStudio is an open source project and is always looking for help with both the application code and the tutorials content.
### Java Contributions
If you are a Java developer, skip ahead to [The Build Instructions](#command-line). The application is a light plugin framework for UI, 3D and Device interaction. You can look at this repository for issues.
### Adding Tutorials
All of the content for BowlerStudio Tutorials is housed on our [Neuronrobotics.github.io](https://github.com/CommonWealthRobotics/CommonWealthRobotics.github.io) web page. Fork that repository and make contributions based on the README.md file in the root of the repository. To merge the changes into the main website, send a pull request with your changes to official repository.
Examples of tutorials that need to be added are [A simple Java Programming Introduction](https://github.com/CommonWealthRobotics/CommonWealthRobotics.github.io/issues/59). This tutorial set would go through the basic syntax of java and what all of the symbols mean and how to use them.
Another example of a tutorial that could be added is one for [JavaCad Cheatsheet](https://github.com/CommonWealthRobotics/CommonWealthRobotics.github.io/issues/58) where you would add a 'cheat sheet' of commands to use in the JavaCad system.
If a tutorial is missing and not described as needed by an issue, feel free to add additional issues.
## How to Build BowlerStudio
### Requirements
- Java >= 1.8
- Internet connection (dependencies are downloaded automatically)
- IDE: [Gradle](http://www.gradle.org/) Plugin (not necessary for command line usage)
- OpenCV 2.4.9 installed and configured in the library paths (OS installers preferred)
- The Binary installer for BowlerStudio must be installed before develpment.
### IDE
Open the `BowlerStudio` [Gradle](http://www.gradle.org/) project in your favorite IDE (tested with NetBeans 7.4) and build
by calling the `assemble` task.
### Command Line
Navigate to the [Gradle](http://www.gradle.org/) project (e.g., `path/to/BowlerStudio`) and enter the following command:
#### Bash (Linux/OS X/Cygwin/other Unix-like shell)
##### Ubuntu 18.04 Dependencies
```
sudo apt install curl
```
##### Ubuntu 16.04 Dependencies
```
sudo apt-get install git gradle
```
##### Ubuntu 14.04, install extra dependencies
```
sudo add-apt-repository "deb http://ppa.launchpad.net/mad-hephaestus/commonwealthrobotics/ubuntu xenial main" -y
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 71EA898B
sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu/ trusty universe multiverse"
sudo apt-get update -qq
sudo apt-get install -y --force-yes gradle
```
##### All Unix
```
bowlerstudio # run this to get the JVM downloaded into $HOME/bin/java8/jre
git clone https://github.com/CommonWealthRobotics/BowlerStudio.git
JAVA_HOME=$HOME/bin/java8/jre
export JAVA_HOME
cd BowlerStudio
git submodule update --init --recursive
git submodule update --recursive
./gradlew shadowJar
$JAVA_HOME/bin/java -jar build/libs/BowlerStudio*.jar
```
Now you can use the Eclipse Marketplace to install the Gradle Plugin
#### Windows (CMD)
gradlew jar
# History
Bowler Studio began [Feb 11, 2015](https://github.com/CommonWealthRobotics/BowlerStudio/releases/tag/0.0.1) with the goal of making a robotics IDE.

View File

@@ -0,0 +1,354 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:5.0.0'
}
}
boolean is64Bit() {
////System.out.println("Arch: "+getOsArch());
return getOsArch().startsWith("x86_64") || getOsArch().startsWith("amd64");
}
boolean isARM() {
return getOsArch().startsWith("arm");
}
boolean isCortexA8(){
if(isARM()){
//TODO check for cortex a8 vs arm9 generic
return true;
}
return false;
}
boolean isWindows() {
////System.out.println("OS name: "+getOsName());
return getOsName().toLowerCase().startsWith("windows") ||getOsName().toLowerCase().startsWith("microsoft") || getOsName().toLowerCase().startsWith("ms");
}
boolean isLinux() {
return getOsName().toLowerCase().startsWith("linux");
}
boolean isOSX() {
return getOsName().toLowerCase().startsWith("mac");
}
String getExtension() {
if(isWindows()) {
return ".dll";
}
if(isLinux()) {
return ".so";
}
if(isOSX()) {
return ".jnilib";
}
return "";
}
String getOsName() {
return System.getProperty("os.name");
}
String getOsArch() {
return System.getProperty("os.arch");
}
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
apply plugin: 'java'
apply plugin: 'signing'
apply plugin: 'maven'
apply plugin: 'application'
//apply plugin: 'edu.sc.seis.launch4j'
sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
// NetBeans will automatically add "run" and "debug" tasks relying on the
// "mainClass" property. You may however define the property prior executing
// tasks by passing a "-PmainClass=<QUALIFIED_CLASS_NAME>" argument.
//
// Note however, that you may define your own "run" and "debug" task if you
// prefer. In this case NetBeans will not add these tasks but you may rely on
// your own compile.
ext.mainClass = 'com.neuronrobotics.bowlerstudio.BowlerStudio'
File buildDir = file(".");
configurations.all {
exclude module: 'slf4j-log4j12'
}
sourceSets {
test {
java {
srcDirs = ["test/java/src" ] // Note @Peter's comment below
}
}
}
/*
launch4j {
mainClassName = ext.mainClass
icon = buildDir.getAbsolutePath()+"/src/main/resources/CommonWealthRobotics.ico"
}
*/
Properties props = new Properties()
props.load(new FileInputStream(buildDir.getAbsolutePath()+"/src/main/resources/com/neuronrobotics/bowlerstudio/build.properties"))
repositories {
maven { url 'https://oss.sonatype.org/service/local/repositories/releases/content/' }
//com.neuronrobotics hosting point
maven { url 'https://oss.sonatype.org/content/repositories/staging/' }
mavenCentral()
jcenter()
maven { url 'https://repository-bubblecloud.forge.cloudbees.com/release/'}
maven { url 'https://clojars.org/repo' }
maven { url 'https://jline.sourceforge.net/m2repo' }
maven { url 'https://repo.spring.io/milestone'}
maven { url 'https://jenkinsci.artifactoryonline.com/jenkinsci/public/' }
maven { url 'https://plugins.gradle.org/m2/' }
maven { url 'https://dl.bintray.com/clearcontrol/ClearControl' }
maven { url "https://jitpack.io" }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://oss.sonatype.org/service/local/staging/deploy/maven2/' }
maven { url 'https://oss.sonatype.org/content/repositories/releases/' }
maven { url 'https://dl.bintray.com/commonwealthrobotics/maven-artifacts' }
maven { url "https://dl.bintray.com/s1m0nw1/KtsRunner" }
}
dependencies {
compile group: 'org.json', name: 'json', version: '20180813'
compile 'com.google.crypto.tink:tink:1.3.0-rc1'
compile 'gov.nist.math:jama:1.0.2'
compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.6'
compile group: 'org.reactfx', name: 'reactfx', version: '2.0-SNAPSHOT'
compile group: 'org.codehaus.groovy', name: 'groovy', version:'2.3.7';
//make grapes work
compile group: 'org.apache.ivy', name:'ivy', version:'2.2.0'
compile group: 'org.controlsfx', name: 'controlsfx', version: '8.0.6'
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
compile group: 'commons-codec', name: 'commons-codec', version: '1.7'
compile 'org.kohsuke.stapler:stapler:1.237'
// https://mvnrepository.com/artifact/org.eclipse.jgit/org.eclipse.jgit
compile group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '5.6.0.201912101111-r'
compile group: 'com.squareup.okhttp', name: 'okhttp-urlconnection', version: '2.0.0'
compile group: 'org.kohsuke', name: 'wordnet-random-name', version: '1.2'
compile group: 'org.mockito', name: 'mockito-all', version: '1.9.5'
compile group: 'com.infradna.tool', name: 'bridge-method-injector', version: '1.14'
compile group: 'com.neuronrobotics', name:'GithubPasswordManager', version:'0.5.0'
compile 'com.miglayout:miglayout-swing:4.2'
compile 'commons-io:commons-io:2.4'
compile group:'org.python',name:'jython',version:'2.5.3'
compile group:'org.python',name:'jython-standalone',version:'2.5.2'
compile 'org.clojure:clojure:1.8.0'
// jetty server
compile "org.eclipse.jetty:jetty-server:9.0.2.v20130417"
compile "org.eclipse.jetty:jetty-servlet:9.0.2.v20130417"
compile "org.eclipse.jetty:jetty-servlets:9.0.2.v20130417"
compile "org.eclipse.jetty:jetty-webapp:9.0.2.v20130417"
compile "javax.servlet:javax.servlet-api:3.1.0"
//compile 'org.clojure:tools.nrepl:0.2.10'
//compile "overtone:overtone:0.9.1"
//compile "edu.cmu.sphinx:sphinx4-core:5prealpha-SNAPSHOT"
//compile "edu.cmu.sphinx:sphinx4-data:5prealpha-SNAPSHOT"
compile group: 'java3d', name: 'vecmath', version: '1.3.1'
compile 'org.slf4j:slf4j-simple:1.6.1'
//compile "com.neuronrobotics:JavaCad:0.14.0"
compile "com.neuronrobotics:CHDK-PTP-Java:0.5.3-SNAPSHOT"
//compile "com.neuronrobotics:java-bowler:3.25.4"
//compile fileTree (dir: '../java-bowler/build/libs/', includes: ['nrsdk-3.23.3-jar-with-dependencies.jar'])
//compile fileTree (dir: '../JCSG/build/libs/', includes: ['JavaCad-0.8.2.jar'])
compile "com.neuronrobotics:WalnutiQ:2.3.3"
/*
String basedir =System.getenv("OPENCV_DIR")+"/java/opencv-249.jar";
if(isWindows()){
basedir =System.getenv("OPENCV_DIR")+"\\..\\..\\java\\opencv-249.jar";
println("OPENCV_DIR="+basedir);
compile files(basedir)
}
if(isOSX()){
basedir =System.getenv("OPENCV_DIR")+"../../java/opencv-249.jar";
println("OPENCV_DIR="+basedir);
if(System.getenv("OPENCV_DIR")!=null)
compile files(basedir)
else
//If you set your OPENCV_DIR environment variable, then we wouldnt have to do hacky things
compile files('/Applications/BowlerStudio.app/Contents/MacOS/opencv249build/bin/opencv-249.jar')
}
if(isLinux()){
//compile files('/usr/share/java/opencv-249.jar')
if(new File("/usr/share/OpenCV/java/").exists()){
System.out.println("Using the legacy opencv dir ")
compile fileTree (dir: '/usr/share/OpenCV/java/', includes: ['*opencv-24*.jar'])
}else{
compile fileTree (dir: '/usr/share/java/', includes: ['*opencv-24*.jar'])
}
}
*/
//compile group: 'jfree', name: 'jfreechart', version: '1.0.12'
compile group: 'jexcelapi', name: 'jxl', version: '2.4.2'
//compile group: 'com.google.zxing', name: 'zxing-parent', version: '3.2.0'
//compile group:'com.github.ellzord', name:'JALSE', version:'1.0.9'
compile group:'de.huxhorn.sulky', name:'de.huxhorn.sulky.3rdparty.jlayer', version:'1.0'
//compile("org.springframework.boot:spring-boot-starter-web:1.2.7.RELEASE")
compile 'com.google.code.gson:gson:2.5'
compile 'org.jsoup:jsoup:1.8.3'
compile 'org.apache.httpcomponents:httpclient:4.5.1'
//compile 'cz.advel.jbullet:jbullet:20101010-1'
//compile 'org.bubblecloud.jbullet:jbullet:2.72.2.4'// replaced by local jar because jbullet maven went down
//compile "alda:alda:1.0.0-rc14"
//Deep Learning 4 j and dependancies
/*
compile 'org.deeplearning4j:deeplearning4j-core:0.4-rc3.8'
//compile 'org.nd4j:nd4j-x86:0.4-rc3.8'
compile 'org.deeplearning4j:deeplearning4j-nlp:0.4-rc3.8'
compile 'org.deeplearning4j:deeplearning4j-ui:0.4-rc3.8'
//compile 'com.google.guava:guava:19.0'
compile 'org.nd4j:canova-nd4j-image:0.0.0.14'
compile 'org.nd4j:canova-nd4j-codec:0.0.0.14'
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.5.1'
*/
// JScience:
//compile 'org.jscience:jscience:4.3.1'
compile 'javax.media:jmf:2.1.1e'
//Weka
//compile 'nz.ac.waikato.cms.weka:weka-stable:3.6.13'
//Firmata
compile 'com.github.kurbatov:firmata4j:2.3.4.1'
compile group: 'jfree', name: 'jfreechart', version: '1.0.12'
//compile fileTree (dir: '../bowler-script-kernel/build/libs', includes: ['BowlerScriptingKernel-0.25.4.jar'])
testCompile group: 'junit', name: 'junit', version: '4.10'
//compile "org.jfxtras:jfxtras-common:8.0-r4"
//compile "org.jfxtras:jfxtras-fxml:8.0-r4"
//compile "org.jfxtras:jfxtras-controls:8.0-r4"
//compile "org.jfxtras:jfxtras-agenda:8.0-r4"
//compile "org.jfxtras:jfxtras-window:8.0-r4"
//compile "org.jfxtras:jfxtras-menu:8.0-r4"
//compile "org.jfxtras:jfxtras-labs:8.0-r4"
//https://bintray.com/clearcontrol/ClearControl/DockFX
compile 'org.dockfx:DockFX:0.1.12'
//compile 'com.github.movisens:SmartGattLib:1.7'
// https://mvnrepository.com/artifact/org.apache.xmlrpc/xmlrpc-client
compile group: 'org.apache.xmlrpc', name: 'xmlrpc-client', version: '3.1.3'
// https://mvnrepository.com/artifact/com.abercap/odoo-java-api
//compile group: 'com.abercap', name: 'odoo-java-api', version: '1.1.0.RELEASE'
//http://www.jocl.org/
//compile group: 'org.jocl', name: 'jocl', version: '2.0.0'
// https://mvnrepository.com/artifact/com.nativelibs4java/jnaerator
//compile group: 'com.nativelibs4java', name: 'jnaerator', version: '0.11'
// https://mvnrepository.com/artifact/com.github.kurbatov/firmata4j
// https://mvnrepository.com/artifact/com.fifesoft/rsyntaxtextarea
compile group: 'com.fifesoft', name: 'rsyntaxtextarea', version: '2.6.0'
//compile 'org.bubblecloud.jbullet:jbullet:2.72.2.4'
// https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-svggen
compile group: 'org.apache.xmlgraphics', name: 'batik-svggen', version: '1.7'
// https://mvnrepository.com/artifact/org.axsl.org.w3c.dom.svg/svg-dom-java
compile group: 'org.axsl.org.w3c.dom.svg', name: 'svg-dom-java', version: '1.1'
compile fileTree (dir: 'libs/', includes: ['*.jar'])
//compile fileTree (dir: 'libraries/bowler-script-kernel/libs/', includes: ['*.jar'])
compile project(':libraries:bowler-script-kernel:java-bowler')
compile project(':libraries:bowler-script-kernel')
compile project(':libraries:bowler-script-kernel:JCSG')
//compile project(':kinematics-chef')
//compile 'com.neuronrobotics:kinematics-chef-core:0.0.15'
//compile fileTree (dir: 'libraries/java-bowler/libs/', includes: ['*.jar'])
// compile group: 'de.dfki.mary', name: 'voice-cmu-slt-hsmm', version: '5.2'
// https://mvnrepository.com/artifact/de.dfki.mary/voice-dfki-poppy-hsmm
compile group: 'de.dfki.mary', name: 'voice-dfki-poppy-hsmm', version: '5.2'
// https://mvnrepository.com/artifact/de.dfki.mary/voice-dfki-poppy-hsmm
compile group: 'de.dfki.mary', name: 'voice-dfki-prudence-hsmm', version: '5.2'
// https://mvnrepository.com/artifact/de.dfki.mary/voice-dfki-poppy-hsmm
compile group: 'de.dfki.mary', name: 'voice-dfki-spike-hsmm', version: '5.2'
// https://mvnrepository.com/artifact/de.dfki.mary/marytts-lang-en
compile group: 'de.dfki.mary', name: 'marytts-lang-en', version: '5.2'
}
// create a fat-jar (class files plus dependencies
// excludes VRL.jar (plugin jar files must not start with 'vrl-\\d+')
jar {
//zip64 true
jar.duplicatesStrategy = DuplicatesStrategy.EXCLUDE
jar.baseName= "BowlerStudio";
// project class files compiled from source
//from files(sourceSets.main.output.classesDir)
manifest {
attributes(
"Main-Class": 'com.neuronrobotics.bowlerstudio.BowlerStudio',
"SplashScreen-Image": "com/neuronrobotics/nrconsole/images/splash.png",
"Manifest-Version": "1.0",
"Created-By": "CommonWealth Robotics Cooperative",
"Specification-Title": props."app.name",
"Specification-Version": props."app.version",
"Specification-Vendor": "CommonWealth Robotics Cooperative",
"Implementation-Title": props."app.name",
"Implementation-Version" : props."app.version",
"Implementation-Vendor": "CommonWealth Robotics Cooperative"
)
}
}
shadowJar {
zip64 true
mainClassName = 'com.neuronrobotics.bowlerstudio.BowlerStudio'
baseName = 'BowlerStudio'
classifier = "fat"
version = props."app.version"
mergeServiceFiles()
}
//task run(type: JavaExec) {
// classpath = sourceSets.main.runtimeClasspath
// main = mainClass;
// // jvmArgs = ['-Dprism.forceGPU=true', '-Dprism.verbose=true']
// jvmArgs = ['-Dprism.forceGPU=true']
//}

2
Java/BowlerStudio/debian/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/changelog.bak
/.changelog.swp

View File

@@ -0,0 +1,6 @@
bowlerstudio for Debian
----------------------
<possible notes regarding this package - if none, delete this file>
-- Kevin Harrington <mad.hephaestus@gmail.com> Sun, 26 Jun 2016 11:43:09 -0400

View File

@@ -0,0 +1,10 @@
bowlerstudio for Debian
----------------------
<this file describes information about the source package, see Debian policy
manual section 4.14. You WILL either need to modify or delete this file>
-- Kevin Harrington <mad.hephaestus@gmail.com> Sun, 26 Jun 2016 11:43:09 -0400

View File

@@ -0,0 +1,2 @@
README.source
README.Debian

View File

@@ -0,0 +1,20 @@
Document: bowlerstudio
Title: Debian bowlerstudio Manual
Author: <insert document author here>
Abstract: This manual describes what bowlerstudio is
and how it can be used to
manage online manuals on Debian systems.
Section: unknown
Format: debiandoc-sgml
Files: /usr/share/doc/bowlerstudio/bowlerstudio.sgml.gz
Format: postscript
Files: /usr/share/doc/bowlerstudio/bowlerstudio.ps.gz
Format: text
Files: /usr/share/doc/bowlerstudio/bowlerstudio.text.gz
Format: HTML
Index: /usr/share/doc/bowlerstudio/html/index.html
Files: /usr/share/doc/bowlerstudio/html/*.html

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -0,0 +1 @@
7

View File

@@ -0,0 +1,13 @@
Source: bowlerstudio
Package: bowlerstudio
Priority: extra
Maintainer: Customer Support <mad.hephaestus@gmail.com>
Architecture: all
Version: 0.18.6
Depends: oracle-java8-set-default,libopencv2.4-java,libopencv2.4-jni,slic3r,jarwrapper,arduino
Provides: bowlerstudio
Conflicts: modemmanager,nr-rdk-java
Replaces: modemmanager,nr-rdk-java
Description: Robotics Development Engironment and runtime.
A scripting platform for writing, designing, simulating
and manufacturing robots.

View File

@@ -0,0 +1,38 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: bowlerstudio
Source: <url://example.com>
Files: *
Copyright: <years> <put author's name and email here>
<years> <likewise for another author>
License: <special license>
<Put the license of the package here indented by 1 space>
<This follows the format of Description: lines in control file>
.
<Including paragraphs>
# If you want to use GPL v2 or later for the /debian/* files use
# the following clauses, or change it to suit. Delete these two lines
Files: debian/*
Copyright: 2016 Kevin Harrington <mad.hephaestus@gmail.com>
License: GPL-2+
This package is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
.
This package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>
.
On Debian systems, the complete text of the GNU General
Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".
# Please also look if there are files or directories which have a
# different copyright/license attached and list them here.
# Please avoid picking licenses with terms that are more restrictive than the
# packaged work, as it may make Debian's contributions unacceptable upstream.

View File

@@ -0,0 +1,10 @@
usr/share/bowlerstudio/BowlerStudio.jar /usr/share/bowlerstudio/
usr/share/bowlerstudio/NeuronRobotics.ico /usr/share/bowlerstudio/
usr/share/bowlerstudio/NeuronRobotics.png /usr/share/bowlerstudio/
usr/share/bowlerstudio/dyio-3.14.6.xml /usr/share/bowlerstudio/
usr/bin/bowlerstudio /usr/bin/
usr/share/bowlerstudio/NeuronRobotics.png /usr/share/themes/base/neuronrobotics/icons/
usr/share/bowlerstudio/BowlerStudio.desktop /usr/share/applications/
usr/share/bowlerstudio/81-neuronrobotics.rules /etc/udev/rules.d/
usr/share/doc/bowlerstudio/copyright /usr/share/doc/bowlerstudio/
usr/share/doc/bowlerstudio/changelog.gz /usr/share/doc/bowlerstudio/

View File

@@ -0,0 +1 @@
3.0 (quilt)

View File

@@ -0,0 +1,14 @@
JAVA_HOME=/usr/lib/jvm/default-java
%:
dh $@ --with javahelper
override_dh_auto_build:
dh_auto_build -- dist
override_dh_install:
dh_auto_build -- package-debian
dh_install
override_jh_exec:
exit 0

Binary file not shown.

View File

@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

183
Java/BowlerStudio/gradlew vendored Normal file
View File

@@ -0,0 +1,183 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

103
Java/BowlerStudio/gradlew.bat vendored Normal file
View File

@@ -0,0 +1,103 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@@ -0,0 +1,2 @@
/.project
/.settings/

4
Java/BowlerStudio/libs/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
/nrsdk-3.11.3-jar-with-dependencies.jar
/BowlerScriptingKernel.jar
/weka-3-8-0/
/debugger.jar

Binary file not shown.

1
Java/BowlerStudio/log/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/server.log

View File

@@ -0,0 +1,11 @@
include ':libraries:bowler-script-kernel'
include ':libraries:bowler-script-kernel:java-bowler'
include ':libraries:bowler-script-kernel:JCSG'
rootProject.name = 'BowlerStudio'
//includeBuild('kinematics-chef'){
// dependencySubstitution {
// substitute module('com.neuronrobotics:kinematics-chef-core') with project(':')
// }
//}

View File

@@ -0,0 +1,164 @@
package com.neuronrobotics.bowlerstudio;
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.bowlerstudio.scripting.IScriptingLanguage;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Modality;
import javafx.stage.Stage;
import java.io.File;
import java.util.List;
/**
* Created by Ryan Benasutti on 2/6/2016.
*/
@SuppressWarnings("restriction")
public class AddFileToGistController extends Application {
@FXML
public TextField filenameField;
@FXML
public Button addFileButton, cancelButton;
@FXML
private ComboBox<String> extention;
@FXML // fx:id="langaugeIcon"
private ImageView langaugeIcon; // Value injected by FXMLLoader
private String extentionStr = ".groovy";
private String gitRepo;
@FXML
private TextArea description;
private MenuRefreshEvent refreshevent;
// private GHGist gistID;
public AddFileToGistController(String gitRepo,MenuRefreshEvent event) {
this.gitRepo = gitRepo;
// this.gistID = id;
this.refreshevent = event;
}
@SuppressWarnings("restriction")
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = AssetFactory.loadLayout("layout/addFileToGist.fxml", true);
Parent root;
loader.setController(this);
// This is needed when loading on MAC
loader.setClassLoader(getClass().getClassLoader());
root = loader.load();
extention.getItems().clear();
List<String> langs = ScriptingEngine.getAllLangauges();
ObservableList<String> options = FXCollections.observableArrayList(langs);
//
for(String s:options){
extention.getItems().add(s);
}
extention.getSelectionModel().select("Groovy");
Image icon;
String asset = "Script-Tab-" + extention.getSelectionModel().getSelectedItem() + ".png";
try {
icon = AssetFactory.loadAsset(asset);
langaugeIcon.setImage(icon);
} catch (Exception e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
extention.setOnAction(event -> {
try {
langaugeIcon.setImage(AssetFactory
.loadAsset(asset));
String key = extention.getSelectionModel().getSelectedItem();
IScriptingLanguage l = ScriptingEngine
.getLangaugesMap()
.get(key);
if(l!=null){
extentionStr= "."+l.getFileExtenetion()
.get(0);
}
else
extentionStr=".groovy";
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
});
Platform.runLater(() -> {
primaryStage.setTitle("Add File to Git Repo "+gitRepo);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.initModality(Modality.WINDOW_MODAL);
primaryStage.setResizable(true);
primaryStage.show();
});
}
@FXML
public void onAddFile(ActionEvent event) {
new Thread(()->{
Platform.runLater(() -> {
Stage stage = (Stage) addFileButton.getScene().getWindow();
stage.close();
});
String text = filenameField.getText();
if(!text.endsWith(extentionStr)){
text=text+extentionStr;
}
String message = description.getText();
if(message == null || message.length()==0){
message = text;
}
if(gitRepo==null){
gitRepo=GistHelper.createNewGist(text, message, true);
}
System.out.println("Adding new file"+text+" to "+gitRepo);
try {
ScriptingEngine.pushCodeToGit(gitRepo, ScriptingEngine.getFullBranch(gitRepo), text, "//Your code here",
message);
File nf = ScriptingEngine.fileFromGit(gitRepo, text);
BowlerStudio.createFileTab(nf);
refreshevent.setToLoggedIn();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}).start();
}
@FXML
public void onCancel(ActionEvent event) {
Platform.runLater(() -> {
Stage stage = (Stage) cancelButton.getScene().getWindow();
stage.close();
});
}
}

View File

@@ -0,0 +1,788 @@
package com.neuronrobotics.bowlerstudio;
//import com.neuronrobotics.kinematicschef.InverseKinematicsEngine;
import com.neuronrobotics.bowlerkernel.BowlerKernelBuildInfo;
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.bowlerstudio.assets.BowlerStudioResourceFactory;
import com.neuronrobotics.bowlerstudio.assets.ConfigurationDatabase;
import com.neuronrobotics.bowlerstudio.assets.StudioBuildInfo;
import com.neuronrobotics.bowlerstudio.creature.MobileBaseCadManager;
import com.neuronrobotics.bowlerstudio.creature.MobileBaseLoader;
import com.neuronrobotics.bowlerstudio.scripting.ArduinoLoader;
import com.neuronrobotics.bowlerstudio.scripting.PasswordManager;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingFileWidget;
import com.neuronrobotics.bowlerstudio.scripting.StlLoader;
import com.neuronrobotics.imageprovider.NativeResource;
//import com.neuronrobotics.imageprovider.OpenCVJNILoader;
import com.neuronrobotics.javacad.JavaCadBuildInfo;
import com.neuronrobotics.replicator.driver.Slic3r;
import com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics;
import com.neuronrobotics.sdk.addons.kinematics.FirmataLink;
import com.neuronrobotics.sdk.addons.kinematics.JavaFXInitializer;
import com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration;
import com.neuronrobotics.sdk.addons.kinematics.MobileBase;
import com.neuronrobotics.sdk.common.*;
import com.neuronrobotics.sdk.config.SDKBuildInfo;
import com.neuronrobotics.sdk.util.ThreadUtil;
import eu.mihosoft.vrl.v3d.CSG;
import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase;
import eu.mihosoft.vrl.v3d.svg.ISVGLoadProgress;
import eu.mihosoft.vrl.v3d.svg.SVGLoad;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.TextArea;
import javafx.stage.Modality;
import javafx.stage.Stage;
import org.dockfx.DockPane;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.TransportException;
import org.kohsuke.github.GHIssue;
import org.kohsuke.github.GHIssueState;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GitHub;
import org.python.antlr.ast.Pass;
import org.reactfx.util.FxTimer;
import org.w3c.dom.Document;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.Thread.UncaughtExceptionHandler;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@SuppressWarnings("restriction")
public class BowlerStudio extends Application {
final static SplashScreen splash = null;// = SplashScreen.getSplashScreen();
private static Scene scene;
private static boolean hasnetwork;
private static Console out;
private static TextArea logViewRefStatic = null;
private static String firstVer = "";
private static Stage primaryStage2;
private static File layoutFile;
private static boolean deleteFlag = false;
private static IssueReportingExceptionHandler reporter = new IssueReportingExceptionHandler();
private static String lastVersion;
private static class Console extends OutputStream {
private static final int LengthOfOutputLog = 5000;
ByteList incoming = new ByteList();
Thread update = new Thread() {
public void run() {
Thread.currentThread().setUncaughtExceptionHandler(new IssueReportingExceptionHandler());
while (true) {
ThreadUtil.wait(150);
if (incoming.size() > 0)
try {
String text = incoming.asString();
incoming.clear();
if (text != null && text.length() > 0)
appendText(text);
text = null;
} catch (Exception e) {
e.printStackTrace();
}
}
}
};
public Console() {
update.start();
}
@SuppressWarnings("restriction")
public void appendText(String valueOf) {
if (BowlerStudioModularFrame.getBowlerStudioModularFrame() == null) {
return;
}
try {
BowlerStudioModularFrame.getBowlerStudioModularFrame().showTerminal();
} catch (Exception ex) {
// frame not open yet
ex.printStackTrace();
}
if (getLogViewRefStatic() != null) {
String text = getLogViewRefStatic().getText();
if (text.length() > LengthOfOutputLog) {
Platform.runLater(() -> {
try {
getLogViewRefStatic().deleteText(0, text.length() - LengthOfOutputLog);
getLogViewRefStatic().appendText(valueOf);
} catch (Throwable t) {
}
});
} else {
Platform.runLater(() -> {
getLogViewRefStatic().appendText(valueOf);
});
}
}
System.err.print(valueOf);
}
public void write(int b) throws IOException {
incoming.add(b);
// appendText(String.valueOf((char)b));
// if(b=='[')
// new RuntimeException().printStackTrace();
}
}
public static OutputStream getOut() {
if (out == null)
out = new Console();
return out;
}
public static MobileBase loadMobileBaseFromGit(String id, String file) throws Exception {
return MobileBaseLoader.fromGit(id, file);
}
public static void select(MobileBase base) {
if (CreatureLab3dController.getEngine().isAutoHightlight()) {
MobileBaseCadManager.get(base).selectCsgByMobileBase(base);
}
/*
* try {
*
* ArrayList<CSG> csg =
* MobileBaseCadManager.get(base).getBasetoCadMap().get(base);
* CreatureLab3dController.getEngine(). setSelectedCsg(csg.get(0));
* CreatureLab3dController.getEngine(). setSelectedCsg(csg); } catch (Exception
* ex) { System.err.println("Base not loaded yet"); }
*/
}
public static void select(MobileBase base, DHParameterKinematics limb) {
if (CreatureLab3dController.getEngine().isAutoHightlight()) {
MobileBaseCadManager.get(base).selectCsgByLimb(base, limb);
}
/*
* try {
*
* ArrayList<CSG> limCad =
* MobileBaseCadManager.get(base).getDHtoCadMap().get(limb); try {
* CreatureLab3dController.getEngine() .setSelectedCsg(limCad.get(limCad.size()
* - 1)); } catch (Exception ex) { // initialization has no csgs yet }
* CreatureLab3dController.getEngine(). setSelectedCsg(limCad); } catch
* (Exception ex) { System.err.println("Limb not loaded yet"); }
*/
}
public static void select(MobileBase base, LinkConfiguration limb) {
if (CreatureLab3dController.getEngine().isAutoHightlight()) {
MobileBaseCadManager.get(base).selectCsgByLink(base, limb);
}
/*
* try {
*
* ArrayList<CSG> limCad =
* MobileBaseCadManager.get(base).getLinktoCadMap().get(limb);
* CreatureLab3dController.getEngine() .setSelectedCsg(limCad.get(limCad.size()
* - 1)); CreatureLab3dController.getEngine(). setSelectedCsg(limCad); } catch
* (Exception ex) { System.err.println("Limb not loaded yet"); }
*/
}
public static void select(File script, int lineNumber) {
if (CreatureLab3dController.getEngine().isAutoHightlight())
try {
CreatureLab3dController.getEngine().setSelectedCsg(script, lineNumber);
} catch (Exception ex) {
System.err.println("File not found");
}
}
/**
* @param args the command line arguments
* @throws Exception
*/
@SuppressWarnings({ "unchecked", "restriction" })
public static void main(String[] args) throws Exception {
Thread.currentThread().setUncaughtExceptionHandler(new IssueReportingExceptionHandler());
if (!StudioBuildInfo.isOS64bit()) {
Platform.runLater(() -> {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("32 Bit Java Detected");
alert.setHeaderText("Insuffient Ram Capibilities in 32 bit mode");
alert.setContentText("This applications uses more that 4gb of ram\nA 32 bit JVM mode detected: "
+ System.getProperty("os.arch"));
alert.showAndWait();
System.exit(1);
});
}
Log.enableWarningPrint();
renderSplashFrame(2, "Testing Internet");
try {
final URL url = new URL("http://github.com");
final URLConnection conn = url.openConnection();
conn.connect();
conn.getInputStream();
setHasnetwork(true);
} catch (Exception e) {
// we assuming we have no access to the server and run off of the
// cached gists.
setHasnetwork(false);
}
CSG.setDefaultOptType(CSG.OptType.CSG_BOUND);
CSG.setProgressMoniter((currentIndex, finalIndex, type, intermediateShape) -> {
// Remove the default printing
});
eu.mihosoft.vrl.v3d.svg.SVGLoad.getProgressDefault();
eu.mihosoft.vrl.v3d.svg.SVGLoad.setProgressDefault(new ISVGLoadProgress() {
@Override
public void onShape(CSG newShape) {
BowlerStudioController.addCsg(newShape);
}
});
StudioBuildInfo.setBaseBuildInfoClass(BowlerStudio.class);
if (args.length == 0) {
renderSplashFrame(5, "Loging In...");
// ScriptingEngine.logout();
if (PasswordManager.hasNetwork()) {
ScriptingEngine.setLoginManager(new GitHubLoginManager());
try {
ScriptingEngine.login();
renderSplashFrame(10, "Login OK!");
} catch (Exception e) {
// e.printStackTrace();
ScriptingEngine.setupAnyonmous();
renderSplashFrame(10, "No Login Found");
}
}
String myAssets = AssetFactory.getGitSource();
if (PasswordManager.hasNetwork()) {
if (ScriptingEngine.isLoginSuccess()) {
if (BowlerStudio.hasNetwork()) {
ScriptingEngine.setAutoupdate(true);
}
renderSplashFrame(15, "Load Configs");
try {
firstVer = (String) ConfigurationDatabase.getObject("BowlerStudioConfigs", "firstVersion",
StudioBuildInfo.getVersion());
} catch (Throwable t) {
System.out.println("Resetting the configs repo...");
// clear the configs repo
ScriptingEngine.deleteRepo(ConfigurationDatabase.getGitSource());
firstVer = (String) ConfigurationDatabase.getObject("BowlerStudioConfigs", "firstVersion",
StudioBuildInfo.getVersion());
}
ConfigurationDatabase.setObject("BowlerStudioConfigs", "currentVersion",
StudioBuildInfo.getVersion());
renderSplashFrame(16, "Done Load Configs");
// String lastVersion = (String)
// ConfigurationDatabase.getObject("BowlerStudioConfigs",
// "skinBranch",
// StudioBuildInfo.getVersion());
myAssets = (String) ConfigurationDatabase.getObject("BowlerStudioConfigs", "skinRepo",
"https://github.com/madhephaestus/BowlerStudioImageAssets.git");
renderSplashFrame(20, "DL'ing Image Assets");
File gitRepoFile = ScriptingEngine.uriToFile(myAssets);
if (!gitRepoFile.exists()) {
lastVersion = null;
} else
lastVersion = ScriptingEngine.getBranch(myAssets);
System.err.println("Asset Repo " + myAssets);
System.err.println("Asset current ver " + lastVersion);
System.err.println("Asset intended ver " + StudioBuildInfo.getVersion());
if (lastVersion != null && StudioBuildInfo.getVersion().contentEquals(lastVersion)) {
ScriptingEngine.pull(myAssets, StudioBuildInfo.getVersion());
System.err.println("Studio version is the same");
} else {
if (lastVersion != null)
ScriptingEngine.cloneRepo(myAssets, lastVersion);
System.err.println("\n\nnew version\n\n");
try {
if (ScriptingEngine.checkOwner(myAssets)) {
ScriptingEngine.newBranch(myAssets, StudioBuildInfo.getVersion());
} else
throw new NullPointerException();
} catch (NullPointerException ex) {
// not the owner
try {
ScriptingEngine.checkout(myAssets, StudioBuildInfo.getVersion());
} catch (Exception ex1) {
ScriptingEngine.deleteRepo(myAssets);
ScriptingEngine.cloneRepo(myAssets, StudioBuildInfo.getVersion());
}
}
lastVersion = ScriptingEngine.getBranch(myAssets);
ConfigurationDatabase.setObject("BowlerStudioConfigs", "skinBranch", lastVersion);
// force the mainline in when a version update happens
// this prevents developers from ending up with unsuable
// version of BowlerStudio
ConfigurationDatabase.setObject("BowlerStudioConfigs", "skinRepo", myAssets);
ConfigurationDatabase.save();
}
if (BowlerStudio.hasNetwork()) {
renderSplashFrame(25, "Populating Menu");
}
} else {
renderSplashFrame(20, "DL'ing Image Assets");
ScriptingEngine.cloneRepo(myAssets, null);
ScriptingEngine.checkout(myAssets, StudioBuildInfo.getVersion());
}
}
layoutFile = AssetFactory.loadFile("layout/default.css");
if (layoutFile == null || !layoutFile.exists()) {
ScriptingEngine.deleteRepo(myAssets);
throw new RuntimeException("Style sheet does not exist");
}
// SplashManager.setIcon(AssetFactory.loadAsset("BowlerStudioTrayIcon.png"));
renderSplashFrame(50, "Tutorials...");
// load tutorials repo
Tutorial.getHomeUrl(); // Dowload and launch the Tutorial server
// force the current version in to the version number
ConfigurationDatabase.setObject("BowlerStudioConfigs", "skinBranch", StudioBuildInfo.getVersion());
renderSplashFrame(53, "Loading Images");
AssetFactory.setGitSource(
(String) ConfigurationDatabase.getObject("BowlerStudioConfigs", "skinRepo", myAssets),
StudioBuildInfo.getVersion());
renderSplashFrame(54, "Load Assets");
// Download and Load all of the assets
renderSplashFrame(60, "Vitamins...");
// load the vitimins repo so the demo is always snappy
ScriptingEngine.cloneRepo("https://github.com/CommonWealthRobotics/BowlerStudioVitamins.git", null);
renderSplashFrame(80, "Example Robots");
ScriptingEngine.fileFromGit("https://github.com/CommonWealthRobotics/BowlerStudioExampleRobots.git", // git
// repo,
// change
// this
// if
// you
// fork
// this
// demo
"exampleRobots.json"// File from within the Git repo
);
renderSplashFrame(81, "CSG database");
CSGDatabase.setDbFile(new File(ScriptingEngine.getWorkspace().getAbsoluteFile() + "/csgDatabase.json"));
// System.out.println("Loading assets ");
// System.out.println("Loading Main.fxml");
renderSplashFrame(81, "Find arduino");
String arduino = "arduino";
if (NativeResource.isLinux()) {
Slic3r.setExecutableLocation("/usr/bin/slic3r");
} else if (NativeResource.isWindows()) {
arduino = "C:\\Program Files (x86)\\Arduino\\arduino.exe";
if (!new File(arduino).exists()) {
arduino = "C:\\Program Files\\Arduino\\arduino.exe";
}
} else if (NativeResource.isOSX()) {
arduino = "/Applications/Arduino.app/Contents/MacOS/Arduino";
}
try {
if (!new File(arduino).exists() && !NativeResource.isLinux()) {
boolean alreadyNotified = Boolean.getBoolean(ConfigurationDatabase
.getObject("BowlerStudioConfigs", "notifiedArduinoDep", false).toString());
if (!alreadyNotified) {
ConfigurationDatabase.setObject("BowlerStudioConfigs", "notifiedArduinoDep", true);
String adr = arduino;
}
}
System.out.println("Arduino exec found at: " + arduino);
ArduinoLoader.setARDUINOExec(arduino);
} catch (Exception e) {
reporter.uncaughtException(Thread.currentThread(), e);
}
renderSplashFrame(82, "Set up UI");
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
// This is a workaround for #8 and is only relavent on osx
// it causes the SwingNodes not to load if not called way ahead
// of time
javafx.scene.text.Font.getFamilies();
} catch (Exception e) {
reporter.uncaughtException(Thread.currentThread(), e);
}
renderSplashFrame(90, "Loading STL Loader");
// Add the engine handeler for STLs
ScriptingEngine.addScriptingLanguage(new StlLoader());
// add a new link provider to the link factory
FirmataLink.addLinkFactory();
// Log.enableInfoPrint();
renderSplashFrame(92, "Preload done");
// ThreadUtil.wait(100);
try {
ScriptingEngine.pull("https://github.com/CommonWealthRobotics/HotfixBowlerStudio.git");
ScriptingEngine.pull("https://github.com/CommonWealthRobotics/DeviceProviders.git");
ScriptingEngine.gitScriptRun("https://github.com/CommonWealthRobotics/HotfixBowlerStudio.git",
"hotfix.groovy", null);
ScriptingEngine.gitScriptRun("https://github.com/CommonWealthRobotics/DeviceProviders.git",
"loadAll.groovy", null);
} catch (Exception e) {
reporter.uncaughtException(Thread.currentThread(), e);
}
launch();
} else {
BowlerKernel.main(args);
}
}
// private static void removeAssets(String myAssets)
// throws InvalidRemoteException, TransportException, GitAPIException, IOException, Exception {
// System.err.println("Clearing assets");
// ScriptingEngine.deleteRepo(myAssets);
// AssetFactory.setGitSource((String) ConfigurationDatabase.getObject("BowlerStudioConfigs", "skinRepo", myAssets),
// StudioBuildInfo.getVersion());
// }
public static void closeSplash() {
SplashManager.closeSplash();
}
public static void renderSplashFrame(int frame, String message) {
SplashManager.renderSplashFrame(frame, message);
}
/**
* open an external web page
*
* @param uri
*/
public static void openExternalWebpage(URL uri) {
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(uri.toURI());
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* @author Sainath
* @version 1.0
* @param url - The URL of the tab that needs to be opened
*/
public static void openUrlInNewTab(URL url) {
BowlerStudioModularFrame.getBowlerStudioModularFrame().openUrlInNewTab(url);
}
/**
* @author Sainath
* @version 1.0
* @param msg - message that needs to be spoken
* @return an integer
*/
public static int speak(String msg) {
return BowlerKernel.speak(msg);
}
public static ScriptingFileWidget createFileTab(File file) {
return BowlerStudioModularFrame.getBowlerStudioModularFrame().createFileTab(file);
}
@SuppressWarnings("restriction")
public static Scene getScene() {
return scene;
}
@SuppressWarnings("restriction")
public static void setScene(Scene s) {
scene = s;
}
@SuppressWarnings("restriction")
public static void clearConsole() {
Platform.runLater(() -> {
if (getLogViewRefStatic() != null)
getLogViewRefStatic().setText("");
});
}
public static boolean hasNetwork() {
return hasnetwork;
}
public static void setHasnetwork(boolean hasnetwork) {
BowlerStudio.hasnetwork = hasnetwork;
}
@SuppressWarnings("restriction")
public static TextArea getLogViewRefStatic() {
return logViewRefStatic;
}
public static void setLogViewRefStatic(@SuppressWarnings("restriction") TextArea logViewRefStatic) {
BowlerStudio.logViewRefStatic = logViewRefStatic;
}
public static void setCreatureLab3d(CreatureLab3dController creatureLab3dController) {
}
@SuppressWarnings("restriction")
@Override
public void start(Stage primaryStage) {
try { // do this ...
Thread thread = Thread.currentThread();
if (thread.getContextClassLoader() == null) {
// seriously Apple??
System.err.println("ContextClassLoader Is Missing! (OSX) ");
thread.setContextClassLoader(getClass().getClassLoader()); // a
// valid
// ClassLoader
// from
// somewhere
// else
}
} catch (SecurityException e) {
reporter.uncaughtException(Thread.currentThread(), e);
}
System.err.println("Class loader: " + Thread.currentThread().getContextClassLoader());
new Thread(() -> {
Thread.currentThread().setUncaughtExceptionHandler(new IssueReportingExceptionHandler());
try {
String stylesheet = Application.STYLESHEET_MODENA;// "MODENA" or
// "CASPIAN"
// System.setProperty("javax.userAgentStylesheetUrl",
// stylesheet);
setUserAgentStylesheet(stylesheet);
} catch (Exception | Error e) {
reporter.uncaughtException(Thread.currentThread(), e);
}
// These must be changed before anything starts
PrintStream ps = new PrintStream(getOut());
// System.setErr(ps);
System.setOut(ps);
renderSplashFrame(93, "Loading resources");
try {
BowlerStudioResourceFactory.load();
} catch (Exception e1) {
reporter.uncaughtException(Thread.currentThread(), e1);
}
primaryStage2 = primaryStage;
BowlerStudioModularFrame.setPrimaryStage(primaryStage);
// Initialize your logic here: all @FXML variables will have been
// injected
FXMLLoader mainControllerPanel;
try {
mainControllerPanel = AssetFactory.loadLayout("layout/BowlerStudioModularFrame.fxml");
renderSplashFrame(96, "Setting controller");
mainControllerPanel.setController(new BowlerStudioModularFrame());
// renderSplashFrame(96, "Class loader");
// mainControllerPanel.setClassLoader(BowlerStudioModularFrame.class.getClassLoader());
try {
renderSplashFrame(96, "Controller load");
mainControllerPanel.load();
} catch (Exception e) {
reporter.uncaughtException(Thread.currentThread(), e);
}
renderSplashFrame(96, "UI Launch...");
Scene scene = new Scene(mainControllerPanel.getRoot(), 1024, 768, true);
String nwfile = layoutFile.toURI().toString().replace("file:/", "file:///");
scene.getStylesheets().clear();
scene.getStylesheets().add(nwfile);
System.err.println("Loading CSS from " + nwfile);
Platform.runLater(() -> {
primaryStage.setScene(scene);
System.err.println("Showing main applicaiton");
primaryStage.show();
// initialize the default styles for the dock pane and
// undocked
// nodes using the DockFX
// library's internal Default.css stylesheet
// unlike other custom control libraries this allows the
// user to
// override them globally
// using the style manager just as they can with internal
// JavaFX
// controls
// this must be called after the primary stage is shown
// https://bugs.openjdk.java.net/browse/JDK-8132900
DockPane.initializeDefaultUserAgentStylesheet();
});
primaryStage.setOnCloseRequest(arg0 -> {
// ThreadUtil.wait(100);
closeBowlerStudio();
});
Platform.runLater(() -> {
primaryStage.setTitle("Bowler Studio: v " + StudioBuildInfo.getVersion());
try {
primaryStage.getIcons().add(AssetFactory.loadAsset("BowlerStudioTrayIcon.png"));
} catch (Exception e) {
reporter.uncaughtException(Thread.currentThread(), e);
}
});
;
primaryStage.setResizable(true);
DeviceManager.addDeviceAddedListener(new IDeviceAddedListener() {
@Override
public void onNewDeviceAdded(BowlerAbstractDevice arg0) {
System.err.println("Device connected: " + arg0);
BowlerStudioModularFrame.getBowlerStudioModularFrame().showConectionManager();
}
@Override
public void onDeviceRemoved(BowlerAbstractDevice arg0) {
}
});
Log.enableDebugPrint(false);
// Log.enableWarningPrint();
// Log.enableDebugPrint();
// Log.enableErrorPrint();
FxTimer.runLater(java.time.Duration.ofMillis((int) 2000), () -> {
String javaVersion = System.getProperty("java.version");
String javafxVersion = System.getProperty("javafx.version");
System.out.println("Java Version : " + javaVersion);
System.out.println("JavaFX Version : " + javafxVersion);
System.out.println("BowlerStudio First Version: " + firstVer);
System.out.println("Java-Bowler Version: " + SDKBuildInfo.getVersion());
System.out.println("Bowler-Scripting-Kernel Version: " + BowlerKernelBuildInfo.getVersion());
System.out.println("JavaCad Version: " + JavaCadBuildInfo.getVersion());
System.out.println("Welcome to BowlerStudio!");
});
closeSplash();
if (!ScriptingEngine.isLoginSuccess() || PasswordManager.isAnonMode())
BowlerStudioModularFrame.getBowlerStudioModularFrame().menueController.onLogin(null);
} catch (Throwable e) {
reporter.uncaughtException(Thread.currentThread(), e);
}
}).start();
}
@SuppressWarnings("restriction")
public static void closeBowlerStudio() {
Platform.runLater(() -> {
primaryStage2.hide();
});
new Thread() {
public void run() {
Thread.currentThread().setUncaughtExceptionHandler(new IssueReportingExceptionHandler());
renderSplashFrame(100, "Saving state..");
ConnectionManager.disconnectAll();
if(PasswordManager.hasNetwork()) {
if (ScriptingEngine.isLoginSuccess() && !PasswordManager.isAnonMode())
ConfigurationDatabase.save();
}
if (isDeleteFlag())
ScriptingEngine.deleteCache();
System.exit(0);
}
}.start();
}
public static void printStackTrace(Throwable e) {
printStackTrace(e, null);
}
public static void printStackTrace(Throwable e, File sourceFile) {
BowlerStudioController.highlightException(sourceFile, e);
}
public static void println(CSG... toDisplay) {
BowlerStudioController.setCsg(Arrays.asList(toDisplay));
}
public static void println(ArrayList<CSG> toDisplay) {
BowlerStudioController.setCsg(toDisplay);
}
public static void print(CSG... toDisplay) {
for (CSG c : Arrays.asList(toDisplay))
BowlerStudioController.addCsg(c);
}
public static void print(ArrayList<CSG> toDisplay) {
for (CSG c : toDisplay)
BowlerStudioController.addCsg(c);
}
public static boolean isDeleteFlag() {
return deleteFlag;
}
public static void setDeleteFlag(boolean deleteFlag) {
BowlerStudio.deleteFlag = deleteFlag;
}
public static void exit() {
closeBowlerStudio();
}
}

View File

@@ -0,0 +1,566 @@
package com.neuronrobotics.bowlerstudio;
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.bowlerstudio.assets.ConfigurationDatabase;
import com.neuronrobotics.bowlerstudio.creature.IMobileBaseUI;
import com.neuronrobotics.bowlerstudio.creature.MobileBaseCadManager;
import com.neuronrobotics.bowlerstudio.scripting.IScriptEventListener;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingFileWidget;
import com.neuronrobotics.bowlerstudio.tabs.LocalFileScriptTab;
import com.neuronrobotics.bowlerstudio.threed.BowlerStudio3dEngine;
import com.neuronrobotics.bowlerstudio.threed.Line3D;
import com.neuronrobotics.imageprovider.AbstractImageProvider;
import com.neuronrobotics.sdk.common.BowlerAbstractDevice;
import com.neuronrobotics.sdk.common.DMDevice;
import com.neuronrobotics.sdk.common.Log;
import com.neuronrobotics.sdk.common.NonBowlerDevice;
import com.neuronrobotics.sdk.util.ThreadUtil;
import eu.mihosoft.vrl.v3d.CSG;
import eu.mihosoft.vrl.v3d.Polygon;
import eu.mihosoft.vrl.v3d.Vertex;
import javafx.application.Platform;
import javafx.scene.Node;
import javafx.scene.control.Tab;
import javafx.stage.Stage;
import javax.swing.text.BadLocationException;
import org.kohsuke.github.GHRepository;
import org.reactfx.util.FxTimer;
import java.awt.Color;
//import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.time.Duration;
//import org.bytedeco.javacpp.DoublePointer;
@SuppressWarnings("restriction")
public class BowlerStudioController implements IScriptEventListener {
/**
*
*/
private ConnectionManager connectionManager;
private AbstractImageProvider vrCamera;
private static BowlerStudioController bowlerStudioControllerStaticReference = null;
private boolean doneLoadingTutorials = false;
private boolean runningExceptionHighlight = false;
public BowlerStudioController() {
if (getBowlerStudio() != null)
throw new RuntimeException("There can be only one Bowler Studio controller");
bowlerStudioControllerStaticReference = this;
size = ((Number) ConfigurationDatabase.getObject("BowlerStudioConfigs", "fontsize", 12)).intValue();
}
private HashMap<String, Tab> openFiles = new HashMap<>();
private HashMap<String, LocalFileScriptTab> widgets = new HashMap<>();
private int size;
private static IMobileBaseUI mbui = new IMobileBaseUI() {
@Override
public void highlightException(File fileEngineRunByName, Exception ex) {
BowlerStudioController.highlightException(fileEngineRunByName, ex);
}
@Override
public void setAllCSG(Collection<CSG> toAdd, File source) {
try {
BowlerStudioController.setCsg(new ArrayList<>(toAdd));
} catch (Throwable t) {
t.printStackTrace();
}
}
@Override
public void addCSG(Collection<CSG> toAdd, File source) {
// TODO Auto-generated method stub
for (CSG b : toAdd)
BowlerStudioController.addCsg(b);
}
@Override
public Set<CSG> getVisibleCSGs() {
return CreatureLab3dController.getEngine().getCsgMap().keySet();
}
@Override
public void setSelectedCsg(Collection<CSG> selectedCsg) {
CreatureLab3dController.getEngine().setSelectedCsg(new ArrayList<>(selectedCsg));
}
};
public void setFontSize(int size) {
this.size = size;
for (String key : widgets.keySet()) {
widgets.get(key).setFontSize(size);
}
ConfigurationDatabase.setObject("BowlerStudioConfigs", "fontsize", size);
}
// Custom function for creation of New Tabs.
public ScriptingFileWidget createFileTab(File file) {
if (openFiles.get(file.getAbsolutePath()) != null && widgets.get(file.getAbsolutePath()) != null) {
BowlerStudioModularFrame.getBowlerStudioModularFrame()
.setSelectedTab(openFiles.get(file.getAbsolutePath()));
return widgets.get(file.getAbsolutePath()).getScripting();
}
Tab fileTab = new Tab(file.getName());
openFiles.put(file.getAbsolutePath(), fileTab);
try {
Log.warning("Loading local file from: " + file.getAbsolutePath());
LocalFileScriptTab t = new LocalFileScriptTab(file);
new Thread() {
public void run() {
BowlerStudioMenuWorkspace.add(t.getScripting().getGitRepo());
}
}.start();
String key = t.getScripting().getGitRepo() + ":" + t.getScripting().getGitFile();
ArrayList<String> files = new ArrayList<>();
files.add(t.getScripting().getGitRepo());
files.add(t.getScripting().getGitFile());
if(key.length()>3 && files.get(0).length()>0 && files.get(1).length()>0)// catch degenerates
ConfigurationDatabase.setObject("studio-open-git", key, files);
fileTab.setContent(t);
fileTab.setGraphic(
AssetFactory.loadIcon("Script-Tab-" + ScriptingEngine.getShellType(file.getName()) + ".png"));
addTab(fileTab, true);
widgets.put(file.getAbsolutePath(), t);
fileTab.setOnCloseRequest(event -> {
widgets.remove(file.getAbsolutePath());
openFiles.remove(file.getAbsolutePath());
ConfigurationDatabase.removeObject("studio-open-git", key);
t.getScripting().close();
System.out.println("Closing " + file.getAbsolutePath());
});
t.setFontSize(size);
return t.getScripting();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public void clearHighlits() {
for (Entry<String, LocalFileScriptTab> set : widgets.entrySet()) {
set.getValue().clearHighlits();
}
}
public void setHighlight(File fileEngineRunByName, int lineNumber, Color color) {
// System.out.println("Highlighting line "+lineNumber+" in
// "+fileEngineRunByName);
if (openFiles.get(fileEngineRunByName.getAbsolutePath()) == null) {
createFileTab(fileEngineRunByName);
ThreadUtil.wait(100);
}
// BowlerStudioModularFrame.getBowlerStudioModularFrame().setSelectedTab(openFiles.get(fileEngineRunByName.getAbsolutePath()));
// System.out.println("Highlighting "+fileEngineRunByName+" at line
// "+lineNumber+" to color "+color);
try {
widgets.get(fileEngineRunByName.getAbsolutePath()).setHighlight(lineNumber, color);
} catch (BadLocationException e) {
// e.printStackTrace();
}
}
public static void highlightException(File fileEngineRunByName, Throwable ex) {
if(bowlerStudioControllerStaticReference!=null)
bowlerStudioControllerStaticReference.highlightExceptionLocal(fileEngineRunByName, ex);
}
public static void clearHighlight() {
bowlerStudioControllerStaticReference.clearHighlits();
}
private void highlightExceptionLocal(File fileEngineRunByName, Throwable ex) {
// THis needs to gate on checking if this thread is running already
if(runningExceptionHighlight) {
ex.printStackTrace();
new RuntimeException("Only one exception Highlight can be called at once!").printStackTrace();
return;
}
new Thread() {
public void run() {
runningExceptionHighlight=true;
setName("Highlighter thread");
if (fileEngineRunByName != null) {
if (openFiles.get(fileEngineRunByName.getAbsolutePath()) == null) {
createFileTab(fileEngineRunByName);
}
BowlerStudioModularFrame.getBowlerStudioModularFrame()
.setSelectedTab(openFiles.get(fileEngineRunByName.getAbsolutePath()));
widgets.get(fileEngineRunByName.getAbsolutePath()).clearHighlits();
// System.out.println("Highlighting "+fileEngineRunByName+" at line
// "+lineNumber+" to color "+color);
StackTraceElement[] stackTrace = ex.getStackTrace();
for (StackTraceElement el : stackTrace) {
try {
// System.out.println("Compairing "+fileEngineRunByName.getName()+" to
// "+el.getFileName());
if (el.getFileName().contentEquals(fileEngineRunByName.getName())) {
widgets.get(fileEngineRunByName.getAbsolutePath()).setHighlight(el.getLineNumber(),
Color.CYAN);
}
} catch (Exception e) {
// StringWriter sw = new StringWriter();
// PrintWriter pw = new PrintWriter(sw);
// e.printStackTrace(pw);
// System.out.println(sw.toString());
}
}
if (ex.getCause() != null) {
for (StackTraceElement el : ex.getCause().getStackTrace()) {
try {
// System.out.println("Compairing "+fileEngineRunByName.getName()+" to
// "+el.getFileName());
if (el.getFileName().contentEquals(fileEngineRunByName.getName())) {
widgets.get(fileEngineRunByName.getAbsolutePath()).setHighlight(el.getLineNumber(),
Color.CYAN);
}
} catch (Exception e) {
// StringWriter sw = new StringWriter();
// PrintWriter pw = new PrintWriter(sw);
// e.printStackTrace(pw);
// System.out.println(sw.toString());
}
}
}
}
try {
if (widgets.get(fileEngineRunByName.getAbsolutePath()) != null) {
String message = ex.getMessage();
// System.out.println(message);
if (message != null && message.contains(fileEngineRunByName.getName()))
try {
int indexOfFile = message.lastIndexOf(fileEngineRunByName.getName());
String fileSub = message.substring(indexOfFile);
String[] fileAndNum = fileSub.split(":");
String FileNum = fileAndNum[1];
int linNum = Integer.parseInt(FileNum.trim());
widgets.get(fileEngineRunByName.getAbsolutePath()).setHighlight(linNum, Color.CYAN);
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
System.out.println(sw.toString());
}
}
} catch (Exception ex1) {
}
try {
String sw = org.apache.commons.lang.exception.ExceptionUtils
.getStackTrace(ex);
System.out.println(sw.toString());
// space out the exception highlights, ensure any sub threads spawned here have time to finish
Thread.sleep(100);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
runningExceptionHighlight=false;
}
}.start();
}
public void addTab(Tab tab, boolean closable) {
// new RuntimeException().printStackTrace();
Platform.runLater(() -> {
BowlerStudioModularFrame.getBowlerStudioModularFrame().addTab(tab, closable);
});
}
public static boolean removeObject(Object p) {
if (CSG.class.isInstance(p) ) {
Platform.runLater(() -> {
CreatureLab3dController.getEngine().removeObject((CSG) p);
});
return true;
}
if ( Node.class.isInstance(p) || Polygon.class.isInstance(p)) {
Platform.runLater(() -> {
CreatureLab3dController.getEngine().clearUserNode();
});
return true;
}
// ThreadUtil.wait(20);
return false;
}
// private boolean removeObject(Object p) {
// if (CSG.class.isInstance(p) || Node.class.isInstance(p) || Polygon.class.isInstance(p)) {
// Platform.runLater(() -> {
// CreatureLab3dController.getEngine().removeObjects();
// CreatureLab3dController.getEngine().clearUserNode();
// });
// return true;
// }
// // ThreadUtil.wait(20);
// return false;
// }
public static void setCsg(List<CSG> toadd, File source) {
Platform.runLater(() -> {
CreatureLab3dController.getEngine().removeObjects();
if (toadd != null)
for (CSG c : toadd) {
if(c!=null)
Platform.runLater(() -> CreatureLab3dController.getEngine().addObject(c, source));
}
});
}
public static void setCsg(List<CSG> toadd) {
setCsg(toadd, null);
}
public static void addCsg(CSG toadd) {
addCsg(toadd, null);
}
public static void setUserNode(List<Node> toadd) {
Platform.runLater(() -> {
CreatureLab3dController.getEngine().clearUserNode();
if (toadd != null)
for (Node c : toadd) {
CreatureLab3dController.getEngine().addUserNode(c);
}
});
}
public static void addUserNode(Node toadd) {
Platform.runLater(() -> {
if (toadd != null)
CreatureLab3dController.getEngine().addUserNode(toadd);
});
}
public static void setSelectedCsg(CSG obj) {
CreatureLab3dController.getEngine().setSelectedCsg(obj);
}
public static void addCsg(CSG toadd, File source) {
Platform.runLater(() -> {
if (toadd != null)
CreatureLab3dController.getEngine().addObject(toadd, source);
});
}
public void addObject(Object o, File source) {
if (List.class.isInstance(o)) {
List<Object> c = (List<Object>) o;
for (int i = 0; i < c.size(); i++) {
// Log.warning("Loading array Lists with removals " + c.get(i));
addObject(c.get(i), source);
}
return;
}
if (CSG.class.isInstance(o)) {
CSG csg = (CSG) o;
Platform.runLater(() -> {
// new RuntimeException().printStackTrace();
CreatureLab3dController.getEngine().addObject(csg, source);
});
return;
} else if (Tab.class.isInstance(o)) {
addTab((Tab) o, true);
return;
} else if (Node.class.isInstance(o)) {
addNode((Node) o);
return;
} else if (Polygon.class.isInstance(o)) {
Polygon p = (Polygon) o;
List<Vertex> vertices = p.vertices;
javafx.scene.paint.Color color = new javafx.scene.paint.Color(Math.random() * 0.5 + 0.5,
Math.random() * 0.5 + 0.5, Math.random() * 0.5 + 0.5, 1);
double stroke = 0.5;
for (int i = 1; i < vertices.size(); i++) {
Line3D line = new Line3D(vertices.get(i - 1), vertices.get(i));
line.setStrokeWidth(stroke);
line.setStroke(color);
addNode(line);
}
// Connecting line
Line3D line = new Line3D(vertices.get(0), vertices.get(vertices.size() - 1));
line.setStrokeWidth(stroke);
line.setStroke(color);
addNode(line);
return;
} else if (BowlerAbstractDevice.class.isInstance(o)) {
BowlerAbstractDevice bad = (BowlerAbstractDevice) o;
ConnectionManager.addConnection((BowlerAbstractDevice) o, bad.getScriptingName());
return;
} else if (DMDevice.wrappable(o)) {
BowlerAbstractDevice bad;
try {
bad = new DMDevice(o);
ConnectionManager.addConnection(bad, bad.getScriptingName());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void addNode(Node o) {
CreatureLab3dController.getEngine().addUserNode(o);
}
@SuppressWarnings({ "unchecked" })
@Override
public void onScriptFinished(Object result, Object Previous, File source) {
Log.warning("Loading script results " + result + " previous " + Previous);
// this is added in the script engine when the connection manager is
// loaded
clearObjects(Previous);
clearObjects(result);
ThreadUtil.wait(40);
if (List.class.isInstance(result)) {
List<Object> c = (List<Object>) result;
for (int i = 0; i < c.size(); i++) {
// Log.warning("Loading array Lists with removals " + c.get(i));
addObject(c.get(i), source);
}
} else {
addObject(result, source);
}
}
private void clearObjects(Object o) {
if (List.class.isInstance(o)) {
@SuppressWarnings("unchecked")
List<Object> c = (List<Object>) o;
for (int i = 0; i < c.size(); i++) {
clearObjects(c.get(i));
}
} else {
removeObject(o);
}
}
@Override
public void onScriptChanged(String previous, String current, File source) {
}
@Override
public void onScriptError(Throwable except, File source) {
// TODO Auto-generated method stub
}
public void disconnect() {
ConnectionManager.disconnectAll();
}
public Stage getPrimaryStage() {
// TODO Auto-generated method stub
return BowlerStudioModularFrame.getPrimaryStage();
}
public AbstractImageProvider getVrCamera() {
return vrCamera;
}
public void setVrCamera(AbstractImageProvider vrCamera) {
this.vrCamera = vrCamera;
}
public static BowlerStudioController getBowlerStudio() {
return bowlerStudioControllerStaticReference;
}
public static void setup() {
// TODO Auto-generated method stub
}
public static void clearCSG() {
Platform.runLater(() -> {
CreatureLab3dController.getEngine().removeObjects();
});
}
public static void setCsg(CSG legAssembly, File cadScript) {
Platform.runLater(() -> {
CreatureLab3dController.getEngine().removeObjects();
if (legAssembly != null)
Platform.runLater(() -> CreatureLab3dController.getEngine().addObject(legAssembly, cadScript));
});
}
public static void setCsg(MobileBaseCadManager thread, File cadScript) {
setCsg(thread.getAllCad(), cadScript);
}
public boolean isDoneLoadingTutorials() {
return doneLoadingTutorials;
}
public void setDoneLoadingTutorials(boolean doneLoadingTutorials) {
this.doneLoadingTutorials = doneLoadingTutorials;
}
public ConnectionManager getConnectionManager() {
return connectionManager;
}
public void setConnectionManager(ConnectionManager connectionManager) {
this.connectionManager = connectionManager;
}
public static IMobileBaseUI getMobileBaseUI() {
return mbui;
}
}

View File

@@ -0,0 +1,235 @@
package com.neuronrobotics.bowlerstudio;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.AnchorPane;
public class BowlerStudioFXMLController {
@FXML // ResourceBundle that was given to the FXMLLoader
private ResourceBundle resources;
@FXML // URL location of the FXML file that was given to the FXMLLoader
private URL location;
@FXML // fx:id="BowlerStudioMenue"
private MenuBar BowlerStudioMenue; // Value injected by FXMLLoader
@FXML // fx:id="CadControlsAnchor"
private AnchorPane CadControlsAnchor; // Value injected by FXMLLoader
@FXML // fx:id="CadTextSplit"
private SplitPane CadTextSplit; // Value injected by FXMLLoader
@FXML // fx:id="CommandLine"
private AnchorPane CommandLine; // Value injected by FXMLLoader
@FXML // fx:id="CreaturesMenu"
private Menu CreaturesMenu; // Value injected by FXMLLoader
@FXML // fx:id="DriveControlsAnchor"
private AnchorPane DriveControlsAnchor; // Value injected by FXMLLoader
@FXML // fx:id="GitHubRoot"
private Menu GitHubRoot; // Value injected by FXMLLoader
@FXML // fx:id="TempControlsAnchor"
private AnchorPane TempControlsAnchor; // Value injected by FXMLLoader
@FXML // fx:id="clearCache"
private MenuItem clearCache; // Value injected by FXMLLoader
@FXML // fx:id="commandLineTitledPane"
private TitledPane commandLineTitledPane; // Value injected by FXMLLoader
@FXML // fx:id="createNewGist"
private MenuItem createNewGist; // Value injected by FXMLLoader
@FXML // fx:id="editorContainer"
private AnchorPane editorContainer; // Value injected by FXMLLoader
@FXML // fx:id="jfx3dControls"
private AnchorPane jfx3dControls; // Value injected by FXMLLoader
@FXML // fx:id="logView"
private AnchorPane logView; // Value injected by FXMLLoader
@FXML // fx:id="logViewRef"
private TextArea logViewRef; // Value injected by FXMLLoader
@FXML // fx:id="logoutGithub"
private MenuItem logoutGithub; // Value injected by FXMLLoader
@FXML // fx:id="myGists"
private Menu myGists; // Value injected by FXMLLoader
@FXML // fx:id="myOrganizations"
private Menu myOrganizations; // Value injected by FXMLLoader
@FXML // fx:id="myRepos"
private Menu myRepos; // Value injected by FXMLLoader
@FXML // fx:id="overlayScrollPanel"
private ScrollPane overlayScrollPanel; // Value injected by FXMLLoader
@FXML // fx:id="viewContainer"
private AnchorPane viewContainer; // Value injected by FXMLLoader
@FXML // fx:id="watchingRepos"
private Menu watchingRepos; // Value injected by FXMLLoader
// Handler for MenuItem[fx:id="clearCache"] onAction
@FXML
void clearScriptCache(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[javafx.scene.control.MenuItem@3d05e65e] onAction
@FXML
void onClose(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[javafx.scene.control.MenuItem@6127215f] onAction
@FXML
void onConnect(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[javafx.scene.control.MenuItem@1d163e1a] onAction
@FXML
void onConnectCHDKCamera(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[javafx.scene.control.MenuItem@3cad92b8] onAction
@FXML
void onConnectCVCamera(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[javafx.scene.control.MenuItem@542487b1] onAction
@FXML
void onConnectFileSourceCamera(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[javafx.scene.control.MenuItem@4845d9d8] onAction
@FXML
void onConnectGamePad(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[javafx.scene.control.MenuItem@36100c4d] onAction
@FXML
void onConnectHokuyoURG(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[javafx.scene.control.MenuItem@7a7cbb68] onAction
@FXML
void onConnectPidSim(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[javafx.scene.control.MenuItem@7d3d14a7] onAction
@FXML
void onConnectURLSourceCamera(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[javafx.scene.control.MenuItem@68e8dfb1] onAction
@FXML
void onConnectVirtual(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[fx:id="createNewGist"] onAction
@FXML
void onCreatenewGist(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[javafx.scene.control.MenuItem@6bfd67ba] onAction
@FXML
void onLoadFile(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[javafx.scene.control.MenuItem@41a2e40f] onAction
@FXML
void onLogin(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[fx:id="logoutGithub"] onAction
@FXML
void onLogout(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[javafx.scene.control.MenuItem@7e3e1a61] onAction
@FXML
void onMobileBaseFromFile(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[javafx.scene.control.MenuItem@57184345] onAction
@FXML
void onMobileBaseFromGit(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[javafx.scene.control.MenuItem@d523af5] onAction
@FXML
void onOpenGitter(ActionEvent event) {
// handle the event here
}
// Handler for MenuItem[javafx.scene.control.MenuItem@2a1c81e] onAction
@FXML
void onPrint(ActionEvent event) {
// handle the event here
}
@FXML // This method is called by the FXMLLoader when initialization is complete
void initialize() {
assert BowlerStudioMenue != null : "fx:id=\"BowlerStudioMenue\" was not injected: check your FXML file 'Main.fxml'.";
assert CadControlsAnchor != null : "fx:id=\"CadControlsAnchor\" was not injected: check your FXML file 'Main.fxml'.";
assert CadTextSplit != null : "fx:id=\"CadTextSplit\" was not injected: check your FXML file 'Main.fxml'.";
assert CommandLine != null : "fx:id=\"CommandLine\" was not injected: check your FXML file 'Main.fxml'.";
assert CreaturesMenu != null : "fx:id=\"CreaturesMenu\" was not injected: check your FXML file 'Main.fxml'.";
assert DriveControlsAnchor != null : "fx:id=\"DriveControlsAnchor\" was not injected: check your FXML file 'Main.fxml'.";
assert GitHubRoot != null : "fx:id=\"GitHubRoot\" was not injected: check your FXML file 'Main.fxml'.";
assert TempControlsAnchor != null : "fx:id=\"TempControlsAnchor\" was not injected: check your FXML file 'Main.fxml'.";
assert clearCache != null : "fx:id=\"clearCache\" was not injected: check your FXML file 'Main.fxml'.";
assert commandLineTitledPane != null : "fx:id=\"commandLineTitledPane\" was not injected: check your FXML file 'Main.fxml'.";
assert createNewGist != null : "fx:id=\"createNewGist\" was not injected: check your FXML file 'Main.fxml'.";
assert editorContainer != null : "fx:id=\"editorContainer\" was not injected: check your FXML file 'Main.fxml'.";
assert jfx3dControls != null : "fx:id=\"jfx3dControls\" was not injected: check your FXML file 'Main.fxml'.";
assert logView != null : "fx:id=\"logView\" was not injected: check your FXML file 'Main.fxml'.";
assert logViewRef != null : "fx:id=\"logViewRef\" was not injected: check your FXML file 'Main.fxml'.";
assert logoutGithub != null : "fx:id=\"logoutGithub\" was not injected: check your FXML file 'Main.fxml'.";
assert myGists != null : "fx:id=\"myGists\" was not injected: check your FXML file 'Main.fxml'.";
assert myOrganizations != null : "fx:id=\"myOrganizations\" was not injected: check your FXML file 'Main.fxml'.";
assert myRepos != null : "fx:id=\"myRepos\" was not injected: check your FXML file 'Main.fxml'.";
assert overlayScrollPanel != null : "fx:id=\"overlayScrollPanel\" was not injected: check your FXML file 'Main.fxml'.";
assert viewContainer != null : "fx:id=\"viewContainer\" was not injected: check your FXML file 'Main.fxml'.";
assert watchingRepos != null : "fx:id=\"watchingRepos\" was not injected: check your FXML file 'Main.fxml'.";
// Initialize your logic here: all @FXML variables will have been injected
}
}

View File

@@ -0,0 +1,181 @@
package com.neuronrobotics.bowlerstudio;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import com.neuronrobotics.bowlerstudio.assets.ConfigurationDatabase;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import javafx.application.Platform;
import javafx.scene.control.Menu;
@SuppressWarnings("restriction")
public class BowlerStudioMenuWorkspace {
private static Menu workspaceMenu;
private static HashMap<String, Object> workspaceData = null;
private static final int maxMenueSize = 15;
private static boolean sorting = false;
private static HashMap<String,Integer> rank = new HashMap<String, Integer>();
private static boolean running = false;
public static void init(Menu workspacemenu) {
if (workspacemenu == null)
throw new RuntimeException();
workspaceMenu = workspacemenu;
}
public static void loginEvent() {
if(running)
return;
running = true;
rank.clear();
workspaceData = ConfigurationDatabase.getParamMap("workspace");
new Thread(()-> {
for (int i=0;i<workspaceData.keySet().size();i++) {
try {
String o = (String) workspaceData.keySet().toArray()[i];
try {
ScriptingEngine.pull(o);
} catch (Exception e) {
workspaceData.remove(o);
i--;
}
} catch (Exception e) {
}
}
running = false;
}).start();
sort();
}
public static void add(String url) {
add(url, BowlerStudioMenu.gitURLtoMessage(url));
}
@SuppressWarnings("unchecked")
public static void add(String url, String menueMessage) {
if (menueMessage == null || menueMessage.length() < 2)
throw new RuntimeException();
ArrayList<String> data;
synchronized (workspaceData) {
if (workspaceData.get(url) == null) {
data = new ArrayList<String>();
data.add(menueMessage);
data.add(new Long(System.currentTimeMillis()).toString());
workspaceData.put(url, data);
System.out.println("Workspace add: "+url);
}
}
//data = (ArrayList<String>) workspaceData.get(url);
//data.set(1, new Long(System.currentTimeMillis()).toString());
sort();
//
}
@SuppressWarnings("unchecked")
private static void sort() {
if (sorting)
return;
sorting = true;
boolean rankChanged=false;
try {
ArrayList<String> myOptions = new ArrayList<String>();
synchronized (workspaceData) {
for (String o : workspaceData.keySet()) {
//System.out.println("Opt: "+o);
myOptions.add(o);
}
}
ArrayList<String> menu = new ArrayList<>();
while (myOptions.size() > 0) {
int bestIndex = 0;
String besturl = (String) myOptions.get(bestIndex);
long newestTime = Long.parseLong(((ArrayList<String>) workspaceData.get(besturl)).get(1));
for (int i = 0; i < myOptions.size(); i++) {
String nowurl = (String) myOptions.get(i);
long myTime = Long.parseLong(((ArrayList<String>) workspaceData.get(nowurl)).get(1));
if (myTime >= newestTime) {
newestTime = myTime;
besturl = nowurl;
bestIndex = i;
}
}
String removedURL = (String) myOptions.remove(bestIndex);
if (menu.size() < maxMenueSize) {
// clone all repos from git
try {
// ScriptingEngine.pull(removedURL);
menu.add(removedURL);
} catch (Exception e) {
// repo is broken or missing
e.printStackTrace();
System.out.println("Removing from workspace: " + removedURL);
synchronized (workspaceData) {
workspaceData.remove(removedURL);
}
}
} else {
System.out.println("Removing from workspace: " + removedURL);
synchronized (workspaceData) {
workspaceData.remove(removedURL);
}
}
}
for(int i=0;i<menu.size();i++) {
String url = menu.get(i);
if(rank.get(url)==null) {
rankChanged=true;
rank.put(url,i);
//System.out.println("Rank firstNoted : "+url+" "+i);
}
if(rank.get(url).intValue()!=i) {
rankChanged=true;
}
rank.put(url,i);
}
if(rankChanged) {
Platform.runLater(() -> {
if (workspaceMenu.getItems() != null)
workspaceMenu.getItems().clear();
new Thread(() -> {
for (String url : menu) {
System.out.println("Workspace : "+url);
ArrayList<String> arrayList = (ArrayList<String>) workspaceData.get(url);
if(arrayList!=null)
BowlerStudioMenu.setUpRepoMenue(workspaceMenu,
url,
false,
false,
arrayList.get(0));
}
sorting = false;
}).start();
});
}else {
sorting = false;
}
} catch (Exception ex) {
ex.printStackTrace();
}
if(rankChanged) {
System.out.println("Sorting workspace...");
new Thread(()->{
ConfigurationDatabase.save();
}).start();
}
}
}

View File

@@ -0,0 +1,407 @@
package com.neuronrobotics.bowlerstudio;
/**
* Sample Skeleton for "BowlerStudioModularFrame.fxml" Controller Class
* You can copy and paste this code into your favorite IDE
**/
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.bowlerstudio.scripting.PasswordManager;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingFileWidget;
import com.neuronrobotics.bowlerstudio.tabs.WebTab;
import com.neuronrobotics.bowlerstudio.threed.BowlerStudio3dEngine;
import com.neuronrobotics.sdk.util.ThreadUtil;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Tab;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.dockfx.DockNode;
import org.dockfx.DockPane;
import org.dockfx.DockPos;
import java.io.File;
import java.io.IOException;
import java.lang.Thread.UncaughtExceptionHandler;
import java.net.URL;
import java.util.HashMap;
import java.util.ResourceBundle;
@SuppressWarnings("restriction")
public class BowlerStudioModularFrame {
@FXML // ResourceBundle that was given to the FXMLLoader
private ResourceBundle resources;
@FXML // URL location of the FXML file that was given to the FXMLLoader
private URL location;
@FXML // fx:id="editorContainer"
private AnchorPane editorContainer; // Value injected by FXMLLoader
@FXML // fx:id="menurAnchor"
private AnchorPane menurAnchor; // Value injected by FXMLLoader
private Image dockImage;
private DockNode tutorialDockNode;
private DockNode connectionManagerDockNode;
private DockPane dockPane;
public BowlerStudioMenu menueController;
// private InvalidationListener connectionManagerRemover;
private CreatureLab3dController creatureLab3dController;
private DockNode creatureLab3dDockNode;
// private InvalidationListener creatureManagerRemover;
private BowlerStudioController controller;
private static Stage primaryStage;
private static BowlerStudioModularFrame bowlerStudioModularFrame;
private HashMap<Tab, DockNode> webTabs = new HashMap<>();
private HashMap<String, Boolean> isOpen = new HashMap<>();
private Terminal terminal;
private DockNode terminalDockNode;
private boolean startup = false;
private WebTab webtab;
@FXML // This method is called by the FXMLLoader when initialization is
// complete
void initialize() throws Exception {
bowlerStudioModularFrame=this;
assert editorContainer != null : "fx:id=\"editorContainer\" was not injected: check your FXML file 'BowlerStudioModularFrame.fxml'.";
assert menurAnchor != null : "fx:id=\"menurAnchor\" was not injected: check your FXML file 'BowlerStudioModularFrame.fxml'.";
dockPane = new DockPane();
dockImage = AssetFactory.loadAsset("BowlerStudioModularFrameIcon.png");
// final Tab newtab = new Tab();
// newtab.setText("");
// newtab.setClosable(false);
// newtab.setGraphic(AssetFactory.loadIcon("New-Web-Tab.png"));
String homeURL = Tutorial.getHomeUrl();
controller = new BowlerStudioController();
WebTab.setBSController(controller);
webtab = null;
try {
Platform.runLater(()->{
try {
webtab = new WebTab("Tutorial", homeURL, true);
setTutorialDockNode(new DockNode(webtab.getContent(), webtab.getText(), webtab.getGraphic()));
getTutorialDockNode().setPrefSize(1024, 730);
} catch (IOException | InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});;
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
connectionManagerDockNode = new DockNode(ConnectionManager.getConnectionManager().getContent(),
ConnectionManager.getConnectionManager().getText(),
ConnectionManager.getConnectionManager().getGraphic());
connectionManagerDockNode.setPrefSize(200, 700);
// Initial docked setup
addTutorial();
// Add the dock pane to the window
editorContainer.getChildren().add(dockPane);
AnchorPane.setTopAnchor(dockPane, 0.0);
AnchorPane.setRightAnchor(dockPane, 0.0);
AnchorPane.setLeftAnchor(dockPane, 0.0);
AnchorPane.setBottomAnchor(dockPane, 0.0);
FXMLLoader WindowLoader3d;
WindowLoader3d = AssetFactory.loadLayout("layout/CreatureLab.fxml");
creatureLab3dController = new CreatureLab3dController();
BowlerStudio.setCreatureLab3d(creatureLab3dController);
WindowLoader3d.setController(creatureLab3dController);
WindowLoader3d.setClassLoader(CreatureLab3dController.class.getClassLoader());
FXMLLoader commandLine;
commandLine = AssetFactory.loadLayout("layout/Terminal.fxml");
terminal = new Terminal();
commandLine.setController(terminal);
commandLine.setClassLoader(Terminal.class.getClassLoader());
FXMLLoader menueBar;
menueBar = AssetFactory.loadLayout("layout/BowlerStudioMenuBar.fxml");
menueController = new BowlerStudioMenu(this);
menueBar.setController(menueController);
menueBar.setClassLoader(BowlerStudioMenu.class.getClassLoader());
try {
menueBar.load();
WindowLoader3d.load();
commandLine.load();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BorderPane menue = (BorderPane) menueBar.getRoot();
BorderPane threed = (BorderPane) WindowLoader3d.getRoot();
VBox cmd = (VBox) commandLine.getRoot();
creatureLab3dDockNode = new DockNode(threed, "Creature Lab", AssetFactory.loadIcon("CreatureLab-Tab.png"));
creatureLab3dDockNode.setPrefSize(400, 400);
terminalDockNode = new DockNode(cmd, "Terminal", AssetFactory.loadIcon("Command-Line.png"));
terminalDockNode.setPrefSize(400, 400);
// Add the dock pane to the window
menurAnchor.getChildren().add(menue);
AnchorPane.setTopAnchor(menue, 0.0);
AnchorPane.setRightAnchor(menue, 0.0);
AnchorPane.setLeftAnchor(menue, 0.0);
AnchorPane.setBottomAnchor(menue, 0.0);
isOpen.put("showCreatureLab", false);
isOpen.put("showTerminal", false);
isOpen.put("showDevices", false);
// focus on the tutorial to start
Platform.runLater(() -> getTutorialDockNode().requestFocus());
connectionManagerDockNode.onMouseClickedProperty().addListener((a, b, c) -> {
System.err.println("Cloick");
});
}
public void loadMobilebaseFromGit(String id, String file) {
menueController.loadMobilebaseFromGit(id, file);
}
private void addTutorial() {
Platform.runLater(() -> getTutorialDockNode().dock(dockPane, DockPos.LEFT));
}
public void showConectionManager() {
String key = "showDevices";
if (isOpen.get(key) == null) {
isOpen.put(key, false);
}
if (isOpen.get("showTerminal") == null) {
isOpen.put("showTerminal", false);
}
Platform.runLater(() -> {
if (!isOpen.get(key)) {
isOpen.put(key, true);
if (isOpen.get("showTerminal"))
connectionManagerDockNode.dock(dockPane, DockPos.RIGHT, terminalDockNode);
else
connectionManagerDockNode.dock(dockPane, DockPos.BOTTOM, getTutorialDockNode());
connectionManagerDockNode.requestFocus();
connectionManagerDockNode.closedProperty().addListener(new InvalidationListener() {
@Override
public void invalidated(Observable event) {
connectionManagerDockNode.closedProperty().removeListener(this);
isOpen.put(key, false);
}
});
}
Platform.runLater(() -> connectionManagerDockNode.requestFocus());
});
}
public void showTerminal() {
String key = "showTerminal";
if (isOpen.get(key) == null || getTutorialDockNode()==null ||terminalDockNode==null) {
isOpen.put(key, false);
return;
}
if (isOpen.get("showDevices") == null) {
isOpen.put("showDevices", false);
}
if (!isOpen.get(key)) {
isOpen.put(key, true);
Platform.runLater(() -> {
if (isOpen.get("showDevices"))
terminalDockNode.dock(dockPane, DockPos.LEFT, connectionManagerDockNode);
else
terminalDockNode.dock(dockPane, DockPos.BOTTOM, getTutorialDockNode());
terminalDockNode.requestFocus();
if (ScriptingEngine.isLoginSuccess()) {
}
terminalDockNode.closedProperty().addListener(new InvalidationListener() {
@Override
public void invalidated(Observable event) {
terminalDockNode.closedProperty().removeListener(this);
isOpen.put(key, false);
}
});
Platform.runLater(() -> terminalDockNode.requestFocus());
});
}
}
public void showCreatureLab() {
showCreatureLab(0);
}
public void showCreatureLab(int depth) {
String key = "showCreatureLab";
if (!isOpen.get(key)) {
isOpen.put(key, true);
new Thread(() -> {
ThreadUtil.wait(100);
Platform.runLater(() -> {
try {
creatureLab3dDockNode.dock(dockPane, DockPos.RIGHT);
isOpen.put(key, true);
return;
} catch (NullPointerException e) {
// keep trying to open
// e.printStackTrace();
isOpen.put(key, false);
if (depth < 2) {
showCreatureLab(depth + 1);
} else
BowlerStudio.printStackTrace(e);// fail and show
// user
} catch (Exception e) {
isOpen.put(key, false);
BowlerStudio.printStackTrace(e);// fail and show user
}
});
Platform.runLater(() -> creatureLab3dDockNode.closedProperty().addListener(new InvalidationListener() {
@Override
public void invalidated(Observable event) {
creatureLab3dDockNode.closedProperty().removeListener(this);
isOpen.put(key, false);
}
}));
}).start();
}
// else
// Platform.runLater(() -> creatureLab3dDockNode.requestFocus());
}
public DockNode getTutorialDockNode() {
return tutorialDockNode;
}
public void setTutorialDockNode(DockNode tutorialDockNode) {
this.tutorialDockNode = tutorialDockNode;
tutorialDockNode.closableProperty().set(false);
}
public static Stage getPrimaryStage() {
return primaryStage;
}
public static void setPrimaryStage(Stage primaryStage) {
BowlerStudioModularFrame.primaryStage = primaryStage;
}
public ScriptingFileWidget createFileTab(File file) {
// TODO Auto-generated method stub
return controller.createFileTab(file);
}
public void openUrlInNewTab(URL url) {
Platform.runLater(() -> {
try {
if (PasswordManager.getUsername() != null) {
WebTab newTab = new WebTab("Web", url.toExternalForm(), false);
addTab(newTab, true);
}
} catch (IOException | InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
}
public void closeTab(Tab newTab) {
if (webTabs.get(newTab) != null) {
System.err.println("Closing tab: " + newTab.getText());
DockNode dn=webTabs.get(newTab);
webTabs.remove(newTab);
if(dn!=null)
Platform.runLater(() -> {
try {
dn.undock();
}catch(java.lang.NullPointerException ex) {}
Platform.runLater(() -> dn.close());
if(newTab!=null)
if (newTab.getOnCloseRequest() != null) {
newTab.getOnCloseRequest().handle(null);
}
});
}
}
public void addTab(Tab newTab, boolean b) {
System.err.println("Loading a new tab: " + newTab.getText());
if (webTabs.get(newTab) != null) {
Platform.runLater(() -> webTabs.get(newTab).requestFocus());
} else {
Platform.runLater(() -> {
DockNode dn = new DockNode(newTab.getContent(), newTab.getText(), newTab.getGraphic());
dn.closedProperty().addListener(event -> {
closeTab(newTab);
});
webTabs.put(newTab, dn);
dn.dock(dockPane, DockPos.CENTER, getTutorialDockNode());
});
}
}
public static BowlerStudioModularFrame getBowlerStudioModularFrame() {
return bowlerStudioModularFrame;
}
public void setSelectedTab(Tab tab) {
if (webTabs.get(tab) != null)
Platform.runLater(() -> webTabs.get(tab).requestFocus());
}
}

View File

@@ -0,0 +1,75 @@
package com.neuronrobotics.bowlerstudio;
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.bowlerstudio.assets.ConfigurationDatabase;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.stage.Modality;
import javafx.stage.Stage;
/**
* Created by Ryan Benasutti on 2/6/2016.
*/
public class ChangeAssetRepoController extends Application {
@FXML
private TextField repoField;
@FXML
private Button changeRepoButton, cancelButton;
public ChangeAssetRepoController() {}
@SuppressWarnings("restriction")
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = AssetFactory.loadLayout("layout/changeAssetRepo.fxml", true);
Parent root;
loader.setController(this);
// This is needed when loading on MAC
loader.setClassLoader(getClass().getClassLoader());
root = loader.load();
Platform.runLater(() -> {
primaryStage.setTitle("Change Asset Repository");
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.initModality(Modality.WINDOW_MODAL);
primaryStage.setResizable(true);
primaryStage.show();
});
}
@FXML
public void onChangeRepo(ActionEvent event)
{
String repo = repoField.getText()
.replaceAll("git://", "https://");
new Thread(()->{
ConfigurationDatabase.setObject("BowlerStudioConfigs", "skinRepo",
repo);
ConfigurationDatabase.save();
}).start();
Stage stage = (Stage) changeRepoButton.getScene().getWindow();
stage.close();
}
@FXML
public void onCancel(ActionEvent event) {
Platform.runLater(() -> {
Stage stage = (Stage) cancelButton.getScene().getWindow();
stage.close();
});
}
}

View File

@@ -0,0 +1,561 @@
package com.neuronrobotics.bowlerstudio;
import com.neuronrobotics.addons.driving.HokuyoURGDevice;
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.bowlerstudio.threed.VirtualCameraDevice;
import com.neuronrobotics.bowlerstudio.utils.BowlerConnectionMenu;
import com.neuronrobotics.imageprovider.AbstractImageProvider;
//import com.neuronrobotics.imageprovider.OpenCVImageProvider;
import com.neuronrobotics.imageprovider.StaticFileProvider;
import com.neuronrobotics.imageprovider.URLImageProvider;
import com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice;
import com.neuronrobotics.sdk.addons.gamepad.IJInputEventListener;
import com.neuronrobotics.sdk.addons.kinematics.FirmataBowler;
import com.neuronrobotics.sdk.addons.kinematics.gcodebridge.GcodeDevice;
import com.neuronrobotics.sdk.common.*;
import com.neuronrobotics.sdk.javaxusb.UsbCDCSerialConnection;
import com.neuronrobotics.sdk.network.BowlerTCPClient;
import com.neuronrobotics.sdk.network.UDPBowlerConnection;
import com.neuronrobotics.sdk.serial.SerialConnection;
import com.neuronrobotics.sdk.ui.AbstractConnectionPanel;
import com.neuronrobotics.sdk.util.ThreadUtil;
import com.neuronrobotics.sdk.wireless.bluetooth.BluetoothSerialConnection;
import gnu.io.NRSerialPort;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.FileChooser;
import javafx.stage.Modality;
import javafx.stage.Stage;
import net.java.games.input.Component;
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;
import net.java.games.input.Event;
import org.reactfx.util.FxTimer;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
//import org.bytedeco.javacv.OpenCVFrameGrabber;
public class ConnectionManager extends Tab implements IDeviceAddedListener ,EventHandler<ActionEvent> {
private static VBox rootItem;
private static final ArrayList<PluginManagerWidget> plugins = new ArrayList<PluginManagerWidget>();
//private BowlerStudioController bowlerStudioController;
String formatStr="%1$-40s %2$-60s %3$-40s";
private static final ConnectionManager connectionManager;
private static Button disconnectAll;
private static HBox topLine;
final static Accordion accordion = new Accordion ();
static{
connectionManager = new ConnectionManager();
}
private Node getIcon(String s) {
return new ImageView(new Image(
AbstractConnectionPanel.class.getResourceAsStream(s)));
}
public ConnectionManager() {
if(connectionManager!=null){
throw new RuntimeException("Connection manager is a static singleton, access it using ConnectionManager.getConnectionmanager()");
}
setText("My Devices");
setGraphic(AssetFactory.loadIcon("My-Devices.png"));
rootItem = new VBox(10);
// rootItem.getColumnConstraints().add(new ColumnConstraints(30)); // column 1 is 75 wide
// rootItem. getColumnConstraints().add(new ColumnConstraints(80)); // column 2 is 300 wide
// rootItem.getColumnConstraints().add(new ColumnConstraints(100)); // column 2 is 100 wide
// rootItem.getColumnConstraints().add(new ColumnConstraints(50)); // column 2 is 100 wide
//
topLine = new HBox(20);
disconnectAll = new Button("Disconnect All",AssetFactory.loadIcon("Disconnect-All.png"));
disconnectAll.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
disconnectAll();
}
});
disconnectAll.setDisable(true);
topLine.getChildren().addAll(AssetFactory.loadIcon("Connected-Devices.png"),new Text("Connected Devices"),disconnectAll);
rootItem.getChildren().add(topLine);
rootItem.getChildren().add(accordion);
// rootItem = new CheckBoxTreeItem<String>( String.format(" "+formatStr, "SCRIPTING NAME","DEVICE TYPE","MAC ADDRESS"),
// getIcon("images/connection-icon.png"
// // "images/usb-icon.png"
// ));
// rootItem.setExpanded(true);
// rootItem.setSelected(true);
// rootItem.selectedProperty().addListener(b -> {
// if (!rootItem.isSelected()) {
// disconnectAll();
// }
// });
setContent(rootItem);
DeviceManager.addDeviceAddedListener(this);
}
public static void addConnection(BowlerAbstractDevice newDevice, String name) {
if(!VirtualCameraDevice.class.isInstance(newDevice))
DeviceManager.addConnection(newDevice, name);
}
@Override
public void handle(ActionEvent event) {
// TODO Auto-generated method stub
}
public static ArrayList<PluginManagerWidget> getPlugins() {
return plugins;
}
//
// public BowlerStudioController getBowlerStudioController() {
// return bowlerStudioController;
// }
//
// public void setBowlerStudioController(
// BowlerStudioController bowlerStudioController) {
// this.bowlerStudioController = bowlerStudioController;
// }
public static BowlerAbstractDevice pickConnectedDevice(@SuppressWarnings("rawtypes") Class class1) {
List<String> choices = DeviceManager.listConnectedDevice(class1);
if(!choices.isEmpty()){
ChoiceDialog<String> dialog = new ChoiceDialog<>(choices.get(0),
choices);
dialog.setTitle("Bowler Device Chooser");
dialog.setHeaderText("Choose connected bowler device");
dialog.setContentText("Device Name:");
// Traditional way to get the response value.
Optional<String> result = dialog.showAndWait();
if (result.isPresent()) {
for (int i = 0; i < plugins.size(); i++) {
if (plugins.get(i).getManager().getName().contains(result.get())) {
return plugins.get(i).getManager().getDevice();
}
}
}
}else{
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Device not availible");
alert.setHeaderText("Connect a "+class1.getSimpleName());
alert.setContentText("A device of type "+class1.getSimpleName()+" is needed");
alert .initModality(Modality.APPLICATION_MODAL);
alert.show();
}
return null;
}
// public BowlerAbstractDevice pickConnectedDevice() {
//
// return pickConnectedDevice(null);
// }
public static void disconnectAll() {
//extract list int thread safe object
Object [] pms= plugins.toArray();
for (int i=0;i<pms.length;i++) {
disconectAndRemoveDevice(((PluginManagerWidget)pms[i]).getManager());
//ThreadUtil.wait(50);
}
}
// public static OpenCVImageProvider onConnectCVCamera() {
// List<String> choices = new ArrayList<>();
// choices.add("0");
// choices.add("1");
// choices.add("2");
// choices.add("3");
// choices.add("4");
//
// ChoiceDialog<String> dialog = new ChoiceDialog<>("0", choices);
// dialog.setTitle("OpenCV Camera Index Chooser");
// dialog.setHeaderText("Choose an OpenCV camera");
// dialog.setContentText("Camera Index:");
//
// // Traditional way to get the response value.
// Optional<String> result = dialog.showAndWait();
//
// // The Java 8 way to get the response value (with lambda expression).
// if (result !=null) {
// String letter = result.get();
// OpenCVImageProvider p = new OpenCVImageProvider(Integer.parseInt(letter));
// String name = "camera"+letter;
// addConnection(p,name);
// return p;
// }
// return null;
//// OpenCVImageProvider p = new OpenCVImageProvider(0);
//// String name = "camera0";
//// application.addConnection(p,name);
//
// }
//
public static void onConnectJavaCVCamera() {
// onConnectCVCamera();
// List<String> choices = new ArrayList<>();
// try {
// String[] des = OpenCVFrameGrabber.getDeviceDescriptions();
// if(des.length==0)
// return;
// for (String s: des){
// choices.add(s);
// }
// } catch (org.bytedeco.javacv.FrameGrabber.Exception |UnsupportedOperationException e1) {
// choices.add("0");
// choices.add("1");
// choices.add("2");
// choices.add("3");
// choices.add("4");
// }
//
// ChoiceDialog<String> dialog = new ChoiceDialog<>(choices.get(0), choices);
// dialog.setTitle("JavaCV Camera Index Chooser");
// dialog.setHeaderText("Choose an JavaCV camera");
// dialog.setContentText("Camera Index:");
//
// // Traditional way to get the response value.
// Optional<String> result = dialog.showAndWait();
//
// // The Java 8 way to get the response value (with lambda expression).
// result.ifPresent(letter -> {
// JavaCVImageProvider p;
// try {
// p = new JavaCVImageProvider(Integer.parseInt(letter));
// String name = "camera"+letter;
// addConnection(p,name);
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
// });
//
}
public static void onConnectFileSourceCamera() {
Platform.runLater(()->{});
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Image File");
File f = fileChooser.showOpenDialog(BowlerStudioModularFrame.getPrimaryStage());
if(f!=null){
AbstractImageProvider p = new StaticFileProvider(f);
String name = "image";
addConnection(p,name);
}
}
public static void onConnectURLSourceCamera() {
TextInputDialog dialog = new TextInputDialog("http://neuronrobotics.com/img/AndrewHarrington/2014-09-15-86.jpg");
dialog.setTitle("URL Image Source");
dialog.setHeaderText("This url will be loaded each capture.");
dialog.setContentText("URL ");
// Traditional way to get the response value.
Optional<String> result = dialog.showAndWait();
if (result.isPresent()){
URLImageProvider p;
try {
p = new URLImageProvider(new URL(result.get()));
String name = "url";
addConnection(p,name);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void onMarlinGCODE() {
Set<String> ports = NRSerialPort.getAvailableSerialPorts();
List<String> choices = new ArrayList<>();
if(ports.isEmpty())
return;
for (String s: ports){
choices.add(s);
}
ChoiceDialog<String> dialog = new ChoiceDialog<>(choices.get(0), choices);
dialog.setTitle("GCODE Device Serial Port Chooser");
dialog.setHeaderText("Supports Marlin");
dialog.setContentText("GCODE Device Port:");
// Traditional way to get the response value.
Optional<String> result = dialog.showAndWait();
// The Java 8 way to get the response value (with lambda expression).
result.ifPresent(letter -> {
GcodeDevice p = new GcodeDevice(new NRSerialPort(letter, 115200));
p.connect();
String name = "GCODE";
addConnection(p,name);
});
}
public static void onConnectHokuyoURG() {
Set<String> ports = NRSerialPort.getAvailableSerialPorts();
List<String> choices = new ArrayList<>();
if(ports.isEmpty())
return;
for (String s: ports){
choices.add(s);
}
ChoiceDialog<String> dialog = new ChoiceDialog<>(choices.get(0), choices);
dialog.setTitle("LIDAR Serial Port Chooser");
dialog.setHeaderText("Supports URG-04LX-UG01");
dialog.setContentText("Lidar Port:");
// Traditional way to get the response value.
Optional<String> result = dialog.showAndWait();
// The Java 8 way to get the response value (with lambda expression).
result.ifPresent(letter -> {
HokuyoURGDevice p = new HokuyoURGDevice(new NRSerialPort(letter, 115200));
p.connect();
String name = "lidar";
addConnection(p,name);
});
}
public static void onConnectGamePad(String name ) {
Controller[] ca = ControllerEnvironment.getDefaultEnvironment().getControllers();
List<String> choices = new ArrayList<>();
if(ca.length==0)
return;
for (Controller s: ca){
choices.add(s.getName());
}
ChoiceDialog<String> dialog = new ChoiceDialog<>(choices.get(0), choices);
dialog.setTitle("JInput Game Controller Select");
dialog.setHeaderText("Connect a game controller");
dialog.setContentText("Controller:");
// Traditional way to get the response value.
Optional<String> result = dialog.showAndWait();
// The Java 8 way to get the response value (with lambda expression).
result.ifPresent(letter -> {
for(Controller s: ca){
if(letter.contains(s.getName())){
BowlerJInputDevice p =new BowlerJInputDevice(s);
p.connect();
IJInputEventListener l=new IJInputEventListener() {
@Override
public void onEvent(Component comp, Event event1,
float value, String eventString) {
//System.out.println(comp.getName()+" is value= "+value);
}
};
p.addListeners(l);
addConnection(p,name);
return;
}
}
});
}
@Override
public void onNewDeviceAdded(BowlerAbstractDevice newDevice) {
if(VirtualCameraDevice.class.isInstance(newDevice))
return;
PluginManager mp;
Log.debug("Adding a "+newDevice.getClass().getName()+" with name "+newDevice.getScriptingName() );
mp = new PluginManager(newDevice);
BowlerAbstractConnection con = newDevice.getConnection();
Node icon = getIcon("images/connection-icon.png"
// "images/usb-icon.png"
);
if (SerialConnection.class.isInstance(con)) {
icon = getIcon(
// "images/ethernet-icon.png"
"images/usb-icon.png");
} else if (UsbCDCSerialConnection.class.isInstance(con)) {
icon = getIcon(
// "images/ethernet-icon.png"
"images/usb-icon.png");
} else if (BluetoothSerialConnection.class.isInstance(con)) {
icon = getIcon(
// "images/ethernet-icon.png"
"images/bluetooth-icon.png");
} else if (UDPBowlerConnection.class.isInstance(con)
|| BowlerTCPClient.class.isInstance(con)) {
icon = getIcon(
// "images/ethernet-icon.png"
"images/ethernet-icon.png");
}
String line = String.format(formatStr,
newDevice.getScriptingName(),
newDevice.getClass().getSimpleName(),
newDevice.getAddress());
PluginManagerWidget e = new PluginManagerWidget(mp,icon);
plugins.add(e);
Platform.runLater(() -> accordion.getPanes().add(e));
Platform.runLater(() -> disconnectAll.setDisable(false));
mp.setName(newDevice.getScriptingName());
newDevice.addConnectionEventListener(
new IDeviceConnectionEventListener() {
@Override
public void onDisconnect(BowlerAbstractDevice source) {
// clean up after yourself...
//disconectAndRemoveDevice(mp);
for(int i=0;i<plugins.size();i++){
PluginManager p=plugins.get(i).getManager();
if(p.getDevice()==source){
DeviceManager.remove(p.getDevice());
return;
}
}
}
// ignore
@Override
public void onConnect(BowlerAbstractDevice source) {
}
});
if( getBowlerStudioController()!=null)
BowlerStudioModularFrame.getBowlerStudioModularFrame().setSelectedTab(this);
}
private BowlerStudioController getBowlerStudioController() {
// TODO Auto-generated method stub
return BowlerStudioController.getBowlerStudio();
}
private static void disconectAndRemoveDevice(PluginManager mp){
System.out.println("CM Disconnecting " + mp.getName());
Log.warning("Disconnecting " + mp.getName());
if(mp.getDevice().isAvailable() || NonBowlerDevice.class.isInstance(mp))
mp.getDevice().disconnect();
DeviceManager.remove(mp.getDevice());
}
@Override
public void onDeviceRemoved(BowlerAbstractDevice bad) {
Log.warning("Removing Device " + bad.getScriptingName());
//new RuntimeException().printStackTrace();
for(int i=0;i<plugins.size();i++){
PluginManager p=plugins.get(i).getManager();
if(p.getDevice()==bad){
Log.warning("Found Device " + bad.getScriptingName());
//new RuntimeException().printStackTrace();
PluginManagerWidget torem = plugins.remove(i);
Platform.runLater(() ->accordion.getPanes().remove(torem));
if (plugins.isEmpty()){
Platform.runLater(() ->disconnectAll.setDisable(true));
}
return;
}
}
}
public static void addConnection() {
Stage s = new Stage();
new Thread() {
public void run() {
BowlerDatagram.setUseBowlerV4(true);
BowlerConnectionMenu controller = new BowlerConnectionMenu();
try {
controller.start(s);
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
//DeviceManager.addConnection();
}
public static ConnectionManager getConnectionManager() {
return connectionManager;
}
public static void onFirmata() {
Set<String> ports = NRSerialPort.getAvailableSerialPorts();
List<String> choices = new ArrayList<>();
if(ports.isEmpty())
return;
for (String s: ports){
choices.add(s);
}
ChoiceDialog<String> dialog = new ChoiceDialog<>(choices.get(0), choices);
dialog.setTitle("Firmata Device Serial Port Chooser");
dialog.setHeaderText("Supports Firmata");
dialog.setContentText("Firmata Device Port:");
// Traditional way to get the response value.
Optional<String> result = dialog.showAndWait();
// The Java 8 way to get the response value (with lambda expression).
result.ifPresent(letter -> {
new Thread(()->{
System.out.print("\nConnecting Firmata...");
FirmataBowler p = new FirmataBowler(letter);
p.connect();
String name = "firmata";
addConnection(p,name);
System.out.print("Done!\n");
}).start();
});
}
}

View File

@@ -0,0 +1,191 @@
package com.neuronrobotics.bowlerstudio;
import java.lang.Thread.UncaughtExceptionHandler;
/**
* Sample Skeleton for "CreatureLab.fxml" Controller Class
* You can copy and paste this code into your favorite IDE
**/
import java.net.URL;
import java.util.ResourceBundle;
import com.neuronrobotics.bowlerstudio.threed.BowlerStudio3dEngine;
import javafx.application.Platform;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.geometry.Bounds;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.SubScene;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TreeView;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
public class CreatureLab3dController {
@FXML // ResourceBundle that was given to the FXMLLoader
private ResourceBundle resources;
@FXML // URL location of the FXML file that was given to the FXMLLoader
private URL location;
@FXML // fx:id="CadControlsAnchor"
private AnchorPane CadControlsAnchor; // Value injected by FXMLLoader
@FXML // fx:id="DriveControlsAnchor"
private AnchorPane DriveControlsAnchor; // Value injected by FXMLLoader
@FXML // fx:id="TempControlsAnchor"
private AnchorPane TempControlsAnchor; // Value injected by FXMLLoader
@FXML // fx:id="jfx3dControls"
private AnchorPane jfx3dControls; // Value injected by FXMLLoader
@FXML // fx:id="overlayScrollPanel"
private ScrollPane overlayScrollPanel; // Value injected by FXMLLoader
@FXML // fx:id="viewContainer"
private AnchorPane viewContainer; // Value injected by FXMLLoader
//private SubScene subScene;
protected EventHandler<? super KeyEvent> normalKeyPessHandle = null;
private static BowlerStudio3dEngine engine;
public CreatureLab3dController (){
setEngine(new BowlerStudio3dEngine());
}
public void setOverlayLeft(Node content) {
Platform.runLater(() -> {
overlayScrollPanel.setFitToHeight(true);
overlayScrollPanel.setContent(content);
content.setOpacity(1);
overlayScrollPanel.viewportBoundsProperty()
.addListener((ObservableValue<? extends Bounds> arg0, Bounds arg1, Bounds arg2) -> {
// Node content = overlayScrollPanel.getContent();
//
// System.out.println("Resizing " + arg2);
Platform.runLater(() -> {
overlayScrollPanel.setFitToHeight(true);
/// content.seth
overlayScrollPanel.setContent(content);
});
});
overlayScrollPanel.setVisible(true);
});
}
public void clearOverlayLeft() {
Platform.runLater(() -> {
overlayScrollPanel.setContent(null);
overlayScrollPanel.setVisible(false);
});
}
public void setOverlayTop(Group content) {
Platform.runLater(() -> {
CadControlsAnchor.getChildren().clear();
CadControlsAnchor.getChildren().add(content);
AnchorPane.setTopAnchor(content, 0.0);
AnchorPane.setRightAnchor(content, 0.0);
AnchorPane.setLeftAnchor(content, 0.0);
AnchorPane.setBottomAnchor(content, 0.0);
CadControlsAnchor.setVisible(true);
});
}
public void clearOverlayTop() {
Platform.runLater(() -> {
CadControlsAnchor.getChildren().clear();
CadControlsAnchor.setVisible(false);
});
}
public void setOverlayTopRight(Group content) {
Platform.runLater(() -> {
DriveControlsAnchor.getChildren().clear();
DriveControlsAnchor.getChildren().add(content);
AnchorPane.setTopAnchor(content, 0.0);
AnchorPane.setRightAnchor(content, 0.0);
AnchorPane.setLeftAnchor(content, 0.0);
AnchorPane.setBottomAnchor(content, 0.0);
DriveControlsAnchor.setVisible(true);
});
}
public void clearOverlayTopRight() {
Platform.runLater(() -> {
DriveControlsAnchor.getChildren().clear();
DriveControlsAnchor.setVisible(false);
});
}
public void setOverlayBottomRight(Group content) {
Platform.runLater(() -> {
TempControlsAnchor.getChildren().clear();
TempControlsAnchor.getChildren().add(content);
AnchorPane.setTopAnchor(content, 0.0);
AnchorPane.setRightAnchor(content, 0.0);
AnchorPane.setLeftAnchor(content, 0.0);
AnchorPane.setBottomAnchor(content, 0.0);
TempControlsAnchor.setVisible(true);
});
}
public void clearOverlayBottomRight() {
Platform.runLater(() -> {
TempControlsAnchor.getChildren().clear();
TempControlsAnchor.setVisible(false);
});
}
@FXML // This method is called by the FXMLLoader when initialization is complete
void initialize() {
assert CadControlsAnchor != null : "fx:id=\"CadControlsAnchor\" was not injected: check your FXML file 'CreatureLab.fxml'.";
assert DriveControlsAnchor != null : "fx:id=\"DriveControlsAnchor\" was not injected: check your FXML file 'CreatureLab.fxml'.";
assert TempControlsAnchor != null : "fx:id=\"TempControlsAnchor\" was not injected: check your FXML file 'CreatureLab.fxml'.";
assert jfx3dControls != null : "fx:id=\"jfx3dControls\" was not injected: check your FXML file 'CreatureLab.fxml'.";
assert overlayScrollPanel != null : "fx:id=\"overlayScrollPanel\" was not injected: check your FXML file 'CreatureLab.fxml'.";
assert viewContainer != null : "fx:id=\"viewContainer\" was not injected: check your FXML file 'CreatureLab.fxml'.";
clearOverlayLeft();
// Initialize your logic here: all @FXML variables will have been injected
setupUi();
}
private void setupUi() {
Platform.runLater(() -> {
getEngine() .getSubScene().setFocusTraversable(false);
getEngine() .getSubScene().widthProperty().bind(viewContainer.widthProperty());
getEngine() .getSubScene().heightProperty().bind(viewContainer.heightProperty());
});
Platform.runLater(() -> {
jfx3dControls.getChildren().add(getEngine().getControlsBox());
viewContainer.getChildren().add(getEngine() .getSubScene());
AnchorPane.setTopAnchor(getEngine() .getSubScene(), 0.0);
AnchorPane.setRightAnchor(getEngine() .getSubScene(), 0.0);
AnchorPane.setLeftAnchor(getEngine() .getSubScene(), 0.0);
AnchorPane.setBottomAnchor(getEngine() .getSubScene(), 0.0);
});
}
public static BowlerStudio3dEngine getEngine() {
return engine;
}
public static void setEngine(BowlerStudio3dEngine engine) {
CreatureLab3dController.engine = engine;
}
}

View File

@@ -0,0 +1,67 @@
package com.neuronrobotics.bowlerstudio;
import com.neuronrobotics.bowlerstudio.tabs.AbstractBowlerStudioTab;
import com.neuronrobotics.sdk.common.BowlerAbstractDevice;
import com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace;
public class DeviceSupportPluginMap implements PluginFactory{
private Class<?> device;
private Class<?> plugin;
private PluginFactory factory=null;
DeviceSupportPluginMap(Class<?> device,Class<?> plugin){
this.setDevice(device);
this.setPlugin(plugin);
}
public DeviceSupportPluginMap(Class<?> device,Class<?> plugin, PluginFactory factory){
this.factory = factory;
this.setDevice(device);
this.setPlugin(plugin);
}
public boolean isFactoryProvided(){
return factory!=null;
}
public Class<?> getDevice() {
return device;
}
private void setDevice(Class<?> device) {
if(BowlerAbstractDevice.class.isAssignableFrom(device) || IPidControlNamespace.class.isAssignableFrom(device) )
this.device = device;
else
throw new RuntimeException("Devices must subclass BowlerAbstractDevice or NonBowlerDevice");
}
public Class<?> getPlugin() {
return plugin;
}
private void setPlugin(Class<?> plugin) {
if(AbstractBowlerStudioTab.class.isAssignableFrom(plugin) )
this.plugin = plugin;
else
throw new RuntimeException("Plugins must subclass AbstractBowlerStudioTab");
}
@Override
public String toString(){
return "Device: "+device.getCanonicalName()+" Plugin: "+plugin.getCanonicalName();
}
@Override
public AbstractBowlerStudioTab generateNewPlugin() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
if(factory!=null)
return factory.generateNewPlugin();
return (AbstractBowlerStudioTab) Class.forName(
plugin.getName()
).cast(plugin.newInstance()// This is where the new tab allocation is called
)
;
}
}

View File

@@ -0,0 +1,103 @@
package com.neuronrobotics.bowlerstudio;
import com.neuronrobotics.bowlerstudio.scripting.PasswordManager;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import com.neuronrobotics.sdk.util.ThreadUtil;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.jfree.util.Log;
import org.kohsuke.github.GHGist;
import org.kohsuke.github.GHGistBuilder;
import org.kohsuke.github.GHGistFile;
import org.kohsuke.github.GitHub;
import java.io.IOException;
import java.net.URL;
/**
* Created by Ryan Benasutti on 2/5/2016.
*/
public class GistHelper
{
private GistHelper() {}
public static String createNewGist(String filename, String description, boolean isPublic)
{
//TODO: Perhaps this method should throw GitAPIException and IOException
//Setup gist
GitHub gitHub = PasswordManager.getGithub();
GHGistBuilder builder = gitHub.createGist();
builder.file(filename, "//Your code here");
builder.description(description);
builder.public_(isPublic);
//Make gist
return createGistFromBuilder(builder, filename);
}
public static String addFileToGist(String filename, String content, GHGist gistID)
{
GitHub gitHub = PasswordManager.getGithub();
try
{
//Copy from old gist
GHGist oldGist = gistID;
GHGistBuilder builder = gitHub.createGist();
builder.description(oldGist.getDescription());
builder.public_(oldGist.isPublic());
for (String key : oldGist.getFiles().keySet())
builder.file(key, oldGist.getFiles().get(key).getContent());
//Add new file
builder.file(filename, content);
//Make new gist with old filename
return createGistFromBuilder(builder, oldGist.getFiles().values().iterator().next().getFileName());
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
private static String createGistFromBuilder(GHGistBuilder builder, String filename)
{
GHGist gist;
try
{
gist = builder.create();
//String gistID = ScriptingEngine.urlToGist(gist.getHtmlUrl());
//BowlerStudio.openUrlInNewTab(new URL(gist.getHtmlUrl()));
System.out.println("Creating repo");
while (true)
{
try
{
ScriptingEngine.fileFromGit(gist.getGitPullUrl(), filename);
break;
}
catch (GitAPIException e)
{
e.printStackTrace();
}
ThreadUtil.wait(500);
Log.warn(filename + " not built yet");
}
System.out.println("Creating gist at " + filename);
return gist.getGitPullUrl();
}
catch (IOException e)
{
e.printStackTrace();
}
return null;
}
}

View File

@@ -0,0 +1,96 @@
package com.neuronrobotics.bowlerstudio;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import com.neuronrobotics.bowlerstudio.assets.BowlerStudioResourceFactory;
import com.neuronrobotics.bowlerstudio.scripting.GithubLoginFX;
import com.neuronrobotics.bowlerstudio.scripting.IGitHubLoginManager;
import com.neuronrobotics.bowlerstudio.scripting.IGithubLoginListener;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import com.neuronrobotics.sdk.util.ThreadUtil;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.stage.Modality;
import javafx.stage.Stage;
public class GitHubLoginManager implements IGitHubLoginManager {
private boolean loginWindowOpen = false;
private GithubLoginFX githublogin = null;
private Stage stage;
private boolean AnonSelected = false;
private String[] creds;
public GitHubLoginManager() {
}
@SuppressWarnings("restriction")
@Override
public String[] prompt(String username) {
if (AnonSelected) {
return null;
}
boolean loginWas = loginWindowOpen;
if (githublogin != null)
githublogin.reset();
if (stage == null) {
if (!loginWas && githublogin != null)
githublogin.reset();
githublogin = null;
// System.out.println("Calling login from BowlerStudio "+username);
// new RuntimeException().printStackTrace();
FXMLLoader fxmlLoader = BowlerStudioResourceFactory.getGithubLogin();
if (fxmlLoader == null)
return null;
Parent root = fxmlLoader.getRoot();
if (githublogin == null) {
githublogin = fxmlLoader.getController();
githublogin.reset();
Platform.runLater(() -> {
if (!loginWindowOpen) {
githublogin.reset();
githublogin.getUsername().setText(username);
stage = new Stage();
stage.setTitle("GitHub Login");
// stage.initModality(Modality.APPLICATION_MODAL);
githublogin.setStage(stage, root);
stage.centerOnScreen();
loginWindowOpen = true;
stage.setAlwaysOnTop(true);
stage.show();
stage = null;
}
});
}
}
// setContent(root);
do {
// System.err.println("Waiting for user login");
ThreadUtil.wait(100);
} while (!githublogin.isDone());
creds = githublogin.getCreds();
// System.err.println(" login = "+creds);
if (creds == null) {
// System.err.println("Anon mode");
AnonSelected = true;
}
loginWindowOpen = false;
return creds;
}
@Override
public String twoFactorAuthCodePrompt() {
JFrame jframe = new JFrame();
String answer = JOptionPane.showInputDialog(jframe, "Enter 2 factor auth code:");
jframe.dispose();
return answer;
}
}

View File

@@ -0,0 +1,11 @@
package com.neuronrobotics.bowlerstudio;
import javafx.scene.control.Menu;
public interface INewVitaminCallback {
void addVitaminType(String s);
Menu getTypeMenu(String type);
void addSizesToMenu(String size,String type);
}

View File

@@ -0,0 +1,26 @@
package com.neuronrobotics.bowlerstudio;
import java.util.HashMap;
public class MeasurmentConfig {
private String key;
private HashMap<String, Object> configs;
public MeasurmentConfig(String key,HashMap<String, Object> configs){
this.configs = configs;
this.setKey(key);
System.out.println("Adding Measurment "+key+" "+getMeasurment());
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getMeasurment() {
return configs.get(key).toString();
}
public void setMeasurment(String measurment) {
System.out.println("Setting field "+key+" to "+measurment);
configs.put(key, measurment);
}
}

View File

@@ -0,0 +1,5 @@
package com.neuronrobotics.bowlerstudio;
public interface MenuRefreshEvent {
void setToLoggedIn();
}

View File

@@ -0,0 +1,26 @@
package com.neuronrobotics.bowlerstudio;
import javafx.event.Event;
import javafx.event.EventHandler;
public abstract class MenuResettingEventHandler implements EventHandler<Event> {
private Runnable menuReset = null;
public Runnable getMenuReset() {
if(menuReset==null)
menuReset=new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
}
};
return menuReset;
}
public void setMenuReset(Runnable menuReset) {
this.menuReset = menuReset;
}
}

View File

@@ -0,0 +1,12 @@
package com.neuronrobotics.bowlerstudio;
public class NewCreatureWizard {
public static void run() {
new Thread(()->{
Thread.setDefaultUncaughtExceptionHandler(new IssueReportingExceptionHandler());
}).start();
}
}

View File

@@ -0,0 +1,577 @@
package com.neuronrobotics.bowlerstudio;
/**
* Sample Skeleton for 'newVitaminWizard.fxml' Controller Class
*/
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Optional;
import java.util.ResourceBundle;
import org.kohsuke.github.GHCreateRepositoryBuilder;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GitHub;
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.bowlerstudio.scripting.PasswordManager;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import com.neuronrobotics.bowlerstudio.vitamins.Vitamins;
import com.neuronrobotics.sdk.addons.kinematics.JavaFXInitializer;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Menu;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.TextInputDialog;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class NewVitaminWizardController extends Application {
@FXML // ResourceBundle that was given to the FXMLLoader
private ResourceBundle resources;
@FXML // URL location of the FXML file that was given to the FXMLLoader
private URL location;
@FXML // fx:id="typePane"
private AnchorPane typePane; // Value injected by FXMLLoader
@FXML // fx:id="x1"
private Font x1; // Value injected by FXMLLoader
@FXML // fx:id="x2"
private Color x2; // Value injected by FXMLLoader
@FXML // fx:id="existingTypeRadio"
private RadioButton existingTypeRadio; // Value injected by FXMLLoader
@FXML // fx:id="newTypeRadio"
private RadioButton newTypeRadio; // Value injected by FXMLLoader
@FXML // fx:id="typeComboBox"
private ComboBox<String> typeComboBox; // Value injected by FXMLLoader
@FXML // fx:id="sizePane"
private AnchorPane sizePane; // Value injected by FXMLLoader
@FXML // fx:id="sizeComboBox"
private ComboBox<String> sizeComboBox; // Value injected by FXMLLoader
@FXML // fx:id="measurmentPane"
private AnchorPane measurmentPane; // Value injected by FXMLLoader
@FXML // fx:id="measurmentsTable"
private TableView<MeasurmentConfig> measurmentsTable; // Value injected by FXMLLoader
@FXML
private TextField newTypeNameField;
@FXML
private TextField newSizeField;
@FXML // fx:id="nameColumn"
private TableColumn<MeasurmentConfig, String> nameColumn; // Value injected by FXMLLoader
@FXML // fx:id="measurmentColumn"
private TableColumn<MeasurmentConfig, String> measurmentColumn; // Value injected by FXMLLoader
@FXML // fx:id="isMotor"
private CheckBox isMotor; // Value injected by FXMLLoader
@FXML // fx:id="isShaft"
private CheckBox isShaft; // Value injected by FXMLLoader
@FXML // fx:id="editExisting"
private CheckBox editExisting; // Value injected by FXMLLoader
@FXML // fx:id="editExisting"
private Button newMeasurmentButton;
private static INewVitaminCallback callback=null;
private static Stage primaryStage;
private static String typeOfVitaminString = null;
private static String sizeOfVitaminString = null;
@FXML
void onConfirmAndCreate(ActionEvent event) {
sizePane.setDisable(true);
measurmentPane.setDisable(true);
typePane.setDisable(true);
new Thread(() -> {
try {
if(newTypeRadio.isSelected()) {
if(isShaft.isSelected())
Vitamins.setIsShaft(typeOfVitaminString);
if(isMotor.isSelected())
Vitamins.setIsActuator(typeOfVitaminString);
GitHub github = PasswordManager.getGithub();
String newName =typeOfVitaminString+"CadGenerator";
GHCreateRepositoryBuilder builder = github.createRepository(newName );
builder.description(newName + " Generates CAD vitamins " );
GHRepository gist=null;
try {
gist = builder.create();
}catch(org.kohsuke.github.HttpException ex) {
if(ex.getMessage().contains("name already exists on this account")) {
gist = github.getRepository(PasswordManager.getLoginID()+"/"+newName);
}
}
String gitURL = gist.getHtmlUrl().toExternalForm()+".git";
String filename = typeOfVitaminString+".groovy";
Vitamins.setScript(typeOfVitaminString, gitURL, filename);
String measurments ="";
for(String key:Vitamins.getConfiguration( typeOfVitaminString,sizeOfVitaminString).keySet()) {
measurments+="\n def "+key+"Value = measurments."+key;
}
for(String key:Vitamins.getConfiguration( typeOfVitaminString,sizeOfVitaminString).keySet()) {
String string = key+"Value";
measurments+="\n println \"Measurment "+string+" = \"+"+string;
}
String loader = "import eu.mihosoft.vrl.v3d.parametrics.*;\n" +
"CSG generate(){\n" +
" String type= \""+typeOfVitaminString+"\"\n" +
" if(args==null)\n" +
" args=[\""+sizeOfVitaminString+"\"]\n" +
" // The variable that stores the current size of this vitamin\n"
+ " StringParameter size = new StringParameter( type+\" Default\"," +
"args.get(0)," +
"Vitamins.listVitaminSizes(type))\n" +
" HashMap<String,Object> measurments = Vitamins.getConfiguration( type,size.getStrValue())\n" +
measurments+"\n"+
" // Stub of a CAD object\n"+
" CSG part = new Cube().toCSG()\n"+
" return part\n" +
" .setParameter(size)\n" +
" .setRegenerate({generate()})\n" +
"}\n" +
"return generate() ";
ScriptingEngine.pushCodeToGit(gitURL, ScriptingEngine.getFullBranch(gitURL), filename,
loader, "new CAD loader script");
new Thread(() -> BowlerStudio.createFileTab(Vitamins.getScriptFile(typeOfVitaminString))).start();
}
Vitamins.saveDatabaseForkIfMissing(typeOfVitaminString);
if(newTypeRadio.isSelected()) {
callback.addVitaminType(typeOfVitaminString);
}else
if(!editExisting.isSelected())
callback.addSizesToMenu(sizeOfVitaminString, typeOfVitaminString);
} catch (Exception e1) {
// TODO Auto-generated catch block
new IssueReportingExceptionHandler().uncaughtException(Thread.currentThread(), e1);
}
try {
Platform.runLater(() -> {
this.primaryStage.close();
primaryStage=null;
});
} catch (Exception e) {
// TODO Auto-generated catch block
new IssueReportingExceptionHandler().uncaughtException(Thread.currentThread(), e);
}
}).start();
}
@FXML
void onConfirmSize(ActionEvent event) {
if(!editExisting.isSelected()) {
sizeOfVitaminString = newSizeField.getText();
if(sizeOfVitaminString.length()<2) {
Platform.runLater(() -> {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("No name specified!");
alert.setHeaderText("Names must be at least 2 charrectors long");
alert.setContentText("Try again...");
alert.showAndWait();
});
return;
}
String slug = BowlerStudioMenu.slugify(sizeOfVitaminString);
if(!sizeOfVitaminString.contentEquals(slug)) {
Platform.runLater(() -> {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("Name Format Wrong");
alert.setHeaderText("Name must be without spaces or special chars");
alert.setContentText("Changed to "+slug+" confirm to continue...");
alert.showAndWait();
Platform.runLater(() -> newSizeField.setText(slug));
});
return;
}
sizeOfVitaminString=slug;
}else {
sizeOfVitaminString=sizeComboBox.getSelectionModel().getSelectedItem();
}
Platform.runLater(() ->nameColumn.setCellValueFactory(new PropertyValueFactory<MeasurmentConfig, String>("key")));
Platform.runLater(() ->measurmentColumn.setCellValueFactory(new PropertyValueFactory<MeasurmentConfig, String>("measurment")));
Platform.runLater(() ->
measurmentColumn
.setCellFactory(
TextFieldTableCell.forTableColumn())
);
Platform.runLater(() ->measurmentsTable.getSelectionModel().cellSelectionEnabledProperty().set(true));
measurmentsTable.setEditable(true);
nameColumn.setEditable(false);
measurmentColumn.setEditable(true);
measurmentColumn.setOnEditCommit(ev -> {
final String value = ev.getNewValue() != null ? (String) ev.getNewValue() : (String) ev.getOldValue();
((MeasurmentConfig) ev.getTableView().getItems().get(ev.getTablePosition().getRow()))
.setMeasurment(value);
measurmentsTable.refresh();
});
if(existingTypeRadio.isSelected()) {
if(!editExisting.isSelected()) {
boolean exists = false;
// for existing types check for existing sizes
ArrayList<String> sizes = Vitamins.listVitaminSizes(typeOfVitaminString);
for(String size:sizes) {
if(size.contentEquals(sizeOfVitaminString))
exists=true;
}
if(exists) {
Platform.runLater(() -> {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("Size already Exists");
alert.setHeaderText("Name must be unique");
alert.setContentText("Rename and confirm to continue...");
alert.showAndWait();
});
return;
}
}
new Thread(() -> {
HashMap<String, Object> configsOld = Vitamins.getConfiguration(typeOfVitaminString, sizeComboBox.getSelectionModel().getSelectedItem());
for(String key:configsOld.keySet()) {
setupKeyValueToTable(key, configsOld.get(key),sizeOfVitaminString);
}
}).start();
}
if(newTypeRadio.isSelected()) {
Vitamins.getConfiguration(typeOfVitaminString, sizeOfVitaminString);
}
if(Vitamins.isActuator(typeOfVitaminString) ||
(newTypeRadio.isSelected() && isMotor.isSelected())
) {
new Thread(() -> {
HashMap<String, Object> required = new HashMap<String, Object>();
required.put("MaxTorqueNewtonmeters", 0.001);
required.put("MaxFreeSpeedRadPerSec", 1);
required.put("massKg", 0.001);
required.put("shaftType", "dShaft");
required.put("shaftSize", "5mm");
setRequiredFields(required);
}).start();
}
new Thread(() -> {
HashMap<String, Object> required = new HashMap<String, Object>();
required.put("massKg", 0.001);
required.put("source", "https://commonwealthrobotics.com");
required.put("price", 0.01);
required.put("massCentroidX", 0.0);
required.put("massCentroidY", 0.0);
required.put("massCentroidZ", 0.0);
setRequiredFields(required);
}).start();
sizePane.setDisable(true);
measurmentPane.setDisable(false);
typePane.setDisable(true);
}
private void setRequiredFields(HashMap<String, Object> required) {
// For each vitamin size in a given type
for(String size:Vitamins.listVitaminSizes(typeOfVitaminString)) {
HashMap<String, Object> configs = Vitamins.getConfiguration(typeOfVitaminString, size);
// For every required key
for(String key:required.keySet()) {
// check to see if the current size has this key already
if(!configs.containsKey(key)) {
// enter a default value, but ensure that the key exists for downstream code
setupKeyValueToTable(key, required.get(key),size);
}
}
}
}
private void setupKeyValueToTable(String key, Object value, String size) {
Vitamins.getConfiguration(typeOfVitaminString, size).put(key, value);
if (size.contentEquals(sizeOfVitaminString))
Platform.runLater(() -> measurmentsTable.getItems()
.add(new MeasurmentConfig(key, Vitamins.getConfiguration(typeOfVitaminString, sizeOfVitaminString))));
}
@FXML
void onConfirmType(ActionEvent event) {
if(newTypeRadio.isSelected()) {
typeOfVitaminString=newTypeNameField.getText();
if(typeOfVitaminString.length()<2) {
Platform.runLater(() -> {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("No name specified!");
alert.setHeaderText("Names must be at least 2 charrectors long");
alert.setContentText("Try again...");
alert.showAndWait();
});
return;
}
String slug = BowlerStudioMenu.slugify(typeOfVitaminString);
if(!typeOfVitaminString.contentEquals(slug)) {
Platform.runLater(() -> {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("Name Format Wrong");
alert.setHeaderText("Name must be without spaces or special chars");
alert.setContentText("Changed to "+slug+" confirm to continue...");
alert.showAndWait();
Platform.runLater(() -> newTypeNameField.setText(slug));
});
return;
}
typeOfVitaminString=slug;
sizeComboBox.setDisable(true);
editExisting.setDisable(true);
saveAndFork();
}else {
typeOfVitaminString=typeComboBox.getSelectionModel().getSelectedItem();
saveAndFork();
ArrayList<String> sizes = Vitamins.listVitaminSizes(typeOfVitaminString);
boolean hasSize=false;
for(String size:sizes) {
sizeComboBox.getItems().add(size);
if(typeOfVitaminString!=null)
if(size.contentEquals(typeOfVitaminString)) {
hasSize=true;
}
}
if(sizes.size()>0) {
if(hasSize) {
sizeComboBox.getSelectionModel().select(typeOfVitaminString);
}else {
sizeComboBox.getSelectionModel().select(sizes.get(0));
}
}else {
sizeComboBox.setDisable(true);
editExisting.setDisable(true);
editExisting.setSelected(false);
}
}
measurmentPane.setDisable(true);
typePane.setDisable(true);
}
private void saveAndFork() {
new Thread(() -> {
try {
Vitamins.saveDatabaseForkIfMissing(typeOfVitaminString);
sizePane.setDisable(false);
} catch (Exception e) {
// TODO Auto-generated catch block
new IssueReportingExceptionHandler().uncaughtException(Thread.currentThread(), e);
}
}).start();
}
@FXML
void onNewMeasurment(ActionEvent event) {
newMeasurmentButton.setDisable(true);
TextInputDialog dialog = new TextInputDialog("lengthOfThing");
dialog.setTitle("Add new measurment to "+typeOfVitaminString);
dialog.setHeaderText("This measurment will be added to all instances of the vitamin");
dialog.setContentText("New measurment name:");
// Traditional way to get the response value.
Optional<String> result = dialog.showAndWait();
// The Java 8 way to get the response value (with lambda expression).
result.ifPresent(name -> {
TextInputDialog dialog2 = new TextInputDialog("0.0");
dialog2.setTitle("Set value of "+name);
dialog2.setHeaderText("This value will be added to all instances of the vitamin");
dialog2.setContentText(name+" = ");
// Traditional way to get the response value.
Optional<String> result2 = dialog2.showAndWait();
result2.ifPresent(name2 -> {
setupKeyValueToTable(name,name2,sizeOfVitaminString);
for(String size:Vitamins.listVitaminSizes(typeOfVitaminString)) {
Vitamins.getConfiguration(typeOfVitaminString, size).put(name,name2);
}
});
newMeasurmentButton.setDisable(false);
});
}
@FXML
void onSelectExistingTypeMode(ActionEvent event) {
newTypeNameField.setEditable(false);
typeComboBox.setDisable(false);
isShaft.setDisable(true);
isMotor.setDisable(true);
}
@FXML
void onSelectNewTypeMode(ActionEvent event) {
newTypeNameField.setEditable(true);
typeComboBox.setDisable(true);
isShaft.setDisable(false);
isMotor.setDisable(false);
}
@FXML
void onEditExisting(ActionEvent event) {
if(editExisting.isSelected()) {
newSizeField.setEditable(false);
}else {
newSizeField.setEditable(true);
}
}
@FXML
void onIsMotor(ActionEvent event) {
if(isMotor.isSelected())
isShaft.setSelected(false);
}
@FXML
void onIsShaft(ActionEvent event) {
if(isShaft.isSelected())
isMotor.setSelected(false);
}
@FXML // This method is called by the FXMLLoader when initialization is complete
void initialize() {
assert x1 != null : "fx:id=\"x1\" was not injected: check your FXML file 'newVitaminWizard.fxml'.";
assert x2 != null : "fx:id=\"x2\" was not injected: check your FXML file 'newVitaminWizard.fxml'.";
assert existingTypeRadio != null : "fx:id=\"existingTypeRadio\" was not injected: check your FXML file 'newVitaminWizard.fxml'.";
assert newTypeRadio != null : "fx:id=\"newTypeRadio\" was not injected: check your FXML file 'newVitaminWizard.fxml'.";
assert typeComboBox != null : "fx:id=\"typeComboBox\" was not injected: check your FXML file 'newVitaminWizard.fxml'.";
assert sizeComboBox != null : "fx:id=\"sizeComboBox\" was not injected: check your FXML file 'newVitaminWizard.fxml'.";
assert measurmentsTable != null : "fx:id=\"measurmentsTable\" was not injected: check your FXML file 'newVitaminWizard.fxml'.";
sizePane.setDisable(true);
measurmentPane.setDisable(true);
ToggleGroup groupForType= new ToggleGroup();
existingTypeRadio.setSelected(true);
newTypeRadio.setSelected(false);
existingTypeRadio.setToggleGroup(groupForType);
newTypeRadio.setToggleGroup(groupForType);
newTypeNameField.setEditable(false);
ArrayList<String> types = Vitamins.listVitaminTypes();
for(String s:types) {
typeComboBox.getItems().add(s);
}
if(typeOfVitaminString==null)
typeComboBox.getSelectionModel().select(types.get(0));
else
typeComboBox.getSelectionModel().select(typeOfVitaminString);
isShaft.setDisable(true);
isMotor.setDisable(true);
}
public static void launchWizard(INewVitaminCallback callback) throws Exception {
NewVitaminWizardController.callback=callback;
Platform.runLater(() -> {
Stage s = new Stage();
primaryStage = s;
new Thread(() -> {
NewVitaminWizardController controller = new NewVitaminWizardController();
try {
controller.start(s);
} catch (Exception e) {
e.printStackTrace();
}
}).start();
});
}
public static void main(String [] args) throws Exception {
JavaFXInitializer.go();
NewVitaminWizardController.launchWizard(new INewVitaminCallback() {
@Override
public Menu getTypeMenu(String type) {
System.out.println("Get Vitamin Menu");
return new Menu(type);
}
@Override
public void addVitaminType(String s) {
getTypeMenu(s);
ArrayList<String> sizes = Vitamins.listVitaminSizes(s);
for(String size:sizes) {
addSizesToMenu(size,s);
}
System.out.println("Add addVitaminType "+s);
}
@Override
public void addSizesToMenu(String size, String type) {
System.out.println("Add addSizesToMenu "+type+" "+size );
}
});
}
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = AssetFactory.loadLayout("layout/newVitaminWizard.fxml",true);
Parent root;
//loader.setController(this);
// This is needed when loading on MAC
loader.setClassLoader(getClass().getClassLoader());
root = loader.load();
Platform.runLater(() -> {
primaryStage.setTitle("Edit Vitamins Wizard");
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.initModality(Modality.WINDOW_MODAL);
primaryStage.setResizable(true);
primaryStage.show();
});
}
}

View File

@@ -0,0 +1,16 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.neuronrobotics.bowlerstudio;
/**
*
* @author Michael Hoffer &lt;info@michaelhoffer.de&gt;
*/
@FunctionalInterface
public interface OutputFilter {
public boolean onMatch(String s);
}

View File

@@ -0,0 +1,7 @@
package com.neuronrobotics.bowlerstudio;
import com.neuronrobotics.bowlerstudio.tabs.AbstractBowlerStudioTab;
public interface PluginFactory {
AbstractBowlerStudioTab generateNewPlugin() throws ClassNotFoundException, InstantiationException, IllegalAccessException ;
}

View File

@@ -0,0 +1,310 @@
package com.neuronrobotics.bowlerstudio;
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.bowlerstudio.creature.CreatureLab;
import com.neuronrobotics.bowlerstudio.creature.DhLab;
import com.neuronrobotics.bowlerstudio.tabs.*;
import com.neuronrobotics.imageprovider.AbstractImageProvider;
import com.neuronrobotics.nrconsole.plugin.BowlerCam.BowlerCamController;
import com.neuronrobotics.nrconsole.plugin.DeviceConfig.PrinterConiguration;
import com.neuronrobotics.nrconsole.plugin.DyIO.Secheduler.AnamationSequencer;
import com.neuronrobotics.nrconsole.plugin.PID.PIDControl;
import com.neuronrobotics.nrconsole.plugin.bootloader.BootloaderPanel;
import com.neuronrobotics.pidsim.LinearPhysicsEngine;
import com.neuronrobotics.pidsim.PidLab;
import com.neuronrobotics.replicator.driver.NRPrinter;
import com.neuronrobotics.sdk.addons.kinematics.AbstractKinematicsNR;
import com.neuronrobotics.sdk.addons.kinematics.FirmataBowler;
import com.neuronrobotics.sdk.addons.kinematics.MobileBase;
import com.neuronrobotics.sdk.bootloader.NRBootLoader;
import com.neuronrobotics.sdk.bowlercam.device.BowlerCamDevice;
import com.neuronrobotics.sdk.common.BowlerAbstractDevice;
import com.neuronrobotics.sdk.common.Log;
import com.neuronrobotics.sdk.common.RpcEncapsulation;
import com.neuronrobotics.sdk.dyio.DyIO;
import com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace;
import javafx.application.Platform;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.CheckBoxTreeCell;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import java.util.ArrayList;
//import com.neuronrobotics.nrconsole.plugin.DyIO.DyIOConsole;
public class PluginManager {
private BowlerAbstractDevice dev;
private static ArrayList<DeviceSupportPluginMap> deviceSupport = new ArrayList<>();
private ArrayList<AbstractBowlerStudioTab> liveTabs = new ArrayList<>();
// add tabs to the support list based on thier class
// adding additional classes here will show up in the default
// tabs list for objects of that type
static{
//DyIO
addPlugin(new DeviceSupportPluginMap(DyIO.class, DyIOControl.class));
addPlugin(new DeviceSupportPluginMap(DyIO.class, AnamationSequencer.class));
//Ipid
addPlugin(new DeviceSupportPluginMap(IPidControlNamespace.class, PIDControl.class));
// Image s
// addPlugin(new DeviceSupportPluginMap(AbstractImageProvider.class, CameraTab.class));
// addPlugin(new DeviceSupportPluginMap(AbstractImageProvider.class, SalientTab.class));
// Bootloader
addPlugin(new DeviceSupportPluginMap(NRBootLoader.class, BootloaderPanel.class));
//BowlerBoard Specific
//addPlugin(new DeviceSupportPlugginMap(BowlerBoardDevice.class, //none yet));
//AbstractKinematicsNR
//addPlugin(new DeviceSupportPluginMap(AbstractKinematicsNR.class, JogKinematicsDevice.class));
//addPlugin(new DeviceSupportPluginMap(AbstractKinematicsNR.class, AdvancedKinematicsController.class));
//addPlugin(new DeviceSupportPluginMap(AbstractKinematicsNR.class, DhLab.class));
addPlugin(new DeviceSupportPluginMap(MobileBase.class, CreatureLab.class));
//NRPrinter
addPlugin(new DeviceSupportPluginMap(NRPrinter.class, PrinterConiguration.class));
//Bowler Cam
addPlugin(new DeviceSupportPluginMap(BowlerCamDevice.class, BowlerCamController.class));
//LinearPhysicsEngine
addPlugin(new DeviceSupportPluginMap(LinearPhysicsEngine.class, PidLab.class));
//Firmata
addPlugin(new DeviceSupportPluginMap(FirmataBowler.class, FirmataTab.class));
}
public PluginManager(BowlerAbstractDevice dev){
this.dev = dev;
if(!dev.isAvailable())
throw new RuntimeException("Device is not reporting availible "+dev.getClass().getSimpleName());
}
public static void addPlugin(DeviceSupportPluginMap newMap){
for(int i=0;i<deviceSupport.size();i++){
try{
if( deviceSupport.get(i).getDevice() == newMap.getDevice() &&
deviceSupport.get(i).getPlugin() == newMap.getPlugin() ){
System.out.println("Removing duplicate plugin: "+deviceSupport.remove(i));
}
}catch(Exception e){
e.printStackTrace();
}
}
Log.debug("Adding Plugin "+newMap);
deviceSupport.add(newMap);
}
public void setName(String name) {
dev.setScriptingName(name);
}
public String getName(){
return dev.getScriptingName();
}
public BowlerAbstractDevice getDevice() {
return dev;
}
private AbstractBowlerStudioTab generateTab(DeviceSupportPluginMap c) throws ClassNotFoundException, InstantiationException, IllegalAccessException{
for(AbstractBowlerStudioTab t: liveTabs){
if(c.getPlugin().isInstance(t)){
// tab already exists, wake it up and return it
t.onTabReOpening();
return t;
}
}
AbstractBowlerStudioTab t=c.generateNewPlugin();
t.setDevice(dev);
liveTabs.add(t);
return t;
}
public void setTree(TreeItem<String> item) {
}
public BowlerStudioController getBowlerStudioController() {
return BowlerStudioController.getBowlerStudio();
}
public Node getBowlerBrowser(){
CheckBoxTreeItem<String> rpc = new CheckBoxTreeItem<> ("Bowler RPC");
TreeView<String> treeView =new TreeView<>(rpc);
treeView.setCellFactory(CheckBoxTreeCell.forTreeView());
if(dev.getConnection()!=null){
rpc.setExpanded(true);
ArrayList<String> nameSpaceList = dev.getNamespaces();
for(String namespace:nameSpaceList){
CheckBoxTreeItem<String> ns = new CheckBoxTreeItem<> (namespace);
ns.setExpanded(false);
rpc.getChildren().add(ns);
ArrayList<RpcEncapsulation> rpcList = dev.getRpcList(namespace);
CheckBoxTreeItem<String> get = new CheckBoxTreeItem<> ("GET");
CheckBoxTreeItem<String> post = new CheckBoxTreeItem<> ("POST");
CheckBoxTreeItem<String> async = new CheckBoxTreeItem<> ("ASYNC");
CheckBoxTreeItem<String> crit = new CheckBoxTreeItem<> ("CRITICAL");
get.setExpanded(false);
ns.getChildren().add(get);
post.setExpanded(false);
ns.getChildren().add(post);
async.setExpanded(false);
ns.getChildren().add(async);
crit.setExpanded(false);
ns.getChildren().add(crit);
for(RpcEncapsulation rpcEnc:rpcList){
CheckBoxTreeItem<String> rc = new CheckBoxTreeItem<> (rpcEnc.getRpc());
rc.setExpanded(false);
switch(rpcEnc.getDownstreamMethod()){
case ASYNCHRONOUS:
async.getChildren().add(rc);
break;
case CRITICAL:
crit.getChildren().add(rc);
break;
case GET:
get.getChildren().add(rc);
break;
case POST:
post.getChildren().add(rc);
break;
default:
break;
}
RpcCommandPanel panel =new RpcCommandPanel(rpcEnc, dev,rc);
// Platform.runLater(()->{
// SwingNode sn = new SwingNode();
// Stage dialog = new Stage();
// dialog.setHeight(panel.getHeight());
// dialog.setWidth(panel.getWidth());
// dialog.initStyle(StageStyle.UTILITY);
// sn.setContent(panel);
// Scene scene = new Scene(new Group(sn));
// dialog.setScene(scene);
// dialog.setOnCloseRequest(event -> {
// rc.setSelected(false);
// });
// rc.selectedProperty().addListener(b ->{
// if(rc.isSelected()){
// dialog.show();
// }else{
// dialog.hide();
// }
// });
// });
}
}
}
return treeView;
}
public ArrayList<TitledPane> getPlugins() {
ArrayList<TitledPane> plugins = new ArrayList<>();
VBox pluginLauncher = new VBox(20);
for( DeviceSupportPluginMap c:deviceSupport){
if(c.getDevice().isInstance(dev)){
Button launcher = new Button("Launch "+c.getPlugin().getSimpleName(), AssetFactory.loadIcon("Plugin-Icon.png"));
try {// These tabs are the select few to autoload when a device of theis type is connected
if( DyIOControl.class ==c.getPlugin() ||
BootloaderPanel.class ==c.getPlugin()||
CreatureLab.class ==c.getPlugin()
){
if(getBowlerStudioController()!=null){
System.out.println("Auto loading "+c.getPlugin().getSimpleName());
Log.warning("Attempting Autoloading "+c);
//if(CreatureLab.class !=c.getPlugin())
launchTab( c,launcher);
//else
// generateTab(c);// dont add the creature lab it uses the overlays
}
}else{
Log.warning("Not autoloading "+c);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
launcher.setOnAction(b ->{
launchTab( c,launcher);
});
pluginLauncher.getChildren().add(launcher);
}
}
TitledPane info = new TitledPane("Device Info", new Text(dev.getClass().getSimpleName()));
TitledPane protocol = new TitledPane("Bowler Protocol", getBowlerBrowser());
TitledPane pluginsPane = new TitledPane("Plugins", pluginLauncher);
info.setGraphic(AssetFactory.loadIcon("Info.png"));
protocol.setGraphic(AssetFactory.loadIcon("BowlerStudio.png"));
pluginsPane.setGraphic(AssetFactory.loadIcon("Plugins.png"));
plugins.add(info);
if(dev.getConnection()!=null)
plugins.add(protocol);
plugins.add(pluginsPane);
return plugins;
}
private void launchTab(DeviceSupportPluginMap c,Button launcher){
new Thread(){
public void run(){
Thread.currentThread().setUncaughtExceptionHandler(new IssueReportingExceptionHandler());
setName("Launching "+c.getPlugin().getSimpleName());
try {
AbstractBowlerStudioTab t = generateTab(c);
// allow the threads to finish before adding
//ThreadUtil.wait(50);
getBowlerStudioController().addTab(t, true);
t.setOnCloseRequest(new EventHandler<Event>() {
@Override
public void handle(Event arg0) {
System.out.println("PM is Closing "+t.getText());
t.onTabClosing();
Platform.runLater(()->launcher.setDisable(false));
}
});
Platform.runLater(()->{
launcher.setDisable(true);
});
System.out.println("Launching "+c.getPlugin().getSimpleName());
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}.start();
}
}

View File

@@ -0,0 +1,61 @@
package com.neuronrobotics.bowlerstudio;
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.sdk.common.Log;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Accordion;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import java.util.ArrayList;
public class PluginManagerWidget extends TitledPane {
private PluginManager manager;
private TextField deviceName = new TextField();
private Button disconnectTHis;
final Accordion accordion = new Accordion ();
public PluginManagerWidget(PluginManager m, Node graphic){
HBox content = new HBox(20);
content.setPadding(new Insets(0, 20, 10, 20));
this.manager = m;
ArrayList<TitledPane> plugins = manager.getPlugins();
accordion.getPanes().addAll(plugins);
disconnectTHis = new Button("Disconnect "+manager.getName(), AssetFactory.loadIcon("Disconnect-Device.png"));
disconnectTHis.setOnMousePressed( event -> {
new Thread(){
public void run(){
Thread.currentThread().setUncaughtExceptionHandler(new IssueReportingExceptionHandler());
setName("disconnect plugins");
Log.warning("Disconnect button for "+manager.getName()+" pressed");
getManager().getDevice().disconnect();
}
}.start();
});
setGraphic(AssetFactory.loadIcon("Bowler-Device-In-Manager.png"));
deviceName.setOnAction(event -> {
getManager().setName(deviceName.getText());
setText(manager.getName());
disconnectTHis.setText("Disconnect "+manager.getName());
});
Platform.runLater(()->deviceName.setText(manager.getName()));
content.setHgrow(accordion, Priority.ALWAYS);
content.getChildren().addAll(graphic,disconnectTHis,deviceName,accordion);
setContent(content);
setText(manager.getName());
}
public PluginManager getManager() {
return manager;
}
}

View File

@@ -0,0 +1,176 @@
package com.neuronrobotics.bowlerstudio;
import java.awt.AlphaComposite;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsDevice;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javafx.scene.image.Image;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import com.neuronrobotics.bowlerstudio.assets.StudioBuildInfo;
public class PsudoSplash {
JFrame interfaceFrame;
private String message = "";
class CustomPanel extends JPanel {
/**
*
*/
private static final long serialVersionUID = 8749662598444052868L;
private BufferedImage image;
public CustomPanel() {
setOpaque(false);
try {
/*
* Since Images are Application Resources, it's always best to access them in
* the form of a URL, instead of File, as you are doing. Uncomment this below
* line and watch this answer of mine, as to HOW TO ADD IMAGES TO THE PROJECT
* https://stackoverflow.com/a/9866659/1057230 In order to access images with
* getClass().getResource(path) here your Directory structure has to be like
* this Project | ------------------------ | | bin src | | --------- .java files
* | | package image(folder) ( or | .class 404error.jpg files, if no package
* exists.)
*/
image = ImageIO.read(getClass().getResource("splash.png"));
} catch (IOException ioe) {
System.out.println("Unable to fetch image.");
ioe.printStackTrace();
}
}
/*
* Make this one customary habbit, of overriding this method, when you extends a
* JPanel/JComponent, to define it's Preferred Size. Now in this case we want it
* to be as big as the Image itself.
*/
@Override
public Dimension getPreferredSize() {
return (new Dimension(image.getWidth(), image.getHeight()));
}
/*
* This is where the actual Painting Code for the JPanel/JComponent goes. Here
* we will draw the image. Here the first line super.paintComponent(...), means
* we want the JPanel to be drawn the usual Java way first, then later on we
* will add our image to it, by writing the other line, g.drawImage(...).
*/
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, this);
Graphics2D splashGraphics = (Graphics2D) g;
splashGraphics.setComposite(AlphaComposite.Clear);
// splashGraphics.fillRect(65, 270, 200, 40);
splashGraphics.setPaintMode();
splashGraphics.setColor(Color.WHITE);
splashGraphics.drawString(StudioBuildInfo.getVersion(), 65, 45);
splashGraphics.setComposite(AlphaComposite.Clear);
// splashGraphics.fillRect(65, 270, 200, 40);
splashGraphics.setPaintMode();
splashGraphics.setColor(Color.WHITE);
splashGraphics.drawString(getMessage(), 65, 280);
}
}
public PsudoSplash() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex) {
} catch (InstantiationException ex) {
} catch (IllegalAccessException ex) {
} catch (UnsupportedLookAndFeelException ex) {
}
interfaceFrame = new JFrame("Loading BowlerStudio...");
interfaceFrame.setUndecorated(true);
interfaceFrame.setLayout(new BorderLayout());
CustomPanel contentPane = new CustomPanel();
// interfaceFrame.setBackground(Color.black);
interfaceFrame.setContentPane(contentPane);
interfaceFrame.pack();
interfaceFrame.setLocationRelativeTo(null);
interfaceFrame.setVisible(true);
interfaceFrame.setBackground(new Color(0, 0, 0, 0));
try {
interfaceFrame.setIconImage( ImageIO.read(getClass().getResource("splash.png")));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
while (interfaceFrame == null)
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// public void setIcon(Image img) {
// BufferedImage image = javafx.embed.swing.SwingFXUtils.fromFXImage(img, null);
// if (interfaceFrame != null)
// interfaceFrame.setIconImage(image);
// }
boolean isVisableSplash() {
if (interfaceFrame != null)
return interfaceFrame.isVisible();
return false;
}
void closeSplashLocal() {
if (interfaceFrame != null)
interfaceFrame.setVisible(false);
}
void updateSplash() {
if (interfaceFrame != null) {
interfaceFrame.invalidate();
interfaceFrame.repaint();
}
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
if (message.length() > 23) {
this.message = message.subSequence(0, 23).toString();
//new RuntimeException().printStackTrace();
} else
this.message = message;
if (interfaceFrame != null) {
interfaceFrame.setVisible(true);
}
}
}

View File

@@ -0,0 +1,191 @@
/*
* RedirectableStream.java
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 20092012 Steinbeis Forschungszentrum (STZ Ölbronn),
* Copyright (c) 20062012 by Michael Hoffer
*
* This file is part of Visual Reflection Library (VRL).
*
* VRL is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* as published by the Free Software Foundation.
*
* see: http://opensource.org/licenses/LGPL-3.0
* file://path/to/VRL/src/eu/mihosoft/vrl/resources/license/lgplv3.txt
*
* VRL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* This version of VRL includes copyright notice and attribution requirements.
* According to the LGPL this information must be displayed even if you modify
* the source code of VRL. Neither the VRL Canvas attribution icon nor any
* copyright statement/attribution may be removed.
*
* Attribution Requirements:
*
* If you create derived work you must do three things regarding copyright
* notice and author attribution.
*
* First, the following text must be displayed on the Canvas:
* "based on VRL source code". In this case the VRL canvas icon must be removed.
*
* Second, the copyright notice must remain. It must be reproduced in any
* program that uses VRL.
*
* Third, add an additional notice, stating that you modified VRL. In addition
* you must cite the publications listed below. A suitable notice might read
* "VRL source code modified by YourName 2012".
*
* Note, that these requirements are in full accordance with the LGPL v3
* (see 7. Additional Terms, b).
*
* Publications:
*
* M. Hoffer, C.Poliwoda, G.Wittum. Visual Reflection Library -
* A Framework for Declarative GUI Programming on the Java Platform.
* Computing and Visualization in Science, 2011, in press.
*/
package com.neuronrobotics.bowlerstudio;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.scene.control.TextArea;
/**
*
* @author Michael Hoffer info@michaelhoffer.de
*/
public class RedirectableStream extends PrintStream {
public static PrintStream ORIGINAL_SOUT = System.out;
public static PrintStream ORIGINAL_SERR = System.err;
private final List<TextArea> views = new ArrayList<>();
private boolean redirectToUi;
private boolean redirectToStdOut;
private final List<OutputFilter> filters = new ArrayList<>();
public RedirectableStream(OutputStream out, TextArea... views) {
super(out);
this.views.clear();
for (TextArea textArea : views) {
addView(textArea);
}
setRedirectToStdOut(true);
}
@Override
public synchronized void write(byte[] buf, int off, int len) {
if (isRedirectToUi()) {
invokeAndWait(() -> {
int i = 0;
for (TextArea view : views) {
String s = new String(buf, off, len);
if (filters.get(i).onMatch(s)) {
try {
int startOffSet = view.getText().length();
view.insertText(startOffSet, s);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
i++;
}
});
// view.setCaretPosition(startOffSet + len);
// }
// catch (BadLocationException e) {
// e.printStackTrace();
// Platform.invokeLater(new Runnable() {
//
// @Override
// public void run() {
// // automatically scroll down to the last line
//// view.scrollRectToVisible(
//// new Rectangle(0, view.getHeight() - 1, 1, 1));
//
// }
// });
}
if (isRedirectToStdOut()) {
super.write(buf, off, len);
}
}
public final void addView(TextArea view) {
views.add(view);
filters.add((OutputFilter) (String s) -> {
return true;
});
}
public void setFilter(TextArea view, OutputFilter filter) {
int i = views.indexOf(view);
filters.set(i, filter);
}
/**
* @return the redirectToUi
*/
public boolean isRedirectToUi() {
return redirectToUi;
}
/**
* @param redirectToUi the redirectToUi to set
*/
public void setRedirectToUi(boolean redirectToUi) {
this.redirectToUi = redirectToUi;
}
/**
* @return the redirectToStdOut
*/
public boolean isRedirectToStdOut() {
return redirectToStdOut;
}
/**
* @param redirectToStdOut the redirectToStdOut to set
*/
public final void setRedirectToStdOut(boolean redirectToStdOut) {
this.redirectToStdOut = redirectToStdOut;
}
private static void invokeAndWait(Runnable r) {
if (Platform.isFxApplicationThread()) {
r.run();
} else {
FutureTask<Boolean> task = new FutureTask<>(r, true);
Platform.runLater(task);
try {
task.get(); // like join()
} catch (InterruptedException | ExecutionException ex) {
Logger.getLogger(RedirectableStream.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}

View File

@@ -0,0 +1,149 @@
package com.neuronrobotics.bowlerstudio;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javafx.scene.control.CheckBoxTreeItem;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.tree.DefaultMutableTreeNode;
import net.miginfocom.swing.MigLayout;
import com.neuronrobotics.sdk.common.BowlerAbstractDevice;
import com.neuronrobotics.sdk.common.BowlerDataType;
import com.neuronrobotics.sdk.common.BowlerDatagram;
import com.neuronrobotics.sdk.common.RpcEncapsulation;
import com.neuronrobotics.sdk.genericdevice.GenericDevice;
public class RpcCommandPanel extends JPanel implements ActionListener {
/**
*
*/
private static final long serialVersionUID = -9199252749669892888L;
private BowlerAbstractDevice device;
private RpcEncapsulation rpc;
private CheckBoxTreeItem<?> rpcDhild;
private boolean commandsEnabled=false;
private ArrayList<JTextField> tx = new ArrayList<>();
private ArrayList<JLabel> rx = new ArrayList<>();
private JButton send = new JButton("Send");
private JLabel txRpc = new JLabel("****");
private JLabel rxRpc = new JLabel("****");
public RpcCommandPanel(RpcEncapsulation rpc,BowlerAbstractDevice device, CheckBoxTreeItem<?> rpcDhild){
this.setRpcDhild(rpcDhild);
this.setRpc(rpc);
this.setDevice(device);
setLayout(new MigLayout());
add(new JLabel("Namespace"), "cell 0 0,alignx leading");
add(new JLabel(rpc.getNamespace().split(";")[0]), "cell 1 0,alignx leading");
add(new JLabel("Method"), "cell 0 1,alignx leading");
add(new JLabel(rpc.getDownstreamMethod().toString()), "cell 1 1,alignx leading");
add(new JLabel("RPC"), "cell 0 2,alignx leading");
add(new JLabel(rpc.getRpc()), "cell 1 2,alignx leading");
add(new JLabel("Tx>>"), "cell 0 3,alignx leading");
txRpc.setText(rpc.getRpc());
add(txRpc, "cell 0 3,alignx leading");
add(new JLabel("Rx<<"), "cell 0 4,alignx leading");
add(rxRpc, "cell 0 4,alignx leading");
add(send,"cell 2 3,alignx leading");
JPanel txPanel = new JPanel(new MigLayout());
JPanel rxPanel = new JPanel(new MigLayout());
int i=0;
for (BowlerDataType s:rpc.getDownstreamArguments()){
JTextField tmp= new JTextField(5);
tmp.setText("0");
txPanel.add(new JLabel(s.toString()), "cell "+i+" 0,alignx leading");
tx.add(tmp);
i++;
}
i=0;
for (BowlerDataType s:rpc.getUpstreamArguments()){
JLabel tmp= new JLabel();
tmp.setText("0");
rxPanel.add(new JLabel(s.toString()), "cell "+i+" 0,alignx leading");
rx.add(tmp);
i++;
}
i=0;
for(JTextField t:tx){
txPanel.add(t, "cell "+i+" 1,alignx leading");
i++;
}
i=0;
for(JLabel t:rx){
rxPanel.add(t, "cell "+i+" 1,alignx leading");
i++;
}
add(txPanel, "cell 1 3,alignx leading");
add(rxPanel, "cell 1 4,alignx leading");
send.addActionListener(this);
}
public RpcEncapsulation getRpc() {
return rpc;
}
private void setRpc(RpcEncapsulation rpc) {
this.rpc = rpc;
}
public BowlerAbstractDevice getDevice() {
return device;
}
private void setDevice(BowlerAbstractDevice device) {
this.device = device;
}
public CheckBoxTreeItem<?> getRpcDhild() {
return rpcDhild;
}
public void setRpcDhild(CheckBoxTreeItem<?> rpcDhild) {
this.rpcDhild = rpcDhild;
}
public void enableCommands() {
if(commandsEnabled)
return;
commandsEnabled = true;
}
@Override
public void actionPerformed(ActionEvent arg0) {
Object[] values = new Object[tx.size()];
for (int i=0;i<values.length;i++){
if(rpc.getDownstreamArguments()[i] == BowlerDataType.ASCII)
values[i] = tx.get(i).getText();
else
values[i] = Integer.parseInt(tx.get(i).getText());
}
BowlerDatagram bd =device.send(rpc.getCommand(values));
rxRpc.setText(bd.getRPC());
Object [] up = rpc.parseResponse(bd);
for(int i=0;i<up.length;i++){
if(up[i]!=null)
rx.get(i).setText(up[i].toString());
else{
rx.get(i).setText("Null");
}
}
}
}

View File

@@ -0,0 +1,90 @@
package com.neuronrobotics.bowlerstudio;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import com.neuronrobotics.bowlerstudio.assets.StudioBuildInfo;
import javafx.scene.image.Image;
public class SplashManager {
private static Graphics2D splashGraphics;
private static boolean loadFirst = true;
private static PsudoSplash psudo = null;
public static void closeSplash() {
if(isVisableSplash())
closeSplashLocal();
}
private static void closeSplashLocal() {
if (BowlerStudio.splash != null) {
BowlerStudio.splash.close();
splashGraphics = null;
return;
}
psudo.closeSplashLocal();
}
private static boolean isVisableSplash() {
if (BowlerStudio.splash != null)
return BowlerStudio.splash.isVisible();
return psudo.isVisableSplash();
}
private static void updateSplash() {
if (BowlerStudio.splash != null) {
BowlerStudio.splash.update();
return;
}
psudo.updateSplash();
}
public static void renderSplashFrame(int frame, String message) {
if (loadFirst) {
loadFirst = false;
initialize();
}
String string = frame + "% " + message;
System.err.println(" Splash Rendering " + frame + " " + message);
if (psudo != null) {
psudo.setMessage(string);
updateSplash();
}else if (splashGraphics != null && isVisableSplash()) {
splashGraphics.setComposite(AlphaComposite.Clear);
splashGraphics.fillRect(65, 270, 200, 40);
splashGraphics.setPaintMode();
splashGraphics.setColor(Color.WHITE);
splashGraphics.drawString(string, 65, 280);
// Platform.runLater(() -> {
updateSplash();
// });
}
}
private static void initialize() {
if (BowlerStudio.splash != null) {
try {
splashGraphics = BowlerStudio.splash.createGraphics();
} catch (IllegalStateException e) {
}
} else {
System.err.println("No splash screen availible!");
psudo = new PsudoSplash();
}
if (psudo == null)
if (splashGraphics != null && isVisableSplash()) {
splashGraphics.setComposite(AlphaComposite.Clear);
splashGraphics.fillRect(65, 270, 200, 40);
splashGraphics.setPaintMode();
splashGraphics.setColor(Color.WHITE);
splashGraphics.drawString(StudioBuildInfo.getVersion(), 65, 45);
updateSplash();
}
}
}

View File

@@ -0,0 +1,268 @@
package com.neuronrobotics.bowlerstudio;
/**
* Sample Skeleton for "Terminal.fxml" Controller Class
* You can copy and paste this code into your favorite IDE
**/
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
//import com.neuronrobotics.imageprovider.OpenCVImageProvider;
import com.neuronrobotics.sdk.common.Log;
import com.neuronrobotics.sdk.util.ThreadUtil;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
public class Terminal {
@FXML // ResourceBundle that was given to the FXMLLoader
private ResourceBundle resources;
@FXML // URL location of the FXML file that was given to the FXMLLoader
private URL location;
@FXML // fx:id="executionBox"
private TextField executionBox; // Value injected by FXMLLoader
@FXML // fx:id="langaugeIcon"
private ImageView langaugeIcon; // Value injected by FXMLLoader
@FXML // fx:id="langauges"
private ComboBox<String> langauges; // Value injected by FXMLLoader
@FXML // fx:id="outputBox"
private TextArea outputBox; // Value injected by FXMLLoader
private ArrayList<String> history = new ArrayList<>();
private int historyIndex = 0;
private boolean running = false;
private Thread scriptRunner = null;
@SuppressWarnings("restriction")
@FXML // This method is called by the FXMLLoader when initialization is
// complete
void initialize() {
assert executionBox != null : "fx:id=\"executionBox\" was not injected: check your FXML file 'Terminal.fxml'.";
assert langaugeIcon != null : "fx:id=\"langaugeIcon\" was not injected: check your FXML file 'Terminal.fxml'.";
assert langauges != null : "fx:id=\"langauges\" was not injected: check your FXML file 'Terminal.fxml'.";
assert outputBox != null : "fx:id=\"outputBox\" was not injected: check your FXML file 'Terminal.fxml'.";
BowlerStudio.setLogViewRefStatic(outputBox);
// Initialize your logic here: all @FXML variables will have been
// injected
langauges.getItems().clear();
executionBox.setOnAction(event -> {
new Thread() {
public void run() {
Thread.currentThread().setUncaughtExceptionHandler(new IssueReportingExceptionHandler());
startStopAction();
}
}.start();
});
executionBox.setPrefWidth(80 * 4);
executionBox.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
// Platform.runLater(() -> {
if ((event.getCode() == KeyCode.UP || event.getCode() == KeyCode.DOWN)) {
System.err.println("Key pressed " + event.getCode() + " history index = " + historyIndex
+ " history size= " + history.size());
if (historyIndex == 0) {
String text = executionBox.getText();
if (text.length() > 0) {
// store what was in the box into he history
history.add(text);
}
}
if (event.getCode() == KeyCode.UP)
historyIndex++;
else
historyIndex--;
if (!history.isEmpty()) {
if (historyIndex > history.size()) {
historyIndex = history.size();
}
if (historyIndex < 0)
historyIndex = 0;
// History index established
if (historyIndex > 0)
Platform.runLater(() -> {
executionBox.setText(history.get(history.size() - historyIndex));
});
else
Platform.runLater(() -> {
executionBox.setText("");
});
}
event.consume();
}
// });
});
try {
history = BowlerKernel.loadHistory();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
BowlerKernel.writeHistory(history);
}
});
List<String> langs = ScriptingEngine.getAllLangauges();
ObservableList<String> options = FXCollections.observableArrayList(langs);
//
for(String s:options){
langauges.getItems().add(s);
}
langauges.getSelectionModel().select("Groovy");
Image icon;
try {
icon = AssetFactory.loadAsset("Script-Tab-" + langauges.getSelectionModel().getSelectedItem() + ".png");
langaugeIcon.setImage(icon);
} catch (Exception e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
langauges.setOnAction(event -> {
try {
langaugeIcon.setImage(AssetFactory
.loadAsset("Script-Tab-" + langauges.getSelectionModel().getSelectedItem() + ".png"));
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
});
}
private void reset() {
running = false;
}
private void start(String code) {
running = true;
scriptRunner = new Thread() {
@SuppressWarnings("restriction")
public void run() {
try {
ScriptingEngine.inlineScriptStringRun(code, null,
langauges.getSelectionModel().getSelectedItem());
reset();
} catch (groovy.lang.MissingPropertyException | org.python.core.PyException d) {
Platform.runLater(() -> {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Device missing error");
String message = "This script needs a device connected: ";
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
d.printStackTrace(pw);
BowlerStudioController.highlightException(null, d);
String stackTrace = sw.toString();
if (stackTrace.contains("dyio"))
message += "dyio";
else if (stackTrace.contains("camera"))
message += "camera";
else if (stackTrace.contains("gamepad"))
message += "gamepad";
else
message += stackTrace;
alert.setHeaderText(message);
alert.setContentText("You need to connect it before running again");
alert.showAndWait();
if (stackTrace.contains("dyio"))
ConnectionManager.addConnection();
// else if (stackTrace.contains("camera"))
// ConnectionManager.addConnection(new OpenCVImageProvider(0), "camera0");
else if (stackTrace.contains("gamepad"))
ConnectionManager.onConnectGamePad("gamepad");
reset();
});
} catch (Exception ex) {
System.err.println("Script exception of type= " + ex.getClass().getName());
Platform.runLater(() -> {
reset();
});
BowlerStudioController.highlightException(null, ex);
}
}
};
scriptRunner.start();
}
private void startStopAction() {
String text = executionBox.getText();
text += "\r\n";
Platform.runLater(() -> {
executionBox.setText("");
});
System.out.println(text);
history.add(text);
BowlerKernel.writeHistory(history);
if (historyIndex != 0)
historyIndex--;
else
historyIndex = 0;
if (running)
stop();
else
start(text);
}
public void stop() {
// TODO Auto-generated method stub
reset();
if (scriptRunner != null)
while (scriptRunner.isAlive()) {
Log.debug("Interrupting");
ThreadUtil.wait(10);
try {
scriptRunner.interrupt();
scriptRunner.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

View File

@@ -0,0 +1,92 @@
package com.neuronrobotics.bowlerstudio;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import com.neuronrobotics.sdk.common.BowlerAbstractDevice;
import com.neuronrobotics.sdk.common.BowlerDataType;
import com.neuronrobotics.sdk.common.BowlerDatagram;
import com.neuronrobotics.sdk.common.BowlerMethod;
import com.neuronrobotics.sdk.common.DeviceManager;
import com.neuronrobotics.sdk.common.Log;
import com.neuronrobotics.sdk.common.MACAddress;
import com.neuronrobotics.sdk.common.RpcEncapsulation;
import com.neuronrobotics.sdk.common.device.server.BowlerAbstractDeviceServerNamespace;
import com.neuronrobotics.sdk.common.device.server.BowlerAbstractServer;
import com.neuronrobotics.sdk.common.device.server.IBowlerCommandProcessor;
import com.neuronrobotics.sdk.network.BowlerTCPClient;
import com.neuronrobotics.sdk.network.UDPBowlerConnection;
public class TestServer {
private TestServer() {
}
public static void main(String[] args) throws Exception {
class SampleBowlerServer extends BowlerAbstractServer {
BowlerAbstractDeviceServerNamespace ns = new BowlerAbstractDeviceServerNamespace(
getMacAddress(), "test.thingy.*;0.3;;") {
};
public SampleBowlerServer() {
super(new MACAddress());
ns.addRpc(new RpcEncapsulation(ns.getNamespaceIndex(), ns
.getNamespace(), "test", BowlerMethod.GET,
new BowlerDataType[] { BowlerDataType.I32,
BowlerDataType.I32, BowlerDataType.I32 },// send 3
// integers
BowlerMethod.POST, new BowlerDataType[] {
BowlerDataType.I32, BowlerDataType.I32,
BowlerDataType.I32 }, // get 3 integers back
new IBowlerCommandProcessor() {
public Object[] process(Object[] data) {
for (int i = 0; i < data.length; i++) {
System.out.println("Server Got # " + data[i]);
}
return new Object[] { 37,42, 999999};
}
}));
addBowlerDeviceServerNamespace(ns);
Log.info("Starting UDP");
try {
startNetworkServer(1865);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}// starts the UDP server
// this also starts tcp server on port+1, in this case 1866
}
}
class SampleBowlerClient extends BowlerAbstractDevice {
public void runCommand() {
Object[] args = send("test.thingy.*;0.3;;", BowlerMethod.GET, "test",
new Object[] { 36, 83, 13 });// send some numbers
for (int i = 0; i < args.length; i++) {
System.out.println("Client Received # " + args[i]);
}
}
@Override
public void onAsyncResponse(BowlerDatagram data) {
}// no async in this demo
}
SampleBowlerClient client = new SampleBowlerClient();
//client.setConnection(new UDPBowlerConnection(InetAddress.getByName("127.0.0.1"), 1865));
// Alternately you can use the tcp connection
client.setConnection( new BowlerTCPClient("127.0.0.1",1866));
DeviceManager.addConnection(client, "sampleClient");
client.runCommand();// runs our test command from client to server and
// back
}
}

View File

@@ -0,0 +1,94 @@
package com.neuronrobotics.bowlerstudio;
import java.io.File;
import java.io.IOException;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.TransportException;
import com.neuronrobotics.bowlerstudio.assets.ConfigurationDatabase;
import com.neuronrobotics.bowlerstudio.assets.StudioBuildInfo;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import com.neuronrobotics.sdk.util.ThreadUtil;
public class Tutorial {
private static int WEBSERVER_PORT = 37037;
private static String HOME_Local_URL_ROOT = null;
private static String HOME_URL =null;
private static String HOME_Local_URL = null;
private static boolean doneLoadingTutorials;
private static Boolean startedLoadingTutorials = false;
public static String getHomeUrl() throws Exception{
File i=null;
do{
i= ScriptingEngine.fileFromGit(
(String)ConfigurationDatabase.getObject("BowlerStudioConfigs", "tutorialSource",
"https://github.com/CommonWealthRobotics/CommonWealthRobotics.github.io.git"),
(String)ConfigurationDatabase.getObject("BowlerStudioConfigs", "tutorialBranch",
"master"), // the default branch is source, so this needs to
// be specified
"index.html");
}while(!i.exists());
HOME_Local_URL_ROOT=(String)ConfigurationDatabase.getObject("BowlerStudioConfigs", "tutorialBaseUrl",
"/BowlerStudio/Welcome-To-BowlerStudio/");
File indexOfTutorial=i;
if(!doneLoadingTutorials ){
if(!startedLoadingTutorials){
//synchronized(startedLoadingTutorials){
startedLoadingTutorials = true;
//}
new Thread(){
public void run(){
Thread.currentThread().setUncaughtExceptionHandler(new IssueReportingExceptionHandler());
//HOME_Local_URL = indexOfTutorial.toURI().toString().replace("file:/", "file:///");
Server server = new Server(WEBSERVER_PORT);
ServerConnector connector = new ServerConnector(server);
server.setConnectors(new Connector[] { connector });
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(true);
resource_handler.setWelcomeFiles(new String[] { "index.html" });
System.out.println("Serving "+ indexOfTutorial.getParent());
resource_handler.setResourceBase(indexOfTutorial.getParent());
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
server.setHandler(handlers);
try {
server.start();
WEBSERVER_PORT= connector.getLocalPort();
HOME_Local_URL = "http://localhost:"+WEBSERVER_PORT+HOME_Local_URL_ROOT;
doneLoadingTutorials = true;
server.join();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}.start();
}
long start = System.currentTimeMillis();
// wait up to 30 seconds for menue to load, then fail over to the web version
while(! doneLoadingTutorials && (System.currentTimeMillis()-start<3000)){
ThreadUtil.wait(100);
}
if(doneLoadingTutorials )
HOME_URL = HOME_Local_URL;
else
HOME_URL= "http://CommonWealthRobotics.com"+HOME_Local_URL_ROOT;
}
return HOME_URL;
}
}

View File

@@ -0,0 +1,187 @@
package com.neuronrobotics.bowlerstudio.assets;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.TransportException;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import com.neuronrobotics.bowlerstudio.BowlerStudio;
import com.neuronrobotics.bowlerstudio.scripting.GithubLoginFX;
import com.neuronrobotics.bowlerstudio.tabs.DyIOPanel;
import com.neuronrobotics.bowlerstudio.tabs.DyIOchannelWidget;
//import com.neuronrobotics.nrconsole.plugin.DyIO.DyIOConsole;
import com.neuronrobotics.sdk.dyio.DyIOChannelMode;
import javafx.fxml.FXMLLoader;
import javafx.scene.image.Image;
public class BowlerStudioResourceFactory {
private static final Map<DyIOChannelMode, Image> lookup = new HashMap<>();
private static Image chanHighlight;
private static Image chanUpdate;
private static Image chanDefault;
private static final ArrayList<FXMLLoader> fxmlLoaders = new ArrayList<>();
private static FXMLLoader mainPanel;
private static FXMLLoader githubLogin;
private static FXMLLoader mainControllerPanel;
private static boolean loaded=false;
private BowlerStudioResourceFactory() {
}
public static FXMLLoader getLoader(int channelIndex) {
return fxmlLoaders.get(channelIndex);
}
@SuppressWarnings("restriction")
public static void load() throws Exception {
if(loaded)
return;
loaded=true;
try {
BowlerStudio.renderSplashFrame( 94,"Loading DyIO");
mainPanel = AssetFactory.loadLayout("layout/DyIOPanel.fxml");
//mainPanel.setController(new DyIOPanel());
mainPanel.setClassLoader(DyIOPanel.class.getClassLoader());
BowlerStudio.renderSplashFrame( 95,"Loading GitHub");
githubLogin = AssetFactory.loadLayout("layout/githublogin.fxml");
//githubLogin.setController(new GithubLoginFX());
githubLogin.setClassLoader(GithubLoginFX.class.getClassLoader());
} catch (InvalidRemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (TransportException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (GitAPIException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
for (DyIOChannelMode cm : EnumSet.allOf(DyIOChannelMode.class)) {
Image image;
//
try {
image = AssetFactory.loadAsset("dyio/icon-" + cm.toSlug() + ".png");
} catch (NullPointerException e) {
image = AssetFactory.loadAsset("dyio/icon-off.png");
}
lookup.put(cm, image);
}
setChanHighlight(AssetFactory.loadAsset("dyio/channel-highlight.png"));
setChanDefault(AssetFactory.loadAsset("dyio/channel-default.png"));
setChanUpdate(AssetFactory.loadAsset("dyio/channel-update.png"));
for (int i = 0; i < 24; i++) {
// generate the control widgets
FXMLLoader fxmlLoader;
try {
fxmlLoader = AssetFactory.loadLayout("layout/DyIOChannelContorol.fxml", true);
//fxmlLoader.setController(new DyIOchannelWidget());
fxmlLoader.setClassLoader(DyIOchannelWidget.class.getClassLoader());
try {
fxmlLoader.load();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
fxmlLoaders.add(fxmlLoader);
} catch (InvalidRemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransportException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GitAPIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
mainPanel.load();
} catch (IOException ex) {
Logger.getLogger(BowlerStudio.class.getName()).log(Level.SEVERE, null, ex);
}
try {
githubLogin.load();
} catch (IOException e) {
Logger.getLogger(BowlerStudio.class.getName()).log(Level.SEVERE, null, e);
}
}// stub to force a load from the static in a specific thread
public static Image getModeImage(DyIOChannelMode mode) {
return lookup.get(mode);
}
public static Image getChanHighlight() {
return chanHighlight;
}
public static void setChanHighlight(Image chanHighlight) {
BowlerStudioResourceFactory.chanHighlight = chanHighlight;
}
public static Image getChanUpdate() {
return chanUpdate;
}
public static void setChanUpdate(Image chanUpdate) {
BowlerStudioResourceFactory.chanUpdate = chanUpdate;
}
public static Image getChanDefault() {
return chanDefault;
}
public static void setChanDefault(Image chanDefault) {
BowlerStudioResourceFactory.chanDefault = chanDefault;
}
public static FXMLLoader getMainPanel() {
return mainPanel;
}
public static void setMainPanel(FXMLLoader mainPanel) {
BowlerStudioResourceFactory.mainPanel = mainPanel;
}
public static FXMLLoader getGithubLogin() {
return githubLogin;
}
public static void setGithubLogin(FXMLLoader githubLogin) {
BowlerStudioResourceFactory.githubLogin = githubLogin;
}
public static FXMLLoader getMainControllerPanel() {
return mainControllerPanel;
}
public static void setMainControllerPanel(FXMLLoader mainControllerPanel) {
BowlerStudioResourceFactory.mainControllerPanel = mainControllerPanel;
}
}

View File

@@ -0,0 +1,45 @@
package com.neuronrobotics.bowlerstudio.creature;
import java.util.ArrayList;
public abstract class AbstractGameController {
private ArrayList<IGameControllerUpdateListener> listeners = new ArrayList<>();
public void addIGameControllerUpdateListener(IGameControllerUpdateListener l){
if(!listeners.contains(l))
listeners.add(l);
}
public void removeIGameControllerUpdateListener(IGameControllerUpdateListener l){
if(listeners.contains(l))
listeners.remove(l);
}
public void clearIGameControllerUpdateListener(){
listeners.clear();
}
protected void fireGameControllerUpdate(){
}
public abstract double getControls0Plus();
public abstract double getControls0Minus();
public abstract double getControls1Plus();
public abstract double getControls1Minus();
public abstract double getControls2Plus();
public abstract double getControls2Minus();
public abstract double getControls3Plus();
public abstract double getControls3Minus();
public abstract double getNavUp();
public abstract double getNavDown();
public abstract double getNavLeft();
public abstract double getNavRight();
public abstract double getActionLeft();
public abstract double getActionRight();
}

View File

@@ -0,0 +1,78 @@
package com.neuronrobotics.bowlerstudio.creature;
import com.neuronrobotics.sdk.addons.kinematics.MobileBase;
import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR;
import javafx.scene.Group;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
public class AdjustbodyMassWidget extends Group {
private MobileBase device;
private MobileBaseCadManager manager;
double textToNum(TextField mass) {
try {
return Double.parseDouble(mass.getText().trim());
}catch(Throwable t) {
mass.setText("0");
return 0;
}
}
public AdjustbodyMassWidget(MobileBase device) {
this.device = device;
manager = MobileBaseCadManager.get(device);
GridPane pane = new GridPane();
TextField mass = new TextField(CreatureLab.getFormatted(device.getMassKg()));
mass.setOnAction(event -> {
device.setMassKg(textToNum(mass));
if(manager!=null)manager.generateCad();
});
TransformNR currentCentroid = device.getCenterOfMassFromCentroid();
TextField massx = new TextField(CreatureLab.getFormatted(currentCentroid.getX()));
massx.setOnAction(event -> {
currentCentroid.setX(textToNum(massx));
device.setCenterOfMassFromCentroid(currentCentroid);
;
if(manager!=null)manager.generateCad();
});
TextField massy = new TextField(CreatureLab.getFormatted(currentCentroid.getY()));
massy.setOnAction(event -> {
currentCentroid.setY(textToNum(massy));
device.setCenterOfMassFromCentroid(currentCentroid);
;
if(manager!=null)manager.generateCad();
});
TextField massz = new TextField(CreatureLab.getFormatted(currentCentroid.getZ()));
massz.setOnAction(event -> {
currentCentroid.setZ(textToNum(massz));
device.setCenterOfMassFromCentroid(currentCentroid);
;
if(manager!=null)manager.generateCad();
});
pane.add(new Text("Mass"), 0, 0);
pane.add(mass, 1, 0);
pane.add(new Text("Mass Centroid x"), 0, 1);
pane.add(massx, 1, 1);
pane.add(new Text("Mass Centroid y"), 0, 2);
pane.add(massy, 1, 2);
pane.add(new Text("Mass Centroid z"), 0, 3);
pane.add(massz, 1,3);
getChildren().add(pane);
}
}

View File

@@ -0,0 +1,203 @@
package com.neuronrobotics.bowlerstudio.creature;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.neuronrobotics.replicator.driver.BowlerBoardDevice;
import com.neuronrobotics.replicator.driver.NRPrinter;
public class CartesianPanel extends JPanel{
/**
*
*/
private static final long serialVersionUID = 1L;
private BowlerBoardDevice delt;
private NRPrinter printer;
private JLabel jLabel0;
private JLabel jLabel1;
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel jLabel4;
private JTextField jTextField0;
private JTextField jTextField1;
private JTextField jTextField2;
private JTextField jTextField3;
private JTextField jTextField4;
private JButton jButton0;
public void setDevices(BowlerBoardDevice delt, NRPrinter printer) {
this.delt = delt;
this.printer = printer;
}
private void initComponents() {
setLayout(new GridLayout(6, 4));
add(getJLabel0());
add(getJTextField0());
add(getJLabel1());
add(getJTextField1());
add(getJLabel2());
add(getJTextField2());
add(getJLabel3());
add(getJTextField3());
add(getJLabel4());
add(getJTextField4());
add(getJButton0());
setSize(358, 291);
}
private JButton getJButton0() {
if (jButton0 == null) {
jButton0 = new JButton();
jButton0.setText("Update Robot");
}
return jButton0;
}
private JTextField getJTextField4() {
if (jTextField4 == null) {
jTextField4 = new JTextField();
jTextField4.setText("tempTarget");
jTextField4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
jTextField4ActionActionPerformed(event);
}
});
}
return jTextField4;
}
private JTextField getJTextField3() {
if (jTextField3 == null) {
jTextField3 = new JTextField();
jTextField3.setText("extrudeTarget");
jTextField3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
jTextField3ActionActionPerformed(event);
}
});
}
return jTextField3;
}
private JTextField getJTextField2() {
if (jTextField2 == null) {
jTextField2 = new JTextField();
jTextField2.setText("ztarget");
jTextField2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
jTextField2ActionActionPerformed(event);
}
});
}
return jTextField2;
}
private JTextField getJTextField1() {
if (jTextField1 == null) {
jTextField1 = new JTextField();
jTextField1.setText("ytarget");
jTextField1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
jTextField1ActionActionPerformed(event);
}
});
}
return jTextField1;
}
private JTextField getJTextField0() {
if (jTextField0 == null) {
jTextField0 = new JTextField();
jTextField0.setText("xtarget");
jTextField0.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
jTextField0ActionActionPerformed(event);
}
});
}
return jTextField0;
}
private JLabel getJLabel4() {
if (jLabel4 == null) {
jLabel4 = new JLabel();
jLabel4.setText("Temp");
}
return jLabel4;
}
private JLabel getJLabel3() {
if (jLabel3 == null) {
jLabel3 = new JLabel();
jLabel3.setText("Extrude");
}
return jLabel3;
}
private JLabel getJLabel2() {
if (jLabel2 == null) {
jLabel2 = new JLabel();
jLabel2.setText("Z");
}
return jLabel2;
}
private JLabel getJLabel1() {
if (jLabel1 == null) {
jLabel1 = new JLabel();
jLabel1.setText("Y");
}
return jLabel1;
}
private JLabel getJLabel0() {
if (jLabel0 == null) {
jLabel0 = new JLabel();
jLabel0.setText("X");
}
return jLabel0;
}
public CartesianPanel() {
initComponents();
}
private void jTextField4ActionActionPerformed(ActionEvent event) {
//set temp
}
private void jTextField3ActionActionPerformed(ActionEvent event) {
//set extrude
}
private void jTextField2ActionActionPerformed(ActionEvent event) {
//set z
}
private void jTextField1ActionActionPerformed(ActionEvent event) {
//set y
}
private void jTextField0ActionActionPerformed(ActionEvent event) {
// set x
}
}

View File

@@ -0,0 +1,297 @@
package com.neuronrobotics.bowlerstudio.creature;
import com.neuronrobotics.bowlerstudio.BowlerStudio;
import com.neuronrobotics.bowlerstudio.BowlerStudioController;
import com.neuronrobotics.bowlerstudio.BowlerStudioModularFrame;
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import com.neuronrobotics.bowlerstudio.tabs.AbstractBowlerStudioTab;
import com.neuronrobotics.bowlerstudio.util.FileWatchDeviceWrapper;
import com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice;
import com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics;
import com.neuronrobotics.sdk.addons.kinematics.DhInverseSolver;
import com.neuronrobotics.sdk.addons.kinematics.IDriveEngine;
import com.neuronrobotics.sdk.addons.kinematics.MobileBase;
import com.neuronrobotics.sdk.common.BowlerAbstractDevice;
import com.neuronrobotics.sdk.common.IDeviceConnectionEventListener;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.scene.layout.HBox;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.TransportException;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import javafx.scene.control.ToggleButton;
public class CreatureLab extends AbstractBowlerStudioTab implements IOnEngineeringUnitsChange {
private BowlerAbstractDevice pm;
private IDriveEngine defaultDriveEngine;
// private DhInverseSolver defaultDHSolver;
private Menu localMenue;
private ProgressIndicator pi;
private MobileBaseCadManager baseManager;
private CheckBox autoRegen = new CheckBox("Auto-Regnerate CAD");
Parent root;
private BowlerJInputDevice gameController = null;
CreatureLabControlsTab tab = new CreatureLabControlsTab();;
@Override
public void onTabClosing() {
baseManager.onTabClosing();
}
@Override
public String[] getMyNameSpaces() {
// TODO Auto-generated method stub
return new String[0];
}
@SuppressWarnings({ "restriction", "restriction" })
@Override
public void initializeUI(BowlerAbstractDevice pm) {
setGraphic(AssetFactory.loadIcon("CreatureLab-Tab.png"));
this.pm = pm;
autoRegen.setSelected(true);
autoRegen.setOnAction(event -> {
baseManager.setAutoRegen(autoRegen.isSelected());
if (autoRegen.isSelected()) {
generateCad();
}
});
// TODO Auto-generated method stub
setText(pm.getScriptingName());
try {
ScriptingEngine.setAutoupdate(true);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
MobileBase device = (MobileBase) pm;
// Button save = new Button("Save Configuration");
FXMLLoader loader;
try {
loader = AssetFactory.loadLayout("layout/CreatureLabControlsTab.fxml", true);
Platform.runLater(() -> {
loader.setController(tab);
// This is needed when loading on MAC
loader.setClassLoader(getClass().getClassLoader());
try {
root = loader.load();
finishLoading(device);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
private void finishLoading(MobileBase device) {
TreeView<String> tree = null;
TreeItem<String> rootItem = null;
try {
rootItem = new TreeItem<String>(device.getScriptingName(), AssetFactory.loadIcon("creature.png"));
} catch (Exception e) {
rootItem = new TreeItem<String>(device.getScriptingName());
}
tree = new TreeView<>(rootItem);
AnchorPane treebox1 = tab.getTreeBox();
treebox1.getChildren().clear();
treebox1.getChildren().add(tree);
AnchorPane.setTopAnchor(tree, 0.0);
AnchorPane.setLeftAnchor(tree, 0.0);
AnchorPane.setRightAnchor(tree, 0.0);
AnchorPane.setBottomAnchor(tree, 0.0);
rootItem.setExpanded(true);
HashMap<TreeItem<String>, Runnable> callbackMapForTreeitems = new HashMap<>();
HashMap<TreeItem<String>, Group> widgetMapForTreeitems = new HashMap<>();
try {
MobleBaseMenueFactory.load(device, tree, rootItem, callbackMapForTreeitems, widgetMapForTreeitems, this);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
tree.setPrefWidth(325);
tree.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
JogWidget walkWidget = new JogWidget(device);
tree.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Object>() {
@Override
public void changed(ObservableValue<?> observable, Object oldValue, Object newValue) {
@SuppressWarnings("unchecked")
TreeItem<String> treeItem = (TreeItem<String>) newValue;
new Thread() {
public void run() {
if (walkWidget.getGameController() != null)
setGameController(walkWidget.getGameController());
if (callbackMapForTreeitems.get(treeItem) != null) {
callbackMapForTreeitems.get(treeItem).run();
}
if (widgetMapForTreeitems.get(treeItem) != null) {
Platform.runLater(() -> {
tab.getControlsBox().getChildren().clear();
Group g = widgetMapForTreeitems.get(treeItem);
tab.getControlsBox().getChildren().add(g);
AnchorPane.setTopAnchor(g, 0.0);
AnchorPane.setLeftAnchor(g, 0.0);
AnchorPane.setRightAnchor(g, 0.0);
AnchorPane.setBottomAnchor(g, 0.0);
});
} else {
Platform.runLater(() -> {
tab.getControlsBox().getChildren().clear();
});
BowlerStudio.select(device);
walkWidget.setGameController(getController());
}
}
}.start();
}
});
VBox progress = new VBox(10);
final ToggleGroup group = new ToggleGroup();
RadioButton rb1 = new RadioButton();
rb1.setToggleGroup(group);
rb1.setSelected(true);
rb1.setOnAction(event -> {
setCadMode(false);
});
RadioButton rb2 = new RadioButton();
rb2.setToggleGroup(group);
rb2.fire();
rb2.setOnAction(event -> {
setCadMode(true);
});
HBox radioOptions = new HBox(10);
radioOptions.getChildren().addAll(new Label("Cad"), rb1, rb2, new Label("Config"));
pi = new ProgressIndicator(0);
baseManager = MobileBaseCadManager.get(device, BowlerStudioController.getMobileBaseUI());
pi.progressProperty().bindBidirectional(baseManager.getProcesIndictor());
HBox progressIndicatorPanel = new HBox(10);
progressIndicatorPanel.getChildren().addAll(new Label("Cad Progress:"), pi);
progress.getChildren().addAll(progressIndicatorPanel, autoRegen, radioOptions);
progress.setStyle("-fx-background-color: #FFFFFF;");
progress.setOpacity(.7);
// progress.setMinHeight(150);
progress.setPrefSize(325, 150);
tab.setOverlayTop(progress);
tab.setOverlayTopRight(walkWidget);
BowlerStudioModularFrame.getBowlerStudioModularFrame().showCreatureLab();
setCadMode(true);// start the UI in config mode
generateCad();
setContent(root);
}
private void setCadMode(boolean mode) {
new Thread(() -> {
baseManager.setConfigurationViewerMode(mode);
baseManager.setAutoRegen(autoRegen.isSelected());
if (autoRegen.isSelected()) {
generateCad();
}
}).start();
}
public void generateCad() {
// new Exception().printStackTrace();
baseManager.generateCad();
}
@Override
public void onTabReOpening() {
baseManager.setCadScript(baseManager.getCadScript());
try {
if (autoRegen.isSelected())
generateCad();
} catch (Exception ex) {
}
}
public static String getFormatted(double value) {
return String.format("%4.3f%n", (double) value);
}
@Override
public void onSliderMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) {
// TODO Auto-generated method stub
}
@Override
public void onSliderDoneMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) {
if (autoRegen.isSelected())
generateCad();
}
public BowlerJInputDevice getController() {
return getGameController();
}
public BowlerJInputDevice getGameController() {
return gameController;
}
public void setGameController(BowlerJInputDevice bowlerJInputDevice) {
this.gameController = bowlerJInputDevice;
}
public void setGitDhEngine(String gitsId, String file, DHParameterKinematics dh) {
MobileBaseLoader.get(baseManager.getMobileBase()).setDefaultDhParameterKinematics(dh);
}
public void setGitCadEngine(String gitsId, String file, MobileBase device)
throws InvalidRemoteException, TransportException, GitAPIException, IOException {
baseManager.setGitCadEngine(gitsId, file, device);
}
public void setGitCadEngine(String gitsId, String file, DHParameterKinematics dh)
throws InvalidRemoteException, TransportException, GitAPIException, IOException {
baseManager.setGitCadEngine(gitsId, file, dh);
}
public void setGitWalkingEngine(String git, String file, MobileBase device) {
MobileBaseLoader.get(baseManager.getMobileBase()).setGitWalkingEngine(git, file, device);
}
}

View File

@@ -0,0 +1,76 @@
package com.neuronrobotics.bowlerstudio.creature;
import javafx.fxml.FXML;
import javafx.scene.control.TreeView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
public class CreatureLabControlsTab {
@FXML
private AnchorPane walkingBox;
@FXML
private AnchorPane controlsBox;
@FXML
private AnchorPane progressBar;
@FXML
private AnchorPane treeBox;
public AnchorPane getWalkingBox() {
return walkingBox;
}
public void setWalkingBox(AnchorPane walkingBox) {
this.walkingBox = walkingBox;
}
public AnchorPane getControlsBox() {
return controlsBox;
}
public void setControlsBox(AnchorPane controlsBox) {
this.controlsBox = controlsBox;
}
// public AnchorPane getProgressBar() {
// return progressBar;
// }
public void setProgressBar(AnchorPane progressBar) {
this.progressBar = progressBar;
}
public AnchorPane getTreeBox() {
return treeBox;
}
public void setTreeBox(AnchorPane treeBox) {
this.treeBox = treeBox;
}
public void setOverlayTop(VBox progress) {
// TODO Auto-generated method stub
progressBar.getChildren().clear();
progressBar.getChildren().add(progress);
AnchorPane.setTopAnchor(progress, 0.0);
AnchorPane.setLeftAnchor(progress, 0.0);
AnchorPane.setRightAnchor(progress, 0.0);
AnchorPane.setBottomAnchor(progress, 0.0);
}
public void setOverlayTopRight(JogWidget walkWidget) {
// TODO Auto-generated method stub
walkingBox.getChildren().clear();
walkingBox.getChildren().add(walkWidget);
AnchorPane.setTopAnchor(walkWidget, 0.0);
AnchorPane.setLeftAnchor(walkWidget, 0.0);
AnchorPane.setRightAnchor(walkWidget, 0.0);
AnchorPane.setBottomAnchor(walkWidget, 0.0);
}
}

View File

@@ -0,0 +1,194 @@
package com.neuronrobotics.bowlerstudio.creature;
import com.neuronrobotics.bowlerstudio.BowlerStudioController;
import com.neuronrobotics.bowlerstudio.CreatureLab3dController;
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.bowlerstudio.physics.MobileBasePhysicsManager;
import com.neuronrobotics.bowlerstudio.physics.PhysicsEngine;
import com.neuronrobotics.bowlerstudio.threed.BowlerStudio3dEngine;
import com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration;
import com.neuronrobotics.sdk.addons.kinematics.MobileBase;
import com.neuronrobotics.sdk.addons.kinematics.imu.IMUUpdate;
import com.neuronrobotics.sdk.addons.kinematics.imu.IMUUpdateListener;
import com.neuronrobotics.sdk.addons.kinematics.math.RotationNR;
import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR;
import com.neuronrobotics.sdk.common.BowlerAbstractDevice;
import com.neuronrobotics.sdk.common.IDeviceConnectionEventListener;
import com.neuronrobotics.sdk.util.ThreadUtil;
import eu.mihosoft.vrl.v3d.CSG;
import javafx.application.Platform;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
public class CreaturePhysicsWidget extends GridPane implements IMUUpdateListener {
Button runstop = new Button("Run", AssetFactory.loadIcon("Run.png"));
Button pauseresume = new Button("Pause", AssetFactory.loadIcon("Pause.png"));
Button step = new Button("Step", AssetFactory.loadIcon("Step.png"));
TextField msLoopTime =new TextField("20") ;
int msLoopTimeInt =0;
private boolean run=false;
private boolean takestep=false;
private boolean pause=false;
Thread physicsThread =null;
private Set<CSG> oldParts=null;
private MobileBase base;
@SuppressWarnings("restriction")
public CreaturePhysicsWidget(MobileBase base){
this.base = base;
base.addConnectionEventListener(new IDeviceConnectionEventListener() {
@Override
public void onDisconnect(BowlerAbstractDevice arg0) {
Platform.runLater(()->{
stop();
});
}
@Override
public void onConnect(BowlerAbstractDevice arg0) {}
});
add(runstop,0,0);
add(pauseresume,1,0);
add(step,2,0);
add(new Label("MS loop"),3,0);
add(msLoopTime,4,0);
pauseresume.setDisable(true);
step.setDisable(true);
pauseresume.setOnAction(event->{
if(!isPause()){
pauseresume.setGraphic(AssetFactory.loadIcon("Resume.png"));
pauseresume.setText("Resume");
step.setDisable(false);
}else{
pauseresume.setGraphic(AssetFactory.loadIcon("Pause.png"));
pauseresume.setText("Pause");
step.setDisable(true);
}
setPause(!isPause());
});
step.setOnAction(event->{
setTakestep(true);
});
runstop.setOnAction(event->{
if(isRun()){
stop();
// new Thread(){
// public void run(){
// ThreadUtil.wait(50);
// System.gc();// clean up any objects created by the physics engine
// }
// }.start();
}else{
//System.gc();// clean up any objects created by the physics engine
runstop.setGraphic(AssetFactory.loadIcon("Stop.png"));
runstop.setText("Stop");
msLoopTime.setDisable(true);
pauseresume.setDisable(false);
base.getImu().addvirtualListeners(this);
new Thread(){
public void run(){
while(MobileBaseCadManager.get( base).getProcesIndictor().get()<1){
ThreadUtil.wait(10);
}
HashMap<LinkConfiguration, ArrayList<CSG>> simplecad = MobileBaseCadManager.getSimplecad(base) ;
ArrayList<CSG> baseCad=MobileBaseCadManager.getBaseCad(base);
base.DriveArc(new TransformNR(.01,0,0,new RotationNR()), 0);
PhysicsEngine.get().clear();
MobileBasePhysicsManager m =new MobileBasePhysicsManager(base, baseCad, simplecad);
//BowlerStudio3dEngine threeD = BowlerStudioController.getBowlerStudio().getJfx3dmanager();
oldParts = CreatureLab3dController.getEngine().getCsgMap().keySet();
BowlerStudioController.setCsg(PhysicsEngine.get().getCsgFromEngine());
int loopTiming = (int) Double.parseDouble(msLoopTime.getText());
physicsThread = new Thread(){
public void run(){
try{
while(!Thread.interrupted() && isRun()){
while(!Thread.interrupted() && isPause() && isTakestep()==false){
ThreadUtil.wait(loopTiming);
}
setTakestep(false);
long start = System.currentTimeMillis();
PhysicsEngine.get().stepMs(loopTiming);
long took = (System.currentTimeMillis() - start);
if (took < loopTiming)
ThreadUtil.wait((int) (loopTiming - took)/4);
else{
if(took>loopTiming*2)
System.out.println("ERROR Real time broken by: "+took+"ms");
}
}
PhysicsEngine.get().clear();
m.clear();
}catch(Exception e){
e.printStackTrace();
}
}
};
physicsThread.start();
}
}.start();
}
setRun(!isRun());
});
}
private void stop() {
runstop.setGraphic(AssetFactory.loadIcon("Run.png"));
runstop.setText("Run");
if(physicsThread!=null)
physicsThread.interrupt();
msLoopTime.setDisable(false);
pauseresume.setDisable(true);
if(oldParts!=null){
ArrayList<CSG>oldp=new ArrayList<>();
for(CSG c:oldParts){
oldp.add(c);
}
BowlerStudioController.setCsg(oldp);
oldParts=null;
}
base.getImu().removevirtualListeners(this);
}
public boolean isTakestep() {
return takestep;
}
public void setTakestep(boolean takestep) {
this.takestep = takestep;
}
public boolean isPause() {
return pause;
}
public void setPause(boolean pause) {
this.pause = pause;
}
public boolean isRun() {
return run;
}
public void setRun(boolean run) {
this.run = run;
}
@Override
public void onIMUUpdate(IMUUpdate arg0) {
// System.err.println("X = "+arg0.getxAcceleration()+
// " Y = "+arg0.getyAcceleration()+
// " Z = "+arg0.getzAcceleration()+
// " rX = "+arg0.getRotxAcceleration()+
// " rY = "+arg0.getRotyAcceleration()+
// " rZ = "+arg0.getRotzAcceleration()
//
// );
}
}

View File

@@ -0,0 +1,154 @@
package com.neuronrobotics.bowlerstudio.creature;
import java.time.Duration;
import org.reactfx.util.FxTimer;
import com.neuronrobotics.sdk.addons.kinematics.AbstractKinematicsNR;
import com.neuronrobotics.sdk.addons.kinematics.AbstractLink;
import com.neuronrobotics.sdk.addons.kinematics.DHLink;
import com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics;
import com.neuronrobotics.sdk.addons.kinematics.DhLinkType;
import com.neuronrobotics.sdk.addons.kinematics.IJointSpaceUpdateListenerNR;
import com.neuronrobotics.sdk.addons.kinematics.JointLimit;
import com.neuronrobotics.sdk.common.Log;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Group;
import javafx.scene.control.Accordion;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.RowConstraints;
import javafx.scene.text.Text;
@SuppressWarnings("restriction")
public class DHLinkWidget extends Group implements IJointSpaceUpdateListenerNR {
private AbstractKinematicsNR device;
private DHParameterKinematics dhdevice;
private int linkIndex;
private EngineeringUnitsSliderWidget setpoint;
private Button del;
public DHLinkWidget(int linkIndex, DHLink dhlink, AbstractKinematicsNR device2, Button del,IOnEngineeringUnitsChange externalListener, MobileBaseCadManager manager ) {
this.linkIndex = linkIndex;
this.device = device2;
if(DHParameterKinematics.class.isInstance(device2)){
dhdevice=(DHParameterKinematics)device2;
}
this.del = del;
AbstractLink abstractLink = device2.getAbstractLink(linkIndex);
TextField name = new TextField(abstractLink.getLinkConfiguration().getName());
name.setMaxWidth(100.0);
name.setOnAction(event -> {
abstractLink.getLinkConfiguration().setName(name.getText());
});
setpoint = new EngineeringUnitsSliderWidget(new IOnEngineeringUnitsChange() {
@Override
public void onSliderMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) {
// TODO Auto-generated method stub
}
@Override
public void onSliderDoneMoving(EngineeringUnitsSliderWidget source,
double newAngleDegrees) {
try {
device2.setDesiredJointAxisValue(linkIndex, setpoint.getValue(), 2);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
};
}
},
abstractLink.getMinEngineeringUnits(),
abstractLink.getMaxEngineeringUnits(),
device2.getCurrentJointSpaceVector()[linkIndex],
180,dhlink.getLinkType()==DhLinkType.ROTORY?"degrees":"mm");
final Accordion accordion = new Accordion();
if(dhdevice!=null)
accordion.getPanes().add(new TitledPane("Configure D-H", new DhSettingsWidget(dhdevice.getChain().getLinks().get(linkIndex),dhdevice,externalListener)));
accordion.getPanes().add(new TitledPane("Configure Link", new LinkConfigurationWidget(abstractLink.getLinkConfiguration(), device2.getFactory(),setpoint,manager)));
GridPane panel = new GridPane();
panel.getColumnConstraints().add(new ColumnConstraints(80)); // column 1 is 75 wide
panel.getColumnConstraints().add(new ColumnConstraints(30)); // column 1 is 75 wide
panel.getColumnConstraints().add(new ColumnConstraints(120)); // column 2 is 300 wide
panel.add( del,
0,
0);
panel.add( new Text("#"+linkIndex),
1,
0);
panel.add( name,
2,
0);
panel.add( setpoint,
3,
0);
panel.add( accordion,
2,
1);
getChildren().add(panel);
}
public void changed(ObservableValue<? extends Boolean> observableValue,
Boolean wasChanging,
Boolean changing) {
}
@Override
public void onJointSpaceUpdate(AbstractKinematicsNR source, double[] joints) {
Platform.runLater(()->{
try{
setpoint.setValue(joints[linkIndex]);
}catch(ArrayIndexOutOfBoundsException ex){
return;
}
});
}
@Override
public void onJointSpaceTargetUpdate(AbstractKinematicsNR source,
double[] joints) {
// TODO Auto-generated method stub
}
@Override
public void onJointSpaceLimit(AbstractKinematicsNR source, int axis,
JointLimit event) {
// TODO Auto-generated method stub
}
}

View File

@@ -0,0 +1,19 @@
package com.neuronrobotics.bowlerstudio.creature;
import javax.swing.JPanel;
import com.neuronrobotics.replicator.driver.NRPrinter;
import com.neuronrobotics.replicator.driver.StateBasedControllerConfiguration;
public abstract class DeviceSettingsBase extends JPanel {
private NRPrinter printer;
public DeviceSettingsBase(NRPrinter _printer){
printer = _printer;
}
public abstract StateBasedControllerConfiguration getStateBasedControllerSettings();
public abstract void setStateBasedControllerSettings(StateBasedControllerConfiguration _state);
}

View File

@@ -0,0 +1,287 @@
package com.neuronrobotics.bowlerstudio.creature;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import eu.mihosoft.vrl.v3d.STL;
import java.nio.file.Path;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.WatchEvent;
import java.util.ArrayList;
import com.neuronrobotics.bowlerstudio.BowlerStudioController;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import com.neuronrobotics.bowlerstudio.util.FileWatchDeviceWrapper;
import com.neuronrobotics.nrconsole.util.FileSelectionFactory;
import com.neuronrobotics.nrconsole.util.GroovyFilter;
import com.neuronrobotics.nrconsole.util.XmlFilter;
import com.neuronrobotics.sdk.addons.kinematics.AbstractKinematicsNR;
import com.neuronrobotics.sdk.addons.kinematics.DHChain;
import com.neuronrobotics.sdk.addons.kinematics.DHLink;
import com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics;
import com.neuronrobotics.sdk.addons.kinematics.DhInverseSolver;
import com.neuronrobotics.sdk.addons.kinematics.IDriveEngine;
import com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration;
import com.neuronrobotics.sdk.addons.kinematics.LinkFactory;
import com.neuronrobotics.sdk.addons.kinematics.MobileBase;
import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR;
import com.neuronrobotics.sdk.common.BowlerAbstractDevice;
import com.neuronrobotics.sdk.common.IDeviceConnectionEventListener;
import com.neuronrobotics.sdk.common.Log;
import com.neuronrobotics.sdk.util.IFileChangeListener;
import eu.mihosoft.vrl.v3d.CSG;
import eu.mihosoft.vrl.v3d.Cube;
import eu.mihosoft.vrl.v3d.Transform;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.control.Accordion;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.FileChooser.ExtensionFilter;
public class DhChainWidget extends Group implements IDeviceConnectionEventListener{
private File currentFile=null;
private VBox links;
private VBox controls;
JogWidget jog = null;
private AbstractKinematicsNR device;
private DHParameterKinematics dhdevice=null;
private MobileBase mbase=null;
private MobileBaseCadManager manager=null;
private File kinematicsFile;
private ArrayList<DHLinkWidget> widgets = new ArrayList<>();
private IOnEngineeringUnitsChange externalListener;
public DhChainWidget(AbstractKinematicsNR device2,IOnEngineeringUnitsChange externalListener){
this.device = device2;
this.externalListener = externalListener;
device.addConnectionEventListener(this);
if(DHParameterKinematics.class.isInstance(device2)){
dhdevice=(DHParameterKinematics)device2;
}
if(MobileBase.class.isInstance(device2)){
mbase=(MobileBase)device2;
manager=MobileBaseCadManager.get(mbase);
}
links = new VBox(20);
controls = new VBox(10);
jog = new JogWidget(device);
VBox advanced = new VBox(10);
Button save = new Button("Save Configuration");
Button add = new Button("Add Link");
Button refresh = new Button("Generate CAD");
Button kinematics = new Button("Set Kinematics");
kinematics.setOnAction(event -> {
new Thread(){
public void run(){
if(getKinematicsFile()==null)
setKinematicsFile(ScriptingEngine.getLastFile());
setKinematicsFile(FileSelectionFactory.GetFile(getKinematicsFile(),
new ExtensionFilter("Kinematics Script","*.groovy","*.java","*.txt")));
if (getKinematicsFile() == null) {
return;
}
setKinematics();
}
}.start();
});
save.setOnAction(event -> {
new Thread(){
public void run(){
File last = FileSelectionFactory.GetFile(currentFile==null?
ScriptingEngine.getWorkspace():
new File(ScriptingEngine.getWorkspace().getAbsolutePath()+"/"+currentFile.getName()),
new ExtensionFilter("MobileBase XML","*.xml","*.XML"));
if (last != null) {
try {
Files.write(Paths.get(last.getAbsolutePath()),device.getXml().getBytes() );
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}.start();
});
add.setOnAction(event -> {
LinkConfiguration newLink = new LinkConfiguration();
if(dhdevice!=null)dhdevice.addNewLink(newLink,new DHLink(0, 0, 0, 0));
onTabReOpening();
});
refresh.setOnAction(event -> {
onTabReOpening();
});
advanced.getChildren().add(new TransformWidget("Base to Global",
device.getFiducialToGlobalTransform(),new IOnTransformChange() {
@Override
public void onTransformFinished(TransformNR newTrans) {
// TODO Auto-generated method stub
}
@Override
public void onTransformChaging(TransformNR newTrans) {
Log.debug("Base to Global"+newTrans.toString());
device.setGlobalToFiducialTransform(newTrans);
device.getCurrentTaskSpaceTransform();
}
}
));
advanced.getChildren().add(save);
advanced.getChildren().add(add);
advanced.getChildren().add(refresh);
advanced.getChildren().add(kinematics);
Accordion advancedPanel = new Accordion();
advancedPanel.getPanes().add(new TitledPane("Advanced Options", advanced));
controls.getChildren().add(jog);
if(mbase==null){
controls.getChildren().add(advancedPanel);
controls.getChildren().add(new TransformWidget("Place Limb",
device.getRobotToFiducialTransform(), new IOnTransformChange() {
@Override
public void onTransformFinished(TransformNR newTrans) {
// Force a cad regeneration
externalListener.onSliderDoneMoving(null, 0);
}
@Override
public void onTransformChaging(TransformNR newTrans) {
Log.debug("Limb to base"+newTrans.toString());
device.setRobotToFiducialTransform(newTrans);
device.getCurrentTaskSpaceTransform();
//this calls the render update function attachec as the on jointspace update
double[] joint=device2.getCurrentJointSpaceVector();
dhdevice.getChain().getChain(joint);
Platform.runLater(()->dhdevice.onJointSpaceUpdate(dhdevice, joint));
}
}
));
}else{
controls.getChildren().add(kinematics);
}
onTabReOpening();
getChildren().add(new ScrollPane(links));
}
private void setKinematics(){
if(getKinematicsFile()!=null){
try{
if(mbase!=null){
mbase.setWalkingDriveEngine( (IDriveEngine) ScriptingEngine.inlineFileScriptRun(getKinematicsFile(), null));
}else if (dhdevice != null){
dhdevice.setInverseSolver((DhInverseSolver) ScriptingEngine.inlineFileScriptRun(getKinematicsFile(), null));
}
}catch(Exception e){
BowlerStudioController.highlightException(getKinematicsFile(), e);
}
}
}
public void onTabReOpening() {
for(DHLinkWidget wid:widgets){
device.removeJointSpaceUpdateListener(wid);
}
widgets.clear();
links.getChildren().clear();
ArrayList<DHLink> dhLinks=null;
if(dhdevice!=null)
dhLinks = dhdevice.getChain().getLinks();
links.getChildren().add(controls);
for(int i=0;i<device.getFactory().getLinkConfigurations().size();i++){
Log.warning("Adding Link Widget: "+i);
DHLink dh=null;
if(dhdevice!=null)
dh=dhLinks.get(i);
Button del = new Button("Delete");
final int linkIndex=i;
del.setOnAction(event -> {
LinkFactory factory =device.getFactory();
//remove the link listener while the number of links could chnage
factory.removeLinkListener(device);
if(dhdevice!=null){
DHChain chain = dhdevice.getDhChain() ;
chain.getLinks().remove(linkIndex);
factory.deleteLink(linkIndex);
//set the modified kinematics chain
dhdevice.setChain(chain);
}else{
factory.deleteLink(linkIndex);
}
//once the new link configuration is set up, re add the listener
factory.addLinkListener(device);
onTabReOpening();
});
DHLinkWidget w = new DHLinkWidget(i,
dh,
device,
del,
externalListener,manager);
widgets.add(w);
links.getChildren().add(w);
device.addJointSpaceListener(w);
}
//BowlerStudioController.setCsg(csg);
jog.home();
}
public File getKinematicsFile() {
return kinematicsFile;
}
public void setKinematicsFile(File kinematicsFile) {
FileWatchDeviceWrapper.watch(device, kinematicsFile, (fileThatChanged, event) -> {
try {
setKinematics();
} catch (Exception ex) {
ex.printStackTrace();
}
});
this.kinematicsFile = kinematicsFile;
}
@Override
public void onDisconnect(BowlerAbstractDevice source) {
}
@Override
public void onConnect(BowlerAbstractDevice source) {
// TODO Auto-generated method stub
}
}

View File

@@ -0,0 +1,24 @@
package com.neuronrobotics.bowlerstudio.creature;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.GridPane;
import com.neuronrobotics.bowlerstudio.tabs.AbstractBowlerStudioTab;
import com.neuronrobotics.sdk.addons.kinematics.AbstractKinematicsNR;
import com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics;
import com.neuronrobotics.sdk.addons.kinematics.MobileBase;
import com.neuronrobotics.sdk.common.BowlerAbstractDevice;
import com.neuronrobotics.sdk.common.Log;
public class DhLab extends CreatureLab {
@Override
public void initializeUI(BowlerAbstractDevice pm) {
super.initializeUI(pm);
setText("DH Lab");
}
}

View File

@@ -0,0 +1,108 @@
package com.neuronrobotics.bowlerstudio.creature;
import javafx.application.Platform;
import javafx.scene.control.Accordion;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.RowConstraints;
import javafx.scene.text.Text;
import com.neuronrobotics.sdk.addons.kinematics.AbstractKinematicsNR;
import com.neuronrobotics.sdk.addons.kinematics.DHLink;
import com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics;
public class DhSettingsWidget extends javafx.scene.Group implements IOnEngineeringUnitsChange {
private DHLink dhLink;
private EngineeringUnitsSliderWidget delta;
private EngineeringUnitsSliderWidget theta;
private EngineeringUnitsSliderWidget alpha;
private EngineeringUnitsSliderWidget radius;
private DHParameterKinematics device2;
private IOnEngineeringUnitsChange externalListener;
public DhSettingsWidget(DHLink dhLink,DHParameterKinematics device2,IOnEngineeringUnitsChange externalListener ){
this.dhLink = dhLink;
this.device2 = device2;
this.externalListener = externalListener;
delta= new EngineeringUnitsSliderWidget(this,
0,
200,
dhLink.getDelta(),
180," mm ");
theta = new EngineeringUnitsSliderWidget(this,
-180,
180,
Math.toDegrees(dhLink.getTheta()),
180,"degrees");
radius= new EngineeringUnitsSliderWidget(this,
0,
200,
dhLink.getRadius(),
180," mm ");
alpha = new EngineeringUnitsSliderWidget(this,
-180,
180,
Math.toDegrees(dhLink.getAlpha()),
180,"degrees");
GridPane gridpane = new GridPane();
gridpane.getColumnConstraints().add(new ColumnConstraints(120)); // column 1 is 75 wide
gridpane.getColumnConstraints().add(new ColumnConstraints(320)); // column 2 is 300 wide
gridpane.getColumnConstraints().add(new ColumnConstraints(100)); // column 2 is 100 wide
gridpane.getRowConstraints().add(new RowConstraints(50)); //
gridpane.getRowConstraints().add(new RowConstraints(50)); //
gridpane.getRowConstraints().add(new RowConstraints(50)); //
gridpane.getRowConstraints().add(new RowConstraints(50)); //
gridpane.add(new Text("Delta (Height)"), 0, 0);
gridpane.add(delta, 1, 0);
gridpane.add(new Text("Radius (Length)"), 0, 1);
gridpane.add(radius, 1, 1);
gridpane.getColumnConstraints().add(new ColumnConstraints(120)); // column 1 is 75 wide
gridpane.getColumnConstraints().add(new ColumnConstraints(320)); // column 2 is 300 wide
gridpane.getColumnConstraints().add(new ColumnConstraints(100)); // column 2 is 100 wide
gridpane.getRowConstraints().add(new RowConstraints(50)); //
gridpane.getRowConstraints().add(new RowConstraints(50)); //
gridpane.add(new Text("Theta"), 0, 2);
gridpane.add(theta, 1, 2);
gridpane.add(new Text("Alpha"), 0, 3);
gridpane.add(alpha, 1, 3);
getChildren().add(gridpane);
}
@Override
public void onSliderMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) {
dhLink.setTheta(Math.toRadians(theta.getValue()));
dhLink.setAlpha(Math.toRadians(alpha.getValue()));
dhLink.setRadius(radius.getValue());
dhLink.setDelta(delta.getValue());
if(externalListener!=null)
externalListener.onSliderMoving(source, newAngleDegrees);
//this calls the render update function attachec as the on jointspace update
double[] joint=device2.getCurrentJointSpaceVector();
device2.getChain().getChain(joint);
Platform.runLater(()->device2.onJointSpaceUpdate(device2, joint));
}
@Override
public void onSliderDoneMoving(EngineeringUnitsSliderWidget source,
double newAngleDegrees) {
// TODO Auto-generated method stub
if(externalListener!=null)
externalListener.onSliderDoneMoving(source, newAngleDegrees);
}
}

View File

@@ -0,0 +1,188 @@
package com.neuronrobotics.bowlerstudio.creature;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
@SuppressWarnings("restriction")
public class EngineeringUnitsSliderWidget extends GridPane implements ChangeListener<Number>{
private TextField setpointValue;
private Slider setpoint;
private IOnEngineeringUnitsChange listener;
private boolean intCast=false;
private boolean allowResize=true;
public EngineeringUnitsSliderWidget(IOnEngineeringUnitsChange listener,double min, double max, double current, double width, String units, boolean intCast){
this(listener, min, max, current, width, units);
this.intCast = intCast;
}
public EngineeringUnitsSliderWidget(IOnEngineeringUnitsChange listener, double current, double width, String units){
this(listener, current/2, current*2, current, width, units);
}
public EngineeringUnitsSliderWidget(IOnEngineeringUnitsChange listener, double min, double max, double current, double width, String units){
this.setListener(listener);
setpoint = new Slider();
if(min>max){
double minStart = min;
min=max;
max=minStart;
}
if(min>current)
min=current;
if(max<current)
max=current;
double range = Math.abs(max-min);
if(range<1){
min=min-100;
max = max+100;
range=200;
}
setpoint.setMin(min);
setpoint.setMax(max);
setpoint.setValue(current);
setpoint.setShowTickLabels(true);
setpoint.setShowTickMarks(true);
//setpoint.setSnapToTicks(true);
setpoint.setMajorTickUnit(range);
setpoint.setMinorTickCount(5);
//setpoint.setBlockIncrement(range/100);
setpointValue = new TextField(getFormatted(current));
setpointValue.setOnAction(event -> {
String txt =setpointValue.getText();
double val =Double.parseDouble(txt);
System.out.println("Setpoint Text changed to "+val);
Platform.runLater(() -> {
setValueLocal(val);
getListener().onSliderMoving(this,val);
getListener().onSliderDoneMoving(this,val);
});
});
setpoint.setMaxWidth(width);
setpoint.valueChangingProperty().addListener((ChangeListener<Boolean>) (observable, oldValue, newValue) -> {
try {
double val =Double.parseDouble(setpointValue.getText());
System.err.println("Slider done moving = "+newValue);
if(!newValue)
getListener().onSliderDoneMoving(this,val);
}catch(java.lang.NumberFormatException ex) {
setValueLocal(0);
return;
}
});
setpoint.valueProperty().addListener(this);
String unitsString = "("+units+")";
getColumnConstraints().add(new ColumnConstraints(width+20)); // column 2 is 100 wide
getColumnConstraints().add(new ColumnConstraints(100)); // column 2 is 100 wide
getColumnConstraints().add(new ColumnConstraints(unitsString.length()*7)); // column 2 is 100 wide
add( setpoint,
0,
0);
add( setpointValue,
1,
0);
add( new Text(unitsString),
2,
0);
}
public void setUpperBound(double newBound){
setpoint.setMax(newBound);
}
public void setLowerBound(double newBound){
setpoint.setMin(newBound);
}
@Override
public void changed(ObservableValue<? extends Number> observable,
Number oldValue, Number newValue) {
updateValue();
}
private void updateValue(){
Platform.runLater(() -> {
setpointValue.setText(getFormatted(setpoint.getValue()));
getListener().onSliderMoving(this,setpoint.getValue());
});
}
public void setValue(double value){
Platform.runLater(() -> {
setValueLocal(value);
});
}
private void setValueLocal(double value) {
setpoint.valueProperty().removeListener(this);
double val = value;
if(val>setpoint.getMax()){
if(isAllowResize())
setpoint.setMax(val);
else
val=setpoint.getMax();
}if(val<setpoint.getMin()){
if(isAllowResize())
setpoint.setMin(val);
else
val=setpoint.getMin();
}
double range = Math.abs(setpoint.getMax()-setpoint.getMin());
setpoint.setMajorTickUnit(range);
setpoint.setValue(val);
setpointValue.setText(getFormatted(setpoint.getValue()));
setpoint.valueProperty().addListener(this);
//System.out.println("Setpoint changed to "+val);
}
public double getValue(){
return setpoint.getValue();
}
public String getFormatted(double value){
if(intCast)
return String.valueOf((int)value);
return String.format("%8.2f", (double)value);
}
public IOnEngineeringUnitsChange getListener() {
if(listener==null)
return new IOnEngineeringUnitsChange() {
@Override
public void onSliderMoving(EngineeringUnitsSliderWidget source,
double newAngleDegrees) {
// TODO Auto-generated method stub
}
@Override
public void onSliderDoneMoving(EngineeringUnitsSliderWidget source,
double newAngleDegrees) {
// TODO Auto-generated method stub
}
};
return listener;
}
public void setListener(IOnEngineeringUnitsChange listener) {
this.listener = listener;
}
public boolean isAllowResize() {
return allowResize;
}
public void setAllowResize(boolean allowResize) {
this.allowResize = allowResize;
}
}

View File

@@ -0,0 +1,5 @@
package com.neuronrobotics.bowlerstudio.creature;
public interface IGameControllerUpdateListener {
public void onControllerUpdate(AbstractGameController source);
}

View File

@@ -0,0 +1,5 @@
package com.neuronrobotics.bowlerstudio.creature;
public interface IGistPromptCompletionListener {
public void done(String gitsId, String file);
}

View File

@@ -0,0 +1,6 @@
package com.neuronrobotics.bowlerstudio.creature;
public interface IOnEngineeringUnitsChange {
public void onSliderMoving(EngineeringUnitsSliderWidget source,double newAngleDegrees);
public void onSliderDoneMoving(EngineeringUnitsSliderWidget source,double newAngleDegrees);
}

View File

@@ -0,0 +1,8 @@
package com.neuronrobotics.bowlerstudio.creature;
import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR;
public interface IOnTransformChange {
public abstract void onTransformChaging(TransformNR newTrans);
public abstract void onTransformFinished(TransformNR newTrans);
}

View File

@@ -0,0 +1,39 @@
package com.neuronrobotics.bowlerstudio.creature;
import com.neuronrobotics.bowlerstudio.tabs.AbstractBowlerStudioTab;
import com.neuronrobotics.sdk.addons.kinematics.AbstractKinematicsNR;
import com.neuronrobotics.sdk.common.BowlerAbstractDevice;
public class JogKinematicsDevice extends AbstractBowlerStudioTab{
@Override
public void onTabClosing() {
// TODO Auto-generated method stub
}
@Override
public String[] getMyNameSpaces() {
// TODO Auto-generated method stub
return new String[]{"bcs.cartesian.*"};
}
@Override
public void initializeUI(BowlerAbstractDevice pm) {
setContent(new JogWidget((AbstractKinematicsNR) pm));
setText("Jog Kinematics Devices");
onTabReOpening();
}
@Override
public void onTabReOpening() {
// TODO Auto-generated method stub
}
}

View File

@@ -0,0 +1,197 @@
package com.neuronrobotics.bowlerstudio.creature;
/**
* Sample Skeleton for "jogTrainerWidget.fxml" Controller Class
* You can copy and paste this code into your favorite IDE
**/
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.bowlerstudio.assets.ConfigurationDatabase;
import com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice;
import com.neuronrobotics.sdk.addons.gamepad.IJInputEventListener;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.stage.Modality;
import javafx.stage.Stage;
import net.java.games.input.Component;
import net.java.games.input.Event;
import java.net.URL;
import java.util.ResourceBundle;
public class JogTrainerWidget extends Application implements IJInputEventListener {
@FXML // ResourceBundle that was given to the FXMLLoader
private ResourceBundle resources;
@FXML // URL location of the FXML file that was given to the FXMLLoader
private URL location;
@FXML // fx:id="linkMinus"
private ImageView linkMinus; // Value injected by FXMLLoader
@FXML // fx:id="linkPlus"
private ImageView linkPlus; // Value injected by FXMLLoader
@FXML // fx:id="linkval"
private TextField linkval; // Value injected by FXMLLoader
@FXML // fx:id="rotzMinus"
private ImageView rotzMinus; // Value injected by FXMLLoader
@FXML // fx:id="rotzPlus"
private ImageView rotzPlus; // Value injected by FXMLLoader
@FXML // fx:id="rzval"
private TextField rzval; // Value injected by FXMLLoader
@FXML // fx:id="xminus"
private ImageView xminus; // Value injected by FXMLLoader
@FXML // fx:id="xplus"
private ImageView xplus; // Value injected by FXMLLoader
// WARNING: fx:id="xval" cannot be injected: several objects share the same fx:id;
@FXML // fx:id="yminus"
private ImageView yminus; // Value injected by FXMLLoader
@FXML // fx:id="yplus"
private ImageView yplus; // Value injected by FXMLLoader
@FXML // fx:id="yval"
private TextField xval; // Value injected by FXMLLoader
@FXML // fx:id="yval"
private TextField yval; // Value injected by FXMLLoader
@FXML // fx:id="zminus"
private ImageView zminus; // Value injected by FXMLLoader
@FXML // fx:id="zplus"
private ImageView zplus; // Value injected by FXMLLoader
@FXML // fx:id="zval"
private TextField zval; // Value injected by FXMLLoader
private Stage primaryStage;
private BowlerJInputDevice gameController;
private String paramsKey;
private TextField selected=null;
public JogTrainerWidget(BowlerJInputDevice gameController) {
this.gameController = gameController;
paramsKey = gameController.getController().getName();
gameController.addListeners(this);
}
// Handler for Button[Button[id=null, styleClass=button]] onAction
@FXML
void configure(ActionEvent event) {
primaryStage.close();
new Thread(()->{
//linkval.setText((String) ConfigurationDatabase.getObject(paramsKey, "jogLink", "x"));
ConfigurationDatabase.setObject(paramsKey, "jogLink", linkval.getText());
// xval.setText((String) ConfigurationDatabase.getObject(paramsKey, "jogKinx", "x"));
ConfigurationDatabase.setObject(paramsKey, "jogKinx", xval.getText());
//yval.setText((String) ConfigurationDatabase.getObject(paramsKey, "jogKiny", "y"));
ConfigurationDatabase.setObject(paramsKey, "jogKiny", yval.getText());
//zval.setText((String) ConfigurationDatabase.getObject(paramsKey, "jogKinz", "rz"));
ConfigurationDatabase.setObject(paramsKey, "jogKinz", zval.getText());
//rzval.setText((String) ConfigurationDatabase.getObject(paramsKey, "jogKinslider", "slider"));
ConfigurationDatabase.setObject(paramsKey, "jogKinslider", rzval.getText());
ConfigurationDatabase.save();
}).start();
gameController.removeListeners(this);
}
@FXML
void selectTraining(MouseEvent event) {
if(TextField.class.isInstance(event.getSource()))
selected = (TextField) event.getSource();
}
@SuppressWarnings("restriction")
@Override
public void start(Stage primaryStage) throws Exception
{
this.primaryStage = primaryStage;
FXMLLoader loader = AssetFactory.loadLayout("layout/jogTrainerWidget.fxml", true);
Parent root;
loader.setController(this);
// This is needed when loading on MAC
loader.setClassLoader(getClass().getClassLoader());
root = loader.load();
Platform.runLater(() -> {
primaryStage.setTitle("Configure the controller");
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.initModality(Modality.WINDOW_MODAL);
primaryStage.setResizable(true);
primaryStage.show();
});
}
@FXML // This method is called by the FXMLLoader when initialization is complete
void initialize() {
assert linkMinus != null : "fx:id=\"linkMinus\" was not injected: check your FXML file 'jogTrainerWidget.fxml'.";
assert linkPlus != null : "fx:id=\"linkPlus\" was not injected: check your FXML file 'jogTrainerWidget.fxml'.";
assert linkval != null : "fx:id=\"linkval\" was not injected: check your FXML file 'jogTrainerWidget.fxml'.";
assert rotzMinus != null : "fx:id=\"rotzMinus\" was not injected: check your FXML file 'jogTrainerWidget.fxml'.";
assert rotzPlus != null : "fx:id=\"rotzPlus\" was not injected: check your FXML file 'jogTrainerWidget.fxml'.";
assert rzval != null : "fx:id=\"rzval\" was not injected: check your FXML file 'jogTrainerWidget.fxml'.";
assert xminus != null : "fx:id=\"xminus\" was not injected: check your FXML file 'jogTrainerWidget.fxml'.";
assert xplus != null : "fx:id=\"xplus\" was not injected: check your FXML file 'jogTrainerWidget.fxml'.";
assert yminus != null : "fx:id=\"yminus\" was not injected: check your FXML file 'jogTrainerWidget.fxml'.";
assert yplus != null : "fx:id=\"yplus\" was not injected: check your FXML file 'jogTrainerWidget.fxml'.";
assert yval != null : "fx:id=\"yval\" was not injected: check your FXML file 'jogTrainerWidget.fxml'.";
assert zminus != null : "fx:id=\"zminus\" was not injected: check your FXML file 'jogTrainerWidget.fxml'.";
assert zplus != null : "fx:id=\"zplus\" was not injected: check your FXML file 'jogTrainerWidget.fxml'.";
assert zval != null : "fx:id=\"zval\" was not injected: check your FXML file 'jogTrainerWidget.fxml'.";
// Initialize your logic here: all @FXML variables will have been injected
try {
xplus.setImage(AssetFactory.loadAsset("Plus-X.png"));
xminus.setImage(AssetFactory.loadAsset("Minus-X.png"));
yplus.setImage(AssetFactory.loadAsset("Plus-Y.png"));
yminus.setImage(AssetFactory.loadAsset("Minus-Y.png"));
zplus.setImage(AssetFactory.loadAsset("Plus-Z.png"));
zminus.setImage(AssetFactory.loadAsset("Minus-Z.png"));
rotzPlus.setImage(AssetFactory.loadAsset("Rotation-Z.png"));
rotzMinus.setImage(AssetFactory.loadAsset("Rotation-Neg-Z.png"));
linkPlus.setImage(AssetFactory.loadAsset("Move-Single-Motor.png"));
linkMinus.setImage(AssetFactory.loadAsset("Move-Single-Motor.png"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Platform.runLater(()->{
linkval.setText((String) ConfigurationDatabase.getObject(paramsKey, "jogLink", "x"));
xval.setText((String) ConfigurationDatabase.getObject(paramsKey, "jogKinx", "x"));
yval.setText((String) ConfigurationDatabase.getObject(paramsKey, "jogKiny", "y"));
zval.setText((String) ConfigurationDatabase.getObject(paramsKey, "jogKinz", "rz"));
rzval.setText((String) ConfigurationDatabase.getObject(paramsKey, "jogKinslider", "slider"));
});
}
@Override
public void onEvent(Component arg0, Event arg1, float value, String arg3) {
if(Math.abs(value)>0.75 && selected!=null){
Platform.runLater(()->selected.setText(arg0.getName()));
}
}
}

View File

@@ -0,0 +1,548 @@
package com.neuronrobotics.bowlerstudio.creature;
import com.neuronrobotics.bowlerstudio.ConnectionManager;
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.bowlerstudio.assets.ConfigurationDatabase;
import com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice;
import com.neuronrobotics.sdk.addons.gamepad.IJInputEventListener;
import com.neuronrobotics.sdk.addons.kinematics.AbstractKinematicsNR;
import com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics;
import com.neuronrobotics.sdk.addons.kinematics.ITaskSpaceUpdateListenerNR;
import com.neuronrobotics.sdk.addons.kinematics.MobileBase;
import com.neuronrobotics.sdk.addons.kinematics.math.RotationNR;
import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR;
import com.neuronrobotics.sdk.common.DeviceManager;
import com.neuronrobotics.sdk.common.Log;
import com.neuronrobotics.sdk.util.ThreadUtil;
import javafx.application.Platform;
import javafx.scene.control.*;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.RowConstraints;
import javafx.stage.Stage;
import net.java.games.input.Component;
import net.java.games.input.Controller;
import org.reactfx.util.FxTimer;
import java.lang.Thread.UncaughtExceptionHandler;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import javax.management.RuntimeErrorException;
public class JogWidget extends GridPane implements ITaskSpaceUpdateListenerNR, IOnTransformChange,IJInputEventListener {
double defauletSpeed=0.05;
private AbstractKinematicsNR kin;
private MobileBase mobilebase=null;
Button px = new Button("", AssetFactory.loadIcon("Plus-X.png"));
Button nx = new Button("",AssetFactory.loadIcon("Minus-X.png"));
Button py = new Button("",AssetFactory.loadIcon("Plus-Y.png"));
Button ny = new Button("",AssetFactory.loadIcon("Minus-Y.png"));
Button pz = new Button("",AssetFactory.loadIcon("Plus-Z.png"));
Button nz = new Button("",AssetFactory.loadIcon("Minus-Z.png"));
Button home = new Button("",AssetFactory.loadIcon("Home.png"));
Button game = new Button("Add Game Controller",AssetFactory.loadIcon("Add-Game-Controller.png"));
Button conf = new Button("Configure...",AssetFactory.loadIcon("Configure-Game-Controller.png"));
TextField increment=new TextField(Double.toString(defauletSpeed));
TextField sec=new TextField("0.01");
private TransformWidget transform;
private BowlerJInputDevice gameController=null;
double x,y,rz,slider=0;
private boolean stop=true;
private jogThread jogTHreadHandle;
private String paramsKey;
private GridPane buttons;
private static ArrayList<JogWidget> allWidgets=new ArrayList<JogWidget>();
public JogWidget(AbstractKinematicsNR kinimatics){
allWidgets.add(this);
this.setKin(kinimatics);
if(MobileBase.class.isInstance(kinimatics)){
py = new Button("",AssetFactory.loadIcon("Rotation-Z.png"));
ny = new Button("",AssetFactory.loadIcon("Rotation-Neg-Z.png"));
}
getKin().addPoseUpdateListener(this);
px.setOnMousePressed( event -> {try {handle( (Button)event.getSource()); }catch(Throwable T) {T.printStackTrace();}});
nx.setOnMousePressed( event ->{try { handle( (Button)event.getSource() ); }catch(Throwable T) {T.printStackTrace();}});
py.setOnMousePressed( event ->{try { handle( (Button)event.getSource() ); }catch(Throwable T) {T.printStackTrace();}});
ny.setOnMousePressed( event -> {try {handle( (Button)event.getSource() ); }catch(Throwable T) {T.printStackTrace();}});
pz.setOnMousePressed( event -> {try {handle( (Button)event.getSource() ); }catch(Throwable T) {T.printStackTrace();}});
nz.setOnMousePressed( event -> {try {handle( (Button)event.getSource() ); }catch(Throwable T) {T.printStackTrace();}});
home.setOnMousePressed( event -> {try {handle( (Button)event.getSource() ); }catch(Throwable T) {T.printStackTrace();}});
px.setOnMouseReleased( event -> {try {handle( (Button)event.getSource() ); }catch(Throwable T) {T.printStackTrace();}});
nx.setOnMouseReleased( event -> {try {handle( (Button)event.getSource() ); }catch(Throwable T) {T.printStackTrace();}});
py.setOnMouseReleased( event -> {try {handle( (Button)event.getSource() ); }catch(Throwable T) {T.printStackTrace();}});
ny.setOnMouseReleased( event -> {try {handle( (Button)event.getSource() ); }catch(Throwable T) {T.printStackTrace();}});
pz.setOnMouseReleased( event -> {try {handle( (Button)event.getSource() ); }catch(Throwable T) {T.printStackTrace();}});
nz.setOnMouseReleased( event -> {try {handle( (Button)event.getSource() ); }catch(Throwable T) {T.printStackTrace();}});
home.setOnMouseReleased( event -> {try {handle( (Button)event.getSource() ); }catch(Throwable T) {T.printStackTrace();}});
game.setOnAction(event -> {
if(getGameController() == null){
setGameController((BowlerJInputDevice) DeviceManager.getSpecificDevice(BowlerJInputDevice.class, "jogController"));
if(getGameController()==null){
ConnectionManager.onConnectGamePad("jogController");
setGameController((BowlerJInputDevice) DeviceManager.getSpecificDevice(BowlerJInputDevice.class, "jogController"));
}
}else{
RemoveGameController();
}
});
conf.setOnAction(event -> {
if(getGameController() != null){
runControllerMap();
}
});
buttons = new GridPane();
buttons.getColumnConstraints().add(new ColumnConstraints(80)); // column 1 is 75 wide
buttons.getColumnConstraints().add(new ColumnConstraints(80)); // column 2 is 300 wide
buttons.getColumnConstraints().add(new ColumnConstraints(80)); // column 2 is 100 wide
buttons.getRowConstraints().add(new RowConstraints(40)); //
buttons. getRowConstraints().add(new RowConstraints(40)); //
buttons. getRowConstraints().add(new RowConstraints(40)); //
buttons.getRowConstraints().add(new RowConstraints(40)); //
buttons.add( py,
0,
1);
buttons.add( home,
1,
1);
buttons.add( ny,
2,
1);
buttons.add( px,
1,
0);
buttons.add( nx,
1,
2);
buttons.add( increment,
0,
3);
buttons.add( new Label("m/s"),
1,
3);
buttons.add( sec,
2,
3);
buttons.add( new Label("sec"),
3,
3);
if(!MobileBase.class.isInstance(kinimatics)){
buttons.add( pz,
3,
0);
buttons.add( nz,
3,
1);
}
add( buttons,
0,
0);
setTransform(new TransformWidget("Current Pose", getKin().getCurrentPoseTarget(), this));
Accordion advancedPanel = new Accordion();
advancedPanel.getPanes().add(new TitledPane("Current Position", getTransform()));
add( advancedPanel,
0,
1);
jogTHreadHandle = new jogThread();
jogTHreadHandle.start();
controllerLoop();
}
private BowlerJInputDevice RemoveGameController() {
BowlerJInputDevice stale = getGameController();
getGameController().removeListeners(this);
game.setText("Add Game Controller");
setGameController(null);
return stale;
}
private void handle(final Button button ){
if(!button.isPressed()){
// button released
//Log.info(button.getText()+" Button released ");
try {
TransformNR t = getKin().getCurrentTaskSpaceTransform();
getKin().setDesiredTaskSpaceTransform(t, 0);
} catch (Exception e) {
e.printStackTrace();
}
if(button == px){
x=0;
}
if(button == nx){
x=0;
}
if(mobilebase==null){
if(button == py){
y=0;
}
if(button == ny){
y=0;
}
}else{
if(button == py){
rz=0;
}
if(button == ny){
rz=0;
}
}
if(button == pz){
slider=0;
}
if(button == nz){
slider=0;
}
stop=true;
return;
}else{
Log.warning(button.getText()+" Button pressed ");
}
if(button == px){
x=1;
}
if(button == nx){
x=-1;
}
if(mobilebase==null){
if(button == py){
y=1;
}
if(button == ny){
y=-1;
}
}else{
if(button == py){
rz=1;
}
if(button == ny){
rz=-1;
}
}
if(button == pz){
slider=1;
}
if(button == nz){
slider=-1;
}
if(button == home){
home();
stop=true;
return;
}
stop=false;
controllerLoop();
}
public void home(){
if(getMobilebase()!=null){
getMobilebase().setGlobalToFiducialTransform(new TransformNR());
for(DHParameterKinematics c:getMobilebase().getAllDHChains()){
homeLimb(c);
}
}else{
homeLimb(getKin());
}
}
private void homeLimb(AbstractKinematicsNR c) {
double[] joints = c.getCurrentJointSpaceVector();
for (int i = 0; i < c.getNumberOfLinks(); i++) {
joints[i] = 0;
}
try {
c.setDesiredJointSpaceVector(joints, 0);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onTaskSpaceUpdate(AbstractKinematicsNR source, TransformNR pose) {
// TODO Auto-generated method stub
if(pose != null &&getTransform()!=null)
Platform.runLater(new Runnable() {
@Override
public void run() {
getTransform().updatePose(pose);
}
});
}
@Override
public void onTargetTaskSpaceUpdate(AbstractKinematicsNR source,
TransformNR pose) {
if(pose != null &&getTransform()!=null)
Platform.runLater(new Runnable() {
@Override
public void run() {
getTransform().updatePose(pose);
}
});
}
@Override
public void onTransformChaging(TransformNR newTrans) {
// TODO Auto-generated method stub
}
@Override
public void onTransformFinished(TransformNR newTrans) {
try {
getKin().setDesiredTaskSpaceTransform(newTrans, Double.parseDouble(sec.getText()));
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public AbstractKinematicsNR getKin() {
return kin;
}
public void setKin(AbstractKinematicsNR kin) {
if(!kin.isAvailable())
kin.connect();
if(MobileBase.class.isInstance(kin))
setMobilebase((MobileBase)kin);
this.kin = kin;
try {
kin.setDesiredTaskSpaceTransform( kin.calcHome(),0);
} catch (Exception e) {}
}
private void controllerLoop(){
//System.out.println("controllerLoop");
double seconds=.1;
if(getGameController()!=null || stop==false){
try{
seconds =Double.parseDouble(sec.getText());
if(!stop){
double inc;
try{
inc = Double.parseDouble(increment.getText())*1000*seconds;//convert to mm
}catch(Exception e){
inc=defauletSpeed;
Platform.runLater(() -> {
try{
increment.setText(Double.toString(defauletSpeed));
}catch(Exception ex){
ex.printStackTrace();
}
});
}
//double rxl=0;
double ryl=inc/20*slider;
double rzl=inc/2*rz;
TransformNR current = new TransformNR(0,0,0,new RotationNR( 0,rzl, 0));
current.translateX(inc*x);
current.translateY(inc*y);
current.translateZ(inc*slider);
try {
if(getMobilebase()==null){
current = getKin().getCurrentPoseTarget();
current.translateX(inc*x);
current.translateY(inc*y);
current.translateZ(inc*slider);
current.setRotation(new RotationNR());
TransformNR toSet = current.copy();
double toSeconds=seconds;
jogTHreadHandle.setToSet(toSet, toSeconds);
//Log.enableDebugPrint();
//System.out.println("Loop Jogging to: "+toSet);
}else{
TransformNR toSet = current.copy();
double toSeconds=seconds;
jogTHreadHandle.setToSet(toSet, toSeconds);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}catch(Exception e){
e.printStackTrace();
}
if(seconds<.01){
seconds=.01;
sec.setText(".01");
}
FxTimer.runLater(
Duration.ofMillis((int)(seconds*1000.0)) ,new Runnable() {
@Override
public void run() {
controllerLoop();
//System.out.println("Controller loop!");
}
});
}
}
private class jogThread extends Thread{
private boolean controlThreadRunning=false;
private TransformNR toSet;
private double toSeconds=.016;
public void run(){
setName("Jog Widget Set Drive Arc Command "+getKin().getScriptingName());
while(kin.isAvailable()){
//System.out.println("Jog loop");
if(controlThreadRunning){
if(getMobilebase()==null){
try {
//Log.enableDebugPrint();
//System.out.println("Jogging to: "+toSet);
getKin().setDesiredTaskSpaceTransform(toSet, toSeconds);
} catch (Exception e) {
e.printStackTrace();
//BowlerStudioController.highlightException(null, e);
}
}else{
//toSet.setZ(0);
try {
getMobilebase().DriveArc(toSet, toSeconds);
} catch (Exception e) {
e.printStackTrace();
//BowlerStudioController.highlightException(null, e);
}
}
controlThreadRunning=false;
}
ThreadUtil.wait((int) (toSeconds*1000));
}
new RuntimeException("Jog thread finished").printStackTrace();
}
public void setToSet(TransformNR toSet,double toSeconds) {
this.toSet = toSet.copy();
this.toSeconds = toSeconds;
controlThreadRunning=true;
}
}
@Override
public void onEvent(Component comp, net.java.games.input.Event event,
float value, String eventString) {
if(comp.getName().toLowerCase().contentEquals((String) ConfigurationDatabase.getObject(paramsKey, "jogKiny", "y")))
x=value;
if(comp.getName().toLowerCase().contentEquals((String) ConfigurationDatabase.getObject(paramsKey, "jogKinz", "rz")))
y=value;
if(comp.getName().toLowerCase().contentEquals((String) ConfigurationDatabase.getObject(paramsKey, "jogKinx", "x")))
rz=-value;
if(comp.getName().toLowerCase().contentEquals((String) ConfigurationDatabase.getObject(paramsKey, "jogKinslider", "slider")))
slider=-value;
if(Math.abs(x)<.01)
x=0;
if(Math.abs(y)<.01)
y=0;
if(Math.abs(rz)<.01)
rz=0;
if(Math.abs(slider)<.01)
slider=0;
if(x==0.0&&y==0.0 &&rz==0.0&&slider==0) {
//System.out.println("Stoping on="+comp.getName());
stop=true;
try {
getKin().setDesiredTaskSpaceTransform(getKin().getCurrentTaskSpaceTransform(), 0);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else
stop=false;
}
public MobileBase getMobilebase() {
return mobilebase;
}
public void setMobilebase(MobileBase mobilebase) {
this.mobilebase = mobilebase;
}
public BowlerJInputDevice getGameController() {
return gameController;
}
public void setGameController(BowlerJInputDevice gameController) {
this.gameController = gameController;
if(gameController!=null){
getGameController().clearListeners();
getGameController().addListeners(this);
game.setText("Remove Game Controller");
controllerLoop();
Controller hwController = gameController.getController();
paramsKey = hwController.getName();
HashMap<String, Object> map = ConfigurationDatabase.getParamMap(paramsKey);
boolean hasmap = false;
if(map.containsKey("jogKinx")&&
map.containsKey("jogKiny") &&
map.containsKey("jogKinz") &&
map.containsKey("jogKinslider")
){
hasmap=true;
}
if(!hasmap){
runControllerMap();
}
}
}
private void runControllerMap() {
Stage s = new Stage();
new Thread(){
public void run(){
JogTrainerWidget controller = new JogTrainerWidget(gameController);
try {
controller.start( s);
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
public TransformWidget getTransform() {
return transform;
}
public void setTransform(TransformWidget transform) {
this.transform = transform;
}
}

View File

@@ -0,0 +1,625 @@
package com.neuronrobotics.bowlerstudio.creature;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GitHub;
import org.reactfx.util.FxTimer;
import com.neuronrobotics.bowlerstudio.BowlerStudio;
import com.neuronrobotics.bowlerstudio.scripting.PasswordManager;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import com.neuronrobotics.bowlerstudio.vitamins.Vitamins;
import com.neuronrobotics.sdk.addons.kinematics.AbstractKinematicsNR;
import com.neuronrobotics.sdk.addons.kinematics.AbstractLink;
import com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration;
import com.neuronrobotics.sdk.addons.kinematics.LinkFactory;
import com.neuronrobotics.sdk.addons.kinematics.LinkType;
import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextInputDialog;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import java.time.Duration;
@SuppressWarnings("restriction")
public class LinkConfigurationWidget extends GridPane {
// private int index;
private LinkConfiguration conf;
private EngineeringUnitsSliderWidget zero;
private EngineeringUnitsSliderWidget lowerBound;
private EngineeringUnitsSliderWidget upperBound;
private AbstractLink activLink;
private MobileBaseCadManager manager;
private EngineeringUnitsSliderWidget setpointSLider;
double textToNum(TextField mass) {
try {
return Double.parseDouble(mass.getText().trim());
} catch (Throwable t) {
mass.setText("0");
return 0;
}
}
public LinkConfigurationWidget(LinkConfiguration congiuration, LinkFactory factory,
EngineeringUnitsSliderWidget slide, MobileBaseCadManager manager) {
// this.index = index;
// this.congiuration = congiuration;
conf = congiuration;
this.setpointSLider = slide;
this.manager = manager;
activLink = factory.getLink(conf);
getColumnConstraints().add(new ColumnConstraints(150)); // column 1 is 75 wide
getColumnConstraints().add(new ColumnConstraints(200)); // column 2 is 300 wide
getColumnConstraints().add(new ColumnConstraints(200)); // column 2 is 300 wide
setHgap(20);
TextField mass = new TextField(CreatureLab.getFormatted(conf.getMassKg()));
mass.setOnAction(event -> {
conf.setMassKg(textToNum(mass));
activLink.setTargetEngineeringUnits(0);
activLink.flush(0);
if (manager != null)
manager.generateCad();
});
TransformNR currentCentroid = conf.getCenterOfMassFromCentroid();
TextField massx = new TextField(CreatureLab.getFormatted(currentCentroid.getX()));
massx.setOnAction(event -> {
currentCentroid.setX(textToNum(massx));
conf.setCenterOfMassFromCentroid(currentCentroid);
;
activLink.setTargetEngineeringUnits(0);
activLink.flush(0);
if (manager != null)
manager.generateCad();
});
TextField massy = new TextField(CreatureLab.getFormatted(currentCentroid.getY()));
massy.setOnAction(event -> {
currentCentroid.setY(textToNum(massy));
conf.setCenterOfMassFromCentroid(currentCentroid);
;
activLink.setTargetEngineeringUnits(0);
activLink.flush(0);
if (manager != null)
manager.generateCad();
});
TextField massz = new TextField(CreatureLab.getFormatted(currentCentroid.getZ()));
massz.setOnAction(event -> {
currentCentroid.setZ(textToNum(massz));
conf.setCenterOfMassFromCentroid(currentCentroid);
;
activLink.setTargetEngineeringUnits(0);
activLink.flush(0);
if (manager != null)
manager.generateCad();
});
TextField scale = new TextField(CreatureLab.getFormatted(conf.getScale()));
scale.setOnAction(event -> {
conf.setScale(textToNum(scale));
activLink.setTargetEngineeringUnits(0);
activLink.flush(0);
if (manager != null)
manager.generateCad();
});
Button editShaft = new Button("Edit " + conf.getShaftSize());
editShaft.setOnAction(event -> {
new Thread() {
public void run() {
try {
String type = conf.getShaftType();
String id = conf.getShaftSize();
edit(type, id, Vitamins.getConfiguration(type, id));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
});
Button newShaft = new Button("New " + conf.getShaftType());
newShaft.setOnAction(event -> {
TextInputDialog d = new TextInputDialog("NewSize");
d.setTitle("Wizard for new " + conf.getShaftType());
d.setHeaderText("Enter th Side ID for a new " + conf.getShaftType());
d.setContentText("Size:");
// Traditional way to get the response value.
Optional<String> result = d.showAndWait();
if (result.isPresent()) {
// Create the custom dialog.
String id = result.get();
String type = conf.getShaftType();
new Thread() {
public void run() {
try {
test(type);
Vitamins.newVitamin(id, type);
edit(type, id, Vitamins.getConfiguration(type, conf.getShaftSize()));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
}
});
Button newHardware = new Button("New " + conf.getElectroMechanicalType());
Button editHardware = new Button("Edit " + conf.getElectroMechanicalSize());
final ComboBox<String> shaftSize = new ComboBox<>();
final ComboBox<String> shaftType = new ComboBox<>();
for (String s : Vitamins.listVitaminSizes(conf.getShaftType())) {
shaftSize.getItems().add(s);
}
shaftSize.setOnAction(event -> {
String motorsize = shaftSize.getSelectionModel().getSelectedItem();
String motortype = shaftType.getSelectionModel().getSelectedItem();
if (motorsize == null || motortype == null)
return;
conf.setShaftSize(motorsize);
conf.setShaftType(motortype);
setShaftSize(editShaft, newShaft, motorsize);
if (manager != null)
manager.generateCad();
});
shaftSize.getSelectionModel().select(conf.getShaftSize());
for (String vitaminsType : Vitamins.listVitaminTypes()) {
HashMap<String, Object> meta = Vitamins.getMeta(vitaminsType);
if (meta != null && meta.containsKey("shaft"))
shaftType.getItems().add(vitaminsType);
}
shaftType.setOnAction(event -> {
String selectedItem = shaftType.getSelectionModel().getSelectedItem();
setShaftType(editShaft, newShaft, shaftSize, selectedItem);
});
shaftType.getSelectionModel().select(conf.getShaftType());
final ComboBox<String> emHardwareType = new ComboBox<>();
final ComboBox<String> emHardwareSize = new ComboBox<>();
for (String s : Vitamins.listVitaminSizes(conf.getElectroMechanicalType())) {
emHardwareSize.getItems().add(s);
}
emHardwareSize.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
String motortype = emHardwareType.getSelectionModel().getSelectedItem();
String motorsize = emHardwareSize.getSelectionModel().getSelectedItem();
if (motorsize == null || motortype == null)
return;
conf.setElectroMechanicalType(motortype);
conf.setElectroMechanicalSize(motorsize);
newHardware.setText("New " + conf.getElectroMechanicalType());
editHardware.setText("Edit " + conf.getElectroMechanicalSize());
HashMap<String, Object> vitaminData = Vitamins.getConfiguration(conf.getElectroMechanicalType(),
conf.getElectroMechanicalSize());
System.out.println("New size " + vitaminData);
String shafttype = (String) vitaminData.get("shaftType");
String shaftsize = (String) vitaminData.get("shaftSize");
Platform.runLater(() -> {
setShaftType(editShaft, newShaft, shaftSize, shafttype);
FxTimer.runLater(Duration.ofMillis(20), () -> {
setShaftSize(editShaft, newShaft, shaftsize);
FxTimer.runLater(Duration.ofMillis(200), new Runnable() {
@Override
public void run() {
System.out.println("Settting shaft size: " + shaftsize + " of " + shafttype);
Platform.runLater(() -> shaftType.getSelectionModel().select(shafttype));
Platform.runLater(() -> shaftSize.getSelectionModel().select(shaftsize));
}
});
});
});
conf.setShaftSize(shaftsize);
conf.setShaftType(shafttype);
if (manager != null)
manager.generateCad();
}
});
emHardwareSize.getSelectionModel().select(conf.getElectroMechanicalSize());
for (String vitaminsType : Vitamins.listVitaminTypes()) {
HashMap<String, Object> meta = Vitamins.getMeta(vitaminsType);
if (meta != null && meta.containsKey("actuator"))
emHardwareType.getItems().add(vitaminsType);
}
emHardwareType.setOnAction(event -> {
String selectedItem = emHardwareType.getSelectionModel().getSelectedItem();
if (selectedItem == null)
return;
System.out.println("New hwType " + selectedItem);
emHardwareSize.getItems().clear();
for (String s : Vitamins.listVitaminSizes(selectedItem)) {
emHardwareSize.getItems().add(s);
}
newHardware.setText("New " + conf.getElectroMechanicalType());
editHardware.setText("Edit " + conf.getElectroMechanicalSize());
});
emHardwareType.getSelectionModel().select(conf.getElectroMechanicalType());
// Actuator editing
editHardware.setOnAction(event -> {
new Thread() {
public void run() {
try {
String type = conf.getElectroMechanicalType();
String id = conf.getElectroMechanicalSize();
edit(type, id, Vitamins.getConfiguration(type, id));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
});
newHardware.setOnAction(event -> {
TextInputDialog d = new TextInputDialog("NewSize");
d.setTitle("Wizard for new " + conf.getElectroMechanicalType());
d.setHeaderText("Enter th Side ID for a new " + conf.getElectroMechanicalType());
d.setContentText("Size:");
// Traditional way to get the response value.
Optional<String> result = d.showAndWait();
if (result.isPresent()) {
// Create the custom dialog.
String id = result.get();
String type = conf.getElectroMechanicalType();
new Thread() {
public void run() {
try {
test(type);
Vitamins.newVitamin(id, type);
edit(type, id, Vitamins.getConfiguration(type, conf.getElectroMechanicalSize()));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
}
});
TextField deviceName = new TextField(congiuration.getDeviceScriptingName());
deviceName.setOnAction(event -> {
conf.setDeviceScriptingName(deviceName.getText());
factory.refreshHardwareLayer(conf);
activLink = factory.getLink(conf);
System.out.println("Link device to " + conf.getDeviceScriptingName());
if (manager != null)
manager.generateCad();
});
add(new Text("Scale To Degrees "), 0, 0);
add(scale, 1, 0);
add(new Text("(unitless)"), 2, 0);
lowerBound = new EngineeringUnitsSliderWidget(new IOnEngineeringUnitsChange() {
@Override
public void onSliderMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) {
double eng = setLowerBound(newAngleDegrees);
activLink.setUseLimits(false);
activLink.setTargetEngineeringUnits(eng);
activLink.flush(0);
activLink.setUseLimits(true);
}
@Override
public void onSliderDoneMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) {
try {
activLink.setUseLimits(false);
activLink.setTargetEngineeringUnits(setLowerBound(newAngleDegrees) + 0.01);
activLink.flush(0);
activLink.setUseLimits(true);
if (manager != null)
manager.generateCad();
zero.setLowerBound(newAngleDegrees);
} catch (Exception ex) {
BowlerStudio.printStackTrace(ex);
}
}
}, conf.getLowerLimit() < 1 ? conf.getLowerLimit() : 1, // min
conf.getStaticOffset(), // max
conf.getLowerLimit(), // current
150, "device units", true);
upperBound = new EngineeringUnitsSliderWidget(new IOnEngineeringUnitsChange() {
@Override
public void onSliderMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) {
double eng = setUpperBound(newAngleDegrees - 0.00001);
activLink.setUseLimits(false);
activLink.setTargetEngineeringUnits(eng);
activLink.flush(0);
activLink.setUseLimits(true);
}
@Override
public void onSliderDoneMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) {
activLink.setUseLimits(false);
activLink.setTargetEngineeringUnits(setUpperBound(newAngleDegrees) - 0.00001);
activLink.flush(0);
activLink.setUseLimits(true);
zero.setUpperBound(newAngleDegrees);
if (manager != null)
manager.generateCad();
}
}, conf.getStaticOffset(), conf.getUpperLimit() > 180 ? conf.getUpperLimit() : 180, conf.getUpperLimit(), 150,
"device units", true);
zero = new EngineeringUnitsSliderWidget(new IOnEngineeringUnitsChange() {
@Override
public void onSliderMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) {
conf.setStaticOffset(newAngleDegrees);
activLink.setTargetEngineeringUnits(0);
activLink.flush(0);
}
@Override
public void onSliderDoneMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) {
setLowerBound(conf.getLowerLimit());
setUpperBound(conf.getUpperLimit());
setpointSLider.setValue(0);
activLink.setTargetEngineeringUnits(0);
activLink.flush(0);
upperBound.setLowerBound(newAngleDegrees);
lowerBound.setUpperBound(newAngleDegrees);
if (manager != null)
manager.generateCad();
}
}, conf.getLowerLimit(), conf.getUpperLimit(), conf.getStaticOffset(), 150, "device units", true);
final ComboBox<String> channel = new ComboBox<>();
for (int i = 0; i < 24; i++) {
channel.getItems().add(Integer.toString(i));
}
channel.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
conf.setHardwareIndex(Integer.parseInt(channel.getSelectionModel().getSelectedItem()));
factory.refreshHardwareLayer(conf);
activLink = factory.getLink(conf);
System.out.println("Link channel to " + conf.getTypeString());
if (manager != null)
manager.generateCad();
}
});
channel.getSelectionModel().select(conf.getHardwareIndex());
final ComboBox<String> comboBox = new ComboBox<>();
for (LinkType type : LinkType.values()) {
comboBox.getItems().add(type.getName());
}
comboBox.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
conf.setType(LinkType.fromString(comboBox.getSelectionModel().getSelectedItem()));
System.out.println("Link type changed to " + conf.getTypeString());
if (manager != null)
manager.generateCad();
}
});
comboBox.getSelectionModel().select(conf.getTypeString().toString());
add(new Text("Zero Degrees Value"), 0, 1);
add(zero, 1, 1);
add(new Text("Upper bound"), 0, 2);
add(upperBound, 1, 2);
add(new Text("Lower bound"), 0, 3);
add(lowerBound, 1, 3);
add(new Text("Link Type"), 0, 4);
add(comboBox, 1, 4);
add(new Text("Link Hardware Index"), 0, 5);
add(channel, 1, 5);
add(new Text("Device Scripting Name"), 0, 6);
add(deviceName, 1, 6);
add(new Text("Mass"), 0, 7);
add(mass, 1, 7);
add(new Text("Mass Centroid x"), 0, 8);
add(massx, 1, 8);
add(new Text("Mass Centroid y"), 0, 9);
add(massy, 1, 9);
add(new Text("Mass Centroid z"), 0, 10);
add(massz, 1, 10);
// link hardware
add(new Text("Hardware Type"), 0, 11);
add(emHardwareType, 1, 11);
add(new Text("Hardware Size"), 0, 12);
add(emHardwareSize, 1, 12);
add(editHardware, 2, 12);
add(newHardware, 1, 13);
// link shaft
add(new Text("Shaft Type"), 0, 14);
add(shaftType, 1, 14);
add(new Text("Shaft Size"), 0, 15);
add(shaftSize, 1, 15);
add(editShaft, 2, 15);
add(newShaft, 1, 16);
}
private double setUpperBound(double newAngleDegrees) {
conf.setUpperLimit(newAngleDegrees);
double eng = 0;
if (conf.getScale() < 0) {
eng = (activLink.getMinEngineeringUnits());
setpointSLider.setLowerBound(eng);
} else {
eng = (activLink.getMaxEngineeringUnits());
setpointSLider.setUpperBound(eng);
}
return eng;
}
private double setLowerBound(double newAngleDegrees) {
conf.setLowerLimit(newAngleDegrees);
double eng = 0;
if (conf.getScale() > 0) {
eng = (activLink.getMinEngineeringUnits());
setpointSLider.setLowerBound(eng);
} else {
eng = (activLink.getMaxEngineeringUnits());
setpointSLider.setUpperBound(eng);
}
return eng;
}
private void setShaftSize(Button editShaft, Button newShaft, String selectedItem) {
if (selectedItem == null) {
newShaft.setText("");
editShaft.setText("");
return;
}
editShaft.setText("Edit " + selectedItem);
}
private void setShaftType(Button editShaft, Button newShaft, final ComboBox<String> shaftSize,
String selectedItem) {
shaftSize.getItems().clear();
if (selectedItem == null)
return;
for (String s : Vitamins.listVitaminSizes(selectedItem)) {
shaftSize.getItems().add(s);
}
newShaft.setText("New " + selectedItem);
// editShaft.setText("Edit "+ conf.getShaftSize());
}
private void test(String type) throws IOException {
try {
Vitamins.saveDatabase(type);
} catch (org.eclipse.jgit.api.errors.TransportException e) {
GitHub github = PasswordManager.getGithub();
GHRepository repo = github.getUser("madhephaestus").getRepository("Hardware-Dimensions");
GHRepository forked = repo.fork();
System.out.println("Vitamins forked to " + forked.getGitTransportUrl());
Vitamins.setGitRepoDatabase(
"https://github.com/" + github.getMyself().getLogin() + "/Hardware-Dimensions.git");
System.out.println("Loading new files");
//
} catch (Exception ex) {
// ex.printStackTrace(MainController.getOut());
}
}
private void edit(String type, String id, HashMap<String, Object> startingConf) throws Exception {
System.out.println("Configuration for " + conf.getElectroMechanicalSize());
System.out.println("Saving to for " + id);
test(type);
Platform.runLater(() -> {
Alert dialog = new Alert(AlertType.CONFIRMATION);
dialog.setTitle("Edit Hardware Wizard");
dialog.setHeaderText("Update the hardare configurations");
// Create the username and password labels and fields.
GridPane grid = new GridPane();
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(20, 150, 10, 10));
HashMap<String, TextField> valueFields = new HashMap<>();
int row = 0;
for (Map.Entry<String, Object> entry : startingConf.entrySet()) {
TextField username = new TextField();
username.setText(entry.getValue().toString());
grid.add(new Label(entry.getKey()), 0, row);
grid.add(username, 1, row);
valueFields.put(entry.getKey(), username);
row++;
}
dialog.getDialogPane().setContent(grid);
Optional<ButtonType> r = dialog.showAndWait();
if (r.get() == ButtonType.OK) {
new Thread() {
public void run() {
for (Map.Entry<String, TextField> entry : valueFields.entrySet()) {
try {
Vitamins.setParameter(type, id, entry.getKey(), (Object) entry.getValue().getText());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
Vitamins.saveDatabase(type);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
}
});
}
}

View File

@@ -0,0 +1,280 @@
package com.neuronrobotics.bowlerstudio.creature;
import java.time.Duration;
import org.reactfx.util.FxTimer;
import com.neuronrobotics.bowlerstudio.assets.ConfigurationDatabase;
import com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice;
import com.neuronrobotics.sdk.addons.gamepad.IJInputEventListener;
import com.neuronrobotics.sdk.addons.kinematics.AbstractKinematicsNR;
import com.neuronrobotics.sdk.addons.kinematics.AbstractLink;
import com.neuronrobotics.sdk.addons.kinematics.DHLink;
import com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics;
import com.neuronrobotics.sdk.addons.kinematics.DhLinkType;
import com.neuronrobotics.sdk.addons.kinematics.IJointSpaceUpdateListenerNR;
import com.neuronrobotics.sdk.addons.kinematics.ILinkListener;
import com.neuronrobotics.sdk.addons.kinematics.JointLimit;
import com.neuronrobotics.sdk.addons.kinematics.math.RotationNR;
import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR;
import com.neuronrobotics.sdk.common.Log;
import com.neuronrobotics.sdk.pid.PIDLimitEvent;
import com.neuronrobotics.sdk.util.ThreadUtil;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Group;
import javafx.scene.control.Accordion;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.RowConstraints;
import javafx.scene.text.Text;
import net.java.games.input.Component;
import net.java.games.input.Controller;
import net.java.games.input.Event;
@SuppressWarnings("restriction")
public class LinkSliderWidget extends Group implements IJInputEventListener, IOnEngineeringUnitsChange, ILinkListener {
private AbstractKinematicsNR device;
private DHParameterKinematics dhdevice;
private int linkIndex;
private EngineeringUnitsSliderWidget setpoint;
private BowlerJInputDevice controller;
private jogThread jogTHreadHandle;
private double slider;
private boolean stop;
private double seconds;
private String paramsKey;
private AbstractLink abstractLink;
// private EngineeringUnitsSliderWidget slide;
public LinkSliderWidget(int linkIndex, DHLink dhlink, AbstractKinematicsNR d) {
this.linkIndex = linkIndex;
this.device = d;
if (DHParameterKinematics.class.isInstance(device)) {
dhdevice = (DHParameterKinematics) device;
}
abstractLink = device.getAbstractLink(linkIndex);
TextField name = new TextField(abstractLink.getLinkConfiguration().getName());
name.setMaxWidth(100.0);
name.setOnAction(event -> {
abstractLink.getLinkConfiguration().setName(name.getText());
});
setSetpoint(new EngineeringUnitsSliderWidget(this, abstractLink.getMinEngineeringUnits(),
abstractLink.getMaxEngineeringUnits(), device.getCurrentJointSpaceVector()[linkIndex], 180,
dhlink.getLinkType() == DhLinkType.ROTORY ? "degrees" : "mm"));
GridPane panel = new GridPane();
panel.getColumnConstraints().add(new ColumnConstraints(30)); // column 1
// is 75
// wide
panel.getColumnConstraints().add(new ColumnConstraints(120)); // column
// 1 is
// 75
// wide
panel.getColumnConstraints().add(new ColumnConstraints(120)); // column
// 2 is
// 300
// wide
panel.add(new Text("#" + linkIndex), 0, 0);
panel.add(name, 1, 0);
panel.add(getSetpoint(), 2, 0);
getChildren().add(panel);
abstractLink.addLinkListener(this);
// device.addJointSpaceListener(this);
}
public void setUpperBound(double newBound) {
getSetpoint().setUpperBound(newBound);
}
public void setLowerBound(double newBound) {
getSetpoint().setLowerBound(newBound);
}
// public void changed(ObservableValue<? extends Boolean> observableValue,
// Boolean wasChanging,
// Boolean changing) {
//
// }
//
// @Override
// public void onJointSpaceUpdate(AbstractKinematicsNR source, double[] joints)
// {
//
// try {
// setpoint.setValue(joints[linkIndex]);
// } catch (ArrayIndexOutOfBoundsException ex) {
// return;
// }
//
//
// }
//
// @Override
// public void onJointSpaceTargetUpdate(AbstractKinematicsNR source, double[]
// joints) {
// // TODO Auto-generated method stub
// System.out.println("targe update");
// }
//
// @Override
// public void onJointSpaceLimit(AbstractKinematicsNR source, int axis,
// JointLimit event) {
// // TODO Auto-generated method stub
// System.out.println("limit update");
//
// }
private void controllerLoop() {
seconds = .1;
if (getGameController() != null || stop == false) {
if (!stop) {
jogTHreadHandle.setToSet(slider + getSetpoint().getValue(), seconds);
}
FxTimer.runLater(Duration.ofMillis((int) (seconds * 1000.0)), new Runnable() {
@Override
public void run() {
controllerLoop();
}
});
}
}
private class jogThread extends Thread {
private boolean controlThreadRunning = false;
private double toSeconds = seconds;
private double newValue;
public void run() {
setName("Jog Link Slider");
while (device.isAvailable()) {
if (controlThreadRunning) {
try {
device.setDesiredJointAxisValue(linkIndex, newValue, toSeconds);
getSetpoint().setValue(newValue);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
controlThreadRunning = false;
}
ThreadUtil.wait((int) (toSeconds * 1000));
}
}
public void setToSet(double newValue, double toSeconds) {
this.newValue = newValue;
this.toSeconds = toSeconds;
controlThreadRunning = true;
}
}
public void setGameController(BowlerJInputDevice controller) {
this.controller = controller;
if (controller != null && jogTHreadHandle == null) {
jogTHreadHandle = new jogThread();
jogTHreadHandle.start();
}
if (controller != null) {
Controller hwController = controller.getController();
paramsKey = hwController.getName();
System.err.println("Controller key: " + paramsKey);
getGameController().clearListeners();
getGameController().addListeners(this);
controllerLoop();
}
}
public BowlerJInputDevice getGameController() {
return controller;
}
@Override
public void onEvent(Component comp, net.java.games.input.Event event, float value, String eventString) {
if (comp.getName().toLowerCase()
.contentEquals((String) ConfigurationDatabase.getObject(paramsKey, "jogLink", "x")))
slider = -value;
if (Math.abs(slider) < .01)
slider = 0;
if (slider == 0) {
// System.out.println("Stoping on="+comp.getName());
stop = true;
} else
stop = false;
}
@Override
public void onSliderMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) {
// TODO Auto-generated method stub
try {
if (newAngleDegrees > device.getAbstractLink(linkIndex).getMaxEngineeringUnits()) {
newAngleDegrees=device.getAbstractLink(linkIndex).getMaxEngineeringUnits();
}
if(newAngleDegrees <device.getAbstractLink(linkIndex).getMinEngineeringUnits()) {
newAngleDegrees=device.getAbstractLink(linkIndex).getMinEngineeringUnits();
}
device.setDesiredJointAxisValue(linkIndex, newAngleDegrees, 0);
} catch (Exception e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
;
}
@Override
public void onSliderDoneMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) {
}
@Override
public void onLinkLimit(AbstractLink arg0, PIDLimitEvent arg1) {
// TODO Auto-generated method stub
}
@Override
public void onLinkPositionUpdate(AbstractLink arg0, double arg1) {
// TODO Auto-generated method stub
try {
getSetpoint().setValue(arg1);
} catch (ArrayIndexOutOfBoundsException ex) {
return;
}
}
public EngineeringUnitsSliderWidget getSetpoint() {
return setpoint;
}
public void setSetpoint(EngineeringUnitsSliderWidget setpoint) {
this.setpoint = setpoint;
}
}

View File

@@ -0,0 +1,109 @@
package com.neuronrobotics.bowlerstudio.creature;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import net.miginfocom.swing.MigLayout;
import com.neuronrobotics.replicator.driver.NRPrinter;
import com.neuronrobotics.replicator.driver.StateBasedControllerConfiguration;
import com.neuronrobotics.sdk.addons.kinematics.AbstractKinematicsNR;
//import com.neuronrobotics.sdk.addons.kinematics.gui.SampleGuiNR;
public class PrinterConfiguration extends JPanel {
/**
*
*/
private static final long serialVersionUID = -1890177802795201269L;
//private SampleGuiNR gui = new SampleGuiNR();
private StateBasedControllerConfiguration state;
private JTextField kp = new JTextField(10);
private JTextField ki = new JTextField(10);
private JTextField kd = new JTextField(10);
private JTextField vkp = new JTextField(10);
private JTextField vkd = new JTextField(10);
private JTextField mmPos = new JTextField(10);
private JTextField maxVel = new JTextField(10);
private JTextField baseRad = new JTextField(10);
private JTextField EErad = new JTextField(10);
private JTextField maxz = new JTextField(10);
private JTextField minz = new JTextField(10);
private JTextField rodlen = new JTextField(10);
private JCheckBox hardPos = new JCheckBox("Use Hard Positioning");
private JButton update=new JButton("Update");
private NRPrinter printer;
private JPanel controls;
public PrinterConfiguration(){
setLayout(new MigLayout());
controls = new JPanel(new MigLayout());
controls.add(new JLabel("kP"));controls.add(kp,"wrap");
controls.add(new JLabel("kI"));controls.add(ki,"wrap");
controls.add(new JLabel("kD"));controls.add(kd,"wrap");
controls.add(new JLabel("VkP"));controls.add(vkp,"wrap");
controls.add(new JLabel("VkD"));controls.add(vkd,"wrap");
controls.add(new JLabel("Resolution (mm)"));controls.add(mmPos,"wrap");
controls.add(new JLabel("Maximum Velocity (mm/s)"));controls.add(maxVel,"wrap");
controls.add(new JLabel("Base Radius(mm)"));controls.add(baseRad,"wrap");
controls.add(new JLabel("End Effector Radius(mm)"));controls.add(EErad,"wrap");
controls.add(new JLabel("Maximum Z(mm)"));controls.add(maxz,"wrap");
controls.add(new JLabel("Minimum Z(mm)"));controls.add(minz,"wrap");
controls.add(new JLabel("Rod Length(mm)"));controls.add(rodlen,"wrap");
controls.add(hardPos,"wrap");
controls.add(update,"wrap");
update.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
state.setkP(Double.parseDouble(kp.getText()));
state.setkI(Double.parseDouble(ki.getText()));
state.setkD(Double.parseDouble(kd.getText()));
state.setvKP(Double.parseDouble(vkp.getText()));
state.setvKD(Double.parseDouble(vkd.getText()));
state.setMmPositionResolution(Double.parseDouble(mmPos.getText()));
state.setMaximumMMperSec(Double.parseDouble(maxVel.getText()));
state.setBaseRadius(Double.parseDouble(baseRad.getText()));
state.setEndEffectorRadius(Double.parseDouble(EErad.getText()));
state.setMaxZ(Double.parseDouble(maxz.getText()));
state.setMinZ(Double.parseDouble(minz.getText()));
state.setRodLength(Double.parseDouble(rodlen.getText()));
state.setUseHardPositioning(hardPos.isSelected());
printer.setStateBasedControllerConfiguration(state);
}
});
}
public void setKinematicsModel(AbstractKinematicsNR p) {
// gui.setKinematicsModel(p);
// if(NRPrinter.class.isInstance(p)){
// this.printer = (NRPrinter)p;
// state = printer.getStateBasedControllerConfiguration();
// kp.setText(Double.toString(state.getkP()));
// ki.setText(Double.toString(state.getkI()));
// kd.setText(Double.toString(state.getkD()));
// vkp.setText(Double.toString(state.getvKP()));
// vkd.setText(Double.toString(state.getvKD()));
// mmPos.setText(Double.toString(state.getMmPositionResolution()));
// maxVel.setText(Double.toString(state.getMaximumMMperSec()));
// baseRad.setText(Double.toString(state.getBaseRadius()));
// EErad.setText(Double.toString(state.getEndEffectorRadius()));
// maxz.setText(Double.toString(state.getMaxZ()));
// minz.setText(Double.toString(state.getMinZ()));
// rodlen.setText(Double.toString(state.getRodLength()));
// hardPos.setSelected(state.isUseHardPositioning());
// add(controls,"wrap");
// }
// add(gui,"wrap");
}
}

View File

@@ -0,0 +1,183 @@
package com.neuronrobotics.bowlerstudio.creature;
import Jama.Matrix;
import com.neuronrobotics.bowlerstudio.threed.BowlerStudio3dEngine;
import com.neuronrobotics.sdk.addons.kinematics.math.RotationNR;
import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR;
import com.neuronrobotics.sdk.common.Log;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.TextField;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
public class TransformWidget extends GridPane implements IOnEngineeringUnitsChange, EventHandler<ActionEvent> {
private IOnTransformChange onChange;
//EngineeringUnitsSliderWidget rw;
private EngineeringUnitsSliderWidget tilt;
private EngineeringUnitsSliderWidget elevation;
private EngineeringUnitsSliderWidget azimeth;
private EngineeringUnitsSliderWidget tx;
private EngineeringUnitsSliderWidget ty;
private EngineeringUnitsSliderWidget tz;
// private TextField tx;
// private TextField ty;
// private TextField tz;
private TransformNR initialState;
public TransformWidget(String title, TransformNR is, IOnTransformChange onChange){
this.initialState = is;
this.onChange = onChange;
// tx = new TextField(CreatureLab.getFormatted(initialState.getX()));
// ty = new TextField(CreatureLab.getFormatted(initialState.getY()));
// tz = new TextField(CreatureLab.getFormatted(initialState.getZ()));
// tx.setOnAction(this);
// ty.setOnAction(this);
// tz.setOnAction(this);
tx = new EngineeringUnitsSliderWidget(this, initialState.getX(), 100,"mm");
ty = new EngineeringUnitsSliderWidget(this, initialState.getY(), 100,"mm");
tz = new EngineeringUnitsSliderWidget(this, initialState.getZ(), 100,"mm");
RotationNR rot = initialState.getRotation();
double t=0;
try{
t=Math.toDegrees(rot.getRotationTilt());
}catch(Exception ex){
ex.printStackTrace();
}
double e=0;
try{
e=Math.toDegrees(rot.getRotationElevation());
}catch(Exception ex){
ex.printStackTrace();
}
double a=0;
try{
a=Math.toDegrees(rot.getRotationAzimuth());
}catch(Exception ex){
ex.printStackTrace();
}
tilt = new EngineeringUnitsSliderWidget(this, -179.99, 179.99, t, 100,"degrees");
elevation = new EngineeringUnitsSliderWidget(this, -89.99, 89.99, e, 100,"degrees");
azimeth = new EngineeringUnitsSliderWidget(this, -179.99, 179.99, a, 100,"degrees");
tilt.setAllowResize(false);
elevation.setAllowResize(false);
azimeth.setAllowResize(false);
getColumnConstraints().add(new ColumnConstraints(30)); // translate text
getColumnConstraints().add(new ColumnConstraints(200)); // translate values
getColumnConstraints().add(new ColumnConstraints(60)); // units
getColumnConstraints().add(new ColumnConstraints(60)); // rotate text
setHgap(20);// gab between elements
add( new Text(title),
1, 0);
// add( new Text("(r)W"),
// 3, 0);
// add( rw,
// 4, 0);
// These all seem out of order here, but it is because the
// screen is rotating the orenation of this interface from BowlerStudio3dEngine.getOffsetforvisualization()
//X line
add( new Text("X"),
0, 1);
add( tx,
1, 1);
add( new Text("Tilt"),
3, 1);
add( tilt,
4, 1);
//Y line
add( new Text("Y"),
0, 2);
add( ty,
1, 2);
add( new Text("Elevation"),
3, 2);
add( elevation,
4, 2);
//Z line
add( new Text("Z"),
0, 3);
add( tz,
1, 3);
add( new Text("Azimuth"),
3, 3);
add( azimeth,
4, 3);
}
private TransformNR getCurrent(){
TransformNR tmp = new TransformNR(
tx.getValue(),
ty.getValue(),
tz.getValue(),
new RotationNR(
tilt.getValue(),
azimeth.getValue(),
elevation.getValue()
));
return tmp;
}
@Override
public void onSliderMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) {
onChange.onTransformChaging(getCurrent());
}
@Override
public void onSliderDoneMoving(EngineeringUnitsSliderWidget source,
double newAngleDegrees) {
handle(null);
}
@Override
public void handle(ActionEvent event) {
onChange.onTransformChaging(getCurrent());
onChange.onTransformFinished(getCurrent());
}
public void updatePose(TransformNR p) {
TransformNR pose = p;
tx.setValue(pose.getX());
ty.setValue(pose.getY());
tz.setValue(pose.getZ());
RotationNR rot = pose.getRotation();
double t=0;
try{
t=Math.toDegrees(rot.getRotationTilt());
}catch(Exception ex){
ex.printStackTrace();
}
double e=0;
try{
e=Math.toDegrees(rot.getRotationElevation());
}catch(Exception ex){
ex.printStackTrace();
}
double a=0;
try{
a=Math.toDegrees(rot.getRotationAzimuth());
}catch(Exception ex){
ex.printStackTrace();
}
tilt.setValue(t);
elevation .setValue(e);
azimeth .setValue(a);
}
}

View File

@@ -0,0 +1,111 @@
package com.neuronrobotics.bowlerstudio.scripting;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.control.PasswordField;
import javafx.stage.Stage;
public class GithubLoginFX implements javafx.fxml.Initializable {
@FXML
private TextField username;
@FXML PasswordField password;
private boolean done=false;
private String [] creds = new String[]{"",""};
private Stage stage;
private Parent root;
private Scene scene;
@Override
public void initialize(URL location, ResourceBundle resources) {
reset();
}
public void reset(){
done=false;
setCreds(new String[]{"",""});
password.clear();
getUsername().clear();
}
@FXML public void anonMode() {
setCreds(null);
try {
// this should make anon mode stick
ScriptingEngine.setupAnyonmous();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finish();
}
private void finish(){
stage.close();
stage.hide();
done=true;
}
@FXML public void login() {
getCreds()[0]= getUsername().getText();
getCreds()[1]= password.getText();
if(getCreds()[0]==null||getCreds()[1]==null){
setCreds(null);
}else if(getCreds()[0].equals("")||getCreds()[1].equals("")){
setCreds(null);
}
finish();
}
@FXML public void focusOnPw() {
password.requestFocus();
}
public boolean isDone() {
return done;
}
public void setDone(boolean done) {
this.done = done;
}
public String [] getCreds() {
return creds;
}
public void setCreds(String [] creds) {
this.creds = creds;
}
public void setStage(Stage stage, Parent root) {
this.stage = stage;
if(this.root==null){
this.root = root;
scene= new Scene(root);
}
stage.setScene(scene);
}
public TextField getUsername() {
return username;
}
public void setUsername(TextField username) {
this.username = username;
}
}

View File

@@ -0,0 +1,16 @@
package com.neuronrobotics.bowlerstudio.scripting;
import java.io.File;
import groovy.lang.GroovyShell;
import groovy.lang.Script;
public interface IScriptEventListener {
void onScriptFinished( Object result,Object pervious, File source);
void onScriptChanged(String previous, String current, File source);
void onScriptError( Throwable except, File source);
}

View File

@@ -0,0 +1,569 @@
package com.neuronrobotics.bowlerstudio.scripting;
import com.neuronrobotics.bowlerstudio.BowlerStudio;
import com.neuronrobotics.bowlerstudio.BowlerStudioController;
import com.neuronrobotics.bowlerstudio.ConnectionManager;
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.bowlerstudio.util.FileChangeWatcher;
//import com.neuronrobotics.imageprovider.OpenCVImageProvider;
import com.neuronrobotics.nrconsole.util.CommitWidget;
import com.neuronrobotics.nrconsole.util.FileSelectionFactory;
import com.neuronrobotics.sdk.common.Log;
import com.neuronrobotics.sdk.util.IFileChangeListener;
import com.neuronrobotics.sdk.util.ThreadUtil;
import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Insets;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.FileChooser.ExtensionFilter;
import org.eclipse.jgit.api.Git;
import org.reactfx.util.FxTimer;
import java.awt.*;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.WatchEvent;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Scanner;
@SuppressWarnings("unused")
public class ScriptingFileWidget extends BorderPane implements
IFileChangeListener {
private boolean running = false;
private Thread scriptRunner = null;
private Dimension codeDimentions = new Dimension(1168, 768);
//Label fileLabel = new Label();
private Object scriptResult;
private String codeText="";
private ArrayList<IScriptEventListener> listeners = new ArrayList<>();
private Button runfx = new Button("Run");
private Button publish = new Button("Publish");
private String addr;
boolean loadGist = false;
private ScriptingWidgetType type;
final TextField fileListBox = new TextField();
final TextField fileNameBox = new TextField();
private File currentFile = null;
private HBox controlPane;
private String currentGist;
private boolean updateneeded = false;
private IScriptingLanguage langaugeType;
private ImageView image=new ImageView();
public ScriptingFileWidget(File currentFile) throws IOException {
this(ScriptingWidgetType.FILE);
this.currentFile = currentFile;
loadCodeFromFile(currentFile);
boolean isOwnedByLoggedInUser= ScriptingEngine.checkOwner(currentFile);
publish.setDisable(!isOwnedByLoggedInUser);
runfx.setGraphic(AssetFactory.loadIcon("Run.png"));
publish.setGraphic(AssetFactory.loadIcon("Publish.png"));
try {
image.setImage(AssetFactory.loadAsset("Script-Tab-"+ScriptingEngine.getShellType(currentFile.getName())+".png"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void startStopAction(){
runfx.setDisable(true);
if (running)
stop();
else
start();
runfx.setDisable(false);
}
private ScriptingFileWidget(ScriptingWidgetType type) {
this.type = type;
runfx.setOnAction(e -> {
new Thread(){
public void run(){
if(langaugeType.getIsTextFile())
save();
//do not attempt to save no binary files
startStopAction();
}
}.start();
});
publish.setOnAction(e -> {
new Thread(()->{
save();
CommitWidget.commit(currentFile, getCode());
}).start();
});
// runsaveAs.setOnAction(e -> {
// new Thread(){
// public void run(){
// updateFile();
// save();
// }
// }.start();
//
// });
// String ctrlSave = "CTRL Save";
// fileLabel.setOnMouseEntered(e -> {
// Platform.runLater(() -> {
// ThreadUtil.wait(10);
// fileLabel.setText(currentFile.getAbsolutePath());
// });
// });
//
// fileLabel.setOnMouseExited(e -> {
// Platform.runLater(() -> {
// ThreadUtil.wait(10);
// fileLabel.setText(currentFile.getName());
// });
// });
// Set up the run controls and the code area
// The BorderPane has the same areas laid out as the
// BorderLayout layout manager
setPadding(new Insets(1, 0, 3, 10));
controlPane = new HBox(20);
double lengthScalar = fileNameBox.getFont().getSize()*1.5;
fileNameBox.textProperty().addListener((ov, prevText, currText) -> {
// Do this in a Platform.runLater because of Textfield has no padding at first time and so on
Platform.runLater(() -> {
Text text = new Text(currText);
text.setFont(fileNameBox.getFont()); // Set the same font, so the size is the same
double width = text.getLayoutBounds().getWidth() // This big is the Text in the TextField
+ fileNameBox.getPadding().getLeft() + fileNameBox.getPadding().getRight() // Add the padding of the TextField
+ lengthScalar; // Add some spacing
fileNameBox.setPrefWidth(width); // Set the width
fileNameBox.positionCaret(fileNameBox.getCaretPosition()); // If you remove this line, it flashes a little bit
});
});
fileListBox.textProperty().addListener((ov, prevText, currText) -> {
// Do this in a Platform.runLater because of Textfield has no padding at first time and so on
Platform.runLater(() -> {
Text text = new Text(currText);
text.setFont(fileListBox.getFont()); // Set the same font, so the size is the same
double width = text.getLayoutBounds().getWidth() // This big is the Text in the TextField
+ fileListBox.getPadding().getLeft() + fileListBox.getPadding().getRight() // Add the padding of the TextField
+ lengthScalar; // Add some spacing
fileListBox.setPrefWidth(width); // Set the width
fileListBox.positionCaret(fileListBox.getCaretPosition()); // If you remove this line, it flashes a little bit
});
});
controlPane.getChildren().add(runfx);
controlPane.getChildren().add(image);
controlPane.getChildren().add(publish);
controlPane.getChildren().add(new Label("file:"));
controlPane.getChildren().add(fileNameBox);
fileNameBox.setMaxWidth(Double.MAX_VALUE);
controlPane.getChildren().add(new Label("git:"));
controlPane.getChildren().add(fileListBox);
fileListBox.setMaxWidth(Double.MAX_VALUE);
controlPane.setMaxWidth(Double.MAX_VALUE);
// put the flowpane in the top area of the BorderPane
setTop(controlPane);
addIScriptEventListener(BowlerStudioController.getBowlerStudio());
reset();
}
private void reset() {
running = false;
Platform.runLater(() -> {
runfx.setText("Run");
runfx.setGraphic(AssetFactory.loadIcon("Run.png"));
runfx.setBackground(new Background(new BackgroundFill(Color.LIGHTGREEN, CornerRadii.EMPTY, Insets.EMPTY)));
});
}
public void addIScriptEventListener(IScriptEventListener l) {
if (!listeners.contains(l))
listeners.add(l);
}
public void removeIScriptEventListener(IScriptEventListener l) {
if (listeners.contains(l))
listeners.remove(l);
}
public void stop() {
// TODO Auto-generated method stub
reset();
if (scriptRunner != null)
while (scriptRunner.isAlive()) {
Log.debug("Interrupting");
ThreadUtil.wait(10);
try {
scriptRunner.interrupt();
scriptRunner.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void loadCodeFromFile(File currentFile) throws IOException {
if (!currentFile.exists()) {
currentFile.createNewFile();
}
setUpFile(currentFile);
if(!langaugeType.getIsTextFile())
setCode("Binary File");
else
setCode(new String(Files.readAllBytes(currentFile.toPath())));
}
private void start() {
try{
if(!currentFile.getName().contentEquals("csgDatabase.json")){
String[] gitID = ScriptingEngine.findGitTagFromFile(currentFile);
String remoteURI=gitID[0];
ArrayList<String> f = ScriptingEngine.filesInGit(remoteURI);
for (String s:f){
if(s.contentEquals("csgDatabase.json")){
File dbFile = ScriptingEngine.fileFromGit(gitID[0], s);
if(!CSGDatabase.getDbFile().equals(dbFile))
CSGDatabase.setDbFile(dbFile);
CSGDatabase.saveDatabase();
}
}
}
}catch(Exception e){
//ignore CSG database
e.printStackTrace();
}
BowlerStudio.clearConsole();
BowlerStudioController.clearHighlight();
try {
ScriptingEngine.setAutoupdate(false);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
running = true;
Platform.runLater(()->{
runfx.setText("Stop");
runfx.setGraphic(AssetFactory.loadIcon("Stop.png"));
runfx.setBackground(new Background(new BackgroundFill(Color.RED, CornerRadii.EMPTY, Insets.EMPTY)));
});
scriptRunner = new Thread() {
public void run() {
// String name;
// try{
// name = currentFile.getName();
// }catch (NullPointerException e){
// name="";
// }
try {
Object obj = ScriptingEngine.inlineFileScriptRun(currentFile, null);
for (IScriptEventListener l : listeners) {
l.onScriptFinished(obj, scriptResult,currentFile);
}
scriptResult = obj;
reset();
}
catch (groovy.lang.MissingPropertyException |org.python.core.PyException d){
Platform.runLater(() -> {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Variable missing error");
String message = "This script needs a variable defined before you use it: ";
String stackTrace = d.getMessage();
if(stackTrace.contains("dyio"))
message+="dyio";
else if(stackTrace.contains("camera"))
message+="camera";
else if(stackTrace.contains("gamepad"))
message+="gamepad";
else
message+=stackTrace;
alert.setHeaderText(message);
alert.showAndWait();
if(stackTrace.contains("dyio"))
ConnectionManager.addConnection();
// else if(stackTrace.contains("camera"))
// ConnectionManager.addConnection(new OpenCVImageProvider(0),"camera0");
else if(stackTrace.contains("gamepad"))
ConnectionManager.onConnectGamePad("gamepad");
reset();
});
BowlerStudioController.highlightException(currentFile, d);
}
catch (Throwable ex) {
System.err.println("Script exception of type= "+ex.getClass().getName());
try{
if (ex.getMessage().contains("sleep interrupted")) {
append("\n" + currentFile + " Interupted\n");
} else{
BowlerStudioController.highlightException(currentFile, new Exception(ex));
}
}catch(Exception e){
e.printStackTrace();
BowlerStudioController.highlightException(currentFile, new Exception(ex));
}
reset();
for (IScriptEventListener l : listeners) {
try {
l.onScriptError(new Exception(ex),currentFile);
}catch (Throwable e) {}
}
}
}
};
try {
scriptRunner.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void append(String s) {
System.out.println(s);
}
public String getGitRepo(){
return fileListBox.getText();
}
public String getGitFile(){
return fileNameBox.getText();
}
private void setUpFile(File f) {
currentFile = f;
String langType = ScriptingEngine.getShellType(currentFile.getName());
try {
image.setImage(AssetFactory.loadAsset("Script-Tab-"+ScriptingEngine.getShellType(currentFile.getName())+".png"));
} catch (Exception e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
langaugeType = ScriptingEngine.getLangaugesMap().get(langType);
//ScriptingEngine.setLastFile(f);
Git git;
try {
git = ScriptingEngine.locateGit(currentFile);
String remote= git.getRepository().getConfig().getString("remote", "origin", "url");
Platform.runLater(() -> {
//fileListBox.setMinWidth(remote.getBytes().length*10);
fileListBox.setText(remote);
//fileListBox.res
fileNameBox.setText(ScriptingEngine.findLocalPath(f, git));
// These values are display only, so if hte user tries to change them, they reset
// the use of text field for static dats is so the user cna copy the vlaues and use them in their scritpts
fileNameBox.textProperty().addListener((observable, oldValue, newValue) -> {
fileNameBox.setText(ScriptingEngine.findLocalPath(f, git));
});
fileListBox.textProperty().addListener((observable, oldValue, newValue) -> {
fileListBox.setText(remote);
});
git.close();
});
} catch (Exception e1) {
Platform.runLater(() -> {
fileListBox.setText("none");
fileListBox.setMinWidth(40);
fileNameBox.setText(f.getAbsolutePath());
// These values are display only, so if hte user tries to change them, they reset
// the use of text field for static dats is so the user cna copy the vlaues and use them in their scritpts
fileNameBox.textProperty().addListener((observable, oldValue, newValue) -> {
fileNameBox.setText(f.getAbsolutePath());
});
fileListBox.textProperty().addListener((observable, oldValue, newValue) -> {
fileListBox.setText("none");
});
});
e1.printStackTrace();
}
if(!langaugeType.getIsTextFile())
return;
try {
getWatcher().addIFileChangeListener(this);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void updateFile() {
File last = FileSelectionFactory.GetFile( currentFile==null?
ScriptingEngine.getWorkspace():
new File(ScriptingEngine.getWorkspace().getAbsolutePath()+"/"+currentFile.getName()),
true,
new ExtensionFilter("Save Script","*"));
if (last != null) {
setUpFile(last);
}
}
public void open() {
updateFile();
try {
setCode(new String(Files.readAllBytes(currentFile.toPath())));
} catch (IOException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
}
}
public void save() {
// TODO Auto-generated method stub
try {
System.out.println("Writing file contents");
BufferedWriter writer = new BufferedWriter(new FileWriter(
currentFile));
writer.write(getCode());
writer.close();
} catch (Exception ex) {
// ex.printStackTrace();
}
}
@Override
public void onFileChange(File fileThatChanged,
@SuppressWarnings("rawtypes") WatchEvent event) {
if(updateneeded)
return;
updateneeded=true;
try {
getWatcher().removeIFileChangeListener(this);
FxTimer.runLater(
Duration.ofMillis(500) ,new Runnable() {
@Override
public void run() {
updateneeded=false;
// TODO Auto-generated method stub
if (fileThatChanged.getAbsolutePath().contains(
currentFile.getAbsolutePath())) {
System.out.println("Code in " + fileThatChanged.getAbsolutePath()
+ " changed");
Platform.runLater(() -> {
try {
String content = new String(Files.readAllBytes(Paths
.get(fileThatChanged.getAbsolutePath())));
if(content.length()>2)// ensures tha the file contents never get wiped out on the user
setCode(content);
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
getWatcher().addIFileChangeListener(ScriptingFileWidget.this);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
} else {
// System.out.println("Othr Code in "+fileThatChanged.getAbsolutePath()+" changed");
}
}
});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String getCode() {
return codeText;
}
public void setCode(String string) {
String pervious = codeText;
codeText = string;
// System.out.println(codeText);
for (int i=0;i<listeners.size();i++ ) {
listeners.get(i).onScriptChanged(pervious, string,currentFile);
}
}
public String getFileName() {
if(currentFile!=null)
return currentFile.getName();
else
return "Web";
}
public FileChangeWatcher getWatcher() throws IOException {
return FileChangeWatcher.watch(currentFile);
}
public void close(){
try {
getWatcher().removeIFileChangeListener(this);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,419 @@
package com.neuronrobotics.bowlerstudio.scripting;
import com.neuronrobotics.bowlerstudio.BowlerStudio;
import com.neuronrobotics.bowlerstudio.BowlerStudioController;
import com.neuronrobotics.bowlerstudio.ConnectionManager;
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
//import com.neuronrobotics.imageprovider.OpenCVImageProvider;
import com.neuronrobotics.sdk.common.Log;
import com.neuronrobotics.sdk.util.ThreadUtil;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Insets;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.web.WebEngine;
import org.kohsuke.github.GHGist;
import org.kohsuke.github.GHGistFile;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@SuppressWarnings({ "unused", "restriction" })
public class ScriptingWebWidget extends BorderPane implements ChangeListener<Object> {
private boolean running = false;
private Thread scriptRunner = null;
private Dimension codeDimentions = new Dimension(1168, 768);
// Label fileLabel = new Label();
private Object scriptResult;
private String codeText = "";
private ArrayList<IScriptEventListener> listeners = new ArrayList<>();
private Button runfx = new Button("Run");;
private Button edit = new Button("Edit...");
private WebEngine engine;
private String addr;
boolean loadGist = false;
private ScriptingWidgetType type;
final ComboBox<String> fileListBox = new ComboBox<>();
private File currentFile = null;
private HBox controlPane;
private String currentGit;
private String currentGist;
private boolean isOwnedByLoggedInUser;
private ImageView image = new ImageView();
public ScriptingWebWidget(File currentFile, String currentGist, WebEngine engine)
throws IOException, InterruptedException {
this(ScriptingWidgetType.GIST);
runfx.setGraphic(AssetFactory.loadIcon("Run.png"));
edit.setGraphic(AssetFactory.loadIcon("Edit-Script.png"));
this.currentFile = currentFile;
try {
loadCodeFromGist(currentGist, engine);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void startStopAction() {
runfx.setDisable(true);
if (running)
stop();
else
start();
runfx.setDisable(false);
}
public ScriptingWebWidget(ScriptingWidgetType type) {
this.type = type;
runfx.setOnAction(e -> {
new Thread() {
public void run() {
startStopAction();
}
}.start();
});
edit.setOnAction(e -> {
new Thread() {
public void run() {
if (isOwnedByLoggedInUser)
BowlerStudio.createFileTab(currentFile);
else {
// todo fork git repo
System.out.println("Making Fork...");
GHGist newGist;
try {
newGist = ScriptingEngine.fork(currentGist);
Map<String, GHGistFile> fileMap = newGist.getFiles();
if (fileMap.size() == 1) {
String filename = (String) fileMap.keySet().toArray()[0];
String url = newGist.getGitPullUrl();
File file = ScriptingEngine.fileFromGit(url, filename);
BowlerStudio.createFileTab(file);
} else {
BowlerStudio.openUrlInNewTab(newGist.getHtmlUrl());
}
} catch (Exception e1) {
BowlerStudioController.highlightException(currentFile, e1);
}
}
}
}.start();
});
setPadding(new Insets(1, 0, 3, 10));
controlPane = new HBox(20);
controlPane.getChildren().add(runfx);
controlPane.getChildren().add(image);
controlPane.getChildren().add(edit);
controlPane.getChildren().add(fileListBox);
// put the flowpane in the top area of the BorderPane
setTop(controlPane);
addIScriptEventListener(BowlerStudioController.getBowlerStudio());
reset();
}
private void reset() {
running = false;
Platform.runLater(() -> {
runfx.setText("Run");
runfx.setGraphic(AssetFactory.loadIcon("Run.png"));
runfx.setBackground(new Background(new BackgroundFill(Color.LIGHTGREEN, CornerRadii.EMPTY, Insets.EMPTY)));
});
}
public void addIScriptEventListener(IScriptEventListener l) {
if (!listeners.contains(l))
listeners.add(l);
}
public void removeIScriptEventListener(IScriptEventListener l) {
if (listeners.contains(l))
listeners.remove(l);
}
public void stop() {
// TODO Auto-generated method stub
reset();
if (scriptRunner != null)
while (scriptRunner.isAlive()) {
Log.debug("Interrupting");
ThreadUtil.wait(10);
try {
scriptRunner.interrupt();
scriptRunner.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// public void loadCodeFromFile(File currentFile) throws IOException {
// if (!currentFile.exists()) {
// currentFile.createNewFile();
// }
// setUpFile(currentFile);
// setCode(new String(Files.readAllBytes(currentFile.toPath())));
// }
private void loadGitLocal(String id, String file) {
// System.out.println("Loading "+file+" from "+id);
String[] code;
try {
code = ScriptingEngine.codeFromGit(id, file);
if (code != null) {
setCode(code[0]);
currentFile = ScriptingEngine.fileFromGit(id, file);
}
isOwnedByLoggedInUser = ScriptingEngine.checkOwner(currentFile);
Platform.runLater(() -> {
if (isOwnedByLoggedInUser) {
edit.setText("Edit...");
edit.setGraphic(AssetFactory.loadIcon("Edit-Script.png"));
} else {
edit.setText("Make Copy");
edit.setGraphic(AssetFactory.loadIcon("Make-Copy-Script.png"));
}
});
try {
image.setImage(AssetFactory
.loadAsset("Script-Tab-" + ScriptingEngine.getShellType(currentFile.getName()) + ".png"));
} catch (Exception e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
System.out.println(sw.toString());
}
}
public void loadCodeFromGist(String a, WebEngine e) throws Exception {
// new Thread(()->{
addr = a;
engine = e;
loadGist = true;
fileListBox.valueProperty().removeListener(this);
Platform.runLater(() -> runfx.setDisable(true));
Platform.runLater(() -> edit.setDisable(true));
Platform.runLater(() -> fileListBox.getItems().clear());
List<String> gists = ScriptingEngine.getCurrentGist(addr, engine);
ArrayList<String> fileList;
if (!gists.isEmpty()) {
currentGist = gists.get(0);
currentGit = "https://gist.github.com/" + currentGist + ".git";
} else if (addr.contains("https://github.com/")) {
if (a.endsWith("/")) {
a = a.substring(0, a.length() - 1);
}
currentGit = a + ".git";
} else {
return;
}
ArrayList<String> tmp = ScriptingEngine.filesInGit(currentGit);
fileList = new ArrayList<>();
for (String s : tmp) {
if (!s.contains("csgDatabase.json"))// filter out configuration files from the list
fileList.add(s);
}
// for(String s:fileList){
// System.out.println("GITS: "+s);
// }
if (!fileList.isEmpty())
loadGitLocal(currentGit, fileList.get(0));
Platform.runLater(() -> {
for (String s : fileList) {
fileListBox.getItems().add(s);
}
if (!fileList.isEmpty()) {
fileListBox.setValue(fileList.get(0));
fileListBox.valueProperty().addListener(this);
Platform.runLater(() -> runfx.setDisable(false));
Platform.runLater(() -> edit.setDisable(false));
}
});
// }).start();
}
private void start() {
BowlerStudio.clearConsole();
try {
ScriptingEngine.setAutoupdate(true);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
running = true;
Platform.runLater(() -> {
runfx.setText("Stop");
runfx.setGraphic(AssetFactory.loadIcon("Stop.png"));
runfx.setBackground(new Background(new BackgroundFill(Color.RED, CornerRadii.EMPTY, Insets.EMPTY)));
});
scriptRunner = new Thread() {
public void run() {
String name;
try {
name = currentFile.getName();
} catch (NullPointerException e) {
name = "";
}
try {
Object obj = ScriptingEngine.inlineScriptRun(currentFile, null, ScriptingEngine.getShellType(name));
for (IScriptEventListener l : listeners) {
l.onScriptFinished(obj, scriptResult, currentFile);
}
scriptResult = obj;
reset();
} catch (groovy.lang.MissingPropertyException | org.python.core.PyException d) {
Platform.runLater(() -> {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Device missing error");
String message = "This script needs a device connected: ";
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
d.printStackTrace(pw);
String stackTrace = sw.toString();
if (stackTrace.contains("dyio"))
message += "dyio";
else if (stackTrace.contains("camera"))
message += "camera";
else if (stackTrace.contains("gamepad"))
message += "gamepad";
else
message += stackTrace;
alert.setHeaderText(message);
alert.setContentText("You need to connect it before running again");
alert.showAndWait();
if (stackTrace.contains("dyio"))
ConnectionManager.addConnection();
// else if (stackTrace.contains("camera"))
// ConnectionManager.addConnection(new OpenCVImageProvider(0), "camera0");
else if (stackTrace.contains("gamepad"))
ConnectionManager.onConnectGamePad("gamepad");
reset();
});
} catch (Throwable ex) {
System.err.println("Script exception of type= " + ex.getClass().getName());
Platform.runLater(() -> {
try {
if (ex.getMessage().contains("sleep interrupted")) {
append("\n" + currentFile + " Interupted\n");
} else {
BowlerStudio.printStackTrace(ex,currentFile);
}
} catch (Throwable e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
append("\n" + currentFile + " \n" + sw + "\n");
}
reset();
});
for (IScriptEventListener l : listeners) {
l.onScriptError(ex, currentFile);
}
BowlerStudio.printStackTrace(ex,currentFile);
}
}
};
try {
// if (loadGist)
// loadCodeFromGist(addr, engine);
scriptRunner.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void append(String s) {
System.out.println(s);
}
public String getCode() {
return codeText;
}
public void setCode(String string) {
String pervious = codeText;
codeText = string;
// System.out.println(codeText);
for (IScriptEventListener l : listeners) {
l.onScriptChanged(pervious, string, currentFile);
}
}
public String getFileName() {
if (currentFile != null)
return currentFile.getName();
else
return "Web";
}
@Override
public void changed(@SuppressWarnings("rawtypes") ObservableValue observable, Object oldValue, Object newValue) {
loadGitLocal(currentGit, (String) newValue);
}
}

View File

@@ -0,0 +1,8 @@
package com.neuronrobotics.bowlerstudio.scripting;
public enum ScriptingWidgetType {
FILE,
WEB,
GIST,
CREATURE
}

View File

@@ -0,0 +1,40 @@
package com.neuronrobotics.bowlerstudio.scripting;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import com.neuronrobotics.bowlerstudio.vitamins.Vitamins;
import eu.mihosoft.vrl.v3d.CSG;
public class StlLoader implements IScriptingLanguage {
@Override
public Object inlineScriptRun(File code, ArrayList<Object> args) throws Exception {
CSG sllLoaded = Vitamins.get(code);
return sllLoaded;
}
@Override
public Object inlineScriptRun(String code, ArrayList<Object> args) throws Exception {
throw new RuntimeException("This engine only supports files");
}
@Override
public String getShellType() {
// TODO Auto-generated method stub
return "Stl";
}
@Override
public boolean getIsTextFile() {
// TODO Auto-generated method stub
return false;
}
@Override
public ArrayList<String> getFileExtenetion() {
// TODO Auto-generated method stub
return new ArrayList<>(Arrays.asList("stl"));
}
}

View File

@@ -0,0 +1,121 @@
package com.neuronrobotics.bowlerstudio.tabs;
import java.util.ArrayList;
import com.neuronrobotics.bowlerstudio.BowlerStudioController;
import com.neuronrobotics.bowlerstudio.BowlerStudioModularFrame;
import com.neuronrobotics.bowlerstudio.creature.MobileBaseCadManager;
import com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics;
import com.neuronrobotics.sdk.addons.kinematics.MobileBase;
import com.neuronrobotics.sdk.common.BowlerAbstractConnection;
import com.neuronrobotics.sdk.common.BowlerAbstractDevice;
import com.neuronrobotics.sdk.common.IConnectionEventListener;
import com.neuronrobotics.sdk.common.IDeviceConnectionEventListener;
import com.sun.javafx.scene.control.behavior.TabPaneBehavior;
import com.sun.javafx.scene.control.skin.TabPaneSkin;
import eu.mihosoft.vrl.v3d.CSG;
import javafx.application.Platform;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.control.Tab;
public abstract class AbstractBowlerStudioTab extends Tab implements EventHandler<Event> {
private boolean active = false;
ArrayList<String> myNames =null;
private EventHandler<Event> localCopyOfEventHandler;
public abstract void onTabClosing();
public abstract String[] getMyNameSpaces();
public abstract void initializeUI(BowlerAbstractDevice pm);
public abstract void onTabReOpening();
public void setDevice(BowlerAbstractDevice pm){
myNames = new ArrayList<> ();
if(getMyNameSpaces().length>0){
for(int i=0;i<getMyNameSpaces().length;i++){
myNames.add(getMyNameSpaces()[i]);
}
if(!isMyNamespace(pm.getNamespaces())){
throw new RuntimeException("Device and namespaces are incompatible ");
}
}
setOnCloseRequest(this);
initializeUI(pm);
pm.addConnectionEventListener(new IDeviceConnectionEventListener() {
@Override
public void onDisconnect(BowlerAbstractDevice source) {
//if the device disconnects, close the tab
if(source ==pm && source !=null ) {
requestClose();
if(MobileBase.class.isInstance(pm)) {
MobileBase dev = (MobileBase)pm;
try {
for(CSG p:MobileBaseCadManager.get(dev).getBasetoCadMap().get(dev))
BowlerStudioController.removeObject(p);
for(DHParameterKinematics leg:dev.getAllDHChains())
for(CSG p:MobileBaseCadManager.get(dev).getDHtoCadMap().get(leg))
BowlerStudioController.removeObject(p);
}catch(Throwable e) {}
}
}
else {
// Not a bug, expected to ensure one device disconnects the rest of the dependent devices
// System.err.println("Device type was "+source.getClass()+" named "+source.getScriptingName()+" expected "+pm.getClass()+" named "+pm.getScriptingName());
// new Exception().printStackTrace();
}
}
@Override
public void onConnect(BowlerAbstractDevice source) {
// TODO Auto-generated method stub
}
});
}
public boolean isMyNamespace(ArrayList<String> names) {
if (names == null)
return false;
for(String s:names){
for(String m:myNames){
if(s.contains(m)){
setActive(true);
}
}
}
return isAcvive();
}
@Override
public void setOnCloseRequest(EventHandler<Event> value){
this.localCopyOfEventHandler = value;
super.setOnCloseRequest(value);
System.err.println(" A close requested for "+getText());
}
public void requestClose() {
BowlerStudioModularFrame.getBowlerStudioModularFrame().closeTab(this);
}
//
private TabPaneBehavior getBehavior() {
return ((TabPaneSkin) getTabPane().getSkin()).getBehavior();
}
public void setActive(boolean a){
active=a;
}
public boolean isAcvive() {
return active;
}
@Override
public void handle(Event event){
System.out.println("Closing "+getText());
onTabClosing();
}
}

View File

@@ -0,0 +1,46 @@
package com.neuronrobotics.bowlerstudio.tabs;
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.bowlerstudio.assets.BowlerStudioResourceFactory;
import com.neuronrobotics.sdk.common.BowlerAbstractDevice;
import com.neuronrobotics.sdk.dyio.DyIO;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
public class DyIOControl extends AbstractBowlerStudioTab {
private DyIO dyio;
DyIOPanel controller ;
@Override
public void onTabClosing() {
// TODO Auto-generated method stub
}
@Override
public String[] getMyNameSpaces() {
// TODO Auto-generated method stub
return new String[]{"neuronrobotics.dyio.*"};
}
@Override
public void initializeUI(BowlerAbstractDevice pm) {
this.dyio = (DyIO)pm;
setGraphic(AssetFactory.loadIcon("DyIO-Tab.png"));
setText(dyio.getScriptingName());
FXMLLoader fxmlLoader = BowlerStudioResourceFactory.getMainPanel();
Parent root = fxmlLoader.getRoot();
controller = fxmlLoader.getController();
controller.setDyIO(dyio);
setContent(root);
}
@Override
public void onTabReOpening() {
// TODO Auto-generated method stub
}
}

View File

@@ -0,0 +1,425 @@
package com.neuronrobotics.bowlerstudio.tabs;
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.bowlerstudio.assets.BowlerStudioResourceFactory;
import com.neuronrobotics.sdk.dyio.DyIO;
import com.neuronrobotics.sdk.dyio.DyIOChannel;
import com.neuronrobotics.sdk.dyio.DyIOChannelMode;
import com.neuronrobotics.sdk.util.ThreadUtil;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.util.Callback;
import org.reactfx.util.FxTimer;
import java.net.URL;
import java.time.Duration;
import java.util.ArrayList;
import java.util.ResourceBundle;
//import com.neuronrobotics.nrconsole.plugin.DyIO.DyIOConsole;
public class DyIOPanel implements Initializable {
private ArrayList<ComboBox<String>> channelTypeSelectors = new ArrayList<>() ;
private ArrayList<ImageView> channelButtonSelectors = new ArrayList<>() ;
private ArrayList<Label> channelValue = new ArrayList<>() ;
private ArrayList<Parent> controlWidgets = new ArrayList<>() ;
private ArrayList<Boolean> displayFlash = new ArrayList<>() ;
private DyIO dyio;
private boolean initialized=false;
@FXML ImageView chanButton23;
@FXML ImageView chanButton22;
@FXML ImageView chanButton21;
@FXML ImageView chanButton20;
@FXML ImageView chanButton19;
@FXML ImageView chanButton18;
@FXML ImageView chanButton17;
@FXML ImageView chanButton16;
@FXML ImageView chanButton15;
@FXML ImageView chanButton14;
@FXML ImageView chanButton13;
@FXML ImageView chanButton12;
@FXML ImageView chanButton11;
@FXML ImageView chanButton10;
@FXML ImageView chanButton9;
@FXML ImageView chanButton8;
@FXML ImageView chanButton7;
@FXML ImageView chanButton6;
@FXML ImageView chanButton5;
@FXML ImageView chanButton4;
@FXML ImageView chanButton3;
@FXML ImageView chanButton2;
@FXML ImageView chanButton1;
@FXML ImageView chanButton0;
@FXML ImageView background;
@FXML ComboBox<String> channelType23;
@FXML ComboBox<String> channelType22;
@FXML ComboBox<String> channelType21;
@FXML ComboBox<String> channelType20;
@FXML ComboBox<String> channelType19;
@FXML ComboBox<String> channelType18;
@FXML ComboBox<String> channelType17;
@FXML ComboBox<String> channelType16;
@FXML ComboBox<String> channelType15;
@FXML ComboBox<String> channelType14;
@FXML ComboBox<String> channelType13;
@FXML ComboBox<String> channelType12;
@FXML ComboBox<String> channelType11;
@FXML ComboBox<String> channelType10;
@FXML ComboBox<String> channelType9;
@FXML ComboBox<String> channelType8;
@FXML ComboBox<String> channelType7;
@FXML ComboBox<String> channelType6;
@FXML ComboBox<String> channelType5;
@FXML ComboBox<String> channelType4;
@FXML ComboBox<String> channelType3;
@FXML ComboBox<String> channelType2;
@FXML ComboBox<String> channelType1;
@FXML ComboBox<String> channelType0;
@FXML Circle centerled;
@FXML Label channelValue0;
@FXML Label channelValue1;
@FXML Label channelValue2;
@FXML Label channelValue3;
@FXML Label channelValue4;
@FXML Label channelValue5;
@FXML Label channelValue6;
@FXML Label channelValue7;
@FXML Label channelValue8;
@FXML Label channelValue9;
@FXML Label channelValue10;
@FXML Label channelValue11;
@FXML Label channelValue12;
@FXML Label channelValue13;
@FXML Label channelValue14;
@FXML Label channelValue15;
@FXML Label channelValue16;
@FXML Label channelValue17;
@FXML Label channelValue18;
@FXML Label channelValue19;
@FXML Label channelValue20;
@FXML Label channelValue21;
@FXML Label channelValue22;
@FXML Label channelValue23;
@FXML AnchorPane controlWidgetPanel;
public void setDyIO(DyIO d){
d.setServoPowerSafeMode(false);// disable the browout when using the UI
channelTypeSelectors.add( channelType0);
channelTypeSelectors.add( channelType1);
channelTypeSelectors.add( channelType2);
channelTypeSelectors.add( channelType3);
channelTypeSelectors.add( channelType4);
channelTypeSelectors.add( channelType5);
channelTypeSelectors.add( channelType6);
channelTypeSelectors.add( channelType7);
channelTypeSelectors.add( channelType8);
channelTypeSelectors.add( channelType9);
channelTypeSelectors.add( channelType10);
channelTypeSelectors.add( channelType11);
channelTypeSelectors.add( channelType12);
channelTypeSelectors.add( channelType13);
channelTypeSelectors.add( channelType14);
channelTypeSelectors.add( channelType15);
channelTypeSelectors.add( channelType16);
channelTypeSelectors.add( channelType17);
channelTypeSelectors.add( channelType18);
channelTypeSelectors.add( channelType19);
channelTypeSelectors.add( channelType20);
channelTypeSelectors.add( channelType21);
channelTypeSelectors.add( channelType22);
channelTypeSelectors.add( channelType23);
channelButtonSelectors.add( chanButton0);
channelButtonSelectors.add( chanButton1);
channelButtonSelectors.add( chanButton2);
channelButtonSelectors.add( chanButton3);
channelButtonSelectors.add( chanButton4);
channelButtonSelectors.add( chanButton5);
channelButtonSelectors.add( chanButton6);
channelButtonSelectors.add( chanButton7);
channelButtonSelectors.add( chanButton8);
channelButtonSelectors.add( chanButton9);
channelButtonSelectors.add( chanButton10);
channelButtonSelectors.add( chanButton11);
channelButtonSelectors.add( chanButton12);
channelButtonSelectors.add( chanButton13);
channelButtonSelectors.add( chanButton14);
channelButtonSelectors.add( chanButton15);
channelButtonSelectors.add( chanButton16);
channelButtonSelectors.add( chanButton17);
channelButtonSelectors.add( chanButton18);
channelButtonSelectors.add( chanButton19);
channelButtonSelectors.add( chanButton20);
channelButtonSelectors.add( chanButton21);
channelButtonSelectors.add( chanButton22);
channelButtonSelectors.add( chanButton23);
//Values
channelValue.add( channelValue0);
channelValue.add( channelValue1);
channelValue.add( channelValue2);
channelValue.add( channelValue3);
channelValue.add( channelValue4);
channelValue.add( channelValue5);
channelValue.add( channelValue6);
channelValue.add( channelValue7);
channelValue.add( channelValue8);
channelValue.add( channelValue9);
channelValue.add( channelValue10);
channelValue.add( channelValue11);
channelValue.add( channelValue12);
channelValue.add( channelValue13);
channelValue.add( channelValue14);
channelValue.add( channelValue15);
channelValue.add( channelValue16);
channelValue.add( channelValue17);
channelValue.add( channelValue18);
channelValue.add( channelValue19);
channelValue.add( channelValue20);
channelValue.add( channelValue21);
channelValue.add( channelValue22);
channelValue.add( channelValue23);
try {
background.setImage(AssetFactory.loadAsset("dyio/dyio-red2.png"));
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
this.dyio = d;
for (int i = 0; i < 24; i++) {
int index = i;
ObservableList<String> items = FXCollections.observableArrayList();
DyIOChannel chan = dyio.getChannel(index);
displayFlash.add(new Boolean(true));
Platform.runLater(()->channelValue.get(index).setText(Integer.toString(chan.getValue())));
Platform.runLater(()->displayFlash( index,chan.getCachedValue()));
chan.addChannelEventListener(e -> {
displayFlash( index,e.getValue());
});
channelButtonSelectors.get(index).setOnMouseEntered(event -> {
Platform.runLater(()->
channelButtonSelectors.get(index).setImage(BowlerStudioResourceFactory.getChanHighlight()));
});
channelButtonSelectors.get(index).setOnMouseExited(event -> {
Platform.runLater(()->
channelButtonSelectors.get(index).setImage(BowlerStudioResourceFactory.getChanDefault()));
});
channelTypeSelectors.get(index);
ArrayList<DyIOChannelMode> modesAvailible = dyio
.getAvailibleChannelModes(index);
for (DyIOChannelMode m : modesAvailible) {
items.add(m.toSlug());
}
Callback<ListView<String>, ListCell<String>> callback =new Callback<ListView<String>, ListCell<String>>() {
@Override
public ListCell<String> call(ListView<String> p) {
return new ListCell<String>() {
Label name = new Label();
Label icon = new Label();
private final HBox cell;
{
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
cell = new HBox(5);
//HERE, ADD YOUR PRE-MADE HBOX CODE
name.setTextFill(Color.BLACK);
cell.getChildren().add(icon);
cell.getChildren().add(name);
}
@Override protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setGraphic(null);
} else {
name.setText(item);
icon.setGraphic(new ImageView(BowlerStudioResourceFactory.getModeImage(DyIOChannelMode.getFromSlug(item))));
setGraphic(cell);
//HERE IS WHERE YOU GET THE LABEL AND NAME
}
}
};
}
};
Platform.runLater(()->{
channelTypeSelectors.get(index).setButtonCell(callback.call(null));
channelTypeSelectors.get(index).setCellFactory(callback);
channelTypeSelectors.get(index).setItems(items);
});
setChannelModeList(index);
dyio.getChannel(index).addChannelModeChangeListener(newMode -> {
setChannelModeList(index);
});
}
new Thread(){
public void run(){
setName("DyIOchannelWidget Setting channel value ");
for (int index = 0; index < 24; index++) {
int i=index;
FXMLLoader fxmlLoader= BowlerStudioResourceFactory.getLoader(i);
Parent root = fxmlLoader.getRoot();
DyIOchannelWidget controller = fxmlLoader.getController();
controller.setChannel(dyio.getChannel(i));
controller.setVisable(false);
controlWidgets.add(root);
}
initialized=true;
while(dyio.isAvailable()){
for(int i=0;i<24;i++){
DyIOchannelWidget controller =BowlerStudioResourceFactory.getLoader(i).getController();
if(controller.isFireValue()){
controller.setFireValue(false);
dyio.setValue(i,controller.getLatestValue());
if(dyio.getMode(i)==DyIOChannelMode.SERVO_OUT && dyio.getChannel(i).getCachedMode()){
dyio.getChannel(i).flush();
}
}
controller.updateValue();
}
ThreadUtil.wait(50);
}
}
}.start();
}
private void displayFlash(int index,int value){
// set the value label text
if(displayFlash.get(index)){
displayFlash.set(index, false);
Platform.runLater(()->{
channelValue.get(index).setText(Integer.toString(value));
channelButtonSelectors.get(index).setImage(BowlerStudioResourceFactory.getChanUpdate());
FxTimer.runLater(
Duration.ofMillis(200) ,new Runnable() {
@Override
public void run() {
channelButtonSelectors.get(index).setImage(BowlerStudioResourceFactory.getChanDefault());
displayFlash.set(index, true);
}
});
});
}
}
@FXML public void channelClicked(MouseEvent event) {
int index=getIndex( event);
System.err.println("Channel was clicked: "+index);
if(!initialized)
return;
setControlWidget( index);
}
private int getIndex(Event event){
for(int i=0;i<24;i++){
if(channelTypeSelectors.get(i).equals(event.getSource())){
return i;
}
if(channelButtonSelectors.get(i).equals(event.getSource())){
return i;
}
}
throw new RuntimeException("This event did not come from this system...");
}
@Override
public void initialize(URL location, ResourceBundle resources) {
}
private void setChannelModeList(int index){
DyIOChannel chan =dyio.getChannel(index);
Platform.runLater(()->{
ComboBox<String> selector = channelTypeSelectors.get(index);
String current =null;
for(String m:selector.getItems()){
if(chan.getMode().toSlug().contentEquals(m)){
current=m;
}
}
String tmp =current;
selector.setValue(tmp);
});
}
private void setControlWidget(int index){
for(int i=0;i<24;i++){
DyIOchannelWidget controller =BowlerStudioResourceFactory.getLoader(i).getController();
controller.setVisable(false);
}
DyIOchannelWidget mine = BowlerStudioResourceFactory.getLoader(index).getController();
Platform.runLater(()->{
if(!initialized)
return;
synchronized (controlWidgetPanel) {
controlWidgetPanel.getChildren().clear();
controlWidgetPanel.getChildren().add(controlWidgets.get(index));
}
mine.setVisable(true);
});
}
@FXML public void onChannelSelect(ActionEvent event) {
int index =getIndex( event);
ComboBox<String> comboBox = channelTypeSelectors.get(index);
String v = comboBox.getValue();
if(v==null)
return;
DyIOChannelMode value = DyIOChannelMode.getFromSlug(v);
if(!initialized)
return;
new Thread(){
public void run(){
setName("Running set mode thread");
dyio.setMode(index, value);
setControlWidget( index);
}
}.start();
}
}

View File

@@ -0,0 +1,376 @@
package com.neuronrobotics.bowlerstudio.tabs;
import javax.swing.SwingUtilities;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;
import org.python.core.exceptions;
import com.neuronrobotics.bowlerstudio.BowlerStudioController;
import com.neuronrobotics.bowlerstudio.assets.BowlerStudioResourceFactory;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import com.neuronrobotics.sdk.common.Log;
//import com.neuronrobotics.nrconsole.plugin.DyIO.DyIOConsole;
import com.neuronrobotics.sdk.dyio.DyIOChannel;
import com.neuronrobotics.sdk.dyio.DyIOChannelEvent;
import com.neuronrobotics.sdk.dyio.DyIOChannelMode;
import com.neuronrobotics.sdk.dyio.IChannelEventListener;
import com.neuronrobotics.sdk.dyio.peripherals.ServoChannel;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.embed.swing.SwingNode;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.chart.XYChart.Data;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.paint.Color;
public class DyIOchannelWidget {
private boolean fireValue=false;
private int latestValue=0;
private boolean isVisable=false;
private final class ChangeListenerImplementation implements
ChangeListener<Number> {
public void changed(ObservableValue<? extends Number> ov,
Number old_val, Number new_val) {
int newVal = new_val.intValue();
chanValue.setText(Integer.toString(newVal));
if(currentMode==DyIOChannelMode.SERVO_OUT ){
if(timeSlider.getValue()>.1){
//servo should only set on release when time is defined
return;
}
}
setLatestValue(newVal);
setFireValue(true);
}
}
@FXML Button setListenerButton;
@FXML AnchorPane listenerCodeBox;
@FXML LineChart<Integer,Integer> channelGraph;
@FXML Slider timeSlider;
@FXML Slider positionSlider;
@FXML Label chanValue;
@FXML Label deviceType;
@FXML Label deviceNumber;
@FXML ImageView deviceModeIcon;
private DyIOChannel channel;
private XYChart.Series<Integer, Integer> series = new XYChart.Series<Integer, Integer>();
private long startTime=0;
@FXML Label secondsLabel;
private IChannelEventListener myLocalListener=null;
private RSyntaxTextArea textArea;
private SwingNode sn;
private RTextScrollPane sp;
private ServoChannel srv= null;
private DyIOChannelMode currentMode;
private ChangeListenerImplementation imp = new ChangeListenerImplementation();
@FXML NumberAxis graphValueAxis;
@FXML NumberAxis graphTimeAxis;
private Integer value=null;
public void setChannel(DyIOChannel c){
this.channel = c;
startTime=System.currentTimeMillis();
setMode( channel.getMode());
Platform.runLater(()->deviceNumber.setText(Integer.toString(channel.getChannelNumber())));
Platform.runLater(()->chanValue.setText(Integer.toString(channel.getValue())));
Platform.runLater(()->secondsLabel.setText(String.format("%.2f", 0.0)));
Platform.runLater(()->positionSlider.setValue(channel.getValue()));
Platform.runLater(()->graphValueAxis.setAnimated(false));
Platform.runLater(()->graphTimeAxis.setAnimated(false));
Platform.runLater(()->positionSlider.valueProperty().addListener(imp));
positionSlider.valueChangingProperty().addListener((ChangeListener<Boolean>) (observable, oldValue, newValue) -> {
chanValue.setText(Integer.toString((int) positionSlider.getValue()));
if(currentMode==DyIOChannelMode.SERVO_OUT && timeSlider.getValue()>.1){
new Thread(){
public void run(){
Platform.runLater(()->setName("Setting servo Pos"));
//int ll = Log.getMinimumPrintLevel();
try{
//Log.enableInfoPrint();
srv.SetPosition((int) positionSlider.getValue(), timeSlider.getValue());
if(srv.getChannel().getCachedMode())
srv.getChannel().flush();
}catch(Exception ex){
ex.printStackTrace();
}
//Log.setMinimumPrintLevel(ll);
}
}.start();
}
});
timeSlider.valueProperty().addListener(new ChangeListener<Number>() {
public void changed(ObservableValue<? extends Number> ov,
Number old_val, Number new_val) {
secondsLabel.setText(String.format("%.2f", new_val));
}
});
channel.addChannelModeChangeListener(newMode -> {
setMode( newMode);
});
channel.addChannelEventListener(new IChannelEventListener() {
@Override
public void onChannelEvent(DyIOChannelEvent dyioEvent) {
if(isVisable()){
setValue(new Integer(dyioEvent.getValue()));
}
}
});
Platform.runLater(()->{
channelGraph.getData().clear();
try{
channelGraph.getData().add(series);
}catch(Exception e){}
});
setUpListenerPanel();
Platform.runLater(()->setListenerButton.setBackground(new Background(new BackgroundFill(Color.GREEN, CornerRadii.EMPTY, Insets.EMPTY))));
}
public void updateValue(){
if(getValue()!=null){
int current = getValue();
Data<Integer, Integer> newChart = new XYChart.Data<Integer, Integer>(
(int) (startTime-System.currentTimeMillis()),
current);
Platform.runLater(()->chanValue.setText(Integer.toString(current)));
if(!positionSlider.isValueChanging()){// only updae the slider position if the user is not sliding it
Platform.runLater(()->{
if(positionSlider==null)
return;
positionSlider.valueProperty().removeListener(imp);
positionSlider.setValue(current);
setLatestValue(current);
setFireValue(false);
positionSlider.valueProperty().addListener(imp);
});
}
Platform.runLater(()->{
if(series.getData().size()>10){// if you keep many more points in the graph it will lag the rendering realy badly
series.getData().remove(0);
}
Platform.runLater(()->{
series.getData().add(newChart);
value=null;
});
});
}
}
private void setMode(DyIOChannelMode newMode){
currentMode = newMode;
Platform.runLater(()->{
deviceModeIcon.setImage(BowlerStudioResourceFactory.getModeImage(newMode));
series.setName(currentMode.toSlug()+" values");
deviceType.setText(currentMode.toSlug());
//set slider bounds
graphValueAxis.setAutoRanging(false);
switch(currentMode){
case ANALOG_IN:
positionSlider.setMin(0);
positionSlider.setMax(1024);
graphValueAxis.setLowerBound(0);
graphValueAxis.setUpperBound(1024);
break;
case COUNT_IN_DIR:
case COUNT_IN_HOME:
case COUNT_IN_INT:
case COUNT_OUT_DIR:
case COUNT_OUT_HOME:
case COUNT_OUT_INT:
positionSlider.setMin(-5000);
positionSlider.setMax(5000);
graphValueAxis.setLowerBound(-5000);
graphValueAxis.setUpperBound(5000);
break;
case DC_MOTOR_DIR:
case DC_MOTOR_VEL:
case PWM_OUT:
case SERVO_OUT:
positionSlider.setMin(0);
positionSlider.setMax(255);
graphValueAxis.setLowerBound(0);
graphValueAxis.setUpperBound(255);
break;
case DIGITAL_IN:
case DIGITAL_OUT:
positionSlider.setMin(0);
positionSlider.setMax(1);
graphValueAxis.setLowerBound(0);
graphValueAxis.setUpperBound(1);
break;
default:
break;
}
// allow slider to be disabled for inputs
switch(currentMode){
case ANALOG_IN:
case COUNT_IN_DIR:
case COUNT_IN_HOME:
case COUNT_IN_INT:
case DIGITAL_IN:
timeSlider.setDisable(true);
positionSlider.setDisable(true);
break;
default:
timeSlider.setDisable(false);
positionSlider.setDisable(false);
break;
}
setLatestValue(channel.getValue());
if(currentMode==DyIOChannelMode.SERVO_OUT && srv==null){
new Thread(){
public void run(){
setName("Connectiong servo object");
srv = new ServoChannel(channel);
}
}.start();
}
});
}
@FXML public void onListenerButtonClicked(ActionEvent event) {
new Thread(){
public void run(){
setName("compiling listener");
try{
if(myLocalListener==null){
Platform.runLater(()->{
sn.setDisable(true);
textArea.setEditable(false);
});
myLocalListener=(IChannelEventListener) ScriptingEngine.inlineScriptStringRun(textArea.getText(), null, "Groovy");
channel.addChannelEventListener(myLocalListener);
Platform.runLater(()->{
setListenerButton.setText("Kill Listener");
setListenerButton.setBackground(new Background(new BackgroundFill(Color.RED, CornerRadii.EMPTY, Insets.EMPTY)));
});
}else{
channel.removeChannelEventListener(myLocalListener);
Platform.runLater(()->{
sn.setDisable(false);
textArea.setEditable(true);
myLocalListener=null;
setListenerButton.setBackground(new Background(new BackgroundFill(Color.GREEN, CornerRadii.EMPTY, Insets.EMPTY)));
setListenerButton.setText("Set Listener");
});
}
}catch(Exception e){
BowlerStudioController.highlightException(null, e);
}
}
}.start();
}
private void setUpListenerPanel(){
//Platform.runLater(()->{
textArea = new RSyntaxTextArea(15, 80);
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_GROOVY);
textArea.setCodeFoldingEnabled(true);
textArea.setText("return new IChannelEventListener() { \n"+
"\tpublic \n"
+ "\tvoid onChannelEvent(DyIOChannelEvent dyioEvent){\n"+
"\t\tprintln \"From Listener=\"+dyioEvent.getValue();\n"+
"\t}\n"+
"}"
);
sp = new RTextScrollPane(textArea);
sn = new SwingNode();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
sn.setContent(sp);
}
});
Platform.runLater(()->listenerCodeBox.getChildren().setAll(sn));
listenerCodeBox.setFocusTraversable(false);
sn.setOnMouseEntered(mouseEvent -> {
sn.requestFocus();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
textArea.requestFocusInWindow();
}
});
});
//});
}
public boolean isVisable() {
return isVisable;
}
public void setVisable(boolean isVisable) {
Platform.runLater(()->series.getData().clear());
this.isVisable = isVisable;
}
public boolean isFireValue() {
return fireValue;
}
public void setFireValue(boolean fireValue) {
this.fireValue = fireValue;
}
public int getLatestValue() {
return latestValue;
}
public void setLatestValue(int latestValue) {
this.latestValue = latestValue;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
}

View File

@@ -0,0 +1,56 @@
package com.neuronrobotics.bowlerstudio.tabs;
import javax.swing.JFrame;
import org.firmata4j.IODevice;
import org.firmata4j.firmata.FirmataDevice;
import org.firmata4j.ui.JPinboard;
import com.neuronrobotics.sdk.addons.kinematics.FirmataBowler;
import com.neuronrobotics.sdk.common.BowlerAbstractDevice;
import javafx.embed.swing.SwingNode;
import javafx.scene.control.ScrollPane;
public class FirmataTab extends AbstractBowlerStudioTab {
@Override
public void onTabClosing() {
// TODO Auto-generated method stub
}
@Override
public String[] getMyNameSpaces() {
// TODO Auto-generated method stub
return new String[0];
}
@Override
public void initializeUI(BowlerAbstractDevice pm) {
FirmataDevice device =( (FirmataBowler) pm).getFirmataDevice();
// TODO Auto-generated method stub
JFrame frame = new JFrame("Pinboard Example");
frame.add(new JPinboard(device ));
frame.pack();
frame.setVisible(true);
JPinboard pinboard = new JPinboard(device );
pinboard.setVisible(true);
SwingNode sn = new SwingNode();
sn.setContent(pinboard);
ScrollPane s1 = new ScrollPane();
s1.setContent(sn);
setContent(s1);
setText("Firmata Pinpoard");
onTabReOpening();
}
@Override
public void onTabReOpening() {
// TODO Auto-generated method stub
}
}

View File

@@ -0,0 +1,510 @@
package com.neuronrobotics.bowlerstudio.tabs;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.lang.Thread.UncaughtExceptionHandler;
import java.time.Duration;
import java.util.HashMap;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;
import org.reactfx.util.FxTimer;
import javax.swing.AbstractAction;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter;
import javax.swing.text.Highlighter;
import javax.swing.text.Highlighter.HighlightPainter;
import javafx.application.Platform;
import javafx.embed.swing.MySwingNode;
import javafx.event.EventHandler;
import javafx.scene.layout.VBox;
import com.neuronrobotics.bowlerstudio.BowlerStudio;
import com.neuronrobotics.bowlerstudio.IssueReportingExceptionHandler;
import com.neuronrobotics.bowlerstudio.scripting.IScriptEventListener;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingFileWidget;
import com.neuronrobotics.bowlerstudio.utils.FindTextWidget;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
public class LocalFileScriptTab extends VBox implements IScriptEventListener, EventHandler<WindowEvent> {
private static final UncaughtExceptionHandler ISSUE_REPORTING_EXCEPTION_HANDLER =new UncaughtExceptionHandler() {
IssueReportingExceptionHandler reporter = new IssueReportingExceptionHandler();
@Override
public void uncaughtException(Thread t, Throwable e) {
if(reporter.getTitle(e).contains("java.awt.datatransfer.DataFlavor at line 503")) {
System.err.println("Known bug in the Swing system, nothing we can do but ignore it");
e.printStackTrace();
return;
}
reporter.uncaughtException(t, e);
}
};// new IssueReportingExceptionHandler();
private long lastRefresh = 0;
private ScriptingFileWidget scripting;
IScriptEventListener l = null;
private MySwingNode swingNode;
private RTextScrollPane spscrollPane;
private Highlighter highlighter;
private HighlightPainter painter;
private int lineSelected = 0;
private MyRSyntaxTextArea textArea = new MyRSyntaxTextArea(200, 300);
private final File file;
private Font myFont;
private static HashMap<String, String> langaugeMapping = new HashMap<>();
private static LocalFileScriptTab selectedTab = null;
static {
SwingUtilities.invokeLater(() -> Thread.setDefaultUncaughtExceptionHandler(new IssueReportingExceptionHandler()));
}
public class MyRSyntaxTextArea extends RSyntaxTextArea implements ComponentListener {
/**
*
*/
private static final long serialVersionUID = 1L;
public MyRSyntaxTextArea() {
this.addComponentListener(this);
}
public MyRSyntaxTextArea(int i, int j) {
super(i, j);
}
public void componentResized(ComponentEvent e) {
System.err.println("componentResized");
}
public void componentHidden(ComponentEvent e) {
System.err.println("componentHidden");
}
public void componentMoved(ComponentEvent e) {
System.err.println("componentMoved");
}
public void componentShown(ComponentEvent e) {
System.err.println("componentShown");
}
}
public static void setExtentionSyntaxType(String shellType, String syntax) {
langaugeMapping.put(shellType, syntax);
}
public LocalFileScriptTab(File file) throws IOException {
Thread.setDefaultUncaughtExceptionHandler(new IssueReportingExceptionHandler());
this.file = file;
setScripting(new ScriptingFileWidget(file));
setSpacing(5);
l = this;
getScripting().addIScriptEventListener(l);
String type;
String shellType = ScriptingEngine.getShellType(file.getName());
switch (shellType) {
case "Clojure":
type = SyntaxConstants.SYNTAX_STYLE_CLOJURE;
break;
default:
type = langaugeMapping.get(shellType);
if (type == null) {
type = SyntaxConstants.SYNTAX_STYLE_NONE;
if (shellType.toLowerCase().contains("arduino")) {
type = SyntaxConstants.SYNTAX_STYLE_CPLUSPLUS;
}
}
case "JSON":
type = SyntaxConstants.SYNTAX_STYLE_JSON;
break;
case "ArduingScriptingLangauge":
type = SyntaxConstants.SYNTAX_STYLE_LISP;
break;
case "Arduino":
type = SyntaxConstants.SYNTAX_STYLE_CPLUSPLUS;
break;
case "Groovy":
type = SyntaxConstants.SYNTAX_STYLE_GROOVY;
break;
case "Jython":
type = SyntaxConstants.SYNTAX_STYLE_PYTHON;
break;
case "MobilBaseXML":
type = SyntaxConstants.SYNTAX_STYLE_XML;
break;
case "Kotlin":
type = SyntaxConstants.SYNTAX_STYLE_JAVA;
break;
case "SVG":
type = SyntaxConstants.SYNTAX_STYLE_XML;
break;
}
textArea.setSyntaxEditingStyle(type);
textArea.setCodeFoldingEnabled(true);
textArea.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
}
@Override
public void insertUpdate(DocumentEvent e) {
}
@Override
public void changedUpdate(DocumentEvent arg0) {
System.err.println("changedUpdate " + file);
new Thread() {
public void run() {
getScripting().removeIScriptEventListener(l);
getScripting().setCode(textArea.getText());
getScripting().addIScriptEventListener(l);
}
}.start();
}
});
textArea.addCaretListener(new CaretListener() {
@Override
public void caretUpdate(CaretEvent e) {
// Lets start with some default values for the line and column.
int linenum = 1;
int columnnum = 1;
// We create a try catch to catch any exceptions. We will simply
// ignore such an error for our demonstration.
try {
// First we find the position of the caret. This is the
// number of where the caret is in relation to the start of
// the JTextArea
// in the upper left corner. We use this position to find
// offset values (eg what line we are on for the given
// position as well as
// what position that line starts on.
int caretpos = textArea.getCaretPosition();
linenum = textArea.getLineOfOffset(caretpos);
// We subtract the offset of where our line starts from the
// overall caret position.
// So lets say that we are on line 5 and that line starts at
// caret position 100, if our caret position is currently
// 106
// we know that we must be on column 6 of line 5.
columnnum = caretpos - textArea.getLineStartOffset(linenum);
// We have to add one here because line numbers start at 0
// for getLineOfOffset and we want it to start at 1 for
// display.
linenum += 1;
} catch (Exception ex) {
ex.printStackTrace();
}
if (lineSelected != linenum) {
lineSelected = linenum;
// System.err.println("Select "+lineSelected);
new Thread(() -> {
BowlerStudio.select(file, lineSelected);
}).start();
}
}
});
textArea.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() > 2) {
highlighter.removeAllHighlights();
}
// System.out.println("Number of click: " + e.getClickCount());
// System.out.println("Click position (X, Y): " + e.getX() + ",
// " + e.getY());
}
});
spscrollPane = new RTextScrollPane(textArea);
swingNode = new MySwingNode(this);
SwingUtilities.invokeLater(() -> swingNode.setContent(spscrollPane));
getScripting().setFocusTraversable(false);
getChildren().setAll(swingNode, getScripting());
swingNode.setOnMouseEntered(mouseEvent -> {
//System.err.println("On mouse entered " + file.getName());
//resizeEvent();
SwingUtilities.invokeLater(() ->{
resizeEvent();
setSelectedTab(this);
// spscrollPane.setSize((int) spscrollPane.getWidth(), (int) spscrollPane.getHeight());
// spscrollPane.invalidate();
// spscrollPane.repaint();
// textArea.invalidate();
// textArea.repaint();
// textArea.requestFocusInWindow();
// FxTimer.runLater(Duration.ofMillis((int) 16), () -> {
// swingNode.requestFocus();
// });
});
});
// textArea
KeyStroke keystroke = KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_MASK);
textArea.getInputMap().put(keystroke, "f");
textArea.getActionMap().put("f", new AbstractAction() {
/**
*
*/
private static final long serialVersionUID = -4698223073831405851L;
public void actionPerformed(ActionEvent e) {
findTextWidget();
}
});
myFont = textArea.getFont();
highlighter = textArea.getHighlighter();
painter = new DefaultHighlighter.DefaultHighlightPainter(Color.pink);
highlighter.removeAllHighlights();
// widthProperty().addListener((w, o, n) -> {
// resizeEvent();
//
// });
// heightProperty().addListener((w, o, n) -> {
// resizeEvent();
// });
SwingUtilities.invokeLater(() -> {
if (getScripting() != null && getScripting().getCode() != null) {
onScriptChanged(null, getScripting().getCode(), file);
}
});
}
private void resizeEvent() {
if (!((lastRefresh + 60) < System.currentTimeMillis())||
spscrollPane.getVerticalScrollBar().getValueIsAdjusting()||
spscrollPane.getHorizontalScrollBar().getValueIsAdjusting()) {
return;
}
lastRefresh = System.currentTimeMillis();
SwingUtilities.invokeLater(() ->{
spscrollPane.setSize((int) spscrollPane.getWidth(), (int) spscrollPane.getHeight());
spscrollPane.invalidate();
spscrollPane.repaint();
textArea.invalidate();
textArea.repaint();
textArea.requestFocusInWindow();
FxTimer.runLater(Duration.ofMillis((int) 16), () -> {
swingNode.setContent(spscrollPane);
swingNode.requestFocus();
});
});
}
@Override
public void onScriptFinished(Object result, Object previous, File source) {
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// textArea.requestFocusInWindow();
// }
// });
}
@Override
public void onScriptChanged(String previous, String current, File source) {
// int place = textArea.getCaretPosition();
// System.err.println("Carrot position is= "+place);
// codeArea.replaceText(current);
// codeArea.setCursor(place);
if (current.length() > 3 && !textArea.getText().contentEquals(current)) {// no
// empty
// writes
SwingUtilities.invokeLater(() -> {
textArea.setText(current);
if (previous == null)
SwingUtilities.invokeLater(() -> textArea.setCaretPosition(0));
});
}
}
@Override
public void onScriptError(Throwable except, File source) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
System.out.println("script error");
textArea.requestFocusInWindow();
}
});
}
public void findTextWidget() {
Platform.runLater(() -> {
Stage s = new Stage();
new Thread() {
public void run() {
Thread.setDefaultUncaughtExceptionHandler(ISSUE_REPORTING_EXCEPTION_HANDLER);
FindTextWidget controller = new FindTextWidget();
controller.setTextArea(textArea);
try {
controller.start(s);
} catch (Exception e) {
ISSUE_REPORTING_EXCEPTION_HANDLER.uncaughtException(Thread.currentThread(), e);
}
}
}.start();
});
}
@Override
public void handle(WindowEvent event) {
getScripting().stop();
}
public ScriptingFileWidget getScripting() {
return scripting;
}
public void setScripting(ScriptingFileWidget scripting) {
this.scripting = scripting;
}
public void setHighlight(int lineNumber, Color color) throws BadLocationException {
if (textArea == null) {
return;
}
painter = new DefaultHighlighter.DefaultHighlightPainter(color);
int startIndex = textArea.getLineStartOffset(lineNumber - 1);
int endIndex = textArea.getLineEndOffset(lineNumber - 1);
try {
SwingUtilities.invokeLater(() -> {
textArea.moveCaretPosition(startIndex);
});
} catch (Error | Exception ex) {
ex.printStackTrace();
}
SwingUtilities.invokeLater(() -> {
try {
textArea.getHighlighter().addHighlight(startIndex, endIndex, painter);
} catch (BadLocationException e) {
ISSUE_REPORTING_EXCEPTION_HANDLER.uncaughtException(Thread.currentThread(), e);
}
});
}
public void clearHighlits() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
highlighter.removeAllHighlights();
}
});
}
public int getFontSize() {
return myFont.getSize();
}
public void setFontSize(int size) {
myFont = new Font(myFont.getName(), myFont.getStyle(), size);
setFontLoop();
}
private void setFontLoop() {
FxTimer.runLater(Duration.ofMillis(200), new Runnable() {
@Override
public void run() {
Thread.setDefaultUncaughtExceptionHandler(ISSUE_REPORTING_EXCEPTION_HANDLER);
SwingUtilities.invokeLater(() -> {
try {
textArea.setFont(myFont);
} catch (Throwable ex) {
//ISSUE_REPORTING_EXCEPTION_HANDLER.uncaughtException(Thread.currentThread(), ex);
setFontLoop();
}
});
}
});
}
public static LocalFileScriptTab getSelectedTab() {
return selectedTab;
}
public static void setSelectedTab(LocalFileScriptTab selectedTab) {
//System.err.println("Currently selected "+selectedTab.file.getAbsolutePath());
LocalFileScriptTab.selectedTab = selectedTab;
}
public void insertString(String string) {
int caretpos = textArea.getCaretPosition();
String text = textArea.getText();
String substring = text.substring(0,caretpos);
String substring2;
try {
substring2 = text.substring(caretpos,text.length());
}catch(java.lang.StringIndexOutOfBoundsException ex) {
substring2="";
}
String combined = substring+string+substring2;
onScriptChanged(text, combined, file);
SwingUtilities.invokeLater(() -> {
textArea.setCaretPosition(caretpos+string.length());
});
}
}

View File

@@ -0,0 +1,384 @@
package com.neuronrobotics.bowlerstudio.tabs;
import com.neuronrobotics.bowlerstudio.BowlerStudioController;
import com.neuronrobotics.bowlerstudio.Tutorial;
import com.neuronrobotics.bowlerstudio.assets.AssetFactory;
import com.neuronrobotics.bowlerstudio.scripting.PasswordManager;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingWebWidget;
import com.neuronrobotics.sdk.common.Log;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.concurrent.Worker.State;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebHistory;
import javafx.scene.web.WebView;
import org.reactfx.util.FxTimer;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.Duration;
public class WebTab extends Tab implements EventHandler<Event>{
private String Current_URL = "http://gist.github.com/";
private WebTab myTab;
boolean loaded=false;
boolean initialized=false;
private WebView webView;
private WebEngine webEngine;
private VBox vBox;
private Button goButton = new Button("");
private Button homeButton = new Button("");
private Button backButton = new Button("");
private Button forwardButton = new Button("");
private TextField urlField;
//private String currentAddress;
private ScriptingWebWidget scripting;
private Graphics2D splashGraphics;
private static boolean firstBoot=true;
private boolean isTutorialTab =false;
private boolean finishedLoadingScriptingWidget;
private static BowlerStudioController controller;
public WebTab(String title, String Url) throws IOException, InterruptedException{
this(title,Url,false);
}
@SuppressWarnings("restriction")
public WebTab(String title, String Url,boolean isTutorialTab) throws IOException, InterruptedException{
if(isTutorialTab){
setGraphic(AssetFactory.loadIcon("Tutorial-Tab.png"));
}else
setGraphic(AssetFactory.loadIcon("Web-Tab.png"));
goButton.setGraphic(AssetFactory.loadIcon("Go-Refresh.png"));
homeButton.setGraphic(AssetFactory.loadIcon("Home.png"));
backButton.setGraphic(AssetFactory.loadIcon("Back-Button.png"));
forwardButton.setGraphic(AssetFactory.loadIcon("Forward-Button.png"));
this.isTutorialTab = isTutorialTab;
myTab = this;
if(title==null)
myTab.setText(" ");
else
myTab.setText(title);
Log.debug("Loading Gist Tab: "+Url);
webView = new WebView();
webEngine = webView.getEngine();
//webEngine.setUserAgent("bowlerstudio");
if(Url!=null)
Current_URL=Url;
loaded=false;
setOnCloseRequest(this);
webEngine.getLoadWorker().workDoneProperty().addListener((ChangeListener<Number>) (observableValue, oldValue, newValue) -> Platform.runLater(() -> {
if(!(newValue.intValue()<100)){
//System.err.println("Just finished! "+webEngine.getLocation());
new Thread(){
public void run(){
if(!initialized){
initialized=true;
loaded=true;
setName("Start finalizing components");
finishLoadingComponents();
}
else{
try {
getScripting().loadCodeFromGist(Current_URL, webEngine);
} catch (Exception e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
}
}
}.start();
}else{
loaded=false;
// if(splashGraphics!=null && splash.isVisible()){
// //BowlerStudio.renderSplashFrame(splashGraphics, newValue.intValue());
// //splash.update();
// }
//System.err.println("Not Done Loading to: "+webEngine.getLocation());
}
}));
urlField = new TextField(Current_URL);
webEngine.locationProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable1,String oldValue, String newValue) {
//System.out.println("Location Changed: "+newValue);
Platform.runLater(() -> {
urlField.setText(newValue);
});
}
});
//goButton.setDefaultButton(true);
webEngine.getLoadWorker().stateProperty().addListener(
new ChangeListener<Object>() {
public void changed(ObservableValue<?> observable,
Object oldValue, Object newValue) {
if (State.SUCCEEDED == newValue) {
Current_URL = urlField.getText().startsWith("http://")|| urlField.getText().startsWith("https://")|| urlField.getText().startsWith("file:")
? urlField.getText()
: "http://" + urlField.getText();
Log.debug("Load Worker State Changed "+Current_URL);
if( !processNewTab(urlField.getText())){
goBack();
}
}else{
//Log.error("State load fault: "+newValue+" object:" +observable);
}
}
});
backButton.setOnAction(arg0 -> {
goBack();
});
forwardButton.setOnAction(arg0 -> {
// TODO Auto-generated method stub
goForward();
});
homeButton.setOnAction(arg0 -> {
// TODO Auto-generated method stub
try {
loadUrl(Tutorial.getHomeUrl());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
// Layout logic
HBox hBox = new HBox(5);
hBox.getChildren().setAll(backButton,forwardButton,homeButton,goButton,urlField);
HBox.setHgrow(urlField, Priority.ALWAYS);
vBox = new VBox(5);
vBox.getChildren().setAll(hBox, webView);
VBox.setVgrow(webView, Priority.ALWAYS);
myTab.setContent(vBox);
//Action definition for the Button Go.
EventHandler<ActionEvent> goAction = event -> {
Log.debug("Hitting load");
if(processNewTab(urlField.getText())){
Log.debug("Loading "+Current_URL);
loadUrl( Current_URL);
}
};
urlField.setOnAction(goAction);
goButton.setOnAction(goAction);
//Once all components are loaded, load URL
FxTimer.runLater(
Duration.ofMillis(200) ,new Runnable() {
@Override
public void run() { goAction.handle(null);}
});
}
public void loadUrl(String url){
if(processNewTab(Current_URL)){
Platform.runLater(() -> {
webEngine.load(url);
});
}
}
private boolean processNewTab(String url){
Current_URL = urlField.getText().startsWith("http://") || urlField.getText().startsWith("https://") || urlField.getText().startsWith("file:")
? urlField.getText()
: "http://" + urlField.getText();
if(isTutorialTab ){
if( !((Current_URL.toLowerCase().contains("commonwealthrobotics.com") ||
Current_URL.contains("gist.github.com/"+PasswordManager.getUsername() )||
Current_URL.contains("localhost") ))){
try {
Log.error("Non demo page found, opening new tab "+Current_URL);
BowlerStudioController.getBowlerStudio().addTab(new WebTab(null, Current_URL), true);
return false;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}else{
Log.debug("no load new tab");
if(getScripting()!=null){
try{
myTab.setText(getScripting().getFileName());
}catch(java.lang.NullPointerException ex){
try {
getScripting().loadCodeFromGist(Current_URL, webEngine);
myTab.setText(getScripting().getFileName());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
return true;
}
private void finishLoadingComponents(){
//System.err.println("Finalizing: "+webEngine.getLocation());
try{
if(getScripting()!=null){
//when navagating to a new file, stop the script that is running
getScripting().stop();
}
}catch(Exception E){
E.printStackTrace();
}
new Thread() {
public void run() {
finishedLoadingScriptingWidget=false;
try{
setScripting(new ScriptingWebWidget( null ,Current_URL, webEngine));
Platform.runLater(() -> {
vBox.getChildren().add(getScripting());
if(!isTutorialTab){
Platform.runLater(()->{
try{
myTab.setText(getScripting().getFileName());
}catch(java.lang.NullPointerException ex){
// web page contains no gist
ex.printStackTrace();
myTab.setText("Web");
}
loadCode();
});
}
else
finishedLoadingScriptingWidget=true;
});
}catch(Exception ex){
ex.printStackTrace();
finishedLoadingScriptingWidget=true;
}
}
}.start();
}
private void loadCode(){
new Thread(()->{
System.out.println("Downloading code from "+Current_URL);
try {
getScripting().loadCodeFromGist(Current_URL, webEngine);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}).start();
}
public String goBack()
{
//new Exception().printStackTrace(System.err);
final WebHistory history=webEngine.getHistory();
ObservableList<WebHistory.Entry> entryList=history.getEntries();
int currentIndex=history.getCurrentIndex();
// Out("currentIndex = "+currentIndex);
// Out(entryList.toString().replace("],","]\n"));
Platform.runLater(() ->{
try{
history.go(-1);
}catch(Exception e){
// e.printStackTrace();
}
});
return entryList.get(currentIndex>0?currentIndex-1:currentIndex).getUrl();
}
public String goForward()
{
final WebHistory history=webEngine.getHistory();
ObservableList<WebHistory.Entry> entryList=history.getEntries();
int currentIndex=history.getCurrentIndex();
// Out("currentIndex = "+currentIndex);
// Out(entryList.toString().replace("],","]\n"));
Platform.runLater(() -> {
try {
history.go(1);
} catch (IndexOutOfBoundsException ex) {
}
});
return entryList.get(currentIndex<entryList.size()-1?currentIndex+1:currentIndex).getUrl();
}
public static String getDomainName(String url) throws URISyntaxException {
URI uri = new URI(url);
String domain = uri.getHost();
return domain.startsWith("www.") ? domain.substring(4) : domain;
}
@Override
public void handle(Event event) {
if(getScripting()!=null)
getScripting().stop();
}
public ScriptingWebWidget getScripting() {
return scripting;
}
public void setScripting(ScriptingWebWidget scripting) {
this.scripting = scripting;
scripting.addIScriptEventListener(controller);
}
public static void setBSController(BowlerStudioController controller) {
WebTab.controller = controller;
}
}

Some files were not shown because too many files have changed in this diff Show More